diff --git a/.gitignore b/.gitignore
index ff947966a2b9c7814a8ca64228810130cabe96f6..b2913b82aead866c8a72dbbe6bfbf16f7c2c0e78 100644
--- a/.gitignore
+++ b/.gitignore
@@ -18,3 +18,8 @@ GPATH
 GRTAGS
 GTAGS
 tags
+
+# others
+nfapi_nr_interface_scf
+*.log
+*.out
diff --git a/.vscode/launch.json b/.vscode/launch.json
index 4b563febdea2f01db7f95405d5bc5ffb1803f586..8be69157639e9efa5c6bffc1a1ffd770d2d7d6ff 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -8,14 +8,17 @@
             "name": "(gdb) Launch",
             "type": "cppdbg",
             "request": "launch",
-            "program": "enter program name, for example ${workspaceFolder}/a.exe",
-            "args": [],
+            "program": "${workspaceFolder}/cmake_targets/ran_build/build/lte-softmodem",
+            "args": [
+                "-O", "../ci-scripts/conf_files/rcc.band7.tm1.nfapi.conf",
+                "--noS1"
+            ],
             "stopAtEntry": false,
-            "cwd": "${workspaceFolder}",
+            "cwd": "${workspaceFolder}/cmake_targets",
             "environment": [],
             "externalConsole": false,
             "MIMode": "gdb",
-            "miDebuggerPath": "/path/to/gdb",
+            "miDebuggerPath": "${workspaceFolder}/cmake_targets/sudo-gdb",
             "setupCommands": [
                 {
                     "description": "Enable pretty-printing for gdb",
diff --git a/README.md b/README.md
index 62f8576e81547cf7769ff966ec0b524629a40ea3..4f38f77e4e9d37d8fdc54ff6b867bc84db818d72 100644
--- a/README.md
+++ b/README.md
@@ -21,16 +21,28 @@
 
 # OpenAirInterface License #
 
-OpenAirInterface is under OpenAirInterface Software Alliance license.
+### Included Fixes: ###
+- Ease of use of gprof and address sanitizer for debugging purposes
+- Updated json files to allow for GDB, real-time debugging capabilities
+- Updated logging features to minimally log only key connection milestones. This imroves scalability of multiple UEs.
+- Updated logging to include time stamp for timing analysis
+- Updated memory allocation procedures to correct size requirements
+- Added debugging features to handle signal terminations
+- nfapi.c pullarray8 fix invalid pointer math
+- Overlapping destination and source memory in memcpy, so updated to memmove to check for this bug
+- Advanced error checking mechanisms in critical pack and unpack functions
+- Created option for CPU assignment to UE to improve scalability
+- Added EPC integration to allow multiple individual UE entities to each have their USIM information parced by the executables
+- Updated random value seeds to minimize probability of error in generation of random values
+- Enables capability round robin scheduler if desired
+- Enables capability real time scheduler if desired
+- Added new standalone functions to the UE phy-layer (phy_stub_ue.c) to incorporate individual UE entities
+- Updated sending and packing functions in UE (lte_ue.c) to incorporate new standalone changes
+- Incorporated semaphores to control timing of incoming downlink packets
+- Implemented new queuing system to handle message exchange from UE to eNB and vice versa
+- Updated global value in nFAPI for size of subframe
+- Updated global value to increase scalability in system
 
- *  [OAI License Model](http://www.openairinterface.org/?page_id=101)
- *  [OAI License v1.1 on our website](http://www.openairinterface.org/?page_id=698)
-
-It is distributed under **OAI Public License V1.1**.
-
-The license information is distributed under [LICENSE](LICENSE) file in the same directory.
-
-Please see [NOTICE](NOTICE.md) file for third party software that is included in the sources.
 
 # Where to Start #
 
diff --git a/ci-scripts/Jenkinsfile-GitLab-Container b/ci-scripts/Jenkinsfile-GitLab-Container
index 654ad23230bfaf745d3b0d6953a972c44493888e..9ff0371ae550c09389e79989ce35077fcaf6b9c3 100644
--- a/ci-scripts/Jenkinsfile-GitLab-Container
+++ b/ci-scripts/Jenkinsfile-GitLab-Container
@@ -238,6 +238,26 @@ pipeline {
             }
           }
         }
+        stage ("Test OAI NR UE - OAI gNB - TDD - Band 78 - N300") {
+          when { expression {doMandatoryTests} }
+          steps {
+            script {
+              triggerSlaveJob ('RAN-gNB-nrUE-MONO-TDD-Band78-N300', 'Test-TDD-Band78-gNB-NR-UE')
+            }
+          }
+          post {
+            always {
+              script {
+                finalizeSlaveJob('RAN-gNB-nrUE-MONO-TDD-Band78-N300')
+              }
+            }
+            failure {
+              script {
+                currentBuild.result = 'FAILURE'
+              }
+            }
+          }
+        }
       }
     }
     stage ("Images Push to Registries") {
diff --git a/ci-scripts/Jenkinsfile-gitlab b/ci-scripts/Jenkinsfile-gitlab
index a0284edb71cc6a645128f192c2deda78a850ad96..df816c12a750908e4979fca89fb9dd7bfe3ec632 100644
--- a/ci-scripts/Jenkinsfile-gitlab
+++ b/ci-scripts/Jenkinsfile-gitlab
@@ -404,26 +404,6 @@ pipeline {
                               }
                             }
                         }
-                        stage ("Test L2 simulator") {
-                            when {
-                                expression {doFullTestsuite}
-                            }
-                            steps {
-                              lock (vmResource) {
-                                script {
-                                    timeout (time: 30, unit: 'MINUTES') {
-                                        try {
-                                            gitlabCommitStatus(name: "Test L2-sim") {
-                                                sh "./ci-scripts/oai-ci-vm-tool test --workspace $WORKSPACE --variant l2-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
-                                            }
-                                        } catch (Exception e) {
-                                            currentBuild.result = 'FAILURE'
-                                        }
-                                    }
-                                }
-                              }
-                            }
-                        }
                         stage ("Destroy all Virtual Machines") {
                             when {
                                 expression {doMandatoryTests}
@@ -663,28 +643,6 @@ pipeline {
                         }
                     }
                 }
-                stage ("Test OAI NR UE - OAI gNB - TDD - Band 78 - N300") {
-                    when {
-                        expression {doMandatoryTests}
-                    }
-                    steps {
-                        script {
-                            triggerSlaveJob ('gNB-nrUE-MONO-TDD-Band78-N300', 'Test-TDD-Band78-gNB-NR-UE')
-                        }
-                    }
-                    post {
-                        always {
-                            script {
-                                finalizeSlaveJob('gNB-nrUE-MONO-TDD-Band78-N300')
-                            }
-                        }
-                        failure {
-                            script {
-                                currentBuild.result = 'FAILURE'
-                            }
-                        }
-                    }
-                }
                 stage ("Test OAI OCP-eNB - FDD - Band 7 - B210") {
                     when {
                         expression {doFullTestsuite}
diff --git a/ci-scripts/cls_containerize.py b/ci-scripts/cls_containerize.py
index 41747f1bc26bd0de31813ac3ff2c64e1de899653..ffd93d79cfda1b24cf3e0ff0daf09017d97a47cc 100644
--- a/ci-scripts/cls_containerize.py
+++ b/ci-scripts/cls_containerize.py
@@ -93,6 +93,7 @@ class Containerize():
 		self.allImagesSize = {}
 		self.collectInfo = {}
 
+		self.tsharkStarted = False
 		self.pingContName = ''
 		self.pingOptions = ''
 		self.pingLossThreshold = ''
@@ -670,6 +671,10 @@ class Containerize():
 				time.sleep(10)
 
 		if count == 100 and healthy == self.nb_healthy[0]:
+			if self.tsharkStarted == False:
+				logging.debug('Starting tshark on public network')
+				self.CaptureOnDockerNetworks()
+				self.tsharkStarted = True
 			HTML.CreateHtmlTestRow('n/a', 'OK', CONST.ALL_PROCESSES_OK)
 			logging.info('\u001B[1m Deploying OAI Object(s) PASS\u001B[0m')
 		else:
@@ -677,8 +682,24 @@ class Containerize():
 			HTML.CreateHtmlTestRow('Could not deploy in time', 'KO', CONST.ALL_PROCESSES_OK)
 			logging.error('\u001B[1m Deploying OAI Object(s) FAILED\u001B[0m')
 
+	def CaptureOnDockerNetworks(self):
+		cmd = 'cd ' + self.yamlPath[0] + ' && docker-compose -f docker-compose-ci.yml config | grep com.docker.network.bridge.name | sed -e "s@^.*name: @@"'
+		networkNames = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=10)
+		cmd = 'sudo nohup tshark -f "not tcp and not arp and not port 53 and not host archive.ubuntu.com and not host security.ubuntu.com"'
+		for name in networkNames.split('\n'):
+			res = re.search('rfsim', name)
+			if res is not None:
+				cmd += ' -i ' + name
+		cmd += ' -w /tmp/capture_'
+		ymlPath = self.yamlPath[0].split('/')
+		cmd += ymlPath[1] + '.pcap > /tmp/tshark.log 2>&1 &'
+		logging.debug(cmd)
+		networkNames = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=10)
+
 	def UndeployGenObject(self, HTML):
 		self.exitStatus = 0
+		ymlPath = self.yamlPath[0].split('/')
+		logPath = '../cmake_targets/log/' + ymlPath[1]
 
 		if (self.ranAllowMerge):
 			cmd = 'cd ' + self.yamlPath[0] + ' && sed -e "s@develop@ci-temp@" docker-compose.y*ml > docker-compose-ci.yml'
@@ -706,9 +727,21 @@ class Containerize():
 				logging.debug(cmd)
 				deployStatus = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=30)
 		if anyLogs:
-			cmd = 'mkdir -p ../cmake_targets/log && mv ' + self.yamlPath[0] + '/*.log ../cmake_targets/log'
+			cmd = 'mkdir -p '+ logPath + ' && mv ' + self.yamlPath[0] + '/*.log ' + logPath
 			logging.debug(cmd)
 			deployStatus = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=10)
+			if self.tsharkStarted:
+				self.tsharkStarted = True
+				ymlPath = self.yamlPath[0].split('/')
+				cmd = 'sudo chmod 666 /tmp/capture_' + ymlPath[1] + '.pcap'
+				logging.debug(cmd)
+				copyStatus = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=10)
+				cmd = 'cp /tmp/capture_' + ymlPath[1] + '.pcap ' + logPath
+				logging.debug(cmd)
+				copyStatus = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=10)
+				cmd = 'sudo rm /tmp/capture_' + ymlPath[1] + '.pcap'
+				logging.debug(cmd)
+				copyStatus = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=10)
 
 		cmd = 'cd ' + self.yamlPath[0] + ' && docker-compose -f docker-compose-ci.yml down'
 		logging.debug(cmd)
@@ -726,10 +759,13 @@ class Containerize():
 
 	def PingFromContainer(self, HTML):
 		self.exitStatus = 0
-		cmd = 'mkdir -p ../cmake_targets/log'
+		ymlPath = self.yamlPath[0].split('/')
+		logPath = '../cmake_targets/log/' + ymlPath[1]
+		cmd = 'mkdir -p ' + logPath
 		deployStatus = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=10)
 
-		cmd = 'docker exec ' + self.pingContName + ' /bin/bash -c "ping ' + self.pingOptions + '" 2>&1 | tee ../cmake_targets/log/ping_' + HTML.testCase_id + '.log || true'
+		cmd = 'docker exec ' + self.pingContName + ' /bin/bash -c "ping ' + self.pingOptions + '" 2>&1 | tee ' + logPath + '/ping_' + HTML.testCase_id + '.log || true'
+
 		logging.debug(cmd)
 		deployStatus = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=100)
 
@@ -784,14 +820,23 @@ class Containerize():
 		if status:
 			HTML.CreateHtmlTestRowQueue(self.pingOptions, 'OK', 1, html_queue)
 		else:
-			self.exitStatus = 1
-			logging.error('\u001B[1;37;41m ' + message + ' \u001B[0m')
+			logging.error('\u001B[1;37;41m ping test FAIL -- ' + message + ' \u001B[0m')
 			HTML.CreateHtmlTestRowQueue(self.pingOptions, 'KO', 1, html_queue)
+			# Automatic undeployment
+			logging.debug('----------------------------------------')
+			logging.debug('\u001B[1m Starting Automatic undeployment \u001B[0m')
+			logging.debug('----------------------------------------')
+			HTML.testCase_id = 'AUTO-UNDEPLOY'
+			HTML.desc = 'Automatic Un-Deployment'
+			self.UndeployGenObject(HTML)
+			self.exitStatus = 1
 
 	def IperfFromContainer(self, HTML):
 		self.exitStatus = 0
 
-		cmd = 'mkdir -p ../cmake_targets/log'
+		ymlPath = self.yamlPath[0].split('/')
+		logPath = '../cmake_targets/log/' + ymlPath[1]
+		cmd = 'mkdir -p ' + logPath
 		logStatus = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=10)
 
 		# Start the server process
@@ -801,7 +846,8 @@ class Containerize():
 		time.sleep(5)
 
 		# Start the client process
-		cmd = 'docker exec ' + self.cliContName + ' /bin/bash -c "iperf ' + self.cliOptions + '" 2>&1 | tee ../cmake_targets/log/iperf_client_' + HTML.testCase_id + '.log || true'
+
+		cmd = 'docker exec ' + self.cliContName + ' /bin/bash -c "iperf ' + self.cliOptions + '" 2>&1 | tee '+ logPath + '/iperf_client_' + HTML.testCase_id + '.log || true'
 		logging.debug(cmd)
 		clientStatus = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=100)
 
@@ -810,7 +856,7 @@ class Containerize():
 		logging.debug(cmd)
 		serverStatus = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=10)
 		time.sleep(5)
-		cmd = 'docker cp ' + self.svrContName + ':/tmp/iperf_server.log ../cmake_targets/log/iperf_server_' + HTML.testCase_id + '.log'
+		cmd = 'docker cp ' + self.svrContName + ':/tmp/iperf_server.log '+ logPath + '/iperf_server_' + HTML.testCase_id + '.log'
 		logging.debug(cmd)
 		serverStatus = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, timeout=30)
 
@@ -906,9 +952,10 @@ class Containerize():
 		if status:
 			HTML.CreateHtmlTestRowQueue(self.cliOptions, 'OK', 1, html_queue)
 		else:
-			self.exitStatus = 1
+			logging.error('\u001B[1m Iperf Test FAIL -- ' + message + ' \u001B[0m')
 			HTML.CreateHtmlTestRowQueue(self.cliOptions, 'KO', 1, html_queue)
 
+
 	def CheckAndAddRoute(self, svrName, ipAddr, userName, password):
 		logging.debug('Checking IP routing on ' + svrName)
 		mySSH = SSH.SSHConnection()
@@ -1019,3 +1066,4 @@ class Containerize():
 			if result is None:
 				mySSH.command('echo ' + password + ' | sudo -S iptables -P FORWARD ACCEPT', '\$', 10)
 			mySSH.close()
+
diff --git a/ci-scripts/cls_oaicitest.py b/ci-scripts/cls_oaicitest.py
index b8b99a053bd640dc832c4c69ffbb93b4081f7d95..097cfd476d7d4898c206f0ec252443604e844e4d 100644
--- a/ci-scripts/cls_oaicitest.py
+++ b/ci-scripts/cls_oaicitest.py
@@ -3012,9 +3012,6 @@ class OaiCiTest():
 			if result is not None and not exitSignalReceived:
 				foundSegFault = True
 			result = re.search('[Cc]ore [dD]ump', str(line))
-			if result is not None and not exitSignalReceived:
-				foundSegFault = True
-			result = re.search('./lte-uesoftmodem', str(line))
 			if result is not None and not exitSignalReceived:
 				foundSegFault = True
 			result = re.search('[Aa]ssertion', str(line))
diff --git a/ci-scripts/conf_files/episci/episci_gnb.band78.sa.fr1.106PRB.usrpn310.conf b/ci-scripts/conf_files/episci/episci_gnb.band78.sa.fr1.106PRB.usrpn310.conf
new file mode 100644
index 0000000000000000000000000000000000000000..01add06e3a57c6c34c1d54be6882c2757345b9f5
--- /dev/null
+++ b/ci-scripts/conf_files/episci/episci_gnb.band78.sa.fr1.106PRB.usrpn310.conf
@@ -0,0 +1,325 @@
+Active_gNBs = ( "gNB-OAI");
+# Asn1_verbosity, choice in: none, info, annoying
+Asn1_verbosity = "none";
+
+gNBs =
+(
+ {
+    ////////// Identification parameters:
+    gNB_ID    =  0xe00;
+    gNB_name  =  "gNB-OAI";
+
+    // Tracking area code, 0x0000 and 0xfffe are reserved values
+    tracking_area_code  =  40960;
+    plmn_list = ({
+                  mcc = 208;
+                  mnc = 95;
+                  mnc_length = 2;
+                  snssaiList = (
+                    {
+                      sst = 1;
+                      sd  = 0x1; // 0 false, else true
+                    },
+                    {
+                      sst = 1;
+                      sd  = 0x112233; // 0 false, else true
+                    }
+                  );
+
+                  });
+
+    nr_cellid = 12345678L;
+
+    ////////// Physical parameters:
+
+    ssb_SubcarrierOffset                                      = 0;
+    pdsch_AntennaPorts                                        = 1;
+    pusch_AntennaPorts                                        = 1;
+    ul_prbblacklist                                           = "51,52,53,54"
+    min_rxtxtime_pdsch = 6;
+     pdcch_ConfigSIB1 = (
+      {
+        controlResourceSetZero = 12;
+        searchSpaceZero = 0;
+      }
+      );
+
+    servingCellConfigCommon = (
+    {
+ #spCellConfigCommon
+
+      physCellId                                                    = 0;
+
+#  downlinkConfigCommon
+    #frequencyInfoDL
+      # this is 3600 MHz + 43 PRBs@30kHz SCS (same as initial BWP)
+      absoluteFrequencySSB                                             = 641280;
+      dl_frequencyBand                                                 = 78;
+      # this is 3600 MHz
+      dl_absoluteFrequencyPointA                                       = 640008;
+      #scs-SpecificCarrierList
+        dl_offstToCarrier                                              = 0;
+# subcarrierSpacing
+# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120
+        dl_subcarrierSpacing                                           = 1;
+        dl_carrierBandwidth                                            = 106;
+     #initialDownlinkBWP
+      #genericParameters
+        # this is RBstart=27,L=48 (275*(L-1))+RBstart
+        initialDLBWPlocationAndBandwidth                               = 12952; # 6366 12925 12956 28875 12952
+# subcarrierSpacing
+# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120
+        initialDLBWPsubcarrierSpacing                                   = 1;
+      #pdcch-ConfigCommon
+        initialDLBWPcontrolResourceSetZero                              = 12;
+        initialDLBWPsearchSpaceZero                                     = 0;
+      #pdsch-ConfigCommon
+        #pdschTimeDomainAllocationList (up to 16 entries)
+        initialDLBWPk0_0                    = 0;  #for DL slot
+        initialDLBWPmappingType_0           = 0;  #0=typeA,1=typeB
+        initialDLBWPstartSymbolAndLength_0  = 40; #this is SS=1,L=13
+
+        initialDLBWPk0_1                    = 0;  #for mixed slot
+        initialDLBWPmappingType_1           = 0;
+        initialDLBWPstartSymbolAndLength_1  = 57; #this is SS=1,L=5
+
+  #uplinkConfigCommon
+     #frequencyInfoUL
+      ul_frequencyBand                                              = 78;
+      #scs-SpecificCarrierList
+      ul_offstToCarrier                                             = 0;
+# subcarrierSpacing
+# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120
+      ul_subcarrierSpacing                                          = 1;
+      ul_carrierBandwidth                                           = 106;
+      pMax                                                          = 20;
+     #initialUplinkBWP
+      #genericParameters
+        initialULBWPlocationAndBandwidth                            = 12952;
+# subcarrierSpacing
+# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120
+        initialULBWPsubcarrierSpacing                               = 1;
+      #rach-ConfigCommon
+        #rach-ConfigGeneric
+          prach_ConfigurationIndex                                  = 98;
+#prach_msg1_FDM
+#0 = one, 1=two, 2=four, 3=eight
+          prach_msg1_FDM                                            = 0;
+          prach_msg1_FrequencyStart                                 = 0;
+          zeroCorrelationZoneConfig                                 = 13;
+          preambleReceivedTargetPower                               = -96;
+#preamblTransMax (0...10) = (3,4,5,6,7,8,10,20,50,100,200)
+          preambleTransMax                                          = 6;
+#powerRampingStep
+# 0=dB0,1=dB2,2=dB4,3=dB6
+        powerRampingStep                                            = 1;
+#ra_ReponseWindow
+#1,2,4,8,10,20,40,80
+        ra_ResponseWindow                                           = 4;
+#ssb_perRACH_OccasionAndCB_PreamblesPerSSB_PR
+#1=oneeighth,2=onefourth,3=half,4=one,5=two,6=four,7=eight,8=sixteen
+        ssb_perRACH_OccasionAndCB_PreamblesPerSSB_PR                = 4;
+#oneHalf (0..15) 4,8,12,16,...60,64
+        ssb_perRACH_OccasionAndCB_PreamblesPerSSB                   = 14;
+#ra_ContentionResolutionTimer
+#(0..7) 8,16,24,32,40,48,56,64
+        ra_ContentionResolutionTimer                                = 7;
+        rsrp_ThresholdSSB                                           = 19;
+#prach-RootSequenceIndex_PR
+#1 = 839, 2 = 139
+        prach_RootSequenceIndex_PR                                  = 2;
+        prach_RootSequenceIndex                                     = 1;
+        # SCS for msg1, can only be 15 for 30 kHz < 6 GHz, takes precendence over the one derived from prach-ConfigIndex
+        #
+        msg1_SubcarrierSpacing                                      = 1,
+# restrictedSetConfig
+# 0=unrestricted, 1=restricted type A, 2=restricted type B
+        restrictedSetConfig                                         = 0,
+
+      # pusch-ConfigCommon (up to 16 elements)
+        initialULBWPk2_0                      = 6;  # used for UL slot
+        initialULBWPmappingType_0             = 1
+        initialULBWPstartSymbolAndLength_0    = 41; # this is SS=0 L=13
+
+        initialULBWPk2_1                      = 6;  # used for mixed slot
+        initialULBWPmappingType_1             = 1;
+        initialULBWPstartSymbolAndLength_1    = 52; # this is SS=10 L=4
+
+        initialULBWPk2_2                      = 7;  # used for Msg.3 during RA
+        initialULBWPmappingType_2             = 1;
+        initialULBWPstartSymbolAndLength_2    = 52; # this is SS=10 L=4
+
+        msg3_DeltaPreamble                                          = 1;
+        p0_NominalWithGrant                                         =-90;
+
+# pucch-ConfigCommon setup :
+# pucchGroupHopping
+# 0 = neither, 1= group hopping, 2=sequence hopping
+        pucchGroupHopping                                           = 0;
+        hoppingId                                                   = 40;
+        p0_nominal                                                  = -90;
+# ssb_PositionsInBurs_BitmapPR
+# 1=short, 2=medium, 3=long
+      ssb_PositionsInBurst_PR                                       = 2;
+      ssb_PositionsInBurst_Bitmap                                   = 1;
+
+# ssb_periodicityServingCell
+# 0 = ms5, 1=ms10, 2=ms20, 3=ms40, 4=ms80, 5=ms160, 6=spare2, 7=spare1
+      ssb_periodicityServingCell                                    = 2;
+
+# dmrs_TypeA_position
+# 0 = pos2, 1 = pos3
+      dmrs_TypeA_Position                                           = 0;
+
+# subcarrierSpacing
+# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120
+      subcarrierSpacing                                             = 1;
+
+
+  #tdd-UL-DL-ConfigurationCommon
+# subcarrierSpacing
+# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120
+      referenceSubcarrierSpacing                                    = 1;
+      # pattern1
+      # dl_UL_TransmissionPeriodicity
+      # 0=ms0p5, 1=ms0p625, 2=ms1, 3=ms1p25, 4=ms2, 5=ms2p5, 6=ms5, 7=ms10
+      dl_UL_TransmissionPeriodicity                                 = 6;
+      nrofDownlinkSlots                                             = 7;
+      nrofDownlinkSymbols                                           = 6;
+      nrofUplinkSlots                                               = 2;
+      nrofUplinkSymbols                                             = 4;
+
+      ssPBCH_BlockPower                                             = -25;
+  }
+
+  );
+
+
+    # ------- SCTP definitions
+    SCTP :
+    {
+        # Number of streams to use in input/output
+        SCTP_INSTREAMS  = 2;
+        SCTP_OUTSTREAMS = 2;
+    };
+
+
+    ////////// AMF parameters:
+    amf_ip_address      = ( { ipv4       = "192.168.70.132";
+                              ipv6       = "192:168:30::17";
+                              active     = "yes";
+                              preference = "ipv4";
+                            }
+                          );
+
+
+    NETWORK_INTERFACES :
+    {
+        GNB_INTERFACE_NAME_FOR_NG_AMF            = "ctrl0";
+        GNB_IPV4_ADDRESS_FOR_NG_AMF              = "172.16.0.1";
+        GNB_INTERFACE_NAME_FOR_NGU               = "ctrl0";
+        GNB_IPV4_ADDRESS_FOR_NGU                 = "172.16.0.1";
+        GNB_PORT_FOR_NGU                         = 2152; # Spec 2152
+    };
+
+  }
+);
+
+MACRLCs = (
+        {
+        num_cc = 1;
+        local_s_if_name  = "lo:";
+        remote_s_address = "127.0.0.1"; // pnf addr [!]
+        local_s_address  = "127.0.0.2"; // vnf addr
+        local_s_portc    = 50601; // vnf p5 port
+        remote_s_portc   = 50600; // pnf p5 port [!]
+        local_s_portd    = 50611; // vnf p7 port [!]
+        remote_s_portd   = 50610; // pnf p7 port [!]
+        tr_s_preference = "nfapi";
+        tr_n_preference = "local_RRC";
+        }
+);
+
+L1s = (
+      {
+      num_cc = 1;
+      tr_n_preference = "local_mac";
+      pusch_proc_threads = 8;
+      prach_dtx_threshold = 120;
+      pucch0_dtx_threshold = 150;
+      }
+);
+
+RUs = (
+    {
+       local_rf       = "yes"
+         nb_tx          = 1
+         nb_rx          = 1
+         att_tx         = 0
+         att_rx         = 0;
+         bands          = [78];
+         max_pdschReferenceSignalPower = -27;
+         max_rxgain                    = 75;
+         eNB_instances  = [0];
+         #beamforming 1x4 matrix:
+         bf_weights = [0x00007fff, 0x0000, 0x0000, 0x0000];
+         #clock_src = "external";
+         sdr_addrs = "mgmt_addr=192.168.18.240,addr=192.168.10.2,second_addr=192.168.20.2,clock_source=internal,time_source=internal"
+    }
+);
+
+THREAD_STRUCT = (
+  {
+    #three config for level of parallelism "PARALLEL_SINGLE_THREAD", "PARALLEL_RU_L1_SPLIT", or "PARALLEL_RU_L1_TRX_SPLIT"
+    parallel_config    = "PARALLEL_SINGLE_THREAD";
+    #two option for worker "WORKER_DISABLE" or "WORKER_ENABLE"
+    worker_config      = "WORKER_ENABLE";
+  }
+);
+
+rfsimulator :
+{
+    serveraddr = "server";
+    serverport = "4043";
+    options = (); #("saviq"); or/and "chanmod"
+    modelname = "AWGN";
+    IQfile = "/tmp/rfsimulator.iqs";
+};
+
+security = {
+  # preferred ciphering algorithms
+  # the first one of the list that an UE supports in chosen
+  # valid values: nea0, nea1, nea2, nea3
+  ciphering_algorithms = ( "nea0" );
+
+  # preferred integrity algorithms
+  # the first one of the list that an UE supports in chosen
+  # valid values: nia0, nia1, nia2, nia3
+  integrity_algorithms = ( "nia2", "nia0" );
+
+  # setting 'drb_ciphering' to "no" disables ciphering for DRBs, no matter
+  # what 'ciphering_algorithms' configures; same thing for 'drb_integrity'
+  drb_ciphering = "yes";
+  drb_integrity = "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";
+       ngap_log_level                         ="debug";
+       ngap_log_verbosity                     ="medium";
+    };
+
diff --git a/ci-scripts/conf_files/episci/episci_nr-ue.nfapi.conf b/ci-scripts/conf_files/episci/episci_nr-ue.nfapi.conf
new file mode 100644
index 0000000000000000000000000000000000000000..f5563ecc026c9e162bebc99afc3232f8080c44b1
--- /dev/null
+++ b/ci-scripts/conf_files/episci/episci_nr-ue.nfapi.conf
@@ -0,0 +1,52 @@
+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";
+};
+
+uicc0 = {
+imsi = "208950000000031";
+key = "0c0a34601d4f07677303652c0462535b";
+opc= "63bfa50ee6523365ff14c1f45f88737d";
+dnn= "oai";
+nssai_sst=222;
+nssai_sd=123;
+}
+
+L1s = (
+        {
+	num_cc = 1;
+	tr_n_preference = "nfapi";
+	local_n_if_name  = "ens3";
+	remote_n_address = "127.0.0.1"; //Proxy IP
+	local_n_address  = "127.0.0.1";
+	local_n_portc    = 50600;
+	remote_n_portc   = 50601;
+	local_n_portd    = 50610;
+	remote_n_portd   = 50611;
+        }  
+);
+
+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/conf_files/episci/episci_nr-ue0.nfapi.conf b/ci-scripts/conf_files/episci/episci_nr-ue0.nfapi.conf
new file mode 100644
index 0000000000000000000000000000000000000000..f5563ecc026c9e162bebc99afc3232f8080c44b1
--- /dev/null
+++ b/ci-scripts/conf_files/episci/episci_nr-ue0.nfapi.conf
@@ -0,0 +1,52 @@
+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";
+};
+
+uicc0 = {
+imsi = "208950000000031";
+key = "0c0a34601d4f07677303652c0462535b";
+opc= "63bfa50ee6523365ff14c1f45f88737d";
+dnn= "oai";
+nssai_sst=222;
+nssai_sd=123;
+}
+
+L1s = (
+        {
+	num_cc = 1;
+	tr_n_preference = "nfapi";
+	local_n_if_name  = "ens3";
+	remote_n_address = "127.0.0.1"; //Proxy IP
+	local_n_address  = "127.0.0.1";
+	local_n_portc    = 50600;
+	remote_n_portc   = 50601;
+	local_n_portd    = 50610;
+	remote_n_portd   = 50611;
+        }  
+);
+
+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/conf_files/episci/episci_nr-ue1.nfapi.conf b/ci-scripts/conf_files/episci/episci_nr-ue1.nfapi.conf
new file mode 100644
index 0000000000000000000000000000000000000000..5df3ccf6cc15686af1b3cca34543468a0fb59d56
--- /dev/null
+++ b/ci-scripts/conf_files/episci/episci_nr-ue1.nfapi.conf
@@ -0,0 +1,52 @@
+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";
+};
+
+uicc0 = {
+imsi = "208950000000032";
+key = "0c0a34601d4f07677303652c0462535b";
+opc= "63bfa50ee6523365ff14c1f45f88737d";
+dnn= "oai";
+nssai_sst=222;
+nssai_sd=123;
+}
+
+L1s = (
+        {
+	num_cc = 1;
+	tr_n_preference = "nfapi";
+	local_n_if_name  = "ens3";
+	remote_n_address = "127.0.0.1"; //Proxy IP
+	local_n_address  = "127.0.0.1";
+	local_n_portc    = 50600;
+	remote_n_portc   = 50601;
+	local_n_portd    = 50610;
+	remote_n_portd   = 50611;
+        }  
+);
+
+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/conf_files/episci/episci_nr-ue2.nfapi.conf b/ci-scripts/conf_files/episci/episci_nr-ue2.nfapi.conf
new file mode 100644
index 0000000000000000000000000000000000000000..b1ce5fee8d0ee856ce483658eba66f37149ea46c
--- /dev/null
+++ b/ci-scripts/conf_files/episci/episci_nr-ue2.nfapi.conf
@@ -0,0 +1,52 @@
+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";
+};
+
+uicc0 = {
+imsi = "208950000000033";
+key = "0c0a34601d4f07677303652c0462535b";
+opc= "63bfa50ee6523365ff14c1f45f88737d";
+dnn= "oai";
+nssai_sst=222;
+nssai_sd=123;
+}
+
+L1s = (
+        {
+	num_cc = 1;
+	tr_n_preference = "nfapi";
+	local_n_if_name  = "ens3";
+	remote_n_address = "127.0.0.1"; //Proxy IP
+	local_n_address  = "127.0.0.1";
+	local_n_portc    = 50600;
+	remote_n_portc   = 50601;
+	local_n_portd    = 50610;
+	remote_n_portd   = 50611;
+        }  
+);
+
+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/conf_files/episci/episci_nr-ue3.nfapi.conf b/ci-scripts/conf_files/episci/episci_nr-ue3.nfapi.conf
new file mode 100644
index 0000000000000000000000000000000000000000..aea5104f1c6f42356495e15b7910bc0dd659da74
--- /dev/null
+++ b/ci-scripts/conf_files/episci/episci_nr-ue3.nfapi.conf
@@ -0,0 +1,52 @@
+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";
+};
+
+uicc0 = {
+imsi = "208950000000034";
+key = "0c0a34601d4f07677303652c0462535b";
+opc= "63bfa50ee6523365ff14c1f45f88737d";
+dnn= "oai";
+nssai_sst=222;
+nssai_sd=123;
+}
+
+L1s = (
+        {
+	num_cc = 1;
+	tr_n_preference = "nfapi";
+	local_n_if_name  = "ens3";
+	remote_n_address = "127.0.0.1"; //Proxy IP
+	local_n_address  = "127.0.0.1";
+	local_n_portc    = 50600;
+	remote_n_portc   = 50601;
+	local_n_portd    = 50610;
+	remote_n_portd   = 50611;
+        }  
+);
+
+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/conf_files/episci/episci_rcc.band7.tm1.nfapi.conf b/ci-scripts/conf_files/episci/episci_rcc.band7.tm1.nfapi.conf
new file mode 100644
index 0000000000000000000000000000000000000000..4e596f81b59b1e72fca2ba3786ccf39479985ac7
--- /dev/null
+++ b/ci-scripts/conf_files/episci/episci_rcc.band7.tm1.nfapi.conf
@@ -0,0 +1,247 @@
+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 = 5;
+
+    plmn_list = ( { mcc = 320; mnc = 230; mnc_length = 3; } );
+
+    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       = "192.168.61.195";
+                              ipv6       = "192:168:30::17";
+                              port       = 36412 ;
+                              active     = "yes";
+                              preference = "ipv4";
+                            }
+                          );
+
+    enable_measurement_reports = "yes";
+
+    ///X2
+    enable_x2 = "yes";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+    t_dc_prep         = 1000;      /* unit: millisecond */
+    t_dc_overall      = 2000;      /* unit: millisecond */
+
+    NETWORK_INTERFACES :
+    {
+        ENB_INTERFACE_NAME_FOR_S1_MME            = "ctrl0";
+        ENB_IPV4_ADDRESS_FOR_S1_MME              = "172.16.0.1";
+        ENB_INTERFACE_NAME_FOR_S1U               = "ctrl0";
+        ENB_IPV4_ADDRESS_FOR_S1U                 = "172.16.0.1";
+        ENB_PORT_FOR_S1U                         = 2152; # Spec 2152
+        ENB_IPV4_ADDRESS_FOR_X2C                 = "172.16.0.1";
+        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.1";
+	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";
+	scheduler_mode = "fairRR";
+        }  
+);
+
+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_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/episci/episci_rcc.band78.tm1.106PRB.nfapi.conf b/ci-scripts/conf_files/episci/episci_rcc.band78.tm1.106PRB.nfapi.conf
new file mode 100644
index 0000000000000000000000000000000000000000..b64b88ddeabbac5332093567592ef8018520950b
--- /dev/null
+++ b/ci-scripts/conf_files/episci/episci_rcc.band78.tm1.106PRB.nfapi.conf
@@ -0,0 +1,265 @@
+Active_gNBs = ( "gNB-Eurecom-5GNRBox");
+# Asn1_verbosity, choice in: none, info, annoying
+Asn1_verbosity = "none";
+
+gNBs =
+(
+ {
+ ////////// Identification parameters:
+    gNB_ID    =  0xe00;
+
+    cell_type =  "CELL_MACRO_GNB";
+
+    gNB_name  =  "gNB-Eurecom-5GNRBox";
+
+    // Tracking area code, 0x0000 and 0xfffe are reserved values
+    tracking_area_code  =  5;
+
+    plmn_list = ({mcc = 320; mnc = 230; mnc_length = 3;});
+
+    tr_s_preference     = "local_mac"
+
+    ////////// Physical parameters:
+
+    ssb_SubcarrierOffset                                      = 31; //0;
+    pdsch_AntennaPorts                                        = 1;
+    pusch_AntennaPorts                                        = 1;
+ 
+    servingCellConfigCommon = (
+    {
+ #spCellConfigCommon
+
+      physCellId                                                    = 0;
+
+#  downlinkConfigCommon
+    #frequencyInfoDL
+      # this is 3600 MHz + 84 PRBs@30kHz SCS (same as initial BWP)
+      absoluteFrequencySSB                                          = 641272; //641032;      #641968; 641968=start of ssb at 3600MHz + 82 RBs    641032=center of SSB at center of cell
+      dl_frequencyBand                                                 = 78;
+      # this is 3600 MHz
+      dl_absoluteFrequencyPointA                                       = 640000;
+      #scs-SpecificCarrierList
+        dl_offstToCarrier                                              = 0;
+# subcarrierSpacing
+# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120  
+        dl_subcarrierSpacing                                           = 1;
+        dl_carrierBandwidth                                            = 106;
+     #initialDownlinkBWP
+      #genericParameters
+        # this is RBstart=84,L=13 (275*(L-1))+RBstart
+        initialDLBWPlocationAndBandwidth                                        = 6368;
+# subcarrierSpacing
+# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120  
+        initialDLBWPsubcarrierSpacing                                           = 1;
+      #pdcch-ConfigCommon
+        initialDLBWPcontrolResourceSetZero                                      = 0;
+        initialDLBWPsearchSpaceZero                                             = 0;
+      #pdsch-ConfigCommon
+        #pdschTimeDomainAllocationList (up to 16 entries)
+        initialDLBWPk0_0                    = 0;  #for DL slot
+        initialDLBWPmappingType_0           = 0;  #0=typeA,1=typeB
+        initialDLBWPstartSymbolAndLength_0  = 40; #this is SS=1,L=13
+
+        initialDLBWPk0_1                    = 0;  #for mixed slot
+        initialDLBWPmappingType_1           = 0;
+        initialDLBWPstartSymbolAndLength_1  = 57; #this is SS=1,L=5
+
+  #uplinkConfigCommon 
+     #frequencyInfoUL
+      ul_frequencyBand                                                 = 78;
+      #scs-SpecificCarrierList
+      ul_offstToCarrier                                              = 0;
+# subcarrierSpacing
+# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120  
+      ul_subcarrierSpacing                                           = 1;
+      ul_carrierBandwidth                                            = 106;
+      pMax                                                          = 20;
+     #initialUplinkBWP
+      #genericParameters
+        initialULBWPlocationAndBandwidth                                        = 6368;
+# subcarrierSpacing
+# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120  
+        initialULBWPsubcarrierSpacing                                           = 1;
+      #rach-ConfigCommon
+        #rach-ConfigGeneric
+          prach_ConfigurationIndex                                  = 98;
+#prach_msg1_FDM
+#0 = one, 1=two, 2=four, 3=eight
+          prach_msg1_FDM                                            = 0;
+          prach_msg1_FrequencyStart                                 = 0;
+          zeroCorrelationZoneConfig                                 = 13;
+          preambleReceivedTargetPower                               = -100;
+#preamblTransMax (0...10) = (3,4,5,6,7,8,10,20,50,100,200)
+          preambleTransMax                                          = 6;
+#powerRampingStep
+# 0=dB0,1=dB2,2=dB4,3=dB6
+        powerRampingStep                                            = 1;
+#ra_ReponseWindow
+#1,2,4,8,10,20,40,80
+        ra_ResponseWindow                                           = 5;
+#ssb_perRACH_OccasionAndCB_PreamblesPerSSB_PR
+#1=oneeighth,2=onefourth,3=half,4=one,5=two,6=four,7=eight,8=sixteen
+        ssb_perRACH_OccasionAndCB_PreamblesPerSSB_PR                = 4;
+#oneHalf (0..15) 4,8,12,16,...60,64
+        ssb_perRACH_OccasionAndCB_PreamblesPerSSB                   = 14; //15;
+#ra_ContentionResolutionTimer
+#(0..7) 8,16,24,32,40,48,56,64
+        ra_ContentionResolutionTimer                                = 7;
+        rsrp_ThresholdSSB                                           = 19;
+#prach-RootSequenceIndex_PR
+#1 = 839, 2 = 139
+        prach_RootSequenceIndex_PR                                  = 2;
+        prach_RootSequenceIndex                                     = 1;
+        # SCS for msg1, can only be 15 for 30 kHz < 6 GHz, takes precendence over the one derived from prach-ConfigIndex
+        #  
+        msg1_SubcarrierSpacing                                      = 1,
+
+# restrictedSetConfig
+# 0=unrestricted, 1=restricted type A, 2=restricted type B
+        restrictedSetConfig                                         = 0,
+      # pusch-ConfigCommon (up to 16 elements)
+        initialULBWPk2_0                      = 6;  # used for UL slot
+        initialULBWPmappingType_0             = 1
+        initialULBWPstartSymbolAndLength_0    = 41; # this is SS=0 L=13
+
+        initialULBWPk2_1                      = 6;  # used for mixed slot
+        initialULBWPmappingType_1             = 1;
+        initialULBWPstartSymbolAndLength_1    = 52; # this is SS=10 L=4
+
+        initialULBWPk2_2                      = 7;  # used for Msg.3 during RA
+        initialULBWPmappingType_2             = 1;
+        initialULBWPstartSymbolAndLength_2    = 52; # this is SS=10 L=4
+
+        msg3_DeltaPreamble                                          = 1;
+        p0_NominalWithGrant                                         =-90;
+
+# pucch-ConfigCommon setup :
+# pucchGroupHopping
+# 0 = neither, 1= group hopping, 2=sequence hopping
+        pucchGroupHopping                                           = 0;
+        hoppingId                                                   = 40;
+        p0_nominal                                                  = -90;
+# ssb_PositionsInBurs_BitmapPR
+# 1=short, 2=medium, 3=long
+      ssb_PositionsInBurst_PR                                       = 2;
+      ssb_PositionsInBurst_Bitmap                                   = 1; #0x80;
+
+# ssb_periodicityServingCell
+# 0 = ms5, 1=ms10, 2=ms20, 3=ms40, 4=ms80, 5=ms160, 6=spare2, 7=spare1 
+      ssb_periodicityServingCell                                    = 2;
+
+# dmrs_TypeA_position
+# 0 = pos2, 1 = pos3
+      dmrs_TypeA_Position                                           = 0;
+
+# subcarrierSpacing
+# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120  
+      subcarrierSpacing                                             = 1;
+
+
+  #tdd-UL-DL-ConfigurationCommon
+# subcarrierSpacing
+# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120  
+      referenceSubcarrierSpacing                                    = 1;
+      # pattern1 
+      # dl_UL_TransmissionPeriodicity
+      # 0=ms0p5, 1=ms0p625, 2=ms1, 3=ms1p25, 4=ms2, 5=ms2p5, 6=ms5, 7=ms10
+      dl_UL_TransmissionPeriodicity                                 = 6;
+      nrofDownlinkSlots                                             = 7; //8; //7;
+      nrofDownlinkSymbols                                           = 6; //0; //6;
+      nrofUplinkSlots                                               = 2;
+      nrofUplinkSymbols                                             = 4; //0; //4;
+
+  ssPBCH_BlockPower                                             = -25;
+  }
+
+  );
+
+    # ------- 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.61.195";
+                              ipv6       = "192:168:30::17";
+                              active     = "yes";
+                              preference = "ipv4";
+                            }
+                          );
+    ///X2
+    enable_x2 = "yes";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+    t_dc_prep         = 1000;      /* unit: millisecond */
+    t_dc_overall      = 2000;      /* unit: millisecond */
+    target_enb_x2_ip_address      = (
+                                     { ipv4       = "172.16.0.1"; # rrc.band7.tm1.nfapi.conf:line 201
+                                       ipv6       = "192:168:30::17";
+                                       preference = "ipv4";
+                                     }
+                                    );
+
+    NETWORK_INTERFACES :
+    {   # All of these have to be IP addr of gNB
+                # if in CORE container, make it 172.16.0.X
+                # if not launched in CORE, can set to lo (127.0.0.2)
+        GNB_INTERFACE_NAME_FOR_S1_MME            = "ctrl0";
+        GNB_IPV4_ADDRESS_FOR_S1_MME              = "172.16.0.2";
+        GNB_INTERFACE_NAME_FOR_S1U               = "ctrl0";
+        GNB_IPV4_ADDRESS_FOR_S1U                 = "172.16.0.2";
+        GNB_PORT_FOR_S1U                         = 2152; # Spec 2152
+        GNB_IPV4_ADDRESS_FOR_X2C                 = "172.16.0.2";
+        GNB_PORT_FOR_X2C                         = 36422; # Spec 36422
+    };
+  }
+);
+
+
+MACRLCs = (
+        {
+        num_cc = 1;
+        local_s_if_name  = "lo:";
+        remote_s_address = "127.0.0.1"; // pnf addr [!]
+        local_s_address  = "127.0.0.2"; // vnf addr
+        local_s_portc    = 50601; // vnf p5 port
+        remote_s_portc   = 50600; // pnf p5 port [!]
+        local_s_portd    = 50611; // vnf p7 port [!]
+        remote_s_portd   = 50610; // pnf p7 port [!]
+        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/episci/episci_ue.nfapi.conf b/ci-scripts/conf_files/episci/episci_ue.nfapi.conf
new file mode 100644
index 0000000000000000000000000000000000000000..0170a466552424119c05fa5ae8c6c40cdb45a471
--- /dev/null
+++ b/ci-scripts/conf_files/episci/episci_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  = "ens3";
+	remote_n_address = "127.0.0.1"; //Proxy IP
+	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/conf_files/episci/episci_ue_test_sfr.conf b/ci-scripts/conf_files/episci/episci_ue_test_sfr.conf
new file mode 100644
index 0000000000000000000000000000000000000000..e98e1b92f1fdd19cb427ee46db6dddc584d917d5
--- /dev/null
+++ b/ci-scripts/conf_files/episci/episci_ue_test_sfr.conf
@@ -0,0 +1,786 @@
+# List of known PLMNS
+PLMN: {
+    PLMN0: {
+           FULLNAME="Test network";
+           SHORTNAME="OAI4G";
+           MNC="01";
+           MCC="001";
+
+    };
+    PLMN1: {
+           FULLNAME="SFR France";
+           SHORTNAME="SFR";
+           MNC="10";
+           MCC="208";
+
+    };
+    PLMN2: {
+           FULLNAME="SFR France";
+           SHORTNAME="SFR";
+           MNC="11";
+           MCC="208";
+    };
+    PLMN3: {
+           FULLNAME="SFR France";
+           SHORTNAME="SFR";
+           MNC="13";
+           MCC="208";
+    };
+    PLMN4: {
+           FULLNAME="OAI LTEBOX";
+           SHORTNAME="OAIALU";
+           MNC="95";
+           MCC="208";
+    };
+    PLMN5: {
+           FULLNAME="T-Mobile USA";
+           SHORTNAME="T-Mobile";
+           MNC="280";
+           MCC="310";
+    };
+    PLMN6: {
+           FULLNAME="FICTITIOUS USA";
+           SHORTNAME="FICTITIO";
+           MNC="028";
+           MCC="310";
+    };
+    PLMN7: {
+           FULLNAME="Vodafone Italia";
+           SHORTNAME="VODAFONE";
+           MNC="10";
+           MCC="222";
+    };
+    PLMN8: {
+           FULLNAME="Vodafone Spain";
+           SHORTNAME="VODAFONE";
+           MNC="01";
+           MCC="214";
+    };
+    PLMN9: {
+           FULLNAME="Vodafone Spain";
+           SHORTNAME="VODAFONE";
+           MNC="06";
+           MCC="214";
+    };
+    PLMN10: {
+           FULLNAME="Vodafone Germ";
+           SHORTNAME="VODAFONE";
+           MNC="02";
+           MCC="262";
+    };
+    PLMN11: {
+           FULLNAME="Vodafone Germ";
+           SHORTNAME="VODAFONE";
+           MNC="04";
+           MCC="262";
+    };
+    PLMN12: {
+           FULLNAME="Vodafone Germ";
+           SHORTNAME="VODAFONE";
+           MNC="230";
+           MCC="320";
+    };
+};
+
+UE0:
+{
+    USER: {
+        IMEI="356113022094148";
+        MANUFACTURER="EURECOM";
+        MODEL="LTE Android PC";
+        PIN="0000";
+    };
+
+    SIM: {
+        MSIN="100000025";
+        USIM_API_K="0c0a34601d4f07677303652c0462535b";
+        OPC="ba05688178e398bedc100674071002cb";
+        MSISDN="1011234561024";
+    };
+
+    # Home PLMN Selector with Access Technology
+    HPLMN= "320230";
+
+    # User controlled PLMN Selector with Access Technology
+    UCPLMN_LIST = ();
+
+    # Operator PLMN List
+    OPLMN_LIST = ("00101", "20810", "20811", "20813", "20895", "310280", "310028", "320230");
+
+    # Operator controlled PLMN Selector with Access Technology
+    OCPLMN_LIST = ("22210", "21401", "21406", "26202", "26204");
+
+    # Forbidden plmns
+    FPLMN_LIST = ();
+
+    # List of Equivalent HPLMNs
+#TODO: UE does not connect if set, to be fixed in the UE
+#    EHPLMN_LIST= ("20811", "20813");
+    EHPLMN_LIST= ();
+};
+
+UE1:
+{
+    USER: {
+        IMEI="356113022094149";
+        MANUFACTURER="EURECOM";
+        MODEL="LTE Android PC";
+        PIN="0000";
+    };
+
+    SIM: {
+        MSIN="100000166";
+        USIM_API_K="0c0a34601d4f07677303652c0462535b";
+        OPC="ba05688178e398bedc100674071002cb";
+        MSISDN="1011234561165";
+    };
+
+    # Home PLMN Selector with Access Technology
+    HPLMN= "320230";
+
+    # User controlled PLMN Selector with Access Technology
+    UCPLMN_LIST = ();
+
+    # Operator PLMN List
+    OPLMN_LIST = ("00101", "20810", "20811", "20813", "20895", "310280", "310028", "320230");
+
+    # Operator controlled PLMN Selector with Access Technology
+    OCPLMN_LIST = ("22210", "21401", "21406", "26202", "26204");
+
+    # Forbidden plmns
+    FPLMN_LIST = ();
+
+    # List of Equivalent HPLMNs
+#TODO: UE does not connect if set, to be fixed in the UE
+#    EHPLMN_LIST= ("20811", "20813");
+    EHPLMN_LIST= ();
+};
+
+UE2:
+{
+    USER: {
+        IMEI="356113022094150";
+        MANUFACTURER="EURECOM";
+        MODEL="LTE Android PC";
+        PIN="0000";
+    };
+
+    SIM: {
+        MSIN="100000012";
+        USIM_API_K="0c0a34601d4f07677303652c0462535b";
+        OPC="ba05688178e398bedc100674071002cb";
+        MSISDN="1011234561011";
+    };
+
+    # Home PLMN Selector with Access Technology
+    HPLMN= "320230";
+
+    # User controlled PLMN Selector with Access Technology
+    UCPLMN_LIST = ();
+
+    # Operator PLMN List
+    OPLMN_LIST = ("00101", "20810", "20811", "20813", "20895", "310280", "310028", "320230");
+
+    # Operator controlled PLMN Selector with Access Technology
+    OCPLMN_LIST = ("22210", "21401", "21406", "26202", "26204");
+
+    # Forbidden plmns
+    FPLMN_LIST = ();
+
+    # List of Equivalent HPLMNs
+#TODO: UE does not connect if set, to be fixed in the UE
+#    EHPLMN_LIST= ("20811", "20813");
+    EHPLMN_LIST= ();
+};
+
+UE3:
+{
+    USER: {
+        IMEI="356113022094151";
+        MANUFACTURER="EURECOM";
+        MODEL="LTE Android PC";
+        PIN="0000";
+    };
+
+    SIM: {
+        MSIN="100000064";
+        USIM_API_K="0c0a34601d4f07677303652c0462535b";
+        OPC="ba05688178e398bedc100674071002cb";
+        MSISDN="1011234561063";
+    };
+
+    # Home PLMN Selector with Access Technology
+    HPLMN= "320230";
+
+    # User controlled PLMN Selector with Access Technology
+    UCPLMN_LIST = ();
+
+    # Operator PLMN List
+    OPLMN_LIST = ("00101", "20810", "20811", "20813", "20895", "310280", "310028", "320230");
+
+    # Operator controlled PLMN Selector with Access Technology
+    OCPLMN_LIST = ("22210", "21401", "21406", "26202", "26204");
+
+    # Forbidden plmns
+    FPLMN_LIST = ();
+
+    # List of Equivalent HPLMNs
+#TODO: UE does not connect if set, to be fixed in the UE
+#    EHPLMN_LIST= ("20811", "20813");
+    EHPLMN_LIST= ();
+};
+
+UE4:
+{
+    USER: {
+        IMEI="356113022094152";
+        MANUFACTURER="EURECOM";
+        MODEL="LTE Android PC";
+        PIN="0000";
+    };
+
+    SIM: {
+        MSIN="100000082";
+        USIM_API_K="0c0a34601d4f07677303652c0462535b";
+        OPC="ba05688178e398bedc100674071002cb";
+        MSISDN="1011234561081";
+    };
+
+    # Home PLMN Selector with Access Technology
+    HPLMN= "320230";
+
+    # User controlled PLMN Selector with Access Technology
+    UCPLMN_LIST = ();
+
+    # Operator PLMN List
+    OPLMN_LIST = ("00101", "20810", "20811", "20813", "20895", "310280", "310028", "320230");
+
+    # Operator controlled PLMN Selector with Access Technology
+    OCPLMN_LIST = ("22210", "21401", "21406", "26202", "26204");
+
+    # Forbidden plmns
+    FPLMN_LIST = ();
+
+    # List of Equivalent HPLMNs
+#TODO: UE does not connect if set, to be fixed in the UE
+#    EHPLMN_LIST= ("20811", "20813");
+    EHPLMN_LIST= ();
+};
+
+UE5:
+{
+    USER: {
+        IMEI="356113022094153";
+        MANUFACTURER="EURECOM";
+        MODEL="LTE Android PC";
+        PIN="0000";
+    };
+
+    SIM: {
+        MSIN="100000011";
+        USIM_API_K="0c0a34601d4f07677303652c0462535b";
+        OPC="ba05688178e398bedc100674071002cb";
+        MSISDN="1011234561010";
+    };
+
+    # Home PLMN Selector with Access Technology
+    HPLMN= "320230";
+
+    # User controlled PLMN Selector with Access Technology
+    UCPLMN_LIST = ();
+
+    # Operator PLMN List
+    OPLMN_LIST = ("00101", "20810", "20811", "20813", "20895", "310280", "310028", "320230");
+
+    # Operator controlled PLMN Selector with Access Technology
+    OCPLMN_LIST = ("22210", "21401", "21406", "26202", "26204");
+
+    # Forbidden plmns
+    FPLMN_LIST = ();
+
+    # List of Equivalent HPLMNs
+#TODO: UE does not connect if set, to be fixed in the UE
+#    EHPLMN_LIST= ("20811", "20813");
+    EHPLMN_LIST= ();
+};
+
+UE6:
+{
+    USER: {
+        IMEI="356113022094154";
+        MANUFACTURER="EURECOM";
+        MODEL="LTE Android PC";
+        PIN="0000";
+    };
+
+    SIM: {
+        MSIN="100000093";
+        USIM_API_K="0c0a34601d4f07677303652c0462535b";
+        OPC="ba05688178e398bedc100674071002cb";
+        MSISDN="1011234561092";
+    };
+
+    # Home PLMN Selector with Access Technology
+    HPLMN= "320230";
+
+    # User controlled PLMN Selector with Access Technology
+    UCPLMN_LIST = ();
+
+    # Operator PLMN List
+    OPLMN_LIST = ("00101", "20810", "20811", "20813", "20895", "310280", "310028", "320230");
+
+    # Operator controlled PLMN Selector with Access Technology
+    OCPLMN_LIST = ("22210", "21401", "21406", "26202", "26204");
+
+    # Forbidden plmns
+    FPLMN_LIST = ();
+
+    # List of Equivalent HPLMNs
+#TODO: UE does not connect if set, to be fixed in the UE
+#    EHPLMN_LIST= ("20811", "20813");
+    EHPLMN_LIST= ();
+};
+
+UE7:
+{
+    USER: {
+        IMEI="356113022094155";
+        MANUFACTURER="EURECOM";
+        MODEL="LTE Android PC";
+        PIN="0000";
+    };
+
+    SIM: {
+        MSIN="100000188";
+        USIM_API_K="0c0a34601d4f07677303652c0462535b";
+        OPC="ba05688178e398bedc100674071002cb";
+        MSISDN="1011234561187";
+    };
+
+    # Home PLMN Selector with Access Technology
+    HPLMN= "320230";
+
+    # User controlled PLMN Selector with Access Technology
+    UCPLMN_LIST = ();
+
+    # Operator PLMN List
+    OPLMN_LIST = ("00101", "20810", "20811", "20813", "20895", "310280", "310028", "320230");
+
+    # Operator controlled PLMN Selector with Access Technology
+    OCPLMN_LIST = ("22210", "21401", "21406", "26202", "26204");
+
+    # Forbidden plmns
+    FPLMN_LIST = ();
+
+    # List of Equivalent HPLMNs
+#TODO: UE does not connect if set, to be fixed in the UE
+#    EHPLMN_LIST= ("20811", "20813");
+    EHPLMN_LIST= ();
+};
+
+UE8:
+{
+    USER: {
+        IMEI="356113022094158";
+        MANUFACTURER="EURECOM";
+        MODEL="LTE Android PC";
+        PIN="0000";
+    };
+
+    SIM: {
+        MSIN="100000017";
+        USIM_API_K="0c0a34601d4f07677303652c0462535b";
+        OPC="ba05688178e398bedc100674071002cb";
+        MSISDN="1011234561016";
+    };
+
+    # Home PLMN Selector with Access Technology
+    HPLMN= "320230";
+
+    # User controlled PLMN Selector with Access Technology
+    UCPLMN_LIST = ();
+
+    # Operator PLMN List
+    OPLMN_LIST = ("00101", "20810", "20811", "20813", "20895", "310280", "310028", "320230");
+
+    # Operator controlled PLMN Selector with Access Technology
+    OCPLMN_LIST = ("22210", "21401", "21406", "26202", "26204");
+
+    # Forbidden plmns
+    FPLMN_LIST = ();
+
+    # List of Equivalent HPLMNs
+#TODO: UE does not connect if set, to be fixed in the UE
+#    EHPLMN_LIST= ("20811", "20813");
+    EHPLMN_LIST= ();
+};
+
+UE9:
+{
+    USER: {
+        IMEI="356113022094159";
+        MANUFACTURER="EURECOM";
+        MODEL="LTE Android PC";
+        PIN="0000";
+    };
+
+    SIM: {
+        MSIN="100000071";
+        USIM_API_K="0c0a34601d4f07677303652c0462535b";
+        OPC="ba05688178e398bedc100674071002cb";
+        MSISDN="1011234561070";
+    };
+
+    # Home PLMN Selector with Access Technology
+    HPLMN= "320230";
+
+    # User controlled PLMN Selector with Access Technology
+    UCPLMN_LIST = ();
+
+    # Operator PLMN List
+    OPLMN_LIST = ("00101", "20810", "20811", "20813", "20895", "310280", "310028", "320230");
+
+    # Operator controlled PLMN Selector with Access Technology
+    OCPLMN_LIST = ("22210", "21401", "21406", "26202", "26204");
+
+    # Forbidden plmns
+    FPLMN_LIST = ();
+
+    # List of Equivalent HPLMNs
+#TODO: UE does not connect if set, to be fixed in the UE
+#    EHPLMN_LIST= ("20811", "20813");
+    EHPLMN_LIST= ();
+};
+
+UE10:
+{
+    USER: {
+        IMEI="356113022094110";
+        MANUFACTURER="EURECOM";
+        MODEL="LTE Android PC";
+        PIN="0000";
+    };
+
+    SIM: {
+        MSIN="100000125";
+        USIM_API_K="0c0a34601d4f07677303652c0462535b";
+        OPC="ba05688178e398bedc100674071002cb";
+        MSISDN="1011234561124";
+    };
+
+    # Home PLMN Selector with Access Technology
+    HPLMN= "320230";
+
+    # User controlled PLMN Selector with Access Technology
+    UCPLMN_LIST = ();
+
+    # Operator PLMN List
+    OPLMN_LIST = ("00101", "20810", "20811", "20813", "20895", "310280", "310028", "320230");
+
+    # Operator controlled PLMN Selector with Access Technology
+    OCPLMN_LIST = ("22210", "21401", "21406", "26202", "26204");
+
+    # Forbidden plmns
+    FPLMN_LIST = ();
+
+    # List of Equivalent HPLMNs
+#TODO: UE does not connect if set, to be fixed in the UE
+#    EHPLMN_LIST= ("20811", "20813");
+    EHPLMN_LIST= ();
+};
+
+UE11:
+{
+    USER: {
+        IMEI="356113022094111";
+        MANUFACTURER="EURECOM";
+        MODEL="LTE Android PC";
+        PIN="0000";
+    };
+
+    SIM: {
+        MSIN="100000067";
+        USIM_API_K="0c0a34601d4f07677303652c0462535b";
+        OPC="ba05688178e398bedc100674071002cb";
+        MSISDN="1011234561066";
+    };
+
+    # Home PLMN Selector with Access Technology
+    HPLMN= "320230";
+
+    # User controlled PLMN Selector with Access Technology
+    UCPLMN_LIST = ();
+
+    # Operator PLMN List
+    OPLMN_LIST = ("00101", "20810", "20811", "20813", "20895", "310280", "310028", "320230");
+
+    # Operator controlled PLMN Selector with Access Technology
+    OCPLMN_LIST = ("22210", "21401", "21406", "26202", "26204");
+
+    # Forbidden plmns
+    FPLMN_LIST = ();
+
+    # List of Equivalent HPLMNs
+#TODO: UE does not connect if set, to be fixed in the UE
+#    EHPLMN_LIST= ("20811", "20813");
+    EHPLMN_LIST= ();
+};
+
+UE12:
+{
+    USER: {
+        IMEI="356113022094112";
+        MANUFACTURER="EURECOM";
+        MODEL="LTE Android PC";
+        PIN="0000";
+    };
+
+    SIM: {
+        MSIN="100000152";
+        USIM_API_K="0c0a34601d4f07677303652c0462535b";
+        OPC="ba05688178e398bedc100674071002cb";
+        MSISDN="1011234561151";
+    };
+
+    # Home PLMN Selector with Access Technology
+    HPLMN= "320230";
+
+    # User controlled PLMN Selector with Access Technology
+    UCPLMN_LIST = ();
+
+    # Operator PLMN List
+    OPLMN_LIST = ("00101", "20810", "20811", "20813", "20895", "310280", "310028", "320230");
+
+    # Operator controlled PLMN Selector with Access Technology
+    OCPLMN_LIST = ("22210", "21401", "21406", "26202", "26204");
+
+    # Forbidden plmns
+    FPLMN_LIST = ();
+
+    # List of Equivalent HPLMNs
+#TODO: UE does not connect if set, to be fixed in the UE
+#    EHPLMN_LIST= ("20811", "20813");
+    EHPLMN_LIST= ();
+};
+
+UE13:
+{
+    USER: {
+        IMEI="356113022094113";
+        MANUFACTURER="EURECOM";
+        MODEL="LTE Android PC";
+        PIN="0000";
+    };
+
+    SIM: {
+        MSIN="100000083";
+        USIM_API_K="0c0a34601d4f07677303652c0462535b";
+        OPC="ba05688178e398bedc100674071002cb";
+        MSISDN="1011234561082";
+    };
+
+    # Home PLMN Selector with Access Technology
+    HPLMN= "320230";
+
+    # User controlled PLMN Selector with Access Technology
+    UCPLMN_LIST = ();
+
+    # Operator PLMN List
+    OPLMN_LIST = ("00101", "20810", "20811", "20813", "20895", "310280", "310028", "320230");
+
+    # Operator controlled PLMN Selector with Access Technology
+    OCPLMN_LIST = ("22210", "21401", "21406", "26202", "26204");
+
+    # Forbidden plmns
+    FPLMN_LIST = ();
+
+    # List of Equivalent HPLMNs
+#TODO: UE does not connect if set, to be fixed in the UE
+#    EHPLMN_LIST= ("20811", "20813");
+    EHPLMN_LIST= ();
+};
+
+UE14:
+{
+    USER: {
+        IMEI="356113022094114";
+        MANUFACTURER="EURECOM";
+        MODEL="LTE Android PC";
+        PIN="0000";
+    };
+
+    SIM: {
+        MSIN="100000086";
+        USIM_API_K="0c0a34601d4f07677303652c0462535b";
+        OPC="ba05688178e398bedc100674071002cb";
+        MSISDN="1011234561085";
+    };
+
+    # Home PLMN Selector with Access Technology
+    HPLMN= "320230";
+
+    # User controlled PLMN Selector with Access Technology
+    UCPLMN_LIST = ();
+
+    # Operator PLMN List
+    OPLMN_LIST = ("00101", "20810", "20811", "20813", "20895", "310280", "310028", "320230");
+
+    # Operator controlled PLMN Selector with Access Technology
+    OCPLMN_LIST = ("22210", "21401", "21406", "26202", "26204");
+
+    # Forbidden plmns
+    FPLMN_LIST = ();
+
+    # List of Equivalent HPLMNs
+#TODO: UE does not connect if set, to be fixed in the UE
+#    EHPLMN_LIST= ("20811", "20813");
+    EHPLMN_LIST= ();
+};
+
+UE15:
+{
+    USER: {
+        IMEI="356113022094115";
+        MANUFACTURER="EURECOM";
+        MODEL="LTE Android PC";
+        PIN="0000";
+    };
+
+    SIM: {
+        MSIN="100000026";
+        USIM_API_K="0c0a34601d4f07677303652c0462535b";
+        OPC="ba05688178e398bedc100674071002cb";
+        MSISDN="1011234561025";
+    };
+
+    # Home PLMN Selector with Access Technology
+    HPLMN= "320230";
+
+    # User controlled PLMN Selector with Access Technology
+    UCPLMN_LIST = ();
+
+    # Operator PLMN List
+    OPLMN_LIST = ("00101", "20810", "20811", "20813", "20895", "310280", "310028", "320230");
+
+    # Operator controlled PLMN Selector with Access Technology
+    OCPLMN_LIST = ("22210", "21401", "21406", "26202", "26204");
+
+    # Forbidden plmns
+    FPLMN_LIST = ();
+
+    # List of Equivalent HPLMNs
+#TODO: UE does not connect if set, to be fixed in the UE
+#    EHPLMN_LIST= ("20811", "20813");
+    EHPLMN_LIST= ();
+};
+
+UE16:
+{
+    USER: {
+        IMEI="356113022094116";
+        MANUFACTURER="EURECOM";
+        MODEL="LTE Android PC";
+        PIN="0000";
+    };
+
+    SIM: {
+        MSIN="100000114";
+        USIM_API_K="0c0a34601d4f07677303652c0462535b";
+        OPC="ba05688178e398bedc100674071002cb";
+        MSISDN="1011234561113";
+    };
+
+    # Home PLMN Selector with Access Technology
+    HPLMN= "320230";
+
+    # User controlled PLMN Selector with Access Technology
+    UCPLMN_LIST = ();
+
+    # Operator PLMN List
+    OPLMN_LIST = ("00101", "20810", "20811", "20813", "20895", "310280", "310028", "320230");
+
+    # Operator controlled PLMN Selector with Access Technology
+    OCPLMN_LIST = ("22210", "21401", "21406", "26202", "26204");
+
+    # Forbidden plmns
+    FPLMN_LIST = ();
+
+    # List of Equivalent HPLMNs
+#TODO: UE does not connect if set, to be fixed in the UE
+#    EHPLMN_LIST= ("20811", "20813");
+    EHPLMN_LIST= ();
+};
+
+UE17:
+{
+    USER: {
+        IMEI="356113022094117";
+        MANUFACTURER="EURECOM";
+        MODEL="LTE Android PC";
+        PIN="0000";
+    };
+
+    SIM: {
+        MSIN="100000159";
+        USIM_API_K="0c0a34601d4f07677303652c0462535b";
+        OPC="ba05688178e398bedc100674071002cb";
+        MSISDN="1011234561158";
+    };
+
+    # Home PLMN Selector with Access Technology
+    HPLMN= "320230";
+
+    # User controlled PLMN Selector with Access Technology
+    UCPLMN_LIST = ();
+
+    # Operator PLMN List
+    OPLMN_LIST = ("00101", "20810", "20811", "20813", "20895", "310280", "310028", "320230");
+
+    # Operator controlled PLMN Selector with Access Technology
+    OCPLMN_LIST = ("22210", "21401", "21406", "26202", "26204");
+
+    # Forbidden plmns
+    FPLMN_LIST = ();
+
+    # List of Equivalent HPLMNs
+#TODO: UE does not connect if set, to be fixed in the UE
+#    EHPLMN_LIST= ("20811", "20813");
+    EHPLMN_LIST= ();
+};
+
+UE18:
+{
+    USER: {
+        IMEI="356113022094118";
+        MANUFACTURER="EURECOM";
+        MODEL="LTE Android PC";
+        PIN="0000";
+    };
+
+    SIM: {
+        MSIN="100000113";
+        USIM_API_K="0c0a34601d4f07677303652c0462535b";
+        OPC="ba05688178e398bedc100674071002cb";
+        MSISDN="1011234561112";
+    };
+
+    # Home PLMN Selector with Access Technology
+    HPLMN= "320230";
+
+    # User controlled PLMN Selector with Access Technology
+    UCPLMN_LIST = ();
+
+    # Operator PLMN List
+    OPLMN_LIST = ("00101", "20810", "20811", "20813", "20895", "310280", "310028", "320230");
+
+    # Operator controlled PLMN Selector with Access Technology
+    OCPLMN_LIST = ("22210", "21401", "21406", "26202", "26204");
+
+    # Forbidden plmns
+    FPLMN_LIST = ();
+
+    # List of Equivalent HPLMNs
+#TODO: UE does not connect if set, to be fixed in the UE
+#    EHPLMN_LIST= ("20811", "20813");
+    EHPLMN_LIST= ();
+};
\ No newline at end of file
diff --git a/ci-scripts/conf_files/episci/proxy_gnb.band78.sa.fr1.106PRB.usrpn310.conf b/ci-scripts/conf_files/episci/proxy_gnb.band78.sa.fr1.106PRB.usrpn310.conf
new file mode 100644
index 0000000000000000000000000000000000000000..ab0cf5f469b2fb1c5d12476f576eb5504660fda3
--- /dev/null
+++ b/ci-scripts/conf_files/episci/proxy_gnb.band78.sa.fr1.106PRB.usrpn310.conf
@@ -0,0 +1,326 @@
+Active_gNBs = ( "gNB-OAI");
+# Asn1_verbosity, choice in: none, info, annoying
+Asn1_verbosity = "none";
+
+gNBs =
+(
+ {
+    ////////// Identification parameters:
+    gNB_ID    =  0xe00;
+    gNB_name  =  "gNB-OAI";
+
+    // Tracking area code, 0x0000 and 0xfffe are reserved values
+    tracking_area_code  =  1;
+    plmn_list = ({
+                  mcc = 208;
+                  mnc = 99;
+                  mnc_length = 2;
+                  snssaiList = (
+                    {
+                      sst = 1;
+                      sd  = 0x1; // 0 false, else true
+                    },
+                    {
+                      sst = 1;
+                      sd  = 0x112233; // 0 false, else true
+                    }
+                  );
+
+                  });
+
+    nr_cellid = 12345678L;
+
+    ////////// Physical parameters:
+
+    ssb_SubcarrierOffset                                      = 0;
+    pdsch_AntennaPorts                                        = 1;
+    pusch_AntennaPorts                                        = 1;
+    ul_prbblacklist                                           = "51,52,53,54"
+    min_rxtxtime_pdsch = 6;
+
+     pdcch_ConfigSIB1 = (
+      {
+        controlResourceSetZero = 12;
+        searchSpaceZero = 0;
+      }
+      );
+
+    servingCellConfigCommon = (
+    {
+ #spCellConfigCommon
+
+      physCellId                                                    = 0;
+
+#  downlinkConfigCommon
+    #frequencyInfoDL
+      # this is 3600 MHz + 43 PRBs@30kHz SCS (same as initial BWP)
+      absoluteFrequencySSB                                             = 641280;
+      dl_frequencyBand                                                 = 78;
+      # this is 3600 MHz
+      dl_absoluteFrequencyPointA                                       = 640008;
+      #scs-SpecificCarrierList
+        dl_offstToCarrier                                              = 0;
+# subcarrierSpacing
+# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120
+        dl_subcarrierSpacing                                           = 1;
+        dl_carrierBandwidth                                            = 106;
+     #initialDownlinkBWP
+      #genericParameters
+        # this is RBstart=27,L=48 (275*(L-1))+RBstart
+        initialDLBWPlocationAndBandwidth                               = 12952; # 6366 12925 12956 28875 12952
+# subcarrierSpacing
+# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120
+        initialDLBWPsubcarrierSpacing                                   = 1;
+      #pdcch-ConfigCommon
+        initialDLBWPcontrolResourceSetZero                              = 12;
+        initialDLBWPsearchSpaceZero                                     = 0;
+      #pdsch-ConfigCommon
+        #pdschTimeDomainAllocationList (up to 16 entries)
+        initialDLBWPk0_0                    = 0;  #for DL slot
+        initialDLBWPmappingType_0           = 0;  #0=typeA,1=typeB
+        initialDLBWPstartSymbolAndLength_0  = 40; #this is SS=1,L=13
+
+        initialDLBWPk0_1                    = 0;  #for mixed slot
+        initialDLBWPmappingType_1           = 0;
+        initialDLBWPstartSymbolAndLength_1  = 57; #this is SS=1,L=5
+
+  #uplinkConfigCommon
+     #frequencyInfoUL
+      ul_frequencyBand                                              = 78;
+      #scs-SpecificCarrierList
+      ul_offstToCarrier                                             = 0;
+# subcarrierSpacing
+# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120
+      ul_subcarrierSpacing                                          = 1;
+      ul_carrierBandwidth                                           = 106;
+      pMax                                                          = 20;
+     #initialUplinkBWP
+      #genericParameters
+        initialULBWPlocationAndBandwidth                            = 12952;
+# subcarrierSpacing
+# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120
+        initialULBWPsubcarrierSpacing                               = 1;
+      #rach-ConfigCommon
+        #rach-ConfigGeneric
+          prach_ConfigurationIndex                                  = 98;
+#prach_msg1_FDM
+#0 = one, 1=two, 2=four, 3=eight
+          prach_msg1_FDM                                            = 0;
+          prach_msg1_FrequencyStart                                 = 0;
+          zeroCorrelationZoneConfig                                 = 13;
+          preambleReceivedTargetPower                               = -96;
+#preamblTransMax (0...10) = (3,4,5,6,7,8,10,20,50,100,200)
+          preambleTransMax                                          = 6;
+#powerRampingStep
+# 0=dB0,1=dB2,2=dB4,3=dB6
+        powerRampingStep                                            = 1;
+#ra_ReponseWindow
+#1,2,4,8,10,20,40,80
+        ra_ResponseWindow                                           = 4;
+#ssb_perRACH_OccasionAndCB_PreamblesPerSSB_PR
+#1=oneeighth,2=onefourth,3=half,4=one,5=two,6=four,7=eight,8=sixteen
+        ssb_perRACH_OccasionAndCB_PreamblesPerSSB_PR                = 4;
+#oneHalf (0..15) 4,8,12,16,...60,64
+        ssb_perRACH_OccasionAndCB_PreamblesPerSSB                   = 14;
+#ra_ContentionResolutionTimer
+#(0..7) 8,16,24,32,40,48,56,64
+        ra_ContentionResolutionTimer                                = 7;
+        rsrp_ThresholdSSB                                           = 19;
+#prach-RootSequenceIndex_PR
+#1 = 839, 2 = 139
+        prach_RootSequenceIndex_PR                                  = 2;
+        prach_RootSequenceIndex                                     = 1;
+        # SCS for msg1, can only be 15 for 30 kHz < 6 GHz, takes precendence over the one derived from prach-ConfigIndex
+        #
+        msg1_SubcarrierSpacing                                      = 1,
+# restrictedSetConfig
+# 0=unrestricted, 1=restricted type A, 2=restricted type B
+        restrictedSetConfig                                         = 0,
+
+      # pusch-ConfigCommon (up to 16 elements)
+        initialULBWPk2_0                      = 6;  # used for UL slot
+        initialULBWPmappingType_0             = 1
+        initialULBWPstartSymbolAndLength_0    = 41; # this is SS=0 L=13
+
+        initialULBWPk2_1                      = 6;  # used for mixed slot
+        initialULBWPmappingType_1             = 1;
+        initialULBWPstartSymbolAndLength_1    = 52; # this is SS=10 L=4
+
+        initialULBWPk2_2                      = 7;  # used for Msg.3 during RA
+        initialULBWPmappingType_2             = 1;
+        initialULBWPstartSymbolAndLength_2    = 52; # this is SS=10 L=4
+
+        msg3_DeltaPreamble                                          = 1;
+        p0_NominalWithGrant                                         =-90;
+
+# pucch-ConfigCommon setup :
+# pucchGroupHopping
+# 0 = neither, 1= group hopping, 2=sequence hopping
+        pucchGroupHopping                                           = 0;
+        hoppingId                                                   = 40;
+        p0_nominal                                                  = -90;
+# ssb_PositionsInBurs_BitmapPR
+# 1=short, 2=medium, 3=long
+      ssb_PositionsInBurst_PR                                       = 2;
+      ssb_PositionsInBurst_Bitmap                                   = 1;
+
+# ssb_periodicityServingCell
+# 0 = ms5, 1=ms10, 2=ms20, 3=ms40, 4=ms80, 5=ms160, 6=spare2, 7=spare1
+      ssb_periodicityServingCell                                    = 2;
+
+# dmrs_TypeA_position
+# 0 = pos2, 1 = pos3
+      dmrs_TypeA_Position                                           = 0;
+
+# subcarrierSpacing
+# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120
+      subcarrierSpacing                                             = 1;
+
+
+  #tdd-UL-DL-ConfigurationCommon
+# subcarrierSpacing
+# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120
+      referenceSubcarrierSpacing                                    = 1;
+      # pattern1
+      # dl_UL_TransmissionPeriodicity
+      # 0=ms0p5, 1=ms0p625, 2=ms1, 3=ms1p25, 4=ms2, 5=ms2p5, 6=ms5, 7=ms10
+      dl_UL_TransmissionPeriodicity                                 = 6;
+      nrofDownlinkSlots                                             = 7;
+      nrofDownlinkSymbols                                           = 6;
+      nrofUplinkSlots                                               = 2;
+      nrofUplinkSymbols                                             = 4;
+
+      ssPBCH_BlockPower                                             = -25;
+  }
+
+  );
+
+
+    # ------- SCTP definitions
+    SCTP :
+    {
+        # Number of streams to use in input/output
+        SCTP_INSTREAMS  = 2;
+        SCTP_OUTSTREAMS = 2;
+    };
+
+
+    ////////// AMF parameters:
+    amf_ip_address      = ( { ipv4       = "192.168.61.195";
+                              ipv6       = "192:168:30::17";
+                              active     = "yes";
+                              preference = "ipv4";
+                            }
+                          );
+
+
+    NETWORK_INTERFACES :
+    {
+        GNB_INTERFACE_NAME_FOR_NG_AMF            = "lo:";
+        GNB_IPV4_ADDRESS_FOR_NG_AMF              = "127.0.0.2";
+        GNB_INTERFACE_NAME_FOR_NGU               = "lo:";
+        GNB_IPV4_ADDRESS_FOR_NGU                 = "127.0.0.2";
+        GNB_PORT_FOR_NGU                         = 2152; # Spec 2152
+    };
+
+  }
+);
+
+MACRLCs = (
+        {
+        num_cc = 1;
+        local_s_if_name  = "lo:";
+        remote_s_address = "127.0.0.1"; // pnf addr [!]
+        local_s_address  = "127.0.0.2"; // vnf addr
+        local_s_portc    = 50601; // vnf p5 port
+        remote_s_portc   = 50600; // pnf p5 port [!]
+        local_s_portd    = 50611; // vnf p7 port [!]
+        remote_s_portd   = 50610; // pnf p7 port [!]
+        tr_s_preference = "nfapi";
+        tr_n_preference = "local_RRC";
+        }
+);
+
+L1s = (
+      {
+      num_cc = 1;
+      tr_n_preference = "local_mac";
+      pusch_proc_threads = 8;
+      prach_dtx_threshold = 120;
+      pucch0_dtx_threshold = 150;
+      }
+);
+
+RUs = (
+    {
+       local_rf       = "yes"
+         nb_tx          = 1
+         nb_rx          = 1
+         att_tx         = 0
+         att_rx         = 0;
+         bands          = [78];
+         max_pdschReferenceSignalPower = -27;
+         max_rxgain                    = 75;
+         eNB_instances  = [0];
+         #beamforming 1x4 matrix:
+         bf_weights = [0x00007fff, 0x0000, 0x0000, 0x0000];
+         #clock_src = "external";
+         sdr_addrs = "mgmt_addr=192.168.18.240,addr=192.168.10.2,second_addr=192.168.20.2,clock_source=internal,time_source=internal"
+    }
+);
+
+THREAD_STRUCT = (
+  {
+    #three config for level of parallelism "PARALLEL_SINGLE_THREAD", "PARALLEL_RU_L1_SPLIT", or "PARALLEL_RU_L1_TRX_SPLIT"
+    parallel_config    = "PARALLEL_SINGLE_THREAD";
+    #two option for worker "WORKER_DISABLE" or "WORKER_ENABLE"
+    worker_config      = "WORKER_ENABLE";
+  }
+);
+
+rfsimulator :
+{
+    serveraddr = "server";
+    serverport = "4043";
+    options = (); #("saviq"); or/and "chanmod"
+    modelname = "AWGN";
+    IQfile = "/tmp/rfsimulator.iqs";
+};
+
+security = {
+  # preferred ciphering algorithms
+  # the first one of the list that an UE supports in chosen
+  # valid values: nea0, nea1, nea2, nea3
+  ciphering_algorithms = ( "nea0" );
+
+  # preferred integrity algorithms
+  # the first one of the list that an UE supports in chosen
+  # valid values: nia0, nia1, nia2, nia3
+  integrity_algorithms = ( "nia2", "nia0" );
+
+  # setting 'drb_ciphering' to "no" disables ciphering for DRBs, no matter
+  # what 'ciphering_algorithms' configures; same thing for 'drb_integrity'
+  drb_ciphering = "yes";
+  drb_integrity = "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";
+       ngap_log_level                         ="debug";
+       ngap_log_verbosity                     ="medium";
+    };
+
diff --git a/ci-scripts/conf_files/episci/proxy_nr-ue.nfapi.conf b/ci-scripts/conf_files/episci/proxy_nr-ue.nfapi.conf
new file mode 100644
index 0000000000000000000000000000000000000000..8411ed8fc6d0a2552e109ccfa3040a1a8b523803
--- /dev/null
+++ b/ci-scripts/conf_files/episci/proxy_nr-ue.nfapi.conf
@@ -0,0 +1,52 @@
+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";
+};
+
+uicc0 = {
+imsi = "2089900007487";
+key = "fec86ba6eb707ed08905757b1bb44b8f";
+opc= "C42449363BBAD02B66D16BC975D77CC1";
+dnn= "oai";
+nssai_sst=1;
+nssai_sd=1;
+}
+
+L1s = (
+        {
+	num_cc = 1;
+	tr_n_preference = "nfapi";
+	local_n_if_name  = "lo:";
+	remote_n_address = "127.0.0.1"; //Proxy IP
+	local_n_address  = "127.0.0.1";
+	local_n_portc    = 50600;
+	remote_n_portc   = 50601;
+	local_n_portd    = 50610;
+	remote_n_portd   = 50611;
+        }  
+);
+
+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/conf_files/episci/proxy_rcc.band7.tm1.nfapi.conf b/ci-scripts/conf_files/episci/proxy_rcc.band7.tm1.nfapi.conf
new file mode 100644
index 0000000000000000000000000000000000000000..d4c72d6c1411433ac8fca598def78739009e1236
--- /dev/null
+++ b/ci-scripts/conf_files/episci/proxy_rcc.band7.tm1.nfapi.conf
@@ -0,0 +1,247 @@
+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 = 5;
+
+    plmn_list = ( { mcc = 320; mnc = 230; mnc_length = 3; } );
+
+    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       = "192.168.61.3";
+                              ipv6       = "192:168:30::17";
+                              port       = 36412 ;
+                              active     = "yes";
+                              preference = "ipv4";
+                            }
+                          );
+
+    enable_measurement_reports = "no";
+
+    ///X2
+    enable_x2 = "yes";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+    t_dc_prep         = 1000;      /* unit: millisecond */
+    t_dc_overall      = 2000;      /* unit: millisecond */
+
+    NETWORK_INTERFACES :
+    {
+        ENB_INTERFACE_NAME_FOR_S1_MME            = "lo";
+        ENB_IPV4_ADDRESS_FOR_S1_MME              = "127.0.0.1";
+        ENB_INTERFACE_NAME_FOR_S1U               = "lo";
+        ENB_IPV4_ADDRESS_FOR_S1U                 = "127.0.0.1";
+        ENB_PORT_FOR_S1U                         = 2152; # Spec 2152
+        ENB_IPV4_ADDRESS_FOR_X2C                 = "127.0.0.1";
+        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.1";
+	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";
+	scheduler_mode = "fairRR";
+        }  
+);
+
+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_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/episci/proxy_rcc.band78.tm1.106PRB.nfapi.conf b/ci-scripts/conf_files/episci/proxy_rcc.band78.tm1.106PRB.nfapi.conf
new file mode 100644
index 0000000000000000000000000000000000000000..0ef317d63e8c5d13c0c5d607582d442ddbaa3fda
--- /dev/null
+++ b/ci-scripts/conf_files/episci/proxy_rcc.band78.tm1.106PRB.nfapi.conf
@@ -0,0 +1,305 @@
+Active_gNBs = ( "gNB-Eurecom-5GNRBox");
+# Asn1_verbosity, choice in: none, info, annoying
+Asn1_verbosity = "none";
+
+gNBs =
+(
+ {
+ ////////// Identification parameters:
+    gNB_ID    =  0xe00;
+
+    cell_type =  "CELL_MACRO_GNB";
+
+    gNB_name  =  "gNB-Eurecom-5GNRBox";
+
+    // Tracking area code, 0x0000 and 0xfffe are reserved values
+    tracking_area_code  =  5;
+
+    plmn_list = ({mcc = 320; mnc = 230; mnc_length = 3;});
+
+    tr_s_preference     = "local_mac"
+
+    ////////// Physical parameters:
+
+    ssb_SubcarrierOffset                                      = 0;
+    pdsch_AntennaPorts                                        = 1;
+	
+    servingCellConfigCommon = (
+    {
+ #spCellConfigCommon
+
+      physCellId                                                    = 0;
+
+#  downlinkConfigCommon
+    #frequencyInfoDL
+      # this is 3600 MHz + 43 PRBs@30kHz SCS (same as initial BWP)
+      absoluteFrequencySSB                                          = 641032;
+      dl_frequencyBand                                                 = 78;
+      # this is 3600 MHz
+      dl_absoluteFrequencyPointA                                       = 640000;
+      #scs-SpecificCarrierList
+        dl_offstToCarrier                                              = 0;
+# subcarrierSpacing
+# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120  
+        dl_subcarrierSpacing                                           = 1;
+        dl_carrierBandwidth                                            = 106;
+     #initialDownlinkBWP
+      #genericParameters
+        # this is RBstart=41,L=24 (275*(L-1))+RBstart
+        initialDLBWPlocationAndBandwidth                                        = 6366;
+# subcarrierSpacing
+# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120  
+        initialDLBWPsubcarrierSpacing                                           = 1;
+      #pdcch-ConfigCommon
+        initialDLBWPcontrolResourceSetZero                                      = 12;
+        initialDLBWPsearchSpaceZero                                             = 0;
+      #pdsch-ConfigCommon
+        #pdschTimeDomainAllocationList (up to 16 entries)
+             initialDLBWPk0_0                    = 0;
+             #initialULBWPmappingType
+	     #0=typeA,1=typeB
+             initialDLBWPmappingType_0           = 0;
+             #this is SS=1,L=13
+             initialDLBWPstartSymbolAndLength_0  = 40;
+
+             initialDLBWPk0_1                    = 0;
+             initialDLBWPmappingType_1           = 0;
+             #this is SS=2,L=12 
+             initialDLBWPstartSymbolAndLength_1  = 53;
+
+             initialDLBWPk0_2                    = 0;
+             initialDLBWPmappingType_2           = 0;
+             #this is SS=1,L=12 
+             initialDLBWPstartSymbolAndLength_2  = 54;
+
+             initialDLBWPk0_3                    = 0;
+             initialDLBWPmappingType_3           = 0;
+             #this is SS=1,L=5
+             initialDLBWPstartSymbolAndLength_3  = 57;
+
+  #uplinkConfigCommon 
+     #frequencyInfoUL
+      ul_frequencyBand                                                 = 78;
+      #scs-SpecificCarrierList
+      ul_offstToCarrier                                              = 0;
+# subcarrierSpacing
+# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120  
+      ul_subcarrierSpacing                                           = 1;
+      ul_carrierBandwidth                                            = 106;
+      pMax                                                          = 20;
+     #initialUplinkBWP
+      #genericParameters
+        initialULBWPlocationAndBandwidth                                        = 6366;
+# subcarrierSpacing
+# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120  
+        initialULBWPsubcarrierSpacing                                           = 1;
+      #rach-ConfigCommon
+        #rach-ConfigGeneric
+          prach_ConfigurationIndex                                  = 98;
+#prach_msg1_FDM
+#0 = one, 1=two, 2=four, 3=eight
+          prach_msg1_FDM                                            = 0;
+          prach_msg1_FrequencyStart                                 = 0;
+          zeroCorrelationZoneConfig                                 = 13;
+          preambleReceivedTargetPower                               = -118;
+#preamblTransMax (0...10) = (3,4,5,6,7,8,10,20,50,100,200)
+          preambleTransMax                                          = 6;
+#powerRampingStep
+# 0=dB0,1=dB2,2=dB4,3=dB6
+        powerRampingStep                                            = 1;
+#ra_ReponseWindow
+#1,2,4,8,10,20,40,80
+        ra_ResponseWindow                                           = 4;
+#ssb_perRACH_OccasionAndCB_PreamblesPerSSB_PR
+#1=oneeighth,2=onefourth,3=half,4=one,5=two,6=four,7=eight,8=sixteen
+        ssb_perRACH_OccasionAndCB_PreamblesPerSSB_PR                = 4;
+#oneHalf (0..15) 4,8,12,16,...60,64
+        ssb_perRACH_OccasionAndCB_PreamblesPerSSB                   = 15;
+#ra_ContentionResolutionTimer
+#(0..7) 8,16,24,32,40,48,56,64
+        ra_ContentionResolutionTimer                                = 7;
+        rsrp_ThresholdSSB                                           = 19;
+#prach-RootSequenceIndex_PR
+#1 = 839, 2 = 139
+        prach_RootSequenceIndex_PR                                  = 2;
+        prach_RootSequenceIndex                                     = 1;
+        # SCS for msg1, can only be 15 for 30 kHz < 6 GHz, takes precendence over the one derived from prach-ConfigIndex
+        #  
+        msg1_SubcarrierSpacing                                      = 1,
+# restrictedSetConfig
+# 0=unrestricted, 1=restricted type A, 2=restricted type B
+        restrictedSetConfig                                         = 0,
+
+      # pusch-ConfigCommon (up to 16 elements)
+        initialULBWPk2_0                      = 6;
+        initialULBWPmappingType_0             = 1
+        # this is SS=0 L=11
+        initialULBWPstartSymbolAndLength_0    = 55;
+
+        initialULBWPk2_1                      = 6;
+        initialULBWPmappingType_1             = 1;
+        # this is SS=0 L=12
+        initialULBWPstartSymbolAndLength_1    = 69;
+
+        initialULBWPk2_2                      = 7;
+        initialULBWPmappingType_2             = 1;
+        # this is SS=10 L=4
+        initialULBWPstartSymbolAndLength_2    = 52;
+
+        msg3_DeltaPreamble                                          = 1;
+        p0_NominalWithGrant                                         =-90;
+
+# pucch-ConfigCommon setup :
+# pucchGroupHopping
+# 0 = neither, 1= group hopping, 2=sequence hopping
+        pucchGroupHopping                                           = 0;
+        hoppingId                                                   = 40;
+        p0_nominal                                                  = -90;
+# ssb_PositionsInBurs_BitmapPR
+# 1=short, 2=medium, 3=long
+      ssb_PositionsInBurst_PR                                       = 2;
+      ssb_PositionsInBurst_Bitmap                                   = 1;
+
+# ssb_periodicityServingCell
+# 0 = ms5, 1=ms10, 2=ms20, 3=ms40, 4=ms80, 5=ms160, 6=spare2, 7=spare1 
+      ssb_periodicityServingCell                                    = 2;
+
+# dmrs_TypeA_position
+# 0 = pos2, 1 = pos3
+      dmrs_TypeA_Position                                           = 0;
+
+# subcarrierSpacing
+# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120  
+      subcarrierSpacing                                             = 1;
+
+
+  #tdd-UL-DL-ConfigurationCommon
+# subcarrierSpacing
+# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120  
+      referenceSubcarrierSpacing                                    = 1;
+      # pattern1 
+      # dl_UL_TransmissionPeriodicity
+      # 0=ms0p5, 1=ms0p625, 2=ms1, 3=ms1p25, 4=ms2, 5=ms2p5, 6=ms5, 7=ms10
+      dl_UL_TransmissionPeriodicity                                 = 6;
+      nrofDownlinkSlots                                             = 7;
+      nrofDownlinkSymbols                                           = 6;
+      nrofUplinkSlots                                               = 2;
+      nrofUplinkSymbols                                             = 4;
+
+  ssPBCH_BlockPower                                             = 10;
+  }
+
+
+  );
+
+
+
+   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.61.3";
+                              ipv6       = "192:168:30::17";
+                              active     = "yes";
+                              preference = "ipv4";
+                            }
+                          );
+    ///X2
+    enable_x2 = "yes";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+    t_dc_prep         = 1000;      /* unit: millisecond */
+    t_dc_overall      = 2000;      /* unit: millisecond */
+    target_enb_x2_ip_address      = (
+                                     { ipv4       = "127.0.0.1"; # rrc.band7.tm1.nfapi.conf:line 201
+                                       ipv6       = "192:168:30::17";
+                                       preference = "ipv4";
+                                     }
+                                    );
+
+    NETWORK_INTERFACES :
+    {   # All of these have to be IP addr of gNB
+                # if in CORE container, make it 172.16.0.X
+                # if not launched in CORE, can set to lo (127.0.0.2)
+        GNB_INTERFACE_NAME_FOR_S1_MME            = "lo:";
+        GNB_IPV4_ADDRESS_FOR_S1_MME              = "127.0.0.2";
+        GNB_INTERFACE_NAME_FOR_S1U               = "lo:";
+        GNB_IPV4_ADDRESS_FOR_S1U                 = "127.0.0.2";
+        GNB_PORT_FOR_S1U                         = 2152; # Spec 2152
+        GNB_IPV4_ADDRESS_FOR_X2C                 = "127.0.0.2";
+        GNB_PORT_FOR_X2C                         = 36422; # Spec 36422
+    };
+  }
+);
+
+
+MACRLCs = (
+        {
+        num_cc = 1;
+        local_s_if_name  = "lo:";
+        remote_s_address = "127.0.0.1"; // pnf addr [!]
+        local_s_address  = "127.0.0.2"; // vnf addr
+        local_s_portc    = 50601; // vnf p5 port
+        remote_s_portc   = 50600; // pnf p5 port [!]
+        local_s_portd    = 50611; // vnf p7 port [!]
+        remote_s_portd   = 50610; // pnf p7 port [!]
+        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/episci/proxy_ue.nfapi.conf b/ci-scripts/conf_files/episci/proxy_ue.nfapi.conf
new file mode 100644
index 0000000000000000000000000000000000000000..3f227d573ce08d877303567177ace3a1fb3611b0
--- /dev/null
+++ b/ci-scripts/conf_files/episci/proxy_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.1";
+	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/conf_files/gNB_SA_CU.conf b/ci-scripts/conf_files/gNB_SA_CU.conf
new file mode 100644
index 0000000000000000000000000000000000000000..d3cfbfc97368a942bc634a824cc593e37784c214
--- /dev/null
+++ b/ci-scripts/conf_files/gNB_SA_CU.conf
@@ -0,0 +1,275 @@
+Active_gNBs = ( "gNB-Eurecom-CU");
+# Asn1_verbosity, choice in: none, info, annoying
+Asn1_verbosity = "none";
+Num_Threads_PUSCH = 8;
+
+gNBs =
+(
+ {
+    ////////// Identification parameters:
+    gNB_CU_ID = 0xe00;
+
+#     cell_type =  "CELL_MACRO_GNB";
+
+    gNB_name  =  "gNB-Eurecom-CU";
+
+    // Tracking area code, 0x0000 and 0xfffe are reserved values
+    tracking_area_code  =  1;
+    plmn_list = ({
+                  mcc = 208;
+                  mnc = 99;
+                  mnc_length = 2;
+                  snssaiList = (        
+                    {        
+                      sst = 1;
+                      sd  = 0x010203; // 0 false, else true
+                    },
+                    {   
+                      sst = 1;
+                      sd  = 0x112233; // 0 false, else true
+                    }
+                  );
+
+                  });
+
+
+    nr_cellid = 12345678L;
+
+    tr_s_preference = "f1";
+
+    local_s_if_name = "lo";
+    local_s_address = "127.0.0.4";
+    remote_s_address = "127.0.0.3";
+    local_s_portc   = 501;
+    local_s_portd   = 2152;
+    remote_s_portc  = 500;
+    remote_s_portd  = 2152;
+    ssb_SubcarrierOffset                                      = 0;
+    pdsch_AntennaPorts                                        = 1;
+    pusch_AntennaPorts                                        = 1;
+    min_rxtxtime                                              = 6;
+    sib1_tda                                                  = 0;
+
+     pdcch_ConfigSIB1 = (
+      {
+        controlResourceSetZero = 12;
+        searchSpaceZero = 0;
+      }
+      );
+
+    servingCellConfigCommon = (
+    {
+ #spCellConfigCommon
+
+      physCellId                                                    = 0;
+
+#  downlinkConfigCommon
+    #frequencyInfoDL
+      # this is 3600 MHz + 43 PRBs@30kHz SCS (same as initial BWP)
+      absoluteFrequencySSB                                             = 641280;
+      dl_frequencyBand                                                 = 78;
+      # this is 3600 MHz
+      dl_absoluteFrequencyPointA                                       = 640008;
+      #scs-SpecificCarrierList
+        dl_offstToCarrier                                              = 0;
+# subcarrierSpacing
+# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120
+        dl_subcarrierSpacing                                           = 1;
+        dl_carrierBandwidth                                            = 106;
+     #initialDownlinkBWP
+      #genericParameters
+        # this is RBstart=27,L=48 (275*(L-1))+RBstart
+        initialDLBWPlocationAndBandwidth                               = 28875; # 6366 12925 12956 28875 12952
+# subcarrierSpacing
+# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120
+        initialDLBWPsubcarrierSpacing                                   = 1;
+      #pdcch-ConfigCommon
+        initialDLBWPcontrolResourceSetZero                              = 12;
+        initialDLBWPsearchSpaceZero                                     = 0;
+      #pdsch-ConfigCommon
+        #pdschTimeDomainAllocationList (up to 16 entries)
+        initialDLBWPk0_0                    = 0;  #for DL slot
+        initialDLBWPmappingType_0           = 0;  #0=typeA,1=typeB
+        initialDLBWPstartSymbolAndLength_0  = 40; #this is SS=1,L=13
+
+        initialDLBWPk0_1                    = 0;  #for mixed slot
+        initialDLBWPmappingType_1           = 0;
+        initialDLBWPstartSymbolAndLength_1  = 57; #this is SS=1,L=5
+
+  #uplinkConfigCommon
+     #frequencyInfoUL
+      ul_frequencyBand                                              = 78;
+      #scs-SpecificCarrierList
+      ul_offstToCarrier                                             = 0;
+# subcarrierSpacing
+# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120
+      ul_subcarrierSpacing                                          = 1;
+      ul_carrierBandwidth                                           = 106;
+      pMax                                                          = 20;
+     #initialUplinkBWP
+      #genericParameters
+        initialULBWPlocationAndBandwidth                            = 28875;
+# subcarrierSpacing
+# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120
+        initialULBWPsubcarrierSpacing                               = 1;
+      #rach-ConfigCommon
+        #rach-ConfigGeneric
+          prach_ConfigurationIndex                                  = 98;
+#prach_msg1_FDM
+#0 = one, 1=two, 2=four, 3=eight
+          prach_msg1_FDM                                            = 0;
+          prach_msg1_FrequencyStart                                 = 0;
+          zeroCorrelationZoneConfig                                 = 13;
+          preambleReceivedTargetPower                               = -96;
+#preamblTransMax (0...10) = (3,4,5,6,7,8,10,20,50,100,200)
+          preambleTransMax                                          = 6;
+#powerRampingStep
+# 0=dB0,1=dB2,2=dB4,3=dB6
+        powerRampingStep                                            = 1;
+#ra_ReponseWindow
+#1,2,4,8,10,20,40,80
+        ra_ResponseWindow                                           = 4;
+#ssb_perRACH_OccasionAndCB_PreamblesPerSSB_PR
+#1=oneeighth,2=onefourth,3=half,4=one,5=two,6=four,7=eight,8=sixteen
+        ssb_perRACH_OccasionAndCB_PreamblesPerSSB_PR                = 4;
+#oneHalf (0..15) 4,8,12,16,...60,64
+        ssb_perRACH_OccasionAndCB_PreamblesPerSSB                   = 14;
+#ra_ContentionResolutionTimer
+#(0..7) 8,16,24,32,40,48,56,64
+        ra_ContentionResolutionTimer                                = 7;
+        rsrp_ThresholdSSB                                           = 19;
+#prach-RootSequenceIndex_PR
+#1 = 839, 2 = 139
+        prach_RootSequenceIndex_PR                                  = 2;
+        prach_RootSequenceIndex                                     = 1;
+        # SCS for msg1, can only be 15 for 30 kHz < 6 GHz, takes precendence over the one derived from prach-ConfigIndex
+        #
+        msg1_SubcarrierSpacing                                      = 1,
+# restrictedSetConfig
+# 0=unrestricted, 1=restricted type A, 2=restricted type B
+        restrictedSetConfig                                         = 0,
+
+      # pusch-ConfigCommon (up to 16 elements)
+        initialULBWPk2_0                      = 6;  # used for UL slot
+        initialULBWPmappingType_0             = 1
+        initialULBWPstartSymbolAndLength_0    = 41; # this is SS=0 L=13
+
+        initialULBWPk2_1                      = 6;  # used for mixed slot
+        initialULBWPmappingType_1             = 1;
+        initialULBWPstartSymbolAndLength_1    = 52; # this is SS=10 L=4
+
+        initialULBWPk2_2                      = 7;  # used for Msg.3 during RA
+        initialULBWPmappingType_2             = 1;
+        initialULBWPstartSymbolAndLength_2    = 52; # this is SS=10 L=4
+
+        msg3_DeltaPreamble                                          = 1;
+        p0_NominalWithGrant                                         =-90;
+
+# pucch-ConfigCommon setup :
+# pucchGroupHopping
+# 0 = neither, 1= group hopping, 2=sequence hopping
+        pucchGroupHopping                                           = 0;
+        hoppingId                                                   = 40;
+        p0_nominal                                                  = -90;
+# ssb_PositionsInBurs_BitmapPR
+# 1=short, 2=medium, 3=long
+      ssb_PositionsInBurst_PR                                       = 2;
+      ssb_PositionsInBurst_Bitmap                                   = 1;
+
+# ssb_periodicityServingCell
+# 0 = ms5, 1=ms10, 2=ms20, 3=ms40, 4=ms80, 5=ms160, 6=spare2, 7=spare1
+      ssb_periodicityServingCell                                    = 2;
+
+# dmrs_TypeA_position
+# 0 = pos2, 1 = pos3
+      dmrs_TypeA_Position                                           = 0;
+
+# subcarrierSpacing
+# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120
+      subcarrierSpacing                                             = 1;
+
+
+  #tdd-UL-DL-ConfigurationCommon
+# subcarrierSpacing
+# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120
+      referenceSubcarrierSpacing                                    = 1;
+      # pattern1
+      # dl_UL_TransmissionPeriodicity
+      # 0=ms0p5, 1=ms0p625, 2=ms1, 3=ms1p25, 4=ms2, 5=ms2p5, 6=ms5, 7=ms10
+      dl_UL_TransmissionPeriodicity                                 = 6;
+      nrofDownlinkSlots                                             = 7;
+      nrofDownlinkSymbols                                           = 6;
+      nrofUplinkSlots                                               = 2;
+      nrofUplinkSymbols                                             = 4;
+
+      ssPBCH_BlockPower                                             = -25;
+  }
+
+  );
+    # ------- SCTP definitions
+    SCTP :
+    {
+        # Number of streams to use in input/output
+        SCTP_INSTREAMS  = 2;
+        SCTP_OUTSTREAMS = 2;
+    };
+
+
+    ////////// AMF parameters:
+        amf_ip_address      = ( { ipv4       = "192.168.5.233";
+                              ipv6       = "192:168:30::17";
+                              active     = "yes";
+                              preference = "ipv4";
+                            }
+                          );
+
+    NETWORK_INTERFACES :
+    {
+
+        GNB_INTERFACE_NAME_FOR_NG_AMF            = "eth0";
+        GNB_IPV4_ADDRESS_FOR_NG_AMF              = "CI_GNB_IP_ADDR";
+        GNB_INTERFACE_NAME_FOR_NGU               = "eth0";
+        GNB_IPV4_ADDRESS_FOR_NGU                 = "CI_GNB_IP_ADDR";
+        GNB_PORT_FOR_S1U                         = 2152; # Spec 2152
+    };
+  }
+);
+
+security = {
+  # preferred ciphering algorithms
+  # the first one of the list that an UE supports in chosen
+  # valid values: nea0, nea1, nea2, nea3
+  ciphering_algorithms = ( "nea0" );
+
+  # preferred integrity algorithms
+  # the first one of the list that an UE supports in chosen
+  # valid values: nia0, nia1, nia2, nia3
+  integrity_algorithms = ( "nia2", "nia0" );
+
+  # setting 'drb_ciphering' to "no" disables ciphering for DRBs, no matter
+  # what 'ciphering_algorithms' configures; same thing for 'drb_integrity'
+  drb_ciphering = "yes";
+  drb_integrity = "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                         ="debug";
+       rlc_log_verbosity                     ="medium";
+       pdcp_log_level                        ="info";
+       pdcp_log_verbosity                    ="medium";
+       rrc_log_level                         ="info";
+       rrc_log_verbosity                     ="medium";
+       f1ap_log_level                         ="debug";
+       f1ap_log_verbosity                     ="medium";
+       ngap_log_level                         ="debug";
+       ngap_log_verbosity                     ="medium";
+    };
+
diff --git a/ci-scripts/conf_files/gNB_SA_DU.conf b/ci-scripts/conf_files/gNB_SA_DU.conf
new file mode 100644
index 0000000000000000000000000000000000000000..b03758a006a83bc6a7fc0a91d91156505df44ff5
--- /dev/null
+++ b/ci-scripts/conf_files/gNB_SA_DU.conf
@@ -0,0 +1,294 @@
+Active_gNBs = ( "gNB-Eurecom-DU");
+# Asn1_verbosity, choice in: none, info, annoying
+Asn1_verbosity = "none";
+
+gNBs =
+(
+ {
+    ////////// Identification parameters:
+    gNB_CU_ID = 0xe00;
+
+#     cell_type =  "CELL_MACRO_GNB";
+
+    gNB_name  =  "gNB-Eurecom-DU";
+
+    // Tracking area code, 0x0000 and 0xfffe are reserved values
+    tracking_area_code  =  1;
+    plmn_list = ({
+                  mcc = 208;
+                  mnc = 99;
+                  mnc_length = 2;
+                  snssaiList = (        
+                    {        
+                      sst = 1;
+                      sd  = 0x010203; // 0 false, else true
+                    },
+                    {   
+                      sst = 1;
+                      sd  = 0x112233; // 0 false, else true
+                    }
+                  );
+
+                  });
+
+
+    nr_cellid = 12345678L;
+
+    ////////// Physical parameters:
+
+    ssb_SubcarrierOffset                                      = 0;
+    pdsch_AntennaPorts                                        = 1;
+    pusch_AntennaPorts                                        = 1;
+    min_rxtxtime                                              = 6;
+    sib1_tda                                                  = 0;
+
+    pdcch_ConfigSIB1 = (
+      {
+        controlResourceSetZero = 12;
+        searchSpaceZero = 0;
+      }
+    );
+
+    servingCellConfigCommon = (
+    {
+ #spCellConfigCommon
+
+      physCellId                                                    = 0;
+
+#  downlinkConfigCommon
+    #frequencyInfoDL
+      # this is 3600 MHz + 43 PRBs@30kHz SCS (same as initial BWP)
+      absoluteFrequencySSB                                          = 641280;
+      dl_frequencyBand                                                 = 78;
+      # this is 3600 MHz
+      dl_absoluteFrequencyPointA                                       = 640008;
+      #scs-SpecificCarrierList
+        dl_offstToCarrier                                              = 0;
+# subcarrierSpacing
+# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120  
+        dl_subcarrierSpacing                                           = 1;
+        dl_carrierBandwidth                                            = 106;
+     #initialDownlinkBWP
+      #genericParameters
+        # this is RBstart=27,L=48 (275*(L-1))+RBstart
+        initialDLBWPlocationAndBandwidth                               = 28875; # 6366 12925 12956 28875 12952
+# subcarrierSpacing
+# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120  
+        initialDLBWPsubcarrierSpacing                                           = 1;
+      #pdcch-ConfigCommon
+        initialDLBWPcontrolResourceSetZero                              = 12;
+        initialDLBWPsearchSpaceZero                                             = 0;
+      #pdsch-ConfigCommon
+        #pdschTimeDomainAllocationList (up to 16 entries)
+        initialDLBWPk0_0                    = 0;  #for DL slot
+        initialDLBWPmappingType_0           = 0;  #0=typeA,1=typeB
+        initialDLBWPstartSymbolAndLength_0  = 40; #this is SS=1,L=13
+
+        initialDLBWPk0_1                    = 0;  #for mixed slot
+             initialDLBWPmappingType_1           = 0;
+        initialDLBWPstartSymbolAndLength_1  = 57; #this is SS=1,L=5
+
+  #uplinkConfigCommon 
+     #frequencyInfoUL
+      ul_frequencyBand                                                 = 78;
+      #scs-SpecificCarrierList
+      ul_offstToCarrier                                              = 0;
+# subcarrierSpacing
+# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120  
+      ul_subcarrierSpacing                                           = 1;
+      ul_carrierBandwidth                                            = 106;
+      pMax                                                          = 20;
+     #initialUplinkBWP
+      #genericParameters
+        initialULBWPlocationAndBandwidth                            = 28875;
+# subcarrierSpacing
+# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120  
+        initialULBWPsubcarrierSpacing                                           = 1;
+      #rach-ConfigCommon
+        #rach-ConfigGeneric
+          prach_ConfigurationIndex                                  = 98;
+#prach_msg1_FDM
+#0 = one, 1=two, 2=four, 3=eight
+          prach_msg1_FDM                                            = 0;
+          prach_msg1_FrequencyStart                                 = 0;
+          zeroCorrelationZoneConfig                                 = 13;
+          preambleReceivedTargetPower                               = -96;
+#preamblTransMax (0...10) = (3,4,5,6,7,8,10,20,50,100,200)
+          preambleTransMax                                          = 6;
+#powerRampingStep
+# 0=dB0,1=dB2,2=dB4,3=dB6
+        powerRampingStep                                            = 1;
+#ra_ReponseWindow
+#1,2,4,8,10,20,40,80
+        ra_ResponseWindow                                           = 4;
+#ssb_perRACH_OccasionAndCB_PreamblesPerSSB_PR
+#1=oneeighth,2=onefourth,3=half,4=one,5=two,6=four,7=eight,8=sixteen
+        ssb_perRACH_OccasionAndCB_PreamblesPerSSB_PR                = 4;
+#oneHalf (0..15) 4,8,12,16,...60,64
+        ssb_perRACH_OccasionAndCB_PreamblesPerSSB                   = 14;
+#ra_ContentionResolutionTimer
+#(0..7) 8,16,24,32,40,48,56,64
+        ra_ContentionResolutionTimer                                = 7;
+        rsrp_ThresholdSSB                                           = 19;
+#prach-RootSequenceIndex_PR
+#1 = 839, 2 = 139
+        prach_RootSequenceIndex_PR                                  = 2;
+        prach_RootSequenceIndex                                     = 1;
+        # SCS for msg1, can only be 15 for 30 kHz < 6 GHz, takes precendence over the one derived from prach-ConfigIndex
+        #  
+        msg1_SubcarrierSpacing                                      = 1,
+# restrictedSetConfig
+# 0=unrestricted, 1=restricted type A, 2=restricted type B
+        restrictedSetConfig                                         = 0,
+
+      # pusch-ConfigCommon (up to 16 elements)
+        initialULBWPk2_0                      = 6;  # used for UL slot
+        initialULBWPmappingType_0             = 1
+        initialULBWPstartSymbolAndLength_0    = 41; # this is SS=0 L=13
+
+        initialULBWPk2_1                      = 6;  # used for mixed slot
+        initialULBWPmappingType_1             = 1;
+        initialULBWPstartSymbolAndLength_1    = 52; # this is SS=10 L=4
+
+        initialULBWPk2_2                      = 7;  # used for Msg.3 during RA
+        initialULBWPmappingType_2             = 1;
+        initialULBWPstartSymbolAndLength_2    = 52; # this is SS=10 L=4
+
+        msg3_DeltaPreamble                                          = 1;
+        p0_NominalWithGrant                                         =-90;
+
+# pucch-ConfigCommon setup :
+# pucchGroupHopping
+# 0 = neither, 1= group hopping, 2=sequence hopping
+        pucchGroupHopping                                           = 0;
+        hoppingId                                                   = 40;
+        p0_nominal                                                  = -90;
+# ssb_PositionsInBurs_BitmapPR
+# 1=short, 2=medium, 3=long
+      ssb_PositionsInBurst_PR                                       = 2;
+      ssb_PositionsInBurst_Bitmap                                   = 1;
+
+# ssb_periodicityServingCell
+# 0 = ms5, 1=ms10, 2=ms20, 3=ms40, 4=ms80, 5=ms160, 6=spare2, 7=spare1 
+      ssb_periodicityServingCell                                    = 2;
+
+# dmrs_TypeA_position
+# 0 = pos2, 1 = pos3
+      dmrs_TypeA_Position                                           = 0;
+
+# subcarrierSpacing
+# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120  
+      subcarrierSpacing                                             = 1;
+
+
+  #tdd-UL-DL-ConfigurationCommon
+# subcarrierSpacing
+# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120  
+      referenceSubcarrierSpacing                                    = 1;
+      # pattern1 
+      # dl_UL_TransmissionPeriodicity
+      # 0=ms0p5, 1=ms0p625, 2=ms1, 3=ms1p25, 4=ms2, 5=ms2p5, 6=ms5, 7=ms10
+      dl_UL_TransmissionPeriodicity                                 = 6;
+      nrofDownlinkSlots                                             = 7;
+      nrofDownlinkSymbols                                           = 6;
+      nrofUplinkSlots                                               = 2;
+      nrofUplinkSymbols                                             = 4;
+
+      ssPBCH_BlockPower                                             = -25;
+     }
+
+  );
+
+
+    # ------- SCTP definitions
+    SCTP :
+    {
+        # Number of streams to use in input/output
+        SCTP_INSTREAMS  = 2;
+        SCTP_OUTSTREAMS = 2;
+    };
+  }
+);
+
+MACRLCs = (
+  {
+    num_cc           = 1;
+    tr_s_preference  = "local_L1";
+    tr_n_preference  = "f1";
+    local_n_if_name = "lo";
+    local_n_address = "127.0.0.3";
+    remote_n_address = "127.0.0.4";
+    local_n_portc   = 500;
+    local_n_portd   = 2152;
+    remote_n_portc  = 501;
+    remote_n_portd  = 2152;
+
+  }
+);
+
+L1s = (
+    	{
+	num_cc = 1;
+	tr_n_preference = "local_mac";
+	pusch_proc_threads = 8;
+	prach_dtx_threshold = 120;
+    pucch0_dtx_threshold = 150;
+    ofdm_offset_divisor = 8; #set this to UINT_MAX for offset 0
+        }  
+);
+
+RUs = (
+    {		  
+       local_rf       = "yes"
+         nb_tx          = 1
+         nb_rx          = 1
+         att_tx         = 0
+         att_rx         = 0;
+         bands          = [78];
+         max_pdschReferenceSignalPower = -27;
+         max_rxgain                    = 114;
+         eNB_instances  = [0];
+         #beamforming 1x4 matrix:
+         bf_weights = [0x00007fff, 0x0000, 0x0000, 0x0000];
+         clock_src = "internal";
+    }
+);  
+
+THREAD_STRUCT = (
+  {
+    #three config for level of parallelism "PARALLEL_SINGLE_THREAD", "PARALLEL_RU_L1_SPLIT", or "PARALLEL_RU_L1_TRX_SPLIT"
+    parallel_config    = "PARALLEL_SINGLE_THREAD";
+    #two option for worker "WORKER_DISABLE" or "WORKER_ENABLE"
+    worker_config      = "WORKER_ENABLE";
+  }
+);
+rfsimulator: {
+serveraddr = "server";
+    serverport = "4043";
+    options = (); #("saviq"); or/and "chanmod"
+    modelname = "AWGN";
+    IQfile = "/tmp/rfsimulator.iqs"
+}
+
+     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                         ="debug";
+       rlc_log_verbosity                     ="medium";
+       pdcp_log_level                        ="info";
+       pdcp_log_verbosity                    ="medium";
+       rrc_log_level                         ="info";
+       rrc_log_verbosity                     ="medium";
+       f1ap_log_level                         ="debug";
+       f1ap_log_verbosity                     ="medium";
+       ngap_log_level                         ="debug";
+       ngap_log_verbosity                     ="medium";
+    };
+
diff --git a/ci-scripts/conf_files/gnb.band78.sa.fr1.162PRB.usrpn310.conf b/ci-scripts/conf_files/gnb.band78.sa.fr1.162PRB.2x2.usrpn310.conf
similarity index 100%
rename from ci-scripts/conf_files/gnb.band78.sa.fr1.162PRB.usrpn310.conf
rename to ci-scripts/conf_files/gnb.band78.sa.fr1.162PRB.2x2.usrpn310.conf
diff --git a/ci-scripts/conf_files/nr-ue.nfapi.conf b/ci-scripts/conf_files/nr-ue.nfapi.conf
new file mode 100644
index 0000000000000000000000000000000000000000..b12e0c8d05beee6edaa4de41334f8beace656c19
--- /dev/null
+++ b/ci-scripts/conf_files/nr-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  = "ens3";
+	remote_n_address = "127.0.0.1"; //Proxy IP
+	local_n_address  = "127.0.0.1";
+	local_n_portc    = 50600;
+	remote_n_portc   = 50601;
+	local_n_portd    = 50610;
+	remote_n_portd   = 50611;
+        }  
+);
+
+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/ran.py b/ci-scripts/ran.py
index 95066d168d1313d59c8c0d3613b1b2bc71ac3eaf..94d37a01ddca7487cbf5511d9112235932fea8e0 100644
--- a/ci-scripts/ran.py
+++ b/ci-scripts/ran.py
@@ -474,7 +474,7 @@ class RANManagement():
 			mySSH.command('echo ' + lPassWord + ' | echo "ulimit -c unlimited && sudo UHD_RFNOC_DIR=/usr/local/share/uhd/rfnoc ./ran_build/build/' + self.air_interface[self.eNB_instance] + ' -O ' + lSourcePath + '/' + ci_full_config_file + extra_options + '" > ./my-lte-softmodem-run' + str(self.eNB_instance) + '.sh', '\$', 5)
 		#otherwise the regular command is ok
 		else:
-			mySSH.command('echo "ulimit -c unlimited && ./ran_build/build/' + self.air_interface[self.eNB_instance] + ' -O ' + lSourcePath + '/' + ci_full_config_file + extra_options + '" > ./my-lte-softmodem-run' + str(self.eNB_instance) + '.sh', '\$', 5)
+			mySSH.command('echo "ulimit -c unlimited && catchsegv ./ran_build/build/' + self.air_interface[self.eNB_instance] + ' -O ' + lSourcePath + '/' + ci_full_config_file + extra_options + '" > ./my-lte-softmodem-run' + str(self.eNB_instance) + '.sh', '\$', 5)
 
 		mySSH.command('chmod 775 ./my-lte-softmodem-run' + str(self.eNB_instance) + '.sh', '\$', 5)
 		mySSH.command('echo ' + lPassWord + ' | sudo -S rm -Rf enb_' + self.testCase_id + '.log', '\$', 5)
@@ -880,9 +880,6 @@ class RANManagement():
 			if result is not None and not exitSignalReceived:
 				foundSegFault = True
 			result = re.search('[Cc]ore [dD]ump', str(line))
-			if result is not None and not exitSignalReceived:
-				foundSegFault = True
-			result = re.search('./ran_build/build/lte-softmodem', str(line))
 			if result is not None and not exitSignalReceived:
 				foundSegFault = True
 			result = re.search('[Aa]ssertion', str(line))
diff --git a/ci-scripts/reportTestLocally.sh b/ci-scripts/reportTestLocally.sh
index 19fac7fd781827e8d83b5bf470772eb03bcbaa9f..6ef6b2e254e80f55a60b0706e5555b7f61708f54 100755
--- a/ci-scripts/reportTestLocally.sh
+++ b/ci-scripts/reportTestLocally.sh
@@ -1033,116 +1033,6 @@ function report_test {
         echo "   </div>" >> ./test_simulator_results.html
     fi
 
-    ARCHIVES_LOC=archives/l2_sim/test
-    if [ -d $ARCHIVES_LOC ]
-    then
-        echo "   <h3>4G LTE 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
-                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
-
-        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
-
-        EPC_CONFIGS=("wS1" "noS1")
-        TRANS_MODES=("fdd")
-        BW_CASES=(05)
-        NB_USERS=(01 04)
-        for CN_CONFIG in ${EPC_CONFIGS[@]}
-        do
-          for TMODE in ${TRANS_MODES[@]}
-          do
-            for BW in ${BW_CASES[@]}
-            do
-              for UES in ${NB_USERS[@]}
-              do
-                echo "      <tr bgcolor = \"#8FBC8F\" >" >> ./test_simulator_results.html
-                if [[ $CN_CONFIG =~ .*wS1.* ]]
-                then
-                    echo "          <td align = \"center\" colspan = 4 >Test with EPC (aka withS1): ${TMODE} -- ${BW}MHz -- ${UES} user(s)</td>" >> ./test_simulator_results.html
-                else
-                    echo "          <td align = \"center\" colspan = 4 >Test without EPC (aka noS1): ${TMODE} -- ${BW}MHz -- ${UES} user(s)</td>" >> ./test_simulator_results.html
-                fi
-                echo "      </tr>" >> ./test_simulator_results.html
-                ENB_LOG=$ARCHIVES_LOC/${TMODE}_${BW}MHz_${UES}users_${CN_CONFIG}_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 "Sending NFAPI_START_RESPONSE" $UE_LOG`
-                    if [ $NB_ENB_GOT_SYNC -gt 0 ] && [ $NB_UE_GOT_SYNC -gt 2 ] && [ $NB_ENB_SYNCED_WITH_UE -gt 0 ]
-                    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 -gt 0 ]
-                    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 -gt 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 -gt 0 ]
-                    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_LOGS=`ls $ARCHIVES_LOC/${TMODE}_${BW}MHz_${UES}users_${CN_CONFIG}_ping*.log 2> /dev/null`
-                analyzePingFiles
-
-                IPERF_TESTS=`ls $ARCHIVES_LOC/${TMODE}_${BW}MHz_${UES}users_${CN_CONFIG}_iperf_dl*client*txt 2> /dev/null`
-                analyzeIperfFiles
-
-                IPERF_TESTS=`ls $ARCHIVES_LOC/${TMODE}_${BW}MHz_${UES}users_${CN_CONFIG}_iperf_ul*client*txt 2> /dev/null`
-                analyzeIperfFiles
-              done
-            done
-          done
-        done
-
-        echo "   </table>" >> ./test_simulator_results.html
-        echo "   </div>" >> ./test_simulator_results.html
-    fi
-
     ARCHIVES_LOC=archives/phy_sim/test
     if [ -d $ARCHIVES_LOC ]
     then
diff --git a/ci-scripts/runTestOnVM.sh b/ci-scripts/runTestOnVM.sh
index de696cdc64b77cb03be90a6d91080fd05e5f837e..8be4a47bfa13219686b8bce3c105363f81f44b32 100755
--- a/ci-scripts/runTestOnVM.sh
+++ b/ci-scripts/runTestOnVM.sh
@@ -65,7 +65,7 @@ function start_basic_sim_enb {
     echo "sudo chmod 777 /home/ubuntu/tmp/cmake_targets/ran_build/" >> $1
     echo "sudo chmod 777 /home/ubuntu/tmp/cmake_targets/ran_build/build/" >> $1
     echo "cd /home/ubuntu/tmp/cmake_targets/ran_build/build/" >> $1
-    echo "echo \"ulimit -c unlimited && ./lte-softmodem -O /home/ubuntu/tmp/ci-scripts/conf_files/ci-$LOC_CONF_FILE --log_config.global_log_options level,nocolor --basicsim\" > ./my-lte-softmodem-run.sh " >> $1
+    echo "echo \"ulimit -c unlimited && ./lte-softmodem -O /home/ubuntu/tmp/ci-scripts/conf_files/ci-$LOC_CONF_FILE --log_config.global_log_options level,nocolor,time --basicsim\" > ./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
@@ -110,7 +110,7 @@ function start_basic_sim_ue {
     echo "echo \"cd /home/ubuntu/tmp/cmake_targets/ran_build/build/\"" > $1
     echo "sudo chmod 777 /home/ubuntu/tmp/cmake_targets/ran_build/build/" >> $1
     echo "cd /home/ubuntu/tmp/cmake_targets/ran_build/build" >> $1
-    echo "echo \"./lte-uesoftmodem -C ${LOC_FREQUENCY}000000 -r $LOC_NB_RBS  --log_config.global_log_options nocolor,level --basicsim\" > ./my-lte-uesoftmodem-run.sh" >> $1
+    echo "echo \"./lte-uesoftmodem -C ${LOC_FREQUENCY}000000 -r $LOC_NB_RBS  --log_config.global_log_options nocolor,line_num,level --basicsim\" > ./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
@@ -818,9 +818,9 @@ function start_l2_sim_enb {
     echo "cd /home/ubuntu/tmp/cmake_targets/ran_build/build/" >> $1
     if [ $LOC_S1_CONFIGURATION -eq 0 ]
     then
-        echo "echo \"ulimit -c unlimited && ./lte-softmodem -O /home/ubuntu/tmp/ci-scripts/conf_files/ci-$LOC_CONF_FILE --log_config.global_log_options level,nocolor --noS1\" > ./my-lte-softmodem-run.sh " >> $1
+        echo "echo \"ulimit -c unlimited && ./lte-softmodem -O /home/ubuntu/tmp/ci-scripts/conf_files/ci-$LOC_CONF_FILE --log_config.global_log_options level,nocolor,time --noS1\" > ./my-lte-softmodem-run.sh " >> $1
     else
-        echo "echo \"ulimit -c unlimited && ./lte-softmodem -O /home/ubuntu/tmp/ci-scripts/conf_files/ci-$LOC_CONF_FILE --log_config.global_log_options level,nocolor \" > ./my-lte-softmodem-run.sh " >> $1
+        echo "echo \"ulimit -c unlimited && ./lte-softmodem -O /home/ubuntu/tmp/ci-scripts/conf_files/ci-$LOC_CONF_FILE --log_config.global_log_options level,nocolor,time \" > ./my-lte-softmodem-run.sh " >> $1
     fi
     echo "chmod 775 ./my-lte-softmodem-run.sh" >> $1
     echo "cat ./my-lte-softmodem-run.sh" >> $1
@@ -929,9 +929,9 @@ function start_l2_sim_ue {
     echo "cd /home/ubuntu/tmp/cmake_targets/ran_build/build/" >> $1
     if [ $LOC_S1_CONFIGURATION -eq 0 ]
     then
-        echo "echo \"ulimit -c unlimited && ./lte-uesoftmodem -O /home/ubuntu/tmp/ci-scripts/conf_files/ci-$LOC_CONF_FILE --L2-emul 3 --num-ues $LOC_NB_UES --nums_ue_thread 1 --nokrnmod 1 --log_config.global_log_options level,nocolor --noS1\" > ./my-lte-softmodem-run.sh " >> $1
+        echo "echo \"ulimit -c unlimited && ./lte-uesoftmodem -O /home/ubuntu/tmp/ci-scripts/conf_files/ci-$LOC_CONF_FILE --L2-emul 3 --num-ues $LOC_NB_UES --nums_ue_thread 1 --nokrnmod 1 --log_config.global_log_options level,nocolor,time --noS1\" > ./my-lte-softmodem-run.sh " >> $1
     else
-        echo "echo \"ulimit -c unlimited && ./lte-uesoftmodem -O /home/ubuntu/tmp/ci-scripts/conf_files/ci-$LOC_CONF_FILE --L2-emul 3 --num-ues $LOC_NB_UES --nums_ue_thread 1 --nokrnmod 1 --log_config.global_log_options level,nocolor\" > ./my-lte-softmodem-run.sh " >> $1
+        echo "echo \"ulimit -c unlimited && ./lte-uesoftmodem -O /home/ubuntu/tmp/ci-scripts/conf_files/ci-$LOC_CONF_FILE --L2-emul 3 --num-ues $LOC_NB_UES --nums_ue_thread 1 --nokrnmod 1 --log_config.global_log_options level,nocolor,time\" > ./my-lte-softmodem-run.sh " >> $1
     fi
     echo "chmod 775 ./my-lte-softmodem-run.sh" >> $1
     echo "cat ./my-lte-softmodem-run.sh" >> $1
@@ -1051,9 +1051,9 @@ function start_rf_sim_enb {
     echo "cd /home/ubuntu/tmp/cmake_targets/ran_build/build/" >> $1
     if [ $LOC_S1_CONFIGURATION -eq 0 ]
     then
-        echo "echo \"ulimit -c unlimited && ./lte-softmodem -O /home/ubuntu/tmp/ci-scripts/conf_files/ci-$LOC_CONF_FILE --rfsim --log_config.global_log_options level,nocolor --noS1 --eNBs.[0].rrc_inactivity_threshold 0\" > ./my-lte-softmodem-run.sh " >> $1
+        echo "echo \"ulimit -c unlimited && ./lte-softmodem -O /home/ubuntu/tmp/ci-scripts/conf_files/ci-$LOC_CONF_FILE --rfsim --log_config.global_log_options level,nocolor,time --noS1 --eNBs.[0].rrc_inactivity_threshold 0\" > ./my-lte-softmodem-run.sh " >> $1
     else
-        echo "echo \"ulimit -c unlimited && ./lte-softmodem -O /home/ubuntu/tmp/ci-scripts/conf_files/ci-$LOC_CONF_FILE --rfsim --log_config.global_log_options level,nocolor --eNBs.[0].rrc_inactivity_threshold 0 --eNBs.[0].plmn_list.[0].mnc 93\" > ./my-lte-softmodem-run.sh " >> $1
+        echo "echo \"ulimit -c unlimited && ./lte-softmodem -O /home/ubuntu/tmp/ci-scripts/conf_files/ci-$LOC_CONF_FILE --rfsim --log_config.global_log_options level,nocolor,time --eNBs.[0].rrc_inactivity_threshold 0 --eNBs.[0].plmn_list.[0].mnc 93\" > ./my-lte-softmodem-run.sh " >> $1
     fi
     echo "chmod 775 ./my-lte-softmodem-run.sh" >> $1
     echo "cat ./my-lte-softmodem-run.sh" >> $1
@@ -1159,9 +1159,9 @@ function start_rf_sim_ue {
     echo "cd /home/ubuntu/tmp/cmake_targets/ran_build/build/" >> $1
     if [ $LOC_S1_CONFIGURATION -eq 0 ]
     then
-        echo "echo \"ulimit -c unlimited && ./lte-uesoftmodem -C ${LOC_FREQUENCY}000000 -r $LOC_PRB --ue-rxgain 140 --ue-txgain 120 --nokrnmod 1 --rfsim --log_config.global_log_options level,nocolor --noS1\" > ./my-lte-softmodem-run.sh " >> $1
+        echo "echo \"ulimit -c unlimited && ./lte-uesoftmodem -C ${LOC_FREQUENCY}000000 -r $LOC_PRB --ue-rxgain 140 --ue-txgain 120 --nokrnmod 1 --rfsim --log_config.global_log_options level,nocolor,time --noS1\" > ./my-lte-softmodem-run.sh " >> $1
     else
-        echo "echo \"ulimit -c unlimited && ./lte-uesoftmodem -C ${LOC_FREQUENCY}000000 -r $LOC_PRB --ue-rxgain 140 --ue-txgain 120 --nokrnmod 1 --rfsim --log_config.global_log_options level,nocolor\" > ./my-lte-softmodem-run.sh " >> $1
+        echo "echo \"ulimit -c unlimited && ./lte-uesoftmodem -C ${LOC_FREQUENCY}000000 -r $LOC_PRB --ue-rxgain 140 --ue-txgain 120 --nokrnmod 1 --rfsim --log_config.global_log_options level,nocolor,time\" > ./my-lte-softmodem-run.sh " >> $1
     fi
     echo "chmod 775 ./my-lte-softmodem-run.sh" >> $1
     echo "cat ./my-lte-softmodem-run.sh" >> $1
@@ -1281,12 +1281,12 @@ function start_rf_sim_gnb {
     then
         if [ $LOC_RA_SA_TEST -eq 0 ] #no RA test => use --phy-test option
         then
-            echo "echo \"./nr-softmodem -O /home/ubuntu/tmp/ci-scripts/conf_files/ci-$LOC_CONF_FILE --log_config.global_log_options level,nocolor --parallel-config PARALLEL_SINGLE_THREAD --noS1 --nokrnmod 1 --rfsim --phy-test --lowmem --noS1\" > ./my-nr-softmodem-run.sh " >> $1
+            echo "echo \"./nr-softmodem -O /home/ubuntu/tmp/ci-scripts/conf_files/ci-$LOC_CONF_FILE --log_config.global_log_options level,nocolor,time --parallel-config PARALLEL_SINGLE_THREAD --noS1 --nokrnmod 1 --rfsim --phy-test --lowmem --noS1\" > ./my-nr-softmodem-run.sh " >> $1
         elif [ $LOC_RA_SA_TEST -eq 1 ] #RA test => use --do-ra option
         then
-            echo "echo \"./nr-softmodem -O /home/ubuntu/tmp/ci-scripts/conf_files/ci-$LOC_CONF_FILE --log_config.global_log_options level,nocolor --parallel-config PARALLEL_SINGLE_THREAD --rfsim --do-ra --lowmem --noS1\" > ./my-nr-softmodem-run.sh " >> $1
+            echo "echo \"./nr-softmodem -O /home/ubuntu/tmp/ci-scripts/conf_files/ci-$LOC_CONF_FILE --log_config.global_log_options level,nocolor,time --parallel-config PARALLEL_SINGLE_THREAD --rfsim --do-ra --lowmem --noS1\" > ./my-nr-softmodem-run.sh " >> $1
         else #SA test => use --sa option
-            echo "echo \"./nr-softmodem -O /home/ubuntu/tmp/ci-scripts/conf_files/ci-$LOC_CONF_FILE --log_config.global_log_options level,nocolor --parallel-config PARALLEL_SINGLE_THREAD --rfsim --sa --lowmem \" > ./my-nr-softmodem-run.sh " >> $1
+            echo "echo \"./nr-softmodem -O /home/ubuntu/tmp/ci-scripts/conf_files/ci-$LOC_CONF_FILE --log_config.global_log_options level,nocolor,time --parallel-config PARALLEL_SINGLE_THREAD --rfsim --sa --lowmem \" > ./my-nr-softmodem-run.sh " >> $1
         fi
     fi
     echo "chmod 775 ./my-nr-softmodem-run.sh" >> $1
@@ -1397,12 +1397,12 @@ function start_rf_sim_nr_ue {
     then
         if [ $LOC_RA_SA_TEST -eq 0 ] #no RA test => use --phy-test option
         then
-            echo "echo \"./nr-uesoftmodem --nokrnmod 1 --rfsim --phy-test --rrc_config_path /home/ubuntu/tmp/cmake_targets/ran_build/build/ --log_config.global_log_options level,nocolor --noS1\" > ./my-nr-softmodem-run.sh " >> $1
+            echo "echo \"./nr-uesoftmodem --nokrnmod 1 --rfsim --phy-test --rrc_config_path /home/ubuntu/tmp/cmake_targets/ran_build/build/ --log_config.global_log_options level,nocolor,time --noS1\" > ./my-nr-softmodem-run.sh " >> $1
         elif [ $LOC_RA_SA_TEST -eq 1 ] #RA test => use --do-ra option
         then
-            echo "echo \"./nr-uesoftmodem --rfsim --do-ra --log_config.global_log_options level,nocolor --rrc_config_path /home/ubuntu/tmp/cmake_targets/ran_build/build/\" > ./my-nr-softmodem-run.sh " >> $1
+            echo "echo \"./nr-uesoftmodem --rfsim --do-ra --log_config.global_log_options level,nocolor,time --rrc_config_path /home/ubuntu/tmp/cmake_targets/ran_build/build/\" > ./my-nr-softmodem-run.sh " >> $1
         else #SA test => use --sa option
-            echo "echo \"./nr-uesoftmodem -r 106 --numerology 1 --band 78 -C 3619200000 --rfsim --sa --log_config.global_log_options level,nocolor\" > ./my-nr-softmodem-run.sh " >> $1
+            echo "echo \"./nr-uesoftmodem -r 106 --numerology 1 --band 78 -C 3619200000 --rfsim --sa --log_config.global_log_options level,nocolor,time\" > ./my-nr-softmodem-run.sh " >> $1
         fi
     fi
     echo "chmod 775 ./my-nr-softmodem-run.sh" >> $1
@@ -1472,13 +1472,18 @@ function run_test_on_vm {
     echo "############################################################"
     echo "OAI CI VM script"
     echo "############################################################"
-    if [[ (( "$RUN_OPTIONS" == "complex" ) && ( $VM_NAME =~ .*-l2-sim.* ))  ]] ||  [[ (( "$RUN_OPTIONS" == "complex" ) && ( $VM_NAME =~ .*-rf-sim.* ))  ]]
+    if [[ (( "$RUN_OPTIONS" == "complex" ) && ( $VM_NAME =~ .*-l2-sim.* ))  ]]
     then
-        ENB_VM_NAME=`echo $VM_NAME | sed -e "s#l2-sim#enb-ethernet#" -e "s#rf-sim#enb-ethernet#"`
+        echo "This VM test type is no longer supported in the pipeline framework"
+        return
+    fi
+    if [[ (( "$RUN_OPTIONS" == "complex" ) && ( $VM_NAME =~ .*-rf-sim.* ))  ]]
+    then
+        ENB_VM_NAME=`echo $VM_NAME | sed -e "s#rf-sim#enb-ethernet#"`
         ENB_VM_CMDS=${ENB_VM_NAME}_cmds.txt
         echo "ENB_VM_NAME         = $ENB_VM_NAME"
         echo "ENB_VM_CMD_FILE     = $ENB_VM_CMDS"
-        UE_VM_NAME=`echo $VM_NAME | sed -e "s#l2-sim#ue-ethernet#" -e "s#rf-sim#ue-ethernet#"`
+        UE_VM_NAME=`echo $VM_NAME | sed -e "s#rf-sim#ue-ethernet#"`
         UE_VM_CMDS=${UE_VM_NAME}_cmds.txt
         echo "UE_VM_NAME          = $UE_VM_NAME"
         echo "UE_VM_CMD_FILE      = $UE_VM_CMDS"
@@ -1499,7 +1504,7 @@ function run_test_on_vm {
     echo "JENKINS_WKSP        = $JENKINS_WKSP"
     echo "ARCHIVES_LOC        = $ARCHIVES_LOC"
 
-    if [[ (( "$RUN_OPTIONS" == "complex" ) && ( $VM_NAME =~ .*-l2-sim.* ))  ]] ||  [[ (( "$RUN_OPTIONS" == "complex" ) && ( $VM_NAME =~ .*-rf-sim.* ))  ]]
+    if [[ (( "$RUN_OPTIONS" == "complex" ) && ( $VM_NAME =~ .*-rf-sim.* ))  ]]
     then
         echo "############################################################"
         echo "Waiting for ENB VM to be started"
diff --git a/ci-scripts/xml_files/benetel_nsa_quectel.xml b/ci-scripts/xml_files/benetel_nsa_quectel.xml
index ed93f59e81cefff0d0b410c38f0636c5cd939452..8c284b6673bd5750fb163c41a838ce896c1ba6df 100644
--- a/ci-scripts/xml_files/benetel_nsa_quectel.xml
+++ b/ci-scripts/xml_files/benetel_nsa_quectel.xml
@@ -61,7 +61,7 @@
 	<testCase id="030000">
 		<class>Initialize_eNB</class>
 		<desc>Initialize eNB</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/benetel-4g.conf</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/benetel-4g.conf --log_config.global_log_options level,nocolor,time,line_num,function</Initialize_eNB_args>
 		<eNB_instance>0</eNB_instance>
 		<eNB_serverId>0</eNB_serverId>
 		<air_interface>lte</air_interface>
@@ -71,7 +71,7 @@
 	<testCase id="040000">
 		<class>Initialize_eNB</class>
 		<desc>Initialize gNB</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/benetel-5g.conf -q</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/benetel-5g.conf -q --log_config.global_log_options level,nocolor,time,line_num,function</Initialize_eNB_args>
 		<eNB_instance>1</eNB_instance>
 		<eNB_serverId>1</eNB_serverId>
 		<air_interface>nr</air_interface>
diff --git a/ci-scripts/xml_files/benetel_nsa_quectel_longrun.xml b/ci-scripts/xml_files/benetel_nsa_quectel_longrun.xml
index 93c0c5a00a209659092d47b39787086b48dc30da..2e4494c81995985dff095b803f8e47984e4ec185 100644
--- a/ci-scripts/xml_files/benetel_nsa_quectel_longrun.xml
+++ b/ci-scripts/xml_files/benetel_nsa_quectel_longrun.xml
@@ -63,7 +63,7 @@
 	<testCase id="030000">
 		<class>Initialize_eNB</class>
 		<desc>Initialize eNB</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/benetel-4g.conf</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/benetel-4g.conf --log_config.global_log_options level,nocolor,time,line_num,function</Initialize_eNB_args>
 		<eNB_instance>0</eNB_instance>
 		<eNB_serverId>0</eNB_serverId>
 		<air_interface>lte</air_interface>
@@ -73,7 +73,7 @@
 	<testCase id="040000">
 		<class>Initialize_eNB</class>
 		<desc>Initialize gNB</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/benetel-5g.conf -q</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/benetel-5g.conf -q --log_config.global_log_options level,nocolor,time,line_num,function</Initialize_eNB_args>
 		<eNB_instance>1</eNB_instance>
 		<eNB_serverId>1</eNB_serverId>
 		<air_interface>nr</air_interface>
diff --git a/ci-scripts/xml_files/container_4g_rfsim.xml b/ci-scripts/xml_files/container_4g_rfsim.xml
index 7f13d599b8945efae275790a161b55b4f2595ed7..2466f55800e6d3b7f21358f4a3a6318fb3777e5b 100644
--- a/ci-scripts/xml_files/container_4g_rfsim.xml
+++ b/ci-scripts/xml_files/container_4g_rfsim.xml
@@ -22,7 +22,7 @@
 -->
 <testCaseList>
         <htmlTabRef>rfsim-4glte</htmlTabRef>
-        <htmlTabName>Testing 4G LTE RF sim in containers</htmlTabName>
+        <htmlTabName>Testing 4G LTE RF sim - Monolithic eNB</htmlTabName>
         <htmlTabIcon>wrench</htmlTabIcon>
         <repeatCount>2</repeatCount>
         <TestCaseRequestedList>
diff --git a/ci-scripts/xml_files/container_4g_rfsim_down.xml b/ci-scripts/xml_files/container_4g_rfsim_down.xml
index dee516d9248e1ea3dd2141dca5fa7f5e2987f3d2..651447a9ca480f40e9b0e3ede56da36ed92feb04 100644
--- a/ci-scripts/xml_files/container_4g_rfsim_down.xml
+++ b/ci-scripts/xml_files/container_4g_rfsim_down.xml
@@ -22,7 +22,7 @@
 -->
 <testCaseList>
         <htmlTabRef>rfsim-4glte-down</htmlTabRef>
-        <htmlTabName>CleanUp 4G RF</htmlTabName>
+        <htmlTabName>CleanUp 4G RF - Monolithic eNB</htmlTabName>
         <htmlTabIcon>trash</htmlTabIcon>
         <TestCaseRequestedList>
  100011
diff --git a/ci-scripts/xml_files/container_5g_f1_rfsim.xml b/ci-scripts/xml_files/container_5g_f1_rfsim.xml
new file mode 100644
index 0000000000000000000000000000000000000000..501f2fe46ff6043468c0b3e7e940bfb8ee36932e
--- /dev/null
+++ b/ci-scripts/xml_files/container_5g_f1_rfsim.xml
@@ -0,0 +1,121 @@
+<!--
+
+ 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>rfsim-5gnr-f1</htmlTabRef>
+        <htmlTabName>Testing 5G NR RF sim in containers - CU-DU F1 split</htmlTabName>
+        <htmlTabIcon>wrench</htmlTabIcon>
+        <TestCaseRequestedList>
+ 100021
+ 000020
+ 000021
+ 000022
+ 000023
+ 000024
+ 020021
+ 020022
+ 030021
+ 100021
+        </TestCaseRequestedList>
+        <TestCaseExclusionList></TestCaseExclusionList>
+
+        <testCase id="000020">
+                <class>DeployGenObject</class>
+                <desc>Deploy MySql Database</desc>
+                <yaml_path>yaml_files/5g_f1_rfsimulator</yaml_path>
+                <services>mysql</services>
+                <nb_healthy>1</nb_healthy>
+        </testCase>
+
+        <testCase id="000021">
+                <class>DeployGenObject</class>
+                <desc>Deploy OAI 5G CoreNetwork</desc>
+                <yaml_path>yaml_files/5g_f1_rfsimulator</yaml_path>
+                <services>oai-nrf oai-amf oai-smf oai-spgwu oai-ext-dn</services>
+                <nb_healthy>6</nb_healthy>
+        </testCase>
+
+        <testCase id="000022">
+                <class>DeployGenObject</class>
+                <desc>Deploy OAI 5G CU RF sim SA</desc>
+                <yaml_path>yaml_files/5g_f1_rfsimulator</yaml_path>
+                <services>oai-cu</services>
+                <nb_healthy>7</nb_healthy>
+        </testCase>
+
+        <testCase id="000023">
+                <class>DeployGenObject</class>
+                <desc>Deploy OAI 5G DU RF sim SA</desc>
+                <yaml_path>yaml_files/5g_f1_rfsimulator</yaml_path>
+                <services>oai-du</services>
+                <nb_healthy>8</nb_healthy>
+        </testCase>
+
+        <testCase id="000024">
+                <class>DeployGenObject</class>
+                <desc>Deploy OAI 5G NR-UE RF sim SA</desc>
+                <yaml_path>yaml_files/5g_f1_rfsimulator</yaml_path>
+                <services>oai-nr-ue</services>
+                <nb_healthy>9</nb_healthy>
+        </testCase>
+
+        <testCase id="020021">
+                <class>PingFromContainer</class>
+                <desc>Ping ext-dn from NR-UE</desc>
+                <container_name>rfsim5g-oai-nr-ue</container_name>
+                <options>-I oaitun_ue1 -c 20 192.168.72.135</options>
+                <loss_threshold>5</loss_threshold>
+        </testCase>
+
+        <testCase id="020022">
+                <class>PingFromContainer</class>
+                <desc>Ping NR-UE from ext-dn</desc>
+		<container_name>rfsim5g-oai-ext-dn</container_name>
+                <options>-c 20 12.1.1.2</options>
+                <loss_threshold>5</loss_threshold>
+        </testCase>
+
+        <testCase id="030021">
+                <class>IperfFromContainer</class>
+                <desc>Iperf UDP Downlink</desc>
+                <server_container_name>rfsim5g-oai-nr-ue</server_container_name>
+                <client_container_name>rfsim5g-oai-ext-dn</client_container_name>
+                <server_options>-B 12.1.1.2 -u -i 1 -s</server_options>
+                <client_options>-c 12.1.1.2 -u -i 1 -t 30 -b 200K</client_options>
+        </testCase>
+
+        <testCase id="030022">
+                <class>IperfFromContainer</class>
+                <desc>Iperf UDP Uplink</desc>
+                <server_container_name>rfsim5g-oai-ext-dn</server_container_name>
+                <client_container_name>rfsim5g-oai-nr-ue</client_container_name>
+                <server_options>-u -i 1 -s</server_options>
+                <client_options>-B 12.1.1.2 -c 192.168.72.135 -u -i 1 -t 30 -b 5K</client_options>
+        </testCase>
+
+        <testCase id="100021">
+                <class>UndeployGenObject</class>
+                <desc>Undeploy all OAI 5G stack</desc>
+                <yaml_path>yaml_files/5g_f1_rfsimulator</yaml_path>
+        </testCase>
+
+</testCaseList>
diff --git a/ci-scripts/xml_files/container_5g_f1_rfsim_down.xml b/ci-scripts/xml_files/container_5g_f1_rfsim_down.xml
new file mode 100644
index 0000000000000000000000000000000000000000..ac3f7347bae311790ef413c98660ef4a446877eb
--- /dev/null
+++ b/ci-scripts/xml_files/container_5g_f1_rfsim_down.xml
@@ -0,0 +1,38 @@
+<!--
+
+ 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>rfsim-5gnr-down-f1</htmlTabRef>
+        <htmlTabName>CleanUp 5G RF - CU-DU F1 split</htmlTabName>
+        <htmlTabIcon>trash</htmlTabIcon>
+        <TestCaseRequestedList>
+ 100022
+        </TestCaseRequestedList>
+        <TestCaseExclusionList></TestCaseExclusionList>
+
+        <testCase id="100022">
+                <class>UndeployGenObject</class>
+                <desc>Undeploy all OAI 5G stack</desc>
+                <yaml_path>yaml_files/5g_f1_rfsimulator</yaml_path>
+        </testCase>
+
+</testCaseList>
diff --git a/ci-scripts/xml_files/container_5g_rfsim.xml b/ci-scripts/xml_files/container_5g_rfsim.xml
index 11f85688ecea2b2e26211169be214413190c49e0..d930886d0b4ed2abc44e8fee9b40f1eee1724b46 100644
--- a/ci-scripts/xml_files/container_5g_rfsim.xml
+++ b/ci-scripts/xml_files/container_5g_rfsim.xml
@@ -22,11 +22,12 @@
 -->
 <testCaseList>
         <htmlTabRef>rfsim-5gnr</htmlTabRef>
-        <htmlTabName>Testing 5G NR RF sim in containers</htmlTabName>
+        <htmlTabName>Testing 5G NR RF sim - Monolithic gNB</htmlTabName>
         <htmlTabIcon>wrench</htmlTabIcon>
         <repeatCount>4</repeatCount>
         <TestCaseRequestedList>
  100001
+ 000000
  000001
  000002
  000003
@@ -38,11 +39,19 @@
         </TestCaseRequestedList>
         <TestCaseExclusionList></TestCaseExclusionList>
 
+        <testCase id="000000">
+                <class>DeployGenObject</class>
+                <desc>Deploy MySql Database</desc>
+                <yaml_path>yaml_files/5g_rfsimulator</yaml_path>
+                <services>mysql</services>
+                <nb_healthy>1</nb_healthy>
+        </testCase>
+
         <testCase id="000001">
                 <class>DeployGenObject</class>
                 <desc>Deploy OAI 5G CoreNetwork</desc>
                 <yaml_path>yaml_files/5g_rfsimulator</yaml_path>
-                <services>mysql oai-nrf oai-amf oai-smf oai-spgwu oai-ext-dn</services>
+                <services>oai-nrf oai-amf oai-smf oai-spgwu oai-ext-dn</services>
                 <nb_healthy>6</nb_healthy>
         </testCase>
 
diff --git a/ci-scripts/xml_files/container_5g_rfsim_down.xml b/ci-scripts/xml_files/container_5g_rfsim_down.xml
index 57b0f67a214c297fe86648559e29aaf04012c1f7..9acc3f85a1b8b2dce671ccf468e62900af1d5b20 100644
--- a/ci-scripts/xml_files/container_5g_rfsim_down.xml
+++ b/ci-scripts/xml_files/container_5g_rfsim_down.xml
@@ -22,7 +22,7 @@
 -->
 <testCaseList>
         <htmlTabRef>rfsim-5gnr-down</htmlTabRef>
-        <htmlTabName>CleanUp 5G RF</htmlTabName>
+        <htmlTabName>CleanUp 5G RF - Monolithic gNB</htmlTabName>
         <htmlTabIcon>trash</htmlTabIcon>
         <TestCaseRequestedList>
  100002
diff --git a/ci-scripts/xml_files/enb_ocp_usrp210_band7_test_05mhz_tm1.xml b/ci-scripts/xml_files/enb_ocp_usrp210_band7_test_05mhz_tm1.xml
index a4caa77075979939cdbe7530caa1f8a399129e57..d330d826bfc6c310ffd434178784a6b08040a7fd 100644
--- a/ci-scripts/xml_files/enb_ocp_usrp210_band7_test_05mhz_tm1.xml
+++ b/ci-scripts/xml_files/enb_ocp_usrp210_band7_test_05mhz_tm1.xml
@@ -35,7 +35,7 @@
 	<testCase id="030101">
 		<class>Initialize_eNB</class>
 		<desc>Initialize OCP-eNB (FDD/Band7/5MHz)</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.25PRB.usrpb210.conf</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.25PRB.usrpb210.conf --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 		<air_interface>ocp</air_interface>
 	</testCase>
 
diff --git a/ci-scripts/xml_files/enb_ue_usrp210_band7_test_05mhz_tm1.xml b/ci-scripts/xml_files/enb_ue_usrp210_band7_test_05mhz_tm1.xml
index 581858e44e1287128d29cebf66ff741b0fb5bd4c..48ce2f298f779c544600d97bb4e40490d0adb15f 100644
--- a/ci-scripts/xml_files/enb_ue_usrp210_band7_test_05mhz_tm1.xml
+++ b/ci-scripts/xml_files/enb_ue_usrp210_band7_test_05mhz_tm1.xml
@@ -52,7 +52,7 @@
 	<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 --noS1 --eNBs.[0].rrc_inactivity_threshold 0</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.25PRB.usrpb210.conf --noS1 --eNBs.[0].rrc_inactivity_threshold 0 --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 	</testCase>
 
 	<testCase id="030201">
@@ -63,7 +63,7 @@
 	<testCase id="090101">
 		<class>Initialize_OAI_UE</class>
 		<desc>Initialize OAI UE (FDD/Band7/5MHz)</desc>
-		<Initialize_OAI_UE_args>-C 2680000000 -r 25 --ue-rxgain 120 --ue-txgain 0 --ue-max-power 0 --ue-scan-carrier --nokrnmod 1 --noS1</Initialize_OAI_UE_args>
+		<Initialize_OAI_UE_args>-C 2680000000 -r 25 --ue-rxgain 120 --ue-txgain 0 --ue-max-power 0 --ue-scan-carrier --nokrnmod 1 --noS1 --log_config.global_log_options level,nocolor,time</Initialize_OAI_UE_args>
 	</testCase>
 
 	<testCase id="090109">
diff --git a/ci-scripts/xml_files/enb_ue_usrp210_band7_test_05mhz_tm1_fembms_no_s1.xml b/ci-scripts/xml_files/enb_ue_usrp210_band7_test_05mhz_tm1_fembms_no_s1.xml
index 775ef2e023257733c55b1cf5a822773caa3f808d..fb66ce0c6684b3605feb1bcd9a918ef71a018d14 100644
--- a/ci-scripts/xml_files/enb_ue_usrp210_band7_test_05mhz_tm1_fembms_no_s1.xml
+++ b/ci-scripts/xml_files/enb_ue_usrp210_band7_test_05mhz_tm1_fembms_no_s1.xml
@@ -52,7 +52,7 @@
 	<testCase id="030104">
 		<class>Initialize_eNB</class>
 		<desc>Initialize eNB (FDD/Band7/5MHz/MBMS)</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band17.tm1.mbms.25PRB.usrpb210.conf --noS1 --eNBs.[0].rrc_inactivity_threshold 0 --nokrnmod 1 --eNBs.[0].component_carriers.[0].eutra_band 7 --eNBs.[0].component_carriers.[0].downlink_frequency 2680000000 --eNBs.[0].component_carriers.[0].uplink_frequency_offset -120000000 --eNBs.[0].component_carriers.[0].mbms_dedicated_serving_cell ENABLE --MCEs.[0].mbms_sched_info.mbms_area_config_list.[0].pmch_config_list.[0].allocated_sf_end 512</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band17.tm1.mbms.25PRB.usrpb210.conf --noS1 --eNBs.[0].rrc_inactivity_threshold 0 --nokrnmod 1 --eNBs.[0].component_carriers.[0].eutra_band 7 --eNBs.[0].component_carriers.[0].downlink_frequency 2680000000 --eNBs.[0].component_carriers.[0].uplink_frequency_offset -120000000 --eNBs.[0].component_carriers.[0].mbms_dedicated_serving_cell ENABLE --MCEs.[0].mbms_sched_info.mbms_area_config_list.[0].pmch_config_list.[0].allocated_sf_end 512 --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 	</testCase>
 
 	<testCase id="030201">
@@ -63,7 +63,7 @@
 	<testCase id="090104">
 		<class>Initialize_OAI_UE</class>
 		<desc>Initialize OAI UE (FDD/Band7/5MHz/MBMS)</desc>
-		<Initialize_OAI_UE_args>-C 2680000000 -r 25 --ue-rxgain 120 --ue-txgain 0 --ue-max-power 0 --ue-scan-carrier --nokrnmod 1 --noS1</Initialize_OAI_UE_args>
+		<Initialize_OAI_UE_args>-C 2680000000 -r 25 --ue-rxgain 120 --ue-txgain 0 --ue-max-power 0 --ue-scan-carrier --nokrnmod 1 --noS1 --log_config.global_log_options level,nocolor,time</Initialize_OAI_UE_args>
 	</testCase>
 
 	<testCase id="090109">
diff --git a/ci-scripts/xml_files/enb_ue_usrp210_band7_test_05mhz_tm1_mbms_no_s1.xml b/ci-scripts/xml_files/enb_ue_usrp210_band7_test_05mhz_tm1_mbms_no_s1.xml
index b841d3bab4b5eea7c60e0492904e8ca78094a4be..234f6639ce1eb69067f572b67b0dc80dc2a51ea9 100644
--- a/ci-scripts/xml_files/enb_ue_usrp210_band7_test_05mhz_tm1_mbms_no_s1.xml
+++ b/ci-scripts/xml_files/enb_ue_usrp210_band7_test_05mhz_tm1_mbms_no_s1.xml
@@ -52,7 +52,7 @@
 	<testCase id="030103">
 		<class>Initialize_eNB</class>
 		<desc>Initialize eNB (FDD/Band7/5MHz/MBMS)</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band17.tm1.mbms.25PRB.usrpb210.conf --noS1 --eNBs.[0].rrc_inactivity_threshold 0 --nokrnmod 1 --eNBs.[0].component_carriers.[0].eutra_band 7 --eNBs.[0].component_carriers.[0].downlink_frequency 2680000000 --eNBs.[0].component_carriers.[0].uplink_frequency_offset -120000000</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band17.tm1.mbms.25PRB.usrpb210.conf --noS1 --eNBs.[0].rrc_inactivity_threshold 0 --nokrnmod 1 --eNBs.[0].component_carriers.[0].eutra_band 7 --eNBs.[0].component_carriers.[0].downlink_frequency 2680000000 --eNBs.[0].component_carriers.[0].uplink_frequency_offset -120000000 --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 	</testCase>
 
 	<testCase id="030201">
@@ -63,7 +63,7 @@
 	<testCase id="090103">
 		<class>Initialize_OAI_UE</class>
 		<desc>Initialize OAI UE (FDD/Band7/5MHz/MBMS)</desc>
-		<Initialize_OAI_UE_args>-C 2680000000 -r 25 --ue-rxgain 120 --ue-txgain 0 --ue-max-power 0 --ue-scan-carrier --nokrnmod 1 --noS1</Initialize_OAI_UE_args>
+		<Initialize_OAI_UE_args>-C 2680000000 -r 25 --ue-rxgain 120 --ue-txgain 0 --ue-max-power 0 --ue-scan-carrier --nokrnmod 1 --noS1 --log_config.global_log_options level,nocolor,time</Initialize_OAI_UE_args>
 	</testCase>
 
 	<testCase id="090109">
diff --git a/ci-scripts/xml_files/enb_ue_usrp210_band7_test_05mhz_tm1_s1.xml b/ci-scripts/xml_files/enb_ue_usrp210_band7_test_05mhz_tm1_s1.xml
index 2336f8e614456fa17c0a566536f9c24c2c097bbc..791d32eec05480e6d914dc9f1ec0acb675a1dc74 100644
--- a/ci-scripts/xml_files/enb_ue_usrp210_band7_test_05mhz_tm1_s1.xml
+++ b/ci-scripts/xml_files/enb_ue_usrp210_band7_test_05mhz_tm1_s1.xml
@@ -46,7 +46,7 @@
 	<testCase id="030102">
 		<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 --eNBs.[0].rrc_inactivity_threshold 0</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.25PRB.usrpb210.conf --eNBs.[0].rrc_inactivity_threshold 0 --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 	</testCase>
 
 	<testCase id="030201">
@@ -57,7 +57,7 @@
 	<testCase id="090102">
 		<class>Initialize_OAI_UE</class>
 		<desc>Initialize OAI UE (FDD/Band7/5MHz)</desc>
-		<Initialize_OAI_UE_args>-C 2680000000 -r 25 --ue-rxgain 120 --ue-txgain 0 --ue-max-power 0 --ue-scan-carrier --nokrnmod 1</Initialize_OAI_UE_args>
+		<Initialize_OAI_UE_args>-C 2680000000 -r 25 --ue-rxgain 120 --ue-txgain 0 --ue-max-power 0 --ue-scan-carrier --nokrnmod 1 --log_config.global_log_options level,nocolor,time</Initialize_OAI_UE_args>
 	</testCase>
 
 	<testCase id="090109">
diff --git a/ci-scripts/xml_files/enb_usrp210_band13_test_10mhz_tm1.xml b/ci-scripts/xml_files/enb_usrp210_band13_test_10mhz_tm1.xml
index cdba0723dff81e5dc8bf6f6a24b08117bc4c8501..c050b38b121c10d191e5ad84b9044305dc4682a7 100644
--- a/ci-scripts/xml_files/enb_usrp210_band13_test_10mhz_tm1.xml
+++ b/ci-scripts/xml_files/enb_usrp210_band13_test_10mhz_tm1.xml
@@ -43,7 +43,7 @@
 	<testCase id="030121">
 		<class>Initialize_eNB</class>
 		<desc>Initialize eNB (FDD/Band13/10MHz)</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band13.tm1.50PRB.emtc.conf</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band13.tm1.50PRB.emtc.conf --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 	</testCase>
 
 	<testCase id="030201">
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
index 6cf5634fcf0a72be9f73184d7d395872f337461d..f1a2ad2ea32537cb221422754db19271c3aa3df6 100644
--- a/ci-scripts/xml_files/enb_usrp210_band40_test_05mhz_tm1.xml
+++ b/ci-scripts/xml_files/enb_usrp210_band40_test_05mhz_tm1.xml
@@ -34,7 +34,7 @@
 	<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>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band40.tm1.25PRB.FairScheduler.usrpb210.conf --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 	</testCase>
 
 	<testCase id="030201">
diff --git a/ci-scripts/xml_files/enb_usrp210_band40_test_05mhz_tm2.xml b/ci-scripts/xml_files/enb_usrp210_band40_test_05mhz_tm2.xml
index 5ece10d37e2cdd22605f19c5b8067fb5d465feb3..2e7da714b05557fd9ec79786b8f13d078cd0e79a 100644
--- a/ci-scripts/xml_files/enb_usrp210_band40_test_05mhz_tm2.xml
+++ b/ci-scripts/xml_files/enb_usrp210_band40_test_05mhz_tm2.xml
@@ -38,7 +38,7 @@
 	<testCase id="030105">
 		<class>Initialize_eNB</class>
 		<desc>Initialize eNB (TDD/Band40/5MHz)</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band40.tm2.25PRB.FairScheduler.usrpb210.conf --MACRLCs.[0].scheduler_mode default</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band40.tm2.25PRB.FairScheduler.usrpb210.conf --MACRLCs.[0].scheduler_mode default --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 	</testCase>
 
 	<testCase id="030201">
diff --git a/ci-scripts/xml_files/enb_usrp210_band40_test_10mhz_tm1.xml b/ci-scripts/xml_files/enb_usrp210_band40_test_10mhz_tm1.xml
index b1d87e598e7ef7cc7bda596ea7aebc34bf15b185..d2877fc01ee1431f87eff50984accdddf03c8821 100644
--- a/ci-scripts/xml_files/enb_usrp210_band40_test_10mhz_tm1.xml
+++ b/ci-scripts/xml_files/enb_usrp210_band40_test_10mhz_tm1.xml
@@ -36,7 +36,7 @@
 	<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</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band40.tm1.50PRB.FairScheduler.usrpb210.conf --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 	</testCase>
 
 	<testCase id="030201">
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
index d75704acebc026b5f449c68a7f4a196eb44f1cac..ef9fee0dca2262fa82b3d0aa3f8710ac688b449d 100644
--- a/ci-scripts/xml_files/enb_usrp210_band40_test_20mhz_tm1.xml
+++ b/ci-scripts/xml_files/enb_usrp210_band40_test_20mhz_tm1.xml
@@ -37,7 +37,7 @@
 	<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>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band40.tm1.100PRB.FairScheduler.usrpb210.conf --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 	</testCase>
 
 	<testCase id="030201">
diff --git a/ci-scripts/xml_files/enb_usrp210_band40_test_20mhz_tm1_default_scheduler.xml b/ci-scripts/xml_files/enb_usrp210_band40_test_20mhz_tm1_default_scheduler.xml
index a6530a920ccc824d85aa659026ebf585c954ca5c..adf03d802a194b36d3bf929011ea5e7cd8801277 100644
--- a/ci-scripts/xml_files/enb_usrp210_band40_test_20mhz_tm1_default_scheduler.xml
+++ b/ci-scripts/xml_files/enb_usrp210_band40_test_20mhz_tm1_default_scheduler.xml
@@ -36,7 +36,7 @@
 	<testCase id="030125">
 		<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 --MACRLCs.[0].scheduler_mode default</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band40.tm1.100PRB.FairScheduler.usrpb210.conf --MACRLCs.[0].scheduler_mode default --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 	</testCase>
 
 	<testCase id="030201">
diff --git a/ci-scripts/xml_files/enb_usrp210_band40_tracer.xml b/ci-scripts/xml_files/enb_usrp210_band40_tracer.xml
index 08cef07c8cad6e861cd705ed2181d5fc12303be3..d8793b63e6198740b585aeed3b12f0336222aac6 100644
--- a/ci-scripts/xml_files/enb_usrp210_band40_tracer.xml
+++ b/ci-scripts/xml_files/enb_usrp210_band40_tracer.xml
@@ -33,7 +33,7 @@
 	<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>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band40.tm1.25PRB.FairScheduler.usrpb210.conf --T_stdout 0 --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 	</testCase>
 
 	<testCase id="030201">
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
index ec6090c00c7004de47fad48539f6f3dd5bd46573..2fe0e17611dabaa2faa1760d748aa2f379e7f02a 100644
--- a/ci-scripts/xml_files/enb_usrp210_band7_test_05mhz_tm1.xml
+++ b/ci-scripts/xml_files/enb_usrp210_band7_test_05mhz_tm1.xml
@@ -34,7 +34,7 @@
 	<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>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.25PRB.usrpb210.conf --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 	</testCase>
 
 	<testCase id="030201">
diff --git a/ci-scripts/xml_files/enb_usrp210_band7_test_05mhz_tm1_rrc_inactivity_no_flexran.xml b/ci-scripts/xml_files/enb_usrp210_band7_test_05mhz_tm1_rrc_inactivity_no_flexran.xml
index 73d12161994923f717c3c330c2d725710b58200b..aedd980c34756ba9da5b12a5a9b6c15a529b6be5 100644
--- a/ci-scripts/xml_files/enb_usrp210_band7_test_05mhz_tm1_rrc_inactivity_no_flexran.xml
+++ b/ci-scripts/xml_files/enb_usrp210_band7_test_05mhz_tm1_rrc_inactivity_no_flexran.xml
@@ -71,7 +71,7 @@
 	<testCase id="030102">
 		<class>Initialize_eNB</class>
 		<desc>Initialize eNB (FDD/Band7/5MHz) for RRC Inactivity Timer testing -- no FlexRan Ctl</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.25PRB.usrpb210.conf</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.25PRB.usrpb210.conf --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 	</testCase>
 
 	<testCase id="030201">
diff --git a/ci-scripts/xml_files/enb_usrp210_band7_test_05mhz_tm1_rrc_inactivity_w_flexran.xml b/ci-scripts/xml_files/enb_usrp210_band7_test_05mhz_tm1_rrc_inactivity_w_flexran.xml
index 6ee9247ef34c5ae8366693105c6bbd51c6801412..b4886374838dc95607d1ac4932bad6daf7b05a92 100644
--- a/ci-scripts/xml_files/enb_usrp210_band7_test_05mhz_tm1_rrc_inactivity_w_flexran.xml
+++ b/ci-scripts/xml_files/enb_usrp210_band7_test_05mhz_tm1_rrc_inactivity_w_flexran.xml
@@ -83,7 +83,7 @@
 	<testCase id="030103">
 		<class>Initialize_eNB</class>
 		<desc>Initialize eNB (FDD/Band7/5MHz) for RRC Inactivity Timer testing -- with FlexRan Ctl</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.25PRB.usrpb210.conf</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.25PRB.usrpb210.conf --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 	</testCase>
 
 	<testCase id="030201">
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
index 1ee223d1c7cceca179be0f1bafc5a29519dafca1..5b3a23dbfb12e02d069be600ec91ea0a67357962 100644
--- a/ci-scripts/xml_files/enb_usrp210_band7_test_10mhz_tm1.xml
+++ b/ci-scripts/xml_files/enb_usrp210_band7_test_10mhz_tm1.xml
@@ -34,7 +34,7 @@
 	<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 --eNBs.[0].component_carriers.[0].drx_Config_present prRelease</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.50PRB.usrpb210.conf --eNBs.[0].component_carriers.[0].drx_Config_present prRelease --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 	</testCase>
 
 	<testCase id="030201">
diff --git a/ci-scripts/xml_files/enb_usrp210_band7_test_10mhz_tm1_cdrx.xml b/ci-scripts/xml_files/enb_usrp210_band7_test_10mhz_tm1_cdrx.xml
index a76f188bc48d19dfe1db5f13e022aa9d3b9dcf82..82e0a32f6a85a04a0f075aad0af84c7c11c2a3fe 100644
--- a/ci-scripts/xml_files/enb_usrp210_band7_test_10mhz_tm1_cdrx.xml
+++ b/ci-scripts/xml_files/enb_usrp210_band7_test_10mhz_tm1_cdrx.xml
@@ -35,7 +35,7 @@
 	<testCase id="030112">
 		<class>Initialize_eNB</class>
 		<desc>Initialize eNB (FDD/Band7/10MHz) with CDRX</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.50PRB.usrpb210.conf  --eNBs.[0].component_carriers.[0].drx_Config_present prSetup</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.50PRB.usrpb210.conf  --eNBs.[0].component_carriers.[0].drx_Config_present prSetup --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 	</testCase>
 
 	<testCase id="030201">
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
index adde118128c5d61d11f2e20dd386e59939749f16..b25f75d2d377615c69a793bad272e14de6a4d875 100644
--- a/ci-scripts/xml_files/enb_usrp210_band7_test_20mhz_tm1.xml
+++ b/ci-scripts/xml_files/enb_usrp210_band7_test_20mhz_tm1.xml
@@ -34,7 +34,7 @@
 	<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>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.100PRB.usrpb210.conf --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 	</testCase>
 
 	<testCase id="030201">
diff --git a/ci-scripts/xml_files/f1_usrp210_band7_test_05mhz.xml b/ci-scripts/xml_files/f1_usrp210_band7_test_05mhz.xml
index c2a48037baf5c2e6b151059d3806d15e4d07e2f9..68aca3a26dc4f8edd4418e16192f928c4fd564df 100644
--- a/ci-scripts/xml_files/f1_usrp210_band7_test_05mhz.xml
+++ b/ci-scripts/xml_files/f1_usrp210_band7_test_05mhz.xml
@@ -42,14 +42,14 @@
 	<testCase id="030141">
 		<class>Initialize_eNB</class>
 		<desc>Initialize DU (FDD/Band7/5MHz)</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/du.band7.tm1.25PRB.usrpb210.conf</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/du.band7.tm1.25PRB.usrpb210.conf --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 		<eNB_instance>1</eNB_instance>
 	</testCase>
 
 	<testCase id="030142">
 		<class>Initialize_eNB</class>
 		<desc>Initialize CU (FDD/Band7/5MHz)</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/cu.band7.tm1.25PRB.conf</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/cu.band7.tm1.25PRB.conf --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 		<eNB_instance>0</eNB_instance>
 	</testCase>
 
diff --git a/ci-scripts/xml_files/f1_usrp210_band7_test_10mhz.xml b/ci-scripts/xml_files/f1_usrp210_band7_test_10mhz.xml
index 8d028df433a9d0ec2a972f2b16f6c64e36441ce9..4e8fe45c36b8e62d2a98c17346f6d244d17ec14e 100644
--- a/ci-scripts/xml_files/f1_usrp210_band7_test_10mhz.xml
+++ b/ci-scripts/xml_files/f1_usrp210_band7_test_10mhz.xml
@@ -42,14 +42,14 @@
 	<testCase id="030151">
 		<class>Initialize_eNB</class>
 		<desc>Initialize DU (FDD/Band7/10MHz)</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/du.band7.tm1.50PRB.usrpb210.conf</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/du.band7.tm1.50PRB.usrpb210.conf --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 		<eNB_instance>1</eNB_instance>
 	</testCase>
 
 	<testCase id="030152">
 		<class>Initialize_eNB</class>
 		<desc>Initialize CU (FDD/Band7/10MHz)</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/cu.band7.tm1.50PRB.conf</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/cu.band7.tm1.50PRB.conf --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 		<eNB_instance>0</eNB_instance>
 	</testCase>
 
diff --git a/ci-scripts/xml_files/f1_usrp210_band7_test_20mhz.xml b/ci-scripts/xml_files/f1_usrp210_band7_test_20mhz.xml
index 061b87294bfe6e328d3433faf420436d508c55f8..22e2aed34c3bafdae10932016391462fc9a2a3f3 100644
--- a/ci-scripts/xml_files/f1_usrp210_band7_test_20mhz.xml
+++ b/ci-scripts/xml_files/f1_usrp210_band7_test_20mhz.xml
@@ -42,14 +42,14 @@
 	<testCase id="030161">
 		<class>Initialize_eNB</class>
 		<desc>Initialize DU (FDD/Band7/20MHz)</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/du.band7.tm1.100PRB.usrpb210.conf</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/du.band7.tm1.100PRB.usrpb210.conf --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 		<eNB_instance>1</eNB_instance>
 	</testCase>
 
 	<testCase id="030162">
 		<class>Initialize_eNB</class>
 		<desc>Initialize CU (FDD/Band7/20MHz)</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/cu.band7.tm1.100PRB.conf</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/cu.band7.tm1.100PRB.conf --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 		<eNB_instance>0</eNB_instance>
 	</testCase>
 
diff --git a/ci-scripts/xml_files/fr1_lte_2x2_quectel.xml b/ci-scripts/xml_files/fr1_lte_2x2_quectel.xml
index ae7a4c92bebf7a31748ee2856f68fbb1c1988dc6..45a4f065e9b6436b5ec94ca4caf0cd548565e4df 100644
--- a/ci-scripts/xml_files/fr1_lte_2x2_quectel.xml
+++ b/ci-scripts/xml_files/fr1_lte_2x2_quectel.xml
@@ -59,7 +59,7 @@
 	<testCase id="030000">
 		<class>Initialize_eNB</class>
 		<desc>Initialize eNB</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band38.lte_2x2.100PRB.usrpn310.conf --usrp-tx-thread-config 1 --thread-pool 0,2,4,6</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band38.lte_2x2.100PRB.usrpn310.conf --usrp-tx-thread-config 1 --thread-pool 0,2,4,6 --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 		<eNB_instance>0</eNB_instance>
 		<eNB_serverId>0</eNB_serverId>
 		<air_interface>lte</air_interface>
diff --git a/ci-scripts/xml_files/fr1_nsa_2x2_quectel.xml b/ci-scripts/xml_files/fr1_nsa_2x2_quectel.xml
index 2516af942900373d0ac73b9573fdc39d1cf2800a..045466a8adaf46b6c8600c57d24dece37d4de949 100644
--- a/ci-scripts/xml_files/fr1_nsa_2x2_quectel.xml
+++ b/ci-scripts/xml_files/fr1_nsa_2x2_quectel.xml
@@ -61,7 +61,7 @@
 	<testCase id="030000">
 		<class>Initialize_eNB</class>
 		<desc>Initialize eNB</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band38.nsa_2x2.100PRB.usrpn310.conf --usrp-tx-thread-config 1 --thread-pool 0,2,4,6</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band38.nsa_2x2.100PRB.usrpn310.conf --usrp-tx-thread-config 1 --thread-pool 0,2,4,6 --log_config.global_log_options level,nocolor,time,line_num,function</Initialize_eNB_args>
 		<eNB_instance>0</eNB_instance>
 		<eNB_serverId>0</eNB_serverId>
 		<air_interface>lte</air_interface>
@@ -74,7 +74,7 @@
 	<testCase id="040000">
 		<class>Initialize_eNB</class>
 		<desc>Initialize gNB</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/gnb.band78.nsa_2x2.106PRB.usrpn310.conf -q --usrp-tx-thread-config 1</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/gnb.band78.nsa_2x2.106PRB.usrpn310.conf -q --usrp-tx-thread-config 1 --log_config.global_log_options level,nocolor,time,line_num,function</Initialize_eNB_args>
 		<eNB_instance>1</eNB_instance>
 		<eNB_serverId>1</eNB_serverId>
 		<air_interface>nr</air_interface>
diff --git a/ci-scripts/xml_files/fr1_nsa_2x2_quectel_attach_detach.xml b/ci-scripts/xml_files/fr1_nsa_2x2_quectel_attach_detach.xml
index 52cf1ec6e8fe6fe867299914ce091de6a64c27a0..6fe23e022b600e379e6d9c624fde29d35d1f802a 100644
--- a/ci-scripts/xml_files/fr1_nsa_2x2_quectel_attach_detach.xml
+++ b/ci-scripts/xml_files/fr1_nsa_2x2_quectel_attach_detach.xml
@@ -81,7 +81,7 @@
 	<testCase id="031000">
 		<class>Initialize_eNB</class>
 		<desc>Initialize eNB</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band38.nsa_2x2.100PRB.usrpn310.conf --usrp-tx-thread-config 1 --thread-pool 0,2,4,6</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band38.nsa_2x2.100PRB.usrpn310.conf --usrp-tx-thread-config 1 --thread-pool 0,2,4,6 --log_config.global_log_options level,nocolor,time,line_num,function</Initialize_eNB_args>
 		<eNB_instance>0</eNB_instance>
 		<eNB_serverId>0</eNB_serverId>
 		<air_interface>lte</air_interface>
@@ -94,7 +94,7 @@
 	<testCase id="041000">
 		<class>Initialize_eNB</class>
 		<desc>Initialize gNB</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/gnb.band78.nsa_2x2.106PRB.usrpn310.conf -q --usrp-tx-thread-config 1</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/gnb.band78.nsa_2x2.106PRB.usrpn310.conf -q --usrp-tx-thread-config 1 --log_config.global_log_options level,nocolor,time,line_num,function</Initialize_eNB_args>
 		<eNB_instance>1</eNB_instance>
 		<eNB_serverId>1</eNB_serverId>
 		<air_interface>nr</air_interface>
diff --git a/ci-scripts/xml_files/fr1_nsa_base.xml b/ci-scripts/xml_files/fr1_nsa_base.xml
index 96bdc79f0f9138e2d43597237575014f28700c04..dec24f7d93046a0dd46412df7d037ce6d7856eb0 100644
--- a/ci-scripts/xml_files/fr1_nsa_base.xml
+++ b/ci-scripts/xml_files/fr1_nsa_base.xml
@@ -70,7 +70,7 @@
 	<testCase id="030000">
 		<class>Initialize_eNB</class>
 		<desc>Initialize eNB</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.fr1.25PRB.usrpb210.conf</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.fr1.25PRB.usrpb210.conf --log_config.global_log_options level,nocolor,time,line_num,function</Initialize_eNB_args>
 		<eNB_instance>0</eNB_instance>
 		<eNB_serverId>0</eNB_serverId>
 		<air_interface>lte</air_interface>
@@ -80,7 +80,7 @@
 	<testCase id="040000">
 		<class>Initialize_eNB</class>
 		<desc>Initialize gNB</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/gnb.band78.tm1.fr1.106PRB.usrpb210.conf -E</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/gnb.band78.tm1.fr1.106PRB.usrpb210.conf -E --log_config.global_log_options level,nocolor,time,line_num,function</Initialize_eNB_args>
 		<eNB_instance>1</eNB_instance>
 		<eNB_serverId>1</eNB_serverId>
 		<air_interface>nr</air_interface>
diff --git a/ci-scripts/xml_files/fr1_nsa_quectel.xml b/ci-scripts/xml_files/fr1_nsa_quectel.xml
index 6414f09b6b8ca72baeb64df714e15f1ef71c2fbe..9d430417c84b80306c3d9ddf2d788717e8d4d16a 100644
--- a/ci-scripts/xml_files/fr1_nsa_quectel.xml
+++ b/ci-scripts/xml_files/fr1_nsa_quectel.xml
@@ -64,7 +64,7 @@
 	<testCase id="030000">
 		<class>Initialize_eNB</class>
 		<desc>Initialize eNB</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.fr1.25PRB.usrpb210.conf</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.fr1.25PRB.usrpb210.conf --log_config.global_log_options level,nocolor,time,line_num,function</Initialize_eNB_args>
 		<eNB_instance>0</eNB_instance>
 		<eNB_serverId>0</eNB_serverId>
 		<air_interface>lte</air_interface>
@@ -75,7 +75,7 @@
 	<testCase id="040000">
 		<class>Initialize_eNB</class>
 		<desc>Initialize gNB</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/gnb.band78.tm1.fr1.106PRB.usrpb210.conf -E -q --RUs.[0].sdr_addrs "serial=30C51D4"</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/gnb.band78.tm1.fr1.106PRB.usrpb210.conf -E -q --RUs.[0].sdr_addrs "serial=30C51D4" --log_config.global_log_options level,nocolor,time,line_num,function</Initialize_eNB_args>
 		<eNB_instance>1</eNB_instance>
 		<eNB_serverId>1</eNB_serverId>
 		<air_interface>nr</air_interface>
diff --git a/ci-scripts/xml_files/fr1_nsa_quectel_attach_detach.xml b/ci-scripts/xml_files/fr1_nsa_quectel_attach_detach.xml
index 2263f731c582219bda3c234f8c6246499f8f8269..68d2f94af920beb5fcd1c8e07b534d6a74f8687e 100644
--- a/ci-scripts/xml_files/fr1_nsa_quectel_attach_detach.xml
+++ b/ci-scripts/xml_files/fr1_nsa_quectel_attach_detach.xml
@@ -81,7 +81,7 @@
 	<testCase id="030000">
 		<class>Initialize_eNB</class>
 		<desc>Initialize eNB</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.fr1.25PRB.usrpb210.conf</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.fr1.25PRB.usrpb210.conf --log_config.global_log_options level,nocolor,time,line_num,function</Initialize_eNB_args>
 		<eNB_instance>0</eNB_instance>
 		<eNB_serverId>0</eNB_serverId>
 		<air_interface>lte</air_interface>
@@ -92,7 +92,7 @@
 	<testCase id="040000">
 		<class>Initialize_eNB</class>
 		<desc>Initialize gNB</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/gnb.band78.tm1.fr1.106PRB.usrpb210.conf -E -q</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/gnb.band78.tm1.fr1.106PRB.usrpb210.conf -E -q --log_config.global_log_options level,nocolor,time,line_num,function</Initialize_eNB_args>
 		<eNB_instance>1</eNB_instance>
 		<eNB_serverId>1</eNB_serverId>
 		<air_interface>nr</air_interface>
diff --git a/ci-scripts/xml_files/fr1_nsa_quectel_long.xml b/ci-scripts/xml_files/fr1_nsa_quectel_long.xml
index 21ff7a63c5b3dfbc4712dd036233b6fdb66f61e1..c3801068a9354160bcd94a1c8f5e2be439eb5013 100644
--- a/ci-scripts/xml_files/fr1_nsa_quectel_long.xml
+++ b/ci-scripts/xml_files/fr1_nsa_quectel_long.xml
@@ -61,7 +61,7 @@
 	<testCase id="030000">
 		<class>Initialize_eNB</class>
 		<desc>Initialize eNB</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.fr1.25PRB.usrpb210.conf</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.fr1.25PRB.usrpb210.conf --log_config.global_log_options level,nocolor,time,line_num,function</Initialize_eNB_args>
 		<eNB_instance>0</eNB_instance>
 		<eNB_serverId>0</eNB_serverId>
 		<air_interface>lte</air_interface>
@@ -72,7 +72,7 @@
 	<testCase id="040000">
 		<class>Initialize_eNB</class>
 		<desc>Initialize gNB</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/gnb.band78.tm1.fr1.106PRB.usrpb210.conf -E -q</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/gnb.band78.tm1.fr1.106PRB.usrpb210.conf -E -q --log_config.global_log_options level,nocolor,time,line_num,function</Initialize_eNB_args>
 		<eNB_instance>1</eNB_instance>
 		<eNB_serverId>1</eNB_serverId>
 		<air_interface>nr</air_interface>
diff --git a/ci-scripts/xml_files/fr1_sa_oaiue_b200.xml b/ci-scripts/xml_files/fr1_sa_oaiue_b200.xml
index 6c359abb8d46054803580b7879174166bb3d5b13..774d5751c5949fc468cb660dbbbd6fb530555827 100644
--- a/ci-scripts/xml_files/fr1_sa_oaiue_b200.xml
+++ b/ci-scripts/xml_files/fr1_sa_oaiue_b200.xml
@@ -42,7 +42,7 @@
 		<class>Initialize_OAI_UE</class>
 		<desc>Initialize OAI UE</desc>
 		<air_interface>nr</air_interface>
-		<Initialize_OAI_UE_args>--sa -O ../../../ci-scripts/conf_files/ue.sa.conf --usrp-args "serial=30C51D1" --numerology 1 -r 106 --band 78 -C 3319680000 --nokrnmod 1 --ue-txgain 0 -E</Initialize_OAI_UE_args>
+		<Initialize_OAI_UE_args>--sa -O ../../../ci-scripts/conf_files/ue.sa.conf --usrp-args "serial=30C51D1" --numerology 1 -r 106 --band 78 -C 3319680000 --nokrnmod 1 --ue-txgain 0 -E --log_config.global_log_options level,nocolor,time</Initialize_OAI_UE_args>
 	</testCase>
 
 	<testCase id="010002">
@@ -54,7 +54,7 @@
 	<testCase id="040000">
 		<class>Initialize_eNB</class>
 		<desc>Initialize gNB</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/gnb.band78.sa.fr1.106PRB.usrpn310.conf --sa -q --usrp-tx-thread-config 1</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/gnb.band78.sa.fr1.106PRB.usrpn310.conf --sa -q --usrp-tx-thread-config 1 --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 		<eNB_instance>0</eNB_instance>
 		<eNB_serverId>0</eNB_serverId>
 		<air_interface>nr</air_interface>
diff --git a/ci-scripts/xml_files/fr1_sa_oaiue_n310.xml b/ci-scripts/xml_files/fr1_sa_oaiue_n310.xml
index cd79e49f2c0d416a02bf002f2ed457bfd2d0c273..55852ad79be335cb9a06f6f328490a09e4b3684b 100644
--- a/ci-scripts/xml_files/fr1_sa_oaiue_n310.xml
+++ b/ci-scripts/xml_files/fr1_sa_oaiue_n310.xml
@@ -42,7 +42,7 @@
 		<class>Initialize_OAI_UE</class>
 		<desc>Initialize OAI UE (N310)</desc>
 		<air_interface>nr</air_interface>
-		<Initialize_OAI_UE_args>--sa -O ../../../ci-scripts/conf_files/ue.sa.conf --usrp-args "mgmt_addr=192.168.18.241,second_addr=192.168.10.2"  --numerology 1 -r 106 --band 78 -C 3319680000 --nokrnmod 1 --ue-txgain 0 --ue-rxgain 70 --ue-fo-compensation </Initialize_OAI_UE_args>
+		<Initialize_OAI_UE_args>--sa -O ../../../ci-scripts/conf_files/ue.sa.conf --usrp-args "mgmt_addr=192.168.18.241,second_addr=192.168.10.2"  --numerology 1 -r 106 --band 78 -C 3319680000 --nokrnmod 1 --ue-txgain 0 --ue-rxgain 70 --ue-fo-compensation --log_config.global_log_options level,nocolor,time</Initialize_OAI_UE_args>
 	</testCase>
 
 	<testCase id="010002">
@@ -54,7 +54,7 @@
 	<testCase id="040000">
 		<class>Initialize_eNB</class>
 		<desc>Initialize gNB</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/gnb.band78.sa.fr1.106PRB.usrpn310.conf --sa --usrp-tx-thread-config 1</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/gnb.band78.sa.fr1.106PRB.usrpn310.conf --sa --usrp-tx-thread-config 1 --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 		<eNB_instance>0</eNB_instance>
 		<eNB_serverId>0</eNB_serverId>
 		<air_interface>nr</air_interface>
diff --git a/ci-scripts/xml_files/fr1_sa_oaiue_x300.xml b/ci-scripts/xml_files/fr1_sa_oaiue_x300.xml
index d527737b3c5e89323d8bcfae4c318bee848375f0..509fef9e8ab5aebb2ef9d6709b8fecfcb81612c1 100644
--- a/ci-scripts/xml_files/fr1_sa_oaiue_x300.xml
+++ b/ci-scripts/xml_files/fr1_sa_oaiue_x300.xml
@@ -42,7 +42,7 @@
 		<class>Initialize_OAI_UE</class>
 		<desc>Initialize OAI UE (X300)</desc>
 		<air_interface>nr</air_interface>
-		<Initialize_OAI_UE_args>--sa -O ../../../ci-scripts/conf_files/ue.sa.conf --usrp-args "addr=192.168.60.2"  --numerology 1 -r 106 --band 78 -C 3319680000 --nokrnmod 1 --ue-txgain 0 --ue-rxgain 70 --ue-fo-compensation </Initialize_OAI_UE_args>
+		<Initialize_OAI_UE_args>--sa -O ../../../ci-scripts/conf_files/ue.sa.conf --usrp-args "addr=192.168.60.2"  --numerology 1 -r 106 --band 78 -C 3319680000 --nokrnmod 1 --ue-txgain 0 --ue-rxgain 70 --ue-fo-compensation --log_config.global_log_options level,nocolor,time</Initialize_OAI_UE_args>
 	</testCase>
 
 	<testCase id="010002">
@@ -54,7 +54,7 @@
 	<testCase id="040000">
 		<class>Initialize_eNB</class>
 		<desc>Initialize gNB</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/gnb.band78.sa.fr1.106PRB.usrpn310.conf --sa --usrp-tx-thread-config 1</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/gnb.band78.sa.fr1.106PRB.usrpn310.conf --sa --usrp-tx-thread-config 1 --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 		<eNB_instance>0</eNB_instance>
 		<eNB_serverId>0</eNB_serverId>
 		<air_interface>nr</air_interface>
diff --git a/ci-scripts/xml_files/fr1_sa_quectel.xml b/ci-scripts/xml_files/fr1_sa_quectel.xml
index 4db5bb64a513ff27f956113148770c395fb0e66e..518e9dfe81aae8298293ad2a0d258f010101417c 100644
--- a/ci-scripts/xml_files/fr1_sa_quectel.xml
+++ b/ci-scripts/xml_files/fr1_sa_quectel.xml
@@ -58,7 +58,7 @@
 	<testCase id="040000">
 		<class>Initialize_eNB</class>
 		<desc>Initialize gNB</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/gnb.band78.sa.fr1.106PRB.2x2.usrpn310.conf --sa -q --usrp-tx-thread-config 1</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/gnb.band78.sa.fr1.106PRB.2x2.usrpn310.conf --sa -q --usrp-tx-thread-config 1 --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 		<eNB_instance>0</eNB_instance>
 		<eNB_serverId>0</eNB_serverId>
 		<air_interface>nr</air_interface>
@@ -84,9 +84,9 @@
 		<class>Ping</class>
 		<desc>Ping: 20pings in 20sec</desc>
 		<id>nrmodule2_quectel</id>
-		<ping_args>-c 20</ping_args>
+		<ping_args>-c 40</ping_args>
 		<ping_packetloss_threshold>1</ping_packetloss_threshold>
-		<ping_rttavg_threshold>15</ping_rttavg_threshold>
+		<ping_rttavg_threshold>20</ping_rttavg_threshold>
 	</testCase>
 
 	<testCase id="050001">
@@ -95,7 +95,7 @@
 		<id>nrmodule2_quectel</id>
 		<ping_args>-c 100 -i 0,2</ping_args>
 		<ping_packetloss_threshold>1</ping_packetloss_threshold>
-		<ping_rttavg_threshold>15</ping_rttavg_threshold>
+		<ping_rttavg_threshold>20</ping_rttavg_threshold>
 	</testCase>
 
 	<testCase id="070000">
diff --git a/ci-scripts/xml_files/fr1_sa_quectel_162prb.xml b/ci-scripts/xml_files/fr1_sa_quectel_162prb.xml
index 20886787071832e8c8cda7e0b839c1519c812f43..f465b320b6555f414f7d696d401a62e93755e001 100644
--- a/ci-scripts/xml_files/fr1_sa_quectel_162prb.xml
+++ b/ci-scripts/xml_files/fr1_sa_quectel_162prb.xml
@@ -58,7 +58,7 @@
 	<testCase id="040000">
 		<class>Initialize_eNB</class>
 		<desc>Initialize gNB</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/gnb.band78.sa.fr1.162PRB.2x2.usrpn310.conf --sa -q --usrp-tx-thread-config 1</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/gnb.band78.sa.fr1.162PRB.2x2.usrpn310.conf --sa -q --usrp-tx-thread-config 1 --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 		<eNB_instance>0</eNB_instance>
 		<eNB_serverId>0</eNB_serverId>
 		<air_interface>nr</air_interface>
diff --git a/ci-scripts/xml_files/fr1_sa_quectel_stages.xml b/ci-scripts/xml_files/fr1_sa_quectel_stages.xml
index a9922bec52e4b6842d32430192f23d3e03572465..4b169f85e99c1e5874aecc969bed6adcfa762d6f 100644
--- a/ci-scripts/xml_files/fr1_sa_quectel_stages.xml
+++ b/ci-scripts/xml_files/fr1_sa_quectel_stages.xml
@@ -65,7 +65,7 @@
 	<testCase id="040000">
 		<class>Initialize_eNB</class>
 		<desc>Initialize gNB</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/gnb.band78.sa.fr1.106PRB.2x2.usrpn310.conf --sa -q --usrp-tx-thread-config 1</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/gnb.band78.sa.fr1.106PRB.2x2.usrpn310.conf --sa -q --usrp-tx-thread-config 1 --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 		<eNB_instance>0</eNB_instance>
 		<eNB_serverId>0</eNB_serverId>
 		<air_interface>nr</air_interface>
@@ -91,9 +91,9 @@
 		<class>Ping</class>
 		<desc>Ping: 20pings in 20sec</desc>
 		<id>nrmodule2_quectel</id>
-		<ping_args>-c 20</ping_args>
+		<ping_args>-c 40</ping_args>
 		<ping_packetloss_threshold>1</ping_packetloss_threshold>
-		<ping_rttavg_threshold>15</ping_rttavg_threshold>
+		<ping_rttavg_threshold>20</ping_rttavg_threshold>
 	</testCase>
 
 
diff --git a/ci-scripts/xml_files/fr1_sa_quectel_stages_162prb.xml b/ci-scripts/xml_files/fr1_sa_quectel_stages_162prb.xml
index 4b2400a4acf3c954648ccb4b47ceb8ca7e82fcd3..c28791e555ec67fb41261a6a1b7ab183c3f68004 100644
--- a/ci-scripts/xml_files/fr1_sa_quectel_stages_162prb.xml
+++ b/ci-scripts/xml_files/fr1_sa_quectel_stages_162prb.xml
@@ -67,7 +67,7 @@
 	<testCase id="040000">
 		<class>Initialize_eNB</class>
 		<desc>Initialize gNB</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/gnb.band78.sa.fr1.162PRB.2x2.usrpn310.conf --sa -q --usrp-tx-thread-config 1</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/gnb.band78.sa.fr1.162PRB.2x2.usrpn310.conf --sa -q --usrp-tx-thread-config 1 --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 		<eNB_instance>0</eNB_instance>
 		<eNB_serverId>0</eNB_serverId>
 		<air_interface>nr</air_interface>
diff --git a/ci-scripts/xml_files/fr1_usrp210_band7_test_05mhz_tm1.xml b/ci-scripts/xml_files/fr1_usrp210_band7_test_05mhz_tm1.xml
index ea25d5b6946fedb72fee0a2965c182413fd540a1..4d78b5b0a9cefd70050a6d7845960226fb39f0e3 100644
--- a/ci-scripts/xml_files/fr1_usrp210_band7_test_05mhz_tm1.xml
+++ b/ci-scripts/xml_files/fr1_usrp210_band7_test_05mhz_tm1.xml
@@ -41,7 +41,7 @@
 	<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 --eNBs.[0].plmn_list.[0].mcc 311 --eNBs.[0].plmn_list.[0].mnc 480 --eNBs.[0].plmn_list.[0].mnc_length 3 --eNBs.[0].component_carriers.[0].Nid_cell 10</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.25PRB.usrpb210.conf --eNBs.[0].plmn_list.[0].mcc 311 --eNBs.[0].plmn_list.[0].mnc 480 --eNBs.[0].plmn_list.[0].mnc_length 3 --eNBs.[0].component_carriers.[0].Nid_cell 10 --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 	</testCase>
 
 	<testCase id="030201">
diff --git a/ci-scripts/xml_files/gnb_nr_ue_usrp_run.xml b/ci-scripts/xml_files/gnb_nr_ue_usrp_run.xml
index b1e9697be2f0e9cba104a7d15ceef8041ec4df8c..a74dd26137a4045dee965376df1223555e0073f0 100644
--- a/ci-scripts/xml_files/gnb_nr_ue_usrp_run.xml
+++ b/ci-scripts/xml_files/gnb_nr_ue_usrp_run.xml
@@ -33,7 +33,7 @@
         <testCase id="090101">
                 <class>Initialize_eNB</class>
                 <desc>Initialize gNB USRP</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/gnb.band78.tm1.106PRB.usrpn300.conf --phy-test</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/gnb.band78.tm1.106PRB.usrpn300.conf --phy-test --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 		<air_interface>NR</air_interface>
         </testCase>
 
@@ -52,7 +52,7 @@
         <testCase id="090102">
                 <class>Initialize_OAI_UE</class>
                 <desc>Initialize NR UE USRP</desc>
-		<Initialize_OAI_UE_args>--phy-test --usrp-args "addr=192.168.30.2,second_addr=192.168.50.2,clock_source=external,time_source=external" --ue-rxgain 50  --rrc_config_path . --dlsch-parallel 4 </Initialize_OAI_UE_args>
+		<Initialize_OAI_UE_args>--phy-test --usrp-args "addr=192.168.30.2,second_addr=192.168.50.2,clock_source=external,time_source=external" --ue-rxgain 50  --rrc_config_path . --dlsch-parallel 4 --log_config.global_log_options level,nocolor,time</Initialize_OAI_UE_args>
 		<air_interface>NR</air_interface>
         </testCase>
 
diff --git a/ci-scripts/xml_files/gnb_nr_ue_usrp_run_multi_thread.xml b/ci-scripts/xml_files/gnb_nr_ue_usrp_run_multi_thread.xml
index 2c44ead8ea7fda1befae4319f178f471e9ac8e8d..f91077aacfda89af28d5dee9190554b18e5a2add 100644
--- a/ci-scripts/xml_files/gnb_nr_ue_usrp_run_multi_thread.xml
+++ b/ci-scripts/xml_files/gnb_nr_ue_usrp_run_multi_thread.xml
@@ -33,7 +33,7 @@
         <testCase id="090103">
                 <class>Initialize_eNB</class>
                 <desc>Initialize gNB USRP (Tx-Write-Threading enabled)</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/gnb.band78.tm1.106PRB.usrpn300.conf --phy-test --usrp-tx-thread-config 1</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/gnb.band78.tm1.106PRB.usrpn300.conf --phy-test --usrp-tx-thread-config 1 --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 		<air_interface>NR</air_interface>
         </testCase>
 
@@ -52,7 +52,7 @@
         <testCase id="090104">
                 <class>Initialize_OAI_UE</class>
                 <desc>Initialize NR UE USRP</desc>
-		<Initialize_OAI_UE_args>--phy-test --usrp-args "addr=192.168.30.2,second_addr=192.168.50.2,clock_source=external,time_source=external" --ue-rxgain 75  --rrc_config_path . --dlsch-parallel 4 </Initialize_OAI_UE_args>
+		<Initialize_OAI_UE_args>--phy-test --usrp-args "addr=192.168.30.2,second_addr=192.168.50.2,clock_source=external,time_source=external" --ue-rxgain 75  --rrc_config_path . --dlsch-parallel 4 --log_config.global_log_options level,nocolor,time</Initialize_OAI_UE_args>
 		<air_interface>NR</air_interface>
         </testCase>
 
diff --git a/ci-scripts/xml_files/gnb_phytest_usrp_run.xml b/ci-scripts/xml_files/gnb_phytest_usrp_run.xml
index 9e798afdc488ca4d13b4c88d7cd4d1976fbbdfb7..9365d7f12ee6fd382b9e6d475a21ac0a146cf6ca 100644
--- a/ci-scripts/xml_files/gnb_phytest_usrp_run.xml
+++ b/ci-scripts/xml_files/gnb_phytest_usrp_run.xml
@@ -33,7 +33,7 @@
         <testCase id="090101">
                 <class>Initialize_eNB</class>
                 <desc>Initialize gNB USRP</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/gnb.band78.tm1.106PRB.usrpn300.conf --phy-test -q -U 787200 -T 106 -t 28 -D 130175 -m 28 -M 106</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/gnb.band78.tm1.106PRB.usrpn300.conf --phy-test -q -U 787200 -T 106 -t 28 -D 130175 -m 28 -M 106 --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 		<air_interface>NR</air_interface>
         </testCase>
 
diff --git a/ci-scripts/xml_files/if4p5_usrp210_band40_test_05mhz.xml b/ci-scripts/xml_files/if4p5_usrp210_band40_test_05mhz.xml
index 06763aa99531e47b968fdaafbe76589a61b2b8d3..715dc0e3153e540eefd882fff711f9d5a366fa9b 100644
--- a/ci-scripts/xml_files/if4p5_usrp210_band40_test_05mhz.xml
+++ b/ci-scripts/xml_files/if4p5_usrp210_band40_test_05mhz.xml
@@ -35,14 +35,14 @@
 	<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 --RUs.[0].max_rxgain 125</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/rru.tdd.band40.conf --RUs.[0].max_rxgain 125 --log_config.global_log_options level,nocolor,time</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>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/rcc.band40.tm1.25PRB.FairScheduler.usrpb210.conf --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 		<eNB_instance>1</eNB_instance>
 	</testCase>
 	
diff --git a/ci-scripts/xml_files/if4p5_usrp210_band40_test_10mhz.xml b/ci-scripts/xml_files/if4p5_usrp210_band40_test_10mhz.xml
index 9224c67fe7ba02b3f0388b12063bec6cd66bcf6c..f755a7ec96cc547e7cae4333dcad22cfc825001f 100644
--- a/ci-scripts/xml_files/if4p5_usrp210_band40_test_10mhz.xml
+++ b/ci-scripts/xml_files/if4p5_usrp210_band40_test_10mhz.xml
@@ -38,14 +38,14 @@
 	<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 --RUs.[0].max_rxgain 120</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/rru.tdd.band40.conf --RUs.[0].max_rxgain 120 --log_config.global_log_options level,nocolor,time</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>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/rcc.band40.tm1.50PRB.FairScheduler.usrpb210.conf --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 		<eNB_instance>1</eNB_instance>
 	</testCase>
 
diff --git a/ci-scripts/xml_files/if4p5_usrp210_band40_test_20mhz.xml b/ci-scripts/xml_files/if4p5_usrp210_band40_test_20mhz.xml
index cb54ba31eeed23f203777d4f7451af63d86a1c4c..4e84c47faf324caffa467cc114a292cd19dba111 100644
--- a/ci-scripts/xml_files/if4p5_usrp210_band40_test_20mhz.xml
+++ b/ci-scripts/xml_files/if4p5_usrp210_band40_test_20mhz.xml
@@ -36,14 +36,14 @@
 	<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>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/rru.tdd.band40.conf --log_config.global_log_options level,nocolor,time</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 --MACRLCs.[0].scheduler_mode default</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/rcc.band40.tm1.100PRB.FairScheduler.usrpb210.conf --MACRLCs.[0].scheduler_mode default --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 		<eNB_instance>1</eNB_instance>
 	</testCase>
 
diff --git a/ci-scripts/xml_files/if4p5_usrp210_band7_test_05mhz.xml b/ci-scripts/xml_files/if4p5_usrp210_band7_test_05mhz.xml
index d72633159df638556f0429d4a35d8f6d114a4bfd..fc3fe29992e1705dbb4ba59936bbf3516dc7ce6c 100644
--- a/ci-scripts/xml_files/if4p5_usrp210_band7_test_05mhz.xml
+++ b/ci-scripts/xml_files/if4p5_usrp210_band7_test_05mhz.xml
@@ -35,14 +35,14 @@
 	<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 --RUs.[0].max_rxgain 125</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/rru.fdd.band7.conf --RUs.[0].max_rxgain 125 --log_config.global_log_options level,nocolor,time</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>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/rcc.band7.tm1.if4p5.lo.25PRB.usrpb210.conf --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 		<eNB_instance>0</eNB_instance>
 	</testCase>
 
diff --git a/ci-scripts/xml_files/if4p5_usrp210_band7_test_10mhz.xml b/ci-scripts/xml_files/if4p5_usrp210_band7_test_10mhz.xml
index 98e1aed575352562e5a7c311641328f9ea746700..8aa07a1c439db47638e7d9b4b29372ac93e0e9c2 100644
--- a/ci-scripts/xml_files/if4p5_usrp210_band7_test_10mhz.xml
+++ b/ci-scripts/xml_files/if4p5_usrp210_band7_test_10mhz.xml
@@ -35,14 +35,14 @@
 	<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 --RUs.[0].max_rxgain 120</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/rru.fdd.band7.conf --RUs.[0].max_rxgain 120 --log_config.global_log_options level,nocolor,time</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>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/rcc.band7.tm1.if4p5.lo.50PRB.usrpb210.conf --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 		<eNB_instance>0</eNB_instance>
 	</testCase>
 
diff --git a/ci-scripts/xml_files/if4p5_usrp210_band7_test_20mhz.xml b/ci-scripts/xml_files/if4p5_usrp210_band7_test_20mhz.xml
index 2cf4e0fbf5310febc64e7b7b56c7954680aad6a9..01f26bdf0fbbdaae38bb62e2b7ee06904fbe6da0 100644
--- a/ci-scripts/xml_files/if4p5_usrp210_band7_test_20mhz.xml
+++ b/ci-scripts/xml_files/if4p5_usrp210_band7_test_20mhz.xml
@@ -35,14 +35,14 @@
 	<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>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/rru.fdd.band7.conf --log_config.global_log_options level,nocolor,time</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>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/rcc.band7.tm1.if4p5.lo.100PRB.usrpb210.conf --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 		<eNB_instance>0</eNB_instance>
 	</testCase>
 
diff --git a/ci-scripts/xml_files/inria/enb_ue_usrp210_band7_test_05mhz_tm1.xml b/ci-scripts/xml_files/inria/enb_ue_usrp210_band7_test_05mhz_tm1.xml
index ae348b6b259d94f44ac379d682079ccf8e355878..c2fb2e8e2e11f9212e2d64f1d285a5e22253310b 100644
--- a/ci-scripts/xml_files/inria/enb_ue_usrp210_band7_test_05mhz_tm1.xml
+++ b/ci-scripts/xml_files/inria/enb_ue_usrp210_band7_test_05mhz_tm1.xml
@@ -46,7 +46,7 @@
 	<testCase id="030102">
 		<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 --eNBs.[0].rrc_inactivity_threshold 0 --RUs.[0].max_rxgain 120 --eNBs.[0].component_carriers.[0].pusch_p0_Nominal -90 --eNBs.[0].component_carriers.[0].pucch_p0_Nominal -96 --eNBs.[0].tracking_area_code 600 --eNBs.[0].plmn_list.[0].mnc 95</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.25PRB.usrpb210.conf --eNBs.[0].rrc_inactivity_threshold 0 --RUs.[0].max_rxgain 120 --eNBs.[0].component_carriers.[0].pusch_p0_Nominal -90 --eNBs.[0].component_carriers.[0].pucch_p0_Nominal -96 --eNBs.[0].tracking_area_code 600 --eNBs.[0].plmn_list.[0].mnc 95 --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 	</testCase>
 
 	<testCase id="030201">
@@ -57,7 +57,7 @@
 	<testCase id="090102">
 		<class>Initialize_OAI_UE</class>
 		<desc>Initialize OAI UE (FDD/Band7/5MHz)</desc>
-		<Initialize_OAI_UE_args>-C 2680000000 -r 25 --ue-rxgain 130 --ue-txgain 1 --ue-max-power -6 --ue-scan-carrier --nokrnmod 1</Initialize_OAI_UE_args>
+		<Initialize_OAI_UE_args>-C 2680000000 -r 25 --ue-rxgain 130 --ue-txgain 1 --ue-max-power -6 --ue-scan-carrier --nokrnmod 1 --log_config.global_log_options level,nocolor,time</Initialize_OAI_UE_args>
 	</testCase>
 
 	<testCase id="090109">
diff --git a/ci-scripts/xml_files/inria/enb_ue_usrp210_band7_test_05mhz_tm1_nos1.xml b/ci-scripts/xml_files/inria/enb_ue_usrp210_band7_test_05mhz_tm1_nos1.xml
index b77c6273e6873a9f37cf3427b4a76bd998cdc49d..d5bdc5a42d68f26dcca9cc71824b6f5e46157210 100644
--- a/ci-scripts/xml_files/inria/enb_ue_usrp210_band7_test_05mhz_tm1_nos1.xml
+++ b/ci-scripts/xml_files/inria/enb_ue_usrp210_band7_test_05mhz_tm1_nos1.xml
@@ -52,7 +52,7 @@
 	<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 --noS1 --eNBs.[0].rrc_inactivity_threshold 0 --RUs.[0].max_rxgain 120 --eNBs.[0].component_carriers.[0].pusch_p0_Nominal -90 --eNBs.[0].component_carriers.[0].pucch_p0_Nominal -96 --eNBs.[0].tracking_area_code 600 --eNBs.[0].plmn_list.[0].mnc 95</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.25PRB.usrpb210.conf --noS1 --eNBs.[0].rrc_inactivity_threshold 0 --RUs.[0].max_rxgain 120 --eNBs.[0].component_carriers.[0].pusch_p0_Nominal -90 --eNBs.[0].component_carriers.[0].pucch_p0_Nominal -96 --eNBs.[0].tracking_area_code 600 --eNBs.[0].plmn_list.[0].mnc 95 --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 	</testCase>
 
 	<testCase id="030201">
@@ -63,7 +63,7 @@
 	<testCase id="090101">
 		<class>Initialize_OAI_UE</class>
 		<desc>Initialize OAI UE (FDD/Band7/5MHz)</desc>
-		<Initialize_OAI_UE_args>-C 2680000000 -r 25 --ue-rxgain 130 --ue-txgain 1 --ue-max-power -6 --ue-scan-carrier --nokrnmod 1 --noS1</Initialize_OAI_UE_args>
+		<Initialize_OAI_UE_args>-C 2680000000 -r 25 --ue-rxgain 130 --ue-txgain 1 --ue-max-power -6 --ue-scan-carrier --nokrnmod 1 --noS1 --log_config.global_log_options level,nocolor,time</Initialize_OAI_UE_args>
 	</testCase>
 
 	<testCase id="090109">
diff --git a/ci-scripts/xml_files/inria/enb_usrp210_band7_test_05mhz_tm1.xml b/ci-scripts/xml_files/inria/enb_usrp210_band7_test_05mhz_tm1.xml
index df41385f83899c751ba1e492a45fff139680c2e8..d0f94dc56029dc7bf8c34806630bb0ff91b5dac1 100644
--- a/ci-scripts/xml_files/inria/enb_usrp210_band7_test_05mhz_tm1.xml
+++ b/ci-scripts/xml_files/inria/enb_usrp210_band7_test_05mhz_tm1.xml
@@ -93,7 +93,7 @@
 	<testCase id="030103">
 		<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 --eNBs.[0].rrc_inactivity_threshold 0 --RUs.[0].max_rxgain 120 --eNBs.[0].component_carriers.[0].pusch_p0_Nominal -90 --eNBs.[0].component_carriers.[0].pucch_p0_Nominal -96 --eNBs.[0].tracking_area_code 600 --eNBs.[0].plmn_list.[0].mnc 95</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.25PRB.usrpb210.conf --eNBs.[0].rrc_inactivity_threshold 0 --RUs.[0].max_rxgain 120 --eNBs.[0].component_carriers.[0].pusch_p0_Nominal -90 --eNBs.[0].component_carriers.[0].pucch_p0_Nominal -96 --eNBs.[0].tracking_area_code 600 --eNBs.[0].plmn_list.[0].mnc 95 --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 	</testCase>
 
 	<testCase id="030201">
diff --git a/ci-scripts/xml_files/inria/enb_usrp210_band7_x2_ho_test_05Mhz_tm1.xml b/ci-scripts/xml_files/inria/enb_usrp210_band7_x2_ho_test_05Mhz_tm1.xml
index 852f48c370e2b2a7455857d6c07250cada0030af..b4b20c12390258c6f99bac9269b028338520244a 100644
--- a/ci-scripts/xml_files/inria/enb_usrp210_band7_x2_ho_test_05Mhz_tm1.xml
+++ b/ci-scripts/xml_files/inria/enb_usrp210_band7_x2_ho_test_05Mhz_tm1.xml
@@ -64,7 +64,7 @@
 	<testCase id="030104">
 		<class>Initialize_eNB</class>
 		<desc>Initialize eNB #0 (FDD/Band7/5MHz)</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.25PRB.usrpb210.conf --eNBs.[0].rrc_inactivity_threshold 0 --RUs.[0].max_rxgain 120 --eNBs.[0].component_carriers.[0].pusch_p0_Nominal -90 --eNBs.[0].component_carriers.[0].pucch_p0_Nominal -96 --eNBs.[0].tracking_area_code 600 --eNBs.[0].plmn_list.[0].mnc 95 --eNBs.[0].enable_measurement_reports yes --eNBs.[0].enable_x2 yes --eNBs.[0].nr_cellid 123456</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.25PRB.usrpb210.conf --eNBs.[0].rrc_inactivity_threshold 0 --RUs.[0].max_rxgain 120 --eNBs.[0].component_carriers.[0].pusch_p0_Nominal -90 --eNBs.[0].component_carriers.[0].pucch_p0_Nominal -96 --eNBs.[0].tracking_area_code 600 --eNBs.[0].plmn_list.[0].mnc 95 --eNBs.[0].enable_measurement_reports yes --eNBs.[0].enable_x2 yes --eNBs.[0].nr_cellid 123456 --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 		<eNB_instance>0</eNB_instance>
 		<eNB_serverId>0</eNB_serverId>
 	</testCase>
@@ -72,7 +72,7 @@
 	<testCase id="030105">
 		<class>Initialize_eNB</class>
 		<desc>Initialize eNB #1 (FDD/Band7/5MHz)</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.25PRB.slave.usrpb210.conf --eNBs.[0].rrc_inactivity_threshold 0 --RUs.[0].max_rxgain 120 --eNBs.[0].component_carriers.[0].pusch_p0_Nominal -90 --eNBs.[0].component_carriers.[0].pucch_p0_Nominal -96 --eNBs.[0].tracking_area_code 600 --eNBs.[0].plmn_list.[0].mnc 95 --eNBs.[0].enable_measurement_reports yes --eNBs.[0].enable_x2 yes --eNBs.[0].nr_cellid 98765</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band7.tm1.25PRB.slave.usrpb210.conf --eNBs.[0].rrc_inactivity_threshold 0 --RUs.[0].max_rxgain 120 --eNBs.[0].component_carriers.[0].pusch_p0_Nominal -90 --eNBs.[0].component_carriers.[0].pucch_p0_Nominal -96 --eNBs.[0].tracking_area_code 600 --eNBs.[0].plmn_list.[0].mnc 95 --eNBs.[0].enable_measurement_reports yes --eNBs.[0].enable_x2 yes --eNBs.[0].nr_cellid 98765 --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 		<eNB_instance>1</eNB_instance>
 		<eNB_serverId>1</eNB_serverId>
 	</testCase>
diff --git a/ci-scripts/xml_files/multi_rru_band38_test_10mhz_tm1.xml b/ci-scripts/xml_files/multi_rru_band38_test_10mhz_tm1.xml
index cca14c0696253f1f87b5c3c88a8f6ffe4c3ff1b0..3875a3df0347d4b91e1e4f3644de83a6bd999ec5 100644
--- a/ci-scripts/xml_files/multi_rru_band38_test_10mhz_tm1.xml
+++ b/ci-scripts/xml_files/multi_rru_band38_test_10mhz_tm1.xml
@@ -42,7 +42,7 @@
 	<testCase id="030111">
 		<class>Initialize_eNB</class>
 		<desc>Initialize RCC (TDD/Band38/10MHz)</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/rcc.band38.tm1.50PRB.multi.rru.conf --noS1</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/rcc.band38.tm1.50PRB.multi.rru.conf --noS1 --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 		<eNB_instance>0</eNB_instance>
 		<eNB_serverId>0</eNB_serverId>
 	</testCase>
@@ -50,7 +50,7 @@
 	<testCase id="030112">
 		<class>Initialize_eNB</class>
 		<desc>Initialize Master RRU (TDD/Band38/10MHz)</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/rru.band38.tm1.master.conf --noS1</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/rru.band38.tm1.master.conf --noS1 --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 		<eNB_instance>1</eNB_instance>
 		<eNB_serverId>1</eNB_serverId>
 	</testCase>
@@ -58,7 +58,7 @@
 	<testCase id="030113">
 		<class>Initialize_eNB</class>
 		<desc>Initialize Slave RRU (TDD/Band38/10MHz)</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/rru.band38.tm1.slave.conf --noS1</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/rru.band38.tm1.slave.conf --noS1 --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 		<eNB_instance>2</eNB_instance>
 		<eNB_serverId>2</eNB_serverId>
 	</testCase>
diff --git a/ci-scripts/xml_files/test_case_list_template.xml b/ci-scripts/xml_files/test_case_list_template.xml
index 69024805beeb58d8d10a99f468697734974cfa8e..1a8871c0370f8c7fa2a7e8aff9de5195a9e8820e 100644
--- a/ci-scripts/xml_files/test_case_list_template.xml
+++ b/ci-scripts/xml_files/test_case_list_template.xml
@@ -42,37 +42,37 @@
 	<testCase id="030101">
 		<class>Initialize_eNB</class>
 		<desc>Initialize eNB (FDD/Band1/5MHz/info)</desc>
-		<Initialize_eNB_args>-O enb.band7.tm1.50PRB.usrpb210.conf</Initialize_eNB_args>
+		<Initialize_eNB_args>-O enb.band7.tm1.50PRB.usrpb210.conf --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 	</testCase>
 
 	<testCase id="030102">
 		<class>Initialize_eNB</class>
 		<desc>Initialize eNB (FDD/Band1/10MHz/info)</desc>
-		<Initialize_eNB_args>-O 10M.band1.FDD.info.conf</Initialize_eNB_args>
+		<Initialize_eNB_args>-O 10M.band1.FDD.info.conf --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 	</testCase>
 
 	<testCase id="030103">
 		<class>Initialize_eNB</class>
 		<desc>Initialize eNB (FDD/Band1/20MHz/info)</desc>
-		<Initialize_eNB_args>-O 20M.band1.FDD.info.conf</Initialize_eNB_args>
+		<Initialize_eNB_args>-O 20M.band1.FDD.info.conf --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 	</testCase>
 
 	<testCase id="030104">
 		<class>Initialize_eNB</class>
 		<desc>Initialize eNB (TDD/Band38/5MHz/info)</desc>
-		<Initialize_eNB_args>-O 5M.band38.TDD.info.conf</Initialize_eNB_args>
+		<Initialize_eNB_args>-O 5M.band38.TDD.info.conf --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 	</testCase>
 
 	<testCase id="030105">
 		<class>Initialize_eNB</class>
 		<desc>Initialize eNB (TDD/Band38/10MHz/info)</desc>
-		<Initialize_eNB_args>-O 10M.band38.TDD.info.conf</Initialize_eNB_args>
+		<Initialize_eNB_args>-O 10M.band38.TDD.info.conf --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 	</testCase>
 
 	<testCase id="030106">
 		<class>Initialize_eNB</class>
 		<desc>Initialize eNB (TDD/Band38/20MHz/info)</desc>
-		<Initialize_eNB_args>-O 20M.band38.TDD.info.conf</Initialize_eNB_args>
+		<Initialize_eNB_args>-O 20M.band38.TDD.info.conf --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 	</testCase>
 
 	<testCase id="030201">
diff --git a/ci-scripts/xml_files/ue_band20_test_10mhz_orange.xml b/ci-scripts/xml_files/ue_band20_test_10mhz_orange.xml
index d3e36f603eb10deac64f57a72f26d93f13bad480..49ccfbca1433cc5a8cffdd50d36f206ac2ea1c22 100644
--- a/ci-scripts/xml_files/ue_band20_test_10mhz_orange.xml
+++ b/ci-scripts/xml_files/ue_band20_test_10mhz_orange.xml
@@ -34,7 +34,7 @@
 	<testCase id="090110">
 		<class>Initialize_OAI_UE</class>
 		<desc>Initialize OAI UE -- sniffing Orange frequency</desc>
-		<Initialize_OAI_UE_args>-C 816000000 -r 50 --ue-rxgain 135 --ue-scan-carrier --no-L2-connect --nokrnmod 1</Initialize_OAI_UE_args>
+		<Initialize_OAI_UE_args>-C 816000000 -r 50 --ue-rxgain 135 --ue-scan-carrier --no-L2-connect --nokrnmod 1 --log_config.global_log_options level,nocolor,time</Initialize_OAI_UE_args>
 	</testCase>
 
 	<testCase id="000001">
diff --git a/ci-scripts/xml_files/ue_band20_test_10mhz_sfr.xml b/ci-scripts/xml_files/ue_band20_test_10mhz_sfr.xml
index 3f6441e06ea8de2379e808f1ee35743379038413..fdc70a9bdd84c0baab9800d84492a5b5b128c771 100644
--- a/ci-scripts/xml_files/ue_band20_test_10mhz_sfr.xml
+++ b/ci-scripts/xml_files/ue_band20_test_10mhz_sfr.xml
@@ -34,7 +34,7 @@
 	<testCase id="090111">
 		<class>Initialize_OAI_UE</class>
 		<desc>Initialize OAI UE -- sniffing SFR frequency</desc>
-		<Initialize_OAI_UE_args>-C 806000000 -r 50 --ue-rxgain 130 --ue-scan-carrier --no-L2-connect --nokrnmod 1</Initialize_OAI_UE_args>
+		<Initialize_OAI_UE_args>-C 806000000 -r 50 --ue-rxgain 130 --ue-scan-carrier --no-L2-connect --nokrnmod 1 --log_config.global_log_options level,nocolor,time</Initialize_OAI_UE_args>
 	</testCase>
 
 	<testCase id="000001">
diff --git a/ci-scripts/xml_files/x2ho_enb_usrp210_band13_test_05mhz_tm1.xml b/ci-scripts/xml_files/x2ho_enb_usrp210_band13_test_05mhz_tm1.xml
index 7256c985c584d02126109b0b41764531294d0d8d..14872c9f8f5ce3b52fb3406e1b894608ec747602 100644
--- a/ci-scripts/xml_files/x2ho_enb_usrp210_band13_test_05mhz_tm1.xml
+++ b/ci-scripts/xml_files/x2ho_enb_usrp210_band13_test_05mhz_tm1.xml
@@ -61,7 +61,7 @@
 	<testCase id="030101">
 		<class>Initialize_eNB</class>
 		<desc>Initialize Master eNB (FDD/Band7/5MHz)</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band13.tm1.25PRB.usrpb210.conf</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band13.tm1.25PRB.usrpb210.conf --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 		<eNB_instance>0</eNB_instance>
 		<eNB_serverId>0</eNB_serverId>
 	</testCase>
@@ -69,7 +69,7 @@
 	<testCase id="030102">
 		<class>Initialize_eNB</class>
 		<desc>Initialize Slave eNB (FDD/Band7/5MHz)</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.slave.band13.tm1.25PRB.usrpb210.conf</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.slave.band13.tm1.25PRB.usrpb210.conf --log_config.global_log_options level,nocolor,time</Initialize_eNB_args>
 		<eNB_instance>1</eNB_instance>
 		<eNB_serverId>1</eNB_serverId>
 	</testCase>
diff --git a/ci-scripts/yaml_files/4g_rfsimulator/docker-compose.yml b/ci-scripts/yaml_files/4g_rfsimulator/docker-compose.yml
index 32e4bd41e8146f4b6e52a16324948d2b18f66e9c..e852643ab9227564e8cbc2c3dca1721a473c8e23 100644
--- a/ci-scripts/yaml_files/4g_rfsimulator/docker-compose.yml
+++ b/ci-scripts/yaml_files/4g_rfsimulator/docker-compose.yml
@@ -221,7 +221,7 @@ services:
             FLEXRAN_ENABLED: 'no'
             FLEXRAN_INTERFACE_NAME: eth0
             FLEXRAN_IPV4_ADDRESS: 192.168.61.10
-            USE_ADDITIONAL_OPTIONS: --rfsim
+            USE_ADDITIONAL_OPTIONS: --rfsim --log_config.global_log_options level,nocolor,time
         healthcheck:
             test: /bin/bash -c "pgrep lte-softmodem"
             interval: 10s
@@ -248,7 +248,7 @@ services:
             OPC: 'c42449363bbad02b66d16bc975d77cc1'
             MSISDN: '001011234561010'
             HPLMN: 20896
-            USE_ADDITIONAL_OPTIONS: --rfsim -C 2680000000 -r 25 --ue-rxgain 140 --ue-txgain 120 --nokrnmod 1
+            USE_ADDITIONAL_OPTIONS: --rfsim -C 2680000000 -r 25 --ue-rxgain 140 --ue-txgain 120 --nokrnmod 1 --log_config.global_log_options level,nocolor,time
         healthcheck:
             test: /bin/bash -c "pgrep lte-uesoftmodem"
             interval: 10s
diff --git a/ci-scripts/yaml_files/5g_f1_rfsimulator/amf-healthcheck.sh b/ci-scripts/yaml_files/5g_f1_rfsimulator/amf-healthcheck.sh
new file mode 100755
index 0000000000000000000000000000000000000000..8bfdee2aac6150b50240f7af4fa15a5eb105e9bc
--- /dev/null
+++ b/ci-scripts/yaml_files/5g_f1_rfsimulator/amf-healthcheck.sh
@@ -0,0 +1,57 @@
+#!/bin/bash
+set -eo pipefail
+
+STATUS=0
+AMF_PORT_FOR_NGAP=38412
+AMF_PORT_FOR_N11_HTTP=80
+AMF_IP_NGAP_INTERFACE=$(ifconfig $AMF_INTERFACE_NAME_FOR_NGAP | grep inet | awk {'print $2'})
+AMF_IP_N11_INTERFACE=$(ifconfig $AMF_INTERFACE_NAME_FOR_N11 | grep inet | awk {'print $2'})
+N2_PORT_STATUS=$(netstat -Snpl | grep -o "$AMF_IP_NGAP_INTERFACE:$AMF_PORT_FOR_NGAP")
+N11_PORT_STATUS=$(netstat -tnpl | grep -o "$AMF_IP_N11_INTERFACE:$AMF_PORT_FOR_N11_HTTP")
+#Check if entrypoint properly configured the conf file and no parameter is unset (optional)
+NB_UNREPLACED_AT=`cat /openair-amf/etc/*.conf | grep -v contact@openairinterface.org | grep -c @ || true`
+
+if [ $NB_UNREPLACED_AT -ne 0 ]; then
+	STATUS=1
+	echo "Healthcheck error: configuration file is not configured properly"
+fi
+
+if [[ -z $N2_PORT_STATUS ]]; then
+	STATUS=1
+	echo "Healthcheck error: N2 SCTP port $AMF_PORT_FOR_NGAP is not listening"
+fi
+
+if [[ -z $N11_PORT_STATUS ]]; then
+	STATUS=1
+	echo "Healthcheck error: N11/SBI TCP/HTTP port $AMF_PORT_FOR_N11_HTTP is not listening"
+fi
+
+#host="${MYSQL_SERVER}"
+#user="${MYSQL_USER:-root}"
+#export MYSQL_PWD="${MYSQL_PASS}"
+
+#args=(
+#	-h"$host"
+#	-u"$user"
+#	--silent
+#)
+
+#if ! command -v mysql &> /dev/null; then
+#	echo "Installing mysql command"
+#	apt update
+#	apt-get -y install mysql-client
+#else
+#	if select="$(echo 'SELECT 1' | mysql "${args[@]}")" && [ "$select" = '1' ]; then
+#		database_check=$(mysql -h$host -u$user -D oai_db --silent -e "SELECT * FROM users;")
+#		if [[ -z $database_check ]]; then
+#			echo "Healthcheck error: oai_db not populated"
+#			STATUS=1
+#		fi
+#		STATUS=0
+#	else
+#		echo "Healthcheck error: Mysql port inactive"
+#		STATUS=1
+#	fi
+#fi
+
+exit $STATUS
diff --git a/ci-scripts/yaml_files/5g_f1_rfsimulator/docker-compose.yaml b/ci-scripts/yaml_files/5g_f1_rfsimulator/docker-compose.yaml
new file mode 100644
index 0000000000000000000000000000000000000000..eb15aef0d8aa48076f147111234baff19a16c3ca
--- /dev/null
+++ b/ci-scripts/yaml_files/5g_f1_rfsimulator/docker-compose.yaml
@@ -0,0 +1,339 @@
+version: '3.8'
+services:
+    oai-nrf:
+        container_name: "rfsim5g-oai-nrf"
+        image: oai-nrf:latest
+        environment:
+            - NRF_INTERFACE_NAME_FOR_SBI=eth0
+            - NRF_INTERFACE_PORT_FOR_SBI=80
+            - NRF_INTERFACE_HTTP2_PORT_FOR_SBI=9090
+            - NRF_API_VERSION=v1
+            - INSTANCE=0
+            - PID_DIRECTORY=/var/run
+        networks:
+            public_net:
+                ipv4_address: 192.168.71.130
+        volumes:
+            - ./nrf-healthcheck.sh:/openair-nrf/bin/nrf-healthcheck.sh
+        healthcheck:
+            test: /bin/bash -c "/openair-nrf/bin/nrf-healthcheck.sh"
+            interval: 10s
+            timeout: 5s
+            retries: 5
+    mysql:
+        container_name: "rfsim5g-mysql"
+        image: mysql:5.7
+        volumes:
+            - ./oai_db.sql:/docker-entrypoint-initdb.d/oai_db.sql
+            - ./mysql-healthcheck.sh:/tmp/mysql-healthcheck.sh
+        environment:
+            - TZ=Europe/Paris
+            - MYSQL_DATABASE=oai_db
+            - MYSQL_USER=test
+            - MYSQL_PASSWORD=test
+            - MYSQL_ROOT_PASSWORD=linux
+        healthcheck:
+            test: /bin/bash -c "/tmp/mysql-healthcheck.sh"
+            interval: 10s
+            timeout: 5s
+            retries: 5
+        networks:
+            public_net:
+                ipv4_address: 192.168.71.131
+    oai-amf:
+        container_name: "rfsim5g-oai-amf"
+        image: oai-amf:latest
+        environment:
+            - TZ=Europe/paris
+            - INSTANCE=0
+            - PID_DIRECTORY=/var/run
+            - MCC=208
+            - MNC=99
+            - REGION_ID=128
+            - AMF_SET_ID=1
+            - SERVED_GUAMI_MCC_0=208
+            - SERVED_GUAMI_MNC_0=99
+            - SERVED_GUAMI_REGION_ID_0=128
+            - SERVED_GUAMI_AMF_SET_ID_0=1
+            - SERVED_GUAMI_MCC_1=460
+            - SERVED_GUAMI_MNC_1=11
+            - SERVED_GUAMI_REGION_ID_1=10
+            - SERVED_GUAMI_AMF_SET_ID_1=1
+            - PLMN_SUPPORT_MCC=208
+            - PLMN_SUPPORT_MNC=99
+            - PLMN_SUPPORT_TAC=0x0001
+            - SST_0=1
+            - SD_0=1
+            - SST_1=1
+            - SD_1=12
+            - AMF_INTERFACE_NAME_FOR_NGAP=eth0
+            - AMF_INTERFACE_NAME_FOR_N11=eth0
+            - SMF_INSTANCE_ID_0=1
+            - SMF_FQDN_0=oai-smf
+            - SMF_IPV4_ADDR_0=0.0.0.0
+            - SMF_HTTP_VERSION_0=v1
+            - SELECTED_0=true
+            - SMF_INSTANCE_ID_1=2
+            - SMF_FQDN_1=oai-smf
+            - SMF_IPV4_ADDR_1=0.0.0.0
+            - SMF_HTTP_VERSION_1=v1
+            - SELECTED_1=false
+            - MYSQL_SERVER=192.168.71.131
+            - MYSQL_USER=root
+            - MYSQL_PASS=linux
+            - MYSQL_DB=oai_db
+            - OPERATOR_KEY=c42449363bbad02b66d16bc975d77cc1
+            - NRF_IPV4_ADDRESS=192.168.71.130
+            - NRF_PORT=80
+            - NF_REGISTRATION=yes
+            - SMF_SELECTION=yes
+            - USE_FQDN_DNS=yes
+            - NRF_API_VERSION=v1
+            - NRF_FQDN=oai-nrf
+            - EXTERNAL_AUSF=no
+            - AUSF_IPV4_ADDRESS=0.0.0.0
+            - AUSF_PORT=80
+            - AUSF_API_VERSION=v1
+            - AUSF_FQDN=localhost
+        depends_on:
+            - oai-nrf
+            - mysql
+        volumes:
+            - ./amf-healthcheck.sh:/openair-amf/bin/amf-healthcheck.sh
+        healthcheck:
+            test: /bin/bash -c "/openair-amf/bin/amf-healthcheck.sh"
+            interval: 10s
+            timeout: 15s
+            retries: 5
+        networks:
+            public_net:
+                ipv4_address: 192.168.71.132
+    oai-smf:
+        container_name: "rfsim5g-oai-smf"
+        image: oai-smf:latest
+        entrypoint: /bin/bash -c "/openair-smf/bin/oai_smf -c /openair-smf/bin/oai-smf.conf -o"
+        environment:
+            - TZ=Europe/Paris
+            - INSTANCE=0
+            - PID_DIRECTORY=/var/run
+            - SMF_INTERFACE_NAME_FOR_N4=eth0
+            - SMF_INTERFACE_NAME_FOR_SBI=eth0
+            - SMF_INTERFACE_PORT_FOR_SBI=80
+            - SMF_INTERFACE_HTTP2_PORT_FOR_SBI=9090
+            - SMF_API_VERSION=v1
+            - DEFAULT_DNS_IPV4_ADDRESS=192.168.18.129
+            - DEFAULT_DNS_SEC_IPV4_ADDRESS=4.4.4.4
+            - AMF_IPV4_ADDRESS=0.0.0.0
+            - AMF_PORT=80
+            - AMF_API_VERSION=v1
+            - AMF_FQDN=oai-amf
+            - UDM_IPV4_ADDRESS=127.0.0.1
+            - UDM_PORT=80
+            - UDM_API_VERSION=v1
+            - UDM_FQDN=localhost
+            - UPF_IPV4_ADDRESS=192.168.71.134
+            - UPF_FQDN_0=oai-spgwu
+            - NRF_IPV4_ADDRESS=192.168.71.130
+            - NRF_PORT=80
+            - NRF_API_VERSION=v1
+            - NRF_FQDN=oai-nrf
+            - REGISTER_NRF=yes
+            - DISCOVER_UPF=yes
+            - USE_FQDN_DNS=yes
+        depends_on:
+            - oai-nrf
+            - oai-amf
+        volumes:
+            - ./smf-healthcheck.sh:/openair-smf/bin/smf-healthcheck.sh
+            - ./oai-smf.conf:/openair-smf/bin/oai-smf.conf
+        healthcheck:
+            test: /bin/bash -c "/openair-smf/bin/smf-healthcheck.sh"
+            interval: 10s
+            timeout: 5s
+            retries: 5
+        networks:
+            public_net:
+                ipv4_address: 192.168.71.133
+    oai-spgwu:
+        container_name: "rfsim5g-oai-spgwu"
+        image: oai-spgwu-tiny:latest
+        environment:
+            - TZ=Europe/Paris
+            - PID_DIRECTORY=/var/run
+            - SGW_INTERFACE_NAME_FOR_S1U_S12_S4_UP=eth0
+            - SGW_INTERFACE_NAME_FOR_SX=eth0
+            - PGW_INTERFACE_NAME_FOR_SGI=eth0
+            - NETWORK_UE_NAT_OPTION=yes
+            - NETWORK_UE_IP=12.1.1.0/24
+            - SPGWC0_IP_ADDRESS=192.168.71.133
+            - BYPASS_UL_PFCP_RULES=no
+            - MCC=208
+            - MNC=99
+            - MNC03=099
+            - TAC=1
+            - GTP_EXTENSION_HEADER_PRESENT=yes
+            - GW_ID=1
+            - REALM=openairinterface.org
+            - ENABLE_5G_FEATURES=yes
+            - REGISTER_NRF=yes
+            - USE_FQDN_NRF=yes
+            - UPF_FQDN_5G=oai-spgwu
+            - NRF_IPV4_ADDRESS=192.168.71.130
+            - NRF_PORT=80
+            - NRF_API_VERSION=v1
+            - NRF_FQDN=oai-nrf
+            - NSSAI_SST_0=1
+            - NSSAI_SD_0=1
+            - DNN_0=oai
+        depends_on:
+            - oai-nrf
+            - oai-smf
+        cap_add:
+            - NET_ADMIN
+            - SYS_ADMIN
+        cap_drop:
+            - ALL
+        privileged: true
+        volumes:
+            - ./spgwu-healthcheck.sh:/openair-spgwu-tiny/bin/spgwu-healthcheck.sh
+        healthcheck:
+            test: /bin/bash -c "/openair-spgwu-tiny/bin/spgwu-healthcheck.sh"
+            interval: 10s
+            timeout: 5s
+            retries: 5
+        networks:
+            public_net:
+                ipv4_address: 192.168.71.134
+            traffic_net:
+                ipv4_address: 192.168.72.134
+    oai-ext-dn:
+        image: ubuntu:bionic
+        privileged: true
+        container_name: rfsim5g-oai-ext-dn
+        entrypoint: /bin/bash -c \
+              "apt update; apt install -y procps iptables iproute2 iperf iputils-ping;"\
+              "iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE;"\
+              "ip route add 12.1.1.0/24 via 192.168.72.134 dev eth0; sleep infinity"
+        depends_on:
+            - oai-spgwu
+        networks:
+            traffic_net:
+                ipv4_address: 192.168.72.135
+        healthcheck:
+            test: /bin/bash -c "ping -c 2 192.168.72.134"
+            interval: 10s
+            timeout: 5s
+            retries: 5
+    oai-cu:
+        image: oai-gnb:develop
+        privileged: true
+        container_name: rfsim5g-oai-cu
+        environment: 
+            RFSIMULATOR: server
+            USE_SA_CU: 'yes'
+            GNB_NAME: cu-rfsim
+            TAC: 1
+            MCC: '208'
+            MNC: '99'
+            MNC_LENGTH: 2
+            NSSAI_SST: 1
+            NSSAI_SD0: 1
+            NSSAI_SD1: 112233
+            AMF_IP_ADDRESS: 192.168.71.132
+            GNB_NGA_IF_NAME: eth0
+            GNB_NGA_IP_ADDRESS: 192.168.71.136
+            GNB_NGU_IF_NAME: eth0
+            GNB_NGU_IP_ADDRESS: 192.168.71.136
+            F1_IF_NAME: eth0
+            F1_CU_IP_ADDRESS: 192.168.71.136
+            F1_DU_IP_ADDRESS: 192.168.71.138
+            F1_CU_D_PORT: 2153
+            F1_DU_D_PORT: 2153
+            USE_ADDITIONAL_OPTIONS: --sa --rfsim --log_config.global_log_options level,nocolor,time
+        depends_on:
+            - oai-ext-dn
+        networks:
+            public_net:
+                ipv4_address: 192.168.71.136
+        healthcheck:
+            test: /bin/bash -c "pgrep nr-softmodem"
+            interval: 10s
+            timeout: 5s
+            retries: 5
+    oai-du:
+        image: oai-gnb:develop
+        privileged: true
+        container_name: rfsim5g-oai-du
+        environment: 
+            RFSIMULATOR: server
+            USE_SA_TDD_CU: 'yes'
+            GNB_NAME: du-rfsim
+            TAC: 1
+            MCC: '208'
+            MNC: '99'
+            MNC_LENGTH: 2
+            NSSAI_SST: 1
+            NSSAI_SD0: 1
+            NSSAI_SD1: 112233
+            AMF_IP_ADDRESS: 192.168.71.132
+            GNB_NGA_IF_NAME: eth0
+            GNB_NGA_IP_ADDRESS: 192.168.71.138
+            GNB_NGU_IF_NAME: eth0
+            GNB_NGU_IP_ADDRESS: 192.168.71.138
+            F1_IF_NAME: eth0
+            F1_CU_IP_ADDRESS: 192.168.71.136
+            F1_DU_IP_ADDRESS: 192.168.71.138
+            F1_CU_D_PORT: 2153
+            F1_DU_D_PORT: 2153
+            USE_ADDITIONAL_OPTIONS: --sa --rfsim --log_config.global_log_options level,nocolor,time
+        depends_on:
+            - oai-cu
+        networks:
+            public_net:
+                ipv4_address: 192.168.71.138
+        healthcheck:
+            test: /bin/bash -c "pgrep nr-softmodem"
+            interval: 10s
+            timeout: 5s
+            retries: 5
+    oai-nr-ue:
+        image: oai-nr-ue:develop
+        privileged: true
+        container_name: rfsim5g-oai-nr-ue
+        environment: 
+            RFSIMULATOR: 192.168.71.138
+            FULL_IMSI: '208990100001100'
+            FULL_KEY: 'fec86ba6eb707ed08905757b1bb44b8f'
+            OPC: 'C42449363BBAD02B66D16BC975D77CC1'
+            DNN: oai
+            NSSAI_SST: 1
+            NSSAI_SD: 1
+            USE_ADDITIONAL_OPTIONS: --sa --rfsim -r 106 --numerology 1 -C 3619200000 --nokrnmod --log_config.global_log_options level,nocolor,time
+        depends_on:
+            - oai-du
+        networks:
+            public_net:
+                ipv4_address: 192.168.71.137
+        healthcheck:
+            test: /bin/bash -c "pgrep nr-uesoftmodem"
+            interval: 10s
+            timeout: 5s
+            retries: 5
+
+networks:
+    public_net:
+        driver: bridge
+        name: rfsim5g-oai-public-net
+        ipam:
+            config:
+                - subnet: 192.168.71.128/26
+        driver_opts:
+            com.docker.network.bridge.name: "rfsim5g-public"
+    traffic_net:
+        driver: bridge
+        name: rfsim5g-oai-traffic_net-net
+        ipam:
+            config:
+                - subnet: 192.168.72.128/26
+        driver_opts:
+            com.docker.network.bridge.name: "rfsim5g-traffic"
diff --git a/ci-scripts/yaml_files/5g_f1_rfsimulator/mysql-healthcheck.sh b/ci-scripts/yaml_files/5g_f1_rfsimulator/mysql-healthcheck.sh
new file mode 100755
index 0000000000000000000000000000000000000000..c92efb9f00a1f69e36dbc8bd410c163bb5d37a97
--- /dev/null
+++ b/ci-scripts/yaml_files/5g_f1_rfsimulator/mysql-healthcheck.sh
@@ -0,0 +1,46 @@
+#!/bin/bash
+set -eo pipefail
+
+if [ "$MYSQL_ROOT_PASSWORD" ] && [ -z "$MYSQL_USER" ] && [ -z "$MYSQL_PASSWORD" ]; then
+	echo >&2 'Healthcheck error: cannot determine root password (and MYSQL_USER and MYSQL_PASSWORD were not set)'
+	exit 0
+fi
+
+host="$(hostname --ip-address || echo '127.0.0.1')"
+user="${MYSQL_USER:-root}"
+export MYSQL_PWD="${MYSQL_PASSWORD:-$MYSQL_ROOT_PASSWORD}"
+
+args=(
+	# force mysql to not use the local "mysqld.sock" (test "external" connectivity)
+	-h"$host"
+	-u"$user"
+	--silent
+)
+
+STATUS=0
+if command -v mysqladmin &> /dev/null; then
+	if mysqladmin "${args[@]}" ping > /dev/null; then
+		database_check=$(mysql -u$user -D oai_db --silent -e "SELECT * FROM users;")
+		if [[ -z $database_check ]]; then
+			echo "Healthcheck error: oai_db not populated"
+			STATUS=1
+		fi
+		STATUS=0
+	else
+		echo "Healthcheck error: Mysql port inactive"
+		STATUS=1
+	fi
+else
+	if select="$(echo 'SELECT 1' | mysql "${args[@]}")" && [ "$select" = '1' ]; then
+		database_check=$(mysql -u$user -D oai_db --silent -e "SELECT * FROM users;")
+		if [[ -z $database_check ]]; then
+			echo "Healthcheck error: oai_db not populated"
+			STATUS=1
+		fi
+		STATUS=0
+	else
+		echo "Healthcheck error: Mysql port inactive"
+		STATUS=1
+	fi
+fi
+exit $STATUS
diff --git a/ci-scripts/yaml_files/5g_f1_rfsimulator/nrf-healthcheck.sh b/ci-scripts/yaml_files/5g_f1_rfsimulator/nrf-healthcheck.sh
new file mode 100755
index 0000000000000000000000000000000000000000..3479c092e8805bf45007d1a4635ee43149786401
--- /dev/null
+++ b/ci-scripts/yaml_files/5g_f1_rfsimulator/nrf-healthcheck.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+set -eo pipefail
+
+STATUS=0
+NRF_IP_SBI_INTERFACE=$(ifconfig $NRF_INTERFACE_NAME_FOR_SBI | grep inet | awk {'print $2'})
+NRF_SBI_PORT_STATUS=$(netstat -tnpl | grep -o "$NRF_IP_SBI_INTERFACE:$NRF_INTERFACE_PORT_FOR_SBI")
+#Check if entrypoint properly configured the conf file and no parameter is unset(optional)
+NB_UNREPLACED_AT=`cat /openair-nrf/etc/*.conf | grep -v contact@openairinterface.org | grep -c @ || true`
+
+if [ $NB_UNREPLACED_AT -ne 0 ]; then
+	STATUS=1
+	echo "Healthcheck error: UNHEALTHY configuration file is not configured properly"
+fi
+
+if [[ -z $NRF_SBI_PORT_STATUS ]]; then
+	STATUS=1
+	echo "Healthcheck error: UNHEALTHY SBI TCP/HTTP port $NRF_INTERFACE_PORT_FOR_SBI is not listening."
+fi
+
+exit $STATUS
\ No newline at end of file
diff --git a/ci-scripts/yaml_files/5g_f1_rfsimulator/oai-smf.conf b/ci-scripts/yaml_files/5g_f1_rfsimulator/oai-smf.conf
new file mode 100644
index 0000000000000000000000000000000000000000..0c83ab8be937cee03a6b1dc0931473e162c952df
--- /dev/null
+++ b/ci-scripts/yaml_files/5g_f1_rfsimulator/oai-smf.conf
@@ -0,0 +1,133 @@
+################################################################################
+# 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
+################################################################################
+
+SMF =
+{
+    FQDN = "oai-smf-svc";               
+    INSTANCE      = 0;         # 0 is the default
+    PID_DIRECTORY = "/var/run";  # /var/run is the default
+
+    INTERFACES :
+    {
+        N4 :
+        {
+            # SMF binded interface for N4 communication (UPF)
+            INTERFACE_NAME = "eth0"; # YOUR NETWORK CONFIG HERE
+            IPV4_ADDRESS   = "read";                        
+         };
+
+        SBI :
+        {
+            # SMF binded interface for SBI interface (e.g., communication with AMF, UDM)
+            INTERFACE_NAME = "eth0";     # YOUR NETWORK CONFIG HERE
+            IPV4_ADDRESS   = "read";
+            PORT           = 80;       # YOUR NETWORK CONFIG HERE (default: 80)
+            HTTP2_PORT     = 9090; # YOUR NETWORK CONFIG HERE
+            API_VERSION    = "v1";                # YOUR SMF API VERSION CONFIG HERE
+         };                 
+
+    };
+
+
+    # Pool of UE assigned IP addresses
+    # Do not make IP pools overlap
+    # first IPv4 address X.Y.Z.1 is reserved for GTP network device on UPF
+    IP_ADDRESS_POOL :
+    {
+        IPV4_LIST = (
+                      {RANGE = "12.1.1.2 - 12.1.1.128";},         # STRING, IPv4 RANGE IP_start - IP_end, YOUR NETWORK CONFIG HERE.
+                      {RANGE = "12.1.1.129 - 12.1.1.224";},       # STRING, IPv4 RANGE IP_start - IP_end, YOUR NETWORK CONFIG HERE.
+                      {RANGE = "10.10.10.2 - 10.10.10.253";}  # STRING, IPv4 RANGE IP_start - IP_end, YOUR NETWORK CONFIG HERE.
+
+                    );
+        IPV6_LIST = (
+                      {PREFIX = "2001:1:2::/64";},                # STRING, IPv6 prefix, YOUR NETWORK CONFIG HERE.
+                      {PREFIX = "3001:1:2::/64";},                # STRING, IPv6 prefix, YOUR NETWORK CONFIG HERE.
+                      {PREFIX = "4001:1:2::/64";}                 # STRING, IPv6 prefix, YOUR NETWORK CONFIG HERE.
+                    );
+    };
+
+    DNN_LIST = (
+       # IPV4_POOL, IPV6_POOL are index in IPV4_LIST, IPV6_LIST, PDU_SESSION_TYPE choice in {IPv4, IPv6, IPv4v6}
+      {DNN_NI = "default"; PDU_SESSION_TYPE = "IPv4"; IPV4_POOL  = 2; IPV6_POOL = -1},
+      {DNN_NI = "carrier.com"; PDU_SESSION_TYPE = "IPv4"; IPV4_POOL = 1; IPV6_POOL = -1},
+      {DNN_NI = "oai"; PDU_SESSION_TYPE = "IPv4"; IPV4_POOL = 0; IPV6_POOL = -1}
+    );
+
+    # DNS address communicated to UEs
+    DEFAULT_DNS_IPV4_ADDRESS     = "192.168.18.129";      # YOUR DNS CONFIG HERE
+    DEFAULT_DNS_SEC_IPV4_ADDRESS = "192.168.18.129";  # YOUR DNS CONFIG HERE
+    DEFAULT_DNS_IPV6_ADDRESS     = "2001:4860:4860::8888";            # YOUR DNS CONFIG HERE
+    DEFAULT_DNS_SEC_IPV6_ADDRESS = "2001:4860:4860::8844";            # YOUR DNS CONFIG HERE
+ 
+    SUPPORT_FEATURES: 
+    {
+      # STRING, {"yes", "no"}, 
+      REGISTER_NRF = "yes";  # Set to yes if SMF resgisters to an NRF
+      DISCOVER_UPF = "yes";  # Set to yes to enable UPF discovery and selection
+      FORCE_PUSH_PROTOCOL_CONFIGURATION_OPTIONS = "no"; # Non standard feature, normally should be set to "no", 
+                                                        # but you may need to set to yes for UE that do not explicitly request a PDN address through NAS signalling
+      USE_LOCAL_SUBSCRIPTION_INFO = "yes";  # Set to yes if SMF uses local subscription information instead of from an UDM
+      USE_FQDN_DNS = "yes";                  # Set to yes if AMF/UDM/NRF/UPF will relying on a DNS to resolve FQDN
+    }  
+  
+    AMF :
+    {
+      IPV4_ADDRESS = "0.0.0.0";  # YOUR AMF CONFIG HERE
+      PORT         = 80;            # YOUR AMF CONFIG HERE (default: 80)
+      API_VERSION  = "v1";   # YOUR AMF API VERSION FOR SBI CONFIG HERE
+      FQDN         = "oai-amf"               # YOUR AMF FQDN CONFIG HERE
+    };
+    
+    UDM :
+    {
+      IPV4_ADDRESS = "127.0.0.1";  # YOUR UDM CONFIG HERE
+      PORT         = 80;            # YOUR UDM CONFIG HERE (default: 80)
+      API_VERSION  = "v1";   # YOUR UDM API VERSION FOR SBI CONFIG HERE
+      FQDN         = "localhost"      # YOUR UDM FQDN CONFIG HERE
+    };    
+
+    NRF :
+    {
+      IPV4_ADDRESS = "192.168.71.130";  # YOUR NRF CONFIG HERE
+      PORT         = 80;            # YOUR NRF CONFIG HERE (default: 80)
+      API_VERSION  = "v1";   # YOUR NRF API VERSION FOR SBI CONFIG HERE
+      FQDN         = "oai-nrf"      # YOUR NRF FQDN CONFIG HERE
+    };
+        
+    UPF_LIST = (
+         {IPV4_ADDRESS = "192.168.71.134" ; FQDN = "oai-spgwu"}   # YOUR UPF CONFIG HERE
+    );   
+   
+    LOCAL_CONFIGURATION :
+    {
+      SESSION_MANAGEMENT_SUBSCRIPTION_LIST = (
+         { NSSAI_SST = 222, NSSAI_SD = "123", DNN = "default", DEFAULT_SESSION_TYPE = "IPV4", DEFAULT_SSC_MODE = 1, 
+           QOS_PROFILE_5QI = 7, QOS_PROFILE_PRIORITY_LEVEL = 1, QOS_PROFILE_ARP_PRIORITY_LEVEL = 1, QOS_PROFILE_ARP_PREEMPTCAP = "NOT_PREEMPT", 
+           QOS_PROFILE_ARP_PREEMPTVULN = "NOT_PREEMPTABLE", SESSION_AMBR_UL = "20Mbps", SESSION_AMBR_DL = "22Mbps"},
+         { NSSAI_SST = 1; NSSAI_SD = "1", DNN = "oai", DEFAULT_SESSION_TYPE = "IPV4", DEFAULT_SSC_MODE = 1, 
+           QOS_PROFILE_5QI = 6, QOS_PROFILE_PRIORITY_LEVEL = 1, QOS_PROFILE_ARP_PRIORITY_LEVEL = 1, QOS_PROFILE_ARP_PREEMPTCAP = "NOT_PREEMPT", 
+           QOS_PROFILE_ARP_PREEMPTVULN = "NOT_PREEMPTABLE", SESSION_AMBR_UL = "20Mbps", SESSION_AMBR_DL = "22Mbps"}
+        );                 
+    };   
+    
+};
+
diff --git a/ci-scripts/yaml_files/5g_f1_rfsimulator/oai_db.sql b/ci-scripts/yaml_files/5g_f1_rfsimulator/oai_db.sql
new file mode 100755
index 0000000000000000000000000000000000000000..fbd7907a71edd41cc32016f91176b270b8b5bd11
--- /dev/null
+++ b/ci-scripts/yaml_files/5g_f1_rfsimulator/oai_db.sql
@@ -0,0 +1,217 @@
+-- MySQL dump 10.13  Distrib 5.5.46, for debian-linux-gnu (x86_64)
+--
+-- Host: localhost    Database: oai_db
+-- ------------------------------------------------------
+-- Server version	5.5.46-0ubuntu0.14.04.2
+
+/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
+/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
+/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
+/*!40101 SET NAMES utf8 */;
+/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
+/*!40103 SET TIME_ZONE='+00:00' */;
+/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
+/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
+/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
+/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
+
+--
+-- Table structure for table `apn`
+--
+
+DROP TABLE IF EXISTS `apn`;
+/*!40101 SET @saved_cs_client     = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `apn` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `apn-name` varchar(60) NOT NULL,
+  `pdn-type` enum('IPv4','IPv6','IPv4v6','IPv4_or_IPv6') NOT NULL,
+  PRIMARY KEY (`id`),
+  UNIQUE KEY `apn-name` (`apn-name`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping data for table `apn`
+--
+
+LOCK TABLES `apn` WRITE;
+/*!40000 ALTER TABLE `apn` DISABLE KEYS */;
+/*!40000 ALTER TABLE `apn` ENABLE KEYS */;
+UNLOCK TABLES;
+
+--
+-- Table structure for table `mmeidentity`
+--
+
+DROP TABLE IF EXISTS `mmeidentity`;
+/*!40101 SET @saved_cs_client     = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `mmeidentity` (
+  `idmmeidentity` int(11) NOT NULL AUTO_INCREMENT,
+  `mmehost` varchar(255) DEFAULT NULL,
+  `mmerealm` varchar(200) DEFAULT NULL,
+  `UE-Reachability` tinyint(1) NOT NULL COMMENT 'Indicates whether the MME supports UE Reachability Notifcation',
+  PRIMARY KEY (`idmmeidentity`)
+) ENGINE=MyISAM AUTO_INCREMENT=46 DEFAULT CHARSET=latin1;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping data for table `mmeidentity`
+--
+
+LOCK TABLES `mmeidentity` WRITE;
+/*!40000 ALTER TABLE `mmeidentity` DISABLE KEYS */;
+INSERT INTO `mmeidentity` VALUES (2,'mme2.openair4G.eur','openair4G.eur',0),(1,'nano.openair4G.eur','openair4G.eur',0),(5,'abeille.openair4G.eur','openair4G.eur',0),(4,'yang.openair4G.eur','openair4G.eur',0),(3,'mme3.openair4G.eur','openair4G.eur',0),(6,'calisson.openair4G.eur','openair4G.eur',0);
+/*!40000 ALTER TABLE `mmeidentity` ENABLE KEYS */;
+UNLOCK TABLES;
+
+--
+-- Table structure for table `pdn`
+--
+
+DROP TABLE IF EXISTS `pdn`;
+/*!40101 SET @saved_cs_client     = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `pdn` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `apn` varchar(60) NOT NULL,
+  `pdn_type` enum('IPv4','IPv6','IPv4v6','IPv4_or_IPv6') NOT NULL DEFAULT 'IPv4',
+  `pdn_ipv4` varchar(15) DEFAULT '0.0.0.0',
+  `pdn_ipv6` varchar(45) CHARACTER SET latin1 COLLATE latin1_general_ci DEFAULT '0:0:0:0:0:0:0:0',
+  `aggregate_ambr_ul` int(10) unsigned DEFAULT '50000000',
+  `aggregate_ambr_dl` int(10) unsigned DEFAULT '100000000',
+  `pgw_id` int(11) NOT NULL,
+  `users_imsi` varchar(15) NOT NULL,
+  `qci` tinyint(3) unsigned NOT NULL DEFAULT '9',
+  `priority_level` tinyint(3) unsigned NOT NULL DEFAULT '15',
+  `pre_emp_cap` enum('ENABLED','DISABLED') DEFAULT 'DISABLED',
+  `pre_emp_vul` enum('ENABLED','DISABLED') DEFAULT 'DISABLED',
+  `LIPA-Permissions` enum('LIPA-prohibited','LIPA-only','LIPA-conditional') NOT NULL DEFAULT 'LIPA-only',
+  PRIMARY KEY (`id`,`pgw_id`,`users_imsi`),
+  KEY `fk_pdn_pgw1_idx` (`pgw_id`),
+  KEY `fk_pdn_users1_idx` (`users_imsi`)
+) ENGINE=MyISAM AUTO_INCREMENT=60 DEFAULT CHARSET=latin1;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping data for table `pdn`
+--
+
+LOCK TABLES `pdn` WRITE;
+/*!40000 ALTER TABLE `pdn` DISABLE KEYS */;
+INSERT INTO `pdn` VALUES (1,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208930000000001',9,15,'DISABLED','ENABLED','LIPA-only'),(41,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'20834123456789',9,15,'DISABLED','ENABLED','LIPA-only'),(40,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'20810000001234',9,15,'DISABLED','ENABLED','LIPA-only'),(42,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'31002890832150',9,15,'DISABLED','ENABLED','LIPA-only'),(16,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208950000000002',9,15,'DISABLED','ENABLED','LIPA-only'),(43,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'001010123456789',9,15,'DISABLED','ENABLED','LIPA-only'),(2,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208930000000002',9,15,'DISABLED','ENABLED','LIPA-only'),(3,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208930000000003',9,15,'DISABLED','ENABLED','LIPA-only'),(4,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208930000000004',9,15,'DISABLED','ENABLED','LIPA-only'),(5,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208930000000005',9,15,'DISABLED','ENABLED','LIPA-only'),(6,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208930000000006',9,15,'DISABLED','ENABLED','LIPA-only'),(7,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208930000000007',9,15,'DISABLED','ENABLED','LIPA-only'),(8,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208940000000001',9,15,'DISABLED','ENABLED','LIPA-only'),(9,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208940000000002',9,15,'DISABLED','ENABLED','LIPA-only'),(10,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208940000000003',9,15,'DISABLED','ENABLED','LIPA-only'),(11,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208940000000004',9,15,'DISABLED','ENABLED','LIPA-only'),(12,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208940000000005',9,15,'DISABLED','ENABLED','LIPA-only'),(13,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208940000000006',9,15,'DISABLED','ENABLED','LIPA-only'),(14,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208940000000007',9,15,'DISABLED','ENABLED','LIPA-only'),(15,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208950000000001',9,15,'DISABLED','ENABLED','LIPA-only'),(17,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208950000000003',9,15,'DISABLED','ENABLED','LIPA-only'),(18,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208950000000004',9,15,'DISABLED','ENABLED','LIPA-only'),(19,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208950000000005',9,15,'DISABLED','ENABLED','LIPA-only'),(20,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208950000000006',9,15,'DISABLED','ENABLED','LIPA-only'),(21,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208950000000007',9,15,'DISABLED','ENABLED','LIPA-only'),(22,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208920100001100',9,15,'DISABLED','ENABLED','LIPA-only'),(23,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208920100001101',9,15,'DISABLED','ENABLED','LIPA-only'),(24,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208920100001102',9,15,'DISABLED','ENABLED','LIPA-only'),(25,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208920100001103',9,15,'DISABLED','ENABLED','LIPA-only'),(26,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208920100001104',9,15,'DISABLED','ENABLED','LIPA-only'),(27,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208920100001105',9,15,'DISABLED','ENABLED','LIPA-only'),(28,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208920100001106',9,15,'DISABLED','ENABLED','LIPA-only'),(29,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208920100001107',9,15,'DISABLED','ENABLED','LIPA-only'),(30,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208920100001108',9,15,'DISABLED','ENABLED','LIPA-only'),(31,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208920100001109',9,15,'DISABLED','ENABLED','LIPA-only'),(32,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208920100001110',9,15,'DISABLED','ENABLED','LIPA-only'),(33,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208930100001111',9,15,'DISABLED','ENABLED','LIPA-only'),(34,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208930100001112',9,15,'DISABLED','ENABLED','LIPA-only'),(35,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208930100001113',9,15,'DISABLED','ENABLED','LIPA-only'),(44,'operator','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208930100001113',9,15,'DISABLED','ENABLED','LIPA-only'),(45,'operator','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208930100001112',9,15,'DISABLED','ENABLED','LIPA-only'),(46,'operator','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208930100001111',9,15,'DISABLED','ENABLED','LIPA-only'),(47,'operator','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208950000000002',9,15,'DISABLED','ENABLED','LIPA-only'),(48,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208950000000008',9,15,'DISABLED','ENABLED','LIPA-only'),(49,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208950000000009',9,15,'DISABLED','ENABLED','LIPA-only'),(50,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208950000000010',9,15,'DISABLED','ENABLED','LIPA-only'),(51,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208950000000011',9,15,'DISABLED','ENABLED','LIPA-only'),(52,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208950000000012',9,15,'DISABLED','ENABLED','LIPA-only'),(53,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208950000000013',9,15,'DISABLED','ENABLED','LIPA-only'),(54,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208950000000014',9,15,'DISABLED','ENABLED','LIPA-only'),(55,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208950000000015',9,15,'DISABLED','ENABLED','LIPA-only'),(56,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208920100001118',9,15,'DISABLED','ENABLED','LIPA-only'),(57,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208920100001121',9,15,'DISABLED','ENABLED','LIPA-only'),(58,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208920100001120',9,15,'DISABLED','ENABLED','LIPA-only'),(59,'oai.ipv4','IPv4','0.0.0.0','0:0:0:0:0:0:0:0',50000000,100000000,3,'208920100001119',9,15,'DISABLED','ENABLED','LIPA-only');
+/*!40000 ALTER TABLE `pdn` ENABLE KEYS */;
+UNLOCK TABLES;
+
+--
+-- Table structure for table `pgw`
+--
+
+DROP TABLE IF EXISTS `pgw`;
+/*!40101 SET @saved_cs_client     = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `pgw` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `ipv4` varchar(15) NOT NULL,
+  `ipv6` varchar(39) NOT NULL,
+  PRIMARY KEY (`id`),
+  UNIQUE KEY `ipv4` (`ipv4`),
+  UNIQUE KEY `ipv6` (`ipv6`)
+) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping data for table `pgw`
+--
+
+LOCK TABLES `pgw` WRITE;
+/*!40000 ALTER TABLE `pgw` DISABLE KEYS */;
+INSERT INTO `pgw` VALUES (1,'127.0.0.1','0:0:0:0:0:0:0:1'),(2,'192.168.56.101',''),(3,'10.0.0.2','0');
+/*!40000 ALTER TABLE `pgw` ENABLE KEYS */;
+UNLOCK TABLES;
+
+--
+-- Table structure for table `terminal-info`
+--
+
+DROP TABLE IF EXISTS `terminal-info`;
+/*!40101 SET @saved_cs_client     = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `terminal-info` (
+  `imei` varchar(15) NOT NULL,
+  `sv` varchar(2) NOT NULL,
+  UNIQUE KEY `imei` (`imei`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping data for table `terminal-info`
+--
+
+LOCK TABLES `terminal-info` WRITE;
+/*!40000 ALTER TABLE `terminal-info` DISABLE KEYS */;
+/*!40000 ALTER TABLE `terminal-info` ENABLE KEYS */;
+UNLOCK TABLES;
+
+--
+-- Table structure for table `users`
+--
+
+DROP TABLE IF EXISTS `users`;
+/*!40101 SET @saved_cs_client     = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `users` (
+  `imsi` varchar(15) NOT NULL COMMENT 'IMSI is the main reference key.',
+  `msisdn` varchar(46) DEFAULT NULL COMMENT 'The basic MSISDN of the UE (Presence of MSISDN is optional).',
+  `imei` varchar(15) DEFAULT NULL COMMENT 'International Mobile Equipment Identity',
+  `imei_sv` varchar(2) DEFAULT NULL COMMENT 'International Mobile Equipment Identity Software Version Number',
+  `ms_ps_status` enum('PURGED','NOT_PURGED') DEFAULT 'PURGED' COMMENT 'Indicates that ESM and EMM status are purged from MME',
+  `rau_tau_timer` int(10) unsigned DEFAULT '120',
+  `ue_ambr_ul` bigint(20) unsigned DEFAULT '50000000' COMMENT 'The Maximum Aggregated uplink MBRs to be shared across all Non-GBR bearers according to the subscription of the user.',
+  `ue_ambr_dl` bigint(20) unsigned DEFAULT '100000000' COMMENT 'The Maximum Aggregated downlink MBRs to be shared across all Non-GBR bearers according to the subscription of the user.',
+  `access_restriction` int(10) unsigned DEFAULT '60' COMMENT 'Indicates the access restriction subscription information. 3GPP TS.29272 #7.3.31',
+  `mme_cap` int(10) unsigned zerofill DEFAULT NULL COMMENT 'Indicates the capabilities of the MME with respect to core functionality e.g. regional access restrictions.',
+  `mmeidentity_idmmeidentity` int(11) NOT NULL DEFAULT '0',
+  `key` varbinary(16) NOT NULL DEFAULT '0' COMMENT 'UE security key',
+  `RFSP-Index` smallint(5) unsigned NOT NULL DEFAULT '1' COMMENT 'An index to specific RRM configuration in the E-UTRAN. Possible values from 1 to 256',
+  `urrp_mme` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'UE Reachability Request Parameter indicating that UE activity notification from MME has been requested by the HSS.',
+  `sqn` bigint(20) unsigned zerofill NOT NULL,
+  `rand` varbinary(16) NOT NULL,
+  `OPc` varbinary(16) DEFAULT NULL COMMENT 'Can be computed by HSS',
+  PRIMARY KEY (`imsi`,`mmeidentity_idmmeidentity`),
+  KEY `fk_users_mmeidentity_idx1` (`mmeidentity_idmmeidentity`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping data for table `users`
+--
+
+LOCK TABLES `users` WRITE;
+/*!40000 ALTER TABLE `users` DISABLE KEYS */;
+INSERT INTO `users` VALUES ('20834123456789','380561234567','35609204079300',NULL,'PURGED',50,40000000,100000000,47,0000000000,1,'+�E��ų\0�,IH��H',0,0,00000000000000000096,'Px�X \Z1��x��','^��K�����FeU���'),('20810000001234','33611123456','35609204079299',NULL,'PURGED',120,40000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000281454575616225,'\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0','�4�s@���z��~�'),('31002890832150','33638060059','35611302209414',NULL,'PURGED',120,40000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000012416,'`�F�݆��D��ϛ���','�4�s@���z��~�'),('001010123456789','33600101789','35609204079298',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'\0	\n\r',1,0,00000000000000000351,'\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0','L�*\\�����^��]� '),('208930000000001','33638030001','35609204079301',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000006103,'��wq��gzW�Ё��Z]','�4�s@���z��~�'),('208950000000002','33638050002','35609204079502',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000020471,'\0	\n\r','�4�s@���z��~�'),('208950000000003','33638050003','35609204079503',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000012343,'\0	\n\r','�4�s@���z��~�'),('208950000000004','33638050004','35609204079504',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000012215,'56f0261d9d051063','�4�s@���z��~�'),('208950000000005','33638050005','35609204079505',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000012215,'56f0261d9d051063','�4�s@���z��~�'),('208950000000001','33638050001','35609204079501',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000006103,'��wq��gzW�Ё��Z]','�4�s@���z��~�'),('208950000000006','33638050006','35609204079506',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000012215,'56f0261d9d051063','�4�s@���z��~�'),('208950000000007','33638050007','35609204079507',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000012215,'56f0261d9d051063','�4�s@���z��~�'),('208930000000002','33638030002','35609204079302',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000006103,'��wq��gzW�Ё��Z]','�4�s@���z��~�'),('208930000000003','33638030003','35609204079303',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000006103,'��wq��gzW�Ё��Z]','�4�s@���z��~�'),('208930000000004','33638030004','35609204079304',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000006103,'��wq��gzW�Ё��Z]','�4�s@���z��~�'),('208930000000005','33638030005','35609204079305',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000006103,'��wq��gzW�Ё��Z]','�4�s@���z��~�'),('208930000000006','33638030006','35609204079306',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000006103,'��wq��gzW�Ё��Z]','�4�s@���z��~�'),('208930000000007','33638030007','35609204079307',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000006103,'��wq��gzW�Ё��Z]','�4�s@���z��~�'),('208940000000007','33638040007','35609204079407',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000006103,'��wq��gzW�Ё��Z]','�4�s@���z��~�'),('208940000000006','33638040006','35609204079406',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000006103,'��wq��gzW�Ё��Z]','�4�s@���z��~�'),('208940000000005','33638040005','35609204079405',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000006103,'��wq��gzW�Ё��Z]','�4�s@���z��~�'),('208940000000004','33638040004','35609204079404',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000006103,'��wq��gzW�Ё��Z]','�4�s@���z��~�'),('208940000000003','33638040003','35609204079403',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000006103,'��wq��gzW�Ё��Z]','�4�s@���z��~�'),('208940000000002','33638040002','35609204079402',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000006103,'��wq��gzW�Ё��Z]','�4�s@���z��~�'),('208940000000001','33638040001','35609204079401',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000006103,'��wq��gzW�Ё��Z]','�4�s@���z��~�'),('208920100001100','33638020001','35609204079201',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000006103,'ebd07771ace8677a','�4�s@���z��~�'),('208920100001101','33638020001','35609204079201',NULL,'NOT_PURGED',120,50000000,100000000,47,0000000000,1,'��k��p~Љu{�K�',1,0,00000281044204937234,'\0	\n\r','�$I6;��+f�k�u�|�'),('208920100001102','33638020002','35609204079202',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000006103,'ebd07771ace8677a','�4�s@���z��~�'),('208920100001103','33638020003','35609204079203',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000006103,'ebd07771ace8677a','�4�s@���z��~�'),('208920100001104','33638020004','35609204079204',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000006103,'ebd07771ace8677a','�4�s@���z��~�'),('208920100001105','33638020005','35609204079205',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000006103,'ebd07771ace8677a','�4�s@���z��~�'),('208920100001106','33638020006','35609204079206',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��k��p~Љu{�K�',1,0,00000000000000006103,'ebd07771ace8677a','�$I6;��+f�k�u�|�'),('208920100001107','33638020007','35609204079207',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000006103,'ebd07771ace8677a','�4�s@���z��~�'),('208920100001108','33638020008','35609204079208',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000006103,'ebd07771ace8677a','�4�s@���z��~�'),('208920100001109','33638020009','35609204079209',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000006103,'ebd07771ace8677a','�4�s@���z��~�'),('208920100001110','33638020010','35609204079210',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000006103,'ebd07771ace8677a','�4�s@���z��~�'),('208930100001111','33638030011','35609304079211',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000006103,'ebd07771ace8677a','�4�s@���z��~�'),('208930100001112','33638030012','35609304079212',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000006103,'ebd07771ace8677a','�4�s@���z��~�'),('208930100001113','33638030013','35609304079213',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000006263,'�SNܒ�Iv��e�6','�4�s@���z��~�'),('208950000000008','33638050008','35609204079508',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000012215,'56f0261d9d051063','�4�s@���z��~�'),('208950000000009','33638050009','35609204079509',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000012215,'56f0261d9d051063','�4�s@���z��~�'),('208950000000010','33638050010','35609204079510',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000012215,'56f0261d9d051063','�4�s@���z��~�'),('208950000000011','33638050011','35609204079511',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000012215,'56f0261d9d051063','�4�s@���z��~�'),('208950000000012','33638050012','35609204079512',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000012215,'56f0261d9d051063','�4�s@���z��~�'),('208950000000013','33638050013','35609204079513',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000012215,'56f0261d9d051063','�4�s@���z��~�'),('208950000000014','33638050014','35609204079514',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000012215,'56f0261d9d051063','�4�s@���z��~�'),('208950000000015','33638050015','35609204079515',NULL,'PURGED',120,50000000,100000000,47,0000000000,1,'��G?/�Д����	|hb',1,0,00000000000000000000,'3536663032363164','�4�s@���z��~�'),('208920100001118','33638020010','35609204079210',NULL,'NOT_PURGED',120,50000000,100000000,47,0000000000,1,'��k��p~Љu{�K�',1,0,00000281044204934762,'~?03�u-%�ey�y�','�$I6;��+f�k�u�|�'),('208920100001121','33638020010','35609204079210',NULL,'NOT_PURGED',120,50000000,100000000,47,0000000000,1,'��k��p~Љu{�K�',1,0,00000281044204935293,'&��@xg�]���\n��Vp','�$I6;��+f�k�u�|�'),('208920100001119','33638020010','35609204079210',NULL,'NOT_PURGED',120,50000000,100000000,47,0000000000,1,'��k��p~Љu{�K�',1,0,00000281044204935293,'269482407867805d','�$I6;��+f�k�u�|�'),('208920100001120','33638020010','35609204079210',NULL,'NOT_PURGED',120,50000000,100000000,47,0000000000,1,'��k��p~Љu{�K�',1,0,00000281044204935293,'3236393438323430','�$I6;��+f�k�u�|�');
+INSERT INTO `users` VALUES ('208990100001100','1','55000000000000',NULL,'PURGED',50,40000000,100000000,47,0000000000,1,0xfec86ba6eb707ed08905757b1bb44b8f,0,0,0x40,'ebd07771ace8677a',0xc42449363bbad02b66d16bc975d77cc1);
+INSERT INTO `users` VALUES ('208950000000031','380561234567','55000000000001',NULL,'PURGED',50,40000000,100000000,47,0000000000,1,0x0C0A34601D4F07677303652C0462535B,0,0,0x40,'ebd07771ace8677a',0x63bfa50ee6523365ff14c1f45f88737d);
+INSERT INTO `users` VALUES ('208950000000032','380561234567','55000000000001',NULL,'PURGED',50,40000000,100000000,47,0000000000,1,0x0C0A34601D4F07677303652C0462535B,0,0,0x40,'ebd07771ace8677a',0x63bfa50ee6523365ff14c1f45f88737d);
+INSERT INTO `users` VALUES ('208950000000033','380561234567','55000000000001',NULL,'PURGED',50,40000000,100000000,47,0000000000,1,0x0C0A34601D4F07677303652C0462535B,0,0,0x40,'ebd07771ace8677a',0x63bfa50ee6523365ff14c1f45f88737d);
+INSERT INTO `users` VALUES ('208950000000034','380561234567','55000000000001',NULL,'PURGED',50,40000000,100000000,47,0000000000,1,0x0C0A34601D4F07677303652C0462535B,0,0,0x40,'ebd07771ace8677a',0x63bfa50ee6523365ff14c1f45f88737d);
+INSERT INTO `users` VALUES ('208950000000035','380561234567','55000000000001',NULL,'PURGED',50,40000000,100000000,47,0000000000,1,0x0C0A34601D4F07677303652C0462535B,0,0,0x40,'ebd07771ace8677a',0x63bfa50ee6523365ff14c1f45f88737d);
+INSERT INTO `users` VALUES ('208950000000036','380561234567','55000000000001',NULL,'PURGED',50,40000000,100000000,47,0000000000,1,0x0C0A34601D4F07677303652C0462535B,0,0,0x40,'ebd07771ace8677a',0x63bfa50ee6523365ff14c1f45f88737d);
+INSERT INTO `users` VALUES ('208950000000037','380561234567','55000000000001',NULL,'PURGED',50,40000000,100000000,47,0000000000,1,0x0C0A34601D4F07677303652C0462535B,0,0,0x40,'ebd07771ace8677a',0x63bfa50ee6523365ff14c1f45f88737d);
+INSERT INTO `users` VALUES ('208950000000038','380561234567','55000000000001',NULL,'PURGED',50,40000000,100000000,47,0000000000,1,0x0C0A34601D4F07677303652C0462535B,0,0,0x40,'ebd07771ace8677a',0x63bfa50ee6523365ff14c1f45f88737d);
+INSERT INTO `users` VALUES ('208950000000039','380561234567','55000000000001',NULL,'PURGED',50,40000000,100000000,47,0000000000,1,0x0C0A34601D4F07677303652C0462535B,0,0,0x40,'ebd07771ace8677a',0x63bfa50ee6523365ff14c1f45f88737d);
+INSERT INTO `users` VALUES ('208950000000040','380561234567','55000000000001',NULL,'PURGED',50,40000000,100000000,47,0000000000,1,0x0C0A34601D4F07677303652C0462535B,0,0,0x40,'ebd07771ace8677a',0x63bfa50ee6523365ff14c1f45f88737d);
+/*!40000 ALTER TABLE `users` ENABLE KEYS */;
+UNLOCK TABLES;
+/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
+
+/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
+/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
+/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
+/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
+/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
+/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
+/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
+
+-- Dump completed on 2016-06-28 11:41:40
diff --git a/ci-scripts/yaml_files/5g_f1_rfsimulator/smf-healthcheck.sh b/ci-scripts/yaml_files/5g_f1_rfsimulator/smf-healthcheck.sh
new file mode 100755
index 0000000000000000000000000000000000000000..d9ff7608e80d8ec5e840e94bcf074d27759c702d
--- /dev/null
+++ b/ci-scripts/yaml_files/5g_f1_rfsimulator/smf-healthcheck.sh
@@ -0,0 +1,21 @@
+#!/bin/bash
+set -eo pipefail
+
+STATUS=0
+SMF_IP_SBI_INTERFACE=$(ifconfig $SMF_INTERFACE_NAME_FOR_SBI | grep inet | awk {'print $2'})
+SMF_SBI_PORT_STATUS=$(netstat -tnpl | grep -o "$SMF_IP_SBI_INTERFACE:$SMF_INTERFACE_PORT_FOR_SBI")
+
+#Check if entrypoint properly configured the conf file and no parameter is unset(optional)
+#NB_UNREPLACED_AT=`cat /openair-smf/etc/*.conf | grep -v contact@openairinterface.org | grep -c @ || true`
+
+#if [ $NB_UNREPLACED_AT -ne 0 ]; then
+#	STATUS=-1
+#	echo "Healthcheck error: UNHEALTHY configuration file is not configured properly"
+#fi
+#
+if [[ -z $SMF_SBI_PORT_STATUS ]]; then
+	STATUS=-1
+	echo "Healthcheck error: UNHEALTHY SBI TCP/HTTP port $SMF_INTERFACE_PORT_FOR_SBI is not listening."
+fi
+
+exit $STATUS
diff --git a/ci-scripts/yaml_files/5g_f1_rfsimulator/spgwu-healthcheck.sh b/ci-scripts/yaml_files/5g_f1_rfsimulator/spgwu-healthcheck.sh
new file mode 100755
index 0000000000000000000000000000000000000000..0e3b67ee7e5653a19552ceae70abd36b04a223a7
--- /dev/null
+++ b/ci-scripts/yaml_files/5g_f1_rfsimulator/spgwu-healthcheck.sh
@@ -0,0 +1,28 @@
+#!/bin/bash
+set -eo pipefail
+
+STATUS=0
+SGW_PORT_FOR_S1U_S12_S4_UP=2152
+SGW_PORT_FOR_SX=8805
+SGW_IP_S1U_INTERFACE=$(ifconfig $SGW_INTERFACE_NAME_FOR_S1U_S12_S4_UP | grep inet | awk {'print $2'})
+SGW_IP_SX_INTERFACE=$(ifconfig $SGW_INTERFACE_NAME_FOR_SX | grep inet | awk {'print $2'})
+S1U_S12_S4_UP_PORT_STATUS=$(netstat -unpl | grep -o "$SGW_IP_S1U_INTERFACE:$SGW_PORT_FOR_S1U_S12_S4_UP")
+SX_PORT_STATUS=$(netstat -unpl | grep -o "$SGW_IP_SX_INTERFACE:$SGW_PORT_FOR_SX")
+#Check if entrypoint properly configured the conf file and no parameter is unset (optional)
+NB_UNREPLACED_AT=`cat /openair-spgwu/etc/*.conf | grep -v contact@openairinterface.org | grep -c @ || true`
+if [ $NB_UNREPLACED_AT -ne 0 ]; then
+	STATUS=1
+	echo "Healthcheck error: UNHEALTHY configuration file is not configured properly"
+fi
+
+if [[ -z $S1U_S12_S4_UP_PORT_STATUS ]]; then
+	STATUS=1
+	echo "Healthcheck error: UNHEALTHY S1U port $SGW_PORT_FOR_S1U_S12_S4_UP is not listening."
+fi
+
+if [[ -z $SX_PORT_STATUS ]]; then
+	STATUS=1
+	echo "Healthcheck error: UNHEALTHY SX port $SGW_PORT_FOR_SX is not listening."
+fi
+
+exit $STATUS
\ No newline at end of file
diff --git a/ci-scripts/yaml_files/5g_rfsimulator/README.md b/ci-scripts/yaml_files/5g_rfsimulator/README.md
index 915b71296fa1ecada3beecdfd634f320667d7337..5c384b3202fe080d5d8f20e4ef272f311b035373 100644
--- a/ci-scripts/yaml_files/5g_rfsimulator/README.md
+++ b/ci-scripts/yaml_files/5g_rfsimulator/README.md
@@ -88,7 +88,9 @@ $ docker logout
 
 **Just `docker-compose up -d` WILL NOT WORK!**
 
-All the following commands **SHALL** be run from the `ci-scripts/yaml_files/5g_rfsimulator` folder.
+All the following commands **SHALL** be run from the `ci-scripts/yaml_files/5g_rfsimulator` folder for a deployment with monolithic gNB.
+
+For a deployment with the gNB split in CU and DU components, the following commands **SHALL** be run from the `ci-scripts/yaml_files/5g_f1_rfsimulator` folder. 
 
 ## 2.1. Deploy OAI 5G Core Network ##
 
@@ -148,6 +150,9 @@ rfsim5g-traffic: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
 
 **CAUTION: To execute this 2nd step, the whole `CN5G` SHALL be in `healthy` state (especially the `mysql` container).**
 
+The gNB can be deployed either in monolithic mode, or in CU/DU split mode.
+- For a deployment with a monolithic gNB:
+
 ```bash
 $ docker-compose up -d oai-gnb
 rfsim5g-oai-nrf is up-to-date
@@ -155,7 +160,16 @@ rfsim5g-oai-spgwu is up-to-date
 rfsim5g-oai-ext-dn is up-to-date
 Creating rfsim5g-oai-gnb ... done
 ```
+- For a deployment with the gNB split in CU and DU components:
+```bash
+#Deployment of the CU
+$ docker-compose up -d oai-cu
+```
 
+```bash
+#Deployment of the DU
+$ docker-compose up -d oai-du
+```
 Wait for a bit.
 
 ```bash
diff --git a/ci-scripts/yaml_files/5g_rfsimulator/docker-compose.yaml b/ci-scripts/yaml_files/5g_rfsimulator/docker-compose.yaml
index 31d64f35dc8dc06e866ff88c7aa308c7dd41972a..952da8087dd93c44f7a1b2c63ebfee5ee1477597 100644
--- a/ci-scripts/yaml_files/5g_rfsimulator/docker-compose.yaml
+++ b/ci-scripts/yaml_files/5g_rfsimulator/docker-compose.yaml
@@ -244,7 +244,7 @@ services:
             GNB_NGA_IP_ADDRESS: 192.168.71.136
             GNB_NGU_IF_NAME: eth0
             GNB_NGU_IP_ADDRESS: 192.168.71.136
-            USE_ADDITIONAL_OPTIONS: --sa -E --rfsim
+            USE_ADDITIONAL_OPTIONS: --sa -E --rfsim --log_config.global_log_options level,nocolor,time
         depends_on:
             - oai-ext-dn
         networks:
@@ -267,7 +267,7 @@ services:
             DNN: oai
             NSSAI_SST: 1
             NSSAI_SD: 1
-            USE_ADDITIONAL_OPTIONS: -E --sa --rfsim -r 106 --numerology 1 -C 3619200000 --nokrnmod
+            USE_ADDITIONAL_OPTIONS: -E --sa --rfsim -r 106 --numerology 1 -C 3619200000 --nokrnmod --log_config.global_log_options level,nocolor,time
         depends_on:
             - oai-gnb
         networks:
diff --git a/ci-scripts/yaml_files/fr1_enb_mono_fdd_tim/docker-compose.yml b/ci-scripts/yaml_files/fr1_enb_mono_fdd_tim/docker-compose.yml
index 2df277d78baa8c43a6cdb15cbda2735e7d2eb9e5..b7dd3d0296194a4ccf8837db1979656b6d0d19ce 100644
--- a/ci-scripts/yaml_files/fr1_enb_mono_fdd_tim/docker-compose.yml
+++ b/ci-scripts/yaml_files/fr1_enb_mono_fdd_tim/docker-compose.yml
@@ -27,7 +27,7 @@ services:
             FLEXRAN_ENABLED: 'no'
             FLEXRAN_INTERFACE_NAME: eth0
             FLEXRAN_IPV4_ADDRESS: CI_FLEXRAN_CTL_IP_ADDR
-            USE_ADDITIONAL_OPTIONS: '--RUs.[0].max_rxgain 115 --RUs.[0].max_pdschReferenceSignalPower -27 --eNBs.[0].component_carriers.[0].pucch_p0_Nominal -96'
+            USE_ADDITIONAL_OPTIONS: --RUs.[0].max_rxgain 115 --RUs.[0].max_pdschReferenceSignalPower -27 --eNBs.[0].component_carriers.[0].pucch_p0_Nominal -96 --log_config.global_log_options level,nocolor,time
         volumes:
             - /dev:/dev
         networks:
diff --git a/ci-scripts/yaml_files/nsa_b200_enb/docker-compose.yml b/ci-scripts/yaml_files/nsa_b200_enb/docker-compose.yml
index 9bd08aeabca231990a90be98401ed3b619435da1..92ccdf8a0ac3fe0e2251ad62e23177f2e060c533 100644
--- a/ci-scripts/yaml_files/nsa_b200_enb/docker-compose.yml
+++ b/ci-scripts/yaml_files/nsa_b200_enb/docker-compose.yml
@@ -31,6 +31,7 @@ services:
             FLEXRAN_INTERFACE_NAME: eth0
             FLEXRAN_IPV4_ADDRESS: 192.168.18.210
             THREAD_PARALLEL_CONFIG: PARALLEL_SINGLE_THREAD
+            USE_ADDITIONAL_OPTIONS: --log_config.global_log_options level,nocolor,time,line_num,function
         volumes:
             - /dev:/dev
         networks:
diff --git a/ci-scripts/yaml_files/nsa_b200_gnb/docker-compose.yml b/ci-scripts/yaml_files/nsa_b200_gnb/docker-compose.yml
index 4ae51158ac2a0783c7627b6769f16788e6169f1e..c6096956a87ec2105ea7b341ae130fef0233d686 100644
--- a/ci-scripts/yaml_files/nsa_b200_gnb/docker-compose.yml
+++ b/ci-scripts/yaml_files/nsa_b200_gnb/docker-compose.yml
@@ -26,7 +26,7 @@ services:
             FLEXRAN_INTERFACE_NAME: eth0
             FLEXRAN_IPV4_ADDRESS: 192.168.18.210
             THREAD_PARALLEL_CONFIG: PARALLEL_RU_L1_TRX_SPLIT
-            USE_ADDITIONAL_OPTIONS: -E -q --RUs.[0].sdr_addrs serial=30C51D4
+            USE_ADDITIONAL_OPTIONS: -E -q --RUs.[0].sdr_addrs serial=30C51D4 --log_config.global_log_options level,nocolor,time,line_num,function
         volumes:
             - /dev:/dev
         networks:
diff --git a/cmake_targets/.gitignore b/cmake_targets/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..6d6cdd29a6a82c09fa1a646f36852a5a2af35dcf
--- /dev/null
+++ b/cmake_targets/.gitignore
@@ -0,0 +1,3 @@
+.usim.*
+.ue_emm.nvram*
+.ue.nvram*
diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt
index f513ac056336e102d12d85ecdcf1e49fc8bbbbd3..bf3bb2b017ce4bb01b0753576eeb95a9157232ce 100644
--- a/cmake_targets/CMakeLists.txt
+++ b/cmake_targets/CMakeLists.txt
@@ -359,6 +359,10 @@ set(CMAKE_C_FLAGS_DEBUG "${debugOpt} -O0")
 set(CMAKE_C_FLAGS_RELWITHDEBINFO "${debugOpt} -O2")
 set(CMAKE_C_FLAGS_RELEASE "-O3")
 
+# Enable assert() for RelWithDebInfo builds
+string(REPLACE "-DNDEBUG" "" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
+string(REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
+
 set(GIT_BRANCH        "UNKNOWN")
 set(GIT_COMMIT_HASH   "UNKNOWN")
 set(GIT_COMMIT_DATE   "UNKNOWN")
@@ -396,14 +400,13 @@ set (FIRMWARE_VERSION "No svn information")
 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_definitions("-DEMIT_ASN_DEBUG=1")
 
 
 # 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(MSG_PRINT           False "print debug messages")
+add_boolean_option(ASN_EMIT_DEBUG      False "ASN1 coder/decoder Debug")
+add_boolean_option(ASN_THREAD_SAFE     True "ASN1 coder/decoder Debug")
+add_boolean_option(MSG_PRINT           True "print debug messages")
 add_boolean_option(DISABLE_XER_PRINT   False "print XER Format")
 add_boolean_option(XER_PRINT           False "print XER Format")
 add_boolean_option(RRC_MSG_PRINT       False "print RRC messages")
@@ -600,10 +603,13 @@ set(M2AP_ASN_DIR ${M2AP_DIR}/MESSAGES/ASN1/${M2AP_RELEASE})
 set(M2AP_C_DIR ${asn1_generated_dir}/M2AP_${M2AP_RELEASE})
 
 # Warning: if you modify ASN.1 source file to generate new C files, cmake should be re-run instead of make
+
 set(m2ap_cmd ${OPENAIR_CMAKE}/tools/make_asn1c_includes.sh  "M2AP_" "-fno-include-deps -DEMIT_ASN_DEBUG=1" "${M2AP_C_DIR}")
 
+
 compile_asn1("${M2AP_ASN_DIR}/${M2AP_ASN_FILES}" "${m2ap_cmd}"  m2_flag)
 file(GLOB M2AP_source ${M2AP_C_DIR}/*.c)
+
 add_library(M2AP_LIB
   ${M2AP_source}
   ${M2AP_DIR}/m2ap_common.c
@@ -755,6 +761,7 @@ set(F1AP_ASN_FILES
   ${F1AP_ASN_DIR}/F1AP-Containers.asn
   )
 
+
 set(F1AP_ASN_GENERATED_C_DIR ${asn1_generated_dir}/F1AP_${ASN1RELDIR})
 
 set(f1_cmd ${OPENAIR_CMAKE}/tools/make_asn1c_includes.sh "F1AP_" "-findirect-choice -fno-include-deps" "${F1AP_ASN_GENERATED_C_DIR}")
@@ -773,6 +780,7 @@ include_directories ("${F1AP_DIR}")
 file(GLOB F1AP_C_FILES ${F1AP_DIR}/*.c)
 add_library(F1AP ${F1AP_C_FILES} )
 
+
 # Hardware dependant options
 ###################################
 add_list1_option(NB_ANTENNAS_RX "4" "Number of antennas in reception" "1" "2" "4")
@@ -1011,6 +1019,7 @@ add_boolean_option(TRACE_RLC_UM_TX_STATUS  False "TRACE for RLC UM, TO BE CHANGE
 ##########################
 #add_boolean_option(LINK_ENB_PDCP_TO_IP_DRIVER  False "For eNB, PDCP communicate with a IP driver")
 #add_boolean_option(LINK_ENB_PDCP_TO_GTPV1U     True  "For eNB, PDCP communicate with GTP-U protocol (eNB<->S-GW)")
+add_definitions(-DNEW_GTPU=1)
 
 ##########################
 # RRC LAYER OPTIONS
@@ -1467,6 +1476,7 @@ set(NFAPI_USER_SRC
   ${NFAPI_USER_DIR}/nfapi.c
   ${NFAPI_USER_DIR}/nfapi_pnf.c
   ${NFAPI_USER_DIR}/nfapi_vnf.c
+  ${NFAPI_USER_DIR}/gnb_ind_vars.c
 )
 add_library(NFAPI_USER_LIB ${NFAPI_USER_SRC})
 add_dependencies(NFAPI_USER_LIB rrc_flag)
@@ -2020,6 +2030,7 @@ set(NR_L2_SRC_UE
   ${NR_UE_RRC_DIR}/L2_interface_ue.c
   ${NR_UE_RRC_DIR}/main_ue.c
   ${NR_UE_RRC_DIR}/rrc_UE.c
+  ${NR_UE_RRC_DIR}/rrc_nsa.c
   )
 
 set (MAC_SRC
@@ -2064,6 +2075,7 @@ set (MAC_NR_SRC
 
 set (MAC_SRC_UE
   ${PHY_INTERFACE_DIR}/phy_stub_UE.c
+  ${PHY_INTERFACE_DIR}/queue_t.c
   ${MAC_DIR}/main_ue.c
   ${MAC_DIR}/ue_procedures.c
   ${MAC_DIR}/ra_procedures.c
@@ -2777,6 +2789,7 @@ add_executable(lte-softmodem
   ${OPENAIR3_DIR}/NAS/UE/nas_ue_task.c
   ${OPENAIR_DIR}/common/utils/utils.c
   ${OPENAIR_DIR}/common/utils/system.c
+  ${PHY_INTERFACE_DIR}/queue_t.c
   ${OPENAIR_DIR}/common/utils/lte/ue_power.c
   ${OPENAIR_DIR}/common/utils/lte/prach_utils.c
   ${XFORMSINTERFACE_SOURCE}
@@ -2788,7 +2801,7 @@ add_dependencies(lte-softmodem rrc_flag s1ap_flag x2_flag oai_iqplayer)
 
 target_link_libraries (lte-softmodem
   -Wl,--start-group
-  RRC_LIB NR_RRC_LIB S1AP_LIB S1AP_ENB F1AP_LIB F1AP M2AP_LIB M2AP_ENB X2AP_LIB X2AP_ENB M3AP_LIB M3AP_ENB NR_GTPV1U SECU_CN SECU_OSA UTIL HASHTABLE SCTP_CLIENT MME_APP UDP SCHED_LIB SCHED_RU_LIB
+  RRC_LIB NR_RRC_LIB S1AP_LIB S1AP_ENB M2AP_LIB M2AP_ENB X2AP_LIB X2AP_ENB M3AP_LIB M3AP_ENB GTPV1U_OCP F1AP_LIB F1AP SECU_CN SECU_OSA UTIL HASHTABLE SCTP_CLIENT MME_APP UDP SCHED_LIB SCHED_RU_LIB
   PHY_COMMON PHY PHY_RU LFDS L2 L2_LTE NFAPI_COMMON_LIB NFAPI_LIB NFAPI_VNF_LIB NFAPI_PNF_LIB NFAPI_USER_LIB MISC_NFAPI_LTE_LIB LFDS7
   ${MSC_LIB} ${RAL_LIB} ${NAS_UE_LIB} ITTI ${FLPT_MSG_LIB} ${ASYNC_IF_LIB} ${FLEXRAN_AGENT_LIB} ${FSPT_MSG_LIB} ${PROTO_AGENT_LIB}
   -Wl,--end-group z dl)
@@ -2821,6 +2834,7 @@ add_executable(ocp-enb
   ${OPENAIR_DIR}/common/utils/system.c
   ${OPENAIR_DIR}/common/utils/lte/ue_power.c
   ${OPENAIR_DIR}/common/utils/lte/prach_utils.c
+  ${PHY_INTERFACE_DIR}/queue_t.c
   ${XFORMSINTERFACE_SOURCE}
   ${T_SOURCE}
   ${CONFIG_SOURCES}
@@ -2831,7 +2845,7 @@ add_dependencies(ocp-enb rrc_flag s1ap_flag x2_flag oai_iqplayer coding params_l
 target_link_libraries (ocp-enb
   -Wl,--start-group
 
-  RRC_LIB NR_RRC_LIB S1AP_LIB S1AP_ENB F1AP_LIB F1AP M2AP_LIB M2AP_ENB X2AP_LIB X2AP_ENB M3AP_LIB M3AP_ENB NR_GTPV1U SECU_CN SECU_OSA UTIL HASHTABLE SCTP_CLIENT MME_APP UDP SCHED_LIB SCHED_RU_LIB
+  RRC_LIB NR_RRC_LIB S1AP_LIB S1AP_ENB F1AP_LIB F1AP M2AP_LIB M2AP_ENB X2AP_LIB X2AP_ENB M3AP_LIB M3AP_ENB GTPV1U_OCP SECU_CN SECU_OSA UTIL HASHTABLE SCTP_CLIENT MME_APP UDP SCHED_LIB SCHED_RU_LIB
   PHY_COMMON PHY PHY_RU LFDS L2 L2_LTE NFAPI_COMMON_LIB NFAPI_LIB MISC_NFAPI_LTE_LIB NFAPI_VNF_LIB NFAPI_PNF_LIB NFAPI_USER_LIB LFDS7 SIMU_COMMON
   ${MSC_LIB} ${RAL_LIB} ${NAS_UE_LIB} ITTI ${FLPT_MSG_LIB} ${ASYNC_IF_LIB} ${FLEXRAN_AGENT_LIB} ${FSPT_MSG_LIB} ${PROTO_AGENT_LIB}
   -Wl,--end-group z dl)
@@ -2926,9 +2940,8 @@ if (NOT ${NOS1})
 endif()
 target_link_libraries (lte-uesoftmodem
   -Wl,--start-group
-  RRC_LIB NR_RRC_LIB S1AP_LIB S1AP_ENB X2AP_LIB X2AP_ENB M2AP_LIB M2AP_ENB M3AP_LIB M3AP_ENB F1AP F1AP_LIB
-
-  NR_GTPV1U SECU_CN SECU_OSA UTIL HASHTABLE SCTP_CLIENT MME_APP UDP SCHED_RU_LIB SCHED_UE_LIB PHY_COMMON
+  RRC_LIB NR_RRC_LIB S1AP_LIB S1AP_ENB X2AP_LIB X2AP_ENB M2AP_LIB M2AP_ENB M3AP_LIB M3AP_ENB
+  SECU_CN SECU_OSA UTIL HASHTABLE SCTP_CLIENT MME_APP UDP SCHED_RU_LIB SCHED_UE_LIB PHY_COMMON
   PHY_UE PHY_RU LFDS L2_UE L2_LTE LFDS7 SIMU_COMMON SIMU NFAPI_COMMON_LIB NFAPI_LIB NFAPI_PNF_LIB NFAPI_USER_LIB MISC_NFAPI_LTE_LIB
   ${MSC_LIB} ${RAL_LIB} ${NAS_UE_LIB} ITTI ${FLPT_MSG_LIB} ${ASYNC_IF_LIB} ${ATLAS_LIBRARIES}
   -Wl,--end-group z dl)
@@ -2962,6 +2975,7 @@ add_executable(nr-softmodem
   ${OPENAIR_DIR}/common/utils/lte/ue_power.c
   ${OPENAIR_DIR}/common/utils/lte/prach_utils.c
   ${OPENAIR_DIR}/common/utils/nr/nr_common.c
+  ${PHY_INTERFACE_DIR}/queue_t.c
   ${XFORMSINTERFACE_SOURCE}
   ${T_SOURCE}
   ${CONFIG_SOURCES}
@@ -3002,6 +3016,7 @@ add_executable(ocp-gnb
   ${OPENAIR_DIR}/common/utils/nr/nr_common.c
   ${OPENAIR_DIR}/common/utils/utils.c
   ${OPENAIR_DIR}/common/utils/system.c
+  ${PHY_INTERFACE_DIR}/queue_t.c
   ${XFORMS_SOURCE_NR}
   ${T_SOURCE}
   ${CONFIG_SOURCES}
@@ -3205,14 +3220,16 @@ add_executable(nr_dlsim
   ${OPENAIR_DIR}/executables/softmodem-common.c
   ${OPENAIR2_DIR}/RRC/NAS/nas_config.c
   ${OPENAIR1_DIR}/SIMULATION/ETH_TRANSPORT/netlink_init.c
+  ${NR_UE_RRC_DIR}/rrc_nsa.c
   ${NFAPI_USER_DIR}/nfapi.c
   ${OPENAIR_DIR}/common/utils/threadPool/thread-pool.c
+  ${PHY_INTERFACE_DIR}/queue_t.c
   ${UTIL_SRC}
   ${T_SOURCE}
   ${SHLIB_LOADER_SOURCES}
   )
 target_link_libraries(nr_dlsim
-  -Wl,--start-group UTIL SIMU_COMMON SIMU PHY_COMMON PHY_NR_COMMON PHY_NR PHY_NR_UE SCHED_NR_LIB SCHED_NR_UE_LIB MAC_NR MAC_UE_NR MAC_NR_COMMON RRC_LIB NR_RRC_LIB CONFIG_LIB L2_LTE_NR L2_NR HASHTABLE X2AP_ENB X2AP_LIB SECU_CN NGAP_GNB -Wl,--end-group
+  -Wl,--start-group UTIL SIMU_COMMON SIMU PHY_COMMON PHY_NR_COMMON PHY_NR PHY_NR_UE SCHED_NR_LIB SCHED_NR_UE_LIB MAC_NR MAC_UE_NR MAC_NR_COMMON RRC_LIB NR_RRC_LIB CONFIG_LIB L2_LTE_NR L2_NR HASHTABLE X2AP_ENB X2AP_LIB SECU_CN NGAP_GNB NFAPI_COMMON_LIB NFAPI_LIB NFAPI_PNF_LIB NFAPI_USER_LIB -lz -Wl,--end-group
   m pthread ${ATLAS_LIBRARIES} ${T_LIB} ITTI ${OPENSSL_LIBRARIES} dl
   )
 target_compile_definitions(nr_dlsim PUBLIC -DPHYSICAL_SIMULATOR)
@@ -3225,13 +3242,15 @@ add_executable(nr_prachsim
   ${OPENAIR1_DIR}/SCHED_NR/phy_procedures_nr_common.c
   ${OPENAIR2_DIR}/RRC/NAS/nas_config.c
   ${OPENAIR1_DIR}/SIMULATION/ETH_TRANSPORT/netlink_init.c
+  ${NR_UE_RRC_DIR}/rrc_nsa.c
   ${NFAPI_USER_DIR}/nfapi.c
   ${OPENAIR_DIR}/common/utils/threadPool/thread-pool.c
+  ${PHY_INTERFACE_DIR}/queue_t.c
   ${UTIL_SRC}
   ${T_SOURCE}
   ${SHLIB_LOADER_SOURCES})
 target_link_libraries(nr_prachsim
-  -Wl,--start-group UTIL SIMU_COMMON SIMU PHY_COMMON PHY_NR_COMMON PHY_NR PHY_RU PHY_NR_UE MAC_NR_COMMON SCHED_NR_LIB SCHED_NR_UE_LIB MAC_NR MAC_UE_NR MAC_NR_COMMON RRC_LIB NR_RRC_LIB CONFIG_LIB L2_LTE_NR L2_NR HASHTABLE X2AP_ENB X2AP_LIB SECU_CN NGAP_GNB -Wl,--end-group
+  -Wl,--start-group UTIL SIMU_COMMON SIMU PHY_COMMON PHY_NR_COMMON PHY_NR PHY_RU PHY_NR_UE MAC_NR_COMMON SCHED_NR_LIB SCHED_NR_UE_LIB MAC_NR MAC_UE_NR MAC_NR_COMMON RRC_LIB NR_RRC_LIB CONFIG_LIB L2_LTE_NR L2_NR HASHTABLE X2AP_ENB X2AP_LIB SECU_CN NGAP_GNB NFAPI_COMMON_LIB NFAPI_LIB NFAPI_PNF_LIB NFAPI_USER_LIB -lz -Wl,--end-group
   m pthread ${ATLAS_LIBRARIES} ${T_LIB} ITTI ${OPENSSL_LIBRARIES} dl)
 
 add_executable(nr_ulschsim
@@ -3240,6 +3259,7 @@ add_executable(nr_ulschsim
   ${OPENAIR_DIR}/common/utils/utils.c
   ${OPENAIR_DIR}/common/utils/system.c
   ${OPENAIR_DIR}/common/utils/nr/nr_common.c
+  ${PHY_INTERFACE_DIR}/queue_t.c
   ${UTIL_SRC}
   ${T_SOURCE}
   ${SHLIB_LOADER_SOURCES}
@@ -3258,13 +3278,15 @@ add_executable(nr_ulsim
   ${OPENAIR_DIR}/executables/softmodem-common.c
   ${OPENAIR2_DIR}/RRC/NAS/nas_config.c
   ${OPENAIR1_DIR}/SIMULATION/ETH_TRANSPORT/netlink_init.c
+  ${NR_UE_RRC_DIR}/rrc_nsa.c
   ${NFAPI_USER_DIR}/nfapi.c
+  ${PHY_INTERFACE_DIR}/queue_t.c
   ${UTIL_SRC}
   ${T_SOURCE}
   ${SHLIB_LOADER_SOURCES}
   )
 target_link_libraries(nr_ulsim
-  -Wl,--start-group UTIL SIMU_COMMON SIMU PHY_COMMON PHY_NR_COMMON PHY_NR PHY_NR_UE SCHED_NR_LIB SCHED_NR_UE_LIB MAC_NR MAC_UE_NR MAC_NR_COMMON RRC_LIB NR_RRC_LIB CONFIG_LIB L2_LTE_NR L2_NR HASHTABLE X2AP_ENB X2AP_LIB SECU_CN NGAP_GNB -Wl,--end-group
+  -Wl,--start-group UTIL SIMU_COMMON SIMU PHY_COMMON PHY_NR_COMMON PHY_NR PHY_NR_UE SCHED_NR_LIB SCHED_NR_UE_LIB MAC_NR MAC_UE_NR MAC_NR_COMMON RRC_LIB NR_RRC_LIB CONFIG_LIB L2_LTE_NR L2_NR HASHTABLE X2AP_ENB X2AP_LIB SECU_CN NGAP_GNB NFAPI_COMMON_LIB NFAPI_LIB NFAPI_PNF_LIB NFAPI_USER_LIB -lz -Wl,--end-group
   m pthread ${ATLAS_LIBRARIES} ${T_LIB} ITTI ${OPENSSL_LIBRARIES} dl
   )
 target_compile_definitions(nr_ulsim PUBLIC -DPHYSICAL_SIMULATOR)
@@ -3302,7 +3324,7 @@ add_executable(test_epc_generate_scenario
   ${OPENAIR3_DIR}/S1AP/s1ap_eNB_defs.h
   )
 target_link_libraries (test_epc_generate_scenario
-  -Wl,--start-group RRC_LIB S1AP_LIB S1AP_ENB X2AP_LIB X2AP_ENB M2AP_LIB M2AP_ENB M3AP_LIB M3AP_ENB F1AP_LIB F1AP NR_GTPV1U LIB_NAS_UE SECU_CN UTIL HASHTABLE SCTP_CLIENT MME_APP UDP SCHED_LIB PHY LFDS ITTI ${MSC_LIB} L2 -Wl,--end-group pthread m rt crypt sctp ${LIBXML2_LIBRARIES} ${LIBXSLT_LIBRARIES} ${CRYPTO_LIBRARIES} ${OPENSSL_LIBRARIES} ${CONFIG_LIB}
+  -Wl,--start-group RRC_LIB S1AP_LIB S1AP_ENB X2AP_LIB X2AP_ENB M2AP_LIB M2AP_ENB M3AP_LIB M3AP_ENB F1AP_LIB F1AP GTPV1U_OCP LIB_NAS_UE SECU_CN UTIL HASHTABLE SCTP_CLIENT MME_APP UDP SCHED_LIB PHY LFDS ITTI ${MSC_LIB} L2 -Wl,--end-group pthread m rt crypt sctp ${LIBXML2_LIBRARIES} ${LIBXSLT_LIBRARIES} ${CRYPTO_LIBRARIES} ${OPENSSL_LIBRARIES} ${CONFIG_LIB}
   )
 
 add_executable(test_epc_play_scenario
@@ -3321,7 +3343,7 @@ add_executable(test_epc_play_scenario
   )
 target_include_directories(test_epc_play_scenario PUBLIC /usr/local/share/asn1c)
 target_link_libraries (test_epc_play_scenario
-  -Wl,--start-group RRC_LIB S1AP_LIB X2AP_LIB X2AP_ENB M3AP_LIB M3AP_ENB F1AP_LIB F1AP NR_GTPV1U LIB_NAS_UE SECU_CN UTIL HASHTABLE SCTP_CLIENT MME_APP UDP SCHED_LIB PHY_NR_COMMON PHY_COMMON PHY PHY_UE LFDS ITTI ${MSC_LIB} -Wl,--end-group pthread m rt crypt sctp ${LIBXML2_LIBRARIES} ${LIBXSLT_LIBRARIES} ${CRYPTO_LIBRARIES} ${OPENSSL_LIBRARIES} ${CONFIG_LIB}
+  -Wl,--start-group RRC_LIB S1AP_LIB X2AP_LIB X2AP_ENB M3AP_LIB M3AP_ENB F1AP_LIB F1AP GTPV1U_OCP LIB_NAS_UE SECU_CN UTIL HASHTABLE SCTP_CLIENT MME_APP UDP SCHED_LIB PHY_NR_COMMON PHY_COMMON PHY PHY_UE LFDS ITTI ${MSC_LIB} -Wl,--end-group pthread m rt crypt sctp ${LIBXML2_LIBRARIES} ${LIBXSLT_LIBRARIES} ${CRYPTO_LIBRARIES} ${OPENSSL_LIBRARIES} ${CONFIG_LIB}
   )
 
 
@@ -3367,7 +3389,7 @@ if (${T_TRACER})
         NFAPI_COMMON_LIB NFAPI_LIB NFAPI_PNF_LIB NFAPI_VNF_LIB NFAPI_USER_LIB
         PHY_COMMON PHY PHY_UE PHY_NR PHY_NR_COMMON PHY_NR_UE PHY_RU PHY_MEX
         L2 L2_LTE L2_NR L2_LTE_NR L2_UE NR_L2_UE L2_UE_LTE_NR MAC_NR_COMMON MAC_NR MAC_UE_NR NGAP_GNB
-        CN_UTILS NR_GTPV1U GTPV1U_OCP SCTP_CLIENT MME_APP UDP LIB_NAS_UE NB_IoT LFDS LFDS7 SIMU_COMMON SIMU SIMU_ETH OPENAIR0_LIB
+        CN_UTILS GTPV1U_OCP GTPV1U_OCP SCTP_CLIENT MME_APP UDP LIB_NAS_UE NB_IoT LFDS LFDS7 SIMU_COMMON SIMU SIMU_ETH OPENAIR0_LIB
         ldpc_orig ldpc_optim ldpc_optim8seg ldpc PROTO_AGENT dfts)
     if (TARGET ${i})
       add_dependencies(${i} generate_T)
diff --git a/common/config/config_load_configmodule.c b/common/config/config_load_configmodule.c
index 740c6e240bc77c61c99fbc08982d83ec30ba3fcd..b961a5db671fc24a5d845e3c041f46129971611a 100644
--- a/common/config/config_load_configmodule.c
+++ b/common/config/config_load_configmodule.c
@@ -182,8 +182,8 @@ int config_cmdlineonly_get(paramdef_t *cfgoptions,int numoptions, char *prefix )
 }
 
 configmodule_interface_t *load_configmodule(int argc,
-		                                    char **argv,
-											uint32_t initflags)
+					    char **argv,
+					    uint32_t initflags)
 {
   char *cfgparam=NULL;
   char *modeparams=NULL;
@@ -194,6 +194,11 @@ configmodule_interface_t *load_configmodule(int argc,
   int i;
   int OoptIdx=-1;
 
+  printf("CMDLINE: ");
+  for (int i=0; i<argc; i++)
+    printf("\"%s\" ", argv[i]);
+  printf("\n");
+
   /* first parse the command line to look for the -O option */
   for (i = 0; i<argc; i++) {
     if (strlen(argv[i]) < 2)
diff --git a/common/config/libconfig/config_libconfig.c b/common/config/libconfig/config_libconfig.c
index 17266246f0c24e9b9178ebb62171ed5ff3dd0fc6..48893fb5bed3d313413e43959eceb4f3f3c82ba7 100644
--- a/common/config/libconfig/config_libconfig.c
+++ b/common/config/libconfig/config_libconfig.c
@@ -122,7 +122,7 @@ int config_libconfig_get(paramdef_t *cfgoptions,int numoptions, char *prefix ) {
 
     switch(cfgoptions[i].type) {
       case TYPE_STRING:
-        if ( config_lookup_string(&(libconfig_privdata.cfg),cfgpath, (const char **)&str)) {
+        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);
diff --git a/common/utils/LOG/DOC/rtusage.md b/common/utils/LOG/DOC/rtusage.md
index 445f335725c57fcc3675b9df0a608b8e2f3cab90..d7c748952d4adcbb2b3ba2dc06f6109de0ceb971 100644
--- a/common/utils/LOG/DOC/rtusage.md
+++ b/common/utils/LOG/DOC/rtusage.md
@@ -9,7 +9,7 @@ All logging facility parameters are defined in the log_config section. Some para
 |:---:|:---:|:---:|:----|
 | `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|
+| `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, `function`, adds the function name, `line_num`, adds the line number, `time` adds the time since process starts|
 
 ### Component specific parameters
 | name | type | default | description |
diff --git a/common/utils/LOG/log.c b/common/utils/LOG/log.c
index d0a53a755b27ca807f5df975aa0f9f5c597446a0..28134d6db1c2a548eb10b1f4b19d23c8967c5f81 100644
--- a/common/utils/LOG/log.c
+++ b/common/utils/LOG/log.c
@@ -43,6 +43,8 @@
 #include <string.h>
 #include <linux/prctl.h>
 #include "common/config/config_userapi.h"
+#include <time.h>
+#include <sys/time.h>
 
 // main log variables
 
@@ -73,6 +75,9 @@ mapping log_options[] = {
   {"nocolor", FLAG_NOCOLOR  },
   {"level",   FLAG_LEVEL  },
   {"thread",  FLAG_THREAD },
+  {"line_num",    FLAG_FILE_LINE },
+  {"function", FLAG_FUNCT},
+  {"time",     FLAG_TIME},
   {NULL,-1}
 };
 
@@ -81,6 +86,7 @@ mapping log_maskmap[] = LOG_MASKMAP_INIT;
 
 char *log_level_highlight_start[] = {LOG_RED, LOG_ORANGE, "", LOG_BLUE, LOG_CYBL};  /*!< \brief Optional start-format strings for highlighting */
 char *log_level_highlight_end[]   = {LOG_RESET,LOG_RESET,LOG_RESET, LOG_RESET,LOG_RESET};   /*!< \brief Optional end-format strings for highlighting */
+static void log_output_memory(log_component_t *c, const char *file, const char *func, int line, int comp, int level, const char* format,va_list args);
 
 
 int write_file_matlab(const char *fname,
@@ -476,6 +482,8 @@ int logInit (void)
   register_log_component("NR_MAC","log",NR_MAC);
   register_log_component("NR_PHY","log",NR_PHY);
   register_log_component("NGAP","",NGAP);
+  register_log_component("ITTI","log",ITTI);
+  register_log_component("UTIL","log",UTIL);
 
   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
@@ -493,84 +501,138 @@ int logInit (void)
   return 0;
 }
 
-
-char *log_getthreadname(char *threadname,
-		                int bufsize)
+static inline int log_header(log_component_t *c,
+			     char *log_buffer,
+			     int buffsize,
+			     const char *file,
+			     const char *func,
+			     int line,
+			     int level)
 {
-  int rt =   pthread_getname_np(pthread_self(), threadname,bufsize) ;
-
-  if (rt == 0) {
-    return threadname;
+  int flag= g_log->flag | c->flag;
+
+  char threadname[64];
+  if (flag & FLAG_THREAD ) {
+    threadname[0]='{';
+    if ( pthread_getname_np(pthread_self(), threadname+1,61) != 0)
+      strcpy(threadname+1, "?thread?");
+    strcat(threadname,"}");
+  } else {
+    threadname[0]=0;
+  }
+ 
+  char l[32];
+  if (flag & FLAG_FILE_LINE && flag & FLAG_FUNCT )
+    snprintf(l, sizeof l," (%s:%d) ", func, line);
+  else if (flag & FLAG_FILE_LINE)
+    sprintf(l," (%d) ", line);
+  else
+    l[0]=0;
+
+  char timeString[32];
+  if ( flag & FLAG_TIME ) {
+    struct timespec t;
+    clock_gettime(CLOCK_MONOTONIC, &t);
+    snprintf(timeString, sizeof t,"%05.3f",t.tv_sec+t.tv_nsec/1.0e9);
   } else {
-    return "thread?";
+    timeString[0]=0;
   }
+  return  snprintf(log_buffer, buffsize, "%s%s[%s]%c%s %s ",
+		   timeString,
+		   flag & FLAG_NOCOLOR ? "" : log_level_highlight_start[level],
+		   c->name,
+		   flag & FLAG_LEVEL ? g_log->level2string[level] : ' ',
+		   l,
+		   threadname
+		   );
 }
 
-static int log_header(char *log_buffer,
-		              int buffsize,
-					  int comp,
-					  int level,
-					  const char *format)
+#if LOG_MINIMAL
+#include <sys/syscall.h>
+void logMinimal(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]);
+    struct timespec ts;
+    if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1)
+        abort();
+
+    char buf[MAX_LOG_TOTAL];
+    int n = snprintf(buf, sizeof(buf), "%lu.%06lu %08lx [%s] %c ",
+                     ts.tv_sec,
+                     ts.tv_nsec / 1000,
+                     syscall(__NR_gettid),
+                     g_log->log_component[comp].name,
+                     level);
+    if (n < 0 || n >= sizeof(buf))
+    {
+        fprintf(stderr, "%s: n=%d\n", __func__, n);
+        return;
+    }
+
+    va_list args;
+    va_start(args, format);
+    int m = vsnprintf(buf + n, sizeof(buf) - n, format, args);
+    va_end(args);
+
+    if (m < 0)
+    {
+        fprintf(stderr, "%s: n=%d m=%d\n", __func__, n, m);
+        return;
+    }
+
+    int len = n + m;
+    if (len > sizeof(buf) - 1)
+    {
+        len = sizeof(buf) - 1;
+    }
+    if (buf[len - 1] != '\n')
+    {
+        buf[len++] = '\n';
+    }
+
+    __attribute__((unused))
+    int unused = write(STDOUT_FILENO, buf, len);
 }
+#endif // LOG_MINIMAL
 
 void logRecord_mt(const char *file,
-		          const char *func,
-				  int line,
-				  int comp,
-				  int level,
-				  const char *format,
-				  ... )
+		  const char *func,
+		  int line,
+		  int comp,
+		  int level,
+		  const char *format,
+		  ... )
 {
-  char log_buffer[MAX_LOG_TOTAL]= {0};
+  log_component_t *c = &g_log->log_component[comp];
   va_list args;
   va_start(args,format);
-  if (log_mem_flag == 1) {
-    log_output_memory(file,func,line,comp,level,format,args);
-  } else {
-  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);
-  fflush(g_log->log_component[comp].stream);
-  }
+  log_output_memory(c, file,func,line,comp,level,format,args);
   va_end(args);
 }
 
 void vlogRecord_mt(const char *file,
-		           const char *func,
-				   int line,
-				   int comp,
-				   int level,
-				   const char *format,
-				   va_list args )
+		   const char *func,
+		   int line,
+		   int comp,
+		   int level,
+		   const char *format,
+		   va_list args )
 {
-  char log_buffer[MAX_LOG_TOTAL];
-  if (log_mem_flag == 1) {
-    log_output_memory(file,func,line,comp,level, format,args);
-  } else {
-  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);
-  }
+  log_component_t *c = &g_log->log_component[comp];
+  log_output_memory(c, file,func,line,comp,level, format,args);
 }
 
 void log_dump(int component,
-		      void *buffer,
-			  int buffsize,
-			  int datatype,
-			  const char *format,
-			  ... )
+	      void *buffer,
+	      int buffsize,
+	      int datatype,
+	      const char *format,
+	      ... )
 {
   va_list args;
   char *wbuf;
-
+  log_component_t *c = &g_log->log_component[component];
+  int flag= g_log->flag | c->flag;
+  
   switch(datatype) {
     case LOG_DUMP_DOUBLE:
       wbuf=malloc((buffsize * 10)  + 64 + MAX_LOG_TOTAL);
@@ -584,9 +646,8 @@ void log_dump(int component,
 
   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;
+    int pos=log_header(c, wbuf,MAX_LOG_TOTAL,"noFile","noFunc",0, OAILOG_INFO);
+    pos+=vsprintf(wbuf+pos,format, args);
     va_end(args);
 
     for (int i=0; i<buffsize; i++) {
@@ -601,9 +662,11 @@ void log_dump(int component,
           break;
       }
     }
-
-    sprintf(wbuf+pos,"\n");
-    g_log->log_component[component].print(g_log->log_component[component].stream,wbuf);
+    if ( flag & FLAG_NOCOLOR )
+      sprintf(wbuf+pos,"\n");
+    else
+      sprintf(wbuf+pos,"%s\n",log_level_highlight_end[OAILOG_INFO]);
+    c->print(c->stream,wbuf);
     free(wbuf);
   }
 }
@@ -803,13 +866,10 @@ void flush_mem_to_file(void)
 
 char logmem_log_level[NUM_LOG_LEVEL]={'E','W','I','D','T'};
 
-void log_output_memory(const char *file, const char *func, int line, int comp, int level, const char* format,va_list args)
+static void log_output_memory(log_component_t *c, const char *file, const char *func, int line, int comp, int level, const char* format,va_list args)
 {
   //logRecord_mt(file,func,line, pthread_self(), comp, level, format, ##args)
   int len = 0;
-  log_component_t *c;
-  char *log_start;
-  char *log_end;
   /* The main difference with the version above is the use of this local log_buffer.
    * The other difference is the return value of snprintf which was not used
    * correctly. It was not a big problem because in practice MAX_LOG_TOTAL is
@@ -817,92 +877,17 @@ void log_output_memory(const char *file, const char *func, int line, int comp, i
    */
   char log_buffer[MAX_LOG_TOTAL];
 
-  /* for no gcc warnings */
-  (void)log_start;
-  (void)log_end;
-
-
-  c = &g_log->log_component[comp];
-
-  //VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_LOG_RECORD, VCD_FUNCTION_IN);
-
   // make sure that for log trace the extra info is only printed once, reset when the level changes
-  if (level == OAILOG_TRACE) {
-    log_start = log_buffer;
-    len = vsnprintf(log_buffer, MAX_LOG_TOTAL, format, args);
-    if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL;
-    log_end = log_buffer + len;
-  } else {
-    if ( (g_log->flag & 0x001) || (c->flag & 0x001) ) {
-      len += snprintf(&log_buffer[len], MAX_LOG_TOTAL - len, "%s",
-                      log_level_highlight_start[level]);
-      if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL;
-    }
-
-    log_start = log_buffer + len;
-
-//    if ( (g_log->flag & 0x004) || (c->flag & 0x004) ) {
-      len += snprintf(&log_buffer[len], MAX_LOG_TOTAL - len, "[%s]",
-                      g_log->log_component[comp].name);
-      if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL;
-//    }
-
-    if ( (level >= OAILOG_ERR) && (level <= OAILOG_TRACE) ) {
-      len += snprintf(&log_buffer[len], MAX_LOG_TOTAL - len, "[%c]",
-                      logmem_log_level[level]);
-      if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL;
-    }
-
-    if ( (g_log->flag & FLAG_THREAD) || (c->flag & FLAG_THREAD) ) {
-#     define THREAD_NAME_LEN 128
-      char threadname[THREAD_NAME_LEN];
-      if (pthread_getname_np(pthread_self(), threadname, THREAD_NAME_LEN) != 0)
-      {
-        perror("pthread_getname_np : ");
-      } else {
-        len += snprintf(&log_buffer[len], MAX_LOG_TOTAL - len, "[%s]", threadname);
-        if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL;
-      }
-#     undef THREAD_NAME_LEN
-    }
-
-    if ( (g_log->flag & FLAG_FUNCT) || (c->flag & FLAG_FUNCT) ) {
-      len += snprintf(&log_buffer[len], MAX_LOG_TOTAL - len, "[%s] ",
-                      func);
-      if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL;
-    }
-
-    if ( (g_log->flag & FLAG_FILE_LINE) || (c->flag & FLAG_FILE_LINE) ) {
-      len += snprintf(&log_buffer[len], MAX_LOG_TOTAL - len, "[%s:%d]",
-                      file, line);
-      if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL;
-    }
-
-/*    len += snprintf(&log_buffer[len], MAX_LOG_TOTAL - len, "[%08lx]", thread_id);
-    if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL;
-
-    struct timeval gettime;
-    gettimeofday(&gettime,NULL);
-    len += snprintf(&log_buffer[len], MAX_LOG_TOTAL - len, "[%ld.%06ld]", gettime.tv_sec, gettime.tv_usec);
-    if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL;
-*/
-    if ( (g_log->flag & FLAG_NOCOLOR) || (c->flag & FLAG_NOCOLOR) ) {
-      len += snprintf(&log_buffer[len], MAX_LOG_TOTAL - len, "%s",
-          log_level_highlight_end[level]);
-      if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL;
-    }
-
-    len += vsnprintf(&log_buffer[len], MAX_LOG_TOTAL - len, format, args);
-    if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL;
-    log_end = log_buffer + len;
-  }
-
-  //va_end(args);
-
+  if (level < OAILOG_TRACE)
+    len += log_header(c, log_buffer, MAX_LOG_TOTAL, file, func, line, level);
+  len += vsnprintf(log_buffer+len, MAX_LOG_TOTAL-len, format, args);
+  if ( !((g_log->flag | c->flag) & FLAG_NOCOLOR) )
+    len+=snprintf(log_buffer+len, MAX_LOG_TOTAL-len, "%s", log_level_highlight_end[level]);
+  
   // OAI printf compatibility
-    if(log_mem_flag==1){
-      if(log_mem_d[log_mem_side].enable_flag==1){
-        int temp_index;
+  if(log_mem_flag==1){
+    if(log_mem_d[log_mem_side].enable_flag==1){
+      int temp_index;
         temp_index=log_mem_d[log_mem_side].buf_index;
         if(temp_index+len+1 < LOG_MEM_SIZE){
           log_mem_d[log_mem_side].buf_index+=len;
@@ -933,9 +918,9 @@ void log_output_memory(const char *file, const char *func, int line, int comp, i
           }
         }
       }
-    }else{
-      fwrite(log_buffer, len, 1, stdout);
-    }
+  }else{
+    if (write(fileno(c->stream), log_buffer, len)) {};
+  }
 }
 
 int logInit_log_mem (void)
diff --git a/common/utils/LOG/log.h b/common/utils/LOG/log.h
index fa95d5a6fee9436755a6c42207cf1a598985742b..d6444454245ee823e3a9967a7b82b3038474cdc5 100644
--- a/common/utils/LOG/log.h
+++ b/common/utils/LOG/log.h
@@ -54,6 +54,12 @@
 #include "T.h"
 #include <common/utils/utils.h>
 /*----------------------------------------------------------------------------*/
+#include <assert.h>
+#ifdef NDEBUG
+#warning assert is disabled
+#endif
+#define NUM_ELEMENTS(ARRAY) (sizeof(ARRAY) / sizeof(ARRAY[0]))
+#define CHECK_INDEX(ARRAY, INDEX) assert((INDEX) < NUM_ELEMENTS(ARRAY))
 
 #ifdef __cplusplus
 extern "C" {
@@ -237,6 +243,8 @@ typedef enum {
   ASN,
   NFAPI_VNF,
   NFAPI_PNF,
+  ITTI,
+  UTIL,
   MAX_LOG_PREDEF_COMPONENTS,
 }
 comp_name_t;
@@ -315,7 +323,6 @@ int register_log_component(char *name, char *fext, int compidx);
 #define LOG_MEM_SIZE 100*1024*1024
 #define LOG_MEM_FILE "./logmem.log"
 void flush_mem_to_file(void);
-void log_output_memory(const char *file, const char *func, int line, int comp, int level, const char* format,va_list args);
 int logInit_log_mem(void);
 void close_log_mem(void);
   
@@ -400,10 +407,30 @@ 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 LOG_MINIMAL
+
+  void logMinimal(int component, int level, const char *format, ...) __attribute__((format(printf, 3, 4)));
+# define LOG_E(COMPONENT, ...) do if (1) logMinimal(COMPONENT, 'E', __VA_ARGS__); while (0)
+# define LOG_W(COMPONENT, ...) do if (1) logMinimal(COMPONENT, 'W', __VA_ARGS__); while (0)
+# define LOG_A(COMPONENT, ...) do if (1) logMinimal(COMPONENT, 'A', __VA_ARGS__); while (0) /* logs intended for analysis */
+# define LOG_I(COMPONENT, ...) do if (1) logMinimal(COMPONENT, 'I', __VA_ARGS__); while (0)
+# define LOG_D(COMPONENT, ...) do if (0) logMinimal(COMPONENT, 'D', __VA_ARGS__); while (0)
+# define LOG_T(COMPONENT, ...) do if (0) logMinimal(COMPONENT, 'T', __VA_ARGS__); while (0)
+
+# define LOG_M(FILE, VECTOR, DATA, LEN, DEC, FORMAT) ((void) 0)
+# define LOG_DUMPFLAG(D) 0
+# define LOG_DEBUGFLAG(D) 0
+# define LOG_DUMPMSG(C, B, S, X...) ((void) 0)
+# define VLOG(C, L, F, ARGS) ((void) 0)
+
+#else // LOG_MINIMAL
+
 #  if T_TRACER
 /* per component, level dependent 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_A LOG_I
 #    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)
@@ -423,6 +450,7 @@ int32_t write_file_matlab(const char *fname, const char *vname, void *data, int
 #    define LOG_E(c, x...) do { if( g_log->log_component[c].level >= OAILOG_ERR    ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_ERR, x)     ;}  while (0)
 #    define LOG_W(c, x...) do { if( g_log->log_component[c].level >= OAILOG_WARNING) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_WARNING, x) ;}  while (0)
 #    define LOG_I(c, x...) do { if( g_log->log_component[c].level >= OAILOG_INFO   ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_INFO, x)    ;}  while (0)
+#    define LOG_A LOG_I
 #    define LOG_D(c, x...) do { if( g_log->log_component[c].level >= OAILOG_DEBUG  ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_DEBUG, x)   ;}  while (0)
 #    define LOG_T(c, x...) do { if( g_log->log_component[c].level >= OAILOG_TRACE  ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_TRACE, x)   ;}  while (0)
 #    define VLOG(c,l, f, args) do { if( g_log->log_component[c].level >= l  ) vlogRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, l, f, args)   ; } while (0)
@@ -436,6 +464,8 @@ int32_t write_file_matlab(const char *fname, const char *vname, void *data, int
 #    define LOG_VAR(A,B) A B
 #    define T_ACTIVE(a) (0) 
 #  endif /* T_TRACER */
+#endif // LOG_MINIMAL
+
 /* 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
diff --git a/common/utils/T/T_messages.txt b/common/utils/T/T_messages.txt
index 192bf8cc371ff0da11ddbfe3304d8ebf1407320a..a8a4f57fcddb8fb92a881f07c80bc6d1157c0acf 100644
--- a/common/utils/T/T_messages.txt
+++ b/common/utils/T/T_messages.txt
@@ -1061,6 +1061,48 @@ ID = LEGACY_NFAPI_PNF_TRACE
     DESC = NFAPI_PNF legacy logs - trace level
     GROUP = ALL:LEGACY_NFAPI_PNF:LEGACY_GROUP_TRACE:LEGACY
     FORMAT = string,log
+
+ID = LEGACY_ITTI_INFO
+    DESC = ITTI legacy logs - info level
+    GROUP = ALL:LEGACY_ITTI:LEGACY_GROUP_INFO:LEGACY
+    FORMAT = string,log
+ID = LEGACY_ITTI_ERROR
+    DESC = ITTI legacy logs - error level
+    GROUP = ALL:LEGACY_ITTI:LEGACY_GROUP_ERROR:LEGACY
+    FORMAT = string,log
+ID = LEGACY_ITTI_WARNING
+    DESC = ITTI legacy logs - warning level
+    GROUP = ALL:LEGACY_ITTI:LEGACY_GROUP_WARNING:LEGACY
+    FORMAT = string,log
+ID = LEGACY_ITTI_DEBUG
+    DESC = ITTI legacy logs - debug level
+    GROUP = ALL:LEGACY_ITTI:LEGACY_GROUP_DEBUG:LEGACY
+    FORMAT = string,log
+ID = LEGACY_ITTI_TRACE
+    DESC = ITTI legacy logs - trace level
+    GROUP = ALL:LEGACY_ITTI:LEGACY_GROUP_TRACE:LEGACY
+    FORMAT = string,log
+
+ID = LEGACY_UTIL_INFO
+    DESC = UTIL legacy logs - info level
+    GROUP = ALL:LEGACY_UTIL:LEGACY_GROUP_INFO:LEGACY
+    FORMAT = string,log
+ID = LEGACY_UTIL_ERROR
+    DESC = UTIL legacy logs - error level
+    GROUP = ALL:LEGACY_UTIL:LEGACY_GROUP_ERROR:LEGACY
+    FORMAT = string,log
+ID = LEGACY_UTIL_WARNING
+    DESC = UTIL legacy logs - warning level
+    GROUP = ALL:LEGACY_UTIL:LEGACY_GROUP_WARNING:LEGACY
+    FORMAT = string,log
+ID = LEGACY_UTIL_DEBUG
+    DESC = UTIL legacy logs - debug level
+    GROUP = ALL:LEGACY_UTIL:LEGACY_GROUP_DEBUG:LEGACY
+    FORMAT = string,log
+ID = LEGACY_UTIL_TRACE
+    DESC = UTIL legacy logs - trace level
+    GROUP = ALL:LEGACY_UTIL:LEGACY_GROUP_TRACE:LEGACY
+    FORMAT = string,log
 # this is a bad hack but I won't fix (function util_print_hex_octets
 # in openairinterface5g/openair2/LAYER2/PDCP_v10.1.0/pdcp_util.c
 # does funky things with the LOG_x macros but we work on the C pre-processor
diff --git a/common/utils/assertions.h b/common/utils/assertions.h
index 06d43bdbfa05c26dc08ac292aae9af8dd15a6364..d85dab79a0c744f7d8cda566caa66638a2e9f34b 100644
--- a/common/utils/assertions.h
+++ b/common/utils/assertions.h
@@ -26,17 +26,10 @@
 #include <stdlib.h>
 #include <inttypes.h>
 #include <platform_types.h>
+#include "backtrace.h"
 
-#if defined(ENB_MODE)
-# define display_backtrace()
-#else
-# include "backtrace.h"
-#endif
-
-void output_log_mem(void);
 #define _Assert_Exit_                           \
     fprintf(stderr, "\nExiting execution\n");   \
-    display_backtrace();                        \
     fflush(stdout);                             \
     fflush(stderr);                             \
     abort();
diff --git a/common/utils/backtrace.c b/common/utils/backtrace.c
index f61cf0349ac5d9a64fcad36a6b235e9c8071768d..634bb3a834dd381ef708d8acc74a274d1f0a6897 100644
--- a/common/utils/backtrace.c
+++ b/common/utils/backtrace.c
@@ -28,7 +28,7 @@
 #include <signal.h>
 #include <execinfo.h>
 
-#include "backtrace.h"
+#include <common/utils/backtrace.h>
 
 /* Obtain a backtrace and print it to stdout. */
 void display_backtrace(void) {
@@ -49,8 +49,3 @@ void display_backtrace(void) {
 
   free(strings);
 }
-
-void backtrace_handle_signal(siginfo_t *info) {
-  display_backtrace();
-  //exit(EXIT_FAILURE);
-}
diff --git a/common/utils/backtrace.h b/common/utils/backtrace.h
index 3977d0321c68c6f007edb2e451479f736c00e05c..9aaf7184530d0b8072ce5a34a6553f2bf2056716 100644
--- a/common/utils/backtrace.h
+++ b/common/utils/backtrace.h
@@ -26,10 +26,7 @@
 #ifdef __cplusplus
 extern "C" {
 #endif
-
 void display_backtrace(void);
-
-void backtrace_handle_signal(siginfo_t *info);
 #ifdef __cplusplus
 }
 #endif
diff --git a/common/utils/nr/nr_common.c b/common/utils/nr/nr_common.c
index 0de24bcf6d705bdb22502699a80a07db0844ef9d..de8a0522e0f30232e7c72c8daf4383123d9d8843 100644
--- a/common/utils/nr/nr_common.c
+++ b/common/utils/nr/nr_common.c
@@ -42,7 +42,7 @@ const char *duplex_mode[]={"FDD","TDD"};
 // - N_OFFs for bands from 80 to 89 and band 95 is referred to UL
 // - Frequencies are expressed in KHz
 // - col: NR_band ul_min  ul_max  dl_min  dl_max  step  N_OFFs_DL  deltaf_raster
-nr_bandentry_t nr_bandtable[] = {
+const nr_bandentry_t nr_bandtable[] = {
   {1,   1920000, 1980000, 2110000, 2170000, 20, 422000, 100},
   {2,   1850000, 1910000, 1930000, 1990000, 20, 386000, 100},
   {3,   1710000, 1785000, 1805000, 1880000, 20, 361000, 100},
@@ -117,7 +117,7 @@ uint16_t get_band(uint64_t downlink_frequency, int32_t delta_duplex)
   uint64_t center_freq_diff_khz = 999999999999999999; // 2^64
   uint16_t current_band = 0;
 
-  for (int ind = 0; ind < nr_bandtable_size; ind++) {
+  for (int ind = 0; ind < sizeofArray(nr_bandtable); ind++) {
 
     if (dl_freq_khz < nr_bandtable[ind].dl_min || dl_freq_khz > nr_bandtable[ind].dl_max)
       continue;
@@ -143,8 +143,6 @@ uint16_t get_band(uint64_t downlink_frequency, int32_t delta_duplex)
   return current_band;
 }
 
-const size_t nr_bandtable_size = sizeof(nr_bandtable) / sizeof(nr_bandentry_t);
-
 int NRRIV2BW(int locationAndBandwidth,int N_RB) {
   int tmp = locationAndBandwidth/N_RB;
   int tmp2 = locationAndBandwidth%N_RB;
@@ -459,31 +457,27 @@ uint16_t config_bandwidth(int mu, int nb_rb, int nr_band)
 
 // Returns the corresponding row index of the NR table
 int get_nr_table_idx(int nr_bandP, uint8_t scs_index) {
-  int i, j;
   int scs_khz = 15 << scs_index;
   int supplementary_bands[] = {29,75,76,80,81,82,83,84,86,89,95};
-  size_t s = sizeof(supplementary_bands)/sizeof(supplementary_bands[0]);
-
-  for(j = 0; j < s; j++){
+  for(int j = 0; j < sizeofArray(supplementary_bands); j++){
     if (nr_bandP == supplementary_bands[j])
       AssertFatal(0 == 1, "Band %d is a supplementary band (%d). This is not supported yet.\n", nr_bandP, supplementary_bands[j]);
   }
 
-  AssertFatal(nr_bandP <= nr_bandtable[nr_bandtable_size-1].band, "NR band %d exceeds NR bands table maximum limit %d\n", nr_bandP, nr_bandtable[nr_bandtable_size-1].band);
-  for (i = 0; i < nr_bandtable_size && nr_bandtable[i].band != nr_bandP; i++);
-
-  // In frequency bands with two deltaFRaster,
-  // the higher deltaFRaster applies to channels using only the SCS that is equal to or larger than the higher deltaFRaster
-  // and SSB SCS is equal to the higher deltaFRaster.
-  while(((i+1)<nr_bandtable_size) &&
-        (nr_bandtable[i+1].band == nr_bandtable[i].band) &&
-        (nr_bandtable[i].deltaf_raster != scs_khz)) {
-    i++;
+  int i;
+  for (i = 0; i < sizeofArray(nr_bandtable); i++) {
+    if ( nr_bandtable[i].band == nr_bandP && nr_bandtable[i].deltaf_raster == scs_khz )
+      break;
   }
 
-  AssertFatal(nr_bandtable[i].band == nr_bandP, "Found band table %d does not correspond to the input one %d\n",nr_bandtable[i].band,nr_bandP);
-
+  if (i == sizeofArray(nr_bandtable)) {
+    LOG_I(PHY, "not found same deltaf_raster == scs_khz, use only band and last deltaf_raster \n");
+    for(i=sizeofArray(nr_bandtable)-1; i >=0; i--)
+       if ( nr_bandtable[i].band == nr_bandP )
+         break;
+  }
 
+  AssertFatal(i > 0 && i < sizeofArray(nr_bandtable), "band is not existing: %d\n",nr_bandP);
   LOG_D(PHY, "NR band table index %d (Band %d, dl_min %lu, ul_min %lu)\n", i, nr_bandtable[i].band, nr_bandtable[i].dl_min,nr_bandtable[i].ul_min);
 
   return i;
diff --git a/common/utils/nr/nr_common.h b/common/utils/nr/nr_common.h
index 44a6e0557704185c9e0dea555840660ccb0de2b2..e7414c9f83c01b8e9da34170611969f08020cd5e 100644
--- a/common/utils/nr/nr_common.h
+++ b/common/utils/nr/nr_common.h
@@ -48,8 +48,7 @@ typedef struct nr_bandentry_s {
   uint8_t deltaf_raster;
 } nr_bandentry_t;
 
-extern const size_t nr_bandtable_size;
-extern nr_bandentry_t nr_bandtable[];
+extern const nr_bandentry_t nr_bandtable[];
 static inline int get_num_dmrs(uint16_t dmrs_mask ) {
 
   int num_dmrs=0;
diff --git a/common/utils/ocp_itti/intertask_interface.cpp b/common/utils/ocp_itti/intertask_interface.cpp
index 4e5323aec98c85d0c807ad195bbfa6ed4f022c8e..44fae9f78884e9b5d47ce0226bfb76eca6aae7d5 100644
--- a/common/utils/ocp_itti/intertask_interface.cpp
+++ b/common/utils/ocp_itti/intertask_interface.cpp
@@ -136,12 +136,12 @@ extern "C" {
       LOG_E(TMR,"Queue for %s task contains %ld messages\n", itti_get_task_name(destination_task_id), s );
 
     if ( s > 50 )
-      LOG_I(TMR,"Queue for %s task size: %ld (last message %s)\n",itti_get_task_name(destination_task_id), s+1,ITTI_MSG_NAME(message));
+      LOG_I(ITTI,"Queue for %s task size: %ld (last message %s)\n",itti_get_task_name(destination_task_id), s+1,ITTI_MSG_NAME(message));
 
     t->message_queue.insert(t->message_queue.begin(), message);
     eventfd_t sem_counter = 1;
     AssertFatal ( sizeof(sem_counter) == write(t->sem_fd, &sem_counter, sizeof(sem_counter)), "");
-    LOG_D(TMR,"sent messages id=%d to %s\n",message_id, t->admin.name);
+    LOG_D(ITTI,"sent messages id=%d to %s\n",message_id, t->admin.name);
     return 0;
   }
 
@@ -152,7 +152,7 @@ extern "C" {
 
     while ( t->message_queue.size()>0 && t->admin.func != NULL ) {
       if (t->message_queue.size()>1)
-        LOG_W(TMR,"queue in no thread mode is %ld\n", t->message_queue.size());
+        LOG_W(ITTI,"queue in no thread mode is %ld\n", t->message_queue.size());
 
       pthread_mutex_unlock (&t->queue_cond_lock);
       t->admin.func(NULL);
@@ -208,7 +208,7 @@ extern "C" {
               message->ittiMsg.timer_has_expired.arg=it->second.timer_arg;
 
               if (itti_send_msg_to_task_locked(task_id, it->second.instance, message) < 0) {
-                LOG_W(TMR,"Failed to send msg TIMER_HAS_EXPIRED to task %u\n", task_id);
+                LOG_W(ITTI,"Failed to send msg TIMER_HAS_EXPIRED to task %u\n", task_id);
                 free(message);
                 t->timer_map.erase(it);
                 return -1;
@@ -233,7 +233,7 @@ extern "C" {
         epoll_timeout = t->next_timer-current_time;
 
       pthread_mutex_unlock(&t->queue_cond_lock);
-      LOG_D(TMR,"enter blocking wait for %s\n", itti_get_task_name(task_id));
+      LOG_D(ITTI,"enter blocking wait for %s, timeout: %d ms\n", itti_get_task_name(task_id),  epoll_timeout);
       t->nb_events = epoll_wait(t->epoll_fd,t->events,t->nb_fd_epoll, epoll_timeout);
 
       if ( t->nb_events  < 0 && (errno == EINTR || errno == EAGAIN ) )
@@ -243,7 +243,7 @@ extern "C" {
     AssertFatal (t->nb_events >=0,
                  "epoll_wait failed for task %s, nb fds %d, timeout %lu: %s!\n",
                  itti_get_task_name(task_id), t->nb_fd_epoll, t->next_timer != UINT64_MAX ? t->next_timer-current_time : -1, strerror(errno));
-    LOG_D(TMR,"receive on %d descriptors for %s\n", t->nb_events, itti_get_task_name(task_id));
+    LOG_D(ITTI,"receive on %d descriptors for %s\n", t->nb_events, itti_get_task_name(task_id));
 
     if (t->nb_events == 0)
       /* No data to read -> return */
@@ -292,11 +292,11 @@ extern "C" {
     // in this case, *received_msg is NULL
     if (t->message_queue.empty()) {
       *received_msg=NULL;
-      LOG_D(TMR,"task %s received even from other fd (total fds: %d), returning msg NULL\n",t->admin.name, t->nb_fd_epoll);
+      LOG_D(ITTI,"task %s received even from other fd (total fds: %d), returning msg NULL\n",t->admin.name, t->nb_fd_epoll);
     } else {
       *received_msg=t->message_queue.back();
       t->message_queue.pop_back();
-      LOG_D(TMR,"task %s received a message\n",t->admin.name);
+      LOG_D(ITTI,"task %s received a message\n",t->admin.name);
     }
 
     pthread_mutex_unlock (&t->queue_cond_lock);
@@ -308,7 +308,7 @@ extern "C" {
     pthread_mutex_lock(&t->queue_cond_lock);
 
     if (!t->message_queue.empty()) {
-      LOG_D(TMR,"task %s received a message in polling mode\n",t->admin.name);
+      LOG_D(ITTI,"task %s received a message in polling mode\n",t->admin.name);
       *received_msg=t->message_queue.back();
       t->message_queue.pop_back();
     } else
@@ -322,7 +322,7 @@ extern "C" {
                        void *args_p) {
     task_list_t *t=tasks[task_id];
     threadCreate (&t->thread, start_routine, args_p, (char *)itti_get_task_name(task_id),-1,OAI_PRIORITY_RT);
-    LOG_I(TMR,"Created Posix thread %s\n",  itti_get_task_name(task_id) );
+    LOG_I(ITTI,"Created Posix thread %s\n",  itti_get_task_name(task_id) );
     return 0;
   }
 
@@ -344,7 +344,7 @@ extern "C" {
     tasks = new_tasks;
     tasks[newQueue]= new task_list_t;
     pthread_mutex_unlock (&lock_nb_queues);
-    LOG_I(TMR,"Starting itti queue: %s as task %d\n", taskInfo->name, newQueue);
+    LOG_I(ITTI,"Starting itti queue: %s as task %d\n", taskInfo->name, newQueue);
     pthread_mutex_init(&tasks[newQueue]->queue_cond_lock, NULL);
     memcpy(&tasks[newQueue]->admin, taskInfo, sizeof(task_info_t));
     AssertFatal( ( tasks[newQueue]->epoll_fd = epoll_create1(0) ) >=0, "");
@@ -392,7 +392,7 @@ extern "C" {
     clock_gettime(CLOCK_MONOTONIC, &tp);
 
     if (interval_us%1000 != 0)
-      LOG_W(TMR, "Can't set timer precision below 1ms, rounding it\n");
+      LOG_W(ITTI, "Can't set timer precision below 1ms, rounding it\n");
 
     timer.duration  = interval_sec*1000+interval_us/1000;
     timer.timeout= ((uint64_t)tp.tv_sec*1000+tp.tv_nsec/(1000*1000)+timer.duration);
@@ -421,7 +421,7 @@ extern "C" {
     if (ret==1)
       return 0;
     else {
-      LOG_W(TMR, "tried to remove a non existing timer\n");
+      LOG_W(ITTI, "tried to remove a non existing timer\n");
       return 1;
     }
   }
@@ -438,9 +438,22 @@ extern "C" {
   void itti_send_terminate_message(task_id_t task_id) {
   }
 
+  static volatile bool shutting_down;
+
+  static void catch_sigterm(int) {
+    static const char msg[] = "\n** Caught SIGTERM, shutting down\n";
+    __attribute__((unused))
+    int unused = write(STDOUT_FILENO, msg, sizeof(msg) - 1);
+    shutting_down = true;
+  }
+
   void itti_wait_tasks_end(void) {
-    while(1)
-      sleep(24*3600);
+    shutting_down = false;
+    signal(SIGTERM, catch_sigterm);
+    while (! shutting_down)
+    {
+      sleep(24 * 3600);
+    }
   }
 
   void itti_update_lte_time(uint32_t frame, uint8_t slot) {}
@@ -455,4 +468,42 @@ extern "C" {
   int signal_mask(void) {
     return 0;
   }
+
+void log_scheduler(const char* label)
+{
+    int policy = sched_getscheduler(0);
+    struct sched_param param;
+    if (sched_getparam(0, &param) == -1)
+    {
+        LOG_E(HW, "sched_getparam: %s\n", strerror(errno));
+        abort();
+    }
+
+    cpu_set_t cpu_set;
+    if (sched_getaffinity(0, sizeof(cpu_set), &cpu_set) == -1)
+    {
+        LOG_E(HW, "sched_getaffinity: %s\n", strerror(errno));
+        abort();
+    }
+    int num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
+    if (num_cpus < 1)
+    {
+        LOG_E(HW, "sysconf(_SC_NPROCESSORS_ONLN): %s\n", strerror(errno));
+        abort();
+    }
+    char buffer[num_cpus];
+    for (int i = 0; i < num_cpus; i++)
+    {
+        buffer[i] = CPU_ISSET(i, &cpu_set) ? 'Y' : '-';
+    }
+
+    LOG_A(HW, "Scheduler policy=%d priority=%d affinity=[%d]%.*s label=%s\n",
+          policy,
+          param.sched_priority,
+          num_cpus,
+          num_cpus,
+          buffer,
+          label);
 }
+} // extern "C"
+
diff --git a/common/utils/ocp_itti/intertask_interface.h b/common/utils/ocp_itti/intertask_interface.h
index 7c17a6f3b12fe9d060b8fb3a9053d7c922ead83f..3188e5889f0d2b43d47c4a1b0e67c620e7a09c18 100644
--- a/common/utils/ocp_itti/intertask_interface.h
+++ b/common/utils/ocp_itti/intertask_interface.h
@@ -346,6 +346,8 @@ void *rrc_enb_process_msg(void *);
   TASK_DEF(TASK_DU_F1,    TASK_PRIORITY_MED,  200, NULL, NULL) \
   TASK_DEF(TASK_RRC_UE_SIM,   TASK_PRIORITY_MED,  200, NULL, NULL)  \
   TASK_DEF(TASK_RRC_GNB_SIM,  TASK_PRIORITY_MED,  200, NULL, NULL)  \
+  TASK_DEF(TASK_RRC_NSA_UE,   TASK_PRIORITY_MED,  200, NULL, NULL)  \
+  TASK_DEF(TASK_RRC_NSA_NRUE,   TASK_PRIORITY_MED,  200, NULL, NULL)  \
   TASK_DEF(TASK_NAS_NRUE,     TASK_PRIORITY_MED,  200, NULL, NULL)  \
   TASK_DEF(TASK_MAX,      TASK_PRIORITY_MED,  200, NULL, NULL)
 
@@ -362,6 +364,8 @@ typedef enum {
   FOREACH_TASK(TASK_ENUM)
 } task_id_t;
 
+extern uint16_t ue_idx_standalone;
+extern uint16_t node_number;
 
 typedef task_id_t thread_id_t;
 
@@ -586,6 +590,7 @@ int timer_remove(long timer_id);
 int signal_handle(int *end);
 int signal_mask(void);
 
+void log_scheduler(const char *label);
 #ifdef __cplusplus
 }
 #endif
diff --git a/common/utils/ocp_itti/itti.md b/common/utils/ocp_itti/itti.md
new file mode 100644
index 0000000000000000000000000000000000000000..89bc3ee29f72951111070ae0d45af93c3b971ed7
--- /dev/null
+++ b/common/utils/ocp_itti/itti.md
@@ -0,0 +1,91 @@
+# interthread interface (ITTI)
+
+A Middleware called “itti” (interthread interface) provides classical send/receive message queues between threads.
+
+A simpler thread safe message queue is available in the thread-pool, as it is a required lower level feature.
+
+ITTI is providing more feature, to be used as the thread event main loop.
+
+It is also made for strong type definition is source code.
+
+It is able to add in the managed events: external sockets, timers
+
+All queues are created in .h files, as static permanent queues, nevertheless the possibility to add queues during runtime is available.
+
+The queues are called tasks because it is often read in a single thread that have the same name.
+
+# API definition
+
+## itti_send_msg_to_task, itti_receive_msg, itti_poll_msg
+
+Standard messages queues, thread safe
+The reader is responsible of freeing the message
+
+## itti_subscribe_event_fd, itti_get_events
+
+Add external sockets to itti based main loop
+
+## timer_setup timer_remove
+
+When a timer expire, it adds a message in a itti queue
+
+## itti_terminate_tasks
+
+Calling this function push a “terminate” message on each itti queue
+
+# Example code of a thread using ITTI
+
+```
+Thread_aLayer_main(void * context) {
+      // initialize the layer data
+      // and register in itti the external sockets (like S1AP, GTP)
+      aLayer_init();
+      while (1) {
+      MessageDef * msg
+            itti_receive_msg(TASK_aLayer, &msg);
+            // itti receive released, so we have incoming data
+            // Can be a itti message
+            if ( msg !=  NULL) {
+                 switch(ITTI_MSG_ID(msg)) {
+                      case …:
+                           processThisMsgType1(msg);
+                           break;
+                      case …:
+                           processThisMsgType2(msg);
+                           break;
+                 }
+                 Itti_free(msg);
+  	      }
+            // or data/event on external entries (sockets)
+            Struct eppol_events* events;
+            int nbEvents=itti_get_events(TASK_aLayer, &events);
+            if ( nbEvents > 0) 
+               processLayerEvents(events, nbEvents);
+      }
+}
+
+
+```
+
+# Current usage in OpenAir
+
+## UDP, SCTP
+
+Simple threads that interface itti internal messages to Linux
+
+## GTPV1-U, S1AP
+
+Threads to implement S1AP and GTP protocols
+
+## PDCP
+
+4G Pdcp is not following itti design pattern, but it uses itti internally , 5G PDCP uses ad hoc design
+
+## RRC
+
+Implements 3GPP Rrc features
+Interfaces the layer 1 and the above itti tasks 
+
+## X2, ENP_APP (configuration), L1L2
+
+Are declared itti queues with a dedicated thread, but they are almost empty
\ No newline at end of file
diff --git a/common/utils/system.c b/common/utils/system.c
index 38d1c1d7ad001202368bca781545fd161b8c7b12..93b13f03f26f5a7df026b1771d43632037eb02f9 100644
--- a/common/utils/system.c
+++ b/common/utils/system.c
@@ -95,53 +95,16 @@ static void read_pipe(int p, char *b, int size) {
     size -= ret;
   }
 }
-
-static int baseRunTimeCommand(char* cmd, size_t cmdSize) {
-  FILE *fp;
-  size_t retSize = 0;
-
-  fp = popen(cmd, "r");
-  if(fp) {
-    memset(cmd, 0, cmdSize);
-    retSize = fread(cmd, 1, cmdSize, fp);
-    fclose(fp);
-  } else {
-    LOG_D(HW,"%s:%d:%s: Cannot open %s\n", __FILE__, __LINE__, __FUNCTION__, cmd);
-  }
-
-  if (retSize == 0) {
-    return 0;
-  }
-  return atoi(cmd);
-}
-
 int checkIfFedoraDistribution(void) {
-  char cmd[200];
-
-  memset(cmd, 0, 200);
-  sprintf(cmd, "cat /etc/os-release | grep ID_LIKE | grep -ic fedora || true");
-  return baseRunTimeCommand(cmd, 200);
+  return !system("grep -iq 'ID_LIKE.*fedora' /etc/os-release ");
 }
 
 int checkIfGenericKernelOnFedora(void) {
-  char cmd[200];
-
-  memset(cmd, 0, 200);
-  sprintf(cmd, "uname -a | grep -c rt || true");
-  return (1 - baseRunTimeCommand(cmd, 200));
+  return system("uname -a | grep -q rt");
 }
 
 int checkIfInsideContainer(void) {
-  char cmd[200];
-  int res = 0;
-
-  memset(cmd, 0, 200);
-  sprintf(cmd, "cat /proc/self/cgroup | egrep -c 'libpod|podman|kubepods' || true");
-  res = baseRunTimeCommand(cmd, 200);
-  if (res > 0)
-    return 1;
-  else
-    return 0;
+  return !system("egrep -q 'libpod|podman|kubepods'  /proc/self/cgroup");
 }
 
 /********************************************************************/
@@ -257,21 +220,21 @@ void threadCreate(pthread_t* t, void * (*func)(void*), void * param, char* name,
   AssertFatal(ret==0,"ret: %d, errno: %d\n",ret, errno);
   ret=pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
   AssertFatal(ret==0,"ret: %d, errno: %d\n",ret, errno);
-  ret=pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
-  AssertFatal(ret==0,"ret: %d, errno: %d\n",ret, errno);
-  if (checkIfFedoraDistribution())
-    if (checkIfGenericKernelOnFedora())
-      if (checkIfInsideContainer())
-        settingPriority = 0;
-
+  
+  if (system("grep -iq 'ID_LIKE.*fedora' /etc/os-release && uname -a | grep -c rt")==0)
+      if (system("cat /proc/self/cgroup | egrep -c 'libpod|podman|kubepods'")==0)
+	settingPriority = 0;
+  
   if (settingPriority) {
+    ret=pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
+    AssertFatal(ret==0,"ret: %d, errno: %d\n",ret, errno);
     ret=pthread_attr_setschedpolicy(&attr, SCHED_OAI);
     AssertFatal(ret==0,"ret: %d, errno: %d\n",ret, errno);
-    if(priority<sched_get_priority_min(SCHED_OAI) || priority>sched_get_priority_max(SCHED_FIFO)) {
-      LOG_E(TMR,"Prio not possible: %d, min is %d, max: %d, forced in the range\n",
-                priority,
-                sched_get_priority_min(SCHED_OAI),
-                sched_get_priority_max(SCHED_OAI));
+    if(priority<sched_get_priority_min(SCHED_OAI) || priority>sched_get_priority_max(SCHED_OAI)) {
+      LOG_E(UTIL,"Prio not possible: %d, min is %d, max: %d, forced in the range\n",
+	    priority,
+	    sched_get_priority_min(SCHED_OAI),
+	    sched_get_priority_max(SCHED_OAI));
       if(priority<sched_get_priority_min(SCHED_OAI))
         priority=sched_get_priority_min(SCHED_OAI);
       if(priority>sched_get_priority_max(SCHED_OAI))
@@ -283,10 +246,10 @@ void threadCreate(pthread_t* t, void * (*func)(void*), void * param, char* name,
     ret=pthread_attr_setschedparam(&attr, &sparam);
     AssertFatal(ret==0,"ret: %d, errno: %d\n",ret, errno);
   }
-
+  
   ret=pthread_create(t, &attr, func, param);
   AssertFatal(ret==0,"ret: %d, errno: %d\n",ret, errno);
-
+  
   pthread_setname_np(*t, name);
   if (affinity != -1 ) {
     cpu_set_t cpuset;
diff --git a/common/utils/threadPool/thread-pool.h b/common/utils/threadPool/thread-pool.h
index 1839b42f39ba188d62ef501ba88a726732d932b5..a8f8572cfe9ff379fa277507fbf69593f1ed97de 100644
--- a/common/utils/threadPool/thread-pool.h
+++ b/common/utils/threadPool/thread-pool.h
@@ -142,7 +142,7 @@ static inline  notifiedFIFO_elt_t *pullNotifiedFIFO_nothreadSafe(notifiedFIFO_t
   notifiedFIFO_elt_t *ret=nf->outF;
 
   if (nf->outF==nf->outF->next)
-    LOG_E(TMR,"Circular list in thread pool: push several times the same buffer is forbidden\n");
+    LOG_E(UTIL,"Circular list in thread pool: push several times the same buffer is forbidden\n");
 
   nf->outF=nf->outF->next;
 
diff --git a/common/utils/utils.c b/common/utils/utils.c
index 7f7aafc94a498f1dd53b006b98c1fc83e37d4e43..3f32881393b0934b8abd234fa96b08f6fa7a74d7 100644
--- a/common/utils/utils.c
+++ b/common/utils/utils.c
@@ -2,6 +2,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
+#include <unistd.h>
+#include <sched.h>
+#include <errno.h>
 #include "utils.h"
 
 void *calloc_or_fail(size_t size) {
@@ -22,6 +25,32 @@ void *malloc_or_fail(size_t size) {
   return ptr;
 }
 
+const char *hexdump(const void *data, size_t data_len, char *out, size_t out_len)
+{
+    char *p = out;
+    char *endp = out + out_len;
+    const uint8_t *q = data;
+    snprintf(p, endp - p, "[%zu]", data_len);
+    p += strlen(p);
+    for (size_t i = 0; i < data_len; ++i)
+    {
+        if (p >= endp)
+        {
+            static const char ellipses[] = "...";
+            char *s = endp - sizeof(ellipses);
+            if (s >= p)
+            {
+                strcpy(s, ellipses);
+            }
+            break;
+        }
+        snprintf(p, endp - p, " %02X", *q++);
+        p += strlen(p);
+    }
+    return out;
+}
+
+
 /****************************************************************************
  **                                                                        **
  ** Name:        hex_char_to_hex_value()                                   **
@@ -111,3 +140,17 @@ void *memcpy1(void *dst,const void *src,size_t n) {
   asm volatile("rep movsb" : "+D" (dst) : "c"(n), "S"(src) : "cc","memory");
   return(ret);
 }
+
+void set_priority(int priority)
+{
+  struct sched_param param =
+  {
+    .sched_priority = priority,
+  };
+  fprintf(stderr, "Calling sched_setscheduler(%d)\n", priority);
+  if (sched_setscheduler(0, SCHED_RR, &param) == -1)
+  {
+    fprintf(stderr, "sched_setscheduler: %s\n", strerror(errno));
+    abort();
+  }
+}
diff --git a/common/utils/utils.h b/common/utils/utils.h
index 16631586c413ec7532812da13f28ecd79dd7a9c1..d4337e71a6b7162164f92b2bbb1f2a264500a2b1 100644
--- a/common/utils/utils.h
+++ b/common/utils/utils.h
@@ -10,6 +10,7 @@ extern "C" {
 #define sizeofArray(a) (sizeof(a)/sizeof(*(a)))
 void *calloc_or_fail(size_t size);
 void *malloc_or_fail(size_t size);
+const char *hexdump(const void *data, size_t data_len, char *out, size_t out_len);
 
 // Converts an hexadecimal ASCII coded digit into its value. **
 int hex_char_to_hex_value (char c);
@@ -18,6 +19,7 @@ int hex_string_to_hex_value (uint8_t *hex_value, const char *hex_string, int siz
 
 void *memcpy1(void *dst,const void *src,size_t n);
 
+void set_priority(int priority);
 
 char *itoa(int i);
 
diff --git a/doc/F1-design.md b/doc/F1-design.md
new file mode 100644
index 0000000000000000000000000000000000000000..80417b1ae3e73c20d52f590ecde03fd505fb2284
--- /dev/null
+++ b/doc/F1-design.md
@@ -0,0 +1,210 @@
+<table style="border-collapse: collapse; border: none;">
+  <tr style="border-collapse: collapse; border: none;">
+    <td style="border-collapse: collapse; border: none;">
+      <a href="http://www.openairinterface.org/">
+         <img src="./images/oai_final_logo.png" alt="" border=3 height=50 width=150>
+         </img>
+      </a>
+    </td>
+    <td style="border-collapse: collapse; border: none; vertical-align: center;">
+      <b><font size = "5">F1 split design</font></b>
+    </td>
+  </tr>
+</table>
+# 1. Introduction
+
+We use OpenAirInterface source code, and it's regular deployment scheme.
+
+F1 specification is in 3GPP documents: TS 38.470 header document and all documents listed in chapter 2 References of TS 38.470.
+
+This document explains how the source code works.
+
+Offered features and deployment instructions are described in: 
+https://gitlab.eurecom.fr/oai/openairinterface5g/-/wikis/f1-interface
+
+# 2. Common multi-threading architecture #
+
+The CU and DU interfaces are based on ITTI threads (see oai/common/utils/ocp_itti/itti.md)
+
+All OAI upper layers use the ITTI framework to run isolated threads dedicated to one feature.
+The lower layers adopt case by case specific software architecture.
+
+```mermaid
+graph TD
+Linux[configuration file] --> APP[gNB_app_task]
+Socks[Linux UDP] --> GTP[nr_gtpv1u_gNB_task]
+APP --> CU
+APP --> DU
+A[Linux SCTP] -->|sockets| SCTP(OAI itti thread TASK_SCTP)
+SCTP-->|TASK_NGAP| NG[ngap_gNB_task]
+NG-->|TASK_SCTP| SCTP
+SCTP-->|TASK_DU_F1| DU[F1AP_DU_task]
+SCTP-->|TASK_CU_F1| CU[F1AP_CU_task]
+CU-->|TASK_RRC_GNB| RRC
+RRC -->|non ITTI| PHY[OAI L1+L2]
+RRC -->|API calls to create tunnels| GTP
+PHY --> |user plane| GTP
+CU --> |TASK_GTPV1_U| GTP
+DU --> |TASK_GTPV1_U| GTP
+```
+A "task" is a Linux thread running infinite waiting loop on one ITTI queue 
+
+app task manages the initial configuration
+
+sctp task mamanges the SCTP Linux sockets
+
+CU code runs in the task F1AP_CU_task. It stores it's private data context in a static variable. No mutex is used, as the single interface to CU ITTI tast in incoming ITTI messages. CU task is a single ITTI queue, but multiple CU could exist in one Linux process, using the "instance id" (called "module id" also) to create separate contextual information for each CU instance.
+
+DU code runs in the task F1AP_DU_task. The design is similar to CU task
+
+All GTP-U tunnels are managed in a Linux Thread, that have partially ITTI design: 
+
+1. tunnel creation/deletion is by C API functions direct calls (a mutex protects it)
+2. outgoing packets are pushed in a ITTI queue to the gtp thread
+3. incoming packets are sent to the tunnel creator using a C callback (the callback function is given in tunnel creation order). The callback should not block
+
+
+# 3. CU F1AP messages  #
+
+## startup
+
+CU thread starts when the CU starts. It opens listening socket on F1AP_PORT_NUMBER by sending the appropriate message to TASK_SCTP.
+
+It will accept the first incoming connection on this port
+
+## F1 SETUP
+
+DU has connected, and sent this message.
+
+The CU receives, decode it and send relevant information to RRC thread by message F1AP_SETUP_REQ
+
+## F1 SETUP response
+
+RRC sends two messages to CU F1 task: the information to encode the F1 setup response and a second message to encode F1AP_GNB_CU_CONFIGURATION_UPDATE
+
+Upon reception of these two messages the CU task encodes and sends the messages to the DU
+
+## UE entry
+
+When CCH channel decoding finds a new UE identity, it call rrc_gNB_generate_RRCSetup() that will send F1AP_DL_RRC_MESSAGE to the CU task.
+
+The CU encodes and sends to DU DLRRCMessageTransfer
+
+## UE attach/detach
+
+When rrc_gNB_process_RRCReconfigurationComplete() occurs, the RRC sends to CU task the message F1AP_UE_CONTEXT_SETUP_REQ. The CU task encodes the F1 message UEContextSetup and send it to the DU over F1AP.
+
+This function rrc_gNB_process_RRCReconfigurationComplete() also creates the GTP-U user plane bearers.
+
+## F1AP incoming messages
+
+SCTP tasks sends a ITTI message  SCTP_DATA_IND to the CU task.
+
+A array of functions pointers and the F1AP standard identifier "procedureCode", the CU calls the appropriate function
+
+Hereafter the most significant messages processing
+
+### CU_handle_F1_SETUP_REQUEST
+
+Transcodes information to the same message toward RRC (F1AP_SETUP_REQ)
+
+### CU_handle_INITIAL_UL_RRC_MESSAGE_TRANSFER
+
+Transcodes information to the same message toward RRC (NR_RRC_MAC_CCCH_DATA_IND)
+
+### CU_handle_UL_RRC_MESSAGE_TRANSFER
+
+Encode and send data to PDCP  (calling pdcp_data_ind ()) for processing UL data.
+
+# DU F1 Messages
+
+## Startup
+
+The task "gNB app" after rzading the configuration file, sends a first message F1AP_SETUP_REQ to DU task
+
+Using this message, the uniq DU task (Linux Thread) creates a DU instance context memory space, calls SCTP task to create a socket to the CU.
+
+When it receives from the SCTP task the socket creation success, the DU task encodes+sends the F1 setup message to the CU.
+
+## F1AP_INITIAL_UL_RRC_MESSAGE
+
+When MAC layer push UL data to DU task, the DU sends to CU the message InitialULRRCMessageTransfer
+
+## F1AP_UL_RRC_MESSAGE
+
+In case of SRB bearer, the RLC layer use this message to push rlc bearer payload to DU task, that forward to CU
+
+## pdcp_data_ind
+
+This function call in RLC, when it is a DRB will be replaced by F1-U transport to CU
+
+## F1AP incoming messages
+
+SCTP tasks sends a ITTI message  SCTP_DATA_IND to the DU task.
+
+A array of functions pointers and the F1AP standard identifier "procedureCode", the DU calls the appropriate function
+
+Hereafter the most significant messages processing
+
+### DU_send_F1_SETUP_RESPONSE
+
+Decode the CU message, then encode a message to TASK_GNB_APP. The thread "APP" extracts the system information block and reconfigure the DU with: du_extract_and_decode_SI(), configure_gnb_du_mac()
+
+### DU_handle_gNB_CU_CONFIGURATION_UPDATE
+
+No developped
+
+### DU_handle_UE_CONTEXT_SETUP_REQUEST
+
+Push data to RLC layer for transmisstion in DL (to the UE) by calling enqueue_rlc_data_req()
+
+### DU_handle_DL_RRC_MESSAGE_TRANSFER
+
+Depending on the content, adds UE context in DU low layers and/or send data to the UE with rlc_data_req()
+
+# F1-U messages 
+
+The data path by itself doesn't make any difficulty:
+1. for UL, rlc calls pdcp_data_ind (DRB) or sends a message to RRC (SRB). So, we can replace pdcp_data_ind() by du_pdcp_data_ind() that will push the message in the GTP tunnel. In CU, assuming the tunnel is in place, the right call back decapsulate the transport (cu_ul_recv()), then calls pdcp_data_ind() in CU
+The SRB are sent in DU RRC tasks via itti F1AP_UL_RRC_MESSAGE (see above the processing)
+2. For DL, pdcp (in CU for DRBs) calls rlc_data_req (by a decoupling queue and thread rlc_data_req_thread, so function du_rlc_data_req() or enqueue_rlc_data_req()). in DU, assuming the gtp-u tunnel exists, a reception call back (du_dl_recv()) decapsulate the gtp-u packet and calls du_rlc_data_req()  
+
+Hereafter the processing design, that doesn't require to setup a new context storage, as we can use the GTP-U internal tables: rnti+rb=>teid for outgoing gtp-u packets and teid=>rnti+rb for incoming gtp-u packets
+
+In CU case, the DRB tunnel to DU and the tunnel on N3 have the same key (rnti, rb id), but they run in two different GTP-U instances.
+Each instance binds on diffrent sockets.
+
+For F1-U, both DU and CU binds on the full quadruplet (IP source, port source, IP destination, port destination) from the configuration file parameters: 
+local_s_address, remote_s_address,local_s_portd, remote_s_portd  
+
+These 4 values are in:  
+CU: at cell level (same level as nr_cellid parameter), they are read if tr_s_preference = "f1"; is set
+DU: in block MACRLCs, if tr_n_preference  = "f1"; is set in this block
+
+## tunnels setup
+In GTP-U, TS 29.281 specifies a option header (NR RAN Container This extension header may be transmitted in a G-PDU over the X2-U, Xn-U and F1-U user plane interfaces), but it is not mandatory optional header (as is the N3 one).
+
+So, we can use this header a something reliable with other vendors implementation.
+
+In DL, we need to associate the packet with: rnti, rb (radio bearer) and "mui" (a OAI internal id that is optional and may be removed soon) to call rlc_data_req()
+
+In UL, we need also the RNTI, the rb
+
+So, we need to create a gtp-u tunnel for each rb over F1, then manage in CU and DU the association between a uniq TEid and the pair(rnti, rb). This is already what we have in existing OAI GTP-U layer interface.
+
+In F1AP, for each "DRB to Be Setup Item IEs", we have a field TNL (transport network layer) to set a specific GTP tunnel (@IP, TEid, udp port is always 2152). This is the same for each message related to DRBs. (F1AP carries the SRB payload inside F1AP).
+
+So, For each F1AP containing DRB setup/modification/deletion, the related GTP-U tunnels will be modified one to one.
+The exception is the intialisation of new tunnel: in the call to tunnel creation, we need to send the remote TEID, but we don't know yet if we are the initial source. In this case, we issue a dummy (0xFFFF) remote teid; when we receive the remote answer, we get the source teid, that we can inform GTP-U with (using update tunnel).
+
+## processing on GTP-U incoming message
+
+Du_dl_recv() or cu_ul_recv() are called because we have set this callbacks in creat/update tunnel calls to gtp-u. As gtp-u maintains a pair(rnti,rbid) associated to each tunnel, the functions can be very simple stateless callback that calls pdcp_data_ind() or rlc_data_req() to get back in normal processing path
+
+## CU/DU outgoing 
+
+DU rlc north output goes to du_pdcp_data_ind() that push a outgoing packet request to gtp-u, using the rnti+rb as ids. GTP-U must have the tunnel existing, then it simply implement the same as in N3 for exemple.
+
+CU pdcp south output calls cu_rlc_data_ind() that do the same symetric processing.
+
+
diff --git a/doc/SW_archi.md b/doc/SW_archi.md
index e5856d63bc73ac1486b807236d9eea2aca66e34f..059386310213a17ef6149ec571c3c0bd813a084f 100644
--- a/doc/SW_archi.md
+++ b/doc/SW_archi.md
@@ -304,25 +304,36 @@ gtpv1u_create_s1u_tunnel(), delete tunnel, ... functions are called inside the o
 
 # New GTP
 ## initialization
-Coexistance until full merge with legacy GTP
-cmake new option: NEW_GTPU to use the new implementation (it changes for the entire executable)
-It is possible to use both old and new GTP in same executable because the itti task and all functions names are different 
-Current status of new implementation: not tested, X2 not developped, 5G new GTP option not developped, remain issues on data coming from void: muid, enb_flag, ...
 
 ocp_gtpv1uTask(): this creates only the thread, doesn't configure anything
 gtpv1Init(): creates a listening socket to Linux for a given reception and select a local IP address
 
-newGtpuCreateTunnel() this function will replace the xxx_create_tunnel_xxx() for various cases
-This creates a outgoing context for a teid (in input), it computes and return the incoming teid that will be used for incoming packets
-These teids and in a "instance", so in a Linux socket: same teid can co-exist for different sockets
- Remain here a lack to fill: the information given in the legacy funtions is not enough to fullfil the data needed by the callback
-stuff like enb_flag, but also mui and more important data are not given explicitly by any legacy function (gtpv1u_create_s1u_tunnel), but the legacy and the new interface to lower layer (like pdcp) require this data.
-The datamodel is still not fully understood, so this data source remain unknown
-A new parameter is the callback function: will be pdpcp_data_req() and gtpv_data_req() (x2 case) for existing implementation and later other call backs like the F1-U implementation.
-
-incoming packets
-the gtp layer retrieves the data, the teid, find out the related data: rnti, bearer and quite a lot of other parameters (not clear why, because it looks like all is statefull, so the lower layer should have the context) 
-if lower layers can be stateless, it is a good idea to keep the context in the gtp layer and pass it to the callback, but the design remain obfuscated.
+## newGtpuCreateTunnel()   
+this function will replace the xxx_create_tunnel_xxx() for various cases  
+The parameters are: 
+1. outgoing TEid, associated with outpoing pair(rnti, id)
+2. incoming packets callback, incoming pair(rnti,id) and a callback function for incoming data 
+
+## outgoing packets 
+
+Each call to newGtpuCreateTunnel() creates a outgoing context for a teid (given as function input), a pair(rnti,outgoing id).  
+ Each outgoing packet received on GTP-U ITTI queue must match one pair(rnti,id), so the gtp-u thread can lookup the related TEid and use it to encode the outpoing GTP-U tunneled packet.  
+
+## incoming packets   
+
+newGtpuCreateTunnel() computes and return the incoming teid that will be used for incoming packets.
+When a incoming packet arrives on this incoming teid, the GTP-U thread calls the defined callback, with the associated pair(rnti, incoming id).  
+
+stuff like enb_flag, mui and more important data are not given explicitly by any legacy function (gtpv1u_create_s1u_tunnel), but the legacy and the new interface to lower layer (like pdcp) require this data. We hardcode it in first version.
+
+## remaining work 
+These teids and "instance", so in a Linux socket: same teid can co-exist for different sockets
+ Remain here a lack to fill: the information given in the legacy funtions is not enough to fullfil the data needed by the callback  
+
+Coexistance until full merge with legacy GTP
+cmake new option: NEW_GTPU to use the new implementation (it changes for the entire executable)
+It is possible to use both old and new GTP in same executable because the itti task and all functions names are different 
+Current status of new implementation: not tested, X2 not developped, 5G new GTP option not developped, remain issues on data coming from void: muid, enb_flag, ...
 
 # NGAP
 NGAP would be a itti thread as is S1AP (+twin thread SCTP that is almost void processing)?  
diff --git a/doc/TESTING_5GSA_setup.md b/doc/TESTING_5GSA_setup.md
index 475123c99094e9cce304418fe9e7a97c8d83a392..048d8c86ff2e7a212693f3c1a65becef2bfa962f 100644
--- a/doc/TESTING_5GSA_setup.md
+++ b/doc/TESTING_5GSA_setup.md
@@ -95,7 +95,7 @@ To get the code and build the gNB executable:
     ./build_oai --gNB -w USRP
 ```
 
-A reference configuration file for the gNB is provided  [here](https://gitlab.eurecom.fr/oai/openairinterface5g/-/blob/develop/targets/PROJECTS/GENERIC-NR-5GC/CONF/gnb.sa.band78.fr1.106PRB.usrpb210.conf).     
+A reference configuration file for the **monolithic** gNB is provided  [here](https://gitlab.eurecom.fr/oai/openairinterface5g/-/blob/develop/targets/PROJECTS/GENERIC-NR-5GC/CONF/gnb.sa.band78.fr1.106PRB.usrpb210.conf).     
 
 
 In the following, we highlight the fields of the file that have to be configured according to the configuration and interfaces of the Core Network. First, the PLMN section has to be filled with the proper values that match the configuration of the AMF and the UE USIM.
@@ -194,6 +194,8 @@ The SA setup with OAI UE has been validated with **RFSIMULATOR**. Both control p
 
 In the following, we provide the instructions on how to build, configure and execute this SA setup.
 
+As another option, if you do not want to build anything and instead deploy the OAI RAN (RFSIMULATOR) and Core Network components directly using docker images and docker-compose, please have a look at [this tutorial](https://gitlab.eurecom.fr/oai/openairinterface5g/-/blob/develop/ci-scripts/yaml_files/5g_rfsimulator/README.md).
+
 ### NAS configuration for the OAI UE
 The NAS configuration parameters of the OAI UE can be set as input parameters, configuration file or can be hardcoded.  More specifically:
 - SUCI (*Subscription Concealed Identifier*)
@@ -245,7 +247,6 @@ The gNB configuration can be performed according to what is described in [sectio
 ## 2.2  OAI 5G Core Network installation and configuration
 The instructions for the installation of OAI CN components (AMF, SMF, NRF, UPF) using `docker-compose` can be found [here](https://gitlab.eurecom.fr/oai/cn5g/oai-cn5g-fed/-/blob/master/README.md).
 
-In addition, if you do not want to build anything, please have a look at [this tutorial](https://gitlab.eurecom.fr/oai/openairinterface5g/-/blob/develop/ci-scripts/yaml_files/5g_rfsimulator/README.md).
 
 ## 2.3 Execution of SA scenario
 
diff --git a/doc/episys/Channel_Abstraction_UE_Handling_LTE.PNG b/doc/episys/Channel_Abstraction_UE_Handling_LTE.PNG
new file mode 100644
index 0000000000000000000000000000000000000000..5e40d6ac1716057a941edbc79f5234d0b7d7b539
Binary files /dev/null and b/doc/episys/Channel_Abstraction_UE_Handling_LTE.PNG differ
diff --git a/doc/episys/Proxy_Interface_Diagram.PNG b/doc/episys/Proxy_Interface_Diagram.PNG
new file mode 100644
index 0000000000000000000000000000000000000000..a734f3d4b0010dd5998d064139fe49deb7727fc6
Binary files /dev/null and b/doc/episys/Proxy_Interface_Diagram.PNG differ
diff --git a/doc/episys/functional_diagram_proxy_lte.png b/doc/episys/functional_diagram_proxy_lte.png
new file mode 100644
index 0000000000000000000000000000000000000000..e2a3a2c8684f39fa91c34f9c41b2ee8bad26480a
Binary files /dev/null and b/doc/episys/functional_diagram_proxy_lte.png differ
diff --git a/doc/episys/functional_diagram_proxy_nsa.png b/doc/episys/functional_diagram_proxy_nsa.png
new file mode 100644
index 0000000000000000000000000000000000000000..4a555d12ea2a91474b496878faaf630ab4c25c8d
Binary files /dev/null and b/doc/episys/functional_diagram_proxy_nsa.png differ
diff --git a/doc/episys/lte_mode_l2_emulator/README.txt b/doc/episys/lte_mode_l2_emulator/README.txt
new file mode 100644
index 0000000000000000000000000000000000000000..7b555b84426c84c79f1176134a480a6fe178db8a
--- /dev/null
+++ b/doc/episys/lte_mode_l2_emulator/README.txt
@@ -0,0 +1,49 @@
+There are fundamental changes to the L2 emulation mechanism; these changes allow the
+user to run multiple UEs in separate Linux processes/machines/VMs/etc. They use a separate
+entity between the UE(s) and eNB. The UEs use nFAPI to communicate with the eNB. The
+nFAPI interface allows us to run in an emulated layer 2 mode, meaning that we are bypassing
+the layer 1 (PHY) functionality. Because we are bypassing the PHY layer,
+channel modeling capabilties have been added in the LTE UE phy_stub_ue.c file. To understand
+the interfaces between the different components associated with LTE mode, the image
+functional_diagram_proxy_lte.png has been provided.
+
+This functionality allows the user to plug in their own channel model and emulate the packet dropping procedure
+in real time. The channel modeling has not been provided by EpiSci, but the OAI code
+base already has some BLER curves available for use. The channel modeling functionality
+that is included in the phy_stub_ue.c file only includes the downlink channel modeling.
+Any uplink channel modeling must be conducted in some sort of proxy, which would sit
+between the UEs and eNB. (A description of the downlink channel modeling is shown in the
+Channel_Abstraction_UE_Handling_LTE.PNG image).
+
+The updates to the OAI code base removed some latent bugs, added multi-UE scalability,
+and were tested with a standard bypass proxy between the UE(s) and eNB. The bypass proxy is
+publicly available on GitHub (https://github.com/EpiSci/oai-lte-multi-ue-proxy). With this package,
+various multi-UE scenarios can be tested without the overhead of PHY-layer features
+of underlying radios. The features added in the L2 Emulator Mode for LTE are:
+
+ - Ease of use of gprof and address sanitizer for debugging purposes
+ - Updated json files to allow for GDB, real-time debugging capabilities
+ - Updated logging features to minimally log only key connection milestones. This improves scalability of multiple UEs.
+The logging mechanism described here is located in the log.c and log.h files. The LOG_MINIMAL
+function allows us to remove most OAI logging and includes LOG_A(...) logs and above. The LOG_A
+logs were chosen as analysis logs to meet EpiSci's internal testing procedure. The LOG_As
+only include logs that are considered to be milestones in a given test. For example, a
+log indicating that the RACH procedure has been completed for LTE. To select full logging, 
+set LOG_MINIMAL = 0 in the log.h file.
+ - Updated logging to include time stamp for timing analysis
+ - Updated memory allocation procedures to correct size requirements
+ - Added debugging features to handle signal terminations
+ - nfapi.c pullarray8 fix invalid pointer math
+ - Overlapping destination and source memory in memcpy, so updated to memmove to check for this bug
+ - Advanced error checking mechanisms in critical pack and unpack functions
+ - Created option for CPU assignment to UE to improve scalability
+ - Added EPC integration to allow multiple individual UE entities to each have their USIM information parsed by the executables
+ - Updated random value seeds to minimize probability of error in generation of random values
+ - Enables capability round robin scheduler if desired
+ - Enables capability real time scheduler if desired
+ - Added new standalone functions to the UE phy-layer (phy_stub_ue.c) to incorporate individual UE entities
+ - Updated sending and packing functions in UE (lte_ue.c) to incorporate new standalone changes
+ - Incorporated semaphores to control timing of incoming downlink packets
+ - Implemented new queuing system to handle message exchange from UE to eNB and vice versa
+ - Updated global value in nFAPI for size of subframe
+ - Updated global value to increase scalability in system
diff --git a/doc/episys/nsa_mode_l2_emulator/README.txt b/doc/episys/nsa_mode_l2_emulator/README.txt
new file mode 100644
index 0000000000000000000000000000000000000000..fefaf63f4479c019ac5107c990d33d850d4b110f
--- /dev/null
+++ b/doc/episys/nsa_mode_l2_emulator/README.txt
@@ -0,0 +1,94 @@
+There are fundamental changes to the L2 emulation mechanism; these changes allow the
+user to run multiple UEs in separate Linux processes/machines/VMs/etc. They use a separate
+entity between the UE(s) and eNB/gNB. The UEs use nFAPI to communicate with the eNB/gNB. The
+nFAPI interface allows us to run in an emulated L2 mode, meaning that we are bypassing
+the layer 1 (PHY) layer functionality. Becasue we are bypassing the PHY layer, special
+channel modeling capabilty has been added in the LTE UE phy_stub_ue.c file. To understand
+the interfaces between the different components associated with NSA mode, the image
+functional_diagram_proxy_nsa.png has been provided.
+
+This functionality allows the user to plug in their own channel model and emulate the packet dropping procedure
+in real time. The channel modeling has not been provided by EpiSci, but the OAI code
+base already has some BLER curves available for use. The chanel modeling functionality
+that is included in the phy_stub_ue.c file only includes the downlink channel modeling.
+Any uplink channel modeling must be conducted in some sort of proxy, which would sit
+between the UEs and eNB/gNB. (A description of the downlink channel modeling is shown in the
+Channel_Abstraction_UE_Handling_LTE.PNG image).
+
+The updates to the OAI code base removed some latent bugs, added multi-UE scalability,
+and were tested with a standard bypass proxy between the UE(s) and eNB/gNB. The bypass proxy is
+publicly available on GitHub (https://github.com/EpiSci/oai-lte-multi-ue-proxy). With this package,
+various multi-UE scenarios can be tested without the overhead of PHY-layer features
+of underlying radios. The added features to the OAI code base are listed below.
+
+ - Ease of use of gprof and address sanitizer for debugging purposes
+ - Updated json files to allow for GDB, real-time debugging capabilities
+ - Updated logging features to minimally log only key connection milestones. This improves scalability of multiple UEs.
+The logging mechanism described here is located in the log.c and log.h files. The LOG_MINIMAL
+function allows us to remove most logs and include LOG_A(...) logs and above. The LOG_A
+logs were chosen as analysis logs to meet EpiSci's internal testing procedure. The LOG_As
+only include logs that are considered to be milestones in a given test. For example, a
+log indicating that the CFRA procedure has been completed for NSA mode. To revert to full logging, 
+set LOG_MINIMAL = 0 in the log.h file.
+ - Updated logging to include time stamp for timing analysis
+ - Updated memory allocation procedures to correct size requirements
+ - Added debugging features to handle signal terminations
+ - nfapi.c pullarray8 fix invalid pointer math
+ - Overlapping destination and source memory in memcpy, so updated to memmove to check for this bug
+ - Advanced error checking mechanisms in critical pack and unpack functions
+ - Created option for CPU assignment to UE to improve scalability
+ - Added EPC integration to allow multiple individual UE entities to each have their USIM information parsed by the executables
+ - Updated random value seeds to minimize probability of error in generation of random values
+ - Enables capability round robin scheduler if desired
+ - Enables capability real time scheduler if desired
+ - Added new standalone functions to the UE phy-layer (phy_stub_ue.c) to incorporate individual UE entities
+ - Updated sending and packing functions in UE (lte_ue.c) to incorporate new standalone changes
+ - Incorporated semaphores to control timing of incoming downlink packets
+ - Implemented new queuing system to handle message exchange from UE to eNB and vice versa
+ - Updated global value in nFAPI for size of subframe
+ - Updated global value to increase scalability in system
+
+
+Additionally, NSA mode includes the establishment between an NR UE and the gNB via the LTE UE and eNB
+connection. For NSA mode, the downlink channel abstraction has not been added to the feature set yet.
+NSA mode has been tested and is fully functional with EpiSci's public version of the nFAPI proxy
+located at https://github.com/EpiSci/oai-lte-multi-ue-proxy
+NSA mode establishment includes the following steps:
+
+ - First UE capability enquiry is sent to NR UE
+ - NR UE updates and fills first capability enquiry
+ - eNB request for a measurement report
+ - Measurement request is sent to NR UE
+ - Measurement report is filled in NR UE
+ - Measurement report is received in eNB
+ - Request for second UE capability enquiry
+ - Send second enquiry to NR UE
+ - Second capability information is filled by NR UE
+ - Second capability information is sent to eNB
+ - NR UE capability information is received in gNB
+ - Periodic measurement report received in gNB
+ - RRCReconfigurationRequest is sent to NR UE
+ - RRCReconfigurationComplete is sent from NR UE
+ - RACH is received in the gNB
+ - RAR is received in NR UE
+ - Msg 3 is generated and sent to gNB
+ - CFRA procedure is complete
+
+Please note, the current status is:
+ - A single NSA UE is able to ping an external source
+ - Up to 4 NSA UEs can complete the CFRA procedure with a single gNB
+ - UE-to-UE traffic is still in work (incomplete due to gNB crashing)
+ - The gNB is crashing regularly and is still in work
+
+Test Setup:
+For launching the multi-UE for NSA mode, there is a provided test script in the
+public EpiSci GitHub multi-ue-proxy repository. However, a brief outline of the
+test set up is included below.
+
+    If running multiple NSA UEs in a single machine, you will need to launch
+    multiple LTE and NR UE processes. For example, to launch a 2 NSA UE scenario
+    there will be a total of 7 processes running for this particular scenario.
+    These processes are LTE UE #1, LTE UE #2, NR UE #1, NR UE #2, eNB, gNB and the
+    proxy. A detailed description of the launch processes can be found at
+    https://github.com/EpiSci/oai-lte-multi-ue-proxy/blob/master/README.md
+
diff --git a/docker/scripts/generateTemplate.py b/docker/scripts/generateTemplate.py
index cc4b72a7035159ebbae7e77767cfc150bfeb106b..3d037294e6b479a6030e7ae921a71a8e4331817a 100644
--- a/docker/scripts/generateTemplate.py
+++ b/docker/scripts/generateTemplate.py
@@ -55,6 +55,8 @@ def main():
                              "rcc.band40.tm1.25PRB": f'{data[0]["paths"]["dest_dir"]}/{outputfilename}',
                              "gnb.band78.tm1.fr1.106PRB.usrpb210.conf": f'{data[0]["paths"]["dest_dir"]}/{outputfilename}',
                              "gnb.band78.sa.fr1.106PRB.usrpn310.conf": f'{data[0]["paths"]["dest_dir"]}/{outputfilename}',
+                             "gNB_SA_CU.conf": f'{data[0]["paths"]["dest_dir"]}/{outputfilename}',
+                             "gNB_SA_DU.conf": f'{data[0]["paths"]["dest_dir"]}/{outputfilename}',
                              "ue.nfapi": f'{data[0]["paths"]["dest_dir"]}/{outputfilename}',
                              "ue_sim_ci": f'{data[0]["paths"]["dest_dir"]}/{outputfilename}'
                              }
@@ -77,6 +79,10 @@ def main():
               templine = re.sub(r'sd  = 0x1;', 'sd  = 0x@NSSAI_SD0@;', line)
               outputfile.write(templine)
               continue
+            if re.search(r'sd  = 0x010203;', line):
+              templine = re.sub(r'sd  = 0x010203;', 'sd  = 0x@NSSAI_SD0@;', line)
+              outputfile.write(templine)
+              continue
             if re.search(r'sd  = 0x112233;', line):
               templine = re.sub(r'sd  = 0x112233;', 'sd  = 0x@NSSAI_SD1@;', line)
               outputfile.write(templine)
diff --git a/docker/scripts/gnb_entrypoint.sh b/docker/scripts/gnb_entrypoint.sh
index 2fe743920ea0877e794ad04cf26a506b494a6c57..79d6c6dc372e62f172b97a06934d411d66b8623e 100755
--- a/docker/scripts/gnb_entrypoint.sh
+++ b/docker/scripts/gnb_entrypoint.sh
@@ -7,8 +7,11 @@ ENABLE_X2=${ENABLE_X2:-yes}
 THREAD_PARALLEL_CONFIG=${THREAD_PARALLEL_CONFIG:-PARALLEL_SINGLE_THREAD}
 
 # Based another env var, pick one template to use
+
 if [[ -v USE_NSA_TDD_MONO ]]; then cp $PREFIX/etc/gnb.nsa.tdd.conf $PREFIX/etc/gnb.conf; fi
 if [[ -v USE_SA_TDD_MONO ]]; then cp $PREFIX/etc/gnb.sa.tdd.conf $PREFIX/etc/gnb.conf; fi
+if [[ -v USE_SA_CU ]]; then ln -s $PREFIX/etc/gnb.sa.cu.conf $PREFIX/etc/gnb.conf; fi
+if [[ -v USE_SA_TDD_CU ]]; then cp $PREFIX/etc/gnb.sa.du.tdd.conf $PREFIX/etc/gnb.conf; fi
 # Sometimes, the templates are not enough. We mount a conf file on $PREFIX/etc. It can be a template itself.
 if [[ -v USE_VOLUMED_CONF ]]; then cp $PREFIX/etc/mounted.conf $PREFIX/etc/gnb.conf; fi
 
diff --git a/docker/scripts/gnb_parameters.yaml b/docker/scripts/gnb_parameters.yaml
index ac5a6cb971629cbc69d0c6959625c83c18b1c518..2f150d394a04697108d04804bfda617ddec6f628 100644
--- a/docker/scripts/gnb_parameters.yaml
+++ b/docker/scripts/gnb_parameters.yaml
@@ -94,3 +94,81 @@
     - key: parallel_config
       env: "@THREAD_PARALLEL_CONFIG@"
 
+  - filePrefix: gNB_SA_CU.conf
+    outputfilename: "gnb.sa.cu.conf"
+    config:
+    - key: Active_gNBs
+      env: "@GNB_NAME@"
+    - key: gNB_name
+      env: "@GNB_NAME@"
+    - key: mcc
+      env: "@MCC@"
+    - key: mnc
+      env: "@MNC@"
+    - key: mnc_length
+      env: "@MNC_LENGTH@"
+    - key: tracking_area_code
+      env: "@TAC@"
+    - key: sst
+      env: "@NSSAI_SST@"
+    - key: ipv4
+      env: "@AMF_IP_ADDRESS@"
+    - key: GNB_INTERFACE_NAME_FOR_NG_AMF
+      env: "@GNB_NGA_IF_NAME@"
+    - key: GNB_IPV4_ADDRESS_FOR_NG_AMF
+      env: "@GNB_NGA_IP_ADDRESS@"
+    - key: GNB_INTERFACE_NAME_FOR_NGU
+      env: "@GNB_NGU_IF_NAME@"
+    - key: GNB_IPV4_ADDRESS_FOR_NGU
+      env: "@GNB_NGU_IP_ADDRESS@"
+    - key: local_s_if_name
+      env: "@F1_IF_NAME@"
+    - key: local_s_address
+      env: "@F1_CU_IP_ADDRESS@"
+    - key: local_s_portd
+      env: "@F1_CU_D_PORT@"
+    - key: remote_s_address
+      env: "@F1_DU_IP_ADDRESS@"
+    - key: remote_s_portd
+      env: "@F1_DU_D_PORT@"
+
+  - filePrefix: gNB_SA_DU.conf
+    outputfilename: "gnb.sa.du.tdd.conf"
+    config:
+    - key: Active_gNBs
+      env: "@GNB_NAME@"
+    - key: gNB_name
+      env: "@GNB_NAME@"
+    - key: mcc
+      env: "@MCC@"
+    - key: mnc
+      env: "@MNC@"
+    - key: mnc_length
+      env: "@MNC_LENGTH@"
+    - key: tracking_area_code
+      env: "@TAC@"
+    - key: sst
+      env: "@NSSAI_SST@"
+    - key: ipv4
+      env: "@AMF_IP_ADDRESS@"
+    - key: GNB_INTERFACE_NAME_FOR_NG_AMF
+      env: "@GNB_NGA_IF_NAME@"
+    - key: GNB_IPV4_ADDRESS_FOR_NG_AMF
+      env: "@GNB_NGA_IP_ADDRESS@"
+    - key: GNB_INTERFACE_NAME_FOR_NGU
+      env: "@GNB_NGU_IF_NAME@"
+    - key: GNB_IPV4_ADDRESS_FOR_NGU
+      env: "@GNB_NGU_IP_ADDRESS@"
+    - key: parallel_config
+      env: "@THREAD_PARALLEL_CONFIG@"
+    - key: local_n_if_name
+      env: "@F1_IF_NAME@"
+    - key: local_n_address
+      env: "@F1_DU_IP_ADDRESS@"
+    - key: local_n_portd
+      env: "@F1_DU_D_PORT@"
+    - key: remote_n_address
+      env: "@F1_CU_IP_ADDRESS@"
+    - key: remote_n_portd
+      env: "@F1_CU_D_PORT@"
+
diff --git a/executables/main-fs6.c b/executables/main-fs6.c
index 438edb4044dd02dc766029406697c6094c4e300c..9e92f2e41af1b9fcdadca62d0c1c6cb0909560a7 100644
--- a/executables/main-fs6.c
+++ b/executables/main-fs6.c
@@ -553,7 +553,11 @@ void fill_rx_indication_from_split(uint8_t *bufferZone, PHY_VARS_eNB *eNB,int UE
   pdu->rx_indication_rel8.tl.tag         = NFAPI_RX_INDICATION_REL8_TAG;
   pdu->rx_indication_rel8.length         = eNB->ulsch[UE_id]->harq_processes[harq_pid]->TBS>>3;
   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                              = eNB->ulsch[UE_id]->harq_processes[harq_pid]->decodedBytes;
+  AssertFatal(pdu->rx_indication_rel8.length <= NFAPI_RX_IND_DATA_MAX, "Invalid PDU len %d\n",
+              pdu->rx_indication_rel8.length);
+  memcpy(pdu->rx_ind_data,
+         eNB->ulsch[UE_id]->harq_processes[harq_pid]->decodedBytes,
+         pdu->rx_indication_rel8.length);
   // estimate timing advance for MAC
   timing_advance_update                  = ul_propa[UE_id].ta;
 
diff --git a/executables/main-ocp.c b/executables/main-ocp.c
index 0355582b2b4e76848588cd22a580dd4577569ab0..ab31eaaa4f17e10059d67b8334019039fd72be67 100644
--- a/executables/main-ocp.c
+++ b/executables/main-ocp.c
@@ -81,17 +81,16 @@ int otg_enabled;
 uint64_t  downlink_frequency[MAX_NUM_CCs][4];
 int32_t   uplink_frequency_offset[MAX_NUM_CCs][4];
 int split73;
-char * split73_config;
+char *split73_config;
 int split73;
 AGENT_RRC_xface *agent_rrc_xface[NUM_MAX_ENB]= {0};
 AGENT_MAC_xface *agent_mac_xface[NUM_MAX_ENB]= {0};
-uint8_t proto_agent_flag = 0;
 void flexran_agent_slice_update(mid_t module_idP) {
 }
-int proto_agent_start(mod_id_t mod_id, const cudu_params_t *p){
-        return 0;
+int proto_agent_start(mod_id_t mod_id, const cudu_params_t *p) {
+  return 0;
 }
-void proto_agent_stop(mod_id_t mod_id){
+void proto_agent_stop(mod_id_t mod_id) {
 }
 
 static void *ru_thread( void *param );
@@ -112,7 +111,6 @@ void exit_function(const char *file, const char *function, const int line, const
 
   close_log_mem();
   oai_exit = 1;
-
   sleep(1); //allow lte-softmodem threads to exit first
   exit(1);
 }
@@ -145,14 +143,16 @@ void init_RU_proc(RU_t *ru) {
   pthread_t t;
 
   switch(split73) {
-  case SPLIT73_CU:
-    threadCreate(&t, cu_fs6, (void *)ru, "MainCu", -1, OAI_PRIORITY_RT_MAX);
-    break;
-  case SPLIT73_DU:
-    threadCreate(&t, du_fs6, (void *)ru, "MainDuRx", -1, OAI_PRIORITY_RT_MAX);
-    break;
-  default:
-    threadCreate(&t,  ru_thread, (void *)ru, "MainRu", -1, OAI_PRIORITY_RT_MAX);
+    case SPLIT73_CU:
+      threadCreate(&t, cu_fs6, (void *)ru, "MainCu", -1, OAI_PRIORITY_RT_MAX);
+      break;
+
+    case SPLIT73_DU:
+      threadCreate(&t, du_fs6, (void *)ru, "MainDuRx", -1, OAI_PRIORITY_RT_MAX);
+      break;
+
+    default:
+      threadCreate(&t,  ru_thread, (void *)ru, "MainRu", -1, OAI_PRIORITY_RT_MAX);
   }
 }
 
@@ -161,7 +161,7 @@ void init_transport(PHY_VARS_eNB *eNB) {
   LTE_DL_FRAME_PARMS *fp = &eNB->frame_parms;
   LOG_I(PHY, "Initialise transport\n");
 
-  for (int i=0; i<NUMBER_OF_UE_MAX; i++) {
+  for (int i=0; i<NUMBER_OF_DLSCH_MAX; i++) {
     LOG_D(PHY,"Allocating Transport Channel Buffers for DLSCH, UE %d\n",i);
 
     for (int j=0; j<2; j++) {
@@ -170,7 +170,9 @@ void init_transport(PHY_VARS_eNB *eNB) {
       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);
     }
+  }
 
+  for (int i=0; i<NUMBER_OF_ULSCH_MAX; i++) {
     LOG_D(PHY,"Allocating Transport Channel Buffer for ULSCH, UE %d\n",i);
     AssertFatal((eNB->ulsch[1+i] = new_eNB_ulsch(MAX_TURBO_ITERATIONS,fp->N_RB_UL, 0)) != NULL,
                 "Can't get eNB ulsch structures\n");
@@ -198,6 +200,9 @@ void init_transport(PHY_VARS_eNB *eNB) {
   eNB->FULL_MUMIMO_transmissions = 0;
   eNB->check_for_SUMIMO_transmissions = 0;
   fp->pucch_config_common.deltaPUCCH_Shift = 1;
+
+  if (eNB->use_DTX == 0)
+    fill_subframe_mask(eNB);
 }
 
 void init_eNB_afterRU(void) {
@@ -228,25 +233,23 @@ void init_eNB_afterRU(void) {
 
           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];
-
         }
       }
 
-
       AssertFatal( eNB->frame_parms.nb_antennas_rx > 0 && eNB->frame_parms.nb_antennas_rx < 5, "");
       AssertFatal( eNB->frame_parms.nb_antennas_tx > 0 && eNB->frame_parms.nb_antennas_rx < 5, "");
-
       phy_init_lte_eNB(eNB,0,0);
 
       // need to copy rxdataF after L1 variables are allocated
       for (int inst=0; inst<RC.nb_inst; inst++) {
-         for (int CC_id=0; CC_id<RC.nb_CC[inst]; CC_id++) {
-           PHY_VARS_eNB *eNB = RC.eNB[inst][CC_id];
-           for (int ru_id=0,aa=0; ru_id<eNB->num_RU; ru_id++) {
-              for (int i=0; i<eNB->RU_list[ru_id]->nb_rx; aa++,i++) 
-                eNB->common_vars.rxdataF[aa]     =  eNB->RU_list[ru_id]->common.rxdataF[i];
-           }
-         }
+        for (int CC_id=0; CC_id<RC.nb_CC[inst]; CC_id++) {
+          PHY_VARS_eNB *eNB = RC.eNB[inst][CC_id];
+
+          for (int ru_id=0,aa=0; ru_id<eNB->num_RU; ru_id++) {
+            for (int i=0; i<eNB->RU_list[ru_id]->nb_rx; aa++,i++)
+              eNB->common_vars.rxdataF[aa]     =  eNB->RU_list[ru_id]->common.rxdataF[i];
+          }
+        }
       }
 
       LOG_I(PHY,"inst %d, CC_id %d : nb_antennas_rx %d\n",inst,CC_id,eNB->frame_parms.nb_antennas_rx);
@@ -300,7 +303,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;
+  int numerology = 0; //get_softmodem_params()->numerology;
 
   if(fp->N_RB_DL == 100) {
     if(numerology == 0) {
@@ -347,7 +350,8 @@ void fill_rf_config(RU_t *ru, char *rf_config_file) {
     cfg->samples_per_frame = 19200;
     cfg->tx_bw = 1.5e6;
     cfg->rx_bw = 1.5e6;
-  } else AssertFatal(1==0,"Unknown N_RB_DL %d\n",fp->N_RB_DL);
+  } else
+    AssertFatal(1==0,"Unknown N_RB_DL %d\n",fp->N_RB_DL);
 
   if (fp->frame_type==TDD)
     cfg->duplex_mode = duplex_mode_TDD;
@@ -468,7 +472,8 @@ void ocp_rx_prach(PHY_VARS_eNB *eNB,
           ((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]=proc->frame_prach_br;
+        if (eNB->prach_vars_br.repetition_number[i]==0)
+          eNB->prach_vars_br.first_frame[i]=proc->frame_prach_br;
 
         // increment repetition number
         eNB->prach_vars_br.repetition_number[i]++;
@@ -771,7 +776,8 @@ static void *ru_thread( void *param ) {
   // Start RF device if any
   if (ru->rfdevice.trx_start_func(&ru->rfdevice) != 0)
     LOG_E(HW,"Could not start the RF device\n");
-  else LOG_I(PHY,"RU %d rf device ready\n",ru->idx);
+  else
+    LOG_I(PHY,"RU %d rf device ready\n",ru->idx);
 
   // This is a forever while loop, it loops over subframes which are scheduled by incoming samples from HW devices
   while (!oai_exit) {
@@ -815,7 +821,7 @@ int init_rf(RU_t *ru) {
   pthread_setname_np(pthread_self(),name);
   return ret;
 }
- 
+
 void ocp_init_RU(RU_t *ru, char *rf_config_file, int send_dmrssync) {
   PHY_VARS_eNB *eNB0= (PHY_VARS_eNB *)NULL;
   int i;
@@ -831,48 +837,47 @@ void ocp_init_RU(RU_t *ru, char *rf_config_file, int send_dmrssync) {
         RC.eNB[i][CC_id]->num_RU=0;
 
   LOG_D(PHY,"Process RUs RC.nb_RU:%d\n",RC.nb_RU);
+  ru->rf_config_file = rf_config_file;
+  ru->idx          = 0;
+  ru->ts_offset    = 0;
 
-    ru->rf_config_file = rf_config_file;
-    ru->idx          = 0;
-    ru->ts_offset    = 0;
-
-    if (ru->is_slave == 1) {
-      ru->in_synch    = 0;
-      ru->generate_dmrs_sync = 0;
-    } else {
-      ru->in_synch    = 1;
-      ru->generate_dmrs_sync=send_dmrssync;
-    }
+  if (ru->is_slave == 1) {
+    ru->in_synch    = 0;
+    ru->generate_dmrs_sync = 0;
+  } else {
+    ru->in_synch    = 1;
+    ru->generate_dmrs_sync=send_dmrssync;
+  }
 
-    ru->cmd      = EMPTY;
-    ru->south_out_cnt= 0;
+  ru->cmd      = EMPTY;
+  ru->south_out_cnt= 0;
 
-    //    ru->generate_dmrs_sync = (ru->is_slave == 0) ? 1 : 0;
-    if (ru->generate_dmrs_sync == 1) {
-      generate_ul_ref_sigs();
-      ru->dmrssync = (int16_t *)malloc16_clear(ru->frame_parms->ofdm_symbol_size*2*sizeof(int16_t));
-    }
+  //    ru->generate_dmrs_sync = (ru->is_slave == 0) ? 1 : 0;
+  if (ru->generate_dmrs_sync == 1) {
+    generate_ul_ref_sigs();
+    ru->dmrssync = (int16_t *)malloc16_clear(ru->frame_parms->ofdm_symbol_size*2*sizeof(int16_t));
+  }
 
-    ru->wakeup_L1_sleeptime = 2000;
-    ru->wakeup_L1_sleep_cnt_max  = 3;
+  ru->wakeup_L1_sleeptime = 2000;
+  ru->wakeup_L1_sleep_cnt_max  = 3;
 
-    if (ru->num_eNB > 0) {
-      AssertFatal(ru->eNB_list[0], "ru->eNB_list is not initialized\n");
-    } else {
-      LOG_E(PHY,"Wrong data model, assigning eNB 0, carrier 0 to RU 0\n");
-      ru->eNB_list[0] = RC.eNB[0][0];
-      ru->num_eNB=1;
-    }
+  if (ru->num_eNB > 0) {
+    AssertFatal(ru->eNB_list[0], "ru->eNB_list is not initialized\n");
+  } else {
+    LOG_E(PHY,"Wrong data model, assigning eNB 0, carrier 0 to RU 0\n");
+    ru->eNB_list[0] = RC.eNB[0][0];
+    ru->num_eNB=1;
+  }
 
-    eNB0 = ru->eNB_list[0];
-    // datamodel error in regular OAI: a RU uses one single eNB carrier parameters!
-    ru->frame_parms = &eNB0->frame_parms;
+  eNB0 = ru->eNB_list[0];
+  // datamodel error in regular OAI: a RU uses one single eNB carrier parameters!
+  ru->frame_parms = &eNB0->frame_parms;
 
-    for (i=0; i<ru->num_eNB; i++) {
-      eNB0 = ru->eNB_list[i];
-      int ruIndex=eNB0->num_RU++;
-      eNB0->RU_list[ruIndex] = ru;
-    }
+  for (i=0; i<ru->num_eNB; i++) {
+    eNB0 = ru->eNB_list[i];
+    int ruIndex=eNB0->num_RU++;
+    eNB0->RU_list[ruIndex] = ru;
+  }
 }
 
 void stop_RU(int nb_ru) {
@@ -885,7 +890,7 @@ void stop_RU(int nb_ru) {
 /* --------------------------------------------------------*/
 /* from here function to use configuration module          */
 static int DEFBFW[] = {0x00007fff};
-void ocpRCconfig_RU(RU_t* ru) {
+void ocpRCconfig_RU(RU_t *ru) {
   paramdef_t RUParams[] = RUPARAMS_DESC;
   paramlist_def_t RUParamList = {CONFIG_STRING_RU_LIST,NULL,0};
   config_getlist( &RUParamList,RUParams,sizeof(RUParams)/sizeof(paramdef_t), NULL);
@@ -915,7 +920,7 @@ void ocpRCconfig_RU(RU_t* ru) {
   if (config_isparamset(vals, RU_SDR_CLK_SRC)) {
     char *paramVal=*(vals[RU_SDR_CLK_SRC].strptr);
     LOG_D(PHY, "RU clock source set as %s\n", paramVal);
-    
+
     if (strcmp(paramVal, "internal") == 0) {
       ru->openair0_cfg.clock_source = internal;
     } else if (strcmp(paramVal, "external") == 0) {
@@ -929,42 +934,41 @@ void ocpRCconfig_RU(RU_t* ru) {
 
   if (strcmp(*(vals[RU_LOCAL_RF_IDX].strptr), "yes") == 0) {
     if ( !(config_isparamset(vals,RU_LOCAL_IF_NAME_IDX)) ) {
-        ru->if_south  = LOCAL_RF;
-        ru->function  = eNodeB_3GPP;
-      } else {
-        ru->eth_params.local_if_name = strdup(*(vals[RU_LOCAL_IF_NAME_IDX].strptr));
-        ru->eth_params.my_addr       = strdup(*(vals[RU_LOCAL_ADDRESS_IDX].strptr));
-        ru->eth_params.remote_addr   = strdup(*(vals[RU_REMOTE_ADDRESS_IDX].strptr));
-        ru->eth_params.my_portc      = *(vals[RU_LOCAL_PORTC_IDX].uptr);
-        ru->eth_params.remote_portc  = *(vals[RU_REMOTE_PORTC_IDX].uptr);
-        ru->eth_params.my_portd      = *(vals[RU_LOCAL_PORTD_IDX].uptr);
-        ru->eth_params.remote_portd  = *(vals[RU_REMOTE_PORTD_IDX].uptr);
-      }
-
-      ru->max_pdschReferenceSignalPower = *(vals[RU_MAX_RS_EPRE_IDX].uptr);;
-      ru->max_rxgain                    = *(vals[RU_MAX_RXGAIN_IDX].uptr);
-      ru->num_bands                     = vals[RU_BAND_LIST_IDX].numelt;
-      /* sf_extension is in unit of samples for 30.72MHz here, has to be scaled later */
-      ru->sf_extension                  = *(vals[RU_SF_EXTENSION_IDX].uptr);
-      ru->end_of_burst_delay            = *(vals[RU_END_OF_BURST_DELAY_IDX].uptr);
-
-      for (int i=0; i<ru->num_bands; i++)
-	ru->band[i] = vals[RU_BAND_LIST_IDX].iptr[i];
+      ru->if_south  = LOCAL_RF;
+      ru->function  = eNodeB_3GPP;
     } else {
-      ru->eth_params.local_if_name    = strdup(*(vals[RU_LOCAL_IF_NAME_IDX].strptr));
-      ru->eth_params.my_addr          = strdup(*(vals[RU_LOCAL_ADDRESS_IDX].strptr));
-      ru->eth_params.remote_addr      = strdup(*(vals[RU_REMOTE_ADDRESS_IDX].strptr));
-      ru->eth_params.my_portc         = *(vals[RU_LOCAL_PORTC_IDX].uptr);
-      ru->eth_params.remote_portc     = *(vals[RU_REMOTE_PORTC_IDX].uptr);
-      ru->eth_params.my_portd         = *(vals[RU_LOCAL_PORTD_IDX].uptr);
-      ru->eth_params.remote_portd     = *(vals[RU_REMOTE_PORTD_IDX].uptr);
-    }  /* strcmp(local_rf, "yes") != 0 */
-
-    ru->nb_tx                             = *(vals[RU_NB_TX_IDX].uptr);
-    ru->nb_rx                             = *(vals[RU_NB_RX_IDX].uptr);
-    ru->att_tx                            = *(vals[RU_ATT_TX_IDX].uptr);
-    ru->att_rx                            = *(vals[RU_ATT_RX_IDX].uptr);
+      ru->eth_params.local_if_name = strdup(*(vals[RU_LOCAL_IF_NAME_IDX].strptr));
+      ru->eth_params.my_addr       = strdup(*(vals[RU_LOCAL_ADDRESS_IDX].strptr));
+      ru->eth_params.remote_addr   = strdup(*(vals[RU_REMOTE_ADDRESS_IDX].strptr));
+      ru->eth_params.my_portc      = *(vals[RU_LOCAL_PORTC_IDX].uptr);
+      ru->eth_params.remote_portc  = *(vals[RU_REMOTE_PORTC_IDX].uptr);
+      ru->eth_params.my_portd      = *(vals[RU_LOCAL_PORTD_IDX].uptr);
+      ru->eth_params.remote_portd  = *(vals[RU_REMOTE_PORTD_IDX].uptr);
+    }
+
+    ru->max_pdschReferenceSignalPower = *(vals[RU_MAX_RS_EPRE_IDX].uptr);;
+    ru->max_rxgain                    = *(vals[RU_MAX_RXGAIN_IDX].uptr);
+    ru->num_bands                     = vals[RU_BAND_LIST_IDX].numelt;
+    /* sf_extension is in unit of samples for 30.72MHz here, has to be scaled later */
+    ru->sf_extension                  = *(vals[RU_SF_EXTENSION_IDX].uptr);
+    ru->end_of_burst_delay            = *(vals[RU_END_OF_BURST_DELAY_IDX].uptr);
 
+    for (int i=0; i<ru->num_bands; i++)
+      ru->band[i] = vals[RU_BAND_LIST_IDX].iptr[i];
+  } else {
+    ru->eth_params.local_if_name    = strdup(*(vals[RU_LOCAL_IF_NAME_IDX].strptr));
+    ru->eth_params.my_addr          = strdup(*(vals[RU_LOCAL_ADDRESS_IDX].strptr));
+    ru->eth_params.remote_addr      = strdup(*(vals[RU_REMOTE_ADDRESS_IDX].strptr));
+    ru->eth_params.my_portc         = *(vals[RU_LOCAL_PORTC_IDX].uptr);
+    ru->eth_params.remote_portc     = *(vals[RU_REMOTE_PORTC_IDX].uptr);
+    ru->eth_params.my_portd         = *(vals[RU_LOCAL_PORTD_IDX].uptr);
+    ru->eth_params.remote_portd     = *(vals[RU_REMOTE_PORTD_IDX].uptr);
+  }  /* strcmp(local_rf, "yes") != 0 */
+
+  ru->nb_tx                             = *(vals[RU_NB_TX_IDX].uptr);
+  ru->nb_rx                             = *(vals[RU_NB_RX_IDX].uptr);
+  ru->att_tx                            = *(vals[RU_ATT_TX_IDX].uptr);
+  ru->att_rx                            = *(vals[RU_ATT_RX_IDX].uptr);
   return;
 }
 
@@ -1044,28 +1048,28 @@ void init_pdcp(void) {
     pdcp_initmask = pdcp_initmask | ENB_NAS_USE_TUN_W_MBMS_BIT;
 
     if ( split73!=SPLIT73_DU)
-      pdcp_module_init(pdcp_initmask);
+      pdcp_module_init(pdcp_initmask, 0);
 
     if (NODE_IS_CU(RC.rrc[0]->node_type)) {
-      //pdcp_set_rlc_data_req_func((send_rlc_data_req_func_t)proto_agent_send_rlc_data_req);
+      //pdcp_set_rlc_data_req_func(proto_agent_send_rlc_data_req);
     } else {
-      pdcp_set_rlc_data_req_func((send_rlc_data_req_func_t) rlc_data_req);
-      pdcp_set_pdcp_data_ind_func((pdcp_data_ind_func_t) pdcp_data_ind);
+      pdcp_set_rlc_data_req_func(rlc_data_req);
+      pdcp_set_pdcp_data_ind_func(pdcp_data_ind);
     }
   } else {
-    //pdcp_set_pdcp_data_ind_func((pdcp_data_ind_func_t) proto_agent_send_pdcp_data_ind);
+    //pdcp_set_pdcp_data_ind_func(proto_agent_send_pdcp_data_ind);
   }
 }
 
 static  void wait_nfapi_init(char *thread_name) {
-  printf( "waiting for NFAPI PNF connection and population of global structure (%s)\n",thread_name);
+  LOG_I(ENB_APP, "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);
+  LOG_I(ENB_APP, "NFAPI: got sync (%s)\n", thread_name);
 }
 
 void terminate_task(module_id_t mod_id, task_id_t from, task_id_t to) {
@@ -1078,7 +1082,6 @@ void terminate_task(module_id_t mod_id, task_id_t from, task_id_t to) {
 
 int stop_L1L2(module_id_t enb_id) {
   LOG_W(ENB_APP, "stopping lte-softmodem\n");
-
   /* these tasks need to pick up new configuration */
   terminate_task(enb_id, TASK_ENB_APP, TASK_RRC_ENB);
   oai_exit = 1;
@@ -1109,11 +1112,9 @@ int restart_L1L2(module_id_t enb_id) {
   pthread_mutex_lock(&sync_mutex);
   sync_var = -1;
   pthread_mutex_unlock(&sync_mutex);
-
   /* copy the changed frame parameters to the RU */
   /* TODO this should be done for all RUs associated to this eNB */
   memcpy(&ru->frame_parms, &RC.eNB[enb_id][0]->frame_parms, sizeof(LTE_DL_FRAME_PARMS));
-
   /* reset the list of connected UEs in the MAC, since in this process with
    * loose all UEs (have to reconnect) */
   init_UE_info(&RC.mac[enb_id]->UE_info);
@@ -1177,7 +1178,6 @@ int main ( int argc, char **argv ) {
   // 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.
   RU_t ru;
-  
 
   /* We need to read RU configuration before FlexRAN starts so it knows what
    * splits to report. Actual RU start comes later. */
@@ -1189,9 +1189,10 @@ int main ( int argc, char **argv ) {
   }
 
   if ( strlen(get_softmodem_params()->split73) > 0 ) {
-    char tmp[1024]={0};
+    char tmp[1024]= {0};
     strncpy(tmp,get_softmodem_params()->split73, 1023);
     tmp[2]=0;
+
     if ( strncasecmp(tmp,"cu", 2)==0 )
       split73=SPLIT73_CU;
     else if ( strncasecmp(tmp,"du", 2)==0 )
@@ -1199,13 +1200,13 @@ int main ( int argc, char **argv ) {
     else
       AssertFatal(false,"split73 syntax: <cu|du>:<remote ip addr>[:<ip port>] (string found: %s) \n",get_softmodem_params()->split73);
   }
-  
+
   if (RC.nb_inst > 0) {
     /* Start the agent. If it is turned off in the configuration, it won't start */
     for (i = 0; i < RC.nb_inst; i++) {
       //flexran_agent_start(i);
     }
-    
+
     /* initializes PDCP and sets correct RLC Request/PDCP Indication callbacks
      * for monolithic/F1 modes */
     init_pdcp();
@@ -1284,17 +1285,14 @@ int main ( int argc, char **argv ) {
 
   printf("About to Init RU threads RC.nb_RU:%d\n", RC.nb_RU);
 
-
   if (RC.nb_RU >0 && NFAPI_MODE!=NFAPI_MODE_VNF) {
     printf("Initializing RU threads\n");
     ocp_init_RU(&ru,
-	    get_softmodem_params()->rf_config_file,
-            get_softmodem_params()->send_dmrs_sync);
-
-      ru.rf_map.card=0;
-      ru.rf_map.chain=CC_id+(get_softmodem_params()->chain_offset);
-      init_RU_proc(&ru);
-
+                get_softmodem_params()->rf_config_file,
+                get_softmodem_params()->send_dmrs_sync);
+    ru.rf_map.card=0;
+    ru.rf_map.chain=CC_id+(get_softmodem_params()->chain_offset);
+    init_RU_proc(&ru);
     config_sync_var=0;
 
     if (NFAPI_MODE==NFAPI_MODE_PNF) { // PNF
@@ -1365,7 +1363,6 @@ int main ( int argc, char **argv ) {
     pthread_cond_destroy(&nfapi_sync_cond);
     pthread_mutex_destroy(&nfapi_sync_mutex);
     pthread_mutex_destroy(&ue_pf_po_mutex);
-
   }
 
   terminate_opt();
diff --git a/executables/nr-gnb.c b/executables/nr-gnb.c
index dc8960846fb6886243bd5b72b489c1be28077eeb..4fe8cfa1bfd310c21c35e70be1651516ef591d12 100644
--- a/executables/nr-gnb.c
+++ b/executables/nr-gnb.c
@@ -240,7 +240,6 @@ void rx_func(void *param) {
   // RX processing
   int tx_slot_type         = nr_slot_select(cfg,frame_tx,slot_tx);
   int rx_slot_type         = nr_slot_select(cfg,frame_rx,slot_rx);
-
   if (rx_slot_type == NR_UPLINK_SLOT || rx_slot_type == NR_MIXED_SLOT) {
     // UE-specific RX processing for subframe n
     // TODO: check if this is correct for PARALLEL_RU_L1_TRX_SPLIT
@@ -451,7 +450,9 @@ void init_gNB_Tpool(int inst) {
   msgData->next_slot = get_next_downlink_slot(gNB, &gNB->gNB_config, 0, first_tx_slot-1);
   pushNotifiedFIFO(gNB->resp_RU_tx,msgRUTx); // to unblock the process in the beginning
 
-  threadCreate(&proc->L1_stats_thread,nrL1_stats_thread,(void*)gNB,"L1_stats",-1,OAI_PRIORITY_RT_LOW);
+  if (!get_softmodem_params()->emulate_l1) {
+    threadCreate(&proc->L1_stats_thread,nrL1_stats_thread,(void*)gNB,"L1_stats",-1,OAI_PRIORITY_RT_LOW);
+  }
 
 }
 
diff --git a/executables/nr-ru.c b/executables/nr-ru.c
index 3a2589632bde85268a9c5a5f76eb2604cb7f26e8..a2539a3adfaba2b4b487d312bee4a3d48d54a63c 100644
--- a/executables/nr-ru.c
+++ b/executables/nr-ru.c
@@ -80,7 +80,8 @@ static int DEFBFW[] = {0x00007fff};
 
 extern volatile int oai_exit;
 
-
+extern struct timespec timespec_sub(struct timespec lhs, struct timespec rhs);
+extern struct timespec timespec_add(struct timespec lhs, struct timespec rhs);
 extern void  nr_phy_free_RU(RU_t *);
 extern void  nr_phy_config_request(NR_PHY_Config_t *gNB);
 #include "executables/thread-common.h"
@@ -1323,9 +1324,35 @@ void *ru_thread( void *param ) {
   }
 
   // This is a forever while loop, it loops over subframes which are scheduled by incoming samples from HW devices
+  struct timespec slot_start;
+	clock_gettime(CLOCK_MONOTONIC, &slot_start);
+  
+  struct timespec slot_duration; 
+	slot_duration.tv_sec = 0;
+	//slot_duration.tv_nsec = 0.5e6;
+	slot_duration.tv_nsec = 0.5e6;
+
+  
+
   while (!oai_exit) {
     // these are local subframe/frame counters to check that we are in synch with the fronthaul timing.
     // They are set on the first rx/tx in the underly FH routines.
+    slot_start = timespec_add(slot_start,slot_duration);
+    struct timespec curr_time;
+    clock_gettime(CLOCK_MONOTONIC, &curr_time);
+
+    struct timespec sleep_time;
+
+    if((slot_start.tv_sec > curr_time.tv_sec) || (slot_start.tv_sec == curr_time.tv_sec && slot_start.tv_nsec > curr_time.tv_nsec)){
+      sleep_time = timespec_sub(slot_start,curr_time);
+      
+      usleep(sleep_time.tv_nsec * 1e-3); 
+    }
+    else{//continue
+    }
+
+   // clock_gettime(CLOCK_MONOTONIC, &curr_time);
+    //printf("sfn:%d, slot:%d, start time %d.%d slot start %d.%d \n",frame,slot,curr_time.tv_sec,curr_time.tv_nsec,slot_start.tv_sec,slot_start.tv_nsec);
     if (slot==(fp->slots_per_frame-1)) {
       slot=0;
       frame++;
diff --git a/executables/nr-softmodem.c b/executables/nr-softmodem.c
index 12728434ad9980627a62074aa68a690d0647a390..65af4f571c66588f223b92531201cecfe8302af3 100644
--- a/executables/nr-softmodem.c
+++ b/executables/nr-softmodem.c
@@ -317,48 +317,36 @@ int create_gNB_tasks(uint32_t gnb_nb) {
     }
   }
 
-  paramdef_t NETParams[]  =  GNBNETPARAMS_DESC;
-  char aprefix[MAX_OPTNAME_SIZE*2 + 8];
-  sprintf(aprefix,"%s.[%i].%s",GNB_CONFIG_STRING_GNB_LIST,0,GNB_CONFIG_STRING_NETWORK_INTERFACES_CONFIG);
-  config_get( NETParams,sizeof(NETParams)/sizeof(paramdef_t),aprefix);
-
-  for(int i = GNB_INTERFACE_NAME_FOR_NG_AMF_IDX; i <= GNB_IPV4_ADDRESS_FOR_NG_AMF_IDX; i++) {
-    if( NETParams[i].strptr == NULL) {
-      LOG_E(NGAP, "No configuration in the file.\n");
-      NGAP_CONF_MODE = 0;
-    } else {
-      LOG_D(NGAP, "Configuration in the file: %s.\n",*NETParams[i].strptr);
+  if (AMF_MODE_ENABLED) {
+
+   char*             gnb_ipv4_address_for_NGU      = NULL;
+   uint32_t          gnb_port_for_NGU              = 0;
+   char*             gnb_ipv4_address_for_S1U      = NULL;
+   uint32_t          gnb_port_for_S1U              = 0;
+    paramdef_t NETParams[]  =  GNBNETPARAMS_DESC;
+    char aprefix[MAX_OPTNAME_SIZE*2 + 8];
+    sprintf(aprefix,"%s.[%i].%s",GNB_CONFIG_STRING_GNB_LIST,0,GNB_CONFIG_STRING_NETWORK_INTERFACES_CONFIG);
+    config_get( NETParams,sizeof(NETParams)/sizeof(paramdef_t),aprefix);
+    
+    for(int i = GNB_INTERFACE_NAME_FOR_NG_AMF_IDX; i <= GNB_IPV4_ADDRESS_FOR_NG_AMF_IDX; i++) {
+      if( NETParams[i].strptr == NULL) {
+	LOG_E(NGAP, "No configuration in the file.\n");
+	NGAP_CONF_MODE = 0;
+      } else {
+	LOG_D(NGAP, "Configuration in the file: %s.\n",*NETParams[i].strptr);
+      }
     }
-  }
 
-  if (AMF_MODE_ENABLED) {
     if (gnb_nb > 0) {
-      /*
-      if (itti_create_task (TASK_SCTP, sctp_eNB_task, NULL) < 0) {
-        LOG_E(SCTP, "Create task for SCTP failed\n");
-        return -1;
-      }
-      */
       if(NGAP_CONF_MODE) {
         if (itti_create_task (TASK_NGAP, ngap_gNB_task, NULL) < 0) {
           LOG_E(NGAP, "Create task for NGAP failed\n");
           return -1;
         }
       } else {
-        LOG_E(NGAP, "Ngap task not created\n");
-      }
-
-      if(!emulate_rf) {
-        if (itti_create_task (TASK_UDP, udp_eNB_task, NULL) < 0) {
-          LOG_E(UDP_, "Create task for UDP failed\n");
-          return -1;
-        }
+        LOG_I(NGAP, "Ngap task not created\n");
       }
 
-      /*if (itti_create_task (TASK_GTPV1_U, &nr_gtpv1u_gNB_task, NULL) < 0) {
-        LOG_E(GTPU, "Create task for GTPV1U failed\n");
-        return -1;
-      }*/
     }
   }
 
@@ -601,8 +589,33 @@ static  void wait_nfapi_init(char *thread_name) {
 }
 
 void init_pdcp(void) {
-  if (!NODE_IS_DU(RC.nrrrc[0]->node_type)) {
-    // pdcp_layer_init();
+  if (!get_softmodem_params()->nsa) {
+    if (!NODE_IS_DU(RC.nrrrc[0]->node_type)) {
+      //pdcp_layer_init();
+      uint32_t pdcp_initmask = (IS_SOFTMODEM_NOS1) ?
+                              (PDCP_USE_NETLINK_BIT | LINK_ENB_PDCP_TO_IP_DRIVER_BIT) : LINK_ENB_PDCP_TO_GTPV1U_BIT;
+
+      if (IS_SOFTMODEM_NOS1) {
+        printf("IS_SOFTMODEM_NOS1 option enabled \n");
+        pdcp_initmask = pdcp_initmask | ENB_NAS_USE_TUN_BIT | SOFTMODEM_NOKRNMOD_BIT;
+      }
+
+      nr_pdcp_module_init(pdcp_initmask, 0);
+
+      if (NODE_IS_CU(RC.nrrrc[0]->node_type)) {
+        LOG_I(PDCP, "node is CU, pdcp send rlc_data_req by proto_agent \n");
+        pdcp_set_rlc_data_req_func((send_rlc_data_req_func_t)proto_agent_send_rlc_data_req);
+      } else {
+        LOG_I(PDCP, "node is gNB \n");
+        pdcp_set_rlc_data_req_func((send_rlc_data_req_func_t) rlc_data_req);
+        pdcp_set_pdcp_data_ind_func((pdcp_data_ind_func_t) pdcp_data_ind);
+      }
+    } else {
+      LOG_I(PDCP, "node is DU, rlc send pdcp_data_ind by proto_agent \n");
+      pdcp_set_pdcp_data_ind_func((pdcp_data_ind_func_t) proto_agent_send_pdcp_data_ind);
+    }
+  } else {
+    pdcp_layer_init();
     uint32_t pdcp_initmask = (IS_SOFTMODEM_NOS1) ?
                              (PDCP_USE_NETLINK_BIT | LINK_ENB_PDCP_TO_IP_DRIVER_BIT) : LINK_ENB_PDCP_TO_GTPV1U_BIT;
 
@@ -611,19 +624,9 @@ void init_pdcp(void) {
       pdcp_initmask = pdcp_initmask | ENB_NAS_USE_TUN_BIT | SOFTMODEM_NOKRNMOD_BIT;
     }
 
-    pdcp_module_init(pdcp_initmask);
-
-    if (NODE_IS_CU(RC.nrrrc[0]->node_type)) {
-      LOG_I(PDCP, "node is CU, pdcp send rlc_data_req by proto_agent \n");
-      pdcp_set_rlc_data_req_func((send_rlc_data_req_func_t)proto_agent_send_rlc_data_req);
-    } else {
-      LOG_I(PDCP, "node is gNB \n");
-      pdcp_set_rlc_data_req_func((send_rlc_data_req_func_t) rlc_data_req);
-      pdcp_set_pdcp_data_ind_func((pdcp_data_ind_func_t) pdcp_data_ind);
-    }
-  } else {
-    LOG_I(PDCP, "node is DU, rlc send pdcp_data_ind by proto_agent \n");
-    pdcp_set_pdcp_data_ind_func((pdcp_data_ind_func_t) proto_agent_send_pdcp_data_ind);
+    nr_pdcp_module_init(pdcp_initmask, 0);
+    pdcp_set_rlc_data_req_func((send_rlc_data_req_func_t) rlc_data_req);
+    pdcp_set_pdcp_data_ind_func((pdcp_data_ind_func_t) pdcp_data_ind);
   }
 }
 
@@ -650,6 +653,8 @@ int main( int argc, char **argv ) {
   printf("Reading in command-line options\n");
   get_options ();
 
+  EPC_MODE_ENABLED = !IS_SOFTMODEM_NOS1;
+
   if (CONFIG_ISFLAGSET(CONFIG_ABORT) ) {
     fprintf(stderr,"Getting configuration failed\n");
     exit(-1);
@@ -681,10 +686,12 @@ int main( int argc, char **argv ) {
   // initialize mscgen log after ITTI
   MSC_INIT(MSC_E_UTRAN, ADDED_QUEUES_MAX+TASK_MAX);
   init_opt();
-  if(PDCP_USE_NETLINK)
-    if(!IS_SOFTMODEM_NOS1)
-      netlink_init();
-  
+  if(PDCP_USE_NETLINK && !IS_SOFTMODEM_NOS1) {
+    netlink_init();
+    if (get_softmodem_params()->nsa) {
+      init_pdcp();
+    }
+  }
 #ifndef PACKAGE_VERSION
 #  define PACKAGE_VERSION "UNKNOWN-EXPERIMENTAL"
 #endif
@@ -694,7 +701,8 @@ int main( int argc, char **argv ) {
     RCconfig_NR_L1();
 
   // don't create if node doesn't connect to RRC/S1/GTP
-  AssertFatal(create_gNB_tasks(1) == 0,"cannot create ITTI tasks\n");
+  int ret=create_gNB_tasks(1);
+  AssertFatal(ret==0,"cannot create ITTI tasks\n");
 
   /* Start the agent. If it is turned off in the configuration, it won't start */
   /*
@@ -808,7 +816,9 @@ int main( int argc, char **argv ) {
   }
 
   printf("About to call end_configmodule() from %s() %s:%d\n", __FUNCTION__, __FILE__, __LINE__);
+
   // We have to set PARAMFLAG_NOFREE on right paramters before re-enabling end_configmodule()
+
   //end_configmodule();
   printf("Called end_configmodule() from %s() %s:%d\n", __FUNCTION__, __FILE__, __LINE__);
   // wait for end of program
diff --git a/executables/nr-ue.c b/executables/nr-ue.c
index 23846b70fc530df7672214839109d13551ccbe6e..1ab609e72b61e73436903b34ed141e97d9545194 100644
--- a/executables/nr-ue.c
+++ b/executables/nr-ue.c
@@ -29,7 +29,9 @@
 #include "SCHED_NR_UE/defs.h"
 #include "PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h"
 #include "executables/softmodem-common.h"
+#include "LAYER2/nr_pdcp/nr_pdcp_entity.h"
 #include "SCHED_NR_UE/pucch_uci_ue_nr.h"
+#include "openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.h"
 
 /*
  *  NR SLOT PROCESSING SEQUENCE
@@ -98,6 +100,10 @@ typedef enum {
   si = 2
 } sync_mode_t;
 
+queue_t nr_rach_ind_queue;
+
+static void *NRUE_phy_stub_standalone_pnf_task(void *arg);
+
 void init_nr_ue_vars(PHY_VARS_NR_UE *ue,
                      uint8_t UE_id,
                      uint8_t abstraction_flag)
@@ -126,6 +132,382 @@ void init_nr_ue_vars(PHY_VARS_NR_UE *ue,
   init_N_TA_offset(ue);
 }
 
+void init_nrUE_standalone_thread(int ue_idx)
+{
+  int standalone_tx_port = 3611 + ue_idx * 2;
+  int standalone_rx_port = 3612 + ue_idx * 2;
+  nrue_init_standalone_socket(standalone_tx_port, standalone_rx_port);
+
+  NR_UE_MAC_INST_t *mac = get_mac_inst(0);
+  pthread_mutex_init(&mac->mutex_dl_info, NULL);
+
+  pthread_t thread;
+  if (pthread_create(&thread, NULL, nrue_standalone_pnf_task, NULL) != 0) {
+    LOG_E(NR_MAC, "pthread_create failed for calling nrue_standalone_pnf_task");
+  }
+  pthread_setname_np(thread, "oai:nrue-stand");
+  pthread_t phy_thread;
+  if (pthread_create(&phy_thread, NULL, NRUE_phy_stub_standalone_pnf_task, NULL) != 0) {
+    LOG_E(NR_MAC, "pthread_create failed for calling NRUE_phy_stub_standalone_pnf_task");
+  }
+  pthread_setname_np(phy_thread, "oai:nrue-stand-phy");
+}
+
+static void L1_nsa_prach_procedures(frame_t frame, int slot, fapi_nr_ul_config_prach_pdu *prach_pdu)
+{
+  NR_UE_MAC_INST_t *mac    = get_mac_inst(0);
+  nfapi_nr_rach_indication_t *rach_ind = CALLOC(1, sizeof(*rach_ind));
+  rach_ind->sfn = frame;
+  rach_ind->slot = slot;
+  rach_ind->header.message_id = NFAPI_NR_PHY_MSG_TYPE_RACH_INDICATION;
+
+  uint8_t pdu_index = 0;
+  rach_ind->pdu_list = CALLOC(1, sizeof(*rach_ind->pdu_list));
+  rach_ind->number_of_pdus  = 1;
+  rach_ind->pdu_list[pdu_index].phy_cell_id                         = prach_pdu->phys_cell_id;
+  rach_ind->pdu_list[pdu_index].symbol_index                        = prach_pdu->prach_start_symbol;
+  rach_ind->pdu_list[pdu_index].slot_index                          = prach_pdu->prach_slot;
+  rach_ind->pdu_list[pdu_index].freq_index                          = prach_pdu->num_ra;
+  rach_ind->pdu_list[pdu_index].avg_rssi                            = 128;
+  rach_ind->pdu_list[pdu_index].avg_snr                             = 0xff; // invalid for now
+
+  rach_ind->pdu_list[pdu_index].num_preamble                        = 1;
+  const int num_p = rach_ind->pdu_list[pdu_index].num_preamble;
+  rach_ind->pdu_list[pdu_index].preamble_list = calloc(num_p, sizeof(nfapi_nr_prach_indication_preamble_t));
+  uint8_t preamble_index = get_softmodem_params()->nsa ?
+                           mac->ra.rach_ConfigDedicated->cfra->resources.choice.ssb->ssb_ResourceList.list.array[0]->ra_PreambleIndex :
+                           mac->ra.ra_PreambleIndex;
+  rach_ind->pdu_list[pdu_index].preamble_list[0].preamble_index     = preamble_index;
+
+  rach_ind->pdu_list[pdu_index].preamble_list[0].timing_advance     = 0;
+  rach_ind->pdu_list[pdu_index].preamble_list[0].preamble_pwr       = 0xffffffff;
+
+  if (!put_queue(&nr_rach_ind_queue, rach_ind))
+  {
+    for (int pdu_index = 0; pdu_index < rach_ind->number_of_pdus; pdu_index++)
+    {
+      free(rach_ind->pdu_list[pdu_index].preamble_list);
+    }
+    free(rach_ind->pdu_list);
+    free(rach_ind);
+  }
+  LOG_D(NR_MAC, "We have successfully filled the rach_ind queue with the recently filled rach ind\n");
+}
+
+static bool sfn_slot_matcher(void *wanted, void *candidate)
+{
+  nfapi_p7_message_header_t *msg = candidate;
+  int sfn_sf = *(int*)wanted;
+
+  switch (msg->message_id)
+  {
+    case NFAPI_NR_PHY_MSG_TYPE_RACH_INDICATION:
+    {
+      nfapi_nr_rach_indication_t *ind = candidate;
+      return NFAPI_SFNSLOT2SFN(sfn_sf) == ind->sfn && NFAPI_SFNSLOT2SLOT(sfn_sf) == ind->slot;
+    }
+
+    case NFAPI_NR_PHY_MSG_TYPE_RX_DATA_INDICATION:
+    {
+      nfapi_nr_rx_data_indication_t *ind = candidate;
+      return NFAPI_SFNSLOT2SFN(sfn_sf) == ind->sfn && NFAPI_SFNSLOT2SLOT(sfn_sf) == ind->slot;
+    }
+
+    case NFAPI_NR_PHY_MSG_TYPE_CRC_INDICATION:
+    {
+      nfapi_nr_crc_indication_t *ind = candidate;
+      return NFAPI_SFNSLOT2SFN(sfn_sf) == ind->sfn && NFAPI_SFNSLOT2SLOT(sfn_sf) == ind->slot;
+    }
+
+    case NFAPI_NR_PHY_MSG_TYPE_UCI_INDICATION:
+    {
+      nfapi_nr_uci_indication_t *ind = candidate;
+      return NFAPI_SFNSLOT2SFN(sfn_sf) == ind->sfn && NFAPI_SFNSLOT2SLOT(sfn_sf) == ind->slot;
+    }
+
+    case NFAPI_NR_PHY_MSG_TYPE_DL_TTI_REQUEST:
+    {
+      nfapi_nr_dl_tti_request_t *ind = candidate;
+      return NFAPI_SFNSLOT2SFN(sfn_sf) == ind->SFN && NFAPI_SFNSLOT2SLOT(sfn_sf) == ind->Slot;
+    }
+
+    case NFAPI_NR_PHY_MSG_TYPE_TX_DATA_REQUEST:
+    {
+      nfapi_nr_tx_data_request_t *ind = candidate;
+      return NFAPI_SFNSLOT2SFN(sfn_sf) == ind->SFN && NFAPI_SFNSLOT2SLOT(sfn_sf) == ind->Slot;
+    }
+
+    case NFAPI_NR_PHY_MSG_TYPE_UL_DCI_REQUEST:
+    {
+      nfapi_nr_ul_dci_request_t *ind = candidate;
+      return NFAPI_SFNSLOT2SFN(sfn_sf) == ind->SFN && NFAPI_SFNSLOT2SLOT(sfn_sf) == ind->Slot;
+    }
+
+    case NFAPI_NR_PHY_MSG_TYPE_UL_TTI_REQUEST:
+    {
+      nfapi_nr_ul_tti_request_t *ind = candidate;
+      return NFAPI_SFNSLOT2SFN(sfn_sf) == ind->SFN && NFAPI_SFNSLOT2SLOT(sfn_sf) == ind->Slot;
+    }
+
+    default:
+      LOG_E(NR_MAC, "sfn_slot_match bad ID: %d\n", msg->message_id);
+
+  }
+
+  return false;
+}
+
+static void process_queued_nr_nfapi_msgs(NR_UE_MAC_INST_t *mac, int sfn_slot)
+{
+  nfapi_nr_rach_indication_t *rach_ind = unqueue_matching(&nr_rach_ind_queue, MAX_QUEUE_SIZE, sfn_slot_matcher, &sfn_slot);
+  nfapi_nr_rx_data_indication_t *rx_ind = unqueue_matching(&nr_rx_ind_queue, MAX_QUEUE_SIZE, sfn_slot_matcher, &sfn_slot);
+  nfapi_nr_crc_indication_t *crc_ind = unqueue_matching(&nr_crc_ind_queue, MAX_QUEUE_SIZE, sfn_slot_matcher, &sfn_slot);
+  nfapi_nr_dl_tti_request_t *dl_tti_request = get_queue(&nr_dl_tti_req_queue);
+  nfapi_nr_ul_dci_request_t *ul_dci_request = get_queue(&nr_ul_dci_req_queue);
+
+  LOG_D(NR_MAC, "Try to get a ul_tti_req for sfn/slot %d %d from queue with %lu items\n",
+        NFAPI_SFNSLOT2SFN(mac->nr_ue_emul_l1.active_harq_sfn_slot),NFAPI_SFNSLOT2SLOT(mac->nr_ue_emul_l1.active_harq_sfn_slot), nr_ul_tti_req_queue.num_items);
+  nfapi_nr_ul_tti_request_t *ul_tti_request = unqueue_matching(&nr_ul_tti_req_queue, MAX_QUEUE_SIZE, sfn_slot_matcher, &mac->nr_ue_emul_l1.active_harq_sfn_slot);
+  if (!ul_tti_request)
+  {
+      LOG_D(NR_MAC, "Try to get a ul_tti_req from seprate queue because dl_tti_req was late\n");
+      ul_tti_request = unqueue_matching(&nr_wait_ul_tti_req_queue, MAX_QUEUE_SIZE, sfn_slot_matcher, &mac->nr_ue_emul_l1.active_harq_sfn_slot);
+  }
+
+  if (rach_ind && rach_ind->number_of_pdus > 0)
+  {
+      NR_UL_IND_t UL_INFO = {
+        .rach_ind = *rach_ind,
+      };
+      send_nsa_standalone_msg(&UL_INFO, rach_ind->header.message_id);
+      for (int i = 0; i < rach_ind->number_of_pdus; i++)
+      {
+        free(rach_ind->pdu_list[i].preamble_list);
+      }
+      free(rach_ind->pdu_list);
+      free(rach_ind);
+      nr_Msg1_transmitted(0, 0, NFAPI_SFNSLOT2SFN(sfn_slot), 0);
+  }
+  if (crc_ind && crc_ind->number_crcs > 0)
+  {
+    NR_UL_IND_t UL_INFO = {
+      .crc_ind = *crc_ind,
+    };
+    send_nsa_standalone_msg(&UL_INFO, crc_ind->header.message_id);
+    free(crc_ind->crc_list);
+    free(crc_ind);
+  }
+  if (rx_ind && rx_ind->number_of_pdus > 0)
+  {
+    NR_UL_IND_t UL_INFO = {
+      .rx_ind = *rx_ind,
+    };
+    send_nsa_standalone_msg(&UL_INFO, rx_ind->header.message_id);
+    free(rx_ind->pdu_list);
+    free(rx_ind);
+  }
+  if (dl_tti_request)
+  {
+    int dl_tti_sfn_slot = NFAPI_SFNSLOT2HEX(dl_tti_request->SFN, dl_tti_request->Slot);
+    nfapi_nr_tx_data_request_t *tx_data_request = unqueue_matching(&nr_tx_req_queue, MAX_QUEUE_SIZE, sfn_slot_matcher, &dl_tti_sfn_slot);
+    if (!tx_data_request)
+    {
+      LOG_E(NR_MAC, "[%d %d] No corresponding tx_data_request for given dl_tti_request sfn/slot\n",
+            NFAPI_SFNSLOT2SFN(dl_tti_sfn_slot), NFAPI_SFNSLOT2SLOT(dl_tti_sfn_slot));
+      if (get_softmodem_params()->nsa)
+        save_nr_measurement_info(dl_tti_request);
+      free(dl_tti_request);
+      dl_tti_request = NULL;
+    }
+    else if (dl_tti_request->dl_tti_request_body.nPDUs > 0 && tx_data_request->Number_of_PDUs > 0)
+    {
+      if (get_softmodem_params()->nsa)
+        save_nr_measurement_info(dl_tti_request);
+      check_and_process_dci(dl_tti_request, tx_data_request, NULL, NULL);
+    }
+    else
+    {
+      AssertFatal(false, "We dont have PDUs in either dl_tti %d or tx_req %d\n",
+                  dl_tti_request->dl_tti_request_body.nPDUs, tx_data_request->Number_of_PDUs);
+    }
+  }
+  if (ul_dci_request && ul_dci_request->numPdus > 0)
+  {
+    check_and_process_dci(NULL, NULL, ul_dci_request, NULL);
+  }
+  if (ul_tti_request && ul_tti_request->n_pdus > 0)
+  {
+    check_and_process_dci(NULL, NULL, NULL, ul_tti_request);
+  }
+}
+
+static void check_nr_prach(NR_UE_MAC_INST_t *mac, nr_uplink_indication_t *ul_info, NR_PRACH_RESOURCES_t *prach_resources)
+{
+  fapi_nr_ul_config_request_t *ul_config = get_ul_config_request(mac, ul_info->slot_tx);
+  if (!ul_config)
+  {
+    LOG_E(NR_MAC, "mac->ul_config is null! \n");
+    return;
+  }
+  if (mac->ra.ra_state != RA_SUCCEEDED)
+  {
+    AssertFatal(ul_config->number_pdus < sizeof(ul_config->ul_config_list) / sizeof(ul_config->ul_config_list[0]),
+                "Number of PDUS in ul_config = %d > ul_config_list num elements", ul_config->number_pdus);
+    fapi_nr_ul_config_prach_pdu *prach_pdu = &ul_config->ul_config_list[ul_config->number_pdus].prach_config_pdu;
+    uint8_t nr_prach = nr_ue_get_rach(prach_resources,
+                                      prach_pdu,
+                                      ul_info->module_id,
+                                      ul_info->cc_id,
+                                      ul_info->frame_tx,
+                                      ul_info->gNB_index,
+                                      ul_info->slot_tx);
+    if (nr_prach == 1)
+    {
+      L1_nsa_prach_procedures(ul_info->frame_tx, ul_info->slot_tx, prach_pdu);
+      ul_config->number_pdus = 0;
+      ul_info->ue_sched_mode = SCHED_ALL;
+    }
+    else if (nr_prach == 2)
+    {
+      LOG_I(NR_PHY, "In %s: [UE %d] RA completed, setting UE mode to PUSCH\n", __FUNCTION__, ul_info->module_id);
+    }
+    else if(nr_prach == 3)
+    {
+      LOG_I(NR_PHY, "In %s: [UE %d] RA failed, setting UE mode to PRACH\n", __FUNCTION__, ul_info->module_id);
+    }
+  }
+}
+
+static void *NRUE_phy_stub_standalone_pnf_task(void *arg)
+{
+  LOG_I(MAC, "Clearing Queues\n");
+  reset_queue(&nr_rach_ind_queue);
+  reset_queue(&nr_rx_ind_queue);
+  reset_queue(&nr_crc_ind_queue);
+  reset_queue(&nr_uci_ind_queue);
+  reset_queue(&nr_dl_tti_req_queue);
+  reset_queue(&nr_tx_req_queue);
+  reset_queue(&nr_ul_dci_req_queue);
+  reset_queue(&nr_ul_tti_req_queue);
+  reset_queue(&nr_wait_ul_tti_req_queue);
+
+  NR_PRACH_RESOURCES_t prach_resources;
+  memset(&prach_resources, 0, sizeof(prach_resources));
+  NR_UL_TIME_ALIGNMENT_t ul_time_alignment;
+  memset(&ul_time_alignment, 0, sizeof(ul_time_alignment));
+  int last_sfn_slot = -1;
+  uint16_t sfn_slot = 0;
+
+  while (!oai_exit)
+  {
+    if (sem_wait(&sfn_slot_semaphore) != 0)
+    {
+      LOG_E(NR_MAC, "sem_wait() error\n");
+      abort();
+    }
+    uint16_t *slot_ind = get_queue(&nr_sfn_slot_queue);
+    nr_phy_channel_params_t *ch_info = get_queue(&nr_chan_param_queue);
+    if (!slot_ind && !ch_info)
+    {
+      LOG_D(MAC, "get nr_sfn_slot_queue and nr_chan_param_queue == NULL!\n");
+      continue;
+    }
+    if (slot_ind) {
+      sfn_slot = *slot_ind;
+    }
+    else if (ch_info) {
+      sfn_slot = ch_info->sfn_slot;
+    }
+
+    frame_t frame = NFAPI_SFNSLOT2SFN(sfn_slot);
+    int slot = NFAPI_SFNSLOT2SLOT(sfn_slot);
+    if (sfn_slot == last_sfn_slot)
+    {
+      LOG_D(NR_MAC, "repeated sfn_sf = %d.%d\n",
+            frame, slot);
+      continue;
+    }
+    last_sfn_slot = sfn_slot;
+
+    LOG_D(NR_MAC, "The received sfn/slot [%d %d] from proxy\n",
+          frame, slot);
+
+    module_id_t mod_id = 0;
+    NR_UE_MAC_INST_t *mac = get_mac_inst(mod_id);
+    if (get_softmodem_params()->sa && mac->mib == NULL)
+    {
+      LOG_D(NR_MAC, "We haven't gotten MIB. Lets see if we received it\n");
+      nr_ue_dl_indication(&mac->dl_info, &ul_time_alignment);
+      process_queued_nr_nfapi_msgs(mac, sfn_slot);
+    }
+    if (mac->scc == NULL && mac->scc_SIB == NULL)
+    {
+      LOG_D(MAC, "[NSA] mac->scc == NULL and [SA] mac->scc_SIB == NULL!\n");
+      continue;
+    }
+
+    mac->ra.generate_nr_prach = 0;
+    int CC_id = 0;
+    uint8_t gNB_id = 0;
+    nr_uplink_indication_t ul_info;
+    int slots_per_frame = 20; //30 kHZ subcarrier spacing
+    int slot_ahead = 2; // TODO: Make this dynamic
+    ul_info.cc_id = CC_id;
+    ul_info.gNB_index = gNB_id;
+    ul_info.module_id = mod_id;
+    ul_info.frame_rx = frame;
+    ul_info.slot_rx = slot;
+    ul_info.slot_tx = (slot + slot_ahead) % slots_per_frame;
+    ul_info.frame_tx = (ul_info.slot_rx + slot_ahead >= slots_per_frame) ? ul_info.frame_rx + 1 : ul_info.frame_rx;
+    ul_info.ue_sched_mode = SCHED_ALL;
+
+    if (pthread_mutex_lock(&mac->mutex_dl_info)) abort();
+
+    memset(&mac->dl_info, 0, sizeof(mac->dl_info));
+    mac->dl_info.cc_id = CC_id;
+    mac->dl_info.gNB_index = gNB_id;
+    mac->dl_info.module_id = mod_id;
+    mac->dl_info.frame = frame;
+    mac->dl_info.slot = slot;
+    mac->dl_info.thread_id = 0;
+    mac->dl_info.dci_ind = NULL;
+    mac->dl_info.rx_ind = NULL;
+
+    if (is_nr_DL_slot(get_softmodem_params()->nsa ?
+                      mac->scc->tdd_UL_DL_ConfigurationCommon :
+                      mac->scc_SIB->tdd_UL_DL_ConfigurationCommon,
+                      ul_info.slot_rx))
+    {
+      nr_ue_dl_indication(&mac->dl_info, &ul_time_alignment);
+    }
+
+    if (pthread_mutex_unlock(&mac->mutex_dl_info)) abort();
+
+    if (is_nr_UL_slot(get_softmodem_params()->nsa ?
+                      mac->scc->tdd_UL_DL_ConfigurationCommon :
+                      mac->scc_SIB->tdd_UL_DL_ConfigurationCommon,
+                      ul_info.slot_tx, mac->frame_type))
+    {
+      LOG_D(NR_MAC, "Slot %d. calling nr_ue_ul_ind() from %s\n", ul_info.slot_tx, __FUNCTION__);
+      nr_ue_ul_indication(&ul_info);
+      check_nr_prach(mac, &ul_info, &prach_resources);
+    }
+    if (!IS_SOFTMODEM_NOS1 && get_softmodem_params()->sa) {
+      NR_UE_MAC_INST_t *mac = get_mac_inst(0);
+      protocol_ctxt_t ctxt;
+      PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, 0, ENB_FLAG_NO, mac->crnti, frame, slot, 0);
+      pdcp_run(&ctxt);
+    }
+    process_queued_nr_nfapi_msgs(mac, sfn_slot);
+    free(slot_ind);
+    slot_ind = NULL;
+    free(ch_info);
+    ch_info = NULL;
+  }
+  return NULL;
+}
+
+
 /*!
  * It performs band scanning and synchonization.
  * \param arg is a pointer to a \ref PHY_VARS_NR_UE structure.
diff --git a/executables/nr-uesoftmodem.c b/executables/nr-uesoftmodem.c
index c63b553fce321bdc083e9018f29535ac797a5887..59f0b81a43803b8d8e7d6b0e81a97f26c629721d 100644
--- a/executables/nr-uesoftmodem.c
+++ b/executables/nr-uesoftmodem.c
@@ -99,7 +99,9 @@ pthread_mutex_t sync_mutex;
 int sync_var=-1; //!< protected by mutex \ref sync_mutex.
 int config_sync_var=-1;
 
-
+// not used in UE
+instance_t CUuniqInstance=0;
+instance_t DUuniqInstance=0;
 
 RAN_CONTEXT_t RC;
 volatile int             oai_exit = 0;
@@ -154,6 +156,7 @@ uint32_t       N_RB_DL    = 106;
  */
 uint8_t abstraction_flag=0;
 
+
 /*---------------------BMC: timespec helpers -----------------------------*/
 
 struct timespec min_diff_time = { .tv_sec = 0, .tv_nsec = 0 };
@@ -187,10 +190,17 @@ int create_tasks_nrue(uint32_t ue_nb) {
       LOG_E(NR_RRC, "Create task for RRC UE failed\n");
       return -1;
     }
-  if (itti_create_task (TASK_NAS_NRUE, nas_nrue_task, NULL) < 0) {
-    LOG_E(NR_RRC, "Create task for NAS UE failed\n");
-    return -1;
-  }
+    if (get_softmodem_params()->nsa) {
+      init_connections_with_lte_ue();
+      if (itti_create_task (TASK_RRC_NSA_NRUE, recv_msgs_from_lte_ue, NULL) < 0) {
+        LOG_E(NR_RRC, "Create task for RRC NSA nr-UE failed\n");
+        return -1;
+      }
+    }
+    if (itti_create_task (TASK_NAS_NRUE, nas_nrue_task, NULL) < 0) {
+      LOG_E(NR_RRC, "Create task for NAS UE failed\n");
+      return -1;
+    }
   }
 
   itti_wait_ready(0);
@@ -360,23 +370,21 @@ void init_openair0(void) {
   }
 }
 
-void init_pdcp(void) {
+static void init_pdcp(int ue_id) {
   uint32_t pdcp_initmask = (!IS_SOFTMODEM_NOS1) ? LINK_ENB_PDCP_TO_GTPV1U_BIT : (LINK_ENB_PDCP_TO_GTPV1U_BIT | PDCP_USE_NETLINK_BIT | LINK_ENB_PDCP_TO_IP_DRIVER_BIT);
 
   /*if (IS_SOFTMODEM_BASICSIM || IS_SOFTMODEM_RFSIM || (nfapi_getmode()==NFAPI_UE_STUB_PNF)) {
     pdcp_initmask = pdcp_initmask | UE_NAS_USE_TUN_BIT;
   }*/
 
-  if (IS_SOFTMODEM_NOKRNMOD)
+  if (IS_SOFTMODEM_NOKRNMOD) {
     pdcp_initmask = pdcp_initmask | UE_NAS_USE_TUN_BIT;
-
-  /*if (rlc_module_init() != 0) {
+  }
+  if (get_softmodem_params()->nsa && rlc_module_init(0) != 0) {
     LOG_I(RLC, "Problem at RLC initiation \n");
   }
   pdcp_layer_init();
-  nr_DRB_preconfiguration();*/
-  pdcp_layer_init();
-  pdcp_module_init(pdcp_initmask);
+  nr_pdcp_module_init(pdcp_initmask, ue_id);
   pdcp_set_rlc_data_req_func((send_rlc_data_req_func_t) rlc_data_req);
   pdcp_set_pdcp_data_ind_func((pdcp_data_ind_func_t) pdcp_data_ind);
 }
@@ -388,6 +396,13 @@ void *rrc_enb_process_msg(void *notUsed) {
 
 
 int main( int argc, char **argv ) {
+  set_priority(79);
+  if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1)
+  {
+    fprintf(stderr, "mlockall: %s\n", strerror(errno));
+    return EXIT_FAILURE;
+  }
+
   //uint8_t beta_ACK=0,beta_RI=0,beta_CQI=2;
   PHY_VARS_NR_UE *UE[MAX_NUM_CCs];
   start_background_system();
@@ -430,13 +445,27 @@ int main( int argc, char **argv ) {
   LOG_I(HW, "Version: %s\n", PACKAGE_VERSION);
 
   init_NR_UE(1,uecap_file,rrc_config_path);
-  if(IS_SOFTMODEM_NOS1 || get_softmodem_params()->sa)
-	  init_pdcp();
+
+  int mode_offset = get_softmodem_params()->nsa ? NUMBER_OF_UE_MAX : 1;
+  uint16_t node_number = get_softmodem_params()->node_number;
+  ue_id_g = (node_number == 0) ? 0 : node_number - 2;
+  AssertFatal(ue_id_g >= 0, "UE id is expected to be nonnegative.\n");
+  if(IS_SOFTMODEM_NOS1 || get_softmodem_params()->sa || get_softmodem_params()->nsa) {
+    if(node_number == 0) {
+      init_pdcp(0);
+    }
+    else {
+      init_pdcp(mode_offset + ue_id_g);
+    }
+  }
 
   NB_UE_INST=1;
   NB_INST=1;
   PHY_vars_UE_g = malloc(sizeof(PHY_VARS_NR_UE **));
   PHY_vars_UE_g[0] = malloc(sizeof(PHY_VARS_NR_UE *)*MAX_NUM_CCs);
+  if (get_softmodem_params()->emulate_l1) {
+    RCconfig_nr_ue_L1();
+  }
 
   if (get_softmodem_params()->do_ra)
     AssertFatal(get_softmodem_params()->phy_test == 0,"RA and phy_test are mutually exclusive\n");
@@ -444,54 +473,57 @@ int main( int argc, char **argv ) {
   if (get_softmodem_params()->sa)
     AssertFatal(get_softmodem_params()->phy_test == 0,"Standalone mode and phy_test are mutually exclusive\n");
 
-  for (int CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
-
-    PHY_vars_UE_g[0][CC_id] = (PHY_VARS_NR_UE *)malloc(sizeof(PHY_VARS_NR_UE));
-    UE[CC_id] = PHY_vars_UE_g[0][CC_id];
-    memset(UE[CC_id],0,sizeof(PHY_VARS_NR_UE));
-
-    set_options(CC_id, UE[CC_id]);
-    NR_UE_MAC_INST_t *mac = get_mac_inst(0);
-
-    if (get_softmodem_params()->sa) {
-      uint16_t nr_band = get_band(downlink_frequency[CC_id][0],uplink_frequency_offset[CC_id][0]);
-      mac->nr_band = nr_band;
-      nr_init_frame_parms_ue_sa(&UE[CC_id]->frame_parms,
-                                downlink_frequency[CC_id][0],
-                                uplink_frequency_offset[CC_id][0],
-                                get_softmodem_params()->numerology,
-                                nr_band);
+  if (!get_softmodem_params()->nsa && get_softmodem_params()->emulate_l1)
+    start_oai_nrue_threads();
+
+  if (!get_softmodem_params()->emulate_l1) {
+    for (int CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
+      PHY_vars_UE_g[0][CC_id] = (PHY_VARS_NR_UE *)malloc(sizeof(PHY_VARS_NR_UE));
+      UE[CC_id] = PHY_vars_UE_g[0][CC_id];
+      memset(UE[CC_id],0,sizeof(PHY_VARS_NR_UE));
+
+      set_options(CC_id, UE[CC_id]);
+      NR_UE_MAC_INST_t *mac = get_mac_inst(0);
+
+      if (get_softmodem_params()->sa) { // set frame config to initial values from command line and assume that the SSB is centered on the grid
+        uint16_t nr_band = get_band(downlink_frequency[CC_id][0],uplink_frequency_offset[CC_id][0]);
+        mac->nr_band = nr_band;
+        nr_init_frame_parms_ue_sa(&UE[CC_id]->frame_parms,
+                                  downlink_frequency[CC_id][0],
+                                  uplink_frequency_offset[CC_id][0],
+                                  get_softmodem_params()->numerology,
+                                  nr_band);
+      }
+      else{
+        if(mac->if_module != NULL && mac->if_module->phy_config_request != NULL)
+          mac->if_module->phy_config_request(&mac->phy_config);
+
+        fapi_nr_config_request_t *nrUE_config = &UE[CC_id]->nrUE_config;
+
+        nr_init_frame_parms_ue(&UE[CC_id]->frame_parms, nrUE_config,
+            *mac->scc->downlinkConfigCommon->frequencyInfoDL->frequencyBandList.list.array[0]);
+      }
+
+      init_symbol_rotation(&UE[CC_id]->frame_parms);
+      init_timeshift_rotation(&UE[CC_id]->frame_parms);
+      init_nr_ue_vars(UE[CC_id], 0, abstraction_flag);
     }
-    else{
-      if(mac->if_module != NULL && mac->if_module->phy_config_request != NULL)
-        mac->if_module->phy_config_request(&mac->phy_config);
 
-      fapi_nr_config_request_t *nrUE_config = &UE[CC_id]->nrUE_config;
+    init_openair0();
+    // 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)*NUMBER_OF_UE_MAX*MAX_NUM_CCs);
+    configure_linux();
+    mlockall(MCL_CURRENT | MCL_FUTURE);
 
-      nr_init_frame_parms_ue(&UE[CC_id]->frame_parms, nrUE_config, *mac->scc->downlinkConfigCommon->frequencyInfoDL->frequencyBandList.list.array[0]);
+    if(IS_SOFTMODEM_DOSCOPE) {
+      load_softscope("nr",PHY_vars_UE_g[0][0]);
     }
 
-    init_symbol_rotation(&UE[CC_id]->frame_parms);
-    init_timeshift_rotation(&UE[CC_id]->frame_parms);
-    init_nr_ue_vars(UE[CC_id], 0, abstraction_flag);
-
+    init_NR_UE_threads(1);
+    printf("UE threads created by %ld\n", gettid());
   }
 
-  init_openair0();
-  // 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)*NUMBER_OF_UE_MAX*MAX_NUM_CCs);
-  configure_linux();
-  mlockall(MCL_CURRENT | MCL_FUTURE);
- 
-  if(IS_SOFTMODEM_DOSCOPE) {
-    load_softscope("nr",PHY_vars_UE_g[0][0]);
-  }     
-
-  
-  init_NR_UE_threads(1);
-  printf("UE threads created by %ld\n", gettid());
-  
   // wait for end of program
   printf("TYPE <CTRL-C> TO TERMINATE\n");
 
diff --git a/executables/nr-uesoftmodem.h b/executables/nr-uesoftmodem.h
index 0cb7c072a035819affbfd5a76d7b88c685a84d7f..b1810a1f4fc71c41c9001643025bb5ddb3cf9b75 100644
--- a/executables/nr-uesoftmodem.h
+++ b/executables/nr-uesoftmodem.h
@@ -35,7 +35,8 @@
     {"nr-dlsch-demod-shift",     CONFIG_HLP_DLSHIFT,     0,               iptr:(int32_t *)&nr_dlsch_demod_shift,    defintval:0,     TYPE_INT,    0}, \
     {"V" ,                       CONFIG_HLP_VCD,         PARAMFLAG_BOOL,  iptr:&vcdflag,                      defintval:0,     TYPE_INT,    0}, \
     {"uecap_file",               CONFIG_HLP_UECAP_FILE,  0,               strptr:(char **)&uecap_file,        defstrval:"./",  TYPE_STRING, 0}, \
-    {"rrc_config_path",          CONFIG_HLP_RRC_CFG_PATH,0,               strptr:(char **)&rrc_config_path,   defstrval:"./",  TYPE_STRING, 0}  \
+    {"rrc_config_path",          CONFIG_HLP_RRC_CFG_PATH,0,               strptr:(char **)&rrc_config_path,   defstrval:"./",  TYPE_STRING, 0}, \
+    {"ue-idx-standalone",        NULL,                   0,               u16ptr:&ue_idx_standalone,          defuintval:0xFFFF,    TYPE_UINT16,   0} \
 }
 
 
@@ -89,7 +90,9 @@ extern void init_NR_UE(int, char*, char*);
 extern void init_NR_UE_threads(int);
 extern void reset_opp_meas(void);
 extern void print_opp_meas(void);
+extern void start_oai_nrue_threads(void);
 void *UE_thread(void *arg);
 void init_nr_ue_vars(PHY_VARS_NR_UE *ue, uint8_t UE_id, uint8_t abstraction_flag);
+void init_nrUE_standalone_thread(int ue_idx);
 
 #endif
diff --git a/executables/ocp-gnb.c b/executables/ocp-gnb.c
index 326f7d277f7df5c5ff20f09da30d174d63d8f605..7b4b1c6680eb1c9f8a6230b60d928b43f77447d2 100644
--- a/executables/ocp-gnb.c
+++ b/executables/ocp-gnb.c
@@ -328,9 +328,9 @@ static void init_pdcp(void) {
     pdcp_initmask = pdcp_initmask | ENB_NAS_USE_TUN_BIT | SOFTMODEM_NOKRNMOD_BIT  ;
   }
 
-  pdcp_module_init(pdcp_initmask);
-  pdcp_set_rlc_data_req_func((send_rlc_data_req_func_t) rlc_data_req);
-  pdcp_set_pdcp_data_ind_func((pdcp_data_ind_func_t) pdcp_data_ind);
+  nr_pdcp_module_init(pdcp_initmask, 0);
+  pdcp_set_rlc_data_req_func(rlc_data_req);
+  pdcp_set_pdcp_data_ind_func(pdcp_data_ind);
 }
 
 void init_main_gNB(void) {
diff --git a/executables/softmodem-common.c b/executables/softmodem-common.c
index e10515ea1acab5330d18e23a0ded937459d23965..3e20081b18ee32de4bdd2c8bdca47ca1eac4507e 100644
--- a/executables/softmodem-common.c
+++ b/executables/softmodem-common.c
@@ -180,15 +180,18 @@ void softmodem_printresources(int sig, telnet_printfunc_t pf) {
 }
 
 void signal_handler(int sig) {
-  void *array[10];
-  size_t size;
+  //void *array[10];
+  //size_t size;
 
   if (sig==SIGSEGV) {
     // get void*'s for all entries on the stack
+    /* backtrace uses malloc, that is not good in signal handlers
+     * I let the code, because it would be nice to make it better
     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 {
     if(sig==SIGINT ||sig==SOFTMODEM_RTSIGNAL)
@@ -208,10 +211,13 @@ void set_softmodem_sighandler(void) {
   memset(&act,0,sizeof(act));
   act.sa_handler=signal_handler;
   sigaction(SOFTMODEM_RTSIGNAL,&act,&oldact);
+  // Disabled in order generate a core dump for analysis with gdb
+  # if 0
   printf("Send signal %d to display resource usage...\n",SIGRTMIN+1);
   signal(SIGSEGV, signal_handler);
   signal(SIGINT,  signal_handler);
   signal(SIGTERM, signal_handler);
   signal(SIGABRT, signal_handler);
+  #endif
 }
 
diff --git a/executables/softmodem-common.h b/executables/softmodem-common.h
index 3a7022a502c6b2ecd7566ac66618aac57a072d58..9aca677473566301b97a45d51635496ac4a0407d 100644
--- a/executables/softmodem-common.h
+++ b/executables/softmodem-common.h
@@ -98,6 +98,7 @@ extern "C"
 #define CONFIG_HLP_DISABLNBIOT   "disable nb-iot, even if defined in config\n"
 #define CONFIG_HLP_USRP_THREAD   "having extra thead for usrp tx\n"
 #define CONFIG_HLP_NFAPI         "Change the nFAPI mode for NR\n"
+#define CONFIG_L1_EMULATOR       "Run in L1 emulated mode (disable PHY layer)\n"
 
 /*-----------------------------------------------------------------------------------------------------------------------------------------------------*/
 /*                                            command line parameters common to eNodeB and UE                                                          */
@@ -122,7 +123,10 @@ extern "C"
 #define USE_256QAM_TABLE    softmodem_params.use_256qam_table
 #define PRB_INTERPOLATION   softmodem_params.prb_interpolation
 #define NFAPI               softmodem_params.nfapi
+#define NSA                 softmodem_params.nsa
+#define NODE_NUMBER         softmodem_params.node_number
 #define NON_STOP            softmodem_params.non_stop
+#define EMULATE_L1          softmodem_params.emulate_l1
 
 #define DEFAULT_RFCONFIG_FILE    "/usr/local/etc/syriq/ue.band7.tm1.PRB100.NR40.dat";
 
@@ -155,13 +159,16 @@ extern int usrp_tx_thread;
     {"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},                     \
     {"use-256qam-table",     CONFIG_HLP_256QAM,       PARAMFLAG_BOOL, iptr:&USE_256QAM_TABLE,             defintval:0,           TYPE_INT,    0},                     \
-    {"do-prb-interpolation",  CONFIG_HLP_PRBINTER,     PARAMFLAG_BOOL, iptr:&PRB_INTERPOLATION,            defintval:0,           TYPE_INT,    0},                     \
-    {"usrp-tx-thread-config", CONFIG_HLP_USRP_THREAD, 0,              iptr:&usrp_tx_thread,               defstrval:0,           TYPE_INT,    0},        \
-    {"nfapi",                CONFIG_HLP_NFAPI,        0,              u8ptr:&nfapi_mode,                       defintval:0,           TYPE_UINT8,  0},                     \
-    {"non-stop",            CONFIG_HLP_NONSTOP,      PARAMFLAG_BOOL, iptr:&NON_STOP,                       defintval:0,           TYPE_INT,  0},                     \
+    {"nsa",                  CONFIG_HLP_NSA,          PARAMFLAG_BOOL, iptr:&NSA,                          defintval:0,           TYPE_INT,    0},                     \
+    {"node-number",          NULL,                    0,              u16ptr:&NODE_NUMBER,                defuintval:0,          TYPE_UINT16, 0},                     \
+    {"usrp-tx-thread-config", CONFIG_HLP_USRP_THREAD, 0,              iptr:&usrp_tx_thread,               defstrval:0,           TYPE_INT,    0},                     \
+    {"do-prb-interpolation", CONFIG_HLP_PRBINTER,     PARAMFLAG_BOOL, iptr:&PRB_INTERPOLATION,            defintval:0,           TYPE_INT,    0},                     \
+    {"nfapi",                CONFIG_HLP_NFAPI,        0,              u8ptr:&nfapi_mode,                  defintval:0,           TYPE_UINT8,  0},                     \
+    {"non-stop",             CONFIG_HLP_NONSTOP,      PARAMFLAG_BOOL, iptr:&NON_STOP,                     defintval:0,           TYPE_INT,    0},                     \
+    {"emulate-l1",           CONFIG_L1_EMULATOR,      PARAMFLAG_BOOL, iptr:&EMULATE_L1,                   defintval:0,           TYPE_INT,    0},                     \
   }
 
-  
+#define CONFIG_HLP_NSA           "Enable NSA mode \n"
 #define CONFIG_HLP_FLOG          "Enable online log \n"
 #define CONFIG_HLP_LOGL          "Set the global log level, valid options: (4:trace, 3:debug, 2:info, 1:warn, (0:error))\n"
 #define CONFIG_HLP_LOGV          "Set the global log verbosity \n"
@@ -251,7 +258,10 @@ typedef struct {
   int            use_256qam_table;
   int            prb_interpolation;
   uint8_t        nfapi;
+  int            nsa;
+  uint16_t       node_number;
   int            non_stop;
+  int            emulate_l1;
 } softmodem_params_t;
 
 extern uint64_t get_softmodem_optmask(void);
@@ -272,6 +282,7 @@ void tx_func(void *param);
 void rx_func(void *param);
 void ru_tx_func(void *param);
 extern uint8_t nfapi_mode;
+extern int16_t vnf_pnf_sfnslot_delta;
 #ifdef __cplusplus
 }
 #endif
diff --git a/nfapi/oai_integration/gnb_ind_vars.c b/nfapi/oai_integration/gnb_ind_vars.c
new file mode 100644
index 0000000000000000000000000000000000000000..148c28a5c4dd7db66594ffc81abcb354220dd223
--- /dev/null
+++ b/nfapi/oai_integration/gnb_ind_vars.c
@@ -0,0 +1,7 @@
+#include "gnb_ind_vars.h"
+
+queue_t gnb_rach_ind_queue;
+queue_t gnb_rx_ind_queue;
+queue_t gnb_crc_ind_queue;
+queue_t gnb_uci_ind_queue;
+queue_t gnb_slot_ind_queue;
diff --git a/nfapi/oai_integration/gnb_ind_vars.h b/nfapi/oai_integration/gnb_ind_vars.h
new file mode 100644
index 0000000000000000000000000000000000000000..8561037d3e444ca2f6686714da556407e6cb482e
--- /dev/null
+++ b/nfapi/oai_integration/gnb_ind_vars.h
@@ -0,0 +1,9 @@
+#pragma once
+
+#include "openair2/PHY_INTERFACE/queue_t.h"
+
+extern queue_t gnb_rach_ind_queue;
+extern queue_t gnb_rx_ind_queue;
+extern queue_t gnb_crc_ind_queue;
+extern queue_t gnb_uci_ind_queue;
+extern queue_t gnb_slot_ind_queue;
diff --git a/nfapi/oai_integration/nfapi.c b/nfapi/oai_integration/nfapi.c
index 86d1ae3127d33c13c71977c43c950830feb1ecdd..5e71c5e2a4458fcff77c9336bbdb36768dd16cb0 100644
--- a/nfapi/oai_integration/nfapi.c
+++ b/nfapi/oai_integration/nfapi.c
@@ -23,7 +23,15 @@
 #include <pthread.h>
 #include "nfapi/oai_integration/vendor_ext.h"
 #include "common/utils/LOG/log.h"
-static char nfapi_str_mode[6][24] = {"MONOLITHIC","PNF","VNF","UE_STUB_PNF","UE_STUB_OFFNET","<UNKNOWN NFAPI MODE>"};
+static const char *const nfapi_str_mode[] = {
+    "MONOLITHIC",
+    "PNF",
+    "VNF",
+    "UE_STUB_PNF",
+    "UE_STUB_OFFNET",
+    "STANDALONE_PNF",
+    "<UNKNOWN NFAPI MODE>"
+};
 
 typedef struct {
   nfapi_mode_t nfapi_mode;
@@ -32,15 +40,9 @@ typedef struct {
 static nfapi_params_t nfapi_params = {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");
-  }
+  set_priority(priority);
 
+  pthread_attr_t ptAttr;
   if(pthread_attr_setschedpolicy(&ptAttr, SCHED_RR) != 0) {
     printf("Failed to set pthread sched policy SCHED_RR\n");
   }
@@ -54,7 +56,7 @@ void set_thread_priority(int priority) {
   }
 }
 
-char *nfapi_get_strmode(void) {
+const char *nfapi_get_strmode(void) {
   if (nfapi_params.nfapi_mode > NFAPI_MODE_UNKNOWN)
     return nfapi_str_mode[NFAPI_MODE_UNKNOWN];
 
diff --git a/nfapi/oai_integration/nfapi_pnf.c b/nfapi/oai_integration/nfapi_pnf.c
index 4edbeee342d9ee69c93b6c3262e9ae52682b4a0c..3a59be41e9e40564acf9287d1655f107a68d6719 100644
--- a/nfapi/oai_integration/nfapi_pnf.c
+++ b/nfapi/oai_integration/nfapi_pnf.c
@@ -218,14 +218,9 @@ void pnf_nfapi_trace(nfapi_trace_level_t nfapi_level, const char *message, ...)
 }
 
 void pnf_set_thread_priority(int priority) {
-  pthread_attr_t ptAttr;
-  struct sched_param schedParam;
-  schedParam.__sched_priority = priority;
-
-  if(sched_setscheduler(0, SCHED_RR, &schedParam) != 0) {
-    printf("failed to set SCHED_RR\n");
-  }
+  set_priority(priority);
 
+  pthread_attr_t ptAttr;
   if(pthread_attr_setschedpolicy(&ptAttr, SCHED_RR) != 0) {
     printf("failed to set pthread SCHED_RR %d\n", errno);
   }
@@ -248,7 +243,7 @@ void *pnf_p7_thread_start(void *ptr) {
 }
 
 void *pnf_nr_p7_thread_start(void *ptr) {
-  NFAPI_TRACE(NFAPI_TRACE_INFO, "[PNF] P7 THREAD %s\n", __FUNCTION__);
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "[NR_PNF] NR P7 THREAD %s\n", __FUNCTION__);
   pnf_set_thread_priority(79);
   nfapi_pnf_p7_config_t *config = (nfapi_pnf_p7_config_t *)ptr;
   nfapi_nr_pnf_p7_start(config);
@@ -805,7 +800,7 @@ int config_request(nfapi_pnf_config_t *config, nfapi_pnf_phy_config_t *phy, nfap
   // to keep only the necessary just to keep the nfapi FSM rolling by sending a dummy response.
   LTE_DL_FRAME_PARMS *fp;
 
-  if (NFAPI_MODE!=NFAPI_UE_STUB_PNF) {
+  if (NFAPI_MODE!=NFAPI_UE_STUB_PNF && NFAPI_MODE!=NFAPI_MODE_STANDALONE_PNF) {
     struct PHY_VARS_eNB_s *eNB = RC.eNB[0][0];
     fp = &eNB->frame_parms;
   } else {
@@ -967,7 +962,7 @@ int config_request(nfapi_pnf_config_t *config, nfapi_pnf_phy_config_t *phy, nfap
     num_tlv++;
   }
 
-  if(NFAPI_MODE!=NFAPI_UE_STUB_PNF) {
+  if(NFAPI_MODE!=NFAPI_UE_STUB_PNF && NFAPI_MODE!=NFAPI_MODE_STANDALONE_PNF) {
     printf("[PNF] CONFIG_REQUEST[num_tlv:%d] TLVs processed:%d\n", req->num_tlv, num_tlv);
     printf("[PNF] Simulating PHY CONFIG - DJP\n");
     PHY_Config_t phy_config;
@@ -991,7 +986,7 @@ int config_request(nfapi_pnf_config_t *config, nfapi_pnf_phy_config_t *phy, nfap
   nfapi_pnf_config_resp(config, &nfapi_resp);
   printf("[PNF] Sent NFAPI_CONFIG_RESPONSE phy_id:%d\n", phy_info->id);
 
-  if(NFAPI_MODE==NFAPI_UE_STUB_PNF)
+  if(NFAPI_MODE==NFAPI_UE_STUB_PNF || NFAPI_MODE==NFAPI_MODE_STANDALONE_PNF)
     free(fp);
 
   return 0;
@@ -1226,15 +1221,15 @@ int pnf_phy_dl_tti_req(gNB_L1_rxtx_proc_t *proc, nfapi_pnf_p7_config_t *pnf_p7,
      proc = &gNB->proc.L1_proc;
   nfapi_nr_dl_tti_request_pdu_t *dl_tti_pdu_list = req->dl_tti_request_body.dl_tti_pdu_list;
 
-    //if (req->dl_tti_request_body.nPDUs)
-    // NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() TX:%d/%d RX:%d/%d; sfn:%d, slot:%d, nGroup:%u, nPDUs: %u, nUE: %u, PduIdx: %u,\n",
-    //             __FUNCTION__, proc->frame_tx, proc->slot_tx, proc->frame_rx, proc->slot_rx, // TODO: change subframes to slot
-    //             req->SFN,
-    //             req->Slot,
-    //             req->dl_tti_request_body.nGroup,
-    //             req->dl_tti_request_body.nPDUs,
-    //             req->dl_tti_request_body.nUe,
-    //             req->dl_tti_request_body.PduIdx);
+  if (req->dl_tti_request_body.nPDUs)
+    NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() TX:%d/%d RX:%d/%d; sfn:%d, slot:%d, nGroup:%u, nPDUs: %u, nUE: %p, PduIdx: %p,\n",
+                __FUNCTION__, proc->frame_tx, proc->slot_tx, proc->frame_rx, proc->slot_rx, // TODO: change subframes to slot
+                req->SFN,
+                req->Slot,
+                req->dl_tti_request_body.nGroup,
+                req->dl_tti_request_body.nPDUs,
+                req->dl_tti_request_body.nUe,
+                req->dl_tti_request_body.PduIdx);
 
   for (int i=0; i<req->dl_tti_request_body.nPDUs; i++) {
     // NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() sfn/sf:%d PDU[%d] size:%d pdcch_vars->num_dci:%d\n", __FUNCTION__, NFAPI_SFNSF2DEC(req->sfn_sf), i, dl_config_pdu_list[i].pdu_size,pdcch_vars->num_dci);
@@ -1250,10 +1245,10 @@ int pnf_phy_dl_tti_req(gNB_L1_rxtx_proc_t *proc, nfapi_pnf_p7_config_t *pnf_p7,
       //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() PDU:%d BCH: pdu_index:%u pdu_length:%d sdu_length:%d BCH_SDU:%x,%x,%x\n", __FUNCTION__, i, pdu_index, bch_pdu->bch_pdu_rel8.length, tx_request_pdu[sfn][sf][pdu_index]->segments[0].segment_length, sdu[0], sdu[1], sdu[2]);
       handle_nr_nfapi_ssb_pdu(msgTx, sfn, slot, &dl_tti_pdu_list[i]);
       gNB->pbch_configured=1;
-    } 
+    }
     else if (dl_tti_pdu_list[i].PDUType == NFAPI_NR_DL_TTI_PDSCH_PDU_TYPE) {
       nfapi_nr_dl_tti_pdsch_pdu *pdsch_pdu = &dl_tti_pdu_list[i].pdsch_pdu;
-      nfapi_nr_dl_tti_pdsch_pdu_rel15_t *rel15_pdu = &pdsch_pdu->pdsch_pdu_rel15;     
+      nfapi_nr_dl_tti_pdsch_pdu_rel15_t *rel15_pdu = &pdsch_pdu->pdsch_pdu_rel15;
       nfapi_nr_pdu_t *tx_data = tx_data_request[sfn][slot][rel15_pdu->pduIndex];
 
       if (tx_data != NULL) {
@@ -1466,6 +1461,7 @@ int pnf_phy_ul_tti_req(gNB_L1_rxtx_proc_t *proc, nfapi_pnf_p7_config_t *pnf_p7,
     switch (ul_tti_pdu_list[i].pdu_type) {
       case NFAPI_NR_UL_CONFIG_PUSCH_PDU_TYPE:
         //LOG_D(PHY,"frame %d, slot %d, Got NFAPI_NR_UL_TTI_PUSCH_PDU_TYPE for %d.%d\n", frame, slot, UL_tti_req->SFN, UL_tti_req->Slot);
+        //curr_sfn = curr_sfn + 3; //Gokul
         nr_fill_ulsch(gNB,curr_sfn, curr_slot, &ul_tti_pdu_list[i].pusch_pdu);
         break;
       case NFAPI_NR_UL_CONFIG_PUCCH_PDU_TYPE:
@@ -1661,7 +1657,6 @@ nfapi_pnf_p7_subframe_buffer_t dummy_subframe;
 
 int start_request(nfapi_pnf_config_t *config, nfapi_pnf_phy_config_t *phy, nfapi_start_request_t *req) {
   printf("[PNF] Received NFAPI_START_REQ phy_id:%d\n", req->header.phy_id);
-  nfapi_set_trace_level(NFAPI_TRACE_INFO);
   pnf_info *pnf = (pnf_info *)(config->user_data);
   phy_info *phy_info = pnf->phys;
   nfapi_pnf_p7_config_t *p7_config = nfapi_pnf_p7_config_create();
@@ -1697,11 +1692,11 @@ int start_request(nfapi_pnf_config_t *config, nfapi_pnf_phy_config_t *phy, nfapi
   p7_config->tx_req = &pnf_phy_tx_req;
   p7_config->lbt_dl_config_req = &pnf_phy_lbt_dl_config_req;
   p7_config->ue_release_req = &pnf_phy_ue_release_req;
-  if (NFAPI_MODE==NFAPI_UE_STUB_PNF) {
-    p7_config->dl_config_req = &memcpy_dl_config_req;
-    p7_config->ul_config_req = &memcpy_ul_config_req;
-    p7_config->hi_dci0_req = &memcpy_hi_dci0_req;
-    p7_config->tx_req = &memcpy_tx_req;
+  if (NFAPI_MODE==NFAPI_UE_STUB_PNF || NFAPI_MODE==NFAPI_MODE_STANDALONE_PNF) {
+    p7_config->dl_config_req = NULL;
+    p7_config->ul_config_req = NULL;
+    p7_config->hi_dci0_req = NULL;
+    p7_config->tx_req = NULL;
   } else {
     p7_config->dl_config_req = &pnf_phy_dl_config_req;
     p7_config->ul_config_req = &pnf_phy_ul_config_req;
@@ -1754,7 +1749,7 @@ int start_request(nfapi_pnf_config_t *config, nfapi_pnf_phy_config_t *phy, nfapi
   //phy_init_RU(RC.ru[0]);
   printf("[PNF] About to call init_eNB_afterRU()\n");
 
-  if (NFAPI_MODE!=NFAPI_UE_STUB_PNF) {
+  if (NFAPI_MODE!=NFAPI_UE_STUB_PNF && NFAPI_MODE!=NFAPI_MODE_STANDALONE_PNF) {
     init_eNB_afterRU();
   }
 
@@ -1781,7 +1776,6 @@ int start_request(nfapi_pnf_config_t *config, nfapi_pnf_phy_config_t *phy, nfapi
 
 int nr_start_request(nfapi_pnf_config_t *config, nfapi_pnf_phy_config_t *phy,  nfapi_nr_start_request_scf_t *req) {
   printf("[PNF] Received NFAPI_START_REQ phy_id:%d\n", req->header.phy_id);
-  nfapi_set_trace_level(NFAPI_TRACE_INFO);
   pnf_info *pnf = (pnf_info *)(config->user_data);
   phy_info *phy_info = pnf->phys;
   nfapi_pnf_p7_config_t *p7_config = nfapi_pnf_p7_config_create();
@@ -1827,10 +1821,10 @@ int nr_start_request(nfapi_pnf_config_t *config, nfapi_pnf_phy_config_t *phy,  n
   p7_config->lbt_dl_config_req = &pnf_phy_lbt_dl_config_req;
   p7_config->ue_release_req = &pnf_phy_ue_release_req;
   if (NFAPI_MODE==NFAPI_UE_STUB_PNF) {
-    p7_config->dl_config_req = &memcpy_dl_config_req;
-    p7_config->ul_config_req = &memcpy_ul_config_req;
-    p7_config->hi_dci0_req = &memcpy_hi_dci0_req;
-    p7_config->tx_req = &memcpy_tx_req;
+    p7_config->dl_config_req = NULL;
+    p7_config->ul_config_req = NULL;
+    p7_config->hi_dci0_req = NULL;
+    p7_config->tx_req = NULL;
   } else {
     p7_config->dl_config_req = &pnf_phy_dl_config_req;
     p7_config->ul_config_req = &pnf_phy_ul_config_req;
@@ -2232,7 +2226,7 @@ void configure_nr_nfapi_pnf(char *vnf_ip_addr, int vnf_p5_port, char *pnf_ip_add
 void configure_nfapi_pnf(char *vnf_ip_addr, int vnf_p5_port, char *pnf_ip_addr, int pnf_p7_port, int vnf_p7_port) {
   printf("%s() PNF\n\n\n\n\n\n", __FUNCTION__);
 
-  if(NFAPI_MODE!=NFAPI_UE_STUB_PNF) {
+  if(NFAPI_MODE!=NFAPI_UE_STUB_PNF && NFAPI_MODE!=NFAPI_MODE_STANDALONE_PNF) {
     nfapi_setmode(NFAPI_MODE_PNF);  // PNF!
   }
   nfapi_pnf_config_t *config = nfapi_pnf_config_create();
@@ -2286,15 +2280,13 @@ void oai_subframe_ind(uint16_t sfn, uint16_t sf) {
     uint16_t sfn_sf_tx = sfn<<4 | sf; 
 
     if ((sfn % 100 == 0) && sf==0) {
-      struct timespec ts;
-      clock_gettime(CLOCK_MONOTONIC, &ts);
-      NFAPI_TRACE(NFAPI_TRACE_INFO, "[PNF] %s %d.%d (sfn:%u sf:%u) SFN/SF(TX):%u\n", __FUNCTION__, ts.tv_sec, ts.tv_nsec, sfn, sf, NFAPI_SFNSF2DEC(sfn_sf_tx));
+      NFAPI_TRACE(NFAPI_TRACE_INFO, "[PNF] (sfn:%u sf:%u) SFN/SF(TX):%u\n", sfn, sf, NFAPI_SFNSF2DEC(sfn_sf_tx));
     }
 
     int subframe_ret = nfapi_pnf_p7_subframe_ind(p7_config_g, p7_config_g->phy_id, sfn_sf_tx);
 
     if (subframe_ret) {
-      NFAPI_TRACE(NFAPI_TRACE_INFO, "[PNF] %s(frame:%u subframe:%u) SFN/SF(TX):%u - PROBLEM with pnf_p7_subframe_ind()\n", __FUNCTION__, sfn, sf, sfn_sf_tx, NFAPI_SFNSF2DEC(sfn_sf_tx));
+      NFAPI_TRACE(NFAPI_TRACE_INFO, "[PNF] (frame:%u subframe:%u) SFN/SF(TX):%u - PROBLEM with pnf_p7_subframe_ind()\n", sfn, sf, sfn_sf_tx);
     } else {
       //NFAPI_TRACE(NFAPI_TRACE_INFO, "***NFAPI subframe handler finished *** \n");
     }
diff --git a/nfapi/oai_integration/nfapi_vnf.c b/nfapi/oai_integration/nfapi_vnf.c
index d96829e127756976157f746ea5176fd7b35378bf..44ee05940fc3aa6879867582f57fe65773b0f8d2 100644
--- a/nfapi/oai_integration/nfapi_vnf.c
+++ b/nfapi/oai_integration/nfapi_vnf.c
@@ -43,6 +43,8 @@
 #include <targets/RT/USER/lte-softmodem.h>
 
 #include "common/ran_context.h"
+#include "openair2/PHY_INTERFACE/queue_t.h"
+#include "gnb_ind_vars.h"
 
 #define TEST
 
@@ -203,7 +205,7 @@ extern uint16_t slot_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 if_inst:%p\n", eNB->Mod_id, eNB->CC_id, RC.nb_CC[0], eNB->abstraction_flag,
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "[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;
@@ -219,20 +221,20 @@ 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");
+    NFAPI_TRACE(NFAPI_TRACE_INFO, "RC.eNB[0][0]->if_inst->PHY_config_req is not installed - install it\n");
     install_schedule_handlers(RC.eNB[0][0]->if_inst);
   }
 
   do {
-    printf("%s() Waiting for eNB to become configured (by RRC/PHY) - need to wait otherwise NFAPI messages won't contain correct values\n", __FUNCTION__);
+    NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() Waiting for eNB to become configured (by RRC/PHY) - need to wait otherwise NFAPI messages won't contain correct values\n", __FUNCTION__);
     usleep(50000);
   } while(eNB->configured != 1);
 
-  printf("%s() eNB is now configured\n", __FUNCTION__);
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() eNB is now configured\n", __FUNCTION__);
 }
 
 void oai_enb_init(void) {
-  printf("%s() About to call init_eNB_afterRU()\n", __FUNCTION__);
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() About to call init_eNB_afterRU()\n", __FUNCTION__);
   init_eNB_afterRU();
 }
 
@@ -253,7 +255,7 @@ void oai_create_gnb(void) {
   
   PHY_VARS_gNB *gNB = RC.gNB[0];
   RC.nb_nr_CC = (int *)malloc(sizeof(int)); // TODO: find a better function to place this in
-  
+
   gNB->Mod_id  = bodge_counter;
   gNB->CC_id   = bodge_counter;
   gNB->abstraction_flag   = 0;
@@ -263,26 +265,26 @@ void oai_create_gnb(void) {
   if (gNB->if_inst==0) {
     gNB->if_inst = NR_IF_Module_init(bodge_counter);
   }
-  
+
 
   // This will cause phy_config_request to be installed. That will result in RRC configuring the PHY
   // that will result in gNB->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.gNB[0]->if_inst==0 || RC.gNB[0]->if_inst->NR_PHY_config_req==0 || RC.gNB[0]->if_inst->NR_Schedule_response==0) {
-    printf("RC.gNB[0][0]->if_inst->NR_PHY_config_req is not installed - install it\n");
+    NFAPI_TRACE(NFAPI_TRACE_INFO, "RC.gNB[0][0]->if_inst->NR_PHY_config_req is not installed - install it\n");
     install_nr_schedule_handlers(RC.gNB[0]->if_inst);
   }
 
   do {
-    printf("%s() Waiting for gNB to become configured (by RRC/PHY) - need to wait otherwise NFAPI messages won't contain correct values\n", __FUNCTION__);
+    NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() Waiting for gNB to become configured (by RRC/PHY) - need to wait otherwise NFAPI messages won't contain correct values\n", __FUNCTION__);
     usleep(50000);
   } while(gNB->configured != 1);
 
-  printf("%s() gNB is now configured\n", __FUNCTION__);
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() gNB is now configured\n", __FUNCTION__);
 }
 
 int pnf_connection_indication_cb(nfapi_vnf_config_t *config, int p5_idx) {
-  printf("[VNF] pnf connection indication idx:%d\n", p5_idx);
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "[VNF] pnf connection indication idx:%d\n", p5_idx);
   oai_create_enb();
   nfapi_pnf_param_request_t req;
   memset(&req, 0, sizeof(req));
@@ -292,7 +294,7 @@ int pnf_connection_indication_cb(nfapi_vnf_config_t *config, int p5_idx) {
 }
 
 int pnf_nr_connection_indication_cb(nfapi_vnf_config_t *config, int p5_idx) {
-  printf("[VNF] pnf connection indication idx:%d\n", p5_idx);
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "[VNF] pnf connection indication idx:%d\n", p5_idx);
   oai_create_gnb();
   nfapi_nr_pnf_param_request_t req;
   memset(&req, 0, sizeof(req));
@@ -302,7 +304,7 @@ int pnf_nr_connection_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);
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "[VNF] pnf disconnection indication idx:%d\n", p5_idx);
   vnf_info *vnf = (vnf_info *)(config->user_data);
   pnf_info *pnf = vnf->pnfs;
   phy_info *phy = pnf->phys;
@@ -312,7 +314,7 @@ int pnf_disconnection_indication_cb(nfapi_vnf_config_t *config, int p5_idx) {
 }
 
 int pnf_nr_param_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_nr_pnf_param_response_t *resp) {
-  printf("[VNF] pnf param response idx:%d error:%d\n", p5_idx, resp->error_code);
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "[VNF] pnf param response idx:%d error:%d\n", p5_idx, resp->error_code);
   vnf_info *vnf = (vnf_info *)(config->user_data);
   pnf_info *pnf = vnf->pnfs;
 
@@ -320,11 +322,11 @@ int pnf_nr_param_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_nr_pnf_pa
     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_TRACE(NFAPI_TRACE_INFO, "[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) {
-      printf("[VNF] (PHY:%d) (RF%d) %d\n", i, j, resp->pnf_phy.phy[i].rf_config[j].rf_config_index);
+      NFAPI_TRACE(NFAPI_TRACE_INFO, "[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;
     }
 
@@ -335,7 +337,7 @@ int pnf_nr_param_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_nr_pnf_pa
   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");
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "DJP:Hard coded num phy rf to 2\n");
 
   for(unsigned i = 0; i < 2; ++i) {
     req.pnf_phy_rf_config.phy_rf_config[i].phy_id = pnf->phys[i].id;
@@ -348,7 +350,7 @@ int pnf_nr_param_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_nr_pnf_pa
 }
 
 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);
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "[VNF] pnf param response idx:%d error:%d\n", p5_idx, resp->error_code);
   vnf_info *vnf = (vnf_info *)(config->user_data);
   pnf_info *pnf = vnf->pnfs;
 
@@ -356,11 +358,11 @@ int pnf_param_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_pnf_param_re
     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_TRACE(NFAPI_TRACE_INFO, "[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) {
-      printf("[VNF] (PHY:%d) (RF%d) %d\n", i, j, resp->pnf_phy.phy[i].rf_config[j].rf_config_index);
+      NFAPI_TRACE(NFAPI_TRACE_INFO, "[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;
     }
 
@@ -370,7 +372,7 @@ int pnf_param_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_pnf_param_re
     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);
+    NFAPI_TRACE(NFAPI_TRACE_INFO, "[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;
@@ -378,7 +380,7 @@ int pnf_param_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_pnf_param_re
   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");
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "DJP:Hard coded num phy rf to 2\n");
 
   for(unsigned i = 0; i < 2; ++i) {
     req.pnf_phy_rf_config.phy_rf_config[i].phy_id = pnf->phys[i].id;
@@ -391,7 +393,7 @@ int pnf_param_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_pnf_param_re
 }
 
 int pnf_nr_config_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_nr_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);
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "[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_nr_pnf_start_request_t req;
@@ -416,7 +418,7 @@ int pnf_nr_config_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_nr_pnf_c
 }
 
 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);
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "[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;
@@ -443,12 +445,12 @@ int pnf_config_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_pnf_config_
 int wake_gNB_rxtx(PHY_VARS_gNB *gNB, uint16_t sfn, uint16_t slot) {
   struct timespec curr_t;
   clock_gettime(CLOCK_MONOTONIC,&curr_t);
- //printf("\n wake_gNB_rxtx before assignment sfn:%d slot:%d TIME %d.%d",sfn,slot,curr_t.tv_sec,curr_t.tv_nsec);
+ //NFAPI_TRACE(NFAPI_TRACE_INFO, "\n wake_gNB_rxtx before assignment sfn:%d slot:%d TIME %d.%d",sfn,slot,curr_t.tv_sec,curr_t.tv_nsec);
   gNB_L1_proc_t *proc=&gNB->proc;
   gNB_L1_rxtx_proc_t *L1_proc= (slot&1)? &proc->L1_proc : &proc->L1_proc_tx;
 
   NR_DL_FRAME_PARMS *fp = &gNB->frame_parms;
-  //printf("%s(eNB:%p, sfn:%d, sf:%d)\n", __FUNCTION__, eNB, sfn, sf);
+  //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s(eNB:%p, sfn:%d, sf:%d)\n", __FUNCTION__, eNB, sfn, sf);
   //int i;
   struct timespec wait;
   clock_gettime(CLOCK_REALTIME, &wait);
@@ -471,7 +473,7 @@ int wake_gNB_rxtx(PHY_VARS_gNB *gNB, uint16_t sfn, uint16_t slot) {
     // Try to be 1 frame back
     old_slot = slot;
     old_sfn = sfn;
-    //printf("\n wake_gNB_rxtx after assignment sfn:%d slot:%d",proc->frame_rx,proc->slot_rx);
+    //NFAPI_TRACE(NFAPI_TRACE_INFO, "\n wake_gNB_rxtx after assignment sfn:%d slot:%d",proc->frame_rx,proc->slot_rx);
     if (old_slot == 0 && old_sfn % 100 == 0) LOG_W( PHY,"[gNB] sfn/slot:%d%d old_sfn/slot:%d%d proc[rx:%d%d]\n", sfn, slot, old_sfn, old_slot, proc->frame_rx, proc->slot_rx);
   }
 
@@ -490,7 +492,7 @@ int wake_gNB_rxtx(PHY_VARS_gNB *gNB, uint16_t sfn, uint16_t slot) {
   L1_proc->slot_tx      = (L1_proc->slot_rx + slot_ahead)%20;
 
   //LOG_I(PHY, "sfn/sf:%d%d proc[rx:%d%d] rx:%d%d] About to wake rxtx thread\n\n", sfn, slot, proc->frame_rx, proc->slot_rx, L1_proc->frame_rx, L1_proc->slot_rx);
-  //printf("\nEntering wake_gNB_rxtx sfn %d slot %d\n",L1_proc->frame_rx,L1_proc->slot_rx);
+  //NFAPI_TRACE(NFAPI_TRACE_INFO, "\nEntering wake_gNB_rxtx sfn %d slot %d\n",L1_proc->frame_rx,L1_proc->slot_rx);
   // the thread can now be woken up
   if (pthread_cond_signal(&L1_proc->cond) != 0) {
     LOG_E( PHY, "[gNB] ERROR pthread_cond_signal for gNB RXn-TXnp4 thread\n");
@@ -508,7 +510,7 @@ int wake_eNB_rxtx(PHY_VARS_eNB *eNB, uint16_t sfn, uint16_t sf) {
   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);
+  //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s(eNB:%p, sfn:%d, sf:%d)\n", __FUNCTION__, eNB, sfn, sf);
   //int i;
   struct timespec wait;
   wait.tv_sec=0;
@@ -596,11 +598,11 @@ 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) {
-  //printf("[VNF] SYNC %s\n", sync==1 ? "ACHIEVED" : "LOST");
+  //NFAPI_TRACE(NFAPI_TRACE_INFO, "[VNF] SYNC %s\n", sync==1 ? "ACHIEVED" : "LOST");
 
   if (sync==1 && nfapi_sync_var!=0) {
-    
-    printf("[VNF] Signal to OAI main code that it can go\n");
+
+    NFAPI_TRACE(NFAPI_TRACE_INFO, "[VNF] Signal to OAI main code that it can go\n");
     pthread_mutex_lock(&nfapi_sync_mutex);
     nfapi_sync_var=0;
     pthread_cond_broadcast(&nfapi_sync_cond);
@@ -615,19 +617,19 @@ int phy_slot_indication(struct nfapi_vnf_p7_config *config, uint16_t phy_id, uin
   static uint8_t first_time = 1;
 
   if (first_time) {
-    printf("[VNF] slot indication %d\n", NFAPI_SFNSLOT2DEC(sfn, slot));
+    NFAPI_TRACE(NFAPI_TRACE_INFO, "[VNF] slot indication %d\n", NFAPI_SFNSLOT2DEC(sfn, slot));
     first_time = 0;
   }
 
   if (RC.gNB && RC.gNB[0]->configured) {
     // uint16_t sfn = NFAPI_SFNSF2SFN(sfn_sf);
     // uint16_t sf = NFAPI_SFNSF2SF(sfn_sf);
-    LOG_D(PHY,"[VNF] slot indication sfn:%d sf:%d\n", sfn, slot);
+    LOG_D(PHY,"[VNF] slot indication sfn:%d slot:%d\n", sfn, slot);
     wake_gNB_rxtx(RC.gNB[0], sfn, slot); // DONE: find NR equivalent
   } else {
-    printf("[VNF] %s() RC.gNB:%p\n", __FUNCTION__, RC.gNB);
+    NFAPI_TRACE(NFAPI_TRACE_INFO, "[VNF] %s() RC.gNB:%p\n", __FUNCTION__, RC.gNB);
 
-    if (RC.gNB) printf("RC.gNB[0]->configured:%d\n", RC.gNB[0]->configured);
+    if (RC.gNB) NFAPI_TRACE(NFAPI_TRACE_INFO, "RC.gNB[0]->configured:%d\n", RC.gNB[0]->configured);
   }
 
   return 0;
@@ -637,7 +639,7 @@ int phy_subframe_indication(struct nfapi_vnf_p7_config *config, uint16_t phy_id,
   static uint8_t first_time = 1;
 
   if (first_time) {
-    printf("[VNF] subframe indication %d\n", NFAPI_SFNSF2DEC(sfn_sf));
+    NFAPI_TRACE(NFAPI_TRACE_INFO, "[VNF] subframe indication %d\n", NFAPI_SFNSF2DEC(sfn_sf));
     first_time = 0;
   }
 
@@ -647,9 +649,9 @@ int phy_subframe_indication(struct nfapi_vnf_p7_config *config, uint16_t phy_id,
     //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);
+    NFAPI_TRACE(NFAPI_TRACE_INFO, "[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);
+    if (RC.eNB) NFAPI_TRACE(NFAPI_TRACE_INFO, "RC.eNB[0][0]->configured:%d\n", RC.eNB[0][0]->configured);
   }
 
   return 0;
@@ -658,21 +660,11 @@ int phy_subframe_indication(struct nfapi_vnf_p7_config *config, uint16_t phy_id,
 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);
+  LOG_D(MAC, "[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);
+  AssertFatal(pthread_mutex_lock(&eNB->UL_INFO_mutex)==0, "Mutex lock failed");
   if(NFAPI_MODE == NFAPI_MODE_VNF){
-    int8_t index = -1;
-    for(uint8_t i= 0;i< NUM_NFPAI_SUBFRAME;i++){
-      if((UL_RCC_INFO.rach_ind[i].header.message_id == 0) && (index == -1)){
-        index = i;
-        break;
-      }
-    }
-    if(index == -1){
-      LOG_E(MAC,"phy_rach_indication : num of rach reach max \n");
-      pthread_mutex_unlock(&eNB->UL_INFO_mutex);
-      return 0;
-    }
+    int8_t index = NFAPI_SFNSF2SF(ind->sfn_sf);
+
     UL_RCC_INFO.rach_ind[index] = *ind;
 
     if (ind->rach_indication_body.number_of_preambles > 0)
@@ -681,7 +673,7 @@ int phy_rach_indication(struct nfapi_vnf_p7_config *config, nfapi_rach_indicatio
     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",
+        LOG_D(MAC, "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,
@@ -689,7 +681,7 @@ int phy_rach_indication(struct nfapi_vnf_p7_config *config, nfapi_rach_indicatio
               );
       }
       if(ind->rach_indication_body.preamble_list[i].preamble_rel13.tl.tag == NFAPI_PREAMBLE_REL13_TAG) {
-        printf("RACH PREAMBLE REL13 present\n");
+        LOG_D(MAC, "RACH PREAMBLE REL13 present\n");
       }
 
       UL_RCC_INFO.rach_ind[index].rach_indication_body.preamble_list[i] = ind->rach_indication_body.preamble_list[i];
@@ -700,7 +692,7 @@ int phy_rach_indication(struct nfapi_vnf_p7_config *config, nfapi_rach_indicatio
 
   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",
+      LOG_D(MAC, "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,
@@ -709,51 +701,190 @@ int phy_rach_indication(struct nfapi_vnf_p7_config *config, nfapi_rach_indicatio
     }
 
     if(ind->rach_indication_body.preamble_list[i].preamble_rel13.tl.tag == NFAPI_PREAMBLE_REL13_TAG) {
-      printf("RACH PREAMBLE REL13 present\n");
+      LOG_D(MAC, "RACH PREAMBLE REL13 present\n");
     }
 
     eNB->preamble_list[i] = ind->rach_indication_body.preamble_list[i];
   }
   }
-  pthread_mutex_unlock(&eNB->UL_INFO_mutex);
+  AssertFatal(pthread_mutex_unlock(&eNB->UL_INFO_mutex)==0, "Mutex unlock failed");
   // vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data);
   //mac_rach_ind(p7_vnf->mac, ind);
   return 1;
 }
 
+int phy_nr_rach_indication(nfapi_nr_rach_indication_t *ind)
+{
+  if(NFAPI_MODE == NFAPI_MODE_VNF)
+  {
+    nfapi_nr_rach_indication_t *rach_ind = CALLOC(1, sizeof(*rach_ind));
+    rach_ind->header.message_id = ind->header.message_id;
+    rach_ind->number_of_pdus = ind->number_of_pdus;
+    rach_ind->sfn = ind->sfn;
+    rach_ind->slot = ind->slot;
+    rach_ind->pdu_list = CALLOC(rach_ind->number_of_pdus, sizeof(*rach_ind->pdu_list));
+    AssertFatal(rach_ind->pdu_list != NULL, "Memory not allocated for rach_ind->pdu_list in phy_nr_rach_indication.");
+    for (int i = 0; i < ind->number_of_pdus; i++)
+    {
+      rach_ind->pdu_list[i].num_preamble = ind->pdu_list[i].num_preamble;
+      rach_ind->pdu_list[i].freq_index = ind->pdu_list[i].freq_index;
+      rach_ind->pdu_list[i].symbol_index = ind->pdu_list[i].symbol_index;
+      rach_ind->pdu_list[i].preamble_list = CALLOC(ind->pdu_list[i].num_preamble, sizeof(nfapi_nr_prach_indication_preamble_t));
+      AssertFatal(rach_ind->pdu_list[i].preamble_list != NULL, "Memory not allocated for rach_ind->pdu_list[i].preamble_list  in phy_nr_rach_indication.");
+      for (int j = 0; j < ind->number_of_pdus; j++)
+      {
+        rach_ind->pdu_list[i].preamble_list[j].preamble_index = ind->pdu_list[i].preamble_list[j].preamble_index;
+        rach_ind->pdu_list[i].preamble_list[j].timing_advance = ind->pdu_list[i].preamble_list[j].timing_advance;
+      }
+    }
+    if (!put_queue(&gnb_rach_ind_queue, rach_ind))
+    {
+      LOG_E(NR_MAC, "Put_queue failed for rach_ind\n");
+      for (int i = 0; i < ind->number_of_pdus; i++)
+      {
+        free(rach_ind->pdu_list[i].preamble_list);
+      }
+      free(rach_ind->pdu_list);
+      free(rach_ind);
+    }
+  }
+  else {
+    LOG_E(NR_MAC, "NFAPI_MODE = %d not NFAPI_MODE_VNF(2)\n", nfapi_getmode());
+  }
+  return 1;
+}
+
+int phy_nr_uci_indication(nfapi_nr_uci_indication_t *ind)
+{
+
+  LOG_I(NR_MAC, "In %s() NFAPI SFN/SF: %d/%d number_of_pdus :%u\n",
+          __FUNCTION__,ind->sfn, ind->slot, ind->num_ucis);
+  if(NFAPI_MODE == NFAPI_MODE_VNF)
+  {
+    nfapi_nr_uci_indication_t *uci_ind = CALLOC(1, sizeof(*uci_ind));
+    AssertFatal(uci_ind != NULL, "Memory not allocated for uci_ind in phy_nr_uci_indication.");
+    *uci_ind = *ind;
+
+    uci_ind->uci_list = CALLOC(NFAPI_NR_UCI_IND_MAX_PDU, sizeof(nfapi_nr_uci_t));
+    AssertFatal(uci_ind->uci_list != NULL, "Memory not allocated for uci_ind->uci_list in phy_nr_uci_indication.");
+    for (int i = 0; i < ind->num_ucis; i++)
+    {
+      uci_ind->uci_list[i] = ind->uci_list[i];
+
+      switch (uci_ind->uci_list[i].pdu_type) {
+        case NFAPI_NR_UCI_PUSCH_PDU_TYPE:
+          LOG_E(MAC, "%s(): unhandled NFAPI_NR_UCI_PUSCH_PDU_TYPE\n", __func__);
+          break;
+
+        case NFAPI_NR_UCI_FORMAT_0_1_PDU_TYPE: {
+          nfapi_nr_uci_pucch_pdu_format_0_1_t *uci_ind_pdu = &uci_ind->uci_list[i].pucch_pdu_format_0_1;
+          nfapi_nr_uci_pucch_pdu_format_0_1_t *ind_pdu = &ind->uci_list[i].pucch_pdu_format_0_1;
+          if (ind_pdu->sr) {
+            uci_ind_pdu->sr = CALLOC(1, sizeof(*uci_ind_pdu->sr));
+            AssertFatal(uci_ind_pdu->sr != NULL, "Memory not allocated for uci_ind_pdu->harq in phy_nr_uci_indication.");
+            *uci_ind_pdu->sr = *ind_pdu->sr;
+          }
+          if (ind_pdu->harq) {
+            uci_ind_pdu->harq = CALLOC(1, sizeof(*uci_ind_pdu->harq));
+            AssertFatal(uci_ind_pdu->harq != NULL, "Memory not allocated for uci_ind_pdu->harq in phy_nr_uci_indication.");
+
+            *uci_ind_pdu->harq = *ind_pdu->harq;
+            uci_ind_pdu->harq->harq_list = CALLOC(uci_ind_pdu->harq->num_harq, sizeof(*uci_ind_pdu->harq->harq_list));
+            AssertFatal(uci_ind_pdu->harq->harq_list != NULL, "Memory not allocated for uci_ind_pdu->harq->harq_list in phy_nr_uci_indication.");
+            for (int j = 0; j < uci_ind_pdu->harq->num_harq; j++)
+                uci_ind_pdu->harq->harq_list[j].harq_value =  ind_pdu->harq->harq_list[j].harq_value;
+          }
+          break;
+        }
+
+        case NFAPI_NR_UCI_FORMAT_2_3_4_PDU_TYPE: {
+          nfapi_nr_uci_pucch_pdu_format_2_3_4_t *uci_ind_pdu = &uci_ind->uci_list[i].pucch_pdu_format_2_3_4;
+          nfapi_nr_uci_pucch_pdu_format_2_3_4_t *ind_pdu = &ind->uci_list[i].pucch_pdu_format_2_3_4;
+          
+          uci_ind_pdu->harq.harq_payload = CALLOC(1, sizeof(*uci_ind_pdu->harq.harq_payload));
+          AssertFatal(uci_ind_pdu->harq.harq_payload != NULL, "Memory not allocated for uci_ind_pdu->harq.harq_payload in phy_nr_uci_indication.");
+          *uci_ind_pdu->harq.harq_payload =  *ind_pdu->harq.harq_payload;
+
+
+          uci_ind_pdu->csi_part1.csi_part1_payload = CALLOC(1, sizeof(*uci_ind_pdu->csi_part1.csi_part1_payload));
+          AssertFatal(uci_ind_pdu->csi_part1.csi_part1_payload != NULL, "Memory not allocated for uci_ind_pdu->csi_part1.csi_part1_payload in phy_nr_uci_indication.");
+          *uci_ind_pdu->csi_part1.csi_part1_payload =  *ind_pdu->csi_part1.csi_part1_payload;
+
+
+          uci_ind_pdu->csi_part2.csi_part2_payload = CALLOC(1, sizeof(*uci_ind_pdu->csi_part2.csi_part2_payload));
+          AssertFatal(uci_ind_pdu->csi_part2.csi_part2_payload != NULL, "Memory not allocated for uci_ind_pdu->csi_part2.csi_part2_payload in phy_nr_uci_indication.");
+          *uci_ind_pdu->csi_part2.csi_part2_payload =  *ind_pdu->csi_part2.csi_part2_payload;
+
+          break;
+        }
+      }
+    }
+
+    if (!put_queue(&gnb_uci_ind_queue, uci_ind))
+    {
+      LOG_E(NR_MAC, "Put_queue failed for uci_ind\n");
+      for (int i = 0; i < ind->num_ucis; i++)
+      {
+          if (uci_ind->uci_list[i].pdu_type == NFAPI_NR_UCI_FORMAT_0_1_PDU_TYPE)
+          {
+            if (uci_ind->uci_list[i].pucch_pdu_format_0_1.harq) {
+              free(uci_ind->uci_list[i].pucch_pdu_format_0_1.harq->harq_list);
+              uci_ind->uci_list[i].pucch_pdu_format_0_1.harq->harq_list = NULL;
+              free(uci_ind->uci_list[i].pucch_pdu_format_0_1.harq);
+              uci_ind->uci_list[i].pucch_pdu_format_0_1.harq = NULL;
+            }
+            if (uci_ind->uci_list[i].pucch_pdu_format_0_1.sr) {
+              free(uci_ind->uci_list[i].pucch_pdu_format_0_1.sr);
+              uci_ind->uci_list[i].pucch_pdu_format_0_1.sr = NULL;
+            }
+          }
+          if (uci_ind->uci_list[i].pdu_type == NFAPI_NR_UCI_FORMAT_2_3_4_PDU_TYPE)
+          {
+            free(uci_ind->uci_list[i].pucch_pdu_format_2_3_4.harq.harq_payload);
+            free(uci_ind->uci_list[i].pucch_pdu_format_2_3_4.csi_part1.csi_part1_payload);
+            free(uci_ind->uci_list[i].pucch_pdu_format_2_3_4.csi_part2.csi_part2_payload);
+          }
+      }
+      free(uci_ind->uci_list);
+      uci_ind->uci_list = NULL;
+      free(uci_ind);
+      uci_ind = NULL;
+    }
+  }
+  else {
+    LOG_E(NR_MAC, "NFAPI_MODE = %d not NFAPI_MODE_VNF(2)\n", nfapi_getmode());
+  }
+  return 1;
+}
+
 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);
+  AssertFatal(pthread_mutex_lock(&eNB->UL_INFO_mutex)==0, "Mutex lock failed");
   if(NFAPI_MODE == NFAPI_MODE_VNF){
-    int8_t index = -1;
-    for(uint8_t i= 0;i< NUM_NFPAI_SUBFRAME;i++){
-      if((UL_RCC_INFO.harq_ind[i].header.message_id == 0) && (index == -1)){
-        index = i;
-        break;
-      }
-    }
-    if(index == -1){
-      LOG_E(MAC,"phy_harq_indication : num of harq reach max \n");
-      pthread_mutex_unlock(&eNB->UL_INFO_mutex);
-      return 0;
-    }
+    int8_t index = NFAPI_SFNSF2SF(ind->sfn_sf);
+
     UL_RCC_INFO.harq_ind[index] = *ind;
 
-    if (ind->harq_indication_body.number_of_harqs > 0)
-      UL_RCC_INFO.harq_ind[index].harq_indication_body.harq_pdu_list = malloc(sizeof(nfapi_harq_indication_pdu_t)*ind->harq_indication_body.number_of_harqs );
+    assert(ind->harq_indication_body.number_of_harqs <= NFAPI_HARQ_IND_MAX_PDU);
+    if (ind->harq_indication_body.number_of_harqs > 0) {
+      UL_RCC_INFO.harq_ind[index].harq_indication_body.harq_pdu_list = malloc(sizeof(nfapi_harq_indication_pdu_t) * NFAPI_HARQ_IND_MAX_PDU);
+    }
     for (int i=0; i<ind->harq_indication_body.number_of_harqs; i++) {
         memcpy(&UL_RCC_INFO.harq_ind[index].harq_indication_body.harq_pdu_list[i], &ind->harq_indication_body.harq_pdu_list[i], sizeof(nfapi_harq_indication_pdu_t));
     }
   }else{
-  eNB->UL_INFO.harq_ind = *ind;
-  eNB->UL_INFO.harq_ind.harq_indication_body.harq_pdu_list = eNB->harq_pdu_list;
+    eNB->UL_INFO.harq_ind = *ind;
+    eNB->UL_INFO.harq_ind.harq_indication_body.harq_pdu_list = eNB->harq_pdu_list;
 
-  for (int i=0; i<ind->harq_indication_body.number_of_harqs; i++) {
-    memcpy(&eNB->UL_INFO.harq_ind.harq_indication_body.harq_pdu_list[i], &ind->harq_indication_body.harq_pdu_list[i], sizeof(eNB->UL_INFO.harq_ind.harq_indication_body.harq_pdu_list[i]));
-  }
+    assert(ind->harq_indication_body.number_of_harqs <= NFAPI_HARQ_IND_MAX_PDU);
+    for (int i=0; i<ind->harq_indication_body.number_of_harqs; i++) {
+      memcpy(&eNB->UL_INFO.harq_ind.harq_indication_body.harq_pdu_list[i],
+             &ind->harq_indication_body.harq_pdu_list[i],
+             sizeof(eNB->UL_INFO.harq_ind.harq_indication_body.harq_pdu_list[i]));
+    }
   }
-  pthread_mutex_unlock(&eNB->UL_INFO_mutex);
+  AssertFatal(pthread_mutex_unlock(&eNB->UL_INFO_mutex)==0, "Mutex unlock failed");
   // vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data);
   //mac_harq_ind(p7_vnf->mac, ind);
   return 1;
@@ -761,28 +892,18 @@ int phy_harq_indication(struct nfapi_vnf_p7_config *config, nfapi_harq_indicatio
 
 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);
+  AssertFatal(pthread_mutex_lock(&eNB->UL_INFO_mutex)==0, "Mutex lock failed");
   if(NFAPI_MODE == NFAPI_MODE_VNF){
-    int8_t index = -1;
-    for(uint8_t i= 0;i< NUM_NFPAI_SUBFRAME;i++){
-      if((UL_RCC_INFO.crc_ind[i].header.message_id == 0) && (index == -1)){
-        index = i;
-      }
-      if(UL_RCC_INFO.rx_ind[i].sfn_sf == ind->sfn_sf){
-        index = i;
-        break;
-      }
-    }
-    if(index == -1){
-      LOG_E(MAC,"phy_crc_indication : num of crc reach max \n");
-      pthread_mutex_unlock(&eNB->UL_INFO_mutex);
-      return 0;
-    }
+    int8_t index = NFAPI_SFNSF2SF(ind->sfn_sf);
+
     UL_RCC_INFO.crc_ind[index] = *ind;
 
-    if (ind->crc_indication_body.number_of_crcs > 0)
-      UL_RCC_INFO.crc_ind[index].crc_indication_body.crc_pdu_list = malloc(sizeof(nfapi_crc_indication_pdu_t)*ind->crc_indication_body.number_of_crcs );
+    assert(ind->crc_indication_body.number_of_crcs <= NFAPI_CRC_IND_MAX_PDU);
+    if (ind->crc_indication_body.number_of_crcs > 0) {
+      UL_RCC_INFO.crc_ind[index].crc_indication_body.crc_pdu_list = malloc(sizeof(nfapi_crc_indication_pdu_t) * NFAPI_CRC_IND_MAX_PDU);
+    }
 
+    assert(ind->crc_indication_body.number_of_crcs <= NFAPI_CRC_IND_MAX_PDU);
     for (int i=0; i<ind->crc_indication_body.number_of_crcs; i++) {
       memcpy(&UL_RCC_INFO.crc_ind[index].crc_indication_body.crc_pdu_list[i], &ind->crc_indication_body.crc_pdu_list[i], sizeof(ind->crc_indication_body.crc_pdu_list[0]));
 
@@ -804,6 +925,7 @@ int phy_crc_indication(struct nfapi_vnf_p7_config *config, nfapi_crc_indication_
     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);
 
+  assert(ind->crc_indication_body.number_of_crcs <= NFAPI_CRC_IND_MAX_PDU);
   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",
@@ -814,12 +936,54 @@ int phy_crc_indication(struct nfapi_vnf_p7_config *config, nfapi_crc_indication_
           eNB->UL_INFO.crc_ind.crc_indication_body.crc_pdu_list[i].rx_ue_information.rnti);
   }
   }
-  pthread_mutex_unlock(&eNB->UL_INFO_mutex);
+  AssertFatal(pthread_mutex_unlock(&eNB->UL_INFO_mutex)==0, "Mutex unlock failed");
   // vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data);
   //mac_crc_ind(p7_vnf->mac, ind);
   return 1;
 }
 
+int phy_nr_crc_indication(nfapi_nr_crc_indication_t *ind) {
+
+  LOG_I(NR_MAC, "In %s() NFAPI SFN/SF: %d/%d number_of_pdus :%u\n",
+          __FUNCTION__,ind->sfn, ind->slot, ind->number_crcs);
+
+  if(NFAPI_MODE == NFAPI_MODE_VNF)
+  {
+    nfapi_nr_crc_indication_t *crc_ind = CALLOC(1, sizeof(*crc_ind));
+    crc_ind->header.message_id = ind->header.message_id;
+    crc_ind->number_crcs = ind->number_crcs;
+    crc_ind->sfn = ind->sfn;
+    crc_ind->slot = ind->slot;
+    if (ind->number_crcs > 0) {
+      crc_ind->crc_list = CALLOC(NFAPI_NR_CRC_IND_MAX_PDU, sizeof(nfapi_nr_crc_t));
+      AssertFatal(crc_ind->crc_list != NULL, "Memory not allocated for crc_ind->crc_list in phy_nr_crc_indication.");
+    }
+    for (int j = 0; j < ind->number_crcs; j++)
+    {
+      crc_ind->crc_list[j].handle = ind->crc_list[j].handle;
+      crc_ind->crc_list[j].harq_id = ind->crc_list[j].harq_id;
+      crc_ind->crc_list[j].num_cb = ind->crc_list[j].num_cb;
+      crc_ind->crc_list[j].rnti = ind->crc_list[j].rnti;
+      crc_ind->crc_list[j].tb_crc_status = ind->crc_list[j].tb_crc_status;
+      crc_ind->crc_list[j].timing_advance = ind->crc_list[j].timing_advance;
+      crc_ind->crc_list[j].ul_cqi = ind->crc_list[j].ul_cqi;
+      LOG_I(NR_MAC, "Received crc_ind.harq_id = %d for %d index SFN SLot %u %u with rnti %x\n",
+                    ind->crc_list[j].harq_id, j, ind->sfn, ind->slot, ind->crc_list[j].rnti);
+    }
+    if (!put_queue(&gnb_crc_ind_queue, crc_ind))
+    {
+      LOG_E(NR_MAC, "Put_queue failed for crc_ind\n");
+      free(crc_ind->crc_list);
+      free(crc_ind);
+    }
+  }
+  else
+  {
+    LOG_E(NR_MAC, "NFAPI_MODE = %d not NFAPI_MODE_VNF(2)\n", nfapi_getmode());
+  }
+  return 1;
+}
+
 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];
 
@@ -827,51 +991,40 @@ int phy_rx_indication(struct nfapi_vnf_p7_config *config, nfapi_rx_indication_t
     LOG_D(MAC, "%s() NFAPI SFN/SF:%d number_of_pdus:%u\n", __FUNCTION__, NFAPI_SFNSF2DEC(ind->sfn_sf), ind->rx_indication_body.number_of_pdus);
   }
 
-  pthread_mutex_lock(&eNB->UL_INFO_mutex);
+  AssertFatal(pthread_mutex_lock(&eNB->UL_INFO_mutex)==0, "Mutex lock failed");
   if(NFAPI_MODE == NFAPI_MODE_VNF){
-    int8_t index = -1;
-    for(uint8_t i= 0;i< NUM_NFPAI_SUBFRAME;i++){
-      if((UL_RCC_INFO.rx_ind[i].header.message_id == 0) && (index == -1)){
-        index = i;
-      }
-      if(UL_RCC_INFO.crc_ind[i].sfn_sf == ind->sfn_sf){
-        index = i;
-        break;
-      }
-    }
-    if(index == -1){
-      LOG_E(MAC,"phy_rx_indication : num of rx reach max \n");
-      pthread_mutex_unlock(&eNB->UL_INFO_mutex);
-      return 0;
-    }
+    int8_t index = NFAPI_SFNSF2SF(ind->sfn_sf);
+
     UL_RCC_INFO.rx_ind[index] = *ind;
 
-    if (ind->rx_indication_body.number_of_pdus > 0)
-      UL_RCC_INFO.rx_ind[index].rx_indication_body.rx_pdu_list = malloc(sizeof(nfapi_rx_indication_pdu_t)*ind->rx_indication_body.number_of_pdus );
+    size_t number_of_pdus = ind->rx_indication_body.number_of_pdus;
+    assert(number_of_pdus <= NFAPI_RX_IND_MAX_PDU);
+
+    if (number_of_pdus > 0) {
+      UL_RCC_INFO.rx_ind[index].rx_indication_body.rx_pdu_list =
+          malloc(sizeof(nfapi_rx_indication_pdu_t) * NFAPI_RX_IND_MAX_PDU);
+    }
 
-    for (int i=0; i<ind->rx_indication_body.number_of_pdus; i++) {
+    for (int i=0; i<number_of_pdus; i++) {
       nfapi_rx_indication_pdu_t *dest_pdu = &UL_RCC_INFO.rx_ind[index].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
       if(dest_pdu->rx_indication_rel8.length > 0){
-        dest_pdu->data = malloc(dest_pdu->rx_indication_rel8.length);
-        memcpy(dest_pdu->data, src_pdu->data, dest_pdu->rx_indication_rel8.length);
-      }else{
-        dest_pdu->data = NULL;
+        assert(dest_pdu->rx_indication_rel8.length <= NFAPI_RX_IND_DATA_MAX);
+        memcpy(dest_pdu->rx_ind_data, src_pdu->rx_ind_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",
+      LOG_D(PHY, "%s() NFAPI SFN/SF:%d PDUs:%zu [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,
+          NFAPI_SFNSF2DEC(ind->sfn_sf), 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
+          dest_pdu->rx_ind_data
           );
     }
   }else{
@@ -880,13 +1033,15 @@ int phy_rx_indication(struct nfapi_vnf_p7_config *config, nfapi_rx_indication_t
   *dest_ind = *ind;
   dest_ind->rx_indication_body.rx_pdu_list = dest_pdu_list;
 
+  assert(ind->rx_indication_body.number_of_pdus <= NFAPI_RX_IND_MAX_PDU);
   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);
+
+    assert(dest_pdu->rx_indication_rel8.length <= NFAPI_RX_IND_DATA_MAX);
+    memcpy(dest_pdu->rx_ind_data, src_pdu->rx_ind_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,
@@ -896,15 +1051,57 @@ int phy_rx_indication(struct nfapi_vnf_p7_config *config, nfapi_rx_indication_t
           dest_pdu->rx_indication_rel8.offset,
           dest_pdu->rx_indication_rel8.ul_cqi,
           dest_pdu->rx_indication_rel8.timing_advance,
-          dest_pdu->data
+          dest_pdu->rx_ind_data
          );
   }
   }
-  pthread_mutex_unlock(&eNB->UL_INFO_mutex);
+  AssertFatal(pthread_mutex_unlock(&eNB->UL_INFO_mutex)==0, "Mutex unlock failed");
   // vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data);
   //mac_rx_ind(p7_vnf->mac, ind);
   return 1;
 }
+
+int phy_nr_rx_data_indication(nfapi_nr_rx_data_indication_t *ind) {
+
+  LOG_I(NR_MAC, "In %s() NFAPI SFN/SF: %d/%d number_of_pdus :%u, and pdu %p\n",
+          __FUNCTION__,ind->sfn, ind->slot, ind->number_of_pdus, ind->pdu_list[0].pdu);
+
+  if(NFAPI_MODE == NFAPI_MODE_VNF)
+  {
+    nfapi_nr_rx_data_indication_t *rx_ind = CALLOC(1, sizeof(*rx_ind));
+    rx_ind->header.message_id = ind->header.message_id;
+    rx_ind->sfn = ind->sfn;
+    rx_ind->slot = ind->slot;
+    rx_ind->number_of_pdus = ind->number_of_pdus;
+
+    if (ind->number_of_pdus > 0) {
+      rx_ind->pdu_list = CALLOC(NFAPI_NR_RX_DATA_IND_MAX_PDU, sizeof(nfapi_nr_rx_data_pdu_t));
+      AssertFatal(rx_ind->pdu_list != NULL, "Memory not allocated for rx_ind->pdu_list in phy_nr_rx_data_indication.");
+    }
+    for (int j = 0; j < ind->number_of_pdus; j++)
+    {
+      rx_ind->pdu_list[j].handle = ind->pdu_list[j].handle;
+      rx_ind->pdu_list[j].harq_id = ind->pdu_list[j].harq_id;
+      rx_ind->pdu_list[j].pdu = ind->pdu_list[j].pdu;
+      rx_ind->pdu_list[j].pdu_length = ind->pdu_list[j].pdu_length;
+      rx_ind->pdu_list[j].rnti = ind->pdu_list[j].rnti;
+      rx_ind->pdu_list[j].timing_advance = ind->pdu_list[j].timing_advance;
+      rx_ind->pdu_list[j].ul_cqi = ind->pdu_list[j].ul_cqi;
+    }
+    if (!put_queue(&gnb_rx_ind_queue, rx_ind))
+    {
+      LOG_E(NR_MAC, "Put_queue failed for rx_ind\n");
+      free(rx_ind->pdu_list);
+      free(rx_ind);
+    }
+  }
+  else
+  {
+    LOG_E(NR_MAC, "NFAPI_MODE = %d not NFAPI_MODE_VNF(2)\n", nfapi_getmode());
+  }
+  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);
@@ -914,25 +1111,18 @@ int phy_srs_indication(struct nfapi_vnf_p7_config *config, nfapi_srs_indication_
 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);
+  AssertFatal(pthread_mutex_lock(&eNB->UL_INFO_mutex)==0, "Mutex lock failed");
   if(NFAPI_MODE == NFAPI_MODE_VNF){
-    int8_t index = -1;
-    for(uint8_t i= 0;i< NUM_NFPAI_SUBFRAME;i++){
-      if((UL_RCC_INFO.sr_ind[i].header.message_id == 0) && (index == -1)){
-        index = i;
-        break;
-      }
-    }
-    if(index == -1){
-      LOG_E(MAC,"phy_sr_indication : num of sr reach max \n");
-      pthread_mutex_unlock(&eNB->UL_INFO_mutex);
-      return 0;
-    }
+    int8_t index = NFAPI_SFNSF2SF(ind->sfn_sf);
+
     UL_RCC_INFO.sr_ind[index] = *ind;
     LOG_D(MAC,"%s() UL_INFO[%d].sr_ind.sr_indication_body.number_of_srs:%d\n", __FUNCTION__, index, eNB->UL_INFO.sr_ind.sr_indication_body.number_of_srs);
-    if (ind->sr_indication_body.number_of_srs > 0)
-      UL_RCC_INFO.sr_ind[index].sr_indication_body.sr_pdu_list = malloc(sizeof(nfapi_sr_indication_pdu_t)*ind->sr_indication_body.number_of_srs );
+    if (ind->sr_indication_body.number_of_srs > 0) {
+      assert(ind->sr_indication_body.number_of_srs <= NFAPI_SR_IND_MAX_PDU);
+      UL_RCC_INFO.sr_ind[index].sr_indication_body.sr_pdu_list = malloc(sizeof(nfapi_sr_indication_pdu_t) * NFAPI_SR_IND_MAX_PDU);
+    }
 
+    assert(ind->sr_indication_body.number_of_srs <= NFAPI_SR_IND_MAX_PDU);
     for (int i=0; i<ind->sr_indication_body.number_of_srs; i++) {
         nfapi_sr_indication_pdu_t *dest_pdu = &UL_RCC_INFO.sr_ind[index].sr_indication_body.sr_pdu_list[i];
         nfapi_sr_indication_pdu_t *src_pdu = &ind->sr_indication_body.sr_pdu_list[i];
@@ -948,6 +1138,7 @@ int phy_sr_indication(struct nfapi_vnf_p7_config *config, nfapi_sr_indication_t
   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);
 
+  assert(eNB->UL_INFO.sr_ind.sr_indication_body.number_of_srs <= NFAPI_SR_IND_MAX_PDU);
   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];
@@ -955,36 +1146,63 @@ int phy_sr_indication(struct nfapi_vnf_p7_config *config, nfapi_sr_indication_t
     memcpy(dest_pdu, src_pdu, sizeof(*src_pdu));
   }
   }
-  pthread_mutex_unlock(&eNB->UL_INFO_mutex);
+  AssertFatal(pthread_mutex_unlock(&eNB->UL_INFO_mutex)==0, "Mutex unlock failed");
   // vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data);
   //mac_sr_ind(p7_vnf->mac, ind);
   return 1;
 }
 
+static bool is_ue_same(uint16_t ue_id_1, uint16_t ue_id_2)
+{
+  return (ue_id_1 == ue_id_2);
+}
+
+static void analyze_cqi_pdus_for_duplicates(nfapi_cqi_indication_t *ind)
+{
+  uint16_t num_cqis = ind->cqi_indication_body.number_of_cqis;
+  assert(num_cqis <= NFAPI_CQI_IND_MAX_PDU);
+  for (int i = 0; i < num_cqis; i++)
+  {
+    nfapi_cqi_indication_pdu_t *src_pdu = &ind->cqi_indication_body.cqi_pdu_list[i];
+
+    LOG_I(MAC, "CQI_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);
+
+    for (int j = i + 1; j < num_cqis; j++)
+    {
+      uint16_t rnti_i = ind->cqi_indication_body.cqi_pdu_list[i].rx_ue_information.rnti;
+      uint16_t rnti_j = ind->cqi_indication_body.cqi_pdu_list[j].rx_ue_information.rnti;
+      if (is_ue_same(rnti_i, rnti_j))
+      {
+        LOG_E(MAC, "Problem, two cqis received from a single UE for rnti %x\n",
+              rnti_i);
+        //abort(); This will be fixed in merge request which handles multiple CQIs.
+      }
+    }
+  }
+}
+
 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);
+  AssertFatal(pthread_mutex_lock(&eNB->UL_INFO_mutex)==0, "Mutex lock failed");
   if(NFAPI_MODE == NFAPI_MODE_VNF){
-    int8_t index = -1;
-    for(uint8_t i= 0;i< NUM_NFPAI_SUBFRAME;i++){
-      if((UL_RCC_INFO.cqi_ind[i].header.message_id == 0) && (index == -1)){
-        index = i;
-        break;
-      }
-    }
-    if(index == -1){
-      LOG_E(MAC,"phy_cqi_indication : num of cqi reach max \n");
-      pthread_mutex_unlock(&eNB->UL_INFO_mutex);
-      return 0;
-    }
+    int8_t index = NFAPI_SFNSF2SF(ind->sfn_sf);
+
     UL_RCC_INFO.cqi_ind[index] = *ind;
+    assert(ind->cqi_indication_body.number_of_cqis <= NFAPI_CQI_IND_MAX_PDU);
     if (ind->cqi_indication_body.number_of_cqis > 0){
-      UL_RCC_INFO.cqi_ind[index].cqi_indication_body.cqi_pdu_list = malloc(sizeof(nfapi_cqi_indication_pdu_t)*ind->cqi_indication_body.number_of_cqis );
-      UL_RCC_INFO.cqi_ind[index].cqi_indication_body.cqi_raw_pdu_list = malloc(sizeof(nfapi_cqi_indication_raw_pdu_t)*ind->cqi_indication_body.number_of_cqis );
+      UL_RCC_INFO.cqi_ind[index].cqi_indication_body.cqi_pdu_list =
+        malloc(sizeof(nfapi_cqi_indication_pdu_t) * NFAPI_CQI_IND_MAX_PDU);
+      UL_RCC_INFO.cqi_ind[index].cqi_indication_body.cqi_raw_pdu_list =
+        malloc(sizeof(nfapi_cqi_indication_raw_pdu_t) * NFAPI_CQI_IND_MAX_PDU);
     }
+
+    analyze_cqi_pdus_for_duplicates(ind);
+
+    assert(ind->cqi_indication_body.number_of_cqis <= NFAPI_CQI_IND_MAX_PDU);
     for (int i=0; i<ind->cqi_indication_body.number_of_cqis; i++) {
         nfapi_cqi_indication_pdu_t *src_pdu = &ind->cqi_indication_body.cqi_pdu_list[i];
         LOG_D(MAC, "SR_IND[PDU:%d][rnti:%x cqi:%d channel:%d]\n", i, src_pdu->rx_ue_information.rnti,
@@ -1000,9 +1218,10 @@ int phy_cqi_indication(struct nfapi_vnf_p7_config *config, nfapi_cqi_indication_
   *dest_ind = *ind;
   dest_ind->cqi_indication_body.cqi_pdu_list = ind->cqi_indication_body.cqi_pdu_list;
   dest_ind->cqi_indication_body.cqi_raw_pdu_list = ind->cqi_indication_body.cqi_raw_pdu_list;
+  assert(ind->cqi_indication_body.number_of_cqis <= NFAPI_CQI_IND_MAX_PDU);
   for(int i=0; i<ind->cqi_indication_body.number_of_cqis; i++) {
     nfapi_cqi_indication_pdu_t *src_pdu = &ind->cqi_indication_body.cqi_pdu_list[i];
-    LOG_D(MAC, "SR_IND[PDU:%d][rnti:%x cqi:%d channel:%d]\n", i, src_pdu->rx_ue_information.rnti,
+    LOG_D(MAC, "CQI_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_ind->cqi_indication_body.cqi_pdu_list[i],
            src_pdu, sizeof(nfapi_cqi_indication_pdu_t));
@@ -1010,79 +1229,34 @@ int phy_cqi_indication(struct nfapi_vnf_p7_config *config, nfapi_cqi_indication_
            &ind->cqi_indication_body.cqi_raw_pdu_list[i], sizeof(nfapi_cqi_indication_raw_pdu_t));
   }
   }
-  pthread_mutex_unlock(&eNB->UL_INFO_mutex);
+  AssertFatal(pthread_mutex_unlock(&eNB->UL_INFO_mutex)==0, "Mutex unlock failed");
   return 1;
 }
 
 //NR phy indication
 
 int phy_nr_slot_indication(nfapi_nr_slot_indication_scf_t *ind) {
-  
-  uint8_t vnf_slot_ahead = 2;
-  uint32_t vnf_sfn_slot = sfnslot_add_slot(ind->sfn, ind->slot, vnf_slot_ahead);
-	uint16_t vnf_sfn = NFAPI_SFNSLOT2SFN(vnf_sfn_slot);
-	uint8_t vnf_slot = NFAPI_SFNSLOT2SLOT(vnf_sfn_slot); //offsetting the vnf from pnf by vnf_slot_head slots
-  struct PHY_VARS_gNB_s *gNB = RC.gNB[0];
-  pthread_mutex_lock(&gNB->UL_INFO_mutex);
-  gNB->UL_INFO.frame     = vnf_sfn;
-	gNB->UL_INFO.slot      = vnf_slot;	
-  pthread_mutex_unlock(&gNB->UL_INFO_mutex);
-  LOG_D(MAC, "VNF SFN/Slot %d.%d \n", gNB->UL_INFO.frame, gNB->UL_INFO.slot);
-
-  return 1;
-}
-
-int phy_nr_crc_indication(nfapi_nr_crc_indication_t *ind) {
-  struct PHY_VARS_gNB_s *gNB = RC.gNB[0];
-  pthread_mutex_lock(&gNB->UL_INFO_mutex);
-
-  gNB->UL_INFO.crc_ind = *ind;
-
-  if (ind->number_crcs > 0)
-    gNB->UL_INFO.crc_ind.crc_list = malloc(sizeof(nfapi_nr_crc_t)*ind->number_crcs);
-
-  for (int i=0; i<ind->number_crcs; i++)
-    memcpy(&gNB->UL_INFO.crc_ind.crc_list[i], &ind->crc_list[i], sizeof(ind->crc_list[0]));
-
-  pthread_mutex_unlock(&gNB->UL_INFO_mutex);
-
-  return 1;
-}
-
-int phy_nr_rx_data_indication(nfapi_nr_rx_data_indication_t *ind) {
-  struct PHY_VARS_gNB_s *gNB = RC.gNB[0];
-  pthread_mutex_lock(&gNB->UL_INFO_mutex);
-
-  gNB->UL_INFO.rx_ind = *ind;
-
-  if (ind->number_of_pdus > 0)
-    gNB->UL_INFO.rx_ind.pdu_list = malloc(sizeof(nfapi_nr_rx_data_pdu_t)*ind->number_of_pdus);
-
-  for (int i=0; i<ind->number_of_pdus; i++) 
-    memcpy(&gNB->UL_INFO.rx_ind.pdu_list[i], &ind->pdu_list[i], sizeof(ind->pdu_list[0]));
-
 
-  pthread_mutex_unlock(&gNB->UL_INFO_mutex);
+  uint8_t vnf_slot_ahead = 0;
+  uint32_t vnf_sfn_slot = sfnslot_add_slot(ind->sfn, ind->slot, vnf_slot_ahead);
+  uint16_t vnf_sfn = NFAPI_SFNSLOT2SFN(vnf_sfn_slot);
+  uint8_t vnf_slot = NFAPI_SFNSLOT2SLOT(vnf_sfn_slot);
+  LOG_D(MAC, "VNF SFN/Slot %d.%d \n", vnf_sfn, vnf_slot);
+
+  nfapi_nr_slot_indication_scf_t *nr_slot_ind = CALLOC(1, sizeof(*nr_slot_ind));
+  nr_slot_ind->header = ind->header;
+  nr_slot_ind->sfn = vnf_sfn;
+  nr_slot_ind->slot = vnf_slot;
+  if (!put_queue(&gnb_slot_ind_queue, nr_slot_ind))
+  {
+    LOG_E(NR_MAC, "Put_queue failed for slot_ind\n");
+    free(nr_slot_ind);
+    nr_slot_ind = NULL;
+  }
 
   return 1;
 }
 
-int phy_nr_uci_indication(nfapi_nr_uci_indication_t *ind) {
-  struct PHY_VARS_gNB_s *gNB = RC.gNB[0];
-  pthread_mutex_lock(&gNB->UL_INFO_mutex);
-
-  gNB->UL_INFO.uci_ind = *ind;
-
-  if (ind->num_ucis > 0)
-    gNB->UL_INFO.uci_ind.uci_list = malloc(sizeof(nfapi_nr_uci_t)*ind->num_ucis);
-
-  for (int i=0; i<ind->num_ucis; i++)
-    memcpy(&gNB->UL_INFO.uci_ind.uci_list[i], &ind->uci_list[i], sizeof(ind->uci_list[0]));
-  //printf("UCI ind written to UL_info: num_ucis: %d, PDU_type : %d. \n", ind->num_ucis, ind->uci_list[0].pdu_type);
-  pthread_mutex_unlock(&gNB->UL_INFO_mutex);
-
-  return 1;
-}
 
 int phy_nr_srs_indication(nfapi_nr_srs_indication_t *ind) {
   struct PHY_VARS_gNB_s *gNB = RC.gNB[0];
@@ -1106,30 +1280,6 @@ int phy_nr_srs_indication(nfapi_nr_srs_indication_t *ind) {
 
   return 1;
 }
-
-int phy_nr_rach_indication(nfapi_nr_rach_indication_t *ind) {
-  struct PHY_VARS_gNB_s *gNB = RC.gNB[0];
-  pthread_mutex_lock(&gNB->UL_INFO_mutex);
-
-  gNB->UL_INFO.rach_ind = *ind;
-
-  if (ind->number_of_pdus > 0)
-    gNB->UL_INFO.rach_ind.pdu_list = malloc(sizeof(nfapi_nr_prach_indication_pdu_t)*ind->number_of_pdus);
-
-  for (int i=0; i<ind->number_of_pdus; i++) {
-    memcpy(&gNB->UL_INFO.rach_ind.pdu_list[i], &ind->pdu_list[i], sizeof(ind->pdu_list[0]));
-
-    LOG_D(MAC, "%s() NFAPI SFN/Slot:%d.%d RACH_IND:number_of_pdus:%d UL_INFO:pdus:%d\n",
-        __FUNCTION__,
-        ind->sfn,ind->slot, ind->number_of_pdus, gNB->UL_INFO.rach_ind.number_of_pdus
-        );
-  }
-
-  pthread_mutex_unlock(&gNB->UL_INFO_mutex);
-
-  return 1;
-}
-
 //end NR phy indication
 
 int phy_lbt_dl_indication(struct nfapi_vnf_p7_config *config, nfapi_lbt_dl_indication_t *ind) {
@@ -1171,9 +1321,9 @@ void vnf_trace(nfapi_trace_level_t nfapi_level, const char *message, ...) {
 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);
+    //NFAPI_TRACE(NFAPI_TRACE_INFO, "[VNF] vendor_ext (error_code:%d)\n", ind->error_code);
   } else {
-    printf("[VNF] unknown %02x\n", msg->message_id);
+    NFAPI_TRACE(NFAPI_TRACE_INFO, "[VNF] unknown %02x\n", msg->message_id);
   }
 
   return 0;
@@ -1263,7 +1413,7 @@ static pthread_t vnf_start_pthread;
 static pthread_t vnf_p7_start_pthread;
 
 void *vnf_nr_p7_start_thread(void *ptr) {
-  printf("%s()\n", __FUNCTION__);
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "%s()\n", __FUNCTION__);
   pthread_setname_np(pthread_self(), "VNF_P7");
   nfapi_vnf_p7_config_t *config = (nfapi_vnf_p7_config_t *)ptr;
   nfapi_nr_vnf_p7_start(config);
@@ -1271,7 +1421,7 @@ void *vnf_nr_p7_start_thread(void *ptr) {
 }
 
 void *vnf_p7_start_thread(void *ptr) {
-  printf("%s()\n", __FUNCTION__);
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "%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_start(config);
@@ -1282,30 +1432,31 @@ void set_thread_priority(int priority);
 
 void *vnf_nr_p7_thread_start(void *ptr) {
   set_thread_priority(79);
+  init_queue(&gnb_rach_ind_queue);
+  init_queue(&gnb_rx_ind_queue);
+  init_queue(&gnb_crc_ind_queue);
+  init_queue(&gnb_uci_ind_queue);
+  init_queue(&gnb_slot_ind_queue);
+
   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->slot_indication = &phy_slot_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->nr_crc_indication = &phy_nr_crc_indication;
+  p7_vnf->config->nr_rx_data_indication = &phy_nr_rx_data_indication;
+  p7_vnf->config->nr_rach_indication = &phy_nr_rach_indication;
+  p7_vnf->config->nr_uci_indication = &phy_nr_uci_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->nr_crc_indication = &phy_nr_crc_indication;
-  p7_vnf->config->nr_slot_indication = &phy_nr_slot_indication;  
-  p7_vnf->config->nr_rx_data_indication = &phy_nr_rx_data_indication;
-  p7_vnf->config->nr_uci_indication = &phy_nr_uci_indication;
-  p7_vnf->config->nr_rach_indication = &phy_nr_rach_indication;
+  p7_vnf->config->nr_slot_indication = &phy_nr_slot_indication;
   p7_vnf->config->nr_srs_indication = &phy_nr_srs_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;
@@ -1342,7 +1493,6 @@ 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;
@@ -1364,7 +1514,7 @@ int pnf_nr_start_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_nr_pnf_st
   vnf_p7_info *p7_vnf = vnf->p7_vnfs;
   pnf_info *pnf = vnf->pnfs;
   nfapi_nr_param_request_scf_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);
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "[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;
@@ -1375,7 +1525,7 @@ int pnf_nr_start_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_nr_pnf_st
   }
 
   // start all the phys in the pnf.
-  printf("[VNF] Sending NFAPI_VNF_PARAM_REQUEST phy_id:%d\n", pnf->phys[0].id);
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "[VNF] Sending NFAPI_VNF_PARAM_REQUEST phy_id:%d\n", pnf->phys[0].id);
   memset(&req, 0, sizeof(req));
   req.header.message_id = NFAPI_NR_PHY_MSG_TYPE_PARAM_REQUEST;
   req.header.phy_id = pnf->phys[0].id;
@@ -1388,7 +1538,7 @@ int pnf_start_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_pnf_start_re
   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);
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "[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;
@@ -1399,7 +1549,7 @@ int pnf_start_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_pnf_start_re
   }
 
   // start all the phys in the pnf.
-  printf("[VNF] Sending NFAPI_VNF_PARAM_REQUEST phy_id:%d\n", pnf->phys[0].id);
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "[VNF] Sending NFAPI_VNF_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;
@@ -1411,37 +1561,38 @@ extern uint32_t to_earfcn(int eutra_bandP,uint32_t dl_CarrierFreq,uint32_t bw);
 
 int nr_param_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_nr_param_response_scf_t *resp) {
 
-  printf("[VNF] Received NFAPI_PARAM_RESP idx:%d phy_id:%d\n", p5_idx, resp->header.phy_id);
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "[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_p7_info *p7_vnf = vnf->p7_vnfs;
   pnf_info *pnf = vnf->pnfs;
   phy_info *phy = pnf->phys;
   struct sockaddr_in pnf_p7_sockaddr;
   nfapi_nr_config_request_scf_t *req = &RC.nrmac[0]->config[0]; // check
-  phy->remote_port = 32123;//resp->nfapi_config.p7_pnf_port.value;
+  phy->remote_port = 50610;//resp->nfapi_config.p7_pnf_port.value;
+  //phy->remote_port = 32123;//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 %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,
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "[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_NR_PHY_MSG_TYPE_CONFIG_REQUEST;
   req->header.phy_id = phy->id;
-  printf("[VNF] Send NFAPI_CONFIG_REQUEST\n");
-  //printf("\n NR bandP =%d\n",req->nfapi_config.rf_bands.rf_band[0]);
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "[VNF] Send NFAPI_CONFIG_REQUEST\n");
+  //NFAPI_TRACE(NFAPI_TRACE_INFO, "\n NR bandP =%d\n",req->nfapi_config.rf_bands.rf_band[0]);
 
   req->nfapi_config.p7_vnf_port.tl.tag = NFAPI_NR_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);
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "[VNF] DJP local_port:%d\n", p7_vnf->local_port);
   req->nfapi_config.p7_vnf_address_ipv4.tl.tag = NFAPI_NR_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);
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "[VNF] DJP local_addr:%s\n", p7_vnf->local_addr);
   req->nfapi_config.timing_window.tl.tag = NFAPI_NR_NFAPI_TIMING_WINDOW_TAG;
   req->nfapi_config.timing_window.value = p7_vnf->timing_window;
-  printf("\n[VNF]Timing window tag : %d Timing window:%u\n",NFAPI_NR_NFAPI_TIMING_WINDOW_TAG, p7_vnf->timing_window);
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "\n[VNF]Timing window tag : %d Timing window:%u\n",NFAPI_NR_NFAPI_TIMING_WINDOW_TAG, p7_vnf->timing_window);
   req->num_tlv++;
 
   if(p7_vnf->periodic_timing_enabled || p7_vnf->aperiodic_timing_enabled) {
@@ -1455,7 +1606,7 @@ int nr_param_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_nr_param_resp
       req->num_tlv++;
     }
   }
-//TODO: Assign tag and value for P7 message offsets  
+//TODO: Assign tag and value for P7 message offsets
 req->nfapi_config.dl_tti_timing_offset.tl.tag = NFAPI_NR_NFAPI_DL_TTI_TIMING_OFFSET;
 req->nfapi_config.ul_tti_timing_offset.tl.tag = NFAPI_NR_NFAPI_UL_TTI_TIMING_OFFSET;
 req->nfapi_config.ul_dci_timing_offset.tl.tag = NFAPI_NR_NFAPI_UL_DCI_TIMING_OFFSET;
@@ -1473,7 +1624,7 @@ req->nfapi_config.tx_data_timing_offset.tl.tag = NFAPI_NR_NFAPI_TX_DATA_TIMING_O
 
 
 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);
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "[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_p7_info *p7_vnf = vnf->p7_vnfs;
   pnf_info *pnf = vnf->pnfs;
@@ -1484,24 +1635,24 @@ int param_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_param_response_t
   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 %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,
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "[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");
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "[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);
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "[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);
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "[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:%u\n", p7_vnf->timing_window);
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "[VNF] Timing window:%u\n", p7_vnf->timing_window);
   req->num_tlv++;
 
   if(p7_vnf->periodic_timing_enabled || p7_vnf->aperiodic_timing_enabled) {
@@ -1528,42 +1679,41 @@ int param_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_param_response_t
 
 int nr_config_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_nr_config_response_scf_t *resp) {
   nfapi_nr_start_request_scf_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");
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "[VNF] Received NFAPI_CONFIG_RESP idx:%d phy_id:%d\n", p5_idx, resp->header.phy_id);
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "[VNF] Calling oai_enb_init()\n");
   oai_enb_init(); // TODO: change to gnb
   memset(&req, 0, sizeof(req));
   req.header.message_id = NFAPI_NR_PHY_MSG_TYPE_START_REQUEST;
   req.header.phy_id = resp->header.phy_id;
   nfapi_nr_vnf_start_req(config, p5_idx, &req);
-  printf("[VNF] Send NFAPI_VNF_START_REQUEST idx:%d phy_id:%d\n", p5_idx, resp->header.phy_id);
   return 0;
 }
 
 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");
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "[VNF] Received NFAPI_CONFIG_RESP idx:%d phy_id:%d\n", p5_idx, resp->header.phy_id);
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "[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);
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "[VNF] Send NFAPI_VNF_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) {
-  printf("[VNF] Received NFAPI_START_RESP idx:%d phy_id:%d\n", p5_idx, resp->header.phy_id);
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "[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);
   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);
+  nfapi_vnf_p7_add_pnf((p7_vnf->config), phy->remote_addr, htons(phy->remote_port), phy->id);
   return 0;
 }
 
 int nr_start_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_nr_start_response_scf_t *resp) {
-  printf("[VNF] Received NFAPI_START_RESP idx:%d phy_id:%d\n", p5_idx, resp->header.phy_id);
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "[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);
   pnf_info *pnf = vnf->pnfs;
   phy_info *phy = pnf->phys;
@@ -1574,12 +1724,12 @@ int nr_start_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_nr_start_resp
 }
 
 int vendor_ext_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_p4_p5_message_header_t *msg) {
-  printf("[VNF] %s\n", __FUNCTION__);
+  NFAPI_TRACE(NFAPI_TRACE_INFO, "[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);
+      NFAPI_TRACE(NFAPI_TRACE_INFO, "[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));
@@ -1645,18 +1795,18 @@ void configure_nr_nfapi_vnf(char *vnf_addr, int vnf_p5_port) {
   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 = vnf.p7_vnfs[0].local_port; // 50001; // TODO: remove hardcode
-  vnf.p7_vnfs[0].local_port = 50011;
+  vnf.p7_vnfs[0].local_port = 50611;  
+  //vnf.p7_vnfs[0].local_port = 50011;
   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_nr_connection_indication = &pnf_nr_connection_indication_cb;
   config->pnf_disconnect_indication = &pnf_disconnection_indication_cb;
 
@@ -1701,7 +1851,6 @@ void configure_nfapi_vnf(char *vnf_addr, int vnf_p5_port) {
   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;
@@ -1738,6 +1887,23 @@ 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;
+  LOG_I(PHY, "[VNF] %s() DL_CONFIG_REQ sfn_sf:%d_%d number_of_pdus:%d\n", __FUNCTION__,
+        NFAPI_SFNSF2SFN(dl_config_req->sfn_sf),NFAPI_SFNSF2SF(dl_config_req->sfn_sf), dl_config_req->dl_config_request_body.number_pdu);
+  if (dl_config_req->dl_config_request_body.number_pdu > 0)
+  {
+    for (int i = 0; i < dl_config_req->dl_config_request_body.number_pdu; i++)
+        {
+            uint8_t pdu_type = dl_config_req->dl_config_request_body.dl_config_pdu_list[i].pdu_type;
+            if(pdu_type ==  NFAPI_DL_CONFIG_DLSCH_PDU_TYPE)
+            {
+                uint16_t dl_rnti = dl_config_req->dl_config_request_body.dl_config_pdu_list[i].dlsch_pdu.dlsch_pdu_rel8.rnti;
+                uint16_t numPDUs = dl_config_req->dl_config_request_body.number_pdu;
+                LOG_I(MAC, "(OAI eNB) Sending dl_config_req at VNF during Frame: %d and Subframe: %d,"
+                           " with a RNTI value of: %x and with number of PDUs: %u\n",
+                      NFAPI_SFNSF2SFN(dl_config_req->sfn_sf),NFAPI_SFNSF2SF(dl_config_req->sfn_sf), dl_rnti, numPDUs);
+            }
+        }
+  }
   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;
@@ -1838,12 +2004,31 @@ int oai_nfapi_hi_dci0_req(nfapi_hi_dci0_request_t *hi_dci0_req) {
   return retval;
 }
 
+static void remove_ul_config_req_pdu(int index, nfapi_ul_config_request_t *ul_config_req)
+{
+  int num_pdus = ul_config_req->ul_config_request_body.number_of_pdus;
+  nfapi_ul_config_request_pdu_t *pdu_list = ul_config_req->ul_config_request_body.ul_config_pdu_list;
+
+  if (index >= num_pdus || index < 0)
+  {
+    LOG_E(MAC, "%s() Unable to drop bad ul_config_req PDU\n", __FUNCTION__);
+    abort();
+  }
+
+  for(int i = index; i + 1 < num_pdus; i++)
+  {
+    pdu_list[i] = pdu_list[i + 1];
+  }
+
+  ul_config_req->ul_config_request_body.number_of_pdus--;
+}
+
 int oai_nfapi_ul_tti_req(nfapi_nr_ul_tti_request_t *ul_tti_req) {
   nfapi_vnf_p7_config_t *p7_config = vnf.p7_vnfs[0].config;
 
   ul_tti_req->header.phy_id = 1; // DJP HACK TODO FIXME - need to pass this around!!!!
   ul_tti_req->header.message_id = NFAPI_NR_PHY_MSG_TYPE_UL_TTI_REQUEST;
-  
+
   int retval = nfapi_vnf_p7_ul_tti_req(p7_config, ul_tti_req);
 
   if (retval!=0) {
@@ -1864,6 +2049,44 @@ int oai_nfapi_ul_config_req(nfapi_ul_config_request_t *ul_config_req) {
   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 num_pdus = ul_config_req->ul_config_request_body.number_of_pdus;
+  nfapi_ul_config_request_pdu_t *pdu_list = ul_config_req->ul_config_request_body.ul_config_pdu_list;
+  for (int i = 0; i < num_pdus; i++)
+  {
+    uint8_t pdu_type = pdu_list[i].pdu_type;
+
+    LOG_I(MAC, "ul_config_req num_pdus: %u pdu_number: %d pdu_type: %u SFN.SF: %d.%d\n",
+          num_pdus, i, pdu_type, ul_config_req->sfn_sf >> 4, ul_config_req->sfn_sf & 15);
+
+    if (pdu_type != NFAPI_UL_CONFIG_ULSCH_CQI_RI_PDU_TYPE)
+    {
+      continue;
+    }
+
+    for (int j = i + 1; j < num_pdus; j++)
+    {
+      uint8_t pdu_type2 = pdu_list[j].pdu_type;
+      if (pdu_type != pdu_type2)
+      {
+        continue;
+      }
+
+      uint16_t rnti_i = pdu_list[i].ulsch_cqi_ri_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti;
+      uint16_t rnti_j = pdu_list[j].ulsch_cqi_ri_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti;
+      if (!is_ue_same(rnti_i, rnti_j))
+      {
+        continue;
+      }
+      remove_ul_config_req_pdu(j, ul_config_req);
+      j--;
+      num_pdus--;
+
+      LOG_E(MAC, "Problem, two cqis being sent to a single UE for rnti %x dropping one\n",
+            rnti_i);
+    }
+  }
+
   int retval = nfapi_vnf_p7_ul_config_req(p7_config, ul_config_req);
 
   if (retval!=0) {
diff --git a/nfapi/oai_integration/vendor_ext.h b/nfapi/oai_integration/vendor_ext.h
index f25aa703ccdb5a5f3eac99225585c6595309066d..9a377dc27d85f4af71eefe9ef92f534b1ab2cf2b 100644
--- a/nfapi/oai_integration/vendor_ext.h
+++ b/nfapi/oai_integration/vendor_ext.h
@@ -70,10 +70,11 @@ typedef enum {
   NFAPI_MODE_VNF,
   NFAPI_UE_STUB_PNF,
   NFAPI_UE_STUB_OFFNET,
+  NFAPI_MODE_STANDALONE_PNF,
   NFAPI_MODE_UNKNOWN
 } nfapi_mode_t;
 
-char *nfapi_get_strmode(void);
+const char *nfapi_get_strmode(void);
 void nfapi_logmode(void);
 nfapi_mode_t nfapi_getmode(void);
 void nfapi_setmode(nfapi_mode_t nfapi_mode);
diff --git a/nfapi/open-nFAPI/common/public_inc/debug.h b/nfapi/open-nFAPI/common/public_inc/debug.h
index 14f97a17f6f8fbe23bd2e3e414b51baaa90f4714..574b09730100b0b54bedb3f454aeeced9f065397 100644
--- a/nfapi/open-nFAPI/common/public_inc/debug.h
+++ b/nfapi/open-nFAPI/common/public_inc/debug.h
@@ -14,38 +14,31 @@
  * limitations under the License.
  */
 
+#pragma once
 
-#ifndef _DEBUG_H_
-#define _DEBUG_H_
+#include <string.h>
+#include <errno.h>
+
+#define ERR strerror(errno)
 
 /*! The trace levels used by the nfapi libraries */
 typedef enum nfapi_trace_level
 {
-	NFAPI_TRACE_ERROR = 1,
-	NFAPI_TRACE_WARN,
-	NFAPI_TRACE_NOTE,
-	NFAPI_TRACE_INFO,
-
-	NFAPI_TRACE_LEVEL_MAX
+    NFAPI_TRACE_NONE,
+    NFAPI_TRACE_ERROR,
+    NFAPI_TRACE_WARN,
+    NFAPI_TRACE_NOTE,
+    NFAPI_TRACE_INFO,
+    NFAPI_TRACE_DEBUG,
 } nfapi_trace_level_t;
 
-/*! The trace function pointer */
-typedef void (*nfapi_trace_fn_t)(nfapi_trace_level_t level, const char* format, ...);
-
-/*! Global trace function */
-extern nfapi_trace_fn_t nfapi_trace_g;
+void nfapi_trace(nfapi_trace_level_t, char const *caller, const char *format, ...)
+    __attribute__((format(printf, 3, 4)));
 
-/*! Global trace level */
-extern nfapi_trace_level_t nfapi_trace_level_g;
-
-/*! NFAPI trace macro */
-//#define NFAPI_TRACE(level, format, ...) { if(nfapi_trace_g && ((nfapi_trace_level_t)level <= nfapi_trace_level_g)) (*nfapi_trace_g)(level, format, ##__VA_ARGS__); }
-#define NFAPI_TRACE(level, format, ...) { if (nfapi_trace_g) (*nfapi_trace_g)(level, format, ##__VA_ARGS__); }
-
-/*! Function to change the trace level 
- * \param new_level The modified trace level
- */
+nfapi_trace_level_t nfapi_trace_level(void);
 
-void nfapi_set_trace_level(nfapi_trace_level_t new_level);
+#define NFAPI_TRACE(LEVEL, FORMAT, ...) do {                            \
+    if (nfapi_trace_level() >= (LEVEL))                                 \
+        nfapi_trace(LEVEL, __func__, FORMAT, ##__VA_ARGS__);            \
+} while (0)
 
-#endif /* _DEBUG_H_ */
diff --git a/nfapi/open-nFAPI/common/src/debug.c b/nfapi/open-nFAPI/common/src/debug.c
index 5d4ad8a19499ed32ccdffb223a28f5f22dc741ac..628e64d9473b103815ac0b8f2eab14f1faa92384 100644
--- a/nfapi/open-nFAPI/common/src/debug.c
+++ b/nfapi/open-nFAPI/common/src/debug.c
@@ -1,75 +1,87 @@
-/*
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-#include <stdarg.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <pthread.h>
-#include <syslog.h>
-
-#include <debug.h>
-
-#define MAX_MSG_LENGTH 			2096
-#define TRACE_HEADER_LENGTH		44
-
-void nfapi_trace_dbg(nfapi_trace_level_t level, const char *format, ...);
-
-// initialize the trace function to 0
-void (*nfapi_trace_g)(nfapi_trace_level_t level, const char* format, ...) = &nfapi_trace_dbg;
-
-nfapi_trace_level_t nfapi_trace_level_g = NFAPI_TRACE_INFO;
-//nfapi_trace_level_t nfapi_trace_level_g = NFAPI_TRACE_WARN;
-
-void nfapi_set_trace_level(nfapi_trace_level_t new_level)
-{
-	nfapi_trace_level_g = new_level;
-}
-
-void nfapi_trace_dbg(nfapi_trace_level_t level, const char *format, ...)
-{
-	char trace_buff[MAX_MSG_LENGTH + TRACE_HEADER_LENGTH];
-	uint32_t num_chars;
-	va_list p_args;
-	struct timeval tv;
-	pthread_t tid = pthread_self();
-
-	(void)gettimeofday(&tv, NULL);
-
-	num_chars = (uint32_t)snprintf(trace_buff, TRACE_HEADER_LENGTH, "%04u.%06u: 0x%02x: %10u: ", ((uint32_t)tv.tv_sec) & 0x1FFF, (uint32_t)tv.tv_usec, (uint32_t)level, (uint32_t)tid);
-
-	if (num_chars > TRACE_HEADER_LENGTH)
-	{
-		printf("trace_dbg: Error, num_chars is too large: %d", num_chars);
-		return;
-	}
-
-	va_start(p_args, format);
-	if ((num_chars = (uint32_t)vsnprintf(&trace_buff[num_chars], MAX_MSG_LENGTH, format, p_args)))
-	{
-		if (level <= NFAPI_TRACE_WARN)
-		{
-			printf("%s", trace_buff);
-		}
-		printf("%s", trace_buff);
-	}
-	va_end(p_args);
-}
+/*
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "debug.h"
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <time.h>
+#include <pthread.h>
+#include <stdbool.h>
+
+static nfapi_trace_level_t trace_level = NFAPI_TRACE_WARN;
+
+static void nfapi_trace_init(void)
+{
+    static bool initialized;
+    if (initialized)
+        return;
+    initialized = true;
+
+    const char *env = getenv("NFAPI_TRACE_LEVEL");
+    if (!env)
+        return;
+    if (strcmp(env, "none") == 0)
+        trace_level = NFAPI_TRACE_NONE;
+    else if (strcmp(env, "error") == 0)
+        trace_level = NFAPI_TRACE_ERROR;
+    else if (strcmp(env, "warn") == 0)
+        trace_level = NFAPI_TRACE_WARN;
+    else if (strcmp(env, "note") == 0)
+        trace_level = NFAPI_TRACE_NOTE;
+    else if (strcmp(env, "info") == 0)
+        trace_level = NFAPI_TRACE_INFO;
+    else if (strcmp(env, "debug") == 0)
+        trace_level = NFAPI_TRACE_DEBUG;
+    else
+    {
+        nfapi_trace(NFAPI_TRACE_ERROR, __func__, "Invalid NFAPI_TRACE_LEVEL='%s'", env);
+        return;
+    }
+    nfapi_trace(trace_level, __func__, "NFAPI_TRACE_LEVEL='%s'", env);
+}
+
+nfapi_trace_level_t nfapi_trace_level()
+{
+    nfapi_trace_init();
+    return trace_level;
+}
+
+void nfapi_trace(nfapi_trace_level_t level,
+                 char const *caller,
+                 char const *format, ...)
+{
+    struct timespec ts;
+    clock_gettime(CLOCK_MONOTONIC, &ts);
+    printf("%ld%06ld [%c] %10u: %s: ",
+           ts.tv_sec,
+           ts.tv_nsec / 1000,
+           "XEWNID"[level], // NFAPI_TRACE_NONE, NFAPI_TRACE_ERROR, ...
+           (unsigned) pthread_self(),
+           caller);
+
+    va_list ap;
+    va_start(ap, format);
+    vprintf(format, ap);
+    va_end(ap);
+
+    // Add a newline if the format string didn't have one
+    int len = strlen(format);
+    if (len == 0 || format[len - 1] != '\n')
+        putchar('\n');
+
+    fflush(stdout);
+}
diff --git a/nfapi/open-nFAPI/nfapi/public_inc/fapi_nr_ue_interface.h b/nfapi/open-nFAPI/nfapi/public_inc/fapi_nr_ue_interface.h
index 0e923931ad4163fd8e4d3f26f31a1ff9d248da4d..21cbaf93c1615c7b0087dbbff5defee935a36001 100644
--- a/nfapi/open-nFAPI/nfapi/public_inc/fapi_nr_ue_interface.h
+++ b/nfapi/open-nFAPI/nfapi/public_inc/fapi_nr_ue_interface.h
@@ -118,11 +118,18 @@ typedef struct {
   short rsrp_dBm;
 } fapi_nr_ssb_pdu_t;
 
+typedef struct {
+  uint32_t pdu_length;
+  uint8_t* pdu;
+  uint32_t sibs_mask;
+} fapi_nr_sib_pdu_t;
+
 typedef struct {
   uint8_t pdu_type;
   union {
     fapi_nr_pdsch_pdu_t pdsch_pdu;
     fapi_nr_ssb_pdu_t ssb_pdu;
+    fapi_nr_sib_pdu_t sib_pdu;
   };
 } fapi_nr_rx_indication_body_t;
 
@@ -403,8 +410,11 @@ typedef struct {
   uint8_t tb2_rv;
   uint8_t harq_process_nbr;
   vrb_to_prb_mapping_t vrb_to_prb_mapping;
+  uint8_t dai;
   double scaling_factor_S;
   int8_t accumulated_delta_PUCCH;
+  uint8_t pucch_resource_id;
+  uint8_t pdsch_to_harq_feedback_time_ind;
   uint8_t n_dmrs_cdm_groups;
   uint8_t dmrs_ports[10];
   uint8_t n_front_load_symb;
@@ -451,6 +461,437 @@ typedef struct {
 } fapi_nr_dl_config_request_t;
 
 
+//
+// P5
+//
+
+    
+
+typedef struct {
+  fapi_nr_coreset_t coreset;
+
+  uint8_t monitoring_slot_peridicity;
+  uint8_t monitoring_slot_offset;
+  uint16_t duration;
+  uint16_t monitoring_symbols_within_slot;
+  uint8_t number_of_candidates[5];            //  aggregation level 1, 2, 4, 8, 16
+
+  uint8_t dci_2_0_number_of_candidates[5];    //  aggregation level 1, 2, 4, 8, 16
+  uint8_t dci_2_3_monitorying_periodicity;
+  uint8_t dci_2_3_number_of_candidates;
+        
+} fapi_nr_search_space_t;
+
+typedef struct {
+  fapi_nr_search_space_t search_space_sib1;
+  fapi_nr_search_space_t search_space_others_sib;
+  fapi_nr_search_space_t search_space_paging;
+  //fapi_nr_coreset_t      coreset_ra;         //  common coreset
+  fapi_nr_search_space_t search_space_ra;    
+} fapi_nr_pdcch_config_common_t;
+
+typedef struct {
+  uint8_t k0;
+  uint8_t mapping_type;
+  uint8_t symbol_starting;
+  uint8_t symbol_length;
+} fapi_nr_pdsch_time_domain_resource_allocation_t;
+
+typedef struct {
+  fapi_nr_pdsch_time_domain_resource_allocation_t allocation_list[FAPI_NR_MAX_NUM_DL_ALLOCATIONS];
+} fapi_nr_pdsch_config_common_t;
+
+typedef struct {
+  uint8_t prach_configuration_index;
+  uint8_t msg1_fdm;
+  uint8_t msg1_frequency_start;
+  uint8_t zero_correlation_zone_config;
+  uint8_t preamble_received_target_power;
+  uint8_t preamble_transmission_max;
+  uint8_t power_ramping_step;
+  uint8_t ra_window_size;
+
+  uint8_t total_number_of_preamble;
+  uint8_t ssb_occasion_per_rach;
+  uint8_t cb_preamble_per_ssb;
+
+  uint8_t group_a_msg3_size;
+  uint8_t group_a_number_of_preamble;
+  uint8_t group_b_power_offset;
+  uint8_t contention_resolution_timer;
+  uint8_t rsrp_threshold_ssb;
+  uint8_t rsrp_threshold_ssb_sul;
+  uint8_t prach_length;   //  l839, l139
+  uint8_t prach_root_sequence_index;  //  0 - 837 for l839, 0 - 137 for l139
+  uint8_t msg1_subcarrier_spacing;
+  uint8_t restrictedset_config;
+  uint8_t msg3_transform_precoding;
+} fapi_nr_rach_config_common_t;
+
+typedef struct {
+  uint8_t k2;
+  uint8_t mapping_type;
+  uint8_t symbol_starting;
+  uint8_t symbol_length;
+} fapi_nr_pusch_time_domain_resource_allocation_t;
+      
+typedef struct {
+  uint8_t group_hopping_enabled_transform_precoding;
+  fapi_nr_pusch_time_domain_resource_allocation_t allocation_list[FAPI_NR_MAX_NUM_UL_ALLOCATIONS];
+  uint8_t msg3_delta_preamble;
+  uint8_t p0_nominal_with_grant;
+} fapi_nr_pusch_config_common_t;
+
+typedef struct {
+  uint8_t pucch_resource_common;
+  uint8_t pucch_group_hopping;
+  uint8_t hopping_id;
+  uint8_t p0_nominal;
+} fapi_nr_pucch_config_common_t;
+
+typedef struct {
+        
+  fapi_nr_pdcch_config_common_t pdcch_config_common;
+  fapi_nr_pdsch_config_common_t pdsch_config_common;
+        
+} fapi_nr_dl_bwp_common_config_t;
+
+
+
+typedef struct {
+  uint16_t int_rnti;
+  uint8_t time_frequency_set;
+  uint8_t dci_payload_size;
+  uint8_t serving_cell_id[FAPI_NR_MAX_NUM_SERVING_CELLS];    //  interrupt configuration per serving cell
+  uint8_t position_in_dci[FAPI_NR_MAX_NUM_SERVING_CELLS];    //  interrupt configuration per serving cell
+} fapi_nr_downlink_preemption_t;
+
+typedef struct {
+  uint8_t tpc_index;
+  uint8_t tpc_index_sul;
+  uint8_t target_cell;
+} fapi_nr_pusch_tpc_command_config_t;
+
+typedef struct {
+  uint8_t tpc_index_pcell;
+  uint8_t tpc_index_pucch_scell;
+} fapi_nr_pucch_tpc_command_config_t;
+
+typedef struct {
+  uint8_t starting_bit_of_format_2_3;
+  uint8_t feild_type_format_2_3;
+} fapi_nr_srs_tpc_command_config_t;
+
+typedef struct {
+  fapi_nr_downlink_preemption_t downlink_preemption;
+  fapi_nr_pusch_tpc_command_config_t tpc_pusch;
+  fapi_nr_pucch_tpc_command_config_t tpc_pucch;
+  fapi_nr_srs_tpc_command_config_t tpc_srs;
+} fapi_nr_pdcch_config_dedicated_t;
+
+typedef struct {
+  uint8_t dmrs_type;
+  uint8_t dmrs_addition_position;
+  uint8_t max_length;
+  uint16_t scrambling_id0;
+  uint16_t scrambling_id1;
+  uint8_t ptrs_frequency_density[2];      //  phase tracking rs
+  uint8_t ptrs_time_density[3];           //  phase tracking rs
+  uint8_t ptrs_epre_ratio;                //  phase tracking rs
+  uint8_t ptrs_resource_element_offset;   //  phase tracking rs
+} fapi_nr_dmrs_downlink_config_t;
+
+typedef struct {
+  uint8_t bwp_or_cell_level;
+  uint8_t pattern_type;
+  uint32_t resource_blocks[9];        //  bitmaps type 275 bits
+  uint8_t slot_type;                  //  bitmaps type one/two slot(s)
+  uint32_t symbols_in_resouece_block; //  bitmaps type 14/28 bits
+  uint8_t periodic;                   //  bitmaps type 
+  uint32_t pattern[2];                //  bitmaps type 2/4/5/8/10/20/40 bits
+
+  fapi_nr_coreset_t coreset;         //  coreset
+
+  uint8_t subcarrier_spacing;
+  uint8_t mode;
+} fapi_nr_rate_matching_pattern_group_t;
+
+typedef struct {
+  //  resource mapping
+  uint8_t row;    //  row1/row2/row4/other
+  uint16_t frequency_domain_allocation; //    4/12/3/6 bits
+  uint8_t number_of_ports;
+  uint8_t first_ofdm_symbol_in_time_domain;
+  uint8_t first_ofdm_symbol_in_time_domain2;
+  uint8_t cdm_type;
+  uint8_t density;            //  .5/1/3
+  uint8_t density_dot5_type;  //  even/odd PRBs
+        
+  uint8_t frequency_band_starting_rb;     //  freqBand
+  uint8_t frequency_band_number_of_rb;    //  freqBand
+
+  //  periodicityAndOffset
+  uint8_t periodicity;    //  slot4/5/8/10/16/20/32/40/64/80/160/320/640
+  uint32_t offset;        //  0..639 bits
+} fapi_nr_zp_csi_rs_resource_t;
+
+typedef struct {
+  uint16_t data_scrambling_id_pdsch;
+  fapi_nr_dmrs_downlink_config_t dmrs_dl_for_pdsch_mapping_type_a;
+  fapi_nr_dmrs_downlink_config_t dmrs_dl_for_pdsch_mapping_type_b; 
+  uint8_t vrb_to_prb_interleaver;
+  uint8_t resource_allocation;
+  fapi_nr_pdsch_time_domain_resource_allocation_t allocation_list[FAPI_NR_MAX_NUM_DL_ALLOCATIONS];
+  uint8_t pdsch_aggregation_factor;
+  fapi_nr_rate_matching_pattern_group_t rate_matching_pattern_group1;
+  fapi_nr_rate_matching_pattern_group_t rate_matching_pattern_group2;
+  uint8_t rbg_size;
+  uint8_t mcs_table;
+  uint8_t max_num_of_code_word_scheduled_by_dci;
+  uint8_t bundle_size;        //  prb_bundling static
+  uint8_t bundle_size_set1;   //  prb_bundling dynamic 
+  uint8_t bundle_size_set2;   //  prb_bundling dynamic
+  fapi_nr_zp_csi_rs_resource_t periodically_zp_csi_rs_resource_set[FAPI_NR_MAX_NUM_ZP_CSI_RS_RESOURCE_PER_SET];
+} fapi_nr_pdsch_config_dedicated_t;
+
+typedef struct {
+  uint16_t starting_prb;
+  uint8_t intra_slot_frequency_hopping;
+  uint16_t second_hop_prb;
+  uint8_t format;                 //  pucch format 0..4
+  uint8_t initial_cyclic_shift;
+  uint8_t number_of_symbols;
+  uint8_t starting_symbol_index;
+  uint8_t time_domain_occ;
+  uint8_t number_of_prbs;
+  uint8_t occ_length;
+  uint8_t occ_index;
+} fapi_nr_pucch_resource_t;
+
+typedef struct {
+  uint8_t periodicity;
+  uint8_t number_of_harq_process;
+  fapi_nr_pucch_resource_t n1_pucch_an;
+} fapi_nr_sps_config_t;
+
+typedef struct {
+  uint8_t beam_failure_instance_max_count;
+  uint8_t beam_failure_detection_timer;
+} fapi_nr_radio_link_monitoring_config_t;
+
+typedef struct {
+  fapi_nr_pdcch_config_dedicated_t pdcch_config_dedicated;
+  fapi_nr_pdsch_config_dedicated_t pdsch_config_dedicated;
+  fapi_nr_sps_config_t sps_config;
+  fapi_nr_radio_link_monitoring_config_t radio_link_monitoring_config;
+
+} fapi_nr_dl_bwp_dedicated_config_t;
+
+typedef struct {
+  fapi_nr_rach_config_common_t  rach_config_common;
+  fapi_nr_pusch_config_common_t pusch_config_common;
+  fapi_nr_pucch_config_common_t pucch_config_common;
+
+} fapi_nr_ul_bwp_common_config_t;
+        
+typedef struct {
+  uint8_t inter_slot_frequency_hopping;
+  uint8_t additional_dmrs;
+  uint8_t max_code_rate;
+  uint8_t number_of_slots;
+  uint8_t pi2bpsk;
+  uint8_t simultaneous_harq_ack_csi;
+} fapi_nr_pucch_format_config_t;
+
+typedef struct {
+  fapi_nr_pucch_format_config_t format1;
+  fapi_nr_pucch_format_config_t format2;
+  fapi_nr_pucch_format_config_t format3;
+  fapi_nr_pucch_format_config_t format4;
+  fapi_nr_pucch_resource_t multi_csi_pucch_resources[2];
+  uint8_t dl_data_to_ul_ack[8];
+  //  pucch power control
+  uint8_t deltaF_pucch_f0;
+  uint8_t deltaF_pucch_f1;
+  uint8_t deltaF_pucch_f2;
+  uint8_t deltaF_pucch_f3;
+  uint8_t deltaF_pucch_f4;
+  uint8_t two_pucch_pc_adjusment_states;
+} fapi_nr_pucch_config_dedicated_t;
+
+typedef struct {
+  uint8_t dmrs_type;
+  uint8_t dmrs_addition_position;
+  uint8_t ptrs_uplink_config; // to indicate if PTRS Uplink is configured of not
+  uint8_t ptrs_type;  //cp-OFDM, dft-S-OFDM
+  uint16_t ptrs_frequency_density[2];
+  uint8_t ptrs_time_density[3];
+  uint8_t ptrs_max_number_of_ports;
+  uint8_t ptrs_resource_element_offset;
+  uint8_t ptrs_power;
+  uint16_t ptrs_sample_density[5];
+  uint8_t ptrs_time_density_transform_precoding;
+
+  uint8_t max_length;
+  uint16_t scrambling_id0;
+  uint16_t scrambling_id1;
+  uint8_t npusch_identity;
+  uint8_t disable_sequence_group_hopping;
+  uint8_t sequence_hopping_enable;
+} fapi_nr_dmrs_uplink_config_t;
+
+typedef struct {
+  uint8_t tpc_accmulation;
+  uint8_t msg3_alpha;
+  uint8_t p0_nominal_with_grant;
+  uint8_t two_pusch_pc_adjustments_states;
+  uint8_t delta_mcs;
+} fapi_nr_pusch_power_control_t;
+
+typedef enum {tx_config_codebook = 1, tx_config_nonCodebook = 2} tx_config_t;
+typedef enum {transform_precoder_enabled = 0, transform_precoder_disabled = 1} transform_precoder_t;
+typedef enum {
+  codebook_subset_fullyAndPartialAndNonCoherent = 1,
+  codebook_subset_partialAndNonCoherent = 2,
+  codebook_subset_nonCoherent = 3} codebook_subset_t;
+typedef struct {
+  uint16_t data_scrambling_identity;
+  tx_config_t tx_config;
+  fapi_nr_dmrs_uplink_config_t dmrs_ul_for_pusch_mapping_type_a;
+  fapi_nr_dmrs_uplink_config_t dmrs_ul_for_pusch_mapping_type_b;
+  fapi_nr_pusch_power_control_t pusch_power_control;
+  uint8_t frequency_hopping;
+  uint16_t frequency_hopping_offset_lists[4];
+  uint8_t resource_allocation;
+  fapi_nr_pusch_time_domain_resource_allocation_t allocation_list[FAPI_NR_MAX_NUM_UL_ALLOCATIONS];
+  uint8_t pusch_aggregation_factor;
+  uint8_t mcs_table;
+  uint8_t mcs_table_transform_precoder;
+  transform_precoder_t transform_precoder;
+  codebook_subset_t codebook_subset;
+  uint8_t max_rank;
+  uint8_t rbg_size;
+
+  //uci-OnPUSCH
+  uint8_t uci_on_pusch_type;  //dynamic, semi-static
+  uint8_t beta_offset_ack_index1[4];
+  uint8_t beta_offset_ack_index2[4];
+  uint8_t beta_offset_ack_index3[4];
+  uint8_t beta_offset_csi_part1_index1[4];
+  uint8_t beta_offset_csi_part1_index2[4];
+  uint8_t beta_offset_csi_part2_index1[4];
+  uint8_t beta_offset_csi_part2_index2[4];
+
+  uint8_t tp_pi2BPSK;
+} fapi_nr_pusch_config_dedicated_t;
+
+typedef struct {
+  uint8_t frequency_hopping;
+  fapi_nr_dmrs_uplink_config_t cg_dmrs_configuration;
+  uint8_t mcs_table;
+  uint8_t mcs_table_transform_precoder;
+
+  //uci-OnPUSCH
+  uint8_t uci_on_pusch_type;  //dynamic, semi-static
+  uint8_t beta_offset_ack_index1[4];
+  uint8_t beta_offset_ack_index2[4];
+  uint8_t beta_offset_ack_index3[4];
+  uint8_t beta_offset_csi_part1_index1[4];
+  uint8_t beta_offset_csi_part1_index2[4];
+  uint8_t beta_offset_csi_part2_index1[4];
+  uint8_t beta_offset_csi_part2_index2[4];
+
+  uint8_t resource_allocation;
+  //  rgb-Size structure missing in spec.
+  uint8_t power_control_loop_to_use;
+  //  p0-PUSCH-Alpha
+  uint8_t p0;
+  uint8_t alpha;
+
+  uint8_t transform_precoder;
+  uint8_t number_of_harq_process;
+  uint8_t rep_k;
+  uint8_t rep_k_rv;
+  uint8_t periodicity;
+  uint8_t configured_grant_timer;
+  //  rrc-ConfiguredUplinkGrant
+  uint16_t time_domain_offset;
+  uint8_t time_domain_allocation;
+  uint32_t frequency_domain_allocation;
+  uint8_t antenna_ports;
+  uint8_t dmrs_seq_initialization;
+  uint8_t precoding_and_number_of_layers;
+  uint8_t srs_resource_indicator;
+  uint8_t mcs_and_tbs;
+  uint8_t frequency_hopping_offset;
+  uint8_t path_loss_reference_index;
+
+} fapi_nr_configured_grant_config_t;
+
+typedef struct {
+  uint8_t qcl_type1_serving_cell_index;
+  uint8_t qcl_type1_bwp_id;
+  uint8_t qcl_type1_rs_type;  //  csi-rs or ssb
+  uint8_t qcl_type1_nzp_csi_rs_resource_id;
+  uint8_t qcl_type1_ssb_index;
+  uint8_t qcl_type1_type;
+        
+  uint8_t qcl_type2_serving_cell_index;
+  uint8_t qcl_type2_bwp_id;
+  uint8_t qcl_type2_rs_type;  //  csi-rs or ssb
+  uint8_t qcl_type2_nzp_csi_rs_resource_id;
+  uint8_t qcl_type2_ssb_index;
+  uint8_t qcl_type2_type;
+
+} fapi_nr_tci_state_t;
+
+typedef struct {
+  uint8_t root_sequence_index;
+  //  rach genertic
+  uint8_t prach_configuration_index;
+  uint8_t msg1_fdm;
+  uint8_t msg1_frequency_start;
+  uint8_t zero_correlation_zone_config;
+  uint8_t preamble_received_target_power;
+  uint8_t preamble_transmission_max;
+  uint8_t power_ramping_step;
+  uint8_t ra_window_size;
+
+  uint8_t rsrp_threshold_ssb;
+  //  PRACH-ResourceDedicatedBFR
+  uint8_t bfr_ssb_index[FAPI_NR_MAX_NUM_CANDIDATE_BEAMS];
+  uint8_t bfr_ssb_ra_preamble_index[FAPI_NR_MAX_NUM_CANDIDATE_BEAMS];
+  // NZP-CSI-RS-Resource
+  uint8_t bfr_csi_rs_nzp_resource_mapping[FAPI_NR_MAX_NUM_CANDIDATE_BEAMS];
+  uint8_t bfr_csi_rs_power_control_offset[FAPI_NR_MAX_NUM_CANDIDATE_BEAMS];
+  uint8_t bfr_csi_rs_power_control_offset_ss[FAPI_NR_MAX_NUM_CANDIDATE_BEAMS];
+  uint16_t bfr_csi_rs_scrambling_id[FAPI_NR_MAX_NUM_CANDIDATE_BEAMS];
+  uint8_t bfr_csi_rs_resource_periodicity[FAPI_NR_MAX_NUM_CANDIDATE_BEAMS];
+  uint16_t bfr_csi_rs_resource_offset[FAPI_NR_MAX_NUM_CANDIDATE_BEAMS];
+  fapi_nr_tci_state_t qcl_infomation_periodic_csi_rs[FAPI_NR_MAX_NUM_CANDIDATE_BEAMS];
+
+  uint8_t bfr_csirs_ra_occasions[FAPI_NR_MAX_NUM_CANDIDATE_BEAMS];
+  uint8_t bfr_csirs_ra_preamble_index[FAPI_NR_MAX_NUM_CANDIDATE_BEAMS][FAPI_NR_MAX_RA_OCCASION_PER_CSIRS];
+
+  uint8_t ssb_per_rach_occasion;
+  uint8_t ra_ssb_occasion_mask_index;
+  fapi_nr_search_space_t recovery_search_space;
+  //  RA-Prioritization
+  uint8_t power_ramping_step_high_priority;
+  uint8_t scaling_factor_bi;
+  uint8_t beam_failure_recovery_timer;
+} fapi_nr_beam_failure_recovery_config_t;
+
+typedef struct {
+  fapi_nr_pucch_config_dedicated_t pucch_config_dedicated;
+  fapi_nr_pusch_config_dedicated_t pusch_config_dedicated;
+  fapi_nr_configured_grant_config_t configured_grant_config;
+  //  SRS-Config
+  uint8_t srs_tpc_accumulation;
+  fapi_nr_beam_failure_recovery_config_t beam_failure_recovery_config;
+        
+} fapi_nr_ul_bwp_dedicated_config_t;
+
 #define FAPI_NR_CONFIG_REQUEST_MASK_PBCH                0x01
 #define FAPI_NR_CONFIG_REQUEST_MASK_DL_BWP_COMMON       0x02
 #define FAPI_NR_CONFIG_REQUEST_MASK_UL_BWP_COMMON       0x04
diff --git a/nfapi/open-nFAPI/nfapi/public_inc/nfapi_interface.h b/nfapi/open-nFAPI/nfapi/public_inc/nfapi_interface.h
index ea459138e1e00aff374b50d0081ff07e9d476132..e1cfc2633607f4a8c95b81c4a469aa878bcd0b41 100644
--- a/nfapi/open-nFAPI/nfapi/public_inc/nfapi_interface.h
+++ b/nfapi/open-nFAPI/nfapi/public_inc/nfapi_interface.h
@@ -27,6 +27,8 @@
 #define NFAPI_PNF_PARAM_GENERAL_OUI_LENGTH 3
 #define NFAPI_MAX_NUM_RF_BANDS 16
 
+#define NFAPI_MAX_PACKED_MESSAGE_SIZE 8192
+
 // The following definition control the size of arrays used in the interface.
 // These may be changed if desired. They are used in the encoder to make sure 
 // that the user has not specified a 'count' larger than the max array, and also
@@ -122,12 +124,13 @@ typedef struct {
 
 // Convenience methods to convert between SFN/SLOT formats
 #define NFAPI_SFNSLOT2DEC(_sfn,_slot) ( _sfn*20 + _slot  )  // total count of slots
-#define NFAPI_SFNSLOTDEC2SFNSLOT(_sfnslot_dec) ((((_sfnslot_dec) / 20) << 4) | (((_sfnslot_dec) - (((_sfnslot_dec) / 20) * 10)) & 0x3F))
+#define NFAPI_SFNSLOTDEC2SFNSLOT(_sfnslot_dec) ((((_sfnslot_dec) / 20) << 6) | (((_sfnslot_dec) - (((_sfnslot_dec) / 20) * 20)) & 0x3F))
 
 #define NFAPI_SFNSLOT2SFN(_sfnslot) ((_sfnslot) >> 6)
 #define NFAPI_SFNSLOT2SLOT(_sfnslot) ((_sfnslot) & 0x3F)
 #define NFAPI_SFNSLOTDEC2SFN(_sfnslot_dec) ((_sfnslot_dec) / 20)
 #define NFAPI_SFNSLOTDEC2SLOT(_sfnslot_dec) ((_sfnslot_dec) % 20)
+#define NFAPI_SFNSLOT2HEX(_sfn,_slot) ((_sfn << 6) | (_slot & 0x3F))
 
 #define NFAPI_MAX_SFNSLOTDEC 1024*20 // 20 is for numerology 1
 
@@ -706,7 +709,6 @@ typedef struct {
 #define NFAPI_PHICH_CONFIG_PHICH_DURATION_TAG 0x0015
 #define NFAPI_PHICH_CONFIG_PHICH_POWER_OFFSET_TAG 0x0016
 
-
 typedef struct {
 	nfapi_uint16_tlv_t primary_synchronization_signal_epre_eprers;
 	nfapi_uint16_tlv_t secondary_synchronization_signal_epre_eprers;
@@ -2497,7 +2499,7 @@ typedef struct {
 typedef struct {
 	nfapi_p7_message_header_t header;
 	uint32_t t1;
-	int32_t delta_sfn_sf;	
+	int32_t delta_sfn_sf;
 	nfapi_vendor_extension_tlv_t vendor_extension;
 } nfapi_dl_node_sync_t;
 
@@ -2872,11 +2874,12 @@ typedef struct {
  } nfapi_rx_indication_rel9_t;
 #define NFAPI_RX_INDICATION_REL9_TAG 0x2025
 
+#define NFAPI_RX_IND_DATA_MAX 8192
 typedef struct {
 	nfapi_rx_ue_information rx_ue_information;
 	nfapi_rx_indication_rel8_t rx_indication_rel8;
 	nfapi_rx_indication_rel9_t rx_indication_rel9;
-	uint8_t* data;
+	uint8_t rx_ind_data[NFAPI_RX_IND_DATA_MAX];
 } nfapi_rx_indication_pdu_t;
 
 #define NFAPI_RX_IND_MAX_PDU 100
diff --git a/nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface_scf.h b/nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface_scf.h
index 9d245446c86d00283f5ce6f678aeac630ce1e8bd..c124ad9fb9dde6b58a258eebc4620c124441ae0a 100644
--- a/nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface_scf.h
+++ b/nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface_scf.h
@@ -984,6 +984,8 @@ typedef struct {
   /// A value indicating how the BCH payload is generated. This should match the PARAM/CONFIG TLVs. Value: 0: MAC generates the full PBCH payload, see Table 3-41, where bchPayload has 31 bits 1: PHY generates the timing PBCH bits, see Table 3-41, where the bchPayload has 24 bits 2: PHY generates the full PBCH payload
   uint8_t  bchPayloadFlag;
   uint32_t bchPayload;
+  /// A value indicating the channel quality between the gNB and nrUE. Value: 0->255 dBM
+  uint8_t  ssbRsrp;
   nfapi_nr_tx_precoding_and_beamforming_t precoding_and_beamforming;
 } nfapi_nr_dl_tti_ssb_pdu_rel15_t;
 
@@ -1476,7 +1478,7 @@ typedef enum {
 //section 3.4.7 rx_data_indication
 
 //table 3-61
-
+#define NFAPI_NR_RX_DATA_IND_MAX_PDU 100
 typedef struct 
 {
   uint32_t handle;
@@ -1497,12 +1499,13 @@ typedef struct
   uint16_t sfn;
   uint16_t slot;
   uint16_t number_of_pdus;
-  nfapi_nr_rx_data_pdu_t *pdu_list; 
+  nfapi_nr_rx_data_pdu_t *pdu_list;
 
 } nfapi_nr_rx_data_indication_t;
 
 //3.4.8 crc_indication
 //table 3-62
+#define NFAPI_NR_CRC_IND_MAX_PDU 100
 typedef struct
 {
   uint32_t handle;
@@ -1642,6 +1645,7 @@ typedef enum {
   NFAPI_NR_UCI_FORMAT_2_3_4_PDU_TYPE = 2,
 } nfapi_nr_uci_pdu_type_e;
 
+#define NFAPI_NR_UCI_IND_MAX_PDU 100
 typedef struct
 {
   uint16_t pdu_type;  // 0 for PDU on PUSCH, 1 for PUCCH format 0 or 1, 2 for PUCCH format 2 to 4
@@ -1678,7 +1682,7 @@ typedef struct
   nfapi_nr_srs_indication_reported_symbol_resource_block_t* rb_list;
 }nfapi_nr_srs_indication_reported_symbol_t;
 
-
+#define NFAPI_NR_SRS_IND_MAX_PDU 100
 typedef struct
 {
   uint32_t handle;
diff --git a/nfapi/open-nFAPI/nfapi/src/nfapi.c b/nfapi/open-nFAPI/nfapi/src/nfapi.c
index 63dd8a16ae81489f3fd655ec469766a23461651d..2783781e2c39b9ceb46d00df2609bb087b453194 100644
--- a/nfapi/open-nFAPI/nfapi/src/nfapi.c
+++ b/nfapi/open-nFAPI/nfapi/src/nfapi.c
@@ -1,783 +1,783 @@
-/*
- * Copyright (c) 2001-2016, Cisco Systems, Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 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.
- *
- * Neither the name of the Cisco Systems, Inc. nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * 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 HOLDERS 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.
- */
-
-#include <signal.h>
-#include <sys/time.h>
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <sched.h>
-#include <time.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-#include <pthread.h>
-
-#include <nfapi_interface.h>
-#include <nfapi.h>
-#include <debug.h>
-
-
-// Fundamental routines
-
-uint8_t push8(uint8_t in, uint8_t **out, uint8_t *end) {
-  uint8_t *pOut = *out;
-
-  if((end - pOut) >= 1) {
-    pOut[0] = in;
-    (*out)+=1;
-    return 1;
-  } else {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
-    return 0;
-  }
-}
-
-uint8_t pushs8(int8_t in, uint8_t **out, uint8_t *end) {
-  uint8_t *pOut = *out;
-
-  if((end - pOut) >= 1) {
-    pOut[0] = in;
-    (*out)+=1;
-    return 1;
-  } else {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
-    return 0;
-  }
-}
-
-uint8_t push16(uint16_t in, uint8_t **out, uint8_t *end) {
-  uint8_t *pOut = *out;
-
-  if((end - pOut) >= 2) {
-    pOut[0] = (in & 0xFF00) >> 8;
-    pOut[1] = (in & 0xFF);
-    (*out)+=2;
-    return 2;
-  } else {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
-    return 0;
-  }
-}
-
-uint8_t pushs16(int16_t in, uint8_t **out, uint8_t *end) {
-  uint8_t *pOut = *out;
-
-  if((end - pOut) >= 2) {
-    pOut[0] = (in & 0xFF00) >> 8;
-    pOut[1] = (in & 0xFF);
-    (*out)+=2;
-    return 2;
-  } else {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
-    return 0;
-  }
-}
-
-uint8_t push32(uint32_t in, uint8_t **out, uint8_t *end) {
-  uint8_t *pOut = *out;
-
-  if((end - pOut) >= 4) {
-    pOut[0] = (in & 0xFF000000) >> 24;
-    pOut[1] = (in & 0xFF0000) >> 16;
-    pOut[2] = (in & 0xFF00) >> 8;
-    pOut[3] = (in & 0xFF);
-    (*out)+=4;
-    return 4;
-  } else {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
-    return 0;
-  }
-}
-
-uint8_t pushs32(int32_t in, uint8_t **out, uint8_t *end) {
-  uint8_t *pOut = *out;
-
-  if((end - pOut) >= 4) {
-    pOut[0] = (in & 0xFF000000) >> 24;
-    pOut[1] = (in & 0xFF0000) >> 16;
-    pOut[2] = (in & 0xFF00) >> 8;
-    pOut[3] = (in & 0xFF);
-    (*out)+=4;
-    return 4;
-  } else {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
-    return 0;
-  }
-}
-
-uint8_t pull8(uint8_t **in, uint8_t *out, uint8_t *end) {
-  uint8_t *pIn = *in;
-
-  if((end - pIn) >= 1 ) {
-    *out = *pIn;
-    (*in)+=1;
-    return 1;
-  } else {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
-    return 0;
-  }
-}
-
-uint8_t pulls8(uint8_t **in, int8_t *out, uint8_t *end) {
-  uint8_t *pIn = *in;
-
-  if((end - pIn) >= 1 ) {
-    *out = *pIn;
-    (*in)+=1;
-    return 1;
-  } else {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
-    return 0;
-  }
-}
-
-uint8_t pull16(uint8_t **in, uint16_t *out, uint8_t *end) {
-  uint8_t *pIn = *in;
-
-  if((end - pIn) >=2 ) {
-    *out = ((pIn[0]) << 8) | pIn[1];
-    (*in)+=2;
-    return 2;
-  } else {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
-    return 0;
-  }
-}
-
-uint8_t pulls16(uint8_t **in, int16_t *out, uint8_t *end) {
-  uint8_t *pIn = *in;
-
-  if((end - pIn) >=2 ) {
-    *out = ((pIn[0]) << 8) | pIn[1];
-    (*in)+=2;
-    return 2;
-  } else {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
-    return 0;
-  }
-}
-
-uint8_t pull32(uint8_t **in, uint32_t *out, uint8_t *end) {
-  uint8_t *pIn = *in;
-
-  if((end - pIn) >=4 ) {
-    *out = (pIn[0] << 24) | (pIn[1] << 16) | (pIn[2] << 8) | pIn[3];
-    (*in)+=4;
-    return 4;
-  } else {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n",  __FUNCTION__);
-    return 0;
-  }
-}
-
-uint8_t pulls32(uint8_t **in, int32_t *out, uint8_t *end) {
-  uint8_t *pIn = *in;
-
-  if((end - pIn) >=4 ) {
-    *out = (pIn[0] << 24) | (pIn[1] << 16) | (pIn[2] << 8) | pIn[3];
-    (*in)+=4;
-    return 4;
-  } else {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
-    return 0;
-  }
-}
-
-/*
-inline void pusharray16(uint8_t **, uint16_t, uint32_t len)
-{
-}
-*/
-
-uint32_t pullarray16(uint8_t **in, uint16_t out[], uint32_t max_len, uint32_t len, uint8_t *end) {
-  if(len == 0)
-    return 1;
-
-  if(len > max_len) {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, len, max_len);
-    return 0;
-  }
-
-  if((end - (*in)) >= sizeof(uint16_t) * len) {
-    uint32_t idx;
-
-    for(idx = 0; idx < len; ++idx) {
-      if(!pull16(in, &out[idx], end))
-        return 0;
-    }
-
-    return sizeof(uint16_t) * len;
-  } else {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
-    return 0;
-  }
-}
-
-uint32_t pullarrays16(uint8_t **in, int16_t out[], uint32_t max_len, uint32_t len, uint8_t *end) {
-  if(len == 0)
-    return 1;
-
-  if(len > max_len) {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, len, max_len);
-    return 0;
-  }
-
-  if((end - (*in)) >= sizeof(uint16_t) * len) {
-    uint32_t idx;
-
-    for(idx = 0; idx < len; ++idx) {
-      if(!pulls16(in, &out[idx], end))
-        return 0;
-    }
-
-    return sizeof(uint16_t) * len;
-  } else {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
-    return 0;
-  }
-}
-uint32_t pusharray16(uint16_t in[], uint32_t max_len, uint32_t len, uint8_t **out, uint8_t *end) {
-  if(len == 0)
-    return 1;
-
-  if(len > max_len) {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, len, max_len);
-    return 0;
-  }
-
-  if((end - (*out)) >= sizeof(uint16_t) * len) {
-    uint32_t idx;
-
-    for(idx = 0; idx < len; ++idx) {
-      if(!push16(in[idx], out, end))
-        return 0;
-    }
-
-    return sizeof(uint16_t) * len;
-  } else {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
-    return 0;
-  }
-}
-uint32_t pusharrays16(int16_t in[], uint32_t max_len, uint32_t len, uint8_t **out, uint8_t *end) {
-  if(len == 0)
-    return 1;
-
-  if(len > max_len) {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, len, max_len);
-    return 0;
-  }
-
-  if((end - (*out)) >= sizeof(uint16_t) * len) {
-    uint32_t idx;
-
-    for(idx = 0; idx < len; ++idx) {
-      pushs16(in[idx], out, end);
-    }
-
-    return sizeof(uint16_t) * len;
-  } else {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
-    return 0;
-  }
-}
-uint32_t pullarray32(uint8_t **in, uint32_t out[], uint32_t max_len, uint32_t len, uint8_t *end) {
-  if(len == 0)
-    return 1;
-
-  if(len > max_len) {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, len, max_len);
-    return 0;
-  }
-
-  if((end - (*in)) >= sizeof(uint32_t) * len) {
-    uint32_t idx;
-
-    for(idx = 0; idx < len; ++idx) {
-      if(!pull32(in, &out[idx], end))
-        return 0;
-    }
-
-    return sizeof(uint32_t) * len;
-  } else {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
-    return 0;
-  }
-}
-
-uint32_t pullarrays32(uint8_t **in, int32_t out[], uint32_t max_len, uint32_t len, uint8_t *end) {
-  if(len == 0)
-    return 1;
-
-  if(len > max_len) {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, len, max_len);
-    return 0;
-  }
-
-  if((end - (*in)) >= sizeof(uint32_t) * len) {
-    uint32_t idx;
-
-    for(idx = 0; idx < len; ++idx) {
-      if(!pulls32(in, &out[idx], end))
-        return 0;
-    }
-
-    return sizeof(uint32_t) * len;
-  } else {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
-    return 0;
-  }
-}
-uint32_t pusharray32(uint32_t in[], uint32_t max_len, uint32_t len, uint8_t **out, uint8_t *end) {
-  if(len == 0)
-    return 1;
-
-  if(len > max_len) {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, len, max_len);
-    return 0;
-  }
-
-  if((end - (*out)) >= sizeof(uint32_t) * len) {
-    uint32_t idx;
-
-    for(idx = 0; idx < len; ++idx) {
-      if(!push32(in[idx], out, end))
-        return 0;
-    }
-
-    return sizeof(uint32_t) * len;
-  } else {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
-    return 0;
-  }
-}
-uint32_t pusharrays32(int32_t in[], uint32_t max_len, uint32_t len, uint8_t **out, uint8_t *end) {
-  if(len == 0)
-    return 1;
-
-  if(len > max_len) {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, len, max_len);
-    return 0;
-  }
-
-  if((end - (*out)) >= sizeof(uint32_t) * len) {
-    uint32_t idx;
-
-    for(idx = 0; idx < len; ++idx) {
-      pushs32(in[idx], out, end);
-    }
-
-    return sizeof(uint32_t) * len;
-  } else {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
-    return 0;
-  }
-}
-uint32_t pullarray8(uint8_t **in, uint8_t out[], uint32_t max_len, uint32_t len, uint8_t *end) {
-  if(len == 0)
-    return 1;
-
-  if(len > max_len) {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, len, max_len);
-    return 0;
-  }
-
-  if((end - (*in)) >= sizeof(uint8_t) * len) {
-    memcpy(out, (*in), len);
-    (*in)+=len;
-    return sizeof(uint8_t) * len;
-  } else {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
-    return 0;
-  }
-}
-
-uint32_t pusharray8(uint8_t in[], uint32_t max_len, uint32_t len, uint8_t **out, uint8_t *end) {
-  if(len == 0)
-    return 1;
-
-  if(len > max_len) {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, len, max_len);
-    return 0;
-  }
-
-  if((end - (*out)) >= sizeof(uint8_t) * len) {
-    memcpy((*out), in, len);
-    (*out)+=len;
-    return sizeof(uint8_t) * len;
-  } else {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
-    return 0;
-  }
-}
-
-uint8_t packarray(void *array, uint16_t array_element_size, uint16_t max_count, uint16_t count, uint8_t **ppwritepackedmsg, uint8_t *end, pack_array_elem_fn fn) {
-  if(count > max_count) {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, count, max_count);
-    return 0;
-  }
-
-  uint16_t i = 0;
-
-  for(i = 0; i < count; ++i) {
-    if((fn)(array, ppwritepackedmsg, end) == 0)
-      return 0;
-
-    array += array_element_size;
-  }
-
-  return 1;
-}
-
-uint8_t unpackarray(uint8_t **ppReadPackedMsg, void *array, uint16_t array_element_size, uint16_t max_count, uint16_t count, uint8_t *end, unpack_array_elem_fn fn) {
-  if(count > max_count) {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, count, max_count);
-    return 0;
-  }
-
-  uint16_t i = 0;
-
-  for(i = 0; i < count; ++i) {
-    if((fn)(array, ppReadPackedMsg, end) == 0)
-      return 0;
-
-    array += array_element_size;
-  }
-
-  return 1;
-}
-
-
-uint32_t pack_vendor_extension_tlv(nfapi_tl_t *ve, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t *config) {
-  if(ve != 0 && config != 0) {
-    if(config->pack_vendor_extension_tlv) {
-      uint8_t *pStartOfTlv = *ppWritePackedMsg;
-
-      if(pack_tl(ve, ppWritePackedMsg, end) == 0)
-        return 0;
-
-      uint8_t *pStartOfValue = *ppWritePackedMsg;
-
-      if((config->pack_vendor_extension_tlv)(ve, ppWritePackedMsg, end, config) == 0)
-        return 0;
-
-      ve->length = (*ppWritePackedMsg) - pStartOfValue;
-      pack_tl(ve, &pStartOfTlv, end);
-      return 1;
-    }
-  }
-
-  return 1;
-}
-
-uint32_t unpack_vendor_extension_tlv(nfapi_tl_t *tl, uint8_t **ppReadPackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t *config, nfapi_tl_t **ve_tlv) {
-  if(ve_tlv != 0 && config != 0) {
-    if(config->unpack_vendor_extension_tlv) {
-      return (config->unpack_vendor_extension_tlv)(tl, ppReadPackedMsg, end, (void **)ve_tlv, config);
-    }
-  }
-
-  return 1;
-}
-
-uint32_t pack_p7_vendor_extension_tlv(nfapi_tl_t *ve, uint8_t **ppWritePackedMsg, uint8_t *end,nfapi_p7_codec_config_t *config) {
-  if(ve != 0 && config != 0) {
-    if(config->pack_vendor_extension_tlv) {
-      uint8_t *pStartOfTlv = *ppWritePackedMsg;
-
-      if(pack_tl(ve, ppWritePackedMsg, end) == 0)
-        return 0;
-
-      uint8_t *pStartOfValue = *ppWritePackedMsg;
-
-      if((config->pack_vendor_extension_tlv)(ve, ppWritePackedMsg, end, config) == 0)
-        return 0;
-
-      ve->length = (*ppWritePackedMsg) - pStartOfValue;
-      pack_tl(ve, &pStartOfTlv, end);
-      return 1;
-    }
-  }
-
-  return 1;
-}
-
-int unpack_p7_vendor_extension_tlv(nfapi_tl_t *tl, uint8_t **ppReadPackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config, nfapi_tl_t **ve_tlv) {
-  if(ve_tlv != 0 && config != 0) {
-    if(config->unpack_vendor_extension_tlv) {
-      return (config->unpack_vendor_extension_tlv)(tl, ppReadPackedMsg, end, (void **)ve_tlv, config);
-    }
-  }
-
-  return 1;
-}
-
-
-uint8_t pack_tl(nfapi_tl_t *tl, uint8_t **ppWritePackedMsg, uint8_t *end) {
-  return (push16(tl->tag, ppWritePackedMsg, end) &&
-          push16(tl->length, ppWritePackedMsg, end));
-}
-
-uint8_t unpack_tl(uint8_t **ppReadPackedMsg, nfapi_tl_t *tl, uint8_t *end) {
-  return (pull16(ppReadPackedMsg, &tl->tag, end) &&
-          pull16(ppReadPackedMsg, &tl->length, end));
-}
-
-int unpack_tlv_list(unpack_tlv_t unpack_fns[], uint16_t size, uint8_t **ppReadPackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t *config, nfapi_tl_t **ve) {
-  nfapi_tl_t generic_tl;
-  uint8_t numBadTags = 0;
-  uint16_t idx = 0;
-
-  while ((uint8_t *)(*ppReadPackedMsg) < end) {
-    // unpack the tl and process the values accordingly
-    if(unpack_tl(ppReadPackedMsg, &generic_tl, end) == 0)
-      return 0;
-
-    uint8_t tagMatch = 0;
-    uint8_t *pStartOfValue = *ppReadPackedMsg;
-
-    for(idx = 0; idx < size; ++idx) {
-      if(unpack_fns[idx].tag == generic_tl.tag) { // match the extracted tag value with all the tags in unpack_fn list
-        tagMatch = 1;
-        nfapi_tl_t *tl = (nfapi_tl_t *)(unpack_fns[idx].tlv);
-        tl->tag = generic_tl.tag;
-        tl->length = generic_tl.length;
-        int result = (*unpack_fns[idx].unpack_func)(tl, ppReadPackedMsg, end);
-
-        if(result == 0) {
-          return 0;
-        }
-
-        // check if the length was right;
-        if(tl->length != (*ppReadPackedMsg - pStartOfValue)) {
-          NFAPI_TRACE(NFAPI_TRACE_ERROR, "Warning tlv tag 0x%x length %d not equal to unpack %d\n", tl->tag, tl->length, (*ppReadPackedMsg - pStartOfValue));
-        }
-      }
-    }
-
-    if(tagMatch == 0) {
-      if(generic_tl.tag >= NFAPI_VENDOR_EXTENSION_MIN_TAG_VALUE &&
-          generic_tl.tag <= NFAPI_VENDOR_EXTENSION_MAX_TAG_VALUE) {
-        int result = unpack_vendor_extension_tlv(&generic_tl, ppReadPackedMsg, end, config, ve);
-
-        if(result == 0) {
-          // got tot the end.
-          return 0;
-        } else if(result < 0) {
-          NFAPI_TRACE(NFAPI_TRACE_ERROR, "Unknown VE TAG value: 0x%04x\n", generic_tl.tag);
-
-          if (++numBadTags > MAX_BAD_TAG) {
-            NFAPI_TRACE(NFAPI_TRACE_ERROR, "Supplied message has had too many bad tags\n");
-            return 0;
-          }
-
-          if((end - *ppReadPackedMsg) >= generic_tl.length) {
-            // Advance past the unknown TLV
-            (*ppReadPackedMsg) += generic_tl.length;
-          } else {
-            // go to the end
-            return 0;
-          }
-        }
-      } else {
-        NFAPI_TRACE(NFAPI_TRACE_ERROR, "Unknown TAG value: 0x%04x\n", generic_tl.tag);
-
-        if (++numBadTags > MAX_BAD_TAG) {
-          NFAPI_TRACE(NFAPI_TRACE_ERROR, "Supplied message has had too many bad tags\n");
-          return 0;
-        }
-
-        if((end - *ppReadPackedMsg) >= generic_tl.length) {
-          // Advance past the unknown TLV
-          (*ppReadPackedMsg) += generic_tl.length;
-        } else {
-          // go to the end
-          return 0;
-        }
-      }
-    }
-  }
-
-  return 1;
-}
-int unpack_p7_tlv_list(unpack_p7_tlv_t unpack_fns[], uint16_t size, uint8_t **ppReadPackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config, nfapi_tl_t **ve) {
-  nfapi_tl_t generic_tl;
-  uint8_t numBadTags = 0;
-  uint16_t idx = 0;
-
-  while ((uint8_t *)(*ppReadPackedMsg) < end) {
-    // unpack the tl and process the values accordingly
-    if(unpack_tl(ppReadPackedMsg, &generic_tl, end) == 0)
-      return 0;
-
-    uint8_t tagMatch = 0;
-    uint8_t *pStartOfValue = *ppReadPackedMsg;
-
-    for(idx = 0; idx < size; ++idx) {
-      if(unpack_fns[idx].tag == generic_tl.tag) {
-        tagMatch = 1;
-        nfapi_tl_t *tl = (nfapi_tl_t *)(unpack_fns[idx].tlv);
-        tl->tag = generic_tl.tag;
-        tl->length = generic_tl.length;
-        int result = (*unpack_fns[idx].unpack_func)(tl, ppReadPackedMsg, end, config);
-
-        if(result == 0) {
-          return  0;
-        }
-
-        // check if the length was right;
-        if(tl->length != (*ppReadPackedMsg - pStartOfValue)) {
-          NFAPI_TRACE(NFAPI_TRACE_ERROR, "Warning tlv tag 0x%x length %d not equal to unpack %d\n", tl->tag, tl->length, (*ppReadPackedMsg - pStartOfValue));
-        }
-      }
-    }
-
-    if(tagMatch == 0) {
-      if(generic_tl.tag >= NFAPI_VENDOR_EXTENSION_MIN_TAG_VALUE &&
-          generic_tl.tag <= NFAPI_VENDOR_EXTENSION_MAX_TAG_VALUE) {
-        int result = unpack_p7_vendor_extension_tlv(&generic_tl, ppReadPackedMsg, end, config, ve);
-
-        if(result == 0) {
-          // got to end
-          return 0;
-        } else if(result < 0) {
-          NFAPI_TRACE(NFAPI_TRACE_ERROR, "Unknown TAG value: 0x%04x\n", generic_tl.tag);
-
-          if (++numBadTags > MAX_BAD_TAG) {
-            NFAPI_TRACE(NFAPI_TRACE_ERROR, "Supplied message has had too many bad tags\n");
-            return -1;
-          }
-
-          if((end - *ppReadPackedMsg) >= generic_tl.length) {
-            // Advance past the unknown TLV
-            (*ppReadPackedMsg) += generic_tl.length;
-          } else {
-            // got ot the dn
-            return 0;
-          }
-        }
-      } else {
-        NFAPI_TRACE(NFAPI_TRACE_ERROR, "Unknown TAG value: 0x%04x\n", generic_tl.tag);
-
-        if (++numBadTags > MAX_BAD_TAG) {
-          NFAPI_TRACE(NFAPI_TRACE_ERROR, "Supplied message has had too many bad tags\n");
-          return -1;
-        }
-
-        if((end - *ppReadPackedMsg) >= generic_tl.length) {
-          // Advance past the unknown TLV
-          (*ppReadPackedMsg) += generic_tl.length;
-        } else {
-          // got ot the dn
-          return 0;
-        }
-      }
-    }
-  }
-
-  return 1;
-}
-
-// This intermediate function deals with calculating the length of the value
-// and writing into the tlv header.
-uint8_t pack_tlv(uint16_t tag, void *tlv, uint8_t **ppWritePackedMsg, uint8_t *end, pack_tlv_fn fn) {
-  nfapi_tl_t *tl = (nfapi_tl_t *)tlv;
-
-  // If the tag is defined
-  if(tl->tag == tag) {
-    uint8_t *pStartOfTlv = *ppWritePackedMsg;
-
-    // write a dumy tlv header
-    if(pack_tl(tl, ppWritePackedMsg, end) == 0)
-      return 0;
-
-    // Record the start of the value
-    uint8_t *pStartOfValue = *ppWritePackedMsg;
-
-    // pack the tlv value
-    if(fn(tlv, ppWritePackedMsg, end) == 0)
-      return 0;
-
-    // calculate the length of the value and rewrite the tl header
-    tl->length = (*ppWritePackedMsg) - pStartOfValue;
-    // rewrite the header with the correct length
-    pack_tl(tl, &pStartOfTlv, end);
-  } else {
-    if(tl->tag != 0) {
-      NFAPI_TRACE(NFAPI_TRACE_WARN, "Warning pack_tlv tag 0x%x does not match expected 0x%x\n", tl->tag, tag);
-    } else {
-      //NFAPI_TRACE(NFAPI_TRACE_ERROR, "Warning pack_tlv tag 0x%x ZERO does not match expected 0x%x\n", tl->tag, tag);
-    }
-  }
-
-  return 1;
-}
-
-const char *nfapi_error_code_to_str(nfapi_error_code_e value) {
-  switch(value) {
-    case NFAPI_MSG_OK:
-      return "NFAPI_MSG_OK";
-
-    case NFAPI_MSG_INVALID_STATE:
-      return "NFAPI_MSG_INVALID_STATE";
-
-    case NFAPI_MSG_INVALID_CONFIG:
-      return "NFAPI_MSG_INVALID_CONFIG";
-
-    case NFAPI_SFN_OUT_OF_SYNC:
-      return "NFAPI_SFN_OUT_OF_SYNC";
-
-    case NFAPI_MSG_SUBFRAME_ERR:
-      return "NFAPI_MSG_SUBFRAME_ERR";
-
-    case NFAPI_MSG_BCH_MISSING:
-      return "NFAPI_MSG_BCH_MISSING";
-
-    case NFAPI_MSG_INVALID_SFN:
-      return "NFAPI_MSG_INVALID_SFN";
-
-    case NFAPI_MSG_HI_ERR:
-      return "NFAPI_MSG_HI_ERR";
-
-    case NFAPI_MSG_TX_ERR:
-      return "NFAPI_MSG_TX_ERR";
-
-    default:
-      return "UNKNOWN";
-  }
-}
+/*
+ * Copyright (c) 2001-2016, Cisco Systems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 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.
+ *
+ * Neither the name of the Cisco Systems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * 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 HOLDERS 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.
+ */
+
+#include <signal.h>
+#include <sys/time.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <sched.h>
+#include <time.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <pthread.h>
+
+#include <nfapi_interface.h>
+#include <nfapi.h>
+#include <debug.h>
+
+
+// Fundamental routines
+
+uint8_t push8(uint8_t in, uint8_t **out, uint8_t *end) {
+  uint8_t *pOut = *out;
+
+  if((end - pOut) >= 1) {
+    pOut[0] = in;
+    (*out)+=1;
+    return 1;
+  } else {
+    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
+    return 0;
+  }
+}
+
+uint8_t pushs8(int8_t in, uint8_t **out, uint8_t *end) {
+  uint8_t *pOut = *out;
+
+  if((end - pOut) >= 1) {
+    pOut[0] = in;
+    (*out)+=1;
+    return 1;
+  } else {
+    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
+    return 0;
+  }
+}
+
+uint8_t push16(uint16_t in, uint8_t **out, uint8_t *end) {
+  uint8_t *pOut = *out;
+
+  if((end - pOut) >= 2) {
+    pOut[0] = (in & 0xFF00) >> 8;
+    pOut[1] = (in & 0xFF);
+    (*out)+=2;
+    return 2;
+  } else {
+    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
+    return 0;
+  }
+}
+
+uint8_t pushs16(int16_t in, uint8_t **out, uint8_t *end) {
+  uint8_t *pOut = *out;
+
+  if((end - pOut) >= 2) {
+    pOut[0] = (in & 0xFF00) >> 8;
+    pOut[1] = (in & 0xFF);
+    (*out)+=2;
+    return 2;
+  } else {
+    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
+    return 0;
+  }
+}
+
+uint8_t push32(uint32_t in, uint8_t **out, uint8_t *end) {
+  uint8_t *pOut = *out;
+
+  if((end - pOut) >= 4) {
+    pOut[0] = (in & 0xFF000000) >> 24;
+    pOut[1] = (in & 0xFF0000) >> 16;
+    pOut[2] = (in & 0xFF00) >> 8;
+    pOut[3] = (in & 0xFF);
+    (*out)+=4;
+    return 4;
+  } else {
+    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
+    return 0;
+  }
+}
+
+uint8_t pushs32(int32_t in, uint8_t **out, uint8_t *end) {
+  uint8_t *pOut = *out;
+
+  if((end - pOut) >= 4) {
+    pOut[0] = (in & 0xFF000000) >> 24;
+    pOut[1] = (in & 0xFF0000) >> 16;
+    pOut[2] = (in & 0xFF00) >> 8;
+    pOut[3] = (in & 0xFF);
+    (*out)+=4;
+    return 4;
+  } else {
+    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
+    return 0;
+  }
+}
+
+uint8_t pull8(uint8_t **in, uint8_t *out, uint8_t *end) {
+  uint8_t *pIn = *in;
+
+  if((end - pIn) >= 1 ) {
+    *out = *pIn;
+    (*in)+=1;
+    return 1;
+  } else {
+    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
+    return 0;
+  }
+}
+
+uint8_t pulls8(uint8_t **in, int8_t *out, uint8_t *end) {
+  uint8_t *pIn = *in;
+
+  if((end - pIn) >= 1 ) {
+    *out = *pIn;
+    (*in)+=1;
+    return 1;
+  } else {
+    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
+    return 0;
+  }
+}
+
+uint8_t pull16(uint8_t **in, uint16_t *out, uint8_t *end) {
+  uint8_t *pIn = *in;
+
+  if((end - pIn) >=2 ) {
+    *out = ((pIn[0]) << 8) | pIn[1];
+    (*in)+=2;
+    return 2;
+  } else {
+    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
+    return 0;
+  }
+}
+
+uint8_t pulls16(uint8_t **in, int16_t *out, uint8_t *end) {
+  uint8_t *pIn = *in;
+
+  if((end - pIn) >=2 ) {
+    *out = ((pIn[0]) << 8) | pIn[1];
+    (*in)+=2;
+    return 2;
+  } else {
+    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
+    return 0;
+  }
+}
+
+uint8_t pull32(uint8_t **in, uint32_t *out, uint8_t *end) {
+  uint8_t *pIn = *in;
+
+  if((end - pIn) >=4 ) {
+    *out = (pIn[0] << 24) | (pIn[1] << 16) | (pIn[2] << 8) | pIn[3];
+    (*in)+=4;
+    return 4;
+  } else {
+    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n",  __FUNCTION__);
+    return 0;
+  }
+}
+
+uint8_t pulls32(uint8_t **in, int32_t *out, uint8_t *end) {
+  uint8_t *pIn = *in;
+
+  if((end - pIn) >=4 ) {
+    *out = (pIn[0] << 24) | (pIn[1] << 16) | (pIn[2] << 8) | pIn[3];
+    (*in)+=4;
+    return 4;
+  } else {
+    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
+    return 0;
+  }
+}
+
+/*
+inline void pusharray16(uint8_t **, uint16_t, uint32_t len)
+{
+}
+*/
+
+uint32_t pullarray16(uint8_t **in, uint16_t out[], uint32_t max_len, uint32_t len, uint8_t *end) {
+  if(len == 0)
+    return 1;
+
+  if(len > max_len) {
+    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, len, max_len);
+    return 0;
+  }
+
+  if((end - (*in)) >= sizeof(uint16_t) * len) {
+    uint32_t idx;
+
+    for(idx = 0; idx < len; ++idx) {
+      if(!pull16(in, &out[idx], end))
+        return 0;
+    }
+
+    return sizeof(uint16_t) * len;
+  } else {
+    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
+    return 0;
+  }
+}
+
+uint32_t pullarrays16(uint8_t **in, int16_t out[], uint32_t max_len, uint32_t len, uint8_t *end) {
+  if(len == 0)
+    return 1;
+
+  if(len > max_len) {
+    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, len, max_len);
+    return 0;
+  }
+
+  if((end - (*in)) >= sizeof(uint16_t) * len) {
+    uint32_t idx;
+
+    for(idx = 0; idx < len; ++idx) {
+      if(!pulls16(in, &out[idx], end))
+        return 0;
+    }
+
+    return sizeof(uint16_t) * len;
+  } else {
+    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
+    return 0;
+  }
+}
+uint32_t pusharray16(uint16_t in[], uint32_t max_len, uint32_t len, uint8_t **out, uint8_t *end) {
+  if(len == 0)
+    return 1;
+
+  if(len > max_len) {
+    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, len, max_len);
+    return 0;
+  }
+
+  if((end - (*out)) >= sizeof(uint16_t) * len) {
+    uint32_t idx;
+
+    for(idx = 0; idx < len; ++idx) {
+      if(!push16(in[idx], out, end))
+        return 0;
+    }
+
+    return sizeof(uint16_t) * len;
+  } else {
+    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
+    return 0;
+  }
+}
+uint32_t pusharrays16(int16_t in[], uint32_t max_len, uint32_t len, uint8_t **out, uint8_t *end) {
+  if(len == 0)
+    return 1;
+
+  if(len > max_len) {
+    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, len, max_len);
+    return 0;
+  }
+
+  if((end - (*out)) >= sizeof(uint16_t) * len) {
+    uint32_t idx;
+
+    for(idx = 0; idx < len; ++idx) {
+      pushs16(in[idx], out, end);
+    }
+
+    return sizeof(uint16_t) * len;
+  } else {
+    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
+    return 0;
+  }
+}
+uint32_t pullarray32(uint8_t **in, uint32_t out[], uint32_t max_len, uint32_t len, uint8_t *end) {
+  if(len == 0)
+    return 1;
+
+  if(len > max_len) {
+    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, len, max_len);
+    return 0;
+  }
+
+  if((end - (*in)) >= sizeof(uint32_t) * len) {
+    uint32_t idx;
+
+    for(idx = 0; idx < len; ++idx) {
+      if(!pull32(in, &out[idx], end))
+        return 0;
+    }
+
+    return sizeof(uint32_t) * len;
+  } else {
+    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
+    return 0;
+  }
+}
+
+uint32_t pullarrays32(uint8_t **in, int32_t out[], uint32_t max_len, uint32_t len, uint8_t *end) {
+  if(len == 0)
+    return 1;
+
+  if(len > max_len) {
+    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, len, max_len);
+    return 0;
+  }
+
+  if((end - (*in)) >= sizeof(uint32_t) * len) {
+    uint32_t idx;
+
+    for(idx = 0; idx < len; ++idx) {
+      if(!pulls32(in, &out[idx], end))
+        return 0;
+    }
+
+    return sizeof(uint32_t) * len;
+  } else {
+    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
+    return 0;
+  }
+}
+uint32_t pusharray32(uint32_t in[], uint32_t max_len, uint32_t len, uint8_t **out, uint8_t *end) {
+  if(len == 0)
+    return 1;
+
+  if(len > max_len) {
+    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, len, max_len);
+    return 0;
+  }
+
+  if((end - (*out)) >= sizeof(uint32_t) * len) {
+    uint32_t idx;
+
+    for(idx = 0; idx < len; ++idx) {
+      if(!push32(in[idx], out, end))
+        return 0;
+    }
+
+    return sizeof(uint32_t) * len;
+  } else {
+    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
+    return 0;
+  }
+}
+uint32_t pusharrays32(int32_t in[], uint32_t max_len, uint32_t len, uint8_t **out, uint8_t *end) {
+  if(len == 0)
+    return 1;
+
+  if(len > max_len) {
+    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, len, max_len);
+    return 0;
+  }
+
+  if((end - (*out)) >= sizeof(uint32_t) * len) {
+    uint32_t idx;
+
+    for(idx = 0; idx < len; ++idx) {
+      pushs32(in[idx], out, end);
+    }
+
+    return sizeof(uint32_t) * len;
+  } else {
+    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
+    return 0;
+  }
+}
+uint32_t pullarray8(uint8_t **in, uint8_t out[], uint32_t max_len, uint32_t len, uint8_t *end) {
+  if(len == 0)
+    return 1;
+
+  if(len > max_len) {
+    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, len, max_len);
+    return 0;
+  }
+
+  if((end - (*in)) >= sizeof(uint8_t) * len) {
+    memcpy(out, (*in), len);
+    (*in)+=len;
+    return sizeof(uint8_t) * len;
+  } else {
+    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
+    return 0;
+  }
+}
+
+uint32_t pusharray8(uint8_t in[], uint32_t max_len, uint32_t len, uint8_t **out, uint8_t *end) {
+  if(len == 0)
+    return 1;
+
+  if(len > max_len) {
+    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, len, max_len);
+    return 0;
+  }
+
+  if((end - (*out)) >= sizeof(uint8_t) * len) {
+    memcpy((*out), in, len);
+    (*out)+=len;
+    return sizeof(uint8_t) * len;
+  } else {
+    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
+    return 0;
+  }
+}
+
+uint8_t packarray(void *array, uint16_t array_element_size, uint16_t max_count, uint16_t count, uint8_t **ppwritepackedmsg, uint8_t *end, pack_array_elem_fn fn) {
+  if(count > max_count) {
+    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, count, max_count);
+    return 0;
+  }
+
+  uint16_t i = 0;
+
+  for(i = 0; i < count; ++i) {
+    if((fn)(array, ppwritepackedmsg, end) == 0)
+      return 0;
+
+    array += array_element_size;
+  }
+
+  return 1;
+}
+
+uint8_t unpackarray(uint8_t **ppReadPackedMsg, void *array, uint16_t array_element_size, uint16_t max_count, uint16_t count, uint8_t *end, unpack_array_elem_fn fn) {
+  if(count > max_count) {
+    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, count, max_count);
+    return 0;
+  }
+
+  uint16_t i = 0;
+
+  for(i = 0; i < count; ++i) {
+    if((fn)(array, ppReadPackedMsg, end) == 0)
+      return 0;
+
+    array += array_element_size;
+  }
+
+  return 1;
+}
+
+
+uint32_t pack_vendor_extension_tlv(nfapi_tl_t *ve, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t *config) {
+  if(ve != 0 && config != 0) {
+    if(config->pack_vendor_extension_tlv) {
+      uint8_t *pStartOfTlv = *ppWritePackedMsg;
+
+      if(pack_tl(ve, ppWritePackedMsg, end) == 0)
+        return 0;
+
+      uint8_t *pStartOfValue = *ppWritePackedMsg;
+
+      if((config->pack_vendor_extension_tlv)(ve, ppWritePackedMsg, end, config) == 0)
+        return 0;
+
+      ve->length = (*ppWritePackedMsg) - pStartOfValue;
+      pack_tl(ve, &pStartOfTlv, end);
+      return 1;
+    }
+  }
+
+  return 1;
+}
+
+uint32_t unpack_vendor_extension_tlv(nfapi_tl_t *tl, uint8_t **ppReadPackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t *config, nfapi_tl_t **ve_tlv) {
+  if(ve_tlv != 0 && config != 0) {
+    if(config->unpack_vendor_extension_tlv) {
+      return (config->unpack_vendor_extension_tlv)(tl, ppReadPackedMsg, end, (void **)ve_tlv, config);
+    }
+  }
+
+  return 1;
+}
+
+uint32_t pack_p7_vendor_extension_tlv(nfapi_tl_t *ve, uint8_t **ppWritePackedMsg, uint8_t *end,nfapi_p7_codec_config_t *config) {
+  if(ve != 0 && config != 0) {
+    if(config->pack_vendor_extension_tlv) {
+      uint8_t *pStartOfTlv = *ppWritePackedMsg;
+
+      if(pack_tl(ve, ppWritePackedMsg, end) == 0)
+        return 0;
+
+      uint8_t *pStartOfValue = *ppWritePackedMsg;
+
+      if((config->pack_vendor_extension_tlv)(ve, ppWritePackedMsg, end, config) == 0)
+        return 0;
+
+      ve->length = (*ppWritePackedMsg) - pStartOfValue;
+      pack_tl(ve, &pStartOfTlv, end);
+      return 1;
+    }
+  }
+
+  return 1;
+}
+
+int unpack_p7_vendor_extension_tlv(nfapi_tl_t *tl, uint8_t **ppReadPackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config, nfapi_tl_t **ve_tlv) {
+  if(ve_tlv != 0 && config != 0) {
+    if(config->unpack_vendor_extension_tlv) {
+      return (config->unpack_vendor_extension_tlv)(tl, ppReadPackedMsg, end, (void **)ve_tlv, config);
+    }
+  }
+
+  return 1;
+}
+
+
+uint8_t pack_tl(nfapi_tl_t *tl, uint8_t **ppWritePackedMsg, uint8_t *end) {
+  return (push16(tl->tag, ppWritePackedMsg, end) &&
+          push16(tl->length, ppWritePackedMsg, end));
+}
+
+uint8_t unpack_tl(uint8_t **ppReadPackedMsg, nfapi_tl_t *tl, uint8_t *end) {
+  return (pull16(ppReadPackedMsg, &tl->tag, end) &&
+          pull16(ppReadPackedMsg, &tl->length, end));
+}
+
+int unpack_tlv_list(unpack_tlv_t unpack_fns[], uint16_t size, uint8_t **ppReadPackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t *config, nfapi_tl_t **ve) {
+  nfapi_tl_t generic_tl;
+  uint8_t numBadTags = 0;
+  uint16_t idx = 0;
+
+  while ((uint8_t *)(*ppReadPackedMsg) < end) {
+    // unpack the tl and process the values accordingly
+    if(unpack_tl(ppReadPackedMsg, &generic_tl, end) == 0)
+      return 0;
+
+    uint8_t tagMatch = 0;
+    uint8_t *pStartOfValue = *ppReadPackedMsg;
+
+    for(idx = 0; idx < size; ++idx) {
+      if(unpack_fns[idx].tag == generic_tl.tag) { // match the extracted tag value with all the tags in unpack_fn list
+        tagMatch = 1;
+        nfapi_tl_t *tl = (nfapi_tl_t *)(unpack_fns[idx].tlv);
+        tl->tag = generic_tl.tag;
+        tl->length = generic_tl.length;
+        int result = (*unpack_fns[idx].unpack_func)(tl, ppReadPackedMsg, end);
+
+        if(result == 0) {
+          return 0;
+        }
+
+        // check if the length was right;
+        if(tl->length != (*ppReadPackedMsg - pStartOfValue)) {
+          NFAPI_TRACE(NFAPI_TRACE_ERROR, "Warning tlv tag 0x%x length %d not equal to unpack %ld\n", tl->tag, tl->length, (*ppReadPackedMsg - pStartOfValue));
+        }
+      }
+    }
+
+    if(tagMatch == 0) {
+      if(generic_tl.tag >= NFAPI_VENDOR_EXTENSION_MIN_TAG_VALUE &&
+          generic_tl.tag <= NFAPI_VENDOR_EXTENSION_MAX_TAG_VALUE) {
+        int result = unpack_vendor_extension_tlv(&generic_tl, ppReadPackedMsg, end, config, ve);
+
+        if(result == 0) {
+          // got tot the end.
+          return 0;
+        } else if(result < 0) {
+          NFAPI_TRACE(NFAPI_TRACE_ERROR, "Unknown VE TAG value: 0x%04x\n", generic_tl.tag);
+
+          if (++numBadTags > MAX_BAD_TAG) {
+            NFAPI_TRACE(NFAPI_TRACE_ERROR, "Supplied message has had too many bad tags\n");
+            return 0;
+          }
+
+          if((end - *ppReadPackedMsg) >= generic_tl.length) {
+            // Advance past the unknown TLV
+            (*ppReadPackedMsg) += generic_tl.length;
+          } else {
+            // go to the end
+            return 0;
+          }
+        }
+      } else {
+        NFAPI_TRACE(NFAPI_TRACE_ERROR, "Unknown TAG value: 0x%04x\n", generic_tl.tag);
+
+        if (++numBadTags > MAX_BAD_TAG) {
+          NFAPI_TRACE(NFAPI_TRACE_ERROR, "Supplied message has had too many bad tags\n");
+          return 0;
+        }
+
+        if((end - *ppReadPackedMsg) >= generic_tl.length) {
+          // Advance past the unknown TLV
+          (*ppReadPackedMsg) += generic_tl.length;
+        } else {
+          // go to the end
+          return 0;
+        }
+      }
+    }
+  }
+
+  return 1;
+}
+int unpack_p7_tlv_list(unpack_p7_tlv_t unpack_fns[], uint16_t size, uint8_t **ppReadPackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config, nfapi_tl_t **ve) {
+  nfapi_tl_t generic_tl;
+  uint8_t numBadTags = 0;
+  uint16_t idx = 0;
+
+  while ((uint8_t *)(*ppReadPackedMsg) < end) {
+    // unpack the tl and process the values accordingly
+    if(unpack_tl(ppReadPackedMsg, &generic_tl, end) == 0)
+      return 0;
+
+    uint8_t tagMatch = 0;
+    uint8_t *pStartOfValue = *ppReadPackedMsg;
+
+    for(idx = 0; idx < size; ++idx) {
+      if(unpack_fns[idx].tag == generic_tl.tag) {
+        tagMatch = 1;
+        nfapi_tl_t *tl = (nfapi_tl_t *)(unpack_fns[idx].tlv);
+        tl->tag = generic_tl.tag;
+        tl->length = generic_tl.length;
+        int result = (*unpack_fns[idx].unpack_func)(tl, ppReadPackedMsg, end, config);
+
+        if(result == 0) {
+          return  0;
+        }
+
+        // check if the length was right;
+        if(tl->length != (*ppReadPackedMsg - pStartOfValue)) {
+          NFAPI_TRACE(NFAPI_TRACE_ERROR, "Warning tlv tag 0x%x length %d not equal to unpack %ld\n", tl->tag, tl->length, (*ppReadPackedMsg - pStartOfValue));
+        }
+      }
+    }
+
+    if(tagMatch == 0) {
+      if(generic_tl.tag >= NFAPI_VENDOR_EXTENSION_MIN_TAG_VALUE &&
+          generic_tl.tag <= NFAPI_VENDOR_EXTENSION_MAX_TAG_VALUE) {
+        int result = unpack_p7_vendor_extension_tlv(&generic_tl, ppReadPackedMsg, end, config, ve);
+
+        if(result == 0) {
+          // got to end
+          return 0;
+        } else if(result < 0) {
+          NFAPI_TRACE(NFAPI_TRACE_ERROR, "Unknown TAG value: 0x%04x\n", generic_tl.tag);
+
+          if (++numBadTags > MAX_BAD_TAG) {
+            NFAPI_TRACE(NFAPI_TRACE_ERROR, "Supplied message has had too many bad tags\n");
+            return -1;
+          }
+
+          if((end - *ppReadPackedMsg) >= generic_tl.length) {
+            // Advance past the unknown TLV
+            (*ppReadPackedMsg) += generic_tl.length;
+          } else {
+            // got ot the dn
+            return 0;
+          }
+        }
+      } else {
+        NFAPI_TRACE(NFAPI_TRACE_ERROR, "Unknown TAG value: 0x%04x\n", generic_tl.tag);
+
+        if (++numBadTags > MAX_BAD_TAG) {
+          NFAPI_TRACE(NFAPI_TRACE_ERROR, "Supplied message has had too many bad tags\n");
+          return -1;
+        }
+
+        if((end - *ppReadPackedMsg) >= generic_tl.length) {
+          // Advance past the unknown TLV
+          (*ppReadPackedMsg) += generic_tl.length;
+        } else {
+          // got ot the dn
+          return 0;
+        }
+      }
+    }
+  }
+
+  return 1;
+}
+
+// This intermediate function deals with calculating the length of the value
+// and writing into the tlv header.
+uint8_t pack_tlv(uint16_t tag, void *tlv, uint8_t **ppWritePackedMsg, uint8_t *end, pack_tlv_fn fn) {
+  nfapi_tl_t *tl = (nfapi_tl_t *)tlv;
+
+  // If the tag is defined
+  if(tl->tag == tag) {
+    uint8_t *pStartOfTlv = *ppWritePackedMsg;
+
+    // write a dumy tlv header
+    if(pack_tl(tl, ppWritePackedMsg, end) == 0)
+      return 0;
+
+    // Record the start of the value
+    uint8_t *pStartOfValue = *ppWritePackedMsg;
+
+    // pack the tlv value
+    if(fn(tlv, ppWritePackedMsg, end) == 0)
+      return 0;
+
+    // calculate the length of the value and rewrite the tl header
+    tl->length = (*ppWritePackedMsg) - pStartOfValue;
+    // rewrite the header with the correct length
+    pack_tl(tl, &pStartOfTlv, end);
+  } else {
+    if(tl->tag != 0) {
+      NFAPI_TRACE(NFAPI_TRACE_WARN, "Warning pack_tlv tag 0x%x does not match expected 0x%x\n", tl->tag, tag);
+    } else {
+      //NFAPI_TRACE(NFAPI_TRACE_ERROR, "Warning pack_tlv tag 0x%x ZERO does not match expected 0x%x\n", tl->tag, tag);
+    }
+  }
+
+  return 1;
+}
+
+const char *nfapi_error_code_to_str(nfapi_error_code_e value) {
+  switch(value) {
+    case NFAPI_MSG_OK:
+      return "NFAPI_MSG_OK";
+
+    case NFAPI_MSG_INVALID_STATE:
+      return "NFAPI_MSG_INVALID_STATE";
+
+    case NFAPI_MSG_INVALID_CONFIG:
+      return "NFAPI_MSG_INVALID_CONFIG";
+
+    case NFAPI_SFN_OUT_OF_SYNC:
+      return "NFAPI_SFN_OUT_OF_SYNC";
+
+    case NFAPI_MSG_SUBFRAME_ERR:
+      return "NFAPI_MSG_SUBFRAME_ERR";
+
+    case NFAPI_MSG_BCH_MISSING:
+      return "NFAPI_MSG_BCH_MISSING";
+
+    case NFAPI_MSG_INVALID_SFN:
+      return "NFAPI_MSG_INVALID_SFN";
+
+    case NFAPI_MSG_HI_ERR:
+      return "NFAPI_MSG_HI_ERR";
+
+    case NFAPI_MSG_TX_ERR:
+      return "NFAPI_MSG_TX_ERR";
+
+    default:
+      return "UNKNOWN";
+  }
+}
diff --git a/nfapi/open-nFAPI/nfapi/src/nfapi_p4.c b/nfapi/open-nFAPI/nfapi/src/nfapi_p4.c
index dbaa4347d33313ce4957b106c623d02ddf28c858..6e79af6348a7f11c72df0067fe925e25f427f492 100644
--- a/nfapi/open-nFAPI/nfapi/src/nfapi_p4.c
+++ b/nfapi/open-nFAPI/nfapi/src/nfapi_p4.c
@@ -29,7 +29,7 @@
 
 static uint32_t get_packed_msg_len(uintptr_t msgHead, uintptr_t msgEnd) {
   if (msgEnd < msgHead) {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "get_packed_msg_len: Error in pointers supplied %d, %d\n", msgHead, msgEnd);
+    NFAPI_TRACE(NFAPI_TRACE_ERROR, "get_packed_msg_len: Error in pointers supplied %lu, %lu\n", msgHead, msgEnd);
     return 0;
   }
 
diff --git a/nfapi/open-nFAPI/nfapi/src/nfapi_p5.c b/nfapi/open-nFAPI/nfapi/src/nfapi_p5.c
index 3a6d807bdd08c06c1fe707f092df8a40b2d3a907..32b87f80e01dfe31d0efbf068b6b9cf277fd41c9 100644
--- a/nfapi/open-nFAPI/nfapi/src/nfapi_p5.c
+++ b/nfapi/open-nFAPI/nfapi/src/nfapi_p5.c
@@ -429,16 +429,6 @@ static uint8_t pack_embms_mbsfn_config_value(void *tlv, uint8_t **ppWritePackedM
            pusharray8(value->fourframes_flag, 8,value->num_mbsfn_config,ppWritePackedMsg, end) &&
            pusharrays32(value->mbsfn_subframeconfig, 8, value->num_mbsfn_config, ppWritePackedMsg, end));
 }
-// static uint8_t unpack_embms_mbsfn_config_value(void* tlv, uint8_t **ppReadPackedMsg, uint8_t* end)
-// {
-//     nfapi_embms_mbsfn_config_t* value = (nfapi_embms_mbsfn_config_t*)tlv;
-
-//     return ( pull16(ppReadPackedMsg, &value->num_mbsfn_config, end) &&
-//              pull16(ppReadPackedMsg, &value->radioframe_allocation_period, end) &&
-//              pull16(ppReadPackedMsg, &value->radioframe_allocation_offset, end) &&
-//              pull8(ppReadPackedMsg, &value->fourframes_flag, end) &&
-//                      pullarrays32(ppReadPackedMsg, value->mbsfn_subframeconfig, 8, value->num_mbsfn_config, end));
-// }
 
 static uint8_t pack_param_response(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t *config) {
   nfapi_param_response_t *pNfapiMsg = (nfapi_param_response_t *)msg;
@@ -734,10 +724,10 @@ static uint8_t pack_nr_config_request(void *msg, uint8_t **ppWritePackedMsg, uin
 			pack_tlv(NFAPI_NR_CONFIG_UL_K0_TAG, &(pNfapiMsg->carrier_config.ul_k0[1]), ppWritePackedMsg, end, &pack_uint16_tlv_value) &&
 			pack_tlv(NFAPI_NR_CONFIG_UPLINK_BANDWIDTH_TAG, &(pNfapiMsg->carrier_config.uplink_bandwidth), ppWritePackedMsg, end, &pack_uint16_tlv_value) &&
 			pack_tlv(NFAPI_NR_CONFIG_UPLINK_FREQUENCY_TAG, &(pNfapiMsg->carrier_config.uplink_frequency), ppWritePackedMsg, end, &pack_uint32_tlv_value) &&
-
+			
 			pack_tlv(NFAPI_NR_CONFIG_FRAME_DUPLEX_TYPE_TAG, &(pNfapiMsg->cell_config.frame_duplex_type), ppWritePackedMsg, end, &pack_uint8_tlv_value) &&
 			pack_tlv(NFAPI_NR_CONFIG_PHY_CELL_ID_TAG, &(pNfapiMsg->cell_config.phy_cell_id), ppWritePackedMsg, end, &pack_uint8_tlv_value) &&
-
+			
 			pack_tlv(NFAPI_NR_CONFIG_NUM_PRACH_FD_OCCASIONS_TAG, &(pNfapiMsg->prach_config.num_prach_fd_occasions), ppWritePackedMsg, end, &pack_uint8_tlv_value) &&
 			pack_tlv(NFAPI_NR_CONFIG_PRACH_SEQUENCE_LENGTH_TAG, &(pNfapiMsg->prach_config.prach_sequence_length), ppWritePackedMsg, end, &pack_uint8_tlv_value) &&
 			pack_tlv(NFAPI_NR_CONFIG_RESTRICTED_SET_CONFIG_TAG, &(pNfapiMsg->prach_config.restricted_set_config), ppWritePackedMsg, end, &pack_uint8_tlv_value) &&
@@ -1036,7 +1026,7 @@ static uint8_t pack_p5_message_body(nfapi_p4_p5_message_header_t *header, uint8_
 
 static uint32_t get_packed_msg_len(uintptr_t msgHead, uintptr_t msgEnd) {
   if (msgEnd < msgHead) {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "get_packed_msg_len: Error in pointers supplied %d, %d\n", msgHead, msgEnd);
+    NFAPI_TRACE(NFAPI_TRACE_ERROR, "get_packed_msg_len: Error in pointers supplied %lu, %lu\n", msgHead, msgEnd);
     return 0;
   }
 
@@ -1351,7 +1341,6 @@ static uint8_t unpack_nr_pnf_config_request(uint8_t **ppReadPackedMsg, uint8_t *
 }
 
 
-
 static uint8_t unpack_pnf_config_request(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p4_p5_codec_config_t *config) {
   nfapi_pnf_config_request_t *pNfapiMsg = (nfapi_pnf_config_request_t *)msg;
   unpack_tlv_t unpack_fns[] = {
@@ -1723,6 +1712,7 @@ static uint8_t unpack_config_request(uint8_t **ppReadPackedMsg, uint8_t *end, vo
   return ( pull8(ppReadPackedMsg, &pNfapiMsg->num_tlv, end) &&
            unpack_tlv_list(unpack_fns, sizeof(unpack_fns)/sizeof(unpack_tlv_t), ppReadPackedMsg, end, config, &pNfapiMsg->vendor_extension));
 }
+
 static uint8_t unpack_nr_config_request(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p4_p5_codec_config_t* config)
 {
 	nfapi_nr_config_request_scf_t *pNfapiMsg = (nfapi_nr_config_request_scf_t*)msg;
@@ -1786,7 +1776,7 @@ static uint8_t unpack_nr_config_request(uint8_t **ppReadPackedMsg, uint8_t *end,
 
 	return ( pull8(ppReadPackedMsg, &pNfapiMsg->num_tlv, end) &&
 			 unpack_tlv_list(unpack_fns, sizeof(unpack_fns)/sizeof(unpack_tlv_t), ppReadPackedMsg, end, config, &pNfapiMsg->vendor_extension));
-
+		
 }
 
 static uint8_t unpack_config_response(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p4_p5_codec_config_t *config) {
@@ -2386,3 +2376,4 @@ int nfapi_p5_message_unpack(void *pMessageBuf, uint32_t messageBufLen, void *pUn
 
   return result;
 }
+
diff --git a/nfapi/open-nFAPI/nfapi/src/nfapi_p7.c b/nfapi/open-nFAPI/nfapi/src/nfapi_p7.c
index 7cb74f8562c34ac307659fad66bab82dddad5eee..adc6d6e384124b1b3ebcf97cad27f2d1d52e71cf 100644
--- a/nfapi/open-nFAPI/nfapi/src/nfapi_p7.c
+++ b/nfapi/open-nFAPI/nfapi/src/nfapi_p7.c
@@ -223,7 +223,6 @@ static uint8_t pack_dl_tti_csi_rs_pdu_rel15_value(void *tlv, uint8_t **ppWritePa
 static uint8_t pack_dl_tti_pdcch_pdu_rel15_value(void* tlv, uint8_t **ppWritePackedMsg, uint8_t *end) {
 
 	nfapi_nr_dl_tti_pdcch_pdu_rel15_t* value = (nfapi_nr_dl_tti_pdcch_pdu_rel15_t*)tlv;
-
 	for(uint8_t i = 0; i < MAX_DCI_CORESET; ++i)
 	{
 		if(!(push16(value->dci_pdu[i].RNTI, ppWritePackedMsg, end) &&
@@ -236,7 +235,6 @@ static uint8_t pack_dl_tti_pdcch_pdu_rel15_value(void* tlv, uint8_t **ppWritePac
 		push16(value->dci_pdu[i].PayloadSizeBits, ppWritePackedMsg, end) &&
 		pusharray8(value->dci_pdu[i].Payload, value->dci_pdu[i].PayloadSizeBits, value->dci_pdu[i].PayloadSizeBits, ppWritePackedMsg, end)))
 		return 0;
-
 	}
 	// TODO: resolve the packaging of array (currently sending a single element)
 	return(
@@ -300,17 +298,21 @@ static uint8_t pack_dl_tti_pdsch_pdu_rel15_value(void *tlv, uint8_t **ppWritePac
 
 
 static uint8_t pack_dl_tti_ssb_pdu_rel15_value(void *tlv, uint8_t **ppWritePackedMsg, uint8_t *end) {
-  nfapi_nr_dl_tti_ssb_pdu_rel15_t *value = (nfapi_nr_dl_tti_ssb_pdu_rel15_t *)tlv;
-  return(
-          push16(value->PhysCellId, ppWritePackedMsg, end) &&
-          push8(value->BetaPss, ppWritePackedMsg, end) &&
-          push8(value->SsbBlockIndex, ppWritePackedMsg, end) &&
-          push8(value->SsbSubcarrierOffset, ppWritePackedMsg, end) &&
-          push16(value->ssbOffsetPointA, ppWritePackedMsg, end) &&
-          push8(value->bchPayloadFlag, ppWritePackedMsg, end) &&
-          push32(value->bchPayload, ppWritePackedMsg, end)
-          // TODO: pack precoding_and_beamforming too
-        );
+	NFAPI_TRACE(NFAPI_TRACE_DEBUG, "Packing ssb. \n");
+	nfapi_nr_dl_tti_ssb_pdu_rel15_t* value = (nfapi_nr_dl_tti_ssb_pdu_rel15_t*)tlv;
+
+	return(
+		push16(value->PhysCellId, ppWritePackedMsg, end) &&
+		push8(value->BetaPss, ppWritePackedMsg, end) &&
+		push8(value->SsbBlockIndex, ppWritePackedMsg, end) &&
+		push8(value->SsbSubcarrierOffset, ppWritePackedMsg, end) &&
+		push16(value->ssbOffsetPointA, ppWritePackedMsg, end) &&
+		push8(value->bchPayloadFlag, ppWritePackedMsg, end) &&
+		push32(value->bchPayload, ppWritePackedMsg, end) &&
+		push8(value->ssbRsrp, ppWritePackedMsg, end)
+		// TODO: pack precoding_and_beamforming too
+	);
+
 }
 
 
@@ -778,38 +780,41 @@ static uint8_t pack_dl_config_request_body_value(void *tlv, uint8_t **ppWritePac
 }
 
 
-static uint8_t pack_dl_tti_request(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config) {
-  nfapi_nr_dl_tti_request_t *pNfapiMsg = (nfapi_nr_dl_tti_request_t *)msg;
-
-  if (!(push16(pNfapiMsg->SFN, ppWritePackedMsg, end) &&
-        push16(pNfapiMsg->Slot, ppWritePackedMsg, end) &&
-        push8(pNfapiMsg->dl_tti_request_body.nGroup, ppWritePackedMsg, end) &&
-        push8(pNfapiMsg->dl_tti_request_body.nPDUs, ppWritePackedMsg, end) &&
-        pusharray8(pNfapiMsg->dl_tti_request_body.nUe,256,pNfapiMsg->dl_tti_request_body.nGroup, ppWritePackedMsg, end)
-        //pusharray8(pNfapiMsg->PduIdx[0] ,256,256, ppWritePackedMsg, end)
-       ))
-    return 0;
-
-  int arr[12];
-
-  for(int i=0; i<pNfapiMsg->dl_tti_request_body.nGroup; i++) {
-    for(int j=0; j<pNfapiMsg->dl_tti_request_body.nUe[i]; j++) {
-      arr[j] = pNfapiMsg->dl_tti_request_body.PduIdx[i][j];
-    }
+static uint8_t pack_dl_tti_request(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t* config)
+{
+	nfapi_nr_dl_tti_request_t *pNfapiMsg = (nfapi_nr_dl_tti_request_t*)msg;
+
+	if (!(push16(pNfapiMsg->SFN , ppWritePackedMsg, end) &&
+		push16(pNfapiMsg->Slot , ppWritePackedMsg, end) &&
+		push8(pNfapiMsg->dl_tti_request_body.nGroup , ppWritePackedMsg, end) &&
+		push8(pNfapiMsg->dl_tti_request_body.nPDUs , ppWritePackedMsg, end) &&
+		pusharray8(pNfapiMsg->dl_tti_request_body.nUe, 256, pNfapiMsg->dl_tti_request_body.nGroup, ppWritePackedMsg, end)
+		//pusharray8(pNfapiMsg->PduIdx[0] ,256,256, ppWritePackedMsg, end)
+		))
+			return 0;
 
-    if(!(pusharrays32(arr,12,pNfapiMsg->dl_tti_request_body.nUe[i],ppWritePackedMsg, end)))
-      return 0;
-  }
+	int arr[12];
+	for(int i=0;i<pNfapiMsg->dl_tti_request_body.nGroup;i++)
+	{
+		for(int j=0;j<pNfapiMsg->dl_tti_request_body.nUe[i];j++)
+		{
+			arr[j] = pNfapiMsg->dl_tti_request_body.PduIdx[i][j];
+		}
+		if(!(pusharrays32(arr, 12, pNfapiMsg->dl_tti_request_body.nUe[i], ppWritePackedMsg, end)))
+		return 0;
+	}
 
-  for(int i=0; i<pNfapiMsg->dl_tti_request_body.nPDUs; i++) {
-    if(!pack_dl_tti_request_body_value(&pNfapiMsg->dl_tti_request_body.dl_tti_pdu_list[i],ppWritePackedMsg,end))
-      return 0;
-  }
+	for(int i=0;i<pNfapiMsg->dl_tti_request_body.nPDUs;i++)	
+	{
+		if(!pack_dl_tti_request_body_value(&pNfapiMsg->dl_tti_request_body.dl_tti_pdu_list[i],ppWritePackedMsg,end))
+		return 0;
+	}
 
-  return 1;
+return 1;
 }
 
 
+
 static uint8_t pack_dl_config_request(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config) {
   nfapi_dl_config_request_t *pNfapiMsg = (nfapi_dl_config_request_t *)msg;
   //return ( push16(pNfapiMsg->sfn_sf, ppWritePackedMsg, end) &&
@@ -902,6 +907,7 @@ static uint8_t pack_ul_tti_request_pucch_pdu(nfapi_nr_pucch_pdu_t *pucch_pdu, ui
           push8(pucch_pdu->cyclic_prefix, ppWritePackedMsg, end) &&
           push8(pucch_pdu->format_type, ppWritePackedMsg, end) &&
           push8(pucch_pdu->multi_slot_tx_indicator, ppWritePackedMsg, end) &&
+          push8(pucch_pdu->pi_2bpsk, ppWritePackedMsg, end) &&
           push16(pucch_pdu->prb_start, ppWritePackedMsg, end) &&
           push16(pucch_pdu->prb_size, ppWritePackedMsg, end) &&
           push8(pucch_pdu->start_symbol_index, ppWritePackedMsg, end) &&
@@ -1803,7 +1809,6 @@ static uint8_t pack_hi_dci0_request_body_value(void *tlv, uint8_t **ppWritePacke
 static uint8_t pack_ul_dci_pdu_list_value(void* tlv, uint8_t **ppWritePackedMsg, uint8_t *end)
 {
 	nfapi_nr_ul_dci_request_pdus_t* value = (nfapi_nr_ul_dci_request_pdus_t*)tlv;
-
 	for(uint8_t i = 0; i < MAX_DCI_CORESET; ++i)
 	{
 		if(!(push16(value->pdcch_pdu.pdcch_pdu_rel15.dci_pdu[i].RNTI, ppWritePackedMsg, end) &&
@@ -1816,7 +1821,6 @@ static uint8_t pack_ul_dci_pdu_list_value(void* tlv, uint8_t **ppWritePackedMsg,
 
 		push8(value->pdcch_pdu.pdcch_pdu_rel15.dci_pdu[i].powerControlOffsetSS, ppWritePackedMsg, end) &&
 		push16(value->pdcch_pdu.pdcch_pdu_rel15.dci_pdu[i].PayloadSizeBits, ppWritePackedMsg, end) &&
-
 		pusharray8(value->pdcch_pdu.pdcch_pdu_rel15.dci_pdu[i].Payload, value->pdcch_pdu.pdcch_pdu_rel15.dci_pdu[i].PayloadSizeBits, value->pdcch_pdu.pdcch_pdu_rel15.dci_pdu[i].PayloadSizeBits, ppWritePackedMsg, end)))
 
 		return 0;
@@ -2263,6 +2267,7 @@ static uint8_t pack_crc_indication_body_value(void *tlv, uint8_t **ppWritePacked
   uint16_t i = 0;
   uint16_t total_number_of_pdus = value->number_of_crcs;
 
+  assert(total_number_of_pdus <= NFAPI_CRC_IND_MAX_PDU);
   for(; i < total_number_of_pdus; ++i) {
     nfapi_crc_indication_pdu_t *pdu = &(value->crc_pdu_list[i]);
     uint8_t *instance_length_p = *ppWritePackedMsg;
@@ -2304,7 +2309,7 @@ static uint8_t pack_rx_indication_rel9_value(void *tlv, uint8_t **ppWritePackedM
 static uint8_t pack_rx_ulsch_indication_body_value(void *tlv, uint8_t **ppWritePackedMsg, uint8_t *end) {
   nfapi_rx_indication_body_t *value = (nfapi_rx_indication_body_t *)tlv;
 
-  //printf("RX ULSCH BODY\n");
+  //NFAPI_TRACE(NFAPI_TRACE_DEBUG, "RX ULSCH BODY\n");
 
   if( push16(value->number_of_pdus, ppWritePackedMsg, end) == 0)
     return 0;
@@ -2313,28 +2318,30 @@ static uint8_t pack_rx_ulsch_indication_body_value(void *tlv, uint8_t **ppWriteP
   uint16_t i = 0;
   uint16_t offset = 2; // taking into account the number_of_pdus
   uint16_t total_number_of_pdus = value->number_of_pdus;
-  //printf("ULSCH:pdus:%d\n", total_number_of_pdus);
+  //NFAPI_TRACE(NFAPI_TRACE_DEBUG, "ULSCH:pdus:%d\n", total_number_of_pdus);
 
+  assert(total_number_of_pdus <= NFAPI_RX_IND_MAX_PDU);
   for(i = 0; i < total_number_of_pdus; ++i) {
     nfapi_rx_indication_pdu_t *pdu = &(value->rx_pdu_list[i]);
 
     if(pdu->rx_ue_information.tl.tag == NFAPI_RX_UE_INFORMATION_TAG) {
-      //printf("NFAPI_RX_UE_INFORMATION_TAG\n");
+      //NFAPI_TRACE(NFAPI_TRACE_DEBUG, "NFAPI_RX_UE_INFORMATION_TAG\n");
       offset += 4 + 6;
     }
 
     if(pdu->rx_indication_rel8.tl.tag == NFAPI_RX_INDICATION_REL8_TAG) {
-      //printf("NFAPI_RX_INDICATION_REL8_TAG\n");
+      //NFAPI_TRACE(NFAPI_TRACE_DEBUG, "NFAPI_RX_INDICATION_REL8_TAG\n");
       offset += 4 + 7;
     }
 
     if(pdu->rx_indication_rel9.tl.tag == NFAPI_RX_INDICATION_REL9_TAG) {
-      //printf("NFAPI_RX_INDICATION_REL9_TAG\n");
+      //NFAPI_TRACE(NFAPI_TRACE_DEBUG, "NFAPI_RX_INDICATION_REL9_TAG\n");
       offset += 4 + 2;
     }
   }
 
   // Now update the structure to include the offset
+  assert(total_number_of_pdus <= NFAPI_RX_IND_MAX_PDU);
   for(i =0; i < total_number_of_pdus; ++i) {
     nfapi_rx_indication_pdu_t *pdu = &(value->rx_pdu_list[i]);
 
@@ -2347,6 +2354,7 @@ static uint8_t pack_rx_ulsch_indication_body_value(void *tlv, uint8_t **ppWriteP
   }
 
   // Write out the pdu
+  assert(total_number_of_pdus <= NFAPI_RX_IND_MAX_PDU);
   for(i = 0; i < total_number_of_pdus; ++i) {
     nfapi_rx_indication_pdu_t *pdu = &(value->rx_pdu_list[i]);
 
@@ -2357,6 +2365,7 @@ static uint8_t pack_rx_ulsch_indication_body_value(void *tlv, uint8_t **ppWriteP
   }
 
   // Write out the pdu data
+  assert(total_number_of_pdus <= NFAPI_RX_IND_MAX_PDU);
   for(i = 0; i < total_number_of_pdus; ++i) {
     uint16_t length = 0;
     nfapi_rx_indication_pdu_t *pdu = &(value->rx_pdu_list[i]);
@@ -2365,7 +2374,7 @@ static uint8_t pack_rx_ulsch_indication_body_value(void *tlv, uint8_t **ppWriteP
       length = pdu->rx_indication_rel8.length;
     }
 
-    if( pusharray8(value->rx_pdu_list[i].data, length, length, ppWritePackedMsg, end) == 0)
+    if( pusharray8(value->rx_pdu_list[i].rx_ind_data, NFAPI_RX_IND_DATA_MAX, length, ppWritePackedMsg, end) == 0)
       return 0;
   }
 
@@ -2584,6 +2593,7 @@ static uint8_t pack_cqi_indication_body_value(void *tlv, uint8_t **ppWritePacked
   uint16_t offset = 2; // taking into account the number_of_cqis
   uint16_t total_number_of_pdus = value->number_of_cqis;
 
+  assert(total_number_of_pdus <= NFAPI_CQI_IND_MAX_PDU);
   for(i = 0; i < total_number_of_pdus; ++i) {
     nfapi_cqi_indication_pdu_t *pdu = &(value->cqi_pdu_list[i]);
     offset += 2; // for the instance length
@@ -2625,6 +2635,7 @@ static uint8_t pack_cqi_indication_body_value(void *tlv, uint8_t **ppWritePacked
   }
 
   // Write out the cqi information
+  assert(total_number_of_pdus <= NFAPI_CQI_IND_MAX_PDU);
   for(i = 0; i < total_number_of_pdus; ++i) {
     nfapi_cqi_indication_pdu_t *pdu = &(value->cqi_pdu_list[i]);
     uint8_t *instance_length_p = *ppWritePackedMsg;
@@ -2645,6 +2656,7 @@ static uint8_t pack_cqi_indication_body_value(void *tlv, uint8_t **ppWritePacked
   }
 
   // Write out the cqi raw data
+  assert(total_number_of_pdus <= NFAPI_CQI_IND_MAX_PDU);
   for(i = 0; i < total_number_of_pdus; ++i) {
     uint16_t length = 0;
     nfapi_cqi_indication_pdu_t *pdu = &(value->cqi_pdu_list[i]);
@@ -3008,7 +3020,10 @@ static uint8_t pack_nr_rx_data_indication_body(void* tlv, uint8_t **ppWritePacke
 		 push16(value->timing_advance, ppWritePackedMsg, end) &&
 		 push16(value->rssi, ppWritePackedMsg, end)
 		 ))
-		  return 0;
+		return 0;
+
+        if(pusharray8(value->pdu, value->pdu_length, value->pdu_length, ppWritePackedMsg, end) == 0)
+		return 0;
 
 	return 1;
 }
@@ -3022,22 +3037,21 @@ static uint8_t pack_nr_rx_data_indication(void *msg, uint8_t **ppWritePackedMsg,
 		push16(pNfapiMsg->slot , ppWritePackedMsg, end) &&
 		push16(pNfapiMsg->number_of_pdus, ppWritePackedMsg, end)
 		))
-			return 0;
+		return 0;
 
-	for(int i=0; i<pNfapiMsg->number_of_pdus;i++)
+	for (int i = 0; i < pNfapiMsg->number_of_pdus; i++)
 	{
-		if(!pack_nr_rx_data_indication_body(pNfapiMsg->pdu_list,ppWritePackedMsg,end))
-		return 0;
+		if(!pack_nr_rx_data_indication_body(&(pNfapiMsg->pdu_list[i]), ppWritePackedMsg, end))
+		        return 0;
 	}
 
-return 1;
+        return 1;
 }
 
 //NR CRC INDICATION
 
-static uint8_t pack_nr_crc_indication_body(void* tlv, uint8_t **ppWritePackedMsg, uint8_t *end)
+static uint8_t pack_nr_crc_indication_body(nfapi_nr_crc_t* value, uint8_t **ppWritePackedMsg, uint8_t *end)
 {
-	nfapi_nr_crc_t* value = (nfapi_nr_crc_t*)tlv;
 
 	if(!(push32(value->handle, ppWritePackedMsg, end) &&
 	 	 push16(value->rnti, ppWritePackedMsg, end) &&
@@ -3064,9 +3078,9 @@ static uint8_t pack_nr_crc_indication(void *msg, uint8_t **ppWritePackedMsg, uin
 		))
 			return 0;
 
-	for(int i=0; i<pNfapiMsg->number_crcs;i++)
+	for (int i = 0; i < pNfapiMsg->number_crcs; i++)
 	{
-		if(!pack_nr_crc_indication_body(pNfapiMsg->crc_list,ppWritePackedMsg,end))
+		if(!pack_nr_crc_indication_body(&pNfapiMsg->crc_list[i], ppWritePackedMsg, end))
 		return 0;
 	}
 
@@ -3133,9 +3147,9 @@ static uint8_t pack_nr_rach_indication_body(void* tlv, uint8_t **ppWritePackedMs
 		  return 0;
 	for(int i = 0; i < value->num_preamble; i++)
 	{
-		if(!(push8(value->preamble_list->preamble_index, ppWritePackedMsg, end) &&
-			push16(value->preamble_list->timing_advance, ppWritePackedMsg, end) &&
-			push32(value->preamble_list->preamble_pwr, ppWritePackedMsg, end)
+		if(!(push8(value->preamble_list[i].preamble_index, ppWritePackedMsg, end) &&
+			push16(value->preamble_list[i].timing_advance, ppWritePackedMsg, end) &&
+			push32(value->preamble_list[i].preamble_pwr, ppWritePackedMsg, end)
 			))
 			return 0;
 	}
@@ -3177,23 +3191,22 @@ static uint8_t pack_nr_uci_pucch_0_1(void* tlv, uint8_t **ppWritePackedMsg, uint
 		 ))
 		  return 0;
 	if (value->pduBitmap & 0x01) { //SR
-		if(!(push8(value->sr->sr_indication, ppWritePackedMsg, end) &&
-	 	 push8(value->sr->sr_confidence_level, ppWritePackedMsg, end)
+		if (!(push8(value->sr->sr_indication, ppWritePackedMsg, end) &&
+		 push8(value->sr->sr_confidence_level, ppWritePackedMsg, end)
 		 ))
 		  return 0;
 	}
 
 	if (((value->pduBitmap >> 1) & 0x01)) { //HARQ
-		if(!(push8(value->harq->num_harq, ppWritePackedMsg, end) &&
-	 	 push8(value->harq->harq_confidence_level, ppWritePackedMsg, end)
+		if (!(push8(value->harq->num_harq, ppWritePackedMsg, end) &&
+		 push8(value->harq->harq_confidence_level, ppWritePackedMsg, end)
 		 ))
 			return 0;
-
-		for(int i=0; i<value->harq->num_harq;i++)
+		for (int i = 0; i < value->harq->num_harq; i++)
 		{
-			if(!(push8(value->harq->harq_list[i].harq_value, ppWritePackedMsg, end)
+			if (!(push8(value->harq->harq_list[i].harq_value, ppWritePackedMsg, end)
 			))
-			return 0;
+			        return 0;
 		}
 	}
 
@@ -3258,7 +3271,7 @@ static uint8_t pack_nr_uci_indication_body(void* tlv, uint8_t **ppWritePackedMsg
 
 	switch (value->pdu_type) {
       case NFAPI_NR_UCI_PUSCH_PDU_TYPE:
-        printf("Unhandled NFAPI_NR_UCI_PUSCH_PDU_TYPE \n");
+        NFAPI_TRACE(NFAPI_TRACE_WARN, "Unhandled NFAPI_NR_UCI_PUSCH_PDU_TYPE \n");
         break;
 
       case NFAPI_NR_UCI_FORMAT_0_1_PDU_TYPE:
@@ -3285,8 +3298,9 @@ static uint8_t pack_nr_uci_indication(void *msg, uint8_t **ppWritePackedMsg, uin
 
 	for(int i=0; i<pNfapiMsg->num_ucis;i++)
 	{
-		if(!pack_nr_uci_indication_body(pNfapiMsg->uci_list,ppWritePackedMsg,end))
-		return 0;
+		if (!pack_nr_uci_indication_body(&pNfapiMsg->uci_list[i], ppWritePackedMsg, end))
+		        return 0;
+
 	}
 
 return 1;
@@ -3307,13 +3321,6 @@ int nfapi_nr_p7_message_pack(void *pMessageBuf, void *pPackedBuf, uint32_t packe
 		NFAPI_TRACE(NFAPI_TRACE_ERROR, "P7 Pack supplied pointers are null\n");
 		return -1;
 	}
-	/*
-	printf("\n P7 MESSAGE SENT: \n");
-	for(int i=0; i< packedBufLen; i++){
-		printf("%d", *(uint8_t *)(pMessageBuf + i));
-	}
-	printf("\n");
-	*/
 	// process the header
 	if(!(push16(pMessageHeader->phy_id, &pWritePackedMessage, end) &&
 		 push16(pMessageHeader->message_id, &pWritePackedMessage, end) &&
@@ -3349,7 +3356,6 @@ int nfapi_nr_p7_message_pack(void *pMessageBuf, void *pPackedBuf, uint32_t packe
 		case NFAPI_NR_PHY_MSG_TYPE_UL_DCI_REQUEST:
 			result = pack_ul_dci_request(pMessageHeader, &pWritePackedMessage, end, config);
 			break;
-
 		case NFAPI_UE_RELEASE_REQUEST:
 			result =pack_ue_release_request(pMessageHeader, &pWritePackedMessage, end, config);
 			break;
@@ -3465,13 +3471,6 @@ int nfapi_p7_message_pack(void *pMessageBuf, void *pPackedBuf, uint32_t packedBu
     return -1;
   }
 
-  /*
-  printf("\n P7 MESSAGE SENT: \n");
-  for(int i=0; i< packedBufLen; i++){
-    printf("%d", *(uint8_t *)(pMessageBuf + i));
-  }
-  printf("\n");
-  */
   // process the header
   if(!(push16(pMessageHeader->phy_id, &pWritePackedMessage, end) &&
        push16(pMessageHeader->message_id, &pWritePackedMessage, end) &&
@@ -3651,7 +3650,6 @@ static uint8_t unpack_dl_tti_csi_rs_pdu_rel15_value(void *tlv, uint8_t **ppReadP
 static uint8_t unpack_dl_tti_pdcch_pdu_rel15_value(void* tlv, uint8_t **ppReadPackedMsg, uint8_t *end) {
 
 	nfapi_nr_dl_tti_pdcch_pdu_rel15_t* value = (nfapi_nr_dl_tti_pdcch_pdu_rel15_t*)tlv;
-
 	for(uint8_t i = 0; i < MAX_DCI_CORESET; ++i)
 	{
 		if(!(pull16(ppReadPackedMsg, &value->dci_pdu[i].RNTI, end) &&
@@ -3738,7 +3736,8 @@ static uint8_t unpack_dl_tti_ssb_pdu_rel15_value(void *tlv, uint8_t **ppReadPack
           pull8(ppReadPackedMsg, &value->SsbSubcarrierOffset, end) &&
           pull16(ppReadPackedMsg, &value->ssbOffsetPointA, end) &&
           pull8(ppReadPackedMsg, &value->bchPayloadFlag, end) &&
-          pull32(ppReadPackedMsg, &value->bchPayload, end)
+          pull32(ppReadPackedMsg, &value->bchPayload, end) &&
+	  pull8(ppReadPackedMsg, &value->ssbRsrp, end)
           // TODO: pack precoding_and_beamforming too
         );
 }
@@ -4404,6 +4403,7 @@ static uint8_t unpack_ul_tti_request_pucch_pdu(void *tlv, uint8_t **ppReadPacked
           pull8(ppReadPackedMsg, &pucch_pdu->cyclic_prefix, end) &&
           pull8(ppReadPackedMsg, &pucch_pdu->format_type, end) &&
           pull8(ppReadPackedMsg, &pucch_pdu->multi_slot_tx_indicator, end) &&
+          pull8(ppReadPackedMsg, &pucch_pdu->pi_2bpsk, end) &&
           pull16(ppReadPackedMsg, &pucch_pdu->prb_start, end) &&
           pull16(ppReadPackedMsg, &pucch_pdu->prb_size, end) &&
           pull8(ppReadPackedMsg, &pucch_pdu->start_symbol_index, end) &&
@@ -5364,7 +5364,7 @@ static uint8_t unpack_hi_dci0_request_body_value(void *tlv, uint8_t **ppReadPack
 
     if(packedPduEnd > end) {
       // pdu end if past buffer end
-      NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s pdu size to big %d %d\n", __FUNCTION__, packedPduEnd, end);
+      NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s pdu size to big %p %p\n", __FUNCTION__, packedPduEnd, end);
       return 0;
     }
 
@@ -5464,7 +5464,6 @@ static uint8_t unpack_ul_dci_pdu_list_value(uint8_t **ppReadPackedMsg, uint8_t *
 			pull16(ppReadPackedMsg, &value->pdcch_pdu.pdcch_pdu_rel15.ShiftIndex, end) &&
 			pull8(ppReadPackedMsg, &value->pdcch_pdu.pdcch_pdu_rel15.precoderGranularity, end) &&
 			pull16(ppReadPackedMsg, &value->pdcch_pdu.pdcch_pdu_rel15.numDlDci, end));
-
 }
 
 static uint8_t unpack_ul_dci_request(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p7_codec_config_t *config) {
@@ -5654,12 +5653,13 @@ static uint8_t unpack_nr_slot_indication(uint8_t **ppReadPackedMsg, uint8_t *end
 return 1;
 }
 
-//RX DATA INDICATION
+//RX DATA INDICATION 
 
-static uint8_t unpack_nr_rx_data_indication_body(void* tlv, uint8_t **ppReadPackedMsg, uint8_t *end)
+static uint8_t unpack_nr_rx_data_indication_body(nfapi_nr_rx_data_pdu_t* value,
+                                                 uint8_t **ppReadPackedMsg,
+                                                 uint8_t *end,
+                                                 nfapi_p7_codec_config_t* config)
 {
-	nfapi_nr_rx_data_pdu_t* value = (nfapi_nr_rx_data_pdu_t*)tlv;
-
 	if(!(pull32(ppReadPackedMsg, &value->handle, end) &&
 	 	 pull16(ppReadPackedMsg, &value->rnti, end) &&
 		 pull8(ppReadPackedMsg, &value->harq_id, end) &&
@@ -5668,7 +5668,16 @@ static uint8_t unpack_nr_rx_data_indication_body(void* tlv, uint8_t **ppReadPack
 		 pull16(ppReadPackedMsg, &value->timing_advance, end) &&
 		 pull16(ppReadPackedMsg, &value->rssi, end)
 		 ))
-		  return 0;
+		return 0;
+
+        uint16_t length = value->pdu_length;
+        value->pdu = nfapi_p7_allocate(length, config);
+
+        if (pullarray8(ppReadPackedMsg, value->pdu, length, length, end) == 0)
+        {
+                NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s pullarray8 failure\n", __FUNCTION__);
+                return 0;
+        }
 	return 1;
 }
 
@@ -5682,10 +5691,14 @@ static uint8_t unpack_nr_rx_data_indication(uint8_t **ppReadPackedMsg, uint8_t *
 		pull16(ppReadPackedMsg, &pNfapiMsg->number_of_pdus, end)
 		))
 			return 0;
+        if (pNfapiMsg->number_of_pdus > 0)
+        {
+                pNfapiMsg->pdu_list = nfapi_p7_allocate(sizeof(*pNfapiMsg->pdu_list) * pNfapiMsg->number_of_pdus, config);
+        }
 
-	for(int i=0; i<pNfapiMsg->number_of_pdus;i++)
+	for (int i = 0; i < pNfapiMsg->number_of_pdus; i++)
 	{
-		if(!unpack_nr_rx_data_indication_body(pNfapiMsg->pdu_list, ppReadPackedMsg, end))
+		if(!unpack_nr_rx_data_indication_body(&pNfapiMsg->pdu_list[i], ppReadPackedMsg, end, config))
 		return 0;
 	}
 
@@ -5715,21 +5728,23 @@ static uint8_t unpack_nr_crc_indication_body(nfapi_nr_crc_t* value, uint8_t **pp
 
 static uint8_t unpack_nr_crc_indication(uint8_t **ppReadPackedMsg, uint8_t *end, nfapi_nr_crc_indication_t *msg, nfapi_p7_codec_config_t* config)
 {
-	nfapi_nr_crc_indication_t *pNfapiMsg = (nfapi_nr_crc_indication_t *) msg;
-	// pNfapiMsg = (nfapi_nr_crc_indication_t *) malloc(sizeof(nfapi_nr_crc_indication_t));
-	// pNfapiMsg->crc_list = (nfapi_nr_crc_t *) malloc(sizeof(nfapi_nr_crc_t));
+	nfapi_nr_crc_indication_t *pNfapiMsg = (nfapi_nr_crc_indication_t*)msg;
 
-	if (!(pull16(ppReadPackedMsg, &pNfapiMsg->sfn, end) &&
-		pull16(ppReadPackedMsg, &pNfapiMsg->slot, end) &&
+	if (!(pull16(ppReadPackedMsg, &pNfapiMsg->sfn , end) &&
+		pull16(ppReadPackedMsg, &pNfapiMsg->slot , end) &&
 		pull16(ppReadPackedMsg, &pNfapiMsg->number_crcs, end)
 		))
-		return 0;
+			return 0;
+
+        if (pNfapiMsg->number_crcs > 0)
+        {
+                pNfapiMsg->crc_list = nfapi_p7_allocate(sizeof(*pNfapiMsg->crc_list) * pNfapiMsg->number_crcs, config);
+        }
 
-	for(int i=0; i<pNfapiMsg->number_crcs;i++)
+	for (int i = 0; i < pNfapiMsg->number_crcs; i++)
 	{
-		if(!unpack_nr_crc_indication_body(pNfapiMsg->crc_list,ppReadPackedMsg,end))
-		//if(!unpack_nr_crc_indication_body(value,ppReadPackedMsg,end))
-		return 0;
+		if(!unpack_nr_crc_indication_body(&pNfapiMsg->crc_list[i], ppReadPackedMsg, end))
+		        return 0;
 	}
 
 return 1;
@@ -5780,9 +5795,11 @@ return 1;
 
 //NR RACH
 
-static uint8_t unpack_nr_rach_indication_body(nfapi_nr_prach_indication_pdu_t* tlv, uint8_t **ppReadPackedMsg, uint8_t *end)
+static uint8_t unpack_nr_rach_indication_body(nfapi_nr_prach_indication_pdu_t* value,
+                                              uint8_t **ppReadPackedMsg,
+                                              uint8_t *end,
+                                              nfapi_p7_codec_config_t* config)
 {
-	nfapi_nr_prach_indication_pdu_t* value = (nfapi_nr_prach_indication_pdu_t*)tlv;
 
 	if(!(pull16(ppReadPackedMsg, &value->phy_cell_id, end) &&
 	 	 pull8(ppReadPackedMsg, &value->symbol_index, end) &&
@@ -5793,15 +5810,18 @@ static uint8_t unpack_nr_rach_indication_body(nfapi_nr_prach_indication_pdu_t* t
 		 pull8(ppReadPackedMsg, &value->num_preamble, end)
 		 ))
 		  return 0;
-	value->preamble_list = (nfapi_nr_prach_indication_preamble_t*) malloc(sizeof(nfapi_nr_prach_indication_preamble_t) * value->num_preamble);
-	for(int i = 0; i < value->num_preamble; i++)
-	{
-		if(!(pull8(ppReadPackedMsg, &value->preamble_list->preamble_index, end) &&
-			pull16(ppReadPackedMsg, &value->preamble_list->timing_advance, end) &&
-			pull32(ppReadPackedMsg, &value->preamble_list->preamble_pwr, end)
-			))
-			return 0;
-	}
+
+        if (value->num_preamble > 0) {
+	        value->preamble_list = nfapi_p7_allocate(sizeof(*value->preamble_list) * value->num_preamble, config);
+                for(int i = 0; i < value->num_preamble; i++)
+                {
+                        if(!(pull8(ppReadPackedMsg, &value->preamble_list[i].preamble_index, end) &&
+                                pull16(ppReadPackedMsg, &value->preamble_list[i].timing_advance, end) &&
+                                pull32(ppReadPackedMsg, &value->preamble_list[i].preamble_pwr, end)
+                                ))
+                                return 0;
+                }
+        }
 	return 1;
 }
 
@@ -5812,31 +5832,27 @@ static uint8_t unpack_nr_rach_indication(uint8_t **ppReadPackedMsg, uint8_t *end
 		pull16(ppReadPackedMsg, &pNfapiMsg->slot , end) &&
 		pull8(ppReadPackedMsg, &pNfapiMsg->number_of_pdus, end)
 		))
-			return 0;
-	pNfapiMsg->pdu_list = (nfapi_nr_prach_indication_pdu_t*) malloc(sizeof(nfapi_nr_prach_indication_pdu_t) * pNfapiMsg->number_of_pdus);
-	for(int i=0; i< pNfapiMsg->number_of_pdus;i++)
-	{
-		if(!unpack_nr_rach_indication_body(pNfapiMsg->pdu_list,ppReadPackedMsg,end))
 		return 0;
-	}
 
-return 1;
+        if (pNfapiMsg->number_of_pdus > 0) {
+	        pNfapiMsg->pdu_list = nfapi_p7_allocate(sizeof(*pNfapiMsg->pdu_list) * pNfapiMsg->number_of_pdus, config);
+                for(int i = 0; i < pNfapiMsg->number_of_pdus; i++)
+                {
+                        if(!unpack_nr_rach_indication_body(&pNfapiMsg->pdu_list[i], ppReadPackedMsg, end, config))
+                                return 0;
+                }
+        }
+        return 1;
 }
 
-//NR UCI
-
-static uint8_t unpack_nr_uci_pucch_0_1(nfapi_nr_uci_pucch_pdu_format_0_1_t* tlv, uint8_t **ppReadPackedMsg, uint8_t *end) {
-	nfapi_nr_uci_pucch_pdu_format_0_1_t* value = (nfapi_nr_uci_pucch_pdu_format_0_1_t*)tlv;
+//NR UCI 
 
-	// uint8_t *ptr = *ppReadPackedMsg;
-	// printf("\n Read P7 message uci_0_1 indication unpack: ");
-	// while(ptr < end){
-	// 	printf(" %d ", *ptr);
-	// 	ptr++;
-	// }
-	// printf("\n");
+static uint8_t unpack_nr_uci_pucch_0_1(nfapi_nr_uci_pucch_pdu_format_0_1_t *value,
+                                       uint8_t **ppReadPackedMsg,
+                                       uint8_t *end,
+                                       nfapi_p7_codec_config_t *config) {
 
-	if(!(pull8(ppReadPackedMsg, &value->pduBitmap, end) &&
+	if (!(pull8(ppReadPackedMsg, &value->pduBitmap, end) &&
 	 	 pull32(ppReadPackedMsg, &value->handle, end) &&
 		 pull16(ppReadPackedMsg, &value->rnti, end) &&
 		 pull8(ppReadPackedMsg, &value->pucch_format, end) &&
@@ -5846,26 +5862,45 @@ static uint8_t unpack_nr_uci_pucch_0_1(nfapi_nr_uci_pucch_pdu_format_0_1_t* tlv,
 		 ))
 		  return 0;
 	if (value->pduBitmap & 0x01) { //SR
-		value->sr = (nfapi_nr_sr_pdu_0_1_t*) malloc(sizeof(nfapi_nr_sr_pdu_0_1_t));
+		value->sr = nfapi_p7_allocate(sizeof(*value->sr), config);
+		if (value->sr == NULL)
+		{
+			NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s failed to allocate sr pdu\n", __FUNCTION__);
+			return 0;
+		}
 		if(!(pull8(ppReadPackedMsg, &value->sr->sr_indication, end) &&
-	 	 pull8(ppReadPackedMsg, &value->sr->sr_confidence_level, end)
+	 	 pull8(ppReadPackedMsg, &value->sr->sr_confidence_level, end) 
 		 ))
 		  return 0;
 	}
 
 	if (((value->pduBitmap >> 1) & 0x01)) { //HARQ
-		value->harq = (nfapi_nr_harq_pdu_0_1_t*) malloc(sizeof(nfapi_nr_harq_pdu_0_1_t));
-		if(!(pull8(ppReadPackedMsg, &value->harq->num_harq, end) &&
-	 	 pull8(ppReadPackedMsg, &value->harq->harq_confidence_level, end)
-		 ))
-			return 0;
-		value->harq->harq_list = (nfapi_nr_harq_t*) malloc(sizeof(nfapi_nr_harq_t*) * value->harq->num_harq);
-		for(int i=0; i<value->harq->num_harq;i++)
-		{
-			if(!(pull8(ppReadPackedMsg, &value->harq->harq_list->harq_value, end)
-			))
-			return 0;
-		}
+
+                value->harq = nfapi_p7_allocate(sizeof(*value->harq), config);
+                if (value->harq == NULL)
+                {
+                        NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s failed to allocate nr_harq pdu\n", __FUNCTION__);
+                        return 0;
+                }
+                if (!(pull8(ppReadPackedMsg, &value->harq->num_harq, end) &&
+                        pull8(ppReadPackedMsg, &value->harq->harq_confidence_level, end)
+                        ))
+                        return 0;
+                value->harq->harq_list = NULL;
+                if (value->harq->num_harq > 0) {
+                        value->harq->harq_list = nfapi_p7_allocate(sizeof(*value->harq->harq_list) * value->harq->num_harq, config);
+                        if (value->harq->harq_list == NULL)
+                        {
+                                NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s failed to allocate harq ind pdu list (count:%d)\n",
+                                                __FUNCTION__, value->harq->num_harq);
+                                return 0;
+                        }
+                        for (int i = 0; i < value->harq->num_harq; i++) {
+                                if (!pull8(ppReadPackedMsg, &value->harq->harq_list[i].harq_value, end)) {
+                                        return 0;
+                                }
+                        }
+                }
 	}
 
 	return 1;
@@ -5930,7 +5965,10 @@ static uint8_t unpack_nr_uci_pucch_2_3_4(nfapi_nr_uci_pucch_pdu_format_2_3_4_t*
 	return 1;
 }
 
-static uint8_t unpack_nr_uci_indication_body(nfapi_nr_uci_t* value, uint8_t **ppReadPackedMsg, uint8_t *end)
+static uint8_t unpack_nr_uci_indication_body(nfapi_nr_uci_t *value,
+                                             uint8_t **ppReadPackedMsg,
+                                             uint8_t *end,
+                                             nfapi_p7_codec_config_t *config)
 {
 	if(!(pull16(ppReadPackedMsg, &value->pdu_type, end) &&
 		pull16(ppReadPackedMsg, &value->pdu_size, end)
@@ -5938,21 +5976,26 @@ static uint8_t unpack_nr_uci_indication_body(nfapi_nr_uci_t* value, uint8_t **pp
 		return 0;
 
 	switch (value->pdu_type) {
-      case NFAPI_NR_UCI_PUSCH_PDU_TYPE:
-        printf("Unhandled NFAPI_NR_UCI_PUSCH_PDU_TYPE \n");
-        break;
-
-      case NFAPI_NR_UCI_FORMAT_0_1_PDU_TYPE: {
-        nfapi_nr_uci_pucch_pdu_format_0_1_t* uci_pdu = &value->pucch_pdu_format_0_1;
-        unpack_nr_uci_pucch_0_1(uci_pdu, ppReadPackedMsg, end);
-		break;
+                case NFAPI_NR_UCI_PUSCH_PDU_TYPE:
+                        NFAPI_TRACE(NFAPI_TRACE_WARN, "Unhandled NFAPI_NR_UCI_PUSCH_PDU_TYPE \n");
+                        break;
+
+                case NFAPI_NR_UCI_FORMAT_0_1_PDU_TYPE: {
+                        nfapi_nr_uci_pucch_pdu_format_0_1_t *uci_pdu = &value->pucch_pdu_format_0_1;
+                        if (!unpack_nr_uci_pucch_0_1(uci_pdu, ppReadPackedMsg, end, config))
+                                return 0;
+                        break;
+                }
+                case NFAPI_NR_UCI_FORMAT_2_3_4_PDU_TYPE: {
+                        nfapi_nr_uci_pucch_pdu_format_2_3_4_t *uci_pdu = &value->pucch_pdu_format_2_3_4;
+                        if (!unpack_nr_uci_pucch_2_3_4(uci_pdu, ppReadPackedMsg, end))
+                                return 0;
+                        break;
+                }
+                default:
+                        NFAPI_TRACE(NFAPI_TRACE_WARN, "Unexpected pdu type %d\n", value->pdu_type);
+                        break;
         }
-      case NFAPI_NR_UCI_FORMAT_2_3_4_PDU_TYPE: {
-        nfapi_nr_uci_pucch_pdu_format_2_3_4_t *uci_pdu = &value->pucch_pdu_format_2_3_4;
-        unpack_nr_uci_pucch_2_3_4(uci_pdu, ppReadPackedMsg, end);
-        break;
-    	}
-	}
 
 	return 1;
 }
@@ -5967,13 +6010,14 @@ static uint8_t unpack_nr_uci_indication(uint8_t **ppReadPackedMsg, uint8_t *end,
 		))
 			return 0;
 
-	for(int i=0; i<pNfapiMsg->num_ucis;i++)
+	pNfapiMsg->uci_list = nfapi_p7_allocate(sizeof(*pNfapiMsg->uci_list) * pNfapiMsg->num_ucis, config);
+	for (int i = 0; i < pNfapiMsg->num_ucis; i++)
 	{
-		if(!unpack_nr_uci_indication_body(pNfapiMsg->uci_list,ppReadPackedMsg,end))
-		return 0;
+		if(!unpack_nr_uci_indication_body(&pNfapiMsg->uci_list[i], ppReadPackedMsg, end, config))
+		        return 0;
 	}
 
-return 1;
+        return 1;
 }
 
 static uint8_t unpack_ue_release_request(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p7_codec_config_t *config) {
@@ -6233,6 +6277,7 @@ static uint8_t unpack_harq_indication_body_value(void *tlv, uint8_t **ppReadPack
     return 0;
   }
 
+  assert(value->number_of_harqs <= NFAPI_HARQ_IND_MAX_PDU);
   value->harq_pdu_list = (nfapi_harq_indication_pdu_t *)nfapi_p7_allocate(sizeof(nfapi_harq_indication_pdu_t) * value->number_of_harqs, config);
 
   if(value->harq_pdu_list == NULL) {
@@ -6297,7 +6342,8 @@ static uint8_t unpack_crc_indication_body_value(void *tlv, uint8_t **ppReadPacke
   }
 
   if(value->number_of_crcs > 0) {
-    value->crc_pdu_list = (nfapi_crc_indication_pdu_t *)nfapi_p7_allocate(sizeof(nfapi_crc_indication_pdu_t) * value->number_of_crcs, config);
+    assert(value->number_of_crcs <= NFAPI_CRC_IND_MAX_PDU);
+    value->crc_pdu_list = (nfapi_crc_indication_pdu_t *)nfapi_p7_allocate(sizeof(nfapi_crc_indication_pdu_t) * NFAPI_CRC_IND_MAX_PDU, config);
 
     if(value->crc_pdu_list == NULL) {
       NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s failed to allocate crc ind pdu list (count:%d)\n", __FUNCTION__, value->number_of_crcs);
@@ -6349,114 +6395,141 @@ static uint8_t unpack_rx_indication_rel9_value(void *tlv, uint8_t **ppReadPacked
   return (pull16(ppReadPackedMsg, &value->timing_advance_r9, end));
 }
 
-static uint8_t unpack_rx_indication_body_value(void *tlv, uint8_t **ppReadPackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config) {
-  nfapi_rx_indication_body_t *value = (nfapi_rx_indication_body_t *)tlv;
-  // the rxBodyEnd points to the end of the cqi PDU's
-  uint8_t *rxBodyEnd = *ppReadPackedMsg + value->tl.length;
-  uint8_t *rxPduEnd = rxBodyEnd;
-  uint8_t *numberOfPdusAddress = *ppReadPackedMsg;
+static uint8_t unpack_rx_indication_body_value(void *tlv, uint8_t **ppReadPackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config)
+{
+	nfapi_rx_indication_body_t *value = (nfapi_rx_indication_body_t*)tlv;
 
-  if(rxBodyEnd > end) {
-    // pdu end is past buffer end
-    return 0;
-  }
+	NFAPI_TRACE(NFAPI_TRACE_DEBUG, "%s value->tl.length in unpack: %u \n", __FUNCTION__,
+				value->tl.length);
+	uint8_t *rxBodyEnd = *ppReadPackedMsg + value->tl.length;
 
-  if(pull16(ppReadPackedMsg, &value->number_of_pdus, end) == 0)
-    return 0;
+	NFAPI_TRACE(NFAPI_TRACE_DEBUG, "%s rxBodyEnd: %p end: %p\n", __FUNCTION__,
+				rxBodyEnd, end);
+	if (rxBodyEnd > end)
+	{
+		// pdu end is past buffer end
+		return 0;
+	}
 
-  if(value->number_of_pdus > NFAPI_RX_IND_MAX_PDU) {
-    NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s number of rx ind pdu's exceed maxium (count:%d max:%d)\n", __FUNCTION__, value->number_of_pdus, NFAPI_RX_IND_MAX_PDU);
-    return 0;
-  }
+	if (pull16(ppReadPackedMsg, &value->number_of_pdus, end) == 0)
+		return 0;
 
-  if(value->number_of_pdus > 0) {
-    value->rx_pdu_list = (nfapi_rx_indication_pdu_t *)nfapi_p7_allocate(sizeof(nfapi_rx_indication_pdu_t) * value->number_of_pdus, config);
+	if (value->number_of_pdus > NFAPI_RX_IND_MAX_PDU)
+	{
+		NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s number of rx ind pdu's exceed maxium (count:%d max:%d)\n", __FUNCTION__, value->number_of_pdus, NFAPI_RX_IND_MAX_PDU);
+		return 0;
+	}
 
-    if(value->rx_pdu_list == NULL) {
-      NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s failed to allocate rx ind pdu list (count:%d)\n", __FUNCTION__, value->number_of_pdus);
-      return 0;
-    }
-  } else {
-    value->rx_pdu_list = 0;
-  }
+	if (value->number_of_pdus > 0)
+	{
+		assert(value->number_of_pdus <= NFAPI_RX_IND_MAX_PDU);
+		value->rx_pdu_list = (nfapi_rx_indication_pdu_t *)nfapi_p7_allocate(sizeof(nfapi_rx_indication_pdu_t) * NFAPI_RX_IND_MAX_PDU, config);
+		if (value->rx_pdu_list == NULL)
+		{
+			NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s failed to allocate rx ind pdu list (count:%d)\n", __FUNCTION__, value->number_of_pdus);
+			return 0;
+		}
+	}
+	else
+	{
+		value->rx_pdu_list = 0;
+	}
 
-  uint8_t i = 0;
-  nfapi_rx_indication_pdu_t *pdu = 0;
+	NFAPI_TRACE(NFAPI_TRACE_INFO, "%s number_of_pdus = %u\n", __FUNCTION__, value->number_of_pdus);
+	for (int i = 0; i < value->number_of_pdus; i++)
+	{
+		NFAPI_TRACE(NFAPI_TRACE_INFO, "%s i = %u\n", __FUNCTION__, i);
+		nfapi_tl_t generic_tl;
 
-  while((uint8_t *)(*ppReadPackedMsg) < rxBodyEnd && (uint8_t *)(*ppReadPackedMsg) < rxPduEnd) {
-    nfapi_tl_t generic_tl;
+		// NFAPI_RX_UE_INFORMATION_TAG
+		if (unpack_tl(ppReadPackedMsg, &generic_tl, end) == 0)
+		{
+			NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s unpack_tl failed\n", __FUNCTION__);
+			return 0;
+		}
 
-    if( unpack_tl(ppReadPackedMsg, &generic_tl, end) == 0)
-      return 0;
+		NFAPI_TRACE(NFAPI_TRACE_INFO, "%s generic_tl.tag = 0x%x length = %u\n", __FUNCTION__, generic_tl.tag, generic_tl.length);
 
-    switch(generic_tl.tag) {
-      case NFAPI_RX_UE_INFORMATION_TAG: {
-        pdu = &(value->rx_pdu_list[i++]);
-        pdu->rx_ue_information.tl = generic_tl;
+		if (generic_tl.tag != NFAPI_RX_UE_INFORMATION_TAG)
+		{
+			NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s generic_tl.tag wrong\n", __FUNCTION__);
+			return 0;
+		}
 
-        if(unpack_rx_ue_information_value(&pdu->rx_ue_information, ppReadPackedMsg, end) == 0)
-          return 0;
-      }
-      break;
+		assert(i < NFAPI_RX_IND_MAX_PDU);
+		nfapi_rx_indication_pdu_t *pdu = &value->rx_pdu_list[i];
 
-      case NFAPI_RX_INDICATION_REL8_TAG: {
-        if(pdu != 0) {
-          pdu->rx_indication_rel8.tl = generic_tl;
+		pdu->rx_ue_information.tl = generic_tl;
+		if (unpack_rx_ue_information_value(&pdu->rx_ue_information, ppReadPackedMsg, end) == 0)
+		{
+			NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s unpack_rx_ue_info failure\n", __FUNCTION__);
+			return 0;
+		}
 
-          if(unpack_rx_indication_rel8_value(&pdu->rx_indication_rel8, ppReadPackedMsg, end) == 0)
-            return 0;
+		// NFAPI_RX_INDICATION_REL8_TAG
+		if (unpack_tl(ppReadPackedMsg, &generic_tl, end) == 0)
+		{
+			NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s unpack_tl failed\n", __FUNCTION__);
+			return 0;
+		}
 
-          if(pdu->rx_indication_rel8.offset > 0) {
-            // Need to check that the data is within the tlv
-            if(numberOfPdusAddress + pdu->rx_indication_rel8.offset + pdu->rx_indication_rel8.length <= rxBodyEnd) {
-              // If this the first pdu set the rxPduEnd
-              if(numberOfPdusAddress + pdu->rx_indication_rel8.offset < rxPduEnd) {
-                rxPduEnd = numberOfPdusAddress + pdu->rx_indication_rel8.offset;
+		NFAPI_TRACE(NFAPI_TRACE_INFO, "%s generic_tl.tag = 0x%x length = %u\n", __FUNCTION__, generic_tl.tag, generic_tl.length);
 
-                if(rxPduEnd > end) {
-                  // pdu end is past buffer end
-                  return 0;
-                }
-              }
-            } else {
-              NFAPI_TRACE(NFAPI_TRACE_ERROR, "FIXME: the rx data is outside of the tlv\n");
-            }
-          }
-        }
-      }
-      break;
+		if (generic_tl.tag != NFAPI_RX_INDICATION_REL8_TAG)
+		{
+			NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s generic_tl.tag wrong\n", __FUNCTION__);
+			return 0;
+		}
 
-      case NFAPI_RX_INDICATION_REL9_TAG: {
-        if(pdu != 0) {
-          pdu->rx_indication_rel9.tl = generic_tl;
+		pdu->rx_indication_rel8.tl = generic_tl;
+		if (unpack_rx_indication_rel8_value(&pdu->rx_indication_rel8, ppReadPackedMsg, end) == 0)
+		{
+			NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s unpack_rx_indication_rel8 failure\n", __FUNCTION__);
+			return 0;
+		}
+		//What is offset not stripping 10 bytes
+		NFAPI_TRACE(NFAPI_TRACE_INFO, "%s pdu->rx_indication_rel8.offset = %u", __FUNCTION__,
+					pdu->rx_indication_rel8.offset);
 
-          if(unpack_rx_indication_rel9_value(&pdu->rx_indication_rel9, ppReadPackedMsg, end) == 0)
-            return 0;
-        }
-      }
-      break;
+		// NFAPI_RX_INDICATION_REL9_TAG
+		if (unpack_tl(ppReadPackedMsg, &generic_tl, end) == 0)
+		{
+			NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s unpack_tl failed\n", __FUNCTION__);
+			return 0;
+		}
 
-      default: {
-        NFAPI_TRACE(NFAPI_TRACE_ERROR, "RX_ULSCH.indication Invalid pdu type %d \n", generic_tl.tag );
-      }
-      break;
-    }
-  }
+		NFAPI_TRACE(NFAPI_TRACE_INFO, "%s generic_tl.tag = 0x%x length = %u\n", __FUNCTION__, generic_tl.tag, generic_tl.length);
 
-  uint8_t idx = 0;
+		if (generic_tl.tag != NFAPI_RX_INDICATION_REL9_TAG)
+		{
+			NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s generic_tl.tag wrong\n", __FUNCTION__);
+			return 0;
+		}
 
-  for(idx = 0; idx < value->number_of_pdus; ++idx) {
-    if(value->rx_pdu_list[idx].rx_indication_rel8.tl.tag == NFAPI_RX_INDICATION_REL8_TAG) {
-      uint32_t length = value->rx_pdu_list[idx].rx_indication_rel8.length;
-      value->rx_pdu_list[idx].data = nfapi_p7_allocate(length, config);
+		pdu->rx_indication_rel9.tl = generic_tl;
+		if (unpack_rx_indication_rel9_value(&pdu->rx_indication_rel9, ppReadPackedMsg, end) == 0)
+		{
+			NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s unpack_rx_indication_rel9 failure\n", __FUNCTION__);
+			return 0;
+		}
+	}
 
-      if(pullarray8(ppReadPackedMsg, value->rx_pdu_list[idx].data, length, length, end) == 0) {
-        return 0;
-      }
-    }
-  }
+        assert(value->number_of_pdus <= NFAPI_RX_IND_MAX_PDU);
+	for (int i = 0; i < value->number_of_pdus; ++i)
+	{
+		nfapi_rx_indication_pdu_t *pdu = &value->rx_pdu_list[i];
+		if (pdu->rx_indication_rel8.tl.tag == NFAPI_RX_INDICATION_REL8_TAG)
+		{
+			uint32_t length = pdu->rx_indication_rel8.length;
+			if (pullarray8(ppReadPackedMsg, pdu->rx_ind_data, NFAPI_RX_IND_DATA_MAX, length, end) == 0)
+			{
+				NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s pullarray8 failure\n", __FUNCTION__);
+				return 0;
+			}
+		}
+	}
 
-  return 1;
+	return 1;
 }
 
 static uint8_t unpack_rx_indication(uint8_t **ppReadPackedMsg, uint8_t *end, void *msg, nfapi_p7_codec_config_t *config) {
@@ -7414,12 +7487,10 @@ static int check_nr_unpack_length(nfapi_message_id_e msgId, uint32_t unpackedBuf
 			if (unpackedBufLen >= sizeof(nfapi_nr_tx_data_request_t))
 				retLen = sizeof(nfapi_nr_tx_data_request_t);
 			break;
-
 		case NFAPI_NR_PHY_MSG_TYPE_RX_DATA_INDICATION:
 			if (unpackedBufLen >= sizeof(nfapi_nr_rx_data_indication_t))
 				retLen = sizeof(nfapi_nr_rx_data_indication_t);
 			break;
-
 		case NFAPI_NR_PHY_MSG_TYPE_CRC_INDICATION:
 			if (unpackedBufLen >= sizeof(nfapi_nr_crc_indication_t))
 				retLen = sizeof(nfapi_nr_crc_indication_t);
@@ -7429,17 +7500,14 @@ static int check_nr_unpack_length(nfapi_message_id_e msgId, uint32_t unpackedBuf
 			if (unpackedBufLen >= sizeof(nfapi_nr_rach_indication_t))
 				retLen = sizeof(nfapi_nr_rach_indication_t);
 			break;
-
 		case NFAPI_NR_PHY_MSG_TYPE_UCI_INDICATION:
 			if (unpackedBufLen >= sizeof(nfapi_nr_uci_indication_t))
 				retLen = sizeof(nfapi_nr_uci_indication_t);
 			break;
-
 		case NFAPI_NR_PHY_MSG_TYPE_SRS_INDICATION:
 			if (unpackedBufLen >= sizeof(nfapi_nr_srs_indication_t))
 				retLen = sizeof(nfapi_nr_srs_indication_t);
 			break;
-
 		case NFAPI_NR_PHY_MSG_TYPE_DL_NODE_SYNC:
 			if (unpackedBufLen >= sizeof(nfapi_nr_dl_node_sync_t))
 				retLen = sizeof(nfapi_nr_dl_node_sync_t);
@@ -7758,14 +7826,6 @@ int nfapi_nr_p7_message_unpack(void *pMessageBuf, uint32_t messageBufLen, void *
 		return -1;
 	}
 
-    // uint8_t *ptr = pMessageBuf;
-	// printf("\n Read P7 message unpack: ");
-	// while(ptr < end){
-	// 	printf(" %d ", *ptr);
-	// 	ptr++;
-	// }
-	// printf("\n");
-
 	// clean the supplied buffer for - tag value blanking
 	(void)memset(pUnpackedBuf, 0, unpackedBufLen);
 
@@ -7823,7 +7883,6 @@ int nfapi_nr_p7_message_unpack(void *pMessageBuf, uint32_t messageBufLen, void *
 			else
 				return -1;
 			break;
-
 		case NFAPI_UE_RELEASE_REQUEST:
 			if (check_nr_unpack_length(NFAPI_UE_RELEASE_REQUEST, unpackedBufLen))
 				result = unpack_ue_release_request(&pReadPackedMessage,  end, pMessageHeader, config);
diff --git a/nfapi/open-nFAPI/pnf/inc/pnf_p7.h b/nfapi/open-nFAPI/pnf/inc/pnf_p7.h
index 763b5c9abe11fc153aa453b54bd27e689cfe85c5..cab245569165bd51a93c40ae6ca53b96ae4ba760 100644
--- a/nfapi/open-nFAPI/pnf/inc/pnf_p7.h
+++ b/nfapi/open-nFAPI/pnf/inc/pnf_p7.h
@@ -148,6 +148,7 @@ typedef struct {
 int pnf_p7_message_pump(pnf_p7_t* pnf_p7);
 int pnf_nr_p7_message_pump(pnf_p7_t* pnf_p7);
 int pnf_p7_pack_and_send_p7_message(pnf_p7_t* pnf_p7, nfapi_p7_message_header_t* msg, uint32_t msg_len);
+int pnf_nr_p7_pack_and_send_p7_message(pnf_p7_t* pnf_p7, nfapi_p7_message_header_t* header, uint32_t msg_len);
 int pnf_p7_send_message(pnf_p7_t* pnf_p7, uint8_t* msg, uint32_t msg_len);
 
 
diff --git a/nfapi/open-nFAPI/pnf/public_inc/nfapi_pnf_interface.h b/nfapi/open-nFAPI/pnf/public_inc/nfapi_pnf_interface.h
index fc9cd660774bbf497e77eb76ecfa1691c8a2f965..ca8bc8d9a46525247fadd7d402af22d157849efb 100644
--- a/nfapi/open-nFAPI/pnf/public_inc/nfapi_pnf_interface.h
+++ b/nfapi/open-nFAPI/pnf/public_inc/nfapi_pnf_interface.h
@@ -800,6 +800,7 @@ int nfapi_pnf_p7_harq_ind(nfapi_pnf_p7_config_t* config, nfapi_harq_indication_t
  * \return 0 means success, -1 means failure
  */
 int nfapi_pnf_p7_crc_ind(nfapi_pnf_p7_config_t* config, nfapi_crc_indication_t* ind);
+int nfapi_pnf_p7_nr_crc_ind(nfapi_pnf_p7_config_t* config, nfapi_nr_crc_indication_t* ind);
 
 /*! Send the RX.indication
  * \param config A pointer to a PNF P7 config
@@ -807,6 +808,7 @@ int nfapi_pnf_p7_crc_ind(nfapi_pnf_p7_config_t* config, nfapi_crc_indication_t*
  * \return 0 means success, -1 means failure
  */
 int nfapi_pnf_p7_rx_ind(nfapi_pnf_p7_config_t* config, nfapi_rx_indication_t* ind);
+int nfapi_pnf_p7_nr_rx_data_ind(nfapi_pnf_p7_config_t* config, nfapi_nr_rx_data_indication_t* ind);
 
 /*! Send the RACH.indication
  * \param config A pointer to a PNF P7 config
@@ -821,6 +823,7 @@ int nfapi_pnf_p7_rach_ind(nfapi_pnf_p7_config_t* config, nfapi_rach_indication_t
  * \return 0 means success, -1 means failure
  */
 int nfapi_pnf_p7_srs_ind(nfapi_pnf_p7_config_t* config, nfapi_srs_indication_t* ind);
+int nfapi_pnf_p7_nr_srs_ind(nfapi_pnf_p7_config_t* config, nfapi_nr_srs_indication_t* ind);
 
 /*! Send the SR.indication
  * \param config A pointer to a PNF P7 config
@@ -842,6 +845,7 @@ int nfapi_pnf_p7_cqi_ind(nfapi_pnf_p7_config_t* config, nfapi_cqi_indication_t*
  * \return 0 means success, -1 means failure
  */
 int nfapi_pnf_p7_lbt_dl_ind(nfapi_pnf_p7_config_t* config, nfapi_lbt_dl_indication_t* ind);
+int nfapi_pnf_p7_nr_uci_ind(nfapi_pnf_p7_config_t* config, nfapi_nr_uci_indication_t* ind);
 
 /*! Send the NB_HARQ.indication
  * \param config A pointer to a PNF P7 config
@@ -856,6 +860,7 @@ int nfapi_pnf_p7_nb_harq_ind(nfapi_pnf_p7_config_t* config, nfapi_nb_harq_indica
  * \return 0 means success, -1 means failure
  */
 int nfapi_pnf_p7_nrach_ind(nfapi_pnf_p7_config_t* config, nfapi_nrach_indication_t* ind);
+int nfapi_pnf_p7_nr_rach_ind(nfapi_pnf_p7_config_t* config, nfapi_nr_rach_indication_t* ind);
 
 
 /*! Send a vendor exntesion message
diff --git a/nfapi/open-nFAPI/pnf/src/pnf.c b/nfapi/open-nFAPI/pnf/src/pnf.c
index fdafd93279179da659f75096b9cccbce0bf88272..b4158dbb40f6bec8c49126e789c2be8e262103d1 100644
--- a/nfapi/open-nFAPI/pnf/src/pnf.c
+++ b/nfapi/open-nFAPI/pnf/src/pnf.c
@@ -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.
@@ -93,9 +93,9 @@ void pnf_nr_handle_pnf_param_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 	else
 	{
 		nfapi_nr_pnf_param_request_t req;
-		
+
 		NFAPI_TRACE(NFAPI_TRACE_INFO, "PNF_PARAM.request received\n");
-	
+
 		// unpack the message
 		if (nfapi_nr_p5_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(nfapi_nr_pnf_param_request_t), &pnf->_public.codec_config) >= 0)
 		{
@@ -109,7 +109,7 @@ void pnf_nr_handle_pnf_param_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 			else
 			{
 				NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: PNF not in IDLE state\n", __FUNCTION__);
-		
+
 				nfapi_nr_pnf_param_response_t resp;
 				memset(&resp, 0, sizeof(resp));
 				resp.header.message_id = NFAPI_NR_PHY_MSG_TYPE_PNF_PARAM_RESPONSE;
@@ -121,7 +121,7 @@ void pnf_nr_handle_pnf_param_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 		{
 			NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Unpack message failed, ignoring\n", __FUNCTION__);
 		}
-	
+
 		if(req.vendor_extension)
 			pnf->_public.codec_config.deallocate(req.vendor_extension);
 	}
@@ -137,9 +137,9 @@ void pnf_handle_pnf_param_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 	else
 	{
 		nfapi_pnf_param_request_t req;
-		
+
 		NFAPI_TRACE(NFAPI_TRACE_INFO, "PNF_PARAM.request received\n");
-	
+
 		// unpack the message
 		if (nfapi_p5_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(nfapi_pnf_param_request_t), &pnf->_public.codec_config) >= 0)
 		{
@@ -153,7 +153,7 @@ void pnf_handle_pnf_param_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 			else
 			{
 				NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: PNF not in IDLE state\n", __FUNCTION__);
-		
+
 				nfapi_pnf_param_response_t resp;
 				memset(&resp, 0, sizeof(resp));
 				resp.header.message_id = NFAPI_PNF_PARAM_RESPONSE;
@@ -165,7 +165,7 @@ void pnf_handle_pnf_param_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 		{
 			NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Unpack message failed, ignoring\n", __FUNCTION__);
 		}
-	
+
 		if(req.vendor_extension)
 			pnf->_public.codec_config.deallocate(req.vendor_extension);
 	}
@@ -185,7 +185,7 @@ void pnf_handle_pnf_config_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 		nfapi_pnf_config_request_t req;
 
 		NFAPI_TRACE(NFAPI_TRACE_INFO, "PNF_CONFIG.request received\n");
-	
+
 		// unpack the message
 		if (nfapi_p5_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(req), &pnf->_public.codec_config) >= 0)
 		{
@@ -194,7 +194,7 @@ void pnf_handle_pnf_config_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 			{
 				// delete the phy records
 				nfapi_pnf_phy_config_delete_all(&pnf->_public);
-		
+
 				// create the phy records
 				if (req.pnf_phy_rf_config.tl.tag == NFAPI_PNF_PHY_RF_TAG)
 				{
@@ -203,14 +203,14 @@ void pnf_handle_pnf_config_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 					{
 						nfapi_pnf_phy_config_t* phy = (nfapi_pnf_phy_config_t*)malloc(sizeof(nfapi_pnf_phy_config_t));
 						memset(phy, 0, sizeof(nfapi_pnf_phy_config_t));
-		
+
 						phy->state = NFAPI_PNF_PHY_IDLE;
 						phy->phy_id = req.pnf_phy_rf_config.phy_rf_config[i].phy_id;
-		
+
 						nfapi_pnf_phy_config_add(&(pnf->_public), phy);
 					}
 				}
-		
+
 				if(pnf->_public.pnf_config_req)
 				{
 					(pnf->_public.pnf_config_req)(&(pnf->_public), &req);
@@ -219,7 +219,7 @@ void pnf_handle_pnf_config_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 			else
 			{
 				NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: PNF not in correct state: %d\n", __FUNCTION__, pnf->_public.state);
-		
+
 				nfapi_pnf_config_response_t resp;
 				memset(&resp, 0, sizeof(resp));
 				resp.header.message_id = NFAPI_PNF_CONFIG_RESPONSE;
@@ -251,7 +251,7 @@ void pnf_nr_handle_pnf_config_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen
 		nfapi_nr_pnf_config_request_t req;
 
 		NFAPI_TRACE(NFAPI_TRACE_INFO, "PNF_CONFIG.request received\n");
-	
+
 		// unpack the message
 		if (nfapi_nr_p5_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(req), &pnf->_public.codec_config) >= 0)
 		{
@@ -260,7 +260,7 @@ void pnf_nr_handle_pnf_config_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen
 			{
 				// delete the phy records
 				nfapi_pnf_phy_config_delete_all(&pnf->_public);
-		
+
 				// create the phy records
 				if (req.pnf_phy_rf_config.tl.tag == NFAPI_PNF_PHY_RF_TAG)
 				{
@@ -269,14 +269,14 @@ void pnf_nr_handle_pnf_config_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen
 					{
 						nfapi_pnf_phy_config_t* phy = (nfapi_pnf_phy_config_t*)malloc(sizeof(nfapi_pnf_phy_config_t));
 						memset(phy, 0, sizeof(nfapi_pnf_phy_config_t));
-		
+
 						phy->state = NFAPI_PNF_PHY_IDLE;
 						phy->phy_id = req.pnf_phy_rf_config.phy_rf_config[i].phy_id;
-		
+
 						nfapi_pnf_phy_config_add(&(pnf->_public), phy);
 					}
 				}
-		
+
 				if(pnf->_public.pnf_nr_config_req)
 				{
 					(pnf->_public.pnf_nr_config_req)(&(pnf->_public), &req);
@@ -285,7 +285,7 @@ void pnf_nr_handle_pnf_config_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen
 			else
 			{
 				NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: PNF not in correct state: %d\n", __FUNCTION__, pnf->_public.state);
-		
+
 				nfapi_nr_pnf_config_response_t resp;
 				memset(&resp, 0, sizeof(resp));
 				resp.header.message_id = NFAPI_PNF_CONFIG_RESPONSE;
@@ -315,7 +315,7 @@ void pnf_handle_pnf_start_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 		nfapi_pnf_start_request_t req;
 
 		NFAPI_TRACE(NFAPI_TRACE_INFO, "PNF_START.request Received\n");
-	
+
 		// unpack the message
 		if (nfapi_p5_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(req), &pnf->_public.codec_config) >= 0)
 		{
@@ -357,7 +357,7 @@ void pnf_nr_handle_pnf_start_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 		nfapi_nr_pnf_start_request_t req;
 
 		NFAPI_TRACE(NFAPI_TRACE_INFO, "PNF_START.request Received\n");
-	
+
 		// unpack the message
 		if (nfapi_nr_p5_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(req), &pnf->_public.codec_config) >= 0)
 		{
@@ -397,9 +397,9 @@ void pnf_handle_pnf_stop_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 	else
 	{
 		nfapi_pnf_stop_request_t req;
-		
+
 		NFAPI_TRACE(NFAPI_TRACE_INFO, "PNF_STOP.request Received\n");
-	
+
 		// unpack the message
 		if (nfapi_p5_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(req), &pnf->_public.codec_config) >= 0)
 		{
@@ -423,7 +423,7 @@ void pnf_handle_pnf_stop_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 		{
 			NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Unpack message failed, ignoring\n", __FUNCTION__);
 		}
-	
+
 
 		if(req.vendor_extension)
 			pnf->_public.codec_config.deallocate(req.vendor_extension);
@@ -440,11 +440,11 @@ void pnf_handle_param_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 	else
 	{
 		nfapi_param_request_t req;
-		
+
 		nfapi_pnf_config_t* config = &(pnf->_public);
-	
+
 		NFAPI_TRACE(NFAPI_TRACE_INFO, "PARAM.request received\n");
-	
+
 		// unpack the message
 		if (nfapi_p5_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(req), &config->codec_config) >= 0)
 		{
@@ -479,7 +479,7 @@ void pnf_handle_param_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 					resp.error_code = NFAPI_MSG_INVALID_CONFIG;
 					nfapi_pnf_param_resp(config, &resp);
 				}
-		
+
 			}
 			else
 			{
@@ -495,7 +495,7 @@ void pnf_handle_param_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 		{
 			NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Unpack message failed, ignoring\n", __FUNCTION__);
 		}
-	
+
 		if(req.vendor_extension)
 			pnf->_public.codec_config.deallocate(req.vendor_extension);
 
@@ -512,11 +512,11 @@ void pnf_nr_handle_param_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 	else
 	{
 		nfapi_nr_param_request_scf_t req;
-		
+
 		nfapi_pnf_config_t* config = &(pnf->_public);
-	
+
 		NFAPI_TRACE(NFAPI_TRACE_INFO, "PARAM.request received\n");
-	
+
 		// unpack the message
 		if (nfapi_nr_p5_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(req), &config->codec_config) >= 0)
 		{
@@ -551,7 +551,7 @@ void pnf_nr_handle_param_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 					resp.error_code = NFAPI_MSG_INVALID_CONFIG;
 					nfapi_nr_pnf_param_resp(config, &resp);
 				}
-		
+
 			}
 			else
 			{
@@ -567,7 +567,7 @@ void pnf_nr_handle_param_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 		{
 			NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Unpack message failed, ignoring\n", __FUNCTION__);
 		}
-	
+
 		if(req.vendor_extension)
 			pnf->_public.codec_config.deallocate(req.vendor_extension);
 
@@ -587,9 +587,9 @@ void pnf_handle_config_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 		nfapi_config_request_t req;
 
 		NFAPI_TRACE(NFAPI_TRACE_INFO, "CONFIG.request received\n");
-	
+
 		nfapi_pnf_config_t* config = &(pnf->_public);
-	
+
 		// unpack the message
 		if (nfapi_p5_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(req), &config->codec_config) >= 0)
 		{
@@ -639,7 +639,7 @@ void pnf_handle_config_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 		{
 			NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Unpack message failed, ignoring\n", __FUNCTION__);
 		}
-	
+
 		if(req.vendor_extension)
 			pnf->_public.codec_config.deallocate(req.vendor_extension);
 	}
@@ -659,9 +659,9 @@ void pnf_nr_handle_config_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 		nfapi_nr_config_request_scf_t req;
 
 		NFAPI_TRACE(NFAPI_TRACE_INFO, "CONFIG.request received\n");
-	
+
 		nfapi_pnf_config_t* config = &(pnf->_public);
-	
+
 		// unpack the message
 		if (nfapi_nr_p5_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(req), &config->codec_config) >= 0)
 		{
@@ -681,7 +681,7 @@ void pnf_nr_handle_config_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 						{
 							(config->nr_config_req)(config, phy, &req);
 
-					
+
 						}
 					}
 					else
@@ -718,7 +718,7 @@ void pnf_nr_handle_config_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 		{
 			NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Unpack message failed, ignoring\n", __FUNCTION__);
 		}
-	
+
 		if(req.vendor_extension)
 			pnf->_public.codec_config.deallocate(req.vendor_extension);
 	}
@@ -734,11 +734,11 @@ void pnf_handle_start_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 	else
 	{
 		nfapi_start_request_t req;
-	
+
 		nfapi_pnf_config_t* config = &(pnf->_public);
-	
+
 		NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() START.request received state:%d\n", __FUNCTION__, config->state);
-	
+
 		// unpack the message
 		if (nfapi_p5_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(req), &config->codec_config) >= 0)
 		{
@@ -788,7 +788,7 @@ void pnf_handle_start_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 		{
 			NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Unpack message failed, ignoring\n", __FUNCTION__);
 		}
-		
+
 		if(req.vendor_extension)
 			pnf->_public.codec_config.deallocate(req.vendor_extension);
 
@@ -805,11 +805,11 @@ void pnf_nr_handle_start_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 	else
 	{
 		 nfapi_nr_start_request_scf_t req;
-	
+
 		nfapi_pnf_config_t* config = &(pnf->_public);
-	
+
 		NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() START.request received state:%d\n", __FUNCTION__, config->state);
-	
+
 		// unpack the message
 		if (nfapi_nr_p5_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(req), &config->codec_config) >= 0)
 		{
@@ -859,7 +859,7 @@ void pnf_nr_handle_start_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 		{
 			NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Unpack message failed, ignoring\n", __FUNCTION__);
 		}
-		
+
 		if(req.vendor_extension)
 			pnf->_public.codec_config.deallocate(req.vendor_extension);
 
@@ -878,9 +878,9 @@ void pnf_handle_stop_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 		nfapi_stop_request_t req;
 
 		NFAPI_TRACE(NFAPI_TRACE_INFO, "STOP.request received\n");
-	
+
 		nfapi_pnf_config_t* config = &(pnf->_public);
-	
+
 		// unpack the message
 		if (nfapi_p5_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(req), &config->codec_config) >= 0)
 		{
@@ -930,10 +930,10 @@ void pnf_handle_stop_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 		{
 			NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Unpack message failed, ignoring\n", __FUNCTION__);
 		}
-			
+
 		if(req.vendor_extension)
 			pnf->_public.codec_config.deallocate(req.vendor_extension);
-	
+
 	}
 }
 
@@ -949,9 +949,9 @@ void pnf_nr_handle_stop_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 		nfapi_nr_stop_request_t req;
 
 		NFAPI_TRACE(NFAPI_TRACE_INFO, "STOP.request received\n");
-	
+
 		nfapi_pnf_config_t* config = &(pnf->_public);
-	
+
 		// unpack the message
 		if (nfapi_nr_p5_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(req), &config->codec_config) >= 0)
 		{
@@ -1001,10 +1001,10 @@ void pnf_nr_handle_stop_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 		{
 			NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Unpack message failed, ignoring\n", __FUNCTION__);
 		}
-			
+
 		if(req.vendor_extension)
 			pnf->_public.codec_config.deallocate(req.vendor_extension);
-	
+
 	}
 }
 
@@ -1020,9 +1020,9 @@ void pnf_handle_measurement_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 		nfapi_measurement_request_t req;
 
 		NFAPI_TRACE(NFAPI_TRACE_INFO, "MEASUREMENT.request received\n");
-	
+
 		nfapi_pnf_config_t* config = &(pnf->_public);
-	
+
 		// unpack the message
 		if (nfapi_p5_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(req), &config->codec_config) >= 0)
 		{
@@ -1072,7 +1072,7 @@ void pnf_handle_measurement_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 		{
 			NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Unpack message failed, ignoring\n", __FUNCTION__);
 		}
-	
+
 		if(req.vendor_extension)
 			pnf->_public.codec_config.deallocate(req.vendor_extension);
 	}
@@ -1087,13 +1087,13 @@ void pnf_handle_rssi_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 		NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: NULL parameters\n", __FUNCTION__);
 	}
 	else
-	{	
+	{
 		nfapi_rssi_request_t req;
-		
+
 		NFAPI_TRACE(NFAPI_TRACE_INFO, "RSSI.request received\n");
-	
+
 		nfapi_pnf_config_t* config = &(pnf->_public);
-	
+
 		// unpack the message
 		if (nfapi_p4_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(req), &config->codec_config) >= 0)
 		{
@@ -1143,10 +1143,10 @@ void pnf_handle_rssi_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 		{
 			NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Unpack message failed, ignoring\n", __FUNCTION__);
 		}
-	
+
 		if(req.vendor_extension)
 			pnf->_public.codec_config.deallocate(req.vendor_extension);
-	
+
 	}
 }
 
@@ -1159,11 +1159,11 @@ void pnf_handle_cell_search_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 	else
 	{
 		nfapi_cell_search_request_t req;
-		
+
 		NFAPI_TRACE(NFAPI_TRACE_INFO, "CELL_SEARCH.request received\n");
-	
+
 		nfapi_pnf_config_t* config = &(pnf->_public);
-	
+
 		if (nfapi_p4_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(req), &config->codec_config) >= 0)
 		{
 			if(config->state == NFAPI_PNF_RUNNING)
@@ -1212,7 +1212,7 @@ void pnf_handle_cell_search_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 		{
 			NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Unpack message failed, ignoring\n", __FUNCTION__);
 		}
-	
+
 		if(req.vendor_extension)
 			pnf->_public.codec_config.deallocate(req.vendor_extension);
 	}
@@ -1231,9 +1231,9 @@ void pnf_handle_broadcast_detect_request(pnf_t* pnf, void *pRecvMsg, int recvMsg
 		nfapi_broadcast_detect_request_t req;
 
 		NFAPI_TRACE(NFAPI_TRACE_INFO, "BROADCAST_DETECT.request received\n");
-	
+
 		nfapi_pnf_config_t* config = &(pnf->_public);
-	
+
 		if (nfapi_p4_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(req), &config->codec_config) >= 0)
 		{
 			if(config->state == NFAPI_PNF_RUNNING)
@@ -1282,7 +1282,7 @@ void pnf_handle_broadcast_detect_request(pnf_t* pnf, void *pRecvMsg, int recvMsg
 		{
 			NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Unpack message failed, ignoring\n", __FUNCTION__);
 		}
-	
+
 		if(req.vendor_extension)
 			pnf->_public.codec_config.deallocate(req.vendor_extension);
 
@@ -1298,11 +1298,11 @@ void pnf_handle_system_information_schedule_request(pnf_t* pnf, void *pRecvMsg,
 	else
 	{
 		nfapi_system_information_schedule_request_t req;
-	
+
 		NFAPI_TRACE(NFAPI_TRACE_INFO, "SYSTEM_INFORMATION_SCHEDULE.request received\n");
-	
+
 		nfapi_pnf_config_t* config = &(pnf->_public);
-	
+
 		if (nfapi_p4_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(req), &config->codec_config) >= 0)
 		{
 			if(config->state == NFAPI_PNF_RUNNING)
@@ -1351,7 +1351,7 @@ void pnf_handle_system_information_schedule_request(pnf_t* pnf, void *pRecvMsg,
 		{
 			NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Unpack message failed, ignoring\n", __FUNCTION__);
 		}
-		
+
 		if(req.vendor_extension)
 			pnf->_public.codec_config.deallocate(req.vendor_extension);
 	}
@@ -1368,9 +1368,9 @@ void pnf_handle_system_information_request(pnf_t* pnf, void *pRecvMsg, int recvM
 		nfapi_system_information_request_t req;
 
 		NFAPI_TRACE(NFAPI_TRACE_INFO, "SYSTEM_INFORMATION.request received\n");
-	
+
 		nfapi_pnf_config_t* config = &(pnf->_public);
-	
+
 		if (nfapi_p4_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(req), &config->codec_config) >= 0)
 		{
 			if(config->state == NFAPI_PNF_RUNNING)
@@ -1419,7 +1419,7 @@ void pnf_handle_system_information_request(pnf_t* pnf, void *pRecvMsg, int recvM
 		{
 			NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Unpack message failed, ignoring\n", __FUNCTION__);
 		}
-	
+
 		if(req.vendor_extension)
 			pnf->_public.codec_config.deallocate(req.vendor_extension);
 	}
@@ -1435,11 +1435,11 @@ void pnf_handle_nmm_stop_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 	else
 	{
 		nfapi_nmm_stop_request_t req;
-		
+
 		NFAPI_TRACE(NFAPI_TRACE_INFO, "NMM_STOP.request received\n");
-	
+
 		nfapi_pnf_config_t* config = &(pnf->_public);
-	
+
 		if (nfapi_p4_message_unpack(pRecvMsg, recvMsgLen, &req, sizeof(req), &config->codec_config) >= 0)
 		{
 			if(config->state == NFAPI_PNF_RUNNING)
@@ -1488,7 +1488,7 @@ void pnf_handle_nmm_stop_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 		{
 			NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Unpack message failed, ignoring\n", __FUNCTION__);
 		}
-	
+
 		if(req.vendor_extension)
 			pnf->_public.codec_config.deallocate(req.vendor_extension);
 	}
@@ -1504,21 +1504,21 @@ void pnf_handle_vendor_extension(void* pRecvMsg, int recvMsgLen, pnf_t* pnf, uin
 	else
 	{
 		nfapi_pnf_config_t* config = &(pnf->_public);
-	
+
 		if(config->allocate_p4_p5_vendor_ext)
 		{
 			uint16_t msg_size;
 			nfapi_p4_p5_message_header_t* msg = config->allocate_p4_p5_vendor_ext(message_id, &msg_size);
-	
+
 			if(msg == 0)
 			{
-				NFAPI_TRACE(NFAPI_TRACE_INFO, "%s failed to allocate vendor extention structure\n");
+				NFAPI_TRACE(NFAPI_TRACE_INFO, "failed to allocate vendor extention structure\n");
 				return;
 			}
-	
-			
+
+
 			int unpack_result = nfapi_p5_message_unpack(pRecvMsg, recvMsgLen, msg, msg_size, &config->codec_config);
-	
+
 			if(unpack_result == 0)
 			{
 				if(config->vendor_ext)
@@ -1528,10 +1528,10 @@ void pnf_handle_vendor_extension(void* pRecvMsg, int recvMsgLen, pnf_t* pnf, uin
 			{
 				NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Unpack message failed, ignoring\n", __FUNCTION__);
 			}
-			
+
 			if(config->deallocate_p4_p5_vendor_ext)
 				config->deallocate_p4_p5_vendor_ext(msg);
-			
+
 		}
 	}
 }
@@ -1732,8 +1732,8 @@ void pnf_handle_p5_message(pnf_t* pnf, void *pRecvMsg, int recvMsgLen)
 int pnf_nr_pack_and_send_p5_message(pnf_t* pnf, nfapi_p4_p5_message_header_t* msg, uint32_t msg_len)
 {
 	int packed_len = nfapi_nr_p5_message_pack(msg, msg_len,
-										   pnf->tx_message_buffer, 
-										   sizeof(pnf->tx_message_buffer), 
+										   pnf->tx_message_buffer,
+										   sizeof(pnf->tx_message_buffer),
 										   &pnf->_public.codec_config);
 
 	if (packed_len < 0)
@@ -1749,8 +1749,8 @@ int pnf_nr_pack_and_send_p5_message(pnf_t* pnf, nfapi_p4_p5_message_header_t* ms
 int pnf_pack_and_send_p5_message(pnf_t* pnf, nfapi_p4_p5_message_header_t* msg, uint32_t msg_len)
 {
 	int packed_len = nfapi_p5_message_pack(msg, msg_len,
-										   pnf->tx_message_buffer, 
-										   sizeof(pnf->tx_message_buffer), 
+										   pnf->tx_message_buffer,
+										   sizeof(pnf->tx_message_buffer),
 										   &pnf->_public.codec_config);
 
 	if (packed_len < 0)
@@ -1765,8 +1765,8 @@ int pnf_pack_and_send_p5_message(pnf_t* pnf, nfapi_p4_p5_message_header_t* msg,
 int pnf_pack_and_send_p4_message(pnf_t* pnf, nfapi_p4_p5_message_header_t* msg, uint32_t msg_len)
 {
 	int packed_len = nfapi_p4_message_pack(msg, msg_len,
-										   pnf->tx_message_buffer, 
-										   sizeof(pnf->tx_message_buffer), 
+										   pnf->tx_message_buffer,
+										   sizeof(pnf->tx_message_buffer),
 										   &pnf->_public.codec_config);
 
 	if (packed_len < 0)
@@ -1797,14 +1797,14 @@ int pnf_connect(pnf_t* pnf)
 	NFAPI_TRACE(NFAPI_TRACE_INFO, "Starting P5 PNF connection to VNF at %s:%u\n", pnf->_public.vnf_ip_addr, pnf->_public.vnf_p5_port);
 
 	// todo split the vnf address list. currently only supporting 1
-	
+
 	struct addrinfo hints, *servinfo;
 	memset(&hints, 0, sizeof(hints));
 
 	hints.ai_socktype = SOCK_STREAM; // For SCTP we are only interested in SOCK_STREAM
 	// todo : allow the client to restrict IPV4 or IPV6
 		// todo : randomize which address to connect to?
-	
+
 	char port_str[8];
 	snprintf(port_str, sizeof(port_str), "%d", pnf->_public.vnf_p5_port);
 	if(getaddrinfo(pnf->_public.vnf_ip_addr, port_str,  &hints, &servinfo) != 0)
@@ -1822,7 +1822,7 @@ int pnf_connect(pnf_t* pnf)
 		char* family = "Unknown";
 		char* address = "Unknown";
 		char _addr[128];
-		
+
 		if(p->ai_family == AF_INET6)
 		{
 			family = "IPV6";
@@ -1886,7 +1886,7 @@ int pnf_connect(pnf_t* pnf)
 		}
 		else
 		{
-			// Create an IP socket point 
+			// Create an IP socket point
 			if ((pnf->p5_sock = socket(p->ai_family, SOCK_STREAM, IPPROTO_IP)) < 0)
 			{
 				NFAPI_TRACE(NFAPI_TRACE_ERROR, "After P5 socket errno: %d\n", errno);
@@ -1894,12 +1894,12 @@ int pnf_connect(pnf_t* pnf)
 				return -1;
 			}
 		}
-	
+
 		NFAPI_TRACE(NFAPI_TRACE_INFO, "P5 socket created...\n");
-	
+
 		if (connect(pnf->p5_sock, p->ai_addr, p->ai_addrlen ) < 0)
 		{
-			NFAPI_TRACE(NFAPI_TRACE_ERROR, "After connect (address:%s port:%d) errno: %d\n", 
+			NFAPI_TRACE(NFAPI_TRACE_ERROR, "After connect (address:%s port:%d) errno: %d\n",
 					pnf->_public.vnf_ip_addr, pnf->_public.vnf_p5_port, errno);
 
 			if(errno == EINVAL)
@@ -1970,14 +1970,16 @@ int pnf_connect(pnf_t* pnf)
 
 int pnf_send_message(pnf_t* pnf, uint8_t *msg, uint32_t len, uint16_t stream)
 {
-	
+
 	if (pnf->sctp)
 	{
+#if 0
 		printf("\nPNF SENDS: \n");
 		for(int i=0; i<len; i++){
 			printf("%d", msg[i]);
 		}
 		printf("\n");
+#endif
 
 		if (sctp_sendmsg(pnf->p5_sock, msg, len, NULL, 0, 42/*config->sctp_stream_number*/, 0, stream/*P5_STREAM_ID*/, 0, 0) < 0)
 		{
@@ -2069,12 +2071,14 @@ int pnf_read_dispatch_message(pnf_t* pnf)
 		}
 		else
 		{
+#if 0
 			// print the received message
 			printf("\n MESSAGE RECEIVED: \n");
 			for(int i=0; i<message_size; i++){
 				printf("%d", read_buffer[i]);
 			}
 			printf("\n");
+#endif
 
 			if (flags & MSG_NOTIFICATION)
 			{
@@ -2198,12 +2202,14 @@ int pnf_nr_read_dispatch_message(pnf_t* pnf)
 		}
 		else
 		{
+#if 0
 			// print the received message
 			printf("\n MESSAGE RECEIVED: \n");
 			for(int i=0; i<message_size; i++){
 				printf("%d", read_buffer[i]);
 			}
 			printf("\n");
+#endif
 
 			if (flags & MSG_NOTIFICATION)
 			{
@@ -2275,7 +2281,7 @@ int pnf_message_pump(pnf_t* pnf)
 		selectRetval = select(pnf->p5_sock+1, &rfds, NULL, NULL, &timeout);
 
 		if(selectRetval == 0)
-		{	
+		{
 			// timeout
 			continue;
 		}
@@ -2336,7 +2342,7 @@ int pnf_nr_message_pump(pnf_t* pnf)
 		selectRetval = select(pnf->p5_sock+1, &rfds, NULL, NULL, &timeout);
 
 		if(selectRetval == 0)
-		{	
+		{
 			// timeout
 			continue;
 		}
@@ -2376,4 +2382,3 @@ int pnf_nr_message_pump(pnf_t* pnf)
 	return 0;
 
 }
-
diff --git a/nfapi/open-nFAPI/pnf/src/pnf_interface.c b/nfapi/open-nFAPI/pnf/src/pnf_interface.c
index 8c9722c13e6df95df9115165ea70412ec0c19835..a53604640cfb12359d7c8aea02be85b8399f0dc9 100644
--- a/nfapi/open-nFAPI/pnf/src/pnf_interface.c
+++ b/nfapi/open-nFAPI/pnf/src/pnf_interface.c
@@ -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.
@@ -32,11 +32,11 @@ nfapi_pnf_config_t* nfapi_pnf_config_create()
 	memset(_this, 0, sizeof(pnf_t));
 
 	_this->sctp = 1;	// enable sctp
-	
+
 	_this->_public.vnf_p5_port = NFAPI_P5_SCTP_PORT;
-	
+
 	_this->_public.malloc = &malloc;
-	_this->_public.free = &free;	
+	_this->_public.free = &free;
 
 	_this->_public.codec_config.allocate = &malloc;
 	_this->_public.codec_config.deallocate = &free;
@@ -55,10 +55,6 @@ int nfapi_pnf_start(nfapi_pnf_config_t* config)
 	if(config == 0)
 		return -1;
 
-	// Make sure to set the defined trace function before using NFAPI_TRACE
-	if(config->trace)
-		nfapi_trace_g = config->trace;
-
 	NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__);
 
 	pnf_t* _this = (pnf_t*)(config);
@@ -89,10 +85,6 @@ int nfapi_nr_pnf_start(nfapi_pnf_config_t* config)
 	if(config == 0)
 		return -1;
 
-	// Make sure to set the defined trace function before using NFAPI_TRACE
-	if(config->trace)
-		nfapi_trace_g = config->trace;
-
 	NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__);
 
 	pnf_t* _this = (pnf_t*)(config);
@@ -265,7 +257,7 @@ int nfapi_pnf_param_resp(nfapi_pnf_config_t* config, nfapi_param_response_t* res
 		NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: NULL parameters\n", __FUNCTION__);
 		return -1;
 	}
-	
+
 	pnf_t* _this = (pnf_t*)(config);
 
 	return pnf_pack_and_send_p5_message(_this, &(resp->header), sizeof(nfapi_param_response_t));
@@ -279,7 +271,7 @@ int nfapi_nr_pnf_param_resp(nfapi_pnf_config_t* config, nfapi_nr_param_response_
 		NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: NULL parameters\n", __FUNCTION__);
 		return -1;
 	}
-	
+
 	pnf_t* _this = (pnf_t*)(config);
 
 	return pnf_nr_pack_and_send_p5_message(_this, &(resp->header), sizeof(nfapi_nr_param_response_scf_t));
@@ -591,4 +583,3 @@ int nfapi_pnf_vendor_extension(nfapi_pnf_config_t* config, nfapi_p4_p5_message_h
 
 	return pnf_pack_and_send_p5_message(_this, msg, msg_len);
 }
-
diff --git a/nfapi/open-nFAPI/pnf/src/pnf_p7.c b/nfapi/open-nFAPI/pnf/src/pnf_p7.c
index 092b967189b5050d057aaa87171dc547ac071e97..fb1a713e56532a60aac9f9ae6a9e3fac74cf14d7 100644
--- a/nfapi/open-nFAPI/pnf/src/pnf_p7.c
+++ b/nfapi/open-nFAPI/pnf/src/pnf_p7.c
@@ -1060,6 +1060,23 @@ int pnf_p7_slot_ind(pnf_p7_t* pnf_p7, uint16_t phy_id, uint16_t sfn, uint16_t sl
 				(pnf_p7->_public.ul_dci_req_fn)(NULL, &(pnf_p7->_public), pnf_p7->_public.dummy_slot.ul_dci_req);
 			}
 		}
+		if(tx_slot_buffer->ul_tti_req != 0)
+		{
+			if(pnf_p7->_public.ul_tti_req_fn)
+			{ 
+				(pnf_p7->_public.ul_tti_req_fn)(NULL, &(pnf_p7->_public), tx_slot_buffer->ul_tti_req);
+			}
+		}
+		else
+		{
+			// send dummy
+			if(pnf_p7->_public.ul_tti_req_fn && pnf_p7->_public.dummy_slot.ul_tti_req)
+			{
+				pnf_p7->_public.dummy_slot.ul_tti_req->SFN = sfn_tx;
+				pnf_p7->_public.dummy_slot.ul_tti_req->Slot = slot_tx;
+				(pnf_p7->_public.ul_tti_req_fn)(NULL, &(pnf_p7->_public), pnf_p7->_public.dummy_slot.ul_tti_req);
+			}
+		}
 
 		//deallocate slot buffers after passing down the PDUs to PHY processing
 
@@ -1585,7 +1602,7 @@ void pnf_handle_dl_tti_request(void* pRecvMsg, int recvMsgLen, pnf_p7_t* pnf_p7)
 
 	if(req == NULL)
 	{
-		NFAPI_TRACE(NFAPI_TRACE_INFO, "%s failed to alloced nfapi_dl_tti_request structure\n");
+		NFAPI_TRACE(NFAPI_TRACE_INFO, "failed to allocate nfapi_dl_tti_request structure\n");
 		return;
 	}
 	int unpack_result = nfapi_nr_p7_message_unpack(pRecvMsg, recvMsgLen, req, sizeof(nfapi_nr_dl_tti_request_t), &(pnf_p7->_public.codec_config));
@@ -1659,7 +1676,7 @@ void pnf_handle_dl_config_request(void* pRecvMsg, int recvMsgLen, pnf_p7_t* pnf_
 
 	if(req == NULL)
 	{
-		NFAPI_TRACE(NFAPI_TRACE_INFO, "%s failed to alloced nfapi_dl_config_request structure\n");
+		NFAPI_TRACE(NFAPI_TRACE_INFO, "failed to allocate nfapi_dl_config_request structure\n");
 		return;
 	}
 
@@ -1750,7 +1767,7 @@ void pnf_handle_ul_tti_request(void* pRecvMsg, int recvMsgLen, pnf_p7_t* pnf_p7)
 
 	if(req == NULL)
 	{
-		NFAPI_TRACE(NFAPI_TRACE_INFO, "%s failed to alloced nfapi_ul_tti_request structure\n");
+		NFAPI_TRACE(NFAPI_TRACE_INFO, "failed to allocate nfapi_ul_tti_request structure\n");
 		return;
 	}
 
@@ -1825,7 +1842,7 @@ void pnf_handle_ul_config_request(void* pRecvMsg, int recvMsgLen, pnf_p7_t* pnf_
 
 	if(req == NULL)
 	{
-		NFAPI_TRACE(NFAPI_TRACE_INFO, "%s failed to alloced nfapi_ul_config_request structure\n");
+		NFAPI_TRACE(NFAPI_TRACE_INFO, "failed to allocate nfapi_ul_config_request structure\n");
 		return;
 	}
 
@@ -1898,7 +1915,7 @@ void pnf_handle_ul_dci_request(void* pRecvMsg, int recvMsgLen, pnf_p7_t* pnf_p7)
 
 	if(req == NULL)
 	{
-		NFAPI_TRACE(NFAPI_TRACE_INFO, "%s failed to allocate nfapi_ul_dci_request structure\n");
+		NFAPI_TRACE(NFAPI_TRACE_INFO, "failed to allocate nfapi_ul_dci_request structure\n");
 		return;
 	}
 
@@ -1969,7 +1986,7 @@ void pnf_handle_hi_dci0_request(void* pRecvMsg, int recvMsgLen, pnf_p7_t* pnf_p7
 
 	if(req == NULL)
 	{
-		NFAPI_TRACE(NFAPI_TRACE_INFO, "%s failed to alloced nfapi_hi_dci0_request structure\n");
+		NFAPI_TRACE(NFAPI_TRACE_INFO, "failed to allocate nfapi_hi_dci0_request structure\n");
 		return;
 	}
 
@@ -2038,7 +2055,7 @@ void pnf_handle_tx_data_request(void* pRecvMsg, int recvMsgLen, pnf_p7_t* pnf_p7
 
 	if(req == NULL)
 	{
-		NFAPI_TRACE(NFAPI_TRACE_INFO, "%s failed to alloced nfapi_tx_request structure\n");
+		NFAPI_TRACE(NFAPI_TRACE_INFO, "failed to allocate nfapi_tx_request structure\n");
 		return;
 	}
 
@@ -2118,7 +2135,7 @@ void pnf_handle_tx_request(void* pRecvMsg, int recvMsgLen, pnf_p7_t* pnf_p7)
 
 	if(req == NULL)
 	{
-		NFAPI_TRACE(NFAPI_TRACE_INFO, "%s failed to alloced nfapi_tx_request structure\n");
+		NFAPI_TRACE(NFAPI_TRACE_INFO, "failed to allocate nfapi_tx_request structure\n");
 		return;
 	}
 
@@ -2192,7 +2209,7 @@ void pnf_handle_lbt_dl_config_request(void* pRecvMsg, int recvMsgLen, pnf_p7_t*
 
 	if(req == NULL)
 	{
-		NFAPI_TRACE(NFAPI_TRACE_INFO, "%s failed to alloced nfapi_lbt_dl_config_request structure\n");
+		NFAPI_TRACE(NFAPI_TRACE_INFO, "failed to allocate nfapi_lbt_dl_config_request structure\n");
 		return;
 	}
 
@@ -2255,7 +2272,7 @@ void pnf_handle_p7_vendor_extension(void* pRecvMsg, int recvMsgLen, pnf_p7_t* pn
 
 		if(msg == 0)
 		{
-			NFAPI_TRACE(NFAPI_TRACE_INFO, "%s failed to allocate vendor extention structure\n");
+			NFAPI_TRACE(NFAPI_TRACE_INFO, "failed to allocate vendor extention structure\n");
 			return;
 		}
 
@@ -2279,7 +2296,7 @@ void pnf_handle_ue_release_request(void* pRecvMsg, int recvMsgLen, pnf_p7_t* pnf
     nfapi_ue_release_request_t* req = allocate_nfapi_ue_release_request(pnf_p7);
     if(req == NULL)
     {
-        NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s failed to alloced nfapi_ue_release_request structure\n");
+        NFAPI_TRACE(NFAPI_TRACE_ERROR, "failed to allocate nfapi_ue_release_request structure\n");
         return;
     }
 
@@ -2381,7 +2398,7 @@ uint32_t calculate_nr_t2(uint32_t now_time_hr, uint16_t sfn,uint16_t slot, uint3
         {
           static uint32_t prev_t2 = 0;
 
-          NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s(now_time_hr:%u sfn:%d slot:%d slot_start_time_Hr:%u) slot_time_us:%u t2:%u prev_t2:%u diff:%u\n",
+          NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s(now_time_hr:%u sfn to slot:%d slot_start_time_Hr:%u) slot_time_us:%u t2:%u prev_t2:%u diff:%u\n",
               __FUNCTION__,
               now_time_hr, NFAPI_SFNSLOT2DEC(sfn, slot), slot_start_time_hr,
               slot_time_us,
@@ -2656,7 +2673,7 @@ void pnf_handle_p7_message(void *pRecvMsg, int recvMsgLen, pnf_p7_t* pnf_p7,  ui
 	// validate the input params
 	if(pRecvMsg == NULL || recvMsgLen < 4 || pnf_p7 == NULL)
 	{
-		NFAPI_TRACE(NFAPI_TRACE_ERROR, "pnf_handle_p7_message: invalid input params (%d %d %d)\n", pRecvMsg, recvMsgLen, pnf_p7);
+		NFAPI_TRACE(NFAPI_TRACE_ERROR, "pnf_handle_p7_message: invalid input params (%p %d %p)\n", pRecvMsg, recvMsgLen, pnf_p7);
 		return;
 	}
 
@@ -2762,7 +2779,7 @@ void pnf_nr_handle_p7_message(void *pRecvMsg, int recvMsgLen, pnf_p7_t* pnf_p7,
 	// validate the input params
 	if(pRecvMsg == NULL || recvMsgLen < 4 || pnf_p7 == NULL)
 	{
-		NFAPI_TRACE(NFAPI_TRACE_ERROR, "pnf_handle_p7_message: invalid input params (%d %d %d)\n", pRecvMsg, recvMsgLen, pnf_p7);
+		NFAPI_TRACE(NFAPI_TRACE_ERROR, "pnf_handle_p7_message: invalid input params (%p %d %p)\n", pRecvMsg, recvMsgLen, pnf_p7);
 		return;
 	}
 
@@ -2889,12 +2906,19 @@ void pnf_nfapi_p7_read_dispatch_message(pnf_p7_t* pnf_p7, uint32_t now_hr_time)
 			}
 
 			// read the segment
-			recvfrom_result = recvfrom(pnf_p7->p7_sock, pnf_p7->rx_message_buffer, header.message_length, MSG_DONTWAIT, (struct sockaddr*)&remote_addr, &remote_addr_size);
+			recvfrom_result = recvfrom(pnf_p7->p7_sock, pnf_p7->rx_message_buffer, pnf_p7->rx_message_buffer_size,
+                                                   MSG_DONTWAIT | MSG_TRUNC, (struct sockaddr*)&remote_addr, &remote_addr_size);
 
 		now_hr_time = pnf_get_current_time_hr(); //DJP - moved to here - get closer timestamp???
 
 			if(recvfrom_result > 0)
 			{
+				if (recvfrom_result != header.message_length)
+				{
+					NFAPI_TRACE(NFAPI_TRACE_ERROR, "(%d) Received unexpected number of bytes. %d != %d",
+                                                    __LINE__, recvfrom_result, header.message_length);
+					break;
+				}
 				pnf_handle_p7_message(pnf_p7->rx_message_buffer, recvfrom_result, pnf_p7, now_hr_time);
 				//printf("\npnf_handle_p7_message sfn=%d,slot=%d\n",pnf_p7->sfn,pnf_p7->slot);
 			}
@@ -3126,6 +3150,38 @@ int pnf_p7_message_pump(pnf_p7_t* pnf_p7)
 	return 0;
 }
 
+struct timespec pnf_timespec_add(struct timespec lhs, struct timespec rhs)
+{
+	struct timespec result;
+
+	result.tv_sec = lhs.tv_sec + rhs.tv_sec;
+	result.tv_nsec = lhs.tv_nsec + rhs.tv_nsec;
+
+	if(result.tv_nsec > 1e9)
+	{
+		result.tv_sec++;
+		result.tv_nsec-= 1e9;
+	}
+
+	return result;
+}
+
+struct timespec pnf_timespec_sub(struct timespec lhs, struct timespec rhs)
+{
+	struct timespec result;
+	if ((lhs.tv_nsec-rhs.tv_nsec)<0) 
+	{
+		result.tv_sec = lhs.tv_sec-rhs.tv_sec-1;
+		result.tv_nsec = 1000000000+lhs.tv_nsec-rhs.tv_nsec;
+	} 
+	else 
+	{
+		result.tv_sec = lhs.tv_sec-rhs.tv_sec;
+		result.tv_nsec = lhs.tv_nsec-rhs.tv_nsec;
+	}
+	return result;
+}
+
 int pnf_nr_p7_message_pump(pnf_p7_t* pnf_p7)
 {
 
@@ -3201,6 +3257,19 @@ int pnf_nr_p7_message_pump(pnf_p7_t* pnf_p7)
 	}
 	NFAPI_TRACE(NFAPI_TRACE_INFO, "PNF P7 bind succeeded...\n");
 
+	//Initializaing timing structures needed for slot ticking 
+
+	struct timespec slot_start;
+	clock_gettime(CLOCK_MONOTONIC, &slot_start);
+
+	struct timespec pselect_start;
+
+	struct timespec slot_duration;
+	slot_duration.tv_sec = 0;
+	slot_duration.tv_nsec = 0.5e6;
+
+	//Infinite loop 
+
 	while(pnf_p7->terminate == 0)
 	{
 		fd_set rfds;
@@ -3210,11 +3279,29 @@ int pnf_nr_p7_message_pump(pnf_p7_t* pnf_p7)
 		FD_ZERO(&rfds);
 		FD_SET(pnf_p7->p7_sock, &rfds);
 
-		struct timeval timeout;
+		struct timespec timeout;
 		timeout.tv_sec = 100;
-		timeout.tv_usec = 0;
+		timeout.tv_nsec = 0;
+		clock_gettime(CLOCK_MONOTONIC, &pselect_start);
 
-		selectRetval = select(pnf_p7->p7_sock+1, &rfds, NULL, NULL, &timeout);
+		//setting the timeout
+
+		if((pselect_start.tv_sec > slot_start.tv_sec) || ((pselect_start.tv_sec == slot_start.tv_sec) && (pselect_start.tv_nsec > slot_start.tv_nsec)))
+		{
+			// overran the end of the subframe we do not want to wait
+			timeout.tv_sec = 0;
+			timeout.tv_nsec = 0;
+
+			//struct timespec overrun = pnf_timespec_sub(pselect_start, sf_start);
+			//NFAPI_TRACE(NFAPI_TRACE_INFO, "Subframe overrun detected of %d.%d running to catchup\n", overrun.tv_sec, overrun.tv_nsec);
+		}
+		else
+		{
+			// still time before the end of the subframe wait
+			timeout = pnf_timespec_sub(slot_start, pselect_start);
+		}
+
+		selectRetval = pselect(pnf_p7->p7_sock+1, &rfds, NULL, NULL, &timeout, NULL);
 
 		uint32_t now_hr_time = pnf_get_current_time_hr();
 
@@ -3224,6 +3311,17 @@ int pnf_nr_p7_message_pump(pnf_p7_t* pnf_p7)
 		if(selectRetval == 0)
 		{	
 			// timeout
+
+			//update slot start timing
+			slot_start = pnf_timespec_add(slot_start, slot_duration);
+
+			//increment sfn/slot
+			if (++pnf_p7->slot == 20)
+                        {
+                                pnf_p7->slot = 0;
+                                pnf_p7->sfn = (pnf_p7->sfn + 1) % 1024;
+                        }
+
 			continue;
 		}
 		else if (selectRetval == -1 && (errno == EINTR))
@@ -3242,7 +3340,7 @@ int pnf_nr_p7_message_pump(pnf_p7_t* pnf_p7)
 		if(FD_ISSET(pnf_p7->p7_sock, &rfds)) 
 
 		{
-			pnf_nr_nfapi_p7_read_dispatch_message(pnf_p7, now_hr_time);
+			pnf_nr_nfapi_p7_read_dispatch_message(pnf_p7, now_hr_time); 
 		}
 	}
 		NFAPI_TRACE(NFAPI_TRACE_ERROR, "PNF_P7 Terminating..\n");
diff --git a/nfapi/open-nFAPI/pnf/src/pnf_p7_interface.c b/nfapi/open-nFAPI/pnf/src/pnf_p7_interface.c
index 0db1feb398cc8922c954d0782337b8fc0c3e4691..a1be4d0edcd8eb66a7a3cb622157ff698d938cec 100644
--- a/nfapi/open-nFAPI/pnf/src/pnf_p7_interface.c
+++ b/nfapi/open-nFAPI/pnf/src/pnf_p7_interface.c
@@ -44,6 +44,7 @@ nfapi_pnf_p7_config_t* nfapi_pnf_p7_config_create()
 	_this->_public.codec_config.allocate = &malloc;
 	_this->_public.codec_config.deallocate = &free;
 
+	// cppcheck-suppress memleak
 	return &(_this->_public);
 }
 
@@ -63,10 +64,6 @@ int nfapi_pnf_p7_start(nfapi_pnf_p7_config_t* config)
 	if(config == 0)
 		return -1;
 
-	// Make sure to set the defined trace function before using NFAPI_TRACE
-	if(config->trace)
-		nfapi_trace_g = config->trace;
-
 	pnf_p7_t* _this = (pnf_p7_t*)(config);
 
 	NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__);
@@ -82,10 +79,6 @@ int nfapi_nr_pnf_p7_start(nfapi_pnf_p7_config_t* config)
 	if(config == 0)
 		return -1;
 
-	// Make sure to set the defined trace function before using NFAPI_TRACE
-	if(config->trace)
-		nfapi_trace_g = config->trace;
-
 	pnf_p7_t* _this = (pnf_p7_t*)(config);
 
 	NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__);
@@ -175,17 +168,7 @@ int nfapi_pnf_p7_rach_ind(nfapi_pnf_p7_config_t* config, nfapi_rach_indication_t
 	pnf_p7_t* _this = (pnf_p7_t*)(config);
 	return pnf_p7_pack_and_send_p7_message(_this, (nfapi_p7_message_header_t*)ind, sizeof(nfapi_rach_indication_t));
 }
-int nfapi_pnf_p7_srs_ind(nfapi_pnf_p7_config_t* config, nfapi_srs_indication_t* ind)
-{
-	if(config == NULL || ind == NULL)
-	{
-		NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: invalid input params\n", __FUNCTION__);
-		return -1;
-	}
 
-	pnf_p7_t* _this = (pnf_p7_t*)(config);
-	return pnf_p7_pack_and_send_p7_message(_this, (nfapi_p7_message_header_t*)ind, sizeof(nfapi_srs_indication_t));
-}
 int nfapi_pnf_p7_sr_ind(nfapi_pnf_p7_config_t* config, nfapi_sr_indication_t* ind)
 {
 	if(config == NULL || ind == NULL)
diff --git a/nfapi/open-nFAPI/pnf_sim/src/fapi_stub.cpp b/nfapi/open-nFAPI/pnf_sim/src/fapi_stub.cpp
index 1c2f0bef8078a072d7abd9eab6de65cbe3b5568d..4fe5065ceac54c687c1fa73e159b87f3061fc549 100644
--- a/nfapi/open-nFAPI/pnf_sim/src/fapi_stub.cpp
+++ b/nfapi/open-nFAPI/pnf_sim/src/fapi_stub.cpp
@@ -278,7 +278,7 @@ void *fapi_thread_start(void *ptr) {
 
     if(instance->tick == 1000) {
       if(instance->tx_byte_count > 0) {
-        printf("[FAPI] Tx rate %d bytes/sec\n", instance->tx_byte_count);
+        printf("[FAPI] Tx rate %u bytes/sec\n", instance->tx_byte_count);
         instance->tx_byte_count = 0;
       }
 
@@ -319,7 +319,7 @@ void *fapi_thread_start(void *ptr) {
       millisec = now_ts.tv_nsec / 1e6;
 
       if(last_millisec != -1 && ((last_millisec + 1 ) % 1000) != millisec) {
-        printf("*** missing millisec %d %d\n", last_millisec, millisec);
+        printf("*** missing millisec %u %u\n", last_millisec, millisec);
         catchup = millisec - last_millisec - 1;
       }
 
diff --git a/nfapi/open-nFAPI/vnf/public_inc/nfapi_vnf_interface.h b/nfapi/open-nFAPI/vnf/public_inc/nfapi_vnf_interface.h
index 31328393c9a5749f8dc784abf74c3a78638b4248..decb48e5c8334482029cc3c05a57f34d8c1ca4f2 100644
--- a/nfapi/open-nFAPI/vnf/public_inc/nfapi_vnf_interface.h
+++ b/nfapi/open-nFAPI/vnf/public_inc/nfapi_vnf_interface.h
@@ -20,6 +20,7 @@
 #include "nfapi_interface.h"
 #include "nfapi_nr_interface_scf.h"
 #include "nfapi_nr_interface.h"
+#include "openair2/PHY_INTERFACE/queue_t.h"
 
 #include "debug.h"
 
@@ -86,8 +87,6 @@ typedef struct nfapi_vnf_config
 	void* (*malloc)(size_t size);
 	/*! A user define callback to override the default memory deallocation */
 	void (*free)(void*);
-	/*! A user define callback to handle trace from the pnf */
-	void (*trace)(nfapi_trace_level_t level, const char* message, ...);
 
 	/*! The port the VNF P5 SCTP connection listens on
 	 *
@@ -662,12 +661,6 @@ typedef struct nfapi_vnf_p7_config
 	 * If not set the vnf p7 library will use free
 	 */
 	void (*free)(void*);
-	
-	/*! A user define callback to handle trace from the pnf
-	 * \param level The trace level 
-	 * \param message The trace string
-	 */
-	void (*trace)(nfapi_trace_level_t level, const char* message, ...);
 
 	/*! The port the vnf p7 will receive on */
 	int port;
@@ -908,7 +901,7 @@ void nfapi_vnf_p7_config_destory(nfapi_vnf_p7_config_t* config);
  * This function is blocking and will not return until the nfapi_vnf_p7_stop
  * function is called. 
  */
- 
+extern queue_t gnb_slot_ind_queue;
 int nfapi_vnf_p7_start(nfapi_vnf_p7_config_t* config);
 int nfapi_nr_vnf_p7_start(nfapi_vnf_p7_config_t* config);
 
diff --git a/nfapi/open-nFAPI/vnf/src/vnf.c b/nfapi/open-nFAPI/vnf/src/vnf.c
index 7fee47d6d5423b5acd381d998a9083a582632eb9..e0431ced174fb9185319201fe748cd8e41b1f8fe 100644
--- a/nfapi/open-nFAPI/vnf/src/vnf.c
+++ b/nfapi/open-nFAPI/vnf/src/vnf.c
@@ -85,7 +85,7 @@ void nfapi_vnf_pnf_list_add(nfapi_vnf_config_t* config, nfapi_vnf_pnf_info_t* no
 
 nfapi_vnf_pnf_info_t* nfapi_vnf_pnf_list_find(nfapi_vnf_config_t* config, int p5_idx)
 {
-	NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s : config->pnf_list:%p\n", __FUNCTION__, config->pnf_list);
+	NFAPI_TRACE(NFAPI_TRACE_DEBUG, "config->pnf_list:%p\n", config->pnf_list);
 
 	nfapi_vnf_pnf_info_t* curr = config->pnf_list;
 	while(curr != 0)
@@ -1051,7 +1051,7 @@ void vnf_handle_vendor_extension(void* pRecvMsg, int recvMsgLen, nfapi_vnf_confi
 		}
 		else
 		{
-			NFAPI_TRACE(NFAPI_TRACE_INFO, "%s failed to allocate vendor extention structure\n");
+			NFAPI_TRACE(NFAPI_TRACE_INFO, "failed to allocate vendor extention structure\n");
 		}
 	}
 }
@@ -1383,6 +1383,7 @@ int vnf_read_dispatch_message(nfapi_vnf_config_t* config, nfapi_vnf_pnf_info_t*
 		
 		uint32_t header_buffer_size = NFAPI_HEADER_LENGTH;
 		uint8_t header_buffer[header_buffer_size];
+		memset(header_buffer, 0, header_buffer_size);
 
 		uint32_t stack_buffer_size = 32; //should it be the size of then sctp_notificatoin structure
 		uint8_t stack_buffer[stack_buffer_size];
@@ -1393,6 +1394,7 @@ int vnf_read_dispatch_message(nfapi_vnf_config_t* config, nfapi_vnf_pnf_info_t*
 		uint32_t message_size = 0;
 
 		struct sockaddr_in addr;
+		memset(&addr, 0, sizeof(addr));
 		socklen_t addr_len = sizeof(addr);
 
 		struct sctp_sndrcvinfo sndrcvinfo;
diff --git a/nfapi/open-nFAPI/vnf/src/vnf_interface.c b/nfapi/open-nFAPI/vnf/src/vnf_interface.c
index 084c4fa48547dcb1958dd806bed057eb2cea4a04..633dd18f2402c0759b9a625b251462fdaa5d525a 100644
--- a/nfapi/open-nFAPI/vnf/src/vnf_interface.c
+++ b/nfapi/open-nFAPI/vnf/src/vnf_interface.c
@@ -25,6 +25,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <errno.h>
+#include <assert.h>
 
 #include <stdio.h>
 
@@ -69,10 +70,6 @@ int nfapi_nr_vnf_start(nfapi_vnf_config_t* config)
 	if(config == 0)
 		return -1;
 
-	// Make sure to set the defined trace function before using NFAPI_TRACE
-	if(config->trace)
-		nfapi_trace_g = (nfapi_trace_fn_t)config->trace;
-
 	NFAPI_TRACE(NFAPI_TRACE_INFO, "%s()\n", __FUNCTION__);
 
 	int p5ListenSock, p5Sock; 
@@ -218,7 +215,7 @@ int nfapi_nr_vnf_start(nfapi_vnf_config_t* config)
 		initMsg.sinit_max_instreams = 5; //MAX_SCTP_STREAMS;  // number of output streams can be greater
 		if (setsockopt(p5ListenSock, IPPROTO_SCTP, SCTP_INITMSG, &initMsg, sizeof(initMsg)) < 0)
 		{
-			NFAPI_TRACE(NFAPI_TRACE_ERROR, "After setsockopt (SCTP_INITMSG) errno: %d\n", errno)
+			NFAPI_TRACE(NFAPI_TRACE_ERROR, "After setsockopt (SCTP_INITMSG) errno: %d\n", errno);
 			close(p5ListenSock);
 			return 0;
 		}
@@ -477,14 +474,7 @@ int nfapi_nr_vnf_start(nfapi_vnf_config_t* config)
 
 int nfapi_vnf_start(nfapi_vnf_config_t* config)
 {
-	// Verify that config is not null
-	if(config == 0)
-		return -1;
-
-	// Make sure to set the defined trace function before using NFAPI_TRACE
-	if(config->trace)
-		nfapi_trace_g = (nfapi_trace_fn_t)config->trace;
-
+	assert(config != 0);
 	NFAPI_TRACE(NFAPI_TRACE_INFO, "%s()\n", __FUNCTION__);
 
 	int p5ListenSock, p5Sock; 
@@ -630,7 +620,7 @@ int nfapi_vnf_start(nfapi_vnf_config_t* config)
 		initMsg.sinit_max_instreams = 5; //MAX_SCTP_STREAMS;  // number of output streams can be greater
 		if (setsockopt(p5ListenSock, IPPROTO_SCTP, SCTP_INITMSG, &initMsg, sizeof(initMsg)) < 0)
 		{
-			NFAPI_TRACE(NFAPI_TRACE_ERROR, "After setsockopt (SCTP_INITMSG) errno: %d\n", errno)
+			NFAPI_TRACE(NFAPI_TRACE_ERROR, "After setsockopt (SCTP_INITMSG) errno: %d\n", errno);
 			close(p5ListenSock);
 			return 0;
 		}
@@ -1164,7 +1154,7 @@ int nfapi_vnf_allocate_phy(nfapi_vnf_config_t* config, int p5_idx, uint16_t* phy
 
 	info->timing_window = 30;       // This seems to override what gets set by the user - why??? //TODO: Change in NR in terms of microsecends,what should be the value?
 	info->timing_info_mode = 0x03;
-	info->timing_info_period = 128;
+	info->timing_info_period = 10;
 
 	nfapi_vnf_phy_info_list_add(config, info);
 
diff --git a/nfapi/open-nFAPI/vnf/src/vnf_p7.c b/nfapi/open-nFAPI/vnf/src/vnf_p7.c
index e3900315540f00e1dc88bea25da468fcf48a49a1..2ac59dd7be91f24ca40d6eb1cb8ac87d1393fb84 100644
--- a/nfapi/open-nFAPI/vnf/src/vnf_p7.c
+++ b/nfapi/open-nFAPI/vnf/src/vnf_p7.c
@@ -17,14 +17,21 @@
 
 #include <time.h>
 
+#include <stdio.h>
 #include <sys/time.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 #include <errno.h>
 #include <stdio.h>
+#include <assert.h>
+
 #include "vnf_p7.h"
 
+#ifdef NDEBUG
+#  warning assert is disabled
+#endif
+
 #define SYNC_CYCLE_COUNT 2
 
 void* vnf_p7_malloc(vnf_p7_t* vnf_p7, size_t size)
@@ -816,11 +823,6 @@ void vnf_handle_rx_ulsch_indication(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vn
 			}
 		}
 
-		uint16_t i = 0;
-		for(i = 0; i < ind.rx_indication_body.number_of_pdus; ++i)
-		{
-			vnf_p7_codec_free(vnf_p7, ind.rx_indication_body.rx_pdu_list[i].data);
-		}
 		vnf_p7_codec_free(vnf_p7, ind.rx_indication_body.rx_pdu_list);
 		vnf_p7_codec_free(vnf_p7, ind.vendor_extension);
 	}
@@ -1157,7 +1159,7 @@ void vnf_handle_ul_node_sync(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vnf_p7)
                   struct timespec ts;
                   clock_gettime(CLOCK_MONOTONIC, &ts);
 
-			NFAPI_TRACE(NFAPI_TRACE_INFO, "(%4d/%1d) %d.%d PNF to VNF phy_id:%2d (t1/2/3/4:%8u, %8u, %8u, %8u) txrx:%4u procT:%3u latency(us):%4d(avg:%4d) offset(us):%8d filtered(us):%8d wrap[t1:%u t2:%u]\n",
+			NFAPI_TRACE(NFAPI_TRACE_INFO, "(%4d/%1d) %ld.%ld PNF to VNF phy_id:%2d (t1/2/3/4:%8u, %8u, %8u, %8u) txrx:%4u procT:%3u latency(us):%4d(avg:%4d) offset(us):%8d filtered(us):%8d wrap[t1:%u t2:%u]\n",
 					NFAPI_SFNSF2SFN(phy->sfn_sf), NFAPI_SFNSF2SF(phy->sfn_sf), ts.tv_sec, ts.tv_nsec, ind.header.phy_id,
 					ind.t1, ind.t2, ind.t3, t4, 
 					tx_2_rx, pnf_proc_time, latency, phy->average_latency, phy->sf_offset, phy->sf_offset_filtered,
@@ -1292,7 +1294,7 @@ void vnf_handle_ul_node_sync(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vnf_p7)
 							//NFAPI_TRACE(NFAPI_TRACE_NOTE, "VNF P7 In Sync with phy (phy_id:%d)\n", phy->phy_id); 
 
 							if(vnf_p7->_public.sync_indication)
-								(vnf_p7->_public.sync_indication)(&(vnf_p7->_public), 1);
+								(vnf_p7->_public.sync_indication)(&(vnf_p7->_public), phy->in_sync);
 						}
 
 						phy->in_sync = 1;
@@ -1471,7 +1473,8 @@ void vnf_handle_nr_slot_indication(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vnf
 		}
 		else
 		{
-			if(vnf_p7->_public.nr_slot_indication)
+			NFAPI_TRACE(NFAPI_TRACE_INFO, "%s: Handling NR SLOT Indication\n", __FUNCTION__);
+                        if(vnf_p7->_public.nr_slot_indication)
 			{
 				(vnf_p7->_public.nr_slot_indication)(&ind);
 			}
@@ -1496,12 +1499,12 @@ void vnf_handle_nr_rx_data_indication(void *pRecvMsg, int recvMsgLen, vnf_p7_t*
 		}
 		else
 		{
-			if(vnf_p7->_public.nr_rx_data_indication)
+			NFAPI_TRACE(NFAPI_TRACE_INFO, "%s: Handling RX Indication\n", __FUNCTION__);
+                        if(vnf_p7->_public.nr_rx_data_indication)
 			{
 				(vnf_p7->_public.nr_rx_data_indication)(&ind);
 			}
 		}
-
 	}
 }
 
@@ -1522,12 +1525,12 @@ void vnf_handle_nr_crc_indication(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vnf_
 		}
 		else
 		{
+		        NFAPI_TRACE(NFAPI_TRACE_INFO, "%s: Handling CRC Indication\n", __FUNCTION__);
 			if(vnf_p7->_public.nr_crc_indication)
-			{	
+			{
 				(vnf_p7->_public.nr_crc_indication)(&ind);
 			}
 		}
-		
 	}
 }
 
@@ -1573,12 +1576,12 @@ void vnf_handle_nr_uci_indication(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vnf_
 		}
 		else
 		{
+		        NFAPI_TRACE(NFAPI_TRACE_INFO, "%s: Handling UCI Indication\n", __FUNCTION__);
 			if(vnf_p7->_public.nr_uci_indication)
 			{
 				(vnf_p7->_public.nr_uci_indication)(&ind);
 			}
 		}
-
 	}
 }
 
@@ -1599,12 +1602,12 @@ void vnf_handle_nr_rach_indication(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vnf
 		}
 		else
 		{
+		        NFAPI_TRACE(NFAPI_TRACE_INFO, "%s: Handling RACH Indication\n", __FUNCTION__);
 			if(vnf_p7->_public.nr_rach_indication)
 			{
 				(vnf_p7->_public.nr_rach_indication)(&ind);
 			}
 		}
-		
 	}
 }
 
@@ -1699,14 +1702,7 @@ void vnf_nr_handle_ul_node_sync(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vnf_p7
 	}
 
         if (phy->filtered_adjust && (phy->slot_offset_filtered > 1e6 || phy->slot_offset_filtered < -1e6))
-        {  struct timespec ts;
-           clock_gettime(CLOCK_MONOTONIC, &ts);
-			NFAPI_TRACE(NFAPI_TRACE_NOTE, "(%4d/%1d) %d.%d PNF to VNF phy_id:%2d (t1/2/3/4:%8u, %8u, %8u, %8u) txrx:%4u procT:%3u latency(us):%4d(avg:%4d) offset(us):%8d filtered(us):%8d wrap[t1:%u t2:%u]\n", 
-					phy->sfn, phy->slot, ts.tv_sec, ts.tv_nsec, ind.header.phy_id,
-					ind.t1, ind.t2, ind.t3, t4, 
-					tx_2_rx, pnf_proc_time, latency, phy->average_latency, phy->slot_offset, phy->slot_offset_filtered,
-					(ind.t1<phy->previous_t1), (ind.t2<phy->previous_t2));
-
+        {
           phy->filtered_adjust = 0;
           phy->zero_count=0;
           phy->min_sync_cycle_count = 2;
@@ -1738,7 +1734,7 @@ void vnf_nr_handle_ul_node_sync(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vnf_p7
 
 			sfn_slot_dec += (phy->slot_offset / 500);
 			
-			//NFAPI_TRACE(NFAPI_TRACE_NOTE, "PNF to VNF slot offset:%d sfn :%d slot:%d \n",phy->slot_offset,NFAPI_SFNSLOTDEC2SFN(sfn_slot_dec),NFAPI_SFNSLOTDEC2SLOT(sfn_slot_dec) ); 
+			NFAPI_TRACE(NFAPI_TRACE_NOTE, "PNF to VNF slot offset:%d sfn :%d slot:%d \n",phy->slot_offset,NFAPI_SFNSLOTDEC2SFN(sfn_slot_dec),NFAPI_SFNSLOTDEC2SLOT(sfn_slot_dec) );
 
 
 		}
@@ -1838,7 +1834,7 @@ void vnf_nr_handle_ul_node_sync(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vnf_p7
 							NFAPI_TRACE(NFAPI_TRACE_NOTE, "VNF P7 In Sync with phy (phy_id:%d)\n", phy->phy_id); 
 
 							if(vnf_p7->_public.sync_indication)
-								(vnf_p7->_public.sync_indication)(&(vnf_p7->_public), 1);
+								(vnf_p7->_public.sync_indication)(&(vnf_p7->_public), phy->in_sync);
 						}
 
 						phy->in_sync = 1;
@@ -2032,6 +2028,7 @@ void vnf_handle_timing_info(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vnf_p7)
         }
 }
 
+int16_t vnf_pnf_sfnslot_delta;
 
 void vnf_nr_handle_timing_info(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vnf_p7)
 {
@@ -2051,18 +2048,21 @@ void vnf_nr_handle_timing_info(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vnf_p7)
         if (vnf_p7 && vnf_p7->p7_connections)
         {
           //int16_t vnf_pnf_sfnsf_delta = NFAPI_SFNSF2DEC(vnf_p7->p7_connections[0].sfn_sf) - NFAPI_SFNSF2DEC(ind.last_sfn_sf);
-            int16_t vnf_pnf_sfnslot_delta = NFAPI_SFNSLOT2DEC(vnf_p7->p7_connections[0].sfn,vnf_p7->p7_connections[0].slot) - NFAPI_SFNSLOT2DEC(ind.last_sfn,ind.last_slot);
+            vnf_pnf_sfnslot_delta = NFAPI_SFNSLOT2DEC(vnf_p7->p7_connections[0].sfn,vnf_p7->p7_connections[0].slot) - NFAPI_SFNSLOT2DEC(ind.last_sfn,ind.last_slot);
           //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() PNF:SFN/SF:%d VNF:SFN/SF:%d deltaSFNSF:%d\n", __FUNCTION__, NFAPI_SFNSF2DEC(ind.last_sfn_sf), NFAPI_SFNSF2DEC(vnf_p7->p7_connections[0].sfn_sf), vnf_pnf_sfnsf_delta);
 
           // Panos: Careful here!!! Modification of the original nfapi-code
           //if (vnf_pnf_sfnsf_delta>1 || vnf_pnf_sfnsf_delta < -1)
 		  //printf("VNF-PNF delta - %d", vnf_pnf_sfnslot_delta);
-          if (vnf_pnf_sfnslot_delta>0 || vnf_pnf_sfnslot_delta < 0)
+          if (vnf_pnf_sfnslot_delta != 0)
           {
-            NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() LARGE SFN/SF DELTA between PNF and VNF delta:%d VNF:%d PNF:%d\n\n\n\n\n\n\n\n\n", __FUNCTION__, vnf_pnf_sfnslot_delta,NFAPI_SFNSLOT2DEC(vnf_p7->p7_connections[0].sfn,vnf_p7->p7_connections[0].slot),NFAPI_SFNSLOT2DEC(ind.last_sfn,ind.last_slot)) ;
+            NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() LARGE SFN/SLOT DELTA between PNF and VNF. Delta %d. PNF:%d.%d VNF:%d.%d\n\n\n\n\n\n\n\n\n",
+                        __FUNCTION__, vnf_pnf_sfnslot_delta,
+                        ind.last_sfn, ind.last_slot,
+                        vnf_p7->p7_connections[0].sfn, vnf_p7->p7_connections[0].slot);
             // Panos: Careful here!!! Modification of the original nfapi-code
-            //  vnf_p7->p7_connections[0].sfn = ind.last_sfn;
-			//  vnf_p7->p7_connections[0].slot = ind.last_slot;
+            vnf_p7->p7_connections[0].sfn = ind.last_sfn;
+            vnf_p7->p7_connections[0].slot = ind.last_slot;
           }
         }
 }
@@ -2248,7 +2248,7 @@ void vnf_handle_p7_message(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vnf_p7)
 	// validate the input params
 	if(pRecvMsg == NULL || recvMsgLen < 4 || vnf_p7 == NULL)
 	{
-		NFAPI_TRACE(NFAPI_TRACE_ERROR, "vnf_handle_p7_message: invalid input params (%d %d %d)\n", pRecvMsg, recvMsgLen, vnf_p7);
+		NFAPI_TRACE(NFAPI_TRACE_ERROR, "vnf_handle_p7_message: invalid input params (%p %d %p)\n", pRecvMsg, recvMsgLen, vnf_p7);
 		return;
 	}
 
@@ -2366,7 +2366,7 @@ void vnf_nr_handle_p7_message(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vnf_p7)
 	// validate the input params
 	if(pRecvMsg == NULL || recvMsgLen < 4 || vnf_p7 == NULL)
 	{
-		NFAPI_TRACE(NFAPI_TRACE_ERROR, "vnf_handle_p7_message: invalid input params (%d %d %d)\n", pRecvMsg, recvMsgLen, vnf_p7);
+		NFAPI_TRACE(NFAPI_TRACE_ERROR, "vnf_handle_p7_message: invalid input params (%p %d %p)\n", pRecvMsg, recvMsgLen, vnf_p7);
 		return;
 	}
 
@@ -2508,26 +2508,22 @@ int vnf_nr_p7_read_dispatch_message(vnf_p7_t* vnf_p7)
 			}
 
 			// read the segment
-			recvfrom_result = recvfrom(vnf_p7->socket, vnf_p7->rx_message_buffer, header.message_length, MSG_WAITALL, (struct sockaddr*)&remote_addr, &remote_addr_size);
+			recvfrom_result = recvfrom(vnf_p7->socket, vnf_p7->rx_message_buffer, header.message_length, MSG_WAITALL | MSG_TRUNC, (struct sockaddr*)&remote_addr, &remote_addr_size);
+			NFAPI_TRACE(NFAPI_TRACE_DEBUG, "recvfrom_result = %d from %s():%d\n", recvfrom_result, __FUNCTION__, __LINE__);
 
 			// todo : how to handle incomplete readfroms, need some sort of buffer/select
 
-			if(recvfrom_result == 0)
-			{
-				NFAPI_TRACE(NFAPI_TRACE_ERROR, "recvfrom returned 0\n");
-			}
-			else if(recvfrom_result != header.message_length)
-			{
-				NFAPI_TRACE(NFAPI_TRACE_NOTE, "did not receive the entire message %d %d\n", recvfrom_result, header.message_length); 
-				
-				recvfrom_result += recvfrom(vnf_p7->socket, &vnf_p7->rx_message_buffer[recvfrom_result], header.message_length - recvfrom_result, MSG_WAITALL, (struct sockaddr*)&remote_addr, &remote_addr_size);
-	
-			}
-			
-			
-			if(recvfrom_result > 0)
+			if (recvfrom_result > 0)
 			{
+				if (recvfrom_result != header.message_length)
+				{
+					NFAPI_TRACE(NFAPI_TRACE_ERROR, "(%d) Received unexpected number of bytes. %d != %d",
+						    __LINE__, recvfrom_result, header.message_length);
+					break;
+				}
+				NFAPI_TRACE(NFAPI_TRACE_DEBUG, "Calling vnf_nr_handle_p7_message from %d\n", __LINE__);
 				vnf_nr_handle_p7_message(vnf_p7->rx_message_buffer, recvfrom_result, vnf_p7);
+				return 0;
 			}
 			else
 			{
@@ -2592,9 +2588,9 @@ int vnf_p7_read_dispatch_message(vnf_p7_t* vnf_p7)
 			{
 				NFAPI_TRACE(NFAPI_TRACE_ERROR, "recvfrom returned 0\n");
 			}
-			else if(recvfrom_result != header.message_length)
+			else if(recvfrom_result != -1 && recvfrom_result != header.message_length)
 			{
-				NFAPI_TRACE(NFAPI_TRACE_NOTE, "did not receive the entire message %d %d\n", recvfrom_result, header.message_length); 
+				NFAPI_TRACE(NFAPI_TRACE_ERROR, "Received unexpected number of bytes %d %d\n", recvfrom_result, header.message_length);
 				
 				recvfrom_result += recvfrom(vnf_p7->socket, &vnf_p7->rx_message_buffer[recvfrom_result], header.message_length - recvfrom_result, MSG_WAITALL, (struct sockaddr*)&remote_addr, &remote_addr_size);
 	
@@ -2646,10 +2642,11 @@ void vnf_p7_release_msg(vnf_p7_t* vnf_p7, nfapi_p7_message_header_t* header)
 		case NFAPI_RX_ULSCH_INDICATION:
 			{
 				nfapi_rx_indication_t* rx_ind = (nfapi_rx_indication_t*)(header);
-				uint16_t i = 0;
-				for(i = 0; i < rx_ind->rx_indication_body.number_of_pdus; ++i)
+				size_t number_of_pdus = rx_ind->rx_indication_body.number_of_pdus;
+                                assert(number_of_pdus <= NFAPI_RX_IND_MAX_PDU);
+				for(size_t i = 0; i < number_of_pdus; ++i)
 				{
-					vnf_p7_codec_free(vnf_p7, rx_ind->rx_indication_body.rx_pdu_list[i].data);
+					vnf_p7_codec_free(vnf_p7, rx_ind->rx_indication_body.rx_pdu_list[i].rx_ind_data);
 				}
 
 				vnf_p7_codec_free(vnf_p7, rx_ind->rx_indication_body.rx_pdu_list);
diff --git a/nfapi/open-nFAPI/vnf/src/vnf_p7_interface.c b/nfapi/open-nFAPI/vnf/src/vnf_p7_interface.c
index 8cebf2b468b7f38b475d342639106ab421933617..852707fbbd25e964c8b60753ac375c99485d1275 100644
--- a/nfapi/open-nFAPI/vnf/src/vnf_p7_interface.c
+++ b/nfapi/open-nFAPI/vnf/src/vnf_p7_interface.c
@@ -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.
@@ -45,13 +45,13 @@ nfapi_vnf_p7_config_t* nfapi_vnf_p7_config_create()
 	_this->_public.segment_size = 1400;
 	_this->_public.max_num_segments = 8;
 	_this->_public.checksum_enabled = 1;
-	
+
 	_this->_public.malloc = &malloc;
-	_this->_public.free = &free;	
+	_this->_public.free = &free;
 
 	_this->_public.codec_config.allocate = &malloc;
 	_this->_public.codec_config.deallocate = &free;
-	
+
 
 	return (nfapi_vnf_p7_config_t*)_this;
 }
@@ -81,12 +81,12 @@ struct timespec timespec_add(struct timespec lhs, struct timespec rhs)
 struct timespec timespec_sub(struct timespec lhs, struct timespec rhs)
 {
 	struct timespec result;
-	if ((lhs.tv_nsec-rhs.tv_nsec)<0) 
+	if ((lhs.tv_nsec-rhs.tv_nsec)<0)
 	{
 		result.tv_sec = lhs.tv_sec-rhs.tv_sec-1;
 		result.tv_nsec = 1000000000+lhs.tv_nsec-rhs.tv_nsec;
-	} 
-	else 
+	}
+	else
 	{
 		result.tv_sec = lhs.tv_sec-rhs.tv_sec;
 		result.tv_nsec = lhs.tv_nsec-rhs.tv_nsec;
@@ -94,7 +94,7 @@ struct timespec timespec_sub(struct timespec lhs, struct timespec rhs)
 	return result;
 }
 
-// monitor the p7 endpoints and the timing loop and 
+// monitor the p7 endpoints and the timing loop and
 // send indications to mac
 int nfapi_nr_vnf_p7_start(nfapi_vnf_p7_config_t* config)
 {	
@@ -107,9 +107,9 @@ int nfapi_nr_vnf_p7_start(nfapi_vnf_p7_config_t* config)
 
 	vnf_p7_t* vnf_p7 = (vnf_p7_t*)config;
 
-	// Create p7 receive udp port 
+	// Create p7 receive udp port
 	// todo : this needs updating for Ipv6
-	
+
 	NFAPI_TRACE(NFAPI_TRACE_INFO, "Initialising VNF P7 port:%u\n", config->port);
 
 	// open the UDP socket
@@ -128,7 +128,7 @@ int nfapi_nr_vnf_p7_start(nfapi_vnf_p7_config_t* config)
 		NFAPI_TRACE(NFAPI_TRACE_ERROR, "After setsockopt (IP_TOS) errno: %d\n", errno);
 		return -1;
 	}
-	
+
 	NFAPI_TRACE(NFAPI_TRACE_INFO, "VNF P7 setsockopt succeeded...\n");
 
 	// Create the address structure
@@ -168,20 +168,34 @@ int nfapi_nr_vnf_p7_start(nfapi_vnf_p7_config_t* config)
 		// Add the p7 socket
 		FD_SET(vnf_p7->socket, &rfds);
 		maxSock = vnf_p7->socket;
-		
+
 		struct timespec curr_time;
 		clock_gettime(CLOCK_MONOTONIC, &curr_time);
 		setup_time = curr_time.tv_sec - ref_time.tv_sec;
 
-		if(setup_time > 10 && prev_slot != gNB->UL_INFO.slot){ //Give the VNF sufficient time to setup before starting scheduling
-
-			//Call the scheduler
+		nfapi_nr_slot_indication_scf_t *slot_ind = get_queue(&gnb_slot_ind_queue);
+		NFAPI_TRACE(NFAPI_TRACE_DEBUG, "This is the slot_ind queue size %ld in %s():%d\n",
+			    gnb_slot_ind_queue.num_items, __FUNCTION__, __LINE__);
+		if (slot_ind) {
 			pthread_mutex_lock(&gNB->UL_INFO_mutex);
-			gNB->UL_INFO.module_id = gNB->Mod_id;
-			gNB->UL_INFO.CC_id     = gNB->CC_id;
-			gNB->if_inst->NR_UL_indication(&gNB->UL_INFO);
+			gNB->UL_INFO.frame     = slot_ind->sfn;
+			gNB->UL_INFO.slot      = slot_ind->slot;
+
+			NFAPI_TRACE(NFAPI_TRACE_DEBUG, "gNB->UL_INFO.frame = %d and slot %d, prev_slot = %d, setup_time = %d\n",
+				    gNB->UL_INFO.frame, gNB->UL_INFO.slot, prev_slot, setup_time);
+			if (setup_time > 3 && prev_slot != gNB->UL_INFO.slot) { //Give the VNF sufficient time to setup before starting scheduling  && prev_slot != gNB->UL_INFO.slot
+
+				//Call the scheduler
+				gNB->UL_INFO.module_id = gNB->Mod_id;
+				gNB->UL_INFO.CC_id     = gNB->CC_id;
+				NFAPI_TRACE(NFAPI_TRACE_DEBUG, "Calling NR_UL_indication for gNB->UL_INFO.frame = %d and slot %d\n",
+					    gNB->UL_INFO.frame, gNB->UL_INFO.slot);
+				gNB->if_inst->NR_UL_indication(&gNB->UL_INFO);
+				prev_slot = gNB->UL_INFO.slot;
+			}
 			pthread_mutex_unlock(&gNB->UL_INFO_mutex);
-			prev_slot = gNB->UL_INFO.slot;
+			free(slot_ind);
+			slot_ind = NULL;
 		}
 
 		selectRetval = pselect(maxSock+1, &rfds, NULL, NULL, &pselect_timeout, NULL);
@@ -234,9 +248,9 @@ int nfapi_vnf_p7_start(nfapi_vnf_p7_config_t* config)
 
 	vnf_p7_t* vnf_p7 = (vnf_p7_t*)config;
 
-	// Create p7 receive udp port 
+	// Create p7 receive udp port
 	// todo : this needs updating for Ipv6
-	
+
 	NFAPI_TRACE(NFAPI_TRACE_INFO, "Initialising VNF P7 port:%u\n", config->port);
 
 	// open the UDP socket
@@ -255,7 +269,7 @@ int nfapi_vnf_p7_start(nfapi_vnf_p7_config_t* config)
 		NFAPI_TRACE(NFAPI_TRACE_ERROR, "After setsockopt (IP_TOS) errno: %d\n", errno);
 		return -1;
 	}
-	
+
 	NFAPI_TRACE(NFAPI_TRACE_INFO, "VNF P7 setsockopt succeeded...\n");
 
 	// Create the address structure
@@ -299,7 +313,7 @@ int nfapi_vnf_p7_start(nfapi_vnf_p7_config_t* config)
 	clock_gettime(CLOCK_MONOTONIC, &sf_start);
 	long millisecond = sf_start.tv_nsec / 1e6;
 	sf_start = timespec_add(sf_start, sf_duration);
-	NFAPI_TRACE(NFAPI_TRACE_INFO, "next subframe will start at %d.%d\n", sf_start.tv_sec, sf_start.tv_nsec);
+	NFAPI_TRACE(NFAPI_TRACE_INFO, "next subframe will start at %ld.%ld\n", sf_start.tv_sec, sf_start.tv_nsec);
 
 	while(vnf_p7->terminate == 0)
 	{
@@ -311,7 +325,7 @@ int nfapi_vnf_p7_start(nfapi_vnf_p7_config_t* config)
 		// Add the p7 socket
 		FD_SET(vnf_p7->socket, &rfds);
 		maxSock = vnf_p7->socket;
-		
+
 		clock_gettime(CLOCK_MONOTONIC, &pselect_start);
 		//long millisecond = pselect_start.tv_nsec / 1e6;
 
@@ -320,7 +334,7 @@ int nfapi_vnf_p7_start(nfapi_vnf_p7_config_t* config)
                   //NFAPI_TRACE(NFAPI_TRACE_INFO, "pselect_start:%d.%d sf_start:%d.%d\n", pselect_start.tv_sec, pselect_start.tv_nsec, sf_start.tv_sec, sf_start.tv_nsec);
 
 
-			if((pselect_start.tv_sec > sf_start.tv_sec) || 
+			if((pselect_start.tv_sec > sf_start.tv_sec) ||
 			   ((pselect_start.tv_sec == sf_start.tv_sec) && (pselect_start.tv_nsec > sf_start.tv_nsec)))
 			{
 				// overran the end of the subframe we do not want to wait
@@ -343,7 +357,7 @@ int nfapi_vnf_p7_start(nfapi_vnf_p7_config_t* config)
 			//pselect_timeout.tv_nsec = 1e6 - (pselect_start.tv_nsec % 1000000);
 
 			//uint8_t underrun_possible =0;
-			
+
 			// if we are not sleeping until the next milisecond due to the
 			// insycn minor adjment flag it so we don't consider it an error
 			//uint8_t underrun_possible =0;
@@ -353,7 +367,7 @@ int nfapi_vnf_p7_start(nfapi_vnf_p7_config_t* config)
 				if(phy && phy->in_sync && phy->insync_minor_adjustment != 0 && phy->insync_minor_adjustment_duration > 0 && pselect_start.tv_nsec != 0)
 				{
 					NFAPI_TRACE(NFAPI_TRACE_NOTE, "[VNF] Subframe minor adjustment %d (%d->%d)\n", phy->insync_minor_adjustment,
-							pselect_timeout.tv_nsec, pselect_timeout.tv_nsec - (phy->insync_minor_adjustment * 1000)) 
+							pselect_timeout.tv_nsec, pselect_timeout.tv_nsec - (phy->insync_minor_adjustment * 1000))
 					if(phy->insync_minor_adjustment > 0)
 					{
 						// todo check we don't go below 0
@@ -376,7 +390,7 @@ int nfapi_vnf_p7_start(nfapi_vnf_p7_config_t* config)
 				}
 			}
 			*/
-			
+
 
 //long wraps = pselect_timeout.tv_nsec % 1e9;
 
@@ -389,9 +403,9 @@ int nfapi_vnf_p7_start(nfapi_vnf_p7_config_t* config)
 
 if (selectRetval==-1 && errno == 22)
 {
-  NFAPI_TRACE(NFAPI_TRACE_ERROR, "INVAL: pselect_timeout:%d.%ld adj[dur:%d adj:%d], sf_dur:%d.%ld\n", 
-  pselect_timeout.tv_sec, pselect_timeout.tv_nsec, 
-  phy->insync_minor_adjustment_duration, phy->insync_minor_adjustment, 
+  NFAPI_TRACE(NFAPI_TRACE_ERROR, "INVAL: pselect_timeout:%ld.%ld adj[dur:%d adj:%d], sf_dur:%ld.%ld\n",
+  pselect_timeout.tv_sec, pselect_timeout.tv_nsec,
+  phy->insync_minor_adjustment_duration, phy->insync_minor_adjustment,
   sf_duration.tv_sec, sf_duration.tv_nsec);
 }
 			if(selectRetval == 0)
@@ -449,7 +463,7 @@ if (selectRetval==-1 && errno == 22)
 					//phy->insync_minor_adjustment = 0;
                                         phy->insync_minor_adjustment_duration--;
 
-                                        NFAPI_TRACE(NFAPI_TRACE_NOTE, "[VNF] AFTER adjustment - Subframe minor adjustment %dus sf_start.tv_nsec:%d duration:%u\n", 
+                                        NFAPI_TRACE(NFAPI_TRACE_NOTE, "[VNF] AFTER adjustment - Subframe minor adjustment %dus sf_start.tv_nsec:%ld duration:%u\n",
                                             phy->insync_minor_adjustment, sf_start.tv_nsec, phy->insync_minor_adjustment_duration);
 
                                         if (phy->insync_minor_adjustment_duration==0)
@@ -473,7 +487,7 @@ if (selectRetval==-1 && errno == 22)
 				}
 				last_millisecond = millisecond;
 				*/
-				
+
 				millisecond ++;
 			}
 		}
@@ -497,9 +511,7 @@ if (selectRetval==-1 && errno == 22)
 			while(curr != 0)
 			{
 				curr->sfn_sf = increment_sfn_sf(curr->sfn_sf);
-				
 				vnf_sync(vnf_p7, curr);
-
 				curr = curr->next;
 			}
 
@@ -523,7 +535,7 @@ if (selectRetval==-1 && errno == 22)
 			}
 			else
 			{
-				NFAPI_TRACE(NFAPI_TRACE_INFO, "P7 select failed result %d errno %d timeout:%d.%d orginal:%d.%d last_ms:%ld ms:%ld\n", selectRetval, errno, pselect_timeout.tv_sec, pselect_timeout.tv_nsec, pselect_timeout.tv_sec, pselect_timeout.tv_nsec, last_millisecond, millisecond);
+				NFAPI_TRACE(NFAPI_TRACE_INFO, "P7 select failed result %d errno %d timeout:%ld.%ld orginal:%ld.%ld last_ms:%ld ms:%ld\n", selectRetval, errno, pselect_timeout.tv_sec, pselect_timeout.tv_nsec, pselect_timeout.tv_sec, pselect_timeout.tv_nsec, last_millisecond, millisecond);
 				// should we exit now?
                                 if (selectRetval == -1 && errno == 22) // invalid argument??? not sure about timeout duration
                                 {
@@ -534,7 +546,7 @@ if (selectRetval==-1 && errno == 22)
 
 	}
 
-	
+
 	NFAPI_TRACE(NFAPI_TRACE_INFO, "Closing p7 socket\n");
 	close(vnf_p7->socket);
 
diff --git a/openair1/PHY/INIT/lte_init.c b/openair1/PHY/INIT/lte_init.c
index 1daeb72187b81454ecc2ed359b234b86ec4dec69..308a059d51417cc760318d98da2419e25ffb99b8 100644
--- a/openair1/PHY/INIT/lte_init.c
+++ b/openair1/PHY/INIT/lte_init.c
@@ -106,7 +106,7 @@ void phy_config_request(PHY_Config_t *phy_config) {
   int                 Ncp            = cfg->subframe_config.dl_cyclic_prefix_type.value;
   int                 p_eNB          = cfg->rf_config.tx_antenna_ports.value;
   uint32_t            dl_CarrierFreq = cfg->nfapi_config.earfcn.value;
-  LOG_I(PHY,"Configuring MIB for instance %d, CCid %d : (band %d,N_RB_DL %d, N_RB_UL %d, Nid_cell %d,eNB_tx_antenna_ports %d,Ncp %d,DL freq %u,phich_config.resource %d, phich_config.duration %d)\n",
+  LOG_A(PHY,"Configuring MIB for instance %d, CCid %d : (band %d,N_RB_DL %d, N_RB_UL %d, Nid_cell %d,eNB_tx_antenna_ports %d,Ncp %d,DL freq %u,phich_config.resource %d, phich_config.duration %d)\n",
         Mod_id, CC_id, eutra_band, dl_Bandwidth, ul_Bandwidth, Nid_cell, p_eNB,Ncp,dl_CarrierFreq,
         cfg->phich_config.phich_resource.value,
         cfg->phich_config.phich_duration.value);
diff --git a/openair1/PHY/INIT/lte_init_ue.c b/openair1/PHY/INIT/lte_init_ue.c
index b75673581687731b5d51bd9eac0c9fd0d4802fde..c3f09fa78c3c6925af5891992e8f52aff2090ad7 100644
--- a/openair1/PHY/INIT/lte_init_ue.c
+++ b/openair1/PHY/INIT/lte_init_ue.c
@@ -548,7 +548,7 @@ void phy_config_dedicated_ue(module_id_t Mod_id,int CC_id,uint8_t eNB_id,
     phy_vars_ue->decode_MIB = 0;
   }
 
-  if(NFAPI_MODE!=NFAPI_UE_STUB_PNF) {
+  if(NFAPI_MODE!=NFAPI_UE_STUB_PNF && NFAPI_MODE!=NFAPI_MODE_STANDALONE_PNF) {
     //phy_vars_ue->pdcch_vars[1][eNB_id]->crnti = phy_vars_ue->pdcch_vars[0][eNB_id]->crnti;
     if(phy_vars_ue->pdcch_vars[0][eNB_id]->crnti == 0x1234)
       phy_vars_ue->pdcch_vars[0][eNB_id]->crnti = phy_vars_ue->pdcch_vars[1][eNB_id]->crnti;
diff --git a/openair1/PHY/INIT/nr_init.c b/openair1/PHY/INIT/nr_init.c
index cd4848ea8ce22cd530b11f70ca57eec9a9ad441a..9e1e472fd69bcc8bf9352c0053a43d8724c5ff64 100644
--- a/openair1/PHY/INIT/nr_init.c
+++ b/openair1/PHY/INIT/nr_init.c
@@ -487,7 +487,7 @@ void nr_phy_config_request(NR_PHY_Config_t *phy_config) {
   LOG_I(PHY, "DL frequency %lu Hz, UL frequency %lu Hz: band %d, uldl offset %d Hz\n", fp->dl_CarrierFreq, fp->ul_CarrierFreq, fp->nr_band, dlul_offset);
 
   fp->threequarter_fs = openair0_cfg[0].threequarter_fs;
-  LOG_I(PHY,"Configuring MIB for instance %d, : (Nid_cell %d,DL freq %llu, UL freq %llu)\n",
+  LOG_A(PHY,"Configuring MIB for instance %d, : (Nid_cell %d,DL freq %llu, UL freq %llu)\n",
         Mod_id,
         gNB_config->cell_config.phy_cell_id.value,
         (unsigned long long)fp->dl_CarrierFreq,
diff --git a/openair1/PHY/LTE_TRANSPORT/dlsch_modulation.c b/openair1/PHY/LTE_TRANSPORT/dlsch_modulation.c
index aba4a464f2bcbbfbef7b008b4801216891674ea0..c6b312cc61a1ffd34e38e6573b9aeae8f16a6825 100644
--- a/openair1/PHY/LTE_TRANSPORT/dlsch_modulation.c
+++ b/openair1/PHY/LTE_TRANSPORT/dlsch_modulation.c
@@ -2921,6 +2921,9 @@ int allocate_REs_in_RB_MCH_khz_1dot25(int32_t **txdataF,
                             uint8_t skip_dc,
                             LTE_DL_FRAME_PARMS *frame_parms)
 {
+  if (!qam_table_s)
+    abort();
+
  uint32_t tti_offset;
   uint8_t re,offset;
   uint8_t qam64_table_offset_re = 0;
diff --git a/openair1/PHY/LTE_UE_TRANSPORT/dlsch_demodulation.c b/openair1/PHY/LTE_UE_TRANSPORT/dlsch_demodulation.c
index 6afd0280991a6911f46d04f5be5169627ec1b0cf..a7054a44d2474df6d6d36297853fc8f0ffb3a9ea 100644
--- a/openair1/PHY/LTE_UE_TRANSPORT/dlsch_demodulation.c
+++ b/openair1/PHY/LTE_UE_TRANSPORT/dlsch_demodulation.c
@@ -370,7 +370,7 @@ int rx_pdsch(PHY_VARS_UE *ue,
 
 #if UE_TIMING_TRACE
   stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
-  LOG_I(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d Flag %d type %d: Pilot/Data extraction  %5.2f \n",frame,subframe,slot,symbol,
+  LOG_D(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
 #if UE_TIMING_TRACE
@@ -398,7 +398,7 @@ int rx_pdsch(PHY_VARS_UE *ue,
 
 #if UE_TIMING_TRACE
   stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
-  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_D(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));
   start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
 #endif
 
@@ -507,7 +507,7 @@ int rx_pdsch(PHY_VARS_UE *ue,
 #endif
 #if UE_TIMING_TRACE
   stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
-  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,
+  LOG_D(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));
   start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
 #endif
@@ -731,7 +731,7 @@ int rx_pdsch(PHY_VARS_UE *ue,
 
 #if UE_TIMING_TRACE
   stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
-  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,
+  LOG_D(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));
   start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
 #endif
@@ -805,7 +805,7 @@ int rx_pdsch(PHY_VARS_UE *ue,
 
 #if UE_TIMING_TRACE
   stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
-  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_D(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));
   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);
diff --git a/openair1/PHY/NR_REFSIG/ptrs_nr.c b/openair1/PHY/NR_REFSIG/ptrs_nr.c
index b50c9a7bc9e33494e8a7881c4f58573de6c64112..d3d4bf0fafb34161be0820676da186047a06dc43 100644
--- a/openair1/PHY/NR_REFSIG/ptrs_nr.c
+++ b/openair1/PHY/NR_REFSIG/ptrs_nr.c
@@ -105,14 +105,19 @@ void set_ptrs_symb_idx(uint16_t *ptrs_symbols,
                        uint8_t L_ptrs,
                        uint16_t ul_dmrs_symb_pos) {
 
-  uint8_t i = 0, last_symbol, is_dmrs_symbol, l_ref;
-  int8_t l_counter;
+  uint i = 0, last_symbol, l_ref;
+  int l_counter;
   l_ref         = start_symbol;
   last_symbol   = start_symbol + duration_in_symbols - 1;
+  if (L_ptrs==0) {
+    LOG_E(PHY,"bug: impossible L_ptrs\n");
+    *ptrs_symbols = 0;
+    return;
+  }
 
   while ( (l_ref + i*L_ptrs) <= last_symbol) {
 
-    is_dmrs_symbol = 0;
+    int is_dmrs_symbol = 0;
 
     for(l_counter = l_ref + i*L_ptrs; l_counter >= max(l_ref + (i-1)*L_ptrs + 1, l_ref); l_counter--) {
 
@@ -259,9 +264,13 @@ void nr_ptrs_cpe_estimation(uint8_t K_ptrs,
   uint16_t              re_cnt           = 0;
   uint16_t              cnt              = 0;
   unsigned short        nb_re_pdsch      = NR_NB_SC_PER_RB * nb_rb;
+  if (K_ptrs==0) {
+    LOG_E(PHY,"K_ptrs == 0\n");
+    return;
+  }
   uint16_t              sc_per_symbol    = (nb_rb + K_ptrs - 1)/K_ptrs;
-  int16_t              *ptrs_p           = (int16_t *)malloc(sizeof(int32_t)*(sc_per_symbol));
-  int16_t              *dmrs_comp_p      = (int16_t *)malloc(sizeof(int32_t)*(sc_per_symbol));
+  int16_t              *ptrs_p           = (int16_t *)malloc(sizeof(int32_t)*((1 + sc_per_symbol/4)*4));
+  int16_t              *dmrs_comp_p      = (int16_t *)malloc(sizeof(int32_t)*((1 + sc_per_symbol/4)*4));
   double                abs              = 0.0;
   double                real             = 0.0;
   double                imag             = 0.0;
diff --git a/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c b/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c
index 5620018b73fce464d7a728efab61c917c886943a..afd1fc6e0da14dcb0aeba83edbff8963fe5fc381 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c
@@ -213,7 +213,7 @@ void ldpc8blocks( void *p) {
   for (int rr=impp->macro_num*8; rr < impp->n_segments && rr < (impp->macro_num+1)*8; rr++ ) {
     if (impp->F>0) {
       // writing into positions d[r][k-2Zc] as in clause 5.3.2 step 2) in 38.212
-      memset(&impp->d[rr][Kr-impp->F-2*(*impp->Zc)], impp->F, NR_NULL);
+      memset(&impp->d[rr][Kr-impp->F-2*(*impp->Zc)], NR_NULL, impp->F);
     }
 
 #ifdef DEBUG_DLSCH_CODING
diff --git a/openair1/PHY/NR_TRANSPORT/nr_dlsch_tools.c b/openair1/PHY/NR_TRANSPORT/nr_dlsch_tools.c
index 26b45eb9f7d973336b142d4bca5f2320ae0bc95c..2dc21af0c503d47908422105273d33859dd3e934 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_dlsch_tools.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_dlsch_tools.c
@@ -32,6 +32,7 @@
 */
 
 #include "nr_dlsch.h"
+#include "../../../nfapi/oai_integration/vendor_ext.h"
 
 extern void set_taus_seed(unsigned int seed_type);
 
diff --git a/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c b/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c
index 8bbf569814795d36cb6ad4d94134264126ad6a4a..5286fe878061b72a04e059ef4ed060e2eacd754e 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c
@@ -111,7 +111,7 @@ NR_gNB_ULSCH_t *new_gNB_ulsch(uint8_t max_ldpc_iterations,uint16_t N_RB_UL, uint
 {
 
   NR_gNB_ULSCH_t *ulsch;
-  uint8_t exit_flag = 0,i,r;
+  uint8_t i,r;
   uint16_t a_segments = MAX_NUM_NR_ULSCH_SEGMENTS;  //number of segments to be allocated
 
   if (N_RB_UL != 273) {
@@ -120,68 +120,26 @@ NR_gNB_ULSCH_t *new_gNB_ulsch(uint8_t max_ldpc_iterations,uint16_t N_RB_UL, uint
   }
 
   uint16_t ulsch_bytes = a_segments*1056;  // allocated bytes per segment
-  ulsch = (NR_gNB_ULSCH_t *)malloc16(sizeof(NR_gNB_ULSCH_t));
-
-  if (ulsch) {
-
-    memset(ulsch,0,sizeof(NR_gNB_ULSCH_t));
-
-    ulsch->max_ldpc_iterations = max_ldpc_iterations;
-    ulsch->Mlimit = 4;
-
-    for (i=0; i<NR_MAX_ULSCH_HARQ_PROCESSES; i++) {
-
-      ulsch->harq_processes[i] = (NR_UL_gNB_HARQ_t *)malloc16(sizeof(NR_UL_gNB_HARQ_t));
-
-      if (ulsch->harq_processes[i]) {
-
-        memset(ulsch->harq_processes[i],0,sizeof(NR_UL_gNB_HARQ_t));
-
-        ulsch->harq_processes[i]->b = (uint8_t*)malloc16(ulsch_bytes);
-
-        if (ulsch->harq_processes[i]->b)
-          memset(ulsch->harq_processes[i]->b,0,ulsch_bytes);
-        else
-          exit_flag=3;
-
-        if (abstraction_flag == 0) {
-          for (r=0; r<a_segments; r++) {
-
-            ulsch->harq_processes[i]->p_nrLDPC_procBuf[r] = nrLDPC_init_mem();
-
-            ulsch->harq_processes[i]->c[r] = (uint8_t*)malloc16(8448*sizeof(uint8_t));
-
-            if (ulsch->harq_processes[i]->c[r])
-              memset(ulsch->harq_processes[i]->c[r],0,8448*sizeof(uint8_t));
-            else
-              exit_flag=2;
-
-            ulsch->harq_processes[i]->d[r] = (int16_t*)malloc16((68*384)*sizeof(int16_t));
-
-            if (ulsch->harq_processes[i]->d[r])
-              memset(ulsch->harq_processes[i]->d[r],0,(68*384)*sizeof(int16_t));
-            else
-              exit_flag=2;
-
-            ulsch->harq_processes[i]->w[r] = (int16_t*)malloc16((3*(6144+64))*sizeof(int16_t));
-
-            if (ulsch->harq_processes[i]->w[r])
-              memset(ulsch->harq_processes[i]->w[r],0,(3*(6144+64))*sizeof(int16_t));
-            else
-              exit_flag=2;
-          }
-        }
-      } else {
-        exit_flag=1;
+  ulsch = (NR_gNB_ULSCH_t *)malloc16_clear(sizeof(NR_gNB_ULSCH_t));
+  
+  ulsch->max_ldpc_iterations = max_ldpc_iterations;
+  ulsch->Mlimit = 4;
+  
+  for (i=0; i<NR_MAX_ULSCH_HARQ_PROCESSES; i++) {
+    
+    ulsch->harq_processes[i] = (NR_UL_gNB_HARQ_t *)malloc16_clear(sizeof(NR_UL_gNB_HARQ_t));
+    ulsch->harq_processes[i]->b = (uint8_t*)malloc16_clear(ulsch_bytes);
+    if (abstraction_flag == 0) {
+      for (r=0; r<a_segments; r++) {
+	ulsch->harq_processes[i]->p_nrLDPC_procBuf[r] = nrLDPC_init_mem();
+	ulsch->harq_processes[i]->c[r] = (uint8_t*)malloc16_clear(8448*sizeof(uint8_t));
+	ulsch->harq_processes[i]->d[r] = (int16_t*)malloc16_clear((68*384)*sizeof(int16_t));
+	ulsch->harq_processes[i]->w[r] = (int16_t*)malloc16_clear((3*(6144+64))*sizeof(int16_t));
       }
     }
-
-    if (exit_flag==0)
-      return(ulsch);
   }
-  printf("new_gNB_ulsch with size %zu: exit_flag = %hhu\n",sizeof(NR_UL_gNB_HARQ_t), exit_flag);
-  free_gNB_ulsch(&ulsch,N_RB_UL);
-  return(NULL);
+  
+  return(ulsch);
 }
 
 void clean_gNB_ulsch(NR_gNB_ULSCH_t *ulsch)
diff --git a/openair1/PHY/NR_TRANSPORT/pucch_rx.c b/openair1/PHY/NR_TRANSPORT/pucch_rx.c
index b81e655817b35d0f8b017e7f1e24e8525c40a314..8844a530afe2dbba066d7f02a8d3b2c16a421a20 100644
--- a/openair1/PHY/NR_TRANSPORT/pucch_rx.c
+++ b/openair1/PHY/NR_TRANSPORT/pucch_rx.c
@@ -47,6 +47,7 @@
 #include "PHY/NR_REFSIG/nr_refsig.h"
 #include "common/utils/LOG/log.h"
 #include "common/utils/LOG/vcd_signal_dumper.h"
+#include "nfapi/oai_integration/vendor_ext.h"
 
 #include "nfapi/oai_integration/vendor_ext.h"
 
@@ -88,7 +89,8 @@ void nr_fill_pucch(PHY_VARS_gNB *gNB,
                    int frame,
                    int slot,
                    nfapi_nr_pucch_pdu_t *pucch_pdu) {
-
+  if (NFAPI_MODE == NFAPI_MODE_PNF)
+    gNB->pucch[0]->active = 0; //check if ture in monolithic mode 
   int id = nr_find_pucch(pucch_pdu->rnti,frame,slot,gNB);
   AssertFatal( (id>=0) && (id<NUMBER_OF_NR_PUCCH_MAX),
               "invalid id found for pucch !!! rnti %04x id %d\n",pucch_pdu->rnti,id);
diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c b/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c
index 86c9974f68377a7a4f80d10297672ad90235aca3..dff347f7c04fb0cc8a6bff4e1a9e994551d817a6 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c
@@ -601,11 +601,11 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue,
 #endif
 
   nr_downlink_indication_t dl_indication;
-  fapi_nr_rx_indication_t rx_ind;
+  fapi_nr_rx_indication_t *rx_ind = calloc(1, sizeof(*rx_ind));
   uint16_t number_pdus = 1;
 
-  nr_fill_dl_indication(&dl_indication, NULL, &rx_ind, proc, ue, gNB_id);
-  nr_fill_rx_indication(&rx_ind, FAPI_NR_RX_PDU_TYPE_SSB, gNB_id, ue, NULL, NULL, number_pdus);
+  nr_fill_dl_indication(&dl_indication, NULL, rx_ind, proc, ue, gNB_id);
+  nr_fill_rx_indication(rx_ind, FAPI_NR_RX_PDU_TYPE_SSB, gNB_id, ue, NULL, NULL, number_pdus, proc);
 
   if (ue->if_inst && ue->if_inst->dl_indication)
     ue->if_inst->dl_indication(&dl_indication, NULL);
diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c
index 945dc516737c8bebc221e151fe89e69f3274291a..b2e247667074a8a965cb53b5e9f70db15a684c03 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c
@@ -258,7 +258,6 @@ int nr_ulsch_encoding(PHY_VARS_NR_UE *ue,
   Ilbrm = 0;
   Tbslbrm = 950984; //max tbs
   Coderate = 0.0;
-  trace_NRpdu(DIRECTION_UPLINK, harq_process->a, harq_process->pusch_pdu.pusch_data.tb_size, 0, WS_C_RNTI, 0, 0, 0,0, 0);
 ///////////
 /////////////////////////////////////////////////////////////////////////////////////////  
 
diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
index 914523bc705539aab2f76198a94e3863948e0660..73615ffb6e74c194be2c86ead7d1b183f7b34261 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
@@ -45,6 +45,7 @@
 #include "executables/nr-softmodem.h"
 #include "executables/softmodem-common.h"
 #include "PHY/NR_REFSIG/ul_ref_seq_nr.h"
+#include <openair2/UTIL/OPT/opt.h>
 
 //#define DEBUG_PUSCH_MAPPING
 //#define DEBUG_MAC_PDU
@@ -163,9 +164,15 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE,
                               nb_dmrs_re_per_rb, number_dmrs_symbols, mod_order, Nl);
     
 
+    trace_NRpdu(DIRECTION_UPLINK,
+		ulsch_ue->harq_processes[harq_pid]->a,
+		ulsch_ue->harq_processes[harq_pid]->pusch_pdu.pusch_data.tb_size,
+		0, WS_C_RNTI, rnti, frame, slot, 0, 0);
+
     if (nr_ulsch_encoding(UE, ulsch_ue, frame_parms, harq_pid, G) == -1)
       return;
 
+
     ///////////
     ////////////////////////////////////////////////////////////////////
 
diff --git a/openair1/PHY/TOOLS/nr_phy_scope.c b/openair1/PHY/TOOLS/nr_phy_scope.c
index 303ec5121d1a5906fd25337f5755ad69a4053f37..44adf02f576f16d39e906238676abda1df701184 100644
--- a/openair1/PHY/TOOLS/nr_phy_scope.c
+++ b/openair1/PHY/TOOLS/nr_phy_scope.c
@@ -240,7 +240,7 @@ static void genericWaterFall (OAIgraph_t *graph, scopeSample_t *values, const in
   for (int pix=0; pix<graph->w; pix++) {
     scopeSample_t *end=values+(pix+1)*samplesPerPixel;
     end-=2;
-    AssertFatal(end <= values+datasize,"diff : %ld", end-values+datasize);
+    AssertFatal(end <= values+datasize,"diff : %tu", end-values+datasize);
     double val=0;
 
     for (scopeSample_t *s=values+(pix)*samplesPerPixel;
diff --git a/openair1/PHY/phy_vars.h b/openair1/PHY/phy_vars.h
index 58797848271b735bec713c2b62b4494eb1b63407..9fd186ec4f9d7ab2a25f7725b735d3150631bbb8 100644
--- a/openair1/PHY/phy_vars.h
+++ b/openair1/PHY/phy_vars.h
@@ -24,6 +24,7 @@
 
 #include "PHY/types.h"
 #include "PHY/defs_eNB.h"
+#include "PHY/defs_gNB.h"
 #include "PHY/defs_UE.h"
 
 char* namepointer_chMag ;
@@ -42,6 +43,7 @@ char* namepointer_log2;
 
 PHY_VARS_UE ***PHY_vars_UE_g;
 UL_RCC_IND_t UL_RCC_INFO;
+NR_UL_IND_t UL_INFO;
 
 unsigned short rev[2048],rev_times4[8192],rev_half[1024];
 unsigned short rev256[256],rev512[512],rev1024[1024],rev4096[4096],rev2048[2048],rev8192[8192];
@@ -81,7 +83,7 @@ const double sinr_to_cqi[4][16]= { {-2.5051, -2.5051, -1.7451, -0.3655, 1.0812,
 };
 
 //int cqi_to_mcs[16]={0, 0, 1, 3, 5, 7, 9, 13, 15, 16, 20, 23, 25, 27, 27, 27};
-const int cqi_to_mcs[16]= {0, 0, 1, 2, 4, 6, 8, 11, 13, 16, 18, 20, 23, 25, 27, 28};
+const int cqi_to_mcs[16]= {0, 0, 1, 2, 4, 6, 8, 11, 13, 16, 18, 20, 23, 25, 27, 27};
 
 //for SNR to MI conversion 7 th order Polynomial coeff
 const double q_qam16[8]= {3.21151853033897e-10,5.55435952230651e-09,-2.30760065362117e-07,-6.25587743817859e-06,4.62251036452795e-06,0.00224150813158937,0.0393723140344367,0.245486379182639};
diff --git a/openair1/PHY/phy_vars_nr_ue.h b/openair1/PHY/phy_vars_nr_ue.h
index cfdfbeb49d009b9fd4c1f70c642b5e70e9cf367a..303853add22a5012bc2b7ff157429a522e0be91b 100644
--- a/openair1/PHY/phy_vars_nr_ue.h
+++ b/openair1/PHY/phy_vars_nr_ue.h
@@ -84,7 +84,7 @@ const double sinr_to_cqi[4][16]= { {-2.5051, -2.5051, -1.7451, -0.3655, 1.0812,
 };
 
 //int cqi_to_mcs[16]={0, 0, 1, 3, 5, 7, 9, 13, 15, 16, 20, 23, 25, 27, 27, 27};
-const int cqi_to_mcs[16]= {0, 0, 1, 2, 4, 6, 8, 11, 13, 16, 18, 20, 23, 25, 27, 28};
+const int cqi_to_mcs[16]= {0, 0, 1, 2, 4, 6, 8, 11, 13, 16, 18, 20, 23, 25, 27, 27};
 
 //for SNR to MI conversion 7 th order Polynomial coeff
 const double q_qam16[8]= {3.21151853033897e-10,5.55435952230651e-09,-2.30760065362117e-07,-6.25587743817859e-06,4.62251036452795e-06,0.00224150813158937,0.0393723140344367,0.245486379182639};
diff --git a/openair1/PHY/phy_vars_ue.h b/openair1/PHY/phy_vars_ue.h
index ca35ab6629c765e33af7d22616a54cd67a308340..2c1334b80b19e679d6312894b10a7addfde95890 100644
--- a/openair1/PHY/phy_vars_ue.h
+++ b/openair1/PHY/phy_vars_ue.h
@@ -73,7 +73,7 @@ const double sinr_to_cqi[4][16]= { {-2.5051, -2.5051, -1.7451, -0.3655, 1.0812,
 };
 
 //int cqi_to_mcs[16]={0, 0, 1, 3, 5, 7, 9, 13, 15, 16, 20, 23, 25, 27, 27, 27};
-const int cqi_to_mcs[16]= {0, 0, 1, 2, 4, 6, 8, 11, 13, 16, 18, 20, 23, 25, 27, 28};
+const int cqi_to_mcs[16]= {0, 0, 1, 2, 4, 6, 8, 11, 13, 16, 18, 20, 23, 25, 27, 27};
 
 //for SNR to MI conversion 7 th order Polynomial coeff
 const double q_qam16[8]= {3.21151853033897e-10,5.55435952230651e-09,-2.30760065362117e-07,-6.25587743817859e-06,4.62251036452795e-06,0.00224150813158937,0.0393723140344367,0.245486379182639};
diff --git a/openair1/SCHED/phy_procedures_lte_eNb.c b/openair1/SCHED/phy_procedures_lte_eNb.c
index 973c921d2347d7c14f276af87255c83a067b5988..569d2a464a10397b72744f025d4a198375312c40 100644
--- a/openair1/SCHED/phy_procedures_lte_eNb.c
+++ b/openair1/SCHED/phy_procedures_lte_eNb.c
@@ -755,6 +755,7 @@ void fill_sr_indication(int UEid, PHY_VARS_eNB *eNB,uint16_t rnti,int frame,int
   pthread_mutex_lock(&eNB->UL_INFO_mutex);
   nfapi_sr_indication_t       *sr_ind =         &eNB->UL_INFO.sr_ind;
   nfapi_sr_indication_body_t  *sr_ind_body =    &sr_ind->sr_indication_body;
+  assert(sr_ind_body->number_of_srs <= NFAPI_SR_IND_MAX_PDU);
   nfapi_sr_indication_pdu_t *pdu =   &sr_ind_body->sr_pdu_list[sr_ind_body->number_of_srs];
   sr_ind->sfn_sf = frame<<4|subframe;
   sr_ind->header.message_id = NFAPI_RX_SR_INDICATION;
@@ -1580,6 +1581,7 @@ void fill_rx_indication(PHY_VARS_eNB *eNB,
   pthread_mutex_lock(&eNB->UL_INFO_mutex);
   eNB->UL_INFO.rx_ind.sfn_sf                    = frame<<4| subframe;
   eNB->UL_INFO.rx_ind.rx_indication_body.tl.tag = NFAPI_RX_INDICATION_BODY_TAG;
+  assert(eNB->UL_INFO.rx_ind.rx_indication_body.number_of_pdus <= NFAPI_RX_IND_MAX_PDU);
   pdu                                    = &eNB->UL_INFO.rx_ind.rx_indication_body.rx_pdu_list[eNB->UL_INFO.rx_ind.rx_indication_body.number_of_pdus];
   //  pdu->rx_ue_information.handle          = eNB->ulsch[ULSCH_id]->handle;
   pdu->rx_ue_information.tl.tag          = NFAPI_RX_UE_INFORMATION_TAG;
@@ -1587,7 +1589,11 @@ void fill_rx_indication(PHY_VARS_eNB *eNB,
   pdu->rx_indication_rel8.tl.tag         = NFAPI_RX_INDICATION_REL8_TAG;
   pdu->rx_indication_rel8.length         = eNB->ulsch[ULSCH_id]->harq_processes[harq_pid]->TBS>>3;
   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                              = eNB->ulsch[ULSCH_id]->harq_processes[harq_pid]->decodedBytes;
+  assert(pdu->rx_indication_rel8.length <= NFAPI_RX_IND_DATA_MAX);
+  memcpy(pdu->rx_ind_data,
+         eNB->ulsch[ULSCH_id]->harq_processes[harq_pid]->decodedBytes,
+         pdu->rx_indication_rel8.length);
+
   // estimate timing advance for MAC
   sync_pos                               = lte_est_timing_advance_pusch(&eNB->frame_parms, eNB->pusch_vars[ULSCH_id]->drs_ch_estimates_time);
   timing_advance_update                  = sync_pos; 
@@ -1832,6 +1838,7 @@ int getM(PHY_VARS_eNB *eNB,int frame,int subframe) {
 
 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);
+  assert(eNB->UL_INFO.cqi_ind.cqi_indication_body.number_of_cqis <= NFAPI_CQI_IND_MAX_PDU);
   nfapi_cqi_indication_pdu_t *pdu         = &eNB->UL_INFO.cqi_ind.cqi_indication_body.cqi_pdu_list[eNB->UL_INFO.cqi_ind.cqi_indication_body.number_of_cqis];
   nfapi_cqi_indication_raw_pdu_t *raw_pdu = &eNB->UL_INFO.cqi_ind.cqi_indication_body.cqi_raw_pdu_list[eNB->UL_INFO.cqi_ind.cqi_indication_body.number_of_cqis];
   pdu->instance_length = 0;
@@ -1878,6 +1885,7 @@ void fill_ulsch_harq_indication (PHY_VARS_eNB *eNB, LTE_UL_eNB_HARQ_t *ulsch_har
 
   //AssertFatal(DLSCH_id>=0,"DLSCH_id doesn't exist\n");
   pthread_mutex_lock(&eNB->UL_INFO_mutex);
+  assert(eNB->UL_INFO.harq_ind.harq_indication_body.number_of_harqs <= NFAPI_HARQ_IND_MAX_PDU);
   nfapi_harq_indication_pdu_t *pdu =   &eNB->UL_INFO.harq_ind.harq_indication_body.harq_pdu_list[eNB->UL_INFO.harq_ind.harq_indication_body.number_of_harqs];
   int M;
   int i;
@@ -1948,6 +1956,7 @@ void fill_uci_harq_indication (int UEid, PHY_VARS_eNB *eNB, LTE_eNB_UCI *uci, in
   pthread_mutex_lock(&eNB->UL_INFO_mutex);
   nfapi_harq_indication_t *ind       = &eNB->UL_INFO.harq_ind;
   nfapi_harq_indication_body_t *body = &ind->harq_indication_body;
+  assert(eNB->UL_INFO.harq_ind.harq_indication_body.number_of_harqs <= NFAPI_HARQ_IND_MAX_PDU);
   nfapi_harq_indication_pdu_t *pdu   = &body->harq_pdu_list[eNB->UL_INFO.harq_ind.harq_indication_body.number_of_harqs];
   ind->sfn_sf = frame<<4|subframe;
   ind->header.message_id = NFAPI_HARQ_INDICATION;
@@ -2124,6 +2133,7 @@ void fill_uci_harq_indication (int UEid, PHY_VARS_eNB *eNB, LTE_eNB_UCI *uci, in
 
 void fill_crc_indication (PHY_VARS_eNB *eNB, int ULSCH_id, int frame, int subframe, uint8_t crc_flag) {
   pthread_mutex_lock(&eNB->UL_INFO_mutex);
+  assert(eNB->UL_INFO.crc_ind.crc_indication_body.number_of_crcs <= NFAPI_CRC_IND_MAX_PDU);
   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];
   eNB->UL_INFO.crc_ind.sfn_sf                         = frame<<4 | subframe;
   eNB->UL_INFO.crc_ind.header.message_id              = NFAPI_CRC_INDICATION;
diff --git a/openair1/SCHED_NR/fapi_nr_l1.c b/openair1/SCHED_NR/fapi_nr_l1.c
index 8f315ba214d2fea4b283685b526308fac516f848..782c70785763d8559ab7c723ba9049fa591583e0 100644
--- a/openair1/SCHED_NR/fapi_nr_l1.c
+++ b/openair1/SCHED_NR/fapi_nr_l1.c
@@ -149,16 +149,15 @@ void nr_schedule_response(NR_Sched_Rsp_t *Sched_INFO){
 
   gNB = RC.gNB[Mod_id];
 
-  notifiedFIFO_elt_t *res;
-  res = pullTpool(gNB->resp_L1_tx, gNB->threadPool);
-  processingData_L1tx_t *msgTx = (processingData_L1tx_t *)NotifiedFifoData(res);
-
   uint8_t number_dl_pdu             = (DL_req==NULL) ? 0 : DL_req->dl_tti_request_body.nPDUs;
   uint8_t number_ul_dci_pdu         = (UL_dci_req==NULL) ? 0 : UL_dci_req->numPdus;
   uint8_t number_ul_tti_pdu         = (UL_tti_req==NULL) ? 0 : UL_tti_req->n_pdus;
   uint8_t number_tx_data_pdu        = (TX_req == NULL) ? 0 : TX_req->Number_of_PDUs;
 
   if (NFAPI_MODE == NFAPI_MONOLITHIC){
+    notifiedFIFO_elt_t *res;
+    res = pullTpool(gNB->resp_L1_tx, gNB->threadPool);
+    processingData_L1tx_t *msgTx = (processingData_L1tx_t *)NotifiedFifoData(res);
     if (DL_req != NULL && TX_req!=NULL && (number_dl_pdu > 0 || number_ul_dci_pdu > 0 || number_ul_tti_pdu > 0))
       LOG_D(PHY,"NFAPI: Sched_INFO:SFN/SLOT:%04d/%d DL_req:SFN/SLO:%04d/%d:dl_pdu:%d tx_req:SFN/SLOT:%04d/%d:pdus:%d;ul_dci %d ul_tti %d\n",
       frame,slot,
@@ -241,12 +240,12 @@ void nr_schedule_response(NR_Sched_Rsp_t *Sched_INFO){
     if (number_ul_dci_pdu>0)
       oai_nfapi_ul_dci_req(UL_dci_req);
 
-    if (number_dl_pdu>0)
-      oai_nfapi_dl_tti_req(DL_req);
-
     if (number_tx_data_pdu>0)
       oai_nfapi_tx_data_req(TX_req);
 
-  }
+    if (number_dl_pdu>0)
+      oai_nfapi_dl_tti_req(DL_req);
 
+  } 
+  
 }
diff --git a/openair1/SCHED_NR/nr_ru_procedures.c b/openair1/SCHED_NR/nr_ru_procedures.c
index d8fa11d1571cba60bfdccd1ec96967e616170398..3f4c2f71fb24b063ad5a0e6e834bf33a6e3c0103 100644
--- a/openair1/SCHED_NR/nr_ru_procedures.c
+++ b/openair1/SCHED_NR/nr_ru_procedures.c
@@ -477,9 +477,10 @@ void nr_feptx_prec(RU_t *ru,int frame_tx,int tti_tx) {
       memcpy((void*)ru->common.txdataF[i],
            (void*)&gNB->common_vars.txdataF[i][txdataF_offset],
            fp->samples_per_slot_wCP*sizeof(int32_t));
-      memcpy((void*)&ru->common.beam_id[i][slot_tx*fp->symbols_per_slot],
-	     (void*)&gNB->common_vars.beam_id[i][slot_tx*fp->symbols_per_slot],
-	     fp->symbols_per_slot*sizeof(uint8_t));
+      if (ru->do_precoding == 1)
+	memcpy((void*)&ru->common.beam_id[i][slot_tx*fp->symbols_per_slot],
+	       (void*)&gNB->common_vars.beam_id[i][slot_tx*fp->symbols_per_slot],
+	       fp->symbols_per_slot*sizeof(uint8_t));
     }
 
     if (ru->nb_tx == 1 && ru->nb_log_antennas == 1) {
diff --git a/openair1/SCHED_NR/phy_procedures_nr_gNB.c b/openair1/SCHED_NR/phy_procedures_nr_gNB.c
index 792667d510d3569f45f4182a9958ffa2f552bb3c..9e5a8a536b1b5f881d83af6f1d9d550eb9620c0d 100644
--- a/openair1/SCHED_NR/phy_procedures_nr_gNB.c
+++ b/openair1/SCHED_NR/phy_procedures_nr_gNB.c
@@ -456,6 +456,7 @@ void nr_fill_indication(PHY_VARS_gNB *gNB, int frame, int slot_rx, int ULSCH_id,
 
 
   if (0/*pusch_pdu->mcs_index == 9*/) {
+      __attribute__((unused))
 #ifdef __AVX2__
       int off = ((pusch_pdu->rb_size&1) == 1)? 4:0;
 #else
@@ -660,6 +661,8 @@ int phy_procedures_gNB_uespec_RX(PHY_VARS_gNB *gNB, int frame_rx, int slot_rx) {
   for (int i=0;i<NUMBER_OF_NR_PUCCH_MAX;i++){
     NR_gNB_PUCCH_t *pucch = gNB->pucch[i];
     if (pucch) {
+      if (NFAPI_MODE == NFAPI_MODE_PNF)
+        pucch->frame = frame_rx;
       if ((pucch->active == 1) &&
           (pucch->frame == frame_rx) &&
           (pucch->slot == slot_rx) ) {
diff --git a/openair1/SCHED_NR_UE/defs.h b/openair1/SCHED_NR_UE/defs.h
index c98574ec42f35addc4758ff8290303605a7d96e1..b3527365a5f3a136efa00d48686bc50d7e728565 100644
--- a/openair1/SCHED_NR_UE/defs.h
+++ b/openair1/SCHED_NR_UE/defs.h
@@ -416,7 +416,8 @@ void nr_fill_rx_indication(fapi_nr_rx_indication_t *rx_ind,
                            PHY_VARS_NR_UE *ue,
                            NR_UE_DLSCH_t *dlsch0,
                            NR_UE_DLSCH_t *dlsch1,
-                           uint16_t n_pdus);
+                           uint16_t n_pdus,
+                           UE_nr_rxtx_proc_t *proc);
 
 bool nr_ue_dlsch_procedures(PHY_VARS_NR_UE *ue,
                             UE_nr_rxtx_proc_t *proc,
diff --git a/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c b/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c
index 6848101a2781a3ef2edf987954a137cb3a523c54..f67c84a07c872c01657b2dd302dcf9ab322658fc 100644
--- a/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c
+++ b/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c
@@ -39,11 +39,176 @@
 
 #include "PHY/defs_nr_UE.h"
 #include "PHY/impl_defs_nr.h"
+#include "utils.h"
 
 extern PHY_VARS_NR_UE ***PHY_vars_UE_g;
 
 const char *dl_pdu_type[]={"DCI", "DLSCH", "RA_DLSCH", "SI_DLSCH", "P_DLSCH"};
 const char *ul_pdu_type[]={"PRACH", "PUCCH", "PUSCH", "SRS"};
+queue_t nr_rx_ind_queue;
+queue_t nr_crc_ind_queue;
+queue_t nr_uci_ind_queue;
+
+int8_t nr_ue_scheduled_response_stub(nr_scheduled_response_t *scheduled_response) {
+
+  if(scheduled_response != NULL)
+  {
+    if (scheduled_response->ul_config != NULL)
+    {
+      fapi_nr_ul_config_request_t *ul_config = scheduled_response->ul_config;
+      AssertFatal(ul_config->number_pdus < sizeof(ul_config->ul_config_list) / sizeof(ul_config->ul_config_list[0]),
+                  "Too many ul_config pdus %d", ul_config->number_pdus);
+      for (int i = 0; i < ul_config->number_pdus; ++i)
+      {
+        LOG_I(PHY, "In %s: processing type %d PDU of %d total UL PDUs (ul_config %p) \n",
+              __FUNCTION__, ul_config->ul_config_list[i].pdu_type, ul_config->number_pdus, ul_config);
+
+        uint8_t pdu_type = ul_config->ul_config_list[i].pdu_type;
+        switch (pdu_type)
+        {
+          case (FAPI_NR_UL_CONFIG_TYPE_PUSCH):
+          {
+            nfapi_nr_rx_data_indication_t *rx_ind = CALLOC(1, sizeof(*rx_ind));
+            nfapi_nr_crc_indication_t *crc_ind = CALLOC(1, sizeof(*crc_ind));
+            nfapi_nr_ue_pusch_pdu_t *pusch_config_pdu = &ul_config->ul_config_list[i].pusch_config_pdu;
+            if (scheduled_response->tx_request)
+            {
+              AssertFatal(scheduled_response->tx_request->number_of_pdus <
+                          sizeof(scheduled_response->tx_request->tx_request_body) / sizeof(scheduled_response->tx_request->tx_request_body[0]),
+                          "Too many tx_req pdus %d", scheduled_response->tx_request->number_of_pdus);
+              rx_ind->header.message_id = NFAPI_NR_PHY_MSG_TYPE_RX_DATA_INDICATION;
+              rx_ind->sfn = scheduled_response->ul_config->sfn;
+              rx_ind->slot = scheduled_response->ul_config->slot;
+              rx_ind->number_of_pdus = scheduled_response->tx_request->number_of_pdus;
+              rx_ind->pdu_list = CALLOC(rx_ind->number_of_pdus, sizeof(*rx_ind->pdu_list));
+              for (int j = 0; j < rx_ind->number_of_pdus; j++)
+              {
+                fapi_nr_tx_request_body_t *tx_req_body = &scheduled_response->tx_request->tx_request_body[j];
+                rx_ind->pdu_list[j].handle = pusch_config_pdu->handle;
+                rx_ind->pdu_list[j].harq_id = pusch_config_pdu->pusch_data.harq_process_id;
+                rx_ind->pdu_list[j].pdu_length = tx_req_body->pdu_length;
+                rx_ind->pdu_list[j].pdu = CALLOC(tx_req_body->pdu_length, sizeof(*rx_ind->pdu_list[j].pdu));
+                memcpy(rx_ind->pdu_list[j].pdu, tx_req_body->pdu, tx_req_body->pdu_length * sizeof(*rx_ind->pdu_list[j].pdu));
+                rx_ind->pdu_list[j].rnti = pusch_config_pdu->rnti;
+                rx_ind->pdu_list[j].timing_advance = scheduled_response->tx_request->tx_config.timing_advance;
+                rx_ind->pdu_list[j].ul_cqi = scheduled_response->tx_request->tx_config.ul_cqi;
+                char buffer[1024];
+                hexdump(rx_ind->pdu_list[j].pdu, rx_ind->pdu_list[j].pdu_length, buffer, sizeof(buffer));
+                LOG_D(NR_MAC, "Hexdump of pdu %s before queuing rx_ind\n",
+                      buffer);
+              }
+
+              crc_ind->header.message_id = NFAPI_NR_PHY_MSG_TYPE_CRC_INDICATION;
+              crc_ind->number_crcs = scheduled_response->ul_config->number_pdus;
+              crc_ind->sfn = scheduled_response->ul_config->sfn;
+              crc_ind->slot = scheduled_response->ul_config->slot;
+              crc_ind->crc_list = CALLOC(crc_ind->number_crcs, sizeof(*crc_ind->crc_list));
+              for (int j = 0; j < crc_ind->number_crcs; j++)
+              {
+                crc_ind->crc_list[j].handle = pusch_config_pdu->handle;
+                crc_ind->crc_list[j].harq_id = pusch_config_pdu->pusch_data.harq_process_id;
+                LOG_D(NR_MAC, "This is the harq pid %d for crc_list[%d]\n", crc_ind->crc_list[j].harq_id, j);
+                LOG_D(NR_MAC, "This is sched sfn/sl [%d %d] and crc sfn/sl [%d %d]\n",
+                      scheduled_response->frame, scheduled_response->slot, crc_ind->sfn, crc_ind->slot);
+                crc_ind->crc_list[j].num_cb = pusch_config_pdu->pusch_data.num_cb;
+                crc_ind->crc_list[j].rnti = pusch_config_pdu->rnti;
+                crc_ind->crc_list[j].tb_crc_status = 0;
+                crc_ind->crc_list[j].timing_advance = scheduled_response->tx_request->tx_config.timing_advance;
+                crc_ind->crc_list[j].ul_cqi = 255;
+              }
+
+              if (!put_queue(&nr_rx_ind_queue, rx_ind))
+              {
+                LOG_E(NR_MAC, "Put_queue failed for rx_ind\n");
+                for (int i = 0; i < rx_ind->number_of_pdus; i++)
+                {
+                  free(rx_ind->pdu_list[i].pdu);
+                  rx_ind->pdu_list[i].pdu = NULL;
+                }
+
+                free(rx_ind->pdu_list);
+                rx_ind->pdu_list = NULL;
+                free(rx_ind);
+                rx_ind = NULL;
+              }
+              if (!put_queue(&nr_crc_ind_queue, crc_ind))
+              {
+                LOG_E(NR_MAC, "Put_queue failed for crc_ind\n");
+                free(crc_ind->crc_list);
+                crc_ind->crc_list = NULL;
+                free(crc_ind);
+                crc_ind = NULL;
+              }
+
+              LOG_D(PHY, "In %s: Filled queue rx/crc_ind which was filled by ulconfig. \n", __FUNCTION__);
+
+              scheduled_response->tx_request->number_of_pdus = 0;
+            }
+            break;
+          }
+
+          default:
+            LOG_I(NR_MAC, "Unknown ul_config->pdu_type %d\n", pdu_type);
+          break;
+        }
+      }
+      scheduled_response->ul_config->number_pdus = 0;
+    }
+
+    if (scheduled_response->dl_config != NULL)
+    {
+      fapi_nr_dl_config_request_t *dl_config = scheduled_response->dl_config;
+      AssertFatal(dl_config->number_pdus < sizeof(dl_config->dl_config_list) / sizeof(dl_config->dl_config_list[0]),
+                  "Too many dl_config pdus %d", dl_config->number_pdus);
+      for (int i = 0; i < dl_config->number_pdus; ++i)
+      {
+        LOG_D(PHY, "In %s: processing %s PDU of %d total DL PDUs (dl_config %p) \n",
+              __FUNCTION__, dl_pdu_type[dl_config->dl_config_list[i].pdu_type - 1], dl_config->number_pdus, dl_config);
+
+        uint8_t pdu_type = dl_config->dl_config_list[i].pdu_type;
+        switch (pdu_type)
+        {
+          case (FAPI_NR_DL_CONFIG_TYPE_DLSCH):
+          {
+            nfapi_nr_uci_indication_t *uci_ind = CALLOC(1, sizeof(*uci_ind));
+            uci_ind->header.message_id = NFAPI_NR_PHY_MSG_TYPE_UCI_INDICATION;
+            uci_ind->sfn = scheduled_response->frame;
+            uci_ind->slot = scheduled_response->slot;
+            uci_ind->num_ucis = 1;
+            uci_ind->uci_list = CALLOC(uci_ind->num_ucis, sizeof(*uci_ind->uci_list));
+            for (int j = 0; j < uci_ind->num_ucis; j++)
+            {
+              nfapi_nr_uci_pucch_pdu_format_0_1_t *pdu_0_1 = &uci_ind->uci_list[j].pucch_pdu_format_0_1;
+              uci_ind->uci_list[j].pdu_type = NFAPI_NR_UCI_FORMAT_0_1_PDU_TYPE;
+              uci_ind->uci_list[j].pdu_size = sizeof(nfapi_nr_uci_pucch_pdu_format_0_1_t);
+              memset(pdu_0_1, 0, sizeof(*pdu_0_1));
+              pdu_0_1->handle = 0;
+              pdu_0_1->rnti = dl_config->dl_config_list[i].dlsch_config_pdu.rnti;
+              pdu_0_1->pucch_format = 1;
+              pdu_0_1->ul_cqi = 255;
+              pdu_0_1->timing_advance = 0;
+              pdu_0_1->rssi = 0;
+            }
+
+            LOG_I(NR_PHY, "In %s: Filled queue uci_ind which was filled by dlconfig.\n"
+                       "uci_num %d, SFN/SLOT: [%d, %d]\n",
+                          __FUNCTION__, uci_ind->num_ucis, uci_ind->sfn, uci_ind->slot);
+
+            if (!put_queue(&nr_uci_ind_queue, uci_ind))
+            {
+              LOG_E(NR_MAC, "Put_queue failed for uci_ind\n");
+              free(uci_ind->uci_list);
+              free(uci_ind);
+            }
+            break;
+          }
+        }
+      }
+    }
+
+  }
+  return 0;
+}
 
 int8_t nr_ue_scheduled_response(nr_scheduled_response_t *scheduled_response){
 
diff --git a/openair1/SCHED_NR_UE/fapi_nr_ue_l1.h b/openair1/SCHED_NR_UE/fapi_nr_ue_l1.h
index 0cd882a9b5d4060447625cd33a9ea9552856dff7..a0b0b805afed872e22ebc639d916d86d6a7574bc 100755
--- a/openair1/SCHED_NR_UE/fapi_nr_ue_l1.h
+++ b/openair1/SCHED_NR_UE/fapi_nr_ue_l1.h
@@ -34,11 +34,15 @@
 #define __FAPI_NR_UE_L1_H__
 
 #include "NR_IF_Module.h"
+#include "openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.h"
+#include "openair2/LAYER2/NR_MAC_UE/mac_proto.h"
 
 /**\brief NR UE FAPI-like P7 messages, scheduled response from L2 indicating L1
    \param scheduled_response including transmission config(dl_config, ul_config) and data transmission (tx_req)*/
 int8_t nr_ue_scheduled_response(nr_scheduled_response_t *scheduled_response);
 
+int8_t nr_ue_scheduled_response_stub(nr_scheduled_response_t *scheduled_response);
+
 /**\brief NR UE FAPI-like P5 message, physical configuration from L2 to configure L1
    \param scheduled_response including transmission config(dl_config, ul_config) and data transmission (tx_req)*/
 int8_t nr_ue_phy_config_request(nr_phy_config_t *phy_config);
diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c
index 850b41d2fbb0a41e2aeefc9d81914394dfda2a2e..e403c7410b583683310e4ea4bb7fdf0b6aa97d15 100644
--- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c
+++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c
@@ -121,7 +121,8 @@ void nr_fill_rx_indication(fapi_nr_rx_indication_t *rx_ind,
                            PHY_VARS_NR_UE *ue,
                            NR_UE_DLSCH_t *dlsch0,
                            NR_UE_DLSCH_t *dlsch1,
-                           uint16_t n_pdus){
+                           uint16_t n_pdus,
+			   UE_nr_rxtx_proc_t *proc ){
 
 
   NR_DL_FRAME_PARMS *frame_parms = &ue->frame_parms;
@@ -130,6 +131,16 @@ void nr_fill_rx_indication(fapi_nr_rx_indication_t *rx_ind,
     LOG_E(PHY, "In %s: multiple number of DL PDUs not supported yet...\n", __FUNCTION__);
   }
 
+  if (pdu_type !=  FAPI_NR_RX_PDU_TYPE_SSB)
+    trace_NRpdu(DIRECTION_DOWNLINK,
+		dlsch0->harq_processes[dlsch0->current_harq_pid]->b,
+		dlsch0->harq_processes[dlsch0->current_harq_pid]->TBS / 8,
+		pdu_type,
+		WS_C_RNTI,
+		dlsch0->rnti,
+		proc->frame_rx,
+		proc->nr_slot_rx,
+		0,0);
   switch (pdu_type){
     case FAPI_NR_RX_PDU_TYPE_SIB:
       rx_ind->rx_indication_body[n_pdus - 1].pdsch_pdu.harq_pid = dlsch0->current_harq_pid;
@@ -478,7 +489,7 @@ int nr_ue_pdcch_procedures(uint8_t gNB_id,
   int frame_rx = proc->frame_rx;
   int nr_slot_rx = proc->nr_slot_rx;
   unsigned int dci_cnt=0;
-  fapi_nr_dci_indication_t dci_ind = {0};
+  fapi_nr_dci_indication_t *dci_ind = calloc(1, sizeof(*dci_ind));
   nr_downlink_indication_t dl_indication;
 
   NR_UE_PDCCH *pdcch_vars = ue->pdcch_vars[proc->thread_id][gNB_id];
@@ -677,7 +688,7 @@ int nr_ue_pdcch_procedures(uint8_t gNB_id,
 	 n_ss);
 #endif
 
-  dci_cnt = nr_dci_decoding_procedure(ue, proc, &dci_ind, rel15);
+  dci_cnt = nr_dci_decoding_procedure(ue, proc, dci_ind, rel15);
 
 #ifdef NR_PDCCH_SCHED_DEBUG
   LOG_I(PHY,"<-NR_PDCCH_PHY_PROCEDURES_LTE_UE (nr_ue_pdcch_procedures)-> Ending function nr_dci_decoding_procedure() -> dci_cnt=%u\n",dci_cnt);
@@ -691,12 +702,12 @@ int nr_ue_pdcch_procedures(uint8_t gNB_id,
       ue->Mod_id,frame_rx%1024,nr_slot_rx,nr_mode_string[ue->UE_mode[gNB_id]],
       i + 1,
       dci_cnt,
-      dci_ind.dci_list[i].rnti,
-      dci_ind.dci_list[i].dci_format);
+      dci_ind->dci_list[i].rnti,
+      dci_ind->dci_list[i].dci_format);
   }
   ue->pdcch_vars[proc->thread_id][gNB_id]->dci_received += dci_cnt;
 
-  dci_ind.number_of_dcis = dci_cnt;
+  dci_ind->number_of_dcis = dci_cnt;
     /*
     for (int i=0; i<dci_cnt; i++) {
       
@@ -734,7 +745,7 @@ int nr_ue_pdcch_procedures(uint8_t gNB_id,
     */
 
     // fill dl_indication message
-    nr_fill_dl_indication(&dl_indication, &dci_ind, NULL, proc, ue, gNB_id);
+    nr_fill_dl_indication(&dl_indication, dci_ind, NULL, proc, ue, gNB_id);
     //  send to mac
     ue->if_inst->dl_indication(&dl_indication, NULL);
 
@@ -873,7 +884,7 @@ bool nr_ue_dlsch_procedures(PHY_VARS_NR_UE *ue,
   NR_UE_PDSCH *pdsch_vars;
   uint16_t dmrs_len = get_num_dmrs(dlsch0->harq_processes[dlsch0->current_harq_pid]->dlDmrsSymbPos);
   nr_downlink_indication_t dl_indication;
-  fapi_nr_rx_indication_t rx_ind;
+  fapi_nr_rx_indication_t *rx_ind = calloc(1, sizeof(*rx_ind));
   uint16_t number_pdus = 1;
   // params for UL time alignment procedure
   NR_UL_TIME_ALIGNMENT_t *ul_time_alignment = &ue->ul_time_alignment[gNB_id];
@@ -1002,17 +1013,17 @@ bool nr_ue_dlsch_procedures(PHY_VARS_NR_UE *ue,
 
     switch (pdsch) {
       case RA_PDSCH:
-        nr_fill_dl_indication(&dl_indication, NULL, &rx_ind, proc, ue, gNB_id);
-        nr_fill_rx_indication(&rx_ind, FAPI_NR_RX_PDU_TYPE_RAR, gNB_id, ue, dlsch0, NULL, number_pdus);
+        nr_fill_dl_indication(&dl_indication, NULL, rx_ind, proc, ue, gNB_id);
+        nr_fill_rx_indication(rx_ind, FAPI_NR_RX_PDU_TYPE_RAR, gNB_id, ue, dlsch0, NULL, number_pdus, proc);
         ue->UE_mode[gNB_id] = RA_RESPONSE;
         break;
       case PDSCH:
-        nr_fill_dl_indication(&dl_indication, NULL, &rx_ind, proc, ue, gNB_id);
-        nr_fill_rx_indication(&rx_ind, FAPI_NR_RX_PDU_TYPE_DLSCH, gNB_id, ue, dlsch0, NULL, number_pdus);
+        nr_fill_dl_indication(&dl_indication, NULL, rx_ind, proc, ue, gNB_id);
+        nr_fill_rx_indication(rx_ind, FAPI_NR_RX_PDU_TYPE_DLSCH, gNB_id, ue, dlsch0, NULL, number_pdus, proc);
         break;
       case SI_PDSCH:
-        nr_fill_dl_indication(&dl_indication, NULL, &rx_ind, proc, ue, gNB_id);
-        nr_fill_rx_indication(&rx_ind, FAPI_NR_RX_PDU_TYPE_SIB, gNB_id, ue, dlsch0, NULL, number_pdus);
+        nr_fill_dl_indication(&dl_indication, NULL, rx_ind, proc, ue, gNB_id);
+        nr_fill_rx_indication(rx_ind, FAPI_NR_RX_PDU_TYPE_SIB, gNB_id, ue, dlsch0, NULL, number_pdus, proc);
         break;
       default:
         break;
diff --git a/openair1/SCHED_UE/phy_procedures_lte_ue.c b/openair1/SCHED_UE/phy_procedures_lte_ue.c
index 5f8269c513d0608f86f39e8a246f165150cd45aa..4635f2b7412eea602cbf2e1714131c5f5854c048 100644
--- a/openair1/SCHED_UE/phy_procedures_lte_ue.c
+++ b/openair1/SCHED_UE/phy_procedures_lte_ue.c
@@ -3193,7 +3193,7 @@ void ue_pdsch_procedures(PHY_VARS_UE *ue,
           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));
+        LOG_D(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) {
@@ -3686,6 +3686,7 @@ void *UE_thread_slot1_dl_processing(void *arg) {
   if ( (proc->sub_frame_start+1)%RX_NB_TH == 1 && threads.slot1_proc_two != -1 )
     CPU_SET(threads.slot1_proc_two, &cpuset);
 
+  // cppcheck-suppress moduloAlwaysTrueFalse
   if ( (proc->sub_frame_start+1)%RX_NB_TH == 2 && threads.slot1_proc_three != -1 )
     CPU_SET(threads.slot1_proc_three, &cpuset);
 
@@ -3825,7 +3826,7 @@ void *UE_thread_slot1_dl_processing(void *arg) {
 
     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));
+      LOG_D(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
@@ -3919,7 +3920,7 @@ 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_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));
+      LOG_D(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) {
@@ -4145,7 +4146,7 @@ int phy_procedures_slot_parallelization_UE_RX(PHY_VARS_UE *ue,
       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));
+        LOG_D(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;
@@ -4155,7 +4156,7 @@ int phy_procedures_slot_parallelization_UE_RX(PHY_VARS_UE *ue,
     //proc->dci_slot0_available=1;
     if (LOG_DEBUGFLAG(UE_TIMING)) {
       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));
+      LOG_D(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));
     }
   }
 
@@ -4164,7 +4165,7 @@ int phy_procedures_slot_parallelization_UE_RX(PHY_VARS_UE *ue,
   // 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,
+    LOG_D(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));
   }
 
@@ -4178,7 +4179,7 @@ int phy_procedures_slot_parallelization_UE_RX(PHY_VARS_UE *ue,
 
   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));
+    LOG_D(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));
   }
 
   /**** End Subframe FE Processing ****/
@@ -4266,7 +4267,7 @@ int phy_procedures_slot_parallelization_UE_RX(PHY_VARS_UE *ue,
 
   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));
+    LOG_D(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
@@ -4279,7 +4280,7 @@ int phy_procedures_slot_parallelization_UE_RX(PHY_VARS_UE *ue,
 
   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));
+    LOG_D(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));
   }
 
   //=====================================================================//
@@ -4351,7 +4352,7 @@ int phy_procedures_slot_parallelization_UE_RX(PHY_VARS_UE *ue,
 
   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));
+    LOG_D(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));
   }
 
   // duplicate harq structure
diff --git a/openair1/SCHED_UE/pusch_pc.c b/openair1/SCHED_UE/pusch_pc.c
index 503d73005f25adcc5bd7afe8b8d2fe61ff0af2ea..55c8c7c547cfd2055e28bdc1eba3f9329ac544b8 100644
--- a/openair1/SCHED_UE/pusch_pc.c
+++ b/openair1/SCHED_UE/pusch_pc.c
@@ -115,7 +115,7 @@ void pusch_power_cntl(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,uint8_
 }
 
 int8_t get_PHR(uint8_t Mod_id, uint8_t CC_id,uint8_t eNB_index) {
-  if(NFAPI_MODE!=NFAPI_UE_STUB_PNF)
+  if(NFAPI_MODE!=NFAPI_UE_STUB_PNF && NFAPI_MODE!=NFAPI_MODE_STANDALONE_PNF)
     return PHY_vars_UE_g[Mod_id][CC_id]->ulsch[eNB_index]->PHR;
   else
     return 40; // l1l2 simulator => ideal conditions
diff --git a/openair1/SIMULATION/ETH_TRANSPORT/netlink_init.c b/openair1/SIMULATION/ETH_TRANSPORT/netlink_init.c
index 9b4aba46c394f1715b6209bcb802449fddd5c450..53374476782af8f5db96aab0878001cd24a034c9 100644
--- a/openair1/SIMULATION/ETH_TRANSPORT/netlink_init.c
+++ b/openair1/SIMULATION/ETH_TRANSPORT/netlink_init.c
@@ -56,7 +56,7 @@ struct nlmsghdr *nas_nlh_rx = NULL;
 struct iovec nas_iov_tx;
 struct iovec nas_iov_rx = {nl_rx_buf, sizeof(nl_rx_buf)};
 
-int nas_sock_fd[MAX_MOBILES_PER_ENB];
+int nas_sock_fd[MAX_MOBILES_PER_ENB*2]; //Allocated for both LTE UE and NR UE.
 
 int nas_sock_mbms_fd;
 
@@ -70,7 +70,7 @@ static int tun_alloc(char *dev) {
   int fd, err;
 
   if( (fd = open("/dev/net/tun", O_RDWR)) < 0 ) {
-    printf("[TUN] failed to open /dev/net/tun\n");
+    LOG_E(PDCP, "[TUN] failed to open /dev/net/tun\n");
     return -1;
   }
 
@@ -95,15 +95,20 @@ static int tun_alloc(char *dev) {
 }
 
 
-int netlink_init_mbms_tun(char *ifprefix) {
+int netlink_init_mbms_tun(char *ifprefix, int id) {//for UE, id = 1, 2, ...,
   int ret;
   char ifname[64];
 
-    sprintf(ifname, "oaitun_%.3s1",ifprefix); // added "1": for historical reasons
+    if (id > 0) {
+      sprintf(ifname, "oaitun_%.3s%d", ifprefix, id-1);
+    }
+    else {
+      sprintf(ifname, "oaitun_%.3s1", ifprefix); // added "1": for historical reasons
+    }
     nas_sock_mbms_fd = tun_alloc(ifname);
 
     if (nas_sock_mbms_fd == -1) {
-      printf("[NETLINK] Error opening socket %s (%d:%s)\n",ifname,errno, strerror(errno));
+      printf("[NETLINK] Error opening mbms socket %s (%d:%s)\n",ifname,errno, strerror(errno));
       exit(1);
     }
 
@@ -123,88 +128,36 @@ int netlink_init_mbms_tun(char *ifprefix) {
     nas_src_addr.nl_pid = 1;//getpid();  /* self pid */
     nas_src_addr.nl_groups = 0;  /* not in mcast groups */
     ret = bind(nas_sock_mbms_fd, (struct sockaddr *)&nas_src_addr, sizeof(nas_src_addr));
-    memset(&nas_dest_addr, 0, sizeof(nas_dest_addr));
-    nas_dest_addr.nl_family = AF_NETLINK;
-    nas_dest_addr.nl_pid = 0;   /* For Linux Kernel */
-    nas_dest_addr.nl_groups = 0; /* unicast */
-    // TX PART
-    nas_nlh_tx=(struct nlmsghdr *)malloc(NLMSG_SPACE(NL_MAX_PAYLOAD));
-    memset(nas_nlh_tx, 0, NLMSG_SPACE(NL_MAX_PAYLOAD));
-    /* Fill the netlink message header */
-    nas_nlh_tx->nlmsg_len = NLMSG_SPACE(NL_MAX_PAYLOAD);
-    nas_nlh_tx->nlmsg_pid = 1;//getpid();  /* self pid */
-    nas_nlh_tx->nlmsg_flags = 0;
-    nas_iov_tx.iov_base = (void *)nas_nlh_tx;
-    nas_iov_tx.iov_len = nas_nlh_tx->nlmsg_len;
-    memset(&nas_msg_tx,0,sizeof(nas_msg_tx));
-    nas_msg_tx.msg_name = (void *)&nas_dest_addr;
-    nas_msg_tx.msg_namelen = sizeof(nas_dest_addr);
-    nas_msg_tx.msg_iov = &nas_iov_tx;
-    nas_msg_tx.msg_iovlen = 1;
-    // RX PART
-    memset(&nas_msg_rx,0,sizeof(nas_msg_rx));
-    nas_msg_rx.msg_name = (void *)&nas_src_addr;
-    nas_msg_rx.msg_namelen = sizeof(nas_src_addr);
-    nas_msg_rx.msg_iov = &nas_iov_rx;
-    nas_msg_rx.msg_iovlen = 1;
 
   return 1;
 }
 
-int netlink_init_tun(char *ifprefix, int num_if) {
+int netlink_init_tun(char *ifprefix, int num_if, int id) {//for UE, id = 1, 2, ...,
   int ret;
   char ifname[64];
 
-  for (int i = 0; i < num_if; i++) {
+  int begx = (id == 0) ? 0 : id - 1;
+  int endx = (id == 0) ? num_if : id;
+  for (int i = begx; i < endx; i++) {
     sprintf(ifname, "oaitun_%.3s%d",ifprefix,i+1);
     nas_sock_fd[i] = tun_alloc(ifname);
 
     if (nas_sock_fd[i] == -1) {
-      printf("[NETLINK] Error opening socket %s (%d:%s)\n",ifname,errno, strerror(errno));
+      LOG_E(PDCP, "TUN: Error opening socket %s (%d:%s)\n",ifname,errno, strerror(errno));
       exit(1);
     }
 
-    printf("[NETLINK]Opened socket %s with fd nas_sock_fd[%d]=%d\n",
+    LOG_I(PDCP, "TUN: Opened socket %s with fd nas_sock_fd[%d]=%d\n",
            ifname, i, nas_sock_fd[i]);
     ret = fcntl(nas_sock_fd[i],F_SETFL,O_NONBLOCK);
 
     if (ret == -1) {
-      printf("[NETLINK] Error fcntl (%d:%s)\n",errno, strerror(errno));
+      LOG_E(PDCP, "TUN: Error fcntl (%d:%s)\n",errno, strerror(errno));
 
       if (LINK_ENB_PDCP_TO_IP_DRIVER) {
         exit(1);
       }
     }
-
-    memset(&nas_src_addr, 0, sizeof(nas_src_addr));
-    nas_src_addr.nl_family = AF_NETLINK;
-    nas_src_addr.nl_pid = 1;//getpid();  /* self pid */
-    nas_src_addr.nl_groups = 0;  /* not in mcast groups */
-    ret = bind(nas_sock_fd[i], (struct sockaddr *)&nas_src_addr, sizeof(nas_src_addr));
-    memset(&nas_dest_addr, 0, sizeof(nas_dest_addr));
-    nas_dest_addr.nl_family = AF_NETLINK;
-    nas_dest_addr.nl_pid = 0;   /* For Linux Kernel */
-    nas_dest_addr.nl_groups = 0; /* unicast */
-    // TX PART
-    nas_nlh_tx=(struct nlmsghdr *)malloc(NLMSG_SPACE(NL_MAX_PAYLOAD));
-    memset(nas_nlh_tx, 0, NLMSG_SPACE(NL_MAX_PAYLOAD));
-    /* Fill the netlink message header */
-    nas_nlh_tx->nlmsg_len = NLMSG_SPACE(NL_MAX_PAYLOAD);
-    nas_nlh_tx->nlmsg_pid = 1;//getpid();  /* self pid */
-    nas_nlh_tx->nlmsg_flags = 0;
-    nas_iov_tx.iov_base = (void *)nas_nlh_tx;
-    nas_iov_tx.iov_len = nas_nlh_tx->nlmsg_len;
-    memset(&nas_msg_tx,0,sizeof(nas_msg_tx));
-    nas_msg_tx.msg_name = (void *)&nas_dest_addr;
-    nas_msg_tx.msg_namelen = sizeof(nas_dest_addr);
-    nas_msg_tx.msg_iov = &nas_iov_tx;
-    nas_msg_tx.msg_iovlen = 1;
-    // RX PART
-    memset(&nas_msg_rx,0,sizeof(nas_msg_rx));
-    nas_msg_rx.msg_name = (void *)&nas_src_addr;
-    nas_msg_rx.msg_namelen = sizeof(nas_src_addr);
-    nas_msg_rx.msg_iov = &nas_iov_rx;
-    nas_msg_rx.msg_iovlen = 1;
   } /* for */
 
   return 1;
@@ -216,7 +169,7 @@ int netlink_init(void) {
   nas_sock_fd[0] = socket(PF_NETLINK, SOCK_RAW,GRAAL_NETLINK_ID);
 
   if (nas_sock_fd[0] == -1) {
-    printf("[NETLINK] Error opening socket %d (%d:%s)\n",nas_sock_fd[0],errno, strerror(errno));
+    printf("[NETLINK] Error opening GRAAL_NETLINK_ID socket %d (%d:%s)\n",nas_sock_fd[0],errno, strerror(errno));
 
     if (LINK_ENB_PDCP_TO_IP_DRIVER) {
       exit(1);
@@ -244,6 +197,7 @@ int netlink_init(void) {
   nas_dest_addr.nl_pid = 0;   /* For Linux Kernel */
   nas_dest_addr.nl_groups = 0; /* unicast */
   // TX PART
+  free(nas_nlh_tx);
   nas_nlh_tx=(struct nlmsghdr *)malloc(NLMSG_SPACE(NL_MAX_PAYLOAD));
   memset(nas_nlh_tx, 0, NLMSG_SPACE(NL_MAX_PAYLOAD));
   /* Fill the netlink message header */
@@ -266,3 +220,8 @@ int netlink_init(void) {
   return(nas_sock_fd[0]);
 }
 
+void netlink_cleanup(void)
+{
+  free(nas_nlh_tx);
+  nas_nlh_tx = NULL;
+}
diff --git a/openair1/SIMULATION/ETH_TRANSPORT/proto.h b/openair1/SIMULATION/ETH_TRANSPORT/proto.h
index e6159199d40898b0d8357a03cac3210a8c0d4426..bc6990ac3e84fdb45d781490e7f58cc64d633d0c 100644
--- a/openair1/SIMULATION/ETH_TRANSPORT/proto.h
+++ b/openair1/SIMULATION/ETH_TRANSPORT/proto.h
@@ -62,7 +62,8 @@ int multicast_link_read_data_from_sock(uint8_t eNB_flag);
 void clear_eNB_transport_info(uint8_t);
 void clear_UE_transport_info(uint8_t);
 int netlink_init(void);
-int netlink_init_tun(char *ifsuffix, int num_if);
-int netlink_init_mbms_tun(char *ifsuffix);
+int netlink_init_tun(char *ifsuffix, int num_if, int id);
+int netlink_init_mbms_tun(char *ifsuffix, int id);
+void netlink_cleanup(void);
 
 #endif /* EMU_PROTO_H_ */
diff --git a/openair1/SIMULATION/LTE_PHY/common_sim.h b/openair1/SIMULATION/LTE_PHY/common_sim.h
index 5e0be3de895bcfce53c3e643643f498e2a08eb8f..5625cf8e2f65c22a00c66f8ead548d9ebb5cd40b 100644
--- a/openair1/SIMULATION/LTE_PHY/common_sim.h
+++ b/openair1/SIMULATION/LTE_PHY/common_sim.h
@@ -134,16 +134,16 @@ struct option * parse_oai_options(paramdef_t *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";
+    char varText[256]={0};
 
     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_INT:
+	   sprintf(varText,"%d",*ptr->iptr);
+	  break;
+	  
           case TYPE_DOUBLE:
             sprintf(varText,"%.2f",*ptr->dblptr);
             break;
@@ -157,6 +157,7 @@ void display_options_values(paramdef_t *options, int verbose) {
 	  break;
 
 	default:
+	  strcpy(varText,"Need specific display");
 	  printf("not decoded type\n");
 	  exit(1);
         }
diff --git a/openair1/SIMULATION/LTE_PHY/dlsim.c b/openair1/SIMULATION/LTE_PHY/dlsim.c
index d4106cb29a50b839538ff212c6a908bc40a69cb0..833207a40861239e242ed59949801b108308da1f 100644
--- a/openair1/SIMULATION/LTE_PHY/dlsim.c
+++ b/openair1/SIMULATION/LTE_PHY/dlsim.c
@@ -634,7 +634,7 @@ int main(int argc, char **argv) {
   //  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 },
+    { "awgn", "Use AWGN channel and not multipath", PARAMFLAG_BOOL, iptr:&awgn_flag, 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 },
diff --git a/openair1/SIMULATION/NR_PHY/dlsim.c b/openair1/SIMULATION/NR_PHY/dlsim.c
index fa868a689696dc2c85be79df95a2249a77fd013e..84c6c3ee5f2ab3088a995276bd3551b96e02d806 100644
--- a/openair1/SIMULATION/NR_PHY/dlsim.c
+++ b/openair1/SIMULATION/NR_PHY/dlsim.c
@@ -71,6 +71,7 @@
 #include <openair2/RRC/LTE/rrc_vars.h>
 
 #include <executables/softmodem-common.h>
+#include <openair3/ocp-gtpu/gtp_itf.h>
 
 LCHAN_DESC DCCH_LCHAN_DESC,DTCH_DL_LCHAN_DESC,DTCH_UL_LCHAN_DESC;
 rlc_info_t Rlc_info_um,Rlc_info_am_config;
@@ -89,6 +90,13 @@ uint64_t downlink_frequency[MAX_NUM_CCs][4];
 THREAD_STRUCT thread_struct;
 nfapi_ue_release_request_body_t release_rntis;
 uint32_t N_RB_DL = 106;
+//Fixme: Uniq dirty DU instance, by global var, datamodel need better management
+instance_t DUuniqInstance=0;
+instance_t CUuniqInstance=0;
+teid_t newGtpuCreateTunnel(instance_t instance, rnti_t rnti, int incoming_bearer_id, int outgoing_bearer_id, teid_t outgoing_teid,
+                           transport_layer_addr_t remoteAddr, int port, gtpCallback callBack) {
+return 0;
+}
 
 // dummy functions
 int dummy_nr_ue_ul_indication(nr_uplink_indication_t *ul_info)              { return(0);  }
@@ -131,12 +139,6 @@ rrc_data_ind(
 {
 }
 
-int ocp_gtpv1u_create_s1u_tunnel(instance_t instance,
-                                 const gtpv1u_enb_create_tunnel_req_t  *create_tunnel_req,
-                                 gtpv1u_enb_create_tunnel_resp_t *create_tunnel_resp) {
-    return 0;
-}
-
 int
 gtpv1u_create_s1u_tunnel(
   const instance_t                              instanceP,
diff --git a/openair1/SIMULATION/NR_PHY/nr_dummy_functions.c b/openair1/SIMULATION/NR_PHY/nr_dummy_functions.c
index 056b018504ab6387e2eb82f5a3cae3a0d367c748..7a47410129f2f78f43df8f9b597675a7c6217e78 100644
--- a/openair1/SIMULATION/NR_PHY/nr_dummy_functions.c
+++ b/openair1/SIMULATION/NR_PHY/nr_dummy_functions.c
@@ -34,4 +34,5 @@ void nr_fill_rx_indication(fapi_nr_rx_indication_t *rx_ind,
                            PHY_VARS_NR_UE *ue,
                            NR_UE_DLSCH_t *dlsch0,
                            NR_UE_DLSCH_t *dlsch1,
-                           uint16_t n_pdus) {}
+                           uint16_t n_pdus,
+                           UE_nr_rxtx_proc_t *proc) {}
diff --git a/openair1/SIMULATION/NR_PHY/pbchsim.c b/openair1/SIMULATION/NR_PHY/pbchsim.c
index 1169b8ecd8e5e18b67a1157717c7f1bb1f4ebb7f..2413a86912fa10ca9dd8b02a1644b19e7cc2c740 100644
--- a/openair1/SIMULATION/NR_PHY/pbchsim.c
+++ b/openair1/SIMULATION/NR_PHY/pbchsim.c
@@ -193,6 +193,7 @@ int main(int argc, char **argv)
 
   int frame=0;
   int frame_length_complex_samples;
+  __attribute__((unused))
   int frame_length_complex_samples_no_prefix;
   NR_DL_FRAME_PARMS *frame_parms;
 
diff --git a/openair1/SIMULATION/NR_PHY/prachsim.c b/openair1/SIMULATION/NR_PHY/prachsim.c
index a33713234c174ecdbd1f75bdb927c2bdde766f87..6b9512a38b7e745bca6eb34f9ac5997ba32cf236 100644
--- a/openair1/SIMULATION/NR_PHY/prachsim.c
+++ b/openair1/SIMULATION/NR_PHY/prachsim.c
@@ -52,6 +52,7 @@
 #include <executables/softmodem-common.h>
 #include <openair2/RRC/NR_UE/rrc_defs.h>
 //#include "openair1/SIMULATION/NR_PHY/nr_dummy_functions.c"
+#include <openair3/ocp-gtpu/gtp_itf.h>
 
 #define NR_PRACH_DEBUG 1
 #define PRACH_WRITE_OUTPUT_DEBUG 1
@@ -88,6 +89,13 @@ int oai_nfapi_nr_crc_indication(nfapi_nr_crc_indication_t *ind) { return(0);  }
 int oai_nfapi_nr_srs_indication(nfapi_nr_srs_indication_t *ind) { return(0);  }
 int oai_nfapi_nr_uci_indication(nfapi_nr_uci_indication_t *ind) { return(0);  }
 int oai_nfapi_nr_rach_indication(nfapi_nr_rach_indication_t *ind) { return(0);  }
+//Fixme: Uniq dirty DU instance, by global var, datamodel need better management
+instance_t DUuniqInstance=0;
+instance_t CUuniqInstance=0;
+teid_t newGtpuCreateTunnel(instance_t instance, rnti_t rnti, int incoming_bearer_id, int outgoing_bearer_id, teid_t outgoing_teid,
+                           transport_layer_addr_t remoteAddr, int port, gtpCallback callBack) {
+return 0;
+}
 
 void
 rrc_data_ind(
@@ -99,12 +107,6 @@ rrc_data_ind(
 {
 }
 
-int ocp_gtpv1u_create_s1u_tunnel(instance_t instance,
-                                 const gtpv1u_enb_create_tunnel_req_t  *create_tunnel_req,
-                                 gtpv1u_enb_create_tunnel_resp_t *create_tunnel_resp) {
-    return 0;
-}
-
 int
 gtpv1u_create_s1u_tunnel(
   const instance_t                              instanceP,
diff --git a/openair1/SIMULATION/NR_PHY/ulsim.c b/openair1/SIMULATION/NR_PHY/ulsim.c
index 97c753d4551392774d39b804b4611d2d0d5ae7bd..db8d54f86d601b7470c79a7fa3ebdf0b02e7d7c3 100644
--- a/openair1/SIMULATION/NR_PHY/ulsim.c
+++ b/openair1/SIMULATION/NR_PHY/ulsim.c
@@ -65,6 +65,7 @@
 
 #include <executables/softmodem-common.h>
 #include "PHY/NR_REFSIG/ul_ref_seq_nr.h"
+#include <openair3/ocp-gtpu/gtp_itf.h>
 //#define DEBUG_ULSIM
 
 LCHAN_DESC DCCH_LCHAN_DESC,DTCH_DL_LCHAN_DESC,DTCH_UL_LCHAN_DESC;
@@ -85,6 +86,13 @@ THREAD_STRUCT thread_struct;
 nfapi_ue_release_request_body_t release_rntis;
 uint32_t N_RB_DL = 106;
 
+//Fixme: Uniq dirty DU instance, by global var, datamodel need better management
+instance_t DUuniqInstance=0;
+instance_t CUuniqInstance=0;
+teid_t newGtpuCreateTunnel(instance_t instance, rnti_t rnti, int incoming_bearer_id, int outgoing_bearer_id, teid_t outgoing_teid,
+                           transport_layer_addr_t remoteAddr, int port, gtpCallback callBack) {
+return 0;
+}
 extern void fix_scd(NR_ServingCellConfig_t *scd);// forward declaration
 
 int8_t nr_mac_rrc_data_ind_ue(const module_id_t module_id,
@@ -120,11 +128,6 @@ rrc_data_ind(
 {
 }
 
-int ocp_gtpv1u_create_s1u_tunnel(instance_t instance,
-                                 const gtpv1u_enb_create_tunnel_req_t  *create_tunnel_req,
-                                 gtpv1u_enb_create_tunnel_resp_t *create_tunnel_resp) {
-    return 0;
-}
 
 int
 gtpv1u_create_s1u_tunnel(
@@ -1278,8 +1281,10 @@ int main(int argc, char **argv)
 
 	if (n_trials == 1  && round==0) {
 #ifdef __AVX2__
+	  __attribute__((unused))
 	  int off = ((nb_rb&1) == 1)? 4:0;
 #else
+	  __attribute__((unused))
 	  int off = 0;
 #endif
 
diff --git a/openair1/SIMULATION/TOOLS/taus.c b/openair1/SIMULATION/TOOLS/taus.c
index cdd4aebec3dff23605946f97d1fb45e3e9ba81f1..a9d2750c06374d80d4b0575176c7bd65e56feccf 100644
--- a/openair1/SIMULATION/TOOLS/taus.c
+++ b/openair1/SIMULATION/TOOLS/taus.c
@@ -21,10 +21,12 @@
 
 #include <time.h>
 #include <stdlib.h>
+#include <fcntl.h>
+#include <unistd.h>
 //#include "SIMULATION/TOOLS/sim.h"
 
 
-unsigned int s0, s1, s2, b;
+static unsigned int s0, s1, s2;
 
 //----------------------------------------------
 //
@@ -34,7 +36,7 @@ unsigned int s0, s1, s2, b;
 
 unsigned int taus(void)
 {
-  b = (((s0 << 13) ^ s0) >> 19);
+  unsigned int b = (((s0 << 13) ^ s0) >> 19);
   s0 = (((s0 & 0xFFFFFFFE) << 12)^  b);
   b = (((s1 << 2) ^ s1) >> 25);
   s1 = (((s1 & 0xFFFFFFF8) << 4)^  b);
@@ -50,9 +52,20 @@ void set_taus_seed(unsigned int seed_init)
   unsigned long result = 0;
 
   if (seed_init == 0) {
-    s0 = (unsigned int)time(NULL);
-    s1 = (unsigned int)time(NULL);
-    s2 = (unsigned int)time(NULL);
+    unsigned int data[3];
+    int fd = open("/dev/urandom", O_RDONLY);
+    if (fd == -1)
+    {
+      abort();
+    }
+    if (read(fd, data, sizeof(data)) != sizeof(data))
+    {
+      abort();
+    }
+    close(fd);
+    s0 = data[0];
+    s1 = data[1];
+    s2 = data[2];
   } else {
     /* Use reentrant version of rand48 to ensure that no conflicts with other generators occur */
     srand48_r((long int)seed_init, &buffer);
diff --git a/openair2/COMMON/as_message.h b/openair2/COMMON/as_message.h
index 829c3c9e33a203aeac0d21f24a612224f874697a..b0ca06daec6aef6b197804d383941f9576dccbee 100644
--- a/openair2/COMMON/as_message.h
+++ b/openair2/COMMON/as_message.h
@@ -219,6 +219,10 @@ typedef struct kenb_refresh_req_s {
   Byte_t kenb[32];
 } kenb_refresh_req_t;
 
+typedef struct nsa_oai_tun_nsa_s {
+  uint8_t buffer[500];
+} nas_oai_tun_nsa_t;
+
 /*
  * NAS->AS - Cell Information request
  * NAS request AS to search for a suitable cell belonging to the selected
diff --git a/openair2/COMMON/f1ap_messages_def.h b/openair2/COMMON/f1ap_messages_def.h
index 6b1c6d94954582f0347caa77711702ea3e0b4eba..0e857f3a83cb5cb6fd9843728359e6748117ee6c 100644
--- a/openair2/COMMON/f1ap_messages_def.h
+++ b/openair2/COMMON/f1ap_messages_def.h
@@ -44,7 +44,8 @@ MESSAGE_DEF(F1AP_UE_CONTEXT_RELEASE_CMD, MESSAGE_PRIORITY_MED, f1ap_ue_context_r
 /* RRC -> F1AP  messages */
 MESSAGE_DEF(F1AP_DL_RRC_MESSAGE              , MESSAGE_PRIORITY_MED, f1ap_dl_rrc_message_t              , f1ap_dl_rrc_message )
 //MESSAGE_DEF(F1AP_INITIAL_CONTEXT_SETUP_REQ , MESSAGE_PRIORITY_MED, f1ap_initial_context_setup_req_t , f1ap_initial_context_setup_req )
-MESSAGE_DEF(F1AP_UE_CONTEXT_SETUP_REQ, MESSAGE_PRIORITY_MED, f1ap_ue_context_setup_req_t, f1ap_ue_context_setup_req)
+MESSAGE_DEF(F1AP_UE_CONTEXT_SETUP_REQ,  MESSAGE_PRIORITY_MED, f1ap_ue_context_setup_t, f1ap_ue_context_setup_req)
+MESSAGE_DEF(F1AP_UE_CONTEXT_SETUP_RESP, MESSAGE_PRIORITY_MED, f1ap_ue_context_setup_t, f1ap_ue_context_setup_resp)
 
 
 
diff --git a/openair2/COMMON/f1ap_messages_types.h b/openair2/COMMON/f1ap_messages_types.h
index c2fb4a9cf7b7e4f1d1adc3c8047e81e033933651..cb1a8c9577704b29d6da8ab86401c0d500e80e2b 100644
--- a/openair2/COMMON/f1ap_messages_types.h
+++ b/openair2/COMMON/f1ap_messages_types.h
@@ -39,6 +39,7 @@
 #define F1AP_INITIAL_UL_RRC_MESSAGE(mSGpTR)        (mSGpTR)->ittiMsg.f1ap_initial_ul_rrc_message
 #define F1AP_UL_RRC_MESSAGE(mSGpTR)                (mSGpTR)->ittiMsg.f1ap_ul_rrc_message
 #define F1AP_UE_CONTEXT_SETUP_REQ(mSGpTR)          (mSGpTR)->ittiMsg.f1ap_ue_context_setup_req
+#define F1AP_UE_CONTEXT_SETUP_RESP(mSGpTR)          (mSGpTR)->ittiMsg.f1ap_ue_context_setup_resp
 #define F1AP_UE_CONTEXT_RELEASE_RESP(mSGpTR)       (mSGpTR)->ittiMsg.f1ap_ue_context_release_resp
 #define F1AP_UE_CONTEXT_MODIFICATION_RESP(mSGpTR)  (mSGpTR)->ittiMsg.f1ap_ue_context_modification_resp
 #define F1AP_UE_CONTEXT_MODIFICATION_FAIL(mSGpTR)  (mSGpTR)->ittiMsg.f1ap_ue_context_modification_fail
@@ -71,6 +72,29 @@ typedef struct f1ap_cu_setup_req_s {
    //
 } f1ap_cu_setup_req_t;
 
+typedef struct cellIDs_s {
+
+  // Served Cell Information
+  /* Tracking area code */
+  uint32_t tac;
+
+  /* Mobile Country Codes
+   * Mobile Network Codes
+   */
+  uint16_t mcc;
+  uint16_t mnc;
+  uint8_t  mnc_digit_length;
+
+  // NR Global Cell Id
+  uint64_t nr_cellid;
+  // NR Physical Cell Ids
+  uint16_t nr_pci;
+  // Number of slide support items (max 16, could be increased to as much as 1024)
+  uint16_t num_ssi;
+  uint8_t sst;
+  uint8_t sd;
+} cellIDs_t;
+
 typedef struct f1ap_setup_req_s {
 
   // Midhaul networking parameters
@@ -84,6 +108,8 @@ typedef struct f1ap_setup_req_s {
   /* The eNB IP address to bind */
   f1ap_net_ip_address_t CU_f1_ip_address;
   f1ap_net_ip_address_t DU_f1_ip_address;
+  uint16_t CUport;
+  uint16_t DUport;
 
   /* Number of SCTP streams used for a mme association */
   uint16_t sctp_in_streams;
@@ -100,31 +126,12 @@ typedef struct f1ap_setup_req_s {
   
   /// number of DU cells available
   uint16_t num_cells_available; //0< num_cells_available <= 512;
-
-  // Served Cell Information
-  /* Tracking area code */
-  uint32_t tac[F1AP_MAX_NB_CELLS];
-
-  /* Mobile Country Codes
-   * Mobile Network Codes
-   */
-  uint16_t mcc[F1AP_MAX_NB_CELLS];//[6];
-  uint16_t mnc[F1AP_MAX_NB_CELLS];//[6];
-  uint8_t  mnc_digit_length[F1AP_MAX_NB_CELLS];//[6];
-
-  // NR Global Cell Id
-  uint64_t nr_cellid[F1AP_MAX_NB_CELLS];
-  // NR Physical Cell Ids
-  uint16_t nr_pci[F1AP_MAX_NB_CELLS];
-  // Number of slide support items (max 16, could be increased to as much as 1024)
-  uint16_t num_ssi[F1AP_MAX_NB_CELLS];//[6];
-  uint8_t sst[F1AP_MAX_NB_CELLS];//[16][6];
-  uint8_t sd[F1AP_MAX_NB_CELLS];//[16][6];
+  cellIDs_t cell[F1AP_MAX_NB_CELLS];
   // fdd_flag = 1 means FDD, 0 means TDD
   int  fdd_flag;
 
   union {
-    struct {
+    struct fdd_s {
       uint32_t ul_nr_arfcn;
       uint8_t ul_scs;
       uint8_t ul_nrb;
@@ -148,7 +155,7 @@ typedef struct f1ap_setup_req_s {
       uint8_t dl_num_sul_frequency_bands;
       uint16_t dl_nr_sul_band[32];
     } fdd;
-    struct {
+    struct tdd_s {
 
       uint32_t nr_arfcn;
       uint8_t scs;
@@ -195,6 +202,7 @@ typedef struct served_cells_to_activate_s {
   /// SI message containers (up to 21 messages per cell)
   uint8_t *SI_container[21];
   int      SI_container_length[21];
+  int SI_type[21];
 } served_cells_to_activate_t;
 
 typedef struct f1ap_setup_resp_s {
@@ -299,7 +307,7 @@ typedef struct f1ap_initial_ul_rrc_message_s {
   uint16_t crnti;
   uint8_t *rrc_container;
   int      rrc_container_length;
-  int8_t *du2cu_rrc_container;
+  char du2cu_rrc_container[200];
   int      du2cu_rrc_container_length;
 } f1ap_initial_ul_rrc_message_t;
 
@@ -312,19 +320,32 @@ typedef struct f1ap_ul_rrc_message_s {
 
 typedef struct f1ap_up_tnl_s {
   in_addr_t tl_address; // currently only IPv4 supported
-  uint32_t  gtp_teid;
+  teid_t  teid;
+  uint16_t port;
 } f1ap_up_tnl_t;
 
 typedef struct f1ap_drb_to_be_setup_s {
-  uint8_t        drb_id;
+  long           drb_id;
   f1ap_up_tnl_t  up_ul_tnl[2];
   uint8_t        up_ul_tnl_length;
+  f1ap_up_tnl_t  up_dl_tnl[2];
+  uint8_t        up_dl_tnl_length;
   rlc_mode_t     rlc_mode;
 } f1ap_drb_to_be_setup_t;
 
-typedef struct f1ap_ue_context_setup_req_s {
+typedef struct f1ap_srb_to_be_setup_s {
+  long           srb_id;
+  rlc_mode_t     rlc_mode;
+  uint8_t        lcid;
+} f1ap_srb_to_be_setup_t;
+
+typedef struct f1ap_rb_failed_to_be_setup_s {
+  long           rb_id;
+} f1ap_rb_failed_to_be_setup_t;
+
+typedef struct f1ap_ue_context_setup_s {
   uint32_t gNB_CU_ue_id;    // BK: need to replace by use from rnti
-  uint32_t *gNB_DU_ue_id;
+  uint32_t gNB_DU_ue_id;
   uint16_t rnti; 
   // SpCell Info
   uint16_t mcc;
@@ -336,13 +357,37 @@ typedef struct f1ap_ue_context_setup_req_s {
   uint32_t servCellId;
   uint8_t *cu_to_du_rrc_information;
   uint8_t  cu_to_du_rrc_information_length;
+  uint8_t *du_to_cu_rrc_information;
+  uint8_t  du_to_cu_rrc_information_length;
   f1ap_drb_to_be_setup_t *drbs_to_be_setup; // BK: need to replace by s1ap_initial_context_setup_req
   uint8_t  drbs_to_be_setup_length;       // BK: need to replace by s1ap_initial_context_setup_req
+  uint8_t  drbs_failed_to_be_setup_length;
+  f1ap_rb_failed_to_be_setup_t *drbs_failed_to_be_setup;
+  f1ap_srb_to_be_setup_t *srbs_to_be_setup;
+  uint8_t  srbs_to_be_setup_length;
+  uint8_t  srbs_failed_to_be_setup_length;
+  f1ap_rb_failed_to_be_setup_t *srbs_failed_to_be_setup;
   s1ap_initial_context_setup_req_t *s1ap_initial_context_setup_req;
    // coniatner for the rrc_eNB_generate_SecurityModeCommand message
   uint8_t *rrc_container;
   int      rrc_container_length;
-} f1ap_ue_context_setup_req_t;
+} f1ap_ue_context_setup_t;
+
+typedef struct f1ap_ue_context_setup_resp_s {
+  uint32_t gNB_CU_ue_id;    // BK: need to replace by use from rnti
+  uint32_t gNB_DU_ue_id;
+  uint16_t rnti;
+  uint8_t  du_to_cu_rrc_information[1024 /*Arbitrarily big enough*/];
+  uint32_t  du_to_cu_rrc_information_length;
+  f1ap_drb_to_be_setup_t *drbs_setup; // BK: need to replace by s1ap_initial_context_setup_req
+  uint8_t  drbs_setup_length;       // BK: need to replace by s1ap_initial_context_setup_req
+  f1ap_srb_to_be_setup_t *srbs_setup;
+  uint8_t  srbs_setup_length;
+  uint8_t  srbs_failed_to_be_setup_length;
+  f1ap_rb_failed_to_be_setup_t *srbs_failed_to_be_setup;
+  uint8_t  drbs_failed_to_be_setup_length;
+  f1ap_rb_failed_to_be_setup_t *drbs_failed_to_be_setup;
+} f1ap_ue_context_setup_resp_t;
 
 typedef enum F1ap_Cause_e {
   F1AP_CAUSE_NOTHING,  /* No components present */
diff --git a/openair2/COMMON/gtpv1_u_messages_def.h b/openair2/COMMON/gtpv1_u_messages_def.h
index e5ce496701ad552f1431e6c3d5df622f934f1499..2835d07e4ae9c523c17411e1842fe5792473fa3b 100644
--- a/openair2/COMMON/gtpv1_u_messages_def.h
+++ b/openair2/COMMON/gtpv1_u_messages_def.h
@@ -29,9 +29,8 @@ MESSAGE_DEF(GTPV1U_ENB_DATA_FORWARDING_REQ, MESSAGE_PRIORITY_MED, gtpv1u_enb_dat
 MESSAGE_DEF(GTPV1U_ENB_DATA_FORWARDING_IND, MESSAGE_PRIORITY_MED, gtpv1u_enb_data_forwarding_ind_t,Gtpv1uDataForwardingInd)
 MESSAGE_DEF(GTPV1U_ENB_END_MARKER_REQ,      MESSAGE_PRIORITY_MED, gtpv1u_enb_end_marker_req_t,    Gtpv1uEndMarkerReq)
 MESSAGE_DEF(GTPV1U_ENB_END_MARKER_IND,      MESSAGE_PRIORITY_MED, gtpv1u_enb_end_marker_ind_t,    Gtpv1uEndMarkerInd)
-MESSAGE_DEF(GTPV1U_ENB_S1_REQ,        MESSAGE_PRIORITY_MED, Gtpv1uS1Req,    gtpv1uS1Req)
+MESSAGE_DEF(GTPV1U_REQ,        MESSAGE_PRIORITY_MED, Gtpv1uReq,    gtpv1uReq)
 
 MESSAGE_DEF(GTPV1U_GNB_DELETE_TUNNEL_REQ,   MESSAGE_PRIORITY_MED, gtpv1u_gnb_delete_tunnel_req_t,  NRGtpv1uDeleteTunnelReq)
 MESSAGE_DEF(GTPV1U_GNB_DELETE_TUNNEL_RESP,  MESSAGE_PRIORITY_MED, gtpv1u_gnb_delete_tunnel_resp_t, NRGtpv1uDeleteTunnelResp)
-MESSAGE_DEF(GTPV1U_GNB_NG_REQ,              MESSAGE_PRIORITY_MED, Gtpv1uNGReq,                     gtpv1uNGReq)
 MESSAGE_DEF(GTPV1U_GNB_TUNNEL_DATA_REQ,     MESSAGE_PRIORITY_MED, gtpv1u_gnb_tunnel_data_req_t,    NRGtpv1uTunnelDataReq)
diff --git a/openair2/COMMON/gtpv1_u_messages_types.h b/openair2/COMMON/gtpv1_u_messages_types.h
index 3c820765103c917cdaaf7a54e3f36e4fd38b1061..2dd476ab686c06a950294334c6e5bf90150154ed 100644
--- a/openair2/COMMON/gtpv1_u_messages_types.h
+++ b/openair2/COMMON/gtpv1_u_messages_types.h
@@ -39,11 +39,10 @@
 #define GTPV1U_ENB_END_MARKER_REQ(mSGpTR)     (mSGpTR)->ittiMsg.Gtpv1uEndMarkerReq
 #define GTPV1U_ENB_END_MARKER_IND(mSGpTR)     (mSGpTR)->ittiMsg.Gtpv1uEndMarkerInd
 
-#define GTPV1U_ENB_S1_REQ(mSGpTR)    (mSGpTR)->ittiMsg.gtpv1uS1Req
+#define GTPV1U_REQ(mSGpTR)    (mSGpTR)->ittiMsg.gtpv1uReq
 
 #define GTPV1U_GNB_DELETE_TUNNEL_REQ(mSGpTR)  (mSGpTR)->ittiMsg.NRGtpv1uDeleteTunnelReq
 #define GTPV1U_GNB_DELETE_TUNNEL_RESP(mSGpTR) (mSGpTR)->ittiMsg.NRGtpv1uDeleteTunnelResp
-#define GTPV1U_GNB_NG_REQ(mSGpTR)             (mSGpTR)->ittiMsg.gtpv1uNGReq
 #define GTPV1U_GNB_TUNNEL_DATA_REQ(mSGpTR)    (mSGpTR)->ittiMsg.NRGtpv1uTunnelDataReq
 
 #define GTPV1U_ALL_TUNNELS_TEID (teid_t)0xFFFFFFFF
@@ -174,25 +173,23 @@ typedef struct gtpv1u_enb_end_marker_ind_s {
 } gtpv1u_enb_end_marker_ind_t;
 
 typedef struct {
-  in_addr_t             enb_ip_address_for_S1u_S12_S4_up;
-  tcp_udp_port_t        enb_port_for_S1u_S12_S4_up;
-  char                  addrStr[256];
-  char                  portStr[256];
-} Gtpv1uS1Req;
+  in_addr_t             localAddr;
+  tcp_udp_port_t        localPort;
+  char                  localAddrStr[256];
+  char                  localPortStr[256];
+} Gtpv1uReq;
+
 
-typedef struct {
-  in_addr_t             gnb_ip_address_for_NGu_up;
-  tcp_udp_port_t        gnb_port_for_NGu_up;
-  char                  addrStr[256];
-  char                  portStr[256];
-} Gtpv1uNGReq;
 typedef struct gtpv1u_gnb_create_tunnel_req_s {
   rnti_t                 rnti;
   int                    num_tunnels;
-  teid_t                 upf_NGu_teid[NR_GTPV1U_MAX_BEARERS_PER_UE];  ///< Tunnel Endpoint Identifier
+  //teid_t                 upf_NGu_teid[NR_GTPV1U_MAX_BEARERS_PER_UE];  ///< Tunnel Endpoint Identifier
+  teid_t                 outgoing_teid[NR_GTPV1U_MAX_BEARERS_PER_UE];
   pdusessionid_t         pdusession_id[NR_GTPV1U_MAX_BEARERS_PER_UE];
   ebi_t                  incoming_rb_id[NR_GTPV1U_MAX_BEARERS_PER_UE];
-  transport_layer_addr_t upf_addr[NR_GTPV1U_MAX_BEARERS_PER_UE];
+  //ebi_t                  outgoing_rb_id[NR_GTPV1U_MAX_BEARERS_PER_UE];
+  //transport_layer_addr_t upf_addr[NR_GTPV1U_MAX_BEARERS_PER_UE];
+  transport_layer_addr_t dst_addr[NR_GTPV1U_MAX_BEARERS_PER_UE];
 } gtpv1u_gnb_create_tunnel_req_t;
 
 typedef struct gtpv1u_gnb_create_tunnel_resp_s {
diff --git a/openair2/COMMON/mac_messages_types.h b/openair2/COMMON/mac_messages_types.h
index a9336a58a999817c90f7bbe571134d9d29f57e54..cad7b9f172b645d0e182f78fc8899fcae3ca6c10 100644
--- a/openair2/COMMON/mac_messages_types.h
+++ b/openair2/COMMON/mac_messages_types.h
@@ -147,6 +147,7 @@ typedef struct NRRrcMacCcchDataInd_s {
   OCTET_STRING_t *du_to_cu_rrc_container;
   uint8_t   gnb_index;
   int       CC_id;
+  uint64_t  nr_cellid;
 } NRRrcMacCcchDataInd;
 
 typedef struct RrcMacMcchDataReq_s {
diff --git a/openair2/COMMON/pdcp_messages_def.h b/openair2/COMMON/pdcp_messages_def.h
index 59d47eb81b992c660c4d9b47a3e19724edf01189..5392c9e04dfe9e069f473b23f898deb136479924 100644
--- a/openair2/COMMON/pdcp_messages_def.h
+++ b/openair2/COMMON/pdcp_messages_def.h
@@ -31,6 +31,8 @@
 MESSAGE_DEF(RRC_DCCH_DATA_REQ,          MESSAGE_PRIORITY_MED_PLUS, RrcDcchDataReq,              rrc_dcch_data_req)
 MESSAGE_DEF(RRC_DCCH_DATA_IND,          MESSAGE_PRIORITY_MED_PLUS, RrcDcchDataInd,              rrc_dcch_data_ind)
 MESSAGE_DEF(RRC_PCCH_DATA_REQ,          MESSAGE_PRIORITY_MED_PLUS, RrcPcchDataReq,              rrc_pcch_data_req)
+MESSAGE_DEF(RRC_NRUE_CAP_INFO_IND,      MESSAGE_PRIORITY_MED_PLUS, RrcDcchDataInd,          rrc_nrue_cap_info_ind)
+MESSAGE_DEF(RRC_DCCH_DATA_COPY_IND,     MESSAGE_PRIORITY_MED_PLUS, RrcDcchDataInd,         rrc_dcch_data_copy_ind)
 
 // gNB
 MESSAGE_DEF(NR_RRC_DCCH_DATA_REQ,       MESSAGE_PRIORITY_MED_PLUS, NRRrcDcchDataReq,           nr_rrc_dcch_data_req)
diff --git a/openair2/COMMON/pdcp_messages_types.h b/openair2/COMMON/pdcp_messages_types.h
index 0390fd80f440dc8af4c02971991085d2ec89799a..d7c84a24a14a6c8cd0284e47b319df6c9ddb40ff 100644
--- a/openair2/COMMON/pdcp_messages_types.h
+++ b/openair2/COMMON/pdcp_messages_types.h
@@ -34,6 +34,8 @@
 #define RRC_DCCH_DATA_REQ(mSGpTR)               (mSGpTR)->ittiMsg.rrc_dcch_data_req
 #define RRC_DCCH_DATA_IND(mSGpTR)               (mSGpTR)->ittiMsg.rrc_dcch_data_ind
 #define RRC_PCCH_DATA_REQ(mSGpTR)               (mSGpTR)->ittiMsg.rrc_pcch_data_req
+#define RRC_NRUE_CAP_INFO_IND(mSGpTR)           (mSGpTR)->ittiMsg.rrc_nrue_cap_info_ind
+#define RRC_DCCH_DATA_COPY_IND(mSGpTR)          (mSGpTR)->ittiMsg.rrc_dcch_data_copy_ind
 
 // gNB
 #define NR_RRC_DCCH_DATA_REQ(mSGpTR)            (mSGpTR)->ittiMsg.nr_rrc_dcch_data_req
@@ -65,6 +67,13 @@ typedef struct RrcDcchDataInd_s {
   uint8_t      eNB_index; // LG: needed in UE
 } RrcDcchDataInd;
 
+typedef struct RrcDcchDataCopyInd_s {
+  uint8_t dcch_index;
+  uint32_t sdu_size;
+  uint8_t *sdu_p;
+  uint8_t      eNB_index;
+} RrcDcchDataCopyInd;
+
 typedef struct NRRrcDcchDataReq_s {
   uint32_t frame;
   uint8_t  gnb_flag;
diff --git a/openair2/COMMON/platform_constants.h b/openair2/COMMON/platform_constants.h
index 355f56f9c9356bfa13acebd645ae6191f7f62dbb..d40965052899ee87e6c1fe15e40764372f25f555 100644
--- a/openair2/COMMON/platform_constants.h
+++ b/openair2/COMMON/platform_constants.h
@@ -75,9 +75,9 @@
       #define MAX_eNB                      2
       #define MAX_gNB                      2
     #else
-      #define MAX_MOBILES_PER_ENB         4
-      #define MAX_MOBILES_PER_ENB_NB_IoT  4
-      #define MAX_MOBILES_PER_GNB         4//16
+      #define MAX_MOBILES_PER_ENB         40
+      #define MAX_MOBILES_PER_ENB_NB_IoT  40
+      #define MAX_MOBILES_PER_GNB         16
       #define MAX_eNB                      2
       #define MAX_gNB                      2
     #endif
diff --git a/openair2/COMMON/platform_types.h b/openair2/COMMON/platform_types.h
index 23b33dd8b13ab1f8249942f2e304c5e800d72dd4..c24291de645460de2e063368cfb0566c82e54273 100644
--- a/openair2/COMMON/platform_types.h
+++ b/openair2/COMMON/platform_types.h
@@ -212,6 +212,14 @@ typedef enum config_action_e {
   CONFIG_ACTION_MBMS_MODIFY       = 11
 } config_action_t;
 
+/* Maximum size of any message we might send or receive (e.g., via a socket) */
+#define MAX_MESSAGE_SIZE 8192
+
+typedef struct nsa_msg_t {
+  uint8_t msg_type;
+  uint8_t msg_buffer[MAX_MESSAGE_SIZE];
+} nsa_msg_t;
+
 //-----------------------------------------------------------------------------
 // GTPV1U TYPES
 //-----------------------------------------------------------------------------
@@ -233,7 +241,6 @@ typedef struct protocol_ctxt_s {
   frame_t     frame;         /*!< \brief  LTE frame number.*/
   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  */
   boolean_t		brOption;
 } protocol_ctxt_t;
 // warning time hardcoded
diff --git a/openair2/COMMON/rrc_messages_def.h b/openair2/COMMON/rrc_messages_def.h
index cde2497880849bccbbbafb3c5e787a946eddde17..35caf3c34274b8603fb4e9fccce25c8b924b88e7 100644
--- a/openair2/COMMON/rrc_messages_def.h
+++ b/openair2/COMMON/rrc_messages_def.h
@@ -65,6 +65,8 @@ MESSAGE_DEF(NAS_UPLINK_DATA_REQ,        MESSAGE_PRIORITY_MED,       NasUlDataReq
 
 MESSAGE_DEF(NAS_RAB_ESTABLI_RSP,        MESSAGE_PRIORITY_MED,       NasRabEstRsp,               nas_rab_est_rsp)
 
+MESSAGE_DEF(NAS_OAI_TUN_NSA,            MESSAGE_PRIORITY_MED,       NasOaiTunNsa,               nas_oai_tun_nsa)
+
 // UE: RRC -> NAS messages
 MESSAGE_DEF(NAS_CELL_SELECTION_CNF,     MESSAGE_PRIORITY_MED,       NasCellSelectionCnf,        nas_cell_selection_cnf)
 MESSAGE_DEF(NAS_CELL_SELECTION_IND,     MESSAGE_PRIORITY_MED,       NasCellSelectionInd,        nas_cell_selection_ind)
@@ -79,3 +81,5 @@ MESSAGE_DEF(RRC_SUBFRAME_PROCESS,       MESSAGE_PRIORITY_MED,       RrcSubframeP
 
 // eNB: RLC -> RRC messages
 MESSAGE_DEF(RLC_SDU_INDICATION,         MESSAGE_PRIORITY_MED,       RlcSduIndication,           rlc_sdu_indication)
+
+MESSAGE_DEF(NR_DU_RRC_DL_INDICATION,    MESSAGE_PRIORITY_MED,       NRDuDlReq_t,                nr_du_dl_req)
diff --git a/openair2/COMMON/rrc_messages_types.h b/openair2/COMMON/rrc_messages_types.h
index e1886b57ffa698978a9223a7df02d2386859ee3c..63a581b37b1c387af714f189e8f537282e10db91 100644
--- a/openair2/COMMON/rrc_messages_types.h
+++ b/openair2/COMMON/rrc_messages_types.h
@@ -89,6 +89,9 @@
 #define RRC_SUBFRAME_PROCESS(mSGpTR)    (mSGpTR)->ittiMsg.rrc_subframe_process
 
 #define RLC_SDU_INDICATION(mSGpTR)      (mSGpTR)->ittiMsg.rlc_sdu_indication
+#define NRDuDlReq(mSGpTR)      (mSGpTR)->ittiMsg.nr_du_dl_req
+
+#define NAS_OAI_TUN_NSA(mSGpTR)         (mSGpTR)->ittiMsg.nas_oai_tun_nsa
 
 //-------------------------------------------------------------------------------------------//
 typedef struct RrcStateInd_s {
@@ -418,6 +421,11 @@ typedef struct NRRrcConfigurationReq_s {
   int                     pucch_TargetSNRx10;
 } gNB_RrcConfigurationReq;
 
+typedef struct NRDuDlReq_s {
+  rnti_t rnti;
+  mem_block_t * buf;
+  uint64_t srb_id;
+}  NRDuDlReq_t; 
 
 // UE: NAS -> RRC messages
 typedef kenb_refresh_req_t      NasKenbRefreshReq;
@@ -427,6 +435,8 @@ typedef ul_info_transfer_req_t  NasUlDataReq;
 
 typedef rab_establish_rsp_t     NasRabEstRsp;
 
+typedef nas_oai_tun_nsa_t       NasOaiTunNsa;
+
 // UE: RRC -> NAS messages
 typedef cell_info_cnf_t         NasCellSelectionCnf;
 typedef cell_info_ind_t         NasCellSelectionInd;
diff --git a/openair2/ENB_APP/enb_config.c b/openair2/ENB_APP/enb_config.c
index 4751596931cbbb78d7acdb7162cdb37d8b15f5a8..a08bcf4baf96e922a754a319362693329217ec03 100644
--- a/openair2/ENB_APP/enb_config.c
+++ b/openair2/ENB_APP/enb_config.c
@@ -1925,6 +1925,7 @@ int RCconfig_DU_F1(MessageDef *msg_p, uint32_t i) {
     AssertFatal(ENBParamList.paramarray[i][ENB_ENB_ID_IDX].uptr != NULL,
                 "eNB id %u is not defined in configuration file\n",i);
     F1AP_SETUP_REQ (msg_p).num_cells_available = 0;
+    F1AP_SETUP_REQ (msg_p).cell_type = CELL_MACRO_ENB;
 
     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) {
@@ -1945,20 +1946,20 @@ int RCconfig_DU_F1(MessageDef *msg_p, uint32_t i) {
         LOG_I(ENB_APP,"F1AP: gNB_DU_id[%d] %ld\n",k,F1AP_SETUP_REQ (msg_p).gNB_DU_id);
         F1AP_SETUP_REQ (msg_p).gNB_DU_name      = strdup(*(ENBParamList.paramarray[0][ENB_ENB_NAME_IDX].strptr));
         LOG_I(ENB_APP,"F1AP: gNB_DU_name[%d] %s\n",k,F1AP_SETUP_REQ (msg_p).gNB_DU_name);
-        F1AP_SETUP_REQ (msg_p).tac[k]              = *ENBParamList.paramarray[i][ENB_TRACKING_AREA_CODE_IDX].uptr;
-        LOG_I(ENB_APP,"F1AP: tac[%d] %d\n",k,F1AP_SETUP_REQ (msg_p).tac[k]);
-        F1AP_SETUP_REQ (msg_p).mcc[k]              = *PLMNParamList.paramarray[0][ENB_MOBILE_COUNTRY_CODE_IDX].uptr;
-        LOG_I(ENB_APP,"F1AP: mcc[%d] %d\n",k,F1AP_SETUP_REQ (msg_p).mcc[k]);
-        F1AP_SETUP_REQ (msg_p).mnc[k]              = *PLMNParamList.paramarray[0][ENB_MOBILE_NETWORK_CODE_IDX].uptr;
-        LOG_I(ENB_APP,"F1AP: mnc[%d] %d\n",k,F1AP_SETUP_REQ (msg_p).mnc[k]);
-        F1AP_SETUP_REQ (msg_p).mnc_digit_length[k] = *PLMNParamList.paramarray[0][ENB_MNC_DIGIT_LENGTH].u8ptr;
-        LOG_I(ENB_APP,"F1AP: mnc_digit_length[%d] %d\n",k,F1AP_SETUP_REQ (msg_p).mnc_digit_length[k]);
-        AssertFatal((F1AP_SETUP_REQ (msg_p).mnc_digit_length[k] == 2) ||
-                    (F1AP_SETUP_REQ (msg_p).mnc_digit_length[k] == 3),
+        F1AP_SETUP_REQ (msg_p).cell[k].tac              = *ENBParamList.paramarray[i][ENB_TRACKING_AREA_CODE_IDX].uptr;
+        LOG_I(ENB_APP,"F1AP: tac[%d] %d\n",k,F1AP_SETUP_REQ (msg_p).cell[k].tac);
+        F1AP_SETUP_REQ (msg_p).cell[k].mcc              = *PLMNParamList.paramarray[0][ENB_MOBILE_COUNTRY_CODE_IDX].uptr;
+        LOG_I(ENB_APP,"F1AP: mcc[%d] %d\n",k,F1AP_SETUP_REQ (msg_p).cell[k].mcc);
+        F1AP_SETUP_REQ (msg_p).cell[k].mnc              = *PLMNParamList.paramarray[0][ENB_MOBILE_NETWORK_CODE_IDX].uptr;
+        LOG_I(ENB_APP,"F1AP: mnc[%d] %d\n",k,F1AP_SETUP_REQ (msg_p).cell[k].mnc);
+        F1AP_SETUP_REQ (msg_p).cell[k].mnc_digit_length = *PLMNParamList.paramarray[0][ENB_MNC_DIGIT_LENGTH].u8ptr;
+        LOG_I(ENB_APP,"F1AP: mnc_digit_length[%d] %d\n",k,F1AP_SETUP_REQ (msg_p).cell[k].mnc_digit_length);
+        AssertFatal((F1AP_SETUP_REQ (msg_p).cell[k].mnc_digit_length == 2) ||
+                    (F1AP_SETUP_REQ (msg_p).cell[k].mnc_digit_length == 3),
                     "BAD MNC DIGIT LENGTH %d",
-                    F1AP_SETUP_REQ (msg_p).mnc_digit_length[k]);
-        F1AP_SETUP_REQ (msg_p).nr_cellid[k] = (uint64_t)*(ENBParamList.paramarray[i][ENB_NRCELLID_IDX].u64ptr);
-        LOG_I(ENB_APP,"F1AP: nr_cellid[%d] %ld\n",k,F1AP_SETUP_REQ (msg_p).nr_cellid[k]);
+                    F1AP_SETUP_REQ (msg_p).cell[k].mnc_digit_length);
+        F1AP_SETUP_REQ (msg_p).cell[k].nr_cellid = (uint64_t)*(ENBParamList.paramarray[i][ENB_NRCELLID_IDX].u64ptr);
+        LOG_I(ENB_APP,"F1AP: nr_cellid[%d] %ld\n",k,F1AP_SETUP_REQ (msg_p).cell[k].nr_cellid);
         LOG_I(ENB_APP,"F1AP: CU_ip4_address in DU %s\n",RC.mac[k]->eth_params_n.remote_addr);
         LOG_I(ENB_APP,"FIAP: CU_ip4_address in DU %p, strlen %d\n",F1AP_SETUP_REQ (msg_p).CU_f1_ip_address.ipv4_address,(int)strlen(RC.mac[k]->eth_params_n.remote_addr));
         F1AP_SETUP_REQ (msg_p).CU_f1_ip_address.ipv6 = 0;
@@ -1969,8 +1970,11 @@ int RCconfig_DU_F1(MessageDef *msg_p, uint32_t i) {
         LOG_I(ENB_APP,"FIAP: DU_ip4_address in DU %p, strlen %d\n",F1AP_SETUP_REQ (msg_p).DU_f1_ip_address.ipv4_address,(int)strlen(RC.mac[k]->eth_params_n.my_addr));
         F1AP_SETUP_REQ (msg_p).DU_f1_ip_address.ipv6 = 0;
         F1AP_SETUP_REQ (msg_p).DU_f1_ip_address.ipv4 = 1;
+	
         //strcpy(F1AP_SETUP_REQ (msg_p).DU_f1_ip_address.ipv6_address, "");
         strcpy(F1AP_SETUP_REQ (msg_p).DU_f1_ip_address.ipv4_address, RC.mac[k]->eth_params_n.my_addr);
+	F1AP_SETUP_REQ (msg_p).DUport= RC.mac[k]->eth_params_n.my_portd;
+	F1AP_SETUP_REQ (msg_p).CUport= RC.mac[k]->eth_params_n.remote_portd;
         //strcpy(F1AP_SETUP_REQ (msg_p).CU_ip_address[l].ipv6_address,*(F1ParamList.paramarray[l][ENB_CU_IPV6_ADDRESS_IDX].strptr));
         //F1AP_SETUP_REQ (msg_p).CU_port = RC.mac[k]->eth_params_n.remote_portc; // maybe we dont need it
         sprintf(aprefix,"%s.[%i].%s",ENB_CONFIG_STRING_ENB_LIST,k,ENB_CONFIG_STRING_SCTP_CONFIG);
@@ -1989,12 +1993,12 @@ int RCconfig_DU_F1(MessageDef *msg_p, uint32_t i) {
           pthread_mutex_unlock(&rrc->cell_info_mutex);
         } while (cell_info_configured ==0);
 
-        rrc->configuration.mcc[0] = F1AP_SETUP_REQ (msg_p).mcc[k];
-        rrc->configuration.mnc[0] = F1AP_SETUP_REQ (msg_p).mnc[k];
-        rrc->configuration.tac    = F1AP_SETUP_REQ (msg_p).tac[k];
-        rrc->nr_cellid = F1AP_SETUP_REQ (msg_p).nr_cellid[k];
-        F1AP_SETUP_REQ (msg_p).nr_pci[k]    = rrc->carrier[0].physCellId;
-        F1AP_SETUP_REQ (msg_p).num_ssi[k] = 0;
+        rrc->configuration.mcc[0] = F1AP_SETUP_REQ (msg_p).cell[k].mcc;
+        rrc->configuration.mnc[0] = F1AP_SETUP_REQ (msg_p).cell[k].mnc;
+        rrc->configuration.tac    = F1AP_SETUP_REQ (msg_p).cell[k].tac;
+        rrc->nr_cellid = F1AP_SETUP_REQ (msg_p).cell[k].nr_cellid;
+        F1AP_SETUP_REQ (msg_p).cell[k].nr_pci    = rrc->carrier[0].physCellId;
+        F1AP_SETUP_REQ (msg_p).cell[k].num_ssi = 0;
 
         if (rrc->carrier[0].sib1->tdd_Config) {
           LOG_I(ENB_APP,"ngran_DU: Configuring Cell %d for TDD\n",k);
@@ -2070,12 +2074,12 @@ int RCconfig_gtpu(void ) {
 
   if (address) {
     MessageDef *message;
-    AssertFatal((message = itti_alloc_new_message(TASK_ENB_APP, 0, GTPV1U_ENB_S1_REQ))!=NULL,"");
-    IPV4_STR_ADDR_TO_INT_NWBO ( address, GTPV1U_ENB_S1_REQ(message).enb_ip_address_for_S1u_S12_S4_up, "BAD IP ADDRESS FORMAT FOR eNB S1_U !\n" );
-    LOG_I(GTPU,"Configuring GTPu address : %s -> %x\n",address,GTPV1U_ENB_S1_REQ(message).enb_ip_address_for_S1u_S12_S4_up);
-    GTPV1U_ENB_S1_REQ(message).enb_port_for_S1u_S12_S4_up = enb_port_for_S1U;
-    strcpy(GTPV1U_ENB_S1_REQ(message).addrStr,address);
-    sprintf(GTPV1U_ENB_S1_REQ(message).portStr,"%d", enb_port_for_S1U);
+    AssertFatal((message = itti_alloc_new_message(TASK_ENB_APP, 0, GTPV1U_REQ))!=NULL,"");
+    IPV4_STR_ADDR_TO_INT_NWBO ( address, GTPV1U_REQ(message).localAddr, "BAD IP ADDRESS FORMAT FOR eNB S1_U !\n" );
+    LOG_I(GTPU,"Configuring GTPu address : %s -> %x\n",address,GTPV1U_REQ(message).localAddr);
+    GTPV1U_REQ(message).localPort = enb_port_for_S1U;
+    strcpy(GTPV1U_REQ(message).localAddrStr,address);
+    sprintf(GTPV1U_REQ(message).localPortStr,"%d", enb_port_for_S1U);
     itti_send_msg_to_task (TASK_VARIABLE, 0, message); // data model is wrong: gtpu doesn't have enb_id (or module_id)
   } else
     LOG_E(GTPU,"invalid address for S1U\n");
@@ -3167,7 +3171,7 @@ void handle_f1ap_setup_resp(f1ap_setup_resp_t *resp) {
           (check_plmn_identity(carrier, resp->cells_to_activate[j].mcc, resp->cells_to_activate[j].mnc, resp->cells_to_activate[j].mnc_digit_length)>0 &&
            resp->cells_to_activate[j].nrpci == carrier->physCellId)) {
         // copy system information and decode it
-        for (si_ind=2; si_ind<resp->cells_to_activate[j].num_SI + 2; si_ind++)  {
+        for (si_ind=0; si_ind<resp->cells_to_activate[j].num_SI; si_ind++)  {
           //printf("SI %d size %d: ", si_ind, resp->cells_to_activate[j].SI_container_length[si_ind]);
           //for (int n=0;n<resp->cells_to_activate[j].SI_container_length[si_ind];n++)
           //  printf("%02x ",resp->cells_to_activate[j].SI_container[si_ind][n]);
@@ -3175,7 +3179,7 @@ void handle_f1ap_setup_resp(f1ap_setup_resp_t *resp) {
           if (si_ind==6) si_ind=9;
           if (resp->cells_to_activate[j].SI_container[si_ind] != NULL) {
             extract_and_decode_SI(i,
-                                  si_ind,
+                                  resp->cells_to_activate[j].SI_type[si_ind],
                                   resp->cells_to_activate[j].SI_container[si_ind],
                                   resp->cells_to_activate[j].SI_container_length[si_ind]);
           }
diff --git a/openair2/F1AP/dummy_enb.c b/openair2/F1AP/dummy_enb.c
index fe6dfb6a06af9f3130cc418a4136ac6f1e487fc6..d54f9b8df7b21bb90ec9ea8ca182f785e7e20787 100644
--- a/openair2/F1AP/dummy_enb.c
+++ b/openair2/F1AP/dummy_enb.c
@@ -29,6 +29,19 @@
 void apply_macrlc_config(gNB_RRC_INST *rrc,
                          rrc_gNB_ue_context_t         *const ue_context_pP,
                          const protocol_ctxt_t        *const ctxt_pP ) {
-abort();
+  abort();
 }
 
+boolean_t sdap_gnb_data_req(protocol_ctxt_t *ctxt_p,
+                            const srb_flag_t srb_flag,
+                            const rb_id_t rb_id,
+                            const mui_t mui,
+                            const confirm_t confirm,
+                            const sdu_size_t sdu_buffer_size,
+                            unsigned char *const sdu_buffer,
+                            const pdcp_transmission_mode_t pt_mode,
+                            const uint32_t *sourceL2Id,
+                            const uint32_t *destinationL2Id
+                           ) {
+abort();
+}
diff --git a/openair2/F1AP/f1ap_common.c b/openair2/F1AP/f1ap_common.c
index 267626dd5ceecddea419461d7b2f7895d3430915..338b5f0c2b89e577c8651213a4681f1f5bf2f534 100644
--- a/openair2/F1AP/f1ap_common.c
+++ b/openair2/F1AP/f1ap_common.c
@@ -32,19 +32,22 @@
 
 #include "f1ap_common.h"
 
+static f1ap_cudu_inst_t *f1_du_inst[NUMBER_OF_eNB_MAX]= {0};
+static f1ap_cudu_inst_t *f1_cu_inst[NUMBER_OF_eNB_MAX]= {0};
+
 #if defined(EMIT_ASN_DEBUG_EXTERN)
 int asn_debug = 0;
 int asn1_xer_print = 0;
 
-inline void ASN_DEBUG(const char *fmt, ...)
-{
+inline void ASN_DEBUG(const char *fmt, ...) {
   if (asn_debug) {
     int adi = asn_debug_indent;
     va_list ap;
     va_start(ap, fmt);
     fprintf(stderr, "[ASN1]");
 
-    while(adi--) fprintf(stderr, " ");
+    while(adi--)
+      fprintf(stderr, " ");
 
     vfprintf(stderr, fmt, ap);
     fprintf(stderr, "\n");
@@ -53,142 +56,157 @@ inline void ASN_DEBUG(const char *fmt, ...)
 }
 #endif
 
-uint8_t F1AP_get_next_transaction_identifier(module_id_t enb_mod_idP, module_id_t cu_mod_idP)
-{
+uint8_t F1AP_get_next_transaction_identifier(instance_t enb_mod_idP, instance_t cu_mod_idP) {
   static uint8_t transaction_identifier[NUMBER_OF_eNB_MAX];
   transaction_identifier[enb_mod_idP+cu_mod_idP] =
-      (transaction_identifier[enb_mod_idP+cu_mod_idP] + 1) % F1AP_TRANSACTION_IDENTIFIER_NUMBER;
+    (transaction_identifier[enb_mod_idP+cu_mod_idP] + 1) % F1AP_TRANSACTION_IDENTIFIER_NUMBER;
   //LOG_T(F1AP,"generated xid is %d\n",transaction_identifier[enb_mod_idP+cu_mod_idP]);
   return transaction_identifier[enb_mod_idP+cu_mod_idP];
 }
 
-int f1ap_add_ue(f1ap_cudu_inst_t    *f1_inst,
-                module_id_t          module_idP,
-                int                  CC_idP,
-                int                  UE_id,
+f1ap_cudu_inst_t *getCxt(F1_t isCU, instance_t instanceP) {
+  //Fixme: 4G F1 has race condtions, someone may debug it, using this test
+  /*
+    static pid_t t=-1;
+    pid_t tNew=gettid();
+    AssertFatal ( t==-1 || t==tNew, "This is not thread safe\n");
+    t=tNew;
+  */
+  AssertFatal( instanceP < sizeofArray(f1_cu_inst), "");
+  return isCU == CUtype ? f1_cu_inst[ instanceP]:  f1_du_inst[ instanceP];
+}
+
+void createF1inst(F1_t isCU, instance_t instanceP, f1ap_setup_req_t *req) {
+  if (isCU == CUtype) {
+    AssertFatal(f1_cu_inst[instanceP] == NULL, "Double call to F1 CU init\n");
+    f1_cu_inst[instanceP]=( f1ap_cudu_inst_t *) calloc(1, sizeof( f1ap_cudu_inst_t));
+    //memcpy(f1_cu_inst[instanceP]->setupReq, req, sizeof(f1ap_setup_req_t) );
+  } else {
+    AssertFatal(f1_du_inst[instanceP] == NULL, "Double call to F1 DU init\n");
+    f1_du_inst[instanceP]=( f1ap_cudu_inst_t *) calloc(1,  sizeof(f1ap_cudu_inst_t));
+    memcpy(&f1_du_inst[instanceP]->setupReq, req, sizeof(f1ap_setup_req_t) );
+  }
+}
+
+int f1ap_add_ue(F1_t isCu,
+                instance_t          instanceP,
                 rnti_t               rntiP) {
+  f1ap_cudu_inst_t *f1_inst=getCxt(isCu, instanceP);
+
   for (int i = 0; i < MAX_MOBILES_PER_ENB; i++) {
     if (f1_inst->f1ap_ue[i].rnti == rntiP) {
       f1_inst->f1ap_ue[i].f1ap_uid = i;
-      f1_inst->f1ap_ue[i].mac_uid = UE_id;
-      LOG_I(F1AP, "Updating the index of UE with RNTI %x and du_ue_f1ap_id %d\n", f1_inst->f1ap_ue[i].rnti, f1_inst->f1ap_ue[i].du_ue_f1ap_id);
+      LOG_I(F1AP, "Updating the index of UE with RNTI %x and du_ue_f1ap_id %ld\n", f1_inst->f1ap_ue[i].rnti, f1_inst->f1ap_ue[i].du_ue_f1ap_id);
       return i;
     }
   }
+
+  // We didn't find the rnti
   for (int i = 0; i < MAX_MOBILES_PER_ENB; i++) {
     if (f1_inst->f1ap_ue[i].rnti == 0 ) {
       f1_inst->f1ap_ue[i].rnti = rntiP;
       f1_inst->f1ap_ue[i].f1ap_uid = i;
-      f1_inst->f1ap_ue[i].mac_uid = UE_id;
       f1_inst->f1ap_ue[i].du_ue_f1ap_id = rntiP;
       f1_inst->f1ap_ue[i].cu_ue_f1ap_id = rntiP;
       f1_inst->num_ues++;
-      LOG_I(F1AP, "Adding a new UE with RNTI %x and cu/du ue_f1ap_id %d\n", f1_inst->f1ap_ue[i].rnti, f1_inst->f1ap_ue[i].du_ue_f1ap_id);
+      LOG_I(F1AP, "Adding a new UE with RNTI %x and cu/du ue_f1ap_id %ld\n", f1_inst->f1ap_ue[i].rnti, f1_inst->f1ap_ue[i].du_ue_f1ap_id);
       return i;
     }
   }
+
   return -1;
 }
 
 
-int f1ap_remove_ue(f1ap_cudu_inst_t *f1_inst,
+int f1ap_remove_ue(F1_t isCu, instance_t instanceP,
                    rnti_t            rntiP) {
+  f1ap_cudu_inst_t *f1_inst=getCxt(isCu, instanceP);
+
   for (int i = 0; i < MAX_MOBILES_PER_ENB; i++) {
     if (f1_inst->f1ap_ue[i].rnti == rntiP) {
       f1_inst->f1ap_ue[i].rnti = 0;
       break;
     }
   }
+
   f1_inst->num_ues--;
   return 0;
 }
 
-int f1ap_get_du_ue_f1ap_id(f1ap_cudu_inst_t *f1_inst,
-                            rnti_t            rntiP) {
+int f1ap_get_du_ue_f1ap_id(F1_t isCu, instance_t instanceP,
+                           rnti_t            rntiP) {
+  f1ap_cudu_inst_t *f1_inst=getCxt(isCu, instanceP);
+
   for (int i = 0; i < MAX_MOBILES_PER_ENB; i++) {
     if (f1_inst->f1ap_ue[i].rnti == rntiP) {
       return f1_inst->f1ap_ue[i].du_ue_f1ap_id;
     }
   }
+
   return -1;
 }
 
-int f1ap_get_cu_ue_f1ap_id(f1ap_cudu_inst_t *f1_inst,
-                            rnti_t            rntiP) {
+int f1ap_get_cu_ue_f1ap_id(F1_t isCu, instance_t instanceP,
+                           rnti_t            rntiP) {
+  f1ap_cudu_inst_t *f1_inst=getCxt(isCu, instanceP);
+
   for (int i = 0; i < MAX_MOBILES_PER_ENB; i++) {
     if (f1_inst->f1ap_ue[i].rnti == rntiP) {
       return f1_inst->f1ap_ue[i].cu_ue_f1ap_id;
     }
   }
+
   return -1;
 }
 
-int f1ap_get_rnti_by_du_id(f1ap_cudu_inst_t *f1_inst,
-                           module_id_t       du_ue_f1ap_id ) {
+int f1ap_get_rnti_by_du_id(F1_t isCu, instance_t instanceP,
+                           instance_t       du_ue_f1ap_id ) {
+  f1ap_cudu_inst_t *f1_inst=getCxt(isCu, instanceP);
+
   for (int i = 0; i < MAX_MOBILES_PER_ENB; i++) {
     if (f1_inst->f1ap_ue[i].du_ue_f1ap_id == du_ue_f1ap_id) {
       return f1_inst->f1ap_ue[i].rnti;
     }
   }
+
   return -1;
 }
 
-int f1ap_get_rnti_by_cu_id(f1ap_cudu_inst_t *f1_inst,
-                           module_id_t       cu_ue_f1ap_id ) {
+int f1ap_get_rnti_by_cu_id(F1_t isCu, instance_t instanceP,
+                           instance_t       cu_ue_f1ap_id ) {
+  f1ap_cudu_inst_t *f1_inst=getCxt(isCu, instanceP);
+
   for (int i = 0; i < MAX_MOBILES_PER_ENB; i++) {
     if (f1_inst->f1ap_ue[i].cu_ue_f1ap_id == cu_ue_f1ap_id) {
       return f1_inst->f1ap_ue[i].rnti;
     }
   }
-  return -1;
-}
 
-int f1ap_get_du_uid(f1ap_cudu_inst_t *f1_inst,
-                    module_id_t       du_ue_f1ap_id ) {
-  for (int i = 0; i < MAX_MOBILES_PER_ENB; i++) {
-    if (f1_inst->f1ap_ue[i].du_ue_f1ap_id == du_ue_f1ap_id) {
-      return i;
-    }
-  }
   return -1;
 }
 
-int f1ap_get_cu_uid(f1ap_cudu_inst_t *f1_inst,
-                    module_id_t       cu_ue_f1ap_id ) {
-  for (int i = 0; i < MAX_MOBILES_PER_ENB; i++) {
-    if (f1_inst->f1ap_ue[i].cu_ue_f1ap_id == cu_ue_f1ap_id) {
-      return i;
-    }
-  }
-  return -1;
-}
+int f1ap_du_add_cu_ue_id(instance_t instanceP,
+                         instance_t       du_ue_f1ap_id,
+                         instance_t       cu_ue_f1ap_id) {
+  f1ap_cudu_inst_t *f1_inst=getCxt(DUtype, instanceP);
+  instance_t f1ap_uid=-1;
 
-int f1ap_get_uid_by_rnti(f1ap_cudu_inst_t *f1_inst,
-                         rnti_t            rntiP ) {
   for (int i = 0; i < MAX_MOBILES_PER_ENB; i++) {
-    if (f1_inst->f1ap_ue[i].rnti == rntiP) {
-      return i;
+    if (f1_inst->f1ap_ue[i].du_ue_f1ap_id == du_ue_f1ap_id) {
+      f1ap_uid=i;
+      break;
     }
   }
-  return -1;
-}
 
-int f1ap_du_add_cu_ue_id(f1ap_cudu_inst_t *f1_inst,
-                         module_id_t       du_ue_f1ap_id,
-                         module_id_t       cu_ue_f1ap_id) {
-  module_id_t f1ap_uid = f1ap_get_du_uid(f1_inst,du_ue_f1ap_id);
-  if (f1ap_uid < 0 || f1ap_uid >= MAX_MOBILES_PER_ENB) return -1;
+  if (f1ap_uid < 0 || f1ap_uid >= MAX_MOBILES_PER_ENB)
+    return -1;
+
   f1_inst->f1ap_ue[f1ap_uid].cu_ue_f1ap_id = cu_ue_f1ap_id;
-  LOG_I(F1AP, "Adding cu_ue_f1ap_id %d for UE with RNTI %x\n", cu_ue_f1ap_id, f1_inst->f1ap_ue[f1ap_uid].rnti);
+  LOG_I(F1AP, "Adding cu_ue_f1ap_id %ld for UE with RNTI %x\n", cu_ue_f1ap_id, f1_inst->f1ap_ue[f1ap_uid].rnti);
   return 0;
 }
 
-int f1ap_cu_add_du_ue_id(f1ap_cudu_inst_t *f1_inst,
-                         module_id_t       cu_ue_f1ap_id,
-                         module_id_t       du_ue_f1ap_id) {
-  module_id_t f1ap_uid = f1ap_get_cu_uid(f1_inst,cu_ue_f1ap_id);
-  if (f1ap_uid < 0 || f1ap_uid >= MAX_MOBILES_PER_ENB) return -1;
-  f1_inst->f1ap_ue[f1ap_uid].du_ue_f1ap_id = du_ue_f1ap_id;
-  LOG_I(F1AP, "Adding du_ue_f1ap_id %d for UE with RNTI %x\n", du_ue_f1ap_id, f1_inst->f1ap_ue[f1ap_uid].rnti);
-  return 0;
+int f1ap_assoc_id(F1_t isCu, instance_t instanceP) {
+  f1ap_setup_req_t *f1_inst=f1ap_req(isCu, instanceP);
+  return f1_inst->assoc_id;
 }
diff --git a/openair2/F1AP/f1ap_common.h b/openair2/F1AP/f1ap_common.h
index 7781a78412ecb4e1c9caf08d805c62995a9c79ed..a393930c8186c138086645a638b7d78ff79db17f 100644
--- a/openair2/F1AP/f1ap_common.h
+++ b/openair2/F1AP/f1ap_common.h
@@ -31,19 +31,20 @@
  */
 
 #if HAVE_CONFIG_H_
-# include "config.h"
+  #include "config.h"
 #endif
 
 #ifndef F1AP_COMMON_H_
 #define F1AP_COMMON_H_
 
 #include "openairinterface5g_limits.h"
+#include <openair2/RRC/NR/MESSAGES/asn1_msg.h>
 
 #define F1AP_UE_IDENTIFIER_NUMBER 3
 #define F1AP_TRANSACTION_IDENTIFIER_NUMBER 3
 
 #if defined(EMIT_ASN_DEBUG_EXTERN)
-inline void ASN_DEBUG(const char *fmt, ...);
+  inline void ASN_DEBUG(const char *fmt, ...);
 #endif
 
 #include "F1AP_RAT-FrequencyPriorityInformation.h"
@@ -360,14 +361,14 @@ inline void ASN_DEBUG(const char *fmt, ...);
 
 /* Checking version of ASN1C compiler */
 #if (ASN1C_ENVIRONMENT_VERSION < ASN1C_MINIMUM_VERSION)
-# error "You are compiling f1ap with the wrong version of ASN1C"
+  # error "You are compiling f1ap with the wrong version of ASN1C"
 #endif
 
 #ifndef FALSE
-# define FALSE (0)
+  #define FALSE (0)
 #endif
 #ifndef TRUE
-# define TRUE  (!FALSE)
+  #define TRUE  (!FALSE)
 #endif
 
 #define F1AP_UE_ID_FMT  "0x%06"PRIX32
@@ -375,20 +376,20 @@ inline void ASN_DEBUG(const char *fmt, ...);
 #include "assertions.h"
 
 #if defined(ENB_MODE)
-# include "common/utils/LOG/log.h"
-# include "f1ap_default_values.h"
-# define F1AP_ERROR(x, args...) LOG_E(F1AP, x, ##args)
-# define F1AP_WARN(x, args...)  LOG_W(F1AP, x, ##args)
-# define F1AP_TRAF(x, args...)  LOG_I(F1AP, x, ##args)
-# define F1AP_INFO(x, args...) LOG_I(F1AP, x, ##args)
-# define F1AP_DEBUG(x, args...) LOG_I(F1AP, x, ##args)
+  #include "common/utils/LOG/log.h"
+  #include "f1ap_default_values.h"
+  #define F1AP_ERROR(x, args...) LOG_E(F1AP, x, ##args)
+  #define F1AP_WARN(x, args...)  LOG_W(F1AP, x, ##args)
+  #define F1AP_TRAF(x, args...)  LOG_I(F1AP, x, ##args)
+  #define F1AP_INFO(x, args...) LOG_I(F1AP, x, ##args)
+  #define F1AP_DEBUG(x, args...) LOG_I(F1AP, x, ##args)
 #else
-//# include "mme_default_values.h"
-# define F1AP_ERROR(x, args...) do { fprintf(stdout, "[F1AP][E]"x, ##args); } while(0)
-# define F1AP_WARN(x, args...)  do { fprintf(stdout, "[F1AP][W]"x, ##args); } while(0)
-# define F1AP_TRAF(x, args...)  do { fprintf(stdout, "[F1AP][T]"x, ##args); } while(0)
-# define F1AP_INFO(x, args...) do { fprintf(stdout, "[F1AP][I]"x, ##args); } while(0)
-# define F1AP_DEBUG(x, args...) do { fprintf(stdout, "[F1AP][D]"x, ##args); } while(0)
+  //# include "mme_default_values.h"
+  #define F1AP_ERROR(x, args...) do { fprintf(stdout, "[F1AP][E]"x, ##args); } while(0)
+  #define F1AP_WARN(x, args...)  do { fprintf(stdout, "[F1AP][W]"x, ##args); } while(0)
+  #define F1AP_TRAF(x, args...)  do { fprintf(stdout, "[F1AP][T]"x, ##args); } while(0)
+  #define F1AP_INFO(x, args...) do { fprintf(stdout, "[F1AP][I]"x, ##args); } while(0)
+  #define F1AP_DEBUG(x, args...) do { fprintf(stdout, "[F1AP][D]"x, ##args); } while(0)
 #endif
 
 //Forward declaration
@@ -407,73 +408,86 @@ inline void ASN_DEBUG(const char *fmt, ...);
     if (mandatory) DevAssert(ie != NULL); \
   } while(0)
 
-/** \brief Function callback prototype.
+/** \brief Function array prototype.
  **/
-typedef int (*f1ap_message_decoded_callback)(
+typedef int (*f1ap_message_processing_t)(
   instance_t             instance,
   uint32_t               assoc_id,
   uint32_t               stream,
   F1AP_F1AP_PDU_t       *message_p
 );
+int f1ap_handle_message(instance_t instance, uint32_t assoc_id, int32_t stream,
+                        const uint8_t *const data, const uint32_t data_length);
 
 typedef struct f1ap_cudu_ue_inst_s {
   // used for eNB stats generation
   rnti_t      rnti;
-  module_id_t f1ap_uid;
-  module_id_t mac_uid;
-  module_id_t du_ue_f1ap_id;
-  module_id_t cu_ue_f1ap_id;
+  instance_t f1ap_uid;
+  instance_t du_ue_f1ap_id;
+  instance_t cu_ue_f1ap_id;
 } f1ap_cudu_ue_t;
 
 typedef struct f1ap_cudu_inst_s {
+  f1ap_setup_req_t setupReq;
+  uint16_t sctp_in_streams;
+  uint16_t sctp_out_streams;
+  uint16_t default_sctp_stream_id;
+  instance_t gtpInst;
+  uint64_t gNB_DU_id;
   uint16_t num_ues;
   f1ap_cudu_ue_t f1ap_ue[MAX_MOBILES_PER_ENB];
 } f1ap_cudu_inst_t;
 
+typedef enum {
+  DUtype=0,
+  CUtype
+} F1_t;
 
+static const int nrb_lut[29] = {11, 18, 24, 25, 31, 32, 38, 51, 52, 65, 66, 78, 79, 93, 106, 107, 121, 132, 133, 135, 160, 162, 189, 216, 217, 245, 264, 270, 273};
 
-uint8_t F1AP_get_next_transaction_identifier(module_id_t enb_mod_idP, module_id_t cu_mod_idP);
+uint8_t F1AP_get_next_transaction_identifier(instance_t enb_mod_idP, instance_t cu_mod_idP);
 
+f1ap_cudu_inst_t *getCxt(F1_t isCU, instance_t instanceP);
 
-int f1ap_add_ue(f1ap_cudu_inst_t *f1_inst,
-                module_id_t     module_idP,
-                int             CC_idP,
-                int             UE_id,
+void createF1inst(F1_t isCU, instance_t instanceP, f1ap_setup_req_t *req);
+int f1ap_add_ue(F1_t isCu,
+                instance_t     instanceP,
                 rnti_t          rntiP);
 
-int f1ap_remove_ue(f1ap_cudu_inst_t *f1_inst,
+int f1ap_remove_ue(F1_t isCu, instance_t instanceP,
                    rnti_t            rntiP);
 
-int f1ap_get_du_ue_f1ap_id (f1ap_cudu_inst_t *f1_inst,
+int f1ap_get_du_ue_f1ap_id (F1_t isCu, instance_t instanceP,
                             rnti_t            rntiP);
 
-int f1ap_get_cu_ue_f1ap_id (f1ap_cudu_inst_t *f1_inst,
+int f1ap_get_cu_ue_f1ap_id (F1_t isCu, instance_t instanceP,
                             rnti_t            rntiP);
 
 
-int f1ap_get_rnti_by_du_id(f1ap_cudu_inst_t *f1_inst,
-                           module_id_t       du_ue_f1ap_id );
+int f1ap_get_rnti_by_du_id(F1_t isCu, instance_t instanceP,
+                           instance_t       du_ue_f1ap_id );
 
 
-int f1ap_get_rnti_by_cu_id(f1ap_cudu_inst_t *f1_inst,
-                           module_id_t       cu_ue_f1ap_id );
+int f1ap_get_rnti_by_cu_id(F1_t isCu, instance_t instanceP,
+                           instance_t       cu_ue_f1ap_id );
 
+int f1ap_du_add_cu_ue_id(instance_t instanceP,
+                         instance_t       du_ue_f1ap_id,
+                         instance_t       cu_ue_f1ap_id);
 
-int f1ap_get_du_uid(f1ap_cudu_inst_t *f1_inst,
-                    module_id_t       du_ue_f1ap_id );
+int f1ap_assoc_id(F1_t isCu, instance_t instanceP);
 
-int f1ap_get_cu_uid(f1ap_cudu_inst_t *f1_inst,
-                    module_id_t       cu_ue_f1ap_id );
+static inline f1ap_setup_req_t *f1ap_req(F1_t isCu, instance_t instanceP) {
+  return &getCxt(isCu, instanceP)->setupReq;
+}
 
-int f1ap_get_uid_by_rnti(f1ap_cudu_inst_t *f1_inst,
-                         rnti_t            rntiP );
+#define TASK_F1APP f1ap_req(false, instance)->cell_type==CELL_MACRO_GNB?TASK_GNB_APP:TASK_ENB_APP
 
-int f1ap_du_add_cu_ue_id(f1ap_cudu_inst_t *f1_inst,
-                         module_id_t       du_ue_f1ap_id,
-                         module_id_t       cu_ue_f1ap_id);
-
-int f1ap_cu_add_du_ue_id(f1ap_cudu_inst_t *f1_inst,
-                         module_id_t       cu_ue_f1ap_id,
-                         module_id_t       du_ue_f1ap_id);
+//lts: C struct type is not homogeneous, so we need macros instead of functions
+#define addnRCGI(nRCGi, servedCelL) \
+  MCC_MNC_TO_PLMNID((servedCelL)->mcc,(servedCelL)-> mnc,(servedCelL)->mnc_digit_length, \
+                    &((nRCGi).pLMN_Identity));        \
+  NR_CELL_ID_TO_BIT_STRING((servedCelL)->nr_cellid, &((nRCGi).nRCellIdentity));
+extern RAN_CONTEXT_t RC;
 
 #endif /* F1AP_COMMON_H_ */
diff --git a/openair2/F1AP/f1ap_cu_interface_management.c b/openair2/F1AP/f1ap_cu_interface_management.c
index 057d0d97a0bbc3b835a3974539f2a6c61d9e72b2..fdd5f3ea3e70d47d7fb8d96d481aab038f16c65a 100644
--- a/openair2/F1AP/f1ap_cu_interface_management.c
+++ b/openair2/F1AP/f1ap_cu_interface_management.c
@@ -36,24 +36,21 @@
 #include "f1ap_itti_messaging.h"
 #include "f1ap_cu_interface_management.h"
 
-extern f1ap_setup_req_t *f1ap_du_data_from_du;
-extern RAN_CONTEXT_t RC;
-
 int CU_send_RESET(instance_t instance, F1AP_Reset_t *Reset) {
   AssertFatal(1==0,"Not implemented yet\n");
 }
 
 int CU_handle_RESET_ACKKNOWLEDGE(instance_t instance,
-                                  uint32_t assoc_id,
-                                  uint32_t stream,
-                                  F1AP_F1AP_PDU_t *pdu) {
+                                 uint32_t assoc_id,
+                                 uint32_t stream,
+                                 F1AP_F1AP_PDU_t *pdu) {
   AssertFatal(1==0,"Not implemented yet\n");
 }
 
 int CU_handle_RESET(instance_t instance,
-                     uint32_t assoc_id,
-                     uint32_t stream,
-                     F1AP_F1AP_PDU_t *pdu) {
+                    uint32_t assoc_id,
+                    uint32_t stream,
+                    F1AP_F1AP_PDU_t *pdu) {
   AssertFatal(1==0,"Not implemented yet\n");
 }
 
@@ -66,9 +63,9 @@ int CU_send_RESET_ACKNOWLEDGE(instance_t instance, F1AP_ResetAcknowledge_t *Rese
     Error Indication
 */
 int CU_handle_ERROR_INDICATION(instance_t instance,
-                                uint32_t assoc_id,
-                                uint32_t stream,
-                                F1AP_F1AP_PDU_t *pdu) {
+                               uint32_t assoc_id,
+                               uint32_t stream,
+                               F1AP_F1AP_PDU_t *pdu) {
   AssertFatal(1==0,"Not implemented yet\n");
 }
 
@@ -83,330 +80,295 @@ int CU_send_ERROR_INDICATION(instance_t instance, F1AP_ErrorIndication_t *ErrorI
 int CU_handle_F1_SETUP_REQUEST(instance_t instance,
                                uint32_t assoc_id,
                                uint32_t stream,
-                               F1AP_F1AP_PDU_t *pdu)
-{
+                               F1AP_F1AP_PDU_t *pdu) {
   LOG_D(F1AP, "CU_handle_F1_SETUP_REQUEST\n");
-  
   MessageDef                         *message_p;
   F1AP_F1SetupRequest_t              *container;
   F1AP_F1SetupRequestIEs_t           *ie;
   int i = 0;
-   
-
   DevAssert(pdu != NULL);
-
   container = &pdu->choice.initiatingMessage->value.choice.F1SetupRequest;
 
   /* F1 Setup Request == Non UE-related procedure -> stream 0 */
   if (stream != 0) {
     LOG_W(F1AP, "[SCTP %d] Received f1 setup request on stream != 0 (%d)\n",
-              assoc_id, stream);
-  }
-
-  if(RC.nrrrc) {
-    message_p = itti_alloc_new_message(TASK_CU_F1, 0, F1AP_SETUP_REQ);
-  } else {
-    message_p = itti_alloc_new_message(TASK_RRC_ENB, 0, F1AP_SETUP_REQ);
+          assoc_id, stream);
   }
 
   /* assoc_id */
-  F1AP_SETUP_REQ(message_p).assoc_id = assoc_id;
-  
+  f1ap_setup_req_t *req=&getCxt(true, instance)->setupReq;
+  req->assoc_id = assoc_id;
   /* gNB_DU_id */
   // this function exits if the ie is mandatory
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_F1SetupRequestIEs_t, ie, container,
                              F1AP_ProtocolIE_ID_id_gNB_DU_ID, true);
-  asn_INTEGER2ulong(&ie->value.choice.GNB_DU_ID, &F1AP_SETUP_REQ(message_p).gNB_DU_id);
-  LOG_D(F1AP, "F1AP_SETUP_REQ(message_p).gNB_DU_id %lu \n", F1AP_SETUP_REQ(message_p).gNB_DU_id);
-
+  asn_INTEGER2ulong(&ie->value.choice.GNB_DU_ID, &req->gNB_DU_id);
+  LOG_D(F1AP, "req->gNB_DU_id %lu \n", req->gNB_DU_id);
   /* gNB_DU_name */
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_F1SetupRequestIEs_t, ie, container,
-                              F1AP_ProtocolIE_ID_id_gNB_DU_Name, true);
-  F1AP_SETUP_REQ(message_p).gNB_DU_name = calloc(ie->value.choice.GNB_DU_Name.size + 1, sizeof(char));
-  memcpy(F1AP_SETUP_REQ(message_p).gNB_DU_name, ie->value.choice.GNB_DU_Name.buf,
+                             F1AP_ProtocolIE_ID_id_gNB_DU_Name, true);
+  req->gNB_DU_name = calloc(ie->value.choice.GNB_DU_Name.size + 1, sizeof(char));
+  memcpy(req->gNB_DU_name, ie->value.choice.GNB_DU_Name.buf,
          ie->value.choice.GNB_DU_Name.size);
-  /* Convert the mme name to a printable string */
-  F1AP_SETUP_REQ(message_p).gNB_DU_name[ie->value.choice.GNB_DU_Name.size] = '\0';
-  LOG_D(F1AP, "F1AP_SETUP_REQ(message_p).gNB_DU_name %s \n", F1AP_SETUP_REQ(message_p).gNB_DU_name);
-
+  LOG_D(F1AP, "req->gNB_DU_name %s \n", req->gNB_DU_name);
   /* GNB_DU_Served_Cells_List */
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_F1SetupRequestIEs_t, ie, container,
-                              F1AP_ProtocolIE_ID_id_gNB_DU_Served_Cells_List, true);
-  F1AP_SETUP_REQ(message_p).num_cells_available = ie->value.choice.GNB_DU_Served_Cells_List.list.count;
-  LOG_D(F1AP, "F1AP_SETUP_REQ(message_p).num_cells_available %d \n",
-        F1AP_SETUP_REQ(message_p).num_cells_available);
-
-  int num_cells_available = F1AP_SETUP_REQ(message_p).num_cells_available;
-
-  for (i=0; i<num_cells_available; i++) {
-    F1AP_GNB_DU_Served_Cells_Item_t *served_cells_item_p;
-
-    served_cells_item_p = &(((F1AP_GNB_DU_Served_Cells_ItemIEs_t *)ie->value.choice.GNB_DU_Served_Cells_List.list.array[i])->value.choice.GNB_DU_Served_Cells_Item);
-    
+                             F1AP_ProtocolIE_ID_id_gNB_DU_Served_Cells_List, true);
+  req->num_cells_available = ie->value.choice.GNB_DU_Served_Cells_List.list.count;
+  LOG_D(F1AP, "req->num_cells_available %d \n", req->num_cells_available);
+
+  for (i=0; i<req->num_cells_available; i++) {
+    F1AP_GNB_DU_Served_Cells_Item_t *served_cells_item = &(((F1AP_GNB_DU_Served_Cells_ItemIEs_t *)
+							    ie->value.choice.GNB_DU_Served_Cells_List.list.array[i])->
+							   value.choice.GNB_DU_Served_Cells_Item);
+    F1AP_Served_Cell_Information_t *servedCellInformation= &served_cells_item->served_Cell_Information;
     /* tac */
-    if (served_cells_item_p->served_Cell_Information.fiveGS_TAC) {
-      OCTET_STRING_TO_INT16(served_cells_item_p->served_Cell_Information.fiveGS_TAC, F1AP_SETUP_REQ(message_p).tac[i]);
-      LOG_D(F1AP, "F1AP_SETUP_REQ(message_p).tac[%d] %d \n", i, F1AP_SETUP_REQ(message_p).tac[i]);
+    if (servedCellInformation->fiveGS_TAC) {
+      OCTET_STRING_TO_INT16(servedCellInformation->fiveGS_TAC, req->cell[i].tac);
+      LOG_D(F1AP, "req->tac[%d] %d \n", i, req->cell[i].tac);
     }
-    /* - nRCGI */
-    TBCD_TO_MCC_MNC(&(served_cells_item_p->served_Cell_Information.nRCGI.pLMN_Identity), F1AP_SETUP_REQ(message_p).mcc[i],
-                    F1AP_SETUP_REQ(message_p).mnc[i],
-                    F1AP_SETUP_REQ(message_p).mnc_digit_length[i]);
-    
     
+    /* - nRCGI */
+    TBCD_TO_MCC_MNC(&(servedCellInformation->nRCGI.pLMN_Identity), req->cell[i].mcc,
+                    req->cell[i].mnc,req->cell[i].mnc_digit_length);
     // NR cellID
-    BIT_STRING_TO_NR_CELL_IDENTITY(&served_cells_item_p->served_Cell_Information.nRCGI.nRCellIdentity,
-				   F1AP_SETUP_REQ(message_p).nr_cellid[i]);
+    BIT_STRING_TO_NR_CELL_IDENTITY(&servedCellInformation->nRCGI.nRCellIdentity,
+                                   req->cell[i].nr_cellid);
     LOG_D(F1AP, "[SCTP %d] Received nRCGI: MCC %d, MNC %d, CELL_ID %llu\n", assoc_id,
-          F1AP_SETUP_REQ(message_p).mcc[i],
-          F1AP_SETUP_REQ(message_p).mnc[i],
-          (long long unsigned int)F1AP_SETUP_REQ(message_p).nr_cellid[i]);
-    LOG_D(F1AP, "nr_cellId : %x %x %x %x %x\n",
-          served_cells_item_p->served_Cell_Information.nRCGI.nRCellIdentity.buf[0],
-          served_cells_item_p->served_Cell_Information.nRCGI.nRCellIdentity.buf[1],
-          served_cells_item_p->served_Cell_Information.nRCGI.nRCellIdentity.buf[2],
-          served_cells_item_p->served_Cell_Information.nRCGI.nRCellIdentity.buf[3],
-          served_cells_item_p->served_Cell_Information.nRCGI.nRCellIdentity.buf[4]);
+          req->cell[i].mcc,
+          req->cell[i].mnc,
+          (long long unsigned int)req->cell[i].nr_cellid);
     /* - nRPCI */
-    F1AP_SETUP_REQ(message_p).nr_pci[i] = served_cells_item_p->served_Cell_Information.nRPCI;
-    LOG_D(F1AP, "F1AP_SETUP_REQ(message_p).nr_pci[%d] %d \n",
-          i, F1AP_SETUP_REQ(message_p).nr_pci[i]);
-  
+    req->cell[i].nr_pci = servedCellInformation->nRPCI;
+    LOG_D(F1AP, "req->nr_pci[%d] %d \n", i, req->cell[i].nr_pci);
+    
+    // LTS: FIXME data model failure: we don't KNOW if we receive a 4G or a 5G cell
+    // Furthermore, cell_type is not a attribute of a cell in the data structure !!!!!!!!!!
+    if (RC.nrrrc && RC.nrrrc[GNB_INSTANCE_TO_MODULE_ID(instance)]->node_type == ngran_gNB_CU)
+      f1ap_req(true, instance)->cell_type=CELL_MACRO_GNB;
+    else
+      f1ap_req(true, instance)->cell_type=CELL_MACRO_ENB;
+    
+    // FDD Cells
+    if (servedCellInformation->nR_Mode_Info.present==F1AP_NR_Mode_Info_PR_fDD) {
+      struct fdd_s *FDDs=&req->nr_mode_info[i].fdd;
+      F1AP_FDD_Info_t * fDD_Info=servedCellInformation->nR_Mode_Info.choice.fDD;
+      FDDs->ul_nr_arfcn=fDD_Info->uL_NRFreqInfo.nRARFCN;
+      FDDs->ul_num_frequency_bands=fDD_Info->uL_NRFreqInfo.freqBandListNr.list.count;
+      for (int f=0; f < fDD_Info->uL_NRFreqInfo.freqBandListNr.list.count; f++) {
+	F1AP_FreqBandNrItem_t * FreqItem=fDD_Info->uL_NRFreqInfo.freqBandListNr.list.array[f];
+	FDDs->ul_nr_band[f]=FreqItem->freqBandIndicatorNr;
+	int num_available_supported_SULBands=FreqItem->supportedSULBandList.list.count;
+	for (int sul=0; sul < num_available_supported_SULBands; sul ++ ) {
+          F1AP_SupportedSULFreqBandItem_t * SulItem= FreqItem->supportedSULBandList.list.array[sul];
+	  FDDs->ul_nr_sul_band[sul]=SulItem->freqBandIndicatorNr;
+	}
+      }
+      FDDs->dl_nr_arfcn=fDD_Info->dL_NRFreqInfo.nRARFCN;
+      int dlBands=fDD_Info->dL_NRFreqInfo.freqBandListNr.list.count;
+      for (int dlB=0; dlB < dlBands; dlB++) {
+	F1AP_FreqBandNrItem_t * FreqItem=fDD_Info->dL_NRFreqInfo.freqBandListNr.list.array[dlB];
+	FDDs->dl_nr_band[dlB]=FreqItem->freqBandIndicatorNr;
+	int num_available_supported_SULBands = FreqItem->supportedSULBandList.list.count;
+	for (int sul=0; sul < num_available_supported_SULBands; sul ++ ) {
+	  F1AP_SupportedSULFreqBandItem_t * SulItem= FreqItem->supportedSULBandList.list.array[sul];
+	  FDDs->ul_nr_sul_band[sul]=SulItem->freqBandIndicatorNr;
+	}
+      }
+      FDDs->ul_scs=fDD_Info->uL_Transmission_Bandwidth.nRSCS;
+      FDDs->ul_nrb=nrb_lut[fDD_Info->uL_Transmission_Bandwidth.nRNRB];
+      FDDs->dl_scs=fDD_Info->dL_Transmission_Bandwidth.nRSCS;
+      FDDs->dl_nrb=nrb_lut[fDD_Info->dL_Transmission_Bandwidth.nRNRB]; 
+    }
+    
+    // TDD
+    if (servedCellInformation->nR_Mode_Info.present==F1AP_NR_Mode_Info_PR_tDD) {
+      struct tdd_s *TDDs=&req->nr_mode_info[i].tdd;
+      F1AP_TDD_Info_t * tDD_Info=servedCellInformation->nR_Mode_Info.choice.tDD;
+      TDDs->nr_arfcn=tDD_Info->nRFreqInfo.nRARFCN;
+      TDDs->num_frequency_bands=tDD_Info->nRFreqInfo.freqBandListNr.list.count;
+      for (int f=0; f < tDD_Info->nRFreqInfo.freqBandListNr.list.count; f++) {
+	struct F1AP_FreqBandNrItem * FreqItem=tDD_Info->nRFreqInfo.freqBandListNr.list.array[f];
+	TDDs->nr_band[f]=FreqItem->freqBandIndicatorNr;
+	int num_available_supported_SULBands=FreqItem->supportedSULBandList.list.count;
+	for (int sul=0; sul < num_available_supported_SULBands; sul ++ ) {
+          struct F1AP_SupportedSULFreqBandItem * SulItem= FreqItem->supportedSULBandList.list.array[sul];
+	  TDDs->nr_sul_band[sul]=SulItem->freqBandIndicatorNr;
+	}
+      }
+      TDDs->scs=tDD_Info->transmission_Bandwidth.nRSCS;
+      TDDs->nrb=nrb_lut[tDD_Info->transmission_Bandwidth.nRNRB];
+    }
+	
+    struct F1AP_GNB_DU_System_Information * DUsi=served_cells_item->gNB_DU_System_Information;
+    LOG_I(F1AP, "Received Cell in %d context\n", f1ap_req(true, instance)->cell_type==CELL_MACRO_GNB);
     // System Information
     /* mib */
-    F1AP_SETUP_REQ(message_p).mib[i] = calloc(served_cells_item_p->gNB_DU_System_Information->mIB_message.size + 1, sizeof(char));
-    memcpy(F1AP_SETUP_REQ(message_p).mib[i], served_cells_item_p->gNB_DU_System_Information->mIB_message.buf,
-           served_cells_item_p->gNB_DU_System_Information->mIB_message.size);
+    req->mib[i] = calloc(DUsi->mIB_message.size + 1, sizeof(char));
+    memcpy(req->mib[i], DUsi->mIB_message.buf, DUsi->mIB_message.size);
     /* Convert the mme name to a printable string */
-    F1AP_SETUP_REQ(message_p).mib[i][served_cells_item_p->gNB_DU_System_Information->mIB_message.size] = '\0';
-    F1AP_SETUP_REQ(message_p).mib_length[i] = served_cells_item_p->gNB_DU_System_Information->mIB_message.size;
-    LOG_D(F1AP, "F1AP_SETUP_REQ(message_p).mib[%d] %s , len = %d \n",
-          i, F1AP_SETUP_REQ(message_p).mib[i], F1AP_SETUP_REQ(message_p).mib_length[i]);
-
+    req->mib[i][DUsi->mIB_message.size] = '\0';
+    req->mib_length[i] = DUsi->mIB_message.size;
+    LOG_D(F1AP, "req->mib[%d] len = %d \n", i, req->mib_length[i]);
     /* sib1 */
-    F1AP_SETUP_REQ(message_p).sib1[i] = calloc(served_cells_item_p->gNB_DU_System_Information->sIB1_message.size + 1, sizeof(char));
-    memcpy(F1AP_SETUP_REQ(message_p).sib1[i], served_cells_item_p->gNB_DU_System_Information->sIB1_message.buf,
-           served_cells_item_p->gNB_DU_System_Information->sIB1_message.size);
+    req->sib1[i] = calloc(DUsi->sIB1_message.size + 1, sizeof(char));
+    memcpy(req->sib1[i], DUsi->sIB1_message.buf, DUsi->sIB1_message.size);
     /* Convert the mme name to a printable string */
-    F1AP_SETUP_REQ(message_p).sib1[i][served_cells_item_p->gNB_DU_System_Information->sIB1_message.size] = '\0';
-    F1AP_SETUP_REQ(message_p).sib1_length[i] = served_cells_item_p->gNB_DU_System_Information->sIB1_message.size;
-    LOG_D(F1AP, "F1AP_SETUP_REQ(message_p).sib1[%d] %s , len = %d \n",
-          i, F1AP_SETUP_REQ(message_p).sib1[i], F1AP_SETUP_REQ(message_p).sib1_length[i]);
+    req->sib1[i][DUsi->sIB1_message.size] = '\0';
+    req->sib1_length[i] = DUsi->sIB1_message.size;
+    LOG_D(F1AP, "req->sib1[%d] len = %d \n", i, req->sib1_length[i]);
   }
-
   
-  *f1ap_du_data_from_du = F1AP_SETUP_REQ(message_p);
   // char *measurement_timing_information[F1AP_MAX_NB_CELLS];
   // uint8_t ranac[F1AP_MAX_NB_CELLS];
-
   // int fdd_flag = f1ap_setup_req->fdd_flag;
-
   // union {
   //   struct {
   //     uint32_t ul_nr_arfcn;
   //     uint8_t ul_scs;
   //     uint8_t ul_nrb;
-
   //     uint32_t dl_nr_arfcn;
   //     uint8_t dl_scs;
   //     uint8_t dl_nrb;
-
   //     uint32_t sul_active;
   //     uint32_t sul_nr_arfcn;
   //     uint8_t sul_scs;
   //     uint8_t sul_nrb;
-
   //     uint8_t num_frequency_bands;
   //     uint16_t nr_band[32];
   //     uint8_t num_sul_frequency_bands;
   //     uint16_t nr_sul_band[32];
   //   } fdd;
   //   struct {
-
   //     uint32_t nr_arfcn;
   //     uint8_t scs;
   //     uint8_t nrb;
-
   //     uint32_t sul_active;
   //     uint32_t sul_nr_arfcn;
   //     uint8_t sul_scs;
   //     uint8_t sul_nrb;
-
   //     uint8_t num_frequency_bands;
   //     uint16_t nr_band[32];
   //     uint8_t num_sul_frequency_bands;
   //     uint16_t nr_sul_band[32];
-
   //   } tdd;
   // } nr_mode_info[F1AP_MAX_NB_CELLS];
 
-  MSC_LOG_TX_MESSAGE(
-  MSC_F1AP_CU,
-  MSC_RRC_ENB,
-  0,
-  0,
-  MSC_AS_TIME_FMT" CU_handle_F1_SETUP_REQUEST",
-  0,0//MSC_AS_TIME_ARGS(ctxt_pP),
-  );
-
-  if (num_cells_available > 0) {
-    if (RC.nrrrc && RC.nrrrc[0]->node_type == ngran_gNB_CU) {
+
+  
+  // We copy and store in F1 task data, RRC will free "req" as it frees all itti received messages
+  message_p = itti_alloc_new_message(TASK_CU_F1, 0, F1AP_SETUP_REQ);
+  memcpy(&F1AP_SETUP_REQ(message_p), req, sizeof(f1ap_setup_req_t) );
+  
+  if (req->num_cells_available > 0) {
+    if (f1ap_req(true, instance)->cell_type == CELL_MACRO_GNB) {
       itti_send_msg_to_task(TASK_RRC_GNB, GNB_MODULE_ID_TO_INSTANCE(instance), message_p);
     } else {
       itti_send_msg_to_task(TASK_RRC_ENB, ENB_MODULE_ID_TO_INSTANCE(instance), message_p);
     }
   } else {
     CU_send_F1_SETUP_FAILURE(instance);
-    if (RC.nrrrc && RC.nrrrc[0]->node_type == ngran_gNB_CU) {
-      itti_free(TASK_RRC_GNB,message_p);
-    } else {
-      itti_free(TASK_RRC_ENB,message_p);
-    }
+    itti_free(TASK_CU_F1,message_p);
     return -1;
   }
+  
   return 0;
 }
 
 int CU_send_F1_SETUP_RESPONSE(instance_t instance,
-                               f1ap_setup_resp_t *f1ap_setup_resp) {
-  
-  module_id_t enb_mod_idP;
-  module_id_t cu_mod_idP;
-
+                              f1ap_setup_resp_t *f1ap_setup_resp) {
+  instance_t enb_mod_idP;
+  instance_t cu_mod_idP;
   // This should be fixed
-  enb_mod_idP = (module_id_t)0;
-  cu_mod_idP  = (module_id_t)0;
-
-  F1AP_F1AP_PDU_t           pdu;
-  F1AP_F1SetupResponse_t    *out;
-  F1AP_F1SetupResponseIEs_t *ie;
-
-  uint8_t  *buffer;
-  uint32_t  len;
-  int       i = 0;
-
+  enb_mod_idP = (instance_t)0;
+  cu_mod_idP  = (instance_t)0;
+  F1AP_F1AP_PDU_t           pdu= {0};
+  uint8_t  *buffer=NULL;
+  uint32_t  len=0;
   /* Create */
   /* 0. Message Type */
-  memset(&pdu, 0, sizeof(pdu));
   pdu.present = F1AP_F1AP_PDU_PR_successfulOutcome;
-  pdu.choice.successfulOutcome = (F1AP_SuccessfulOutcome_t *)calloc(1, sizeof(F1AP_SuccessfulOutcome_t));
-  pdu.choice.successfulOutcome->procedureCode = F1AP_ProcedureCode_id_F1Setup;
-  pdu.choice.successfulOutcome->criticality   = F1AP_Criticality_reject;
-  pdu.choice.successfulOutcome->value.present = F1AP_SuccessfulOutcome__value_PR_F1SetupResponse;
-  out = &pdu.choice.successfulOutcome->value.choice.F1SetupResponse;
-  
+  asn1cCalloc(pdu.choice.successfulOutcome, tmp);
+  tmp->procedureCode = F1AP_ProcedureCode_id_F1Setup;
+  tmp->criticality   = F1AP_Criticality_reject;
+  tmp->value.present = F1AP_SuccessfulOutcome__value_PR_F1SetupResponse;
+  F1AP_F1SetupResponse_t    *out = &pdu.choice.successfulOutcome->value.choice.F1SetupResponse;
   /* mandatory */
   /* c1. Transaction ID (integer value)*/
-  ie = (F1AP_F1SetupResponseIEs_t *)calloc(1, sizeof(F1AP_F1SetupResponseIEs_t));
-  ie->id                        = F1AP_ProtocolIE_ID_id_TransactionID;
-  ie->criticality               = F1AP_Criticality_reject;
-  ie->value.present             = F1AP_F1SetupResponseIEs__value_PR_TransactionID;
-  ie->value.choice.TransactionID = F1AP_get_next_transaction_identifier(enb_mod_idP, cu_mod_idP);
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
- 
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_F1SetupResponseIEs_t, ie1);
+  ie1->id                        = F1AP_ProtocolIE_ID_id_TransactionID;
+  ie1->criticality               = F1AP_Criticality_reject;
+  ie1->value.present             = F1AP_F1SetupResponseIEs__value_PR_TransactionID;
+  ie1->value.choice.TransactionID = F1AP_get_next_transaction_identifier(enb_mod_idP, cu_mod_idP);
+
   /* optional */
   /* c2. GNB_CU_Name */
   if (f1ap_setup_resp->gNB_CU_name != NULL) {
-    ie = (F1AP_F1SetupResponseIEs_t *)calloc(1, sizeof(F1AP_F1SetupResponseIEs_t));
-    ie->id                        = F1AP_ProtocolIE_ID_id_gNB_CU_Name;
-    ie->criticality               = F1AP_Criticality_ignore;
-    ie->value.present             = F1AP_F1SetupResponseIEs__value_PR_GNB_CU_Name;
-    OCTET_STRING_fromBuf(&ie->value.choice.GNB_CU_Name, f1ap_setup_resp->gNB_CU_name,
+    asn1cSequenceAdd(out->protocolIEs.list, F1AP_F1SetupResponseIEs_t, ie2);
+    ie2->id                        = F1AP_ProtocolIE_ID_id_gNB_CU_Name;
+    ie2->criticality               = F1AP_Criticality_ignore;
+    ie2->value.present             = F1AP_F1SetupResponseIEs__value_PR_GNB_CU_Name;
+    OCTET_STRING_fromBuf(&ie2->value.choice.GNB_CU_Name, f1ap_setup_resp->gNB_CU_name,
                          strlen(f1ap_setup_resp->gNB_CU_name));
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
   }
 
   /* mandatory */
   /* c3. cells to be Activated list */
   int num_cells_to_activate = f1ap_setup_resp->num_cells_to_activate;
   LOG_D(F1AP, "num_cells_to_activate = %d \n", num_cells_to_activate);
-  if (num_cells_to_activate >0) {
-    ie = (F1AP_F1SetupResponseIEs_t *)calloc(1, sizeof(F1AP_F1SetupResponseIEs_t));
-    ie->id                        = F1AP_ProtocolIE_ID_id_Cells_to_be_Activated_List;
-    ie->criticality               = F1AP_Criticality_reject;
-    ie->value.present             = F1AP_F1SetupResponseIEs__value_PR_Cells_to_be_Activated_List;
-
-    for (i=0; i<num_cells_to_activate; i++) {
-
-      LOG_D(F1AP, "[c3] (cell %d) mcc = %d, mnc = %d, mnc_digit_length = %d, nr_cellid = %lu\n",
-            i,
-            f1ap_setup_resp->cells_to_activate[i].mcc,
-            f1ap_setup_resp->cells_to_activate[i].mnc,
-            f1ap_setup_resp->cells_to_activate[i].mnc_digit_length,
-            f1ap_setup_resp->cells_to_activate[i].nr_cellid);
-
-      F1AP_Cells_to_be_Activated_List_ItemIEs_t *cells_to_be_activated_list_item_ies;
-      cells_to_be_activated_list_item_ies = (F1AP_Cells_to_be_Activated_List_ItemIEs_t *)calloc(1, sizeof(F1AP_Cells_to_be_Activated_List_ItemIEs_t));
-      cells_to_be_activated_list_item_ies->id = F1AP_ProtocolIE_ID_id_Cells_to_be_Activated_List_Item;
-      cells_to_be_activated_list_item_ies->criticality = F1AP_Criticality_reject;
-      cells_to_be_activated_list_item_ies->value.present = F1AP_Cells_to_be_Activated_List_ItemIEs__value_PR_Cells_to_be_Activated_List_Item;
 
+  if (num_cells_to_activate >0) {
+    asn1cSequenceAdd(out->protocolIEs.list, F1AP_F1SetupResponseIEs_t, ie3);
+    ie3->id                        = F1AP_ProtocolIE_ID_id_Cells_to_be_Activated_List;
+    ie3->criticality               = F1AP_Criticality_reject;
+    ie3->value.present             = F1AP_F1SetupResponseIEs__value_PR_Cells_to_be_Activated_List;
+
+    for (int i=0; i<num_cells_to_activate;  i++) {
+      asn1cSequenceAdd(ie3->value.choice.Cells_to_be_Activated_List.list,
+                       F1AP_Cells_to_be_Activated_List_ItemIEs_t, cells_to_be_activated_ies);
+      cells_to_be_activated_ies->id = F1AP_ProtocolIE_ID_id_Cells_to_be_Activated_List_Item;
+      cells_to_be_activated_ies->criticality = F1AP_Criticality_reject;
+      cells_to_be_activated_ies->value.present = F1AP_Cells_to_be_Activated_List_ItemIEs__value_PR_Cells_to_be_Activated_List_Item;
       /* 3.1 cells to be Activated list item */
-      F1AP_Cells_to_be_Activated_List_Item_t cells_to_be_activated_list_item;
-      memset((void *)&cells_to_be_activated_list_item, 0, sizeof(F1AP_Cells_to_be_Activated_List_Item_t));
-
+      F1AP_Cells_to_be_Activated_List_Item_t *cells_to_be_activated_item=
+        &cells_to_be_activated_ies->value.choice.Cells_to_be_Activated_List_Item;
       /* - nRCGI */
-      F1AP_NRCGI_t nRCGI;
-      memset(&nRCGI, 0, sizeof(F1AP_NRCGI_t));
-      MCC_MNC_TO_PLMNID(f1ap_setup_resp->cells_to_activate[i].mcc, f1ap_setup_resp->cells_to_activate[i].mnc, f1ap_setup_resp->cells_to_activate[i].mnc_digit_length,
-			&nRCGI.pLMN_Identity);
-      NR_CELL_ID_TO_BIT_STRING(f1ap_setup_resp->cells_to_activate[i].nr_cellid, &nRCGI.nRCellIdentity);
-      cells_to_be_activated_list_item.nRCGI = nRCGI;
+      addnRCGI(cells_to_be_activated_item->nRCGI, f1ap_setup_resp->cells_to_activate+i);
 
       /* optional */
       /* - nRPCI */
       if (1) {
-        cells_to_be_activated_list_item.nRPCI = (F1AP_NRPCI_t *)calloc(1, sizeof(F1AP_NRPCI_t));
-        *cells_to_be_activated_list_item.nRPCI = f1ap_setup_resp->cells_to_activate[i].nrpci;  // int 0..1007
+        cells_to_be_activated_item->nRPCI = (F1AP_NRPCI_t *)calloc(1, sizeof(F1AP_NRPCI_t));
+        *cells_to_be_activated_item->nRPCI = f1ap_setup_resp->cells_to_activate[i].nrpci;  // int 0..1007
       }
 
       /* optional */
       /* - gNB-CU System Information */
       if (1) {
-      /* 3.1.2 gNB-CUSystem Information */
-      F1AP_Cells_to_be_Activated_List_ItemExtIEs_t *cells_to_be_activated_list_itemExtIEs;
-      cells_to_be_activated_list_itemExtIEs = (F1AP_Cells_to_be_Activated_List_ItemExtIEs_t *)calloc(1, sizeof(F1AP_Cells_to_be_Activated_List_ItemExtIEs_t));
-      cells_to_be_activated_list_itemExtIEs->id                     = F1AP_ProtocolIE_ID_id_gNB_CUSystemInformation;
-      cells_to_be_activated_list_itemExtIEs->criticality            = F1AP_Criticality_reject;
-      cells_to_be_activated_list_itemExtIEs->extensionValue.present = F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_GNB_CUSystemInformation;
-
-      F1AP_GNB_CUSystemInformation_t *gNB_CUSystemInformation = (F1AP_GNB_CUSystemInformation_t *)calloc(1, sizeof(F1AP_GNB_CUSystemInformation_t));
-      //LOG_I(F1AP, "%s() SI %d size %d: ", __func__, i, f1ap_setup_resp->SI_container_length[i][0]);
-      //for (int n = 0; n < f1ap_setup_resp->SI_container_length[i][0]; n++)
-      //  printf("%02x ", f1ap_setup_resp->SI_container[i][0][n]);
-          //printf("\n");
-
-          // for (int sIBtype=2;sIBtype<33;sIBtype++) { //21 ? 33 ?
-      for (int sIBtype=2;sIBtype<21;sIBtype++) {
-        if (f1ap_setup_resp->cells_to_activate[i].SI_container[sIBtype]!=NULL) {
-          AssertFatal(sIBtype < 6 || sIBtype == 9, "Illegal SI type %d\n",sIBtype);
-          F1AP_SibtypetobeupdatedListItem_t *sib_item = calloc(1,sizeof(*sib_item));
-          memset((void*)sib_item,0,sizeof(*sib_item));
-          sib_item->sIBtype = sIBtype;
-          OCTET_STRING_fromBuf(&sib_item->sIBmessage,
-             (const char*)f1ap_setup_resp->cells_to_activate[i].SI_container[sIBtype],
-             f1ap_setup_resp->cells_to_activate[i].SI_container_length[sIBtype]);
-
-          LOG_D(F1AP, "f1ap_setup_resp->SI_container_length[%d][%d] = %d \n", i,sIBtype,f1ap_setup_resp->cells_to_activate[i].SI_container_length[sIBtype]);
-          ASN_SEQUENCE_ADD(&gNB_CUSystemInformation->sibtypetobeupdatedlist.list,sib_item);
+        /* 3.1.2 gNB-CUSystem Information */
+        F1AP_ProtocolExtensionContainer_154P112_t *p_154P112=calloc(1, sizeof(* p_154P112));
+        cells_to_be_activated_item->iE_Extensions = (struct F1AP_ProtocolExtensionContainer *)p_154P112;
+        asn1cSequenceAdd(p_154P112->list, F1AP_Cells_to_be_Activated_List_ItemExtIEs_t, cells_to_be_activated_itemExtIEs);
+        cells_to_be_activated_itemExtIEs->id                     = F1AP_ProtocolIE_ID_id_gNB_CUSystemInformation;
+        cells_to_be_activated_itemExtIEs->criticality            = F1AP_Criticality_reject;
+        cells_to_be_activated_itemExtIEs->extensionValue.present = F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_GNB_CUSystemInformation;
+        F1AP_GNB_CUSystemInformation_t *gNB_CUSystemInformation =
+          &cells_to_be_activated_itemExtIEs->extensionValue.choice.GNB_CUSystemInformation;
+
+        // for (int sIBtype=2;sIBtype<33;sIBtype++) { //21 ? 33 ?
+        for (int sIBtype=2; sIBtype<21; sIBtype++) {
+          if (f1ap_setup_resp->cells_to_activate[i].SI_container[sIBtype]!=NULL) {
+            AssertFatal(sIBtype < 6 || sIBtype == 9, "Illegal SI type %d\n",sIBtype);
+            asn1cSequenceAdd(gNB_CUSystemInformation->sibtypetobeupdatedlist.list, F1AP_SibtypetobeupdatedListItem_t, sib_item);
+            sib_item->sIBtype = sIBtype;
+            OCTET_STRING_fromBuf(&sib_item->sIBmessage,
+                                 (const char *)f1ap_setup_resp->cells_to_activate[i].SI_container[sIBtype],
+                                 f1ap_setup_resp->cells_to_activate[i].SI_container_length[sIBtype]);
+            LOG_D(F1AP, "f1ap_setup_resp->SI_container_length[%d][%d] = %d \n", i,sIBtype,f1ap_setup_resp->cells_to_activate[i].SI_container_length[sIBtype]);
+          }
         }
       }
-      cells_to_be_activated_list_itemExtIEs->extensionValue.choice.GNB_CUSystemInformation = *gNB_CUSystemInformation;
-
-      F1AP_ProtocolExtensionContainer_154P112_t p_154P112_t;
-      memset((void *)&p_154P112_t, 0, sizeof(F1AP_ProtocolExtensionContainer_154P112_t));
-
-      ASN_SEQUENCE_ADD(&p_154P112_t.list, cells_to_be_activated_list_itemExtIEs);
-      cells_to_be_activated_list_item.iE_Extensions = (struct F1AP_ProtocolExtensionContainer*)&p_154P112_t;
-
-      free(gNB_CUSystemInformation);
-      gNB_CUSystemInformation = NULL;
-      }
-      /* ADD */
-      cells_to_be_activated_list_item_ies->value.choice.Cells_to_be_Activated_List_Item = cells_to_be_activated_list_item;
-      ASN_SEQUENCE_ADD(&ie->value.choice.Cells_to_be_Activated_List.list, cells_to_be_activated_list_item_ies);
     }
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
   }
 
   /* encode */
@@ -415,84 +377,68 @@ int CU_send_F1_SETUP_RESPONSE(instance_t instance,
     return -1;
   }
 
-  cu_f1ap_itti_send_sctp_data_req(instance, f1ap_du_data_from_du->assoc_id, buffer, len, 0);
-
+  ASN_STRUCT_RESET(asn_DEF_F1AP_F1AP_PDU, &pdu);
+  f1ap_itti_send_sctp_data_req(true, instance, buffer, len, 0);
   return 0;
 }
 
 int CU_send_F1_SETUP_FAILURE(instance_t instance) {
   LOG_D(F1AP, "CU_send_F1_SETUP_FAILURE\n");
-  
-  module_id_t enb_mod_idP;
-  module_id_t cu_mod_idP;
-
+  instance_t enb_mod_idP=0;
+  instance_t cu_mod_idP=0;
   // This should be fixed
-  enb_mod_idP = (module_id_t)0;
-  cu_mod_idP  = (module_id_t)0;
-
-  F1AP_F1AP_PDU_t           pdu;
-  F1AP_F1SetupFailure_t    *out;
-  F1AP_F1SetupFailureIEs_t *ie;
-
-  uint8_t  *buffer;
-  uint32_t  len;
-
+  F1AP_F1AP_PDU_t           pdu= {0};
+  uint8_t  *buffer=NULL;
+  uint32_t  len=0;
   /* Create */
   /* 0. Message Type */
-  memset(&pdu, 0, sizeof(pdu));
+  asn1cCalloc(pdu.choice.unsuccessfulOutcome, UnsuccessfulOutcome);
   pdu.present = F1AP_F1AP_PDU_PR_unsuccessfulOutcome;
-  pdu.choice.unsuccessfulOutcome = (F1AP_UnsuccessfulOutcome_t *)calloc(1, sizeof(F1AP_UnsuccessfulOutcome_t));
-  pdu.choice.unsuccessfulOutcome->procedureCode = F1AP_ProcedureCode_id_F1Setup;
-  pdu.choice.unsuccessfulOutcome->criticality   = F1AP_Criticality_reject;
-  pdu.choice.unsuccessfulOutcome->value.present = F1AP_UnsuccessfulOutcome__value_PR_F1SetupFailure;
-  out = &pdu.choice.unsuccessfulOutcome->value.choice.F1SetupFailure;
-
+  UnsuccessfulOutcome->procedureCode = F1AP_ProcedureCode_id_F1Setup;
+  UnsuccessfulOutcome->criticality   = F1AP_Criticality_reject;
+  UnsuccessfulOutcome->value.present = F1AP_UnsuccessfulOutcome__value_PR_F1SetupFailure;
+  F1AP_F1SetupFailure_t *out = &pdu.choice.unsuccessfulOutcome->value.choice.F1SetupFailure;
   /* mandatory */
   /* c1. Transaction ID (integer value)*/
-  ie = (F1AP_F1SetupFailureIEs_t *)calloc(1, sizeof(F1AP_F1SetupFailureIEs_t));
-  ie->id                        = F1AP_ProtocolIE_ID_id_TransactionID;
-  ie->criticality               = F1AP_Criticality_reject;
-  ie->value.present             = F1AP_F1SetupFailureIEs__value_PR_TransactionID;
-  ie->value.choice.TransactionID = F1AP_get_next_transaction_identifier(enb_mod_idP, cu_mod_idP);
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_F1SetupFailureIEs_t, ie1);
+  ie1->id                        = F1AP_ProtocolIE_ID_id_TransactionID;
+  ie1->criticality               = F1AP_Criticality_reject;
+  ie1->value.present             = F1AP_F1SetupFailureIEs__value_PR_TransactionID;
+  ie1->value.choice.TransactionID = F1AP_get_next_transaction_identifier(enb_mod_idP, cu_mod_idP);
   /* mandatory */
   /* c2. Cause */
-  ie = (F1AP_F1SetupFailureIEs_t *)calloc(1, sizeof(F1AP_F1SetupFailureIEs_t));
-  ie->id                        = F1AP_ProtocolIE_ID_id_Cause;
-  ie->criticality               = F1AP_Criticality_ignore;
-  ie->value.present             = F1AP_F1SetupFailureIEs__value_PR_Cause;
-  ie->value.choice.Cause.present = F1AP_Cause_PR_radioNetwork;
-  ie->value.choice.Cause.choice.radioNetwork = F1AP_CauseRadioNetwork_unspecified;
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_F1SetupFailureIEs_t, ie2);
+  ie2->id                        = F1AP_ProtocolIE_ID_id_Cause;
+  ie2->criticality               = F1AP_Criticality_ignore;
+  ie2->value.present             = F1AP_F1SetupFailureIEs__value_PR_Cause;
+  ie2->value.choice.Cause.present = F1AP_Cause_PR_radioNetwork;
+  ie2->value.choice.Cause.choice.radioNetwork = F1AP_CauseRadioNetwork_unspecified;
 
   /* optional */
   /* c3. TimeToWait */
   if (0) {
-    ie = (F1AP_F1SetupFailureIEs_t *)calloc(1, sizeof(F1AP_F1SetupFailureIEs_t));
-    ie->id                        = F1AP_ProtocolIE_ID_id_TimeToWait;
-    ie->criticality               = F1AP_Criticality_ignore;
-    ie->value.present             = F1AP_F1SetupFailureIEs__value_PR_TimeToWait;
-    ie->value.choice.TimeToWait = F1AP_TimeToWait_v10s;
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    asn1cSequenceAdd(out->protocolIEs.list, F1AP_F1SetupFailureIEs_t, ie3);
+    ie3->id                        = F1AP_ProtocolIE_ID_id_TimeToWait;
+    ie3->criticality               = F1AP_Criticality_ignore;
+    ie3->value.present             = F1AP_F1SetupFailureIEs__value_PR_TimeToWait;
+    ie3->value.choice.TimeToWait = F1AP_TimeToWait_v10s;
   }
 
   /* optional */
   /* c4. CriticalityDiagnostics*/
   if (0) {
-    ie = (F1AP_F1SetupFailureIEs_t *)calloc(1, sizeof(F1AP_F1SetupFailureIEs_t));
-    ie->id                        = F1AP_ProtocolIE_ID_id_CriticalityDiagnostics;
-    ie->criticality               = F1AP_Criticality_ignore;
-    ie->value.present             = F1AP_F1SetupFailureIEs__value_PR_CriticalityDiagnostics;
-    ie->value.choice.CriticalityDiagnostics.procedureCode = (F1AP_ProcedureCode_t *)calloc(1, sizeof(F1AP_ProcedureCode_t));
-    *ie->value.choice.CriticalityDiagnostics.procedureCode = F1AP_ProcedureCode_id_UEContextSetup;
-    ie->value.choice.CriticalityDiagnostics.triggeringMessage = (F1AP_TriggeringMessage_t *)calloc(1, sizeof(F1AP_TriggeringMessage_t));
-    *ie->value.choice.CriticalityDiagnostics.triggeringMessage = F1AP_TriggeringMessage_initiating_message;
-    ie->value.choice.CriticalityDiagnostics.procedureCriticality = (F1AP_Criticality_t *)calloc(1, sizeof(F1AP_Criticality_t));
-    *ie->value.choice.CriticalityDiagnostics.procedureCriticality = F1AP_Criticality_reject;
-    ie->value.choice.CriticalityDiagnostics.transactionID = (F1AP_TransactionID_t *)calloc(1, sizeof(F1AP_TransactionID_t));
-    *ie->value.choice.CriticalityDiagnostics.transactionID = 0;
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    asn1cSequenceAdd(out->protocolIEs.list, F1AP_F1SetupFailureIEs_t, ie4);
+    ie4->id                        = F1AP_ProtocolIE_ID_id_CriticalityDiagnostics;
+    ie4->criticality               = F1AP_Criticality_ignore;
+    ie4->value.present             = F1AP_F1SetupFailureIEs__value_PR_CriticalityDiagnostics;
+    asn1cCallocOne(ie4->value.choice.CriticalityDiagnostics.procedureCode,
+                   F1AP_ProcedureCode_id_UEContextSetup);
+    asn1cCallocOne(ie4->value.choice.CriticalityDiagnostics.triggeringMessage,
+                   F1AP_TriggeringMessage_initiating_message);
+    asn1cCallocOne(ie4->value.choice.CriticalityDiagnostics.procedureCriticality,
+                   F1AP_Criticality_reject);
+    asn1cCallocOne(ie4->value.choice.CriticalityDiagnostics.transactionID,
+                   0);
   }
 
   /* encode */
@@ -501,451 +447,306 @@ int CU_send_F1_SETUP_FAILURE(instance_t instance) {
     return -1;
   }
 
-  cu_f1ap_itti_send_sctp_data_req(instance, f1ap_du_data_from_du->assoc_id, buffer, len, 0);
-
+  ASN_STRUCT_RESET(asn_DEF_F1AP_F1AP_PDU, &pdu);
+  f1ap_itti_send_sctp_data_req(true,instance, buffer, len, 0);
   return 0;
 }
 
-
-
 /*
     gNB-DU Configuration Update
 */
 
 int CU_handle_gNB_DU_CONFIGURATION_UPDATE(instance_t instance,
-                                           uint32_t assoc_id,
-                                           uint32_t stream,
-                                           F1AP_F1AP_PDU_t *pdu) {
+    uint32_t assoc_id,
+    uint32_t stream,
+    F1AP_F1AP_PDU_t *pdu) {
   AssertFatal(1==0,"Not implemented yet\n");
 }
 
 int CU_send_gNB_DU_CONFIGURATION_FAILURE(instance_t instance,
-                    F1AP_GNBDUConfigurationUpdateFailure_t *GNBDUConfigurationUpdateFailure) {
+    F1AP_GNBDUConfigurationUpdateFailure_t *GNBDUConfigurationUpdateFailure) {
   AssertFatal(1==0,"Not implemented yet\n");
 }
 
 int CU_send_gNB_DU_CONFIGURATION_UPDATE_ACKNOWLEDGE(instance_t instance,
-                    F1AP_GNBDUConfigurationUpdateAcknowledge_t *GNBDUConfigurationUpdateAcknowledge) {
+    F1AP_GNBDUConfigurationUpdateAcknowledge_t *GNBDUConfigurationUpdateAcknowledge) {
   AssertFatal(1==0,"Not implemented yet\n");
 }
 
-
-
 /*
     gNB-CU Configuration Update
 */
 
 //void CU_send_gNB_CU_CONFIGURATION_UPDATE(F1AP_GNBCUConfigurationUpdate_t *GNBCUConfigurationUpdate) {
 int CU_send_gNB_CU_CONFIGURATION_UPDATE(instance_t instance, f1ap_gnb_cu_configuration_update_t *f1ap_gnb_cu_configuration_update) {
-  F1AP_F1AP_PDU_t                    pdu;
-  F1AP_GNBCUConfigurationUpdate_t    *out;
-  F1AP_GNBCUConfigurationUpdateIEs_t *ie;
-
+  F1AP_F1AP_PDU_t                    pdu= {0};
   uint8_t  *buffer;
   uint32_t  len;
-  int       i = 0;
-
-
   /* Create */
   /* 0. Message Type */
-  memset(&pdu, 0, sizeof(pdu));
   pdu.present = F1AP_F1AP_PDU_PR_initiatingMessage;
-  pdu.choice.initiatingMessage = (F1AP_InitiatingMessage_t *)calloc(1, sizeof(F1AP_InitiatingMessage_t));
-  pdu.choice.initiatingMessage->procedureCode = F1AP_ProcedureCode_id_gNBCUConfigurationUpdate;
-  pdu.choice.initiatingMessage->criticality   = F1AP_Criticality_ignore;
-  pdu.choice.initiatingMessage->value.present = F1AP_InitiatingMessage__value_PR_GNBCUConfigurationUpdate;
-  out = &pdu.choice.initiatingMessage->value.choice.GNBCUConfigurationUpdate;
-
+  asn1cCalloc(pdu.choice.initiatingMessage, initMsg);
+  initMsg->procedureCode = F1AP_ProcedureCode_id_gNBCUConfigurationUpdate;
+  initMsg->criticality   = F1AP_Criticality_reject;
+  initMsg->value.present = F1AP_InitiatingMessage__value_PR_GNBCUConfigurationUpdate;
+  F1AP_GNBCUConfigurationUpdate_t *cfgUpdate = &pdu.choice.initiatingMessage->value.choice.GNBCUConfigurationUpdate;
   /* mandatory */
   /* c1. Transaction ID (integer value) */
-  ie = (F1AP_GNBCUConfigurationUpdateIEs_t *)calloc(1, sizeof(F1AP_GNBCUConfigurationUpdateIEs_t));
-  ie->id                        = F1AP_ProtocolIE_ID_id_TransactionID;
-  ie->criticality               = F1AP_Criticality_reject;
-  ie->value.present             = F1AP_GNBCUConfigurationUpdateIEs__value_PR_TransactionID;
-  ie->value.choice.TransactionID = F1AP_get_next_transaction_identifier(instance, 0);
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
-
+  asn1cSequenceAdd(cfgUpdate->protocolIEs.list, F1AP_GNBCUConfigurationUpdateIEs_t, ieC1);
+  ieC1->id                        = F1AP_ProtocolIE_ID_id_TransactionID;
+  ieC1->criticality               = F1AP_Criticality_reject;
+  ieC1->value.present             = F1AP_GNBCUConfigurationUpdateIEs__value_PR_TransactionID;
+  ieC1->value.choice.TransactionID = F1AP_get_next_transaction_identifier(instance, 0);
 
   // mandatory
   // c2. Cells_to_be_Activated_List
   if (f1ap_gnb_cu_configuration_update->num_cells_to_activate > 0) {
-    ie = (F1AP_GNBCUConfigurationUpdateIEs_t *)calloc(1, sizeof(F1AP_GNBCUConfigurationUpdateIEs_t));
-    ie->id                        = F1AP_ProtocolIE_ID_id_Cells_to_be_Activated_List;
-    ie->criticality               = F1AP_Criticality_reject;
-    ie->value.present             = F1AP_GNBCUConfigurationUpdateIEs__value_PR_Cells_to_be_Activated_List;
-
-    for (i=0; i<f1ap_gnb_cu_configuration_update->num_cells_to_activate; i++) {
-
-      LOG_D(F1AP, "[c2] (cell %d) mcc = %d, mnc = %d, mnc_digit_length = %d, nr_cellid = %lu\n",
-            i,
-            f1ap_gnb_cu_configuration_update->cells_to_activate[i].mcc,
-            f1ap_gnb_cu_configuration_update->cells_to_activate[i].mnc,
-            f1ap_gnb_cu_configuration_update->cells_to_activate[i].mnc_digit_length,
-            f1ap_gnb_cu_configuration_update->cells_to_activate[i].nr_cellid);
-
-      F1AP_Cells_to_be_Activated_List_ItemIEs_t *cells_to_be_activated_list_item_ies;
-      cells_to_be_activated_list_item_ies = (F1AP_Cells_to_be_Activated_List_ItemIEs_t *)calloc(1, sizeof(F1AP_Cells_to_be_Activated_List_ItemIEs_t));
-      cells_to_be_activated_list_item_ies->id = F1AP_ProtocolIE_ID_id_Cells_to_be_Activated_List_Item;
-      cells_to_be_activated_list_item_ies->criticality = F1AP_Criticality_reject;
-      cells_to_be_activated_list_item_ies->value.present = F1AP_Cells_to_be_Activated_List_ItemIEs__value_PR_Cells_to_be_Activated_List_Item;
-
+    asn1cSequenceAdd(cfgUpdate->protocolIEs.list, F1AP_GNBCUConfigurationUpdateIEs_t, ieC3);
+    ieC3->id                        = F1AP_ProtocolIE_ID_id_Cells_to_be_Activated_List;
+    ieC3->criticality               = F1AP_Criticality_reject;
+    ieC3->value.present             = F1AP_GNBCUConfigurationUpdateIEs__value_PR_Cells_to_be_Activated_List;
+
+    for (int i=0; i<f1ap_gnb_cu_configuration_update->num_cells_to_activate; i++) {
+      asn1cSequenceAdd(ieC3->value.choice.Cells_to_be_Activated_List.list,F1AP_Cells_to_be_Activated_List_ItemIEs_t,
+                       cells_to_be_activated_ies);
+      cells_to_be_activated_ies->id = F1AP_ProtocolIE_ID_id_Cells_to_be_Activated_List_Item;
+      cells_to_be_activated_ies->criticality = F1AP_Criticality_reject;
+      cells_to_be_activated_ies->value.present = F1AP_Cells_to_be_Activated_List_ItemIEs__value_PR_Cells_to_be_Activated_List_Item;
       // 2.1 cells to be Activated list item
-      F1AP_Cells_to_be_Activated_List_Item_t cells_to_be_activated_list_item;
-      memset((void *)&cells_to_be_activated_list_item, 0, sizeof(F1AP_Cells_to_be_Activated_List_Item_t));
-
+      F1AP_Cells_to_be_Activated_List_Item_t *cells_to_be_activated_list_item=
+        &cells_to_be_activated_ies->value.choice.Cells_to_be_Activated_List_Item;
       // - nRCGI
-      F1AP_NRCGI_t nRCGI;
-      memset(&nRCGI, 0, sizeof(F1AP_NRCGI_t));
-      MCC_MNC_TO_PLMNID(f1ap_gnb_cu_configuration_update->cells_to_activate[i].mcc,
-			f1ap_gnb_cu_configuration_update->cells_to_activate[i].mnc,
-			f1ap_gnb_cu_configuration_update->cells_to_activate[i].mnc_digit_length,
-			&nRCGI.pLMN_Identity);
-      NR_CELL_ID_TO_BIT_STRING(f1ap_gnb_cu_configuration_update->cells_to_activate[i].nr_cellid,
-			       &nRCGI.nRCellIdentity);
-      cells_to_be_activated_list_item.nRCGI = nRCGI;
-
-      if(RC.nrrrc) {
-
-        // optional
-        // -nRPCI
-        cells_to_be_activated_list_item.nRPCI = (F1AP_NRPCI_t *)calloc(1, sizeof(F1AP_NRPCI_t));
-        *cells_to_be_activated_list_item.nRPCI = f1ap_gnb_cu_configuration_update->cells_to_activate[i].nrpci;  // int 0..1007
-
-        // optional
-        // 3.1.2 gNB-CUSystem Information
-        F1AP_Cells_to_be_Activated_List_ItemExtIEs_t *cells_to_be_activated_list_itemExtIEs;
-        cells_to_be_activated_list_itemExtIEs = (F1AP_Cells_to_be_Activated_List_ItemExtIEs_t *)calloc(1, sizeof(F1AP_Cells_to_be_Activated_List_ItemExtIEs_t));
-        cells_to_be_activated_list_itemExtIEs->id                     = F1AP_ProtocolIE_ID_id_gNB_CUSystemInformation;
-        cells_to_be_activated_list_itemExtIEs->criticality            = F1AP_Criticality_reject;
-        cells_to_be_activated_list_itemExtIEs->extensionValue.present = F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_GNB_CUSystemInformation;
-
-        if (f1ap_gnb_cu_configuration_update->cells_to_activate[i].num_SI > 0) {
-          F1AP_GNB_CUSystemInformation_t *gNB_CUSystemInformation = (F1AP_GNB_CUSystemInformation_t *)calloc(1, sizeof(F1AP_GNB_CUSystemInformation_t));
-          //LOG_I(F1AP, "%s() SI %d size %d: ", __func__, i, f1ap_setup_resp->SI_container_length[i][0]);
-          //for (int n = 0; n < f1ap_setup_resp->SI_container_length[i][0]; n++)
-          //  printf("%02x ", f1ap_setup_resp->SI_container[i][0][n]);
-          //printf("\n");
-
-          // for (int sIBtype=2;sIBtype<33;sIBtype++) { //21 ? 33 ?
-          for (int sIBtype=2;sIBtype<21;sIBtype++) {
-            if (f1ap_gnb_cu_configuration_update->cells_to_activate[i].SI_container[sIBtype]!=NULL) {
-              AssertFatal(sIBtype < 6 || sIBtype == 9, "Illegal SI type %d\n",sIBtype);
-              F1AP_SibtypetobeupdatedListItem_t *sib_item = calloc(1,sizeof(*sib_item));
-              memset((void*)sib_item,0,sizeof(*sib_item));
-              sib_item->sIBtype = sIBtype;
-              OCTET_STRING_fromBuf(&sib_item->sIBmessage,
-                                   (const char*)f1ap_gnb_cu_configuration_update->cells_to_activate[i].SI_container[sIBtype],
-                                   f1ap_gnb_cu_configuration_update->cells_to_activate[i].SI_container_length[sIBtype]);
-
-              LOG_D(F1AP, "f1ap_setup_resp->SI_container_length[%d][%d] = %d \n", i,sIBtype,f1ap_gnb_cu_configuration_update->cells_to_activate[i].SI_container_length[sIBtype]);
-              ASN_SEQUENCE_ADD(&gNB_CUSystemInformation->sibtypetobeupdatedlist.list,sib_item);
-            }
+      addnRCGI(cells_to_be_activated_list_item->nRCGI, f1ap_gnb_cu_configuration_update->cells_to_activate+i);
+      // optional
+      // -nRPCI
+      asn1cCalloc(cells_to_be_activated_list_item->nRPCI, tmp);
+      *tmp = f1ap_gnb_cu_configuration_update->cells_to_activate[i].nrpci;  // int 0..1007
+      // optional
+      // 3.1.2 gNB-CUSystem Information
+      F1AP_ProtocolExtensionContainer_154P112_t *p_154P112=(F1AP_ProtocolExtensionContainer_154P112_t *) calloc(1,sizeof(*p_154P112));
+      cells_to_be_activated_list_item->iE_Extensions = (struct F1AP_ProtocolExtensionContainer *)p_154P112;
+      //F1AP_ProtocolExtensionContainer_154P112_t
+      asn1cSequenceAdd(p_154P112->list,F1AP_Cells_to_be_Activated_List_ItemExtIEs_t,  cells_to_be_activated_itemExtIEs);
+      cells_to_be_activated_itemExtIEs->id                     = F1AP_ProtocolIE_ID_id_gNB_CUSystemInformation;
+      cells_to_be_activated_itemExtIEs->criticality            = F1AP_Criticality_reject;
+      cells_to_be_activated_itemExtIEs->extensionValue.present = F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_GNB_CUSystemInformation;
+
+      if (f1ap_gnb_cu_configuration_update->cells_to_activate[i].num_SI > 0) {
+        F1AP_GNB_CUSystemInformation_t *gNB_CUSystemInformation =
+          &cells_to_be_activated_itemExtIEs->extensionValue.choice.GNB_CUSystemInformation;
+        //LOG_I(F1AP, "%s() SI %d size %d: ", __func__, i, f1ap_setup_resp->SI_container_length[i][0]);
+        //for (int n = 0; n < f1ap_setup_resp->SI_container_length[i][0]; n++)
+        //  printf("%02x ", f1ap_setup_resp->SI_container[i][0][n]);
+        //printf("\n");
+
+        // for (int sIBtype=2;sIBtype<33;sIBtype++) { //21 ? 33 ?
+        for (int sIBtype=2; sIBtype<21; sIBtype++) {
+          if (f1ap_gnb_cu_configuration_update->cells_to_activate[i].SI_container[sIBtype]!=NULL) {
+            AssertFatal(sIBtype < 6 || sIBtype == 9, "Illegal SI type %d\n",sIBtype);
+            asn1cSequenceAdd(gNB_CUSystemInformation->sibtypetobeupdatedlist.list, F1AP_SibtypetobeupdatedListItem_t, sib_item);
+            sib_item->sIBtype = sIBtype;
+            OCTET_STRING_fromBuf(&sib_item->sIBmessage,
+                                 (const char *)f1ap_gnb_cu_configuration_update->cells_to_activate[i].SI_container[sIBtype],
+                                 f1ap_gnb_cu_configuration_update->cells_to_activate[i].SI_container_length[sIBtype]);
+            LOG_D(F1AP, "f1ap_setup_resp->SI_container_length[%d][%d] = %d \n", i,sIBtype,
+                  f1ap_gnb_cu_configuration_update->cells_to_activate[i].SI_container_length[sIBtype]);
           }
-          cells_to_be_activated_list_itemExtIEs->extensionValue.choice.GNB_CUSystemInformation = *gNB_CUSystemInformation;
-
-
-          F1AP_ProtocolExtensionContainer_154P112_t p_154P112_t;
-          memset((void *)&p_154P112_t, 0, sizeof(F1AP_ProtocolExtensionContainer_154P112_t));
-
-          ASN_SEQUENCE_ADD(&p_154P112_t.list,
-                           cells_to_be_activated_list_itemExtIEs);
-          cells_to_be_activated_list_item.iE_Extensions = (struct F1AP_ProtocolExtensionContainer*)&p_154P112_t;
-
-          free(gNB_CUSystemInformation);
-          gNB_CUSystemInformation = NULL;
         }
       }
-
-      // ADD
-      cells_to_be_activated_list_item_ies->value.choice.Cells_to_be_Activated_List_Item = cells_to_be_activated_list_item;
-      ASN_SEQUENCE_ADD(&ie->value.choice.Cells_to_be_Activated_List.list,
-		       cells_to_be_activated_list_item_ies);
     }
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
   }
 
-
+  // c3. Cells_to_be_Deactivated_List
+  //
+  /*
   if(!RC.nrrrc) {
-
-    /* mandatory */
-    /* c3. Cells_to_be_Deactivated_List */
-    ie = (F1AP_GNBCUConfigurationUpdateIEs_t *)calloc(1, sizeof(F1AP_GNBCUConfigurationUpdateIEs_t));
-    ie->id                        = F1AP_ProtocolIE_ID_id_Cells_to_be_Deactivated_List;
-    ie->criticality               = F1AP_Criticality_reject;
-    ie->value.present             = F1AP_GNBCUConfigurationUpdateIEs__value_PR_Cells_to_be_Deactivated_List;
-
-    for (i=0;
-         i<1;
-         i++) {
-
-      F1AP_Cells_to_be_Deactivated_List_ItemIEs_t *cells_to_be_deactivated_list_item_ies;
-      cells_to_be_deactivated_list_item_ies = (F1AP_Cells_to_be_Deactivated_List_ItemIEs_t *)calloc(1, sizeof(F1AP_Cells_to_be_Deactivated_List_ItemIEs_t));
-      cells_to_be_deactivated_list_item_ies->id = F1AP_ProtocolIE_ID_id_Cells_to_be_Activated_List_Item;
-      cells_to_be_deactivated_list_item_ies->criticality = F1AP_Criticality_reject;
-      cells_to_be_deactivated_list_item_ies->value.present = F1AP_Cells_to_be_Deactivated_List_ItemIEs__value_PR_Cells_to_be_Deactivated_List_Item;
-
+    // mandatory
+    // c3. Cells_to_be_Deactivated_List
+    asn1cSequenceAdd(cfgUpdate->protocolIEs.list, F1AP_GNBCUConfigurationUpdateIEs_t, ieC3);
+    ieC3->id                        = F1AP_ProtocolIE_ID_id_Cells_to_be_Deactivated_List;
+    ieC3->criticality               = F1AP_Criticality_reject;
+    ieC3->value.present             = F1AP_GNBCUConfigurationUpdateIEs__value_PR_Cells_to_be_Deactivated_List;
+
+    for (int i=0; i<1; i++) {
+      asn1cSequenceAdd(ieC3->value.choice.Cells_to_be_Deactivated_List.list,
+           F1AP_Cells_to_be_Deactivated_List_ItemIEs_t, cells_to_be_deactivated);
+      cells_to_be_deactivated->id = F1AP_ProtocolIE_ID_id_Cells_to_be_Activated_List_Item;
+      cells_to_be_deactivated->criticality = F1AP_Criticality_reject;
+      cells_to_be_deactivated->value.present = F1AP_Cells_to_be_Deactivated_List_ItemIEs__value_PR_Cells_to_be_Deactivated_List_Item;
       // 3.1 cells to be Deactivated list item
-      F1AP_Cells_to_be_Deactivated_List_Item_t cells_to_be_deactivated_list_item;
-      memset((void *)&cells_to_be_deactivated_list_item, 0, sizeof(F1AP_Cells_to_be_Deactivated_List_Item_t));
-
-
-      F1AP_NRCGI_t nRCGI;
-      memset(&nRCGI, 0, sizeof(F1AP_NRCGI_t));
-      MCC_MNC_TO_PLMNID(f1ap_gnb_cu_configuration_update->cells_to_activate[i].mcc,
-                        f1ap_gnb_cu_configuration_update->cells_to_activate[i].mnc,
-                        f1ap_gnb_cu_configuration_update->cells_to_activate[i].mnc_digit_length,
-                        &nRCGI.pLMN_Identity);
-      NR_CELL_ID_TO_BIT_STRING(f1ap_gnb_cu_configuration_update->cells_to_activate[i].nr_cellid, &nRCGI.nRCellIdentity);
-      cells_to_be_deactivated_list_item.nRCGI = nRCGI;
-
-      cells_to_be_deactivated_list_item_ies->value.choice.Cells_to_be_Deactivated_List_Item = cells_to_be_deactivated_list_item;
-      ASN_SEQUENCE_ADD(&ie->value.choice.Cells_to_be_Deactivated_List.list,
-                       cells_to_be_deactivated_list_item_ies);
-    }
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
-
-    /* mandatory */
-    /* c4. GNB_CU_TNL_Association_To_Add_List */
-    ie = (F1AP_GNBCUConfigurationUpdateIEs_t *)calloc(1, sizeof(F1AP_GNBCUConfigurationUpdateIEs_t));
-    ie->id                        = F1AP_ProtocolIE_ID_id_GNB_CU_TNL_Association_To_Add_List;
-    ie->criticality               = F1AP_Criticality_reject;
-    ie->value.present             = F1AP_GNBCUConfigurationUpdateIEs__value_PR_GNB_CU_TNL_Association_To_Add_List;
-
-    for (i=0;
-         i<1;
-         i++) {
-
-      F1AP_GNB_CU_TNL_Association_To_Add_ItemIEs_t *gnb_cu_tnl_association_to_add_item_ies;
-      gnb_cu_tnl_association_to_add_item_ies = (F1AP_GNB_CU_TNL_Association_To_Add_ItemIEs_t *)calloc(1, sizeof(F1AP_GNB_CU_TNL_Association_To_Add_ItemIEs_t));
-      gnb_cu_tnl_association_to_add_item_ies->id = F1AP_ProtocolIE_ID_id_GNB_CU_TNL_Association_To_Add_Item;
-      gnb_cu_tnl_association_to_add_item_ies->criticality = F1AP_Criticality_reject;
-      gnb_cu_tnl_association_to_add_item_ies->value.present = F1AP_GNB_CU_TNL_Association_To_Add_ItemIEs__value_PR_GNB_CU_TNL_Association_To_Add_Item;
-
-      // 4.1 GNB_CU_TNL_Association_To_Add_Item
-      F1AP_GNB_CU_TNL_Association_To_Add_Item_t gnb_cu_tnl_association_to_add_item;
-      memset((void *)&gnb_cu_tnl_association_to_add_item, 0, sizeof(F1AP_GNB_CU_TNL_Association_To_Add_Item_t));
-
-
-      // 4.1.1 tNLAssociationTransportLayerAddress
-      F1AP_CP_TransportLayerAddress_t transportLayerAddress;
-      memset((void *)&transportLayerAddress, 0, sizeof(F1AP_CP_TransportLayerAddress_t));
-      transportLayerAddress.present = F1AP_CP_TransportLayerAddress_PR_endpoint_IP_address;
-      TRANSPORT_LAYER_ADDRESS_IPv4_TO_BIT_STRING(1234, &transportLayerAddress.choice.endpoint_IP_address);
-
-      // memset((void *)&transportLayerAddress, 0, sizeof(F1AP_CP_TransportLayerAddress_t));
-      // transportLayerAddress.present = F1AP_CP_TransportLayerAddress_PR_endpoint_IP_address_and_port;
-      // transportLayerAddress.choice.endpoint_IP_address_and_port = (F1AP_Endpoint_IP_address_and_port_t *)calloc(1, sizeof(F1AP_Endpoint_IP_address_and_port_t));
-      // TRANSPORT_LAYER_ADDRESS_IPv4_TO_BIT_STRING(1234, &transportLayerAddress.choice.endpoint_IP_address_and_port.endpoint_IP_address);
-
-      gnb_cu_tnl_association_to_add_item.tNLAssociationTransportLayerAddress = transportLayerAddress;
-
-      // 4.1.2 tNLAssociationUsage
-      gnb_cu_tnl_association_to_add_item.tNLAssociationUsage = F1AP_TNLAssociationUsage_non_ue;
-
-
-
-      gnb_cu_tnl_association_to_add_item_ies->value.choice.GNB_CU_TNL_Association_To_Add_Item = gnb_cu_tnl_association_to_add_item;
-      ASN_SEQUENCE_ADD(&ie->value.choice.GNB_CU_TNL_Association_To_Add_List.list,
-                       gnb_cu_tnl_association_to_add_item_ies);
-    }
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
-
-    /* mandatory */
-    /* c5. GNB_CU_TNL_Association_To_Remove_List */
-    ie = (F1AP_GNBCUConfigurationUpdateIEs_t *)calloc(1, sizeof(F1AP_GNBCUConfigurationUpdateIEs_t));
-    ie->id                        = F1AP_ProtocolIE_ID_id_GNB_CU_TNL_Association_To_Remove_List;
-    ie->criticality               = F1AP_Criticality_reject;
-    ie->value.present             = F1AP_GNBCUConfigurationUpdateIEs__value_PR_GNB_CU_TNL_Association_To_Remove_List;
-    for (i=0;
-         i<1;
-         i++) {
-
-      F1AP_GNB_CU_TNL_Association_To_Remove_ItemIEs_t *gnb_cu_tnl_association_to_remove_item_ies;
-      gnb_cu_tnl_association_to_remove_item_ies = (F1AP_GNB_CU_TNL_Association_To_Remove_ItemIEs_t *)calloc(1, sizeof(F1AP_GNB_CU_TNL_Association_To_Remove_ItemIEs_t));
-      gnb_cu_tnl_association_to_remove_item_ies->id = F1AP_ProtocolIE_ID_id_GNB_CU_TNL_Association_To_Remove_Item;
-      gnb_cu_tnl_association_to_remove_item_ies->criticality = F1AP_Criticality_reject;
-      gnb_cu_tnl_association_to_remove_item_ies->value.present = F1AP_GNB_CU_TNL_Association_To_Remove_ItemIEs__value_PR_GNB_CU_TNL_Association_To_Remove_Item;
-
-      // 4.1 GNB_CU_TNL_Association_To_Remove_Item
-      F1AP_GNB_CU_TNL_Association_To_Remove_Item_t gnb_cu_tnl_association_to_remove_item;
-      memset((void *)&gnb_cu_tnl_association_to_remove_item, 0, sizeof(F1AP_GNB_CU_TNL_Association_To_Remove_Item_t));
-
-
-      // 4.1.1 tNLAssociationTransportLayerAddress
-      F1AP_CP_TransportLayerAddress_t transportLayerAddress;
-      memset((void *)&transportLayerAddress, 0, sizeof(F1AP_CP_TransportLayerAddress_t));
-      transportLayerAddress.present = F1AP_CP_TransportLayerAddress_PR_endpoint_IP_address;
-      TRANSPORT_LAYER_ADDRESS_IPv4_TO_BIT_STRING(1234, &transportLayerAddress.choice.endpoint_IP_address);
-
-      // memset((void *)&transportLayerAddress, 0, sizeof(F1AP_CP_TransportLayerAddress_t));
-      // transportLayerAddress.present = F1AP_CP_TransportLayerAddress_PR_endpoint_IP_address_and_port;
-      // transportLayerAddress.choice.endpoint_IP_address_and_port = (F1AP_Endpoint_IP_address_and_port_t *)calloc(1, sizeof(F1AP_Endpoint_IP_address_and_port_t));
-      // TRANSPORT_LAYER_ADDRESS_IPv4_TO_BIT_STRING(1234, &transportLayerAddress.choice.endpoint_IP_address_and_port.endpoint_IP_address);
-
-      gnb_cu_tnl_association_to_remove_item.tNLAssociationTransportLayerAddress = transportLayerAddress;
-
-
-
-      gnb_cu_tnl_association_to_remove_item_ies->value.choice.GNB_CU_TNL_Association_To_Remove_Item = gnb_cu_tnl_association_to_remove_item;
-      ASN_SEQUENCE_ADD(&ie->value.choice.GNB_CU_TNL_Association_To_Remove_List.list,
-                       gnb_cu_tnl_association_to_remove_item_ies);
-    }
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
-
-    /* mandatory */
-    /* c6. GNB_CU_TNL_Association_To_Update_List */
-    ie = (F1AP_GNBCUConfigurationUpdateIEs_t *)calloc(1, sizeof(F1AP_GNBCUConfigurationUpdateIEs_t));
-    ie->id                        = F1AP_ProtocolIE_ID_id_GNB_CU_TNL_Association_To_Update_List;
-    ie->criticality               = F1AP_Criticality_reject;
-    ie->value.present             = F1AP_GNBCUConfigurationUpdateIEs__value_PR_GNB_CU_TNL_Association_To_Update_List;
-    for (i=0;
-         i<1;
-         i++) {
-
-      F1AP_GNB_CU_TNL_Association_To_Update_ItemIEs_t *gnb_cu_tnl_association_to_update_item_ies;
-      gnb_cu_tnl_association_to_update_item_ies = (F1AP_GNB_CU_TNL_Association_To_Update_ItemIEs_t *)calloc(1, sizeof(F1AP_GNB_CU_TNL_Association_To_Update_ItemIEs_t));
-      gnb_cu_tnl_association_to_update_item_ies->id = F1AP_ProtocolIE_ID_id_GNB_CU_TNL_Association_To_Update_Item;
-      gnb_cu_tnl_association_to_update_item_ies->criticality = F1AP_Criticality_reject;
-      gnb_cu_tnl_association_to_update_item_ies->value.present = F1AP_GNB_CU_TNL_Association_To_Update_ItemIEs__value_PR_GNB_CU_TNL_Association_To_Update_Item;
-
-      // 4.1 GNB_CU_TNL_Association_To_Update_Item
-      F1AP_GNB_CU_TNL_Association_To_Update_Item_t gnb_cu_tnl_association_to_update_item;
-      memset((void *)&gnb_cu_tnl_association_to_update_item, 0, sizeof(F1AP_GNB_CU_TNL_Association_To_Update_Item_t));
-
-
-      // 4.1.1 tNLAssociationTransportLayerAddress
-      F1AP_CP_TransportLayerAddress_t transportLayerAddress;
-      memset((void *)&transportLayerAddress, 0, sizeof(F1AP_CP_TransportLayerAddress_t));
-      transportLayerAddress.present = F1AP_CP_TransportLayerAddress_PR_endpoint_IP_address;
-      TRANSPORT_LAYER_ADDRESS_IPv4_TO_BIT_STRING(1234, &transportLayerAddress.choice.endpoint_IP_address);
-
-      // memset((void *)&transportLayerAddress, 0, sizeof(F1AP_CP_TransportLayerAddress_t));
-      // transportLayerAddress.present = F1AP_CP_TransportLayerAddress_PR_endpoint_IP_address_and_port;
-      // transportLayerAddress.choice.endpoint_IP_address_and_port = (F1AP_Endpoint_IP_address_and_port_t *)calloc(1, sizeof(F1AP_Endpoint_IP_address_and_port_t));
-      // TRANSPORT_LAYER_ADDRESS_IPv4_TO_BIT_STRING(1234, &transportLayerAddress.choice.endpoint_IP_address_and_port.endpoint_IP_address);
-
-      gnb_cu_tnl_association_to_update_item.tNLAssociationTransportLayerAddress = transportLayerAddress;
-
-
-      // 4.1.2 tNLAssociationUsage
-      if (1) {
-        gnb_cu_tnl_association_to_update_item.tNLAssociationUsage = (F1AP_TNLAssociationUsage_t *)calloc(1, sizeof(F1AP_TNLAssociationUsage_t));
-        *gnb_cu_tnl_association_to_update_item.tNLAssociationUsage = F1AP_TNLAssociationUsage_non_ue;
+      F1AP_Cells_to_be_Deactivated_List_Item_t *cells_to_be_deactivated_list=
+  cells_to_be_deactivated->value.choice.Cells_to_be_Deactivated_List_Item;
+      addnRCGI(cells_to_be_deactivated_item->nRCGI, f1ap_setup_resp->cells_to_deactivate+i);
       }
-
-
-      gnb_cu_tnl_association_to_update_item_ies->value.choice.GNB_CU_TNL_Association_To_Update_Item = gnb_cu_tnl_association_to_update_item;
-      ASN_SEQUENCE_ADD(&ie->value.choice.GNB_CU_TNL_Association_To_Update_List.list,
-                       gnb_cu_tnl_association_to_update_item_ies);
-    }
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
-
-    /* mandatory */
-    /* c7. Cells_to_be_Barred_List */
-    ie = (F1AP_GNBCUConfigurationUpdateIEs_t *)calloc(1, sizeof(F1AP_GNBCUConfigurationUpdateIEs_t));
-    ie->id                        = F1AP_ProtocolIE_ID_id_Cells_to_be_Barred_List;
-    ie->criticality               = F1AP_Criticality_reject;
-    ie->value.present             = F1AP_GNBCUConfigurationUpdateIEs__value_PR_Cells_to_be_Barred_List;
-    for (i=0;
-         i<1;
-         i++) {
-
-      F1AP_Cells_to_be_Barred_ItemIEs_t *cells_to_be_barred_item_ies;
-      cells_to_be_barred_item_ies = (F1AP_Cells_to_be_Barred_ItemIEs_t *)calloc(1, sizeof(F1AP_Cells_to_be_Barred_ItemIEs_t));
-      cells_to_be_barred_item_ies->id = F1AP_ProtocolIE_ID_id_Cells_to_be_Activated_List_Item;
-      cells_to_be_barred_item_ies->criticality = F1AP_Criticality_reject;
-      cells_to_be_barred_item_ies->value.present = F1AP_Cells_to_be_Barred_ItemIEs__value_PR_Cells_to_be_Barred_Item;
-
-      // 7.1 cells to be Deactivated list item
-      F1AP_Cells_to_be_Barred_Item_t cells_to_be_barred_item;
-      memset((void *)&cells_to_be_barred_item, 0, sizeof(F1AP_Cells_to_be_Barred_Item_t));
-
-      // - nRCGI
-      F1AP_NRCGI_t nRCGI;
-      memset(&nRCGI,0,sizeof(F1AP_NRCGI_t));
-      MCC_MNC_TO_PLMNID(f1ap_gnb_cu_configuration_update->cells_to_activate[i].mcc,
-                        f1ap_gnb_cu_configuration_update->cells_to_activate[i].mnc,
-                        f1ap_gnb_cu_configuration_update->cells_to_activate[i].mnc_digit_length,
-                        &nRCGI.pLMN_Identity);
-      NR_CELL_ID_TO_BIT_STRING(f1ap_gnb_cu_configuration_update->cells_to_activate[i].nr_cellid, &nRCGI.nRCellIdentity);
-      cells_to_be_barred_item.nRCGI = nRCGI;
-
-      // 7.2 cellBarred
-      cells_to_be_barred_item.cellBarred = F1AP_CellBarred_not_barred;
-
-      cells_to_be_barred_item_ies->value.choice.Cells_to_be_Barred_Item = cells_to_be_barred_item;
-      ASN_SEQUENCE_ADD(&ie->value.choice.Cells_to_be_Barred_List.list,
-                       cells_to_be_barred_item_ies);
-    }
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
-
-    /* mandatory */
-    /* c8. Protected_EUTRA_Resources_List */
-    ie = (F1AP_GNBCUConfigurationUpdateIEs_t *)calloc(1, sizeof(F1AP_GNBCUConfigurationUpdateIEs_t));
-    ie->id                        = F1AP_ProtocolIE_ID_id_Protected_EUTRA_Resources_List;
-    ie->criticality               = F1AP_Criticality_reject;
-    ie->value.present             = F1AP_GNBCUConfigurationUpdateIEs__value_PR_Protected_EUTRA_Resources_List;
-
-    for (i=0;
-         i<1;
-         i++) {
-
-
-      F1AP_Protected_EUTRA_Resources_ItemIEs_t *protected_eutra_resources_item_ies;
-
-      // 8.1 SpectrumSharingGroupID
-      protected_eutra_resources_item_ies = (F1AP_Protected_EUTRA_Resources_ItemIEs_t *)calloc(1, sizeof(F1AP_Protected_EUTRA_Resources_ItemIEs_t));
-      protected_eutra_resources_item_ies->id = F1AP_ProtocolIE_ID_id_Protected_EUTRA_Resources_List;
-      protected_eutra_resources_item_ies->criticality = F1AP_Criticality_reject;
-      protected_eutra_resources_item_ies->value.present = F1AP_Protected_EUTRA_Resources_ItemIEs__value_PR_Protected_EUTRA_Resources_Item;
-      ((F1AP_Protected_EUTRA_Resources_Item_t*)&protected_eutra_resources_item_ies->value.choice.Protected_EUTRA_Resources_Item)->spectrumSharingGroupID = 123L;
-      memset(&protected_eutra_resources_item_ies->value.choice.Protected_EUTRA_Resources_Item,0,
-             sizeof(F1AP_Protected_EUTRA_Resources_Item_t));
-      ASN_SEQUENCE_ADD(&ie->value.choice.Protected_EUTRA_Resources_List.list, protected_eutra_resources_item_ies);
-
-      /*
-       F1AP_Served_EUTRA_Cells_Information_t served_eutra_cells_information;
-       memset((void *)&served_eutra_cells_information, 0, sizeof(F1AP_Served_EUTRA_Cells_Information_t));
-
-       F1AP_EUTRA_Mode_Info_t eUTRA_Mode_Info;
-       memset((void *)&eUTRA_Mode_Info, 0, sizeof(F1AP_EUTRA_Mode_Info_t));
-
-       // eUTRAFDD
-       eUTRA_Mode_Info.present = F1AP_EUTRA_Mode_Info_PR_eUTRAFDD;
-       F1AP_EUTRA_FDD_Info_t *eutra_fdd_info;
-       eutra_fdd_info = (F1AP_EUTRA_FDD_Info_t *)calloc(1, sizeof(F1AP_EUTRA_FDD_Info_t));
-       eutra_fdd_info->uL_offsetToPointA = 123L;
-       eutra_fdd_info->dL_offsetToPointA = 456L;
-       eUTRA_Mode_Info.choice.eUTRAFDD = eutra_fdd_info;
-
-       // eUTRATDD
-       // eUTRA_Mode_Info.present = F1AP_EUTRA_Mode_Info_PR_eUTRATDD;
-       // F1AP_EUTRA_TDD_Info_t *eutra_tdd_info;
-       // eutra_tdd_info = (F1AP_EUTRA_TDD_Info_t *)calloc(1, sizeof(F1AP_EUTRA_TDD_Info_t));
-       // eutra_tdd_info->uL_offsetToPointA = 123L;
-       // eutra_tdd_info->dL_offsetToPointA = 456L;
-       // eUTRA_Mode_Info.choice.eUTRATDD = eutra_tdd_info;
-
-       served_eutra_cells_information.eUTRA_Mode_Info = eUTRA_Mode_Info;
-
-       OCTET_STRING_fromBuf(&served_eutra_cells_information.protectedEUTRAResourceIndication, "asdsa1d32sa1d31asd31as",
-                       strlen("asdsa1d32sa1d31asd31as"));
-
-       ASN_SEQUENCE_ADD(&protected_eutra_resources_item_ies->value.choice.ListofEUTRACellsinGNBDUCoordination.list, &served_eutra_cells_information);
-
-       ASN_SEQUENCE_ADD(&ie->value.choice.Protected_EUTRA_Resources_List.list, protected_eutra_resources_item_ies);
-      */
+  }
+  */
+
+  // c4. GNB_CU_TNL_Association_To_Add_List
+  /*
+  asn1cSequenceAdd(cfgUpdate->protocolIEs.list, F1AP_GNBCUConfigurationUpdateIEs_t, ieC4);
+  ieC4->id                        = F1AP_ProtocolIE_ID_id_GNB_CU_TNL_Association_To_Add_List;
+  ieC4->criticality               = F1AP_Criticality_reject;
+  ieC4->value.present             = F1AP_GNBCUConfigurationUpdateIEs__value_PR_GNB_CU_TNL_Association_To_Add_List;
+
+  for (int i=0; i<1; i++) {
+    asn1cSequenceAdd(ieC4->value.choice.GNB_CU_TNL_Association_To_Add_List.list,
+         F1AP_GNB_CU_TNL_Association_To_Add_ItemIEs_t, gnb_cu_tnl_association_to_add;
+       gnb_cu_tnl_association_to_add->id = F1AP_ProtocolIE_ID_id_GNB_CU_TNL_Association_To_Add_Item;
+       gnb_cu_tnl_association_to_add->criticality = F1AP_Criticality_reject;
+       gnb_cu_tnl_association_to_add->value.present = F1AP_GNB_CU_TNL_Association_To_Add_ItemIEs__value_PR_GNB_CU_TNL_Association_To_Add_Item;
+
+       // 4.1 GNB_CU_TNL_Association_To_Add_Item
+       F1AP_GNB_CU_TNL_Association_To_Add_Item_t *gnb_cu_tnl_association_to_add_item=
+         &gnb_cu_tnl_association_to_add_item_ies->value.choice.GNB_CU_TNL_Association_To_Add_Item;
+
+       // 4.1.1 tNLAssociationTransportLayerAddress
+       F1AP_CP_TransportLayerAddress_t *transportLayerAddress=;
+         gnb_cu_tnl_association_to_add->value.choice.GNB_CU_TNL_Association_To_Add_Item;
+
+       transportLayerAddress->present = F1AP_CP_TransportLayerAddress_PR_endpoint_IP_address;
+       TRANSPORT_LAYER_ADDRESS_IPv4_TO_BIT_STRING(1234, &transportLayerAddress->choice.endpoint_IP_address);
+
+       // memset((void *)&transportLayerAddress, 0, sizeof(F1AP_CP_TransportLayerAddress_t));
+       // transportLayerAddress.present = F1AP_CP_TransportLayerAddress_PR_endpoint_IP_address_and_port;
+       // transportLayerAddress.choice.endpoint_IP_address_and_port = (F1AP_Endpoint_IP_address_and_port_t *)calloc(1, sizeof(F1AP_Endpoint_IP_address_and_port_t));
+       // TRANSPORT_LAYER_ADDRESS_IPv4_TO_BIT_STRING(1234, &transportLayerAddress.choice.endpoint_IP_address_and_port.endpoint_IP_address);
+
+       // 4.1.2 tNLAssociationUsage
+       gnb_cu_tnl_association_to_add_item->tNLAssociationUsage = F1AP_TNLAssociationUsage_non_ue;
+  }
+  */
+
+  /*
+    // c5. GNB_CU_TNL_Association_To_Remove_List
+  asn1cSequenceAdd(cfgUpdate->protocolIEs.list, F1AP_GNBCUConfigurationUpdateIEs_t, ieC5);
+    ieC5->id                        = F1AP_ProtocolIE_ID_id_GNB_CU_TNL_Association_To_Remove_List;
+    ieC5->criticality               = F1AP_Criticality_reject;
+    ieC5->value.present             = F1AP_GNBCUConfigurationUpdateIEs__value_PR_GNB_CU_TNL_Association_To_Remove_List;
+    for (int i=0; i<1; i++) {
+      asn1cSequenceAdd(ieC5->value.choice.GNB_CU_TNL_Association_To_Remove_List.list,
+           F1AP_GNB_CU_TNL_Association_To_Remove_ItemIEs_t, gnb_cu_tnl_association_to_remove);
+      gnb_cu_tnl_association_to_remove->id = F1AP_ProtocolIE_ID_id_GNB_CU_TNL_Association_To_Remove_Item;
+      gnb_cu_tnl_association_to_remove->criticality = F1AP_Criticality_reject;
+      gnb_cu_tnl_association_to_remove->value.present = F1AP_GNB_CU_TNL_Association_To_Remove_ItemIEs__value_PR_GNB_CU_TNL_Association_To_Remove_Item;
+
+         // 4.1 GNB_CU_TNL_Association_To_Remove_Item
+         F1AP_GNB_CU_TNL_Association_To_Remove_Item_t *gnb_cu_tnl_association_to_remove_item=
+     &gnb_cu_tnl_association_to_remove->value.choice.GNB_CU_TNL_Association_To_Remove_Item;
+
+         // 4.1.1 tNLAssociationTransportLayerAddress
+         F1AP_CP_TransportLayerAddress_t *transportLayerAddress=
+     &gnb_cu_tnl_association_to_remove_item->tNLAssociationTransportLayerAddress;
+         transportLayerAddress->present = F1AP_CP_TransportLayerAddress_PR_endpoint_IP_address;
+         TRANSPORT_LAYER_ADDRESS_IPv4_TO_BIT_STRING(1234, &transportLayerAddress->choice.endpoint_IP_address);
+
+         // memset((void *)&transportLayerAddress, 0, sizeof(F1AP_CP_TransportLayerAddress_t));
+         // transportLayerAddress.present = F1AP_CP_TransportLayerAddress_PR_endpoint_IP_address_and_port;
+         // transportLayerAddress.choice.endpoint_IP_address_and_port = (F1AP_Endpoint_IP_address_and_port_t *)calloc(1, sizeof(F1AP_Endpoint_IP_address_and_port_t));
+         // TRANSPORT_LAYER_ADDRESS_IPv4_TO_BIT_STRING(1234, &transportLayerAddress.choice.endpoint_IP_address_and_port.endpoint_IP_address);
     }
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+  */
+
+  /*
+    //mandatory
+   // c6. GNB_CU_TNL_Association_To_Update_List
+   asn1cSequenceAdd(cfgUpdate->protocolIEs.list, F1AP_GNBCUConfigurationUpdateIEs_t, ieC6);
+   ieC6->id                        = F1AP_ProtocolIE_ID_id_GNB_CU_TNL_Association_To_Update_List;
+   ieC6->criticality               = F1AP_Criticality_reject;
+   ieC6->value.present             = F1AP_GNBCUConfigurationUpdateIEs__value_PR_GNB_CU_TNL_Association_To_Update_List;
+
+   for (int i=0;  i<1; i++) {
+    asn1cSequenceAdd(ieC3->value.choice.GNB_CU_TNL_Association_To_Update_List.list,
+         F1AP_GNB_CU_TNL_Association_To_Update_ItemIEs_t, gnb_cu_tnl_association_to_update);
+     gnb_cu_tnl_association_to_update->id = F1AP_ProtocolIE_ID_id_GNB_CU_TNL_Association_To_Update_Item;
+     gnb_cu_tnl_association_to_update->criticality = F1AP_Criticality_reject;
+     gnb_cu_tnl_association_to_update->value.present = F1AP_GNB_CU_TNL_Association_To_Update_ItemIEs__value_PR_GNB_CU_TNL_Association_To_Update_Item;
+     // 4.1 GNB_CU_TNL_Association_To_Update_Item
+     F1AP_GNB_CU_TNL_Association_To_Update_Item_t *gnb_cu_tnl_association_to_update_item=
+       &gnb_cu_tnl_association_to_update->value.choice.GNB_CU_TNL_Association_To_Update_Item;
+     // 4.1.1 tNLAssociationTransportLayerAddress
+     F1AP_CP_TransportLayerAddress_t *transportLayerAddress=
+       &gnb_cu_tnl_association_to_update_item.tNLAssociationTransportLayerAddress;
+     transportLayerAddress->present = F1AP_CP_TransportLayerAddress_PR_endpoint_IP_address;
+     TRANSPORT_LAYER_ADDRESS_IPv4_TO_BIT_STRING(1234, &transportLayerAddress->choice.endpoint_IP_address);
+     // memset((void *)&transportLayerAddress, 0, sizeof(F1AP_CP_TransportLayerAddress_t));
+     // transportLayerAddress.present = F1AP_CP_TransportLayerAddress_PR_endpoint_IP_address_and_port;
+     // transportLayerAddress.choice.endpoint_IP_address_and_port = (F1AP_Endpoint_IP_address_and_port_t *)calloc(1, sizeof(F1AP_Endpoint_IP_address_and_port_t));
+     // TRANSPORT_LAYER_ADDRESS_IPv4_TO_BIT_STRING(1234, &transportLayerAddress.choice.endpoint_IP_address_and_port.endpoint_IP_address);
+     // 4.1.2 tNLAssociationUsage
+     if (1) {
+       gnb_cu_tnl_association_to_update_item.tNLAssociationUsage = (F1AP_TNLAssociationUsage_t *)calloc(1, sizeof(F1AP_TNLAssociationUsage_t));
+       *gnb_cu_tnl_association_to_update_item.tNLAssociationUsage = F1AP_TNLAssociationUsage_non_ue;
+     }
+   }
+  */
+
+  /*
+  // c7. Cells_to_be_Barred_List
+  asn1cSequenceAdd(cfgUpdate->protocolIEs.list, F1AP_GNBCUConfigurationUpdateIEs_t, ieC7);
+  ieC7->id                        = F1AP_ProtocolIE_ID_id_Cells_to_be_Barred_List;
+  ieC7->criticality               = F1AP_Criticality_reject;
+  ieC7->value.present             = F1AP_GNBCUConfigurationUpdateIEs__value_PR_Cells_to_be_Barred_List;
+
+  for (int i=0; i<1; i++) {
+    asn1cSequenceAdd(ieC7->value.choice.Cells_to_be_Barred_List.list,
+         F1AP_Cells_to_be_Barred_ItemIEs_t,cells_to_be_barred);
+   cells_to_be_barred->id = F1AP_ProtocolIE_ID_id_Cells_to_be_Activated_List_Item;
+   cells_to_be_barred->criticality = F1AP_Criticality_reject;
+   cells_to_be_barred->value.present = F1AP_Cells_to_be_Barred_ItemIEs__value_PR_Cells_to_be_Barred_Item;
+   // 7.1 cells to be Deactivated list item
+   F1AP_Cells_to_be_Barred_Item_t *cells_to_be_barred_item=
+     &cells_to_be_barred_item_ies->value.choice.Cells_to_be_Barred_Item;
+   // - nRCGI
+   addnRCGI(cells_to_be_barred_item->nRCGI, f1ap_gnb_cu_configuration_update->cells_to_activate+i);
+   // 7.2 cellBarred
+   cells_to_be_barred_item->cellBarred = F1AP_CellBarred_not_barred;
   }
-
+  */
+
+  /*
+   // c8. Protected_EUTRA_Resources_List
+  asn1cSequenceAdd(cfgUpdate->protocolIEs.list, F1AP_GNBCUConfigurationUpdateIEs_t, ieC8);
+   ieC8->id                        = F1AP_ProtocolIE_ID_id_Protected_EUTRA_Resources_List;
+   ieC8->criticality               = F1AP_Criticality_reject;
+   ieC8->value.present             = F1AP_GNBCUConfigurationUpdateIEs__value_PR_Protected_EUTRA_Resources_List;
+
+   for (int i=0; i<1; i++) {
+     asn1cSequenceAdd(ieC8->value.choice.Protected_EUTRA_Resources_List.list,
+          F1AP_Protected_EUTRA_Resources_ItemIEs_t, protected_eutra_resources);
+     // 8.1 SpectrumSharingGroupID
+     protected_eutra_resources->id = F1AP_ProtocolIE_ID_id_Protected_EUTRA_Resources_List;
+     protected_eutra_resources->criticality = F1AP_Criticality_reject;
+     protected_eutra_resources->value.present = F1AP_Protected_EUTRA_Resources_ItemIEs__value_PR_Protected_EUTRA_Resources_Item;
+     ((F1AP_Protected_EUTRA_Resources_Item_t *)&protected_eutra_resources->value.choice.Protected_EUTRA_Resources_Item)->spectrumSharingGroupID = 123L;
+     memset(&protected_eutra_resources->value.choice.Protected_EUTRA_Resources_Item,0,
+            sizeof(F1AP_Protected_EUTRA_Resources_Item_t));
+
+     asn1cSequenceAdd(protected_eutra_resources->value.choice.ListofEUTRACellsinGNBDUCoordination.list,
+          F1AP_Served_EUTRA_Cells_Information_t, served_eutra_cells_information);
+      memset((void *)&served_eutra_cells_information, 0, sizeof(F1AP_Served_EUTRA_Cells_Information_t));
+
+      F1AP_EUTRA_Mode_Info_t *eUTRA_Mode_Info=
+  &served_eutra_cells_information.eUTRA_Mode_Info;
+
+      // eUTRAFDD
+      eUTRA_Mode_Info->present = F1AP_EUTRA_Mode_Info_PR_eUTRAFDD;
+      F1AP_EUTRA_FDD_Info_t *eutra_fdd_info = (F1AP_EUTRA_FDD_Info_t *)calloc(1, sizeof(F1AP_EUTRA_FDD_Info_t));
+      eutra_fdd_info->uL_offsetToPointA = 123L;
+      eutra_fdd_info->dL_offsetToPointA = 456L;
+      eUTRA_Mode_Info.choice.eUTRAFDD = eutra_fdd_info;
+
+      // eUTRATDD
+      // eUTRA_Mode_Info.present = F1AP_EUTRA_Mode_Info_PR_eUTRATDD;
+      // F1AP_EUTRA_TDD_Info_t *eutra_tdd_info;
+      // eutra_tdd_info = (F1AP_EUTRA_TDD_Info_t *)calloc(1, sizeof(F1AP_EUTRA_TDD_Info_t));
+      // eutra_tdd_info->uL_offsetToPointA = 123L;
+      // eutra_tdd_info->dL_offsetToPointA = 456L;
+      // eUTRA_Mode_Info.choice.eUTRATDD = eutra_tdd_info;
+
+      OCTET_STRING_fromBuf(&served_eutra_cells_information.protectedEUTRAResourceIndication, "asdsa1d32sa1d31asd31as",
+                      strlen("asdsa1d32sa1d31asd31as"));
+   }
+  */
 
   /* encode */
   if (f1ap_encode_pdu(&pdu, &buffer, &len) < 0) {
@@ -953,38 +754,36 @@ int CU_send_gNB_CU_CONFIGURATION_UPDATE(instance_t instance, f1ap_gnb_cu_configu
     return -1;
   }
 
-  LOG_D(F1AP, "F1AP gNB-CU CONFIGURATION UPDATE\n");
-  //for (int i=0;i<len;i++) printf("%02x ",buffer[i]);
-  //printf("\n");
-
-  cu_f1ap_itti_send_sctp_data_req(instance, f1ap_du_data_from_du->assoc_id, buffer, len, 0);
+  LOG_DUMPMSG(F1AP, LOG_DUMP_CHAR, buffer, len, "F1AP gNB-CU CONFIGURATION UPDATE : ");
+  ASN_STRUCT_RESET(asn_DEF_F1AP_F1AP_PDU, &pdu);
+  f1ap_itti_send_sctp_data_req(true,instance, buffer, len, 0);
   return 0;
 }
 
 int CU_handle_gNB_CU_CONFIGURATION_UPDATE_FAILURE(instance_t instance,
-                                                   uint32_t assoc_id,
-                                                   uint32_t stream,
-                                                   F1AP_F1AP_PDU_t *pdu) {
+    uint32_t assoc_id,
+    uint32_t stream,
+    F1AP_F1AP_PDU_t *pdu) {
   AssertFatal(1==0,"Not implemented yet\n");
 }
 
 int CU_handle_gNB_CU_CONFIGURATION_UPDATE_ACKNOWLEDGE(instance_t instance,
-                                                       uint32_t assoc_id,
-                                                       uint32_t stream,
-                                                       F1AP_F1AP_PDU_t *pdu) {
-  LOG_D(F1AP,"Cell Configuration ok (assoc_id %d)\n",assoc_id);
+    uint32_t assoc_id,
+    uint32_t stream,
+    F1AP_F1AP_PDU_t *pdu) {
+  LOG_I(F1AP,"Cell Configuration ok (assoc_id %d)\n",assoc_id);
   return(0);
 }
 
 
 int CU_handle_gNB_DU_RESOURCE_COORDINATION_REQUEST(instance_t instance,
-                                                    uint32_t assoc_id,
-                                                    uint32_t stream,
-                                                    F1AP_F1AP_PDU_t *pdu) {
+    uint32_t assoc_id,
+    uint32_t stream,
+    F1AP_F1AP_PDU_t *pdu) {
   AssertFatal(0, "Not implemented yet\n");
 }
 
 int CU_send_gNB_DU_RESOURCE_COORDINATION_RESPONSE(instance_t instance,
-                    F1AP_GNBDUResourceCoordinationResponse_t *GNBDUResourceCoordinationResponse) {
+    F1AP_GNBDUResourceCoordinationResponse_t *GNBDUResourceCoordinationResponse) {
   AssertFatal(0, "Not implemented yet\n");
 }
diff --git a/openair2/F1AP/f1ap_cu_interface_management.h b/openair2/F1AP/f1ap_cu_interface_management.h
index de7dcfe99ba9b9b475813010a406a0a12d6297af..83da037925544a3648f60a8c79c6c0fbcb65dd87 100644
--- a/openair2/F1AP/f1ap_cu_interface_management.h
+++ b/openair2/F1AP/f1ap_cu_interface_management.h
@@ -72,39 +72,39 @@ int CU_send_F1_SETUP_FAILURE(instance_t instance);
  * gNB-DU Configuration Update
  */
 int CU_handle_gNB_DU_CONFIGURATION_UPDATE(instance_t instance,
-                                          uint32_t assoc_id,
-                                          uint32_t stream,
-                                          F1AP_F1AP_PDU_t *pdu);
+    uint32_t assoc_id,
+    uint32_t stream,
+    F1AP_F1AP_PDU_t *pdu);
 
 int CU_send_gNB_DU_CONFIGURATION_FAILURE(instance_t instance,
-                    F1AP_GNBDUConfigurationUpdateFailure_t *GNBDUConfigurationUpdateFailure);
+    F1AP_GNBDUConfigurationUpdateFailure_t *GNBDUConfigurationUpdateFailure);
 
 int CU_send_gNB_DU_CONFIGURATION_UPDATE_ACKNOWLEDGE(instance_t instance,
-                    F1AP_GNBDUConfigurationUpdateAcknowledge_t *GNBDUConfigurationUpdateAcknowledge);
+    F1AP_GNBDUConfigurationUpdateAcknowledge_t *GNBDUConfigurationUpdateAcknowledge);
 
 /*
  * gNB-CU Configuration Update
  */
 int CU_send_gNB_CU_CONFIGURATION_UPDATE(instance_t instance, f1ap_gnb_cu_configuration_update_t *f1ap_gnb_cu_configuration_update);
 int CU_handle_gNB_CU_CONFIGURATION_UPDATE_FAILURE(instance_t instance,
-                                                  uint32_t assoc_id,
-                                                  uint32_t stream,
-                                                  F1AP_F1AP_PDU_t *pdu);
+    uint32_t assoc_id,
+    uint32_t stream,
+    F1AP_F1AP_PDU_t *pdu);
 
 int CU_handle_gNB_CU_CONFIGURATION_UPDATE_ACKNOWLEDGE(instance_t instance,
-                                                      uint32_t assoc_id,
-                                                      uint32_t stream,
-                                                      F1AP_F1AP_PDU_t *pdu);
+    uint32_t assoc_id,
+    uint32_t stream,
+    F1AP_F1AP_PDU_t *pdu);
 
 /*
  * gNB-DU Resource Coordination
  */
 int CU_handle_gNB_DU_RESOURCE_COORDINATION_REQUEST(instance_t instance,
-                                                   uint32_t assoc_id,
-                                                   uint32_t stream,
-                                                   F1AP_F1AP_PDU_t *pdu);
+    uint32_t assoc_id,
+    uint32_t stream,
+    F1AP_F1AP_PDU_t *pdu);
 
 int CU_send_gNB_DU_RESOURCE_COORDINATION_RESPONSE(instance_t instance,
-                    F1AP_GNBDUResourceCoordinationResponse_t *GNBDUResourceCoordinationResponse);
+    F1AP_GNBDUResourceCoordinationResponse_t *GNBDUResourceCoordinationResponse);
 
 #endif /* F1AP_CU_INTERFACE_MANAGEMENT_H_ */
diff --git a/openair2/F1AP/f1ap_cu_rrc_message_transfer.c b/openair2/F1AP/f1ap_cu_rrc_message_transfer.c
index 8a5b9785b50f50c95beea62d6f93cbd540db0724..62a62095b16fcd22f70632be95d298bc0cdf901a 100644
--- a/openair2/F1AP/f1ap_cu_rrc_message_transfer.c
+++ b/openair2/F1AP/f1ap_cu_rrc_message_transfer.c
@@ -38,78 +38,54 @@
 #include "common/ran_context.h"
 #include "openair3/UTILS/conversions.h"
 
-// Bing Kai: create CU and DU context, and put all the information there.
-uint64_t        du_ue_f1ap_id = 0;
-uint32_t        f1ap_assoc_id = 0;
-uint32_t        f1ap_stream = 0;
-
-
-extern f1ap_cudu_inst_t f1ap_cu_inst[MAX_eNB];
-
 /*
     Initial UL RRC Message Transfer
 */
 
-extern RAN_CONTEXT_t RC;
-
 int CU_handle_INITIAL_UL_RRC_MESSAGE_TRANSFER(instance_t             instance,
-                                              uint32_t               assoc_id,
-                                              uint32_t               stream,
-                                              F1AP_F1AP_PDU_t       *pdu) {
-
+    uint32_t               assoc_id,
+    uint32_t               stream,
+    F1AP_F1AP_PDU_t       *pdu) {
   LOG_D(F1AP, "CU_handle_INITIAL_UL_RRC_MESSAGE_TRANSFER\n");
   // decode the F1 message
-  // get the rrc message from the contauiner 
+  // get the rrc message from the contauiner
   // call func rrc_eNB_decode_ccch: <-- needs some update here
   MessageDef                            *message_p;
   F1AP_InitialULRRCMessageTransfer_t    *container;
   F1AP_InitialULRRCMessageTransferIEs_t *ie;
-  
   rnti_t          rnti;
   sdu_size_t      ccch_sdu_len;
   int             CC_id =0;
-  
-
   DevAssert(pdu != NULL);
-  
+
   if (stream != 0) {
     LOG_E(F1AP, "[SCTP %d] Received F1 on stream != 0 (%d)\n",
           assoc_id, stream);
     return -1;
   }
-  // TODO: use context 
-  f1ap_stream    = stream;
-  f1ap_assoc_id = assoc_id;
 
   container = &pdu->choice.initiatingMessage->value.choice.InitialULRRCMessageTransfer;
-
   /* GNB_DU_UE_F1AP_ID */
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_InitialULRRCMessageTransferIEs_t, ie, container,
                              F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID, true);
-  du_ue_f1ap_id = ie->value.choice.GNB_DU_UE_F1AP_ID;
-  LOG_D(F1AP, "du_ue_f1ap_id %lu \n", du_ue_f1ap_id);
-
-  /* NRCGI 
-  * TODO: process NRCGI
+  /* NRCGI
+  * Fixme: process NRCGI
   */
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_InitialULRRCMessageTransferIEs_t, ie, container,
                              F1AP_ProtocolIE_ID_id_NRCGI, true);
-
-
   uint64_t nr_cellid;
   BIT_STRING_TO_NR_CELL_IDENTITY(&ie->value.choice.NRCGI.nRCellIdentity,nr_cellid);
-					       
   /* RNTI */
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_InitialULRRCMessageTransferIEs_t, ie, container,
                              F1AP_ProtocolIE_ID_id_C_RNTI, true);
   rnti = ie->value.choice.C_RNTI;
-
   /* RRC Container */
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_InitialULRRCMessageTransferIEs_t, ie, container,
                              F1AP_ProtocolIE_ID_id_RRCContainer, true);
   AssertFatal(ie!=NULL,"RRCContainer is missing\n");
+
   // create an ITTI message and copy SDU
-  if (RC.nrrrc && RC.nrrrc[GNB_INSTANCE_TO_MODULE_ID(instance)]->node_type == ngran_gNB_CU) {
+  if (f1ap_req(true, instance)->cell_type==CELL_MACRO_GNB) {
     message_p = itti_alloc_new_message (TASK_CU_F1, 0, NR_RRC_MAC_CCCH_DATA_IND);
     memset (NR_RRC_MAC_CCCH_DATA_IND (message_p).sdu, 0, CCCH_SDU_SIZE);
     ccch_sdu_len = ie->value.choice.RRCContainer.size;
@@ -123,310 +99,212 @@ int CU_handle_INITIAL_UL_RRC_MESSAGE_TRANSFER(instance_t             instance,
            ccch_sdu_len);
   }
 
-  if (RC.nrrrc && RC.nrrrc[GNB_INSTANCE_TO_MODULE_ID(instance)]->node_type == ngran_gNB_CU) {
-
-    LOG_D(F1AP, "%s() RRCContainer (CCCH) size %ld: ", __func__, ie->value.choice.RRCContainer.size);
-    //for (int i = 0; i < ie->value.choice.RRCContainer.size; i++)
-    //  printf("%02x ", RRC_MAC_CCCH_DATA_IND (message_p).sdu[i]);
-    //printf("\n");
-
-    /* DUtoCURRCContainer */
-    F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_InitialULRRCMessageTransferIEs_t, ie, container,
-                               F1AP_ProtocolIE_ID_id_DUtoCURRCContainer, true);
-    if (ie) {
-      NR_RRC_MAC_CCCH_DATA_IND (message_p).du_to_cu_rrc_container = malloc(sizeof(OCTET_STRING_t));
-      NR_RRC_MAC_CCCH_DATA_IND (message_p).du_to_cu_rrc_container->size = ie->value.choice.DUtoCURRCContainer.size;
-      NR_RRC_MAC_CCCH_DATA_IND (message_p).du_to_cu_rrc_container->buf = malloc(
-          ie->value.choice.DUtoCURRCContainer.size);
-      memcpy(NR_RRC_MAC_CCCH_DATA_IND (message_p).du_to_cu_rrc_container->buf,
-             ie->value.choice.DUtoCURRCContainer.buf,
-             ie->value.choice.DUtoCURRCContainer.size);
-    }
+  LOG_I(F1AP, "%s() RRCContainer (CCCH) size %ld: ", __func__, ie->value.choice.RRCContainer.size);
+  /* DUtoCURRCContainer */
+  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_InitialULRRCMessageTransferIEs_t, ie, container,
+                             F1AP_ProtocolIE_ID_id_DUtoCURRCContainer, false);
+
+  if (ie) {
+    NR_RRC_MAC_CCCH_DATA_IND (message_p).du_to_cu_rrc_container = malloc(sizeof(OCTET_STRING_t));
+    NR_RRC_MAC_CCCH_DATA_IND (message_p).du_to_cu_rrc_container->size = ie->value.choice.DUtoCURRCContainer.size;
+    NR_RRC_MAC_CCCH_DATA_IND (message_p).du_to_cu_rrc_container->buf = malloc(ie->value.choice.DUtoCURRCContainer.size);
+    memcpy(NR_RRC_MAC_CCCH_DATA_IND (message_p).du_to_cu_rrc_container->buf,
+           ie->value.choice.DUtoCURRCContainer.buf,
+           ie->value.choice.DUtoCURRCContainer.size);
   }
 
-  // Find instance from nr_cellid
-  int rrc_inst = -1;
-  if (RC.nrrrc && RC.nrrrc[GNB_INSTANCE_TO_MODULE_ID(instance)]->node_type == ngran_gNB_CU) {
-    for (int i=0;i<RC.nb_nr_inst;i++) {
-      // first get RRC instance (note, no the ITTI instance)
-      gNB_RRC_INST *rrc = RC.nrrrc[i];
-      if (rrc->nr_cellid == nr_cellid) {
-        rrc_inst = i;
-        break;
-      }
-    }
-  } else {
-    for (int i=0;i<RC.nb_inst;i++) {
-          // first get RRC instance (note, no the ITTI instance)
-      eNB_RRC_INST *rrc = RC.rrc[i];
-      if (rrc->nr_cellid == nr_cellid) {
-        rrc_inst = i;
-        break;
-      }
-    }
-  }
-  AssertFatal(rrc_inst>=0,"couldn't find an RRC instance for nr_cell %llu\n",(unsigned long long int)nr_cellid);
+  int f1ap_uid = f1ap_add_ue(CUtype, instance, rnti);
 
-  int f1ap_uid = f1ap_add_ue(&f1ap_cu_inst[rrc_inst], rrc_inst, CC_id, 0, rnti);
   if (f1ap_uid  < 0 ) {
     LOG_E(F1AP, "Failed to add UE \n");
     itti_free(ITTI_MSG_ORIGIN_ID(message_p), message_p);
     return -1;
   }
-  f1ap_cu_inst[rrc_inst].f1ap_ue[f1ap_uid].du_ue_f1ap_id = du_ue_f1ap_id;
-
-  if (RC.nrrrc && RC.nrrrc[GNB_INSTANCE_TO_MODULE_ID(instance)]->node_type == ngran_gNB_CU) {
-    NR_RRC_MAC_CCCH_DATA_IND (message_p).frame     = 0;
-    NR_RRC_MAC_CCCH_DATA_IND (message_p).sub_frame = 0;
-    NR_RRC_MAC_CCCH_DATA_IND (message_p).sdu_size  = ccch_sdu_len;
-    NR_RRC_MAC_CCCH_DATA_IND (message_p).gnb_index = rrc_inst; // CU instance
-    NR_RRC_MAC_CCCH_DATA_IND (message_p).rnti      = rnti;
-    NR_RRC_MAC_CCCH_DATA_IND (message_p).CC_id     = CC_id;
-    itti_send_msg_to_task (TASK_RRC_GNB, instance, message_p);
-  } else {
-    RRC_MAC_CCCH_DATA_IND (message_p).frame      = 0;
-    RRC_MAC_CCCH_DATA_IND (message_p).sub_frame  = 0;
-    RRC_MAC_CCCH_DATA_IND (message_p).sdu_size   = ccch_sdu_len;
-    RRC_MAC_CCCH_DATA_IND (message_p).enb_index  = rrc_inst; // CU instance
-    RRC_MAC_CCCH_DATA_IND (message_p).rnti       = rnti;
-    RRC_MAC_CCCH_DATA_IND (message_p).CC_id      = CC_id;
-    itti_send_msg_to_task (TASK_RRC_ENB, instance, message_p);
-  }
 
+  //getCxt(true,ITTI_MSG_DESTINATION_ID(message_p))->f1ap_ue[f1ap_uid].du_ue_f1ap_id = du_ue_f1ap_id;
+  NR_RRC_MAC_CCCH_DATA_IND (message_p).frame     = 0;
+  NR_RRC_MAC_CCCH_DATA_IND (message_p).sub_frame = 0;
+  NR_RRC_MAC_CCCH_DATA_IND (message_p).sdu_size  = ccch_sdu_len;
+  NR_RRC_MAC_CCCH_DATA_IND (message_p).nr_cellid = nr_cellid; // CU instance
+  NR_RRC_MAC_CCCH_DATA_IND (message_p).rnti      = rnti;
+  NR_RRC_MAC_CCCH_DATA_IND (message_p).CC_id     = CC_id;
+  itti_send_msg_to_task (f1ap_req(true,ITTI_MSG_DESTINATION_ID(message_p))->cell_type==CELL_MACRO_GNB?TASK_RRC_GNB:TASK_RRC_ENB, instance, message_p);
   return 0;
 }
 
-
 /*
     DL RRC Message Transfer.
 */
-
 //void CU_send_DL_RRC_MESSAGE_TRANSFER(F1AP_DLRRCMessageTransfer_t *DLRRCMessageTransfer) {
 int CU_send_DL_RRC_MESSAGE_TRANSFER(instance_t                instance,
-                                    f1ap_dl_rrc_message_t    *f1ap_dl_rrc)
-                                    {
-
+                                    f1ap_dl_rrc_message_t    *f1ap_dl_rrc) {
   LOG_D(F1AP, "CU send DL_RRC_MESSAGE_TRANSFER \n");
-  F1AP_F1AP_PDU_t                 pdu;
+  F1AP_F1AP_PDU_t                 pdu= {0};
   F1AP_DLRRCMessageTransfer_t    *out;
-  F1AP_DLRRCMessageTransferIEs_t *ie;
-
-  uint8_t  *buffer;
-  uint32_t  len;
-
+  uint8_t  *buffer=NULL;
+  uint32_t  len=0;
   /* Create */
-  /* 0. Message Type */ 
-  memset(&pdu, 0, sizeof(pdu));
+  /* 0. Message Type */
   pdu.present = F1AP_F1AP_PDU_PR_initiatingMessage;
-  pdu.choice.initiatingMessage = (F1AP_InitiatingMessage_t *)calloc(1, sizeof(F1AP_InitiatingMessage_t));
-  pdu.choice.initiatingMessage->procedureCode = F1AP_ProcedureCode_id_DLRRCMessageTransfer;
-  pdu.choice.initiatingMessage->criticality   = F1AP_Criticality_ignore;
-  pdu.choice.initiatingMessage->value.present = F1AP_InitiatingMessage__value_PR_DLRRCMessageTransfer;
-  out = &pdu.choice.initiatingMessage->value.choice.DLRRCMessageTransfer;
-  
+  asn1cCalloc(pdu.choice.initiatingMessage, tmp);
+  tmp->procedureCode = F1AP_ProcedureCode_id_DLRRCMessageTransfer;
+  tmp->criticality   = F1AP_Criticality_ignore;
+  tmp->value.present = F1AP_InitiatingMessage__value_PR_DLRRCMessageTransfer;
+  out = &tmp->value.choice.DLRRCMessageTransfer;
   /* mandatory */
   /* c1. GNB_CU_UE_F1AP_ID */
-
-  ie = (F1AP_DLRRCMessageTransferIEs_t *)calloc(1, sizeof(F1AP_DLRRCMessageTransferIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
-  ie->criticality                    = F1AP_Criticality_reject;
-  ie->value.present                  = F1AP_DLRRCMessageTransferIEs__value_PR_GNB_CU_UE_F1AP_ID;
-  ie->value.choice.GNB_CU_UE_F1AP_ID = f1ap_get_cu_ue_f1ap_id(&f1ap_cu_inst[instance], f1ap_dl_rrc->rnti);
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_DLRRCMessageTransferIEs_t, ie1);
+  ie1->id                             = F1AP_ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
+  ie1->criticality                    = F1AP_Criticality_reject;
+  ie1->value.present                  = F1AP_DLRRCMessageTransferIEs__value_PR_GNB_CU_UE_F1AP_ID;
+  ie1->value.choice.GNB_CU_UE_F1AP_ID = f1ap_get_cu_ue_f1ap_id(CUtype, instance, f1ap_dl_rrc->rnti);
   LOG_I(F1AP, "Setting GNB_CU_UE_F1AP_ID %llu associated with UE RNTI %x (instance %ld)\n",
-        (unsigned long long int)ie->value.choice.GNB_CU_UE_F1AP_ID, f1ap_dl_rrc->rnti, instance);
-
-
+        (unsigned long long int)ie1->value.choice.GNB_CU_UE_F1AP_ID, f1ap_dl_rrc->rnti, instance);
   /* mandatory */
   /* c2. GNB_DU_UE_F1AP_ID */
-  ie = (F1AP_DLRRCMessageTransferIEs_t *)calloc(1, sizeof(F1AP_DLRRCMessageTransferIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
-  ie->criticality                    = F1AP_Criticality_reject;
-  ie->value.present                  = F1AP_DLRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
-  ie->value.choice.GNB_DU_UE_F1AP_ID = f1ap_get_du_ue_f1ap_id(&f1ap_cu_inst[instance], f1ap_dl_rrc->rnti);
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-  LOG_I(F1AP, "GNB_DU_UE_F1AP_ID %llu associated with UE RNTI %x \n", (unsigned long long int)ie->value.choice.GNB_DU_UE_F1AP_ID, f1ap_dl_rrc->rnti);
-
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_DLRRCMessageTransferIEs_t, ie2);
+  ie2->id                             = F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
+  ie2->criticality                    = F1AP_Criticality_reject;
+  ie2->value.present                  = F1AP_DLRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
+  ie2->value.choice.GNB_DU_UE_F1AP_ID = f1ap_get_du_ue_f1ap_id(CUtype, instance, f1ap_dl_rrc->rnti);
+  LOG_I(F1AP, "GNB_DU_UE_F1AP_ID %llu associated with UE RNTI %x \n", (unsigned long long int)ie2->value.choice.GNB_DU_UE_F1AP_ID, f1ap_dl_rrc->rnti);
   /* optional */
   /* c3. oldgNB_DU_UE_F1AP_ID */
- /* if (f1ap_dl_rrc->old_gNB_DU_ue_id != 0xFFFFFFFF) {
-    ie = (F1AP_DLRRCMessageTransferIEs_t *)calloc(1, sizeof(F1AP_DLRRCMessageTransferIEs_t));
-    ie->id                                = F1AP_ProtocolIE_ID_id_oldgNB_DU_UE_F1AP_ID;
-    ie->criticality                       = F1AP_Criticality_reject;
-    ie->value.present                     = F1AP_DLRRCMessageTransferIEs__value_PR_NOTHING;
-    ie->value.choice.oldgNB_DU_UE_F1AP_ID = f1ap_dl_rrc->old_gNB_DU_ue_id;
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-  }*/ 
-
+  /* if (f1ap_dl_rrc->old_gNB_DU_ue_id != 0xFFFFFFFF) {
+     asn1cSequenceAdd(out->protocolIEs.list, F1AP_DLRRCMessageTransferIEs_t, ie3);
+     ie3->id                                = F1AP_ProtocolIE_ID_id_oldgNB_DU_UE_F1AP_ID;
+     ie3->criticality                       = F1AP_Criticality_reject;
+     ie3->value.present                     = F1AP_DLRRCMessageTransferIEs__value_PR_NOTHING;
+     ie3->value.choice.oldgNB_DU_UE_F1AP_ID = f1ap_dl_rrc->old_gNB_DU_ue_id;
+   }*/
   /* mandatory */
   /* c4. SRBID */
-  ie = (F1AP_DLRRCMessageTransferIEs_t *)calloc(1, sizeof(F1AP_DLRRCMessageTransferIEs_t));
-  ie->id                            = F1AP_ProtocolIE_ID_id_SRBID;
-  ie->criticality                   = F1AP_Criticality_reject;
-  ie->value.present                 = F1AP_DLRRCMessageTransferIEs__value_PR_SRBID;
-  ie->value.choice.SRBID            = f1ap_dl_rrc->srb_id;
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_DLRRCMessageTransferIEs_t, ie4);
+  ie4->id                            = F1AP_ProtocolIE_ID_id_SRBID;
+  ie4->criticality                   = F1AP_Criticality_reject;
+  ie4->value.present                 = F1AP_DLRRCMessageTransferIEs__value_PR_SRBID;
+  ie4->value.choice.SRBID            = f1ap_dl_rrc->srb_id;
 
   /* optional */
   /* c5. ExecuteDuplication */
   if (f1ap_dl_rrc->execute_duplication) {
-    ie = (F1AP_DLRRCMessageTransferIEs_t *)calloc(1, sizeof(F1AP_DLRRCMessageTransferIEs_t));
-    ie->id                            = F1AP_ProtocolIE_ID_id_ExecuteDuplication;
-    ie->criticality                   = F1AP_Criticality_ignore;
-    ie->value.present                 = F1AP_DLRRCMessageTransferIEs__value_PR_ExecuteDuplication;
-    ie->value.choice.ExecuteDuplication = F1AP_ExecuteDuplication_true;
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    asn1cSequenceAdd(out->protocolIEs.list, F1AP_DLRRCMessageTransferIEs_t, ie5);
+    ie5->id                            = F1AP_ProtocolIE_ID_id_ExecuteDuplication;
+    ie5->criticality                   = F1AP_Criticality_ignore;
+    ie5->value.present                 = F1AP_DLRRCMessageTransferIEs__value_PR_ExecuteDuplication;
+    ie5->value.choice.ExecuteDuplication = F1AP_ExecuteDuplication_true;
   }
 
   // issue in here
   /* mandatory */
   /* c6. RRCContainer */
-  ie = (F1AP_DLRRCMessageTransferIEs_t *)calloc(1, sizeof(F1AP_DLRRCMessageTransferIEs_t));
-  ie->id                            = F1AP_ProtocolIE_ID_id_RRCContainer;
-  ie->criticality                   = F1AP_Criticality_reject;
-  ie->value.present                 = F1AP_DLRRCMessageTransferIEs__value_PR_RRCContainer;
-  OCTET_STRING_fromBuf(&ie->value.choice.RRCContainer, (const char*)f1ap_dl_rrc->rrc_container, f1ap_dl_rrc->rrc_container_length);
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
-  if (RC.nrrrc && RC.nrrrc[GNB_INSTANCE_TO_MODULE_ID(instance)]->node_type == ngran_gNB_CU) {
-    LOG_I(F1AP, "%s() RRCContainer size %d: ", __func__, f1ap_dl_rrc->rrc_container_length);
-    for (int i = 0; i < ie->value.choice.RRCContainer.size; i++)
-      printf("%02x ", f1ap_dl_rrc->rrc_container[i]);
-    printf("\n");
-  }
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_DLRRCMessageTransferIEs_t, ie6);
+  ie6->id                            = F1AP_ProtocolIE_ID_id_RRCContainer;
+  ie6->criticality                   = F1AP_Criticality_reject;
+  ie6->value.present                 = F1AP_DLRRCMessageTransferIEs__value_PR_RRCContainer;
+  OCTET_STRING_fromBuf(&ie6->value.choice.RRCContainer,
+                       (const char *)f1ap_dl_rrc->rrc_container, f1ap_dl_rrc->rrc_container_length);
 
   /* optional */
   /* c7. RAT_FrequencyPriorityInformation */
-  /* TODO */ 
-  int endc=1;
-  ie = (F1AP_DLRRCMessageTransferIEs_t *)calloc(1, sizeof(F1AP_DLRRCMessageTransferIEs_t));
-  ie->id                            = F1AP_ProtocolIE_ID_id_RAT_FrequencyPriorityInformation;
-  ie->criticality                   = F1AP_Criticality_reject;
-  ie->value.present                 = F1AP_DLRRCMessageTransferIEs__value_PR_RAT_FrequencyPriorityInformation;
-  if (endc==1) {
-    ie->value.choice.RAT_FrequencyPriorityInformation.present = F1AP_RAT_FrequencyPriorityInformation_PR_eNDC;
-    ie->value.choice.RAT_FrequencyPriorityInformation.choice.eNDC = 123L;
-  }
-  else {
-    ie->value.choice.RAT_FrequencyPriorityInformation.present = F1AP_RAT_FrequencyPriorityInformation_PR_nGRAN;
-    ie->value.choice.RAT_FrequencyPriorityInformation.choice.nGRAN = 11L;
-  }
+  /* TODO */
+  if (0) {
+    int endc=1;
+    asn1cSequenceAdd(out->protocolIEs.list, F1AP_DLRRCMessageTransferIEs_t, ie7);
+    ie7->id                            = F1AP_ProtocolIE_ID_id_RAT_FrequencyPriorityInformation;
+    ie7->criticality                   = F1AP_Criticality_reject;
+    ie7->value.present                 = F1AP_DLRRCMessageTransferIEs__value_PR_RAT_FrequencyPriorityInformation;
+
+    if (endc==1) {
+      ie7->value.choice.RAT_FrequencyPriorityInformation.present = F1AP_RAT_FrequencyPriorityInformation_PR_eNDC;
+      ie7->value.choice.RAT_FrequencyPriorityInformation.choice.eNDC = 123L;
+    } else {
+      ie7->value.choice.RAT_FrequencyPriorityInformation.present = F1AP_RAT_FrequencyPriorityInformation_PR_nGRAN;
+      ie7->value.choice.RAT_FrequencyPriorityInformation.choice.nGRAN = 11L;
+    }
+
     //ie->value.choice.RAT_FrequencyPriorityInformation.present = F1AP_RAT_FrequencyPriorityInformation_PR_rAT_FrequencySelectionPriority;
     //ie->value.choice.RAT_FrequencyPriorityInformation.choice.rAT_FrequencySelectionPriority = 123L;
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
- 
+  }
+
   /* encode */
   if (f1ap_encode_pdu(&pdu, &buffer, &len) < 0) {
     LOG_E(F1AP, "Failed to encode F1 DL RRC MESSAGE TRANSFER \n");
     return -1;
   }
 
-  cu_f1ap_itti_send_sctp_data_req(instance, f1ap_assoc_id /* BK: fix me*/ , buffer, len, 0 /* BK: fix me*/);
-
+  f1ap_itti_send_sctp_data_req(true, instance, buffer, len, 0 /* BK: fix me*/);
   return 0;
 }
 
 /*
     UL RRC Message Transfer
 */
-
 int CU_handle_UL_RRC_MESSAGE_TRANSFER(instance_t       instance,
                                       uint32_t         assoc_id,
                                       uint32_t         stream,
                                       F1AP_F1AP_PDU_t *pdu) {
-
   LOG_D(F1AP, "CU_handle_UL_RRC_MESSAGE_TRANSFER \n");
-  
   F1AP_ULRRCMessageTransfer_t    *container;
   F1AP_ULRRCMessageTransferIEs_t *ie;
-
   uint64_t        cu_ue_f1ap_id;
   uint64_t        du_ue_f1ap_id;
   uint64_t        srb_id;
-
   DevAssert(pdu != NULL);
-  
+
   if (stream != 0) {
     LOG_E(F1AP, "[SCTP %d] Received F1 on stream != 0 (%d)\n",
-               assoc_id, stream);
+          assoc_id, stream);
     return -1;
   }
 
   container = &pdu->choice.initiatingMessage->value.choice.ULRRCMessageTransfer;
-
-
   /* GNB_CU_UE_F1AP_ID */
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_ULRRCMessageTransferIEs_t, ie, container,
                              F1AP_ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID, true);
   cu_ue_f1ap_id = ie->value.choice.GNB_CU_UE_F1AP_ID;
-  LOG_D(F1AP, "cu_ue_f1ap_id %lu associated with RNTI %x\n", cu_ue_f1ap_id, f1ap_get_rnti_by_cu_id(&f1ap_cu_inst[instance], cu_ue_f1ap_id));
-
-
+  LOG_D(F1AP, "cu_ue_f1ap_id %lu associated with RNTI %x\n",
+        cu_ue_f1ap_id, f1ap_get_rnti_by_cu_id(CUtype, instance, cu_ue_f1ap_id));
   /* GNB_DU_UE_F1AP_ID */
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_ULRRCMessageTransferIEs_t, ie, container,
                              F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID, true);
   du_ue_f1ap_id = ie->value.choice.GNB_DU_UE_F1AP_ID;
-  LOG_D(F1AP, "du_ue_f1ap_id %lu associated with RNTI %x\n", du_ue_f1ap_id, f1ap_get_rnti_by_cu_id(&f1ap_cu_inst[instance], du_ue_f1ap_id));
-
-
+  LOG_D(F1AP, "du_ue_f1ap_id %lu associated with RNTI %x\n",
+        du_ue_f1ap_id, f1ap_get_rnti_by_cu_id(CUtype, instance, du_ue_f1ap_id));
   /* mandatory */
   /* SRBID */
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_ULRRCMessageTransferIEs_t, ie, container,
                              F1AP_ProtocolIE_ID_id_SRBID, true);
   srb_id = ie->value.choice.SRBID;
-  if (srb_id < 1 ) 
+
+  if (srb_id < 1 )
     LOG_E(F1AP, "Unexpected UL RRC MESSAGE for srb_id %lu \n", srb_id);
-  else  
+  else
     LOG_D(F1AP, "UL RRC MESSAGE for srb_id %lu in DCCH \n", srb_id);
 
-
   // issue in here
   /* mandatory */
   /* RRC Container */
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_ULRRCMessageTransferIEs_t, ie, container,
                              F1AP_ProtocolIE_ID_id_RRCContainer, true);
-  // print message in debug mode 
-
-  // create an ITTI message and copy SDU
-
-  /*
-  
-  message_p = itti_alloc_new_message (TASK_CU_F1, 0, RRC_DCCH_DATA_IND);
-
-  RRC_DCCH_DATA_IND (message_p).sdu_p = malloc(ie->value.choice.RRCContainer.size);
-
-  RRC_DCCH_DATA_IND (message_p).sdu_size = ie->value.choice.RRCContainer.size;
-  memcpy(RRC_DCCH_DATA_IND (message_p).sdu_p, ie->value.choice.RRCContainer.buf,
-         ie->value.choice.RRCContainer.size);
-
-  RRC_DCCH_DATA_IND (message_p).dcch_index = srb_id;
-  RRC_DCCH_DATA_IND (message_p).rnti = f1ap_get_rnti_by_cu_id(&f1ap_cu_inst[instance], cu_ue_f1ap_id);
-  RRC_DCCH_DATA_IND (message_p).module_id = instance;
-  RRC_DCCH_DATA_IND (message_p).eNB_index = instance; // not needed for CU
-
-  itti_send_msg_to_task(TASK_RRC_ENB, instance, message_p);
-  */
-  protocol_ctxt_t ctxt;
-  ctxt.module_id = instance;
+  protocol_ctxt_t ctxt={0};
   ctxt.instance = instance;
-  ctxt.rnti = f1ap_get_rnti_by_cu_id(&f1ap_cu_inst[instance], cu_ue_f1ap_id);
+  ctxt.module_id = instance;
+  ctxt.rnti = f1ap_get_rnti_by_cu_id(CUtype, instance, cu_ue_f1ap_id);
   ctxt.enb_flag = 1;
   ctxt.eNB_index = 0;
-  ctxt.configured = 1;
   mem_block_t *mb = get_free_mem_block(ie->value.choice.RRCContainer.size,__func__);
-  memcpy((void*)mb->data,(void*)ie->value.choice.RRCContainer.buf,ie->value.choice.RRCContainer.size);
+  memcpy((void *)mb->data,(void *)ie->value.choice.RRCContainer.buf,ie->value.choice.RRCContainer.size);
   LOG_I(F1AP, "Calling pdcp_data_ind for UE RNTI %x srb_id %lu with size %ld (DCCH) \n", ctxt.rnti, srb_id, ie->value.choice.RRCContainer.size);
-
   //LOG_I(F1AP, "%s() RRCContainer size %lu: ", __func__, ie->value.choice.RRCContainer.size);
   //for (int i = 0; i < ie->value.choice.RRCContainer.size; i++)
   //  printf("%02x ", mb->data[i]);
   //printf("\n");
-
   pdcp_data_ind (&ctxt,
-     1, // srb_flag
-     0, // embms_flag
-     srb_id,
-     ie->value.choice.RRCContainer.size,
-     mb);
+                 1, // srb_flag
+                 0, // embms_flag
+                 srb_id,
+                 ie->value.choice.RRCContainer.size,
+                 mb, NULL, NULL);
   return 0;
 }
diff --git a/openair2/F1AP/f1ap_cu_rrc_message_transfer.h b/openair2/F1AP/f1ap_cu_rrc_message_transfer.h
index 68ebbfe41e81ad2704fd44733943cde85dd62cab..c8c9d3a6f9b79d117287d2df416c5435c68f26b6 100644
--- a/openair2/F1AP/f1ap_cu_rrc_message_transfer.h
+++ b/openair2/F1AP/f1ap_cu_rrc_message_transfer.h
@@ -34,9 +34,9 @@
 #define F1AP_CU_RRC_MESSAGE_TRANSFER_H_
 
 int CU_handle_INITIAL_UL_RRC_MESSAGE_TRANSFER(instance_t       instance,
-                                              uint32_t         assoc_id,
-                                              uint32_t         stream,
-                                              F1AP_F1AP_PDU_t *pdu);
+    uint32_t         assoc_id,
+    uint32_t         stream,
+    F1AP_F1AP_PDU_t *pdu);
 
 int CU_send_DL_RRC_MESSAGE_TRANSFER(instance_t                instance,
                                     f1ap_dl_rrc_message_t    *f1ap_dl_rrc);
diff --git a/openair2/F1AP/f1ap_cu_task.c b/openair2/F1AP/f1ap_cu_task.c
index b261d8e85b2bd63b0af30ee4605b8f01d7504279..13f08b9458846c5118190b3adac681fe51257846 100644
--- a/openair2/F1AP/f1ap_cu_task.c
+++ b/openair2/F1AP/f1ap_cu_task.c
@@ -31,150 +31,134 @@
 */
 
 #include "f1ap_common.h"
-#include "f1ap_handlers.h"
 #include "f1ap_cu_interface_management.h"
 #include "f1ap_cu_rrc_message_transfer.h"
 #include "f1ap_cu_ue_context_management.h"
 #include "f1ap_cu_task.h"
 #include "proto_agent.h"
-
-extern RAN_CONTEXT_t RC;
-extern uint8_t proto_agent_flag;
-
-f1ap_setup_req_t *f1ap_du_data_from_du;
-f1ap_cudu_inst_t f1ap_cu_inst[MAX_eNB];
-
-void cu_task_handle_sctp_association_ind(instance_t instance, sctp_new_association_ind_t *sctp_new_association_ind) {
-  // Nothing
+#include <openair3/ocp-gtpu/gtp_itf.h>
+
+//Fixme: Uniq dirty DU instance, by global var, datamodel need better management
+instance_t CUuniqInstance=0;
+
+static instance_t cu_task_create_gtpu_instance_to_du(eth_params_t *IPaddrs) {
+  openAddr_t tmp= {0};
+  strncpy(tmp.originHost, IPaddrs->my_addr, sizeof(tmp.originHost)-1);
+  strncpy(tmp.destinationHost, IPaddrs->remote_addr, sizeof(tmp.destinationHost)-1);
+  sprintf(tmp.originService, "%d",  IPaddrs->my_portd);
+  sprintf(tmp.destinationService, "%d",  IPaddrs->remote_portd);
+  return ocp_gtpv1Init(tmp);
 }
 
-void cu_task_handle_sctp_association_resp(instance_t instance, sctp_new_association_resp_t *sctp_new_association_resp) {
+static void cu_task_handle_sctp_association_ind(instance_t instance, sctp_new_association_ind_t *sctp_new_association_ind,
+    eth_params_t *IPaddrs) {
+  createF1inst(true, instance, NULL);
+  // save the assoc id
+  f1ap_setup_req_t *f1ap_cu_data=f1ap_req(true, instance);
+  f1ap_cu_data->assoc_id         = sctp_new_association_ind->assoc_id;
+  f1ap_cu_data->sctp_in_streams  = sctp_new_association_ind->in_streams;
+  f1ap_cu_data->sctp_out_streams = sctp_new_association_ind->out_streams;
+  f1ap_cu_data->default_sctp_stream_id = 0;
+  getCxt(CUtype, instance)->gtpInst=cu_task_create_gtpu_instance_to_du(IPaddrs);
+  AssertFatal(getCxt(CUtype, instance)->gtpInst>0,"Failed to create CU F1-U UDP listener");
+  // Fixme: fully inconsistent instances management
+  // dirty global var is a bad fix
+  CUuniqInstance=getCxt(CUtype, instance)->gtpInst;
+}
 
+static void cu_task_handle_sctp_association_resp(instance_t instance, sctp_new_association_resp_t *sctp_new_association_resp) {
   DevAssert(sctp_new_association_resp != NULL);
 
   if (sctp_new_association_resp->sctp_state != SCTP_STATE_ESTABLISHED) {
     LOG_W(F1AP, "Received unsuccessful result for SCTP association (%u), instance %ld, cnx_id %u\n",
-              sctp_new_association_resp->sctp_state,
-              instance,
-              sctp_new_association_resp->ulp_cnx_id);
-
-    if (sctp_new_association_resp->sctp_state == SCTP_STATE_SHUTDOWN)
-      proto_agent_stop(instance);
-      //f1ap_handle_setup_message(instance, sctp_new_association_resp->sctp_state == SCTP_STATE_SHUTDOWN);
-    return; // exit -1 for debugging 
+          sctp_new_association_resp->sctp_state,
+          instance,
+          sctp_new_association_resp->ulp_cnx_id);
+    //if (sctp_new_association_resp->sctp_state == SCTP_STATE_SHUTDOWN)
+    //proto_agent_stop(instance);
+    //f1ap_handle_setup_message(instance, sctp_new_association_resp->sctp_state == SCTP_STATE_SHUTDOWN);
+    return; // exit -1 for debugging
   }
-
-  // go to an init func
-  f1ap_du_data_from_du = (f1ap_setup_req_t *)calloc(1, sizeof(f1ap_setup_req_t));
-  // save the assoc id 
-  f1ap_du_data_from_du->assoc_id         = sctp_new_association_resp->assoc_id;
-  f1ap_du_data_from_du->sctp_in_streams  = sctp_new_association_resp->in_streams;
-  f1ap_du_data_from_du->sctp_out_streams = sctp_new_association_resp->out_streams;
-
-  /* setup parameters for F1U and start the server */
-  const cudu_params_t params = (RC.nrrrc && RC.nrrrc[instance]->node_type == ngran_gNB_CU) ? (cudu_params_t){
-    .local_ipv4_address  = RC.nrrrc[instance]->eth_params_s.my_addr,
-    .local_port          = RC.nrrrc[instance]->eth_params_s.my_portd,
-    .remote_ipv4_address = RC.nrrrc[instance]->eth_params_s.remote_addr,
-    .remote_port         = RC.nrrrc[instance]->eth_params_s.remote_portd
-  } : (cudu_params_t){
-    .local_ipv4_address  = RC.rrc[instance]->eth_params_s.my_addr,
-    .local_port          = RC.rrc[instance]->eth_params_s.my_portd,
-    .remote_ipv4_address = RC.rrc[instance]->eth_params_s.remote_addr,
-    .remote_port         = RC.rrc[instance]->eth_params_s.remote_portd
-  };
-  AssertFatal(proto_agent_start(instance, &params) == 0,
-              "could not start PROTO_AGENT for F1U on instance %ld!\n", instance);
-  proto_agent_flag = 1;
 }
 
-void cu_task_handle_sctp_data_ind(instance_t instance, sctp_data_ind_t *sctp_data_ind) {
+static void cu_task_handle_sctp_data_ind(instance_t instance, sctp_data_ind_t *sctp_data_ind) {
   int result;
-
   DevAssert(sctp_data_ind != NULL);
-
   f1ap_handle_message(instance, 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);
   result = itti_free(TASK_UNKNOWN, sctp_data_ind->buffer);
   AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
 }
 
-void cu_task_send_sctp_init_req(instance_t enb_id) {
+static void cu_task_send_sctp_init_req(instance_t instance, char *my_addr) {
   // 1. get the itti msg, and retrive the enb_id from the message
   // 2. use RC.rrc[enb_id] to fill the sctp_init_t with the ip, port
   // 3. creat an itti message to init
-
   LOG_I(F1AP, "F1AP_CU_SCTP_REQ(create socket)\n");
   MessageDef  *message_p = NULL;
-
   message_p = itti_alloc_new_message (TASK_CU_F1, 0, SCTP_INIT_MSG);
   message_p->ittiMsg.sctp_init.port = F1AP_PORT_NUMBER;
   message_p->ittiMsg.sctp_init.ppid = F1AP_SCTP_PPID;
   message_p->ittiMsg.sctp_init.ipv4 = 1;
   message_p->ittiMsg.sctp_init.ipv6 = 0;
   message_p->ittiMsg.sctp_init.nb_ipv4_addr = 1;
-  if (RC.nrrrc && RC.nrrrc[0]->node_type == ngran_gNB_CU) {
-    message_p->ittiMsg.sctp_init.ipv4_address[0] = inet_addr(RC.nrrrc[enb_id]->eth_params_s.my_addr);
-  } else{
-    message_p->ittiMsg.sctp_init.ipv4_address[0] = inet_addr(RC.rrc[enb_id]->eth_params_s.my_addr);
-  }
+  message_p->ittiMsg.sctp_init.ipv4_address[0] = inet_addr(my_addr);
   /*
    * SR WARNING: ipv6 multi-homing fails sometimes for localhost.
    * * * * Disable it for now.
    */
   message_p->ittiMsg.sctp_init.nb_ipv6_addr = 0;
   message_p->ittiMsg.sctp_init.ipv6_address[0] = "0:0:0:0:0:0:0:1";
-
-  itti_send_msg_to_task(TASK_SCTP, enb_id, message_p);
+  itti_send_msg_to_task(TASK_SCTP, instance, message_p);
 }
 
-
 void *F1AP_CU_task(void *arg) {
-
   MessageDef *received_msg = NULL;
   int         result;
-
   LOG_I(F1AP, "Starting F1AP at CU\n");
-
   // no RLC in CU, initialize mem pool for PDCP
   pool_buffer_init();
-
   itti_mark_task_ready(TASK_CU_F1);
+  eth_params_t *IPaddrs;
+
+  // Hardcoded instance id!
+  if (RC.nrrrc && RC.nrrrc[0]->node_type == ngran_gNB_CU)
+    IPaddrs=&RC.nrrrc[0]->eth_params_s;
+  else
+    IPaddrs=&RC.rrc[0]->eth_params_s;
 
-  cu_task_send_sctp_init_req(0);
+  cu_task_send_sctp_init_req(0, IPaddrs->my_addr);
 
   while (1) {
     itti_receive_msg(TASK_CU_F1, &received_msg);
-    switch (ITTI_MSG_ID(received_msg)) {
 
+    switch (ITTI_MSG_ID(received_msg)) {
       case SCTP_NEW_ASSOCIATION_IND:
         LOG_I(F1AP, "CU Task Received SCTP_NEW_ASSOCIATION_IND for instance %ld\n",
               ITTI_MSG_DESTINATION_INSTANCE(received_msg));
-        cu_task_handle_sctp_association_ind(ITTI_MSG_DESTINATION_INSTANCE(received_msg),
-                                         &received_msg->ittiMsg.sctp_new_association_ind);
+        cu_task_handle_sctp_association_ind(ITTI_MSG_ORIGIN_INSTANCE(received_msg),
+                                            &received_msg->ittiMsg.sctp_new_association_ind,
+                                            IPaddrs);
         break;
 
       case SCTP_NEW_ASSOCIATION_RESP:
         LOG_I(F1AP, "CU Task Received SCTP_NEW_ASSOCIATION_RESP for instance %ld\n",
               ITTI_MSG_DESTINATION_INSTANCE(received_msg));
         cu_task_handle_sctp_association_resp(ITTI_MSG_DESTINATION_INSTANCE(received_msg),
-                                         &received_msg->ittiMsg.sctp_new_association_resp);
+                                             &received_msg->ittiMsg.sctp_new_association_resp);
         break;
 
       case SCTP_DATA_IND:
         LOG_I(F1AP, "CU Task Received SCTP_DATA_IND for Instance %ld\n",
               ITTI_MSG_DESTINATION_INSTANCE(received_msg));
         cu_task_handle_sctp_data_ind(ITTI_MSG_DESTINATION_INSTANCE(received_msg),
-                                        &received_msg->ittiMsg.sctp_data_ind);
+                                     &received_msg->ittiMsg.sctp_data_ind);
         break;
 
       case F1AP_SETUP_RESP: // from rrc
         LOG_I(F1AP, "CU Task Received F1AP_SETUP_RESP\n");
-        // CU_send_f1setup_resp(ITTI_MSG_DESTINATION_INSTANCE(received_msg),
-        //                                       &F1AP_SETUP_RESP(received_msg));
         CU_send_F1_SETUP_RESPONSE(ITTI_MSG_DESTINATION_INSTANCE(received_msg),
-                                               &F1AP_SETUP_RESP(received_msg));
+                                  &F1AP_SETUP_RESP(received_msg));
         break;
 
       case F1AP_GNB_CU_CONFIGURATION_UPDATE: // from rrc
@@ -182,19 +166,19 @@ void *F1AP_CU_task(void *arg) {
         // CU_send_f1setup_resp(ITTI_MSG_DESTINATION_INSTANCE(received_msg),
         //                                       &F1AP_SETUP_RESP(received_msg));
         CU_send_gNB_CU_CONFIGURATION_UPDATE(ITTI_MSG_DESTINATION_INSTANCE(received_msg),
-					    &F1AP_GNB_CU_CONFIGURATION_UPDATE(received_msg));
+                                            &F1AP_GNB_CU_CONFIGURATION_UPDATE(received_msg));
         break;
 
       case F1AP_DL_RRC_MESSAGE: // from rrc
         LOG_I(F1AP, "CU Task Received F1AP_DL_RRC_MESSAGE\n");
         CU_send_DL_RRC_MESSAGE_TRANSFER(ITTI_MSG_DESTINATION_INSTANCE(received_msg),
-                                               &F1AP_DL_RRC_MESSAGE(received_msg));
+                                        &F1AP_DL_RRC_MESSAGE(received_msg));
         break;
 
       case F1AP_UE_CONTEXT_SETUP_REQ: // from rrc
         LOG_I(F1AP, "CU Task Received F1AP_UE_CONTEXT_SETUP_REQ\n");
         CU_send_UE_CONTEXT_SETUP_REQUEST(ITTI_MSG_DESTINATION_INSTANCE(received_msg),
-                                               &F1AP_UE_CONTEXT_SETUP_REQ(received_msg));
+                                         &F1AP_UE_CONTEXT_SETUP_REQ(received_msg));
         break;
 
       case F1AP_UE_CONTEXT_RELEASE_CMD: // from rrc
@@ -203,13 +187,13 @@ void *F1AP_CU_task(void *arg) {
                                            &F1AP_UE_CONTEXT_RELEASE_CMD(received_msg));
         break;
 
-//    case F1AP_SETUP_RESPONSE: // This is from RRC
-//    CU_send_F1_SETUP_RESPONSE(instance, *f1ap_setup_ind, &(F1AP_SETUP_RESP) f1ap_setup_resp)   
-//        break;
-        
-//    case F1AP_SETUP_FAILURE: // This is from RRC
-//    CU_send_F1_SETUP_FAILURE(instance, *f1ap_setup_ind, &(F1AP_SETUP_FAILURE) f1ap_setup_failure)   
-//       break;
+      //    case F1AP_SETUP_RESPONSE: // This is from RRC
+      //    CU_send_F1_SETUP_RESPONSE(instance, *f1ap_setup_ind, &(F1AP_SETUP_RESP) f1ap_setup_resp)
+      //        break;
+
+      //    case F1AP_SETUP_FAILURE: // This is from RRC
+      //    CU_send_F1_SETUP_FAILURE(instance, *f1ap_setup_ind, &(F1AP_SETUP_FAILURE) f1ap_setup_failure)
+      //       break;
 
       case TERMINATE_MESSAGE:
         LOG_W(F1AP, " *** Exiting F1AP thread\n");
@@ -221,9 +205,9 @@ void *F1AP_CU_task(void *arg) {
               ITTI_MSG_ID(received_msg), ITTI_MSG_NAME(received_msg));
         break;
     } // switch
+
     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;
   } // while
 
diff --git a/openair2/F1AP/f1ap_cu_task.h b/openair2/F1AP/f1ap_cu_task.h
index dec844accfb0f00d840ff630cc0a6bcf94a66752..9048d2b157de6312c24a07dd58915283ca7fecb1 100644
--- a/openair2/F1AP/f1ap_cu_task.h
+++ b/openair2/F1AP/f1ap_cu_task.h
@@ -22,11 +22,6 @@
 #ifndef F1AP_CU_TASK_H_
 #define F1AP_CU_TASK_H_
 
-void cu_task_handle_sctp_association_ind(instance_t instance, sctp_new_association_ind_t *sctp_new_association_ind);
-void cu_task_handle_sctp_association_resp(instance_t instance, sctp_new_association_resp_t *sctp_new_association_resp);
-void cu_task_handle_sctp_data_ind(instance_t instance, sctp_data_ind_t *sctp_data_ind);
-void cu_task_send_sctp_init_req(instance_t enb_id);
-
 void *F1AP_CU_task(void *arg);
 
 #endif /* F1AP_CU_TASK_H_ */
diff --git a/openair2/F1AP/f1ap_cu_ue_context_management.c b/openair2/F1AP/f1ap_cu_ue_context_management.c
index da723ba5a38f8612efb899afb1b2532a8be0d0f3..c68bfb3852f1119e445a47197c2452f666625be4 100644
--- a/openair2/F1AP/f1ap_cu_ue_context_management.c
+++ b/openair2/F1AP/f1ap_cu_ue_context_management.c
@@ -43,752 +43,589 @@
 #include "rrc_eNB_S1AP.h"
 #include "rrc_eNB_GTPV1U.h"
 #include "openair2/RRC/NR/rrc_gNB_NGAP.h"
+#include <openair3/ocp-gtpu/gtp_itf.h>
 
-extern f1ap_setup_req_t *f1ap_du_data_from_du;
-extern f1ap_cudu_inst_t f1ap_cu_inst[MAX_eNB];
-extern RAN_CONTEXT_t RC;
-extern uint32_t f1ap_assoc_id;
+static void setQos(F1AP_NonDynamic5QIDescriptor_t *toFill) {
+  asn1cCalloc(toFill, tmp);
+  /* fiveQI */
+  tmp->fiveQI = 1L;
 
-int CU_send_UE_CONTEXT_SETUP_REQUEST(instance_t instance,
-                                     f1ap_ue_context_setup_req_t *f1ap_ue_context_setup_req) {
-  F1AP_F1AP_PDU_t                 pdu;
-  F1AP_UEContextSetupRequest_t    *out;
-  F1AP_UEContextSetupRequestIEs_t *ie;
+  /* OPTIONAL */
+  /* qoSPriorityLevel */
+  if (0) {
+    asn1cCallocOne(toFill->qoSPriorityLevel, 1L);
+  }
 
-  uint8_t  *buffer;
-  uint32_t  len;
-  int       i = 0, j = 0;
+  /* OPTIONAL */
+  /* averagingWindow */
+  if (0) {
+    asn1cCallocOne(toFill->averagingWindow, 1L);
+  }
 
+  /* OPTIONAL */
+  /* maxDataBurstVolume */
+  if (0) {
+    asn1cCallocOne(toFill->maxDataBurstVolume, 1L);
+  }
+}
+
+int CU_send_UE_CONTEXT_SETUP_REQUEST(instance_t instance,
+                                     f1ap_ue_context_setup_t *f1ap_ue_context_setup_req) {
+  F1AP_F1AP_PDU_t  pdu= {0};
   /* Create */
   /* 0. Message Type */
-  memset(&pdu, 0, sizeof(pdu));
   pdu.present = F1AP_F1AP_PDU_PR_initiatingMessage;
-  pdu.choice.initiatingMessage = (F1AP_InitiatingMessage_t *)calloc(1, sizeof(F1AP_InitiatingMessage_t));
-  pdu.choice.initiatingMessage->procedureCode = F1AP_ProcedureCode_id_UEContextSetup;
-  pdu.choice.initiatingMessage->criticality   = F1AP_Criticality_reject;
-  pdu.choice.initiatingMessage->value.present = F1AP_InitiatingMessage__value_PR_UEContextSetupRequest;
-  out = &pdu.choice.initiatingMessage->value.choice.UEContextSetupRequest;
-  
+  asn1cCalloc(pdu.choice.initiatingMessage, tmp);
+  tmp->procedureCode = F1AP_ProcedureCode_id_UEContextSetup;
+  tmp->criticality   = F1AP_Criticality_reject;
+  tmp->value.present = F1AP_InitiatingMessage__value_PR_UEContextSetupRequest;
+  F1AP_UEContextSetupRequest_t    *out = &pdu.choice.initiatingMessage->value.choice.UEContextSetupRequest;
   /* mandatory */
   /* c1. GNB_CU_UE_F1AP_ID */
-  ie = (F1AP_UEContextSetupRequestIEs_t *)calloc(1, sizeof(F1AP_UEContextSetupRequestIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
-  ie->criticality                    = F1AP_Criticality_reject;
-  ie->value.present                  = F1AP_UEContextSetupRequestIEs__value_PR_GNB_CU_UE_F1AP_ID;
-  ie->value.choice.GNB_CU_UE_F1AP_ID = f1ap_ue_context_setup_req->gNB_CU_ue_id;
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextSetupRequestIEs_t, ie1);
+  ie1->id                             = F1AP_ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
+  ie1->criticality                    = F1AP_Criticality_reject;
+  ie1->value.present                  = F1AP_UEContextSetupRequestIEs__value_PR_GNB_CU_UE_F1AP_ID;
+  ie1->value.choice.GNB_CU_UE_F1AP_ID = f1ap_get_cu_ue_f1ap_id(CUtype, instance, f1ap_ue_context_setup_req->rnti); //f1ap_ue_context_setup_req->gNB_CU_ue_id;
 
   /* optional */
   /* c2. GNB_DU_UE_F1AP_ID */
   if (f1ap_ue_context_setup_req->gNB_DU_ue_id) {
-    ie = (F1AP_UEContextSetupRequestIEs_t *)calloc(1, sizeof(F1AP_UEContextSetupRequestIEs_t));
-    ie->id                             = F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
-    ie->criticality                    = F1AP_Criticality_ignore;
-    ie->value.present                  = F1AP_UEContextSetupRequestIEs__value_PR_GNB_DU_UE_F1AP_ID;
-    ie->value.choice.GNB_DU_UE_F1AP_ID = *f1ap_ue_context_setup_req->gNB_DU_ue_id;
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextSetupRequestIEs_t, ie2);
+    ie2->id                             = F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
+    ie2->criticality                    = F1AP_Criticality_ignore;
+    ie2->value.present                  = F1AP_UEContextSetupRequestIEs__value_PR_GNB_DU_UE_F1AP_ID;
+    ie2->value.choice.GNB_DU_UE_F1AP_ID = f1ap_get_du_ue_f1ap_id(CUtype, instance, f1ap_ue_context_setup_req->rnti); //*f1ap_ue_context_setup_req->gNB_DU_ue_id;
   }
 
   /* mandatory */
   /* c3. SpCell_ID */
-  ie = (F1AP_UEContextSetupRequestIEs_t *)calloc(1, sizeof(F1AP_UEContextSetupRequestIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_SpCell_ID;
-  ie->criticality                    = F1AP_Criticality_reject;
-  ie->value.present                  = F1AP_UEContextSetupRequestIEs__value_PR_NRCGI;
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextSetupRequestIEs_t, ie3);
+  ie3->id                             = F1AP_ProtocolIE_ID_id_SpCell_ID;
+  ie3->criticality                    = F1AP_Criticality_reject;
+  ie3->value.present                  = F1AP_UEContextSetupRequestIEs__value_PR_NRCGI;
   /* - nRCGI */
-  F1AP_NRCGI_t nRCGI;
-  memset(&nRCGI, 0, sizeof(F1AP_NRCGI_t));
-  MCC_MNC_TO_PLMNID(f1ap_ue_context_setup_req->mcc,
-                    f1ap_ue_context_setup_req->mnc,
-                    f1ap_ue_context_setup_req->mnc_digit_length,
-                    &nRCGI.pLMN_Identity);
-  NR_CELL_ID_TO_BIT_STRING(f1ap_ue_context_setup_req->nr_cellid, &nRCGI.nRCellIdentity);
-
-  ie->value.choice.NRCGI = nRCGI;
-
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
+  addnRCGI(ie3->value.choice.NRCGI, f1ap_ue_context_setup_req);
   /* mandatory */
   /* c4. ServCellIndex */
-  ie = (F1AP_UEContextSetupRequestIEs_t *)calloc(1, sizeof(F1AP_UEContextSetupRequestIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_ServCellIndex;
-  ie->criticality                    = F1AP_Criticality_reject;
-  ie->value.present                  = F1AP_UEContextSetupRequestIEs__value_PR_ServCellIndex;
-  ie->value.choice.ServCellIndex = 2;
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextSetupRequestIEs_t, ie4);
+  ie4->id                             = F1AP_ProtocolIE_ID_id_ServCellIndex;
+  ie4->criticality                    = F1AP_Criticality_reject;
+  ie4->value.present                  = F1AP_UEContextSetupRequestIEs__value_PR_ServCellIndex;
+  ie4->value.choice.ServCellIndex = 0;
 
   /* optional */
   /* c5. CellULConfigured */
   if (0) {
-    ie = (F1AP_UEContextSetupRequestIEs_t *)calloc(1, sizeof(F1AP_UEContextSetupRequestIEs_t));
-    ie->id                             = F1AP_ProtocolIE_ID_id_SpCellULConfigured;
-    ie->criticality                    = F1AP_Criticality_ignore;
-    ie->value.present                  = F1AP_UEContextSetupRequestIEs__value_PR_CellULConfigured;
-    ie->value.choice.CellULConfigured = F1AP_CellULConfigured_ul;
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextSetupRequestIEs_t, ie5);
+    ie5->id                             = F1AP_ProtocolIE_ID_id_SpCellULConfigured;
+    ie5->criticality                    = F1AP_Criticality_ignore;
+    ie5->value.present                  = F1AP_UEContextSetupRequestIEs__value_PR_CellULConfigured;
+    ie5->value.choice.CellULConfigured = F1AP_CellULConfigured_ul;
   }
 
   /* mandatory */
   /* c6. CUtoDURRCInformation */
-  ie = (F1AP_UEContextSetupRequestIEs_t *)calloc(1, sizeof(F1AP_UEContextSetupRequestIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_CUtoDURRCInformation;
-  ie->criticality                    = F1AP_Criticality_reject;
-  ie->value.present                  = F1AP_UEContextSetupRequestIEs__value_PR_CUtoDURRCInformation;
-  
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextSetupRequestIEs_t, ie6);
+  ie6->id                             = F1AP_ProtocolIE_ID_id_CUtoDURRCInformation;
+  ie6->criticality                    = F1AP_Criticality_reject;
+  ie6->value.present                  = F1AP_UEContextSetupRequestIEs__value_PR_CUtoDURRCInformation;
+
   /* optional */
   /* 6.1 cG_ConfigInfo */
-  ie->value.choice.CUtoDURRCInformation.cG_ConfigInfo = (F1AP_CG_ConfigInfo_t *)calloc(1, sizeof(F1AP_CG_ConfigInfo_t));
-  OCTET_STRING_fromBuf(ie->value.choice.CUtoDURRCInformation.cG_ConfigInfo, "asdsa1d32sa1d31asd31as",
-                       strlen("asdsa1d32sa1d31asd31as"));
-  /* optional */
-  /* 6.2 uE_CapabilityRAT_ContainerList */
-  ie->value.choice.CUtoDURRCInformation.uE_CapabilityRAT_ContainerList = (F1AP_UE_CapabilityRAT_ContainerList_t *)calloc(1, sizeof(F1AP_UE_CapabilityRAT_ContainerList_t));
-  OCTET_STRING_fromBuf(ie->value.choice.CUtoDURRCInformation.uE_CapabilityRAT_ContainerList, "asdsa1d32sa1d31asd31as",
-                       strlen("asdsa1d32sa1d31asd31as"));
-  /* optional */
-  /* 6.3 measConfig */
-  ie->value.choice.CUtoDURRCInformation.measConfig = (F1AP_MeasConfig_t *)calloc(1, sizeof(F1AP_MeasConfig_t));
-  OCTET_STRING_fromBuf(ie->value.choice.CUtoDURRCInformation.measConfig, "asdsa1d32sa1d31asd31as",
-                       strlen("asdsa1d32sa1d31asd31as"));
-
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
+  if (0) {
+    const char cG_ConfigInfoStr[]="asdsa1d32sa1d31asd31as";
+    asn1cCalloc(ie6->value.choice.CUtoDURRCInformation.cG_ConfigInfo, cG_ConfigInfo);
+    OCTET_STRING_fromBuf(cG_ConfigInfo, cG_ConfigInfoStr, strlen( cG_ConfigInfoStr )) ;
+    /* optional */
+    /* 6.2 uE_CapabilityRAT_ContainerList */
+    asn1cCalloc(ie6->value.choice.CUtoDURRCInformation.uE_CapabilityRAT_ContainerList, uE_CapabilityRAT_ContainerList );
+    OCTET_STRING_fromBuf(uE_CapabilityRAT_ContainerList, cG_ConfigInfoStr, strlen( cG_ConfigInfoStr )) ;
+    /* optional */
+    /* 6.3 measConfig */
+    asn1cCalloc(ie6->value.choice.CUtoDURRCInformation.measConfig,  measConfig);
+    OCTET_STRING_fromBuf(measConfig, cG_ConfigInfoStr, strlen( cG_ConfigInfoStr )) ;
+  }
 
   /* mandatory */
   /* c7. Candidate_SpCell_List */
-  ie = (F1AP_UEContextSetupRequestIEs_t *)calloc(1, sizeof(F1AP_UEContextSetupRequestIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_Candidate_SpCell_List;  //90
-  ie->criticality                    = F1AP_Criticality_ignore;
-  ie->value.present                  = F1AP_UEContextSetupRequestIEs__value_PR_Candidate_SpCell_List;
-
-  for (i=0;
-       i<0;
-       i++) {
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextSetupRequestIEs_t, ie7);
+  ie7->id                             = F1AP_ProtocolIE_ID_id_Candidate_SpCell_List;  //90
+  ie7->criticality                    = F1AP_Criticality_ignore;
+  ie7->value.present                  = F1AP_UEContextSetupRequestIEs__value_PR_Candidate_SpCell_List;
 
-    F1AP_Candidate_SpCell_ItemIEs_t *candidate_spCell_item_ies;
-    candidate_spCell_item_ies = (F1AP_Candidate_SpCell_ItemIEs_t *)calloc(1, sizeof(F1AP_Candidate_SpCell_ItemIEs_t));
+  for (int i=0;   i<1;  i++) {
+    asn1cSequenceAdd(ie7->value.choice.Candidate_SpCell_List.list,F1AP_Candidate_SpCell_ItemIEs_t, candidate_spCell_item_ies);
     candidate_spCell_item_ies->id            = F1AP_ProtocolIE_ID_id_Candidate_SpCell_Item; // 91
     candidate_spCell_item_ies->criticality   = F1AP_Criticality_reject;
     candidate_spCell_item_ies->value.present = F1AP_Candidate_SpCell_ItemIEs__value_PR_Candidate_SpCell_Item;
-
     /* 7.1 Candidate_SpCell_Item */
-    F1AP_Candidate_SpCell_Item_t candidate_spCell_item;
-    memset((void *)&candidate_spCell_item, 0, sizeof(F1AP_Candidate_SpCell_Item_t));
-
+    F1AP_Candidate_SpCell_Item_t *candidate_spCell_item=
+      &candidate_spCell_item_ies->value.choice.Candidate_SpCell_Item;
     /* - candidate_SpCell_ID */
-    F1AP_NRCGI_t nRCGI;
+    //FixMe: first cell ???
+    addnRCGI(candidate_spCell_item->candidate_SpCell_ID,f1ap_ue_context_setup_req);
     /* TODO add correct mcc/mnc */
-    MCC_MNC_TO_PLMNID(f1ap_ue_context_setup_req->mcc,
-                      f1ap_ue_context_setup_req->mnc,
-                      f1ap_ue_context_setup_req->mnc_digit_length,
-                      &nRCGI.pLMN_Identity);
-    NR_CELL_ID_TO_BIT_STRING(f1ap_ue_context_setup_req->nr_cellid, &nRCGI.nRCellIdentity);
-
-    candidate_spCell_item.candidate_SpCell_ID = nRCGI;
-
-    /* ADD */
-    candidate_spCell_item_ies->value.choice.Candidate_SpCell_Item = candidate_spCell_item;
-    ASN_SEQUENCE_ADD(&ie->value.choice.Candidate_SpCell_List.list,
-                    candidate_spCell_item_ies);
   }
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
 
   /* optional */
   /* c8. DRXCycle */
   if (0) {
-    ie = (F1AP_UEContextSetupRequestIEs_t *)calloc(1, sizeof(F1AP_UEContextSetupRequestIEs_t));
-    ie->id                             = F1AP_ProtocolIE_ID_id_DRXCycle;
-    ie->criticality                    = F1AP_Criticality_ignore;
-    ie->value.present                  = F1AP_UEContextSetupRequestIEs__value_PR_DRXCycle;
+    asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextSetupRequestIEs_t, ie8);
+    ie8->id                             = F1AP_ProtocolIE_ID_id_DRXCycle;
+    ie8->criticality                    = F1AP_Criticality_ignore;
+    ie8->value.present                  = F1AP_UEContextSetupRequestIEs__value_PR_DRXCycle;
     /* 8.1 longDRXCycleLength */
-    ie->value.choice.DRXCycle.longDRXCycleLength = F1AP_LongDRXCycleLength_ms10; // enum
+    ie8->value.choice.DRXCycle.longDRXCycleLength = F1AP_LongDRXCycleLength_ms10; // enum
 
     /* optional */
     /* 8.2 shortDRXCycleLength */
     if (0) {
-      ie->value.choice.DRXCycle.shortDRXCycleLength = (F1AP_ShortDRXCycleLength_t *)calloc(1, sizeof(F1AP_ShortDRXCycleLength_t));
-      *ie->value.choice.DRXCycle.shortDRXCycleLength = F1AP_ShortDRXCycleLength_ms2; // enum
+      asn1cCallocOne(ie6->value.choice.DRXCycle.shortDRXCycleLength,
+                     F1AP_ShortDRXCycleLength_ms2); // enum
     }
 
     /* optional */
     /* 8.3 shortDRXCycleTimer */
     if (0) {
-      ie->value.choice.DRXCycle.shortDRXCycleTimer = (F1AP_ShortDRXCycleTimer_t *)calloc(1, sizeof(F1AP_ShortDRXCycleTimer_t));
-      *ie->value.choice.DRXCycle.shortDRXCycleTimer = 123L;
+      asn1cCallocOne(ie8->value.choice.DRXCycle.shortDRXCycleTimer,
+                     123L);
     }
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
   }
 
   /* optional */
   /* c9. ResourceCoordinationTransferContainer */
   if (0) {
-    ie = (F1AP_UEContextSetupRequestIEs_t *)calloc(1, sizeof(F1AP_UEContextSetupRequestIEs_t));
-    ie->id                             = F1AP_ProtocolIE_ID_id_ResourceCoordinationTransferContainer;
-    ie->criticality                    = F1AP_Criticality_ignore;
-    ie->value.present                  = F1AP_UEContextSetupRequestIEs__value_PR_ResourceCoordinationTransferContainer;
-    
-    ie->value.choice.ResourceCoordinationTransferContainer.buf = malloc(4);
-    ie->value.choice.ResourceCoordinationTransferContainer.size = 4;
-    strncpy((char *)ie->value.choice.ResourceCoordinationTransferContainer.buf, "123", 4);
-
-
-    OCTET_STRING_fromBuf(&ie->value.choice.ResourceCoordinationTransferContainer, "asdsa1d32sa1d31asd31as",
+    asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextSetupRequestIEs_t, ie9);
+    ie9->id                             = F1AP_ProtocolIE_ID_id_ResourceCoordinationTransferContainer;
+    ie9->criticality                    = F1AP_Criticality_ignore;
+    ie9->value.present                  = F1AP_UEContextSetupRequestIEs__value_PR_ResourceCoordinationTransferContainer;
+    ie9->value.choice.ResourceCoordinationTransferContainer.buf = malloc(4);
+    ie9->value.choice.ResourceCoordinationTransferContainer.size = 4;
+    strncpy((char *)ie9->value.choice.ResourceCoordinationTransferContainer.buf, "123", 4);
+    OCTET_STRING_fromBuf(&ie9->value.choice.ResourceCoordinationTransferContainer, "asdsa1d32sa1d31asd31as",
                          strlen("asdsa1d32sa1d31asd31as"));
-
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
   }
 
   /* mandatory */
   /* c10. SCell_ToBeSetup_List */
-  ie = (F1AP_UEContextSetupRequestIEs_t *)calloc(1, sizeof(F1AP_UEContextSetupRequestIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_SCell_ToBeSetup_List;
-  ie->criticality                    = F1AP_Criticality_ignore;
-  ie->value.present                  = F1AP_UEContextSetupRequestIEs__value_PR_SCell_ToBeSetup_List;
-
-  for (i=0;
-       i<0;
-       i++) {
-     //
-     F1AP_SCell_ToBeSetup_ItemIEs_t *scell_toBeSetup_item_ies;
-     scell_toBeSetup_item_ies = (F1AP_SCell_ToBeSetup_ItemIEs_t *)calloc(1, sizeof(F1AP_SCell_ToBeSetup_ItemIEs_t));
-     scell_toBeSetup_item_ies->id            = F1AP_ProtocolIE_ID_id_SCell_ToBeSetup_Item; //53
-     scell_toBeSetup_item_ies->criticality   = F1AP_Criticality_ignore;
-     scell_toBeSetup_item_ies->value.present = F1AP_SCell_ToBeSetup_ItemIEs__value_PR_SCell_ToBeSetup_Item;
-
-     /* 10.1 SCell_ToBeSetup_Item */
-     F1AP_SCell_ToBeSetup_Item_t scell_toBeSetup_item;
-     memset((void *)&scell_toBeSetup_item, 0, sizeof(F1AP_SCell_ToBeSetup_Item_t));
-
-     /* 10.1.1 sCell_ID */
-     F1AP_NRCGI_t nRCGI;
-     /* TODO correct MCC/MNC */
-     MCC_MNC_TO_PLMNID(f1ap_ue_context_setup_req->mcc,
-                       f1ap_ue_context_setup_req->mnc,
-                       f1ap_ue_context_setup_req->mnc_digit_length,
-                       &nRCGI.pLMN_Identity);
-     NR_CELL_ID_TO_BIT_STRING(12345678, &nRCGI.nRCellIdentity);
-     scell_toBeSetup_item.sCell_ID = nRCGI;
-
-     /* 10.1.2 sCellIndex */
-     scell_toBeSetup_item.sCellIndex = 3;  // issue here
-
-     /* OPTIONAL */
-     /* 10.1.3 sCellULConfigured*/
-     if (0) {
-       scell_toBeSetup_item.sCellULConfigured = (F1AP_CellULConfigured_t *)calloc(1, sizeof(F1AP_CellULConfigured_t));
-       *scell_toBeSetup_item.sCellULConfigured = F1AP_CellULConfigured_ul_and_sul; // enum
-     }
-
-     /* ADD */
-     scell_toBeSetup_item_ies->value.choice.SCell_ToBeSetup_Item = scell_toBeSetup_item;
-
-     ASN_SEQUENCE_ADD(&ie->value.choice.SCell_ToBeSetup_List.list,
-                     scell_toBeSetup_item_ies);
-  }
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextSetupRequestIEs_t, ie10);
+  ie10->id                             = F1AP_ProtocolIE_ID_id_SCell_ToBeSetup_List;
+  ie10->criticality                    = F1AP_Criticality_ignore;
+  ie10->value.present                  = F1AP_UEContextSetupRequestIEs__value_PR_SCell_ToBeSetup_List;
 
+  for (int i=0; i<1; i++) {
+    //
+    asn1cSequenceAdd(ie10->value.choice.SCell_ToBeSetup_List.list, F1AP_SCell_ToBeSetup_ItemIEs_t, scell_toBeSetup_item_ies);
+    scell_toBeSetup_item_ies->id            = F1AP_ProtocolIE_ID_id_SCell_ToBeSetup_Item; //53
+    scell_toBeSetup_item_ies->criticality   = F1AP_Criticality_ignore;
+    scell_toBeSetup_item_ies->value.present = F1AP_SCell_ToBeSetup_ItemIEs__value_PR_SCell_ToBeSetup_Item;
+    /* 10.1 SCell_ToBeSetup_Item */
+    F1AP_SCell_ToBeSetup_Item_t *scell_toBeSetup_item=&scell_toBeSetup_item_ies->value.choice.SCell_ToBeSetup_Item;
+    /* 10.1.1 sCell_ID */
+    addnRCGI(scell_toBeSetup_item->sCell_ID, f1ap_ue_context_setup_req);
+    /* TODO correct MCC/MNC */
+    /* 10.1.2 sCellIndex */
+    scell_toBeSetup_item->sCellIndex = 3;  // issue here
+
+    /* OPTIONAL */
+    /* 10.1.3 sCellULConfigured*/
+    if (0) {
+      asn1cCallocOne(scell_toBeSetup_item->sCellULConfigured,
+                     F1AP_CellULConfigured_ul_and_sul); // enum
+    }
+  }
 
   /* mandatory */
   /* c11. SRBs_ToBeSetup_List */
-  ie = (F1AP_UEContextSetupRequestIEs_t *)calloc(1, sizeof(F1AP_UEContextSetupRequestIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_SRBs_ToBeSetup_List;
-  ie->criticality                    = F1AP_Criticality_reject;  // ?
-  ie->value.present                  = F1AP_UEContextSetupRequestIEs__value_PR_SRBs_ToBeSetup_List;
-
-  for (i=0;
-       i<0;
-       i++) {
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextSetupRequestIEs_t, ie11);
+  ie11->id                             = F1AP_ProtocolIE_ID_id_SRBs_ToBeSetup_List;
+  ie11->criticality                    = F1AP_Criticality_reject;  // ?
+  ie11->value.present                  = F1AP_UEContextSetupRequestIEs__value_PR_SRBs_ToBeSetup_List;
+
+  for (int i=0; i<f1ap_ue_context_setup_req->srbs_to_be_setup_length; i++) {
     //
-    F1AP_SRBs_ToBeSetup_ItemIEs_t *srbs_toBeSetup_item_ies;
-    srbs_toBeSetup_item_ies = (F1AP_SRBs_ToBeSetup_ItemIEs_t *)calloc(1, sizeof(F1AP_SRBs_ToBeSetup_ItemIEs_t));
+    asn1cSequenceAdd(ie11->value.choice.SRBs_ToBeSetup_List.list, F1AP_SRBs_ToBeSetup_ItemIEs_t, srbs_toBeSetup_item_ies);
     srbs_toBeSetup_item_ies->id            = F1AP_ProtocolIE_ID_id_SRBs_ToBeSetup_Item; // 73
     srbs_toBeSetup_item_ies->criticality   = F1AP_Criticality_ignore;
     srbs_toBeSetup_item_ies->value.present = F1AP_SRBs_ToBeSetup_ItemIEs__value_PR_SRBs_ToBeSetup_Item;
-
     /* 11.1 SRBs_ToBeSetup_Item */
-    F1AP_SRBs_ToBeSetup_Item_t srbs_toBeSetup_item;
-    memset((void *)&srbs_toBeSetup_item, 0, sizeof(F1AP_SRBs_ToBeSetup_Item_t));
-
+    F1AP_SRBs_ToBeSetup_Item_t *srbs_toBeSetup_item=&srbs_toBeSetup_item_ies->value.choice.SRBs_ToBeSetup_Item;
     /* 11.1.1 sRBID */
-    srbs_toBeSetup_item.sRBID = 2L;
-
+    srbs_toBeSetup_item->sRBID = f1ap_ue_context_setup_req->srbs_to_be_setup[i].srb_id;
     /* OPTIONAL */
     /* 11.1.2 duplicationIndication */
-    if (0) {
-      srbs_toBeSetup_item.duplicationIndication = (F1AP_DuplicationIndication_t *)calloc(1, sizeof(F1AP_DuplicationIndication_t));
-      srbs_toBeSetup_item.duplicationIndication = F1AP_DuplicationIndication_true; // enum
-    }
-
-    /* ADD */
-    srbs_toBeSetup_item_ies->value.choice.SRBs_ToBeSetup_Item = srbs_toBeSetup_item;
-    ASN_SEQUENCE_ADD(&ie->value.choice.SRBs_ToBeSetup_List.list,
-                    srbs_toBeSetup_item_ies);
+    //if (0) {
+    asn1cCallocOne(srbs_toBeSetup_item->duplicationIndication,
+                   F1AP_DuplicationIndication_true); // enum
+    //}
   }
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
 
   /* mandatory */
   /* c12. DRBs_ToBeSetup_List */
-  ie = (F1AP_UEContextSetupRequestIEs_t *)calloc(1, sizeof(F1AP_UEContextSetupRequestIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_DRBs_ToBeSetup_List;
-  ie->criticality                    = F1AP_Criticality_reject;
-  ie->value.present                  = F1AP_UEContextSetupRequestIEs__value_PR_DRBs_ToBeSetup_List;
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextSetupRequestIEs_t, ie12);
+  ie12->id                             = F1AP_ProtocolIE_ID_id_DRBs_ToBeSetup_List;
+  ie12->criticality                    = F1AP_Criticality_reject;
+  ie12->value.present                  = F1AP_UEContextSetupRequestIEs__value_PR_DRBs_ToBeSetup_List;
+  LOG_I(F1AP, "Length of drbs_to_be_setup: %d \n", f1ap_ue_context_setup_req->drbs_to_be_setup_length);
 
-  for (i = 0; i < f1ap_ue_context_setup_req->drbs_to_be_setup_length; i++) {
+  for (int i = 0; i < f1ap_ue_context_setup_req->drbs_to_be_setup_length; i++) {
     //
-    F1AP_DRBs_ToBeSetup_ItemIEs_t *drbs_toBeSetup_item_ies;
-    drbs_toBeSetup_item_ies = (F1AP_DRBs_ToBeSetup_ItemIEs_t *)calloc(1, sizeof(F1AP_DRBs_ToBeSetup_ItemIEs_t));
+    asn1cSequenceAdd(ie12->value.choice.DRBs_ToBeSetup_List.list, F1AP_DRBs_ToBeSetup_ItemIEs_t, drbs_toBeSetup_item_ies);
     drbs_toBeSetup_item_ies->id            = F1AP_ProtocolIE_ID_id_DRBs_ToBeSetup_Item;
     drbs_toBeSetup_item_ies->criticality   = F1AP_Criticality_reject;
     drbs_toBeSetup_item_ies->value.present = F1AP_DRBs_ToBeSetup_ItemIEs__value_PR_DRBs_ToBeSetup_Item;
-
     /* 12.1 DRBs_ToBeSetup_Item */
-    F1AP_DRBs_ToBeSetup_Item_t drbs_toBeSetup_item;
-    memset((void *)&drbs_toBeSetup_item, 0, sizeof(F1AP_DRBs_ToBeSetup_Item_t));
-
+    F1AP_DRBs_ToBeSetup_Item_t *drbs_toBeSetup_item=&drbs_toBeSetup_item_ies->value.choice.DRBs_ToBeSetup_Item;
     /* 12.1.1 dRBID */
-    drbs_toBeSetup_item.dRBID = f1ap_ue_context_setup_req->drbs_to_be_setup[i].drb_id; // 9
-
+    drbs_toBeSetup_item->dRBID = f1ap_ue_context_setup_req->drbs_to_be_setup[i].drb_id; // 9
     /* 12.1.2 qoSInformation */
-    int some_decide_qos = 1; // BK: Need Check
-    if (some_decide_qos) {
-      drbs_toBeSetup_item.qoSInformation.present = F1AP_QoSInformation_PR_eUTRANQoS;
+    int some_decide_qos = 0; // BK: Need Check
 
+    if (some_decide_qos) {
+      drbs_toBeSetup_item->qoSInformation.present = F1AP_QoSInformation_PR_eUTRANQoS;
       /*  12.1.2.1 eUTRANQoS */
-      drbs_toBeSetup_item.qoSInformation.choice.eUTRANQoS = (F1AP_EUTRANQoS_t *)calloc(1, sizeof(F1AP_EUTRANQoS_t));
-
+      asn1cCalloc(drbs_toBeSetup_item->qoSInformation.choice.eUTRANQoS, eUTRANQoS);
       /*  12.1.2.1.1 qCI */
-      drbs_toBeSetup_item.qoSInformation.choice.eUTRANQoS->qCI = 254L;
-
+      eUTRANQoS->qCI = 254L;
       /*  12.1.2.1.2 allocationAndRetentionPriority */
       {
         /*  12.1.2.1.2.1 priorityLevel */
-        drbs_toBeSetup_item.qoSInformation.choice.eUTRANQoS->allocationAndRetentionPriority.priorityLevel = F1AP_PriorityLevel_highest; // enum
-        
+        eUTRANQoS->allocationAndRetentionPriority.priorityLevel = F1AP_PriorityLevel_highest; // enum
         /*  12.1.2.1.2.2 pre_emptionCapability */
-        drbs_toBeSetup_item.qoSInformation.choice.eUTRANQoS->allocationAndRetentionPriority.pre_emptionCapability = F1AP_Pre_emptionCapability_may_trigger_pre_emption; // enum
-
+        eUTRANQoS->allocationAndRetentionPriority.pre_emptionCapability = F1AP_Pre_emptionCapability_may_trigger_pre_emption; // enum
         /*  12.1.2.1.2.2 pre_emptionVulnerability */
-        drbs_toBeSetup_item.qoSInformation.choice.eUTRANQoS->allocationAndRetentionPriority.pre_emptionVulnerability = F1AP_Pre_emptionVulnerability_not_pre_emptable; // enum
+        eUTRANQoS->allocationAndRetentionPriority.pre_emptionVulnerability = F1AP_Pre_emptionVulnerability_not_pre_emptable; // enum
       }
 
       /* OPTIONAL */
       /*  12.1.2.1.3 gbrQosInformation */
       if (0) {
-        drbs_toBeSetup_item.qoSInformation.choice.eUTRANQoS->gbrQosInformation = (F1AP_GBR_QosInformation_t *)calloc(1, sizeof(F1AP_GBR_QosInformation_t));
-        asn_long2INTEGER(&drbs_toBeSetup_item.qoSInformation.choice.eUTRANQoS->gbrQosInformation->e_RAB_MaximumBitrateDL, 1L);
-        asn_long2INTEGER(&drbs_toBeSetup_item.qoSInformation.choice.eUTRANQoS->gbrQosInformation->e_RAB_MaximumBitrateUL, 1L);
-        asn_long2INTEGER(&drbs_toBeSetup_item.qoSInformation.choice.eUTRANQoS->gbrQosInformation->e_RAB_GuaranteedBitrateDL, 1L);
-        asn_long2INTEGER(&drbs_toBeSetup_item.qoSInformation.choice.eUTRANQoS->gbrQosInformation->e_RAB_GuaranteedBitrateUL, 1L);
+        eUTRANQoS->gbrQosInformation = (F1AP_GBR_QosInformation_t *)calloc(1, sizeof(F1AP_GBR_QosInformation_t));
+        asn_long2INTEGER(&eUTRANQoS->gbrQosInformation->e_RAB_MaximumBitrateDL, 1L);
+        asn_long2INTEGER(&eUTRANQoS->gbrQosInformation->e_RAB_MaximumBitrateUL, 1L);
+        asn_long2INTEGER(&eUTRANQoS->gbrQosInformation->e_RAB_GuaranteedBitrateDL, 1L);
+        asn_long2INTEGER(&eUTRANQoS->gbrQosInformation->e_RAB_GuaranteedBitrateUL, 1L);
       }
-
-    } else { 
+    } else {
       /* 12.1.2 DRB_Information */
-      drbs_toBeSetup_item.qoSInformation.present = F1AP_QoSInformation_PR_choice_extension;
-
-      F1AP_QoSInformation_ExtIEs_t *ie;
-      ie = (F1AP_QoSInformation_ExtIEs_t *)calloc(1, sizeof(F1AP_QoS_Characteristics_ExtIEs_t));
+      drbs_toBeSetup_item->qoSInformation.present = F1AP_QoSInformation_PR_choice_extension;
+      F1AP_QoSInformation_ExtIEs_t *ie = (F1AP_QoSInformation_ExtIEs_t *)calloc(1, sizeof(*ie));
       ie->id                             = F1AP_ProtocolIE_ID_id_DRB_Information;
       ie->criticality                    = F1AP_Criticality_reject;
       ie->value.present                  = F1AP_QoSInformation_ExtIEs__value_PR_DRB_Information;
       F1AP_DRB_Information_t   *DRB_Information = &ie->value.choice.DRB_Information;
-
-      drbs_toBeSetup_item.qoSInformation.choice.choice_extension = (struct F1AP_ProtocolIE_SingleContainer*)ie;
-
-
+      drbs_toBeSetup_item->qoSInformation.choice.choice_extension = (struct F1AP_ProtocolIE_SingleContainer *)ie;
       /* 12.1.2.1 dRB_QoS */
       {
         /* qoS_Characteristics */
         {
-          int some_decide_qoS_characteristics = 1; // BK: Need Check
+          int some_decide_qoS_characteristics = 0; // BK: Need Check
+
           if (some_decide_qoS_characteristics) {
             DRB_Information->dRB_QoS.qoS_Characteristics.present = F1AP_QoS_Characteristics_PR_non_Dynamic_5QI;
-            DRB_Information->dRB_QoS.qoS_Characteristics.choice.non_Dynamic_5QI = (F1AP_NonDynamic5QIDescriptor_t *)calloc(1, sizeof(F1AP_NonDynamic5QIDescriptor_t));
-            
-            /* fiveQI */
-            DRB_Information->dRB_QoS.qoS_Characteristics.choice.non_Dynamic_5QI->fiveQI = 1L;
-
-            /* OPTIONAL */
-            /* qoSPriorityLevel */
-            if (0) {
-              DRB_Information->dRB_QoS.qoS_Characteristics.choice.non_Dynamic_5QI->qoSPriorityLevel = (long *)calloc(1, sizeof(long));
-              *DRB_Information->dRB_QoS.qoS_Characteristics.choice.non_Dynamic_5QI->qoSPriorityLevel = 1L;
-            }
-
-            /* OPTIONAL */
-            /* averagingWindow */
-            if (0) {
-              DRB_Information->dRB_QoS.qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow = (F1AP_AveragingWindow_t *)calloc(1, sizeof(F1AP_AveragingWindow_t));
-              *DRB_Information->dRB_QoS.qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow = 1L;
-            }
-
-            /* OPTIONAL */
-            /* maxDataBurstVolume */
-            if (0) {
-              DRB_Information->dRB_QoS.qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume = (F1AP_MaxDataBurstVolume_t *)calloc(1, sizeof(F1AP_MaxDataBurstVolume_t));
-              *DRB_Information->dRB_QoS.qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume = 1L;
-            }
-
+            setQos(DRB_Information->dRB_QoS.qoS_Characteristics.choice.non_Dynamic_5QI);
           } else {
             DRB_Information->dRB_QoS.qoS_Characteristics.present = F1AP_QoS_Characteristics_PR_dynamic_5QI;
-            DRB_Information->dRB_QoS.qoS_Characteristics.choice.dynamic_5QI = (F1AP_Dynamic5QIDescriptor_t *)calloc(1, sizeof(F1AP_Dynamic5QIDescriptor_t));
-            
+            asn1cCalloc(DRB_Information->dRB_QoS.qoS_Characteristics.choice.dynamic_5QI, tmp);
             /* qoSPriorityLevel */
-            DRB_Information->dRB_QoS.qoS_Characteristics.choice.dynamic_5QI->qoSPriorityLevel = 1L;
-
+            tmp->qoSPriorityLevel = 1L;
             /* packetDelayBudget */
-            DRB_Information->dRB_QoS.qoS_Characteristics.choice.dynamic_5QI->packetDelayBudget = 1L;
-
+            tmp->packetDelayBudget = 1L;
             /* packetErrorRate */
-            DRB_Information->dRB_QoS.qoS_Characteristics.choice.dynamic_5QI->packetErrorRate.pER_Scalar = 1L;
-            DRB_Information->dRB_QoS.qoS_Characteristics.choice.dynamic_5QI->packetErrorRate.pER_Exponent = 6L;
-
+            tmp->packetErrorRate.pER_Scalar = 1L;
+            tmp->packetErrorRate.pER_Exponent = 6L;
 
             /* OPTIONAL */
             /* delayCritical */
             if (0) {
-              DRB_Information->dRB_QoS.qoS_Characteristics.choice.dynamic_5QI->delayCritical = (long *)calloc(1, sizeof(long));
-              *DRB_Information->dRB_QoS.qoS_Characteristics.choice.dynamic_5QI->delayCritical = 1L;
+              asn1cCallocOne(DRB_Information->dRB_QoS.qoS_Characteristics.choice.dynamic_5QI->delayCritical, 1L);
             }
 
             /* OPTIONAL */
             /* averagingWindow */
             if (0) {
-              DRB_Information->dRB_QoS.qoS_Characteristics.choice.dynamic_5QI->averagingWindow = (F1AP_AveragingWindow_t *)calloc(1, sizeof(F1AP_AveragingWindow_t));
-              *DRB_Information->dRB_QoS.qoS_Characteristics.choice.dynamic_5QI->averagingWindow = 1L;
+              asn1cCallocOne(DRB_Information->dRB_QoS.qoS_Characteristics.choice.dynamic_5QI->averagingWindow, 1L);
             }
 
             /* OPTIONAL */
             /* maxDataBurstVolume */
             if (0) {
-              DRB_Information->dRB_QoS.qoS_Characteristics.choice.dynamic_5QI->maxDataBurstVolume = (F1AP_MaxDataBurstVolume_t *)calloc(1, sizeof(F1AP_MaxDataBurstVolume_t));
-              *DRB_Information->dRB_QoS.qoS_Characteristics.choice.dynamic_5QI->maxDataBurstVolume = 1L;
+              asn1cCallocOne(DRB_Information->dRB_QoS.qoS_Characteristics.choice.dynamic_5QI->maxDataBurstVolume, 1L);
             }
-
           } // if some_decide_qoS_characteristics
-
         } // qoS_Characteristics
-
         /* nGRANallocationRetentionPriority */
         {
-            DRB_Information->dRB_QoS.nGRANallocationRetentionPriority.priorityLevel = F1AP_PriorityLevel_highest; // enum
-            DRB_Information->dRB_QoS.nGRANallocationRetentionPriority.pre_emptionCapability = F1AP_Pre_emptionCapability_shall_not_trigger_pre_emption; // enum
-            DRB_Information->dRB_QoS.nGRANallocationRetentionPriority.pre_emptionVulnerability = F1AP_Pre_emptionVulnerability_not_pre_emptable; // enum
+          DRB_Information->dRB_QoS.nGRANallocationRetentionPriority.priorityLevel = F1AP_PriorityLevel_highest; // enum
+          DRB_Information->dRB_QoS.nGRANallocationRetentionPriority.pre_emptionCapability = F1AP_Pre_emptionCapability_shall_not_trigger_pre_emption; // enum
+          DRB_Information->dRB_QoS.nGRANallocationRetentionPriority.pre_emptionVulnerability = F1AP_Pre_emptionVulnerability_not_pre_emptable; // enum
         } // nGRANallocationRetentionPriority
 
         /* OPTIONAL */
         /* gBR_QoS_Flow_Information */
         if (0) {
-          DRB_Information->dRB_QoS.gBR_QoS_Flow_Information = (F1AP_GBR_QoSFlowInformation_t *)calloc(1, sizeof(F1AP_GBR_QoSFlowInformation_t));
-          asn_long2INTEGER(&DRB_Information->dRB_QoS.gBR_QoS_Flow_Information->maxFlowBitRateDownlink, 1L);
-          asn_long2INTEGER(&DRB_Information->dRB_QoS.gBR_QoS_Flow_Information->maxFlowBitRateUplink, 1L);
-          asn_long2INTEGER(&DRB_Information->dRB_QoS.gBR_QoS_Flow_Information->guaranteedFlowBitRateDownlink, 1L);
-          asn_long2INTEGER(&DRB_Information->dRB_QoS.gBR_QoS_Flow_Information->guaranteedFlowBitRateUplink, 1L);
+          asn1cCalloc(DRB_Information->dRB_QoS.gBR_QoS_Flow_Information, tmp);
+          asn_long2INTEGER(&tmp->maxFlowBitRateDownlink, 1L);
+          asn_long2INTEGER(&tmp->maxFlowBitRateUplink, 1L);
+          asn_long2INTEGER(&tmp->guaranteedFlowBitRateDownlink, 1L);
+          asn_long2INTEGER(&tmp->guaranteedFlowBitRateUplink, 1L);
 
           /* OPTIONAL */
           /* maxPacketLossRateDownlink */
           if (0) {
-            DRB_Information->dRB_QoS.gBR_QoS_Flow_Information->maxPacketLossRateDownlink = (F1AP_MaxPacketLossRate_t *)calloc(1, sizeof(F1AP_MaxPacketLossRate_t));
-            *DRB_Information->dRB_QoS.gBR_QoS_Flow_Information->maxPacketLossRateDownlink = 1L;
+            asn1cCallocOne(DRB_Information->dRB_QoS.gBR_QoS_Flow_Information->maxPacketLossRateDownlink, 1L);
           }
 
           /* OPTIONAL */
           /* maxPacketLossRateUplink */
           if (0) {
-            DRB_Information->dRB_QoS.gBR_QoS_Flow_Information->maxPacketLossRateUplink = (F1AP_MaxPacketLossRate_t *)calloc(1, sizeof(F1AP_MaxPacketLossRate_t));
-            *DRB_Information->dRB_QoS.gBR_QoS_Flow_Information->maxPacketLossRateUplink = 1L;
+            asn1cCallocOne(DRB_Information->dRB_QoS.gBR_QoS_Flow_Information->maxPacketLossRateUplink, 1L);
           }
-
         }
 
         /* OPTIONAL */
         /* reflective_QoS_Attribute */
         if (0) {
-          DRB_Information->dRB_QoS.reflective_QoS_Attribute = (long *)calloc(1, sizeof(long));
-          *DRB_Information->dRB_QoS.reflective_QoS_Attribute = 1L;
+          asn1cCallocOne(DRB_Information->dRB_QoS.reflective_QoS_Attribute, 1L);
         }
-
       } // dRB_QoS
-
       /* 12.1.2.2 sNSSAI */
       {
         /* sST */
-        OCTET_STRING_fromBuf(&DRB_Information->sNSSAI.sST, "asdsa1d32sa1d31asd31as",
-                           strlen("asdsa1d32sa1d31asd31as"));
+        OCTET_STRING_fromBuf(&DRB_Information->sNSSAI.sST, "1", 1);
+
         /* OPTIONAL */
         /* sD */
         if (0) {
-          DRB_Information->sNSSAI.sD = (OCTET_STRING_t *)calloc(1, sizeof(OCTET_STRING_t));
-          OCTET_STRING_fromBuf(DRB_Information->sNSSAI.sD, "asdsa1d32sa1d31asd31as",
-                           strlen("asdsa1d32sa1d31asd31as"));
+          asn1cCalloc(DRB_Information->sNSSAI.sD, tmp);
+          OCTET_STRING_fromBuf(tmp, "asdsa1d32sa1d31asd31as",
+                               strlen("asdsa1d32sa1d31asd31as"));
         }
       }
+
       /* OPTIONAL */
       /* 12.1.2.3 notificationControl */
       if (0) {
-        DRB_Information->notificationControl = (F1AP_NotificationControl_t *)calloc(1, sizeof(F1AP_NotificationControl_t));
-        *DRB_Information->notificationControl = F1AP_NotificationControl_active; // enum
+        asn1cCallocOne(DRB_Information->notificationControl,
+                       F1AP_NotificationControl_active); // enum
       }
 
       /* 12.1.2.4 flows_Mapped_To_DRB_List */  // BK: need verifiy
-      int k;
-      for (k = 0; k < 1; k ++) {
-        
-        F1AP_Flows_Mapped_To_DRB_Item_t flows_mapped_to_drb_item;
-        memset((void *)&flows_mapped_to_drb_item, 0, sizeof(F1AP_Flows_Mapped_To_DRB_Item_t));
-        
-        /* qoSFlowIndicator */
-        flows_mapped_to_drb_item.qoSFlowIdentifier = 1L;
 
+      for (int k = 0; k < 1; k ++) {
+        asn1cSequenceAdd(DRB_Information->flows_Mapped_To_DRB_List.list,
+                         F1AP_Flows_Mapped_To_DRB_Item_t, flows_mapped_to_drb_item);
+        /* qoSFlowIndicator */
+        flows_mapped_to_drb_item->qoSFlowIdentifier = 1L;
         /* qoSFlowLevelQoSParameters */
-        {  
+        {
           /* qoS_Characteristics */
           {
-            int some_decide_qoS_characteristics = 1; // BK: Need Check
-            if (some_decide_qoS_characteristics) {
-              flows_mapped_to_drb_item.qoSFlowLevelQoSParameters.qoS_Characteristics.present = F1AP_QoS_Characteristics_PR_non_Dynamic_5QI;
-              flows_mapped_to_drb_item.qoSFlowLevelQoSParameters.qoS_Characteristics.choice.non_Dynamic_5QI = (F1AP_NonDynamic5QIDescriptor_t *)calloc(1, sizeof(F1AP_NonDynamic5QIDescriptor_t));
-              
-              /* fiveQI */
-              flows_mapped_to_drb_item.qoSFlowLevelQoSParameters.qoS_Characteristics.choice.non_Dynamic_5QI->fiveQI = 1L;
-
-              /* OPTIONAL */
-              /* qoSPriorityLevel */
-              if (0) {
-                flows_mapped_to_drb_item.qoSFlowLevelQoSParameters.qoS_Characteristics.choice.non_Dynamic_5QI->qoSPriorityLevel = (long *)calloc(1, sizeof(long));
-                *flows_mapped_to_drb_item.qoSFlowLevelQoSParameters.qoS_Characteristics.choice.non_Dynamic_5QI->qoSPriorityLevel = 1L;
-              }
-
-              /* OPTIONAL */
-              /* averagingWindow */
-              if (0) {
-                flows_mapped_to_drb_item.qoSFlowLevelQoSParameters.qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow = (F1AP_AveragingWindow_t *)calloc(1, sizeof(F1AP_AveragingWindow_t));
-                *flows_mapped_to_drb_item.qoSFlowLevelQoSParameters.qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow = 1L;
-              }
-
-              /* OPTIONAL */
-              /* maxDataBurstVolume */
-              if (0) {
-                flows_mapped_to_drb_item.qoSFlowLevelQoSParameters.qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume = (F1AP_MaxDataBurstVolume_t *)calloc(1, sizeof(F1AP_MaxDataBurstVolume_t));
-                *flows_mapped_to_drb_item.qoSFlowLevelQoSParameters.qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume = 1L;
-              }
+            int some_decide_qoS_characteristics = 0; // BK: Need Check
+            F1AP_QoS_Characteristics_t *QosParams=&flows_mapped_to_drb_item->qoSFlowLevelQoSParameters.qoS_Characteristics;
 
+            if (some_decide_qoS_characteristics) {
+              QosParams->present = F1AP_QoS_Characteristics_PR_non_Dynamic_5QI;
+              setQos(QosParams->choice.non_Dynamic_5QI);
             } else {
-              flows_mapped_to_drb_item.qoSFlowLevelQoSParameters.qoS_Characteristics.present = F1AP_QoS_Characteristics_PR_dynamic_5QI;
-              flows_mapped_to_drb_item.qoSFlowLevelQoSParameters.qoS_Characteristics.choice.dynamic_5QI = (F1AP_Dynamic5QIDescriptor_t *)calloc(1, sizeof(F1AP_Dynamic5QIDescriptor_t));
-              
+              QosParams->present = F1AP_QoS_Characteristics_PR_dynamic_5QI;
+              asn1cCalloc(QosParams->choice.dynamic_5QI, tmp);
               /* qoSPriorityLevel */
-              flows_mapped_to_drb_item.qoSFlowLevelQoSParameters.qoS_Characteristics.choice.dynamic_5QI->qoSPriorityLevel = 1L;
-
+              tmp->qoSPriorityLevel = 1L;
               /* packetDelayBudget */
-              flows_mapped_to_drb_item.qoSFlowLevelQoSParameters.qoS_Characteristics.choice.dynamic_5QI->packetDelayBudget = 1L;
-
+              tmp->packetDelayBudget = 1L;
               /* packetErrorRate */
-              flows_mapped_to_drb_item.qoSFlowLevelQoSParameters.qoS_Characteristics.choice.dynamic_5QI->packetErrorRate.pER_Scalar = 1L;
-	            flows_mapped_to_drb_item.qoSFlowLevelQoSParameters.qoS_Characteristics.choice.dynamic_5QI->packetErrorRate.pER_Exponent = 6L;
+              tmp->packetErrorRate.pER_Scalar = 1L;
+              tmp->packetErrorRate.pER_Exponent = 6L;
 
-	            /* OPTIONAL */
+              /* OPTIONAL */
               /* delayCritical */
               if (0) {
-                flows_mapped_to_drb_item.qoSFlowLevelQoSParameters.qoS_Characteristics.choice.dynamic_5QI->delayCritical = (long *)calloc(1, sizeof(long));
-                *flows_mapped_to_drb_item.qoSFlowLevelQoSParameters.qoS_Characteristics.choice.dynamic_5QI->delayCritical = 1L;
+                asn1cCalloc(QosParams->choice.dynamic_5QI->delayCritical, tmp);
+                *tmp = 1L;
               }
 
               /* OPTIONAL */
               /* averagingWindow */
               if (0) {
-                flows_mapped_to_drb_item.qoSFlowLevelQoSParameters.qoS_Characteristics.choice.dynamic_5QI->averagingWindow = (F1AP_AveragingWindow_t *)calloc(1, sizeof(F1AP_AveragingWindow_t));
-                *flows_mapped_to_drb_item.qoSFlowLevelQoSParameters.qoS_Characteristics.choice.dynamic_5QI->averagingWindow = 1L;
+                asn1cCalloc(QosParams->choice.dynamic_5QI->averagingWindow, tmp);
+                *tmp = 1L;
               }
 
               /* OPTIONAL */
               /* maxDataBurstVolume */
               if (0) {
-                flows_mapped_to_drb_item.qoSFlowLevelQoSParameters.qoS_Characteristics.choice.dynamic_5QI->maxDataBurstVolume = (F1AP_MaxDataBurstVolume_t *)calloc(1, sizeof(F1AP_MaxDataBurstVolume_t));
-                *flows_mapped_to_drb_item.qoSFlowLevelQoSParameters.qoS_Characteristics.choice.dynamic_5QI->maxDataBurstVolume = 1L;
+                asn1cCalloc(QosParams->choice.dynamic_5QI->maxDataBurstVolume, tmp);
+                *tmp= 1L;
               }
-
             } // if some_decide_qoS_characteristics
-
           } // qoS_Characteristics
-
           /* nGRANallocationRetentionPriority */
           {
-              flows_mapped_to_drb_item.qoSFlowLevelQoSParameters.nGRANallocationRetentionPriority.priorityLevel = F1AP_PriorityLevel_highest; // enum
-              flows_mapped_to_drb_item.qoSFlowLevelQoSParameters.nGRANallocationRetentionPriority.pre_emptionCapability = F1AP_Pre_emptionCapability_shall_not_trigger_pre_emption; // enum
-              flows_mapped_to_drb_item.qoSFlowLevelQoSParameters.nGRANallocationRetentionPriority.pre_emptionVulnerability = F1AP_Pre_emptionVulnerability_not_pre_emptable; // enum
+            flows_mapped_to_drb_item->qoSFlowLevelQoSParameters.nGRANallocationRetentionPriority.priorityLevel = F1AP_PriorityLevel_highest; // enum
+            flows_mapped_to_drb_item->qoSFlowLevelQoSParameters.nGRANallocationRetentionPriority.pre_emptionCapability = F1AP_Pre_emptionCapability_shall_not_trigger_pre_emption; // enum
+            flows_mapped_to_drb_item->qoSFlowLevelQoSParameters.nGRANallocationRetentionPriority.pre_emptionVulnerability = F1AP_Pre_emptionVulnerability_not_pre_emptable; // enum
           } // nGRANallocationRetentionPriority
 
           /* OPTIONAL */
           /* gBR_QoS_Flow_Information */
           if (0) {
-            flows_mapped_to_drb_item.qoSFlowLevelQoSParameters.gBR_QoS_Flow_Information = (F1AP_GBR_QoSFlowInformation_t *)calloc(1, sizeof(F1AP_GBR_QoSFlowInformation_t)); 
-            asn_long2INTEGER(&flows_mapped_to_drb_item.qoSFlowLevelQoSParameters.gBR_QoS_Flow_Information->maxFlowBitRateDownlink, 1L);
-            asn_long2INTEGER(&flows_mapped_to_drb_item.qoSFlowLevelQoSParameters.gBR_QoS_Flow_Information->maxFlowBitRateUplink, 1L);
-            asn_long2INTEGER(&flows_mapped_to_drb_item.qoSFlowLevelQoSParameters.gBR_QoS_Flow_Information->guaranteedFlowBitRateDownlink, 1L);
-            asn_long2INTEGER(&flows_mapped_to_drb_item.qoSFlowLevelQoSParameters.gBR_QoS_Flow_Information->guaranteedFlowBitRateUplink, 1L);
+            asn1cCalloc(flows_mapped_to_drb_item->qoSFlowLevelQoSParameters.gBR_QoS_Flow_Information, tmp);
+            asn_long2INTEGER(&tmp->maxFlowBitRateDownlink, 1L);
+            asn_long2INTEGER(&tmp->maxFlowBitRateUplink, 1L);
+            asn_long2INTEGER(&tmp->guaranteedFlowBitRateDownlink, 1L);
+            asn_long2INTEGER(&tmp->guaranteedFlowBitRateUplink, 1L);
 
             /* OPTIONAL */
             /* maxPacketLossRateDownlink */
             if (0) {
-              flows_mapped_to_drb_item.qoSFlowLevelQoSParameters.gBR_QoS_Flow_Information->maxPacketLossRateDownlink = (F1AP_MaxPacketLossRate_t *)calloc(1, sizeof(F1AP_MaxPacketLossRate_t)); 
-              *flows_mapped_to_drb_item.qoSFlowLevelQoSParameters.gBR_QoS_Flow_Information->maxPacketLossRateDownlink = 1L;
+              asn1cCallocOne(flows_mapped_to_drb_item->qoSFlowLevelQoSParameters.gBR_QoS_Flow_Information->maxPacketLossRateDownlink, 1L);
             }
 
             /* OPTIONAL */
             /* maxPacketLossRateUplink */
             if (0) {
-              flows_mapped_to_drb_item.qoSFlowLevelQoSParameters.gBR_QoS_Flow_Information->maxPacketLossRateUplink = (F1AP_MaxPacketLossRate_t *)calloc(1, sizeof(F1AP_MaxPacketLossRate_t)); 
-              *flows_mapped_to_drb_item.qoSFlowLevelQoSParameters.gBR_QoS_Flow_Information->maxPacketLossRateUplink = 1L;
+              asn1cCallocOne(flows_mapped_to_drb_item->qoSFlowLevelQoSParameters.gBR_QoS_Flow_Information->maxPacketLossRateUplink, 1L);
             }
-
           }
 
           /* OPTIONAL */
           /* reflective_QoS_Attribute */
           if (0) {
-            flows_mapped_to_drb_item.qoSFlowLevelQoSParameters.reflective_QoS_Attribute = (long *)calloc(1, sizeof(long)); 
-            *flows_mapped_to_drb_item.qoSFlowLevelQoSParameters.reflective_QoS_Attribute = 1L;
+            asn1cCallocOne(flows_mapped_to_drb_item->qoSFlowLevelQoSParameters.reflective_QoS_Attribute, 1L);
           }
-
         } // qoSFlowLevelQoSParameters
-        // BK: need check
-        ASN_SEQUENCE_ADD(&DRB_Information->flows_Mapped_To_DRB_List.list, &flows_mapped_to_drb_item);
       }
-
     } // if some_decide_qos
 
     /* 12.1.3 uLUPTNLInformation_ToBeSetup_List */
-    for (j = 0; j < f1ap_ue_context_setup_req->drbs_to_be_setup[i].up_ul_tnl_length; j++) {
-      f1ap_up_tnl_t *up_tnl = &f1ap_ue_context_setup_req->drbs_to_be_setup[i].up_ul_tnl[j];
-
+    for (int j = 0; j < f1ap_ue_context_setup_req->drbs_to_be_setup[i].up_ul_tnl_length; j++) {
+      /* Here the callback function used as input is not the right one. Need to create a new one probably for F1-U, not sure
+       * if the kind of input parameters to the callback function are convenient though for gtp-u over F1-U.*/
+      //Use a dummy teid for the outgoing GTP-U tunnel (DU) which will be updated once we get the UE context setup response from the DU
+      transport_layer_addr_t addr;
+      int sz=sizeof(f1ap_ue_context_setup_req->drbs_to_be_setup[i].up_dl_tnl[0].tl_address);
+      memcpy(addr.buffer,&f1ap_ue_context_setup_req->drbs_to_be_setup[i].up_dl_tnl[0].tl_address, sz);
+      addr.length = sz*8;
+      f1ap_ue_context_setup_req->drbs_to_be_setup[i].up_ul_tnl[j].teid=
+        newGtpuCreateTunnel(getCxt(CUtype, instance)->gtpInst,
+                            f1ap_ue_context_setup_req->rnti,
+                            f1ap_ue_context_setup_req->drbs_to_be_setup[i].drb_id,
+                            f1ap_ue_context_setup_req->drbs_to_be_setup[i].drb_id,
+                            0xFFFF, // We will set the right value from DU answer
+                            addr,
+                            f1ap_ue_context_setup_req->drbs_to_be_setup[i].up_dl_tnl[0].port,
+                            cu_f1u_data_req);
       /*  12.3.1 ULTunnels_ToBeSetup_Item */
-      F1AP_ULUPTNLInformation_ToBeSetup_Item_t *uLUPTNLInformation_ToBeSetup_Item;
-
-      /* 12.3.1.1 gTPTunnel */
-      uLUPTNLInformation_ToBeSetup_Item = calloc(1, sizeof(F1AP_ULUPTNLInformation_ToBeSetup_Item_t));
+      asn1cSequenceAdd(drbs_toBeSetup_item->uLUPTNLInformation_ToBeSetup_List.list,
+                       F1AP_ULUPTNLInformation_ToBeSetup_Item_t, uLUPTNLInformation_ToBeSetup_Item);
       uLUPTNLInformation_ToBeSetup_Item->uLUPTNLInformation.present = F1AP_UPTransportLayerInformation_PR_gTPTunnel;
-      F1AP_GTPTunnel_t *gTPTunnel = (F1AP_GTPTunnel_t *)calloc(1, sizeof(F1AP_GTPTunnel_t));
-
+      asn1cCalloc( uLUPTNLInformation_ToBeSetup_Item->uLUPTNLInformation.choice.gTPTunnel,
+                   gTPTunnel);
       /* 12.3.1.1.1 transportLayerAddress */
-      TRANSPORT_LAYER_ADDRESS_IPv4_TO_BIT_STRING(up_tnl->tl_address, &gTPTunnel->transportLayerAddress);
-
+      TRANSPORT_LAYER_ADDRESS_IPv4_TO_BIT_STRING(f1ap_ue_context_setup_req->drbs_to_be_setup[i].up_ul_tnl[j].tl_address,
+          &gTPTunnel->transportLayerAddress);
       /* 12.3.1.1.2 gTP_TEID */
-      INT32_TO_OCTET_STRING(up_tnl->gtp_teid, &gTPTunnel->gTP_TEID);
-
-      // Add
-      uLUPTNLInformation_ToBeSetup_Item->uLUPTNLInformation.choice.gTPTunnel = gTPTunnel;
-      ASN_SEQUENCE_ADD(&drbs_toBeSetup_item.uLUPTNLInformation_ToBeSetup_List.list, uLUPTNLInformation_ToBeSetup_Item);
+      INT32_TO_OCTET_STRING(f1ap_ue_context_setup_req->drbs_to_be_setup[i].up_ul_tnl[j].teid,
+                            &gTPTunnel->gTP_TEID);
     }
 
     /* 12.1.4 rLCMode */
     /* TODO use rlc_mode from f1ap_drb_to_be_setup */
     switch (f1ap_ue_context_setup_req->drbs_to_be_setup[i].rlc_mode) {
       case RLC_MODE_AM:
-        drbs_toBeSetup_item.rLCMode = F1AP_RLCMode_rlc_am;
+        drbs_toBeSetup_item->rLCMode = F1AP_RLCMode_rlc_am;
         break;
+
       default:
-        drbs_toBeSetup_item.rLCMode = F1AP_RLCMode_rlc_um_bidirectional;
+        drbs_toBeSetup_item->rLCMode = F1AP_RLCMode_rlc_um_bidirectional;
     }
 
     /* OPTIONAL */
     /* 12.1.5 ULConfiguration */
     if (0) {
-       drbs_toBeSetup_item.uLConfiguration = (F1AP_ULConfiguration_t *)calloc(1, sizeof(F1AP_ULConfiguration_t));
-       drbs_toBeSetup_item.uLConfiguration->uLUEConfiguration = F1AP_ULUEConfiguration_no_data;
+      asn1cCalloc(drbs_toBeSetup_item->uLConfiguration, tmp);
+      tmp->uLUEConfiguration = F1AP_ULUEConfiguration_no_data;
     }
 
     /* OPTIONAL */
     /* 12.1.6 duplicationActivation */
     if (0) {
-       drbs_toBeSetup_item.duplicationActivation = (F1AP_DuplicationActivation_t *)calloc(1, sizeof(F1AP_DuplicationActivation_t));
-       drbs_toBeSetup_item.duplicationActivation = F1AP_DuplicationActivation_active;  // enum
+      asn1cCalloc(drbs_toBeSetup_item->duplicationActivation, tmp);
+      *tmp = F1AP_DuplicationActivation_active;  // enum
     }
-
-    /* ADD */
-    drbs_toBeSetup_item_ies->value.choice.DRBs_ToBeSetup_Item = drbs_toBeSetup_item;
-    ASN_SEQUENCE_ADD(&ie->value.choice.DRBs_ToBeSetup_List.list,
-                   drbs_toBeSetup_item_ies);
-
   }
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
 
   /* OPTIONAL */
   /* InactivityMonitoringRequest */
   if (0) {
-    ie = (F1AP_UEContextSetupRequestIEs_t *)calloc(1, sizeof(F1AP_UEContextSetupRequestIEs_t));
-    ie->id                             = F1AP_ProtocolIE_ID_id_InactivityMonitoringRequest;
-    ie->criticality                    = F1AP_Criticality_reject;
-    ie->value.present                  = F1AP_UEContextSetupRequestIEs__value_PR_InactivityMonitoringRequest;
-    ie->value.choice.InactivityMonitoringRequest = F1AP_InactivityMonitoringRequest_true; // 0
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextSetupRequestIEs_t, ie12);
+    ie12->id                             = F1AP_ProtocolIE_ID_id_InactivityMonitoringRequest;
+    ie12->criticality                    = F1AP_Criticality_reject;
+    ie12->value.present                  = F1AP_UEContextSetupRequestIEs__value_PR_InactivityMonitoringRequest;
+    ie12->value.choice.InactivityMonitoringRequest = F1AP_InactivityMonitoringRequest_true; // 0
   }
 
   /* OPTIONAL */
   /* RAT_FrequencyPriorityInformation */
   if (0) {
-    ie = (F1AP_UEContextSetupRequestIEs_t *)calloc(1, sizeof(F1AP_UEContextSetupRequestIEs_t));
-    ie->id                             = F1AP_ProtocolIE_ID_id_RAT_FrequencyPriorityInformation;
-    ie->criticality                    = F1AP_Criticality_reject;
-    ie->value.present                  = F1AP_UEContextSetupRequestIEs__value_PR_RAT_FrequencyPriorityInformation;
-
+    asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextSetupRequestIEs_t, ie13);
+    ie13->id                             = F1AP_ProtocolIE_ID_id_RAT_FrequencyPriorityInformation;
+    ie13->criticality                    = F1AP_Criticality_reject;
+    ie13->value.present                  = F1AP_UEContextSetupRequestIEs__value_PR_RAT_FrequencyPriorityInformation;
     int endc = 1; // RK: Get this from somewhere ...
+
     if (endc) {
-      ie->value.choice.RAT_FrequencyPriorityInformation.present = F1AP_RAT_FrequencyPriorityInformation_PR_eNDC;
-      ie->value.choice.RAT_FrequencyPriorityInformation.choice.eNDC = 11L;
+      ie13->value.choice.RAT_FrequencyPriorityInformation.present = F1AP_RAT_FrequencyPriorityInformation_PR_eNDC;
+      ie13->value.choice.RAT_FrequencyPriorityInformation.choice.eNDC = 11L;
     } else {
-      ie->value.choice.RAT_FrequencyPriorityInformation.present = F1AP_RAT_FrequencyPriorityInformation_PR_nGRAN;
-      ie->value.choice.RAT_FrequencyPriorityInformation.choice.nGRAN = 11L;
+      ie13->value.choice.RAT_FrequencyPriorityInformation.present = F1AP_RAT_FrequencyPriorityInformation_PR_nGRAN;
+      ie13->value.choice.RAT_FrequencyPriorityInformation.choice.nGRAN = 11L;
     }
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
   }
 
   /* OPTIONAL */
   /* RRCContainer */
-  if(RC.nrrrc) {
-    ie = (F1AP_UEContextSetupRequestIEs_t *)calloc(1, sizeof(F1AP_UEContextSetupRequestIEs_t));
-    ie->id                             = F1AP_ProtocolIE_ID_id_RRCContainer;
-    ie->criticality                    = F1AP_Criticality_reject;
-    ie->value.present                  = F1AP_UEContextSetupRequestIEs__value_PR_RRCContainer;
-    OCTET_STRING_fromBuf(&ie->value.choice.RRCContainer, (const char*)f1ap_ue_context_setup_req->rrc_container,
-                          f1ap_ue_context_setup_req->rrc_container_length);
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+  if(f1ap_ue_context_setup_req->rrc_container_length > 0) {
+    asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextSetupRequestIEs_t, ie14);
+    ie14->id                             = F1AP_ProtocolIE_ID_id_RRCContainer;
+    ie14->criticality                    = F1AP_Criticality_reject;
+    ie14->value.present                  = F1AP_UEContextSetupRequestIEs__value_PR_RRCContainer;
+    OCTET_STRING_fromBuf(&ie14->value.choice.RRCContainer, (const char *)f1ap_ue_context_setup_req->rrc_container,
+                         f1ap_ue_context_setup_req->rrc_container_length);
   }
 
   /* OPTIONAL */
   /* MaskedIMEISV */
   if (0) {
-    ie = (F1AP_UEContextSetupRequestIEs_t *)calloc(1, sizeof(F1AP_UEContextSetupRequestIEs_t));
-    ie->id                             = F1AP_ProtocolIE_ID_id_MaskedIMEISV;
-    ie->criticality                    = F1AP_Criticality_reject;
-    ie->value.present                  = F1AP_UEContextSetupRequestIEs__value_PR_MaskedIMEISV;
-    MaskedIMEISV_TO_BIT_STRING(12340000l, &ie->value.choice.MaskedIMEISV); // size (64)
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextSetupRequestIEs_t, ie15);
+    ie15->id                             = F1AP_ProtocolIE_ID_id_MaskedIMEISV;
+    ie15->criticality                    = F1AP_Criticality_reject;
+    ie15->value.present                  = F1AP_UEContextSetupRequestIEs__value_PR_MaskedIMEISV;
+    MaskedIMEISV_TO_BIT_STRING(12340000l, &ie15->value.choice.MaskedIMEISV); // size (64)
   }
 
   /* encode */
+  uint8_t  *buffer=NULL;
+  uint32_t  len=0;
+
   if (f1ap_encode_pdu(&pdu, &buffer, &len) < 0) {
     LOG_E(F1AP, "Failed to encode F1 UE CONTEXT SETUP REQUEST\n");
     return -1;
   }
 
   // xer_fprint(stdout, &asn_DEF_F1AP_F1AP_PDU, (void *)pdu);
-
   // asn_encode_to_new_buffer_result_t res = { NULL, {0, NULL, NULL} };
   // res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_F1AP_F1AP_PDU, pdu);
   // buffer = res.buffer;
   // len = res.result.encoded;
-
   // if (res.result.encoded <= 0) {
   //   LOG_E(F1AP, "ASN1 message encoding failed (%s, %lu)!\n", res.result.failed_type->name, res.result.encoded);
   //   return -1;
   // }
-
   LOG_D(F1AP,"F1AP UEContextSetupRequest Encoded %u bits\n", len);
-
-  if(RC.nrrrc) {
-    cu_f1ap_itti_send_sctp_data_req(instance, f1ap_assoc_id /* BK: fix me*/ , buffer, len, 0 /* BK: fix me*/);
-  }
-
+  f1ap_itti_send_sctp_data_req(true, instance, buffer, len, 0 /* BK: fix me*/);
   return 0;
 }
 
@@ -796,41 +633,133 @@ int CU_handle_UE_CONTEXT_SETUP_RESPONSE(instance_t       instance,
                                         uint32_t         assoc_id,
                                         uint32_t         stream,
                                         F1AP_F1AP_PDU_t *pdu) {
+  MessageDef                       *msg_p;
   F1AP_UEContextSetupResponse_t    *container;
   F1AP_UEContextSetupResponseIEs_t *ie;
-
   DevAssert(pdu);
-
+  msg_p = itti_alloc_new_message(TASK_DU_F1, 0,  F1AP_UE_CONTEXT_SETUP_RESP);
+  f1ap_ue_context_setup_t *f1ap_ue_context_setup_resp = &F1AP_UE_CONTEXT_SETUP_RESP(msg_p);
   container = &pdu->choice.successfulOutcome->value.choice.UEContextSetupResponse;
-
+  int i;
   /* GNB_CU_UE_F1AP_ID */
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_UEContextSetupResponseIEs_t, ie, container,
                              F1AP_ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID, true);
-
+  f1ap_ue_context_setup_resp->gNB_CU_ue_id = ie->value.choice.GNB_CU_UE_F1AP_ID;
+  LOG_D(F1AP, "f1ap_ue_context_setup_resp->gNB_CU_ue_id is: %d \n", f1ap_ue_context_setup_resp->gNB_CU_ue_id);
   /* GNB_DU_UE_F1AP_ID */
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_UEContextSetupResponseIEs_t, ie, container,
                              F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID, true);
-
-  /* DUtoCURRCInformation */
+  f1ap_ue_context_setup_resp->gNB_DU_ue_id = ie->value.choice.GNB_DU_UE_F1AP_ID;
+  LOG_D(F1AP, "f1ap_ue_context_setup_resp->gNB_DU_ue_id is: %d \n", f1ap_ue_context_setup_resp->gNB_DU_ue_id);
+  f1ap_ue_context_setup_resp->rnti =
+    f1ap_get_rnti_by_du_id(CUtype, instance, f1ap_ue_context_setup_resp->gNB_DU_ue_id);
+  // DUtoCURRCInformation
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_UEContextSetupResponseIEs_t, ie, container,
                              F1AP_ProtocolIE_ID_id_DUtoCURRCInformation, true);
 
-  /* DRBs_Setup_List */
+  if (ie == NULL) {
+    LOG_E(F1AP,"%s %d: ie is a NULL pointer \n",__FILE__,__LINE__);
+    return -1;
+  }
+
+  f1ap_ue_context_setup_resp->du_to_cu_rrc_information = (uint8_t *)calloc(1,ie->value.choice.DUtoCURRCInformation.cellGroupConfig.size);
+  memcpy(f1ap_ue_context_setup_resp->du_to_cu_rrc_information, ie->value.choice.DUtoCURRCInformation.cellGroupConfig.buf, ie->value.choice.DUtoCURRCInformation.cellGroupConfig.size);
+  f1ap_ue_context_setup_resp->du_to_cu_rrc_information_length = ie->value.choice.DUtoCURRCInformation.cellGroupConfig.size;
+  // DRBs_Setup_List
+  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_UEContextSetupResponseIEs_t, ie, container,
+                             F1AP_ProtocolIE_ID_id_DRBs_Setup_List, false);
+
+  if(ie!=NULL) {
+    f1ap_ue_context_setup_resp->drbs_to_be_setup_length = ie->value.choice.DRBs_Setup_List.list.count;
+    f1ap_ue_context_setup_resp->drbs_to_be_setup = calloc(f1ap_ue_context_setup_resp->drbs_to_be_setup_length,
+        sizeof(f1ap_drb_to_be_setup_t));
+    AssertFatal(f1ap_ue_context_setup_resp->drbs_to_be_setup,
+                "could not allocate memory for f1ap_ue_context_setup_resp->drbs_setup\n");
+
+    for (i = 0; i < f1ap_ue_context_setup_resp->drbs_to_be_setup_length; ++i) {
+      f1ap_drb_to_be_setup_t *drb_p = &f1ap_ue_context_setup_resp->drbs_to_be_setup[i];
+      F1AP_DRBs_Setup_Item_t *drbs_setup_item_p;
+      drbs_setup_item_p = &((F1AP_DRBs_Setup_ItemIEs_t *)ie->value.choice.DRBs_Setup_List.list.array[i])->value.choice.DRBs_Setup_Item;
+      drb_p->drb_id = drbs_setup_item_p->dRBID;
+      // TODO in the following, assume only one UP UL TNL is present.
+      // this matches/assumes OAI CU/DU implementation, can be up to 2!
+      drb_p->up_dl_tnl_length = 1;
+      AssertFatal(drbs_setup_item_p->dLUPTNLInformation_ToBeSetup_List.list.count > 0,
+                  "no DL UP TNL Information in DRBs to be Setup list\n");
+      F1AP_DLUPTNLInformation_ToBeSetup_Item_t *dl_up_tnl_info_p = (F1AP_DLUPTNLInformation_ToBeSetup_Item_t *)drbs_setup_item_p->dLUPTNLInformation_ToBeSetup_List.list.array[0];
+      F1AP_GTPTunnel_t *dl_up_tnl0 = dl_up_tnl_info_p->dLUPTNLInformation.choice.gTPTunnel;
+      BIT_STRING_TO_TRANSPORT_LAYER_ADDRESS_IPv4(&dl_up_tnl0->transportLayerAddress, drb_p->up_dl_tnl[0].tl_address);
+      OCTET_STRING_TO_INT32(&dl_up_tnl0->gTP_TEID, drb_p->up_dl_tnl[0].teid);
+      GtpuUpdateTunnelOutgoingTeid(getCxt(CUtype, instance)->gtpInst,
+                                   f1ap_ue_context_setup_resp->rnti,
+                                   (ebi_t)drbs_setup_item_p->dRBID,
+                                   drb_p->up_dl_tnl[0].teid);
+    }
+  }
+
+  // SRBs_FailedToBeSetup_List
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_UEContextSetupResponseIEs_t, ie, container,
-                             F1AP_ProtocolIE_ID_id_DRBs_Setup_List, true);
+                             F1AP_ProtocolIE_ID_id_SRBs_FailedToBeSetup_List, false);
+
+  if(ie!=NULL) {
+    f1ap_ue_context_setup_resp->srbs_failed_to_be_setup_length = ie->value.choice.SRBs_FailedToBeSetup_List.list.count;
+    f1ap_ue_context_setup_resp->srbs_failed_to_be_setup = calloc(f1ap_ue_context_setup_resp->srbs_failed_to_be_setup_length,
+        sizeof(f1ap_rb_failed_to_be_setup_t));
+    AssertFatal(f1ap_ue_context_setup_resp->srbs_failed_to_be_setup,
+                "could not allocate memory for f1ap_ue_context_setup_resp->srbs_failed_to_be_setup\n");
+
+    for (i = 0; i < f1ap_ue_context_setup_resp->srbs_failed_to_be_setup_length; ++i) {
+      f1ap_rb_failed_to_be_setup_t *srb_p = &f1ap_ue_context_setup_resp->srbs_failed_to_be_setup[i];
+      srb_p->rb_id = ((F1AP_SRBs_FailedToBeSetup_Item_t *)ie->value.choice.SRBs_FailedToBeSetup_List.list.array[i])->sRBID;
+    }
+  }
 
-  /* SRBs_FailedToBeSetup_List */
+  // DRBs_FailedToBeSetup_List
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_UEContextSetupResponseIEs_t, ie, container,
-                             F1AP_ProtocolIE_ID_id_SRBs_FailedToBeSetup_List, true);
+                             F1AP_ProtocolIE_ID_id_DRBs_FailedToBeSetup_List, false);
+
+  if(ie!=NULL) {
+    f1ap_ue_context_setup_resp->drbs_failed_to_be_setup_length = ie->value.choice.DRBs_FailedToBeSetup_List.list.count;
+    f1ap_ue_context_setup_resp->drbs_failed_to_be_setup = calloc(f1ap_ue_context_setup_resp->drbs_failed_to_be_setup_length,
+        sizeof(f1ap_rb_failed_to_be_setup_t));
+    AssertFatal(f1ap_ue_context_setup_resp->drbs_failed_to_be_setup,
+                "could not allocate memory for f1ap_ue_context_setup_resp->drbs_failed_to_be_setup\n");
+
+    for (i = 0; i < f1ap_ue_context_setup_resp->drbs_failed_to_be_setup_length; ++i) {
+      f1ap_rb_failed_to_be_setup_t *drb_p = &f1ap_ue_context_setup_resp->drbs_failed_to_be_setup[i];
+      drb_p->rb_id = ((F1AP_DRBs_FailedToBeSetup_Item_t *)ie->value.choice.DRBs_FailedToBeSetup_List.list.array[i])->dRBID;
+    }
+  }
 
-  /* DRBs_FailedToBeSetup_List */
+  // SCell_FailedtoSetup_List
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_UEContextSetupResponseIEs_t, ie, container,
-                             F1AP_ProtocolIE_ID_id_DRBs_FailedToBeSetup_List, true);
+                             F1AP_ProtocolIE_ID_id_SCell_FailedtoSetup_List, false);
 
-  /* SCell_FailedtoSetup_List */
+  if(ie!=NULL) {
+    LOG_E (F1AP, "Not supporting handling of SCell_FailedtoSetup_List \n");
+  }
+
+  // SRBs_Setup_List
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_UEContextSetupResponseIEs_t, ie, container,
-                             F1AP_ProtocolIE_ID_id_SCell_FailedtoSetup_List, true);
+                             F1AP_ProtocolIE_ID_id_SRBs_Setup_List, false);
+
+  if(ie!=NULL) {
+    f1ap_ue_context_setup_resp->srbs_to_be_setup_length = ie->value.choice.SRBs_Setup_List.list.count;
+    f1ap_ue_context_setup_resp->srbs_to_be_setup = calloc(f1ap_ue_context_setup_resp->srbs_to_be_setup_length,
+        sizeof(f1ap_srb_to_be_setup_t));
+    AssertFatal(f1ap_ue_context_setup_resp->srbs_to_be_setup,
+                "could not allocate memory for f1ap_ue_context_setup_resp->drbs_setup\n");
+
+    for (i = 0; i < f1ap_ue_context_setup_resp->srbs_to_be_setup_length; ++i) {
+      f1ap_srb_to_be_setup_t *srb_p = &f1ap_ue_context_setup_resp->srbs_to_be_setup[i];
+      F1AP_SRBs_Setup_Item_t *srbs_setup_item_p;
+      srbs_setup_item_p = &((F1AP_SRBs_Setup_ItemIEs_t *)ie->value.choice.SRBs_Setup_List.list.array[i])->value.choice.SRBs_Setup_Item;
+      srb_p->srb_id = srbs_setup_item_p->sRBID;
+      srb_p->lcid = srbs_setup_item_p->lCID;
+    }
+  }
 
+  itti_send_msg_to_task(TASK_RRC_GNB, instance, msg_p);
   return 0;
 }
 
@@ -841,31 +770,26 @@ int CU_handle_UE_CONTEXT_SETUP_FAILURE(instance_t       instance,
   AssertFatal(1==0,"Not implemented yet\n");
 }
 
-
 int CU_handle_UE_CONTEXT_RELEASE_REQUEST(instance_t       instance,
-                                         uint32_t         assoc_id,
-                                         uint32_t         stream,
-                                         F1AP_F1AP_PDU_t *pdu) {
+    uint32_t         assoc_id,
+    uint32_t         stream,
+    F1AP_F1AP_PDU_t *pdu) {
   F1AP_UEContextReleaseRequest_t    *container;
   F1AP_UEContextReleaseRequestIEs_t *ie;
-
   DevAssert(pdu);
-
   container = &pdu->choice.initiatingMessage->value.choice.UEContextReleaseRequest;
   /* GNB_CU_UE_F1AP_ID */
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_UEContextReleaseRequestIEs_t, ie, container,
                              F1AP_ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID, true);
-  const rnti_t rnti = f1ap_get_rnti_by_cu_id(&f1ap_cu_inst[instance],
-                                             ie->value.choice.GNB_CU_UE_F1AP_ID);
-
+  const rnti_t rnti = f1ap_get_rnti_by_cu_id(true, instance,
+                      ie->value.choice.GNB_CU_UE_F1AP_ID);
   /* GNB_DU_UE_F1AP_ID */
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_UEContextReleaseRequestIEs_t, ie, container,
                              F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID, true);
-  const rnti_t rnti2 = f1ap_get_rnti_by_du_id(&f1ap_cu_inst[instance],
-                                              ie->value.choice.GNB_DU_UE_F1AP_ID);
+  const rnti_t rnti2 = f1ap_get_rnti_by_du_id(CUtype, instance,
+                       ie->value.choice.GNB_DU_UE_F1AP_ID);
   AssertFatal(rnti == rnti2, "RNTI obtained through DU ID (%x) is different from CU ID (%x)\n",
               rnti2, rnti);
-
   /* Cause */
   /* We don't care for the moment
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_UEContextReleaseRequestIEs_t, ie, container,
@@ -890,15 +814,19 @@ int CU_handle_UE_CONTEXT_RELEASE_REQUEST(instance_t       instance,
       break;
   }
   */
-
   LOG_I(F1AP, "Received UE CONTEXT RELEASE REQUEST: Trigger RRC for RNTI %x\n", rnti);
-  struct rrc_eNB_ue_context_s *ue_context_pP;
-  ue_context_pP = rrc_eNB_get_ue_context(RC.rrc[instance], rnti);
-  rrc_eNB_send_S1AP_UE_CONTEXT_RELEASE_REQ(
+
+  if (f1ap_req(true, instance)->cell_type==CELL_MACRO_GNB) {
+    AssertFatal(false,"must be devlopped\n");
+  } else {
+    struct rrc_eNB_ue_context_s *ue_context_pP;
+    ue_context_pP = rrc_eNB_get_ue_context(RC.rrc[instance], rnti);
+    rrc_eNB_send_S1AP_UE_CONTEXT_RELEASE_REQ(
       instance,
       ue_context_pP,
       S1AP_CAUSE_RADIO_NETWORK,
       21); // send cause 21: connection with ue lost
+  }
 
   return 0;
 }
@@ -906,82 +834,74 @@ int CU_handle_UE_CONTEXT_RELEASE_REQUEST(instance_t       instance,
 
 int CU_send_UE_CONTEXT_RELEASE_COMMAND(instance_t instance,
                                        f1ap_ue_context_release_cmd_t *cmd) {
-  F1AP_F1AP_PDU_t                   pdu;
+  F1AP_F1AP_PDU_t                   pdu= {0};
   F1AP_UEContextReleaseCommand_t    *out;
-  F1AP_UEContextReleaseCommandIEs_t *ie;
-
-  uint8_t  *buffer;
-  uint32_t  len;
-
+  uint8_t  *buffer=NULL;
+  uint32_t  len=0;
   /* Create */
   /* 0. Message Type */
-  memset(&pdu, 0, sizeof(pdu));
   pdu.present = F1AP_F1AP_PDU_PR_initiatingMessage;
-  pdu.choice.initiatingMessage = (F1AP_InitiatingMessage_t *)calloc(1, sizeof(F1AP_InitiatingMessage_t));
-  pdu.choice.initiatingMessage->procedureCode = F1AP_ProcedureCode_id_UEContextRelease;
-  pdu.choice.initiatingMessage->criticality   = F1AP_Criticality_reject;
-  pdu.choice.initiatingMessage->value.present = F1AP_InitiatingMessage__value_PR_UEContextReleaseCommand;
-  out = &pdu.choice.initiatingMessage->value.choice.UEContextReleaseCommand;
-  
+  asn1cCalloc(pdu.choice.initiatingMessage, tmp);
+  tmp->procedureCode = F1AP_ProcedureCode_id_UEContextRelease;
+  tmp->criticality   = F1AP_Criticality_reject;
+  tmp->value.present = F1AP_InitiatingMessage__value_PR_UEContextReleaseCommand;
+  out = &tmp->value.choice.UEContextReleaseCommand;
   /* mandatory */
   /* c1. GNB_CU_UE_F1AP_ID */
-  ie = (F1AP_UEContextReleaseCommandIEs_t *)calloc(1, sizeof(F1AP_UEContextReleaseCommandIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
-  ie->criticality                    = F1AP_Criticality_reject;
-  ie->value.present                  = F1AP_UEContextReleaseCommandIEs__value_PR_GNB_CU_UE_F1AP_ID;
-  ie->value.choice.GNB_CU_UE_F1AP_ID = f1ap_get_cu_ue_f1ap_id(&f1ap_cu_inst[instance], cmd->rnti);
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextReleaseCommandIEs_t, ie1);
+  ie1->id                             = F1AP_ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
+  ie1->criticality                    = F1AP_Criticality_reject;
+  ie1->value.present                  = F1AP_UEContextReleaseCommandIEs__value_PR_GNB_CU_UE_F1AP_ID;
+  ie1->value.choice.GNB_CU_UE_F1AP_ID = f1ap_get_cu_ue_f1ap_id(CUtype, instance, cmd->rnti);
   /* mandatory */
   /* c2. GNB_DU_UE_F1AP_ID */
-  ie = (F1AP_UEContextReleaseCommandIEs_t *)calloc(1, sizeof(F1AP_UEContextReleaseCommandIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
-  ie->criticality                    = F1AP_Criticality_reject;
-  ie->value.present                  = F1AP_UEContextReleaseCommandIEs__value_PR_GNB_DU_UE_F1AP_ID;
-  ie->value.choice.GNB_DU_UE_F1AP_ID = f1ap_get_du_ue_f1ap_id(&f1ap_cu_inst[instance], cmd->rnti);
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextReleaseCommandIEs_t, ie2);
+  ie2->id                             = F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
+  ie2->criticality                    = F1AP_Criticality_reject;
+  ie2->value.present                  = F1AP_UEContextReleaseCommandIEs__value_PR_GNB_DU_UE_F1AP_ID;
+  ie2->value.choice.GNB_DU_UE_F1AP_ID = f1ap_get_du_ue_f1ap_id(CUtype, instance, cmd->rnti);
   /* mandatory */
   /* c3. Cause */
-  ie = (F1AP_UEContextReleaseCommandIEs_t *)calloc(1, sizeof(F1AP_UEContextReleaseCommandIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_Cause;
-  ie->criticality                    = F1AP_Criticality_ignore;
-  ie->value.present                  = F1AP_UEContextReleaseCommandIEs__value_PR_Cause;
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextReleaseCommandIEs_t, ie3);
+  ie3->id                             = F1AP_ProtocolIE_ID_id_Cause;
+  ie3->criticality                    = F1AP_Criticality_ignore;
+  ie3->value.present                  = F1AP_UEContextReleaseCommandIEs__value_PR_Cause;
 
   switch (cmd->cause) {
     case F1AP_CAUSE_RADIO_NETWORK:
-      ie->value.choice.Cause.present = F1AP_Cause_PR_radioNetwork;
-      ie->value.choice.Cause.choice.radioNetwork = cmd->cause_value;
+      ie3->value.choice.Cause.present = F1AP_Cause_PR_radioNetwork;
+      ie3->value.choice.Cause.choice.radioNetwork = cmd->cause_value;
       break;
+
     case F1AP_CAUSE_TRANSPORT:
-      ie->value.choice.Cause.present = F1AP_Cause_PR_transport;
-      ie->value.choice.Cause.choice.transport = cmd->cause_value;
+      ie3->value.choice.Cause.present = F1AP_Cause_PR_transport;
+      ie3->value.choice.Cause.choice.transport = cmd->cause_value;
       break;
+
     case F1AP_CAUSE_PROTOCOL:
-      ie->value.choice.Cause.present = F1AP_Cause_PR_protocol;
-      ie->value.choice.Cause.choice.protocol = cmd->cause_value;
+      ie3->value.choice.Cause.present = F1AP_Cause_PR_protocol;
+      ie3->value.choice.Cause.choice.protocol = cmd->cause_value;
       break;
+
     case F1AP_CAUSE_MISC:
-      ie->value.choice.Cause.present = F1AP_Cause_PR_misc;
-      ie->value.choice.Cause.choice.misc = cmd->cause_value;
+      ie3->value.choice.Cause.present = F1AP_Cause_PR_misc;
+      ie3->value.choice.Cause.choice.misc = cmd->cause_value;
       break;
+
     case F1AP_CAUSE_NOTHING:
     default:
-      ie->value.choice.Cause.present = F1AP_Cause_PR_NOTHING;
+      ie3->value.choice.Cause.present = F1AP_Cause_PR_NOTHING;
       break;
   }
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
 
   /* optional */
   /* c4. RRCContainer */
-  ie = (F1AP_UEContextReleaseCommandIEs_t *)calloc(1, sizeof(F1AP_UEContextReleaseCommandIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_RRCContainer;
-  ie->criticality                    = F1AP_Criticality_ignore;
-  ie->value.present                  = F1AP_UEContextReleaseCommandIEs__value_PR_RRCContainer;
-
-  OCTET_STRING_fromBuf(&ie->value.choice.RRCContainer, (const char *)cmd->rrc_container,
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextReleaseCommandIEs_t, ie4);
+  ie4->id                             = F1AP_ProtocolIE_ID_id_RRCContainer;
+  ie4->criticality                    = F1AP_Criticality_ignore;
+  ie4->value.present                  = F1AP_UEContextReleaseCommandIEs__value_PR_RRCContainer;
+  OCTET_STRING_fromBuf(&ie4->value.choice.RRCContainer, (const char *)cmd->rrc_container,
                        cmd->rrc_container_length);
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
 
   /* encode */
   if (f1ap_encode_pdu(&pdu, &buffer, &len) < 0) {
@@ -989,91 +909,85 @@ int CU_send_UE_CONTEXT_RELEASE_COMMAND(instance_t instance,
     return -1;
   }
 
-  cu_f1ap_itti_send_sctp_data_req(instance, f1ap_du_data_from_du->assoc_id, buffer, len, 0);
-
+  f1ap_itti_send_sctp_data_req(true, instance, buffer, len, 0);
   return 0;
 }
-
 int CU_handle_UE_CONTEXT_RELEASE_COMPLETE(instance_t       instance,
-                                         uint32_t         assoc_id,
-                                         uint32_t         stream,
-                                         F1AP_F1AP_PDU_t *pdu) {
+    uint32_t         assoc_id,
+    uint32_t         stream,
+    F1AP_F1AP_PDU_t *pdu) {
   F1AP_UEContextReleaseComplete_t    *container;
   F1AP_UEContextReleaseCompleteIEs_t *ie;
-
   DevAssert(pdu);
-
   container = &pdu->choice.successfulOutcome->value.choice.UEContextReleaseComplete;
   /* GNB_CU_UE_F1AP_ID */
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_UEContextReleaseCompleteIEs_t, ie, container,
                              F1AP_ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID, true);
-  const rnti_t rnti = f1ap_get_rnti_by_cu_id(&f1ap_cu_inst[instance],
-                                             ie->value.choice.GNB_CU_UE_F1AP_ID);
-
+  const rnti_t rnti = f1ap_get_rnti_by_cu_id(CUtype, instance,
+                      ie->value.choice.GNB_CU_UE_F1AP_ID);
   /* GNB_DU_UE_F1AP_ID */
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_UEContextReleaseCompleteIEs_t, ie, container,
                              F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID, true);
-  const rnti_t rnti2 = f1ap_get_rnti_by_du_id(&f1ap_cu_inst[instance],
-                                              ie->value.choice.GNB_DU_UE_F1AP_ID);
+  const rnti_t rnti2 = f1ap_get_rnti_by_du_id(CUtype, instance,
+                       ie->value.choice.GNB_DU_UE_F1AP_ID);
   AssertFatal(rnti == rnti2, "RNTI obtained through DU ID (%x) is different from CU ID (%x)\n",
               rnti2, rnti);
-
   /* Optional*/
   /* CriticalityDiagnostics */
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_UEContextReleaseCompleteIEs_t, ie, container,
                              F1AP_ProtocolIE_ID_id_CriticalityDiagnostics, false);
+
   if (ie) {
     // ie->value.choice.CriticalityDiagnostics.procedureCode
     // ie->value.choice.CriticalityDiagnostics.triggeringMessage
     // ie->value.choice.CriticalityDiagnostics.procedureCriticality
     // ie->value.choice.CriticalityDiagnostics.transactionID
-
     // F1AP_CriticalityDiagnostics_IE_List
   }
 
   protocol_ctxt_t ctxt;
   PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, instance, ENB_FLAG_YES, rnti, 0, 0, instance);
 
-  if (RC.nrrrc[instance]->node_type == ngran_gNB_CU) {
+  if (f1ap_req(true, instance)->cell_type==CELL_MACRO_GNB) {
     struct rrc_gNB_ue_context_s *ue_context_p =
-        rrc_gNB_get_ue_context(RC.nrrrc[instance], rnti);
+      rrc_gNB_get_ue_context(RC.nrrrc[instance], rnti);
 
     if (ue_context_p) {
       MessageDef *msg = itti_alloc_new_message(TASK_CU_F1, 0, NGAP_UE_CONTEXT_RELEASE_COMPLETE);
       NGAP_UE_CONTEXT_RELEASE_COMPLETE(msg).gNB_ue_ngap_id = ue_context_p->ue_context.gNB_ue_ngap_id;
       itti_send_msg_to_task(TASK_NGAP, instance, msg);
-
       rrc_gNB_remove_ue_context(&ctxt, RC.nrrrc[instance], ue_context_p);
     } else {
       LOG_E(F1AP, "could not find ue_context of UE RNTI %x\n", rnti);
     }
+
 #ifdef ITTI_SIM
     return 0;
 #endif
-
   } else {
     struct rrc_eNB_ue_context_s *ue_context_p =
-        rrc_eNB_get_ue_context(RC.rrc[instance], rnti);
+      rrc_eNB_get_ue_context(RC.rrc[instance], rnti);
 
     if (ue_context_p) {
       /* The following is normally done in the function rrc_rx_tx() */
       rrc_eNB_send_S1AP_UE_CONTEXT_RELEASE_CPLT(instance,
           ue_context_p->ue_context.eNB_ue_s1ap_id);
-
       rrc_eNB_send_GTPV1U_ENB_DELETE_TUNNEL_REQ(instance, 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]));
+               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 =
-          rrc_eNB_S1AP_get_ue_ids(RC.rrc[instance], 0,
-                                  ue_context_p->ue_context.eNB_ue_s1ap_id);
+        rrc_eNB_S1AP_get_ue_ids(RC.rrc[instance], 0,
+                                ue_context_p->ue_context.eNB_ue_s1ap_id);
+
       if (rrc_ue_s1ap_ids)
-          rrc_eNB_S1AP_remove_ue_ids(RC.rrc[instance], rrc_ue_s1ap_ids);
+        rrc_eNB_S1AP_remove_ue_ids(RC.rrc[instance], rrc_ue_s1ap_ids);
 
       /* trigger UE release in RRC */
       rrc_eNB_remove_ue_context(&ctxt, RC.rrc[instance], ue_context_p);
@@ -1087,477 +1001,345 @@ int CU_handle_UE_CONTEXT_RELEASE_COMPLETE(instance_t       instance,
   /* notify the agent */
   if (flexran_agent_get_rrc_xface(instance))
     flexran_agent_get_rrc_xface(instance)->flexran_agent_notify_ue_state_change(
-        instance, rnti, PROTOCOL__FLEX_UE_STATE_CHANGE_TYPE__FLUESC_DEACTIVATED);
+      instance, rnti, PROTOCOL__FLEX_UE_STATE_CHANGE_TYPE__FLUESC_DEACTIVATED);
 
   LOG_I(F1AP, "Received UE CONTEXT RELEASE COMPLETE: Removing CU UE entry for RNTI %x\n", rnti);
-  f1ap_remove_ue(&f1ap_cu_inst[instance], rnti);
+  f1ap_remove_ue(CUtype, instance, rnti);
   return 0;
 }
-
-
 //void CU_send_UE_CONTEXT_MODIFICATION_REQUEST(F1AP_UEContextModificationRequest_t *UEContextModificationRequest) {
 int CU_send_UE_CONTEXT_MODIFICATION_REQUEST(instance_t instance) {
-  F1AP_F1AP_PDU_t                        pdu;
+  F1AP_F1AP_PDU_t                        pdu= {0};
   F1AP_UEContextModificationRequest_t    *out;
-  F1AP_UEContextModificationRequestIEs_t *ie;
-
-  uint8_t  *buffer;
-  uint32_t  len;
-  int       i = 0;
-
+  uint8_t  *buffer=NULL;
+  uint32_t  len=0;
   // for test
-  int mcc = 208;
-  int mnc = 92;
-  int mnc_digit_length = 2;
-
+  cellIDs_t hardCoded= { .mcc=208, .mnc=93, .mnc_digit_length=2};
   /* Create */
   /* 0. Message Type */
-  memset(&pdu, 0, sizeof(pdu));
   pdu.present = F1AP_F1AP_PDU_PR_initiatingMessage;
-  pdu.choice.initiatingMessage = (F1AP_InitiatingMessage_t *)calloc(1, sizeof(F1AP_InitiatingMessage_t));
-  pdu.choice.initiatingMessage->procedureCode = F1AP_ProcedureCode_id_UEContextModification;
-  pdu.choice.initiatingMessage->criticality   = F1AP_Criticality_reject;
-  pdu.choice.initiatingMessage->value.present = F1AP_InitiatingMessage__value_PR_UEContextModificationRequest;
-  out = &pdu.choice.initiatingMessage->value.choice.UEContextModificationRequest;
-  
+  asn1cCalloc(pdu.choice.initiatingMessage, tmp);
+  tmp->procedureCode = F1AP_ProcedureCode_id_UEContextModification;
+  tmp->criticality   = F1AP_Criticality_reject;
+  tmp->value.present = F1AP_InitiatingMessage__value_PR_UEContextModificationRequest;
+  out = &tmp->value.choice.UEContextModificationRequest;
   /* mandatory */
   /* c1. GNB_CU_UE_F1AP_ID */
-  ie = (F1AP_UEContextModificationRequestIEs_t *)calloc(1, sizeof(F1AP_UEContextModificationRequestIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
-  ie->criticality                    = F1AP_Criticality_reject;
-  ie->value.present                  = F1AP_UEContextModificationRequestIEs__value_PR_GNB_CU_UE_F1AP_ID;
-  ie->value.choice.GNB_CU_UE_F1AP_ID = 126L;
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextModificationRequestIEs_t, ie1);
+  ie1->id                             = F1AP_ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
+  ie1->criticality                    = F1AP_Criticality_reject;
+  ie1->value.present                  = F1AP_UEContextModificationRequestIEs__value_PR_GNB_CU_UE_F1AP_ID;
+  ie1->value.choice.GNB_CU_UE_F1AP_ID = 126L;
   /* mandatory */
   /* c2. GNB_DU_UE_F1AP_ID */
-  ie = (F1AP_UEContextModificationRequestIEs_t *)calloc(1, sizeof(F1AP_UEContextModificationRequestIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
-  ie->criticality                    = F1AP_Criticality_reject;
-  ie->value.present                  = F1AP_UEContextModificationRequestIEs__value_PR_GNB_DU_UE_F1AP_ID;
-  ie->value.choice.GNB_DU_UE_F1AP_ID = 651L;
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextModificationRequestIEs_t, ie2);
+  ie2->id                             = F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
+  ie2->criticality                    = F1AP_Criticality_reject;
+  ie2->value.present                  = F1AP_UEContextModificationRequestIEs__value_PR_GNB_DU_UE_F1AP_ID;
+  ie2->value.choice.GNB_DU_UE_F1AP_ID = 651L;
 
   /* optional */
   /* c3. NRCGI */
   if (0) {
-    ie = (F1AP_UEContextModificationRequestIEs_t *)calloc(1, sizeof(F1AP_UEContextModificationRequestIEs_t));
-    ie->id                             = F1AP_ProtocolIE_ID_id_SpCell_ID;
-    ie->criticality                    = F1AP_Criticality_ignore;
-    ie->value.present                  = F1AP_UEContextModificationRequestIEs__value_PR_NRCGI;
+    asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextModificationRequestIEs_t, ie3);
+    ie3->id                             = F1AP_ProtocolIE_ID_id_SpCell_ID;
+    ie3->criticality                    = F1AP_Criticality_ignore;
+    ie3->value.present                  = F1AP_UEContextModificationRequestIEs__value_PR_NRCGI;
     /* - nRCGI */
-    F1AP_NRCGI_t nRCGI;
-    MCC_MNC_TO_PLMNID(mcc, mnc, mnc_digit_length,
-                                         &nRCGI.pLMN_Identity);
-    NR_CELL_ID_TO_BIT_STRING(12345678, &nRCGI.nRCellIdentity);
-    ie->value.choice.NRCGI = nRCGI;
-
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    addnRCGI(ie3->value.choice.NRCGI, &hardCoded);
   }
 
   /* mandatory */
   /* c4. ServCellIndex */
-  ie = (F1AP_UEContextModificationRequestIEs_t *)calloc(1, sizeof(F1AP_UEContextModificationRequestIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_ServCellIndex;
-  ie->criticality                    = F1AP_Criticality_reject;
-  ie->value.present                  = F1AP_UEContextModificationRequestIEs__value_PR_ServCellIndex;
-  ie->value.choice.ServCellIndex     = 5L;
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextModificationRequestIEs_t, ie4);
+  ie4->id                             = F1AP_ProtocolIE_ID_id_ServCellIndex;
+  ie4->criticality                    = F1AP_Criticality_reject;
+  ie4->value.present                  = F1AP_UEContextModificationRequestIEs__value_PR_ServCellIndex;
+  ie4->value.choice.ServCellIndex     = 5L;
 
   /* optional */
   /* c5. DRXCycle */
   if (0) {
-    ie = (F1AP_UEContextModificationRequestIEs_t *)calloc(1, sizeof(F1AP_UEContextModificationRequestIEs_t));
-    ie->id                             = F1AP_ProtocolIE_ID_id_DRXCycle;
-    ie->criticality                    = F1AP_Criticality_ignore;
-    ie->value.present                  = F1AP_UEContextModificationRequestIEs__value_PR_DRXCycle;
-    ie->value.choice.DRXCycle.longDRXCycleLength = F1AP_LongDRXCycleLength_ms10; // enum
+    asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextModificationRequestIEs_t, ie5);
+    ie5->id                             = F1AP_ProtocolIE_ID_id_DRXCycle;
+    ie5->criticality                    = F1AP_Criticality_ignore;
+    ie5->value.present                  = F1AP_UEContextModificationRequestIEs__value_PR_DRXCycle;
+    ie5->value.choice.DRXCycle.longDRXCycleLength = F1AP_LongDRXCycleLength_ms10; // enum
+
     if (0) {
-      ie->value.choice.DRXCycle.shortDRXCycleLength = (F1AP_ShortDRXCycleLength_t *)calloc(1, sizeof(F1AP_ShortDRXCycleLength_t));
-      *ie->value.choice.DRXCycle.shortDRXCycleLength = F1AP_ShortDRXCycleLength_ms2; // enum
+      asn1cCallocOne(ie5->value.choice.DRXCycle.shortDRXCycleLength,
+                     F1AP_ShortDRXCycleLength_ms2); // enum
     }
+
     if (0) {
-      ie->value.choice.DRXCycle.shortDRXCycleTimer = (F1AP_ShortDRXCycleTimer_t *)calloc(1, sizeof(F1AP_ShortDRXCycleTimer_t));
-      *ie->value.choice.DRXCycle.shortDRXCycleTimer = 123L;
+      asn1cCallocOne(ie5->value.choice.DRXCycle.shortDRXCycleTimer, 123L);
     }
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
   }
 
   /* optional */
   /* c5. CUtoDURRCInformation */
   if (1) {
-    ie = (F1AP_UEContextModificationRequestIEs_t *)calloc(1, sizeof(F1AP_UEContextModificationRequestIEs_t));
-    ie->id                             = F1AP_ProtocolIE_ID_id_CUtoDURRCInformation;
-    ie->criticality                    = F1AP_Criticality_reject;
-    ie->value.present                  = F1AP_UEContextModificationRequestIEs__value_PR_CUtoDURRCInformation;
-    ie->value.choice.CUtoDURRCInformation.cG_ConfigInfo = (F1AP_CG_ConfigInfo_t *)calloc(1, sizeof(F1AP_CG_ConfigInfo_t));
+    asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextModificationRequestIEs_t, ie5);
+    ie5->id                             = F1AP_ProtocolIE_ID_id_CUtoDURRCInformation;
+    ie5->criticality                    = F1AP_Criticality_reject;
+    ie5->value.present                  = F1AP_UEContextModificationRequestIEs__value_PR_CUtoDURRCInformation;
+    asn1cCalloc(ie5->value.choice.CUtoDURRCInformation.cG_ConfigInfo, tmp);
     /* optional */
-    OCTET_STRING_fromBuf(ie->value.choice.CUtoDURRCInformation.cG_ConfigInfo, "asdsa1d32sa1d31asd31as",
+    OCTET_STRING_fromBuf(tmp, "asdsa1d32sa1d31asd31as",
                          strlen("asdsa1d32sa1d31asd31as"));
-    ie->value.choice.CUtoDURRCInformation.uE_CapabilityRAT_ContainerList = (F1AP_UE_CapabilityRAT_ContainerList_t *)calloc(1, sizeof(F1AP_UE_CapabilityRAT_ContainerList_t));
+    asn1cCalloc(ie5->value.choice.CUtoDURRCInformation.uE_CapabilityRAT_ContainerList,
+                tmp2);
     /* optional */
-    OCTET_STRING_fromBuf(ie->value.choice.CUtoDURRCInformation.uE_CapabilityRAT_ContainerList, "asdsa1d32sa1d31asd31as",
+    OCTET_STRING_fromBuf(tmp2, "asdsa1d32sa1d31asd31as",
                          strlen("asdsa1d32sa1d31asd31as"));
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
   }
 
   /* optional */
   /* c6. TransmissionActionIndicator */
   if (1) {
-    ie = (F1AP_UEContextModificationRequestIEs_t *)calloc(1, sizeof(F1AP_UEContextModificationRequestIEs_t));
-    ie->id                                     = F1AP_ProtocolIE_ID_id_TransmissionActionIndicator;
-    ie->criticality                            = F1AP_Criticality_ignore;
-    ie->value.present                          = F1AP_UEContextModificationRequestIEs__value_PR_TransmissionActionIndicator;
-    ie->value.choice.TransmissionActionIndicator = F1AP_TransmissionActionIndicator_stop;
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextModificationRequestIEs_t, ie6);
+    ie6->id                                     = F1AP_ProtocolIE_ID_id_TransmissionActionIndicator;
+    ie6->criticality                            = F1AP_Criticality_ignore;
+    ie6->value.present                          = F1AP_UEContextModificationRequestIEs__value_PR_TransmissionActionIndicator;
+    ie6->value.choice.TransmissionActionIndicator = F1AP_TransmissionActionIndicator_stop;
   }
 
   /* optional */
   /* c7. ResourceCoordinationTransferContainer */
   if (0) {
-    ie = (F1AP_UEContextModificationRequestIEs_t *)calloc(1, sizeof(F1AP_UEContextModificationRequestIEs_t));
-    ie->id                             = F1AP_ProtocolIE_ID_id_ResourceCoordinationTransferContainer;
-    ie->criticality                    = F1AP_Criticality_ignore;
-    ie->value.present                  = F1AP_UEContextModificationRequestIEs__value_PR_ResourceCoordinationTransferContainer;
-    OCTET_STRING_fromBuf(&ie->value.choice.ResourceCoordinationTransferContainer, "asdsa1d32sa1d31asd31as",
+    asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextModificationRequestIEs_t, ie7);
+    ie7->id                             = F1AP_ProtocolIE_ID_id_ResourceCoordinationTransferContainer;
+    ie7->criticality                    = F1AP_Criticality_ignore;
+    ie7->value.present                  = F1AP_UEContextModificationRequestIEs__value_PR_ResourceCoordinationTransferContainer;
+    OCTET_STRING_fromBuf(&ie7->value.choice.ResourceCoordinationTransferContainer, "asdsa1d32sa1d31asd31as",
                          strlen("asdsa1d32sa1d31asd31as"));
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
   }
 
   /* optional */
   /* c7. RRCRconfigurationCompleteIndicator */
   if (1) {
-    ie = (F1AP_UEContextModificationRequestIEs_t *)calloc(1, sizeof(F1AP_UEContextModificationRequestIEs_t));
-    ie->id                             = F1AP_ProtocolIE_ID_id_RRCReconfigurationCompleteIndicator;
-    ie->criticality                    = F1AP_Criticality_ignore;
-    ie->value.present                  = F1AP_UEContextModificationRequestIEs__value_PR_RRCReconfigurationCompleteIndicator;
-    ie->value.choice.RRCReconfigurationCompleteIndicator = F1AP_RRCReconfigurationCompleteIndicator_true;
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextModificationRequestIEs_t, ie71);
+    ie71->id                             = F1AP_ProtocolIE_ID_id_RRCReconfigurationCompleteIndicator;
+    ie71->criticality                    = F1AP_Criticality_ignore;
+    ie71->value.present                  = F1AP_UEContextModificationRequestIEs__value_PR_RRCReconfigurationCompleteIndicator;
+    ie71->value.choice.RRCReconfigurationCompleteIndicator = F1AP_RRCReconfigurationCompleteIndicator_true;
   }
 
   /* optional */
   /* c8. RRCContainer */
   if (1) {
-    ie = (F1AP_UEContextModificationRequestIEs_t *)calloc(1, sizeof(F1AP_UEContextModificationRequestIEs_t));
-    ie->id                             = F1AP_ProtocolIE_ID_id_RRCContainer;
-    ie->criticality                    = F1AP_Criticality_ignore;
-    ie->value.present                  = F1AP_UEContextModificationRequestIEs__value_PR_RRCContainer;
-    OCTET_STRING_fromBuf(&ie->value.choice.RRCContainer, "asdsa1d32sa1d31asd31as",
+    asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextModificationRequestIEs_t, ie8);
+    ie8->id                             = F1AP_ProtocolIE_ID_id_RRCContainer;
+    ie8->criticality                    = F1AP_Criticality_ignore;
+    ie8->value.present                  = F1AP_UEContextModificationRequestIEs__value_PR_RRCContainer;
+    OCTET_STRING_fromBuf(&ie8->value.choice.RRCContainer, "asdsa1d32sa1d31asd31as",
                          strlen("asdsa1d32sa1d31asd31as"));
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
   }
 
   /* mandatory */
   /* c9. SCell_ToBeSetupMod_List */
-  ie = (F1AP_UEContextModificationRequestIEs_t *)calloc(1, sizeof(F1AP_UEContextModificationRequestIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_SCell_ToBeSetupMod_List;
-  ie->criticality                    = F1AP_Criticality_ignore;
-  ie->value.present                  = F1AP_UEContextModificationRequestIEs__value_PR_SCell_ToBeSetupMod_List;
-
-  for (i=0;
-       i<1;
-       i++) {
-     //
-     F1AP_SCell_ToBeSetupMod_ItemIEs_t *scell_toBeSetupMod_item_ies;
-     scell_toBeSetupMod_item_ies = (F1AP_SCell_ToBeSetupMod_ItemIEs_t *)calloc(1, sizeof(F1AP_SCell_ToBeSetupMod_ItemIEs_t));
-     //memset((void *)&scell_toBeSetupMod_item_ies, 0, sizeof(F1AP_SCell_ToBeSetupMod_ItemIEs_t));
-     scell_toBeSetupMod_item_ies->id            = F1AP_ProtocolIE_ID_id_SCell_ToBeSetupMod_Item;
-     scell_toBeSetupMod_item_ies->criticality   = F1AP_Criticality_ignore;
-     scell_toBeSetupMod_item_ies->value.present = F1AP_SCell_ToBeSetupMod_ItemIEs__value_PR_SCell_ToBeSetupMod_Item;
-
-     /* 8.1 SCell_ToBeSetup_Item */
-     F1AP_SCell_ToBeSetupMod_Item_t scell_toBeSetupMod_item;
-     memset((void *)&scell_toBeSetupMod_item, 0, sizeof(F1AP_SCell_ToBeSetupMod_Item_t));
-
-  //   /* - sCell_ID */
-     F1AP_NRCGI_t nRCGI;
-     memset(&nRCGI, 0, sizeof(F1AP_NRCGI_t));
-     MCC_MNC_TO_PLMNID(mcc, mnc, mnc_digit_length,
-                                        &nRCGI.pLMN_Identity);
-     NR_CELL_ID_TO_BIT_STRING(12345678, &nRCGI.nRCellIdentity);
-     scell_toBeSetupMod_item.sCell_ID = nRCGI;
-
-     /* sCellIndex */
-     scell_toBeSetupMod_item.sCellIndex = 6;  // issue here
-
-     //   /* ADD */
-     scell_toBeSetupMod_item_ies->value.choice.SCell_ToBeSetupMod_Item = scell_toBeSetupMod_item;
-     ASN_SEQUENCE_ADD(&ie->value.choice.SCell_ToBeSetupMod_List.list,
-                      scell_toBeSetupMod_item_ies);
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextModificationRequestIEs_t, ie9);
+  ie9->id                             = F1AP_ProtocolIE_ID_id_SCell_ToBeSetupMod_List;
+  ie9->criticality                    = F1AP_Criticality_ignore;
+  ie9->value.present                  = F1AP_UEContextModificationRequestIEs__value_PR_SCell_ToBeSetupMod_List;
+
+  for (int i=0; i<1; i++) {
+    //
+    asn1cSequenceAdd(ie9->value.choice.SCell_ToBeSetupMod_List.list,
+                     F1AP_SCell_ToBeSetupMod_ItemIEs_t, scell_toBeSetupMod_item_ies);
+    scell_toBeSetupMod_item_ies->id            = F1AP_ProtocolIE_ID_id_SCell_ToBeSetupMod_Item;
+    scell_toBeSetupMod_item_ies->criticality   = F1AP_Criticality_ignore;
+    scell_toBeSetupMod_item_ies->value.present = F1AP_SCell_ToBeSetupMod_ItemIEs__value_PR_SCell_ToBeSetupMod_Item;
+    /* 8.1 SCell_ToBeSetup_Item */
+    F1AP_SCell_ToBeSetupMod_Item_t *scell_toBeSetupMod_item=
+      &scell_toBeSetupMod_item_ies->value.choice.SCell_ToBeSetupMod_Item;
+    //   /* - sCell_ID */
+    addnRCGI(scell_toBeSetupMod_item->sCell_ID, &hardCoded);
+    /* sCellIndex */
+    scell_toBeSetupMod_item->sCellIndex = 6;  // issue here
   }
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
 
   /* mandatory */
   /* c10. SCell_ToBeRemoved_List */
-  ie = (F1AP_UEContextModificationRequestIEs_t *)calloc(1, sizeof(F1AP_UEContextModificationRequestIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_SCell_ToBeRemoved_List;
-  ie->criticality                    = F1AP_Criticality_ignore;
-  ie->value.present                  = F1AP_UEContextModificationRequestIEs__value_PR_SCell_ToBeRemoved_List;
-
-  for (i=0;
-       i<1;
-       i++) {
-     //
-     F1AP_SCell_ToBeRemoved_ItemIEs_t *scell_toBeRemoved_item_ies;
-     scell_toBeRemoved_item_ies = (F1AP_SCell_ToBeRemoved_ItemIEs_t *)calloc(1, sizeof(F1AP_SCell_ToBeRemoved_ItemIEs_t));
-     //memset((void *)&scell_toBeRemoved_item_ies, 0, sizeof(F1AP_SCell_ToBeRemoved_ItemIEs_t));
-     scell_toBeRemoved_item_ies->id            = F1AP_ProtocolIE_ID_id_SCell_ToBeRemoved_Item;
-     scell_toBeRemoved_item_ies->criticality   = F1AP_Criticality_ignore;
-     scell_toBeRemoved_item_ies->value.present = F1AP_SCell_ToBeRemoved_ItemIEs__value_PR_SCell_ToBeRemoved_Item;
-
-     /* 10.1 SCell_ToBeRemoved_Item */
-     F1AP_SCell_ToBeRemoved_Item_t scell_toBeRemoved_item;
-     memset((void *)&scell_toBeRemoved_item, 0, sizeof(F1AP_SCell_ToBeRemoved_Item_t));
-
-     /* - sCell_ID */
-     F1AP_NRCGI_t nRCGI;
-     memset(&nRCGI, 0, sizeof(F1AP_NRCGI_t));
-     MCC_MNC_TO_PLMNID(mcc, mnc, mnc_digit_length,
-                                        &nRCGI.pLMN_Identity);
-     NR_CELL_ID_TO_BIT_STRING(12345678, &nRCGI.nRCellIdentity);
-     scell_toBeRemoved_item.sCell_ID = nRCGI;
-
-     /* ADD */
-     scell_toBeRemoved_item_ies->value.choice.SCell_ToBeRemoved_Item = scell_toBeRemoved_item;
-     ASN_SEQUENCE_ADD(&ie->value.choice.SCell_ToBeRemoved_List.list,
-                      scell_toBeRemoved_item_ies);
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextModificationRequestIEs_t, ie10);
+  ie10->id                             = F1AP_ProtocolIE_ID_id_SCell_ToBeRemoved_List;
+  ie10->criticality                    = F1AP_Criticality_ignore;
+  ie10->value.present                  = F1AP_UEContextModificationRequestIEs__value_PR_SCell_ToBeRemoved_List;
+
+  for (int i=0;  i<1; i++) {
+    //
+    asn1cSequenceAdd(ie10->value.choice.SCell_ToBeRemoved_List.list,
+                     F1AP_SCell_ToBeRemoved_ItemIEs_t, scell_toBeRemoved_item_ies);
+    scell_toBeRemoved_item_ies = (F1AP_SCell_ToBeRemoved_ItemIEs_t *)calloc(1, sizeof(F1AP_SCell_ToBeRemoved_ItemIEs_t));
+    //memset((void *)&scell_toBeRemoved_item_ies, 0, sizeof(F1AP_SCell_ToBeRemoved_ItemIEs_t));
+    scell_toBeRemoved_item_ies->id            = F1AP_ProtocolIE_ID_id_SCell_ToBeRemoved_Item;
+    scell_toBeRemoved_item_ies->criticality   = F1AP_Criticality_ignore;
+    scell_toBeRemoved_item_ies->value.present = F1AP_SCell_ToBeRemoved_ItemIEs__value_PR_SCell_ToBeRemoved_Item;
+    /* 10.1 SCell_ToBeRemoved_Item */
+    F1AP_SCell_ToBeRemoved_Item_t *scell_toBeRemoved_item=
+      &scell_toBeRemoved_item_ies->value.choice.SCell_ToBeRemoved_Item;
+    /* - sCell_ID */
+    addnRCGI(scell_toBeRemoved_item->sCell_ID, &hardCoded);
   }
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
 
   /* mandatory */
   /* c11. SRBs_ToBeSetupMod_List */
-  ie = (F1AP_UEContextModificationRequestIEs_t *)calloc(1, sizeof(F1AP_UEContextModificationRequestIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_SRBs_ToBeSetupMod_List;
-  ie->criticality                    = F1AP_Criticality_reject;
-  ie->value.present                  = F1AP_UEContextModificationRequestIEs__value_PR_SRBs_ToBeSetupMod_List;
-
-  for (i=0;
-       i<1;
-       i++) {
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextModificationRequestIEs_t, ie11);
+  ie11->id                             = F1AP_ProtocolIE_ID_id_SRBs_ToBeSetupMod_List;
+  ie11->criticality                    = F1AP_Criticality_reject;
+  ie11->value.present                  = F1AP_UEContextModificationRequestIEs__value_PR_SRBs_ToBeSetupMod_List;
+
+  for (int i=0;  i<1; i++) {
     //
-    F1AP_SRBs_ToBeSetupMod_ItemIEs_t *srbs_toBeSetupMod_item_ies;
-    srbs_toBeSetupMod_item_ies = (F1AP_SRBs_ToBeSetupMod_ItemIEs_t *)calloc(1, sizeof(F1AP_SRBs_ToBeSetupMod_ItemIEs_t));
-    //memset((void *)&srbs_toBeSetupMod_item_ies, 0, sizeof(F1AP_SRBs_ToBeSetupMod_ItemIEs_t));
+    asn1cSequenceAdd(ie11->value.choice.SRBs_ToBeSetupMod_List.list,
+                     F1AP_SRBs_ToBeSetupMod_ItemIEs_t, srbs_toBeSetupMod_item_ies);
     srbs_toBeSetupMod_item_ies->id            = F1AP_ProtocolIE_ID_id_SRBs_ToBeSetupMod_Item;
     srbs_toBeSetupMod_item_ies->criticality   = F1AP_Criticality_ignore;
     srbs_toBeSetupMod_item_ies->value.present = F1AP_SRBs_ToBeSetupMod_ItemIEs__value_PR_SRBs_ToBeSetupMod_Item;
-
     /* 9.1 SRBs_ToBeSetupMod_Item */
-    F1AP_SRBs_ToBeSetupMod_Item_t srbs_toBeSetupMod_item;
-    memset((void *)&srbs_toBeSetupMod_item, 0, sizeof(F1AP_SRBs_ToBeSetupMod_Item_t));
-
+    F1AP_SRBs_ToBeSetupMod_Item_t *srbs_toBeSetupMod_item=
+      &srbs_toBeSetupMod_item_ies->value.choice.SRBs_ToBeSetupMod_Item;
     /* - sRBID */
-    srbs_toBeSetupMod_item.sRBID = 3L;
-
-    /* ADD */
-    srbs_toBeSetupMod_item_ies->value.choice.SRBs_ToBeSetupMod_Item = srbs_toBeSetupMod_item;
-
-    ASN_SEQUENCE_ADD(&ie->value.choice.SRBs_ToBeSetupMod_List.list,
-                     srbs_toBeSetupMod_item_ies);
+    srbs_toBeSetupMod_item->sRBID = 3L;
   }
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
 
   /* mandatory */
   /* c12. DRBs_ToBeSetupMod_List */
-  ie = (F1AP_UEContextModificationRequestIEs_t *)calloc(1, sizeof(F1AP_UEContextModificationRequestIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_DRBs_ToBeSetupMod_List;
-  ie->criticality                    = F1AP_Criticality_reject;
-  ie->value.present                  = F1AP_UEContextModificationRequestIEs__value_PR_DRBs_ToBeSetupMod_List;
-
-  for (i=0;
-       i<1;
-       i++) {
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextModificationRequestIEs_t, ie12);
+  ie12->id                             = F1AP_ProtocolIE_ID_id_DRBs_ToBeSetupMod_List;
+  ie12->criticality                    = F1AP_Criticality_reject;
+  ie12->value.present                  = F1AP_UEContextModificationRequestIEs__value_PR_DRBs_ToBeSetupMod_List;
+
+  for (int i=0;   i<1; i++) {
     //
-    F1AP_DRBs_ToBeSetupMod_ItemIEs_t *drbs_toBeSetupMod_item_ies;
-    drbs_toBeSetupMod_item_ies = (F1AP_DRBs_ToBeSetupMod_ItemIEs_t *)calloc(1, sizeof(F1AP_DRBs_ToBeSetupMod_ItemIEs_t));
+    asn1cSequenceAdd(ie12->value.choice.DRBs_ToBeSetupMod_List.list,
+                     F1AP_DRBs_ToBeSetupMod_ItemIEs_t, drbs_toBeSetupMod_item_ies);
     drbs_toBeSetupMod_item_ies->id            = F1AP_ProtocolIE_ID_id_DRBs_ToBeSetupMod_Item;
     drbs_toBeSetupMod_item_ies->criticality   = F1AP_Criticality_reject;
     drbs_toBeSetupMod_item_ies->value.present = F1AP_DRBs_ToBeSetupMod_ItemIEs__value_PR_DRBs_ToBeSetupMod_Item;
-
     /* 12.1 DRBs_ToBeSetupMod_Item */
-    F1AP_DRBs_ToBeSetupMod_Item_t drbs_toBeSetupMod_item;
-    memset((void *)&drbs_toBeSetupMod_item, 0, sizeof(F1AP_DRBs_ToBeSetupMod_Item_t));
-
+    F1AP_DRBs_ToBeSetupMod_Item_t *drbs_toBeSetupMod_item=
+      &drbs_toBeSetupMod_item_ies->value.choice.DRBs_ToBeSetupMod_Item;
     /* dRBID */
-    drbs_toBeSetupMod_item.dRBID = 30L;
-
+    drbs_toBeSetupMod_item->dRBID = 30L;
     /* qoSInformation */
-    drbs_toBeSetupMod_item.qoSInformation.present = F1AP_QoSInformation_PR_eUTRANQoS;
-    drbs_toBeSetupMod_item.qoSInformation.choice.eUTRANQoS = (F1AP_EUTRANQoS_t *)calloc(1, sizeof(F1AP_EUTRANQoS_t));
-    drbs_toBeSetupMod_item.qoSInformation.choice.eUTRANQoS->qCI = 253L;
-
+    drbs_toBeSetupMod_item->qoSInformation.present = F1AP_QoSInformation_PR_eUTRANQoS;
+    drbs_toBeSetupMod_item->qoSInformation.choice.eUTRANQoS = (F1AP_EUTRANQoS_t *)calloc(1, sizeof(F1AP_EUTRANQoS_t));
+    drbs_toBeSetupMod_item->qoSInformation.choice.eUTRANQoS->qCI = 253L;
     /* uLUPTNLInformation_ToBeSetup_List */
-    int j = 0;
     int maxnoofULTunnels = 1; // 2;
-    for (j=0;
-            j<maxnoofULTunnels;
-            j++) {
-            /*  ULTunnels_ToBeSetup_Item */
-
-            F1AP_ULUPTNLInformation_ToBeSetup_Item_t *uLUPTNLInformation_ToBeSetup_Item;
-            uLUPTNLInformation_ToBeSetup_Item = (F1AP_ULUPTNLInformation_ToBeSetup_Item_t *)calloc(1, sizeof(F1AP_ULUPTNLInformation_ToBeSetup_Item_t));
-            uLUPTNLInformation_ToBeSetup_Item->uLUPTNLInformation.present = F1AP_UPTransportLayerInformation_PR_gTPTunnel;
-            F1AP_GTPTunnel_t *gTPTunnel = (F1AP_GTPTunnel_t *)calloc(1, sizeof(F1AP_GTPTunnel_t));
-
-            /* transportLayerAddress */
-            TRANSPORT_LAYER_ADDRESS_IPv4_TO_BIT_STRING(1234, &gTPTunnel->transportLayerAddress);
-
-            /* gTP_TEID */
-            OCTET_STRING_fromBuf(&gTPTunnel->gTP_TEID, "4567",
-                             strlen("4567"));
-
-            // Add
-            uLUPTNLInformation_ToBeSetup_Item->uLUPTNLInformation.choice.gTPTunnel = gTPTunnel;
-            ASN_SEQUENCE_ADD(&drbs_toBeSetupMod_item.uLUPTNLInformation_ToBeSetup_List.list, uLUPTNLInformation_ToBeSetup_Item);
+
+    for (int j=0;  j<maxnoofULTunnels;  j++) {
+      /*  ULTunnels_ToBeSetup_Item */
+      asn1cSequenceAdd( drbs_toBeSetupMod_item->uLUPTNLInformation_ToBeSetup_List.list,
+                        F1AP_ULUPTNLInformation_ToBeSetup_Item_t, uLUPTNLInformation_ToBeSetup_Item);
+      uLUPTNLInformation_ToBeSetup_Item->uLUPTNLInformation.present = F1AP_UPTransportLayerInformation_PR_gTPTunnel;
+      asn1cCalloc(uLUPTNLInformation_ToBeSetup_Item->uLUPTNLInformation.choice.gTPTunnel,
+                  gTPTunnel)
+      /* transportLayerAddress */
+      TRANSPORT_LAYER_ADDRESS_IPv4_TO_BIT_STRING(1234, &gTPTunnel->transportLayerAddress);
+      /* gTP_TEID */
+      OCTET_STRING_fromBuf(&gTPTunnel->gTP_TEID, "4567",
+                           strlen("4567"));
     }
 
     /* rLCMode */
-    drbs_toBeSetupMod_item.rLCMode = F1AP_RLCMode_rlc_um_bidirectional; // enum
+    drbs_toBeSetupMod_item->rLCMode = F1AP_RLCMode_rlc_um_bidirectional; // enum
 
     /* OPTIONAL */
     /* ULConfiguration */
     if (0) {
-       drbs_toBeSetupMod_item.uLConfiguration = (F1AP_ULConfiguration_t *)calloc(1, sizeof(F1AP_ULConfiguration_t));
+      drbs_toBeSetupMod_item->uLConfiguration = (F1AP_ULConfiguration_t *)calloc(1, sizeof(F1AP_ULConfiguration_t));
     }
-
-    /* ADD */
-    drbs_toBeSetupMod_item_ies->value.choice.DRBs_ToBeSetupMod_Item = drbs_toBeSetupMod_item;
-    ASN_SEQUENCE_ADD(&ie->value.choice.DRBs_ToBeSetupMod_List.list,
-                   drbs_toBeSetupMod_item_ies);
-    
   }
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
 
   /* mandatory */
   /* c13. DRBs_ToBeModified_List */
-  ie = (F1AP_UEContextModificationRequestIEs_t *)calloc(1, sizeof(F1AP_UEContextModificationRequestIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_DRBs_ToBeModified_List;
-  ie->criticality                    = F1AP_Criticality_reject;
-  ie->value.present                  = F1AP_UEContextModificationRequestIEs__value_PR_DRBs_ToBeModified_List;
-
-  for (i=0;
-       i<1;
-       i++) {
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextModificationRequestIEs_t, ie13);
+  ie13->id                             = F1AP_ProtocolIE_ID_id_DRBs_ToBeModified_List;
+  ie13->criticality                    = F1AP_Criticality_reject;
+  ie13->value.present                  = F1AP_UEContextModificationRequestIEs__value_PR_DRBs_ToBeModified_List;
+
+  for (int i=0;   i<1; i++) {
     //
-    F1AP_DRBs_ToBeModified_ItemIEs_t *drbs_toBeModified_item_ies;
-    drbs_toBeModified_item_ies = (F1AP_DRBs_ToBeModified_ItemIEs_t *)calloc(1, sizeof(F1AP_DRBs_ToBeModified_ItemIEs_t));
+    asn1cSequenceAdd( ie13->value.choice.DRBs_ToBeModified_List.list,
+                      F1AP_DRBs_ToBeModified_ItemIEs_t, drbs_toBeModified_item_ies);
     drbs_toBeModified_item_ies->id            = F1AP_ProtocolIE_ID_id_DRBs_ToBeModified_Item;
     drbs_toBeModified_item_ies->criticality   = F1AP_Criticality_reject;
     drbs_toBeModified_item_ies->value.present = F1AP_DRBs_ToBeModified_ItemIEs__value_PR_DRBs_ToBeModified_Item;
-
     /* 13.1 SRBs_ToBeModified_Item */
-    F1AP_DRBs_ToBeModified_Item_t drbs_toBeModified_item;
-    memset((void *)&drbs_toBeModified_item, 0, sizeof(F1AP_DRBs_ToBeModified_Item_t));
-
+    F1AP_DRBs_ToBeModified_Item_t *drbs_toBeModified_item=
+      &drbs_toBeModified_item_ies->value.choice.DRBs_ToBeModified_Item;
     /* dRBID */
-    drbs_toBeModified_item.dRBID = 30L;
-
+    drbs_toBeModified_item->dRBID = 30L;
     /* qoSInformation */
-    drbs_toBeModified_item.qoSInformation =calloc(1,sizeof(*drbs_toBeModified_item.qoSInformation));
-    drbs_toBeModified_item.qoSInformation->present = F1AP_QoSInformation_PR_eUTRANQoS;
-    drbs_toBeModified_item.qoSInformation->choice.eUTRANQoS = (F1AP_EUTRANQoS_t *)calloc(1, sizeof(F1AP_EUTRANQoS_t));
-    drbs_toBeModified_item.qoSInformation->choice.eUTRANQoS->qCI = 254L;
-
+    asn1cCalloc(drbs_toBeModified_item->qoSInformation, tmp);
+    tmp->present = F1AP_QoSInformation_PR_eUTRANQoS;
+    tmp->choice.eUTRANQoS = (F1AP_EUTRANQoS_t *)calloc(1, sizeof(F1AP_EUTRANQoS_t));
+    tmp->choice.eUTRANQoS->qCI = 254L;
     /* ULTunnels_ToBeModified_List */
-    int j = 0;
     int maxnoofULTunnels = 1; // 2;
-    for (j=0;
-            j<maxnoofULTunnels;
-            j++) {
-            /*  ULTunnels_ToBeModified_Item */
-            F1AP_ULUPTNLInformation_ToBeSetup_Item_t *uLUPTNLInformation_ToBeSetup_Item;
-            uLUPTNLInformation_ToBeSetup_Item = (F1AP_ULUPTNLInformation_ToBeSetup_Item_t *)calloc(1, sizeof(F1AP_ULUPTNLInformation_ToBeSetup_Item_t));
-            uLUPTNLInformation_ToBeSetup_Item->uLUPTNLInformation.present = F1AP_UPTransportLayerInformation_PR_gTPTunnel;
-            F1AP_GTPTunnel_t *gTPTunnel = (F1AP_GTPTunnel_t *)calloc(1, sizeof(F1AP_GTPTunnel_t));
-
-            TRANSPORT_LAYER_ADDRESS_IPv4_TO_BIT_STRING(1234, &gTPTunnel->transportLayerAddress);
 
-            OCTET_STRING_fromBuf(&gTPTunnel->gTP_TEID, "1204",
-                                 strlen("1204"));
-
-            uLUPTNLInformation_ToBeSetup_Item->uLUPTNLInformation.choice.gTPTunnel = gTPTunnel;
-
-            ASN_SEQUENCE_ADD(&drbs_toBeModified_item.uLUPTNLInformation_ToBeSetup_List.list, uLUPTNLInformation_ToBeSetup_Item);
+    for (int j=0; j<maxnoofULTunnels; j++) {
+      /*  ULTunnels_ToBeModified_Item */
+      asn1cSequenceAdd(drbs_toBeModified_item->uLUPTNLInformation_ToBeSetup_List.list,
+                       F1AP_ULUPTNLInformation_ToBeSetup_Item_t, uLUPTNLInformation_ToBeSetup_Item);
+      uLUPTNLInformation_ToBeSetup_Item->uLUPTNLInformation.present = F1AP_UPTransportLayerInformation_PR_gTPTunnel;
+      asn1cCalloc(uLUPTNLInformation_ToBeSetup_Item->uLUPTNLInformation.choice.gTPTunnel,
+                  gTPTunnel);
+      TRANSPORT_LAYER_ADDRESS_IPv4_TO_BIT_STRING(1234, &gTPTunnel->transportLayerAddress);
+      OCTET_STRING_fromBuf(&gTPTunnel->gTP_TEID, "1204",
+                           strlen("1204"));
     }
 
     /* OPTIONAL */
     /* ULConfiguration */
     if (0) {
-       drbs_toBeModified_item.uLConfiguration = (F1AP_ULConfiguration_t *)calloc(1, sizeof(F1AP_ULConfiguration_t));
+      drbs_toBeModified_item->uLConfiguration = (F1AP_ULConfiguration_t *)calloc(1, sizeof(F1AP_ULConfiguration_t));
     }
-
-    /* ADD */
-    drbs_toBeModified_item_ies->value.choice.DRBs_ToBeModified_Item = drbs_toBeModified_item;
-    ASN_SEQUENCE_ADD(&ie->value.choice.DRBs_ToBeModified_List.list,
-                   drbs_toBeModified_item_ies);
-
   }
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
 
   /* mandatory */
   /* c14. SRBs_ToBeReleased_List */
-  ie = (F1AP_UEContextModificationRequestIEs_t *)calloc(1, sizeof(F1AP_UEContextModificationRequestIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_SRBs_ToBeReleased_List;
-  ie->criticality                    = F1AP_Criticality_reject;
-  ie->value.present                  = F1AP_UEContextModificationRequestIEs__value_PR_SRBs_ToBeReleased_List;
-
-  for (i=0;
-       i<1;
-       i++) {
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextModificationRequestIEs_t, ie14);
+  ie14->id                             = F1AP_ProtocolIE_ID_id_SRBs_ToBeReleased_List;
+  ie14->criticality                    = F1AP_Criticality_reject;
+  ie14->value.present                  = F1AP_UEContextModificationRequestIEs__value_PR_SRBs_ToBeReleased_List;
+
+  for (int i=0;  i<1; i++) {
     //
-    F1AP_SRBs_ToBeReleased_ItemIEs_t *srbs_toBeReleased_item_ies;
-    srbs_toBeReleased_item_ies = (F1AP_SRBs_ToBeReleased_ItemIEs_t *)calloc(1, sizeof(F1AP_SRBs_ToBeReleased_ItemIEs_t));
-    //memset((void *)&srbs_toBeReleased_item_ies, 0, sizeof(F1AP_SRBs_ToBeReleased_ItemIEs_t));
+    asn1cSequenceAdd(ie14->value.choice.SRBs_ToBeReleased_List.list,
+                     F1AP_SRBs_ToBeReleased_ItemIEs_t, srbs_toBeReleased_item_ies);
     srbs_toBeReleased_item_ies->id            = F1AP_ProtocolIE_ID_id_SRBs_ToBeReleased_Item;
     srbs_toBeReleased_item_ies->criticality   = F1AP_Criticality_ignore;
     srbs_toBeReleased_item_ies->value.present = F1AP_SRBs_ToBeReleased_ItemIEs__value_PR_SRBs_ToBeReleased_Item;
-
     /* 9.1 SRBs_ToBeReleased_Item */
-    F1AP_SRBs_ToBeReleased_Item_t srbs_toBeReleased_item;
-    memset((void *)&srbs_toBeReleased_item, 0, sizeof(F1AP_SRBs_ToBeReleased_Item_t));
-
+    F1AP_SRBs_ToBeReleased_Item_t *srbs_toBeReleased_item=
+      &srbs_toBeReleased_item_ies->value.choice.SRBs_ToBeReleased_Item;
     /* - sRBID */
-    srbs_toBeReleased_item.sRBID = 2L;
-
-    /* ADD */
-    srbs_toBeReleased_item_ies->value.choice.SRBs_ToBeReleased_Item = srbs_toBeReleased_item;
-    ASN_SEQUENCE_ADD(&ie->value.choice.SRBs_ToBeReleased_List.list,
-                    srbs_toBeReleased_item_ies);
+    srbs_toBeReleased_item->sRBID = 2L;
   }
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
 
   /* mandatory */
   /* c15. DRBs_ToBeReleased_List */
-  ie = (F1AP_UEContextModificationRequestIEs_t *)calloc(1, sizeof(F1AP_UEContextModificationRequestIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_DRBs_ToBeReleased_List;
-  ie->criticality                    = F1AP_Criticality_reject;
-  ie->value.present                  = F1AP_UEContextModificationRequestIEs__value_PR_DRBs_ToBeReleased_List;
-
-  for (i=0;
-       i<1;
-       i++) {
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextModificationRequestIEs_t, ie15);
+  ie15->id                             = F1AP_ProtocolIE_ID_id_DRBs_ToBeReleased_List;
+  ie15->criticality                    = F1AP_Criticality_reject;
+  ie15->value.present                  = F1AP_UEContextModificationRequestIEs__value_PR_DRBs_ToBeReleased_List;
+
+  for (int i=0; i<1;  i++) {
     //
-    F1AP_DRBs_ToBeReleased_ItemIEs_t *drbs_toBeReleased_item_ies;
-    drbs_toBeReleased_item_ies = (F1AP_DRBs_ToBeReleased_ItemIEs_t *)calloc(1, sizeof(F1AP_DRBs_ToBeReleased_ItemIEs_t));
+    asn1cSequenceAdd(ie15->value.choice.DRBs_ToBeReleased_List.list,
+                     F1AP_DRBs_ToBeReleased_ItemIEs_t, drbs_toBeReleased_item_ies);
     drbs_toBeReleased_item_ies->id            = F1AP_ProtocolIE_ID_id_DRBs_ToBeReleased_Item;
     drbs_toBeReleased_item_ies->criticality   = F1AP_Criticality_reject;
     drbs_toBeReleased_item_ies->value.present = F1AP_DRBs_ToBeReleased_ItemIEs__value_PR_DRBs_ToBeReleased_Item;
-
     /* 14.1 SRBs_ToBeReleased_Item */
-    F1AP_DRBs_ToBeReleased_Item_t drbs_toBeReleased_item;
-    memset((void *)&drbs_toBeReleased_item, 0, sizeof(F1AP_DRBs_ToBeReleased_Item_t));
-
+    F1AP_DRBs_ToBeReleased_Item_t *drbs_toBeReleased_item=
+      &drbs_toBeReleased_item_ies->value.choice.DRBs_ToBeReleased_Item;
     /* dRBID */
-    drbs_toBeReleased_item.dRBID = 30L;
-
-    /* ADD */
-    drbs_toBeReleased_item_ies->value.choice.DRBs_ToBeReleased_Item = drbs_toBeReleased_item;
-    ASN_SEQUENCE_ADD(&ie->value.choice.DRBs_ToBeReleased_List.list,
-                    drbs_toBeReleased_item_ies);
-
+    drbs_toBeReleased_item->dRBID = 30L;
   }
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
 
   /* encode */
   if (f1ap_encode_pdu(&pdu, &buffer, &len) < 0) {
@@ -1569,27 +1351,27 @@ int CU_send_UE_CONTEXT_MODIFICATION_REQUEST(instance_t instance) {
 }
 
 int CU_handle_UE_CONTEXT_MODIFICATION_RESPONSE(instance_t       instance,
-                                               uint32_t         assoc_id,
-                                               uint32_t         stream,
-                                               F1AP_F1AP_PDU_t *pdu) {
+    uint32_t         assoc_id,
+    uint32_t         stream,
+    F1AP_F1AP_PDU_t *pdu) {
   AssertFatal(1==0,"Not implemented yet\n");
 }
 
 int CU_handle_UE_CONTEXT_MODIFICATION_FAILURE(instance_t       instance,
-                                              uint32_t         assoc_id,
-                                              uint32_t         stream,
-                                              F1AP_F1AP_PDU_t *pdu) {
+    uint32_t         assoc_id,
+    uint32_t         stream,
+    F1AP_F1AP_PDU_t *pdu) {
   AssertFatal(1==0,"Not implemented yet\n");
 }
 
 int CU_handle_UE_CONTEXT_MODIFICATION_REQUIRED(instance_t       instance,
-                                               uint32_t         assoc_id,
-                                               uint32_t         stream,
-                                               F1AP_F1AP_PDU_t *pdu) {
+    uint32_t         assoc_id,
+    uint32_t         stream,
+    F1AP_F1AP_PDU_t *pdu) {
   AssertFatal(1==0,"Not implemented yet\n");
 }
 
 int CU_send_UE_CONTEXT_MODIFICATION_CONFIRM(instance_t instance,
-                                            F1AP_UEContextModificationConfirm_t UEContextModificationConfirm_t) {
+    F1AP_UEContextModificationConfirm_t UEContextModificationConfirm_t) {
   AssertFatal(1==0,"Not implemented yet\n");
 }
diff --git a/openair2/F1AP/f1ap_cu_ue_context_management.h b/openair2/F1AP/f1ap_cu_ue_context_management.h
index cc4ca3e35f08cf768842e14a2410db6f4b828518..09af51ec54c2a9328e840e92151895c009fa9513 100644
--- a/openair2/F1AP/f1ap_cu_ue_context_management.h
+++ b/openair2/F1AP/f1ap_cu_ue_context_management.h
@@ -37,7 +37,7 @@
  * UE Context Setup
  */
 int CU_send_UE_CONTEXT_SETUP_REQUEST(instance_t instance,
-                                     f1ap_ue_context_setup_req_t *f1ap_ue_context_setup_req);
+                                     f1ap_ue_context_setup_t *f1ap_ue_context_setup_req);
 
 int CU_handle_UE_CONTEXT_SETUP_RESPONSE(instance_t       instance,
                                         uint32_t         assoc_id,
@@ -54,9 +54,9 @@ int CU_handle_UE_CONTEXT_SETUP_FAILURE(instance_t       instance,
  * UE Context Release Request (gNB-DU initiated)
  */
 int CU_handle_UE_CONTEXT_RELEASE_REQUEST(instance_t       instance,
-                                         uint32_t         assoc_id,
-                                         uint32_t         stream,
-                                         F1AP_F1AP_PDU_t *pdu);
+    uint32_t         assoc_id,
+    uint32_t         stream,
+    F1AP_F1AP_PDU_t *pdu);
 
 /*
  * UE Context Release (gNB-CU initiated)
@@ -65,32 +65,32 @@ int CU_send_UE_CONTEXT_RELEASE_COMMAND(instance_t instance,
                                        f1ap_ue_context_release_cmd_t *cmd);
 
 int CU_handle_UE_CONTEXT_RELEASE_COMPLETE(instance_t       instance,
-                                         uint32_t         assoc_id,
-                                         uint32_t         stream,
-                                         F1AP_F1AP_PDU_t *pdu);
+    uint32_t         assoc_id,
+    uint32_t         stream,
+    F1AP_F1AP_PDU_t *pdu);
 
 /*
  * UE Context Modification (gNB-CU initiated)
  */
 int CU_send_UE_CONTEXT_MODIFICATION_REQUEST(instance_t instance);
 int CU_handle_UE_CONTEXT_MODIFICATION_RESPONSE(instance_t       instance,
-                                               uint32_t         assoc_id,
-                                               uint32_t         stream,
-                                               F1AP_F1AP_PDU_t *pdu);
+    uint32_t         assoc_id,
+    uint32_t         stream,
+    F1AP_F1AP_PDU_t *pdu);
 int CU_handle_UE_CONTEXT_MODIFICATION_FAILURE(instance_t       instance,
-                                              uint32_t         assoc_id,
-                                              uint32_t         stream,
-                                              F1AP_F1AP_PDU_t *pdu);
+    uint32_t         assoc_id,
+    uint32_t         stream,
+    F1AP_F1AP_PDU_t *pdu);
 
 /*
  * UE Context Modification Required (gNB-DU initiated)
  */
 int CU_handle_UE_CONTEXT_MODIFICATION_REQUIRED(instance_t       instance,
-                                               uint32_t         assoc_id,
-                                               uint32_t         stream,
-                                               F1AP_F1AP_PDU_t *pdu);
+    uint32_t         assoc_id,
+    uint32_t         stream,
+    F1AP_F1AP_PDU_t *pdu);
 int CU_send_UE_CONTEXT_MODIFICATION_CONFIRM(instance_t instance,
-                                            F1AP_UEContextModificationConfirm_t UEContextModificationConfirm_t);
+    F1AP_UEContextModificationConfirm_t UEContextModificationConfirm_t);
 
 /*
  * UE Inactivity Notification
diff --git a/openair2/F1AP/f1ap_decoder.c b/openair2/F1AP/f1ap_decoder.c
index ac55db7fda7f9f16603d850d74004098f67b4f3a..6ebf1cc16d483445fe7095cfc633109f1193fc53 100644
--- a/openair2/F1AP/f1ap_decoder.c
+++ b/openair2/F1AP/f1ap_decoder.c
@@ -35,15 +35,13 @@
 
 int asn1_decoder_xer_print = 0;
 
-static int f1ap_decode_initiating_message(F1AP_F1AP_PDU_t *pdu)
-{
+static int f1ap_decode_initiating_message(F1AP_F1AP_PDU_t *pdu) {
   //MessageDef *message_p;
   //MessagesIds message_id;
   //asn_encode_to_new_buffer_result_t res = { NULL, {0, NULL, NULL} };
   DevAssert(pdu != NULL);
 
   switch(pdu->choice.initiatingMessage->procedureCode) {
-    
     case F1AP_ProcedureCode_id_F1Setup:
       //res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_F1AP_F1AP_PDU, pdu);
       LOG_I(F1AP, "%s(): F1AP_ProcedureCode_id_F1Setup\n", __func__);
@@ -68,15 +66,19 @@ static int f1ap_decode_initiating_message(F1AP_F1AP_PDU_t *pdu)
       //res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_F1AP_F1AP_PDU, pdu);
       LOG_I(F1AP, "%s(): F1AP_ProcedureCode_id_ULRRCMessageTransfer\n", __func__);
       break;
+
     case F1AP_ProcedureCode_id_UEContextRelease:
       LOG_I(F1AP, "%s(): F1AP_ProcedureCode_id_UEContextRelease\n", __func__);
       break;
+
     case F1AP_ProcedureCode_id_UEContextReleaseRequest:
       LOG_I(F1AP, "%s(): F1AP_ProcedureCode_id_UEContextReleaseRequest\n", __func__);
       break;
+
     case F1AP_ProcedureCode_id_UEContextSetup:
       LOG_I(F1AP, "%s(): F1AP_ProcedureCode_id_UEContextSetup\n", __func__);
       break;
+
     // case F1AP_ProcedureCode_id_InitialContextSetup:
     //   res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_F1AP_F1AP_PDU, pdu);
     //   message_id = F1AP_INITIAL_CONTEXT_SETUP_LOG;
@@ -92,7 +94,7 @@ static int f1ap_decode_initiating_message(F1AP_F1AP_PDU_t *pdu)
       // F1AP_ERROR("Unknown procedure ID (%d) for initiating message\n",
       //            (int)pdu->choice.initiatingMessage->procedureCode);
       LOG_E(F1AP, "Unknown procedure ID (%d) for initiating message\n",
-                  (int)pdu->choice.initiatingMessage->procedureCode);
+            (int)pdu->choice.initiatingMessage->procedureCode);
       AssertFatal( 0, "Unknown procedure ID (%d) for initiating message\n",
                    (int)pdu->choice.initiatingMessage->procedureCode);
       return -1;
@@ -101,8 +103,7 @@ static int f1ap_decode_initiating_message(F1AP_F1AP_PDU_t *pdu)
   return 0;
 }
 
-static int f1ap_decode_successful_outcome(F1AP_F1AP_PDU_t *pdu)
-{
+static int f1ap_decode_successful_outcome(F1AP_F1AP_PDU_t *pdu) {
   DevAssert(pdu != NULL);
 
   switch(pdu->choice.successfulOutcome->procedureCode) {
@@ -118,41 +119,41 @@ static int f1ap_decode_successful_outcome(F1AP_F1AP_PDU_t *pdu)
       LOG_I(F1AP, "%s(): F1AP_ProcedureCode_id_UEContextRelease\n", __func__);
       break;
 
+    case F1AP_ProcedureCode_id_UEContextSetup:
+      LOG_I(F1AP, "%s(): F1AP_ProcedureCode_id_UEContextSetup\n", __func__);
+      break;
+
     default:
       LOG_E(F1AP,"Unknown procedure ID (%d) for successfull outcome message\n",
-                 (int)pdu->choice.successfulOutcome->procedureCode);
+            (int)pdu->choice.successfulOutcome->procedureCode);
       return -1;
   }
 
   return 0;
 }
 
-static int f1ap_decode_unsuccessful_outcome(F1AP_F1AP_PDU_t *pdu)
-{
+static int f1ap_decode_unsuccessful_outcome(F1AP_F1AP_PDU_t *pdu) {
   DevAssert(pdu != NULL);
 
   switch(pdu->choice.unsuccessfulOutcome->procedureCode) {
     case F1AP_ProcedureCode_id_F1Setup:
-    LOG_I(F1AP, "%s(): F1AP_ProcedureCode_id_F1Setup\n", __func__);
-    break;
+      LOG_I(F1AP, "%s(): F1AP_ProcedureCode_id_F1Setup\n", __func__);
+      break;
 
     default:
       // F1AP_ERROR("Unknown procedure ID (%d) for unsuccessfull outcome message\n",
       //            (int)pdu->choice.unsuccessfulOutcome->procedureCode);
       LOG_E(F1AP, "Unknown procedure ID (%d) for unsuccessfull outcome message\n",
-                 (int)pdu->choice.unsuccessfulOutcome->procedureCode);
+            (int)pdu->choice.unsuccessfulOutcome->procedureCode);
       return -1;
   }
 
   return 0;
 }
 
-int f1ap_decode_pdu(F1AP_F1AP_PDU_t *pdu, const uint8_t *const buffer, uint32_t length)
-{
+int f1ap_decode_pdu(F1AP_F1AP_PDU_t *pdu, const uint8_t *const buffer, uint32_t length) {
   asn_dec_rval_t dec_ret;
-
   DevAssert(buffer != NULL);
-
   dec_ret = aper_decode(NULL,
                         &asn_DEF_F1AP_F1AP_PDU,
                         (void **)&pdu,
@@ -166,6 +167,7 @@ int f1ap_decode_pdu(F1AP_F1AP_PDU_t *pdu, const uint8_t *const buffer, uint32_t
     xer_fprint(stdout, &asn_DEF_F1AP_F1AP_PDU, pdu);
     LOG_E(F1AP, "----------------- ASN1 DECODER PRINT END ----------------- \n");
   }
+
   //LOG_I(F1AP, "f1ap_decode_pdu.dec_ret.code = %d\n", dec_ret.code);
 
   if (dec_ret.code != RC_OK) {
@@ -188,6 +190,5 @@ int f1ap_decode_pdu(F1AP_F1AP_PDU_t *pdu, const uint8_t *const buffer, uint32_t
       break;
   }
 
-
   return -1;
 }
diff --git a/openair2/F1AP/f1ap_du_interface_management.c b/openair2/F1AP/f1ap_du_interface_management.c
index b6ece9b13ff9c207d7e8ac0e61c464dd839e44e5..ce54e901919ea60b8e56a2016ae3fdff0dfa3c1b 100644
--- a/openair2/F1AP/f1ap_du_interface_management.c
+++ b/openair2/F1AP/f1ap_du_interface_management.c
@@ -37,24 +37,21 @@
 #include "f1ap_du_interface_management.h"
 #include "assertions.h"
 
-extern f1ap_setup_req_t *f1ap_du_data;
-extern RAN_CONTEXT_t RC;
+int to_NRNRB(int nrb) {
+  for (int i=0; i<sizeofArray(nrb_lut); i++)
+    if (nrb_lut[i] == nrb)
+      return i;
 
-int nrb_lut[29] = {11, 18, 24, 25, 31, 32, 38, 51, 52, 65, 66, 78, 79, 93, 106, 107, 121, 132, 133, 135, 160, 162, 189, 216, 217, 245, 264, 270, 273};
+  if(!RC.nrrrc)
+    return 0;
 
-int to_NRNRB(int nrb) {
-  if (RC.nrrrc) {
-    for (int i=0;i<29;i++) if (nrb_lut[i] == nrb) return i;
-    AssertFatal(1==0,"nrb %d is not in the list of possible NRNRB\n",nrb);
-  } else {
-    return nrb;
-  }
+  AssertFatal(1==0,"nrb %d is not in the list of possible NRNRB\n",nrb);
 }
 
 int DU_handle_RESET(instance_t instance,
-                                uint32_t assoc_id,
-                                uint32_t stream,
-                                F1AP_F1AP_PDU_t *pdu) {
+                    uint32_t assoc_id,
+                    uint32_t stream,
+                    F1AP_F1AP_PDU_t *pdu) {
   AssertFatal(1==0,"Not implemented yet\n");
 }
 
@@ -83,9 +80,9 @@ int DU_send_ERROR_INDICATION(instance_t instance, F1AP_F1AP_PDU_t *pdu_p) {
 }
 
 int DU_handle_ERROR_INDICATION(instance_t instance,
-                                uint32_t assoc_id,
-                                uint32_t stream,
-                                F1AP_F1AP_PDU_t *pdu) {
+                               uint32_t assoc_id,
+                               uint32_t stream,
+                               F1AP_F1AP_PDU_t *pdu) {
   AssertFatal(1==0,"Not implemented yet\n");
 }
 
@@ -96,336 +93,221 @@ int DU_handle_ERROR_INDICATION(instance_t instance,
 
 // SETUP REQUEST
 int DU_send_F1_SETUP_REQUEST(instance_t instance) {
-  module_id_t enb_mod_idP=0;
-  module_id_t du_mod_idP=0;
-
-  F1AP_F1AP_PDU_t          pdu; 
-  F1AP_F1SetupRequest_t    *out;
-  F1AP_F1SetupRequestIEs_t *ie;
-
+  instance_t enb_mod_idP=0;
+  instance_t du_mod_idP=0;
+  F1AP_F1AP_PDU_t       pdu= {0};
   uint8_t  *buffer;
   uint32_t  len;
-  int       i = 0;
-
   /* Create */
   /* 0. pdu Type */
-  memset(&pdu, 0, sizeof(pdu));
   pdu.present = F1AP_F1AP_PDU_PR_initiatingMessage;
-  pdu.choice.initiatingMessage = (F1AP_InitiatingMessage_t *)calloc(1, sizeof(F1AP_InitiatingMessage_t));
-  pdu.choice.initiatingMessage->procedureCode = F1AP_ProcedureCode_id_F1Setup;
-  pdu.choice.initiatingMessage->criticality   = F1AP_Criticality_reject;
-  pdu.choice.initiatingMessage->value.present = F1AP_InitiatingMessage__value_PR_F1SetupRequest;
-  out = &pdu.choice.initiatingMessage->value.choice.F1SetupRequest;
-
+  asn1cCalloc(pdu.choice.initiatingMessage, initMsg);
+  initMsg->procedureCode = F1AP_ProcedureCode_id_F1Setup;
+  initMsg->criticality   = F1AP_Criticality_reject;
+  initMsg->value.present = F1AP_InitiatingMessage__value_PR_F1SetupRequest;
+  F1AP_F1SetupRequest_t *f1Setup = &initMsg->value.choice.F1SetupRequest;
   /* mandatory */
   /* c1. Transaction ID (integer value) */
-  ie = (F1AP_F1SetupRequestIEs_t *)calloc(1, sizeof(F1AP_F1SetupRequestIEs_t));
-  ie->id                        = F1AP_ProtocolIE_ID_id_TransactionID;
-  ie->criticality               = F1AP_Criticality_reject;
-  ie->value.present             = F1AP_F1SetupRequestIEs__value_PR_TransactionID;
-  ie->value.choice.TransactionID = F1AP_get_next_transaction_identifier(enb_mod_idP, du_mod_idP);
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
+  asn1cSequenceAdd(f1Setup->protocolIEs.list, F1AP_F1SetupRequestIEs_t, ieC1);
+  ieC1->id                        = F1AP_ProtocolIE_ID_id_TransactionID;
+  ieC1->criticality               = F1AP_Criticality_reject;
+  ieC1->value.present             = F1AP_F1SetupRequestIEs__value_PR_TransactionID;
+  ieC1->value.choice.TransactionID = F1AP_get_next_transaction_identifier(enb_mod_idP, du_mod_idP);
   /* mandatory */
   /* c2. GNB_DU_ID (integer value) */
-  ie = (F1AP_F1SetupRequestIEs_t *)calloc(1, sizeof(F1AP_F1SetupRequestIEs_t));
-  ie->id                        = F1AP_ProtocolIE_ID_id_gNB_DU_ID;
-  ie->criticality               = F1AP_Criticality_reject;
-  ie->value.present             = F1AP_F1SetupRequestIEs__value_PR_GNB_DU_ID;
-  asn_int642INTEGER(&ie->value.choice.GNB_DU_ID, f1ap_du_data->gNB_DU_id);
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+  asn1cSequenceAdd(f1Setup->protocolIEs.list, F1AP_F1SetupRequestIEs_t, ieC2);
+  ieC2->id                        = F1AP_ProtocolIE_ID_id_gNB_DU_ID;
+  ieC2->criticality               = F1AP_Criticality_reject;
+  ieC2->value.present             = F1AP_F1SetupRequestIEs__value_PR_GNB_DU_ID;
+  asn_int642INTEGER(&ieC2->value.choice.GNB_DU_ID, f1ap_req(false, instance)->gNB_DU_id);
 
   /* optional */
   /* c3. GNB_DU_Name */
-  if (f1ap_du_data->gNB_DU_name != NULL) {
-    ie = (F1AP_F1SetupRequestIEs_t *)calloc(1, sizeof(F1AP_F1SetupRequestIEs_t));
-    ie->id                        = F1AP_ProtocolIE_ID_id_gNB_DU_Name;
-    ie->criticality               = F1AP_Criticality_ignore;
-    ie->value.present             = F1AP_F1SetupRequestIEs__value_PR_GNB_DU_Name;
-    OCTET_STRING_fromBuf(&ie->value.choice.GNB_DU_Name, f1ap_du_data->gNB_DU_name,
-                         strlen(f1ap_du_data->gNB_DU_name));
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+  if (f1ap_req(false,instance)->gNB_DU_name != NULL) {
+    asn1cSequenceAdd(f1Setup->protocolIEs.list, F1AP_F1SetupRequestIEs_t, ieC3);
+    ieC3->id                        = F1AP_ProtocolIE_ID_id_gNB_DU_Name;
+    ieC3->criticality               = F1AP_Criticality_ignore;
+    ieC3->value.present             = F1AP_F1SetupRequestIEs__value_PR_GNB_DU_Name;
+    char *gNB_DU_name=f1ap_req(false, instance)->gNB_DU_name;
+    OCTET_STRING_fromBuf(&ieC3->value.choice.GNB_DU_Name, gNB_DU_name, strlen(gNB_DU_name));
   }
 
   /* mandatory */
   /* c4. served cells list */
-  ie = (F1AP_F1SetupRequestIEs_t *)calloc(1, sizeof(F1AP_F1SetupRequestIEs_t));
-  ie->id                        = F1AP_ProtocolIE_ID_id_gNB_DU_Served_Cells_List;
-  ie->criticality               = F1AP_Criticality_reject;
-  ie->value.present             = F1AP_F1SetupRequestIEs__value_PR_GNB_DU_Served_Cells_List;
-
-  int num_cells_available = f1ap_du_data->num_cells_available;
+  asn1cSequenceAdd(f1Setup->protocolIEs.list, F1AP_F1SetupRequestIEs_t, ieCells);
+  ieCells->id                        = F1AP_ProtocolIE_ID_id_gNB_DU_Served_Cells_List;
+  ieCells->criticality               = F1AP_Criticality_reject;
+  ieCells->value.present             = F1AP_F1SetupRequestIEs__value_PR_GNB_DU_Served_Cells_List;
+  int num_cells_available = f1ap_req(false, instance)->num_cells_available;
   LOG_D(F1AP, "num_cells_available = %d \n", num_cells_available);
-  for (i=0;
-       i<num_cells_available;
-       i++) {
-        /* mandatory */
-        /* 4.1 served cells item */
-
-        F1AP_GNB_DU_Served_Cells_ItemIEs_t *gnb_du_served_cell_list_item_ies;
-        gnb_du_served_cell_list_item_ies = (F1AP_GNB_DU_Served_Cells_ItemIEs_t *)calloc(1, sizeof(F1AP_GNB_DU_Served_Cells_ItemIEs_t));
-        gnb_du_served_cell_list_item_ies->id = F1AP_ProtocolIE_ID_id_GNB_DU_Served_Cells_Item;
-        gnb_du_served_cell_list_item_ies->criticality = F1AP_Criticality_reject;
-        gnb_du_served_cell_list_item_ies->value.present = F1AP_GNB_DU_Served_Cells_ItemIEs__value_PR_GNB_DU_Served_Cells_Item;
-        
-
-        F1AP_GNB_DU_Served_Cells_Item_t gnb_du_served_cells_item;
-        memset((void *)&gnb_du_served_cells_item, 0, sizeof(F1AP_GNB_DU_Served_Cells_Item_t));
-
-        /* 4.1.1 served cell Information */
-        F1AP_Served_Cell_Information_t served_cell_information;
-
-        memset((void *)&served_cell_information, 0, sizeof(F1AP_Served_Cell_Information_t));
-
-        /* - nRCGI */
-        F1AP_NRCGI_t nRCGI;
-        memset(&nRCGI, 0, sizeof(F1AP_NRCGI_t));
-        MCC_MNC_TO_PLMNID(f1ap_du_data->mcc[i], f1ap_du_data->mnc[i], f1ap_du_data->mnc_digit_length[i], &nRCGI.pLMN_Identity);
-        LOG_D(F1AP, "plmn: (%d,%d)\n",f1ap_du_data->mcc[i],f1ap_du_data->mnc[i]);
-        //MCC_MNC_TO_PLMNID(208, 95, 2, &nRCGI.pLMN_Identity);
-
-        NR_CELL_ID_TO_BIT_STRING(f1ap_du_data->nr_cellid[i], &nRCGI.nRCellIdentity);
-        LOG_D(F1AP, "nRCellIdentity (%llx): %x.%x.%x.%x.%x\n",
-              (long long unsigned int)f1ap_du_data->nr_cellid[i],
-              nRCGI.nRCellIdentity.buf[0],
-              nRCGI.nRCellIdentity.buf[1],
-              nRCGI.nRCellIdentity.buf[2],
-              nRCGI.nRCellIdentity.buf[3],
-              nRCGI.nRCellIdentity.buf[4]);
-
-        served_cell_information.nRCGI = nRCGI;
-
-        /* - nRPCI */
-        served_cell_information.nRPCI = f1ap_du_data->nr_pci[i];  // int 0..1007
-
-        /* - fiveGS_TAC */
-        if (RC.nrrrc) {
-          uint8_t fiveGS_TAC[3];
-          fiveGS_TAC[0] = ((uint8_t*)&f1ap_du_data->tac[i])[2];
-          fiveGS_TAC[1] = ((uint8_t*)&f1ap_du_data->tac[i])[1];
-          fiveGS_TAC[2] = ((uint8_t*)&f1ap_du_data->tac[i])[0];
-          OCTET_STRING_fromBuf(served_cell_information.fiveGS_TAC,
-                               (const char *)fiveGS_TAC,
-                               3);
-        } else {
-          OCTET_STRING_fromBuf(served_cell_information.fiveGS_TAC,
-                               (const char*)&f1ap_du_data->tac[i],
-                               3);
-        }
-
-        /* - Configured_EPS_TAC */
-        if(0){
-          served_cell_information.configured_EPS_TAC = (F1AP_Configured_EPS_TAC_t *)calloc(1, sizeof(F1AP_Configured_EPS_TAC_t));
-          OCTET_STRING_fromBuf(served_cell_information.configured_EPS_TAC,
-                             "2",
-                             2);
-        }
-
-        /* servedPLMN information */
-        F1AP_ServedPLMNs_Item_t *servedPLMN_item = calloc(1,sizeof(*servedPLMN_item));
-        memset(servedPLMN_item,0,sizeof(*servedPLMN_item));
-        MCC_MNC_TO_PLMNID(f1ap_du_data->mcc[i], f1ap_du_data->mnc[i], f1ap_du_data->mnc_digit_length[i], &servedPLMN_item->pLMN_Identity);
-        ASN_SEQUENCE_ADD(&served_cell_information.servedPLMNs.list, servedPLMN_item);
-
-        // // /* - CHOICE NR-MODE-Info */
-        F1AP_NR_Mode_Info_t nR_Mode_Info;
-        //f1ap_du_data->fdd_flag = 1;
-        if (f1ap_du_data->fdd_flag) { // FDD
-          nR_Mode_Info.present = F1AP_NR_Mode_Info_PR_fDD;
-          F1AP_FDD_Info_t *fDD_Info = (F1AP_FDD_Info_t *)calloc(1, sizeof(F1AP_FDD_Info_t));
-
-          /* FDD.1 UL NRFreqInfo */
-            /* FDD.1.1 UL NRFreqInfo ARFCN */
-            fDD_Info->uL_NRFreqInfo.nRARFCN = f1ap_du_data->nr_mode_info[i].fdd.ul_nr_arfcn; // Integer
-
-            /* FDD.1.2 F1AP_SUL_Information */
-            if(0) { // Optional
-              F1AP_SUL_Information_t *fdd_sul_info = (F1AP_SUL_Information_t *)calloc(1, sizeof(F1AP_SUL_Information_t));
-              fdd_sul_info->sUL_NRARFCN = 0;
-              fdd_sul_info->sUL_transmission_Bandwidth.nRSCS = 0;
-              fdd_sul_info->sUL_transmission_Bandwidth.nRNRB = 0;
-              fDD_Info->uL_NRFreqInfo.sul_Information = fdd_sul_info;
-            }
-
-            /* FDD.1.3 freqBandListNr */
-            int fdd_ul_num_available_freq_Bands = f1ap_du_data->nr_mode_info[i].fdd.ul_num_frequency_bands;
-            LOG_I(F1AP, "fdd_ul_num_available_freq_Bands = %d \n", fdd_ul_num_available_freq_Bands);
-            int fdd_ul_j;
-            for (fdd_ul_j=0;
-                 fdd_ul_j<fdd_ul_num_available_freq_Bands;
-                 fdd_ul_j++) {
-
-                  F1AP_FreqBandNrItem_t nr_freqBandNrItem;
-                  memset((void *)&nr_freqBandNrItem, 0, sizeof(F1AP_FreqBandNrItem_t));
-                  /* FDD.1.3.1 freqBandIndicatorNr*/
-                  nr_freqBandNrItem.freqBandIndicatorNr = f1ap_du_data->nr_mode_info[i].fdd.ul_nr_band[fdd_ul_j]; //
-
-                  /* FDD.1.3.2 supportedSULBandList*/
-                  int num_available_supported_SULBands = f1ap_du_data->nr_mode_info[i].fdd.ul_num_sul_frequency_bands;
-                  LOG_D(F1AP, "num_available_supported_SULBands = %d \n", num_available_supported_SULBands);
-                  int fdd_ul_k;
-                  for (fdd_ul_k=0;
-                       fdd_ul_k<num_available_supported_SULBands;
-                       fdd_ul_k++) {
-                        F1AP_SupportedSULFreqBandItem_t nr_supportedSULFreqBandItem;
-                        memset((void *)&nr_supportedSULFreqBandItem, 0, sizeof(F1AP_SupportedSULFreqBandItem_t));
-                          /* FDD.1.3.2.1 freqBandIndicatorNr */
-                          nr_supportedSULFreqBandItem.freqBandIndicatorNr = f1ap_du_data->nr_mode_info[i].fdd.ul_nr_sul_band[fdd_ul_k]; //
-                        ASN_SEQUENCE_ADD(&nr_freqBandNrItem.supportedSULBandList.list, &nr_supportedSULFreqBandItem);
-                  } // for FDD : UL supported_SULBands
-                  ASN_SEQUENCE_ADD(&fDD_Info->uL_NRFreqInfo.freqBandListNr.list, &nr_freqBandNrItem);
-            } // for FDD : UL freq_Bands
-           
-          /* FDD.2 DL NRFreqInfo */
-            /* FDD.2.1 DL NRFreqInfo ARFCN */
-            fDD_Info->dL_NRFreqInfo.nRARFCN = f1ap_du_data->nr_mode_info[i].fdd.dl_nr_arfcn; // Integer
-
-            /* FDD.2.2 F1AP_SUL_Information */
-            if(0) { // Optional
-              F1AP_SUL_Information_t *fdd_sul_info = (F1AP_SUL_Information_t *)calloc(1, sizeof(F1AP_SUL_Information_t));
-              fdd_sul_info->sUL_NRARFCN = 0;
-              fdd_sul_info->sUL_transmission_Bandwidth.nRSCS = 0;
-              fdd_sul_info->sUL_transmission_Bandwidth.nRNRB = 0;
-              fDD_Info->dL_NRFreqInfo.sul_Information = fdd_sul_info;
-            }
-
-            /* FDD.2.3 freqBandListNr */
-            int fdd_dl_num_available_freq_Bands = f1ap_du_data->nr_mode_info[i].fdd.dl_num_frequency_bands;
-            LOG_I(F1AP, "fdd_dl_num_available_freq_Bands = %d \n", fdd_dl_num_available_freq_Bands);
-            int fdd_dl_j;
-            for (fdd_dl_j=0;
-                 fdd_dl_j<fdd_dl_num_available_freq_Bands;
-                 fdd_dl_j++) {
-
-                  F1AP_FreqBandNrItem_t nr_freqBandNrItem;
-                  memset((void *)&nr_freqBandNrItem, 0, sizeof(F1AP_FreqBandNrItem_t));
-                  /* FDD.2.3.1 freqBandIndicatorNr*/
-                  nr_freqBandNrItem.freqBandIndicatorNr = f1ap_du_data->nr_mode_info[i].fdd.dl_nr_band[fdd_dl_j]; //
-
-                  /* FDD.2.3.2 supportedSULBandList*/
-                  int num_available_supported_SULBands = f1ap_du_data->nr_mode_info[i].fdd.dl_num_sul_frequency_bands;
-                  LOG_D(F1AP, "num_available_supported_SULBands = %d \n", num_available_supported_SULBands);
-                  int fdd_dl_k;
-                  for (fdd_dl_k=0;
-                       fdd_dl_k<num_available_supported_SULBands;
-                       fdd_dl_k++) {
-                        F1AP_SupportedSULFreqBandItem_t nr_supportedSULFreqBandItem;
-                        memset((void *)&nr_supportedSULFreqBandItem, 0, sizeof(F1AP_SupportedSULFreqBandItem_t));
-                          /* FDD.2.3.2.1 freqBandIndicatorNr */
-                          nr_supportedSULFreqBandItem.freqBandIndicatorNr = f1ap_du_data->nr_mode_info[i].fdd.dl_nr_sul_band[fdd_dl_k]; //
-                        ASN_SEQUENCE_ADD(&nr_freqBandNrItem.supportedSULBandList.list, &nr_supportedSULFreqBandItem);
-                  } // for FDD : DL supported_SULBands
-                  ASN_SEQUENCE_ADD(&fDD_Info->dL_NRFreqInfo.freqBandListNr.list, &nr_freqBandNrItem);
-            } // for FDD : DL freq_Bands
-
-          /* FDD.3 UL Transmission Bandwidth */
-          fDD_Info->uL_Transmission_Bandwidth.nRSCS = f1ap_du_data->nr_mode_info[i].fdd.ul_scs;
-          fDD_Info->uL_Transmission_Bandwidth.nRNRB = to_NRNRB(f1ap_du_data->nr_mode_info[i].fdd.ul_nrb);
-          /* FDD.4 DL Transmission Bandwidth */
-          fDD_Info->dL_Transmission_Bandwidth.nRSCS = f1ap_du_data->nr_mode_info[i].fdd.dl_scs;
-          fDD_Info->dL_Transmission_Bandwidth.nRNRB = to_NRNRB(f1ap_du_data->nr_mode_info[i].fdd.dl_nrb);
-          
-          nR_Mode_Info.choice.fDD = fDD_Info;
-        } else { // TDD
-          nR_Mode_Info.present = F1AP_NR_Mode_Info_PR_tDD;
-          F1AP_TDD_Info_t *tDD_Info = (F1AP_TDD_Info_t *)calloc(1, sizeof(F1AP_TDD_Info_t));
-
-          /* TDD.1 nRFreqInfo */
-            /* TDD.1.1 nRFreqInfo ARFCN */
-            tDD_Info->nRFreqInfo.nRARFCN = f1ap_du_data->nr_mode_info[i].tdd.nr_arfcn; // Integer
-
-            /* TDD.1.2 F1AP_SUL_Information */
-            if(0) { // Optional
-              F1AP_SUL_Information_t *tdd_sul_info = (F1AP_SUL_Information_t *)calloc(1, sizeof(F1AP_SUL_Information_t));
-              tdd_sul_info->sUL_NRARFCN = 0;
-              tdd_sul_info->sUL_transmission_Bandwidth.nRSCS = 0;
-              tdd_sul_info->sUL_transmission_Bandwidth.nRNRB = 0;
-              tDD_Info->nRFreqInfo.sul_Information = tdd_sul_info;
-            }
-
-            /* TDD.1.3 freqBandListNr */
-            int tdd_num_available_freq_Bands = f1ap_du_data->nr_mode_info[i].tdd.num_frequency_bands;
-            LOG_I(F1AP, "tdd_num_available_freq_Bands = %d \n", tdd_num_available_freq_Bands);
-            AssertFatal(tdd_num_available_freq_Bands > 0, "should have at least one TDD band available\n");
-            int j;
-            for (j=0;
-                 j<tdd_num_available_freq_Bands;
-                 j++) {
-
-                  F1AP_FreqBandNrItem_t nr_freqBandNrItem;
-                  memset((void *)&nr_freqBandNrItem, 0, sizeof(F1AP_FreqBandNrItem_t));
-                  /* TDD.1.3.1 freqBandIndicatorNr*/
-                  nr_freqBandNrItem.freqBandIndicatorNr = *f1ap_du_data->nr_mode_info[i].tdd.nr_band; //
-
-                  /* TDD.1.3.2 supportedSULBandList*/
-                  int num_available_supported_SULBands = f1ap_du_data->nr_mode_info[i].tdd.num_sul_frequency_bands;
-                  LOG_D(F1AP, "num_available_supported_SULBands = %d \n", num_available_supported_SULBands);
-                  int k;
-                  for (k=0;
-                       k<num_available_supported_SULBands;
-                       k++) {
-                        F1AP_SupportedSULFreqBandItem_t nr_supportedSULFreqBandItem;
-                        memset((void *)&nr_supportedSULFreqBandItem, 0, sizeof(F1AP_SupportedSULFreqBandItem_t));
-                          /* TDD.1.3.2.1 freqBandIndicatorNr */
-                          nr_supportedSULFreqBandItem.freqBandIndicatorNr = *f1ap_du_data->nr_mode_info[i].tdd.nr_sul_band; //
-                        ASN_SEQUENCE_ADD(&nr_freqBandNrItem.supportedSULBandList.list, &nr_supportedSULFreqBandItem);
-                  } // for TDD : supported_SULBands
-                  ASN_SEQUENCE_ADD(&tDD_Info->nRFreqInfo.freqBandListNr.list, &nr_freqBandNrItem);
-            } // for TDD : freq_Bands
-
-          /* TDD.2 transmission_Bandwidth */
-          tDD_Info->transmission_Bandwidth.nRSCS = f1ap_du_data->nr_mode_info[i].tdd.scs;
-          tDD_Info->transmission_Bandwidth.nRNRB = to_NRNRB(f1ap_du_data->nr_mode_info[i].tdd.nrb);
-     
-          nR_Mode_Info.choice.tDD = tDD_Info;
-        } // if nR_Mode_Info
-        
-        served_cell_information.nR_Mode_Info = nR_Mode_Info;
-
-        /* - measurementTimingConfiguration */
-        char *measurementTimingConfiguration = f1ap_du_data->measurement_timing_information[i]; // sept. 2018
-
-        OCTET_STRING_fromBuf(&served_cell_information.measurementTimingConfiguration,
-                             measurementTimingConfiguration,
-                             strlen(measurementTimingConfiguration));
-        gnb_du_served_cells_item.served_Cell_Information = served_cell_information; //
-
-        /* 4.1.2 gNB-DU System Information */
-        F1AP_GNB_DU_System_Information_t *gNB_DU_System_Information = (F1AP_GNB_DU_System_Information_t *)calloc(1, sizeof(F1AP_GNB_DU_System_Information_t));
-
-        OCTET_STRING_fromBuf(&gNB_DU_System_Information->mIB_message,  // sept. 2018
-                             (const char*)f1ap_du_data->mib[i],//f1ap_du_data->mib,
-                             f1ap_du_data->mib_length[i]);
-
-        LOG_D(F1AP,"Filling SIB1_message for cell %d, length %d\n",i,f1ap_du_data->sib1_length[i]);
-        OCTET_STRING_fromBuf(&gNB_DU_System_Information->sIB1_message,  // sept. 2018
-                             (const char*)f1ap_du_data->sib1[i],
-                             f1ap_du_data->sib1_length[i]);
-
-        gnb_du_served_cells_item.gNB_DU_System_Information = gNB_DU_System_Information; //
-
-        /* ADD */
-        gnb_du_served_cell_list_item_ies->value.choice.GNB_DU_Served_Cells_Item = gnb_du_served_cells_item;
-
-        ASN_SEQUENCE_ADD(&ie->value.choice.GNB_DU_Served_Cells_List.list, 
-                        gnb_du_served_cell_list_item_ies);
 
+  for (int i=0; i<num_cells_available; i++) {
+    /* mandatory */
+    /* 4.1 served cells item */
+    cellIDs_t *cell=&f1ap_req(false, instance)->cell[i];
+    asn1cSequenceAdd(ieCells->value.choice.GNB_DU_Served_Cells_List.list,
+                     F1AP_GNB_DU_Served_Cells_ItemIEs_t, duServedCell);
+    duServedCell->id = F1AP_ProtocolIE_ID_id_GNB_DU_Served_Cells_Item;
+    duServedCell->criticality = F1AP_Criticality_reject;
+    duServedCell->value.present = F1AP_GNB_DU_Served_Cells_ItemIEs__value_PR_GNB_DU_Served_Cells_Item;
+    F1AP_GNB_DU_Served_Cells_Item_t  *gnb_du_served_cells_item=&duServedCell->value.choice.GNB_DU_Served_Cells_Item;
+    /* 4.1.1 served cell Information */
+    F1AP_Served_Cell_Information_t *served_cell_information= &gnb_du_served_cells_item->served_Cell_Information;
+    addnRCGI(served_cell_information->nRCGI,cell);
+    /* - nRPCI */
+    served_cell_information->nRPCI = cell->nr_pci;  // int 0..1007
+    /* - fiveGS_TAC */
+    uint32_t tac=htonl(cell->tac);
+    asn1cCalloc(served_cell_information->fiveGS_TAC, netOrder);
+    OCTET_STRING_fromBuf(netOrder, ((char *)&tac)+1, 3);
+
+    /* - Configured_EPS_TAC */
+    if(0) {
+      served_cell_information->configured_EPS_TAC = (F1AP_Configured_EPS_TAC_t *)calloc(1, sizeof(F1AP_Configured_EPS_TAC_t));
+      OCTET_STRING_fromBuf(served_cell_information->configured_EPS_TAC, "2", 2);
+    }
+
+    /* servedPLMN information */
+    asn1cSequenceAdd(served_cell_information->servedPLMNs.list, F1AP_ServedPLMNs_Item_t,servedPLMN_item);
+    MCC_MNC_TO_PLMNID(cell->mcc, cell->mnc, cell->mnc_digit_length, &servedPLMN_item->pLMN_Identity);
+    // // /* - CHOICE NR-MODE-Info */
+    F1AP_NR_Mode_Info_t *nR_Mode_Info= &served_cell_information->nR_Mode_Info;
+
+    if (f1ap_req(false, instance)->fdd_flag) { // FDD
+      nR_Mode_Info->present = F1AP_NR_Mode_Info_PR_fDD;
+      asn1cCalloc(nR_Mode_Info->choice.fDD, fDD_Info);
+      /* FDD.1 UL NRFreqInfo */
+      /* FDD.1.1 UL NRFreqInfo ARFCN */
+      fDD_Info->uL_NRFreqInfo.nRARFCN = f1ap_req(false,instance)->nr_mode_info[i].fdd.ul_nr_arfcn; // Integer
+
+      /* FDD.1.2 F1AP_SUL_Information */
+      if(0) { // Optional
+        asn1cCalloc(fDD_Info->uL_NRFreqInfo.sul_Information, fdd_sul_info);
+        fdd_sul_info->sUL_NRARFCN = 0;
+        fdd_sul_info->sUL_transmission_Bandwidth.nRSCS = 0;
+        fdd_sul_info->sUL_transmission_Bandwidth.nRNRB = 0;
+      }
+
+      /* FDD.1.3 freqBandListNr */
+      int fdd_ul_num_available_freq_Bands = f1ap_req(false,instance)->nr_mode_info[i].fdd.ul_num_frequency_bands;
+      LOG_D(F1AP, "fdd_ul_num_available_freq_Bands = %d \n", fdd_ul_num_available_freq_Bands);
+
+      for (int fdd_ul_j=0; fdd_ul_j<fdd_ul_num_available_freq_Bands; fdd_ul_j++) {
+        asn1cSequenceAdd(fDD_Info->uL_NRFreqInfo.freqBandListNr.list, F1AP_FreqBandNrItem_t, nr_freqBandNrItem);
+        /* FDD.1.3.1 freqBandIndicatorNr*/
+        nr_freqBandNrItem->freqBandIndicatorNr = f1ap_req(false,instance)->nr_mode_info[i].fdd.ul_nr_band[fdd_ul_j]; //
+        /* FDD.1.3.2 supportedSULBandList*/
+        int num_available_supported_SULBands = f1ap_req(false,instance)->nr_mode_info[i].fdd.ul_num_sul_frequency_bands;
+        LOG_D(F1AP, "num_available_supported_SULBands = %d \n", num_available_supported_SULBands);
+
+        for (int fdd_ul_k=0; fdd_ul_k<num_available_supported_SULBands; fdd_ul_k++) {
+          asn1cSequenceAdd(nr_freqBandNrItem->supportedSULBandList.list, F1AP_SupportedSULFreqBandItem_t, nr_supportedSULFreqBandItem);
+          /* FDD.1.3.2.1 freqBandIndicatorNr */
+          nr_supportedSULFreqBandItem->freqBandIndicatorNr = f1ap_req(false,instance)->nr_mode_info[i].fdd.ul_nr_sul_band[fdd_ul_k]; //
+        } // for FDD : UL supported_SULBands
+      } // for FDD : UL freq_Bands
+
+      /* FDD.2 DL NRFreqInfo */
+      /* FDD.2.1 DL NRFreqInfo ARFCN */
+      fDD_Info->dL_NRFreqInfo.nRARFCN = f1ap_req(false,instance)->nr_mode_info[i].fdd.dl_nr_arfcn; // Integer
+
+      /* FDD.2.2 F1AP_SUL_Information */
+      if(0) { // Optional
+        F1AP_SUL_Information_t *fdd_sul_info=fDD_Info->dL_NRFreqInfo.sul_Information;
+        fdd_sul_info->sUL_NRARFCN = 0;
+        fdd_sul_info->sUL_transmission_Bandwidth.nRSCS = 0;
+        fdd_sul_info->sUL_transmission_Bandwidth.nRNRB = 0;
+      }
+
+      /* FDD.2.3 freqBandListNr */
+      int fdd_dl_num_available_freq_Bands = f1ap_req(false,instance)->nr_mode_info[i].fdd.dl_num_frequency_bands;
+      LOG_D(F1AP, "fdd_dl_num_available_freq_Bands = %d \n", fdd_dl_num_available_freq_Bands);
+
+      for (int fdd_dl_j=0; fdd_dl_j<fdd_dl_num_available_freq_Bands; fdd_dl_j++) {
+        asn1cSequenceAdd(fDD_Info->dL_NRFreqInfo.freqBandListNr.list, F1AP_FreqBandNrItem_t, nr_freqBandNrItem);
+        /* FDD.2.3.1 freqBandIndicatorNr*/
+        nr_freqBandNrItem->freqBandIndicatorNr = f1ap_req(false,instance)->nr_mode_info[i].fdd.dl_nr_band[fdd_dl_j]; //
+        /* FDD.2.3.2 supportedSULBandList*/
+        int num_available_supported_SULBands = f1ap_req(false,instance)->nr_mode_info[i].fdd.dl_num_sul_frequency_bands;
+        LOG_D(F1AP, "num_available_supported_SULBands = %d \n", num_available_supported_SULBands);
+
+        for (int fdd_dl_k=0; fdd_dl_k<num_available_supported_SULBands; fdd_dl_k++) {
+          asn1cSequenceAdd(nr_freqBandNrItem->supportedSULBandList.list, F1AP_SupportedSULFreqBandItem_t, nr_supportedSULFreqBandItem);
+          /* FDD.2.3.2.1 freqBandIndicatorNr */
+          nr_supportedSULFreqBandItem->freqBandIndicatorNr = f1ap_req(false,instance)->nr_mode_info[i].fdd.dl_nr_sul_band[fdd_dl_k]; //
+        } // for FDD : DL supported_SULBands
+      } // for FDD : DL freq_Bands
+
+      /* FDD.3 UL Transmission Bandwidth */
+      fDD_Info->uL_Transmission_Bandwidth.nRSCS = f1ap_req(false,instance)->nr_mode_info[i].fdd.ul_scs;
+      fDD_Info->uL_Transmission_Bandwidth.nRNRB = to_NRNRB(f1ap_req(false,instance)->nr_mode_info[i].fdd.ul_nrb);
+      /* FDD.4 DL Transmission Bandwidth */
+      fDD_Info->dL_Transmission_Bandwidth.nRSCS = f1ap_req(false,instance)->nr_mode_info[i].fdd.dl_scs;
+      fDD_Info->dL_Transmission_Bandwidth.nRNRB = to_NRNRB(f1ap_req(false,instance)->nr_mode_info[i].fdd.dl_nrb);
+    } else { // TDD
+      nR_Mode_Info->present = F1AP_NR_Mode_Info_PR_tDD;
+      asn1cCalloc(nR_Mode_Info->choice.tDD, tDD_Info);
+      /* TDD.1 nRFreqInfo */
+      /* TDD.1.1 nRFreqInfo ARFCN */
+      tDD_Info->nRFreqInfo.nRARFCN = f1ap_req(false,instance)->nr_mode_info[i].tdd.nr_arfcn; // Integer
+
+      /* TDD.1.2 F1AP_SUL_Information */
+      if(0) { // Optional
+        F1AP_SUL_Information_t *tdd_sul_info= tDD_Info->nRFreqInfo.sul_Information;
+        tdd_sul_info->sUL_NRARFCN = 0;
+        tdd_sul_info->sUL_transmission_Bandwidth.nRSCS = 0;
+        tdd_sul_info->sUL_transmission_Bandwidth.nRNRB = 0;
+      }
+
+      /* TDD.1.3 freqBandListNr */
+      int tdd_num_available_freq_Bands = f1ap_req(false,instance)->nr_mode_info[i].tdd.num_frequency_bands;
+      LOG_D(F1AP, "tdd_num_available_freq_Bands = %d \n", tdd_num_available_freq_Bands);
+
+      for (int j=0; j<tdd_num_available_freq_Bands; j++) {
+        asn1cSequenceAdd(tDD_Info->nRFreqInfo.freqBandListNr.list, F1AP_FreqBandNrItem_t, nr_freqBandNrItem);
+        /* TDD.1.3.1 freqBandIndicatorNr*/
+        nr_freqBandNrItem->freqBandIndicatorNr = *f1ap_req(false,instance)->nr_mode_info[i].tdd.nr_band; //
+        /* TDD.1.3.2 supportedSULBandList*/
+        int num_available_supported_SULBands = f1ap_req(false,instance)->nr_mode_info[i].tdd.num_sul_frequency_bands;
+        LOG_D(F1AP, "num_available_supported_SULBands = %d \n", num_available_supported_SULBands);
+
+        for (int k=0; k<num_available_supported_SULBands; k++) {
+          asn1cSequenceAdd(nr_freqBandNrItem->supportedSULBandList.list,F1AP_SupportedSULFreqBandItem_t, nr_supportedSULFreqBandItem);
+          /* TDD.1.3.2.1 freqBandIndicatorNr */
+          nr_supportedSULFreqBandItem->freqBandIndicatorNr = *f1ap_req(false,instance)->nr_mode_info[i].tdd.nr_sul_band; //
+        } // for TDD : supported_SULBands
+      } // for TDD : freq_Bands
+
+      /* TDD.2 transmission_Bandwidth */
+      tDD_Info->transmission_Bandwidth.nRSCS = f1ap_req(false,instance)->nr_mode_info[i].tdd.scs;
+      tDD_Info->transmission_Bandwidth.nRNRB = to_NRNRB(f1ap_req(false,instance)->nr_mode_info[i].tdd.nrb);
+    } // if nR_Mode_Info
+
+    /* - measurementTimingConfiguration */
+    char *measurementTimingConfiguration = f1ap_req(false,instance)->measurement_timing_information[i]; // sept. 2018
+    OCTET_STRING_fromBuf(&served_cell_information->measurementTimingConfiguration,
+                         measurementTimingConfiguration,
+                         strlen(measurementTimingConfiguration));
+    asn1cCalloc(gnb_du_served_cells_item->gNB_DU_System_Information, gNB_DU_System_Information);
+    /* 4.1.2 gNB-DU System Information */
+    OCTET_STRING_fromBuf(&gNB_DU_System_Information->mIB_message,  // sept. 2018
+                         (const char *)f1ap_req(false,instance)->mib[i], //f1ap_du_data->mib,
+                         f1ap_req(false,instance)->mib_length[i]);
+    OCTET_STRING_fromBuf(&gNB_DU_System_Information->sIB1_message,  // sept. 2018
+                         (const char *)f1ap_req(false,instance)->sib1[i],
+                         f1ap_req(false,instance)->sib1_length[i]);
   }
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
 
   /* mandatory */
   /* c5. RRC VERSION */
-  if(RC.nrrrc) {
-    ie = (F1AP_F1SetupRequestIEs_t *) calloc(1, sizeof(F1AP_F1SetupRequestIEs_t));
-    ie->id = F1AP_ProtocolIE_ID_id_GNB_DU_RRC_Version;
-    ie->criticality = F1AP_Criticality_reject;
-    ie->value.present = F1AP_F1SetupRequestIEs__value_PR_RRC_Version;
-    ie->value.choice.RRC_Version.latest_RRC_Version.buf = calloc(1, sizeof(char));
-    ie->value.choice.RRC_Version.latest_RRC_Version.buf[0] = 0xe0;
-    ie->value.choice.RRC_Version.latest_RRC_Version.size = 1;
-    ie->value.choice.RRC_Version.latest_RRC_Version.bits_unused = 5;
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-  }
+  asn1cSequenceAdd(f1Setup->protocolIEs.list, F1AP_F1SetupRequestIEs_t, ie2);
+  ie2->id                        = F1AP_ProtocolIE_ID_id_GNB_DU_RRC_Version;
+  ie2->criticality               = F1AP_Criticality_reject;
+  ie2->value.present             = F1AP_F1SetupRequestIEs__value_PR_RRC_Version;
+  ie2->value.choice.RRC_Version.latest_RRC_Version.buf=calloc(1,sizeof(char));
+  ie2->value.choice.RRC_Version.latest_RRC_Version.buf[0] = 0xe0;
+  ie2->value.choice.RRC_Version.latest_RRC_Version.size = 1;
+  ie2->value.choice.RRC_Version.latest_RRC_Version.bits_unused = 5;
 
   /* encode */
   if (f1ap_encode_pdu(&pdu, &buffer, &len) < 0) {
@@ -433,161 +315,154 @@ int DU_send_F1_SETUP_REQUEST(instance_t instance) {
     return -1;
   }
 
-  MSC_LOG_TX_MESSAGE(
-  MSC_F1AP_DU,
-  MSC_F1AP_CU,
-  (const char *)buffer,
-  len,
-  MSC_AS_TIME_FMT" F1_SETUP_REQUEST initiatingMessage gNB_DU_name %s",
-  0,0,//MSC_AS_TIME_ARGS(ctxt_pP),
-  f1ap_du_data->gNB_DU_name);
-
-  du_f1ap_itti_send_sctp_data_req(instance, f1ap_du_data->assoc_id, buffer, len, 0);
-
+  ASN_STRUCT_RESET(asn_DEF_F1AP_F1AP_PDU, &pdu);
+  f1ap_itti_send_sctp_data_req(false, instance, buffer, len, 0);
   return 0;
 }
 
 int DU_handle_F1_SETUP_RESPONSE(instance_t instance,
-				uint32_t               assoc_id,
-				uint32_t               stream,
-				F1AP_F1AP_PDU_t       *pdu)
-{
-
+                                uint32_t               assoc_id,
+                                uint32_t               stream,
+                                F1AP_F1AP_PDU_t       *pdu) {
   LOG_D(F1AP, "DU_handle_F1_SETUP_RESPONSE\n");
-
   AssertFatal(pdu->present == F1AP_F1AP_PDU_PR_successfulOutcome,
-        "pdu->present != F1AP_F1AP_PDU_PR_successfulOutcome\n");
+              "pdu->present != F1AP_F1AP_PDU_PR_successfulOutcome\n");
   AssertFatal(pdu->choice.successfulOutcome->procedureCode  == F1AP_ProcedureCode_id_F1Setup,
-        "pdu->choice.successfulOutcome->procedureCode != F1AP_ProcedureCode_id_F1Setup\n");
+              "pdu->choice.successfulOutcome->procedureCode != F1AP_ProcedureCode_id_F1Setup\n");
   AssertFatal(pdu->choice.successfulOutcome->criticality  == F1AP_Criticality_reject,
-        "pdu->choice.successfulOutcome->criticality != F1AP_Criticality_reject\n");
+              "pdu->choice.successfulOutcome->criticality != F1AP_Criticality_reject\n");
   AssertFatal(pdu->choice.successfulOutcome->value.present  == F1AP_SuccessfulOutcome__value_PR_F1SetupResponse,
-        "pdu->choice.successfulOutcome->value.present != F1AP_SuccessfulOutcome__value_PR_F1SetupResponse\n");
-
+              "pdu->choice.successfulOutcome->value.present != F1AP_SuccessfulOutcome__value_PR_F1SetupResponse\n");
   F1AP_F1SetupResponse_t    *in = &pdu->choice.successfulOutcome->value.choice.F1SetupResponse;
-
-
   F1AP_F1SetupResponseIEs_t *ie;
   int TransactionId = -1;
   int num_cells_to_activate = 0;
   F1AP_Cells_to_be_Activated_List_Item_t *cell;
-
   MessageDef *msg_p = itti_alloc_new_message (TASK_DU_F1, 0, F1AP_SETUP_RESP);
-
   LOG_D(F1AP, "F1AP: F1Setup-Resp: protocolIEs.list.count %d\n",
         in->protocolIEs.list.count);
-  for (int i=0;i < in->protocolIEs.list.count; i++) {
+
+  for (int i=0; i < in->protocolIEs.list.count; i++) {
     ie = in->protocolIEs.list.array[i];
+
     switch (ie->id) {
       case F1AP_ProtocolIE_ID_id_TransactionID:
         AssertFatal(ie->criticality == F1AP_Criticality_reject,
-        "ie->criticality != F1AP_Criticality_reject\n");
+                    "ie->criticality != F1AP_Criticality_reject\n");
         AssertFatal(ie->value.present == F1AP_F1SetupResponseIEs__value_PR_TransactionID,
-        "ie->value.present != F1AP_F1SetupResponseIEs__value_PR_TransactionID\n");
+                    "ie->value.present != F1AP_F1SetupResponseIEs__value_PR_TransactionID\n");
         TransactionId=ie->value.choice.TransactionID;
         LOG_D(F1AP, "F1AP: F1Setup-Resp: TransactionId %d\n",
               TransactionId);
         break;
+
       case F1AP_ProtocolIE_ID_id_gNB_CU_Name:
         AssertFatal(ie->criticality == F1AP_Criticality_ignore,
-        "ie->criticality != F1AP_Criticality_ignore\n");
+                    "ie->criticality != F1AP_Criticality_ignore\n");
         AssertFatal(ie->value.present == F1AP_F1SetupResponseIEs__value_PR_GNB_CU_Name,
-        "ie->value.present != F1AP_F1SetupResponseIEs__value_PR_TransactionID\n");
+                    "ie->value.present != F1AP_F1SetupResponseIEs__value_PR_TransactionID\n");
         F1AP_SETUP_RESP (msg_p).gNB_CU_name = malloc(ie->value.choice.GNB_CU_Name.size+1);
         memcpy(F1AP_SETUP_RESP (msg_p).gNB_CU_name,ie->value.choice.GNB_CU_Name.buf,ie->value.choice.GNB_CU_Name.size);
         F1AP_SETUP_RESP (msg_p).gNB_CU_name[ie->value.choice.GNB_CU_Name.size]='\0';
         LOG_D(F1AP, "F1AP: F1Setup-Resp: gNB_CU_name %s\n",
               F1AP_SETUP_RESP (msg_p).gNB_CU_name);
         break;
+
       case F1AP_ProtocolIE_ID_id_GNB_CU_RRC_Version:
         LOG_D(F1AP, "F1AP: Received GNB-CU-RRC-Version, ignoring\n");
         break;
-      case F1AP_ProtocolIE_ID_id_Cells_to_be_Activated_List:
-      {
+
+      case F1AP_ProtocolIE_ID_id_Cells_to_be_Activated_List: {
         AssertFatal(ie->criticality == F1AP_Criticality_reject,
-          "ie->criticality != F1AP_Criticality_reject\n");
+                    "ie->criticality != F1AP_Criticality_reject\n");
         AssertFatal(ie->value.present == F1AP_F1SetupResponseIEs__value_PR_Cells_to_be_Activated_List,
-          "ie->value.present != F1AP_F1SetupResponseIEs__value_PR_Cells_to_be_Activated_List\n");
+                    "ie->value.present != F1AP_F1SetupResponseIEs__value_PR_Cells_to_be_Activated_List\n");
         num_cells_to_activate = ie->value.choice.Cells_to_be_Activated_List.list.count;
         LOG_D(F1AP, "F1AP: Activating %d cells\n",num_cells_to_activate);
-        for (int i=0;i<num_cells_to_activate;i++) {
 
+        for (int i=0; i<num_cells_to_activate; i++) {
           F1AP_Cells_to_be_Activated_List_ItemIEs_t *cells_to_be_activated_list_item_ies = (F1AP_Cells_to_be_Activated_List_ItemIEs_t *) ie->value.choice.Cells_to_be_Activated_List.list.array[i];
-
           AssertFatal(cells_to_be_activated_list_item_ies->id == F1AP_ProtocolIE_ID_id_Cells_to_be_Activated_List_Item,
-              "cells_to_be_activated_list_item_ies->id != F1AP_ProtocolIE_ID_id_Cells_to_be_Activated_List_Item");
+                      "cells_to_be_activated_list_item_ies->id != F1AP_ProtocolIE_ID_id_Cells_to_be_Activated_List_Item");
           AssertFatal(cells_to_be_activated_list_item_ies->criticality == F1AP_Criticality_reject,
-                "cells_to_be_activated_list_item_ies->criticality == F1AP_Criticality_reject");
+                      "cells_to_be_activated_list_item_ies->criticality == F1AP_Criticality_reject");
           AssertFatal(cells_to_be_activated_list_item_ies->value.present == F1AP_Cells_to_be_Activated_List_ItemIEs__value_PR_Cells_to_be_Activated_List_Item,
-                "cells_to_be_activated_list_item_ies->value.present == F1AP_Cells_to_be_Activated_List_ItemIEs__value_PR_Cells_to_be_Activated_List_Item");
-
+                      "cells_to_be_activated_list_item_ies->value.present == F1AP_Cells_to_be_Activated_List_ItemIEs__value_PR_Cells_to_be_Activated_List_Item");
           cell = &cells_to_be_activated_list_item_ies->value.choice.Cells_to_be_Activated_List_Item;
-
-          TBCD_TO_MCC_MNC(&cell->nRCGI.pLMN_Identity, F1AP_SETUP_RESP (msg_p).cells_to_activate[i].mcc, F1AP_SETUP_RESP (msg_p).cells_to_activate[i].mnc, F1AP_SETUP_RESP (msg_p).cells_to_activate[i].mnc_digit_length);
-
+          TBCD_TO_MCC_MNC(&cell->nRCGI.pLMN_Identity, F1AP_SETUP_RESP (msg_p).cells_to_activate[i].mcc, F1AP_SETUP_RESP (msg_p).cells_to_activate[i].mnc,
+                          F1AP_SETUP_RESP (msg_p).cells_to_activate[i].mnc_digit_length);
           LOG_D(F1AP, "nr_cellId : %x %x %x %x %x\n",
                 cell->nRCGI.nRCellIdentity.buf[0],
                 cell->nRCGI.nRCellIdentity.buf[1],
                 cell->nRCGI.nRCellIdentity.buf[2],
                 cell->nRCGI.nRCellIdentity.buf[3],
                 cell->nRCGI.nRCellIdentity.buf[4]);
-
           BIT_STRING_TO_NR_CELL_IDENTITY(&cell->nRCGI.nRCellIdentity,
-          F1AP_SETUP_RESP (msg_p).cells_to_activate[i].nr_cellid);
+                                         F1AP_SETUP_RESP (msg_p).cells_to_activate[i].nr_cellid);
           F1AP_ProtocolExtensionContainer_154P112_t *ext = (F1AP_ProtocolExtensionContainer_154P112_t *)cell->iE_Extensions;
 
-          if (ext==NULL) continue;
+          if (ext==NULL)
+            continue;
 
-          for (int cnt=0;cnt<ext->list.count;cnt++) {
+          for (int cnt=0; cnt<ext->list.count; cnt++) {
             F1AP_Cells_to_be_Activated_List_ItemExtIEs_t *cells_to_be_activated_list_itemExtIEs=(F1AP_Cells_to_be_Activated_List_ItemExtIEs_t *)ext->list.array[cnt];
+
             switch (cells_to_be_activated_list_itemExtIEs->id) {
-  /*
-                case F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_NOTHING:
-                case F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_GNB_CUSystemInformation,
-                case F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_AvailablePLMNList,
-                case F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_ExtendedAvailablePLMN_List,
-                case F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_IAB_Info_IAB_donor_CU,
-                case F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_AvailableSNPN_ID_List
-  */
-              case F1AP_ProtocolIE_ID_id_gNB_CUSystemInformation:
-              {
+              /*
+                            case F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_NOTHING:
+                            case F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_GNB_CUSystemInformation,
+                            case F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_AvailablePLMNList,
+                            case F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_ExtendedAvailablePLMN_List,
+                            case F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_IAB_Info_IAB_donor_CU,
+                            case F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_AvailableSNPN_ID_List
+              */
+              case F1AP_ProtocolIE_ID_id_gNB_CUSystemInformation: {
                 F1AP_SETUP_RESP (msg_p).cells_to_activate[i].nrpci = (cell->nRPCI != NULL) ? *cell->nRPCI : 0;
-                F1AP_GNB_CUSystemInformation_t *gNB_CUSystemInformation = (F1AP_GNB_CUSystemInformation_t*)&cells_to_be_activated_list_itemExtIEs->extensionValue.choice.GNB_CUSystemInformation;
+                F1AP_GNB_CUSystemInformation_t *gNB_CUSystemInformation = (F1AP_GNB_CUSystemInformation_t *)&cells_to_be_activated_list_itemExtIEs->extensionValue.choice.GNB_CUSystemInformation;
                 F1AP_SETUP_RESP (msg_p).cells_to_activate[i].num_SI = gNB_CUSystemInformation->sibtypetobeupdatedlist.list.count;
                 AssertFatal(ext->list.count==1,"At least one SI message should be there, and only 1 for now!\n");
                 LOG_D(F1AP, "F1AP: Cell %d MCC %d MNC %d NRCellid %lx num_si %d\n",
                       i, F1AP_SETUP_RESP (msg_p).cells_to_activate[i].mcc, F1AP_SETUP_RESP (msg_p).cells_to_activate[i].mnc,
                       F1AP_SETUP_RESP (msg_p).cells_to_activate[i].nr_cellid, F1AP_SETUP_RESP (msg_p).cells_to_activate[i].num_SI);
-                for (int si = 0;si < gNB_CUSystemInformation->sibtypetobeupdatedlist.list.count;si++) {
+
+                for (int si = 0; si < gNB_CUSystemInformation->sibtypetobeupdatedlist.list.count; si++) {
                   F1AP_SibtypetobeupdatedListItem_t *sib_item = gNB_CUSystemInformation->sibtypetobeupdatedlist.list.array[si];
                   size_t size = sib_item->sIBmessage.size;
-                  F1AP_SETUP_RESP (msg_p).cells_to_activate[i].SI_container_length[sib_item->sIBtype] = size;
-                  LOG_I(F1AP, "F1AP: SI_container_length[%d][%d] %ld bytes\n", i, (int)sib_item->sIBtype, size);
-                  F1AP_SETUP_RESP (msg_p).cells_to_activate[i].SI_container[sib_item->sIBtype] = malloc(size);
-                  memcpy((void*)F1AP_SETUP_RESP (msg_p).cells_to_activate[i].SI_container[sib_item->sIBtype],
-                          (void*)sib_item->sIBmessage.buf,
-                          size);
+                  F1AP_SETUP_RESP (msg_p).cells_to_activate[i].SI_container_length[si] = size;
+                  LOG_D(F1AP, "F1AP: SI_container_length[%d][%ld] %ld bytes\n", i, sib_item->sIBtype, size);
+                  F1AP_SETUP_RESP (msg_p).cells_to_activate[i].SI_container[si] = malloc(F1AP_SETUP_RESP (msg_p).cells_to_activate[i].SI_container_length[si]);
+                  memcpy((void *)F1AP_SETUP_RESP (msg_p).cells_to_activate[i].SI_container[si],
+                         (void *)sib_item->sIBmessage.buf,
+                         size);
+                  F1AP_SETUP_RESP (msg_p).cells_to_activate[i].SI_type[si]=sib_item->sIBtype;
                 }
+
                 break;
               }
+
               case F1AP_ProtocolIE_ID_id_AvailablePLMNList:
                 AssertFatal(1==0,"F1AP_ProtocolIE_ID_id_AvailablePLMNList not supported yet\n");
                 break;
+
               case F1AP_ProtocolIE_ID_id_ExtendedAvailablePLMN_List:
                 AssertFatal(1==0,"F1AP_ProtocolIE_ID_id_AvailablePLMNList not supported yet\n");
                 break;
+
               case F1AP_ProtocolIE_ID_id_IAB_Info_IAB_donor_CU:
                 AssertFatal(1==0,"F1AP_ProtocolIE_ID_id_AvailablePLMNList not supported yet\n");
                 break;
+
               case F1AP_ProtocolIE_ID_id_AvailableSNPN_ID_List:
                 AssertFatal(1==0,"F1AP_ProtocolIE_ID_id_AvailablePLMNList not supported yet\n");
                 break;
+
               default:
                 AssertFatal(1==0,"F1AP_ProtocolIE_ID_id %d unknown\n",(int)cells_to_be_activated_list_itemExtIEs->id);
                 break;
             }
           } // for (cnt=...
         } // for (cells_to_activate...
+
         break;
       } // case F1AP_ProtocolIE_ID_id_Cells_to_be_Activated_List
 
@@ -596,31 +471,26 @@ int DU_handle_F1_SETUP_RESPONSE(instance_t instance,
         break;
     } // switch ie
   } // for IE
+
   AssertFatal(TransactionId!=-1,"TransactionId was not sent\n");
+  LOG_D(F1AP,"F1AP: num_cells_to_activate %d\n",num_cells_to_activate);
   F1AP_SETUP_RESP (msg_p).num_cells_to_activate = num_cells_to_activate;
 
-  for (int i=0;i<num_cells_to_activate;i++)
+  // tmp
+  // F1AP_SETUP_RESP (msg_p).num_SI[0] = 1;
+  for (int i=0; i<num_cells_to_activate; i++)
     AssertFatal(F1AP_SETUP_RESP (msg_p).cells_to_activate[i].num_SI > 0, "System Information %d is missing",i);
 
   MSC_LOG_RX_MESSAGE(
-  MSC_F1AP_DU,
-  MSC_F1AP_CU,
-  0,
-  0,
-  MSC_AS_TIME_FMT" DU_handle_F1_SETUP_RESPONSE successfulOutcome assoc_id %d",
-  0,0,//MSC_AS_TIME_ARGS(ctxt_pP),
-  assoc_id);
-
-  if (RC.nrrrc && RC.nrrrc[0]->node_type == ngran_gNB_DU) {
-    LOG_D(F1AP, "Sending F1AP_SETUP_RESP ITTI message to GNB_APP with assoc_id (%d->%d)\n",
-         assoc_id,ENB_MODULE_ID_TO_INSTANCE(assoc_id));
-    itti_send_msg_to_task(TASK_GNB_APP, GNB_MODULE_ID_TO_INSTANCE(assoc_id), msg_p);
-  } else {
-    LOG_D(F1AP, "Sending F1AP_SETUP_RESP ITTI message to ENB_APP with assoc_id (%d->%d)\n",
-         assoc_id,ENB_MODULE_ID_TO_INSTANCE(assoc_id));
-    itti_send_msg_to_task(TASK_ENB_APP, instance, msg_p);
-  }
-
+    MSC_F1AP_DU,
+    MSC_F1AP_CU,
+    0,
+    0,
+    MSC_AS_TIME_FMT" DU_handle_F1_SETUP_RESPONSE successfulOutcome assoc_id %d",
+    0,0,//MSC_AS_TIME_ARGS(ctxt_pP),
+    assoc_id);
+  LOG_D(F1AP, "Sending F1AP_SETUP_RESP ITTI message\n");
+  itti_send_msg_to_task(TASK_F1APP, GNB_MODULE_ID_TO_INSTANCE(assoc_id), msg_p);
   return 0;
 }
 
@@ -630,24 +500,20 @@ int DU_handle_F1_SETUP_FAILURE(instance_t instance,
                                uint32_t stream,
                                F1AP_F1AP_PDU_t *pdu) {
   LOG_E(F1AP, "DU_handle_F1_SETUP_FAILURE\n");
-
   F1AP_F1SetupFailure_t    *out;
   F1AP_F1SetupFailureIEs_t *ie;
-
   out = &pdu->choice.unsuccessfulOutcome->value.choice.F1SetupFailure;
-
   /* Transaction ID */
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_F1SetupFailureIEs_t, ie, out,
-                              F1AP_ProtocolIE_ID_id_TransactionID, true);
-
+                             F1AP_ProtocolIE_ID_id_TransactionID, true);
   /* Cause */
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_F1SetupFailureIEs_t, ie, out,
-                              F1AP_ProtocolIE_ID_id_Cause, true);
+                             F1AP_ProtocolIE_ID_id_Cause, true);
 
   if(0) {
     /* TimeToWait */
     F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_F1SetupFailureIEs_t, ie, out,
-                              F1AP_ProtocolIE_ID_id_TimeToWait, true);
+                               F1AP_ProtocolIE_ID_id_TimeToWait, true);
   }
 
   return 0;
@@ -660,495 +526,306 @@ int DU_handle_F1_SETUP_FAILURE(instance_t instance,
 
 //void DU_send_gNB_DU_CONFIGURATION_UPDATE(F1AP_GNBDUConfigurationUpdate_t *GNBDUConfigurationUpdate) {
 int DU_send_gNB_DU_CONFIGURATION_UPDATE(instance_t instance,
-                                         instance_t du_mod_idP,
-                                         f1ap_setup_req_t *f1ap_setup_req) {
-  F1AP_F1AP_PDU_t                     pdu;
-  F1AP_GNBDUConfigurationUpdate_t     *out;
-  F1AP_GNBDUConfigurationUpdateIEs_t  *ie;
-
-  uint8_t  *buffer;
-  uint32_t  len;
-  int       i = 0;
-  int       j = 0;
-
+                                        instance_t du_mod_idP,
+                                        f1ap_setup_req_t *f1ap_setup_req) {
+  F1AP_F1AP_PDU_t                     pdu= {0};
+  uint8_t  *buffer=NULL;
+  uint32_t  len=0;
   /* Create */
   /* 0. Message Type */
-  memset(&pdu, 0, sizeof(pdu));
   pdu.present = F1AP_F1AP_PDU_PR_initiatingMessage;
-  pdu.choice.initiatingMessage = (F1AP_InitiatingMessage_t *)calloc(1, sizeof(F1AP_InitiatingMessage_t));
-  pdu.choice.initiatingMessage->procedureCode = F1AP_ProcedureCode_id_gNBDUConfigurationUpdate;
-  pdu.choice.initiatingMessage->criticality   = F1AP_Criticality_reject;
-  pdu.choice.initiatingMessage->value.present = F1AP_InitiatingMessage__value_PR_GNBDUConfigurationUpdate;
-  out = &pdu.choice.initiatingMessage->value.choice.GNBDUConfigurationUpdate;
-
+  asn1cCalloc(pdu.choice.initiatingMessage, initMsg);
+  initMsg->procedureCode = F1AP_ProcedureCode_id_gNBDUConfigurationUpdate;
+  initMsg->criticality   = F1AP_Criticality_reject;
+  initMsg->value.present = F1AP_InitiatingMessage__value_PR_GNBDUConfigurationUpdate;
+  F1AP_GNBDUConfigurationUpdate_t      *out = &pdu.choice.initiatingMessage->value.choice.GNBDUConfigurationUpdate;
   /* mandatory */
   /* c1. Transaction ID (integer value) */
-  ie = (F1AP_GNBDUConfigurationUpdateIEs_t *)calloc(1, sizeof(F1AP_GNBDUConfigurationUpdateIEs_t));
-  ie->id                        = F1AP_ProtocolIE_ID_id_TransactionID;
-  ie->criticality               = F1AP_Criticality_reject;
-  ie->value.present             = F1AP_GNBDUConfigurationUpdateIEs__value_PR_TransactionID;
-  ie->value.choice.TransactionID = F1AP_get_next_transaction_identifier(instance, du_mod_idP);
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
-
+  asn1cSequenceAdd(out, F1AP_GNBDUConfigurationUpdateIEs_t, ie1);
+  ie1->id                        = F1AP_ProtocolIE_ID_id_TransactionID;
+  ie1->criticality               = F1AP_Criticality_reject;
+  ie1->value.present             = F1AP_GNBDUConfigurationUpdateIEs__value_PR_TransactionID;
+  ie1->value.choice.TransactionID = F1AP_get_next_transaction_identifier(instance, du_mod_idP);
   /* mandatory */
   /* c2. Served_Cells_To_Add */
-  ie = (F1AP_GNBDUConfigurationUpdateIEs_t *)calloc(1, sizeof(F1AP_GNBDUConfigurationUpdateIEs_t));
-  ie->id                        = F1AP_ProtocolIE_ID_id_Served_Cells_To_Add_List;
-  ie->criticality               = F1AP_Criticality_reject;
-  ie->value.present             = F1AP_GNBDUConfigurationUpdateIEs__value_PR_Served_Cells_To_Add_List;
-
-  for (j=0;
-       j<1;
-       j++) {
-        //
-        F1AP_Served_Cells_To_Add_ItemIEs_t *served_cells_to_add_item_ies;
-        served_cells_to_add_item_ies = (F1AP_Served_Cells_To_Add_ItemIEs_t *)calloc(1, sizeof(F1AP_Served_Cells_To_Add_ItemIEs_t));
-        served_cells_to_add_item_ies->id            = F1AP_ProtocolIE_ID_id_Served_Cells_To_Add_Item;
-        served_cells_to_add_item_ies->criticality   = F1AP_Criticality_reject;
-        served_cells_to_add_item_ies->value.present = F1AP_Served_Cells_To_Add_ItemIEs__value_PR_Served_Cells_To_Add_Item;
-        
-        F1AP_Served_Cells_To_Add_Item_t served_cells_to_add_item;
-        memset((void *)&served_cells_to_add_item, 0, sizeof(F1AP_Served_Cells_To_Add_Item_t));
-
-        /* 2.1.1 serverd cell Information */
-        F1AP_Served_Cell_Information_t served_cell_information;
-
-        memset((void *)&served_cell_information, 0, sizeof(F1AP_Served_Cell_Information_t));
-        /* - nRCGI */
-        F1AP_NRCGI_t nRCGI;
-        memset(&nRCGI, 0, sizeof(F1AP_NRCGI_t));
-        MCC_MNC_TO_PLMNID(f1ap_setup_req->mcc[i], f1ap_setup_req->mnc[i], f1ap_setup_req->mnc_digit_length[i], &nRCGI.pLMN_Identity);
-        LOG_D(F1AP, "nr_cellId : %x %x %x %x %x\n",
-              nRCGI.nRCellIdentity.buf[0],
-              nRCGI.nRCellIdentity.buf[1],
-              nRCGI.nRCellIdentity.buf[2],
-              nRCGI.nRCellIdentity.buf[3],
-              nRCGI.nRCellIdentity.buf[4]);
-        NR_CELL_ID_TO_BIT_STRING(f1ap_setup_req->nr_cellid[i], &nRCGI.nRCellIdentity);
-        served_cell_information.nRCGI = nRCGI;
-
-        /* - nRPCI */
-        served_cell_information.nRPCI = f1ap_setup_req->nr_pci[i];  // int 0..1007
-
-        /* - fiveGS_TAC */
-        if (RC.nrrrc) {
-          uint8_t fiveGS_TAC[3];
-          fiveGS_TAC[0] = ((uint8_t*)&f1ap_setup_req->tac[i])[2];
-          fiveGS_TAC[1] = ((uint8_t*)&f1ap_setup_req->tac[i])[1];
-          fiveGS_TAC[2] = ((uint8_t*)&f1ap_setup_req->tac[i])[0];
-          OCTET_STRING_fromBuf(served_cell_information.fiveGS_TAC,
-                               (const char *)fiveGS_TAC,
-                               3);
-        } else {
-          OCTET_STRING_fromBuf(served_cell_information.fiveGS_TAC,
-                               (const char *) &f1ap_setup_req->tac[i],
-                               3);
-        }
-
-        /* - Configured_EPS_TAC */
-        if(1){
-          served_cell_information.configured_EPS_TAC = (F1AP_Configured_EPS_TAC_t *)calloc(1, sizeof(F1AP_Configured_EPS_TAC_t));
-          OCTET_STRING_fromBuf(served_cell_information.configured_EPS_TAC,
-                             "2",
-                             2);
-        }
-
-        F1AP_ServedPLMNs_Item_t *servedPLMN_item = calloc(1,sizeof(*servedPLMN_item));
-        memset(servedPLMN_item,0,sizeof(*servedPLMN_item));
-        MCC_MNC_TO_PLMNID(f1ap_du_data->mcc[i], f1ap_du_data->mnc[i], f1ap_du_data->mnc_digit_length[i], &servedPLMN_item->pLMN_Identity);
-        ASN_SEQUENCE_ADD(&served_cell_information.servedPLMNs.list, servedPLMN_item);
-
-        // // /* - CHOICE NR-MODE-Info */
-        F1AP_NR_Mode_Info_t nR_Mode_Info;
-
-        if (f1ap_setup_req->fdd_flag) {
-          nR_Mode_Info.present = F1AP_NR_Mode_Info_PR_fDD;
-          /* > FDD >> FDD Info */
-          F1AP_FDD_Info_t *fDD_Info = (F1AP_FDD_Info_t *)calloc(1, sizeof(F1AP_FDD_Info_t));
-          /* >>> UL NRFreqInfo */
-          fDD_Info->uL_NRFreqInfo.nRARFCN = 999L;
-
-          F1AP_FreqBandNrItem_t ul_freqBandNrItem;
-          memset((void *)&ul_freqBandNrItem, 0, sizeof(F1AP_FreqBandNrItem_t));
-          ul_freqBandNrItem.freqBandIndicatorNr = 888L;
-
-            F1AP_SupportedSULFreqBandItem_t ul_supportedSULFreqBandItem;
-            memset((void *)&ul_supportedSULFreqBandItem, 0, sizeof(F1AP_SupportedSULFreqBandItem_t));
-            ul_supportedSULFreqBandItem.freqBandIndicatorNr = 777L;
-            ASN_SEQUENCE_ADD(&ul_freqBandNrItem.supportedSULBandList.list, &ul_supportedSULFreqBandItem);
-
-          ASN_SEQUENCE_ADD(&fDD_Info->uL_NRFreqInfo.freqBandListNr.list, &ul_freqBandNrItem);
-
-          /* >>> DL NRFreqInfo */
-          fDD_Info->dL_NRFreqInfo.nRARFCN = 666L;
-
-          F1AP_FreqBandNrItem_t dl_freqBandNrItem;
-          memset((void *)&dl_freqBandNrItem, 0, sizeof(F1AP_FreqBandNrItem_t));
-          dl_freqBandNrItem.freqBandIndicatorNr = 555L;
-
-            F1AP_SupportedSULFreqBandItem_t dl_supportedSULFreqBandItem;
-            memset((void *)&dl_supportedSULFreqBandItem, 0, sizeof(F1AP_SupportedSULFreqBandItem_t));
-            dl_supportedSULFreqBandItem.freqBandIndicatorNr = 444L;
-            ASN_SEQUENCE_ADD(&dl_freqBandNrItem.supportedSULBandList.list, &dl_supportedSULFreqBandItem);
-
-          ASN_SEQUENCE_ADD(&fDD_Info->dL_NRFreqInfo.freqBandListNr.list, &dl_freqBandNrItem);
-
-          /* >>> UL Transmission Bandwidth */
-          fDD_Info->uL_Transmission_Bandwidth.nRSCS = F1AP_NRSCS_scs15;
-          fDD_Info->uL_Transmission_Bandwidth.nRNRB = F1AP_NRNRB_nrb11;
-          /* >>> DL Transmission Bandwidth */
-          fDD_Info->dL_Transmission_Bandwidth.nRSCS = F1AP_NRSCS_scs15;
-          fDD_Info->dL_Transmission_Bandwidth.nRNRB = F1AP_NRNRB_nrb11;
-          
-          nR_Mode_Info.choice.fDD = fDD_Info;
-        } else { // TDD
-          nR_Mode_Info.present = F1AP_NR_Mode_Info_PR_tDD;
-
-          /* > TDD >> TDD Info */
-          F1AP_TDD_Info_t *tDD_Info = (F1AP_TDD_Info_t *)calloc(1, sizeof(F1AP_TDD_Info_t));
-          /* >>> ARFCN */
-          tDD_Info->nRFreqInfo.nRARFCN = 999L; // Integer
-          F1AP_FreqBandNrItem_t nr_freqBandNrItem;
-          memset((void *)&nr_freqBandNrItem, 0, sizeof(F1AP_FreqBandNrItem_t));
-          nr_freqBandNrItem.freqBandIndicatorNr = 555L;
-
-            F1AP_SupportedSULFreqBandItem_t nr_supportedSULFreqBandItem;
-            memset((void *)&nr_supportedSULFreqBandItem, 0, sizeof(F1AP_SupportedSULFreqBandItem_t));
-            nr_supportedSULFreqBandItem.freqBandIndicatorNr = 444L;
-            ASN_SEQUENCE_ADD(&nr_freqBandNrItem.supportedSULBandList.list, &nr_supportedSULFreqBandItem);
-
-          ASN_SEQUENCE_ADD(&tDD_Info->nRFreqInfo.freqBandListNr.list, &nr_freqBandNrItem);
-
-          tDD_Info->transmission_Bandwidth.nRSCS= F1AP_NRSCS_scs15;
-          tDD_Info->transmission_Bandwidth.nRNRB= F1AP_NRNRB_nrb11;
-     
-          nR_Mode_Info.choice.tDD = tDD_Info;
-        } 
-        
-        served_cell_information.nR_Mode_Info = nR_Mode_Info;
-
-        /* - measurementTimingConfiguration */
-        char *measurementTimingConfiguration = "0"; // sept. 2018
-
-        OCTET_STRING_fromBuf(&served_cell_information.measurementTimingConfiguration,
-                             measurementTimingConfiguration,
-                             strlen(measurementTimingConfiguration));
-        served_cells_to_add_item.served_Cell_Information = served_cell_information; //
-
-        /* 2.1.2 gNB-DU System Information */
-        F1AP_GNB_DU_System_Information_t *gNB_DU_System_Information = (F1AP_GNB_DU_System_Information_t *)calloc(1, sizeof(F1AP_GNB_DU_System_Information_t));
-
-        OCTET_STRING_fromBuf(&gNB_DU_System_Information->mIB_message,  // sept. 2018
-                             "1",
-                             sizeof("1"));
-
-        OCTET_STRING_fromBuf(&gNB_DU_System_Information->sIB1_message,  // sept. 2018
-                             "1",
-                             sizeof("1"));
-        served_cells_to_add_item.gNB_DU_System_Information = gNB_DU_System_Information; //
-
-        /* ADD */
-        served_cells_to_add_item_ies->value.choice.Served_Cells_To_Add_Item = served_cells_to_add_item;
-
-        ASN_SEQUENCE_ADD(&ie->value.choice.Served_Cells_To_Add_List.list, 
-                        served_cells_to_add_item_ies);
-
+  asn1cSequenceAdd(out, F1AP_GNBDUConfigurationUpdateIEs_t, ie2);
+  ie2->id                        = F1AP_ProtocolIE_ID_id_Served_Cells_To_Add_List;
+  ie2->criticality               = F1AP_Criticality_reject;
+  ie2->value.present             = F1AP_GNBDUConfigurationUpdateIEs__value_PR_Served_Cells_To_Add_List;
+
+  for (int j=0;   j<1; j++) {
+    //
+    asn1cSequenceAdd(ie2->value.choice.Served_Cells_To_Add_List.list, F1AP_Served_Cells_To_Add_ItemIEs_t, served_cells_to_add_item_ies);
+    served_cells_to_add_item_ies->id            = F1AP_ProtocolIE_ID_id_Served_Cells_To_Add_Item;
+    served_cells_to_add_item_ies->criticality   = F1AP_Criticality_reject;
+    served_cells_to_add_item_ies->value.present = F1AP_Served_Cells_To_Add_ItemIEs__value_PR_Served_Cells_To_Add_Item;
+    F1AP_Served_Cells_To_Add_Item_t *served_cells_to_add_item= &served_cells_to_add_item_ies->value.choice.Served_Cells_To_Add_Item;
+    F1AP_Served_Cell_Information_t  *served_cell_information=&served_cells_to_add_item->served_Cell_Information;
+    /* - nRCGI */
+    addnRCGI(served_cell_information->nRCGI, &f1ap_setup_req->cell[j]);
+    /* - nRPCI */
+    /* 2.1.1 serverd cell Information */
+    cellIDs_t *cell=&f1ap_req(false, instance)->cell[j];
+    served_cell_information->nRPCI = cell->nr_pci;  // int 0..1007
+    /* - fiveGS_TAC */
+    uint32_t tac=htonl(cell->tac);
+    served_cell_information->fiveGS_TAC=(F1AP_FiveGS_TAC_t *) calloc(1,sizeof(F1AP_FiveGS_TAC_t *));
+    OCTET_STRING_fromBuf(served_cell_information->fiveGS_TAC, ((char *)&tac)+1, 3);
+
+    /* - Configured_EPS_TAC */
+    if(1) {
+      served_cell_information->configured_EPS_TAC = (F1AP_Configured_EPS_TAC_t *)calloc(1, sizeof(F1AP_Configured_EPS_TAC_t));
+      OCTET_STRING_fromBuf(served_cell_information->configured_EPS_TAC,"2", 2);
+    }
+
+    asn1cSequenceAdd(served_cell_information->servedPLMNs.list, F1AP_ServedPLMNs_Item_t, servedPLMN_item);
+    MCC_MNC_TO_PLMNID(cell->mcc, cell->mnc, cell->mnc_digit_length, &servedPLMN_item->pLMN_Identity);
+    // // /* - CHOICE NR-MODE-Info */
+    F1AP_NR_Mode_Info_t *nR_Mode_Info=&served_cell_information->nR_Mode_Info;
+    LOG_E(F1AP,"Here hardcoded values instead of values from configuration file\n");
+
+    if (f1ap_setup_req->fdd_flag) {
+      nR_Mode_Info->present = F1AP_NR_Mode_Info_PR_fDD;
+      /* > FDD >> FDD Info */
+      asn1cCalloc(nR_Mode_Info->choice.fDD, fDD_Info);
+      /* >>> UL NRFreqInfo */
+      fDD_Info->uL_NRFreqInfo.nRARFCN = 999L;
+      asn1cSequenceAdd(fDD_Info->uL_NRFreqInfo.freqBandListNr.list, F1AP_FreqBandNrItem_t, ul_freqBandNrItem);
+      ul_freqBandNrItem->freqBandIndicatorNr = 888L;
+      asn1cSequenceAdd(ul_freqBandNrItem->supportedSULBandList.list, F1AP_SupportedSULFreqBandItem_t, ul_supportedSULFreqBandItem);
+      ul_supportedSULFreqBandItem->freqBandIndicatorNr = 777L;
+      /* >>> DL NRFreqInfo */
+      fDD_Info->dL_NRFreqInfo.nRARFCN = 666L;
+      asn1cSequenceAdd(fDD_Info->dL_NRFreqInfo.freqBandListNr.list, F1AP_FreqBandNrItem_t, dl_freqBandNrItem);
+      dl_freqBandNrItem->freqBandIndicatorNr = 555L;
+      asn1cSequenceAdd(dl_freqBandNrItem->supportedSULBandList.list, F1AP_SupportedSULFreqBandItem_t, dl_supportedSULFreqBandItem);
+      dl_supportedSULFreqBandItem->freqBandIndicatorNr = 444L;
+      /* >>> UL Transmission Bandwidth */
+      fDD_Info->uL_Transmission_Bandwidth.nRSCS = F1AP_NRSCS_scs15;
+      fDD_Info->uL_Transmission_Bandwidth.nRNRB = F1AP_NRNRB_nrb11;
+      /* >>> DL Transmission Bandwidth */
+      fDD_Info->dL_Transmission_Bandwidth.nRSCS = F1AP_NRSCS_scs15;
+      fDD_Info->dL_Transmission_Bandwidth.nRNRB = F1AP_NRNRB_nrb11;
+    } else { // TDD
+      nR_Mode_Info->present = F1AP_NR_Mode_Info_PR_tDD;
+      /* > TDD >> TDD Info */
+      asn1cCalloc(nR_Mode_Info->choice.tDD, tDD_Info);
+      /* >>> ARFCN */
+      tDD_Info->nRFreqInfo.nRARFCN = 999L; // Integer
+      asn1cSequenceAdd(tDD_Info->nRFreqInfo.freqBandListNr.list, F1AP_FreqBandNrItem_t, nr_freqBandNrItem);
+      nr_freqBandNrItem->freqBandIndicatorNr = 555L;
+      asn1cSequenceAdd(nr_freqBandNrItem->supportedSULBandList.list, F1AP_SupportedSULFreqBandItem_t, nr_supportedSULFreqBandItem);
+      nr_supportedSULFreqBandItem->freqBandIndicatorNr = 444L;
+      tDD_Info->transmission_Bandwidth.nRSCS= F1AP_NRSCS_scs15;
+      tDD_Info->transmission_Bandwidth.nRNRB= F1AP_NRNRB_nrb11;
+    }
+
+    /* - measurementTimingConfiguration */
+    char *measurementTimingConfiguration = "0"; // sept. 2018
+    OCTET_STRING_fromBuf(&served_cell_information->measurementTimingConfiguration,
+                         measurementTimingConfiguration,
+                         strlen(measurementTimingConfiguration));
+    /* 2.1.2 gNB-DU System Information */
+    asn1cCalloc(served_cells_to_add_item->gNB_DU_System_Information, gNB_DU_System_Information);
+    OCTET_STRING_fromBuf(&gNB_DU_System_Information->mIB_message,  // sept. 2018
+                         "1",
+                         sizeof("1"));
+    OCTET_STRING_fromBuf(&gNB_DU_System_Information->sIB1_message,  // sept. 2018
+                         "1",
+                         sizeof("1"));
   }
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
 
   /* mandatory */
   /* c3. Served_Cells_To_Modify */
-  ie = (F1AP_GNBDUConfigurationUpdateIEs_t *)calloc(1, sizeof(F1AP_GNBDUConfigurationUpdateIEs_t));
-  ie->id                        = F1AP_ProtocolIE_ID_id_Served_Cells_To_Modify_List;
-  ie->criticality               = F1AP_Criticality_reject;
-  ie->value.present             = F1AP_GNBDUConfigurationUpdateIEs__value_PR_Served_Cells_To_Modify_List;
-
-  for (i=0;
-       i<1;
-       i++) {
-        //
-        F1AP_Served_Cells_To_Modify_ItemIEs_t *served_cells_to_modify_item_ies;
-        served_cells_to_modify_item_ies = (F1AP_Served_Cells_To_Modify_ItemIEs_t *)calloc(1, sizeof(F1AP_Served_Cells_To_Modify_ItemIEs_t));
-        served_cells_to_modify_item_ies->id            = F1AP_ProtocolIE_ID_id_Served_Cells_To_Modify_Item;
-        served_cells_to_modify_item_ies->criticality   = F1AP_Criticality_reject;
-        served_cells_to_modify_item_ies->value.present = F1AP_Served_Cells_To_Modify_ItemIEs__value_PR_Served_Cells_To_Modify_Item;
-        
-        F1AP_Served_Cells_To_Modify_Item_t served_cells_to_modify_item;
-        memset((void *)&served_cells_to_modify_item, 0, sizeof(F1AP_Served_Cells_To_Modify_Item_t));
-
-        /* 3.1 oldNRCGI */
-        F1AP_NRCGI_t oldNRCGI;
-        memset(&oldNRCGI, 0, sizeof(F1AP_NRCGI_t));
-        MCC_MNC_TO_PLMNID(f1ap_setup_req->mcc[i], f1ap_setup_req->mnc[i], f1ap_setup_req->mnc_digit_length[i],
-                                         &oldNRCGI.pLMN_Identity);
-        NR_CELL_ID_TO_BIT_STRING(f1ap_setup_req->nr_cellid[i], &oldNRCGI.nRCellIdentity);
-        served_cells_to_modify_item.oldNRCGI = oldNRCGI;
-
-
-        /* 3.2.1 serverd cell Information */
-        F1AP_Served_Cell_Information_t served_cell_information;
-        memset((void *)&served_cell_information, 0, sizeof(F1AP_Served_Cell_Information_t));
-
-        /* - nRCGI */
-        F1AP_NRCGI_t nRCGI;
-        memset(&nRCGI, 0, sizeof(F1AP_NRCGI_t));
-        MCC_MNC_TO_PLMNID(f1ap_setup_req->mcc[i], f1ap_setup_req->mnc[i], f1ap_setup_req->mnc_digit_length[i],
-                                         &nRCGI.pLMN_Identity);
-        NR_CELL_ID_TO_BIT_STRING(f1ap_setup_req->nr_cellid[i], &nRCGI.nRCellIdentity);
-        served_cell_information.nRCGI = nRCGI;
-
-        /* - nRPCI */
-        served_cell_information.nRPCI = f1ap_setup_req->nr_pci[i];  // int 0..1007
-
-        /* - fiveGS_TAC */
-        OCTET_STRING_fromBuf(served_cell_information.fiveGS_TAC,
-                             (const char *) &f1ap_setup_req->tac[i],
-                             3);
-
-        /* - Configured_EPS_TAC */
-        if(1){
-          served_cell_information.configured_EPS_TAC = (F1AP_Configured_EPS_TAC_t *)calloc(1, sizeof(F1AP_Configured_EPS_TAC_t));
-          OCTET_STRING_fromBuf(served_cell_information.configured_EPS_TAC,
-                             "2",
-                             2);
-        }
-
-        F1AP_ServedPLMNs_Item_t *servedPLMN_item = calloc(1,sizeof(*servedPLMN_item));
-        memset(servedPLMN_item,0,sizeof(*servedPLMN_item));
-        MCC_MNC_TO_PLMNID(f1ap_du_data->mcc[i], f1ap_du_data->mnc[i], f1ap_du_data->mnc_digit_length[i], &servedPLMN_item->pLMN_Identity);
-        ASN_SEQUENCE_ADD(&served_cell_information.servedPLMNs.list, servedPLMN_item);
-
-        // // /* - CHOICE NR-MODE-Info */
-        F1AP_NR_Mode_Info_t nR_Mode_Info;
-
-        if (f1ap_setup_req->fdd_flag) {
-          nR_Mode_Info.present = F1AP_NR_Mode_Info_PR_fDD;
-          /* > FDD >> FDD Info */
-          F1AP_FDD_Info_t *fDD_Info = (F1AP_FDD_Info_t *)calloc(1, sizeof(F1AP_FDD_Info_t));
-          /* >>> UL NRFreqInfo */
-          fDD_Info->uL_NRFreqInfo.nRARFCN = 999L;
-
-          F1AP_FreqBandNrItem_t ul_freqBandNrItem;
-          memset((void *)&ul_freqBandNrItem, 0, sizeof(F1AP_FreqBandNrItem_t));
-          ul_freqBandNrItem.freqBandIndicatorNr = 888L;
-
-            F1AP_SupportedSULFreqBandItem_t ul_supportedSULFreqBandItem;
-            memset((void *)&ul_supportedSULFreqBandItem, 0, sizeof(F1AP_SupportedSULFreqBandItem_t));
-            ul_supportedSULFreqBandItem.freqBandIndicatorNr = 777L;
-            ASN_SEQUENCE_ADD(&ul_freqBandNrItem.supportedSULBandList.list, &ul_supportedSULFreqBandItem);
-
-          ASN_SEQUENCE_ADD(&fDD_Info->uL_NRFreqInfo.freqBandListNr.list, &ul_freqBandNrItem);
-
-          /* >>> DL NRFreqInfo */
-          fDD_Info->dL_NRFreqInfo.nRARFCN = 666L;
-
-          F1AP_FreqBandNrItem_t dl_freqBandNrItem;
-          memset((void *)&dl_freqBandNrItem, 0, sizeof(F1AP_FreqBandNrItem_t));
-          dl_freqBandNrItem.freqBandIndicatorNr = 555L;
-
-            F1AP_SupportedSULFreqBandItem_t dl_supportedSULFreqBandItem;
-            memset((void *)&dl_supportedSULFreqBandItem, 0, sizeof(F1AP_SupportedSULFreqBandItem_t));
-            dl_supportedSULFreqBandItem.freqBandIndicatorNr = 444L;
-            ASN_SEQUENCE_ADD(&dl_freqBandNrItem.supportedSULBandList.list, &dl_supportedSULFreqBandItem);
-
-          ASN_SEQUENCE_ADD(&fDD_Info->dL_NRFreqInfo.freqBandListNr.list, &dl_freqBandNrItem);
-
-          /* >>> UL Transmission Bandwidth */
-          fDD_Info->uL_Transmission_Bandwidth.nRSCS = F1AP_NRSCS_scs15;
-          fDD_Info->uL_Transmission_Bandwidth.nRNRB = F1AP_NRNRB_nrb11;
-          /* >>> DL Transmission Bandwidth */
-          fDD_Info->dL_Transmission_Bandwidth.nRSCS = F1AP_NRSCS_scs15;
-          fDD_Info->dL_Transmission_Bandwidth.nRNRB = F1AP_NRNRB_nrb11;
-          
-          nR_Mode_Info.choice.fDD = fDD_Info;
-        } else { // TDD
-          nR_Mode_Info.present = F1AP_NR_Mode_Info_PR_tDD;
-
-          /* > TDD >> TDD Info */
-          F1AP_TDD_Info_t *tDD_Info = (F1AP_TDD_Info_t *)calloc(1, sizeof(F1AP_TDD_Info_t));
-          /* >>> ARFCN */
-          tDD_Info->nRFreqInfo.nRARFCN = 999L; // Integer
-          F1AP_FreqBandNrItem_t nr_freqBandNrItem;
-          memset((void *)&nr_freqBandNrItem, 0, sizeof(F1AP_FreqBandNrItem_t));
-          nr_freqBandNrItem.freqBandIndicatorNr = 555L;
-
-            F1AP_SupportedSULFreqBandItem_t nr_supportedSULFreqBandItem;
-            memset((void *)&nr_supportedSULFreqBandItem, 0, sizeof(F1AP_SupportedSULFreqBandItem_t));
-            nr_supportedSULFreqBandItem.freqBandIndicatorNr = 444L;
-            ASN_SEQUENCE_ADD(&nr_freqBandNrItem.supportedSULBandList.list, &nr_supportedSULFreqBandItem);
-
-          ASN_SEQUENCE_ADD(&tDD_Info->nRFreqInfo.freqBandListNr.list, &nr_freqBandNrItem);
-
-          tDD_Info->transmission_Bandwidth.nRSCS= F1AP_NRSCS_scs15;
-          tDD_Info->transmission_Bandwidth.nRNRB= F1AP_NRNRB_nrb11;
-     
-          nR_Mode_Info.choice.tDD = tDD_Info;
-        } 
-        
-        served_cell_information.nR_Mode_Info = nR_Mode_Info;
-
-        /* - measurementTimingConfiguration */
-        char *measurementTimingConfiguration = "0"; // sept. 2018
-
-        OCTET_STRING_fromBuf(&served_cell_information.measurementTimingConfiguration,
-                             measurementTimingConfiguration,
-                             strlen(measurementTimingConfiguration));
-        served_cells_to_modify_item.served_Cell_Information = served_cell_information; //
-
-        /* 3.2.2 gNB-DU System Information */
-        F1AP_GNB_DU_System_Information_t *gNB_DU_System_Information = (F1AP_GNB_DU_System_Information_t *)calloc(1, sizeof(F1AP_GNB_DU_System_Information_t));
-
-        OCTET_STRING_fromBuf(&gNB_DU_System_Information->mIB_message,  // sept. 2018
-                             "1",
-                             sizeof("1"));
-
-        OCTET_STRING_fromBuf(&gNB_DU_System_Information->sIB1_message,  // sept. 2018
-                             "1",
-                             sizeof("1"));
-        served_cells_to_modify_item.gNB_DU_System_Information = gNB_DU_System_Information; //
-
-        /* ADD */
-        served_cells_to_modify_item_ies->value.choice.Served_Cells_To_Modify_Item = served_cells_to_modify_item;
-
-        ASN_SEQUENCE_ADD(&ie->value.choice.Served_Cells_To_Modify_List.list, 
-                        served_cells_to_modify_item_ies);
-
+  asn1cSequenceAdd(out, F1AP_GNBDUConfigurationUpdateIEs_t, ie3);
+  ie3->id                        = F1AP_ProtocolIE_ID_id_Served_Cells_To_Modify_List;
+  ie3->criticality               = F1AP_Criticality_reject;
+  ie3->value.present             = F1AP_GNBDUConfigurationUpdateIEs__value_PR_Served_Cells_To_Modify_List;
+
+  for (int i=0; i<1; i++) {
+    //
+    cellIDs_t *cell=&f1ap_req(false, instance)->cell[i];
+    asn1cSequenceAdd(ie3->value.choice.Served_Cells_To_Modify_List.list, F1AP_Served_Cells_To_Modify_ItemIEs_t, served_cells_to_modify_item_ies);
+    served_cells_to_modify_item_ies->id            = F1AP_ProtocolIE_ID_id_Served_Cells_To_Modify_Item;
+    served_cells_to_modify_item_ies->criticality   = F1AP_Criticality_reject;
+    served_cells_to_modify_item_ies->value.present = F1AP_Served_Cells_To_Modify_ItemIEs__value_PR_Served_Cells_To_Modify_Item;
+    F1AP_Served_Cells_To_Modify_Item_t *served_cells_to_modify_item=&served_cells_to_modify_item_ies->value.choice.Served_Cells_To_Modify_Item;
+    /* 3.1 oldNRCGI */
+    //addnRGCI(served_cells_to_modify_item->oldNRCGI, f1ap_setup_req->cell[i]);
+    /* 3.2.1 serverd cell Information */
+    F1AP_Served_Cell_Information_t *served_cell_information= &served_cells_to_modify_item->served_Cell_Information;
+    /* - nRCGI */
+    //addnRGCI(served_cell_information->nRCGI,f1ap_setup_req->cell[i]);
+    /* - nRPCI */
+    served_cell_information->nRPCI = f1ap_setup_req->cell[i].nr_pci;  // int 0..1007
+    /* - fiveGS_TAC */
+    asn1cCalloc(served_cell_information->fiveGS_TAC, tac );
+    OCTET_STRING_fromBuf(tac,
+                         (const char *) &f1ap_setup_req->cell[i].tac,
+                         3);
+
+    /* - Configured_EPS_TAC */
+    if(1) {
+      asn1cCalloc(served_cell_information->configured_EPS_TAC, tmp2);
+      OCTET_STRING_fromBuf(tmp2,
+                           "2",
+                           2);
+    }
+
+    asn1cSequenceAdd(served_cell_information->servedPLMNs.list, F1AP_ServedPLMNs_Item_t, servedPLMN_item);
+    MCC_MNC_TO_PLMNID(cell->mcc, cell->mnc, cell->mnc_digit_length, &servedPLMN_item->pLMN_Identity);
+    // // /* - CHOICE NR-MODE-Info */
+    F1AP_NR_Mode_Info_t *nR_Mode_Info= &served_cell_information->nR_Mode_Info;
+
+    if (f1ap_setup_req->fdd_flag) {
+      nR_Mode_Info->present = F1AP_NR_Mode_Info_PR_fDD;
+      /* > FDD >> FDD Info */
+      asn1cCalloc(nR_Mode_Info->choice.fDD, fDD_Info);
+      /* >>> UL NRFreqInfo */
+      fDD_Info->uL_NRFreqInfo.nRARFCN = 999L;
+      asn1cSequenceAdd(fDD_Info->uL_NRFreqInfo.freqBandListNr.list, F1AP_FreqBandNrItem_t, ul_freqBandNrItem);
+      ul_freqBandNrItem->freqBandIndicatorNr = 888L;
+      asn1cSequenceAdd(ul_freqBandNrItem->supportedSULBandList.list, F1AP_SupportedSULFreqBandItem_t, ul_supportedSULFreqBandItem);
+      ul_supportedSULFreqBandItem->freqBandIndicatorNr = 777L;
+      /* >>> DL NRFreqInfo */
+      fDD_Info->dL_NRFreqInfo.nRARFCN = 666L;
+      asn1cSequenceAdd(dl_freqBandNrItem->supportedSULBandList.list, F1AP_FreqBandNrItem_t, dl_freqBandNrItem);
+      dl_freqBandNrItem->freqBandIndicatorNr = 555L;
+      F1AP_SupportedSULFreqBandItem_t dl_supportedSULFreqBandItem;
+      memset((void *)&dl_supportedSULFreqBandItem, 0, sizeof(F1AP_SupportedSULFreqBandItem_t));
+      dl_supportedSULFreqBandItem.freqBandIndicatorNr = 444L;
+      /* >>> UL Transmission Bandwidth */
+      fDD_Info->uL_Transmission_Bandwidth.nRSCS = F1AP_NRSCS_scs15;
+      fDD_Info->uL_Transmission_Bandwidth.nRNRB = F1AP_NRNRB_nrb11;
+      /* >>> DL Transmission Bandwidth */
+      fDD_Info->dL_Transmission_Bandwidth.nRSCS = F1AP_NRSCS_scs15;
+      fDD_Info->dL_Transmission_Bandwidth.nRNRB = F1AP_NRNRB_nrb11;
+    } else { // TDD
+      nR_Mode_Info->present = F1AP_NR_Mode_Info_PR_tDD;
+      /* > TDD >> TDD Info */
+      asn1cCalloc(nR_Mode_Info->choice.tDD, tDD_Info);
+      /* >>> ARFCN */
+      tDD_Info->nRFreqInfo.nRARFCN = 999L; // Integer
+      asn1cSequenceAdd(tDD_Info->nRFreqInfo.freqBandListNr.list, F1AP_FreqBandNrItem_t, nr_freqBandNrItem);
+      nr_freqBandNrItem->freqBandIndicatorNr = 555L;
+      asn1cSequenceAdd(nr_freqBandNrItem->supportedSULBandList.list, F1AP_SupportedSULFreqBandItem_t, nr_supportedSULFreqBandItem);
+      nr_supportedSULFreqBandItem->freqBandIndicatorNr = 444L;
+      tDD_Info->transmission_Bandwidth.nRSCS= F1AP_NRSCS_scs15;
+      tDD_Info->transmission_Bandwidth.nRNRB= F1AP_NRNRB_nrb11;
+    }
+
+    /* - measurementTimingConfiguration */
+    char *measurementTimingConfiguration = "0"; // sept. 2018
+    OCTET_STRING_fromBuf(&served_cell_information->measurementTimingConfiguration,
+                         measurementTimingConfiguration,
+                         strlen(measurementTimingConfiguration));
+    /* 3.2.2 gNB-DU System Information */
+    asn1cCalloc( served_cells_to_modify_item->gNB_DU_System_Information, gNB_DU_System_Information);
+    OCTET_STRING_fromBuf(&gNB_DU_System_Information->mIB_message,  // sept. 2018
+                         "1",
+                         sizeof("1"));
+    OCTET_STRING_fromBuf(&gNB_DU_System_Information->sIB1_message,  // sept. 2018
+                         "1",
+                         sizeof("1"));
   }
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
 
   /* mandatory */
   /* c4. Served_Cells_To_Delete */
-  ie = (F1AP_GNBDUConfigurationUpdateIEs_t *)calloc(1, sizeof(F1AP_GNBDUConfigurationUpdateIEs_t));
-  ie->id                        = F1AP_ProtocolIE_ID_id_Served_Cells_To_Delete_List;
-  ie->criticality               = F1AP_Criticality_reject;
-  ie->value.present             = F1AP_GNBDUConfigurationUpdateIEs__value_PR_Served_Cells_To_Delete_List;
-
-  for (i=0;
-       i<1;
-       i++) {
-        //
-        F1AP_Served_Cells_To_Delete_ItemIEs_t *served_cells_to_delete_item_ies;
-        served_cells_to_delete_item_ies = (F1AP_Served_Cells_To_Delete_ItemIEs_t *)calloc(1, sizeof(F1AP_Served_Cells_To_Delete_ItemIEs_t));
-        served_cells_to_delete_item_ies->id            = F1AP_ProtocolIE_ID_id_Served_Cells_To_Delete_Item;
-        served_cells_to_delete_item_ies->criticality   = F1AP_Criticality_reject;
-        served_cells_to_delete_item_ies->value.present = F1AP_Served_Cells_To_Delete_ItemIEs__value_PR_Served_Cells_To_Delete_Item;
-        
-        F1AP_Served_Cells_To_Delete_Item_t served_cells_to_delete_item;
-        memset((void *)&served_cells_to_delete_item, 0, sizeof(F1AP_Served_Cells_To_Delete_Item_t));
-
-        /* 3.1 oldNRCGI */
-        F1AP_NRCGI_t oldNRCGI;
-        memset(&oldNRCGI, 0, sizeof(F1AP_NRCGI_t));
-        MCC_MNC_TO_PLMNID(f1ap_setup_req->mcc[i], f1ap_setup_req->mnc[i], f1ap_setup_req->mnc_digit_length[i],
-                                         &oldNRCGI.pLMN_Identity);
-        NR_CELL_ID_TO_BIT_STRING(f1ap_setup_req->nr_cellid[i], &oldNRCGI.nRCellIdentity);
-        served_cells_to_delete_item.oldNRCGI = oldNRCGI;
-
-        /* ADD */
-        served_cells_to_delete_item_ies->value.choice.Served_Cells_To_Delete_Item = served_cells_to_delete_item;
-
-        ASN_SEQUENCE_ADD(&ie->value.choice.Served_Cells_To_Delete_List.list, 
-                         served_cells_to_delete_item_ies);
+  asn1cSequenceAdd(out, F1AP_GNBDUConfigurationUpdateIEs_t, ie4);
+  ie4->id                        = F1AP_ProtocolIE_ID_id_Served_Cells_To_Delete_List;
+  ie4->criticality               = F1AP_Criticality_reject;
+  ie4->value.present             = F1AP_GNBDUConfigurationUpdateIEs__value_PR_Served_Cells_To_Delete_List;
+
+  for (int i=0; i<1; i++) {
+    //
+    asn1cSequenceAdd(ie4->value.choice.Served_Cells_To_Delete_List.list, F1AP_Served_Cells_To_Delete_ItemIEs_t, served_cells_to_delete_item_ies);
+    served_cells_to_delete_item_ies->id            = F1AP_ProtocolIE_ID_id_Served_Cells_To_Delete_Item;
+    served_cells_to_delete_item_ies->criticality   = F1AP_Criticality_reject;
+    served_cells_to_delete_item_ies->value.present = F1AP_Served_Cells_To_Delete_ItemIEs__value_PR_Served_Cells_To_Delete_Item;
+    F1AP_Served_Cells_To_Delete_Item_t *served_cells_to_delete_item=&served_cells_to_delete_item_ies->value.choice.Served_Cells_To_Delete_Item;
+    /* 3.1 oldNRCGI */
+    addnRCGI(served_cells_to_delete_item->oldNRCGI, &f1ap_setup_req->cell[i]);
   }
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
-
 
   if (f1ap_encode_pdu(&pdu, &buffer, &len) < 0) {
     LOG_E(F1AP, "Failed to encode F1 gNB-DU CONFIGURATION UPDATE\n");
     return -1;
   }
 
+  ASN_STRUCT_RESET(asn_DEF_F1AP_F1AP_PDU, &pdu);
   return 0;
 }
 
-
-
 int DU_handle_gNB_DU_CONFIGURATION_FAILURE(instance_t instance,
-                                uint32_t assoc_id,
-                                uint32_t stream,
-                                F1AP_F1AP_PDU_t *pdu) {
+    uint32_t assoc_id,
+    uint32_t stream,
+    F1AP_F1AP_PDU_t *pdu) {
   AssertFatal(1==0,"Not implemented yet\n");
 }
 
 int DU_handle_gNB_DU_CONFIGURATION_UPDATE_ACKNOWLEDGE(instance_t instance,
-                                uint32_t assoc_id,
-                                uint32_t stream,
-                                F1AP_F1AP_PDU_t *pdu) {
+    uint32_t assoc_id,
+    uint32_t stream,
+    F1AP_F1AP_PDU_t *pdu) {
   AssertFatal(1==0,"Not implemented yet\n");
 }
 
 
 int DU_handle_gNB_CU_CONFIGURATION_UPDATE(instance_t instance,
-                                uint32_t assoc_id,
-                                uint32_t stream,
-                                F1AP_F1AP_PDU_t *pdu) {
-
-  if(!RC.nrrrc) {
-    return 0;
-  }
-
+    uint32_t assoc_id,
+    uint32_t stream,
+    F1AP_F1AP_PDU_t *pdu) {
   LOG_D(F1AP, "DU_handle_gNB_CU_CONFIGURATION_UPDATE\n");
-
   AssertFatal(pdu->present == F1AP_F1AP_PDU_PR_initiatingMessage,
-        "pdu->present != F1AP_F1AP_PDU_PR_initiatingMessage\n");
+              "pdu->present != F1AP_F1AP_PDU_PR_initiatingMessage\n");
   AssertFatal(pdu->choice.initiatingMessage->procedureCode  == F1AP_ProcedureCode_id_gNBCUConfigurationUpdate,
-        "pdu->choice.initiatingMessage->procedureCode != F1AP_ProcedureCode_id_gNBCUConfigurationUpdate\n");
+              "pdu->choice.initiatingMessage->procedureCode != F1AP_ProcedureCode_id_gNBCUConfigurationUpdate\n");
   AssertFatal(pdu->choice.initiatingMessage->criticality  == F1AP_Criticality_reject,
-        "pdu->choice.initiatingMessage->criticality != F1AP_Criticality_reject\n");
+              "pdu->choice.initiatingMessage->criticality != F1AP_Criticality_reject\n");
   AssertFatal(pdu->choice.initiatingMessage->value.present  == F1AP_InitiatingMessage__value_PR_GNBCUConfigurationUpdate,
-        "pdu->choice.initiatingMessage->value.present != F1AP_InitiatingMessage__value_PR_GNBCUConfigurationUpdate\n");
-
+              "pdu->choice.initiatingMessage->value.present != F1AP_InitiatingMessage__value_PR_GNBCUConfigurationUpdate\n");
   F1AP_GNBCUConfigurationUpdate_t *in = &pdu->choice.initiatingMessage->value.choice.GNBCUConfigurationUpdate;
-
-
   F1AP_GNBCUConfigurationUpdateIEs_t *ie;
   int TransactionId = -1;
   int num_cells_to_activate = 0;
   F1AP_Cells_to_be_Activated_List_Item_t *cell;
-
   MessageDef *msg_p = itti_alloc_new_message (TASK_DU_F1, 0, F1AP_GNB_CU_CONFIGURATION_UPDATE);
-
   LOG_D(F1AP, "F1AP: gNB_CU_Configuration_Update: protocolIEs.list.count %d\n",
         in->protocolIEs.list.count);
-  for (int i=0;i < in->protocolIEs.list.count; i++) {
+
+  for (int i=0; i < in->protocolIEs.list.count; i++) {
     ie = in->protocolIEs.list.array[i];
+
     switch (ie->id) {
       case F1AP_ProtocolIE_ID_id_TransactionID:
         AssertFatal(ie->criticality == F1AP_Criticality_reject,
-        "ie->criticality != F1AP_Criticality_reject\n");
+                    "ie->criticality != F1AP_Criticality_reject\n");
         AssertFatal(ie->value.present == F1AP_GNBCUConfigurationUpdateIEs__value_PR_TransactionID,
-        "ie->value.present != F1AP_GNBCUConfigurationUpdateIEs__value_PR_TransactionID\n");
+                    "ie->value.present != F1AP_GNBCUConfigurationUpdateIEs__value_PR_TransactionID\n");
         TransactionId=ie->value.choice.TransactionID;
         LOG_D(F1AP, "F1AP: GNB-CU-ConfigurationUpdate: TransactionId %d\n",
               TransactionId);
         break;
-      case F1AP_ProtocolIE_ID_id_Cells_to_be_Activated_List:
-      {
+
+      case F1AP_ProtocolIE_ID_id_Cells_to_be_Activated_List: {
         AssertFatal(ie->criticality == F1AP_Criticality_reject,
-          "ie->criticality != F1AP_Criticality_reject\n");
+                    "ie->criticality != F1AP_Criticality_reject\n");
         AssertFatal(ie->value.present == F1AP_GNBCUConfigurationUpdateIEs__value_PR_Cells_to_be_Activated_List,
-          "ie->value.present != F1AP_GNBCUConfigurationUpdateIEs__value_PR_Cells_to_be_Activated_List\n");
+                    "ie->value.present != F1AP_GNBCUConfigurationUpdateIEs__value_PR_Cells_to_be_Activated_List\n");
         num_cells_to_activate = ie->value.choice.Cells_to_be_Activated_List.list.count;
         LOG_D(F1AP, "F1AP: Activating %d cells\n",num_cells_to_activate);
-        for (int i=0;i<num_cells_to_activate;i++) {
 
+        for (int i=0; i<num_cells_to_activate; i++) {
           F1AP_Cells_to_be_Activated_List_ItemIEs_t *cells_to_be_activated_list_item_ies = (F1AP_Cells_to_be_Activated_List_ItemIEs_t *) ie->value.choice.Cells_to_be_Activated_List.list.array[i];
-
           AssertFatal(cells_to_be_activated_list_item_ies->id == F1AP_ProtocolIE_ID_id_Cells_to_be_Activated_List_Item,
-              "cells_to_be_activated_list_item_ies->id != F1AP_ProtocolIE_ID_id_Cells_to_be_Activated_List_Item");
+                      "cells_to_be_activated_list_item_ies->id != F1AP_ProtocolIE_ID_id_Cells_to_be_Activated_List_Item");
           AssertFatal(cells_to_be_activated_list_item_ies->criticality == F1AP_Criticality_reject,
-                "cells_to_be_activated_list_item_ies->criticality == F1AP_Criticality_reject");
+                      "cells_to_be_activated_list_item_ies->criticality == F1AP_Criticality_reject");
           AssertFatal(cells_to_be_activated_list_item_ies->value.present == F1AP_Cells_to_be_Activated_List_ItemIEs__value_PR_Cells_to_be_Activated_List_Item,
-                "cells_to_be_activated_list_item_ies->value.present == F1AP_Cells_to_be_Activated_List_ItemIEs__value_PR_Cells_to_be_Activated_List_Item");
-
+                      "cells_to_be_activated_list_item_ies->value.present == F1AP_Cells_to_be_Activated_List_ItemIEs__value_PR_Cells_to_be_Activated_List_Item");
           cell = &cells_to_be_activated_list_item_ies->value.choice.Cells_to_be_Activated_List_Item;
-
-          TBCD_TO_MCC_MNC(&cell->nRCGI.pLMN_Identity, F1AP_GNB_CU_CONFIGURATION_UPDATE (msg_p).cells_to_activate[i].mcc, F1AP_GNB_CU_CONFIGURATION_UPDATE (msg_p).cells_to_activate[i].mnc, F1AP_GNB_CU_CONFIGURATION_UPDATE (msg_p).cells_to_activate[i].mnc_digit_length);
-
+          TBCD_TO_MCC_MNC(&cell->nRCGI.pLMN_Identity, F1AP_GNB_CU_CONFIGURATION_UPDATE (msg_p).cells_to_activate[i].mcc, F1AP_GNB_CU_CONFIGURATION_UPDATE (msg_p).cells_to_activate[i].mnc,
+                          F1AP_GNB_CU_CONFIGURATION_UPDATE (msg_p).cells_to_activate[i].mnc_digit_length);
           LOG_D(F1AP, "nr_cellId : %x %x %x %x %x\n",
                 cell->nRCGI.nRCellIdentity.buf[0],
                 cell->nRCGI.nRCellIdentity.buf[1],
@@ -1156,61 +833,71 @@ int DU_handle_gNB_CU_CONFIGURATION_UPDATE(instance_t instance,
                 cell->nRCGI.nRCellIdentity.buf[3],
                 cell->nRCGI.nRCellIdentity.buf[4]);
           BIT_STRING_TO_NR_CELL_IDENTITY(&cell->nRCGI.nRCellIdentity,
-					 F1AP_GNB_CU_CONFIGURATION_UPDATE (msg_p).cells_to_activate[i].nr_cellid);
-	  F1AP_ProtocolExtensionContainer_154P112_t *ext = (F1AP_ProtocolExtensionContainer_154P112_t *)cell->iE_Extensions;
+                                         F1AP_GNB_CU_CONFIGURATION_UPDATE (msg_p).cells_to_activate[i].nr_cellid);
+          F1AP_ProtocolExtensionContainer_154P112_t *ext = (F1AP_ProtocolExtensionContainer_154P112_t *)cell->iE_Extensions;
 
-	  if (ext==NULL) continue;
+          if (ext==NULL)
+            continue;
 
-          for (int cnt=0;cnt<ext->list.count;cnt++) {
+          for (int cnt=0; cnt<ext->list.count; cnt++) {
             F1AP_Cells_to_be_Activated_List_ItemExtIEs_t *cells_to_be_activated_list_itemExtIEs=(F1AP_Cells_to_be_Activated_List_ItemExtIEs_t *)ext->list.array[cnt];
+
             switch (cells_to_be_activated_list_itemExtIEs->id) {
-  /*
-                case F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_NOTHING:
-                case F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_GNB_CUSystemInformation,
-                case F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_AvailablePLMNList,
-                case F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_ExtendedAvailablePLMN_List,
-                case F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_IAB_Info_IAB_donor_CU,
-                case F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_AvailableSNPN_ID_List
-  */
-              case F1AP_ProtocolIE_ID_id_gNB_CUSystemInformation:
-              {
+              /*
+                            case F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_NOTHING:
+                            case F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_GNB_CUSystemInformation,
+                            case F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_AvailablePLMNList,
+                            case F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_ExtendedAvailablePLMN_List,
+                            case F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_IAB_Info_IAB_donor_CU,
+                            case F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_AvailableSNPN_ID_List
+              */
+              case F1AP_ProtocolIE_ID_id_gNB_CUSystemInformation: {
                 F1AP_GNB_CU_CONFIGURATION_UPDATE (msg_p).cells_to_activate[i].nrpci = (cell->nRPCI != NULL) ? *cell->nRPCI : 0;
-                F1AP_GNB_CUSystemInformation_t *gNB_CUSystemInformation = (F1AP_GNB_CUSystemInformation_t*)&cells_to_be_activated_list_itemExtIEs->extensionValue.choice.GNB_CUSystemInformation;
+                F1AP_GNB_CUSystemInformation_t *gNB_CUSystemInformation = (F1AP_GNB_CUSystemInformation_t *)&cells_to_be_activated_list_itemExtIEs->extensionValue.choice.GNB_CUSystemInformation;
                 F1AP_GNB_CU_CONFIGURATION_UPDATE (msg_p).cells_to_activate[i].num_SI = gNB_CUSystemInformation->sibtypetobeupdatedlist.list.count;
                 AssertFatal(ext->list.count==1,"At least one SI message should be there, and only 1 for now!\n");
                 LOG_D(F1AP, "F1AP: Cell %d MCC %d MNC %d NRCellid %lx num_si %d\n",
                       i, F1AP_GNB_CU_CONFIGURATION_UPDATE (msg_p).cells_to_activate[i].mcc, F1AP_GNB_CU_CONFIGURATION_UPDATE (msg_p).cells_to_activate[i].mnc,
                       F1AP_GNB_CU_CONFIGURATION_UPDATE (msg_p).cells_to_activate[i].nr_cellid, F1AP_GNB_CU_CONFIGURATION_UPDATE (msg_p).cells_to_activate[i].num_SI);
-                for (int si = 0;si < gNB_CUSystemInformation->sibtypetobeupdatedlist.list.count;si++) {
+
+                for (int si = 0; si < gNB_CUSystemInformation->sibtypetobeupdatedlist.list.count; si++) {
                   F1AP_SibtypetobeupdatedListItem_t *sib_item = gNB_CUSystemInformation->sibtypetobeupdatedlist.list.array[si];
                   size_t size = sib_item->sIBmessage.size;
-                  F1AP_GNB_CU_CONFIGURATION_UPDATE (msg_p).cells_to_activate[i].SI_container_length[sib_item->sIBtype] = size;
-                  LOG_I(F1AP, "F1AP: SI_container_length[%d][%d] %ld bytes\n", i, (int)sib_item->sIBtype, size);
-                  F1AP_GNB_CU_CONFIGURATION_UPDATE (msg_p).cells_to_activate[i].SI_container[sib_item->sIBtype] = malloc(size);
-                  memcpy((void*)F1AP_GNB_CU_CONFIGURATION_UPDATE (msg_p).cells_to_activate[i].SI_container[sib_item->sIBtype],
-                          (void*)sib_item->sIBmessage.buf,
-                          size);
+                  F1AP_GNB_CU_CONFIGURATION_UPDATE (msg_p).cells_to_activate[i].SI_container_length[si] = size;
+                  LOG_D(F1AP, "F1AP: SI_container_length[%d][%ld] %ld bytes\n", i, sib_item->sIBtype, size);
+                  F1AP_GNB_CU_CONFIGURATION_UPDATE (msg_p).cells_to_activate[i].SI_container[si] = malloc(F1AP_GNB_CU_CONFIGURATION_UPDATE (msg_p).cells_to_activate[i].SI_container_length[si]);
+                  memcpy((void *)F1AP_GNB_CU_CONFIGURATION_UPDATE (msg_p).cells_to_activate[i].SI_container[si],
+                         (void *)sib_item->sIBmessage.buf,
+                         size);
+                  F1AP_GNB_CU_CONFIGURATION_UPDATE (msg_p).cells_to_activate[i].SI_type[si]=sib_item->sIBtype;
                 }
+
                 break;
               }
+
               case F1AP_ProtocolIE_ID_id_AvailablePLMNList:
                 AssertFatal(1==0,"F1AP_ProtocolIE_ID_id_AvailablePLMNList not supported yet\n");
                 break;
+
               case F1AP_ProtocolIE_ID_id_ExtendedAvailablePLMN_List:
                 AssertFatal(1==0,"F1AP_ProtocolIE_ID_id_AvailablePLMNList not supported yet\n");
                 break;
+
               case F1AP_ProtocolIE_ID_id_IAB_Info_IAB_donor_CU:
                 AssertFatal(1==0,"F1AP_ProtocolIE_ID_id_AvailablePLMNList not supported yet\n");
                 break;
+
               case F1AP_ProtocolIE_ID_id_AvailableSNPN_ID_List:
                 AssertFatal(1==0,"F1AP_ProtocolIE_ID_id_AvailablePLMNList not supported yet\n");
                 break;
+
               default:
                 AssertFatal(1==0,"F1AP_ProtocolIE_ID_id %d unknown\n",(int)cells_to_be_activated_list_itemExtIEs->id);
                 break;
             }
           } // for (cnt=...
         } // for (cells_to_activate...
+
         break;
       } // case F1AP_ProtocolIE_ID_id_Cells_to_be_Activated_List
 
@@ -1219,84 +906,61 @@ int DU_handle_gNB_CU_CONFIGURATION_UPDATE(instance_t instance,
         break;
     } // switch ie
   } // for IE
+
   AssertFatal(TransactionId!=-1,"TransactionId was not sent\n");
   LOG_D(F1AP,"F1AP: num_cells_to_activate %d\n",num_cells_to_activate);
   F1AP_GNB_CU_CONFIGURATION_UPDATE (msg_p).num_cells_to_activate = num_cells_to_activate;
-
   MSC_LOG_RX_MESSAGE(
-  MSC_F1AP_DU,
-  MSC_F1AP_CU,
-  0,
-  0,
-  MSC_AS_TIME_FMT" DU_handle_GNB_CU_CONFIGURATION_UPDATE initiatingMessage assoc_id %d",
-  0,0,//MSC_AS_TIME_ARGS(ctxt_pP),
-  assoc_id);
-
-  if (RC.nrrrc && RC.nrrrc[0]->node_type == ngran_gNB_DU) {
-    LOG_D(F1AP, "Sending F1AP_GNB_CU_CONFIGURATION_UPDATE ITTI message to GNB_APP with assoc_id (%d->%d)\n",
-         assoc_id,ENB_MODULE_ID_TO_INSTANCE(assoc_id));
-    itti_send_msg_to_task(TASK_GNB_APP, GNB_MODULE_ID_TO_INSTANCE(assoc_id), msg_p);
-  } else {
-    LOG_D(F1AP, "Sending F1AP_GNB_CU_CONFIGURATION_UPDATE ITTI message to ENB_APP with assoc_id (%d->%d)\n",
-         assoc_id,ENB_MODULE_ID_TO_INSTANCE(assoc_id));
-    itti_send_msg_to_task(TASK_ENB_APP, ENB_MODULE_ID_TO_INSTANCE(assoc_id), msg_p);
-  }
-
+    MSC_F1AP_DU,
+    MSC_F1AP_CU,
+    0,
+    0,
+    MSC_AS_TIME_FMT" DU_handle_GNB_CU_CONFIGURATION_UPDATE initiatingMessage assoc_id %d",
+    0,0,//MSC_AS_TIME_ARGS(ctxt_pP),
+    assoc_id);
+  LOG_D(F1AP, "Sending F1AP_GNB_CU_CONFIGURATION_UPDATE ITTI message \n");
+  itti_send_msg_to_task(TASK_F1APP, GNB_MODULE_ID_TO_INSTANCE(assoc_id), msg_p);
   return 0;
 }
 
 int DU_send_gNB_CU_CONFIGURATION_UPDATE_FAILURE(instance_t instance,
-						f1ap_gnb_cu_configuration_update_failure_t *GNBCUConfigurationUpdateFailure) {
+    f1ap_gnb_cu_configuration_update_failure_t *GNBCUConfigurationUpdateFailure) {
   AssertFatal(1==0,"received gNB CU CONFIGURATION UPDATE FAILURE with cause %d\n",
-	      GNBCUConfigurationUpdateFailure->cause);
+              GNBCUConfigurationUpdateFailure->cause);
 }
 
 int DU_send_gNB_CU_CONFIGURATION_UPDATE_ACKNOWLEDGE(instance_t instance,
-						    f1ap_gnb_cu_configuration_update_acknowledge_t *GNBCUConfigurationUpdateAcknowledge) {
-
-  if(!RC.nrrrc) {
-    return 0;
-  }
-
+    f1ap_gnb_cu_configuration_update_acknowledge_t *GNBCUConfigurationUpdateAcknowledge) {
   AssertFatal(GNBCUConfigurationUpdateAcknowledge->num_cells_failed_to_be_activated == 0,
-	      "%d cells failed to activate\n",
-	      GNBCUConfigurationUpdateAcknowledge->num_cells_failed_to_be_activated);
-
+              "%d cells failed to activate\n",
+              GNBCUConfigurationUpdateAcknowledge->num_cells_failed_to_be_activated);
   AssertFatal(GNBCUConfigurationUpdateAcknowledge->noofTNLAssociations_to_setup == 0,
-	      "%d TNLAssociations to setup, handle this ...\n",
-	      GNBCUConfigurationUpdateAcknowledge->noofTNLAssociations_to_setup);
-
-
+              "%d TNLAssociations to setup, handle this ...\n",
+              GNBCUConfigurationUpdateAcknowledge->noofTNLAssociations_to_setup);
   AssertFatal(GNBCUConfigurationUpdateAcknowledge->noofTNLAssociations_failed == 0,
-	      "%d TNLAssociations failed\n",
-	      GNBCUConfigurationUpdateAcknowledge->noofTNLAssociations_failed);
-
+              "%d TNLAssociations failed\n",
+              GNBCUConfigurationUpdateAcknowledge->noofTNLAssociations_failed);
   AssertFatal(GNBCUConfigurationUpdateAcknowledge->noofDedicatedSIDeliveryNeededUEs == 0,
-	      "%d DedicatedSIDeliveryNeededUEs\n",
-	      GNBCUConfigurationUpdateAcknowledge->noofDedicatedSIDeliveryNeededUEs);
-
-  F1AP_F1AP_PDU_t           pdu;
-  uint8_t  *buffer;
-  uint32_t  len;
-
+              "%d DedicatedSIDeliveryNeededUEs\n",
+              GNBCUConfigurationUpdateAcknowledge->noofDedicatedSIDeliveryNeededUEs);
+  F1AP_F1AP_PDU_t           pdu= {0};
+  uint8_t  *buffer=NULL;
+  uint32_t  len=0;
   /* Create */
   /* 0. pdu Type */
-  memset(&pdu, 0, sizeof(pdu));
   pdu.present = F1AP_F1AP_PDU_PR_successfulOutcome;
-  pdu.choice.successfulOutcome = (F1AP_SuccessfulOutcome_t *)calloc(1, sizeof(F1AP_SuccessfulOutcome_t));
-  pdu.choice.successfulOutcome->procedureCode = F1AP_ProcedureCode_id_gNBCUConfigurationUpdate;
-  pdu.choice.successfulOutcome->criticality   = F1AP_Criticality_reject;
-  pdu.choice.successfulOutcome->value.present = F1AP_SuccessfulOutcome__value_PR_GNBCUConfigurationUpdateAcknowledge;
-  F1AP_GNBCUConfigurationUpdateAcknowledge_t *out = &pdu.choice.successfulOutcome->value.choice.GNBCUConfigurationUpdateAcknowledge;
-
+  asn1cCalloc(pdu.choice.successfulOutcome, tmp);
+  tmp->procedureCode = F1AP_ProcedureCode_id_gNBCUConfigurationUpdate;
+  tmp->criticality   = F1AP_Criticality_reject;
+  tmp->value.present = F1AP_SuccessfulOutcome__value_PR_GNBCUConfigurationUpdateAcknowledge;
+  F1AP_GNBCUConfigurationUpdateAcknowledge_t *out = &tmp->value.choice.GNBCUConfigurationUpdateAcknowledge;
   /* mandatory */
   /* c1. Transaction ID (integer value)*/
-  F1AP_GNBCUConfigurationUpdateAcknowledgeIEs_t *ie = (F1AP_GNBCUConfigurationUpdateAcknowledgeIEs_t *)calloc(1, sizeof(F1AP_F1SetupResponseIEs_t));
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_GNBCUConfigurationUpdateAcknowledgeIEs_t, ie);
   ie->id                        = F1AP_ProtocolIE_ID_id_TransactionID;
   ie->criticality               = F1AP_Criticality_reject;
   ie->value.present             = F1AP_GNBCUConfigurationUpdateAcknowledgeIEs__value_PR_TransactionID;
   ie->value.choice.TransactionID = F1AP_get_next_transaction_identifier(0, 0);
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
 
   /* encode */
   if (f1ap_encode_pdu(&pdu, &buffer, &len) < 0) {
@@ -1304,22 +968,20 @@ int DU_send_gNB_CU_CONFIGURATION_UPDATE_ACKNOWLEDGE(instance_t instance,
     return -1;
   }
 
-  du_f1ap_itti_send_sctp_data_req(instance, f1ap_du_data->assoc_id, buffer, len, 0);
-
-
-
+  ASN_STRUCT_RESET(asn_DEF_F1AP_F1AP_PDU, &pdu);
+  f1ap_itti_send_sctp_data_req(false, instance, buffer, len, 0);
   return 0;
 }
 
 
 int DU_send_gNB_DU_RESOURCE_COORDINATION_REQUEST(instance_t instance,
-                    F1AP_GNBDUResourceCoordinationRequest_t *GNBDUResourceCoordinationRequest) {
+    F1AP_GNBDUResourceCoordinationRequest_t *GNBDUResourceCoordinationRequest) {
   AssertFatal(0, "Not implemented yet\n");
 }
 
 int DU_handle_gNB_DU_RESOURCE_COORDINATION_RESPONSE(instance_t instance,
-                                uint32_t assoc_id,
-                                uint32_t stream,
-                                F1AP_F1AP_PDU_t *pdu) {
+    uint32_t assoc_id,
+    uint32_t stream,
+    F1AP_F1AP_PDU_t *pdu) {
   AssertFatal(0, "Not implemented yet\n");
 }
diff --git a/openair2/F1AP/f1ap_du_interface_management.h b/openair2/F1AP/f1ap_du_interface_management.h
index 619b725f38832478d4260d89ff9d4b844875a6fb..83cd69cf6c0b6c05a72692fb1f943d417a2fc79d 100644
--- a/openair2/F1AP/f1ap_du_interface_management.h
+++ b/openair2/F1AP/f1ap_du_interface_management.h
@@ -76,43 +76,44 @@ int DU_handle_F1_SETUP_FAILURE(instance_t instance,
  * gNB-DU Configuration Update
  */
 int DU_send_gNB_DU_CONFIGURATION_UPDATE(instance_t instance,
-                                         instance_t du_mod_idP,
-                                         f1ap_setup_req_t *f1ap_du_data);
+                                        instance_t du_mod_idP,
+                                        f1ap_setup_req_t *f1ap_du_data);
 
 int DU_handle_gNB_DU_CONFIGURATION_FAILURE(instance_t instance,
-                                           uint32_t assoc_id,
-                                           uint32_t stream,
-                                           F1AP_F1AP_PDU_t *pdu);
+    uint32_t assoc_id,
+    uint32_t stream,
+    F1AP_F1AP_PDU_t *pdu);
 
 int DU_handle_gNB_DU_CONFIGURATION_UPDATE_ACKNOWLEDGE(instance_t instance,
-                                                      uint32_t assoc_id,
-                                                      uint32_t stream,
-                                                      F1AP_F1AP_PDU_t *pdu);
+    uint32_t assoc_id,
+    uint32_t stream,
+    F1AP_F1AP_PDU_t *pdu);
 
 /*
  * gNB-CU Configuration Update
  */
 int DU_handle_gNB_CU_CONFIGURATION_UPDATE(instance_t instance,
-                                          uint32_t assoc_id,
-                                          uint32_t stream,
-                                          F1AP_F1AP_PDU_t *pdu);
+    uint32_t assoc_id,
+    uint32_t stream,
+    F1AP_F1AP_PDU_t *pdu);
 
 int DU_send_gNB_CU_CONFIGURATION_UPDATE_FAILURE(instance_t instance,
-                                                f1ap_gnb_cu_configuration_update_failure_t *GNBCUConfigurationUpdateFailure);
+    f1ap_gnb_cu_configuration_update_failure_t *GNBCUConfigurationUpdateFailure);
 
 int DU_send_gNB_CU_CONFIGURATION_UPDATE_ACKNOWLEDGE(instance_t instance,
-                                                    f1ap_gnb_cu_configuration_update_acknowledge_t *GNBCUConfigurationUpdateAcknowledge);
+    f1ap_gnb_cu_configuration_update_acknowledge_t *GNBCUConfigurationUpdateAcknowledge);
+
 
 
 /*
  * gNB-DU Resource Coordination
  */
 int DU_send_gNB_DU_RESOURCE_COORDINATION_REQUEST(instance_t instance,
-                                                 F1AP_GNBDUResourceCoordinationRequest_t *GNBDUResourceCoordinationRequest);
+    F1AP_GNBDUResourceCoordinationRequest_t *GNBDUResourceCoordinationRequest);
 
 int DU_handle_gNB_DU_RESOURCE_COORDINATION_RESPONSE(instance_t instance,
-                                                    uint32_t assoc_id,
-                                                    uint32_t stream,
-                                                    F1AP_F1AP_PDU_t *pdu);
+    uint32_t assoc_id,
+    uint32_t stream,
+    F1AP_F1AP_PDU_t *pdu);
 
 #endif /* F1AP_DU_INTERFACE_MANAGEMENT_H_ */
diff --git a/openair2/F1AP/f1ap_du_rrc_message_transfer.c b/openair2/F1AP/f1ap_du_rrc_message_transfer.c
index 0c8f566fd669fc2e30a189b352cf5e7bc7c8230c..90ea324a2821479682a1bedd3aa5b2e1665f43f4 100644
--- a/openair2/F1AP/f1ap_du_rrc_message_transfer.c
+++ b/openair2/F1AP/f1ap_du_rrc_message_transfer.c
@@ -56,76 +56,55 @@
 #include "intertask_interface.h"
 #include "LAYER2/NR_MAC_gNB/mac_proto.h"
 
-extern f1ap_setup_req_t *f1ap_du_data;
-extern RAN_CONTEXT_t RC;
-extern f1ap_cudu_inst_t f1ap_du_inst[MAX_eNB];
-
-extern rlc_op_status_t nr_rrc_rlc_config_asn1_req (const protocol_ctxt_t   * const ctxt_pP,
-                                                   const NR_SRB_ToAddModList_t   * const srb2add_listP,
-                                                   const NR_DRB_ToAddModList_t   * const drb2add_listP,
-                                                   const NR_DRB_ToReleaseList_t  * const drb2release_listP,
-                                                   const LTE_PMCH_InfoList_r9_t * const pmch_InfoList_r9_pP,
-                                                   struct NR_CellGroupConfig__rlc_BearerToAddModList *rlc_srb_bearer2add_list,
-                                                   struct NR_CellGroupConfig__rlc_BearerToAddModList *rlc_drb_bearer2add_list);
-
-uint8_t du_ccch_flag = 1;
 
 int DU_handle_DL_NR_RRC_MESSAGE_TRANSFER(instance_t       instance,
-                                         uint32_t         assoc_id,
-                                         uint32_t         stream,
-                                         F1AP_F1AP_PDU_t *pdu);
+    uint32_t         assoc_id,
+    uint32_t         stream,
+    F1AP_F1AP_PDU_t *pdu);
 
 /*  DL RRC Message Transfer */
 int DU_handle_DL_RRC_MESSAGE_TRANSFER(instance_t       instance,
                                       uint32_t         assoc_id,
                                       uint32_t         stream,
                                       F1AP_F1AP_PDU_t *pdu) {
-
   if (RC.nrrrc && RC.nrrrc[instance]->node_type == ngran_gNB_DU) {
     LOG_I(F1AP, "node is gNB DU, call DU_handle_DL_NR_RRC_MESSAGE_TRANSFER \n");
     return DU_handle_DL_NR_RRC_MESSAGE_TRANSFER(instance, assoc_id, stream, pdu);
   }
 
-  LOG_D(F1AP, "DU_handle_DL_RRC_MESSAGE_TRANSFER \n");
-  
+  LOG_W(F1AP, "DU_handle_DL_RRC_MESSAGE_TRANSFER is a big race condition with rrc \n");
   F1AP_DLRRCMessageTransfer_t    *container;
   F1AP_DLRRCMessageTransferIEs_t *ie;
-
   uint64_t        cu_ue_f1ap_id;
   uint64_t        du_ue_f1ap_id;
-  uint64_t        srb_id;
   int             executeDuplication;
   sdu_size_t      rrc_dl_sdu_len;
   //uint64_t        subscriberProfileIDforRFP;
   //uint64_t        rAT_FrequencySelectionPriority;
-
   DevAssert(pdu != NULL);
 
   if (stream != 0) {
     LOG_E(F1AP, "[SCTP %d] Received F1 on stream != 0 (%d)\n",
-               assoc_id, stream);
+          assoc_id, stream);
     return -1;
   }
 
   container = &pdu->choice.initiatingMessage->value.choice.DLRRCMessageTransfer;
-
-
   /* GNB_CU_UE_F1AP_ID */
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_DLRRCMessageTransferIEs_t, ie, container,
                              F1AP_ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID, true);
   cu_ue_f1ap_id = ie->value.choice.GNB_CU_UE_F1AP_ID;
   LOG_D(F1AP, "cu_ue_f1ap_id %lu \n", cu_ue_f1ap_id);
-
-
   /* GNB_DU_UE_F1AP_ID */
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_DLRRCMessageTransferIEs_t, ie, container,
                              F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID, true);
   du_ue_f1ap_id = ie->value.choice.GNB_DU_UE_F1AP_ID;
   LOG_D(F1AP, "du_ue_f1ap_id %lu associated with UE RNTI %x \n",
         du_ue_f1ap_id,
-        f1ap_get_rnti_by_du_id(&f1ap_du_inst[instance], du_ue_f1ap_id)); // this should be the one transmitted via initial ul rrc message transfer
+        f1ap_get_rnti_by_du_id(DUtype, instance, du_ue_f1ap_id));
+  // this should be the one transmitted via initial ul rrc message transfer
 
-  if (f1ap_du_add_cu_ue_id(&f1ap_du_inst[instance],du_ue_f1ap_id, cu_ue_f1ap_id) < 0 ) {
+  if (f1ap_du_add_cu_ue_id(instance,du_ue_f1ap_id, cu_ue_f1ap_id) < 0 ) {
     LOG_E(F1AP, "Failed to find the F1AP UID \n");
     //return -1;
   }
@@ -134,21 +113,21 @@ int DU_handle_DL_RRC_MESSAGE_TRANSFER(instance_t       instance,
   /* oldgNB_DU_UE_F1AP_ID */
   if (0) {
     F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_DLRRCMessageTransferIEs_t, ie, container,
-                             F1AP_ProtocolIE_ID_id_oldgNB_DU_UE_F1AP_ID, true);
+                               F1AP_ProtocolIE_ID_id_oldgNB_DU_UE_F1AP_ID, true);
   }
 
   /* mandatory */
   /* SRBID */
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_DLRRCMessageTransferIEs_t, ie, container,
                              F1AP_ProtocolIE_ID_id_SRBID, true);
-  srb_id = ie->value.choice.SRBID;
+  uint64_t  srb_id = ie->value.choice.SRBID;
   LOG_D(F1AP, "srb_id %lu \n", srb_id);
 
   /* optional */
   /* ExecuteDuplication */
   if (0) {
     F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_DLRRCMessageTransferIEs_t, ie, container,
-                             F1AP_ProtocolIE_ID_id_ExecuteDuplication, true);
+                               F1AP_ProtocolIE_ID_id_ExecuteDuplication, true);
     executeDuplication = ie->value.choice.ExecuteDuplication;
     LOG_D(F1AP, "ExecuteDuplication %d \n", executeDuplication);
   }
@@ -158,33 +137,23 @@ int DU_handle_DL_RRC_MESSAGE_TRANSFER(instance_t       instance,
   /* RRC Container */
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_DLRRCMessageTransferIEs_t, ie, container,
                              F1AP_ProtocolIE_ID_id_RRCContainer, true);
-  // BK: need check
-  // create an ITTI message and copy SDU
-
-  //  message_p = itti_alloc_new_message (TASK_CU_F1, 0, RRC_MAC_CCCH_DATA_IND);
-  //  memset (RRC_MAC_CCCH_DATA_IND (message_p).sdu, 0, CCCH_SDU_SIZE);
   rrc_dl_sdu_len = ie->value.choice.RRCContainer.size;
-  //  memcpy(RRC_MAC_CCCH_DATA_IND (message_p).sdu, ie->value.choice.RRCContainer.buf,
-  //         ccch_sdu_len);
-
-  //LOG_I(F1AP, "%s() RRCContainer size %lu: ", __func__, ie->value.choice.RRCContainer.size);
-  //for (int i = 0;i < ie->value.choice.RRCContainer.size; i++)
-  //  printf("%02x ", ie->value.choice.RRCContainer.buf[i]);
-  //printf("\n");
 
   /* optional */
   /* RAT_FrequencyPriorityInformation */
   if (0) {
     F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_DLRRCMessageTransferIEs_t, ie, container,
-                             F1AP_ProtocolIE_ID_id_RAT_FrequencyPriorityInformation, true);
+                               F1AP_ProtocolIE_ID_id_RAT_FrequencyPriorityInformation, true);
 
     switch(ie->value.choice.RAT_FrequencyPriorityInformation.present) {
       case F1AP_RAT_FrequencyPriorityInformation_PR_eNDC:
         //subscriberProfileIDforRFP = ie->value.choice.RAT_FrequencyPriorityInformation.choice.subscriberProfileIDforRFP;
         break;
+
       case F1AP_RAT_FrequencyPriorityInformation_PR_nGRAN:
         //rAT_FrequencySelectionPriority = ie->value.choice.RAT_FrequencyPriorityInformation.choice.rAT_FrequencySelectionPriority;
         break;
+
       default:
         LOG_W(F1AP, "unhandled IE RAT_FrequencyPriorityInformation.present\n");
         break;
@@ -193,28 +162,26 @@ int DU_handle_DL_RRC_MESSAGE_TRANSFER(instance_t       instance,
 
   // decode RRC Container and act on the message type
   AssertFatal(srb_id<3,"illegal srb_id\n");
-
   protocol_ctxt_t ctxt;
-  ctxt.rnti      = f1ap_get_rnti_by_du_id(&f1ap_du_inst[instance], du_ue_f1ap_id);
+  ctxt.rnti      = f1ap_get_rnti_by_du_id(DUtype, instance, du_ue_f1ap_id);
+  ctxt.instance = instance;
   ctxt.module_id = instance;
-  ctxt.instance  = instance;
   ctxt.enb_flag  = 1;
-
- struct rrc_eNB_ue_context_s* ue_context_p = rrc_eNB_get_ue_context(
-                                                RC.rrc[ctxt.module_id],
-                                                ctxt.rnti);
+  struct rrc_eNB_ue_context_s *ue_context_p = rrc_eNB_get_ue_context(
+        RC.rrc[ctxt.instance],
+        ctxt.rnti);
 
   if (srb_id == 0) {
-    LTE_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_LTE_DL_CCCH_Message,
-         (void**)&dl_ccch_msg,
-         ie->value.choice.RRCContainer.buf,
-         rrc_dl_sdu_len,0,0);
+                           &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) {
 
+    switch (dl_ccch_msg->message.choice.c1.present) {
       case LTE_DL_CCCH_MessageType__c1_PR_NOTHING:
         LOG_I(F1AP, "Received PR_NOTHING on DL-CCCH-Message\n");
         break;
@@ -234,32 +201,27 @@ int DU_handle_DL_RRC_MESSAGE_TRANSFER(instance_t       instance,
               "Logical Channel DL-CCCH (SRB0), Received RRCConnectionReject \n");
         break;
 
-      case LTE_DL_CCCH_MessageType__c1_PR_rrcConnectionSetup:
-      {
+      case LTE_DL_CCCH_MessageType__c1_PR_rrcConnectionSetup: {
         LOG_I(F1AP,
               "Logical Channel DL-CCCH (SRB0), Received RRCConnectionSetup DU_ID %lx/RNTI %x\n",
               du_ue_f1ap_id,
-              f1ap_get_rnti_by_du_id(&f1ap_du_inst[instance], du_ue_f1ap_id));
-          // Get configuration
-
-        LTE_RRCConnectionSetup_t* rrcConnectionSetup = &dl_ccch_msg->message.choice.c1.choice.rrcConnectionSetup;
+              f1ap_get_rnti_by_du_id(DUtype, instance, du_ue_f1ap_id));
+        // Get configuration
+        LTE_RRCConnectionSetup_t *rrcConnectionSetup = &dl_ccch_msg->message.choice.c1.choice.rrcConnectionSetup;
         AssertFatal(rrcConnectionSetup!=NULL,"rrcConnectionSetup is null\n");
-        LTE_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
-        LTE_SRB_ToAddModList_t *SRB_configList;
-        LTE_SRB_ToAddMod_t *SRB1_config;
+        LTE_SRB_ToAddModList_t *SRB_configList = radioResourceConfigDedicated->srb_ToAddModList;
+        AssertFatal(SRB_configList!=NULL,"SRB_configList is null\n");
         LTE_LogicalChannelConfig_t *SRB1_logicalChannelConfig = NULL;
-        SRB_configList                 = radioResourceConfigDedicated->srb_ToAddModList;
 
-        AssertFatal(SRB_configList!=NULL,"SRB_configList is null\n");
         for (int cnt = 0; cnt < (SRB_configList)->list.count; cnt++) {
           if ((SRB_configList)->list.array[cnt]->srb_Identity == 1) {
-            SRB1_config = (SRB_configList)->list.array[cnt];
+           LTE_SRB_ToAddMod_t * SRB1_config = (SRB_configList)->list.array[cnt];
 
             if (SRB1_config->logicalChannelConfig) {
               if (SRB1_config->logicalChannelConfig->present ==
-                LTE_SRB_ToAddMod__logicalChannelConfig_PR_explicitValue) {
+                  LTE_SRB_ToAddMod__logicalChannelConfig_PR_explicitValue) {
                 SRB1_logicalChannelConfig = &SRB1_config->logicalChannelConfig->choice.explicitValue;
               } else {
                 SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
@@ -269,35 +231,33 @@ int DU_handle_DL_RRC_MESSAGE_TRANSFER(instance_t       instance,
             }
           }
         } // for
+
         rrc_rlc_config_asn1_req(&ctxt,
-          SRB_configList,
-          (LTE_DRB_ToAddModList_t*) NULL,
-          (LTE_DRB_ToReleaseList_t*) NULL
-          , (LTE_PMCH_InfoList_r9_t *) NULL,
-          0,0
-          );
-
-      // This should be somewhere in the f1ap_cudu_ue_inst_t
-      /*int macrlc_instance = 0; 
-
-      rnti_t rnti = f1ap_get_rnti_by_du_id(&f1ap_du_inst[0], du_ue_f1ap_id);
-      struct rrc_eNB_ue_context_s *ue_context_p = rrc_eNB_get_ue_context(RC.rrc[macrlc_instance],rnti);
-      */  
-      eNB_RRC_UE_t *ue_p = &ue_context_p->ue_context; 
-      AssertFatal(ue_p->Srb0.Active == 1,"SRB0 is not active\n");
-
-      memcpy((void*)ue_p->Srb0.Tx_buffer.Payload,
-             (void*)ie->value.choice.RRCContainer.buf,
-             rrc_dl_sdu_len); // ie->value.choice.RRCContainer.size
-
-      ue_p->Srb0.Tx_buffer.payload_size = rrc_dl_sdu_len;
-
-      LTE_MAC_MainConfig_t    *mac_MainConfig  = NULL;
-      if (radioResourceConfigDedicated->mac_MainConfig)
-        mac_MainConfig = &radioResourceConfigDedicated->mac_MainConfig->choice.explicitValue;
-
-      rrc_mac_config_req_eNB(
-          ctxt.module_id,
+                                SRB_configList,
+                                (LTE_DRB_ToAddModList_t *) NULL,
+                                (LTE_DRB_ToReleaseList_t *) NULL
+                                , (LTE_PMCH_InfoList_r9_t *) NULL,
+                                0,0
+                               );
+        // This should be somewhere in the f1ap_cudu_ue_inst_t
+        /*int macrlc_instance = 0;
+
+        rnti_t rnti = f1ap_get_rnti_by_du_id(DUtype, instance, du_ue_f1ap_id);
+        struct rrc_eNB_ue_context_s *ue_context_p = rrc_eNB_get_ue_context(RC.rrc[macrlc_instance],rnti);
+        */
+        eNB_RRC_UE_t *ue_p = &ue_context_p->ue_context;
+        AssertFatal(ue_p->Srb0.Active == 1,"SRB0 is not active\n");
+        memcpy((void *)ue_p->Srb0.Tx_buffer.Payload,
+               (void *)ie->value.choice.RRCContainer.buf,
+               rrc_dl_sdu_len); // ie->value.choice.RRCContainer.size
+        ue_p->Srb0.Tx_buffer.payload_size = rrc_dl_sdu_len;
+        LTE_MAC_MainConfig_t    *mac_MainConfig  = NULL;
+
+        if (radioResourceConfigDedicated->mac_MainConfig)
+          mac_MainConfig = &radioResourceConfigDedicated->mac_MainConfig->choice.explicitValue;
+
+        rrc_mac_config_req_eNB(
+          ctxt.instance,
           0, //primaryCC_id,
           0,0,0,0,0,0,
           ctxt.rnti,
@@ -318,234 +278,239 @@ int DU_handle_DL_RRC_MESSAGE_TRANSFER(instance_t       instance,
           0, NULL, NULL, (LTE_MBSFN_SubframeConfigList_t *) NULL
           , 0, (LTE_MBSFN_AreaInfoList_r9_t *) NULL, (LTE_PMCH_InfoList_r9_t *) NULL,
           (LTE_SystemInformationBlockType1_v1310_IEs_t *)NULL
-                        ,
-                        0,
-                        (LTE_BCCH_DL_SCH_Message_MBMS_t *) NULL,
-                        (LTE_SchedulingInfo_MBMS_r14_t *) NULL,
-                        (struct LTE_NonMBSFN_SubframeConfig_r14 *) NULL,
-                        (LTE_SystemInformationBlockType1_MBMS_r14_t *) NULL,
-                        (LTE_MBSFN_AreaInfoList_r9_t *) NULL,
-                        (LTE_MBSFNAreaConfiguration_r9_t*) NULL
-          );
-          break;
+          ,
+          0,
+          (LTE_BCCH_DL_SCH_Message_MBMS_t *) NULL,
+          (LTE_SchedulingInfo_MBMS_r14_t *) NULL,
+          (struct LTE_NonMBSFN_SubframeConfig_r14 *) NULL,
+          (LTE_SystemInformationBlockType1_MBMS_r14_t *) NULL,
+          (LTE_MBSFN_AreaInfoList_r9_t *) NULL,
+          (LTE_MBSFNAreaConfiguration_r9_t *) NULL
+        );
+        break;
       } // case
 
       default:
         AssertFatal(1==0,
-        "Unknown message\n");
+                    "Unknown message\n");
         break;
     }// switch case
-    return(0);
-  } else if (srb_id == 1) { 
 
-    LTE_DL_DCCH_Message_t* dl_dcch_msg=NULL;
+    return(0);
+  } else if (srb_id == 1) {
+    LTE_DL_DCCH_Message_t *dl_dcch_msg=NULL;
     asn_dec_rval_t dec_rval;
     dec_rval = uper_decode(NULL,
-         &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);
-    
-    if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0)) 
+                           &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);
+
+    if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0))
       LOG_E(F1AP," Failed to decode DL-DCCH (%zu bytes)\n",dec_rval.consumed);
     else
       LOG_D(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 == LTE_DL_DCCH_MessageType_PR_c1) {
-     
       switch (dl_dcch_msg->message.choice.c1.present) {
-	
-      case LTE_DL_DCCH_MessageType__c1_PR_NOTHING:
-        LOG_I(F1AP, "Received PR_NOTHING on DL-DCCH-Message\n");
-        return 0;
-      case LTE_DL_DCCH_MessageType__c1_PR_dlInformationTransfer:
-        LOG_I(F1AP,"Received NAS DL Information Transfer\n");
-        break;	
-      case LTE_DL_DCCH_MessageType__c1_PR_csfbParametersResponseCDMA2000:
-        LOG_I(F1AP,"Received NAS sfbParametersResponseCDMA2000\n");
-        break;  
-      case LTE_DL_DCCH_MessageType__c1_PR_handoverFromEUTRAPreparationRequest:
-        LOG_I(F1AP,"Received NAS andoverFromEUTRAPreparationRequest\n");
-        break;  
-      case LTE_DL_DCCH_MessageType__c1_PR_mobilityFromEUTRACommand:
-        LOG_I(F1AP,"Received NAS mobilityFromEUTRACommand\n");
-        break;
-      case LTE_DL_DCCH_MessageType__c1_PR_rrcConnectionReconfiguration:
-	     // handle RRCConnectionReconfiguration
-        LOG_I(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));
-	
-        LTE_RRCConnectionReconfiguration_t* rrcConnectionReconfiguration = &dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration;
-
-        if (rrcConnectionReconfiguration->criticalExtensions.present == LTE_RRCConnectionReconfiguration__criticalExtensions_PR_c1) {
-	        if (rrcConnectionReconfiguration->criticalExtensions.choice.c1.present ==
-	         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) {
-	            LOG_I(F1AP, "Mobility Control Information is present\n");
-	            AssertFatal(1==0,"Can't handle this yet in DU\n");
-	          }
-	          if (rrcConnectionReconfiguration_r8->measConfig != NULL) {
-	            LOG_I(F1AP, "Measurement Configuration is present\n");
-	          } 
-	    
-      	    if (rrcConnectionReconfiguration_r8->radioResourceConfigDedicated) {
-              LOG_I(F1AP, "Radio Resource Configuration is present\n");
-      	      uint8_t DRB2LCHAN[8];
-              long drb_id;
-              int i;
-              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  = NULL;
-              
-              for (i = 0; i< 8; i++){
-                DRB2LCHAN[i] = 0;
+        case LTE_DL_DCCH_MessageType__c1_PR_NOTHING:
+          LOG_I(F1AP, "Received PR_NOTHING on DL-DCCH-Message\n");
+          return 0;
+
+        case LTE_DL_DCCH_MessageType__c1_PR_dlInformationTransfer:
+          LOG_I(F1AP,"Received NAS DL Information Transfer\n");
+          break;
+
+        case LTE_DL_DCCH_MessageType__c1_PR_csfbParametersResponseCDMA2000:
+          LOG_I(F1AP,"Received NAS sfbParametersResponseCDMA2000\n");
+          break;
+
+        case LTE_DL_DCCH_MessageType__c1_PR_handoverFromEUTRAPreparationRequest:
+          LOG_I(F1AP,"Received NAS andoverFromEUTRAPreparationRequest\n");
+          break;
+
+        case LTE_DL_DCCH_MessageType__c1_PR_mobilityFromEUTRACommand:
+          LOG_I(F1AP,"Received NAS mobilityFromEUTRACommand\n");
+          break;
+
+        case LTE_DL_DCCH_MessageType__c1_PR_rrcConnectionReconfiguration:
+          // handle RRCConnectionReconfiguration
+          LOG_I(F1AP,
+                "Logical Channel DL-DCCH (SRB1), Received RRCConnectionReconfiguration DU_ID %lx/RNTI %x\n",
+                du_ue_f1ap_id,
+                f1ap_get_rnti_by_du_id(DUtype, instance, du_ue_f1ap_id));
+          LTE_RRCConnectionReconfiguration_t *rrcConnectionReconfiguration = &dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration;
+
+          if (rrcConnectionReconfiguration->criticalExtensions.present == LTE_RRCConnectionReconfiguration__criticalExtensions_PR_c1) {
+            if (rrcConnectionReconfiguration->criticalExtensions.choice.c1.present ==
+                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) {
+                LOG_I(F1AP, "Mobility Control Information is present\n");
+                AssertFatal(1==0,"Can't handle this yet in DU\n");
               }
 
-              if (rrcConnectionReconfiguration_r8->radioResourceConfigDedicated->mac_MainConfig) {
-                LOG_D(F1AP, "MAC Main Configuration is present\n");
+              if (rrcConnectionReconfiguration_r8->measConfig != NULL) {
+                LOG_I(F1AP, "Measurement Configuration is present\n");
+              }
 
-                mac_MainConfig = &rrcConnectionReconfiguration_r8->radioResourceConfigDedicated->mac_MainConfig->choice.explicitValue;
+              if (rrcConnectionReconfiguration_r8->radioResourceConfigDedicated) {
+                LOG_I(F1AP, "Radio Resource Configuration is present\n");
+                uint8_t DRB2LCHAN[8];
+                long drb_id;
+                int i;
+                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  = NULL;
 
-                /* CDRX Configuration */
-                if (mac_MainConfig->drx_Config == NULL) {
-                  LOG_W(F1AP, "drx_Configuration parameter is NULL, cannot configure local UE parameters or CDRX is deactivated\n");
-                } else {
-                  MessageDef *message_p = NULL;
+                for (i = 0; i< 8; i++) {
+                  DRB2LCHAN[i] = 0;
+                }
+
+                if (rrcConnectionReconfiguration_r8->radioResourceConfigDedicated->mac_MainConfig) {
+                  LOG_D(F1AP, "MAC Main Configuration is present\n");
+                  mac_MainConfig = &rrcConnectionReconfiguration_r8->radioResourceConfigDedicated->mac_MainConfig->choice.explicitValue;
 
-                  /* Send DRX configuration to MAC task to configure timers of local UE context */
-                  message_p = itti_alloc_new_message(TASK_DU_F1, 0, RRC_MAC_DRX_CONFIG_REQ);
-                  RRC_MAC_DRX_CONFIG_REQ(message_p).rnti = ctxt.rnti;
-                  RRC_MAC_DRX_CONFIG_REQ(message_p).drx_Configuration = mac_MainConfig->drx_Config;
-                  itti_send_msg_to_task(TASK_MAC_ENB, ctxt.module_id, message_p);
-                  LOG_D(F1AP, "DRX configured in MAC Main Configuration for RRC Connection Reconfiguration\n");
+                  /* CDRX Configuration */
+                  if (mac_MainConfig->drx_Config == NULL) {
+                    LOG_W(F1AP, "drx_Configuration parameter is NULL, cannot configure local UE parameters or CDRX is deactivated\n");
+                  } else {
+                    MessageDef *message_p = NULL;
+                    /* Send DRX configuration to MAC task to configure timers of local UE context */
+                    message_p = itti_alloc_new_message(TASK_DU_F1, 0, RRC_MAC_DRX_CONFIG_REQ);
+                    RRC_MAC_DRX_CONFIG_REQ(message_p).rnti = ctxt.rnti;
+                    RRC_MAC_DRX_CONFIG_REQ(message_p).drx_Configuration = mac_MainConfig->drx_Config;
+                    itti_send_msg_to_task(TASK_MAC_ENB, ctxt.instance, message_p);
+                    LOG_D(F1AP, "DRX configured in MAC Main Configuration for RRC Connection Reconfiguration\n");
+                  }
+
+                  /* End of CDRX configuration */
                 }
-                /* End of CDRX configuration */
-              }
 
-              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, (LTE_PMCH_InfoList_r9_t *) NULL, 0, 0
+                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, (LTE_PMCH_InfoList_r9_t *) NULL, 0, 0
                 );
 
-              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_p->ue_context.Srb1.Active=1;
+                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_p->ue_context.Srb1.Active=1;
+                    } else if (SRB_configList->list.array[i]->srb_Identity == 2 )  {
+                      ue_context_p->ue_context.Srb2.Active=1;
+                      ue_context_p->ue_context.Srb2.Srb_info.Srb_id=2;
+                      LOG_I(F1AP, "[DU %ld] SRB2 is now active\n",ctxt.instance);
+                    } else {
+                      LOG_W(F1AP, "[DU %ld] invalid SRB identity %ld\n",ctxt.instance,
+                            SRB_configList->list.array[i]->srb_Identity);
+                    }
                   }
-                  else if (SRB_configList->list.array[i]->srb_Identity == 2 )  {
-                    ue_context_p->ue_context.Srb2.Active=1;
-                    ue_context_p->ue_context.Srb2.Srb_info.Srb_id=2;
-                    LOG_I(F1AP, "[DU %d] SRB2 is now active\n",ctxt.module_id);
-                  } else {
-                    LOG_W(F1AP, "[DU %d] invalide SRB identity %ld\n",ctxt.module_id,
-                   SRB_configList->list.array[i]->srb_Identity);
+                }
+
+                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;
+                      LOG_I(F1AP,
+                            "[DU %ld] Logical Channel UL-DCCH, Received RRCConnectionReconfiguration for UE rnti %x, reconfiguring DRB %d/LCID %d\n",
+                            ctxt.instance,
+                            ctxt.rnti,
+                            (int)DRB_configList->list.array[i]->drb_Identity,
+                            (int)*DRB_configList->list.array[i]->logicalChannelIdentity);
+
+                      if (ue_context_p->ue_context.DRB_active[drb_id] == 0) {
+                        ue_context_p->ue_context.DRB_active[drb_id] = 1;
+
+                        if (DRB_configList->list.array[i]->logicalChannelIdentity) {
+                          DRB2LCHAN[i] = (uint8_t) * DRB_configList->list.array[i]->logicalChannelIdentity;
+                        }
+
+                        rrc_mac_config_req_eNB(
+                          ctxt.instance,
+                          0,0,0,0,0,0,
+                          0,
+                          ue_context_p->ue_context.rnti,
+                          (LTE_BCCH_BCH_Message_t *) NULL,
+                          (LTE_RadioResourceConfigCommonSIB_t *) NULL,
+                          (LTE_RadioResourceConfigCommonSIB_t *) NULL,
+                          physicalConfigDedicated,
+                          (LTE_SCellToAddMod_r10_t *)NULL,
+                          //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
+                          (LTE_MeasObjectToAddMod_t **) NULL,
+                          mac_MainConfig,
+                          DRB2LCHAN[i],
+                          DRB_configList->list.array[i]->logicalChannelConfig,
+                          measGapConfig,
+                          (LTE_TDD_Config_t *) NULL,
+                          NULL,
+                          (LTE_SchedulingInfoList_t *) NULL,
+                          0, NULL, NULL, (LTE_MBSFN_SubframeConfigList_t *) NULL
+                          , 0, (LTE_MBSFN_AreaInfoList_r9_t *) NULL, (LTE_PMCH_InfoList_r9_t *) NULL,
+                          (LTE_SystemInformationBlockType1_v1310_IEs_t *)NULL,
+                          0,
+                          (LTE_BCCH_DL_SCH_Message_MBMS_t *) NULL,
+                          (LTE_SchedulingInfo_MBMS_r14_t *) NULL,
+                          (struct LTE_NonMBSFN_SubframeConfig_r14 *) NULL,
+                          (LTE_SystemInformationBlockType1_MBMS_r14_t *) NULL,
+                          (LTE_MBSFN_AreaInfoList_r9_t *) NULL,
+                          (LTE_MBSFNAreaConfiguration_r9_t *) NULL
+                        );
+                      }
+                    } else {        // remove LCHAN from MAC/PHY
+                      AssertFatal(1==0,"Can't handle this yet in DU\n");
+                    }
                   }
                 }
               }
+            }
+          }
 
-              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;
-                    LOG_I(F1AP,
-                          "[DU %d] Logical Channel UL-DCCH, Received RRCConnectionReconfiguration for UE rnti %x, reconfiguring DRB %d/LCID %d\n",
-                          ctxt.module_id,
-                          ctxt.rnti,
-                          (int)DRB_configList->list.array[i]->drb_Identity,
-                          (int)*DRB_configList->list.array[i]->logicalChannelIdentity);
-
-                  if (ue_context_p->ue_context.DRB_active[drb_id] == 0) {
-                    ue_context_p->ue_context.DRB_active[drb_id] = 1;
-
-                    if (DRB_configList->list.array[i]->logicalChannelIdentity) {
-                      DRB2LCHAN[i] = (uint8_t) * DRB_configList->list.array[i]->logicalChannelIdentity;
-                    }
+          break;
 
-                     rrc_mac_config_req_eNB(
-                     ctxt.module_id,
-                     0,0,0,0,0,0,
-                     0,
-                     ue_context_p->ue_context.rnti,
-                     (LTE_BCCH_BCH_Message_t *) NULL,
-                     (LTE_RadioResourceConfigCommonSIB_t *) NULL,
-                     (LTE_RadioResourceConfigCommonSIB_t *) NULL,
-                     physicalConfigDedicated,
-                     (LTE_SCellToAddMod_r10_t *)NULL,
-                     //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
-                     (LTE_MeasObjectToAddMod_t **) NULL,
-                     mac_MainConfig,
-                     DRB2LCHAN[i],
-                     DRB_configList->list.array[i]->logicalChannelConfig,
-                     measGapConfig,
-                     (LTE_TDD_Config_t *) NULL,
-                     NULL,
-                     (LTE_SchedulingInfoList_t *) NULL,
-                     0, NULL, NULL, (LTE_MBSFN_SubframeConfigList_t *) NULL
-                     , 0, (LTE_MBSFN_AreaInfoList_r9_t *) NULL, (LTE_PMCH_InfoList_r9_t *) NULL,
-                     (LTE_SystemInformationBlockType1_v1310_IEs_t *)NULL,
-                     0,
-                     (LTE_BCCH_DL_SCH_Message_MBMS_t *) NULL,
-                     (LTE_SchedulingInfo_MBMS_r14_t *) NULL,
-                     (struct LTE_NonMBSFN_SubframeConfig_r14 *) NULL,
-                     (LTE_SystemInformationBlockType1_MBMS_r14_t *) NULL,
-                     (LTE_MBSFN_AreaInfoList_r9_t *) NULL,
-                     (LTE_MBSFNAreaConfiguration_r9_t*) NULL
-                     );
-                  }
+        case LTE_DL_DCCH_MessageType__c1_PR_rrcConnectionRelease:
+          // handle RRCConnectionRelease
+          LOG_I(F1AP, "Received RRCConnectionRelease\n");
+          break;
 
-                } else {        // remove LCHAN from MAC/PHY
-                  AssertFatal(1==0,"Can't handle this yet in DU\n");  
-                } 
-        	     }
-        	   }
-           }
-         }
-       }
-	    break;
-      case LTE_DL_DCCH_MessageType__c1_PR_rrcConnectionRelease:
-  	    // handle RRCConnectionRelease
-        LOG_I(F1AP, "Received RRCConnectionRelease\n");
-  	    break;
-      case LTE_DL_DCCH_MessageType__c1_PR_securityModeCommand:
-        LOG_I(F1AP, "Received securityModeCommand\n");
-          break; 
-      case LTE_DL_DCCH_MessageType__c1_PR_ueCapabilityEnquiry:
-        LOG_I(F1AP, "Received ueCapabilityEnquiry\n");
+        case LTE_DL_DCCH_MessageType__c1_PR_securityModeCommand:
+          LOG_I(F1AP, "Received securityModeCommand\n");
           break;
-      case LTE_DL_DCCH_MessageType__c1_PR_counterCheck:
-      case LTE_DL_DCCH_MessageType__c1_PR_loggedMeasurementConfiguration_r10:
-      case LTE_DL_DCCH_MessageType__c1_PR_rnReconfiguration_r10:
-      case LTE_DL_DCCH_MessageType__c1_PR_spare1:
-      case LTE_DL_DCCH_MessageType__c1_PR_spare2:
-      case LTE_DL_DCCH_MessageType__c1_PR_spare3:
-  	    break;
-      case LTE_DL_DCCH_MessageType__c1_PR_ueInformationRequest_r9:
-        LOG_I(F1AP, "Received ueInformationRequest_r9\n");
-        break;
-      case LTE_DL_DCCH_MessageType__c1_PR_rrcConnectionResume_r13:
-        LOG_I(F1AP, "Received rrcConnectionResume_r13\n");
-	   } 
-	 }	
-  }
-  else if (srb_id == 2) {
-    
+
+        case LTE_DL_DCCH_MessageType__c1_PR_ueCapabilityEnquiry:
+          LOG_I(F1AP, "Received ueCapabilityEnquiry\n");
+          break;
+
+        case LTE_DL_DCCH_MessageType__c1_PR_counterCheck:
+        case LTE_DL_DCCH_MessageType__c1_PR_loggedMeasurementConfiguration_r10:
+        case LTE_DL_DCCH_MessageType__c1_PR_rnReconfiguration_r10:
+        case LTE_DL_DCCH_MessageType__c1_PR_spare1:
+        case LTE_DL_DCCH_MessageType__c1_PR_spare2:
+        case LTE_DL_DCCH_MessageType__c1_PR_spare3:
+          break;
+
+        case LTE_DL_DCCH_MessageType__c1_PR_ueInformationRequest_r9:
+          LOG_I(F1AP, "Received ueInformationRequest_r9\n");
+          break;
+
+        case LTE_DL_DCCH_MessageType__c1_PR_rrcConnectionResume_r13:
+          LOG_I(F1AP, "Received rrcConnectionResume_r13\n");
+      }
+    }
+  } else if (srb_id == 2) {
   }
 
   LOG_I(F1AP, "Received DL RRC Transfer on srb_id %ld\n", srb_id);
   rlc_op_status_t    rlc_status;
   boolean_t          ret             = TRUE;
-  mem_block_t       *pdcp_pdu_p      = NULL; 
+  mem_block_t       *pdcp_pdu_p      = NULL;
   pdcp_pdu_p = get_free_mem_block(rrc_dl_sdu_len, __func__);
 
   //LOG_I(F1AP, "PRRCContainer size %lu:", ie->value.choice.RRCContainer.size);
@@ -556,75 +521,68 @@ int DU_handle_DL_RRC_MESSAGE_TRANSFER(instance_t       instance,
   //for (int i=0;i<rrc_dl_sdu_len;i++) printf("%2x ",pdcp_pdu_p->data[i]);
   //printf("\n");
 
-
   if (pdcp_pdu_p != NULL) {
     memset(pdcp_pdu_p->data, 0, rrc_dl_sdu_len);
     memcpy(&pdcp_pdu_p->data[0], ie->value.choice.RRCContainer.buf, rrc_dl_sdu_len);
+    rlc_status = rlc_data_req(&ctxt
+                              , 1
+                              , MBMS_FLAG_NO
+                              , srb_id
+                              , 0
+                              , 0
+                              , rrc_dl_sdu_len
+                              , pdcp_pdu_p
+                              ,NULL
+                              ,NULL
+                             );
 
-      rlc_status = rlc_data_req(&ctxt
-                                , 1
-                                , MBMS_FLAG_NO
-                                , srb_id
-                                , 0
-                                , 0
-                                , rrc_dl_sdu_len
-                                , pdcp_pdu_p
-                                ,NULL
-                                ,NULL
-                                );
-      switch (rlc_status) {
-        case RLC_OP_STATUS_OK:
-          //LOG_I(F1AP, "Data sending request over RLC succeeded!\n");
-          ret=TRUE;
-          break;
+    switch (rlc_status) {
+      case RLC_OP_STATUS_OK:
+        //LOG_I(F1AP, "Data sending request over RLC succeeded!\n");
+        ret=TRUE;
+        break;
 
-        case RLC_OP_STATUS_BAD_PARAMETER:
-          LOG_W(F1AP, "Data sending request over RLC failed with 'Bad Parameter' reason!\n");
-          ret= FALSE;
-          break;
+      case RLC_OP_STATUS_BAD_PARAMETER:
+        LOG_W(F1AP, "Data sending request over RLC failed with 'Bad Parameter' reason!\n");
+        ret= FALSE;
+        break;
 
-        case RLC_OP_STATUS_INTERNAL_ERROR:
-          LOG_W(F1AP, "Data sending request over RLC failed with 'Internal Error' reason!\n");
-          ret= FALSE;
-          break;
+      case RLC_OP_STATUS_INTERNAL_ERROR:
+        LOG_W(F1AP, "Data sending request over RLC failed with 'Internal Error' reason!\n");
+        ret= FALSE;
+        break;
 
-        case RLC_OP_STATUS_OUT_OF_RESSOURCES:
-          LOG_W(F1AP, "Data sending request over RLC failed with 'Out of Resources' reason!\n");
-          ret= FALSE;
-          break;
+      case RLC_OP_STATUS_OUT_OF_RESSOURCES:
+        LOG_W(F1AP, "Data sending request over RLC failed with 'Out of Resources' reason!\n");
+        ret= FALSE;
+        break;
+
+      default:
+        LOG_W(F1AP, "RLC returned an unknown status code after PDCP placed the order to send some data (Status Code:%d)\n", rlc_status);
+        ret= FALSE;
+        break;
+    } // switch case
+
+    return ret;
+  } // if pdcp_pdu_p
 
-        default:
-          LOG_W(F1AP, "RLC returned an unknown status code after PDCP placed the order to send some data (Status Code:%d)\n", rlc_status);
-          ret= FALSE;
-          break;
-      } // switch case
-      return ret; 
-    } // if pdcp_pdu_p
-  
   return 0;
-  
 }
 
-int DU_send_UL_RRC_MESSAGE_TRANSFER(instance_t instance, 
+int DU_send_UL_RRC_MESSAGE_TRANSFER(instance_t instance,
                                     const f1ap_ul_rrc_message_t *msg) {
   const rnti_t rnti = msg->rnti;
-
   F1AP_F1AP_PDU_t                pdu;
   F1AP_ULRRCMessageTransfer_t    *out;
   F1AP_ULRRCMessageTransferIEs_t *ie;
-
   uint8_t *buffer = NULL;
   uint32_t len;
-
-
   LOG_I(F1AP, "[DU %ld] %s: size %d UE RNTI %x in SRB %d\n",
         instance, __func__, msg->rrc_container_length, rnti, msg->srb_id);
-
   //LOG_I(F1AP, "%s() RRCContainer size %d: ", __func__, msg->rrc_container_length);
   //for (int i = 0;i < msg->rrc_container_length; i++)
   //  printf("%02x ", msg->rrc_container[i]);
   //printf("\n");
-
   /* Create */
   /* 0. Message Type */
   memset(&pdu, 0, sizeof(pdu));
@@ -634,27 +592,22 @@ int DU_send_UL_RRC_MESSAGE_TRANSFER(instance_t instance,
   pdu.choice.initiatingMessage->criticality   = F1AP_Criticality_ignore;
   pdu.choice.initiatingMessage->value.present = F1AP_InitiatingMessage__value_PR_ULRRCMessageTransfer;
   out = &pdu.choice.initiatingMessage->value.choice.ULRRCMessageTransfer;
-  
   /* mandatory */
   /* c1. GNB_CU_UE_F1AP_ID */
   ie = (F1AP_ULRRCMessageTransferIEs_t *)calloc(1, sizeof(F1AP_ULRRCMessageTransferIEs_t));
   ie->id                             = F1AP_ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
   ie->criticality                    = F1AP_Criticality_reject;
   ie->value.present                  = F1AP_ULRRCMessageTransferIEs__value_PR_GNB_CU_UE_F1AP_ID;
-
-  ie->value.choice.GNB_CU_UE_F1AP_ID = f1ap_get_cu_ue_f1ap_id(&f1ap_du_inst[instance], rnti);
-
+  ie->value.choice.GNB_CU_UE_F1AP_ID = f1ap_get_cu_ue_f1ap_id(DUtype, instance, rnti);
   ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
   /* mandatory */
   /* c2. GNB_DU_UE_F1AP_ID */
   ie = (F1AP_ULRRCMessageTransferIEs_t *)calloc(1, sizeof(F1AP_ULRRCMessageTransferIEs_t));
   ie->id                             = F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
   ie->criticality                    = F1AP_Criticality_reject;
   ie->value.present                  = F1AP_ULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
-  ie->value.choice.GNB_DU_UE_F1AP_ID = f1ap_get_du_ue_f1ap_id(&f1ap_du_inst[instance], rnti);
+  ie->value.choice.GNB_DU_UE_F1AP_ID = f1ap_get_du_ue_f1ap_id(DUtype, instance, rnti);
   ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
   /* mandatory */
   /* c3. SRBID */
   ie = (F1AP_ULRRCMessageTransferIEs_t *)calloc(1, sizeof(F1AP_ULRRCMessageTransferIEs_t));
@@ -663,7 +616,6 @@ int DU_send_UL_RRC_MESSAGE_TRANSFER(instance_t instance,
   ie->value.present                 = F1AP_ULRRCMessageTransferIEs__value_PR_SRBID;
   ie->value.choice.SRBID            = msg->srb_id;
   ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
   // issue in here
   /* mandatory */
   /* c4. RRCContainer */
@@ -677,138 +629,132 @@ int DU_send_UL_RRC_MESSAGE_TRANSFER(instance_t instance,
   ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
 
   if (msg->srb_id == 1 || msg->srb_id == 2) {
-    struct rrc_eNB_ue_context_s* ue_context_p = rrc_eNB_get_ue_context(RC.rrc[instance], rnti);
-
-   
-    LTE_UL_DCCH_Message_t* ul_dcch_msg=NULL;
+    struct rrc_eNB_ue_context_s *ue_context_p = rrc_eNB_get_ue_context(RC.rrc[instance], rnti);
+    LTE_UL_DCCH_Message_t *ul_dcch_msg=NULL;
     asn_dec_rval_t dec_rval;
     dec_rval = uper_decode(NULL,
-         &asn_DEF_LTE_UL_DCCH_Message,
-         (void**)&ul_dcch_msg,
-         &ie->value.choice.RRCContainer.buf[1], // buf[0] includes the pdcp header
-         msg->rrc_container_length, 0, 0);
-    
-    if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0)) 
+                           &asn_DEF_LTE_UL_DCCH_Message,
+                           (void **)&ul_dcch_msg,
+                           &ie->value.choice.RRCContainer.buf[1], // buf[0] includes the pdcp header
+                           msg->rrc_container_length, 0, 0);
+
+    if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0))
       LOG_E(F1AP, " Failed to decode UL-DCCH (%zu bytes)\n",dec_rval.consumed);
     else
       LOG_I(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 == LTE_UL_DCCH_MessageType_PR_c1) {
-
       switch (ul_dcch_msg->message.choice.c1.present) {
-      case LTE_UL_DCCH_MessageType__c1_PR_NOTHING:   /* No components present */
-        break;
+        case LTE_UL_DCCH_MessageType__c1_PR_NOTHING:   /* No components present */
+          break;
 
-      case LTE_UL_DCCH_MessageType__c1_PR_csfbParametersRequestCDMA2000:
-        break;
+        case LTE_UL_DCCH_MessageType__c1_PR_csfbParametersRequestCDMA2000:
+          break;
 
-      case LTE_UL_DCCH_MessageType__c1_PR_measurementReport:
-        break;
+        case LTE_UL_DCCH_MessageType__c1_PR_measurementReport:
+          break;
+
+        case LTE_UL_DCCH_MessageType__c1_PR_rrcConnectionReconfigurationComplete:
+          LOG_I(F1AP, "[MSG] RRC UL rrcConnectionReconfigurationComplete\n");
+          /* CDRX: activated when RRC Connection Reconfiguration Complete is received */
+          int UE_id_mac = find_UE_id(instance, rnti);
+
+          if (UE_id_mac == -1) {
+            LOG_E(F1AP, "Can't find UE_id(MAC) of UE rnti %x\n", rnti);
+            break;
+          }
 
-      case LTE_UL_DCCH_MessageType__c1_PR_rrcConnectionReconfigurationComplete:
-        LOG_I(F1AP, "[MSG] RRC UL rrcConnectionReconfigurationComplete\n");
-        
-        /* CDRX: activated when RRC Connection Reconfiguration Complete is received */
-        int UE_id_mac = find_UE_id(instance, rnti);
-        
-        if (UE_id_mac == -1) {
-          LOG_E(F1AP, "Can't find UE_id(MAC) of UE rnti %x\n", rnti);
+          UE_sched_ctrl_t *UE_scheduling_control = &(RC.mac[instance]->UE_info.UE_sched_ctrl[UE_id_mac]);
+
+          if (UE_scheduling_control->cdrx_waiting_ack == TRUE) {
+            UE_scheduling_control->cdrx_waiting_ack = FALSE;
+            UE_scheduling_control->cdrx_configured = TRUE; // Set to TRUE when RRC Connection Reconfiguration Complete is received
+            LOG_I(F1AP, "CDRX configuration activated after RRC Connection Reconfiguration Complete reception\n");
+          }
+
+          /* End of CDRX processing */
           break;
-        }
-        
-        UE_sched_ctrl_t *UE_scheduling_control = &(RC.mac[instance]->UE_info.UE_sched_ctrl[UE_id_mac]);
-        
-        if (UE_scheduling_control->cdrx_waiting_ack == TRUE) {
-          UE_scheduling_control->cdrx_waiting_ack = FALSE;
-          UE_scheduling_control->cdrx_configured = TRUE; // Set to TRUE when RRC Connection Reconfiguration Complete is received
-          LOG_I(F1AP, "CDRX configuration activated after RRC Connection Reconfiguration Complete reception\n");
-        }
-        /* End of CDRX processing */
-        
-        break;
 
-      case LTE_UL_DCCH_MessageType__c1_PR_rrcConnectionReestablishmentComplete:
-        break;
+        case LTE_UL_DCCH_MessageType__c1_PR_rrcConnectionReestablishmentComplete:
+          break;
 
-      case LTE_UL_DCCH_MessageType__c1_PR_rrcConnectionSetupComplete:
-        LOG_I(F1AP, "[MSG] RRC UL rrcConnectionSetupComplete \n");
-        
-        if(!ue_context_p){
-          LOG_E(F1AP, "Did not find the UE context associated with UE RNTOI %x, ue_context_p is NULL\n", rnti);
+        case LTE_UL_DCCH_MessageType__c1_PR_rrcConnectionSetupComplete:
+          LOG_I(F1AP, "[MSG] RRC UL rrcConnectionSetupComplete \n");
 
-        } else {
-          LOG_I(F1AP, "Processing RRCConnectionSetupComplete UE %x\n", rnti);
-          ue_context_p->ue_context.StatusRrc = RRC_CONNECTED;
-        }
-        break;
+          if(!ue_context_p) {
+            LOG_E(F1AP, "Did not find the UE context associated with UE RNTOI %x, ue_context_p is NULL\n", rnti);
+          } else {
+            LOG_I(F1AP, "Processing RRCConnectionSetupComplete UE %x\n", rnti);
+            ue_context_p->ue_context.StatusRrc = RRC_CONNECTED;
+          }
 
-      case LTE_UL_DCCH_MessageType__c1_PR_securityModeComplete:
-        LOG_I(F1AP, "[MSG] RRC securityModeComplete \n");
-        break;
+          break;
 
-      case LTE_UL_DCCH_MessageType__c1_PR_securityModeFailure:
-        break;
+        case LTE_UL_DCCH_MessageType__c1_PR_securityModeComplete:
+          LOG_I(F1AP, "[MSG] RRC securityModeComplete \n");
+          break;
 
-      case LTE_UL_DCCH_MessageType__c1_PR_ueCapabilityInformation:
-        LOG_I(F1AP, "[MSG] RRC ueCapabilityInformation \n");
-        break;
+        case LTE_UL_DCCH_MessageType__c1_PR_securityModeFailure:
+          break;
 
-      case LTE_UL_DCCH_MessageType__c1_PR_ulHandoverPreparationTransfer:
-        break;
+        case LTE_UL_DCCH_MessageType__c1_PR_ueCapabilityInformation:
+          LOG_I(F1AP, "[MSG] RRC ueCapabilityInformation \n");
+          break;
 
-      case LTE_UL_DCCH_MessageType__c1_PR_ulInformationTransfer:
-        LOG_I(F1AP,"[MSG] RRC UL Information Transfer \n");
-        break;
+        case LTE_UL_DCCH_MessageType__c1_PR_ulHandoverPreparationTransfer:
+          break;
 
-      case LTE_UL_DCCH_MessageType__c1_PR_counterCheckResponse:
-        break;
+        case LTE_UL_DCCH_MessageType__c1_PR_ulInformationTransfer:
+          LOG_I(F1AP,"[MSG] RRC UL Information Transfer \n");
+          break;
 
-      case LTE_UL_DCCH_MessageType__c1_PR_ueInformationResponse_r9:
-        break;
+        case LTE_UL_DCCH_MessageType__c1_PR_counterCheckResponse:
+          break;
 
-      case LTE_UL_DCCH_MessageType__c1_PR_proximityIndication_r9:
-       break;
+        case LTE_UL_DCCH_MessageType__c1_PR_ueInformationResponse_r9:
+          break;
 
-      case LTE_UL_DCCH_MessageType__c1_PR_rnReconfigurationComplete_r10:
-        break;
+        case LTE_UL_DCCH_MessageType__c1_PR_proximityIndication_r9:
+          break;
+
+        case LTE_UL_DCCH_MessageType__c1_PR_rnReconfigurationComplete_r10:
+          break;
 
-      case LTE_UL_DCCH_MessageType__c1_PR_mbmsCountingResponse_r10:
-       break;
+        case LTE_UL_DCCH_MessageType__c1_PR_mbmsCountingResponse_r10:
+          break;
 
-      case LTE_UL_DCCH_MessageType__c1_PR_interFreqRSTDMeasurementIndication_r10:
-       break;
+        case LTE_UL_DCCH_MessageType__c1_PR_interFreqRSTDMeasurementIndication_r10:
+          break;
       }
     }
   }
-    /* encode */
+
+  /* encode */
   if (f1ap_encode_pdu(&pdu, &buffer, &len) < 0) {
     LOG_E(F1AP, "Failed to encode F1 UL RRC MESSAGE TRANSFER\n");
     return -1;
   }
 
-  du_f1ap_itti_send_sctp_data_req(instance, f1ap_du_data->assoc_id, buffer, len, f1ap_du_data->default_sctp_stream_id);
+  ASN_STRUCT_RESET(asn_DEF_F1AP_F1AP_PDU, &pdu);
+  f1ap_itti_send_sctp_data_req(false, instance, buffer, len, getCxt(DUtype, instance)->default_sctp_stream_id);
   return 0;
 }
 
-
 /*  UL RRC Message Transfer */
-int DU_send_INITIAL_UL_RRC_MESSAGE_TRANSFER(module_id_t     module_idP,
-                                            int             CC_idP,
-                                            int             UE_id,
-                                            rnti_t          rntiP,
-                                            const uint8_t   *sduP,
-                                            sdu_size_t      sdu_lenP,
-                                            const int8_t   *sdu2P,
-					                                  sdu_size_t      sdu2_lenP) {
-
-  F1AP_F1AP_PDU_t                       pdu;
+int DU_send_INITIAL_UL_RRC_MESSAGE_TRANSFER(instance_t     instanceP,
+    int             CC_idP,
+    int             UE_id,
+    rnti_t          rntiP,
+    const uint8_t   *sduP,
+    sdu_size_t      sdu_lenP,
+    const char      *sdu2P,
+    sdu_size_t      sdu2_lenP) {
+  F1AP_F1AP_PDU_t                       pdu= {0};
   F1AP_InitialULRRCMessageTransfer_t    *out;
-  F1AP_InitialULRRCMessageTransferIEs_t *ie;
-
-  uint8_t  *buffer;
-  uint32_t  len;
-  int f1ap_uid = f1ap_add_ue (&f1ap_du_inst[module_idP], module_idP, CC_idP,UE_id, rntiP);
+  uint8_t  *buffer=NULL;
+  uint32_t  len=0;
+  int f1ap_uid = f1ap_add_ue (DUtype, instanceP, rntiP);
 
   if (f1ap_uid  < 0 ) {
     LOG_E(F1AP, "Failed to add UE \n");
@@ -817,227 +763,157 @@ int DU_send_INITIAL_UL_RRC_MESSAGE_TRANSFER(module_id_t     module_idP,
 
   /* Create */
   /* 0. Message Type */
-  memset(&pdu, 0, sizeof(pdu));
   pdu.present = F1AP_F1AP_PDU_PR_initiatingMessage;
-  pdu.choice.initiatingMessage = (F1AP_InitiatingMessage_t *)calloc(1, sizeof(F1AP_InitiatingMessage_t));
-  pdu.choice.initiatingMessage->procedureCode = F1AP_ProcedureCode_id_InitialULRRCMessageTransfer;
-  pdu.choice.initiatingMessage->criticality   = F1AP_Criticality_ignore;
-  pdu.choice.initiatingMessage->value.present = F1AP_InitiatingMessage__value_PR_InitialULRRCMessageTransfer;
-  out = &pdu.choice.initiatingMessage->value.choice.InitialULRRCMessageTransfer;
-  
-
+  asn1cCalloc(pdu.choice.initiatingMessage, tmp);
+  tmp->procedureCode = F1AP_ProcedureCode_id_InitialULRRCMessageTransfer;
+  tmp->criticality   = F1AP_Criticality_ignore;
+  tmp->value.present = F1AP_InitiatingMessage__value_PR_InitialULRRCMessageTransfer;
+  out = &tmp->value.choice.InitialULRRCMessageTransfer;
   /* mandatory */
   /* c1. GNB_DU_UE_F1AP_ID */
-  ie = (F1AP_InitialULRRCMessageTransferIEs_t *)calloc(1, sizeof(F1AP_InitialULRRCMessageTransferIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
-  ie->criticality                    = F1AP_Criticality_reject;
-  ie->value.present                  = F1AP_InitialULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
-  ie->value.choice.GNB_DU_UE_F1AP_ID = f1ap_du_inst[module_idP].f1ap_ue[f1ap_uid].du_ue_f1ap_id;
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_InitialULRRCMessageTransferIEs_t, ie1);
+  ie1->id                             = F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
+  ie1->criticality                    = F1AP_Criticality_reject;
+  ie1->value.present                  = F1AP_InitialULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
+  ie1->value.choice.GNB_DU_UE_F1AP_ID = getCxt(DUtype, instanceP)->f1ap_ue[f1ap_uid].du_ue_f1ap_id;
   /* mandatory */
   /* c2. NRCGI */
-  ie = (F1AP_InitialULRRCMessageTransferIEs_t *)calloc(1, sizeof(F1AP_InitialULRRCMessageTransferIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_NRCGI;
-  ie->criticality                    = F1AP_Criticality_reject;
-  ie->value.present                  = F1AP_InitialULRRCMessageTransferIEs__value_PR_NRCGI;
-
-  F1AP_NRCGI_t nRCGI;
-  memset(&nRCGI, 0, sizeof(F1AP_NRCGI_t));
-  MCC_MNC_TO_PLMNID(f1ap_du_data->mcc[0], f1ap_du_data->mnc[0], f1ap_du_data->mnc_digit_length[0],
-                                         &nRCGI.pLMN_Identity);
-  NR_CELL_ID_TO_BIT_STRING(f1ap_du_data->nr_cellid[0], &nRCGI.nRCellIdentity);
-  ie->value.choice.NRCGI = nRCGI;
-
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_InitialULRRCMessageTransferIEs_t, ie2);
+  ie2->id                             = F1AP_ProtocolIE_ID_id_NRCGI;
+  ie2->criticality                    = F1AP_Criticality_reject;
+  ie2->value.present                  = F1AP_InitialULRRCMessageTransferIEs__value_PR_NRCGI;
+  //Fixme: takes always the first cell
+  addnRCGI(ie2->value.choice.NRCGI, getCxt(DUtype, instanceP)->setupReq.cell);
   /* mandatory */
   /* c3. C_RNTI */  // 16
-  ie = (F1AP_InitialULRRCMessageTransferIEs_t *)calloc(1, sizeof(F1AP_InitialULRRCMessageTransferIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_C_RNTI;
-  ie->criticality                    = F1AP_Criticality_reject;
-  ie->value.present                  = F1AP_InitialULRRCMessageTransferIEs__value_PR_C_RNTI;
-  ie->value.choice.C_RNTI=rntiP;
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_InitialULRRCMessageTransferIEs_t, ie3);
+  ie3->id                             = F1AP_ProtocolIE_ID_id_C_RNTI;
+  ie3->criticality                    = F1AP_Criticality_reject;
+  ie3->value.present                  = F1AP_InitialULRRCMessageTransferIEs__value_PR_C_RNTI;
+  ie3->value.choice.C_RNTI=rntiP;
   /* mandatory */
   /* c4. RRCContainer */
-  ie = (F1AP_InitialULRRCMessageTransferIEs_t *)calloc(1, sizeof(F1AP_InitialULRRCMessageTransferIEs_t));
-  ie->id                            = F1AP_ProtocolIE_ID_id_RRCContainer;
-  ie->criticality                   = F1AP_Criticality_reject;
-  ie->value.present                 = F1AP_InitialULRRCMessageTransferIEs__value_PR_RRCContainer;
-  OCTET_STRING_fromBuf(&ie->value.choice.RRCContainer, (const char *)sduP, sdu_lenP);
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_InitialULRRCMessageTransferIEs_t, ie4);
+  ie4->id                            = F1AP_ProtocolIE_ID_id_RRCContainer;
+  ie4->criticality                   = F1AP_Criticality_reject;
+  ie4->value.present                 = F1AP_InitialULRRCMessageTransferIEs__value_PR_RRCContainer;
+  OCTET_STRING_fromBuf(&ie4->value.choice.RRCContainer, (const char *)sduP, sdu_lenP);
 
   /* optional */
   /* c5. DUtoCURRCContainer */
-  if (sdu2P && RC.nrrrc) {
-    ie = (F1AP_InitialULRRCMessageTransferIEs_t *)calloc(1, sizeof(F1AP_InitialULRRCMessageTransferIEs_t));
-    ie->id                             = F1AP_ProtocolIE_ID_id_DUtoCURRCContainer;
-    ie->criticality                    = F1AP_Criticality_reject;
-    ie->value.present                  = F1AP_InitialULRRCMessageTransferIEs__value_PR_DUtoCURRCContainer;
-    OCTET_STRING_fromBuf(&ie->value.choice.DUtoCURRCContainer, (char *)sdu2P, sdu2_lenP);
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-  }    
-
-    /* encode */
+  if (sdu2P) {
+    asn1cSequenceAdd(out->protocolIEs.list, F1AP_InitialULRRCMessageTransferIEs_t, ie5);
+    ie5->id                             = F1AP_ProtocolIE_ID_id_DUtoCURRCContainer;
+    ie5->criticality                    = F1AP_Criticality_reject;
+    ie5->value.present                  = F1AP_InitialULRRCMessageTransferIEs__value_PR_DUtoCURRCContainer;
+    OCTET_STRING_fromBuf(&ie5->value.choice.DUtoCURRCContainer,
+                         sdu2P,
+                         sdu2_lenP);
+  }
+
+  /* encode */
   if (f1ap_encode_pdu(&pdu, &buffer, &len) < 0) {
     LOG_E(F1AP, "Failed to encode F1 INITIAL UL RRC MESSAGE TRANSFER\n");
     return -1;
   }
 
-  if (RC.nrrrc && RC.nrrrc[module_idP]->node_type == ngran_gNB_DU) {
-    struct rrc_gNB_ue_context_s* ue_context_p = rrc_gNB_allocate_new_UE_context(RC.nrrrc[module_idP]);
-    ue_context_p->ue_id_rnti                    = rntiP; 
-    ue_context_p->ue_context.rnti               = rntiP;
-    ue_context_p->ue_context.random_ue_identity = rntiP;
-    ue_context_p->ue_context.Srb0.Active        = 1;
-    RB_INSERT(rrc_nr_ue_tree_s, &RC.nrrrc[module_idP]->rrc_ue_head, ue_context_p);
-  } else {
-    struct rrc_eNB_ue_context_s* ue_context_p = rrc_eNB_allocate_new_UE_context(RC.rrc[module_idP]);
-    ue_context_p->ue_id_rnti                    = rntiP; 
-    ue_context_p->ue_context.rnti               = rntiP;
-    ue_context_p->ue_context.random_ue_identity = rntiP;
-    ue_context_p->ue_context.Srb0.Active        = 1;
-    RB_INSERT(rrc_ue_tree_s, &RC.rrc[module_idP]->rrc_ue_head, ue_context_p);
-  }
-  du_f1ap_itti_send_sctp_data_req(module_idP, f1ap_du_data->assoc_id, buffer, len,  f1ap_du_data->default_sctp_stream_id);
-
+  f1ap_itti_send_sctp_data_req(false, instanceP, buffer, len, getCxt(DUtype, instanceP)->default_sctp_stream_id);
   return 0;
 }
-    
-
-void init_f1ap_du_ue_inst (void) {
 
-   memset(f1ap_du_inst, 0, sizeof(f1ap_du_inst));
-}
 
-int DU_send_UL_NR_RRC_MESSAGE_TRANSFER(instance_t instance, 
-                                    const f1ap_ul_rrc_message_t *msg) {
+int DU_send_UL_NR_RRC_MESSAGE_TRANSFER(instance_t instance,
+                                       const f1ap_ul_rrc_message_t *msg) {
   const rnti_t rnti = msg->rnti;
-
-  F1AP_F1AP_PDU_t                pdu;
+  F1AP_F1AP_PDU_t                pdu= {0};
   F1AP_ULRRCMessageTransfer_t    *out;
-  F1AP_ULRRCMessageTransferIEs_t *ie;
-
   uint8_t *buffer = NULL;
   uint32_t len;
-
-
   LOG_I(F1AP, "[DU %ld] %s: size %d UE RNTI %x in SRB %d\n",
         instance, __func__, msg->rrc_container_length, rnti, msg->srb_id);
-
   //LOG_I(F1AP, "%s() RRCContainer size %d: ", __func__, msg->rrc_container_length);
   //for (int i = 0;i < msg->rrc_container_length; i++)
   //  printf("%02x ", msg->rrc_container[i]);
   //printf("\n");
-
   /* Create */
   /* 0. Message Type */
-  memset(&pdu, 0, sizeof(pdu));
   pdu.present = F1AP_F1AP_PDU_PR_initiatingMessage;
-  pdu.choice.initiatingMessage = (F1AP_InitiatingMessage_t *)calloc(1, sizeof(F1AP_InitiatingMessage_t));
-  pdu.choice.initiatingMessage->procedureCode = F1AP_ProcedureCode_id_ULRRCMessageTransfer;
-  pdu.choice.initiatingMessage->criticality   = F1AP_Criticality_ignore;
-  pdu.choice.initiatingMessage->value.present = F1AP_InitiatingMessage__value_PR_ULRRCMessageTransfer;
-  out = &pdu.choice.initiatingMessage->value.choice.ULRRCMessageTransfer;
-  
+  asn1cCalloc(pdu.choice.initiatingMessage, tmp);
+  tmp->procedureCode = F1AP_ProcedureCode_id_ULRRCMessageTransfer;
+  tmp->criticality   = F1AP_Criticality_ignore;
+  tmp->value.present = F1AP_InitiatingMessage__value_PR_ULRRCMessageTransfer;
+  out = &tmp->value.choice.ULRRCMessageTransfer;
   /* mandatory */
   /* c1. GNB_CU_UE_F1AP_ID */
-  ie = (F1AP_ULRRCMessageTransferIEs_t *)calloc(1, sizeof(F1AP_ULRRCMessageTransferIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
-  ie->criticality                    = F1AP_Criticality_reject;
-  ie->value.present                  = F1AP_ULRRCMessageTransferIEs__value_PR_GNB_CU_UE_F1AP_ID;
-
-  ie->value.choice.GNB_CU_UE_F1AP_ID = f1ap_get_cu_ue_f1ap_id(&f1ap_du_inst[instance], rnti);
-
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_ULRRCMessageTransferIEs_t, ie1);
+  ie1->id                             = F1AP_ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
+  ie1->criticality                    = F1AP_Criticality_reject;
+  ie1->value.present                  = F1AP_ULRRCMessageTransferIEs__value_PR_GNB_CU_UE_F1AP_ID;
+  ie1->value.choice.GNB_CU_UE_F1AP_ID = f1ap_get_cu_ue_f1ap_id(DUtype, instance, rnti);
   /* mandatory */
   /* c2. GNB_DU_UE_F1AP_ID */
-  ie = (F1AP_ULRRCMessageTransferIEs_t *)calloc(1, sizeof(F1AP_ULRRCMessageTransferIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
-  ie->criticality                    = F1AP_Criticality_reject;
-  ie->value.present                  = F1AP_ULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
-  ie->value.choice.GNB_DU_UE_F1AP_ID = f1ap_get_du_ue_f1ap_id(&f1ap_du_inst[instance], rnti);
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_ULRRCMessageTransferIEs_t, ie2);
+  ie2->id                             = F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
+  ie2->criticality                    = F1AP_Criticality_reject;
+  ie2->value.present                  = F1AP_ULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
+  ie2->value.choice.GNB_DU_UE_F1AP_ID = f1ap_get_du_ue_f1ap_id(DUtype, instance, rnti);
   /* mandatory */
   /* c3. SRBID */
-  ie = (F1AP_ULRRCMessageTransferIEs_t *)calloc(1, sizeof(F1AP_ULRRCMessageTransferIEs_t));
-  ie->id                            = F1AP_ProtocolIE_ID_id_SRBID;
-  ie->criticality                   = F1AP_Criticality_reject;
-  ie->value.present                 = F1AP_ULRRCMessageTransferIEs__value_PR_SRBID;
-  ie->value.choice.SRBID            = msg->srb_id;
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_ULRRCMessageTransferIEs_t, ie3);
+  ie3->id                            = F1AP_ProtocolIE_ID_id_SRBID;
+  ie3->criticality                   = F1AP_Criticality_reject;
+  ie3->value.present                 = F1AP_ULRRCMessageTransferIEs__value_PR_SRBID;
+  ie3->value.choice.SRBID            = msg->srb_id;
   // issue in here
   /* mandatory */
   /* c4. RRCContainer */
-  ie = (F1AP_ULRRCMessageTransferIEs_t *)calloc(1, sizeof(F1AP_ULRRCMessageTransferIEs_t));
-  ie->id                            = F1AP_ProtocolIE_ID_id_RRCContainer;
-  ie->criticality                   = F1AP_Criticality_reject;
-  ie->value.present                 = F1AP_ULRRCMessageTransferIEs__value_PR_RRCContainer;
-  OCTET_STRING_fromBuf(&ie->value.choice.RRCContainer,
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_ULRRCMessageTransferIEs_t, ie4);
+  ie4->id                            = F1AP_ProtocolIE_ID_id_RRCContainer;
+  ie4->criticality                   = F1AP_Criticality_reject;
+  ie4->value.present                 = F1AP_ULRRCMessageTransferIEs__value_PR_RRCContainer;
+  OCTET_STRING_fromBuf(&ie4->value.choice.RRCContainer,
                        (const char *) msg->rrc_container,
                        msg->rrc_container_length);
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
 
-    /* encode */
+  /* encode */
   if (f1ap_encode_pdu(&pdu, &buffer, &len) < 0) {
     LOG_E(F1AP, "Failed to encode F1 UL RRC MESSAGE TRANSFER \n");
     return -1;
   }
 
-  du_f1ap_itti_send_sctp_data_req(instance, f1ap_du_data->assoc_id, buffer, len, f1ap_du_data->default_sctp_stream_id);
+  f1ap_itti_send_sctp_data_req(false, instance, buffer, len, getCxt(DUtype, instance)->default_sctp_stream_id);
   return 0;
 }
 
 /*  DL NR RRC Message Transfer */
 int DU_handle_DL_NR_RRC_MESSAGE_TRANSFER(instance_t       instance,
-                                         uint32_t         assoc_id,
-                                         uint32_t         stream,
-                                         F1AP_F1AP_PDU_t *pdu) {
+    uint32_t         assoc_id,
+    uint32_t         stream,
+    F1AP_F1AP_PDU_t *pdu) {
   LOG_D(F1AP, "DU_handle_DL_NR_RRC_MESSAGE_TRANSFER \n");
-  
   F1AP_DLRRCMessageTransfer_t    *container;
   F1AP_DLRRCMessageTransferIEs_t *ie;
-
   uint64_t        cu_ue_f1ap_id;
   uint64_t        du_ue_f1ap_id;
-  uint64_t        srb_id;
   int             executeDuplication;
-  sdu_size_t      rrc_dl_sdu_len;
   //uint64_t        subscriberProfileIDforRFP;
   //uint64_t        rAT_FrequencySelectionPriority;
-
   DevAssert(pdu != NULL);
-
-  if (stream != 0) {
-    LOG_E(F1AP, "[SCTP %d] Received F1 on stream != 0 (%d)\n",
-               assoc_id, stream);
-    return -1;
-  }
-
   container = &pdu->choice.initiatingMessage->value.choice.DLRRCMessageTransfer;
-
-
   /* GNB_CU_UE_F1AP_ID */
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_DLRRCMessageTransferIEs_t, ie, container,
                              F1AP_ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID, true);
   cu_ue_f1ap_id = ie->value.choice.GNB_CU_UE_F1AP_ID;
   LOG_D(F1AP, "cu_ue_f1ap_id %lu \n", cu_ue_f1ap_id);
-
-
   /* GNB_DU_UE_F1AP_ID */
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_DLRRCMessageTransferIEs_t, ie, container,
                              F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID, true);
   du_ue_f1ap_id = ie->value.choice.GNB_DU_UE_F1AP_ID;
   LOG_D(F1AP, "du_ue_f1ap_id %lu associated with UE RNTI %x \n",
         du_ue_f1ap_id,
-        f1ap_get_rnti_by_du_id(&f1ap_du_inst[instance], du_ue_f1ap_id)); // this should be the one transmitted via initial ul rrc message transfer
+        f1ap_get_rnti_by_du_id(DUtype, instance, du_ue_f1ap_id)); // this should be the one transmitted via initial ul rrc message transfer
 
-  if (f1ap_du_add_cu_ue_id(&f1ap_du_inst[instance],du_ue_f1ap_id, cu_ue_f1ap_id) < 0 ) {
+  if (f1ap_du_add_cu_ue_id(instance,du_ue_f1ap_id, cu_ue_f1ap_id) < 0 ) {
     LOG_E(F1AP, "Failed to find the F1AP UID \n");
     //return -1;
   }
@@ -1046,21 +922,21 @@ int DU_handle_DL_NR_RRC_MESSAGE_TRANSFER(instance_t       instance,
   /* oldgNB_DU_UE_F1AP_ID */
   if (0) {
     F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_DLRRCMessageTransferIEs_t, ie, container,
-                             F1AP_ProtocolIE_ID_id_oldgNB_DU_UE_F1AP_ID, true);
+                               F1AP_ProtocolIE_ID_id_oldgNB_DU_UE_F1AP_ID, true);
   }
 
   /* mandatory */
   /* SRBID */
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_DLRRCMessageTransferIEs_t, ie, container,
                              F1AP_ProtocolIE_ID_id_SRBID, true);
-  srb_id = ie->value.choice.SRBID;
+  uint64_t  srb_id = ie->value.choice.SRBID;
   LOG_D(F1AP, "srb_id %lu \n", srb_id);
 
   /* optional */
   /* ExecuteDuplication */
   if (0) {
     F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_DLRRCMessageTransferIEs_t, ie, container,
-                             F1AP_ProtocolIE_ID_id_ExecuteDuplication, true);
+                               F1AP_ProtocolIE_ID_id_ExecuteDuplication, true);
     executeDuplication = ie->value.choice.ExecuteDuplication;
     LOG_D(F1AP, "ExecuteDuplication %d \n", executeDuplication);
   }
@@ -1072,10 +948,8 @@ int DU_handle_DL_NR_RRC_MESSAGE_TRANSFER(instance_t       instance,
                              F1AP_ProtocolIE_ID_id_RRCContainer, true);
   // BK: need check
   // create an ITTI message and copy SDU
-
   //  message_p = itti_alloc_new_message (TASK_CU_F1, RRC_MAC_CCCH_DATA_IND);
   //  memset (RRC_MAC_CCCH_DATA_IND (message_p).sdu, 0, CCCH_SDU_SIZE);
-  rrc_dl_sdu_len = ie->value.choice.RRCContainer.size;
   //  memcpy(RRC_MAC_CCCH_DATA_IND (message_p).sdu, ie->value.choice.RRCContainer.buf,
   //         ccch_sdu_len);
 
@@ -1088,15 +962,17 @@ int DU_handle_DL_NR_RRC_MESSAGE_TRANSFER(instance_t       instance,
   /* RAT_FrequencyPriorityInformation */
   if (0) {
     F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_DLRRCMessageTransferIEs_t, ie, container,
-                             F1AP_ProtocolIE_ID_id_RAT_FrequencyPriorityInformation, true);
+                               F1AP_ProtocolIE_ID_id_RAT_FrequencyPriorityInformation, true);
 
     switch(ie->value.choice.RAT_FrequencyPriorityInformation.present) {
       case F1AP_RAT_FrequencyPriorityInformation_PR_eNDC:
         //subscriberProfileIDforRFP = ie->value.choice.RAT_FrequencyPriorityInformation.choice.subscriberProfileIDforRFP;
         break;
+
       case F1AP_RAT_FrequencyPriorityInformation_PR_nGRAN:
         //rAT_FrequencySelectionPriority = ie->value.choice.RAT_FrequencyPriorityInformation.choice.rAT_FrequencySelectionPriority;
         break;
+
       default:
         LOG_W(F1AP, "unhandled IE RAT_FrequencyPriorityInformation.present\n");
         break;
@@ -1105,280 +981,12 @@ int DU_handle_DL_NR_RRC_MESSAGE_TRANSFER(instance_t       instance,
 
   // decode RRC Container and act on the message type
   AssertFatal(srb_id<3,"illegal srb_id\n");
-
-  protocol_ctxt_t ctxt;
-  ctxt.rnti      = f1ap_get_rnti_by_du_id(&f1ap_du_inst[instance], du_ue_f1ap_id);
-  ctxt.module_id = instance;
-  ctxt.instance  = instance;
-  ctxt.enb_flag  = 1;
-
-  struct rrc_gNB_ue_context_s* ue_context_p = rrc_gNB_get_ue_context(
-								     RC.nrrrc[ctxt.module_id],
-								     ctxt.rnti);
-
-  gNB_RRC_INST *rrc = RC.nrrrc[ctxt.module_id];
-  if (srb_id == 0) {
-    NR_DL_CCCH_Message_t* dl_ccch_msg=NULL;
-    asn_dec_rval_t dec_rval;
-    dec_rval = uper_decode(NULL,
-                           &asn_DEF_NR_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 NR_DL_CCCH_MessageType__c1_PR_NOTHING:
-
-        LOG_I(F1AP, "Received PR_NOTHING on DL-CCCH-Message\n");
-        break;
-
-      case NR_DL_CCCH_MessageType__c1_PR_rrcReject:
-        LOG_I(F1AP,
-              "Logical Channel DL-CCCH (SRB0), Received RRCReject\n");
-        break;
-
-      case NR_DL_CCCH_MessageType__c1_PR_rrcSetup:
-      {
-        LOG_I(F1AP,
-              "Logical Channel DL-CCCH (SRB0), Received RRCSetup DU_ID %lx/RNTI %x\n",
-              du_ue_f1ap_id,
-              f1ap_get_rnti_by_du_id(&f1ap_du_inst[instance], du_ue_f1ap_id));
-          // Get configuration
-
-        NR_RRCSetup_t* rrcSetup = dl_ccch_msg->message.choice.c1->choice.rrcSetup;
-        AssertFatal(rrcSetup!=NULL, "rrcSetup is null\n");
-        NR_RRCSetup_IEs_t *rrcSetup_ies = rrcSetup->criticalExtensions.choice.rrcSetup;
-
-	ue_context_p->ue_context.SRB_configList = rrcSetup_ies->radioBearerConfig.srb_ToAddModList;
-        AssertFatal(rrcSetup_ies->masterCellGroup.buf!=NULL,"masterCellGroup is null\n");
-	asn_dec_rval_t dec_rval;
-	dec_rval = uper_decode(NULL,
-			       &asn_DEF_NR_CellGroupConfig,
-			       (void**)&ue_context_p->ue_context.masterCellGroup,
-			       rrcSetup_ies->masterCellGroup.buf,
-			       rrcSetup_ies->masterCellGroup.size,0,0);
-	AssertFatal(dec_rval.code == RC_OK, "could not decode masterCellGroup\n");
-
-        apply_macrlc_config(rrc,ue_context_p,&ctxt);
-
-        gNB_RRC_UE_t *ue_p = &ue_context_p->ue_context;
-        AssertFatal(ue_p->Srb0.Active == 1,"SRB0 is not active\n");
-
-        memcpy((void*)ue_p->Srb0.Tx_buffer.Payload,
-               (void*)ie->value.choice.RRCContainer.buf,
-               rrc_dl_sdu_len); // ie->value.choice.RRCContainer.size
-
-        ue_p->Srb0.Tx_buffer.payload_size = rrc_dl_sdu_len;
-
-          break;
-      } // case
-
-      case NR_DL_CCCH_MessageType__c1_PR_spare2:
-        LOG_I(F1AP,
-              "Logical Channel DL-CCCH (SRB0), Received spare2\n");
-        break;
-
-      case NR_DL_CCCH_MessageType__c1_PR_spare1:
-        LOG_I(F1AP,
-              "Logical Channel DL-CCCH (SRB0), Received spare1\n");
-        break;
-
-      default:
-        AssertFatal(1==0,
-        "Unknown message\n");
-        break;
-    }// switch case
-    return(0);
-  } else if (srb_id == 1) { 
-
-    NR_DL_DCCH_Message_t* dl_dcch_msg=NULL;
-    asn_dec_rval_t dec_rval;
-    dec_rval = uper_decode(NULL,
-         &asn_DEF_NR_DL_DCCH_Message,
-         (void**)&dl_dcch_msg,
-         &ie->value.choice.RRCContainer.buf[2], // buf[0] includes the pdcp header
-         rrc_dl_sdu_len-6,0,0);
-
-    if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0)) 
-      LOG_E(F1AP," Failed to decode DL-DCCH (%zu bytes)\n",dec_rval.consumed);
-    else
-      LOG_D(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 == NR_DL_DCCH_MessageType_PR_c1) {
-      switch (dl_dcch_msg->message.choice.c1->present) {
-        case NR_DL_DCCH_MessageType__c1_PR_NOTHING:
-          LOG_I(F1AP, "Received PR_NOTHING on DL-DCCH-Message\n");
-          return 0;
-
-        case NR_DL_DCCH_MessageType__c1_PR_rrcReconfiguration:
-        // handle RRCReconfiguration
-          LOG_I(F1AP,
-                "Logical Channel DL-DCCH (SRB1), Received RRCReconfiguration DU_ID %lx/RNTI %x\n",
-                du_ue_f1ap_id,
-                f1ap_get_rnti_by_du_id(&f1ap_du_inst[instance], du_ue_f1ap_id));
-    
-          NR_RRCReconfiguration_t* rrcReconfiguration = dl_dcch_msg->message.choice.c1->choice.rrcReconfiguration;
-
-          if (rrcReconfiguration->criticalExtensions.present == NR_RRCReconfiguration__criticalExtensions_PR_rrcReconfiguration) {
-            NR_RRCReconfiguration_IEs_t* rrcReconfiguration_ies =
-              rrcReconfiguration->criticalExtensions.choice.rrcReconfiguration;
-
-            if (rrcReconfiguration_ies->measConfig != NULL) {
-              LOG_I(F1AP, "Measurement Configuration is present\n");
-            }
-
-              if (rrcReconfiguration_ies->radioBearerConfig) {
-                LOG_I(F1AP, "Radio Resource Configuration is present\n");
-                long drb_id;
-                int i;
-                NR_DRB_ToAddModList_t  *DRB_configList  = rrcReconfiguration_ies->radioBearerConfig->drb_ToAddModList;
-                NR_SRB_ToAddModList_t  *SRB_configList  = rrcReconfiguration_ies->radioBearerConfig->srb_ToAddModList;
-                // NR_DRB_ToReleaseList_t *DRB_ReleaseList = rrcReconfiguration_ies->radioBearerConfig->drb_ToReleaseList;
-
-                // rrc_rlc_config_asn1_req
-
-                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_p->ue_context.Srb1.Active=1;
-                    }
-                    else if (SRB_configList->list.array[i]->srb_Identity == 2 )  {
-                      ue_context_p->ue_context.Srb2.Active=1;
-                      ue_context_p->ue_context.Srb2.Srb_info.Srb_id=2;
-                      LOG_I(F1AP, "[DU %d] SRB2 is now active\n",ctxt.module_id);
-                    } else {
-                      LOG_W(F1AP, "[DU %d] invalide SRB identity %ld\n",ctxt.module_id,
-                      SRB_configList->list.array[i]->srb_Identity);
-                    }
-                  }
-                }
-
-                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;
-                      LOG_I(F1AP,
-                            "[DU %d] Logical Channel UL-DCCH, Received RRCConnectionReconfiguration for UE rnti %x, reconfiguring DRB %d\n",
-                            ctxt.module_id,
-                            ctxt.rnti,
-                            (int)DRB_configList->list.array[i]->drb_Identity);
-                            // (int)*DRB_configList->list.array[i]->logicalChannelIdentity);
-
-                    if (ue_context_p->ue_context.DRB_active[drb_id] == 0) {
-                      ue_context_p->ue_context.DRB_active[drb_id] = 1;
-
-                      // logicalChannelIdentity
-                      // rrc_mac_config_req_eNB
-                    }
-
-                  } else {        // remove LCHAN from MAC/PHY
-                    AssertFatal(1==0,"Can't handle this yet in DU\n");  
-                  } 
-                }
-              }
-            }
-        }
-        break;
-      case NR_DL_DCCH_MessageType__c1_PR_rrcResume:
-        LOG_I(F1AP,"Received rrcResume\n");
-        break;	
-      case NR_DL_DCCH_MessageType__c1_PR_rrcRelease:
-        LOG_I(F1AP,"Received rrcRelease\n");
-        break;  
-      case NR_DL_DCCH_MessageType__c1_PR_rrcReestablishment:
-        LOG_I(F1AP,"Received rrcReestablishment\n");
-        break;  
-      case NR_DL_DCCH_MessageType__c1_PR_securityModeCommand:
-        LOG_I(F1AP,"Received securityModeCommand\n");
-        break;
-      case NR_DL_DCCH_MessageType__c1_PR_dlInformationTransfer:
-        LOG_I(F1AP, "Received dlInformationTransfer\n");
-  	    break;
-      case NR_DL_DCCH_MessageType__c1_PR_ueCapabilityEnquiry:
-        LOG_I(F1AP, "Received ueCapabilityEnquiry\n");
-          break; 
-      case NR_DL_DCCH_MessageType__c1_PR_counterCheck:
-        LOG_I(F1AP, "Received counterCheck\n");
-          break;
-      case NR_DL_DCCH_MessageType__c1_PR_mobilityFromNRCommand:
-      case NR_DL_DCCH_MessageType__c1_PR_dlDedicatedMessageSegment_r16:
-      case NR_DL_DCCH_MessageType__c1_PR_ueInformationRequest_r16:
-      case NR_DL_DCCH_MessageType__c1_PR_dlInformationTransferMRDC_r16:
-      case NR_DL_DCCH_MessageType__c1_PR_loggedMeasurementConfiguration_r16:
-      case NR_DL_DCCH_MessageType__c1_PR_spare3:
-      case NR_DL_DCCH_MessageType__c1_PR_spare2:
-      case NR_DL_DCCH_MessageType__c1_PR_spare1:
-        break;
-    }
-   }
-  }
-  else if (srb_id == 2) {
-    // TODO
-  }
-
-  LOG_I(F1AP, "Received DL RRC Transfer on srb_id %ld\n", srb_id);
-
-
-//   rlc_op_status_t    rlc_status;
-//   boolean_t          ret             = TRUE;
-  mem_block_t       *pdcp_pdu_p      = NULL; 
-  pdcp_pdu_p = get_free_mem_block(rrc_dl_sdu_len, __func__);
-
-  //LOG_I(F1AP, "PRRCContainer size %lu:", ie->value.choice.RRCContainer.size);
-  //for (int i = 0; i < ie->value.choice.RRCContainer.size; i++)
-  //  printf("%02x ", ie->value.choice.RRCContainer.buf[i]);
-
-  //printf (", PDCP PDU size %d:", rrc_dl_sdu_len);
-  //for (int i=0;i<rrc_dl_sdu_len;i++) printf("%2x ",pdcp_pdu_p->data[i]);
-  //printf("\n");
-
-  if (pdcp_pdu_p != NULL) {
-    memset(pdcp_pdu_p->data, 0, rrc_dl_sdu_len);
-    memcpy(&pdcp_pdu_p->data[0], ie->value.choice.RRCContainer.buf, rrc_dl_sdu_len);
-
-    /* for rfsim */
-    du_rlc_data_req(&ctxt, 1, 0x00, 1, 1, 0, rrc_dl_sdu_len, pdcp_pdu_p);
-    //   rlc_status = rlc_data_req(&ctxt
-    //                             , 1
-    //                             , MBMS_FLAG_NO
-    //                             , srb_id
-    //                             , 0
-    //                             , 0
-    //                             , rrc_dl_sdu_len
-    //                             , pdcp_pdu_p
-    //                             ,NULL
-    //                             ,NULL
-    //                             );
-    //   switch (rlc_status) {
-    //     case RLC_OP_STATUS_OK:
-    //       //LOG_I(F1AP, "Data sending request over RLC succeeded!\n");
-    //       ret=TRUE;
-    //       break;
-
-    //     case RLC_OP_STATUS_BAD_PARAMETER:
-    //       LOG_W(F1AP, "Data sending request over RLC failed with 'Bad Parameter' reason!\n");
-    //       ret= FALSE;
-    //       break;
-
-    //     case RLC_OP_STATUS_INTERNAL_ERROR:
-    //       LOG_W(F1AP, "Data sending request over RLC failed with 'Internal Error' reason!\n");
-    //       ret= FALSE;
-    //       break;
-
-    //     case RLC_OP_STATUS_OUT_OF_RESSOURCES:
-    //       LOG_W(F1AP, "Data sending request over RLC failed with 'Out of Resources' reason!\n");
-    //       ret= FALSE;
-    //       break;
-
-    //     default:
-    //       LOG_W(F1AP, "RLC returned an unknown status code after PDCP placed the order to send some data (Status Code:%d)\n", rlc_status);
-    //       ret= FALSE;
-    //       break;
-    //   } // switch case
-    //   return ret; 
-    } // if pdcp_pdu_p
-
+  MessageDef *msg = itti_alloc_new_message(TASK_DU_F1, 0, NR_DU_RRC_DL_INDICATION);
+  NRDuDlReq_t *req=&NRDuDlReq(msg);
+  req->rnti=f1ap_get_rnti_by_du_id(DUtype, instance, du_ue_f1ap_id);
+  req->srb_id=srb_id;
+  req->buf= get_free_mem_block( ie->value.choice.RRCContainer.size, __func__);
+  memcpy(req->buf->data, ie->value.choice.RRCContainer.buf, ie->value.choice.RRCContainer.size);
+  itti_send_msg_to_task(TASK_RRC_GNB, instance, msg);
   return 0;
 }
diff --git a/openair2/F1AP/f1ap_du_rrc_message_transfer.h b/openair2/F1AP/f1ap_du_rrc_message_transfer.h
index 3036c66d709942babf98e857620ab56e2964bbf2..d6f196e38431add79afde8ad4848f4ea50d469d9 100644
--- a/openair2/F1AP/f1ap_du_rrc_message_transfer.h
+++ b/openair2/F1AP/f1ap_du_rrc_message_transfer.h
@@ -44,13 +44,13 @@ int DU_handle_DL_RRC_MESSAGE_TRANSFER(instance_t       instance,
 int DU_send_UL_RRC_MESSAGE_TRANSFER(instance_t instance, const f1ap_ul_rrc_message_t *msg);
 int DU_send_UL_NR_RRC_MESSAGE_TRANSFER(instance_t instance, const f1ap_ul_rrc_message_t *msg);
 
-int DU_send_INITIAL_UL_RRC_MESSAGE_TRANSFER(module_id_t     module_idP,
-                                            int             CC_idP,
-                                            int             UE_id,
-                                            rnti_t          rntiP,
-                                            const uint8_t   *sduP,
-                                            sdu_size_t      sdu_lenP,
-                                            const int8_t   *sdu2P,
-                                            sdu_size_t      sdu2_lenP);
+int DU_send_INITIAL_UL_RRC_MESSAGE_TRANSFER(instance_t     instanceP,
+    int             CC_idP,
+    int             UE_id,
+    rnti_t          rntiP,
+    const uint8_t   *sduP,
+    sdu_size_t      sdu_lenP,
+    const char   *sdu2P,
+    sdu_size_t      sdu2_lenP);
 
 #endif /* F1AP_DU_RRC_MESSAGE_TRANSFER_H_ */
diff --git a/openair2/F1AP/f1ap_du_task.c b/openair2/F1AP/f1ap_du_task.c
index 50f7cdff805ec3811ab4bd70fc958da1bec101ef..537f0060aecb072e6789c85ae7b6eb18ce8dacad 100644
--- a/openair2/F1AP/f1ap_du_task.c
+++ b/openair2/F1AP/f1ap_du_task.c
@@ -31,189 +31,171 @@
 */
 
 #include "f1ap_common.h"
-#include "f1ap_handlers.h"
 #include "f1ap_du_interface_management.h"
 #include "f1ap_du_ue_context_management.h"
 #include "f1ap_du_rrc_message_transfer.h"
 #include "f1ap_du_task.h"
 #include "proto_agent.h"
+#include <openair3/ocp-gtpu/gtp_itf.h>
 
-extern RAN_CONTEXT_t RC;
-
-f1ap_setup_req_t *f1ap_du_data;
-f1ap_cudu_inst_t f1ap_du_inst[MAX_eNB];
+//Fixme: Uniq dirty DU instance, by global var, datamodel need better management
+instance_t DUuniqInstance=0;
 
 void du_task_send_sctp_association_req(instance_t instance, f1ap_setup_req_t *f1ap_setup_req) {
-  
   DevAssert(f1ap_setup_req != NULL);
-
   MessageDef                 *message_p                   = NULL;
   sctp_new_association_req_t *sctp_new_association_req_p  = NULL;
-
   message_p = itti_alloc_new_message(TASK_DU_F1, 0, SCTP_NEW_ASSOCIATION_REQ);
-
   sctp_new_association_req_p = &message_p->ittiMsg.sctp_new_association_req;
   sctp_new_association_req_p->ulp_cnx_id = instance;
   sctp_new_association_req_p->port = F1AP_PORT_NUMBER;
   sctp_new_association_req_p->ppid = F1AP_SCTP_PPID;
-
   sctp_new_association_req_p->in_streams  = f1ap_setup_req->sctp_in_streams;
   sctp_new_association_req_p->out_streams = f1ap_setup_req->sctp_out_streams;
-
   // remote
   memcpy(&sctp_new_association_req_p->remote_address,
          &f1ap_setup_req->CU_f1_ip_address,
          sizeof(f1ap_setup_req->CU_f1_ip_address));
-
   // local
   memcpy(&sctp_new_association_req_p->local_address,
          &f1ap_setup_req->DU_f1_ip_address,
          sizeof(f1ap_setup_req->DU_f1_ip_address));
-
-  // store data
-  f1ap_du_data = (f1ap_setup_req_t *)calloc(1, sizeof(f1ap_setup_req_t));
-  *f1ap_du_data = *f1ap_setup_req;
   //printf("sib itti message %s\n", f1ap_setup_req_t->sib1[0]);
-
   //printf("nr_cellid : %llx (%lld)",f1ap_setup_req->nr_cellid[0],f1ap_setup_req->nr_cellid[0]);
-  
   //du_f1ap_register_to_sctp
   itti_send_msg_to_task(TASK_SCTP, instance, message_p);
 }
 
 void du_task_handle_sctp_association_resp(instance_t instance, sctp_new_association_resp_t *sctp_new_association_resp) {
-
   DevAssert(sctp_new_association_resp != NULL);
 
   if (sctp_new_association_resp->sctp_state != SCTP_STATE_ESTABLISHED) {
-    LOG_E(F1AP, "Received unsuccessful result for SCTP association (%u), instance %d, cnx_id %u\n",
-              sctp_new_association_resp->sctp_state,
-              (int)instance,
-              sctp_new_association_resp->ulp_cnx_id);
-
-      //f1ap_handle_setup_message(instance, sctp_new_association_resp->sctp_state == SCTP_STATE_SHUTDOWN);
-    return; // exit -1 for debugging 
-    }
-
-    // save the assoc id 
+    LOG_W(F1AP, "Received unsuccessful result for SCTP association (%u), instance %ld, cnx_id %u\n",
+          sctp_new_association_resp->sctp_state,
+          instance,
+          sctp_new_association_resp->ulp_cnx_id);
+    //f1ap_handle_setup_message(instance, sctp_new_association_resp->sctp_state == SCTP_STATE_SHUTDOWN);
+    return; // exit -1 for debugging
+  }
+
+  // save the assoc id
+  f1ap_setup_req_t *f1ap_du_data=f1ap_req(false, instance);
   f1ap_du_data->assoc_id         = sctp_new_association_resp->assoc_id;
   f1ap_du_data->sctp_in_streams  = sctp_new_association_resp->in_streams;
   f1ap_du_data->sctp_out_streams = sctp_new_association_resp->out_streams;
   f1ap_du_data->default_sctp_stream_id = 0;
-
   /* setup parameters for F1U and start the server */
-  const cudu_params_t params = (RC.nrrrc && RC.nrrrc[instance]->node_type == ngran_gNB_DU) ? (cudu_params_t){
-    .local_ipv4_address  = RC.nrmac[instance]->eth_params_n.my_addr,
-    .local_port          = RC.nrmac[instance]->eth_params_n.my_portd,
-    .remote_ipv4_address = RC.nrmac[instance]->eth_params_n.remote_addr,
-    .remote_port         = RC.nrmac[instance]->eth_params_n.remote_portd
-  } : (cudu_params_t){
-    .local_ipv4_address  = RC.mac[instance]->eth_params_n.my_addr,
-    .local_port          = RC.mac[instance]->eth_params_n.my_portd,
-    .remote_ipv4_address = RC.mac[instance]->eth_params_n.remote_addr,
-    .remote_port         = RC.mac[instance]->eth_params_n.remote_portd
-  };
-  AssertFatal(proto_agent_start(instance, &params) == 0,
-              "could not start PROTO_AGENT for F1U on instance %ld!\n", instance);
-
   DU_send_F1_SETUP_REQUEST(instance);
 }
 
-void du_task_handle_sctp_data_ind(instance_t instance, sctp_data_ind_t *sctp_data_ind)
-{
+void du_task_handle_sctp_data_ind(instance_t instance, sctp_data_ind_t *sctp_data_ind) {
   int result;
-
   DevAssert(sctp_data_ind != NULL);
-
   f1ap_handle_message(instance, 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);
   result = itti_free(TASK_UNKNOWN, sctp_data_ind->buffer);
   AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
 }
 
+static instance_t du_create_gtpu_instance_to_cu(char *CUaddr, uint16_t CUport, char *DUaddr, uint16_t DUport) {
+  openAddr_t tmp= {0};
+  strncpy(tmp.originHost, DUaddr, sizeof(tmp.originHost)-1);
+  strncpy(tmp.destinationHost, CUaddr, sizeof(tmp.destinationHost)-1);
+  sprintf(tmp.originService, "%d", DUport);
+  sprintf(tmp.destinationService, "%d", CUport);
+  return ocp_gtpv1Init(tmp);
+}
 
 void *F1AP_DU_task(void *arg) {
-
   //sctp_cu_init();
-  MessageDef *received_msg = NULL;
-  int         result;
-
   LOG_I(F1AP, "Starting F1AP at DU\n");
-
   //f1ap_eNB_prepare_internal_data();
-
   itti_mark_task_ready(TASK_DU_F1);
 
   // SCTP
   while (1) {
-    itti_receive_msg(TASK_DU_F1, &received_msg);
-
-    switch (ITTI_MSG_ID(received_msg)) {
-
-      // case TERMINATE_MESSAGE:
-      //   //F1AP_WARN(" *** Exiting F1AP DU thread\n");
-      //   itti_exit_task();
-      //   break;
-
-      case F1AP_SETUP_REQ: // this is not a true F1 message, but rather an ITTI message sent by enb_app
-        // 1. save the itti msg so that you can use it to sen f1ap_setup_req, fill the f1ap_setup_req message, 
+    MessageDef *msg = NULL;
+    itti_receive_msg(TASK_DU_F1, &msg);
+    instance_t myInstance=ITTI_MSG_DESTINATION_INSTANCE(msg);
+
+    switch (ITTI_MSG_ID(msg)) {
+      case F1AP_SETUP_REQ:
+        // this is not a true F1 message, but rather an ITTI message sent by enb_app
+        // 1. save the itti msg so that you can use it to sen f1ap_setup_req, fill the f1ap_setup_req message,
         // 2. store the message in f1ap context, that is also stored in RC
         // 2. send a sctp_association req
         LOG_I(F1AP, "DU Task Received F1AP_SETUP_REQ\n");
-        du_task_send_sctp_association_req(ITTI_MSG_DESTINATION_INSTANCE(received_msg),
-                                              &F1AP_SETUP_REQ(received_msg));
+        f1ap_setup_req_t *msgSetup=&F1AP_SETUP_REQ(msg);
+        createF1inst(false, myInstance, msgSetup);
+        getCxt(DUtype, myInstance)->gtpInst=du_create_gtpu_instance_to_cu(msgSetup->CU_f1_ip_address.ipv4_address,
+                                            msgSetup->CUport,
+                                            msgSetup->DU_f1_ip_address.ipv4_address,
+                                            msgSetup->DUport);
+        AssertFatal(getCxt(DUtype, myInstance)->gtpInst>0,"Failed to create CU F1-U UDP listener");
+        // Fixme: fully inconsistent instances management
+        // dirty global var is a bad fix
+        extern instance_t legacyInstanceMapping;
+        legacyInstanceMapping = DUuniqInstance = getCxt(DUtype, myInstance)->gtpInst;
+        du_task_send_sctp_association_req(myInstance,msgSetup);
         break;
+
       case F1AP_GNB_CU_CONFIGURATION_UPDATE_ACKNOWLEDGE:
-	      DU_send_gNB_CU_CONFIGURATION_UPDATE_ACKNOWLEDGE(ITTI_MSG_DESTINATION_INSTANCE(received_msg),
-							&F1AP_GNB_CU_CONFIGURATION_UPDATE_ACKNOWLEDGE(received_msg));
-	      break;
+        DU_send_gNB_CU_CONFIGURATION_UPDATE_ACKNOWLEDGE(ITTI_MSG_ORIGIN_INSTANCE(msg),
+            &F1AP_GNB_CU_CONFIGURATION_UPDATE_ACKNOWLEDGE(msg));
+        break;
+
       case F1AP_GNB_CU_CONFIGURATION_UPDATE_FAILURE:
-	      DU_send_gNB_CU_CONFIGURATION_UPDATE_FAILURE(ITTI_MSG_DESTINATION_INSTANCE(received_msg),
-						    &F1AP_GNB_CU_CONFIGURATION_UPDATE_FAILURE(received_msg));
-	      break;
+        DU_send_gNB_CU_CONFIGURATION_UPDATE_FAILURE(myInstance,
+            &F1AP_GNB_CU_CONFIGURATION_UPDATE_FAILURE(msg));
+        break;
 
       case SCTP_NEW_ASSOCIATION_RESP:
         // 1. store the respon
         // 2. send the f1setup_req
         LOG_I(F1AP, "DU Task Received SCTP_NEW_ASSOCIATION_RESP\n");
-        du_task_handle_sctp_association_resp(ITTI_MSG_DESTINATION_INSTANCE(received_msg),
-                                      &received_msg->ittiMsg.sctp_new_association_resp);
+        du_task_handle_sctp_association_resp(myInstance,
+                                             &msg->ittiMsg.sctp_new_association_resp);
         break;
 
-      case SCTP_DATA_IND: 
+      case SCTP_DATA_IND:
         // ex: any F1 incoming message for DU ends here
         LOG_I(F1AP, "DU Task Received SCTP_DATA_IND\n");
-        du_task_handle_sctp_data_ind(ITTI_MSG_DESTINATION_INSTANCE(received_msg),
-                                    &received_msg->ittiMsg.sctp_data_ind);
+        du_task_handle_sctp_data_ind(myInstance,
+                                     &msg->ittiMsg.sctp_data_ind);
         break;
 
-      case F1AP_INITIAL_UL_RRC_MESSAGE: // to rrc
+      case F1AP_INITIAL_UL_RRC_MESSAGE: // from rrc
         LOG_I(F1AP, "DU Task Received F1AP_INITIAL_UL_RRC_MESSAGE\n");
-
-        f1ap_initial_ul_rrc_message_t *msg = &F1AP_INITIAL_UL_RRC_MESSAGE(received_msg);
-        DU_send_INITIAL_UL_RRC_MESSAGE_TRANSFER(0,0,0,msg->crnti,
-                                                msg->rrc_container,
-                                                msg->rrc_container_length,
-                                                (const int8_t*)msg->du2cu_rrc_container,
-                                                msg->du2cu_rrc_container_length);
+        f1ap_initial_ul_rrc_message_t *msgRrc = &F1AP_INITIAL_UL_RRC_MESSAGE(msg);
+        DU_send_INITIAL_UL_RRC_MESSAGE_TRANSFER(0,0,0,msgRrc->crnti,
+                                                msgRrc->rrc_container,
+                                                msgRrc->rrc_container_length,
+                                                msgRrc->du2cu_rrc_container,
+                                                msgRrc->du2cu_rrc_container_length
+                                               );
         break;
 
-     case F1AP_UL_RRC_MESSAGE: // to rrc
+      case F1AP_UL_RRC_MESSAGE: // to rrc
         LOG_I(F1AP, "DU Task Received F1AP_UL_RRC_MESSAGE\n");
+
         if (RC.nrrrc && RC.nrrrc[0]->node_type == ngran_gNB_DU) {
-          DU_send_UL_NR_RRC_MESSAGE_TRANSFER(ITTI_MSG_DESTINATION_INSTANCE(received_msg),
-                                             &F1AP_UL_RRC_MESSAGE(received_msg));
+          DU_send_UL_NR_RRC_MESSAGE_TRANSFER(myInstance,
+                                             &F1AP_UL_RRC_MESSAGE(msg));
         } else {
-          DU_send_UL_RRC_MESSAGE_TRANSFER(ITTI_MSG_DESTINATION_INSTANCE(received_msg),
-                                          &F1AP_UL_RRC_MESSAGE(received_msg));
+          DU_send_UL_RRC_MESSAGE_TRANSFER(myInstance,
+                                          &F1AP_UL_RRC_MESSAGE(msg));
         }
+
+        break;
+
+      case F1AP_UE_CONTEXT_SETUP_RESP:
+        DU_send_UE_CONTEXT_SETUP_RESPONSE(myInstance, &F1AP_UE_CONTEXT_SETUP_RESP(msg));
         break;
 
       case F1AP_UE_CONTEXT_RELEASE_REQ: // from MAC
         LOG_I(F1AP, "DU Task Received F1AP_UE_CONTEXT_RELEASE_REQ\n");
-        DU_send_UE_CONTEXT_RELEASE_REQUEST(ITTI_MSG_DESTINATION_INSTANCE(received_msg),
-                                           &F1AP_UE_CONTEXT_RELEASE_REQ(received_msg));
+        DU_send_UE_CONTEXT_RELEASE_REQUEST(myInstance,
+                                           &F1AP_UE_CONTEXT_RELEASE_REQ(msg));
         break;
 
       case TERMINATE_MESSAGE:
@@ -223,13 +205,12 @@ void *F1AP_DU_task(void *arg) {
 
       default:
         LOG_E(F1AP, "DU Received unhandled message: %d:%s\n",
-              ITTI_MSG_ID(received_msg), ITTI_MSG_NAME(received_msg));
+              ITTI_MSG_ID(msg), ITTI_MSG_NAME(msg));
         break;
     } // switch
-    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;
+    int result = itti_free (ITTI_MSG_ORIGIN_ID(msg), msg);
+    AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
   } // while
 
   return NULL;
diff --git a/openair2/F1AP/f1ap_du_ue_context_management.c b/openair2/F1AP/f1ap_du_ue_context_management.c
index 131dbce8efad12aa46f060c12ee2f51b4ba62e8a..7b20bfb2aa54aa81962809ce9c7bdd6a21d0a72d 100644
--- a/openair2/F1AP/f1ap_du_ue_context_management.c
+++ b/openair2/F1AP/f1ap_du_ue_context_management.c
@@ -40,10 +40,28 @@
 #include "rrc_eNB_UE_context.h"
 #include "openair2/RRC/NR/rrc_gNB_UE_context.h"
 #include "openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h"
-
-extern f1ap_setup_req_t *f1ap_du_data;
-extern f1ap_cudu_inst_t f1ap_du_inst[MAX_eNB];
-extern RAN_CONTEXT_t RC;
+#include <openair3/ocp-gtpu/gtp_itf.h>
+
+boolean_t lteDURecvCb( protocol_ctxt_t  *ctxt_pP,
+                       const srb_flag_t     srb_flagP,
+                       const rb_id_t        rb_idP,
+                       const mui_t          muiP,
+                       const confirm_t      confirmP,
+                       const sdu_size_t     sdu_buffer_sizeP,
+                       unsigned char *const sdu_buffer_pP,
+                       const pdcp_transmission_mode_t modeP,
+                       const uint32_t *sourceL2Id,
+                       const uint32_t *destinationL2Id) {
+  // The buffer comes from the stack in gtp-u thread, we have a make a separate buffer to enqueue in a inter-thread message queue
+  mem_block_t *sdu=get_free_mem_block(sdu_buffer_sizeP, __func__);
+  memcpy(sdu->data,  sdu_buffer_pP,  sdu_buffer_sizeP);
+  // weird rb id management in 4G, not fully understand (looks bad design)
+  // overcomplex: if i understand, on the interface DRB start at 4 because there can be SRB 0..3
+  // but it would be much simpler to use absolute numbering
+  // instead of this "srb flag" associated to these +/-4
+  du_rlc_data_req(ctxt_pP,srb_flagP, false,  rb_idP-4,muiP, confirmP,  sdu_buffer_sizeP, sdu);
+  return true;
+}
 
 int DU_handle_UE_CONTEXT_SETUP_REQUEST(instance_t       instance,
                                        uint32_t         assoc_id,
@@ -51,121 +69,96 @@ int DU_handle_UE_CONTEXT_SETUP_REQUEST(instance_t       instance,
                                        F1AP_F1AP_PDU_t *pdu) {
   MessageDef                      *msg_p; // message to RRC
   F1AP_UEContextSetupRequest_t    *container;
-  F1AP_UEContextSetupRequestIEs_t *ie;
   int i;
   DevAssert(pdu);
-  msg_p = itti_alloc_new_message(TASK_DU_F1, 0, F1AP_UE_CONTEXT_SETUP_REQ);
-  f1ap_ue_context_setup_req_t *f1ap_ue_context_setup_req;
-  f1ap_ue_context_setup_req = &F1AP_UE_CONTEXT_SETUP_REQ(msg_p);
+  msg_p = itti_alloc_new_message(TASK_DU_F1, 0,  F1AP_UE_CONTEXT_SETUP_REQ);
+  f1ap_ue_context_setup_t *f1ap_ue_context_setup_req = &F1AP_UE_CONTEXT_SETUP_REQ(msg_p);
   container = &pdu->choice.initiatingMessage->value.choice.UEContextSetupRequest;
   /* GNB_CU_UE_F1AP_ID */
-  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_UEContextSetupRequestIEs_t, ie, container,
+  F1AP_UEContextSetupRequestIEs_t *ieCU;
+  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_UEContextSetupRequestIEs_t, ieCU, container,
                              F1AP_ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID, true);
-  f1ap_ue_context_setup_req->gNB_CU_ue_id = ie->value.choice.GNB_CU_UE_F1AP_ID;
+  f1ap_ue_context_setup_req->gNB_CU_ue_id = ieCU->value.choice.GNB_CU_UE_F1AP_ID;
   /* optional */
   /* GNB_DU_UE_F1AP_ID */
-  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_UEContextSetupRequestIEs_t, ie, container,
+  F1AP_UEContextSetupRequestIEs_t *ieDU_UE;
+  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_UEContextSetupRequestIEs_t, ieDU_UE, container,
                              F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID, false);
 
-  if (ie) {
-    f1ap_ue_context_setup_req->gNB_DU_ue_id = malloc(sizeof(uint32_t));
-
-    if (f1ap_ue_context_setup_req->gNB_DU_ue_id)
-      *f1ap_ue_context_setup_req->gNB_DU_ue_id = ie->value.choice.GNB_DU_UE_F1AP_ID;
+  if (ieDU_UE) {
+    f1ap_ue_context_setup_req->gNB_DU_ue_id =
+      ieDU_UE->value.choice.GNB_DU_UE_F1AP_ID;
+    f1ap_ue_context_setup_req->rnti =
+      f1ap_get_rnti_by_du_id(DUtype, instance, f1ap_ue_context_setup_req->gNB_DU_ue_id);
   } else {
-    f1ap_ue_context_setup_req->gNB_DU_ue_id = NULL;
+    f1ap_ue_context_setup_req->gNB_DU_ue_id = -1;
+    f1ap_ue_context_setup_req->rnti =
+      f1ap_get_rnti_by_cu_id(DUtype, instance, f1ap_ue_context_setup_req->gNB_CU_ue_id);
   }
 
+  if(f1ap_ue_context_setup_req->rnti<0)
+    LOG_E(F1AP, "Could not retrieve UE rnti based on the CU/DU UE id \n");
+  else
+    LOG_I(F1AP, "Retrieved rnti is: %d \n", f1ap_ue_context_setup_req->rnti);
+
   /* SpCell_ID */
-  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_UEContextSetupRequestIEs_t, ie, container,
+  F1AP_UEContextSetupRequestIEs_t *ieNet;
+  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_UEContextSetupRequestIEs_t, ieNet, container,
                              F1AP_ProtocolIE_ID_id_SpCell_ID, true);
-  PLMNID_TO_MCC_MNC(&ie->value.choice.NRCGI.pLMN_Identity,
+  PLMNID_TO_MCC_MNC(&ieNet->value.choice.NRCGI.pLMN_Identity,
                     f1ap_ue_context_setup_req->mcc,
                     f1ap_ue_context_setup_req->mnc,
                     f1ap_ue_context_setup_req->mnc_digit_length);
-  BIT_STRING_TO_NR_CELL_IDENTITY(&ie->value.choice.NRCGI.nRCellIdentity, f1ap_ue_context_setup_req->nr_cellid);
+  BIT_STRING_TO_NR_CELL_IDENTITY(&ieNet->value.choice.NRCGI.nRCellIdentity, f1ap_ue_context_setup_req->nr_cellid);
   /* ServCellIndex */
-  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_UEContextSetupRequestIEs_t, ie, container,
+  F1AP_UEContextSetupRequestIEs_t *ieCell;
+  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_UEContextSetupRequestIEs_t, ieCell, container,
                              F1AP_ProtocolIE_ID_id_ServCellIndex, true);
-  f1ap_ue_context_setup_req->servCellIndex = ie->value.choice.ServCellIndex;
+  f1ap_ue_context_setup_req->servCellIndex = ieCell->value.choice.ServCellIndex;
   /* optional */
   /* CellULConfigured */
-  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_UEContextSetupRequestIEs_t, ie, container,
+  F1AP_UEContextSetupRequestIEs_t *ieULCell;
+  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_UEContextSetupRequestIEs_t, ieULCell, container,
                              F1AP_ProtocolIE_ID_id_SpCellULConfigured, false);  // SpCellULConfigured
 
-  if (ie) {
+  if (ieULCell) {
     /* correct here */
     f1ap_ue_context_setup_req->cellULConfigured = malloc(sizeof(uint32_t));
 
     if (f1ap_ue_context_setup_req->cellULConfigured)
-      *f1ap_ue_context_setup_req->cellULConfigured = ie->value.choice.CellULConfigured;
+      *f1ap_ue_context_setup_req->cellULConfigured = ieULCell->value.choice.CellULConfigured;
   } else {
     f1ap_ue_context_setup_req->cellULConfigured = NULL;
   }
 
-  if (RC.nrrrc) {
-    /* RRCContainer */
-    F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_UEContextSetupRequestIEs_t, ie, container,
-                               F1AP_ProtocolIE_ID_id_RRCContainer, false);
-    if (ie) {
-      /* correct here */
-      f1ap_ue_context_setup_req->rrc_container = malloc(ie->value.choice.RRCContainer.size);
-      memcpy(f1ap_ue_context_setup_req->rrc_container, ie->value.choice.RRCContainer.buf, ie->value.choice.RRCContainer.size);
-    } else {
-      LOG_E(F1AP, "can't find RRCContainer in UEContextSetupRequestIEs by id %ld \n", F1AP_ProtocolIE_ID_id_RRCContainer);
-    }
-
-    // AssertFatal(0, "check configuration, send to appropriate handler\n");
-
-    protocol_ctxt_t ctxt;
-    // ctxt.rnti      = f1ap_get_rnti_by_du_id(&f1ap_du_inst[instance], ie->value.choice.GNB_DU_UE_F1AP_ID);
-    ctxt.rnti = 0x1234;
-    ctxt.module_id = instance;
-    ctxt.instance  = instance;
-    ctxt.enb_flag  = 1;
+  /* DRB */
+  F1AP_UEContextSetupRequestIEs_t *ieDrb;
+  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_UEContextSetupRequestIEs_t, ieDrb, container,
+                             F1AP_ProtocolIE_ID_id_DRBs_ToBeSetup_List, false);
 
-    mem_block_t *pdcp_pdu_p = NULL;
-    pdcp_pdu_p = get_free_mem_block(ie->value.choice.RRCContainer.size, __func__);
-    if (pdcp_pdu_p != NULL) {
-      memset(pdcp_pdu_p->data, 0, ie->value.choice.RRCContainer.size);
-      memcpy(&pdcp_pdu_p->data[0], ie->value.choice.RRCContainer.buf, ie->value.choice.RRCContainer.size);
-
-      /* for rfsim */
-      du_rlc_data_req(&ctxt, 1, 0x00, 1, 1, 0, ie->value.choice.RRCContainer.size, pdcp_pdu_p);
-    }
-  } else {
-    /* CUtoDURRCInformation */
-    /* Candidate_SpCell_List */
-    /* optional */
-    /* DRXCycle */
-    /* optional */
-    /* ResourceCoordinationTransferContainer */
-    /* SCell_ToBeSetup_List */
-    /* SRBs_ToBeSetup_List */
-    /* DRBs_ToBeSetup_List */
-    /* Decode DRBs_ToBeSetup_List */
-    F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_UEContextSetupRequestIEs_t, ie, container,
-                               F1AP_ProtocolIE_ID_id_DRBs_ToBeSetup_List, true);
-    f1ap_ue_context_setup_req->drbs_to_be_setup_length = ie->value.choice.DRBs_ToBeSetup_List.list.count;
+  if(ieDrb!=NULL) {
+    f1ap_ue_context_setup_req->drbs_to_be_setup_length = ieDrb->value.choice.DRBs_ToBeSetup_List.list.count;
     f1ap_ue_context_setup_req->drbs_to_be_setup = calloc(f1ap_ue_context_setup_req->drbs_to_be_setup_length,
-                                                         sizeof(f1ap_drb_to_be_setup_t));
+        sizeof(f1ap_drb_to_be_setup_t));
     AssertFatal(f1ap_ue_context_setup_req->drbs_to_be_setup,
                 "could not allocate memory for f1ap_ue_context_setup_req->drbs_to_be_setup\n");
 
     for (i = 0; i < f1ap_ue_context_setup_req->drbs_to_be_setup_length; ++i) {
       f1ap_drb_to_be_setup_t *drb_p = &f1ap_ue_context_setup_req->drbs_to_be_setup[i];
-      F1AP_DRBs_ToBeSetup_Item_t *drbs_tobesetup_item_p;
-      drbs_tobesetup_item_p = &((F1AP_DRBs_ToBeSetup_ItemIEs_t *)ie->value.choice.DRBs_ToBeSetup_List.list.array[i])->value.choice.DRBs_ToBeSetup_Item;
+      F1AP_DRBs_ToBeSetup_Item_t *drbs_tobesetup_item_p =
+        &((F1AP_DRBs_ToBeSetup_ItemIEs_t *)ieDrb->value.choice.DRBs_ToBeSetup_List.list.array[i])->value.choice.DRBs_ToBeSetup_Item;
       drb_p->drb_id = drbs_tobesetup_item_p->dRBID;
       /* TODO in the following, assume only one UP UL TNL is present.
-      * this matches/assumes OAI CU implementation, can be up to 2! */
+       * this matches/assumes OAI CU implementation, can be up to 2! */
       drb_p->up_ul_tnl_length = 1;
       AssertFatal(drbs_tobesetup_item_p->uLUPTNLInformation_ToBeSetup_List.list.count > 0,
                   "no UL UP TNL Information in DRBs to be Setup list\n");
       F1AP_ULUPTNLInformation_ToBeSetup_Item_t *ul_up_tnl_info_p = (F1AP_ULUPTNLInformation_ToBeSetup_Item_t *)drbs_tobesetup_item_p->uLUPTNLInformation_ToBeSetup_List.list.array[0];
       F1AP_GTPTunnel_t *ul_up_tnl0 = ul_up_tnl_info_p->uLUPTNLInformation.choice.gTPTunnel;
       BIT_STRING_TO_TRANSPORT_LAYER_ADDRESS_IPv4(&ul_up_tnl0->transportLayerAddress, drb_p->up_ul_tnl[0].tl_address);
-      OCTET_STRING_TO_INT32(&ul_up_tnl0->gTP_TEID, drb_p->up_ul_tnl[0].gtp_teid);
+      OCTET_STRING_TO_INT32(&ul_up_tnl0->gTP_TEID, drb_p->up_ul_tnl[0].teid);
+      // 3GPP assumes GTP-U is on port 2152, but OAI is configurable
+      drb_p->up_ul_tnl[0].port=getCxt(false,instance)->setupReq.CUport;
 
       switch (drbs_tobesetup_item_p->rLCMode) {
         case F1AP_RLCMode_rlc_am:
@@ -176,363 +169,404 @@ int DU_handle_UE_CONTEXT_SETUP_REQUEST(instance_t       instance,
           drb_p->rlc_mode = RLC_MODE_TM;
           break;
       }
+
+      if (!(RC.nrrrc && RC.nrrrc[instance]->node_type == ngran_gNB_DU)) {
+        transport_layer_addr_t addr;
+        memcpy(addr.buffer, &drb_p->up_ul_tnl[0].tl_address, sizeof(drb_p->up_ul_tnl[0].tl_address));
+        addr.length=sizeof(drb_p->up_ul_tnl[0].tl_address)*8;
+        drb_p->up_dl_tnl[0].teid=newGtpuCreateTunnel(INSTANCE_DEFAULT,
+                                 f1ap_ue_context_setup_req->rnti,
+                                 drb_p->drb_id,
+                                 drb_p->drb_id,
+                                 drb_p->up_ul_tnl[0].teid,
+                                 addr,
+                                 drb_p->up_ul_tnl[0].port,
+                                 lteDURecvCb);
+        drb_p->up_dl_tnl_length++;
+      }
     }
   }
 
+  /* SRB */
+  F1AP_UEContextSetupRequestIEs_t *ieSrb;
+  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_UEContextSetupRequestIEs_t, ieSrb, container,
+                             F1AP_ProtocolIE_ID_id_SRBs_ToBeSetup_List, false);
+
+  if(ieSrb != NULL) {
+    f1ap_ue_context_setup_req->srbs_to_be_setup_length = ieSrb->value.choice.SRBs_ToBeSetup_List.list.count;
+    f1ap_ue_context_setup_req->srbs_to_be_setup = calloc(f1ap_ue_context_setup_req->srbs_to_be_setup_length,
+        sizeof(f1ap_srb_to_be_setup_t));
+    AssertFatal(f1ap_ue_context_setup_req->srbs_to_be_setup,
+                "could not allocate memory for f1ap_ue_context_setup_req->srbs_to_be_setup\n");
+
+    for (i = 0; i < f1ap_ue_context_setup_req->srbs_to_be_setup_length; ++i) {
+      f1ap_srb_to_be_setup_t *srb_p = &f1ap_ue_context_setup_req->srbs_to_be_setup[i];
+      F1AP_SRBs_ToBeSetup_Item_t *srbs_tobesetup_item_p;
+      srbs_tobesetup_item_p = &((F1AP_SRBs_ToBeSetup_ItemIEs_t *)ieSrb->value.choice.SRBs_ToBeSetup_List.list.array[i])->value.choice.SRBs_ToBeSetup_Item;
+      srb_p->srb_id = srbs_tobesetup_item_p->sRBID;
+    }
+  }
+
+  /* RRCContainer */
+  F1AP_UEContextSetupRequestIEs_t *ieRRC;
+  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_UEContextSetupRequestIEs_t, ieRRC, container,
+                             F1AP_ProtocolIE_ID_id_RRCContainer, false);
+
+  if (ieRRC) {
+    /* correct here */
+    if ( ieRRC->value.choice.RRCContainer.size )  {
+      f1ap_ue_context_setup_req->rrc_container = malloc(ieRRC->value.choice.RRCContainer.size);
+      memcpy(f1ap_ue_context_setup_req->rrc_container,
+             ieRRC->value.choice.RRCContainer.buf, ieRRC->value.choice.RRCContainer.size);
+      // AssertFatal(0, "check configuration, send to appropriate handler\n");
+      protocol_ctxt_t ctxt;
+      // decode RRC Container and act on the message type
+      //FIXME
+      //rnti_t rnti      = f1ap_get_rnti_by_du_id(DUtype, instance, du_ue_f1ap_id);
+      ctxt.instance = instance;
+      ctxt.instance  = instance;
+      ctxt.enb_flag  = 1;
+      mem_block_t *pdcp_pdu_p = get_free_mem_block(ieRRC->value.choice.RRCContainer.size, __func__);
+      memcpy(&pdcp_pdu_p->data[0], ieRRC->value.choice.RRCContainer.buf, ieRRC->value.choice.RRCContainer.size);
+      du_rlc_data_req(&ctxt, 1, 0x00, 1, 1, 0, ieRRC->value.choice.RRCContainer.size, pdcp_pdu_p);
+    } else {
+      LOG_E(F1AP, " RRCContainer in UEContextSetupRequestIEs size id 0\n");
+    }
+  } else {
+    LOG_W(F1AP, "can't find RRCContainer in UEContextSetupRequestIEs by id %ld \n", F1AP_ProtocolIE_ID_id_RRCContainer);
+  }
+
+  if (RC.nrrrc && RC.nrrrc[instance]->node_type == ngran_gNB_DU)
+    itti_send_msg_to_task(TASK_RRC_GNB, instance, msg_p);
+  else
+    // in 4G, race conditon is to fix
+    DU_send_UE_CONTEXT_SETUP_RESPONSE(instance,  f1ap_ue_context_setup_req);
+
   return 0;
 }
 
-//void DU_send_UE_CONTEXT_SETUP_RESPONSE(F1AP_UEContextSetupResponse_t *UEContextSetupResponse) {
-int DU_send_UE_CONTEXT_SETUP_RESPONSE(instance_t instance) {
-  F1AP_F1AP_PDU_t                  pdu;
+int DU_send_UE_CONTEXT_SETUP_RESPONSE(instance_t instance, f1ap_ue_context_setup_t *req) {
+  F1AP_F1AP_PDU_t                  pdu= {0};
   F1AP_UEContextSetupResponse_t    *out;
-  F1AP_UEContextSetupResponseIEs_t *ie;
-  uint8_t  *buffer;
-  uint32_t  len;
-  int       i = 0, j = 0;
-  rnti_t    rntiP;  // note: need get value
+  uint8_t  *buffer=NULL;
+  uint32_t  len=0;
   /* Create */
   /* 0. Message Type */
-  memset(&pdu, 0, sizeof(pdu));
   pdu.present = F1AP_F1AP_PDU_PR_successfulOutcome;
-  pdu.choice.successfulOutcome = (F1AP_SuccessfulOutcome_t *)calloc(1, sizeof(F1AP_SuccessfulOutcome_t));
-  pdu.choice.successfulOutcome->procedureCode = F1AP_ProcedureCode_id_UEContextSetup;
-  pdu.choice.successfulOutcome->criticality   = F1AP_Criticality_reject;
-  pdu.choice.successfulOutcome->value.present = F1AP_SuccessfulOutcome__value_PR_UEContextSetupResponse;
-  out = &pdu.choice.successfulOutcome->value.choice.UEContextSetupResponse;
+  asn1cCalloc(pdu.choice.successfulOutcome, tmp);
+  tmp->procedureCode = F1AP_ProcedureCode_id_UEContextSetup;
+  tmp->criticality   = F1AP_Criticality_reject;
+  tmp->value.present = F1AP_SuccessfulOutcome__value_PR_UEContextSetupResponse;
+  out = &tmp->value.choice.UEContextSetupResponse;
   /* mandatory */
   /* c1. GNB_CU_UE_F1AP_ID */
-  ie = (F1AP_UEContextSetupResponseIEs_t *)calloc(1, sizeof(F1AP_UEContextSetupResponseIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
-  ie->criticality                    = F1AP_Criticality_reject;
-  ie->value.present                  = F1AP_UEContextSetupResponseIEs__value_PR_GNB_CU_UE_F1AP_ID;
-  ie->value.choice.GNB_CU_UE_F1AP_ID = 126L;
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextSetupResponseIEs_t, ie1);
+  ie1->id                             = F1AP_ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
+  ie1->criticality                    = F1AP_Criticality_reject;
+  ie1->value.present                  = F1AP_UEContextSetupResponseIEs__value_PR_GNB_CU_UE_F1AP_ID;
+  ie1->value.choice.GNB_CU_UE_F1AP_ID = req->gNB_CU_ue_id;
   /* mandatory */
   /* c2. GNB_DU_UE_F1AP_ID */
-  ie = (F1AP_UEContextSetupResponseIEs_t *)calloc(1, sizeof(F1AP_UEContextSetupResponseIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
-  ie->criticality                    = F1AP_Criticality_reject;
-  ie->value.present                  = F1AP_UEContextSetupResponseIEs__value_PR_GNB_DU_UE_F1AP_ID;
-  ie->value.choice.GNB_DU_UE_F1AP_ID = 651L;
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextSetupResponseIEs_t, ie2);
+  ie2->id                             = F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
+  ie2->criticality                    = F1AP_Criticality_reject;
+  ie2->value.present                  = F1AP_UEContextSetupResponseIEs__value_PR_GNB_DU_UE_F1AP_ID;
+  ie2->value.choice.GNB_DU_UE_F1AP_ID = f1ap_get_du_ue_f1ap_id(DUtype, instance, req->rnti);
   /* mandatory */
   /* c3. DUtoCURRCInformation */
-  ie = (F1AP_UEContextSetupResponseIEs_t *)calloc(1, sizeof(F1AP_UEContextSetupResponseIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_DUtoCURRCInformation;
-  ie->criticality                    = F1AP_Criticality_reject;
-  ie->value.present                  = F1AP_UEContextSetupResponseIEs__value_PR_DUtoCURRCInformation;
+  //if (0) {
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextSetupResponseIEs_t, ie3);
+  ie3->id                             = F1AP_ProtocolIE_ID_id_DUtoCURRCInformation;
+  ie3->criticality                    = F1AP_Criticality_reject;
+  ie3->value.present                  = F1AP_UEContextSetupResponseIEs__value_PR_DUtoCURRCInformation;
   {
     /* cellGroupConfig */
-    OCTET_STRING_fromBuf(&ie->value.choice.DUtoCURRCInformation.cellGroupConfig, "asdsa",
-                         strlen("asdsa"));
+    OCTET_STRING_fromBuf(&ie3->value.choice.DUtoCURRCInformation.cellGroupConfig, (const char *)req->du_to_cu_rrc_information,
+                         req->du_to_cu_rrc_information_length);
 
     /* OPTIONAL */
     /* measGapConfig */
     if (0) {
-      ie->value.choice.DUtoCURRCInformation.measGapConfig = (F1AP_MeasGapConfig_t *)calloc(1, sizeof(F1AP_MeasGapConfig_t));
-      OCTET_STRING_fromBuf( ie->value.choice.DUtoCURRCInformation.measGapConfig, "asdsa",
-                            strlen("asdsa"));
+      asn1cCalloc(ie3->value.choice.DUtoCURRCInformation.measGapConfig, tmp);
+      OCTET_STRING_fromBuf(tmp, "asdsa", strlen("asdsa"));
     }
 
     /* OPTIONAL */
     /* requestedP_MaxFR1 */
     if (0) {
-      ie->value.choice.DUtoCURRCInformation.requestedP_MaxFR1 = (OCTET_STRING_t *)calloc(1, sizeof(OCTET_STRING_t));
-      OCTET_STRING_fromBuf( ie->value.choice.DUtoCURRCInformation.requestedP_MaxFR1, "asdsa",
-                            strlen("asdsa"));
+      asn1cCalloc(ie3->value.choice.DUtoCURRCInformation.requestedP_MaxFR1, tmp);
+      OCTET_STRING_fromBuf(tmp, "asdsa", strlen("asdsa"));
     }
-
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
   }
+  //}
 
   /* optional */
   /* c4. C_RNTI */
   if (0) {
-    ie = (F1AP_UEContextSetupResponseIEs_t *)calloc(1, sizeof(F1AP_UEContextSetupResponseIEs_t));
-    ie->id                             = F1AP_ProtocolIE_ID_id_C_RNTI;
-    ie->criticality                    = F1AP_Criticality_ignore;
-    ie->value.present                  = F1AP_UEContextSetupResponseIEs__value_PR_C_RNTI;
+    asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextSetupResponseIEs_t, ie4);
+    ie4->id                             = F1AP_ProtocolIE_ID_id_C_RNTI;
+    ie4->criticality                    = F1AP_Criticality_ignore;
+    ie4->value.present                  = F1AP_UEContextSetupResponseIEs__value_PR_C_RNTI;
     //C_RNTI_TO_BIT_STRING(rntiP, &ie->value.choice.C_RNTI);
-    ie->value.choice.C_RNTI=rntiP;
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    ie4->value.choice.C_RNTI=req->rnti;
+    LOG_E(F1AP,"RNTI to code!\n");
   }
 
   /* optional */
   /* c5. ResourceCoordinationTransferContainer */
   if (0) {
-    ie = (F1AP_UEContextSetupResponseIEs_t *)calloc(1, sizeof(F1AP_UEContextSetupResponseIEs_t));
-    ie->id                             = F1AP_ProtocolIE_ID_id_ResourceCoordinationTransferContainer;
-    ie->criticality                    = F1AP_Criticality_ignore;
-    ie->value.present                  = F1AP_UEContextSetupResponseIEs__value_PR_ResourceCoordinationTransferContainer;
-    OCTET_STRING_fromBuf(&ie->value.choice.ResourceCoordinationTransferContainer, "asdsa",
+    asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextSetupResponseIEs_t, ie5);
+    ie5->id                             = F1AP_ProtocolIE_ID_id_ResourceCoordinationTransferContainer;
+    ie5->criticality                    = F1AP_Criticality_ignore;
+    ie5->value.present                  = F1AP_UEContextSetupResponseIEs__value_PR_ResourceCoordinationTransferContainer;
+    OCTET_STRING_fromBuf(&ie5->value.choice.ResourceCoordinationTransferContainer, "asdsa",
                          strlen("asdsa"));
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
   }
 
   /* optional */
   /* c6. FullConfiguration */
   if (0) {
-    ie = (F1AP_UEContextSetupResponseIEs_t *)calloc(1, sizeof(F1AP_UEContextSetupResponseIEs_t));
-    ie->id                             = F1AP_ProtocolIE_ID_id_FullConfiguration;
-    ie->criticality                    = F1AP_Criticality_ignore;
-    ie->value.present                  = F1AP_UEContextSetupResponseIEs__value_PR_FullConfiguration;
-    ie->value.choice.FullConfiguration = F1AP_FullConfiguration_full;   //enum
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextSetupResponseIEs_t, ie6);
+    ie6->id                             = F1AP_ProtocolIE_ID_id_FullConfiguration;
+    ie6->criticality                    = F1AP_Criticality_ignore;
+    ie6->value.present                  = F1AP_UEContextSetupResponseIEs__value_PR_FullConfiguration;
+    ie6->value.choice.FullConfiguration = F1AP_FullConfiguration_full;   //enum
   }
 
   /* mandatory */
   /* c7. DRBs_Setup_List */
-  ie = (F1AP_UEContextSetupResponseIEs_t *)calloc(1, sizeof(F1AP_UEContextSetupResponseIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_DRBs_Setup_List;
-  ie->criticality                    = F1AP_Criticality_ignore;
-  ie->value.present                  = F1AP_UEContextSetupResponseIEs__value_PR_DRBs_Setup_List;
-
-  for (i=0;
-       i<1;
-       i++) {
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextSetupResponseIEs_t, ie7);
+  ie7->id                             = F1AP_ProtocolIE_ID_id_DRBs_Setup_List;
+  ie7->criticality                    = F1AP_Criticality_ignore;
+  ie7->value.present                  = F1AP_UEContextSetupResponseIEs__value_PR_DRBs_Setup_List;
+
+  for (int i=0;  i< req->drbs_to_be_setup_length; i++) {
     //
-    F1AP_DRBs_Setup_ItemIEs_t *drbs_setup_item_ies;
-    drbs_setup_item_ies = (F1AP_DRBs_Setup_ItemIEs_t *)calloc(1, sizeof(F1AP_DRBs_Setup_ItemIEs_t));
+    asn1cSequenceAdd(ie7->value.choice.DRBs_Setup_List.list,
+                     F1AP_DRBs_Setup_ItemIEs_t, drbs_setup_item_ies);
     drbs_setup_item_ies->id            = F1AP_ProtocolIE_ID_id_DRBs_Setup_Item;
     drbs_setup_item_ies->criticality   = F1AP_Criticality_ignore;
     drbs_setup_item_ies->value.present = F1AP_SRBs_FailedToBeSetup_ItemIEs__value_PR_SRBs_FailedToBeSetup_Item;
     /* 7.1 DRBs_Setup_Item */
-    F1AP_DRBs_Setup_Item_t drbs_setup_item;
-    memset((void *)&drbs_setup_item, 0, sizeof(F1AP_DRBs_Setup_Item_t));
+    /* ADD */
+    F1AP_DRBs_Setup_Item_t *drbs_setup_item=&drbs_setup_item_ies->value.choice.DRBs_Setup_Item;
     /* dRBID */
-    drbs_setup_item.dRBID = 12;
+    drbs_setup_item->dRBID = req->drbs_to_be_setup[i].drb_id;
 
     /* OPTIONAL */
     /* lCID */
     //drbs_setup_item.lCID = (F1AP_LCID_t *)calloc(1, sizeof(F1AP_LCID_t));
     //drbs_setup_item.lCID = 1L;
 
-    for (j=0;
-         j<1;
-         j++) {
-      F1AP_DLUPTNLInformation_ToBeSetup_Item_t *dLUPTNLInformation_ToBeSetup_Item;
-      dLUPTNLInformation_ToBeSetup_Item = (F1AP_DLUPTNLInformation_ToBeSetup_Item_t *)calloc(1, sizeof(F1AP_DLUPTNLInformation_ToBeSetup_Item_t));
+    for (int j=0;  j<req->drbs_to_be_setup[i].up_dl_tnl_length; j++) {
+      /* ADD */
+      asn1cSequenceAdd(drbs_setup_item->dLUPTNLInformation_ToBeSetup_List.list,
+                       F1AP_DLUPTNLInformation_ToBeSetup_Item_t, dLUPTNLInformation_ToBeSetup_Item);
       dLUPTNLInformation_ToBeSetup_Item->dLUPTNLInformation.present = F1AP_UPTransportLayerInformation_PR_gTPTunnel;
       /* gTPTunnel */
-      F1AP_GTPTunnel_t *gTPTunnel = (F1AP_GTPTunnel_t *)calloc(1, sizeof(F1AP_GTPTunnel_t));
-      {
-        /* transportLayerAddress */
-        TRANSPORT_LAYER_ADDRESS_IPv4_TO_BIT_STRING(1234, &gTPTunnel->transportLayerAddress);
-        /* gTP_TEID */
-        OCTET_STRING_fromBuf(&gTPTunnel->gTP_TEID, "1204",
-                             strlen("1204"));
-        dLUPTNLInformation_ToBeSetup_Item->dLUPTNLInformation.choice.gTPTunnel = gTPTunnel;
-      }
-      /* ADD */
-      ASN_SEQUENCE_ADD(&drbs_setup_item.dLUPTNLInformation_ToBeSetup_List.list,
-                       dLUPTNLInformation_ToBeSetup_Item);
+      asn1cCalloc(dLUPTNLInformation_ToBeSetup_Item->dLUPTNLInformation.choice.gTPTunnel,gTPTunnel);
+      /* transportLayerAddress */
+      struct sockaddr_in addr= {0};
+      inet_pton(AF_INET, getCxt(false,instance)->setupReq.DU_f1_ip_address.ipv4_address,
+                &addr.sin_addr.s_addr);
+      TRANSPORT_LAYER_ADDRESS_IPv4_TO_BIT_STRING(addr.sin_addr.s_addr,
+          &gTPTunnel->transportLayerAddress);
+      /* gTP_TEID */
+      INT32_TO_OCTET_STRING(req->drbs_to_be_setup[i].up_dl_tnl[j].teid, &gTPTunnel->gTP_TEID);
     } // for j
-
-    /* ADD */
-    drbs_setup_item_ies->value.choice.DRBs_Setup_Item = drbs_setup_item;
-    ASN_SEQUENCE_ADD(&ie->value.choice.DRBs_Setup_List.list,
-                     drbs_setup_item_ies);
   } // for i
 
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
   /* mandatory */
   /* c8. SRBs_FailedToBeSetup_List */
-  ie = (F1AP_UEContextSetupResponseIEs_t *)calloc(1, sizeof(F1AP_UEContextSetupResponseIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_SRBs_FailedToBeSetup_List;
-  ie->criticality                    = F1AP_Criticality_ignore;
-  ie->value.present                  = F1AP_UEContextSetupResponseIEs__value_PR_SRBs_FailedToBeSetup_List;
-
-  for (i=0;
-       i<1;
-       i++) {
-    //
-    F1AP_SRBs_FailedToBeSetup_ItemIEs_t *srbs_failedToBeSetup_item_ies;
-    srbs_failedToBeSetup_item_ies = (F1AP_SRBs_FailedToBeSetup_ItemIEs_t *)calloc(1, sizeof(F1AP_SRBs_FailedToBeSetup_ItemIEs_t));
-    srbs_failedToBeSetup_item_ies->id            = F1AP_ProtocolIE_ID_id_SRBs_FailedToBeSetup_Item;
-    srbs_failedToBeSetup_item_ies->criticality   = F1AP_Criticality_ignore;
-    srbs_failedToBeSetup_item_ies->value.present = F1AP_SRBs_FailedToBeSetup_ItemIEs__value_PR_SRBs_FailedToBeSetup_Item;
-    /* 8.1 SRBs_Setup_Item */
-    F1AP_SRBs_FailedToBeSetup_Item_t srbs_failedToBeSetup_item;
-    memset((void *)&srbs_failedToBeSetup_item, 0, sizeof(F1AP_SRBs_FailedToBeSetup_Item_t));
-    /* sRBID */
-    srbs_failedToBeSetup_item.sRBID = 13L;
-    /* cause */
-    srbs_failedToBeSetup_item.cause = (F1AP_Cause_t *)calloc(1, sizeof(F1AP_Cause_t));
-    // dummy value
-    srbs_failedToBeSetup_item.cause->present = F1AP_Cause_PR_radioNetwork;
-
-    switch(srbs_failedToBeSetup_item.cause->present) {
-      case F1AP_Cause_PR_radioNetwork:
-        srbs_failedToBeSetup_item.cause->choice.radioNetwork = F1AP_CauseRadioNetwork_unspecified;
-        break;
-
-      case F1AP_Cause_PR_transport:
-        srbs_failedToBeSetup_item.cause->choice.transport = F1AP_CauseTransport_unspecified;
-        break;
+  if(0) {
+    asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextSetupResponseIEs_t, ie8);
+    ie8->id                             = F1AP_ProtocolIE_ID_id_SRBs_FailedToBeSetup_List;
+    ie8->criticality                    = F1AP_Criticality_ignore;
+    ie8->value.present                  = F1AP_UEContextSetupResponseIEs__value_PR_SRBs_FailedToBeSetup_List;
+
+    for (int i=0;  i<1; i++) {
+      //
+      asn1cSequenceAdd(ie8->value.choice.SRBs_FailedToBeSetup_List.list,
+                       F1AP_SRBs_FailedToBeSetup_ItemIEs_t, srbs_failedToBeSetup_item_ies);
+      srbs_failedToBeSetup_item_ies->id            = F1AP_ProtocolIE_ID_id_SRBs_FailedToBeSetup_Item;
+      srbs_failedToBeSetup_item_ies->criticality   = F1AP_Criticality_ignore;
+      srbs_failedToBeSetup_item_ies->value.present = F1AP_SRBs_FailedToBeSetup_ItemIEs__value_PR_SRBs_FailedToBeSetup_Item;
+      /* 8.1 SRBs_Setup_Item */
+      F1AP_SRBs_FailedToBeSetup_Item_t *srbs_failedToBeSetup_item=
+        &srbs_failedToBeSetup_item_ies->value.choice.SRBs_FailedToBeSetup_Item;
+      /* sRBID */
+      srbs_failedToBeSetup_item->sRBID = 13L;
+      /* cause */
+      asn1cCalloc(srbs_failedToBeSetup_item->cause, tmp);
+      // dummy value
+      tmp->present = F1AP_Cause_PR_radioNetwork;
+
+      switch(tmp->present) {
+        case F1AP_Cause_PR_radioNetwork:
+          tmp->choice.radioNetwork = F1AP_CauseRadioNetwork_unspecified;
+          break;
 
-      case F1AP_Cause_PR_protocol:
-        srbs_failedToBeSetup_item.cause->choice.protocol = F1AP_CauseProtocol_unspecified;
-        break;
+        case F1AP_Cause_PR_transport:
+          tmp->choice.transport = F1AP_CauseTransport_unspecified;
+          break;
 
-      case F1AP_Cause_PR_misc:
-        srbs_failedToBeSetup_item.cause->choice.misc = F1AP_CauseMisc_unspecified;
-        break;
+        case F1AP_Cause_PR_protocol:
+          tmp->choice.protocol = F1AP_CauseProtocol_unspecified;
+          break;
 
-      case F1AP_Cause_PR_NOTHING:
-      default:
-        break;
-    } // switch
+        case F1AP_Cause_PR_misc:
+          tmp->choice.misc = F1AP_CauseMisc_unspecified;
+          break;
 
-    /* ADD */
-    srbs_failedToBeSetup_item_ies->value.choice.SRBs_FailedToBeSetup_Item = srbs_failedToBeSetup_item;
-    ASN_SEQUENCE_ADD(&ie->value.choice.SRBs_FailedToBeSetup_List.list,
-                     srbs_failedToBeSetup_item_ies);
-  } // for i
+        case F1AP_Cause_PR_NOTHING:
+        default:
+          break;
+      } // switch
+    } // for i
+  }
 
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
   /*  */
   /* c9. DRBs_FailedToBeSetup_List */
-  ie = (F1AP_UEContextSetupResponseIEs_t *)calloc(1, sizeof(F1AP_UEContextSetupResponseIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_DRBs_FailedToBeSetup_List;
-  ie->criticality                    = F1AP_Criticality_ignore;
-  ie->value.present                  = F1AP_UEContextSetupResponseIEs__value_PR_DRBs_FailedToBeSetup_List;
-
-  for (i=0;
-       i<1;
-       i++) {
-    //
-    F1AP_DRBs_FailedToBeSetup_ItemIEs_t *drbs_failedToBeSetup_item_ies;
-    drbs_failedToBeSetup_item_ies = (F1AP_DRBs_FailedToBeSetup_ItemIEs_t *)calloc(1, sizeof(F1AP_DRBs_FailedToBeSetup_ItemIEs_t));
-    drbs_failedToBeSetup_item_ies->id            = F1AP_ProtocolIE_ID_id_DRBs_FailedToBeSetup_Item;
-    drbs_failedToBeSetup_item_ies->criticality   = F1AP_Criticality_ignore;
-    drbs_failedToBeSetup_item_ies->value.present = F1AP_DRBs_FailedToBeSetup_ItemIEs__value_PR_DRBs_FailedToBeSetup_Item;
-    /* 9.1 DRBs_Setup_Item */
-    F1AP_DRBs_FailedToBeSetup_Item_t drbs_failedToBeSetup_item;
-    memset((void *)&drbs_failedToBeSetup_item, 0, sizeof(F1AP_DRBs_FailedToBeSetup_Item_t));
-    /* dRBID */
-    drbs_failedToBeSetup_item.dRBID = 14;
-    /* cause */
-    drbs_failedToBeSetup_item.cause = (F1AP_Cause_t *)calloc(1, sizeof(F1AP_Cause_t));
-    // dummy value
-    drbs_failedToBeSetup_item.cause->present = F1AP_Cause_PR_radioNetwork;
-
-    switch(drbs_failedToBeSetup_item.cause->present) {
-      case F1AP_Cause_PR_radioNetwork:
-        drbs_failedToBeSetup_item.cause->choice.radioNetwork = F1AP_CauseRadioNetwork_unspecified;
-        break;
-
-      case F1AP_Cause_PR_transport:
-        drbs_failedToBeSetup_item.cause->choice.transport = F1AP_CauseTransport_unspecified;
-        break;
+  if(0) {
+    asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextSetupResponseIEs_t, ie9);
+    ie9->id                             = F1AP_ProtocolIE_ID_id_DRBs_FailedToBeSetup_List;
+    ie9->criticality                    = F1AP_Criticality_ignore;
+    ie9->value.present                  = F1AP_UEContextSetupResponseIEs__value_PR_DRBs_FailedToBeSetup_List;
+
+    for (int i=0;  i<1; i++) {
+      asn1cSequenceAdd(ie9->value.choice.DRBs_FailedToBeSetup_List.list,
+                       F1AP_DRBs_FailedToBeSetup_ItemIEs_t, drbs_failedToBeSetup_item_ies);
+      drbs_failedToBeSetup_item_ies->id            = F1AP_ProtocolIE_ID_id_DRBs_FailedToBeSetup_Item;
+      drbs_failedToBeSetup_item_ies->criticality   = F1AP_Criticality_ignore;
+      drbs_failedToBeSetup_item_ies->value.present = F1AP_DRBs_FailedToBeSetup_ItemIEs__value_PR_DRBs_FailedToBeSetup_Item;
+      /* 9.1 DRBs_Setup_Item */
+      /* ADD */
+      F1AP_DRBs_FailedToBeSetup_Item_t *drbs_failedToBeSetup_item=
+        &drbs_failedToBeSetup_item_ies->value.choice.DRBs_FailedToBeSetup_Item;
+      /* dRBID */
+      drbs_failedToBeSetup_item->dRBID = 14;
+      /* cause */
+      asn1cCalloc(drbs_failedToBeSetup_item->cause,tmp);
+      // dummy value
+      tmp->present = F1AP_Cause_PR_radioNetwork;
+
+      switch(tmp->present) {
+        case F1AP_Cause_PR_radioNetwork:
+          tmp->choice.radioNetwork = F1AP_CauseRadioNetwork_unspecified;
+          break;
 
-      case F1AP_Cause_PR_protocol:
-        drbs_failedToBeSetup_item.cause->choice.protocol = F1AP_CauseProtocol_unspecified;
-        break;
+        case F1AP_Cause_PR_transport:
+          tmp->choice.transport = F1AP_CauseTransport_unspecified;
+          break;
 
-      case F1AP_Cause_PR_misc:
-        drbs_failedToBeSetup_item.cause->choice.misc = F1AP_CauseMisc_unspecified;
-        break;
+        case F1AP_Cause_PR_protocol:
+          tmp->choice.protocol = F1AP_CauseProtocol_unspecified;
+          break;
 
-      case F1AP_Cause_PR_NOTHING:
-      default:
-        break;
-    } // switch
+        case F1AP_Cause_PR_misc:
+          tmp->choice.misc = F1AP_CauseMisc_unspecified;
+          break;
 
-    /* ADD */
-    drbs_failedToBeSetup_item_ies->value.choice.DRBs_FailedToBeSetup_Item = drbs_failedToBeSetup_item;
-    ASN_SEQUENCE_ADD(&ie->value.choice.DRBs_FailedToBeSetup_List.list,
-                     drbs_failedToBeSetup_item_ies);
-  } // for i
+        case F1AP_Cause_PR_NOTHING:
+        default:
+          break;
+      } // switch
+    } // for i
+  }
 
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
   // /*  */
   /* c10. SCell_FailedtoSetup_List */
-  ie = (F1AP_UEContextSetupResponseIEs_t *)calloc(1, sizeof(F1AP_UEContextSetupResponseIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_SCell_FailedtoSetup_List;
-  ie->criticality                    = F1AP_Criticality_ignore;
-  ie->value.present                  = F1AP_UEContextSetupResponseIEs__value_PR_SCell_FailedtoSetup_List;
-
-  for (i=0;
-       i<1;
-       i++) {
-    //
-    F1AP_SCell_FailedtoSetup_ItemIEs_t *sCell_FailedtoSetup_item_ies;
-    sCell_FailedtoSetup_item_ies = (F1AP_SCell_FailedtoSetup_ItemIEs_t *)calloc(1, sizeof(F1AP_SCell_FailedtoSetup_ItemIEs_t));
-    sCell_FailedtoSetup_item_ies->id            = F1AP_ProtocolIE_ID_id_SCell_FailedtoSetup_Item;
-    sCell_FailedtoSetup_item_ies->criticality   = F1AP_Criticality_ignore;
-    sCell_FailedtoSetup_item_ies->value.present = F1AP_SCell_FailedtoSetup_ItemIEs__value_PR_SCell_FailedtoSetup_Item;
-    /* 10.1 DRBs_Setup_Item */
-    F1AP_SCell_FailedtoSetup_Item_t sCell_FailedtoSetup_item;
-    memset((void *)&sCell_FailedtoSetup_item, 0, sizeof(F1AP_SCell_FailedtoSetup_Item_t));
-    /* sCell_ID */
-    F1AP_NRCGI_t nRCGI;  // issue here
-    memset(&nRCGI, 0, sizeof(F1AP_NRCGI_t));
-    MCC_MNC_TO_PLMNID(f1ap_du_data->mcc[i], f1ap_du_data->mnc[i], f1ap_du_data->mnc_digit_length[i], &nRCGI.pLMN_Identity);
-    NR_CELL_ID_TO_BIT_STRING(f1ap_du_data->nr_cellid[0], &nRCGI.nRCellIdentity);
-    sCell_FailedtoSetup_item.sCell_ID = nRCGI;
-    /* cause */
-    sCell_FailedtoSetup_item.cause = (F1AP_Cause_t *)calloc(1, sizeof(F1AP_Cause_t));
-    // dummy value
-    sCell_FailedtoSetup_item.cause->present = F1AP_Cause_PR_radioNetwork;
-
-    switch(sCell_FailedtoSetup_item.cause->present) {
-      case F1AP_Cause_PR_radioNetwork:
-        sCell_FailedtoSetup_item.cause->choice.radioNetwork = F1AP_CauseRadioNetwork_unspecified;
-        break;
+  if(0) {
+    asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextSetupResponseIEs_t, ie10);
+    ie10->id                             = F1AP_ProtocolIE_ID_id_SCell_FailedtoSetup_List;
+    ie10->criticality                    = F1AP_Criticality_ignore;
+    ie10->value.present                  = F1AP_UEContextSetupResponseIEs__value_PR_SCell_FailedtoSetup_List;
+
+    for (int i=0;   i<1; i++) {
+      asn1cSequenceAdd(ie10->value.choice.SCell_FailedtoSetup_List.list,
+                       F1AP_SCell_FailedtoSetup_ItemIEs_t, sCell_FailedtoSetup_item_ies);
+      sCell_FailedtoSetup_item_ies->id            = F1AP_ProtocolIE_ID_id_SCell_FailedtoSetup_Item;
+      sCell_FailedtoSetup_item_ies->criticality   = F1AP_Criticality_ignore;
+      sCell_FailedtoSetup_item_ies->value.present = F1AP_SCell_FailedtoSetup_ItemIEs__value_PR_SCell_FailedtoSetup_Item;
+      /* 10.1 DRBs_Setup_Item */
+      F1AP_SCell_FailedtoSetup_Item_t *sCell_FailedtoSetup_item=
+        &sCell_FailedtoSetup_item_ies->value.choice.SCell_FailedtoSetup_Item;
+      /* sCell_ID */
+      addnRCGI(sCell_FailedtoSetup_item->sCell_ID,f1ap_req(false, instance)->cell+i);
+      /* cause */
+      asn1cCalloc(sCell_FailedtoSetup_item->cause, tmp);
+      // dummy value
+      tmp->present = F1AP_Cause_PR_radioNetwork;
+
+      switch(tmp->present) {
+        case F1AP_Cause_PR_radioNetwork:
+          tmp->choice.radioNetwork = F1AP_CauseRadioNetwork_unspecified;
+          break;
 
-      case F1AP_Cause_PR_transport:
-        sCell_FailedtoSetup_item.cause->choice.transport = F1AP_CauseTransport_unspecified;
-        break;
+        case F1AP_Cause_PR_transport:
+          tmp->choice.transport = F1AP_CauseTransport_unspecified;
+          break;
 
-      case F1AP_Cause_PR_protocol:
-        sCell_FailedtoSetup_item.cause->choice.protocol = F1AP_CauseProtocol_unspecified;
-        break;
+        case F1AP_Cause_PR_protocol:
+          tmp->choice.protocol = F1AP_CauseProtocol_unspecified;
+          break;
 
-      case F1AP_Cause_PR_misc:
-        sCell_FailedtoSetup_item.cause->choice.misc = F1AP_CauseMisc_unspecified;
-        break;
+        case F1AP_Cause_PR_misc:
+          tmp->choice.misc = F1AP_CauseMisc_unspecified;
+          break;
 
-      case F1AP_Cause_PR_NOTHING:
-      default:
-        break;
-    } // switch
+        case F1AP_Cause_PR_NOTHING:
+        default:
+          break;
+      } // switch
+    } // for i
+  }
 
+  /* mandatory */
+  /* c11. SRBs_Setup_List */
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextSetupResponseIEs_t, ie11);
+  ie11->id                             = F1AP_ProtocolIE_ID_id_SRBs_Setup_List;
+  ie11->criticality                    = F1AP_Criticality_ignore;
+  ie11->value.present                  = F1AP_UEContextSetupResponseIEs__value_PR_SRBs_Setup_List;
+
+  for (int i=0;  i< req->srbs_to_be_setup_length; i++) {//
+    asn1cSequenceAdd(ie11->value.choice.SRBs_Setup_List.list,
+                     F1AP_SRBs_Setup_ItemIEs_t, srbs_setup_item_ies);
+    srbs_setup_item_ies->id            = F1AP_ProtocolIE_ID_id_SRBs_Setup_Item;
+    srbs_setup_item_ies->criticality   = F1AP_Criticality_ignore;
+    srbs_setup_item_ies->value.present = F1AP_SRBs_Setup_ItemIEs__value_PR_SRBs_Setup_Item;
+    /* 11.1 SRBs_Setup_Item */
     /* ADD */
-    sCell_FailedtoSetup_item_ies->value.choice.SCell_FailedtoSetup_Item = sCell_FailedtoSetup_item;
-    ASN_SEQUENCE_ADD(&ie->value.choice.SCell_FailedtoSetup_List.list,
-                     sCell_FailedtoSetup_item_ies);
-  } // for i
-
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    F1AP_SRBs_Setup_Item_t *srbs_setup_item=&srbs_setup_item_ies->value.choice.SRBs_Setup_Item;
+    /* sRBID */
+    srbs_setup_item->sRBID = req->srbs_to_be_setup[i].srb_id;
+  }
 
   /* Optional */
-  /* c11. InactivityMonitoringResponse */
+  /* c12. InactivityMonitoringResponse */
   if (0) {
-    ie = (F1AP_UEContextSetupResponseIEs_t *)calloc(1, sizeof(F1AP_UEContextSetupResponseIEs_t));
-    ie->id                                        = F1AP_ProtocolIE_ID_id_InactivityMonitoringResponse;
-    ie->criticality                               = F1AP_Criticality_ignore;
-    ie->value.present                             = F1AP_UEContextSetupResponseIEs__value_PR_InactivityMonitoringResponse;
-    ie->value.choice.InactivityMonitoringResponse = F1AP_InactivityMonitoringResponse_not_supported;
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextSetupResponseIEs_t, ie11);
+    ie11->id                                        = F1AP_ProtocolIE_ID_id_InactivityMonitoringResponse;
+    ie11->criticality                               = F1AP_Criticality_ignore;
+    ie11->value.present                             = F1AP_UEContextSetupResponseIEs__value_PR_InactivityMonitoringResponse;
+    ie11->value.choice.InactivityMonitoringResponse = F1AP_InactivityMonitoringResponse_not_supported;
   }
 
   /* Optional */
-  /* c12. CriticalityDiagnostics */
+  /* c13. CriticalityDiagnostics */
   if (0) {
-    ie = (F1AP_UEContextSetupResponseIEs_t *)calloc(1, sizeof(F1AP_UEContextSetupResponseIEs_t));
-    ie->id                             = F1AP_ProtocolIE_ID_id_CriticalityDiagnostics;
-    ie->criticality                    = F1AP_Criticality_ignore;
-    ie->value.present                  = F1AP_UEContextSetupResponseIEs__value_PR_CriticalityDiagnostics;
-    ie->value.choice.CriticalityDiagnostics.procedureCode = (F1AP_ProcedureCode_t *)calloc(1, sizeof(F1AP_ProcedureCode_t));
-    *ie->value.choice.CriticalityDiagnostics.procedureCode = F1AP_ProcedureCode_id_UEContextSetup;
-    ie->value.choice.CriticalityDiagnostics.triggeringMessage = (F1AP_TriggeringMessage_t *)calloc(1, sizeof(F1AP_TriggeringMessage_t));
-    *ie->value.choice.CriticalityDiagnostics.triggeringMessage = F1AP_TriggeringMessage_initiating_message;
-    ie->value.choice.CriticalityDiagnostics.procedureCriticality = (F1AP_Criticality_t *)calloc(1, sizeof(F1AP_Criticality_t));
-    *ie->value.choice.CriticalityDiagnostics.procedureCriticality = F1AP_Criticality_reject;
-    ie->value.choice.CriticalityDiagnostics.transactionID = (F1AP_TransactionID_t *)calloc(1, sizeof(F1AP_TransactionID_t));
-    *ie->value.choice.CriticalityDiagnostics.transactionID = 0;
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+    asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextSetupResponseIEs_t, ie12);
+    ie12->id                             = F1AP_ProtocolIE_ID_id_CriticalityDiagnostics;
+    ie12->criticality                    = F1AP_Criticality_ignore;
+    ie12->value.present                  = F1AP_UEContextSetupResponseIEs__value_PR_CriticalityDiagnostics;
+    asn1cCallocOne(ie12->value.choice.CriticalityDiagnostics.procedureCode,
+                   F1AP_ProcedureCode_id_UEContextSetup);
+    asn1cCallocOne(ie12->value.choice.CriticalityDiagnostics.triggeringMessage,
+                   F1AP_TriggeringMessage_initiating_message);
+    asn1cCallocOne(ie12->value.choice.CriticalityDiagnostics.procedureCriticality,
+                   F1AP_Criticality_reject);
+    asn1cCallocOne(ie12->value.choice.CriticalityDiagnostics.transactionID,
+                   0);
   }
 
   /* encode */
@@ -541,98 +575,89 @@ int DU_send_UE_CONTEXT_SETUP_RESPONSE(instance_t instance) {
     return -1;
   }
 
+  f1ap_itti_send_sctp_data_req(false, instance,
+                               buffer,
+                               len,
+                               getCxt(false, instance)->default_sctp_stream_id);
   return 0;
 }
-
 int DU_send_UE_CONTEXT_SETUP_FAILURE(instance_t instance) {
   AssertFatal(1==0,"Not implemented yet\n");
 }
-
-
 int DU_send_UE_CONTEXT_RELEASE_REQUEST(instance_t instance,
                                        f1ap_ue_context_release_req_t *req) {
   F1AP_F1AP_PDU_t                   pdu;
   F1AP_UEContextReleaseRequest_t    *out;
-  F1AP_UEContextReleaseRequestIEs_t *ie;
-  uint8_t  *buffer;
-  uint32_t  len;
-  //int       i = 0, j = 0;
+  uint8_t  *buffer=NULL;
+  uint32_t  len=0;
   /* Create */
   /* 0. Message Type */
-  memset(&pdu, 0, sizeof(pdu));
   pdu.present = F1AP_F1AP_PDU_PR_initiatingMessage;
-  pdu.choice.initiatingMessage = (F1AP_InitiatingMessage_t *)calloc(1, sizeof(F1AP_InitiatingMessage_t));
-  pdu.choice.initiatingMessage->procedureCode = F1AP_ProcedureCode_id_UEContextReleaseRequest;
-  pdu.choice.initiatingMessage->criticality   = F1AP_Criticality_reject;
-  pdu.choice.initiatingMessage->value.present = F1AP_InitiatingMessage__value_PR_UEContextReleaseRequest;
-  out = &pdu.choice.initiatingMessage->value.choice.UEContextReleaseRequest;
+  asn1cCalloc(pdu.choice.initiatingMessage, tmp);
+  tmp->procedureCode = F1AP_ProcedureCode_id_UEContextReleaseRequest;
+  tmp->criticality   = F1AP_Criticality_reject;
+  tmp->value.present = F1AP_InitiatingMessage__value_PR_UEContextReleaseRequest;
+  out = &tmp->value.choice.UEContextReleaseRequest;
   /* mandatory */
   /* c1. GNB_CU_UE_F1AP_ID */
-  ie = (F1AP_UEContextReleaseRequestIEs_t *)calloc(1, sizeof(F1AP_UEContextReleaseRequestIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
-  ie->criticality                    = F1AP_Criticality_reject;
-  ie->value.present                  = F1AP_UEContextReleaseRequestIEs__value_PR_GNB_CU_UE_F1AP_ID;
-  ie->value.choice.GNB_CU_UE_F1AP_ID = f1ap_get_cu_ue_f1ap_id(&f1ap_du_inst[instance], req->rnti);
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextReleaseRequestIEs_t, ie1);
+  ie1->id                             = F1AP_ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
+  ie1->criticality                    = F1AP_Criticality_reject;
+  ie1->value.present                  = F1AP_UEContextReleaseRequestIEs__value_PR_GNB_CU_UE_F1AP_ID;
+  ie1->value.choice.GNB_CU_UE_F1AP_ID = f1ap_get_cu_ue_f1ap_id(DUtype, instance, req->rnti);
   /* mandatory */
   /* c2. GNB_DU_UE_F1AP_ID */
-  ie = (F1AP_UEContextReleaseRequestIEs_t *)calloc(1, sizeof(F1AP_UEContextReleaseRequestIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
-  ie->criticality                    = F1AP_Criticality_reject;
-  ie->value.present                  = F1AP_UEContextReleaseRequestIEs__value_PR_GNB_DU_UE_F1AP_ID;
-  ie->value.choice.GNB_DU_UE_F1AP_ID = f1ap_get_du_ue_f1ap_id(&f1ap_du_inst[instance], req->rnti);
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextReleaseRequestIEs_t, ie2);
+  ie2->id                             = F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
+  ie2->criticality                    = F1AP_Criticality_reject;
+  ie2->value.present                  = F1AP_UEContextReleaseRequestIEs__value_PR_GNB_DU_UE_F1AP_ID;
+  ie2->value.choice.GNB_DU_UE_F1AP_ID = f1ap_get_du_ue_f1ap_id(DUtype, instance, req->rnti);
   /* mandatory */
   /* c3. Cause */
-  ie = (F1AP_UEContextReleaseRequestIEs_t *)calloc(1, sizeof(F1AP_UEContextReleaseRequestIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_Cause;
-  ie->criticality                    = F1AP_Criticality_ignore;
-  ie->value.present                  = F1AP_UEContextReleaseRequestIEs__value_PR_Cause;
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextReleaseRequestIEs_t, ie3);
+  ie3->id                             = F1AP_ProtocolIE_ID_id_Cause;
+  ie3->criticality                    = F1AP_Criticality_ignore;
+  ie3->value.present                  = F1AP_UEContextReleaseRequestIEs__value_PR_Cause;
 
   switch (req->cause) {
     case F1AP_CAUSE_RADIO_NETWORK:
-      ie->value.choice.Cause.present = F1AP_Cause_PR_radioNetwork;
-      ie->value.choice.Cause.choice.radioNetwork = req->cause_value;
+      ie3->value.choice.Cause.present = F1AP_Cause_PR_radioNetwork;
+      ie3->value.choice.Cause.choice.radioNetwork = req->cause_value;
       break;
 
     case F1AP_CAUSE_TRANSPORT:
-      ie->value.choice.Cause.present = F1AP_Cause_PR_transport;
-      ie->value.choice.Cause.choice.transport = req->cause_value;
+      ie3->value.choice.Cause.present = F1AP_Cause_PR_transport;
+      ie3->value.choice.Cause.choice.transport = req->cause_value;
       break;
 
     case F1AP_CAUSE_PROTOCOL:
-      ie->value.choice.Cause.present = F1AP_Cause_PR_protocol;
-      ie->value.choice.Cause.choice.protocol = req->cause_value;
+      ie3->value.choice.Cause.present = F1AP_Cause_PR_protocol;
+      ie3->value.choice.Cause.choice.protocol = req->cause_value;
       break;
 
     case F1AP_CAUSE_MISC:
-      ie->value.choice.Cause.present = F1AP_Cause_PR_misc;
-      ie->value.choice.Cause.choice.misc = req->cause_value;
+      ie3->value.choice.Cause.present = F1AP_Cause_PR_misc;
+      ie3->value.choice.Cause.choice.misc = req->cause_value;
       break;
 
     case F1AP_CAUSE_NOTHING:
     default:
-      ie->value.choice.Cause.present = F1AP_Cause_PR_NOTHING;
+      ie3->value.choice.Cause.present = F1AP_Cause_PR_NOTHING;
       break;
   }
 
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
   /* encode */
   if (f1ap_encode_pdu(&pdu, &buffer, &len) < 0) {
     LOG_E(F1AP, "Failed to encode F1 context release request\n");
     return -1;
   }
 
-  du_f1ap_itti_send_sctp_data_req(instance,
-                                  f1ap_du_data->assoc_id,
-                                  buffer,
-                                  len,
-                                  f1ap_du_data->default_sctp_stream_id);
+  f1ap_itti_send_sctp_data_req(false, instance,
+                               buffer,
+                               len,
+                               getCxt(false, instance)->default_sctp_stream_id);
   return 0;
 }
-
-
 int DU_handle_UE_CONTEXT_RELEASE_COMMAND(instance_t       instance,
     uint32_t         assoc_id,
     uint32_t         stream,
@@ -645,21 +670,21 @@ int DU_handle_UE_CONTEXT_RELEASE_COMMAND(instance_t       instance,
   /* GNB_CU_UE_F1AP_ID */
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_UEContextReleaseCommandIEs_t, ie, container,
                              F1AP_ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID, true);
-  ctxt.rnti = f1ap_get_rnti_by_cu_id(&f1ap_du_inst[instance], ie->value.choice.GNB_CU_UE_F1AP_ID);
+  ctxt.rnti = f1ap_get_rnti_by_cu_id(DUtype, instance, ie->value.choice.GNB_CU_UE_F1AP_ID);
+  ctxt.instance = instance;
   ctxt.module_id = instance;
-  ctxt.instance  = instance;
   ctxt.enb_flag  = 1;
   /* GNB_DU_UE_F1AP_ID */
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_UEContextReleaseCommandIEs_t, ie, container,
                              F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID, true);
-  const rnti_t rnti = f1ap_get_rnti_by_du_id(&f1ap_du_inst[instance],
+  const rnti_t rnti = f1ap_get_rnti_by_du_id(DUtype, instance,
                       ie->value.choice.GNB_DU_UE_F1AP_ID);
   AssertFatal(ctxt.rnti == rnti,
               "RNTI obtained through DU ID (%x) is different from CU ID (%x)\n",
               rnti, ctxt.rnti);
   int UE_out_of_sync = 0;
 
-  if (RC.nrrrc[instance]->node_type == ngran_gNB_DU) {
+  if (RC.nrrrc && RC.nrrrc[instance]->node_type == ngran_gNB_DU) {
     for (int n = 0; n < MAX_MOBILES_PER_GNB; ++n) {
       if (RC.nrmac[instance]->UE_info.active[n] == TRUE
           && rnti == RC.nrmac[instance]->UE_info.rnti[n]) {
@@ -723,89 +748,81 @@ int DU_handle_UE_CONTEXT_RELEASE_COMMAND(instance_t       instance,
     }
   }
 
-  if (RC.nrrrc[instance]->node_type == ngran_gNB_DU) {
+  if (RC.nrrrc && RC.nrrrc[instance]->node_type == ngran_gNB_DU) {
     // struct rrc_gNB_ue_context_s *ue_context_p;
-
     f1ap_ue_context_release_cplt_t cplt;
     cplt.rnti = ctxt.rnti;
     DU_send_UE_CONTEXT_RELEASE_COMPLETE(instance, &cplt);
     return 0;
-  }
-
-  struct rrc_eNB_ue_context_s *ue_context_p;
-
-  ue_context_p = rrc_eNB_get_ue_context(RC.rrc[ctxt.module_id], ctxt.rnti);
-
-  if (ue_context_p && !UE_out_of_sync) {
-    /* UE exists and is in sync so we start a timer before releasing the
-     * connection */
-    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_p->ue_context.ue_release_timer_s1 > 0)
-          rrc_release_info.RRC_release_ctrl[release_num].flag = 1;
-        else
-          rrc_release_info.RRC_release_ctrl[release_num].flag = 2;
-
-        rrc_release_info.RRC_release_ctrl[release_num].rnti = ctxt.rnti;
-        LOG_D(F1AP, "add rrc_release_info RNTI %x\n", ctxt.rnti);
-        // TODO: how to provide the correct MUI?
-        rrc_release_info.RRC_release_ctrl[release_num].rrc_eNB_mui = 0;
-        rrc_release_info.num_UEs++;
-        LOG_D(RRC,"Generate DLSCH Release send: index %d rnti %x mui %d flag %d \n",release_num,
-              ctxt.rnti, 0, rrc_release_info.RRC_release_ctrl[release_num].flag);
-        break;
+  } else {
+    struct rrc_eNB_ue_context_s *ue_context_p;
+    ue_context_p = rrc_eNB_get_ue_context(RC.rrc[ctxt.instance], ctxt.rnti);
+
+    if (ue_context_p && !UE_out_of_sync) {
+      /* UE exists and is in sync so we start a timer before releasing the
+       * connection */
+      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_p->ue_context.ue_release_timer_s1 > 0)
+            rrc_release_info.RRC_release_ctrl[release_num].flag = 1;
+          else
+            rrc_release_info.RRC_release_ctrl[release_num].flag = 2;
+
+          rrc_release_info.RRC_release_ctrl[release_num].rnti = ctxt.rnti;
+          LOG_D(F1AP, "add rrc_release_info RNTI %x\n", ctxt.rnti);
+          // TODO: how to provide the correct MUI?
+          rrc_release_info.RRC_release_ctrl[release_num].rrc_eNB_mui = 0;
+          rrc_release_info.num_UEs++;
+          LOG_D(RRC,"Generate DLSCH Release send: index %d rnti %x mui %d flag %d \n",release_num,
+                ctxt.rnti, 0, rrc_release_info.RRC_release_ctrl[release_num].flag);
+          break;
+        }
       }
+
+      pthread_mutex_unlock(&rrc_release_freelist);
+      ue_context_p->ue_context.ue_release_timer_s1 = 0;
+    } else if (ue_context_p && UE_out_of_sync) {
+      /* UE exists and is out of sync, drop the connection */
+      mac_eNB_rrc_ul_failure(instance, 0, 0, 0, rnti);
+    } else {
+      LOG_E(F1AP, "no ue_context for RNTI %x, acknowledging release\n", rnti);
     }
 
-    pthread_mutex_unlock(&rrc_release_freelist);
-    ue_context_p->ue_context.ue_release_timer_s1 = 0;
-  } else if (ue_context_p && UE_out_of_sync) {
-    /* UE exists and is out of sync, drop the connection */
-    mac_eNB_rrc_ul_failure(instance, 0, 0, 0, rnti);
-  } else {
-    LOG_E(F1AP, "no ue_context for RNTI %x, acknowledging release\n", rnti);
+    /* TODO send this once the connection has really been released */
+    f1ap_ue_context_release_cplt_t cplt;
+    cplt.rnti = ctxt.rnti;
+    DU_send_UE_CONTEXT_RELEASE_COMPLETE(instance, &cplt);
+    return 0;
   }
-
-  /* TODO send this once the connection has really been released */
-  f1ap_ue_context_release_cplt_t cplt;
-  cplt.rnti = ctxt.rnti;
-  DU_send_UE_CONTEXT_RELEASE_COMPLETE(instance, &cplt);
-  return 0;
 }
-
-
 int DU_send_UE_CONTEXT_RELEASE_COMPLETE(instance_t instance,
                                         f1ap_ue_context_release_cplt_t *cplt) {
-  F1AP_F1AP_PDU_t                     pdu;
+  F1AP_F1AP_PDU_t                     pdu= {0};
   F1AP_UEContextReleaseComplete_t    *out;
-  F1AP_UEContextReleaseCompleteIEs_t *ie;
   /* Create */
   /* 0. Message Type */
-  memset(&pdu, 0, sizeof(pdu));
   pdu.present = F1AP_F1AP_PDU_PR_successfulOutcome;
-  pdu.choice.successfulOutcome = (F1AP_SuccessfulOutcome_t *)calloc(1, sizeof(F1AP_SuccessfulOutcome_t));
-  pdu.choice.successfulOutcome->procedureCode = F1AP_ProcedureCode_id_UEContextRelease;
-  pdu.choice.successfulOutcome->criticality   = F1AP_Criticality_reject;
-  pdu.choice.successfulOutcome->value.present = F1AP_SuccessfulOutcome__value_PR_UEContextReleaseComplete;
-  out = &pdu.choice.successfulOutcome->value.choice.UEContextReleaseComplete;
+  asn1cCalloc(pdu.choice.successfulOutcome, tmp);
+  tmp->procedureCode = F1AP_ProcedureCode_id_UEContextRelease;
+  tmp->criticality   = F1AP_Criticality_reject;
+  tmp->value.present = F1AP_SuccessfulOutcome__value_PR_UEContextReleaseComplete;
+  out = &tmp->value.choice.UEContextReleaseComplete;
   /* mandatory */
   /* c1. GNB_CU_UE_F1AP_ID */
-  ie = (F1AP_UEContextReleaseCompleteIEs_t *)calloc(1, sizeof(F1AP_UEContextReleaseCompleteIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
-  ie->criticality                    = F1AP_Criticality_reject;
-  ie->value.present                  = F1AP_UEContextReleaseCompleteIEs__value_PR_GNB_CU_UE_F1AP_ID;
-  ie->value.choice.GNB_CU_UE_F1AP_ID = f1ap_get_cu_ue_f1ap_id(&f1ap_du_inst[instance], cplt->rnti);
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextReleaseCompleteIEs_t, ie1);
+  ie1->id                             = F1AP_ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
+  ie1->criticality                    = F1AP_Criticality_reject;
+  ie1->value.present                  = F1AP_UEContextReleaseCompleteIEs__value_PR_GNB_CU_UE_F1AP_ID;
+  ie1->value.choice.GNB_CU_UE_F1AP_ID = f1ap_get_cu_ue_f1ap_id(DUtype, instance, cplt->rnti);
   /* mandatory */
   /* c2. GNB_DU_UE_F1AP_ID */
-  ie = (F1AP_UEContextReleaseCompleteIEs_t *)calloc(1, sizeof(F1AP_UEContextReleaseCompleteIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
-  ie->criticality                    = F1AP_Criticality_reject;
-  ie->value.present                  = F1AP_UEContextReleaseCompleteIEs__value_PR_GNB_DU_UE_F1AP_ID;
-  ie->value.choice.GNB_DU_UE_F1AP_ID = f1ap_get_du_ue_f1ap_id(&f1ap_du_inst[instance], cplt->rnti);
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+  asn1cSequenceAdd(out->protocolIEs.list,F1AP_UEContextReleaseCompleteIEs_t, ie2);
+  ie2->id                             = F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
+  ie2->criticality                    = F1AP_Criticality_reject;
+  ie2->value.present                  = F1AP_UEContextReleaseCompleteIEs__value_PR_GNB_DU_UE_F1AP_ID;
+  ie2->value.choice.GNB_DU_UE_F1AP_ID = f1ap_get_du_ue_f1ap_id(DUtype, instance, cplt->rnti);
   /* optional -> currently not used */
   /* c3. CriticalityDiagnostics */
   //if (0) {
@@ -863,365 +880,288 @@ int DU_send_UE_CONTEXT_RELEASE_COMPLETE(instance_t instance,
     return -1;
   }
 
-  du_f1ap_itti_send_sctp_data_req(instance,
-                                  f1ap_du_data->assoc_id,
-                                  buffer,
-                                  len,
-                                  f1ap_du_data->default_sctp_stream_id);
-  f1ap_remove_ue(&f1ap_du_inst[instance], cplt->rnti);
+  f1ap_itti_send_sctp_data_req(false, instance,
+                               buffer,
+                               len,
+                               getCxt(false, instance)->default_sctp_stream_id);
+  f1ap_remove_ue(DUtype, instance, cplt->rnti);
   return 0;
 }
-
-
 int DU_handle_UE_CONTEXT_MODIFICATION_REQUEST(instance_t       instance,
     uint32_t         assoc_id,
     uint32_t         stream,
     F1AP_F1AP_PDU_t *pdu) {
   AssertFatal(1==0,"Not implemented yet\n");
 }
-
 //void DU_send_UE_CONTEXT_MODIFICATION_RESPONSE(F1AP_UEContextModificationResponse_t *UEContextModificationResponse) {
 int DU_send_UE_CONTEXT_MODIFICATION_RESPONSE(instance_t instance) {
-  F1AP_F1AP_PDU_t                        pdu;
+  F1AP_F1AP_PDU_t                        pdu= {0};
   F1AP_UEContextModificationResponse_t    *out;
-  F1AP_UEContextModificationResponseIEs_t *ie;
-  uint8_t  *buffer;
-  uint32_t  len;
-  int       i = 0;
+  uint8_t  *buffer=NULL;
+  uint32_t  len=0;
   /* Create */
   /* 0. Message Type */
-  memset(&pdu, 0, sizeof(pdu));
   pdu.present = F1AP_F1AP_PDU_PR_successfulOutcome;
-  pdu.choice.successfulOutcome = (F1AP_SuccessfulOutcome_t *)calloc(1, sizeof(F1AP_SuccessfulOutcome_t));
-  pdu.choice.successfulOutcome->procedureCode = F1AP_ProcedureCode_id_UEContextModification;
-  pdu.choice.successfulOutcome->criticality   = F1AP_Criticality_reject;
-  pdu.choice.successfulOutcome->value.present = F1AP_SuccessfulOutcome__value_PR_UEContextModificationResponse;
-  out = &pdu.choice.successfulOutcome->value.choice.UEContextModificationResponse;
+  asn1cCalloc(pdu.choice.successfulOutcome,tmp);
+  tmp->procedureCode = F1AP_ProcedureCode_id_UEContextModification;
+  tmp->criticality   = F1AP_Criticality_reject;
+  tmp->value.present = F1AP_SuccessfulOutcome__value_PR_UEContextModificationResponse;
+  out = &tmp->value.choice.UEContextModificationResponse;
   /* mandatory */
   /* c1. GNB_CU_UE_F1AP_ID */
-  ie = (F1AP_UEContextModificationResponseIEs_t *)calloc(1, sizeof(F1AP_UEContextModificationResponseIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
-  ie->criticality                    = F1AP_Criticality_reject;
-  ie->value.present                  = F1AP_UEContextModificationResponseIEs__value_PR_GNB_CU_UE_F1AP_ID;
-  ie->value.choice.GNB_CU_UE_F1AP_ID = 126L;
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextModificationResponseIEs_t, ie1);
+  ie1->id                             = F1AP_ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
+  ie1->criticality                    = F1AP_Criticality_reject;
+  ie1->value.present                  = F1AP_UEContextModificationResponseIEs__value_PR_GNB_CU_UE_F1AP_ID;
+  ie1->value.choice.GNB_CU_UE_F1AP_ID = 126L;
   /* mandatory */
   /* c2. GNB_DU_UE_F1AP_ID */
-  ie = (F1AP_UEContextModificationResponseIEs_t *)calloc(1, sizeof(F1AP_UEContextModificationResponseIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
-  ie->criticality                    = F1AP_Criticality_reject;
-  ie->value.present                  = F1AP_UEContextModificationResponseIEs__value_PR_GNB_DU_UE_F1AP_ID;
-  ie->value.choice.GNB_DU_UE_F1AP_ID = 651L;
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextModificationResponseIEs_t, ie2);
+  ie2->id                             = F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
+  ie2->criticality                    = F1AP_Criticality_reject;
+  ie2->value.present                  = F1AP_UEContextModificationResponseIEs__value_PR_GNB_DU_UE_F1AP_ID;
+  ie2->value.choice.GNB_DU_UE_F1AP_ID = 651L;
 
   /* optional */
   /* c3. ResourceCoordinationTransferContainer */
   if (0) {
-    ie = (F1AP_UEContextModificationResponseIEs_t *)calloc(1, sizeof(F1AP_UEContextModificationResponseIEs_t));
-    ie->id                             = F1AP_ProtocolIE_ID_id_ResourceCoordinationTransferContainer;
-    ie->criticality                    = F1AP_Criticality_ignore;
-    ie->value.present                  = F1AP_UEContextModificationResponseIEs__value_PR_ResourceCoordinationTransferContainer;
-    OCTET_STRING_fromBuf(&ie->value.choice.ResourceCoordinationTransferContainer, "asdsa1d32sa1d31asd31as",
+    asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextModificationResponseIEs_t, ie3);
+    ie3->id                             = F1AP_ProtocolIE_ID_id_ResourceCoordinationTransferContainer;
+    ie3->criticality                    = F1AP_Criticality_ignore;
+    ie3->value.present                  = F1AP_UEContextModificationResponseIEs__value_PR_ResourceCoordinationTransferContainer;
+    OCTET_STRING_fromBuf(&ie3->value.choice.ResourceCoordinationTransferContainer, "asdsa1d32sa1d31asd31as",
                          strlen("asdsa1d32sa1d31asd31as"));
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
   }
 
   /* optional */
   /* c4. DUtoCURRCInformation */
   if (0) {
-    ie = (F1AP_UEContextModificationResponseIEs_t *)calloc(1, sizeof(F1AP_UEContextModificationResponseIEs_t));
-    ie->id                             = F1AP_ProtocolIE_ID_id_DUtoCURRCInformation;
-    ie->criticality                    = F1AP_Criticality_reject;
-    ie->value.present                  = F1AP_UEContextModificationResponseIEs__value_PR_DUtoCURRCInformation;
-    OCTET_STRING_fromBuf(&ie->value.choice.DUtoCURRCInformation.cellGroupConfig, "asdsa1d32sa1d31asd31as",
+    asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextModificationResponseIEs_t, ie4);
+    ie4->id                             = F1AP_ProtocolIE_ID_id_DUtoCURRCInformation;
+    ie4->criticality                    = F1AP_Criticality_reject;
+    ie4->value.present                  = F1AP_UEContextModificationResponseIEs__value_PR_DUtoCURRCInformation;
+    OCTET_STRING_fromBuf(&ie4->value.choice.DUtoCURRCInformation.cellGroupConfig, "asdsa1d32sa1d31asd31as",
                          strlen("asdsa1d32sa1d31asd31as"));
 
     /* OPTIONAL */
     if (1) {
-      ie->value.choice.DUtoCURRCInformation.measGapConfig = (F1AP_MeasGapConfig_t *)calloc(1, sizeof(F1AP_MeasGapConfig_t));
-      OCTET_STRING_fromBuf( ie->value.choice.DUtoCURRCInformation.measGapConfig, "asdsa1d32sa1d31asd31as",
+      asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextModificationResponseIEs_t, ie41);
+      ie41->value.choice.DUtoCURRCInformation.measGapConfig = (F1AP_MeasGapConfig_t *)calloc(1, sizeof(F1AP_MeasGapConfig_t));
+      OCTET_STRING_fromBuf( ie41->value.choice.DUtoCURRCInformation.measGapConfig, "asdsa1d32sa1d31asd31as",
                             strlen("asdsa1d32sa1d31asd31as"));
-      ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
     }
   }
 
   /* mandatory */
   /* c5. DRBs_SetupMod_List */
-  ie = (F1AP_UEContextModificationResponseIEs_t *)calloc(1, sizeof(F1AP_UEContextModificationResponseIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_DRBs_SetupMod_List;
-  ie->criticality                    = F1AP_Criticality_reject;
-  ie->value.present                  = F1AP_UEContextModificationResponseIEs__value_PR_DRBs_SetupMod_List;
-
-  for (i=0;
-       i<1;
-       i++) {
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextModificationResponseIEs_t, ie5);
+  ie5->id                             = F1AP_ProtocolIE_ID_id_DRBs_SetupMod_List;
+  ie5->criticality                    = F1AP_Criticality_reject;
+  ie5->value.present                  = F1AP_UEContextModificationResponseIEs__value_PR_DRBs_SetupMod_List;
+
+  for (int i=0;   i<1;  i++) {
     //
-    F1AP_DRBs_SetupMod_ItemIEs_t *drbs_setupMod_item_ies;
-    drbs_setupMod_item_ies = (F1AP_DRBs_SetupMod_ItemIEs_t *)calloc(1, sizeof(F1AP_DRBs_SetupMod_ItemIEs_t));
+    asn1cSequenceAdd(ie5->value.choice.DRBs_SetupMod_List.list,
+                     F1AP_DRBs_SetupMod_ItemIEs_t, drbs_setupMod_item_ies);
     drbs_setupMod_item_ies->id            = F1AP_ProtocolIE_ID_id_DRBs_SetupMod_Item;
     drbs_setupMod_item_ies->criticality   = F1AP_Criticality_reject;
     drbs_setupMod_item_ies->value.present = F1AP_DRBs_SetupMod_ItemIEs__value_PR_DRBs_SetupMod_Item;
     /* 10.1 DRBs_SetupMod_Item */
-    F1AP_DRBs_SetupMod_Item_t drbs_setupMod_item;
-    memset((void *)&drbs_setupMod_item, 0, sizeof(F1AP_DRBs_SetupMod_Item_t));
+    F1AP_DRBs_SetupMod_Item_t *drbs_setupMod_item=&drbs_setupMod_item_ies->value.choice.DRBs_SetupMod_Item;
     /* dRBID */
-    drbs_setupMod_item.dRBID = 30L;
+    drbs_setupMod_item->dRBID = 30L;
     /* DLTunnels_SetupMod_List */
-    int j = 0;
     int maxnoofDLUPTNLInformation = 1; // 2;
 
-    for (j=0;
-         j<maxnoofDLUPTNLInformation;
-         j++) {
+    for (int j=0;    j<maxnoofDLUPTNLInformation;    j++) {
       /*  DLTunnels_ToBeSetup_Item */
-      F1AP_DLUPTNLInformation_ToBeSetup_Item_t *dLUPTNLInformation_ToBeSetup_Item;
-      dLUPTNLInformation_ToBeSetup_Item = (F1AP_DLUPTNLInformation_ToBeSetup_Item_t *)calloc(1, sizeof(F1AP_DLUPTNLInformation_ToBeSetup_Item_t));
+      asn1cSequenceAdd(ie5->value.choice.DRBs_SetupMod_List.list,
+                       F1AP_DLUPTNLInformation_ToBeSetup_Item_t, dLUPTNLInformation_ToBeSetup_Item);
       dLUPTNLInformation_ToBeSetup_Item->dLUPTNLInformation.present = F1AP_UPTransportLayerInformation_PR_gTPTunnel;
-      F1AP_GTPTunnel_t *gTPTunnel = (F1AP_GTPTunnel_t *)calloc(1, sizeof(F1AP_GTPTunnel_t));
+      asn1cCalloc(dLUPTNLInformation_ToBeSetup_Item->dLUPTNLInformation.choice.gTPTunnel,
+                  gTPTunnel);
       TRANSPORT_LAYER_ADDRESS_IPv4_TO_BIT_STRING(1234, &gTPTunnel->transportLayerAddress);
       OCTET_STRING_fromBuf(&gTPTunnel->gTP_TEID, "1204",
                            strlen("1204"));
-      dLUPTNLInformation_ToBeSetup_Item->dLUPTNLInformation.choice.gTPTunnel = gTPTunnel;
-      ASN_SEQUENCE_ADD(&drbs_setupMod_item.dLUPTNLInformation_ToBeSetup_List.list, dLUPTNLInformation_ToBeSetup_Item);
     }
-
-    /* ADD */
-    drbs_setupMod_item_ies->value.choice.DRBs_SetupMod_Item = drbs_setupMod_item;
-    ASN_SEQUENCE_ADD(&ie->value.choice.DRBs_SetupMod_List.list,
-                     drbs_setupMod_item_ies);
   }
 
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
   /* mandatory */
   /* c6. DRBs_Modified_List */
-  ie = (F1AP_UEContextModificationResponseIEs_t *)calloc(1, sizeof(F1AP_UEContextModificationResponseIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_DRBs_Modified_List;
-  ie->criticality                    = F1AP_Criticality_reject;
-  ie->value.present                  = F1AP_UEContextModificationResponseIEs__value_PR_DRBs_Modified_List;
-
-  for (i=0;
-       i<1;
-       i++) {
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextModificationResponseIEs_t, ie6);
+  ie6->id                             = F1AP_ProtocolIE_ID_id_DRBs_Modified_List;
+  ie6->criticality                    = F1AP_Criticality_reject;
+  ie6->value.present                  = F1AP_UEContextModificationResponseIEs__value_PR_DRBs_Modified_List;
+
+  for (int i=0;  i<1; i++) {
     //
-    F1AP_DRBs_Modified_ItemIEs_t *drbs_modified_item_ies;
-    drbs_modified_item_ies = (F1AP_DRBs_Modified_ItemIEs_t *)calloc(1, sizeof(F1AP_DRBs_Modified_ItemIEs_t));
+    asn1cSequenceAdd(ie6->value.choice.DRBs_Modified_List.list,
+                     F1AP_DRBs_Modified_ItemIEs_t, drbs_modified_item_ies);
     drbs_modified_item_ies->id            = F1AP_ProtocolIE_ID_id_DRBs_Modified_Item;
     drbs_modified_item_ies->criticality   = F1AP_Criticality_reject;
     drbs_modified_item_ies->value.present = F1AP_DRBs_Modified_ItemIEs__value_PR_DRBs_Modified_Item;
     /* 13.1 SRBs_modified_Item */
-    F1AP_DRBs_Modified_Item_t drbs_modified_item;
-    memset((void *)&drbs_modified_item, 0, sizeof(F1AP_DRBs_Modified_Item_t));
+    F1AP_DRBs_Modified_Item_t *drbs_modified_item=
+      &drbs_modified_item_ies->value.choice.DRBs_Modified_Item;
     /* dRBID */
-    drbs_modified_item.dRBID = 25L;
+    drbs_modified_item->dRBID = 25L;
     /* ULTunnels_Modified_List */
     int maxnoofULTunnels = 1; // 2;
-    int j = 0;
 
-    for (j=0;
-         j<maxnoofULTunnels;
-         j++) {
+    for (int j=0;  j<maxnoofULTunnels;  j++) {
       /*  DLTunnels_Modified_Item */
-      F1AP_DLUPTNLInformation_ToBeSetup_Item_t *dLUPTNLInformation_ToBeSetup_Item;
-      dLUPTNLInformation_ToBeSetup_Item = (F1AP_DLUPTNLInformation_ToBeSetup_Item_t *)calloc(1, sizeof(F1AP_DLUPTNLInformation_ToBeSetup_Item_t));
-      dLUPTNLInformation_ToBeSetup_Item->dLUPTNLInformation.present = F1AP_UPTransportLayerInformation_PR_gTPTunnel;
-      F1AP_GTPTunnel_t *gTPTunnel = (F1AP_GTPTunnel_t *)calloc(1, sizeof(F1AP_GTPTunnel_t));
+      asn1cSequenceAdd(drbs_modified_item->dLUPTNLInformation_ToBeSetup_List.list,
+                       F1AP_DLUPTNLInformation_ToBeSetup_Item_t, dLUPTNLInformation_ToBeSetup_Item);
+      asn1cCalloc(dLUPTNLInformation_ToBeSetup_Item, tmp);
+      tmp->dLUPTNLInformation.present = F1AP_UPTransportLayerInformation_PR_gTPTunnel;
+      asn1cCalloc(dLUPTNLInformation_ToBeSetup_Item->dLUPTNLInformation.choice.gTPTunnel, gTPTunnel);
       TRANSPORT_LAYER_ADDRESS_IPv4_TO_BIT_STRING(1234, &gTPTunnel->transportLayerAddress);
-      OCTET_STRING_fromBuf(&gTPTunnel->gTP_TEID, "1204",
-                           strlen("1204"));
-      dLUPTNLInformation_ToBeSetup_Item->dLUPTNLInformation.choice.gTPTunnel = gTPTunnel;
-      ASN_SEQUENCE_ADD(&drbs_modified_item.dLUPTNLInformation_ToBeSetup_List.list, dLUPTNLInformation_ToBeSetup_Item);
+      OCTET_STRING_fromBuf(&gTPTunnel->gTP_TEID, "1204", strlen("1204"));
     }
-
-    /* ADD */
-    drbs_modified_item_ies->value.choice.DRBs_Modified_Item = drbs_modified_item;
-    ASN_SEQUENCE_ADD(&ie->value.choice.DRBs_Modified_List.list,
-                     drbs_modified_item_ies);
   }
 
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
   /* mandatory */
   /* c7. SRBs_FailedToBeSetupMod_List */
-  ie = (F1AP_UEContextModificationResponseIEs_t *)calloc(1, sizeof(F1AP_UEContextModificationResponseIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_SRBs_FailedToBeSetupMod_List;
-  ie->criticality                    = F1AP_Criticality_reject;
-  ie->value.present                  = F1AP_UEContextModificationResponseIEs__value_PR_SRBs_FailedToBeSetupMod_List;
-
-  for (i=0;
-       i<1;
-       i++) {
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextModificationResponseIEs_t, ie7);
+  ie7->id                             = F1AP_ProtocolIE_ID_id_SRBs_FailedToBeSetupMod_List;
+  ie7->criticality                    = F1AP_Criticality_reject;
+  ie7->value.present                  = F1AP_UEContextModificationResponseIEs__value_PR_SRBs_FailedToBeSetupMod_List;
+
+  for (int i=0; i<1; i++) {
     //
-    F1AP_SRBs_FailedToBeSetupMod_ItemIEs_t *srbs_failedToBeSetupMod_item_ies;
-    srbs_failedToBeSetupMod_item_ies = (F1AP_SRBs_FailedToBeSetupMod_ItemIEs_t *)calloc(1, sizeof(F1AP_SRBs_FailedToBeSetupMod_ItemIEs_t));
+    asn1cSequenceAdd(ie7->value.choice.SRBs_FailedToBeSetupMod_List.list,
+                     F1AP_SRBs_FailedToBeSetupMod_ItemIEs_t, srbs_failedToBeSetupMod_item_ies);
     srbs_failedToBeSetupMod_item_ies->id            = F1AP_ProtocolIE_ID_id_SRBs_FailedToBeSetupMod_Item;
     srbs_failedToBeSetupMod_item_ies->criticality   = F1AP_Criticality_ignore;
     srbs_failedToBeSetupMod_item_ies->value.present = F1AP_SRBs_FailedToBeSetupMod_ItemIEs__value_PR_SRBs_FailedToBeSetupMod_Item;
     /* 9.1 SRBs_FailedToBeSetupMod_Item */
-    F1AP_SRBs_FailedToBeSetupMod_Item_t srbs_failedToBeSetupMod_item;
-    memset((void *)&srbs_failedToBeSetupMod_item, 0, sizeof(F1AP_SRBs_FailedToBeSetupMod_Item_t));
+    F1AP_SRBs_FailedToBeSetupMod_Item_t *srbs_failedToBeSetupMod_item=
+      &srbs_failedToBeSetupMod_item_ies->value.choice.SRBs_FailedToBeSetupMod_Item;
     /* - sRBID */
-    srbs_failedToBeSetupMod_item.sRBID = 50L;
-    srbs_failedToBeSetupMod_item.cause = (F1AP_Cause_t *)calloc(1, sizeof(F1AP_Cause_t));
-    srbs_failedToBeSetupMod_item.cause->present = F1AP_Cause_PR_radioNetwork;
-    srbs_failedToBeSetupMod_item.cause->choice.radioNetwork = F1AP_CauseRadioNetwork_unknown_or_already_allocated_gnb_du_ue_f1ap_id;
-    /* ADD */
-    srbs_failedToBeSetupMod_item_ies->value.choice.SRBs_FailedToBeSetupMod_Item = srbs_failedToBeSetupMod_item;
-    ASN_SEQUENCE_ADD(&ie->value.choice.SRBs_FailedToBeSetupMod_List.list,
-                     srbs_failedToBeSetupMod_item_ies);
+    srbs_failedToBeSetupMod_item->sRBID = 50L;
+    asn1cCalloc(srbs_failedToBeSetupMod_item->cause, tmp)
+    tmp->present = F1AP_Cause_PR_radioNetwork;
+    tmp->choice.radioNetwork = F1AP_CauseRadioNetwork_unknown_or_already_allocated_gnb_du_ue_f1ap_id;
   }
 
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
   /* mandatory */
   /* c8. DRBs_FailedToBeSetupMod_List */
-  ie = (F1AP_UEContextModificationResponseIEs_t *)calloc(1, sizeof(F1AP_UEContextModificationResponseIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_DRBs_FailedToBeSetupMod_List;
-  ie->criticality                    = F1AP_Criticality_reject;
-  ie->value.present                  = F1AP_UEContextModificationResponseIEs__value_PR_DRBs_FailedToBeSetupMod_List;
-
-  for (i=0;
-       i<1;
-       i++) {
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextModificationResponseIEs_t, ie8);
+  ie8->id                             = F1AP_ProtocolIE_ID_id_DRBs_FailedToBeSetupMod_List;
+  ie8->criticality                    = F1AP_Criticality_reject;
+  ie8->value.present                  = F1AP_UEContextModificationResponseIEs__value_PR_DRBs_FailedToBeSetupMod_List;
+
+  for (int i=0;   i<1; i++) {
     //
-    F1AP_DRBs_FailedToBeSetupMod_ItemIEs_t *drbs_failedToBeSetupMod_item_ies;
-    drbs_failedToBeSetupMod_item_ies = (F1AP_DRBs_FailedToBeSetupMod_ItemIEs_t *)calloc(1, sizeof(F1AP_DRBs_FailedToBeSetupMod_ItemIEs_t));
+    asn1cSequenceAdd(ie8->value.choice.DRBs_FailedToBeSetupMod_List.list,
+                     F1AP_DRBs_FailedToBeSetupMod_ItemIEs_t, drbs_failedToBeSetupMod_item_ies);
     drbs_failedToBeSetupMod_item_ies->id            = F1AP_ProtocolIE_ID_id_DRBs_FailedToBeSetupMod_Item;
     drbs_failedToBeSetupMod_item_ies->criticality   = F1AP_Criticality_reject;
     drbs_failedToBeSetupMod_item_ies->value.present = F1AP_DRBs_FailedToBeSetupMod_ItemIEs__value_PR_DRBs_FailedToBeSetupMod_Item;
     /* 10.1 DRBs_ToBeSetupMod_Item */
-    F1AP_DRBs_FailedToBeSetupMod_Item_t drbs_failedToBeSetupMod_item;
-    memset((void *)&drbs_failedToBeSetupMod_item, 0, sizeof(F1AP_DRBs_FailedToBeSetupMod_Item_t));
+    F1AP_DRBs_FailedToBeSetupMod_Item_t *drbs_failedToBeSetupMod_item=
+      &drbs_failedToBeSetupMod_item_ies->value.choice.DRBs_FailedToBeSetupMod_Item;
     /* dRBID */
-    drbs_failedToBeSetupMod_item.dRBID = 30L;
-    drbs_failedToBeSetupMod_item.cause = (F1AP_Cause_t *)calloc(1, sizeof(F1AP_Cause_t));
-    drbs_failedToBeSetupMod_item.cause->present = F1AP_Cause_PR_radioNetwork;
-    drbs_failedToBeSetupMod_item.cause->choice.radioNetwork = F1AP_CauseRadioNetwork_unknown_or_already_allocated_gnb_du_ue_f1ap_id;
-    /* ADD */
-    drbs_failedToBeSetupMod_item_ies->value.choice.DRBs_FailedToBeSetupMod_Item = drbs_failedToBeSetupMod_item;
-    ASN_SEQUENCE_ADD(&ie->value.choice.DRBs_FailedToBeSetupMod_List.list,
-                     drbs_failedToBeSetupMod_item_ies);
+    drbs_failedToBeSetupMod_item->dRBID = 30L;
+    drbs_failedToBeSetupMod_item->cause = (F1AP_Cause_t *)calloc(1, sizeof(F1AP_Cause_t));
+    drbs_failedToBeSetupMod_item->cause->present = F1AP_Cause_PR_radioNetwork;
+    drbs_failedToBeSetupMod_item->cause->choice.radioNetwork = F1AP_CauseRadioNetwork_unknown_or_already_allocated_gnb_du_ue_f1ap_id;
   }
 
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
   /* mandatory */
   /* c9. SCell_FailedtoSetupMod_List */
-  ie = (F1AP_UEContextModificationResponseIEs_t *)calloc(1, sizeof(F1AP_UEContextModificationResponseIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_SCell_FailedtoSetupMod_List;
-  ie->criticality                    = F1AP_Criticality_ignore;
-  ie->value.present                  = F1AP_UEContextModificationResponseIEs__value_PR_SCell_FailedtoSetupMod_List;
-
-  for (i=0;
-       i<1;
-       i++) {
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextModificationResponseIEs_t, ie9);
+  ie9->id                             = F1AP_ProtocolIE_ID_id_SCell_FailedtoSetupMod_List;
+  ie9->criticality                    = F1AP_Criticality_ignore;
+  ie9->value.present                  = F1AP_UEContextModificationResponseIEs__value_PR_SCell_FailedtoSetupMod_List;
+
+  for (int i=0; i<1; i++) {
     //
-    F1AP_SCell_FailedtoSetupMod_ItemIEs_t *scell_failedtoSetupMod_item_ies;
-    scell_failedtoSetupMod_item_ies = (F1AP_SCell_FailedtoSetupMod_ItemIEs_t *)calloc(1, sizeof(F1AP_SCell_FailedtoSetupMod_ItemIEs_t));
+    asn1cSequenceAdd(ie9->value.choice.SCell_FailedtoSetupMod_List.list,
+                     F1AP_SCell_FailedtoSetupMod_ItemIEs_t, scell_failedtoSetupMod_item_ies);
     scell_failedtoSetupMod_item_ies->id            = F1AP_ProtocolIE_ID_id_SCell_FailedtoSetupMod_Item;
     scell_failedtoSetupMod_item_ies->criticality   = F1AP_Criticality_ignore;
     scell_failedtoSetupMod_item_ies->value.present = F1AP_SCell_FailedtoSetupMod_ItemIEs__value_PR_SCell_FailedtoSetupMod_Item;
     /* 8.1 SCell_ToBeSetup_Item */
-    F1AP_SCell_FailedtoSetupMod_Item_t scell_failedtoSetupMod_item;
-    memset((void *)&scell_failedtoSetupMod_item, 0, sizeof(F1AP_SCell_FailedtoSetupMod_Item_t));
+    F1AP_SCell_FailedtoSetupMod_Item_t *scell_failedtoSetupMod_item=&scell_failedtoSetupMod_item_ies->value.choice.SCell_FailedtoSetupMod_Item;
     /* - sCell_ID */
-    F1AP_NRCGI_t nRCGI;
-    memset(&nRCGI, 0, sizeof(F1AP_NRCGI_t));
-    MCC_MNC_TO_PLMNID(f1ap_du_data->mcc[i], f1ap_du_data->mnc[i], f1ap_du_data->mnc_digit_length[i],
-                      &nRCGI.pLMN_Identity);
-    NR_CELL_ID_TO_BIT_STRING(f1ap_du_data->nr_cellid[0], &nRCGI.nRCellIdentity);
-    scell_failedtoSetupMod_item.sCell_ID = nRCGI;
-    scell_failedtoSetupMod_item.cause = (F1AP_Cause_t *)calloc(1, sizeof(F1AP_Cause_t));
-    scell_failedtoSetupMod_item.cause->present = F1AP_Cause_PR_radioNetwork;
-    scell_failedtoSetupMod_item.cause->choice.radioNetwork = F1AP_CauseRadioNetwork_unknown_or_already_allocated_gnb_du_ue_f1ap_id;
-    /* ADD */
-    scell_failedtoSetupMod_item_ies->value.choice.SCell_FailedtoSetupMod_Item = scell_failedtoSetupMod_item;
-    ASN_SEQUENCE_ADD(&ie->value.choice.SCell_FailedtoSetupMod_List.list,
-                     scell_failedtoSetupMod_item_ies);
+    addnRCGI(scell_failedtoSetupMod_item->sCell_ID, &f1ap_req(false, instance)->cell[i]);
+    asn1cCalloc(scell_failedtoSetupMod_item->cause, tmp);
+    tmp->present = F1AP_Cause_PR_radioNetwork;
+    tmp->choice.radioNetwork = F1AP_CauseRadioNetwork_unknown_or_already_allocated_gnb_du_ue_f1ap_id;
   }
 
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
   /* mandatory */
   /* c10. DRBs_FailedToBeModified_List */
-  ie = (F1AP_UEContextModificationResponseIEs_t *)calloc(1, sizeof(F1AP_UEContextModificationResponseIEs_t));
-  ie->id                             = F1AP_ProtocolIE_ID_id_DRBs_FailedToBeModified_List;
-  ie->criticality                    = F1AP_Criticality_reject;
-  ie->value.present                  = F1AP_UEContextModificationResponseIEs__value_PR_DRBs_FailedToBeModified_List;
-
-  for (i=0;
-       i<1;
-       i++) {
+  asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextModificationResponseIEs_t, ie10);
+  ie10->id                             = F1AP_ProtocolIE_ID_id_DRBs_FailedToBeModified_List;
+  ie10->criticality                    = F1AP_Criticality_reject;
+  ie10->value.present                  = F1AP_UEContextModificationResponseIEs__value_PR_DRBs_FailedToBeModified_List;
+
+  for (int i=0; i<1; i++) {
     //
-    F1AP_DRBs_FailedToBeModified_ItemIEs_t *drbs_failedToBeModified_item_ies;
-    drbs_failedToBeModified_item_ies = (F1AP_DRBs_FailedToBeModified_ItemIEs_t *)calloc(1, sizeof(F1AP_DRBs_FailedToBeModified_ItemIEs_t));
+    asn1cSequenceAdd(ie10->value.choice.DRBs_FailedToBeModified_List.list,
+                     F1AP_DRBs_FailedToBeModified_ItemIEs_t, drbs_failedToBeModified_item_ies);
     drbs_failedToBeModified_item_ies->id            = F1AP_ProtocolIE_ID_id_DRBs_FailedToBeModified_Item;
     drbs_failedToBeModified_item_ies->criticality   = F1AP_Criticality_reject;
     drbs_failedToBeModified_item_ies->value.present = F1AP_DRBs_FailedToBeModified_ItemIEs__value_PR_DRBs_FailedToBeModified_Item;
     /* 13.1 DRBs_FailedToBeModified_Item */
-    F1AP_DRBs_FailedToBeModified_Item_t drbs_failedToBeModified_item;
-    memset((void *)&drbs_failedToBeModified_item, 0, sizeof(F1AP_DRBs_FailedToBeModified_Item_t));
+    F1AP_DRBs_FailedToBeModified_Item_t *drbs_failedToBeModified_item=
+      &drbs_failedToBeModified_item_ies->value.choice.DRBs_FailedToBeModified_Item ;
     /* dRBID */
-    drbs_failedToBeModified_item.dRBID = 30L;
-    drbs_failedToBeModified_item.cause = (F1AP_Cause_t *)calloc(1, sizeof(F1AP_Cause_t));
-    drbs_failedToBeModified_item.cause->present = F1AP_Cause_PR_radioNetwork;
-    drbs_failedToBeModified_item.cause->choice.radioNetwork = F1AP_CauseRadioNetwork_unknown_or_already_allocated_gnb_du_ue_f1ap_id;
-    /* ADD */
-    drbs_failedToBeModified_item_ies->value.choice.DRBs_FailedToBeModified_Item = drbs_failedToBeModified_item;
-    ASN_SEQUENCE_ADD(&ie->value.choice.DRBs_FailedToBeModified_List.list,
-                     drbs_failedToBeModified_item_ies);
+    drbs_failedToBeModified_item->dRBID = 30L;
+    asn1cCalloc(drbs_failedToBeModified_item->cause, tmp);
+    tmp->present = F1AP_Cause_PR_radioNetwork;
+    tmp->choice.radioNetwork = F1AP_CauseRadioNetwork_unknown_or_already_allocated_gnb_du_ue_f1ap_id;
   }
 
-  ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
-
   // /*  */
   /* c11. CriticalityDiagnostics */
   if (0) {
-    ie = (F1AP_UEContextModificationResponseIEs_t *)calloc(1, sizeof(F1AP_UEContextModificationResponseIEs_t));
-    ie->id                             = F1AP_ProtocolIE_ID_id_CriticalityDiagnostics;
-    ie->criticality                    = F1AP_Criticality_ignore;
-    ie->value.present                  = F1AP_UEContextModificationResponseIEs__value_PR_CriticalityDiagnostics;
+    asn1cSequenceAdd(out->protocolIEs.list, F1AP_UEContextModificationResponseIEs_t, ie11);
+    ie11->id                             = F1AP_ProtocolIE_ID_id_CriticalityDiagnostics;
+    ie11->criticality                    = F1AP_Criticality_ignore;
+    ie11->value.present                  = F1AP_UEContextModificationResponseIEs__value_PR_CriticalityDiagnostics;
 
     // dummy value
     /* optional */
     /* procedureCode */
     if (0) {
-      ie->value.choice.CriticalityDiagnostics.procedureCode = (F1AP_ProcedureCode_t *)calloc(1, sizeof(F1AP_ProcedureCode_t));
-      ie->value.choice.CriticalityDiagnostics.procedureCode = 0L;
+      ie11->value.choice.CriticalityDiagnostics.procedureCode = (F1AP_ProcedureCode_t *)calloc(1, sizeof(F1AP_ProcedureCode_t));
+      ie11->value.choice.CriticalityDiagnostics.procedureCode = 0L;
     }
 
     /* optional */
     /* triggeringMessage */
     if (0) {
-      ie->value.choice.CriticalityDiagnostics.triggeringMessage = (F1AP_TriggeringMessage_t *)calloc(1, sizeof(F1AP_TriggeringMessage_t));
-      ie->value.choice.CriticalityDiagnostics.triggeringMessage = (F1AP_TriggeringMessage_t *)F1AP_TriggeringMessage_successful_outcome;
+      ie11->value.choice.CriticalityDiagnostics.triggeringMessage = (F1AP_TriggeringMessage_t *)calloc(1, sizeof(F1AP_TriggeringMessage_t));
+      *ie11->value.choice.CriticalityDiagnostics.triggeringMessage = F1AP_TriggeringMessage_successful_outcome;
     }
 
     /* optional */
     /* procedureCriticality */
     if (0) {
-      ie->value.choice.CriticalityDiagnostics.procedureCriticality = (F1AP_Criticality_t *)calloc(1, sizeof(F1AP_Criticality_t));
-      ie->value.choice.CriticalityDiagnostics.procedureCriticality = F1AP_Criticality_reject;
+      ie11->value.choice.CriticalityDiagnostics.procedureCriticality = (F1AP_Criticality_t *)calloc(1, sizeof(F1AP_Criticality_t));
+      ie11->value.choice.CriticalityDiagnostics.procedureCriticality = F1AP_Criticality_reject;
     }
 
     /* optional */
     /* transactionID */
     if (0) {
-      ie->value.choice.CriticalityDiagnostics.transactionID = (F1AP_TransactionID_t *)calloc(1, sizeof(F1AP_TransactionID_t));
-      ie->value.choice.CriticalityDiagnostics.transactionID = 0L;
+      ie11->value.choice.CriticalityDiagnostics.transactionID = (F1AP_TransactionID_t *)calloc(1, sizeof(F1AP_TransactionID_t));
+      ie11->value.choice.CriticalityDiagnostics.transactionID = 0L;
     }
 
     /* optional */
     /* F1AP_CriticalityDiagnostics_IE_List */
     if (0) {
-      for (i=0;
-           i<0;
-           i++) {
-        F1AP_CriticalityDiagnostics_IE_Item_t *criticalityDiagnostics_ie_item = (F1AP_CriticalityDiagnostics_IE_Item_t *)calloc(1, sizeof(F1AP_CriticalityDiagnostics_IE_Item_t));;
+      for (int i=0; i<0; i++) {
+        asn1cSequenceAdd(ie11->value.choice.CriticalityDiagnostics.iEsCriticalityDiagnostics->list, F1AP_CriticalityDiagnostics_IE_Item_t, criticalityDiagnostics_ie_item);
         criticalityDiagnostics_ie_item->iECriticality = F1AP_Criticality_reject;
         criticalityDiagnostics_ie_item->iE_ID         = 0L;
         criticalityDiagnostics_ie_item->typeOfError   = F1AP_TypeOfError_not_understood;
-        ASN_SEQUENCE_ADD(&ie->value.choice.CriticalityDiagnostics.iEsCriticalityDiagnostics->list,
-                         criticalityDiagnostics_ie_item);
       }
     }
-
-    ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie);
   }
 
   /* encode */
@@ -1230,18 +1170,15 @@ int DU_send_UE_CONTEXT_MODIFICATION_RESPONSE(instance_t instance) {
     return -1;
   }
 
-  //du_f1ap_itti_send_sctp_data_req(instance, f1ap_setup_req->assoc_id, buffer, len, 0);
+  //f1ap_itti_send_sctp_data_req(false, instance, buffer, len, 0);
   return 0;
 }
-
 int DU_send_UE_CONTEXT_MODIFICATION_FAILURE(instance_t instance) {
   AssertFatal(1==0,"Not implemented yet\n");
 }
-
 int DU_send_UE_CONTEXT_MODIFICATION_REQUIRED(instance_t instance) {
   AssertFatal(1==0,"Not implemented yet\n");
 }
-
 int DU_handle_UE_CONTEXT_MODIFICATION_CONFIRM(instance_t       instance,
     uint32_t         assoc_id,
     uint32_t         stream,
diff --git a/openair2/F1AP/f1ap_du_ue_context_management.h b/openair2/F1AP/f1ap_du_ue_context_management.h
index 2bb3ca95b9600cc552d616d9788e78bb79eccee4..82643fa933ca306e73781730be184b8b7dcbd7a3 100644
--- a/openair2/F1AP/f1ap_du_ue_context_management.h
+++ b/openair2/F1AP/f1ap_du_ue_context_management.h
@@ -36,11 +36,12 @@
 /*
  * UE Context Setup
  */
+int DU_send_UE_CONTEXT_SETUP_RESPONSE(instance_t instance, f1ap_ue_context_setup_t *req);
+
 int DU_handle_UE_CONTEXT_SETUP_REQUEST(instance_t       instance,
                                        uint32_t         assoc_id,
                                        uint32_t         stream,
                                        F1AP_F1AP_PDU_t *pdu);
-int DU_send_UE_CONTEXT_SETUP_RESPONSE(instance_t instance);
 int DU_send_UE_CONTEXT_SETUP_FAILURE(instance_t instance);
 
 
@@ -55,9 +56,9 @@ int DU_send_UE_CONTEXT_RELEASE_REQUEST(instance_t instance,
  * UE Context Release Command (gNB-CU initiated)
  */
 int DU_handle_UE_CONTEXT_RELEASE_COMMAND(instance_t       instance,
-                                         uint32_t         assoc_id,
-                                         uint32_t         stream,
-                                         F1AP_F1AP_PDU_t *pdu);
+    uint32_t         assoc_id,
+    uint32_t         stream,
+    F1AP_F1AP_PDU_t *pdu);
 
 /*
  * UE Context Release Complete (gNB-DU initiated)
@@ -70,9 +71,9 @@ int DU_send_UE_CONTEXT_RELEASE_COMPLETE(instance_t instance,
  * UE Context Modification (gNB-CU initiated)
  */
 int DU_handle_UE_CONTEXT_MODIFICATION_REQUEST(instance_t       instance,
-                                              uint32_t         assoc_id,
-                                              uint32_t         stream,
-                                              F1AP_F1AP_PDU_t *pdu);
+    uint32_t         assoc_id,
+    uint32_t         stream,
+    F1AP_F1AP_PDU_t *pdu);
 int DU_send_UE_CONTEXT_MODIFICATION_RESPONSE(instance_t instance);
 int DU_send_UE_CONTEXT_MODIFICATION_FAILURE(instance_t instance);
 
@@ -82,9 +83,11 @@ int DU_send_UE_CONTEXT_MODIFICATION_FAILURE(instance_t instance);
  */
 int DU_send_UE_CONTEXT_MODIFICATION_REQUIRED(instance_t instance);
 int DU_handle_UE_CONTEXT_MODIFICATION_CONFIRM(instance_t       instance,
-                                              uint32_t         assoc_id,
-                                              uint32_t         stream,
-                                              F1AP_F1AP_PDU_t *pdu);
+    uint32_t         assoc_id,
+    uint32_t         stream,
+    F1AP_F1AP_PDU_t *pdu);
+
+int DU_send_UE_CONTEXT_SETUP_RESPONSE(instance_t instance, f1ap_ue_context_setup_t *req);
 
 /*
  * UE Inactivity Notification
diff --git a/openair2/F1AP/f1ap_encoder.c b/openair2/F1AP/f1ap_encoder.c
index 6e5f0f4e493ed63a12498d617fe7fb59fb1e4e2e..e623e665362ec38227b55b8558d8ce9d0ec8e68e 100644
--- a/openair2/F1AP/f1ap_encoder.c
+++ b/openair2/F1AP/f1ap_encoder.c
@@ -33,46 +33,9 @@
 #include "f1ap_common.h"
 #include "f1ap_encoder.h"
 
-int asn1_encoder_xer_print = 0;
+int asn1_encoder_xer_print = 1;
 
-/*
-static inline int f1ap_encode_initiating(f1ap_message *message,
-    uint8_t **buffer,
-    uint32_t *len);
-
-static inline int f1ap_encode_successfull_outcome(f1ap_message *message,
-    uint8_t **buffer, uint32_t *len);
-
-static inline int f1ap_encode_unsuccessfull_outcome(f1ap_message *message,
-    uint8_t **buffer, uint32_t *len);
-
-static inline int f1ap_encode_f1_setup_request(
-  F1ap_F1SetupRequestIEs_t *f1SetupRequestIEs, uint8_t **buffer, uint32_t *length);
-
-static inline int f1ap_encode_trace_failure(F1ap_TraceFailureIndicationIEs_t
-    *trace_failure_ies_p, uint8_t **buffer,
-    uint32_t *length);
-
-static inline int f1ap_encode_initial_context_setup_response(
-  F1ap_InitialContextSetupResponseIEs_t *initialContextSetupResponseIEs,
-  uint8_t **buffer,
-  uint32_t *length);
-
-static inline
-int f1ap_encode_ue_context_release_complete(
-  F1ap_UEContextReleaseCompleteIEs_t *f1ap_UEContextReleaseCompleteIEs,
-  uint8_t                           **buffer,
-  uint32_t                           *length);
-
-static inline
-int f1ap_encode_ue_context_release_request(
-  F1ap_UEContextReleaseRequestIEs_t *f1ap_UEContextReleaseRequestIEs,
-  uint8_t                              **buffer,
-  uint32_t                              *length);
-  */
-
-int f1ap_encode_pdu(F1AP_F1AP_PDU_t *pdu, uint8_t **buffer, uint32_t *length)
-{
+int f1ap_encode_pdu(F1AP_F1AP_PDU_t *pdu, uint8_t **buffer, uint32_t *length) {
   ssize_t    encoded;
   DevAssert(pdu != NULL);
   DevAssert(buffer != NULL);
@@ -84,11 +47,23 @@ int f1ap_encode_pdu(F1AP_F1AP_PDU_t *pdu, uint8_t **buffer, uint32_t *length)
     LOG_E(F1AP, "----------------- ASN1 ENCODER PRINT END----------------- \n");
   }
 
-  AssertFatal((encoded = aper_encode_to_new_buffer(&asn_DEF_F1AP_F1AP_PDU, 0, pdu, (void **)buffer))>0,
-	      "Failed to encode F1AP message\n");
+  char errbuf[128]; /* Buffer for error message */
+  size_t errlen = sizeof(errbuf); /* Size of the buffer */
+  int ret = asn_check_constraints(&asn_DEF_F1AP_F1AP_PDU, pdu, errbuf, &errlen);
 
-  *length = encoded;
+  /* assert(errlen < sizeof(errbuf)); // Guaranteed: you may rely on that */
+  if(ret) {
+    fprintf(stderr, "Constraint validation failed: %s\n", errbuf);
+  }
+
+  encoded = aper_encode_to_new_buffer(&asn_DEF_F1AP_F1AP_PDU, 0, pdu, (void **)buffer);
+
+  if (encoded < 0) {
+    LOG_E(F1AP, "Failed to encode F1AP message\n");
+    return -1;
+  }
 
+  *length = encoded;
   return encoded;
 }
 
diff --git a/openair2/F1AP/f1ap_handlers.c b/openair2/F1AP/f1ap_handlers.c
index 5aca059ae40d297a607fb9779bac8993cb5b74ab..fec03bb0b90002a399cdfd027fccf92acd5c0d0c 100644
--- a/openair2/F1AP/f1ap_handlers.c
+++ b/openair2/F1AP/f1ap_handlers.c
@@ -31,7 +31,6 @@
  */
 
 #include "f1ap_common.h"
-#include "f1ap_handlers.h"
 #include "f1ap_decoder.h"
 #include "f1ap_cu_interface_management.h"
 #include "f1ap_du_interface_management.h"
@@ -40,11 +39,9 @@
 #include "f1ap_cu_ue_context_management.h"
 #include "f1ap_du_ue_context_management.h"
 
-extern f1ap_setup_req_t *f1ap_du_data_from_du;
-
 /* Handlers matrix. Only f1 related procedure present here */
-f1ap_message_decoded_callback f1ap_messages_callback[][3] = {
-  
+f1ap_message_processing_t f1ap_messages_processing[][3] = {
+
 
   { 0, 0, 0 }, /* Reset */
   { CU_handle_F1_SETUP_REQUEST, DU_handle_F1_SETUP_RESPONSE, DU_handle_F1_SETUP_FAILURE }, /* F1Setup */
@@ -73,55 +70,50 @@ f1ap_message_decoded_callback f1ap_messages_callback[][3] = {
 };
 
 const char *f1ap_direction2String(int f1ap_dir) {
-static const char *f1ap_direction_String[] = {
-  "", /* Nothing */
-  "Initiating message", /* initiating message */
-  "Successfull outcome", /* successfull outcome */
-  "UnSuccessfull outcome", /* successfull outcome */
-};
-return(f1ap_direction_String[f1ap_dir]);
+  static const char *f1ap_direction_String[] = {
+    "", /* Nothing */
+    "Initiating message", /* initiating message */
+    "Successfull outcome", /* successfull outcome */
+    "UnSuccessfull outcome", /* successfull outcome */
+  };
+  return(f1ap_direction_String[f1ap_dir]);
 }
 
 int f1ap_handle_message(instance_t instance, uint32_t assoc_id, int32_t stream,
-                            const uint8_t * const data, const uint32_t data_length)
-{
-  F1AP_F1AP_PDU_t pdu;
+                        const uint8_t *const data, const uint32_t data_length) {
+  F1AP_F1AP_PDU_t pdu= {0};
   int ret;
-
   DevAssert(data != NULL);
 
-  memset(&pdu, 0, sizeof(pdu));
-
   if (f1ap_decode_pdu(&pdu, data, data_length) < 0) {
     LOG_E(F1AP, "Failed to decode PDU\n");
     return -1;
   }
 
   /* Checking procedure Code and direction of message */
-  if (pdu.choice.initiatingMessage->procedureCode >= sizeof(f1ap_messages_callback) / (3 * sizeof(
-        f1ap_message_decoded_callback))
+  if (pdu.choice.initiatingMessage->procedureCode >=
+      sizeof(f1ap_messages_processing) /
+      (3 * sizeof(f1ap_message_processing_t))
       || (pdu.present > F1AP_F1AP_PDU_PR_unsuccessfulOutcome)) {
     LOG_E(F1AP, "[SCTP %d] Either procedureCode %ld or direction %d exceed expected\n",
-               assoc_id, pdu.choice.initiatingMessage->procedureCode, pdu.present);
+          assoc_id, pdu.choice.initiatingMessage->procedureCode, pdu.present);
     ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_F1AP_F1AP_PDU, &pdu);
     return -1;
   }
 
-  /* No handler present.
-   * This can mean not implemented or no procedure for eNB (wrong direction).
-   */
-  if (f1ap_messages_callback[pdu.choice.initiatingMessage->procedureCode][pdu.present - 1] == NULL) {
+  if (f1ap_messages_processing[pdu.choice.initiatingMessage->procedureCode][pdu.present - 1] == NULL) {
+    // No handler present. This can mean not implemented or no procedure for eNB (wrong direction).
     LOG_E(F1AP, "[SCTP %d] No handler for procedureCode %ld in %s\n",
-                assoc_id, pdu.choice.initiatingMessage->procedureCode,
-               f1ap_direction2String(pdu.present - 1));
-    ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_F1AP_F1AP_PDU, &pdu);
-    return -1;
+          assoc_id, pdu.choice.initiatingMessage->procedureCode,
+          f1ap_direction2String(pdu.present - 1));
+    ret=-1;
+  } else {
+    /* Calling the right handler */
+    LOG_I(F1AP, "Calling handler with instance %ld\n",instance);
+    ret = (*f1ap_messages_processing[pdu.choice.initiatingMessage->procedureCode][pdu.present - 1])
+          (instance, assoc_id, stream, &pdu);
   }
 
-  /* Calling the right handler */
-  LOG_I(F1AP, "Calling handler with instance %ld\n",instance);
-  ret = (*f1ap_messages_callback[pdu.choice.initiatingMessage->procedureCode][pdu.present - 1])
-        (instance, assoc_id, stream, &pdu);
   ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_F1AP_F1AP_PDU, &pdu);
   return ret;
 }
diff --git a/openair2/F1AP/f1ap_handlers.h b/openair2/F1AP/f1ap_handlers.h
deleted file mode 100644
index 631249a324287607d7c2c3ea539f6aea85913a9d..0000000000000000000000000000000000000000
--- a/openair2/F1AP/f1ap_handlers.h
+++ /dev/null
@@ -1,39 +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 f1ap_handlers.h
- * \brief f1ap messages handlers
- * \author EURECOM/NTUST
- * \date 2018
- * \version 0.1
- * \company Eurecom
- * \email: navid.nikaein@eurecom.fr, bing-kai.hong@eurecom.fr
- * \note
- * \warning
- */
-
-#ifndef F1AP_HANDLERS_H_
-#define F1AP_HANDLERS_H_
-
-int f1ap_handle_message(instance_t instance, uint32_t assoc_id, int32_t stream,
-                            const uint8_t * const data, const uint32_t data_length);
-
-#endif /* F1AP_HANDLERS_H_ */
diff --git a/openair2/F1AP/f1ap_itti_messaging.c b/openair2/F1AP/f1ap_itti_messaging.c
index 443357a45e329dd87886eefe61af71883fc26cec..21096a65188cb41ffb8f6946be24047b61ee5bf0 100644
--- a/openair2/F1AP/f1ap_itti_messaging.c
+++ b/openair2/F1AP/f1ap_itti_messaging.c
@@ -22,52 +22,26 @@
 #include "f1ap_common.h"
 #include "f1ap_itti_messaging.h"
 
-void cu_f1ap_itti_send_sctp_data_req(instance_t instance, int32_t assoc_id, uint8_t *buffer,
-                                      uint32_t buffer_length, uint16_t stream)
-{
+void f1ap_itti_send_sctp_data_req(bool isCu, instance_t instance, uint8_t *buffer,
+                                  uint32_t buffer_length, uint16_t stream) {
   MessageDef      *message_p;
   sctp_data_req_t *sctp_data_req;
-
-  message_p = itti_alloc_new_message(TASK_CU_F1, 0, SCTP_DATA_REQ);
-
+  message_p = itti_alloc_new_message(isCu?TASK_CU_F1:TASK_DU_F1, 0, SCTP_DATA_REQ);
   sctp_data_req = &message_p->ittiMsg.sctp_data_req;
-
-  sctp_data_req->assoc_id      = assoc_id;
+  sctp_data_req->assoc_id      =  f1ap_assoc_id(isCu,instance);
   sctp_data_req->buffer        = buffer;
   sctp_data_req->buffer_length = buffer_length;
   sctp_data_req->stream        = stream;
-
-  itti_send_msg_to_task(TASK_SCTP, instance, message_p);
-}
-
-void du_f1ap_itti_send_sctp_data_req(instance_t instance, int32_t assoc_id, uint8_t *buffer,
-                                      uint32_t buffer_length, uint16_t stream)
-{
-  MessageDef      *message_p;
-  sctp_data_req_t *sctp_data_req;
-
-  message_p = itti_alloc_new_message(TASK_DU_F1, 0, SCTP_DATA_REQ);
-
-  sctp_data_req = &message_p->ittiMsg.sctp_data_req;
-
-  sctp_data_req->assoc_id      = assoc_id;
-  sctp_data_req->buffer        = buffer;
-  sctp_data_req->buffer_length = buffer_length;
-  sctp_data_req->stream        = stream;
-
   LOG_I(F1AP, "Sending ITTI message to SCTP Task\n");
   itti_send_msg_to_task(TASK_SCTP, instance, message_p);
 }
 
-void f1ap_itti_send_sctp_close_association(instance_t instance, int32_t assoc_id)
-{
+void f1ap_itti_send_sctp_close_association(bool isCu, instance_t instance) {
   MessageDef               *message_p = NULL;
   sctp_close_association_t *sctp_close_association_p = NULL;
-
   message_p = itti_alloc_new_message(TASK_S1AP, 0, SCTP_CLOSE_ASSOCIATION);
   sctp_close_association_p = &message_p->ittiMsg.sctp_close_association;
-  sctp_close_association_p->assoc_id      = assoc_id;
-
+  sctp_close_association_p->assoc_id      = f1ap_assoc_id(isCu,instance);
   itti_send_msg_to_task(TASK_SCTP, instance, message_p);
 }
 
diff --git a/openair2/F1AP/f1ap_itti_messaging.h b/openair2/F1AP/f1ap_itti_messaging.h
index 66c59a72e72ee1f721aa7bd41b4b07e6c961073a..a5560e6c8159eb22ba22aa4ea7944bacc7d00db2 100644
--- a/openair2/F1AP/f1ap_itti_messaging.h
+++ b/openair2/F1AP/f1ap_itti_messaging.h
@@ -22,14 +22,10 @@
 #ifndef F1AP_ITTI_MESSAGING_H_
 #define F1AP_ITTI_MESSAGING_H_
 
-void cu_f1ap_itti_send_sctp_data_req(instance_t instance, int32_t assoc_id, uint8_t *buffer,
-                                      uint32_t buffer_length, uint16_t stream);
+void f1ap_itti_send_sctp_data_req(bool isCu,instance_t instance, uint8_t *buffer,
+                                  uint32_t buffer_length, uint16_t stream);
 
-void du_f1ap_itti_send_sctp_data_req(instance_t instance, int32_t assoc_id, uint8_t *buffer,
-                                      uint32_t buffer_length, uint16_t stream);
-
-void f1ap_eNB_itti_send_sctp_close_association(instance_t instance,
-    int32_t assoc_id);
+void f1ap_eNB_itti_send_sctp_close_association(bool isCu,instance_t instance);
 
 
 #endif /* F1AP_ITTI_MESSAGING_H_ */
diff --git a/openair2/F1AP/f1ap_messaging.c b/openair2/F1AP/f1ap_messaging.c
deleted file mode 100644
index fb189eaed3d28c9cc6c22c6bb7c8dd0110ab4814..0000000000000000000000000000000000000000
--- a/openair2/F1AP/f1ap_messaging.c
+++ /dev/null
@@ -1,66 +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 f1ap_messaging.c
- * \brief f1ap procedures
- * \author EURECOM/NTUST
- * \date 2018
- * \version 0.1
- * \company Eurecom
- * \email: navid.nikaein@eurecom.fr, bing-kai.hong@eurecom.fr
- * \note
- * \warning
- */
-
-
-#include "f1ap_common.h"
-#include "f1ap_messaging.h"
-
-// void f1ap_send_sctp_data_req(instance_t instance, int32_t assoc_id, uint8_t *buffer,
-//                                       uint32_t buffer_length, uint16_t stream)
-// {
-//   MessageDef      *message_p;
-//   sctp_data_req_t *sctp_data_req;
-
-//   message_p = itti_alloc_new_message(TASK_F1AP, SCTP_DATA_REQ);
-
-//   sctp_data_req = &message_p->ittiMsg.sctp_data_req;
-
-//   sctp_data_req->assoc_id      = assoc_id;
-//   sctp_data_req->buffer        = buffer;
-//   sctp_data_req->buffer_length = buffer_length;
-//   sctp_data_req->stream        = stream;
-
-//   itti_send_msg_to_task(TASK_SCTP, instance, message_p);
-// }
-
-// void f1ap_send_sctp_close_association(instance_t instance, int32_t assoc_id)
-// {
-//   MessageDef               *message_p = NULL;
-//   sctp_close_association_t *sctp_close_association_p = NULL;
-
-//   message_p = itti_alloc_new_message(TASK_F1AP, SCTP_CLOSE_ASSOCIATION);
-//   sctp_close_association_p = &message_p->ittiMsg.sctp_close_association;
-//   sctp_close_association_p->assoc_id      = assoc_id;
-
-//   itti_send_msg_to_task(TASK_SCTP, instance, message_p);
-// }
-
diff --git a/openair2/F1AP/f1ap_messaging.h b/openair2/F1AP/f1ap_messaging.h
index 9ad0388d0198179d164e0176b246aa98f154522d..eb3b4224e933f0c93aeae114535a233e43af6473 100644
--- a/openair2/F1AP/f1ap_messaging.h
+++ b/openair2/F1AP/f1ap_messaging.h
@@ -35,10 +35,10 @@
 #define F1AP_MESSAGING_H_
 
 void f1ap_send_sctp_data_req(instance_t instance, int32_t assoc_id, uint8_t *buffer,
-                                      uint32_t buffer_length, uint16_t stream);
+                             uint32_t buffer_length, uint16_t stream);
 
 void f1ap_send_sctp_close_association(instance_t instance,
-    int32_t assoc_id);
+                                      int32_t assoc_id);
 
 
 #endif /* F1AP_MESSAGING_H_ */
diff --git a/openair2/GNB_APP/gnb_app.c b/openair2/GNB_APP/gnb_app.c
index 510402139995171f0dc43fab6b1eacbea3989cec..7d51d95840635fe98dcfc104f07392797b74c106 100644
--- a/openair2/GNB_APP/gnb_app.c
+++ b/openair2/GNB_APP/gnb_app.c
@@ -51,6 +51,7 @@
 #include "f1ap_du_task.h"
 #include "nfapi/oai_integration/vendor_ext.h"
 #include <openair2/LAYER2/nr_pdcp/nr_pdcp.h>
+#include "openair2/LAYER2/PDCP_v10.1.0/pdcp.h"
 extern unsigned char NB_gNB_INST;
 
 extern RAN_CONTEXT_t RC;
@@ -144,19 +145,19 @@ static void init_pdcp(void) {
       pdcp_initmask = pdcp_initmask | ENB_NAS_USE_TUN_BIT | SOFTMODEM_NOKRNMOD_BIT;
     }
 
-    pdcp_module_init(pdcp_initmask);
+    nr_pdcp_module_init(pdcp_initmask, 0);
 
     if (NODE_IS_CU(RC.nrrrc[0]->node_type)) {
       LOG_I(PDCP, "node is CU, pdcp send rlc_data_req by proto_agent \n");
-      pdcp_set_rlc_data_req_func((send_rlc_data_req_func_t)proto_agent_send_rlc_data_req);
+      pdcp_set_rlc_data_req_func(proto_agent_send_rlc_data_req);
     } else {
       LOG_I(PDCP, "node is gNB \n");
-      pdcp_set_rlc_data_req_func((send_rlc_data_req_func_t) rlc_data_req);
-      pdcp_set_pdcp_data_ind_func((pdcp_data_ind_func_t) pdcp_data_ind);
+      pdcp_set_rlc_data_req_func(rlc_data_req);
+      pdcp_set_pdcp_data_ind_func(pdcp_data_ind);
     }
   } else {
     LOG_I(PDCP, "node is DU, rlc send pdcp_data_ind by proto_agent \n");
-    pdcp_set_pdcp_data_ind_func((pdcp_data_ind_func_t) proto_agent_send_pdcp_data_ind);
+    pdcp_set_pdcp_data_ind_func(proto_agent_send_pdcp_data_ind);
   }
 }
 
@@ -181,6 +182,8 @@ void *gNB_app_task(void *args_p)
 
   LOG_I(PHY, "%s() Task ready initialize structures\n", __FUNCTION__);
 
+  RCconfig_NR_L1();
+
   if (RC.nb_nr_macrlc_inst>0) RCconfig_nr_macrlc();
 
   LOG_I(PHY, "%s() RC.nb_nr_L1_inst:%d\n", __FUNCTION__, RC.nb_nr_L1_inst);
@@ -195,15 +198,13 @@ void *gNB_app_task(void *args_p)
 
   RC.nrrrc = (gNB_RRC_INST **)malloc(RC.nb_nr_inst*sizeof(gNB_RRC_INST *));
   LOG_I(PHY, "%s() RC.nb_nr_inst:%d RC.nrrrc:%p\n", __FUNCTION__, RC.nb_nr_inst, RC.nrrrc);
-
   for (gnb_id = gnb_id_start; (gnb_id < gnb_id_end) ; gnb_id++) {
-    RC.nrrrc[gnb_id] = (gNB_RRC_INST*)malloc(sizeof(gNB_RRC_INST));
+    RC.nrrrc[gnb_id] = (gNB_RRC_INST*)calloc(1,sizeof(gNB_RRC_INST));
     LOG_I(PHY, "%s() Creating RRC instance RC.nrrrc[%d]:%p (%d of %d)\n", __FUNCTION__, gnb_id, RC.nrrrc[gnb_id], gnb_id+1, gnb_id_end);
-    memset((void *)RC.nrrrc[gnb_id],0,sizeof(gNB_RRC_INST));
     configure_nr_rrc(gnb_id);
   }
 
-  if (RC.nb_nr_inst > 0)  {
+  if (RC.nb_nr_inst > 0 && !get_softmodem_params()->nsa)  {
     init_pdcp();
   }
 
@@ -214,7 +215,7 @@ void *gNB_app_task(void *args_p)
 
   /* For the CU case the gNB registration with the AMF might have to take place after the F1 setup, as the PLMN info
      * can originate from the DU. Add check on whether x2ap is enabled to account for ENDC NSA scenario.*/
-  if ((AMF_MODE_ENABLED || is_x2ap_enabled()) && !NODE_IS_DU(RC.nrrrc[0]->node_type) && !NODE_IS_CU(RC.nrrrc[0]->node_type)) {
+  if ((AMF_MODE_ENABLED || is_x2ap_enabled()) && !NODE_IS_DU(RC.nrrrc[0]->node_type) ) { //&& !NODE_IS_CU(RC.nrrrc[0]->node_type)) {
     /* Try to register each gNB */
     //registered_gnb = 0;
     __attribute__((unused)) uint32_t register_gnb_pending = gNB_app_register (gnb_id_start, gnb_id_end);
diff --git a/openair2/GNB_APP/gnb_config.c b/openair2/GNB_APP/gnb_config.c
index ef464f4976afdf8bf927a025cfb0dc9387a16a6f..9710dd18146cf889fcd06187ef7a55abc81653f6 100644
--- a/openair2/GNB_APP/gnb_config.c
+++ b/openair2/GNB_APP/gnb_config.c
@@ -957,9 +957,8 @@ void RCconfig_NRRRC(MessageDef *msg_p, uint32_t i, gNB_RRC_INST *rrc) {
   paramdef_t GNBParams[]  = GNBPARAMS_DESC;
   paramlist_def_t GNBParamList = {GNB_CONFIG_STRING_GNB_LIST,NULL,0};
 
-  NR_ServingCellConfigCommon_t *scc = calloc(1,sizeof(NR_ServingCellConfigCommon_t));
+  NR_ServingCellConfigCommon_t *scc = calloc(1,sizeof(*scc));
   uint64_t ssb_bitmap=0xff;
-  memset((void*)scc,0,sizeof(NR_ServingCellConfigCommon_t));
   prepare_scc(scc);
   paramdef_t SCCsParams[] = SCCPARAMS_DESC(scc);
   paramlist_def_t SCCsParamList = {GNB_CONFIG_STRING_SERVINGCELLCONFIGCOMMON, NULL, 0};
@@ -1182,23 +1181,14 @@ void RCconfig_NRRRC(MessageDef *msg_p, uint32_t i, gNB_RRC_INST *rrc) {
 int RCconfig_nr_gtpu(void ) {
 
   int               num_gnbs                      = 0;
-
-
-
-  char*             gnb_interface_name_for_NGU    = NULL;
   char*             gnb_ipv4_address_for_NGU      = NULL;
   uint32_t          gnb_port_for_NGU              = 0;
-  char*             gnb_interface_name_for_S1U    = NULL;
   char*             gnb_ipv4_address_for_S1U      = NULL;
   uint32_t          gnb_port_for_S1U              = 0;
-  char             *address                       = NULL;
-  char             *cidr                          = NULL;
   char gtpupath[MAX_OPTNAME_SIZE*2 + 8];
-  uint8_t           gnb_mode                      = 0;
 
   paramdef_t GNBSParams[] = GNBSPARAMS_DESC;
   paramdef_t NETParams[]  =  GNBNETPARAMS_DESC;
-  paramdef_t GTPUParams[] = GNBGTPUPARAMS_DESC;
   LOG_I(GTPU,"Configuring GTPu\n");
 
 /* get number of active eNodeBs */
@@ -1208,49 +1198,32 @@ int RCconfig_nr_gtpu(void ) {
            "Failed to parse config file no active gNodeBs in %s \n", GNB_CONFIG_STRING_ACTIVE_GNBS);
 
   sprintf(gtpupath,"%s.[%i].%s",GNB_CONFIG_STRING_GNB_LIST,0,GNB_CONFIG_STRING_NETWORK_INTERFACES_CONFIG);
-  config_get(GTPUParams,sizeof(GTPUParams)/sizeof(paramdef_t),gtpupath);
-
   config_get(NETParams,sizeof(NETParams)/sizeof(paramdef_t),gtpupath); 
-
-  if (NETParams[0].strptr != NULL) { // SA
+  char *cidr=NULL, *address = NULL;
+  int port;
+  if (NETParams[1].strptr != NULL) {
     LOG_I(GTPU, "SA mode \n");
-    cidr = gnb_ipv4_address_for_NGU;
-    gnb_mode = 0;
-  } else {// NSA
+    address = strtok_r(gnb_ipv4_address_for_NGU, "/", &cidr);
+    port=gnb_port_for_NGU;
+  } else { 
     LOG_I(GTPU, "NSA mode \n");
-    cidr = gnb_ipv4_address_for_S1U;
-    gnb_mode = 1;
+    address = strtok_r(gnb_ipv4_address_for_S1U, "/", &cidr);
+    port=gnb_port_for_S1U;
   }
 
-    address = strtok(cidr, "/");
-
-    if (address) {
-      MessageDef *message;
-
-      if (gnb_mode == 1) { // NSA
-        message = itti_alloc_new_message(TASK_GNB_APP, 0, GTPV1U_ENB_S1_REQ);
-        AssertFatal(message!=NULL,"");
-        // IPV4_STR_ADDR_TO_INT_NWBO ( address, RC.gtpv1u_data_g->enb_ip_address_for_S1u_S12_S4_up, "BAD IP ADDRESS FORMAT FOR eNB S1_U !\n" );
-        // LOG_I(GTPU,"Configuring GTPu address : %s -> %x\n",address,RC.gtpv1u_data_g->enb_ip_address_for_S1u_S12_S4_up);
-        IPV4_STR_ADDR_TO_INT_NWBO (address, GTPV1U_ENB_S1_REQ(message).enb_ip_address_for_S1u_S12_S4_up, "BAD IP ADDRESS FORMAT FOR eNB S1_U !\n" );
-        LOG_I(GTPU,"Configuring GTPu address : %s -> %x\n",address,GTPV1U_ENB_S1_REQ(message).enb_ip_address_for_S1u_S12_S4_up);
-        GTPV1U_ENB_S1_REQ(message).enb_port_for_S1u_S12_S4_up = gnb_port_for_S1U;
-        strcpy(GTPV1U_ENB_S1_REQ(message).addrStr,address);
-        sprintf(GTPV1U_ENB_S1_REQ(message).portStr,"%d", gnb_port_for_NGU);
-      } else {// TODO SA
-        message = itti_alloc_new_message(TASK_GNB_APP, 0, GTPV1U_GNB_NG_REQ);
-        AssertFatal(message!=NULL,"");
-        IPV4_STR_ADDR_TO_INT_NWBO (address, GTPV1U_GNB_NG_REQ(message).gnb_ip_address_for_NGu_up, "BAD IP ADDRESS FORMAT FOR gNB NG_U !\n" );
-        LOG_I(GTPU,"Configuring GTPu address : %s -> %x\n",address,GTPV1U_GNB_NG_REQ(message).gnb_ip_address_for_NGu_up);
-        GTPV1U_GNB_NG_REQ(message).gnb_port_for_NGu_up = gnb_port_for_NGU;
-        strcpy(GTPV1U_GNB_NG_REQ(message).addrStr,address);
-        sprintf(GTPV1U_GNB_NG_REQ(message).portStr,"%d", gnb_port_for_NGU);
-      }
-     itti_send_msg_to_task (TASK_VARIABLE, 0, message); // data model is wrong: gtpu doesn't have enb_id (or module_id)
-    } else
-    LOG_E(GTPU,"invalid address for NGU\n");
-
-
+  if (address) {
+    MessageDef *message;
+    message = itti_alloc_new_message(TASK_GNB_APP, 0, GTPV1U_REQ);
+    AssertFatal(message!=NULL,"");
+    IPV4_STR_ADDR_TO_INT_NWBO (address, GTPV1U_REQ(message).localAddr, "BAD IP ADDRESS FORMAT FOR gNB NG_U !\n" );
+    LOG_I(GTPU,"Configuring GTPu address : %s -> %x\n",address,GTPV1U_REQ(message).localAddr);
+    GTPV1U_REQ(message).localPort = port;
+    strcpy(GTPV1U_REQ(message).localAddrStr,address);
+    sprintf(GTPV1U_REQ(message).localPortStr,"%d", port);
+    itti_send_msg_to_task (TASK_VARIABLE, 0, message); // data model is wrong: gtpu doesn't have enb_id (or module_id)
+  } else
+    LOG_E(GTPU,"invalid address for NGU or S1U\n");
+  
 return 0;
 }
 
@@ -1268,6 +1241,10 @@ int RCconfig_NR_NG(MessageDef *msg_p, uint32_t i) {
   (void)  my_int;
 
   memset((char*)active_gnb,0,MAX_GNB* sizeof(char*));
+  char*             gnb_ipv4_address_for_NGU      = NULL;
+  uint32_t          gnb_port_for_NGU              = 0;
+  char*             gnb_ipv4_address_for_S1U      = NULL;
+  uint32_t          gnb_port_for_S1U              = 0;
 
   paramdef_t GNBSParams[] = GNBSPARAMS_DESC;
   paramdef_t GNBParams[]  = GNBPARAMS_DESC;
@@ -1609,6 +1586,11 @@ int RCconfig_NR_X2(MessageDef *msg_p, uint32_t i) {
             paramdef_t X2Params[]  = X2PARAMS_DESC;
             paramlist_def_t X2ParamList = {ENB_CONFIG_STRING_TARGET_ENB_X2_IP_ADDRESS,NULL,0};
             paramdef_t SCTPParams[]  = GNBSCTPPARAMS_DESC;
+	    char*             gnb_ipv4_address_for_NGU      = NULL;
+	    uint32_t          gnb_port_for_NGU              = 0;
+	    char*             gnb_ipv4_address_for_S1U      = NULL;
+	    uint32_t          gnb_port_for_S1U              = 0;
+
             paramdef_t NETParams[]  =  GNBNETPARAMS_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 */
@@ -1769,7 +1751,9 @@ int RCconfig_NR_DU_F1(MessageDef *msg_p, uint32_t i) {
     config_getlist( &GNBParamList,GNBParams,sizeof(GNBParams)/sizeof(paramdef_t),NULL);
     AssertFatal(GNBParamList.paramarray[i][GNB_GNB_ID_IDX].uptr != NULL,
                 "gNB id %u is not defined in configuration file\n",i);
-    F1AP_SETUP_REQ (msg_p).num_cells_available = 0;
+    f1ap_setup_req_t * f1Setup=&F1AP_SETUP_REQ(msg_p);
+    f1Setup->num_cells_available = 0;
+    f1Setup->cell_type=CELL_MACRO_GNB;
 
     for (k=0; k <num_gnbs ; k++) {
       if (strcmp(GNBSParams[GNB_ACTIVE_GNBS_IDX].strlistptr[k], *(GNBParamList.paramarray[i][GNB_GNB_NAME_IDX].strptr)) == 0) {
@@ -1785,42 +1769,46 @@ int RCconfig_NR_DU_F1(MessageDef *msg_p, uint32_t i) {
 
         config_getlist(&PLMNParamList, PLMNParams, sizeof(PLMNParams)/sizeof(paramdef_t), aprefix);
         paramdef_t SCTPParams[]  = SCTPPARAMS_DESC;
-        F1AP_SETUP_REQ (msg_p).num_cells_available++;
-        F1AP_SETUP_REQ (msg_p).gNB_DU_id        = *(GNBParamList.paramarray[0][GNB_GNB_ID_IDX].uptr);
-        LOG_I(GNB_APP,"F1AP: gNB_DU_id[%d] %ld\n",k,F1AP_SETUP_REQ (msg_p).gNB_DU_id);
-        F1AP_SETUP_REQ (msg_p).gNB_DU_name      = strdup(*(GNBParamList.paramarray[0][GNB_GNB_NAME_IDX].strptr));
-        LOG_I(GNB_APP,"F1AP: gNB_DU_name[%d] %s\n",k,F1AP_SETUP_REQ (msg_p).gNB_DU_name);
-        F1AP_SETUP_REQ (msg_p).tac[k]              = *GNBParamList.paramarray[i][GNB_TRACKING_AREA_CODE_IDX].uptr;
-        LOG_I(GNB_APP,"F1AP: tac[%d] %d\n",k,F1AP_SETUP_REQ (msg_p).tac[k]);
-        F1AP_SETUP_REQ (msg_p).mcc[k]              = *PLMNParamList.paramarray[0][GNB_MOBILE_COUNTRY_CODE_IDX].uptr;
-        LOG_I(GNB_APP,"F1AP: mcc[%d] %d\n",k,F1AP_SETUP_REQ (msg_p).mcc[k]);
-        F1AP_SETUP_REQ (msg_p).mnc[k]              = *PLMNParamList.paramarray[0][GNB_MOBILE_NETWORK_CODE_IDX].uptr;
-        LOG_I(GNB_APP,"F1AP: mnc[%d] %d\n",k,F1AP_SETUP_REQ (msg_p).mnc[k]);
-        F1AP_SETUP_REQ (msg_p).mnc_digit_length[k] = *PLMNParamList.paramarray[0][GNB_MNC_DIGIT_LENGTH].u8ptr;
-        LOG_I(GNB_APP,"F1AP: mnc_digit_length[%d] %d\n",k,F1AP_SETUP_REQ (msg_p).mnc_digit_length[k]);
-        AssertFatal((F1AP_SETUP_REQ (msg_p).mnc_digit_length[k] == 2) ||
-                    (F1AP_SETUP_REQ (msg_p).mnc_digit_length[k] == 3),
+        f1Setup->num_cells_available++;
+        f1Setup->gNB_DU_id        = *(GNBParamList.paramarray[0][GNB_GNB_ID_IDX].uptr);
+        LOG_I(GNB_APP,"F1AP: gNB_DU_id[%d] %ld\n",k,f1Setup->gNB_DU_id);
+        f1Setup->gNB_DU_name      = strdup(*(GNBParamList.paramarray[0][GNB_GNB_NAME_IDX].strptr));
+        LOG_I(GNB_APP,"F1AP: gNB_DU_name[%d] %s\n",k,f1Setup->gNB_DU_name);
+        f1Setup->cell[k].tac              = *GNBParamList.paramarray[i][GNB_TRACKING_AREA_CODE_IDX].uptr;
+        LOG_I(GNB_APP,"F1AP: tac[%d] %d\n",k,f1Setup->cell[k].tac);
+        f1Setup->cell[k].mcc              = *PLMNParamList.paramarray[0][GNB_MOBILE_COUNTRY_CODE_IDX].uptr;
+        LOG_I(GNB_APP,"F1AP: mcc[%d] %d\n",k,f1Setup->cell[k].mcc);
+        f1Setup->cell[k].mnc              = *PLMNParamList.paramarray[0][GNB_MOBILE_NETWORK_CODE_IDX].uptr;
+        LOG_I(GNB_APP,"F1AP: mnc[%d] %d\n",k,f1Setup->cell[k].mnc);
+        f1Setup->cell[k].mnc_digit_length = *PLMNParamList.paramarray[0][GNB_MNC_DIGIT_LENGTH].u8ptr;
+        LOG_I(GNB_APP,"F1AP: mnc_digit_length[%d] %d\n",k,f1Setup->cell[k].mnc_digit_length);
+        AssertFatal((f1Setup->cell[k].mnc_digit_length == 2) ||
+                    (f1Setup->cell[k].mnc_digit_length == 3),
                     "BAD MNC DIGIT LENGTH %d",
-                    F1AP_SETUP_REQ (msg_p).mnc_digit_length[k]);
-        F1AP_SETUP_REQ (msg_p).nr_cellid[k] = (uint64_t)*(GNBParamList.paramarray[i][GNB_NRCELLID_IDX].u64ptr);
-        LOG_I(GNB_APP,"F1AP: nr_cellid[%d] %ld\n",k,F1AP_SETUP_REQ (msg_p).nr_cellid[k]);
+                    f1Setup->cell[k].mnc_digit_length);
+        f1Setup->cell[k].nr_cellid = (uint64_t)*(GNBParamList.paramarray[i][GNB_NRCELLID_IDX].u64ptr);
+        LOG_I(GNB_APP,"F1AP: nr_cellid[%d] %ld\n",k,f1Setup->cell[k].nr_cellid);
         LOG_I(GNB_APP,"F1AP: CU_ip4_address in DU %s\n",RC.nrmac[k]->eth_params_n.remote_addr);
-        LOG_I(GNB_APP,"FIAP: CU_ip4_address in DU %p, strlen %d\n",F1AP_SETUP_REQ (msg_p).CU_f1_ip_address.ipv4_address,(int)strlen(RC.nrmac[k]->eth_params_n.remote_addr));
-        F1AP_SETUP_REQ (msg_p).CU_f1_ip_address.ipv6 = 0;
-        F1AP_SETUP_REQ (msg_p).CU_f1_ip_address.ipv4 = 1;
-        //strcpy(F1AP_SETUP_REQ (msg_p).CU_f1_ip_address.ipv6_address, "");
-        strcpy(F1AP_SETUP_REQ (msg_p).CU_f1_ip_address.ipv4_address, RC.nrmac[k]->eth_params_n.remote_addr);
+        LOG_I(GNB_APP,"FIAP: CU_ip4_address in DU %p, strlen %d\n",f1Setup->CU_f1_ip_address.ipv4_address,(int)strlen(RC.nrmac[k]->eth_params_n.remote_addr));
+        f1Setup->CU_f1_ip_address.ipv6 = 0;
+        f1Setup->CU_f1_ip_address.ipv4 = 1;
+        //strcpy(f1Setup->CU_f1_ip_address.ipv6_address, "");
+        strcpy(f1Setup->CU_f1_ip_address.ipv4_address, RC.nrmac[k]->eth_params_n.remote_addr);
         LOG_I(GNB_APP,"F1AP: DU_ip4_address in DU %s\n",RC.nrmac[k]->eth_params_n.my_addr);
-        LOG_I(GNB_APP,"FIAP: DU_ip4_address in DU %p, strlen %d\n",F1AP_SETUP_REQ (msg_p).DU_f1_ip_address.ipv4_address,(int)strlen(RC.nrmac[k]->eth_params_n.my_addr));
-        F1AP_SETUP_REQ (msg_p).DU_f1_ip_address.ipv6 = 0;
-        F1AP_SETUP_REQ (msg_p).DU_f1_ip_address.ipv4 = 1;
-        //strcpy(F1AP_SETUP_REQ (msg_p).DU_f1_ip_address.ipv6_address, "");
-        strcpy(F1AP_SETUP_REQ (msg_p).DU_f1_ip_address.ipv4_address, RC.nrmac[k]->eth_params_n.my_addr);
-        //strcpy(F1AP_SETUP_REQ (msg_p).CU_ip_address[l].ipv6_address,*(F1ParamList.paramarray[l][ENB_CU_IPV6_ADDRESS_IDX].strptr));
+        LOG_I(GNB_APP,"FIAP: DU_ip4_address in DU %p, strlen %ld\n",
+	      f1Setup->DU_f1_ip_address.ipv4_address,
+	      strlen(RC.nrmac[k]->eth_params_n.my_addr));
+        f1Setup->DU_f1_ip_address.ipv6 = 0;
+        f1Setup->DU_f1_ip_address.ipv4 = 1;
+        //strcpy(f1Setup->DU_f1_ip_address.ipv6_address, "");
+        strcpy(f1Setup->DU_f1_ip_address.ipv4_address, RC.nrmac[k]->eth_params_n.my_addr);
+	f1Setup->DUport= RC.nrmac[k]->eth_params_n.my_portd;
+	f1Setup->CUport= RC.nrmac[k]->eth_params_n.remote_portd;
+        //strcpy(f1Setup->CU_ip_address[l].ipv6_address,*(F1ParamList.paramarray[l][ENB_CU_IPV6_ADDRESS_IDX].strptr));
         sprintf(aprefix,"%s.[%i].%s",GNB_CONFIG_STRING_GNB_LIST,k,GNB_CONFIG_STRING_SCTP_CONFIG);
         config_get(SCTPParams,sizeof(SCTPParams)/sizeof(paramdef_t),aprefix);
-        F1AP_SETUP_REQ (msg_p).sctp_in_streams = (uint16_t)*(SCTPParams[GNB_SCTP_INSTREAMS_IDX].uptr);
-        F1AP_SETUP_REQ (msg_p).sctp_out_streams = (uint16_t)*(SCTPParams[GNB_SCTP_OUTSTREAMS_IDX].uptr);
+        f1Setup->sctp_in_streams = (uint16_t)*(SCTPParams[GNB_SCTP_INSTREAMS_IDX].uptr);
+        f1Setup->sctp_out_streams = (uint16_t)*(SCTPParams[GNB_SCTP_OUTSTREAMS_IDX].uptr);
         gNB_RRC_INST *rrc = RC.nrrrc[k];
         // wait until RRC cell information is configured
         int cell_info_configured = 0;
@@ -1833,53 +1821,53 @@ int RCconfig_NR_DU_F1(MessageDef *msg_p, uint32_t i) {
           pthread_mutex_unlock(&rrc->cell_info_mutex);
         } while (cell_info_configured == 0);
 
-        rrc->configuration.mcc[0] = F1AP_SETUP_REQ (msg_p).mcc[k];
-        rrc->configuration.mnc[0] = F1AP_SETUP_REQ (msg_p).mnc[k];
-        rrc->configuration.tac    = F1AP_SETUP_REQ (msg_p).tac[k];
-        rrc->nr_cellid = F1AP_SETUP_REQ (msg_p).nr_cellid[k];
-        F1AP_SETUP_REQ (msg_p).nr_pci[k]    = *rrc->configuration.scc->physCellId;
-        F1AP_SETUP_REQ (msg_p).num_ssi[k] = 0;
+        rrc->configuration.mcc[0] = f1Setup->cell[k].mcc;
+        rrc->configuration.mnc[0] = f1Setup->cell[k].mnc;
+        rrc->configuration.tac    = f1Setup->cell[k].tac;
+        rrc->nr_cellid = f1Setup->cell[k].nr_cellid;
+        f1Setup->cell[k].nr_pci    = *rrc->configuration.scc->physCellId;
+        f1Setup->cell[k].num_ssi = 0;
 
         if (rrc->configuration.scc->tdd_UL_DL_ConfigurationCommon) {
           LOG_I(GNB_APP,"ngran_DU: Configuring Cell %d for TDD\n",k);
-          F1AP_SETUP_REQ (msg_p).fdd_flag = 0;
-          F1AP_SETUP_REQ (msg_p).nr_mode_info[k].tdd.nr_arfcn = rrc->configuration.scc->downlinkConfigCommon->frequencyInfoDL->absoluteFrequencyPointA;
-          F1AP_SETUP_REQ (msg_p).nr_mode_info[k].tdd.scs = rrc->configuration.scc->downlinkConfigCommon->frequencyInfoDL->scs_SpecificCarrierList.list.array[0]->subcarrierSpacing;
-          F1AP_SETUP_REQ (msg_p).nr_mode_info[k].tdd.nrb = rrc->configuration.scc->downlinkConfigCommon->frequencyInfoDL->scs_SpecificCarrierList.list.array[0]->carrierBandwidth;
-          F1AP_SETUP_REQ (msg_p).nr_mode_info[k].tdd.num_frequency_bands = 1;
-          F1AP_SETUP_REQ (msg_p).nr_mode_info[k].tdd.nr_band[0] = *rrc->configuration.scc->downlinkConfigCommon->frequencyInfoDL->frequencyBandList.list.array[0];
-          F1AP_SETUP_REQ (msg_p).nr_mode_info[k].tdd.sul_active              = 0;
+          f1Setup->fdd_flag = 0;
+          f1Setup->nr_mode_info[k].tdd.nr_arfcn = rrc->configuration.scc->downlinkConfigCommon->frequencyInfoDL->absoluteFrequencyPointA;
+          f1Setup->nr_mode_info[k].tdd.scs = rrc->configuration.scc->downlinkConfigCommon->frequencyInfoDL->scs_SpecificCarrierList.list.array[0]->subcarrierSpacing;
+          f1Setup->nr_mode_info[k].tdd.nrb = rrc->configuration.scc->downlinkConfigCommon->frequencyInfoDL->scs_SpecificCarrierList.list.array[0]->carrierBandwidth;
+          f1Setup->nr_mode_info[k].tdd.num_frequency_bands = 1;
+          f1Setup->nr_mode_info[k].tdd.nr_band[0] = *rrc->configuration.scc->downlinkConfigCommon->frequencyInfoDL->frequencyBandList.list.array[0];
+          f1Setup->nr_mode_info[k].tdd.sul_active              = 0;
         } else {
           /***************** for test *****************/
           LOG_I(GNB_APP,"ngran_DU: Configuring Cell %d for FDD\n",k);
-          F1AP_SETUP_REQ (msg_p).fdd_flag = 1;
-          F1AP_SETUP_REQ (msg_p).nr_mode_info[k].fdd.dl_nr_arfcn             = 26200UL;
-          F1AP_SETUP_REQ (msg_p).nr_mode_info[k].fdd.ul_nr_arfcn             = 26200UL;
+          f1Setup->fdd_flag = 1;
+          f1Setup->nr_mode_info[k].fdd.dl_nr_arfcn             = 26200UL;
+          f1Setup->nr_mode_info[k].fdd.ul_nr_arfcn             = 26200UL;
           // For LTE use scs field to carry prefix type and number of antennas
-          F1AP_SETUP_REQ (msg_p).nr_mode_info[k].fdd.dl_scs                  = 0;
-          F1AP_SETUP_REQ (msg_p).nr_mode_info[k].fdd.ul_scs                  = 0;
+          f1Setup->nr_mode_info[k].fdd.dl_scs                  = 0;
+          f1Setup->nr_mode_info[k].fdd.ul_scs                  = 0;
           // use nrb field to hold LTE N_RB_DL (0...5)
-          F1AP_SETUP_REQ (msg_p).nr_mode_info[k].fdd.ul_nrb                  = 3;
-          F1AP_SETUP_REQ (msg_p).nr_mode_info[k].fdd.ul_nrb                  = 3;
+          f1Setup->nr_mode_info[k].fdd.ul_nrb                  = 3;
+          f1Setup->nr_mode_info[k].fdd.ul_nrb                  = 3;
           // RK: we need to check there value for FDD's frequency_bands DL/UL
-          F1AP_SETUP_REQ (msg_p).nr_mode_info[k].fdd.ul_num_frequency_bands  = 1;
-          F1AP_SETUP_REQ (msg_p).nr_mode_info[k].fdd.ul_nr_band[0]           = 7;
-          F1AP_SETUP_REQ (msg_p).nr_mode_info[k].fdd.dl_num_frequency_bands  = 1;
-          F1AP_SETUP_REQ (msg_p).nr_mode_info[k].fdd.dl_nr_band[0]           = 7;
-          F1AP_SETUP_REQ (msg_p).nr_mode_info[k].fdd.ul_num_sul_frequency_bands  = 0;
-          F1AP_SETUP_REQ (msg_p).nr_mode_info[k].fdd.ul_nr_sul_band[0]           = 7;
-          F1AP_SETUP_REQ (msg_p).nr_mode_info[k].fdd.dl_num_sul_frequency_bands  = 0;
-          F1AP_SETUP_REQ (msg_p).nr_mode_info[k].fdd.dl_nr_sul_band[0]           = 7;
-          F1AP_SETUP_REQ (msg_p).nr_mode_info[k].fdd.sul_active              = 0;
+          f1Setup->nr_mode_info[k].fdd.ul_num_frequency_bands  = 1;
+          f1Setup->nr_mode_info[k].fdd.ul_nr_band[0]           = 7;
+          f1Setup->nr_mode_info[k].fdd.dl_num_frequency_bands  = 1;
+          f1Setup->nr_mode_info[k].fdd.dl_nr_band[0]           = 7;
+          f1Setup->nr_mode_info[k].fdd.ul_num_sul_frequency_bands  = 0;
+          f1Setup->nr_mode_info[k].fdd.ul_nr_sul_band[0]           = 7;
+          f1Setup->nr_mode_info[k].fdd.dl_num_sul_frequency_bands  = 0;
+          f1Setup->nr_mode_info[k].fdd.dl_nr_sul_band[0]           = 7;
+          f1Setup->nr_mode_info[k].fdd.sul_active              = 0;
           /***************** for test *****************/
         }
 
-        F1AP_SETUP_REQ (msg_p).measurement_timing_information[k]             = "0";
-        F1AP_SETUP_REQ (msg_p).ranac[k]                                      = 0;
-        F1AP_SETUP_REQ (msg_p).mib[k]                                        = rrc->carrier.MIB;
-        F1AP_SETUP_REQ (msg_p).sib1[k]                                       = rrc->carrier.SIB1;
-        F1AP_SETUP_REQ (msg_p).mib_length[k]                                 = rrc->carrier.sizeof_MIB;
-        F1AP_SETUP_REQ (msg_p).sib1_length[k]                                = rrc->carrier.sizeof_SIB1;
+        f1Setup->measurement_timing_information[k]             = "0";
+        f1Setup->ranac[k]                                      = 0;
+        f1Setup->mib[k]                                        = rrc->carrier.MIB;
+        f1Setup->sib1[k]                                       = rrc->carrier.SIB1;
+        f1Setup->mib_length[k]                                 = rrc->carrier.sizeof_MIB;
+        f1Setup->sib1_length[k]                                = rrc->carrier.sizeof_SIB1;
         break;
       }
     }
@@ -2075,8 +2063,8 @@ int gNB_app_handle_f1ap_setup_resp(f1ap_setup_resp_t *resp) {
 
           du_extract_and_decode_SI(i,
                                    si_ind,
-                                   resp->cells_to_activate[j].SI_container[2+si_ind],
-                                   resp->cells_to_activate[j].SI_container_length[2+si_ind]);
+                                   resp->cells_to_activate[j].SI_container[si_ind],
+                                   resp->cells_to_activate[j].SI_container_length[si_ind]);
         }
 
         // perform MAC/L1 common configuration
@@ -2110,8 +2098,8 @@ int gNB_app_handle_f1ap_gnb_cu_configuration_update(f1ap_gnb_cu_configuration_up
 
           du_extract_and_decode_SI(i,
                                    si_ind,
-                                   gnb_cu_cfg_update->cells_to_activate[j].SI_container[2+si_ind],
-                                   gnb_cu_cfg_update->cells_to_activate[j].SI_container_length[2+si_ind]);
+                                   gnb_cu_cfg_update->cells_to_activate[j].SI_container[si_ind],
+                                   gnb_cu_cfg_update->cells_to_activate[j].SI_container_length[si_ind]);
         }
 
         // perform MAC/L1 common configuration
diff --git a/openair2/GNB_APP/gnb_paramdef.h b/openair2/GNB_APP/gnb_paramdef.h
index 730b6b85b62c652b7d0c922ae97230dc3fbf17a5..5b879e04f6488f430d5c0aebc561793c8ecdc371 100644
--- a/openair2/GNB_APP/gnb_paramdef.h
+++ b/openair2/GNB_APP/gnb_paramdef.h
@@ -334,29 +334,17 @@ typedef enum {
 /*   optname                                            helpstr   paramflags    XXXptr              defXXXval             type           numelt     */
 /*--------------------------------------------------------------------------------------------------------------------------------------------------*/
 #define GNBNETPARAMS_DESC {  \
-{GNB_CONFIG_STRING_GNB_INTERFACE_NAME_FOR_NG_AMF,        NULL,      0,         strptr:NULL,         defstrval:NULL,      TYPE_STRING,      0},      \
-{GNB_CONFIG_STRING_GNB_IPV4_ADDRESS_FOR_NG_AMF,          NULL,      0,         strptr:NULL,         defstrval:NULL,      TYPE_STRING,      0},      \
-{GNB_CONFIG_STRING_GNB_INTERFACE_NAME_FOR_NGU,           NULL,      0,         strptr:NULL,         defstrval:NULL,      TYPE_STRING,      0},      \
-{GNB_CONFIG_STRING_GNB_IPV4_ADDR_FOR_NGU,                NULL,      0,         strptr:NULL,         defstrval:NULL,      TYPE_STRING,      0},      \
-{GNB_CONFIG_STRING_GNB_PORT_FOR_NGU,                     NULL,      0,         uptr:NULL,           defintval:2152L,     TYPE_UINT,        0},      \
-{GNB_CONFIG_STRING_ENB_IPV4_ADDR_FOR_X2C,                NULL,      0,         strptr:NULL,         defstrval:NULL,      TYPE_STRING,      0},      \
-{GNB_CONFIG_STRING_ENB_PORT_FOR_X2C,                     NULL,      0,         uptr:NULL,           defintval:0L,        TYPE_UINT,        0}      \
-}   
-
-
-
-/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
-/*                                            GTPU  configuration parameters                                                                                                      */
-/*   optname                                            helpstr   paramflags    XXXptr              defXXXval                                           type           numelt     */
-/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
-#define GNBGTPUPARAMS_DESC { \
-{GNB_CONFIG_STRING_GNB_INTERFACE_NAME_FOR_NGU,           NULL,    0,            strptr:&gnb_interface_name_for_NGU,      defstrval:"lo",                TYPE_STRING,   0},        \
-{GNB_CONFIG_STRING_GNB_IPV4_ADDR_FOR_NGU,                NULL,    0,            strptr:&gnb_ipv4_address_for_NGU,        defstrval:"127.0.0.1",         TYPE_STRING,   0},        \
-{GNB_CONFIG_STRING_GNB_PORT_FOR_NGU,                     NULL,    0,            uptr:&gnb_port_for_NGU,                  defintval:2152,                TYPE_UINT,     0},        \
-{GNB_CONFIG_STRING_GNB_INTERFACE_NAME_FOR_S1U,           NULL,    0,            strptr:&gnb_interface_name_for_S1U,      defstrval:"lo",                TYPE_STRING,   0},        \
-{GNB_CONFIG_STRING_GNB_IPV4_ADDRESS_FOR_S1U,             NULL,    0,            strptr:&gnb_ipv4_address_for_S1U,        defstrval:"127.0.0.1",         TYPE_STRING,   0},        \
-{GNB_CONFIG_STRING_GNB_PORT_FOR_S1U,                     NULL,    0,            uptr:&gnb_port_for_S1U,                  defintval:2152,                TYPE_UINT,     0}         \
-}
+    {GNB_CONFIG_STRING_GNB_INTERFACE_NAME_FOR_NG_AMF,        NULL,      0,         strptr:NULL,         defstrval:NULL,       TYPE_STRING,      0}, \
+      {GNB_CONFIG_STRING_GNB_IPV4_ADDRESS_FOR_NG_AMF,          NULL,      0,         strptr:NULL,         defstrval:NULL,      TYPE_STRING,      0}, \
+      {GNB_CONFIG_STRING_GNB_INTERFACE_NAME_FOR_NGU,           NULL,      0,         strptr:NULL,         defstrval:NULL,      TYPE_STRING,      0}, \
+      {GNB_CONFIG_STRING_GNB_IPV4_ADDR_FOR_NGU,                NULL,      0,         strptr:&gnb_ipv4_address_for_NGU, defstrval:"127.0.0.1",TYPE_STRING,   0},	\
+      {GNB_CONFIG_STRING_GNB_PORT_FOR_NGU,                     NULL,      0,         uptr:&gnb_port_for_NGU,           defintval:2152L,      TYPE_UINT,     0},	\
+      {GNB_CONFIG_STRING_ENB_IPV4_ADDR_FOR_X2C,                NULL,      0,         strptr:NULL,                      defstrval:NULL,       TYPE_STRING,   0},	\
+      {GNB_CONFIG_STRING_ENB_PORT_FOR_X2C,                     NULL,      0,         uptr:NULL,                        defintval:0L,         TYPE_UINT,     0}, \
+      {GNB_CONFIG_STRING_GNB_INTERFACE_NAME_FOR_S1U,           NULL,    0,           strptr:NULL,                      defstrval:NULL,       TYPE_STRING,   0},	\
+      {GNB_CONFIG_STRING_GNB_IPV4_ADDRESS_FOR_S1U,             NULL,    0,           strptr:&gnb_ipv4_address_for_S1U, defstrval:"127.0.0.1",TYPE_STRING,   0}, \
+      {GNB_CONFIG_STRING_GNB_PORT_FOR_S1U,                     NULL,    0,           uptr:&gnb_port_for_S1U,           defintval:2152L,       TYPE_UINT,     0}	\
+  }
 /*-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
 /*-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
 
diff --git a/openair2/LAYER2/MAC/config.c b/openair2/LAYER2/MAC/config.c
index 8d4a53da6c21cad4d1e0d49ad7b2f91addde0a5f..209275acb38c69c6351fce0f87ed7fda56589662 100644
--- a/openair2/LAYER2/MAC/config.c
+++ b/openair2/LAYER2/MAC/config.c
@@ -799,7 +799,7 @@ int rrc_mac_config_req_eNB(module_id_t Mod_idP,
     RC.mac[Mod_idP]->common_channels[CC_idP].Ncp = Ncp;
     RC.mac[Mod_idP]->common_channels[CC_idP].eutra_band = eutra_band;
     RC.mac[Mod_idP]->common_channels[CC_idP].dl_CarrierFreq = dl_CarrierFreq;
-    LOG_I(MAC,
+    LOG_A(MAC,
           "Configuring MIB for instance %d, CCid %d : (band %d,N_RB_DL %d,Nid_cell %d,p %d,DL freq %u,phich_config.resource %d, phich_config.duration %d)\n",
           Mod_idP,
           CC_idP,
@@ -1067,7 +1067,7 @@ int rrc_mac_config_req_eNB(module_id_t Mod_idP,
     while(RC.mac[Mod_idP]->if_inst->PHY_config_req == NULL) {
       // DJP AssertFatal(RC.mac[Mod_idP]->if_inst->PHY_config_req != NULL,"if_inst->phy_config_request is null\n");
       usleep(100 * 1000);
-      printf("Waiting for PHY_config_req\n");
+      LOG_I(MAC, "Waiting for PHY_config_req\n");
     }
   }
 
diff --git a/openair2/LAYER2/MAC/config_ue.c b/openair2/LAYER2/MAC/config_ue.c
index f5c12e710d35103c2056206dfe28247e9d329c68..3cfc725fdb3f4d6e249740deccff972d0908bad9 100644
--- a/openair2/LAYER2/MAC/config_ue.c
+++ b/openair2/LAYER2/MAC/config_ue.c
@@ -200,7 +200,7 @@ rrc_mac_config_req_ue(module_id_t Mod_idP,
           LTE_MAC_MainConfig__ul_SCH_Config__maxHARQ_Tx_n5;
       }
 
-      if(NFAPI_MODE !=  NFAPI_UE_STUB_PNF)
+      if(NFAPI_MODE!=NFAPI_UE_STUB_PNF && NFAPI_MODE!=NFAPI_MODE_STANDALONE_PNF)
         phy_config_harq_ue(Mod_idP, 0, eNB_index, UE_mac_inst[Mod_idP].scheduling_info.maxHARQ_Tx);
 
       if (mac_MainConfig->ul_SCH_Config->retxBSR_Timer) {
@@ -308,7 +308,7 @@ rrc_mac_config_req_ue(module_id_t Mod_idP,
   }
 
   if (physicalConfigDedicated != NULL) {
-    if(NFAPI_MODE !=  NFAPI_UE_STUB_PNF)
+    if(NFAPI_MODE != NFAPI_UE_STUB_PNF && NFAPI_MODE != NFAPI_MODE_STANDALONE_PNF)
       phy_config_dedicated_ue(Mod_idP, 0, eNB_index,
                               physicalConfigDedicated);
 
diff --git a/openair2/LAYER2/MAC/eNB_scheduler.c b/openair2/LAYER2/MAC/eNB_scheduler.c
index 9d07018e2feddeea160bd9af1b94e6f20122e7e4..d647eff7cbe7800c5fe49d24cca69885a9c7314a 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler.c
@@ -313,6 +313,7 @@ schedule_SR (module_id_t module_idP,
   nfapi_ul_config_request_body_t *ul_req_body = NULL;
   LTE_SchedulingRequestConfig_t  *SRconfig = NULL;
   nfapi_ul_config_sr_information sr;
+  memset(&sr, 0, sizeof(sr));
 
   for (int CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
     eNB->UL_req[CC_id].sfn_sf = (frameP << 4) + subframeP;
@@ -573,6 +574,27 @@ eNB_dlsch_ulsch_scheduler(module_id_t module_idP,
   UE_sched_ctrl_t     *UE_scheduling_control  = NULL;
   start_meas(&(eNB->eNB_scheduler));
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ULSCH_SCHEDULER, VCD_FUNCTION_IN);
+  // TODO: Better solution needed this is the first
+  // 3 indications of this function on startup
+  // 1303275.278188 [MAC]   XXX 0.0 -> 0.4 = 4
+  // 1303275.279443 [MAC]   XXX 0.4 -> 639.5 = 6391
+  // 1303275.348686 [MAC]   XXX 646.3 -> 646.3 = 0
+  int delta = (frameP * 10 + subframeP) - (eNB->frame * 10 + eNB->subframe);
+  if (delta < 0)
+  {
+    delta += 10240; // sfn_sf decimal values range from 0 to 10239
+  }
+  // If we ever see a difference this big something is very wrong
+  // This threshold is arbitrary
+  if (delta > 8500 || delta == 0) // 850 frames
+  {
+    LOG_I(MAC, "scheduler ignoring outerspace %d.%d -> %d.%d = %d\n",
+          eNB->frame, eNB->subframe, frameP, subframeP, delta);
+    return;
+  }
+  LOG_D(MAC, "Entering dlsch_ulsch scheduler %d.%d -> %d.%d = %d\n",
+        eNB->frame, eNB->subframe, frameP, subframeP, delta);
+
   eNB->frame    = frameP;
   eNB->subframe = subframeP;
 
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_RA.c b/openair2/LAYER2/MAC/eNB_scheduler_RA.c
index 8a400af1f30a4b7576aad53ad6062c4ae013c9aa..e62978782c90f770056441b5f49d0d441c287780 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_RA.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_RA.c
@@ -918,7 +918,7 @@ generate_Msg4(module_id_t module_idP,
               module_idP, CC_idP, frameP, subframeP, UE_id, rrc_sdu_length);
         //          AssertFatal(rrc_sdu_length > 0,
         //          "[MAC][eNB Scheduler] CCCH not allocated, rrc_sdu_length: %d\n", rrc_sdu_length);
-        LOG_D(MAC,"[eNB %d][RAPROC] CC_id %d Frame %d, subframeP %d: Generating Msg4 with RRC Piggyback (RNTI %x)\n",
+        LOG_A(MAC,"[eNB %d][RAPROC] CC_id %d Frame %d, subframeP %d: Generating Msg4 with RRC Piggyback (RNTI %x)\n",
               module_idP, CC_idP, frameP, subframeP, ra->rnti);
         /// Choose first 4 RBs for Msg4, should really check that these are free!
         first_rb = 0;
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_fairRR.c b/openair2/LAYER2/MAC/eNB_scheduler_fairRR.c
index e9f0b807c4f7d44f9a0360fd4b22e6a5b924d5b0..827d95dba5843c5e3d22ce259694620a85010246 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_fairRR.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_fairRR.c
@@ -560,7 +560,7 @@ void dlsch_scheduler_pre_ue_select_fairRR(
   return;
 }
 
-void dlsch_scheduler_pre_processor_reset_fairRR(
+static void dlsch_scheduler_pre_processor_reset_fairRR(
     module_id_t module_idP,
     frame_t frameP,
     sub_frame_t subframeP,
@@ -729,7 +729,7 @@ void dlsch_scheduler_pre_processor_reset_fairRR(
 }
 
 // This function returns the estimated number of RBs required by each UE for downlink scheduling
-void assign_rbs_required_fairRR(
+static void assign_rbs_required_fairRR(
     module_id_t Mod_id,
     frame_t frameP,
     sub_frame_t subframe,
@@ -1018,8 +1018,8 @@ void dlsch_scheduler_pre_processor_fairRR (module_id_t   Mod_id,
           UE_id,
           CC_id,
           N_RBG[CC_id],
-          (uint16_t(*)[NUMBER_OF_UE_MAX])nb_rbs_required,
-          (uint16_t(*)[NUMBER_OF_UE_MAX])nb_rbs_required_remaining,
+          nb_rbs_required,
+          nb_rbs_required_remaining,
           rballoc_sub);
       temp_total_rbs_count -= ue_sched_ctl->pre_nb_available_rbs[CC_id];
       temp_total_ue_count--;
@@ -1925,7 +1925,7 @@ schedule_ue_spec_fairRR(module_id_t module_idP,
           }
 
           trace_pdu(DIRECTION_DOWNLINK, (uint8_t *)UE_info->DLSCH_pdu[CC_id][0][UE_id].payload[0],
-                    TBS, module_idP, WS_RA_RNTI, UE_RNTI(module_idP, UE_id),
+                    TBS, module_idP, WS_C_RNTI, UE_RNTI(module_idP, UE_id),
                     eNB->frame, eNB->subframe,0,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_info->DLSCH_pdu[CC_id][0][UE_id].payload[0], TBS));
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_fairRR.h b/openair2/LAYER2/MAC/eNB_scheduler_fairRR.h
index 880e60ec199d747fea8bf0203105efd31eaab63e..9c4421abd285ca76427c0718481336d20e105444 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_fairRR.h
+++ b/openair2/LAYER2/MAC/eNB_scheduler_fairRR.h
@@ -85,21 +85,6 @@ void dlsch_scheduler_pre_ue_select_fairRR(
     uint16_t        nb_rbs_required[MAX_NUM_CCs][MAX_MOBILES_PER_ENB],
     DLSCH_UE_SELECT dlsch_ue_select[MAX_NUM_CCs]);
 
-void dlsch_scheduler_pre_processor_reset_fairRR(
-    module_id_t module_idP,
-    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],
-    uint8_t rballoc_sub[NFAPI_CC_MAX][N_RBG_MAX],
-    uint8_t MIMO_mode_indicator[NFAPI_CC_MAX][N_RBG_MAX]);
-
-void assign_rbs_required_fairRR(
-    module_id_t Mod_id,
-    frame_t frameP,
-    sub_frame_t subframe,
-    uint16_t nb_rbs_required[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB]);
-
 void dlsch_scheduler_pre_processor_allocate_fairRR(
     module_id_t Mod_id,
     int UE_id,
diff --git a/openair2/LAYER2/MAC/main_ue.c b/openair2/LAYER2/MAC/main_ue.c
index 2140d66a1024e93ebeefc908c042c8371e9e6442..5ea2d26abdb063468e939fe1987806be019e0872 100644
--- a/openair2/LAYER2/MAC/main_ue.c
+++ b/openair2/LAYER2/MAC/main_ue.c
@@ -41,10 +41,12 @@
 #include "common/utils/LOG/log.h"
 #include "nfapi/oai_integration/vendor_ext.h"
 #include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"
-
-
+#include "PHY_INTERFACE/phy_stub_UE.h"
 #include "common/ran_context.h"
 #include <openair2/RRC/LTE/rrc_proto.h>
+
+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
   LOG_D(MAC, "[UE %d] Frame %d: PHY Sync to eNB_index %d successful \n",
         module_idP, frameP, eNB_index);
@@ -88,6 +90,16 @@ 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 == NFAPI_UE_STUB_PNF || NFAPI_MODE == NFAPI_MODE_STANDALONE_PNF) {
+    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,
                           HO_active);
diff --git a/openair2/LAYER2/MAC/ra_procedures.c b/openair2/LAYER2/MAC/ra_procedures.c
index 0d1afdf2a247814aed4ecac945051130544b4339..1aa959e103450f7b759585523c7959bdb933cc1f 100644
--- a/openair2/LAYER2/MAC/ra_procedures.c
+++ b/openair2/LAYER2/MAC/ra_procedures.c
@@ -287,9 +287,12 @@ PRACH_RESOURCES_t *ue_get_rach(module_id_t module_idP, int CC_id,
                                sub_frame_t subframeP) {
   uint8_t Size = 0;
   UE_MODE_t UE_mode;
-
+  protocol_ctxt_t ctxt;
+  PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, module_idP, ENB_FLAG_NO,
+                                 UE_mac_inst[module_idP].crnti, frameP,
+                                 subframeP, eNB_indexP);
   // Modification for phy_stub_ue operation
-  if(NFAPI_MODE == NFAPI_UE_STUB_PNF) { // phy_stub_ue mode
+  if(NFAPI_MODE == NFAPI_UE_STUB_PNF || NFAPI_MODE == NFAPI_MODE_STANDALONE_PNF) { // phy_stub_ue mode
     UE_mode = UE_mac_inst[module_idP].UE_mode[0];
     LOG_D(MAC, "ue_get_rach , UE_mode: %d", UE_mode);
   } else { // Full stack mode
@@ -320,6 +323,18 @@ PRACH_RESOURCES_t *ue_get_rach(module_id_t module_idP, int CC_id,
 
     if (UE_mac_inst[module_idP].RA_active == 0) {
       LOG_I(MAC, "RA not active\n");
+      if (UE_rrc_inst[module_idP].Info[eNB_indexP].T300_cnt
+          != T300[UE_rrc_inst[module_idP].sib2[eNB_indexP]->ue_TimersAndConstants.t300]) {
+            /* Calling rrc_ue_generate_RRCConnectionRequest here to ensure that
+               every time we fill the UE_mac_inst context we generate new random
+               values in msg3. When the T300 timer has expired, rrc_common.c will
+               call rrc_ue_generate_RRCConnectionRequest, so we do not want to call
+               when UE_rrc_inst[module_idP].Info[eNB_indexP].T300_cnt ==
+               T300[UE_rrc_inst[module_idP].sib2[eNB_indexP]->ue_TimersAndConstants.t300. */
+            UE_rrc_inst[module_idP].Srb0[eNB_indexP].Tx_buffer.payload_size = 0;
+            rrc_ue_generate_RRCConnectionRequest(&ctxt, eNB_indexP);
+      }
+
       // check if RRC is ready to initiate the RA procedure
       Size = mac_rrc_data_req_ue(module_idP,
                                  CC_id,
diff --git a/openair2/LAYER2/MAC/rar_tools_ue.c b/openair2/LAYER2/MAC/rar_tools_ue.c
index 611aaf865b27d1d36f21785f7dbdcfa2ef086764..9af5baec3998bedd25bc552087668fe1ff2356f8 100644
--- a/openair2/LAYER2/MAC/rar_tools_ue.c
+++ b/openair2/LAYER2/MAC/rar_tools_ue.c
@@ -67,6 +67,7 @@ uint16_t ue_process_rar(const module_id_t module_idP, const int CC_id, const fra
       LOG_D(PHY, "Found RAR with the intended RAPID %d\n",
             rarh->RAPID);
       rar = (uint8_t *) (dlsch_buffer + n_rarh + (n_rarpy - 1) * 6);
+      UE_mac_inst[module_idP].UE_mode[0] = RA_RESPONSE;
       break;
     }
 
@@ -77,9 +78,10 @@ uint16_t ue_process_rar(const module_id_t module_idP, const int CC_id, const fra
     }
 
     if (rarh->E == 0) {
-      LOG_I(PHY,
+      LOG_I(MAC,
             "No RAR found with the intended RAPID. The closest RAPID in all RARs is %d\n",
             best_rx_rapid);
+      UE_mac_inst[module_idP].UE_mode[0] = PRACH;
       break;
     } else {
       rarh++;
@@ -94,7 +96,7 @@ uint16_t ue_process_rar(const module_id_t module_idP, const int CC_id, const fra
     return (0xffff);
   }
 
-  LOG_I(MAC,
+  LOG_A(MAC,
         "[UE %d][RAPROC] Frame %d Received RAR (%02x|%02x.%02x.%02x.%02x.%02x.%02x) for preamble %d/%d\n",
         module_idP, frameP, *(uint8_t *) rarh, rar[0], rar[1], rar[2],
         rar[3], rar[4], rar[5], rarh->RAPID, preamble_index);
@@ -130,7 +132,7 @@ uint16_t ue_process_rar(const module_id_t module_idP, const int CC_id, const fra
   }
 
   // move the selected RAR to the front of the RA_PDSCH buffer
-  memcpy(selected_rar_buffer + 0, (uint8_t *) rarh, 1);
-  memcpy(selected_rar_buffer + 1, (uint8_t *) rar, 6);
+  memmove(selected_rar_buffer + 0, (uint8_t *) rarh, 1);
+  memmove(selected_rar_buffer + 1, (uint8_t *) rar, 6);
   return ret;
 }
diff --git a/openair2/LAYER2/MAC/ue_procedures.c b/openair2/LAYER2/MAC/ue_procedures.c
index 21d349ea5284c468bfb27e08f772849e53d4431d..926c44381cbefccd38c6a35a798c48d5dc8ac59b 100644
--- a/openair2/LAYER2/MAC/ue_procedures.c
+++ b/openair2/LAYER2/MAC/ue_procedures.c
@@ -149,15 +149,13 @@ void ue_init_mac(module_id_t module_idP) {
     UE_mac_inst[module_idP].scheduling_info.LCID_buffer_remain[i] = 0;
   }
 
-  if(NFAPI_MODE==NFAPI_UE_STUB_PNF) {
+  if(NFAPI_MODE==NFAPI_UE_STUB_PNF || NFAPI_MODE==NFAPI_MODE_STANDALONE_PNF) {
     pthread_mutex_init(&UE_mac_inst[module_idP].UL_INFO_mutex,NULL);
-    UE_mac_inst[module_idP].UE_mode[0] = NOT_SYNCHED; //PRACH;
+    UE_mac_inst[module_idP].UE_mode[0] = PRACH; //NOT_SYNCHED;
     UE_mac_inst[module_idP].first_ULSCH_Tx =0;
     UE_mac_inst[module_idP].SI_Decoded = 0;
     next_ra_frame = 0;
     next_Mod_id = 0;
-    tx_request_pdu_list = NULL;
-    tx_req_num_elems = 0;
   }
 }
 
@@ -411,7 +409,7 @@ ue_send_sdu(module_id_t module_idP,
 
   if (payload_ptr != NULL) {
     for (i = 0; i < num_ce; i++) {
-      //    printf("ce %d : %d\n",i,rx_ces[i]);
+      LOG_I(MAC, "ce %d : %d\n",i,rx_ces[i]);
       switch (rx_ces[i]) {
         case UE_CONT_RES:
           LOG_I(MAC,
@@ -436,7 +434,7 @@ ue_send_sdu(module_id_t module_idP,
                       "[UE %d][RAPROC] Contention detected, RA failed\n",
                       module_idP);
 
-                if(NFAPI_MODE==NFAPI_UE_STUB_PNF) { // phy_stub mode
+                if(NFAPI_MODE==NFAPI_UE_STUB_PNF || NFAPI_MODE==NFAPI_MODE_STANDALONE_PNF) { // phy_stub mode
                   //  Modification for phy_stub mode operation here. We only need to make sure that the ue_mode is back to
                   // PRACH state.
                   LOG_I(MAC, "nfapi_mode3: Setting UE_mode BACK to PRACH 1\n");
@@ -462,7 +460,7 @@ ue_send_sdu(module_id_t module_idP,
             [module_idP].
             RA_contention_resolution_timer_active = 0;
 
-            if(NFAPI_MODE==NFAPI_UE_STUB_PNF) { // phy_stub mode
+            if(NFAPI_MODE==NFAPI_UE_STUB_PNF || NFAPI_MODE==NFAPI_MODE_STANDALONE_PNF) { // phy_stub mode
               // Modification for phy_stub mode operation here. We only need to change the ue_mode to PUSCH
               UE_mac_inst[module_idP].UE_mode[eNB_index] = PUSCH;
             } else { // Full stack mode
@@ -480,7 +478,7 @@ ue_send_sdu(module_id_t module_idP,
 #endif
 
           // Eliminate call to process_timing_advance for the phy_stub UE operation mode. Is this correct?
-          if (NFAPI_MODE!=NFAPI_UE_STUB_PNF) {
+          if (NFAPI_MODE!=NFAPI_UE_STUB_PNF && NFAPI_MODE!=NFAPI_MODE_STANDALONE_PNF) {
             process_timing_advance(module_idP,CC_id,payload_ptr[0]);
           }
 
@@ -2508,6 +2506,7 @@ ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP,
               scheduling_info.BSR_bytes[UE_mac_inst[module_idP].
                                         scheduling_info.LCGID
                                         [lcid]]);
+        AssertFatal(num_sdus < sizeof(sdu_lengths) / sizeof(sdu_lengths[0]), "num_sdus %d > num sdu_length elements\n", num_sdus);
         sdu_lengths[num_sdus] = mac_rlc_data_req(module_idP,
                                 UE_mac_inst
                                 [module_idP].
@@ -2639,7 +2638,7 @@ ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP,
 
   // build PHR and update the timers
   if (phr_ce_len == sizeof(POWER_HEADROOM_CMD)) {
-    if(NFAPI_MODE==NFAPI_UE_STUB_PNF) {
+    if(NFAPI_MODE==NFAPI_UE_STUB_PNF || NFAPI_MODE==NFAPI_MODE_STANDALONE_PNF) {
       //Substitute with a static value for the MAC layer abstraction (phy_stub mode)
       phr_p->PH = 60;
     } else {
@@ -3090,7 +3089,7 @@ ue_scheduler(const module_id_t module_idP,
             "Module id %u Contention resolution timer expired, RA failed\n",
             module_idP);
 
-      if(NFAPI_MODE==NFAPI_UE_STUB_PNF) { // phy_stub mode
+      if(NFAPI_MODE==NFAPI_UE_STUB_PNF || NFAPI_MODE==NFAPI_MODE_STANDALONE_PNF) { // phy_stub mode
         // Modification for phy_stub mode operation here. We only need to make sure that the ue_mode is back to
         // PRACH state.
         LOG_I(MAC, "nfapi_mode3: Setting UE_mode to PRACH 2 \n");
diff --git a/openair2/LAYER2/NR_MAC_COMMON/nr_mac.h b/openair2/LAYER2/NR_MAC_COMMON/nr_mac.h
index 4ef0a55c6b96c0691fc754f29a9c61a11958f5f2..ba3128923fb32e86895f99fd183a7ec179db9619 100644
--- a/openair2/LAYER2/NR_MAC_COMMON/nr_mac.h
+++ b/openair2/LAYER2/NR_MAC_COMMON/nr_mac.h
@@ -264,6 +264,16 @@ typedef struct {
   uint8_t nbits;
 } dci_field_t;
 
+typedef struct {
+  bool expected_sib;
+  bool index_has_sib[16];
+  bool expected_rar;
+  bool index_has_rar[16];
+  bool expected_dci;
+  bool index_has_dci[16];
+  int active_harq_sfn_slot;
+} nr_emulated_l1_t;
+
 typedef struct {
 
   uint8_t     format_indicator; //1 bit
diff --git a/openair2/LAYER2/NR_MAC_COMMON/nr_mac_extern.h b/openair2/LAYER2/NR_MAC_COMMON/nr_mac_extern.h
index 5def748d42dc535877d22c4a055e5b521544a4ac..4b37c19dff25bdb6208aea2233338af8f61ac2fc 100644
--- a/openair2/LAYER2/NR_MAC_COMMON/nr_mac_extern.h
+++ b/openair2/LAYER2/NR_MAC_COMMON/nr_mac_extern.h
@@ -39,6 +39,8 @@
 
 extern const uint8_t nr_slots_per_frame[5];
 
+extern dci_pdu_rel15_t *def_dci_pdu_rel15;
+
 /* extern const uint32_t BSR_TABLE[BSR_TABLE_SIZE];
 extern const uint32_t Extended_BSR_TABLE[BSR_TABLE_SIZE];
 extern const uint8_t cqi2fmt0_agg[MAX_SUPPORTED_BW][CQI_VALUE_RANGE];
diff --git a/openair2/LAYER2/NR_MAC_UE/config_ue.c b/openair2/LAYER2/NR_MAC_UE/config_ue.c
index 764c92ecb74f6dde78c8837ab3e3dd7aeee27f63..b03c8fa55fa4ad56746e132e0796877892592838 100644
--- a/openair2/LAYER2/NR_MAC_UE/config_ue.c
+++ b/openair2/LAYER2/NR_MAC_UE/config_ue.c
@@ -627,7 +627,8 @@ int nr_rrc_mac_config_req_ue(
         pthread_mutex_init(&(mac->ul_config_request[i].mutex_ul_config), NULL);
       // Setup the SSB to Rach Occasions mapping according to the config
       build_ssb_to_ro_map(mac);//->scc, mac->phy_config.config_req.cell_config.frame_duplex_type);
-      mac->if_module->phy_config_request(&mac->phy_config);
+      if (!get_softmodem_params()->emulate_l1)
+        mac->if_module->phy_config_request(&mac->phy_config);
       mac->common_configuration_complete = 1;
     }
     if(scell_group_config != NULL ){
@@ -654,7 +655,16 @@ int nr_rrc_mac_config_req_ue(
     else if (cell_group_config != NULL ){
       LOG_I(MAC,"Applying CellGroupConfig from gNodeB\n");
       mac->cg = cell_group_config;
-      mac->servCellIndex = cell_group_config->spCellConfig->servCellIndex ? *cell_group_config->spCellConfig->servCellIndex : 0;
+      if (cell_group_config->spCellConfig) {
+        mac->servCellIndex = cell_group_config->spCellConfig->servCellIndex ? *cell_group_config->spCellConfig->servCellIndex : 0;
+        mac->DL_BWP_Id=mac->cg->spCellConfig->spCellConfigDedicated->firstActiveDownlinkBWP_Id ? *mac->cg->spCellConfig->spCellConfigDedicated->firstActiveDownlinkBWP_Id : 0;
+        mac->UL_BWP_Id=mac->cg->spCellConfig->spCellConfigDedicated->uplinkConfig->firstActiveUplinkBWP_Id ? *mac->cg->spCellConfig->spCellConfigDedicated->uplinkConfig->firstActiveUplinkBWP_Id : 0;
+      }
+      else {
+        mac->servCellIndex = 0;
+        mac->DL_BWP_Id = 0;
+        mac->UL_BWP_Id = 0;
+      }
 
       mac->scheduling_info.periodicBSR_SF =
         MAC_UE_BSR_TIMER_NOT_RUNNING;
@@ -667,7 +677,26 @@ int nr_rrc_mac_config_req_ue(
             mac->scheduling_info.retxBSR_SF);
 
       config_control_ue(mac);
-      //config_common_ue(mac,module_id,cc_idP);
+      if (get_softmodem_params()->nsa) {
+        if (cell_group_config->spCellConfig && cell_group_config->spCellConfig->reconfigurationWithSync) {
+          if (cell_group_config->spCellConfig->reconfigurationWithSync->rach_ConfigDedicated) {
+            ra->rach_ConfigDedicated = cell_group_config->spCellConfig->reconfigurationWithSync->rach_ConfigDedicated->choice.uplink;
+          }
+          mac->scc = cell_group_config->spCellConfig->reconfigurationWithSync->spCellConfigCommon;
+          int num_slots = mac->scc->tdd_UL_DL_ConfigurationCommon->pattern1.nrofUplinkSlots;
+          if (mac->scc->tdd_UL_DL_ConfigurationCommon->pattern1.nrofUplinkSymbols > 0) {
+            num_slots++;
+          }
+          mac->ul_config_request = calloc(num_slots, sizeof(*mac->ul_config_request));
+          config_common_ue(mac,module_id,cc_idP);
+          mac->crnti = cell_group_config->spCellConfig->reconfigurationWithSync->newUE_Identity;
+          LOG_I(MAC,"Configuring CRNTI %x\n",mac->crnti);
+        }
+
+        // Setup the SSB to Rach Occasions mapping according to the config
+        build_ssb_to_ro_map(mac);
+      }
+
       /*      
       if(mac_cell_group_configP != NULL){
 	if(mac_cell_group_configP->drx_Config != NULL ){
diff --git a/openair2/LAYER2/NR_MAC_UE/mac_defs.h b/openair2/LAYER2/NR_MAC_UE/mac_defs.h
index edfd37c3a00bc4073f6f914b1d29351dfdecb387..ad86b1385df114294fbe2f131a9a568c75f06a38 100644
--- a/openair2/LAYER2/NR_MAC_UE/mac_defs.h
+++ b/openair2/LAYER2/NR_MAC_UE/mac_defs.h
@@ -430,8 +430,14 @@ typedef struct {
 
   dci_pdu_rel15_t def_dci_pdu_rel15[8];
 
+  // Defined for abstracted mode
+  nr_downlink_indication_t dl_info;
   NR_UE_HARQ_STATUS_t dl_harq_info[16];
 
+  nr_emulated_l1_t nr_ue_emul_l1;
+
+  pthread_mutex_t mutex_dl_info;
+
 } NR_UE_MAC_INST_t;
 
 typedef enum seach_space_mask_e {
diff --git a/openair2/LAYER2/NR_MAC_UE/mac_extern.h b/openair2/LAYER2/NR_MAC_UE/mac_extern.h
index e551790f7aa1bd8e67f6bf4924fd6c5237817240..7fd63666f07957912441dc6fdf4fe85e13f51686 100644
--- a/openair2/LAYER2/NR_MAC_UE/mac_extern.h
+++ b/openair2/LAYER2/NR_MAC_UE/mac_extern.h
@@ -68,8 +68,6 @@ extern const uint16_t table_7_2_1[16];
 
 extern dci_pdu_rel15_t *def_dci_pdu_rel15;
 
-extern dci_pdu_rel15_t *def_dci_pdu_rel15;
-
 extern void mac_rlc_data_ind(const module_id_t         module_idP,
                              const rnti_t              rntiP,
                              const eNB_index_t         eNB_index,
diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c
index 2d059783fed0e56a4ebc1a807328c0ceb5a911b8..3851ee011d34e0498b126b7d2465a06172a1fe04 100644
--- a/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c
+++ b/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c
@@ -595,7 +595,9 @@ void nr_get_prach_resources(module_id_t mod_id,
       LOG_D(MAC, "In %s: selected RA preamble index %d for contention-free random access procedure for SSB with Id %d\n", __FUNCTION__, prach_resources->ra_PreambleIndex, cfra_ssb_resource_idx);
     }
   } else {
-    int16_t dl_pathloss = get_nr_PL(mod_id, CC_id, gNB_id);
+    /* TODO: This controls the tx_power of UE and the ramping procedure of RA of UE. Later we
+             can abstract this, perhaps in the proxy. But for the time being lets leave it as below. */
+    int16_t dl_pathloss = !get_softmodem_params()->emulate_l1 ? get_nr_PL(mod_id, CC_id, gNB_id) : 0;
     ssb_rach_config(ra, prach_resources, nr_rach_ConfigCommon, prach_pdu);
     ra_preambles_config(prach_resources, mac, dl_pathloss);
     LOG_D(MAC, "[RAPROC] - Selected RA preamble index %d for contention-based random access procedure... \n", prach_resources->ra_PreambleIndex);
@@ -674,7 +676,8 @@ uint8_t nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources,
 
   // Delay init RA procedure to allow the convergence of the IIR filter on PRACH noise measurements at gNB side
   if (!prach_resources->init_msg1) {
-    if ( (mac->common_configuration_complete>0 || get_softmodem_params()->do_ra==1) && ((MAX_FRAME_NUMBER+frame-prach_resources->sync_frame)%MAX_FRAME_NUMBER)>150 ){
+    if ((mac->common_configuration_complete > 0 || get_softmodem_params()->do_ra || get_softmodem_params()->nsa) &&
+       ((MAX_FRAME_NUMBER + frame - prach_resources->sync_frame) % MAX_FRAME_NUMBER) > 150) {
       prach_resources->init_msg1 = 1;
     } else {
       LOG_D(NR_MAC,"PRACH Condition not met: frame %d, prach_resources->sync_frame %d\n",frame,prach_resources->sync_frame);
@@ -738,6 +741,30 @@ uint8_t nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources,
           pdu -= sh_size;
         }
 
+      } else if (get_softmodem_params()->nsa) {
+
+        uint8_t mac_sdus[MAX_NR_ULSCH_PAYLOAD_BYTES];
+        uint16_t sdu_lengths[NB_RB_MAX] = {0};
+        int TBS_bytes = 848;
+        int mac_ce_len = 0;
+        int header_length_total=0;
+        unsigned short post_padding = 1;
+
+        // fill ulsch_buffer with random data
+        for (int i = 0; i < TBS_bytes; i++){
+          mac_sdus[i] = (unsigned char) (lrand48()&0xff);
+        }
+        //Sending SDUs with size 1
+        //Initialize elements of sdu_lengths
+        sdu_lengths[0] = TBS_bytes - 3 - post_padding - mac_ce_len;
+        header_length_total += 2 + (sdu_lengths[0] >= 128);
+        size_sdu += sdu_lengths[0];
+
+        if (size_sdu > 0) {
+          memcpy(ra->cont_res_id, mac_sdus, sizeof(uint8_t) * 6);
+          ra->Msg3_size = size_sdu + sizeof(NR_MAC_SUBHEADER_SHORT) + sizeof(NR_MAC_SUBHEADER_SHORT);
+        }
+
       } else {
 
         size_sdu = nr_write_ce_ulsch_pdu(pdu, mac, 0,  &(mac->crnti), NULL, NULL, NULL);
@@ -746,19 +773,20 @@ uint8_t nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources,
 
       }
 
-      if (size_sdu > 0 && ra->generate_nr_prach == GENERATE_PREAMBLE) {
+      if (size_sdu > 0 && (ra->generate_nr_prach == GENERATE_PREAMBLE || get_softmodem_params()->nsa)) {
 
         LOG_D(NR_MAC, "In %s: [UE %d][%d.%d]: starting initialisation Random Access Procedure...\n", __FUNCTION__, mod_id, frame, nr_slot_tx);
-        AssertFatal(TBS_max > ra->Msg3_size, "In %s: allocated resources are not enough for Msg3!\n", __FUNCTION__);
 
         // Init RA procedure
         init_RA(mod_id, prach_resources, setup, rach_ConfigGeneric, rach_ConfigDedicated);
         nr_get_RA_window(mac);
         // Fill in preamble and PRACH resources
-        nr_get_prach_resources(mod_id, CC_id, gNB_id, prach_resources, prach_pdu, rach_ConfigDedicated);
+        if (ra->generate_nr_prach == GENERATE_PREAMBLE)
+          nr_get_prach_resources(mod_id, CC_id, gNB_id, prach_resources, prach_pdu, rach_ConfigDedicated);
 
         // Padding: fill remainder with 0
         if (TBS_max - ra->Msg3_size > 0) {
+          AssertFatal(TBS_max > ra->Msg3_size, "In %s: allocated resources are not enough for Msg3!\n", __FUNCTION__);
           LOG_D(NR_MAC, "In %s: remaining %d bytes, filling with padding\n", __FUNCTION__, TBS_max - ra->Msg3_size);
           ((NR_MAC_SUBHEADER_FIXED *) pdu)->R = 0;
           ((NR_MAC_SUBHEADER_FIXED *) pdu)->LCID = UL_SCH_LCID_PADDING;
@@ -777,8 +805,10 @@ uint8_t nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources,
         // Msg3 was initialized with TBS_max bytes because the RA_Msg3_size will only be known after
         // receiving Msg2 (which contains the Msg3 resource reserve).
         // Msg3 will be transmitted with RA_Msg3_size bytes, removing unnecessary 0s.
-        mac->ulsch_pdu.Pdu_size = TBS_max;
-        memcpy(mac->ulsch_pdu.payload, payload, TBS_max);
+        if (!get_softmodem_params()->nsa) {
+          mac->ulsch_pdu.Pdu_size = TBS_max;
+          memcpy(mac->ulsch_pdu.payload, payload, TBS_max);
+        }
 
       } else {
         return 0;
@@ -936,7 +966,7 @@ void nr_ra_succeeded(module_id_t mod_id, frame_t frame, int slot){
 
   } else {
 
-    LOG_I(MAC, "[UE %d][%d.%d][RAPROC] RA procedure succeeded. CB-RA: Contention Resolution is successful.\n", mod_id, frame, slot);
+    LOG_A(MAC, "[UE %d][%d.%d][RAPROC] RA procedure succeeded. CB-RA: Contention Resolution is successful.\n", mod_id, frame, slot);
 
     ra->RA_contention_resolution_timer_active = 0;
     mac->crnti = ra->t_crnti;
diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_dci_configuration.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_dci_configuration.c
index ad82161fb977c03149842b1a28dbc7e463a56f2d..3453e071b10c897cfdb0e8fb8190081e4dbf62b9 100644
--- a/openair2/LAYER2/NR_MAC_UE/nr_ue_dci_configuration.c
+++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_dci_configuration.c
@@ -428,7 +428,8 @@ void ue_dci_configuration(NR_UE_MAC_INST_t *mac, fapi_nr_dl_config_request_t *dl
   NR_SetupRelease_PDCCH_ConfigCommon_t *pdcch_ConfigCommon = bwp_Common->pdcch_ConfigCommon;
 
   if (pdcch_ConfigCommon &&
-      pdcch_ConfigCommon->choice.setup->searchSpaceSIB1){
+      pdcch_ConfigCommon->choice.setup->searchSpaceSIB1 &&
+      !get_softmodem_params()->nsa) {
 
     NR_SearchSpace_t *ss0 = mac->search_space_zero;
     fapi_nr_dl_config_dci_dl_pdu_rel15_t *rel15 = &dl_config->dl_config_list[dl_config->number_pdus].dci_config_pdu.dci_config_rel15;
@@ -442,7 +443,7 @@ void ue_dci_configuration(NR_UE_MAC_INST_t *mac, fapi_nr_dl_config_request_t *dl
       }
     }
   }
-  else { // use coreset0/ss0
+  else if (!get_softmodem_params()->nsa) { // use coreset0/ss0
     NR_SearchSpace_t *ss0 = mac->search_space_zero;
     if(ss0) {
       fapi_nr_dl_config_dci_dl_pdu_rel15_t *rel15 = &dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15;
diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c
index 2f4ceb48ecbd59243012fd0bc79a6288c2a011b6..85bb10290a9159d1c024f9522f382badcb51e3e2 100644
--- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c
+++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c
@@ -608,7 +608,6 @@ int nr_ue_process_dci_indication_pdu(module_id_t module_id,int cc_id, int gNB_in
     def_dci_pdu_rel15 = &mac->def_dci_pdu_rel15[dci->dci_format];
   }
   int8_t ret_proc = nr_ue_process_dci(module_id, cc_id, gNB_index, frame, slot, def_dci_pdu_rel15, dci);
-  memset(def_dci_pdu_rel15, 0, sizeof(dci_pdu_rel15_t));
   return ret_proc;
 }
 
@@ -728,6 +727,7 @@ int8_t nr_ue_process_dci(module_id_t module_id, int cc_id, uint8_t gNB_index, fr
         LOG_W(MAC, "In %s: ul_config request is NULL. Probably due to unexpected UL DCI in frame.slot %d.%d. Ignoring DCI!\n", __FUNCTION__, frame, slot);
         return -1;
       }
+      ul_config->number_pdus = 0;
 
       pthread_mutex_lock(&ul_config->mutex_ul_config);
       AssertFatal(ul_config->number_pdus<FAPI_NR_UL_CONFIG_LIST_NUM, "ul_config->number_pdus %d out of bounds\n",ul_config->number_pdus);
@@ -868,7 +868,7 @@ int8_t nr_ue_process_dci(module_id_t module_id, int cc_id, uint8_t gNB_index, fr
 
     /* dmrs symbol positions*/
     dlsch_config_pdu_1_0->dlDmrsSymbPos = fill_dmrs_mask(pdsch_config,
-                                                         mac->mib->dmrs_TypeA_Position,
+                                                         (get_softmodem_params()->nsa) ? mac->scc->dmrs_TypeA_Position : mac->mib->dmrs_TypeA_Position,
                                                          dlsch_config_pdu_1_0->number_symbols,
                                                          dlsch_config_pdu_1_0->start_symbol,
                                                          mappingtype);
@@ -1255,6 +1255,7 @@ int8_t nr_ue_process_dci(module_id_t module_id, int cc_id, uint8_t gNB_index, fr
     /* TODO same calculation for MCS table as done in UL */
     dlsch_config_pdu_1_1->mcs_table = (pdsch_Config->mcs_Table) ? (*pdsch_Config->mcs_Table + 1) : 0;
     /*PTRS configuration */
+    dlsch_config_pdu_1_1->pduBitmap = 0;
     if(pdsch_Config->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup->phaseTrackingRS != NULL) {
       valid_ptrs_setup = set_dl_ptrs_values(pdsch_Config->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup->phaseTrackingRS->choice.setup,
                                             dlsch_config_pdu_1_1->number_rbs, dlsch_config_pdu_1_1->mcs, dlsch_config_pdu_1_1->mcs_table,
@@ -1333,8 +1334,10 @@ void set_harq_status(NR_UE_MAC_INST_t *mac,
   // FIXME k0 != 0 currently not taken into consideration
   current_harq->dl_frame = frame;
   current_harq->dl_slot = slot;
+  mac->nr_ue_emul_l1.active_harq_sfn_slot = NFAPI_SFNSLOT2HEX(frame, (slot + data_toul_fb));
 
-  LOG_D(PHY,"Setting harq_status for harq_id %d, dl %d.%d\n",harq_id,frame,slot);
+  LOG_D(NR_PHY,"Setting harq_status for harq_id %d, dl %d.%d, sched ul %d.%d\n",
+        harq_id, frame, slot, frame, (slot + data_toul_fb));
 }
 
 
@@ -2837,7 +2840,7 @@ uint8_t nr_extract_dci_info(NR_UE_MAC_INST_t *mac,
       // check BWP id
       if (mac->DLbwp[0]) N_RB=NRRIV2BW(mac->DLbwp[0]->bwp_Common->genericParameters.locationAndBandwidth, MAX_BWP_SIZE);
       else         N_RB=mac->type0_PDCCH_CSS_config.num_rbs;
-;
+
 
       // indicating a DL DCI format 1bit
       pos++;
@@ -3331,6 +3334,9 @@ void nr_ue_process_mac_pdu(nr_downlink_indication_t *dl_info,
           mac_subheader_len = 2;
         }
 
+        AssertFatal(pdu_len > mac_sdu_len, "The mac_sdu_len (%d) has an invalid size. PDU len = %d! \n",
+                    mac_sdu_len, pdu_len);
+
         // Check if it is a valid CCCH message, we get all 00's messages very often
         int i = 0;
         for(i=0; i<(mac_subheader_len+mac_sdu_len); i++) {
@@ -3496,47 +3502,56 @@ void nr_ue_process_mac_pdu(nr_downlink_indication_t *dl_info,
       case DL_SCH_LCID_DCCH1:
         //  check if LCID is valid at current time.
       default:
-        //  check if LCID is valid at current time.
-        if(((NR_MAC_SUBHEADER_SHORT *)pduP)->F){
-          //mac_sdu_len |= (uint16_t)(((NR_MAC_SUBHEADER_LONG *)pduP)->L2)<<8;
-          mac_subheader_len = 3;
-          mac_sdu_len = ((uint16_t)(((NR_MAC_SUBHEADER_LONG *) pduP)->L1 & 0x7f) << 8)
-                        | ((uint16_t)((NR_MAC_SUBHEADER_LONG *) pduP)->L2 & 0xff);
-
-        } else {
-          mac_sdu_len = (uint16_t)((NR_MAC_SUBHEADER_SHORT *)pduP)->L;
-          mac_subheader_len = 2;
-        }
+            {
+                //  check if LCID is valid at current time.
+                if (pdu_len < sizeof(NR_MAC_SUBHEADER_SHORT))
+                  return;
+                NR_MAC_SUBHEADER_SHORT *shs = (NR_MAC_SUBHEADER_SHORT *)pduP;
+                if (shs->F) {
+                    //mac_sdu_len |= (uint16_t)(((NR_MAC_SUBHEADER_LONG *)pduP)->L2)<<8;
+                    mac_subheader_len = 3;
+                    if (pdu_len < sizeof(NR_MAC_SUBHEADER_LONG))
+                      return;
+                    NR_MAC_SUBHEADER_LONG *shl = (NR_MAC_SUBHEADER_LONG *)pduP;
+                    mac_sdu_len = ((uint16_t)(shl->L1 & 0x7f) << 8) | (uint16_t)(shl->L2 & 0xff);
+                } else {
+                  if (pdu_len < sizeof(NR_MAC_SUBHEADER_SHORT))
+                    return;
+                  mac_sdu_len = (uint16_t)((NR_MAC_SUBHEADER_SHORT *)pduP)->L;
+                  mac_subheader_len = 2;
+                }
+
+                LOG_D(NR_MAC, "[UE %d] Frame %d : DLSCH -> DL-DTCH %d (gNB %d, %d bytes)\n", module_idP, frameP, rx_lcid, gNB_index, mac_sdu_len);
+
+                #if defined(ENABLE_MAC_PAYLOAD_DEBUG)
+                    LOG_T(MAC, "[UE %d] First 32 bytes of DLSCH : \n", module_idP);
+
+                    for (i = 0; i < 32; i++)
+                      LOG_T(MAC, "%x.", (pduP + mac_subheader_len)[i]);
+
+                    LOG_T(MAC, "\n");
+                #endif
+
+                if (rx_lcid < NB_RB_MAX && rx_lcid >= DL_SCH_LCID_DCCH) {
+
+                mac_rlc_data_ind(module_idP,
+                                mac->crnti,
+                                gNB_index,
+                                frameP,
+                                ENB_FLAG_NO,
+                                MBMS_FLAG_NO,
+                                rx_lcid,
+                                (char *) (pduP + mac_subheader_len),
+                                mac_sdu_len,
+                                1,
+                                NULL);
+                } else {
+                  LOG_E(MAC, "[UE %d] Frame %d : unknown LCID %d (gNB %d)\n", module_idP, frameP, rx_lcid, gNB_index);
+                }
 
-        LOG_D(MAC, "[UE %d] Frame %d : DLSCH -> DL-DTCH %d (gNB %d, %d bytes)\n", module_idP, frameP, rx_lcid, gNB_index, mac_sdu_len);
 
-        #if defined(ENABLE_MAC_PAYLOAD_DEBUG)
-          LOG_T(MAC, "[UE %d] First 32 bytes of DLSCH : \n", module_idP);
-
-          for (i = 0; i < 32; i++)
-            LOG_T(MAC, "%x.", (pduP + mac_subheader_len)[i]);
-
-          LOG_T(MAC, "\n");
-        #endif
-
-        if (rx_lcid < NB_RB_MAX && rx_lcid >= DL_SCH_LCID_DCCH) {
-
-          mac_rlc_data_ind(module_idP,
-                           mac->crnti,
-                           gNB_index,
-                           frameP,
-                           ENB_FLAG_NO,
-                           MBMS_FLAG_NO,
-                           rx_lcid,
-                           (char *) (pduP + mac_subheader_len),
-                           mac_sdu_len,
-                           1,
-                           NULL);
-        } else {
-          LOG_E(MAC, "[UE %d] Frame %d : unknown LCID %d (gNB %d)\n", module_idP, frameP, rx_lcid, gNB_index);
-        }
-
-        break;
+            break;
+            }
       }
       pduP += ( mac_subheader_len + mac_ce_len + mac_sdu_len );
       pdu_len -= ( mac_subheader_len + mac_ce_len + mac_sdu_len );
@@ -3791,7 +3806,7 @@ int nr_ue_process_rar(nr_downlink_indication_t *dl_info, NR_UL_TIME_ALIGNMENT_t
       }
     }
     if (rarh->RAPID == preamble_index) {
-      LOG_I(NR_MAC, "[UE %d][RAPROC][%d.%d] Found RAR with the intended RAPID %d\n", mod_id, frame, slot, rarh->RAPID);
+      LOG_A(NR_MAC, "[UE %d][RAPROC][%d.%d] Found RAR with the intended RAPID %d\n", mod_id, frame, slot, rarh->RAPID);
       rar = (NR_MAC_RAR *) (dlsch_buffer + n_subheaders + (n_subPDUs - 1) * sizeof(NR_MAC_RAR));
       ra->RA_RAPID_found = 1;
       break;
@@ -3908,6 +3923,8 @@ int nr_ue_process_rar(nr_downlink_indication_t *dl_info, NR_UL_TIME_ALIGNMENT_t
         LOG_W(MAC, "In %s: ul_config request is NULL. Probably due to unexpected UL DCI in frame.slot %d.%d. Ignoring DCI!\n", __FUNCTION__, frame, slot);
         return -1;
       }
+      AssertFatal(ul_config->number_pdus < sizeof(ul_config->ul_config_list) / sizeof(ul_config->ul_config_list[0]),
+                  "Number of PDUS in ul_config = %d > ul_config_list num elements", ul_config->number_pdus);
 
       // Upon successful reception, set the T-CRNTI to the RAR value if the RA preamble is selected among the contention-based RA Preambles
       if (!ra->cfra) {
diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c
index 3d45877979b9f24a84ceba69b2bb688d2e14d18a..5284f7fc53c9db5cf3bde91a523c5a6404f9b342 100644
--- a/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c
+++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c
@@ -51,6 +51,7 @@
 #include "assertions.h"
 #include "asn1_conversions.h"
 #include "SIMULATION/TOOLS/sim.h" // for taus
+#include "utils.h"
 
 #include <executables/softmodem-common.h>
 
@@ -60,8 +61,13 @@ static prach_association_pattern_t prach_assoc_pattern;
 static ssb_list_info_t ssb_list;
 
 void fill_ul_config(fapi_nr_ul_config_request_t *ul_config, frame_t frame_tx, int slot_tx, uint8_t pdu_type){
+
+  AssertFatal(ul_config->number_pdus < sizeof(ul_config->ul_config_list) / sizeof(ul_config->ul_config_list[0]),
+              "Number of PDUS in ul_config = %d > ul_config_list num elements", ul_config->number_pdus);
   // clear ul_config for new frame/slot
-  if ((ul_config->slot != slot_tx || ul_config->sfn != frame_tx) && ul_config->number_pdus != 0) {
+  if ((ul_config->slot != slot_tx || ul_config->sfn != frame_tx) &&
+      ul_config->number_pdus != 0 &&
+      !get_softmodem_params()->emulate_l1) {
     LOG_D(MAC, "%d.%d %d.%d f clear ul_config %p t %d pdu %d\n", frame_tx, slot_tx, ul_config->sfn, ul_config->slot, ul_config, pdu_type, ul_config->number_pdus);
     ul_config->number_pdus = 0;
     memset(ul_config->ul_config_list, 0, sizeof(ul_config->ul_config_list)); 
@@ -166,6 +172,8 @@ fapi_nr_ul_config_request_t *get_ul_config_request(NR_UE_MAC_INST_t *mac, int sl
                 num_slots_ul,
                 index);
 
+  if(!mac->ul_config_request)
+    return NULL;
   return &mac->ul_config_request[index];
 }
 
@@ -912,6 +920,7 @@ NR_UE_L2_STATE_t nr_ue_scheduler(nr_downlink_indication_t *dl_info, nr_uplink_in
       dcireq.slot      = rx_slot;
       dcireq.dl_config_req.number_pdus = 0;
       nr_ue_dcireq(&dcireq); //to be replaced with function pointer later
+      mac->dl_config_request = dcireq.dl_config_req;
 
       fill_scheduled_response(&scheduled_response, &dcireq.dl_config_req, NULL, NULL, mod_id, cc_id, rx_frame, rx_slot, dl_info->thread_id);
       if(mac->if_module != NULL && mac->if_module->scheduled_response != NULL)
@@ -948,7 +957,9 @@ NR_UE_L2_STATE_t nr_ue_scheduler(nr_downlink_indication_t *dl_info, nr_uplink_in
     RA_config_t *ra       = &mac->ra;
 
     fapi_nr_ul_config_request_t *ul_config = get_ul_config_request(mac, slot_tx);
-
+    if (!ul_config) {
+      LOG_E(NR_MAC, "mac->ul_config is null!\n");
+    }
     // Schedule ULSCH only if the current frame and slot match those in ul_config_req
     // AND if a UL grant (UL DCI or Msg3) has been received (as indicated by num_pdus)
     if (ul_config){
@@ -1019,7 +1030,7 @@ NR_UE_L2_STATE_t nr_ue_scheduler(nr_downlink_indication_t *dl_info, nr_uplink_in
               nr_Msg3_transmitted(ul_info->module_id, ul_info->cc_id, ul_info->frame_tx, ul_info->slot_tx, ul_info->gNB_index);
             }
             if (ra->ra_state == WAIT_RAR && !ra->cfra){
-              LOG_I(NR_MAC,"[RAPROC][%d.%d] RA-Msg3 transmitted\n", frame_tx, slot_tx);
+              LOG_A(NR_MAC, "[RAPROC][%d.%d] RA-Msg3 transmitted\n", frame_tx, slot_tx);
               nr_Msg3_transmitted(ul_info->module_id, ul_info->cc_id, ul_info->frame_tx, ul_info->slot_tx, ul_info->gNB_index);
             }
           }
@@ -2197,9 +2208,12 @@ void nr_ue_prach_scheduler(module_id_t module_idP, frame_t frameP, sub_frame_t s
 
   NR_UE_MAC_INST_t *mac = get_mac_inst(module_idP);
   RA_config_t *ra = &mac->ra;
+  fapi_nr_ul_config_request_t *ul_config = get_ul_config_request(mac, slotP);
+  if (!ul_config) {
+    LOG_E(NR_MAC, "mac->ul_config is null! \n");
+    return;
+  }
 
-  //fapi_nr_ul_config_request_t *ul_config = get_ul_config_request(mac, slotP);
-  fapi_nr_ul_config_request_t *ul_config = &mac->ul_config_request[0];
   fapi_nr_ul_config_prach_pdu *prach_config_pdu;
   fapi_nr_config_request_t *cfg = &mac->phy_config.config_req;
   fapi_nr_prach_config_t *prach_config = &cfg->prach_config;
@@ -2236,11 +2250,13 @@ void nr_ue_prach_scheduler(module_id_t module_idP, frame_t frameP, sub_frame_t s
       format = prach_occasion_info_p->format;
       format0 = format & 0xff;        // single PRACH format
       format1 = (format >> 8) & 0xff; // dual PRACH format
+      AssertFatal(ul_config->number_pdus < sizeof(ul_config->ul_config_list) / sizeof(ul_config->ul_config_list[0]),
+                  "Number of PDUS in ul_config = %d > ul_config_list num elements", ul_config->number_pdus);
 
       pthread_mutex_lock(&ul_config->mutex_ul_config);
       AssertFatal(ul_config->number_pdus<FAPI_NR_UL_CONFIG_LIST_NUM, "ul_config->number_pdus %d out of bounds\n",ul_config->number_pdus);
       prach_config_pdu = &ul_config->ul_config_list[ul_config->number_pdus].prach_config_pdu;
-
+      memset(prach_config_pdu, 0, sizeof(fapi_nr_ul_config_prach_pdu));
       fill_ul_config(ul_config, frameP, slotP, FAPI_NR_UL_CONFIG_TYPE_PRACH);
       pthread_mutex_unlock(&ul_config->mutex_ul_config);
       LOG_D(PHY, "In %s: (%p) %d UL PDUs:\n", __FUNCTION__, ul_config, ul_config->number_pdus);
diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c
index 2705b85b8c7c5a29ba3ac632647bde76d74cda75..4172374ee8e37d715fc9e61b270c876457b66004 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c
@@ -519,10 +519,16 @@ void nr_initiate_ra_proc(module_id_t module_idP,
   for (int i = 0; i < NR_NB_RA_PROC_MAX; i++) {
     NR_RA_t *ra = &cc->ra[i];
     pr_found = 0;
+    const int UE_id = find_nr_UE_id(module_idP, ra->rnti);
+    if (UE_id != -1) {
+      continue;
+    }
     if (ra->state == RA_IDLE) {
       for(int j = 0; j < ra->preambles.num_preambles; j++) {
         //check if the preamble received correspond to one of the listed or configured preambles
         if (preamble_index == ra->preambles.preamble_list[j]) {
+          if (ra->rnti == 0 && get_softmodem_params()->nsa)
+            continue;
           pr_found=1;
           break;
         }
@@ -636,16 +642,17 @@ void nr_initiate_ra_proc(module_id_t module_idP,
       ra->preamble_index = preamble_index;
       ra->beam_id = beam_index;
 
-      LOG_D(NR_MAC,
+      LOG_I(NR_MAC,
             "[gNB %d][RAPROC] CC_id %d Frame %d Activating Msg2 generation in frame %d, slot %d using RA rnti %x SSB "
-            "index %u\n",
+            "index %u RA index %d\n",
             module_idP,
             CC_id,
             frameP,
             ra->Msg2_frame,
             ra->Msg2_slot,
             ra->RA_rnti,
-            cc->ssb_index[beam_index]);
+            cc->ssb_index[beam_index],
+            i);
 
       return;
     }
@@ -1229,7 +1236,7 @@ void nr_generate_Msg2(module_id_t module_idP, int CC_id, frame_t frameP, sub_fra
     dl_req->nPDUs+=1;
     nfapi_nr_dl_tti_pdsch_pdu_rel15_t *pdsch_pdu_rel15 = &dl_tti_pdsch_pdu->pdsch_pdu.pdsch_pdu_rel15;
 
-    LOG_I(NR_MAC,"[gNB %d][RAPROC] CC_id %d Frame %d, slotP %d: Generating RA-Msg2 DCI, rnti 0x%04x, state %d, CoreSetType %d\n",
+    LOG_A(NR_MAC,"[gNB %d][RAPROC] CC_id %d Frame %d, slotP %d: Generating RA-Msg2 DCI, rnti 0x%x, state %d, CoreSetType %d\n",
           module_idP, CC_id, frameP, slotP, ra->RA_rnti, ra->state,pdcch_pdu_rel15->CoreSetType);
 
     // SCF222: PDU index incremented for each PDSCH PDU sent in TX control message. This is used to associate control
@@ -1624,7 +1631,7 @@ void nr_generate_Msg4(module_id_t module_idP, int CC_id, frame_t frameP, sub_fra
     dl_req->nPDUs+=1;
     nfapi_nr_dl_tti_pdsch_pdu_rel15_t *pdsch_pdu_rel15 = &dl_tti_pdsch_pdu->pdsch_pdu.pdsch_pdu_rel15;
 
-    LOG_I(NR_MAC,"[gNB %d] [RAPROC] CC_id %d Frame %d, slotP %d: Generating RA-Msg4 DCI, state %d\n", module_idP, CC_id, frameP, slotP, ra->state);
+    LOG_A(NR_MAC, "[gNB %d] [RAPROC] CC_id %d Frame %d, slotP %d: Generating RA-Msg4 DCI, state %d\n", module_idP, CC_id, frameP, slotP, ra->state);
 
     // SCF222: PDU index incremented for each PDSCH PDU sent in TX control message. This is used to associate control
     // information to data and is reset every slot.
@@ -1809,7 +1816,7 @@ void nr_check_Msg4_Ack(module_id_t module_id, int CC_id, frame_t frame, sub_fram
   if (harq->is_waiting == 0) {
     if (harq->round == 0) {
       if (stats->dlsch_errors == 0) {
-        LOG_I(NR_MAC, "(ue %i, rnti 0x%04x) Received Ack of RA-Msg4. CBRA procedure succeeded!\n", UE_id, ra->rnti);
+        LOG_A(NR_MAC, "(ue %i, rnti 0x%04x) Received Ack of RA-Msg4. CBRA procedure succeeded!\n", UE_id, ra->rnti);
         UE_info->active[UE_id] = true;
         UE_info->Msg4_ACKed[UE_id] = true;
       }
diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c
index f9209f4cfe45a88df936abc696045dff1f10426b..ea298494c438e73c05deb9332c2294df49a04c2e 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c
@@ -741,6 +741,11 @@ void pf_dl(module_id_t module_id,
     const uint16_t bwpSize = NRRIV2BW(genericParameters->locationAndBandwidth,MAX_BWP_SIZE);
     int rbStart = 0; // start wrt BWPstart
 
+    if (sched_ctrl->available_dl_harq.head < 0) {
+      LOG_D(MAC, "UE %d RNTI %04x has no free HARQ process, skipping\n", UE_id, UE_info->rnti[UE_id]);
+      continue;
+    }
+
     /* Find a free CCE */
     bool freeCCE = find_free_CCE(module_id, slot, UE_id);
     if (!freeCCE) {
@@ -851,7 +856,7 @@ void nr_fr1_dlsch_preprocessor(module_id_t module_id, frame_t frame, sub_frame_t
         frame,
         slot,
         &UE_info->list,
-        2,
+        MAX_MOBILES_PER_GNB,
         n_rb_sched,
         rballoc_mask);
 }
@@ -997,6 +1002,7 @@ void nr_schedule_ue_spec(module_id_t module_id,
     const int coresetid = (bwp||bwpd) ? sched_ctrl->coreset->controlResourceSetId : gNB_mac->sched_ctrlCommon->coreset->controlResourceSetId;
     nfapi_nr_dl_tti_pdcch_pdu_rel15_t *pdcch_pdu = gNB_mac->pdcch_pdu_idx[CC_id][bwpid][coresetid];
     if (!pdcch_pdu) {
+      LOG_D(NR_MAC, "creating pdcch pdu, pdcch_pdu = NULL. \n");
       nfapi_nr_dl_tti_request_pdu_t *dl_tti_pdcch_pdu = &dl_req->dl_tti_pdu_list[dl_req->nPDUs];
       memset(dl_tti_pdcch_pdu, 0, sizeof(nfapi_nr_dl_tti_request_pdu_t));
       dl_tti_pdcch_pdu->PDUType = NFAPI_NR_DL_TTI_PDCCH_PDU_TYPE;
diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_uci.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_uci.c
index a94559769deae9ddfcda5b94240c934fdc9dc3d8..ca641ed1baae62a365717ec2a73fdc56cd6249c0 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_uci.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_uci.c
@@ -292,7 +292,7 @@ uint8_t compute_ri_bitlen(struct NR_CSI_ReportConfig *csi_reportconfig,
     }
     return max_ri;
   }
-  else
+  else 
     AssertFatal(1==0,"Other configurations not yet implemented\n");
   return -1;
 }
@@ -563,6 +563,7 @@ void nr_csi_meas_reporting(int Mod_idP,
   }
 }
 
+__attribute__((unused))
 static void handle_dl_harq(module_id_t mod_id,
                            int UE_id,
                            int8_t harq_pid,
@@ -1094,8 +1095,10 @@ void handle_nr_uci_pucch_0_1(module_id_t mod_id,
       const uint8_t harq_value = uci_01->harq->harq_list[harq_bit].harq_value;
       const uint8_t harq_confidence = uci_01->harq->harq_confidence_level;
       NR_UE_harq_t *harq = find_harq(mod_id, frame, slot, UE_id);
-      if (!harq)
+      if (!harq) {
+        LOG_E(NR_MAC, "Oh no! Could not find a harq in %s!\n", __FUNCTION__);
         break;
+      }
       DevAssert(harq->is_waiting);
       const int8_t pid = sched_ctrl->feedback_dl_harq.head;
       remove_front_nr_list(&sched_ctrl->feedback_dl_harq);
@@ -1416,6 +1419,7 @@ int nr_acknack_scheduling(int mod_id,
   /* verify that at that slot and symbol, resources are free. We only do this
    * for initialCyclicShift 0 (we assume it always has that one), so other
    * initialCyclicShifts can overlap with ICS 0!*/
+
   if (pucch_Config) {
     const NR_PUCCH_Resource_t *resource = pucch_Config->resourceToAddModList->list.array[pucch->resource_indicator];
     DevAssert(resource->format.present == NR_PUCCH_Resource__format_PR_format0);
@@ -1464,8 +1468,11 @@ void nr_sr_reporting(int Mod_idP, frame_t SFN, sub_frame_t slot)
              RC.nrmac[Mod_idP]->UE_info.CellGroup[UE_id]->spCellConfig->spCellConfigDedicated->uplinkConfig->initialUplinkBWP->pucch_Config->choice.setup) {
       pucch_Config = RC.nrmac[Mod_idP]->UE_info.CellGroup[UE_id]->spCellConfig->spCellConfigDedicated->uplinkConfig->initialUplinkBWP->pucch_Config->choice.setup;
     }
+
     else continue;
-    if (!pucch_Config->schedulingRequestResourceToAddModList) continue;
+    if (!pucch_Config->schedulingRequestResourceToAddModList) 
+        continue;
+
     AssertFatal(pucch_Config->schedulingRequestResourceToAddModList->list.count>0,"NO SR configuration available");
 
     for (int SR_resource_id =0; SR_resource_id < pucch_Config->schedulingRequestResourceToAddModList->list.count;SR_resource_id++) {
diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c
index c68b16b5538451ff69d83f321ab22f7ddfd69592..bde6c6109d5d33cbef4107320ba5805398f17aa0 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c
@@ -32,6 +32,7 @@
 #include "LAYER2/NR_MAC_gNB/mac_proto.h"
 #include "executables/softmodem-common.h"
 #include "common/utils/nr/nr_common.h"
+#include "utils.h"
 #include <openair2/UTIL/OPT/opt.h>
 
 #include "LAYER2/NR_MAC_COMMON/nr_mac_extern.h"
@@ -565,6 +566,7 @@ void handle_nr_ul_harq(const int CC_idP,
   NR_UE_info_t *UE_info = &RC.nrmac[mod_id]->UE_info;
   NR_UE_sched_ctrl_t *sched_ctrl = &UE_info->UE_sched_ctrl[UE_id];
   int8_t harq_pid = sched_ctrl->feedback_ul_harq.head;
+  LOG_D(NR_MAC, "Comparing crc_pdu->harq_id vs feedback harq_pid = %d %d\n",crc_pdu->harq_id, harq_pid);
   while (crc_pdu->harq_id != harq_pid || harq_pid < 0) {
     LOG_W(NR_MAC,
           "Unexpected ULSCH HARQ PID %d (have %d) for RNTI 0x%04x (ignore this warning for RA)\n",
@@ -800,14 +802,14 @@ void nr_rx_sdu(const module_id_t gnb_mod_idP,
       LOG_D(NR_MAC, "[UE %d] PUSCH TPC %d and TA %d\n",UE_id,UE_scheduling_control->tpc0,UE_scheduling_control->ta_update);
         if(ra->cfra) {
 
-          LOG_I(NR_MAC, "(ue %i, rnti 0x%04x) CFRA procedure succeeded!\n", UE_id, ra->rnti);
+          LOG_A(NR_MAC, "(ue %i, rnti 0x%04x) CFRA procedure succeeded!\n", UE_id, ra->rnti);
           nr_mac_remove_ra_rnti(gnb_mod_idP, ra->rnti);
           nr_clear_ra_proc(gnb_mod_idP, CC_idP, frameP, ra);
           UE_info->active[UE_id] = true;
 
         } else {
 
-          LOG_I(NR_MAC,"[RAPROC] RA-Msg3 received (sdu_lenP %d)\n",sdu_lenP);
+          LOG_A(NR_MAC,"[RAPROC] RA-Msg3 received (sdu_lenP %d)\n",sdu_lenP);
           LOG_D(NR_MAC,"[RAPROC] Received Msg3:\n");
           for (int k = 0; k < sdu_lenP; k++) {
             LOG_D(NR_MAC,"(%i): 0x%x\n",k,sduP[k]);
@@ -1491,6 +1493,7 @@ void nr_schedule_ulsch(module_id_t module_id, frame_t frame, sub_frame_t slot)
     NR_pusch_semi_static_t *ps = &sched_ctrl->pusch_semi_static;
 
     /* Statistics */
+    AssertFatal(cur_harq->round < 8, "Indexing ulsch_rounds[%d] is out of bounds\n", cur_harq->round);
     UE_info->mac_stats[UE_id].ulsch_rounds[cur_harq->round]++;
     if (cur_harq->round == 0) {
       UE_info->mac_stats[UE_id].ulsch_total_bytes_scheduled += sched_pusch->tb_size;
@@ -1624,6 +1627,7 @@ void nr_schedule_ulsch(module_id_t module_id, frame_t frame, sub_frame_t slot)
     pusch_pdu->nr_of_symbols = ps->nrOfSymbols;
 
     /* PUSCH PDU */
+    AssertFatal(cur_harq->round < 4, "Indexing nr_rv_round_map[%d] is out of bounds\n", cur_harq->round);
     pusch_pdu->pusch_data.rv_index = nr_rv_round_map[cur_harq->round];
     pusch_pdu->pusch_data.harq_process_id = harq_id;
     pusch_pdu->pusch_data.new_data_indicator = cur_harq->ndi;
diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp.c
index cddb666bfdbd346cf2dc7ae4cd7837bc50d850bf..4d2e157728bb9595929924a819332f70bc038e8b 100644
--- a/openair2/LAYER2/PDCP_v10.1.0/pdcp.c
+++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp.c
@@ -140,6 +140,36 @@ extern volatile int oai_exit;
 
 pthread_t pdcp_stats_thread_desc;
 
+// will be called when 4G F1 implementation will use GTP-U instead of protobuf
+boolean_t cu_f1u_data_req(
+  protocol_ctxt_t  *ctxt_pP,
+  const srb_flag_t srb_flagP,
+  const rb_id_t rb_id,
+  const mui_t muiP,
+  const confirm_t confirmP,
+  const sdu_size_t sdu_buffer_size,
+  unsigned char *const sdu_buffer,
+  const pdcp_transmission_mode_t mode,
+  const uint32_t *const sourceL2Id,
+  const uint32_t *const destinationL2Id
+  ) {
+  mem_block_t *memblock = get_free_mem_block(sdu_buffer_size, __func__);
+  if (memblock == NULL) {
+    LOG_E(RLC, "%s:%d:%s: ERROR: get_free_mem_block failed\n", __FILE__, __LINE__, __FUNCTION__);
+    exit(1);
+  }
+  memcpy(memblock->data,sdu_buffer, sdu_buffer_size);
+  // weird rb id management in 4G, not fully understand (looks bad design)
+  // overcomplex: if i understand, on the interface DRB start at 4 because there can be SRB 0..3
+  // but it would be much simpler to use absolute numbering
+  // instead of this "srb flag" associated to these +/-4
+  int ret=pdcp_data_ind(ctxt_pP,srb_flagP, false, rb_id-4, sdu_buffer_size, memblock, NULL, NULL);
+  if (!ret) {
+    LOG_E(RLC, "%s:%d:%s: ERROR: pdcp_data_ind failed\n", __FILE__, __LINE__, __FUNCTION__);
+    /* what to do in case of failure? for the moment: nothing */
+  }
+  return ret;
+}
 void *pdcp_stats_thread(void *param) {
 
    FILE *fd;
@@ -176,6 +206,33 @@ void *pdcp_stats_thread(void *param) {
 uint64_t get_pdcp_optmask(void) {
   return pdcp_params.optmask;
 }
+
+rlc_op_status_t cu_send_to_du(const protocol_ctxt_t *const ctxt,
+			       const srb_flag_t srb_flag, const MBMS_flag_t MBMS_flag,
+			       const rb_id_t rb_id, const mui_t mui,
+			       confirm_t confirm, sdu_size_t size, mem_block_t *sdu,
+                               const uint32_t *const sourceID, const uint32_t *const destID) {
+  uint8_t *gtpu_buffer_p = itti_malloc(TASK_PDCP_ENB, TASK_GTPV1_U,
+				       size  + GTPU_HEADER_OVERHEAD_MAX);
+  AssertFatal(gtpu_buffer_p != NULL, "OUT OF MEMORY");
+  memcpy(gtpu_buffer_p+GTPU_HEADER_OVERHEAD_MAX,
+	 sdu->data,
+	 size );
+  MessageDef  *message_p = itti_alloc_new_message(TASK_PDCP_ENB, 0, GTPV1U_ENB_TUNNEL_DATA_REQ);
+  AssertFatal(message_p != NULL, "OUT OF MEMORY");
+  gtpv1u_enb_tunnel_data_req_t *req=&GTPV1U_ENB_TUNNEL_DATA_REQ(message_p);
+  req->buffer        = gtpu_buffer_p;
+  req->length        = size;
+  req->offset        = GTPU_HEADER_OVERHEAD_MAX;
+  req->rnti          = ctxt->rnti;
+  req->rab_id = rb_id+4;
+  LOG_D(PDCP, "%s() (drb %ld) sending message to gtp size %d\n",
+	__func__, rb_id, size);
+  extern instance_t CUuniqInstance;
+  itti_send_msg_to_task(TASK_VARIABLE, CUuniqInstance, message_p);
+  return TRUE;
+}
+
 //-----------------------------------------------------------------------------
 /*
  * If PDCP_UNIT_TEST is set here then data flow between PDCP and RLC is broken
@@ -249,12 +306,8 @@ boolean_t pdcp_data_req(
       LOG_W(PDCP, PROTOCOL_CTXT_FMT" Instance is not configured for rb_id %ld Ignoring SDU...\n",
             PROTOCOL_CTXT_ARGS(ctxt_pP),
             rb_idP);
-      ctxt_pP->configured=FALSE;
       return FALSE;
     }
-  } else {
-    // instance for a given RB is configured
-    ctxt_pP->configured=TRUE;
   }
 
   if (ctxt_pP->enb_flag == ENB_FLAG_YES) {
@@ -575,7 +628,9 @@ pdcp_data_ind(
   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,
+  const uint32_t *const srcID,
+  const uint32_t *const dstID
 )
 //-----------------------------------------------------------------------------
 {
@@ -1072,7 +1127,7 @@ pdcp_data_ind(
            * for the UE compiled in noS1 mode, we need 0
            * TODO: be sure of this
            */
-          if (NFAPI_MODE == NFAPI_UE_STUB_PNF ) {
+          if (NFAPI_MODE == NFAPI_UE_STUB_PNF || NFAPI_MODE == NFAPI_MODE_STANDALONE_PNF) {
             pdcpHead->inst  = ctxt_pP->module_id;
           } else {  // nfapi_mode
             if (UE_NAS_USE_TUN) {
@@ -1288,7 +1343,7 @@ pdcp_run (
 
   // IP/NAS -> PDCP traffic : TX, read the pkt from the upper layer buffer
   //  if (LINK_ENB_PDCP_TO_GTPV1U && ctxt_pP->enb_flag == ENB_FLAG_NO) {
-  if (!EPC_MODE_ENABLED || ctxt_pP->enb_flag == ENB_FLAG_NO ) {
+  if (!get_softmodem_params()->emulate_l1 && (!EPC_MODE_ENABLED || ctxt_pP->enb_flag == ENB_FLAG_NO)) {
     pdcp_fifo_read_input_sdus(ctxt_pP);
   }
 
@@ -1298,8 +1353,9 @@ pdcp_run (
   } else {
     start_meas(&UE_pdcp_stats[ctxt_pP->module_id].pdcp_ip);
   }
-
-  pdcp_fifo_flush_sdus(ctxt_pP);
+  if (!get_softmodem_params()->emulate_l1) {
+    pdcp_fifo_flush_sdus(ctxt_pP);
+  }
 
   if (ctxt_pP->enb_flag) {
     stop_meas(&eNB_pdcp_stats[ctxt_pP->module_id].pdcp_ip);
@@ -1491,7 +1547,7 @@ void pdcp_add_UE(const protocol_ctxt_t *const  ctxt_pP) {
         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);
+        LOG_I(PDCP,"add new uid is %d %x\n", i, ctxt_pP->rnti);
         pdcp_init_stats_UE(ctxt_pP->module_id, i);
         // ret=1;
         break;
@@ -2342,7 +2398,7 @@ void pdcp_set_pdcp_data_ind_func(pdcp_data_ind_func_t pdcp_data_ind) {
   pdcp_params.pdcp_data_ind_func = pdcp_data_ind;
 }
 
-uint64_t pdcp_module_init( uint64_t pdcp_optmask ) {
+uint64_t pdcp_module_init( uint64_t pdcp_optmask, int id) {
   /* temporary enforce netlink when UE_NAS_USE_TUN is set,
      this is while switching from noS1 as build option
      to noS1 as config option                               */
@@ -2359,18 +2415,18 @@ uint64_t pdcp_module_init( uint64_t pdcp_optmask ) {
     nas_getparams();
 
     if(UE_NAS_USE_TUN) {
-      int num_if = (NFAPI_MODE == NFAPI_UE_STUB_PNF || IS_SOFTMODEM_SIML1 )? MAX_MOBILES_PER_ENB : 1;
-      netlink_init_tun("ue",num_if);
+      int num_if = (NFAPI_MODE == NFAPI_UE_STUB_PNF || IS_SOFTMODEM_SIML1 || NFAPI_MODE == NFAPI_MODE_STANDALONE_PNF)? MAX_MOBILES_PER_ENB : 1;
+      netlink_init_tun("ue",num_if, id);
       if (IS_SOFTMODEM_NOS1)
-    	  nas_config(1, 1, 2, "ue");
-      netlink_init_mbms_tun("uem");
+        nas_config(1, 1, 2, "ue");
+      netlink_init_mbms_tun("uem", id);
       nas_config_mbms(1, 2, 2, "uem");
       LOG_I(PDCP, "UE pdcp will use tun interface\n");
     } else if(ENB_NAS_USE_TUN) {
-      netlink_init_tun("enb",1);
+      netlink_init_tun("enb", 1, 0);
       nas_config(1, 1, 1, "enb");
       if(pdcp_optmask & ENB_NAS_USE_TUN_W_MBMS_BIT){
-        netlink_init_mbms_tun("enm");
+        netlink_init_mbms_tun("enm", 0);
       	nas_config_mbms(1, 2, 1, "enm"); 
       	LOG_I(PDCP, "ENB pdcp will use mbms tun interface\n");
       }
@@ -2382,8 +2438,8 @@ uint64_t pdcp_module_init( uint64_t pdcp_optmask ) {
   }else{
          if(pdcp_optmask & ENB_NAS_USE_TUN_W_MBMS_BIT){
              LOG_W(PDCP, "ENB pdcp will use tun interface for MBMS\n");
-            netlink_init_mbms_tun("enm");
-             nas_config_mbms_s1(1, 2, 1, "enm"); 
+             netlink_init_mbms_tun("enm", 0);
+             nas_config_mbms_s1(1, 2, 1, "enm");
          }else
              LOG_E(PDCP, "ENB pdcp will not use tun interface\n");
    }
@@ -2425,6 +2481,7 @@ pdcp_free (
 void pdcp_module_cleanup (void)
 //-----------------------------------------------------------------------------
 {
+  netlink_cleanup();
 }
 
 //-----------------------------------------------------------------------------
diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp.h b/openair2/LAYER2/PDCP_v10.1.0/pdcp.h
index 9d9224d660493d43686cdb974f6a0b2702c854b3..332ee382d712bd3c161623845d9a08d1d002569a 100644
--- a/openair2/LAYER2/PDCP_v10.1.0/pdcp.h
+++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp.h
@@ -47,13 +47,16 @@
 
 
 typedef rlc_op_status_t  (*send_rlc_data_req_func_t)(const protocol_ctxt_t *const,
-    const srb_flag_t, const MBMS_flag_t,
-    const rb_id_t, const mui_t,
+						     const srb_flag_t, const MBMS_flag_t,
+						     const rb_id_t, const mui_t,
     confirm_t, sdu_size_t, mem_block_t *,const uint32_t *const, const uint32_t *const);
-typedef boolean_t (*pdcp_data_ind_func_t)( const protocol_ctxt_t *, const srb_flag_t,
-    const MBMS_flag_t, const rb_id_t, const sdu_size_t,
-    mem_block_t *,const uint32_t *const, const uint32_t *const);
 
+typedef boolean_t (pdcp_data_ind_t)( const protocol_ctxt_t *, const srb_flag_t,
+						 const MBMS_flag_t, const rb_id_t, const sdu_size_t,
+						 mem_block_t *,const uint32_t *const, const uint32_t *const);
+typedef pdcp_data_ind_t* pdcp_data_ind_func_t;
+
+#define MAX_NUMBER_NETIF                 1 //16
 #define ENB_NAS_USE_TUN_W_MBMS_BIT      (1<< 10)
 #define PDCP_USE_NETLINK_BIT            (1<< 11)
 #define LINK_ENB_PDCP_TO_IP_DRIVER_BIT  (1<< 13)
@@ -254,6 +257,19 @@ boolean_t pdcp_data_req(
   const uint32_t * destinationL2Id
 );
 
+boolean_t cu_f1u_data_req(
+  protocol_ctxt_t  *ctxt_pP,
+  const srb_flag_t srb_flagP,
+  const rb_id_t rb_id,
+  const mui_t muiP,
+  const confirm_t confirmP,
+  const sdu_size_t sdu_buffer_size,
+  unsigned char *const sdu_buffer,
+  const pdcp_transmission_mode_t mode,
+  const uint32_t *const sourceL2Id,
+  const uint32_t *const destinationL2Id
+  );
+
 /*! \fn boolean_t pdcp_data_ind(const protocol_ctxt_t* const, srb_flag_t, MBMS_flag_t, rb_id_t, sdu_size_t, mem_block_t*, boolean_t)
 * \brief This functions handles data transfer indications coming from RLC
 * \param[in] ctxt_pP        Running context.
@@ -267,13 +283,7 @@ boolean_t pdcp_data_req(
 * \note None
 * @ingroup _pdcp
 */
-boolean_t pdcp_data_ind(
-  const protocol_ctxt_t *const  ctxt_pP,
-  const srb_flag_t srb_flagP,
-  const MBMS_flag_t MBMS_flagP,
-  const rb_id_t rb_id,
-  const sdu_size_t sdu_buffer_size,
-  mem_block_t *const sdu_buffer);
+pdcp_data_ind_t pdcp_data_ind;
 
 /*! \fn void rrc_pdcp_config_req(const protocol_ctxt_t* const ,uint32_t,rb_id_t,uint8_t)
 * \brief This functions initializes relevant PDCP entity
@@ -401,7 +411,8 @@ void pdcp_mbms_run            (
 */
 void pdcp_run            (
   const protocol_ctxt_t *const  ctxt_pP);
-uint64_t pdcp_module_init     (uint64_t pdcp_optmask);
+uint64_t pdcp_module_init (uint64_t pdcp_optmask, int ue_id);
+uint64_t nr_pdcp_module_init(uint64_t _pdcp_optmask, int id);
 void pdcp_module_cleanup (void);
 void nr_ip_over_LTE_DRB_preconfiguration (void);
 void pdcp_layer_init     (void);
@@ -419,7 +430,10 @@ pdcp_data_ind_func_t get_pdcp_data_ind_func(void);
 //-----------------------------------------------------------------------------
 int pdcp_fifo_flush_mbms_sdus                      ( const protocol_ctxt_t *const  ctxt_pP);
 int pdcp_fifo_read_input_mbms_sdus_fromtun       ( const protocol_ctxt_t *const  ctxt_pP);
-
+rlc_op_status_t cu_send_to_du(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 mui_t muiP,
+			       confirm_t confirmP, sdu_size_t sdu_sizeP, mem_block_t *sdu_pP, const uint32_t *const, const uint32_t *const);
 
 /*
  * Following two types are utilized between NAS driver and PDCP
diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp_control_primitive.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp_control_primitive.c
deleted file mode 100644
index c2736ddd840869392fd20bc236648594485cbc0f..0000000000000000000000000000000000000000
--- a/openair2/LAYER2/PDCP_v10.1.0/pdcp_control_primitive.c
+++ /dev/null
@@ -1,53 +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
- */
-
-/***************************************************************************
-                        pdcp_control_primitives.c
-                             -------------------
-    begin                : Mon Dec 10 2001
-    email                : Lionel.Gauthier@eurecom.fr
-                             -------------------
-    description
-    This file contains the functions used for configuration of pdcp
-
- ***************************************************************************/
-#include "rtos_header.h"
-#include "platform.h"
-#include "protocol_vars_extern.h"
-//-----------------------------------------------------------------------------
-#include "rlc.h"
-#include "pdcp.h"
-#include "debug_l2.h"
-//-----------------------------------------------------------------------------
-void
-configure_pdcp_req (struct pdcp_entity *pdcpP, void *rlcP, uint8_t rlc_sap_typeP, uint8_t header_compression_typeP)
-{
-  //-----------------------------------------------------------------------------
-  mem_block      *mb;
-
-  mb = get_free_mem_block (sizeof (struct cpdcp_primitive), __func__);
-  if(mb==NULL) return;
-  ((struct cpdcp_primitive *) mb->data)->type = CPDCP_CONFIG_REQ;
-  ((struct cpdcp_primitive *) mb->data)->primitive.config_req.rlc_sap = rlcP;
-  ((struct cpdcp_primitive *) mb->data)->primitive.config_req.rlc_type_sap = rlc_sap_typeP;
-  ((struct cpdcp_primitive *) mb->data)->primitive.config_req.header_compression_type = header_compression_typeP;
-  send_pdcp_control_primitive (pdcpP, mb);
-}
diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp_control_primitives_proto_extern.h b/openair2/LAYER2/PDCP_v10.1.0/pdcp_control_primitives_proto_extern.h
deleted file mode 100644
index 6226dccc335c3b46d9010d224d8c103c28c331ca..0000000000000000000000000000000000000000
--- a/openair2/LAYER2/PDCP_v10.1.0/pdcp_control_primitives_proto_extern.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
- */
-
-/***************************************************************************
-                            pdcp_control_primitives_proto_extern.h
-                             -------------------
-    begin                : Mon Dec 10 2001
-    email                : Lionel.Gauthier@eurecom.fr
-                             -------------------
-    description
-    This file contains the prototypes of functions used for configuration of pdcp
-
- ***************************************************************************/
-#ifndef PDCP_CONTROL_PRIMITIVES_PROTO_EXTERN_H
-#    define PDCP_CONTROL_PRIMITIVES_PROTO_EXTERN_H
-#    include "pdcp.h"
-void            rrc_configure_pdcp (struct pdcp_entity *pdcpP, void *rlcP, uint8_t rlc_sap_typeP, uint8_t header_compression_typeP);
-#endif
diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c
index 05e77a935de7b17b3dc1db423228991d0dbd390d..b49b02042821d8d0c3071858703faa179dfce9bf 100644
--- a/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c
+++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c
@@ -89,7 +89,7 @@ extern struct msghdr nas_msg_rx;
 
 
 extern int gtpv1u_new_data_req( uint8_t  enb_module_idP, rnti_t   ue_rntiP, uint8_t  rab_idP, uint8_t *buffer_pP, uint32_t buf_lenP, uint32_t buf_offsetP);
-
+uint16_t ue_id_g; // Global variable to identify the ID for each UE. It is updated in main() of lte-uesoftmodem.c
 
 void debug_pdcp_pc5s_sdu(sidelink_pc5s_element *sl_pc5s_msg, char *title) {
   LOG_I(PDCP,"%s: \nPC5S message, header traffic_type: %d)\n", title, sl_pc5s_msg->pc5s_header.traffic_type);
@@ -210,14 +210,46 @@ int pdcp_fifo_read_input_sdus_fromtun (const protocol_ctxt_t *const  ctxt_pP) {
   pdcp_t *pdcp_p = NULL;
   int len;
   rb_id_t rab_id = DEFAULT_RAB_ID;
+  int sockd;
 
-  do {
+  if (UE_NAS_USE_TUN) {
+    if (ue_id_g == 0) {
+      sockd = nas_sock_fd[ctxt_pP->module_id];
+    }
+    else {
+      sockd = nas_sock_fd[ue_id_g];
+    }
+  }
+  else {
+    sockd = nas_sock_fd[0];
+  }
+
+  for (;;) {
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_READ, 1 );
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_READ_BUFFER, 1 );
-    len = read(UE_NAS_USE_TUN?nas_sock_fd[ctxt_pP->module_id]:nas_sock_fd[0], &nl_rx_buf, NL_MAX_PAYLOAD);
-    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_READ_BUFFER, 0 );
+    len = read(sockd, &nl_rx_buf, NL_MAX_PAYLOAD);
 
-    if (len<=0) continue;
+    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_READ_BUFFER, 0 );
+    if (len == -1) {
+      if (errno == EAGAIN) {
+        LOG_D(PDCP, "Error reading NAS socket: %s\n", strerror(errno));
+      }
+      else {
+        LOG_E(PDCP, "Error reading NAS socket: %s\n", strerror(errno));
+      }
+      break;
+    }
+    /* Check for message truncation. Strictly speaking if the packet is exactly sizeof(nl_rx_buf) bytes
+       that would not be an error. But we cannot distinguish that from a packet > sizeof(nl_rx_buf) */
+    if (len == sizeof(nl_rx_buf))
+    {
+      LOG_E(PDCP, "%s(%d). Message truncated %d\n", __FUNCTION__, __LINE__, len);
+      break;
+    }
+    if (len == 0) {
+      LOG_E(PDCP, "EOF Reading NAS socket\n");
+      break;
+    }
 
     if (UE_NAS_USE_TUN) {
       key = PDCP_COLL_KEY_DEFAULT_DRB_VALUE(ctxt.module_id, ctxt.rnti, ctxt.enb_flag);
@@ -263,7 +295,7 @@ int pdcp_fifo_read_input_sdus_fromtun (const protocol_ctxt_t *const  ctxt_pP) {
             ctxt.frame, ctxt.instance, rab_id, len, ctxt.module_id,
             ctxt.rnti, rab_id, key);
     }
-  } while (len > 0);
+  }
 
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_READ, 0 );
   return len;
@@ -474,8 +506,12 @@ int pdcp_fifo_read_input_sdus_fromnetlinksock (const protocol_ctxt_t *const  ctx
               // never finished code, dropped
             }
           } else { // ctxt.enb_flag => UE
-            if (NFAPI_MODE == NFAPI_UE_STUB_PNF) {
+            if (NFAPI_MODE == NFAPI_UE_STUB_PNF || NFAPI_MODE == NFAPI_MODE_STANDALONE_PNF) {
+#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;
             }
@@ -526,8 +562,8 @@ int pdcp_fifo_read_input_sdus_fromnetlinksock (const protocol_ctxt_t *const  ctx
                   pdcp_read_header_g.data_size,
                   (unsigned char *)NLMSG_DATA(nas_nlh_rx),
                   PDCP_TRANSMISSION_MODE_DATA,
-                  (NFAPI_MODE == NFAPI_UE_STUB_PNF)?NULL:&pdcp_read_header_g.sourceL2Id,
-                  (NFAPI_MODE == NFAPI_UE_STUB_PNF)?NULL:&pdcp_read_header_g.destinationL2Id
+                  (NFAPI_MODE == NFAPI_UE_STUB_PNF || NFAPI_MODE == NFAPI_MODE_STANDALONE_PNF) ? NULL : &pdcp_read_header_g.sourceL2Id,
+                  (NFAPI_MODE == NFAPI_UE_STUB_PNF || NFAPI_MODE == NFAPI_MODE_STANDALONE_PNF) ? NULL : &pdcp_read_header_g.destinationL2Id
                 );
               } else { /* else of h_rc == HASH_TABLE_OK */
                 MSC_LOG_RX_DISCARDED_MESSAGE(
@@ -571,8 +607,8 @@ int pdcp_fifo_read_input_sdus_fromnetlinksock (const protocol_ctxt_t *const  ctx
                 pdcp_read_header_g.data_size,
                 (unsigned char *)NLMSG_DATA(nas_nlh_rx),
                 PDCP_TRANSMISSION_MODE_DATA,
-                (NFAPI_MODE == NFAPI_UE_STUB_PNF) ? NULL :&pdcp_read_header_g.sourceL2Id,
-                (NFAPI_MODE == NFAPI_UE_STUB_PNF) ? NULL :&pdcp_read_header_g.destinationL2Id
+                (NFAPI_MODE == NFAPI_UE_STUB_PNF|| NFAPI_MODE == NFAPI_MODE_STANDALONE_PNF) ? NULL : &pdcp_read_header_g.sourceL2Id,
+                (NFAPI_MODE == NFAPI_UE_STUB_PNF|| NFAPI_MODE == NFAPI_MODE_STANDALONE_PNF) ? NULL : &pdcp_read_header_g.destinationL2Id
               );
             } /* rab_id == 0 */
           } /*pdcp_read_state_g != 0 */
@@ -597,35 +633,45 @@ void pdcp_fifo_read_input_sdus_frompc5s (const protocol_ctxt_t *const  ctxt_pP)
   /* avoid gcc warnings */
   (void)data_p;
   pdcp_t                        *pdcp_p    = NULL;
-  //TTN for D2D (PC5S)
-  int prose_addr_len = sizeof(prose_pdcp_addr);
-  char send_buf[BUFSIZE], receive_buf[BUFSIZE];
-  //int optval;
   int bytes_received;
   sidelink_pc5s_element *sl_pc5s_msg_send = NULL;
   pc5s_header_t *pc5s_header  = NULL;
   rb_id_t          rab_id  = 0;
   //TTN for D2D (PC5S)
   // receive a message from ProSe App
-  memset(receive_buf, 0, BUFSIZE);
-  bytes_received = recvfrom(pdcp_pc5_sockfd, receive_buf, BUFSIZE, 0,
-                            (struct sockaddr *) &prose_pdcp_addr, (socklen_t *)&prose_addr_len);
-
+  char receive_buf[MAX_MESSAGE_SIZE];
+  memset(receive_buf, 0, sizeof(receive_buf));
+  socklen_t prose_addr_len = sizeof(prose_pdcp_addr);
+  bytes_received = recvfrom(pdcp_pc5_sockfd, receive_buf, sizeof(receive_buf), MSG_TRUNC,
+                            (struct sockaddr *) &prose_pdcp_addr, &prose_addr_len);
+  if (bytes_received == -1) {
+    LOG_E(PDCP, "%s(%d). recvfrom failed. %s\n", __FUNCTION__, __LINE__, strerror(errno));
+    return;
+  }
+  if (bytes_received == 0) {
+    LOG_E(PDCP, "%s(%d). EOF pdcp_pc5_sockfd.\n", __FUNCTION__, __LINE__);
+  }
+  if (bytes_received > sizeof(receive_buf)) {
+    LOG_E(PDCP, "%s(%d). Message truncated. %d\n", __FUNCTION__, __LINE__, bytes_received);
+    return;
+  }
   if (bytes_received > 0) {
     pc5s_header = calloc(1, sizeof(pc5s_header_t));
     memcpy((void *)pc5s_header, (void *)receive_buf, sizeof(pc5s_header_t));
 
+    char send_buf[MAX_MESSAGE_SIZE];
     switch(pc5s_header->traffic_type) {
       case TRAFFIC_PC5S_SESSION_INIT :
         //send reply to ProSe app
         LOG_D(PDCP,"Received a request to open PDCP socket and establish a new PDCP session ... send response to ProSe App \n");
-        memset(send_buf, 0, BUFSIZE);
+        memset(send_buf, 0, sizeof(send_buf));
         sl_pc5s_msg_send = calloc(1, sizeof(sidelink_pc5s_element));
         sl_pc5s_msg_send->pc5s_header.traffic_type = TRAFFIC_PC5S_SESSION_INIT;
         sl_pc5s_msg_send->pc5sPrimitive.status = 1;
-        memcpy((void *)send_buf, (void *)sl_pc5s_msg_send, sizeof(sidelink_pc5s_element));
+        memcpy(send_buf, sl_pc5s_msg_send, sizeof(sidelink_pc5s_element));
         int prose_addr_len = sizeof(prose_pdcp_addr);
-        int bytes_sent = sendto(pdcp_pc5_sockfd, (char *)send_buf, sizeof(sidelink_pc5s_element), 0, (struct sockaddr *)&prose_pdcp_addr, prose_addr_len);
+        int bytes_sent = sendto(pdcp_pc5_sockfd, send_buf, sizeof(sidelink_pc5s_element), 0,
+                                (struct sockaddr *) &prose_pdcp_addr, prose_addr_len);
         free (sl_pc5s_msg_send);
 
         if (bytes_sent < 0) {
diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp_thread.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp_thread.c
deleted file mode 100644
index f1f6ebb7941502e5ae176ce218f72922ab600b91..0000000000000000000000000000000000000000
--- a/openair2/LAYER2/PDCP_v10.1.0/pdcp_thread.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
- */
-
-/*! \file pdcp_thread.c
- * \brief
- * \author F. Kaltenberger
- * \date 2013
- * \version 0.1
- * \company Eurecom
- * \email: florian.kaltenberger@eurecom.fr
- * \note
- * \warning
- */
-#include <pthread.h>
-//#include <inttypes.h>
-
-#include "pdcp.h"
-#include "PHY/extern.h" //for PHY_vars
-#include "UTIL/LOG/log.h"
-#include "UTIL/LOG/vcd_signal_dumper.h"
-#include "msc.h"
-
-#define OPENAIR_THREAD_STACK_SIZE    8192
-#define OPENAIR_THREAD_PRIORITY        255
-
-extern int  oai_exit;
-extern char UE_flag;
-
-pthread_t       pdcp_thread;
-pthread_mutex_t pdcp_mutex;
-pthread_cond_t  pdcp_cond;
-int             pdcp_instance_cnt;
-
-static void *pdcp_thread_main(void* param);
-
-static void *pdcp_thread_main(void* param)
-{
-  uint8_t eNB_flag = !UE_flag;
-
-  LOG_I(PDCP,"This is pdcp_thread eNB_flag = %d\n",eNB_flag);
-  MSC_START_USE();
-
-  while (!oai_exit) {
-
-    if (pthread_mutex_lock(&pdcp_mutex) != 0) {
-      LOG_E(PDCP,"Error locking mutex.\n");
-    } else {
-      while (pdcp_instance_cnt < 0) {
-        pthread_cond_wait(&pdcp_cond,&pdcp_mutex);
-      }
-
-      if (pthread_mutex_unlock(&pdcp_mutex) != 0) {
-        LOG_E(PDCP,"Error unlocking mutex.\n");
-      }
-    }
-
-    if (oai_exit) break;
-
-    if (eNB_flag) {
-      pdcp_run(PHY_vars_eNB_g[0]->frame, eNB_flag, PHY_vars_eNB_g[0]->Mod_id, 0);
-      LOG_D(PDCP,"Calling pdcp_run (eNB) for frame %d\n",PHY_vars_eNB_g[0]->frame);
-    } else  {
-      pdcp_run(PHY_vars_UE_g[0]->frame, eNB_flag, 0, PHY_vars_UE_g[0]->Mod_id);
-      LOG_D(PDCP,"Calling pdcp_run (UE) for frame %d\n",PHY_vars_UE_g[0]->frame);
-    }
-
-    if (pthread_mutex_lock(&pdcp_mutex) != 0) {
-      LOG_E(PDCP,"Error locking mutex.\n");
-    } else {
-      pdcp_instance_cnt--;
-
-      if (pthread_mutex_unlock(&pdcp_mutex) != 0) {
-        LOG_E(PDCP,"Error unlocking mutex.\n");
-      }
-    }
-  }
-
-  return(NULL);
-}
-
-
-int init_pdcp_thread(void)
-{
-
-  pthread_mutex_init(&pdcp_mutex,NULL);
-  pthread_cond_init(&pdcp_cond,NULL);
-
-  pdcp_instance_cnt = -1;
-  LOG_I(PDCP,"Allocating PDCP thread\n");
-  threadCreate(&pdcp_thread, pdcp_thread_main, (void*)NULL, "PDCP", -1, OAI_PRIORITY_RT);
-
-  return(0);
-}
-
-
-void cleanup_pdcp_thread(void)
-{
-  void *status_p = NULL;
-
-  LOG_I(PDCP,"Scheduling PDCP thread to exit\n");
-
-  pdcp_instance_cnt = 0;
-
-  if (pthread_cond_signal(&pdcp_cond) != 0) {
-    LOG_I(PDCP,"ERROR pthread_cond_signal\n");
-  } else {
-    LOG_I(PDCP,"Signalled PDCP thread to exit\n");
-  }
-
-  pthread_join(pdcp_thread,&status_p);
-  LOG_I(PDCP,"PDCP thread exited\n");
-  pthread_cond_destroy(&pdcp_cond);
-  pthread_mutex_destroy(&pdcp_mutex);
-}
diff --git a/openair2/LAYER2/PROTO_AGENT/proto_agent.c b/openair2/LAYER2/PROTO_AGENT/proto_agent.c
index 6bf9cdce229a249417febf87340c68e6dce6f453..5cf71b826db089bb177df20d5d67590582c2c5cc 100644
--- a/openair2/LAYER2/PROTO_AGENT/proto_agent.c
+++ b/openair2/LAYER2/PROTO_AGENT/proto_agent.c
@@ -157,7 +157,7 @@ void proto_agent_stop(mod_id_t mod_id) {
 rlc_op_status_t  proto_agent_send_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, const mui_t muiP,
-    confirm_t confirmP, sdu_size_t sdu_sizeP, mem_block_t *sdu_pP) {
+    confirm_t confirmP, sdu_size_t sdu_sizeP, mem_block_t *sdu_pP,const uint32_t *const SrcID, const uint32_t *const DstID) {
   uint8_t *msg = NULL;
   Protocol__FlexsplitMessage *init_msg=NULL;
   int msg_flag = 0;
@@ -191,9 +191,10 @@ error:
 }
 
 
-boolean_t
-proto_agent_send_pdcp_data_ind(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, sdu_size_t sdu_sizeP, mem_block_t *sdu_pP) {
+boolean_t proto_agent_send_pdcp_data_ind(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,
+					       sdu_size_t sdu_sizeP, mem_block_t *sdu_pP,
+					       const uint32_t *const SrcID, const uint32_t *const DstID) {
   uint8_t *msg = NULL;
   Protocol__FlexsplitMessage *init_msg = NULL;
   int msg_flag = 0;
diff --git a/openair2/LAYER2/PROTO_AGENT/proto_agent.h b/openair2/LAYER2/PROTO_AGENT/proto_agent.h
index 32bf5aa13c7793f07732c4af25d208f6133f45ec..4badda43b7953ba80be008b02e1cfc39320c25e1 100644
--- a/openair2/LAYER2/PROTO_AGENT/proto_agent.h
+++ b/openair2/LAYER2/PROTO_AGENT/proto_agent.h
@@ -42,10 +42,8 @@ void proto_agent_stop(mod_id_t mod_id);
 rlc_op_status_t proto_agent_send_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, const mui_t muiP, confirm_t confirmP,
-    sdu_size_t sdu_sizeP, mem_block_t *sdu_pP);
+    sdu_size_t sdu_sizeP, mem_block_t *sdu_pP,const uint32_t *const SrcID, const uint32_t *const DstID);
 
-boolean_t proto_agent_send_pdcp_data_ind(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, sdu_size_t sdu_sizeP, mem_block_t *sdu_pP);
+pdcp_data_ind_t proto_agent_send_pdcp_data_ind;
 
 #endif
diff --git a/openair2/LAYER2/PROTO_AGENT/proto_agent_common.c b/openair2/LAYER2/PROTO_AGENT/proto_agent_common.c
index f19d7526fe3dc0467bb346ccd8d1a5ed36c4d263..d3d00d1adaa0abf95b17603a9d19f30704acb0b4 100644
--- a/openair2/LAYER2/PROTO_AGENT/proto_agent_common.c
+++ b/openair2/LAYER2/PROTO_AGENT/proto_agent_common.c
@@ -496,14 +496,6 @@ error:
   return -1;
 }
 
-boolean_t pdcp_data_ind(
-  const protocol_ctxt_t *const  ctxt_pP,
-  const srb_flag_t srb_flagP,
-  const MBMS_flag_t MBMS_flagP,
-  const rb_id_t rb_id,
-  const sdu_size_t sdu_buffer_size,
-  mem_block_t *const sdu_buffer);
-
 int proto_agent_pdcp_data_ind_process(mod_id_t mod_id, const void *params, Protocol__FlexsplitMessage **msg) {
   boolean_t result = 0;
   Protocol__FlexsplitMessage *input = (Protocol__FlexsplitMessage *)params;
@@ -525,7 +517,6 @@ int proto_agent_pdcp_data_ind_process(mod_id_t mod_id, const void *params, Proto
   ctxt_pP.rnti = ctxt->fsp_rnti;
   ctxt_pP.frame = ctxt->fsp_frame;
   ctxt_pP.subframe = ctxt->fsp_subframe;
-  ctxt_pP.configured = 1;
   ctxt_pP.brOption = 0;
   ctxt_pP.eNB_index = ctxt->fsp_enb_index;
   srb_flagP = rlc_data->fsp_srb_flag;
@@ -546,7 +537,7 @@ int proto_agent_pdcp_data_ind_process(mod_id_t mod_id, const void *params, Proto
                          flag_MBMS,
                          rb_idP,
                          pdcp_pdu_size,
-                         pdcp_pdu_p);
+                         pdcp_pdu_p, NULL, NULL);
   return result;
 error:
 
diff --git a/openair2/LAYER2/nr_pdcp/nr_pdcp_entity.c b/openair2/LAYER2/nr_pdcp/nr_pdcp_entity.c
index 87b71894c7047c668abd174b8e136e17238a365e..62aa101a500534a1837579157b0825f0ee321cb4 100644
--- a/openair2/LAYER2/nr_pdcp/nr_pdcp_entity.c
+++ b/openair2/LAYER2/nr_pdcp/nr_pdcp_entity.c
@@ -108,7 +108,7 @@ static void nr_pdcp_entity_recv_pdu(nr_pdcp_entity_t *entity,
 
   if (rcvd_count < entity->rx_deliv
       || nr_pdcp_sdu_in_list(entity->rx_list, rcvd_count)) {
-    LOG_D(PDCP, "discard NR PDU rcvd_count=%d\n", rcvd_count);
+    LOG_W(PDCP, "discard NR PDU rcvd_count=%d\n", rcvd_count);
     return;
   }
 
diff --git a/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c b/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c
index 298588f11245484d9c1a832602d1f371c5497584..ab8578a0e7e5ccce3f3907a92b26fa0856124679 100644
--- a/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c
+++ b/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c
@@ -55,6 +55,7 @@ hash_table_t  *pdcp_coll_p;
 static uint64_t pdcp_optmask;
 
 ngran_node_t node_type = ngran_gNB;
+uint8_t first_dcch = 0;
 uint8_t proto_agent_flag = 0;
 
 /****************************************************************************/
@@ -160,8 +161,7 @@ static void enqueue_rlc_data_req(const protocol_ctxt_t *const ctxt_pP,
                                  const mui_t        muiP,
                                  confirm_t    confirmP,
                                  sdu_size_t   sdu_sizeP,
-                                 mem_block_t *sdu_pP,
-                                 void *_unused1, void *_unused2)
+                                 mem_block_t *sdu_pP)
 {
   int i;
   int logged = 0;
@@ -206,9 +206,7 @@ void du_rlc_data_req(const protocol_ctxt_t *const ctxt_pP,
                        rb_idP, muiP,
                        confirmP,
                        sdu_sizeP,
-                       sdu_pP,
-                       NULL,
-                       NULL);
+                       sdu_pP);
 }
 
 /****************************************************************************/
@@ -256,7 +254,6 @@ static void do_pdcp_data_ind(
       //ctxt_pP->enb_flag != 1 ||
       ctxt_pP->instance != 0 ||
       ctxt_pP->eNB_index != 0 ||
-      ctxt_pP->configured != 1 ||
       ctxt_pP->brOption != 0) {
     LOG_E(PDCP, "%s:%d:%s: fatal\n", __FILE__, __LINE__, __FUNCTION__);
     exit(1);
@@ -376,7 +373,9 @@ boolean_t pdcp_data_ind(
   const MBMS_flag_t MBMS_flagP,
   const rb_id_t rb_id,
   const sdu_size_t sdu_buffer_size,
-  mem_block_t *const sdu_buffer)
+  mem_block_t *const sdu_buffer,
+  const uint32_t *const srcID,
+  const uint32_t *const dstID)
 {
   enqueue_pdcp_data_ind(ctxt_pP,
                         srb_flagP,
@@ -442,7 +441,6 @@ static void *enb_tun_read_thread(void *_)
     ctxt.frame = 0;
     ctxt.subframe = 0;
     ctxt.eNB_index = 0;
-    ctxt.configured = 1;
     ctxt.brOption = 0;
 
     ctxt.rnti = rnti;
@@ -486,7 +484,6 @@ static void *ue_tun_read_thread(void *_)
     ctxt.frame = 0;
     ctxt.subframe = 0;
     ctxt.eNB_index = 0;
-    ctxt.configured = 1;
     ctxt.brOption = 0;
 
     ctxt.rnti = rnti;
@@ -559,7 +556,7 @@ void pdcp_layer_init(void)
 #include "targets/RT/USER/lte-softmodem.h"
 #include "openair2/RRC/NAS/nas_config.h"
 
-uint64_t pdcp_module_init(uint64_t _pdcp_optmask)
+uint64_t nr_pdcp_module_init(uint64_t _pdcp_optmask, int id)
 {
   /* hack: be sure to initialize only once */
   static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
@@ -591,16 +588,18 @@ uint64_t pdcp_module_init(uint64_t _pdcp_optmask)
     nas_getparams();
 
     if(UE_NAS_USE_TUN) {
-      int num_if = (NFAPI_MODE == NFAPI_UE_STUB_PNF || IS_SOFTMODEM_SIML1 )? MAX_MOBILES_PER_ENB : 1;
-      netlink_init_tun("ue",num_if);
+      char *ifsuffix_ue = get_softmodem_params()->nsa ? "nrue" : "ue";
+      int num_if = (NFAPI_MODE == NFAPI_UE_STUB_PNF || IS_SOFTMODEM_SIML1 || NFAPI_MODE == NFAPI_MODE_STANDALONE_PNF)? MAX_MOBILES_PER_ENB : 1;
+      netlink_init_tun(ifsuffix_ue, num_if, id);
       //Add --nr-ip-over-lte option check for next line
       if (IS_SOFTMODEM_NOS1)
-          nas_config(1, 1, 2, "ue");
+          nas_config(1, 1, !get_softmodem_params()->nsa ? 2 : 3, ifsuffix_ue);
       LOG_I(PDCP, "UE pdcp will use tun interface\n");
       start_pdcp_tun_ue();
     } else if(ENB_NAS_USE_TUN) {
-      netlink_init_tun("enb",1);
-      nas_config(1, 1, 1, "enb");
+      char *ifsuffix_base_s = get_softmodem_params()->nsa ? "gnb" : "enb";
+      netlink_init_tun(ifsuffix_base_s, 1, id);
+      nas_config(1, 1, 1, ifsuffix_base_s);
       LOG_I(PDCP, "ENB pdcp will use tun interface\n");
       start_pdcp_tun_enb();
     } else {
@@ -623,7 +622,7 @@ static void deliver_sdu_drb(void *_ue, nr_pdcp_entity_t *entity,
   int rb_id;
   int i;
 
-  if(IS_SOFTMODEM_NOS1 || UE_NAS_USE_TUN){
+  if (IS_SOFTMODEM_NOS1 || UE_NAS_USE_TUN) {
     LOG_D(PDCP, "IP packet received, to be sent to TUN interface");
 
     if(entity->has_sdapDLheader){
@@ -634,7 +633,7 @@ static void deliver_sdu_drb(void *_ue, nr_pdcp_entity_t *entity,
     }
 
     if (len != size) {
-      LOG_E(PDCP, "%s:%d:%s: fatal\n", __FILE__, __LINE__, __FUNCTION__);
+      LOG_E(PDCP, "%s:%d:%s: fatal error %d: %s\n", __FILE__, __LINE__, __FUNCTION__, errno, strerror(errno));
     }
     
   }
@@ -653,19 +652,23 @@ static void deliver_sdu_drb(void *_ue, nr_pdcp_entity_t *entity,
     rb_found:
     {
       int offset=0;
-      if (entity->has_sdap == 1 && entity->has_sdapULheader == 1) offset = 1; // this is the offset of the SDAP header in bytes
+      if (entity->has_sdap == 1 && entity->has_sdapULheader == 1)
+	offset = 1; // this is the offset of the SDAP header in bytes
 
-      gtpu_buffer_p = itti_malloc(TASK_PDCP_ENB, TASK_GTPV1_U,
-                                  size + GTPU_HEADER_OVERHEAD_MAX - offset);
-      AssertFatal(gtpu_buffer_p != NULL, "OUT OF MEMORY");
-      memcpy(&gtpu_buffer_p[GTPU_HEADER_OVERHEAD_MAX], buf+offset, size-offset);
-      message_p = itti_alloc_new_message(TASK_PDCP_ENB, 0, GTPV1U_GNB_TUNNEL_DATA_REQ);
+      message_p = itti_alloc_new_message_sized(TASK_PDCP_ENB, 0,
+					       GTPV1U_GNB_TUNNEL_DATA_REQ,
+					       sizeof(gtpv1u_gnb_tunnel_data_req_t) + size
+					       + GTPU_HEADER_OVERHEAD_MAX - offset);
       AssertFatal(message_p != NULL, "OUT OF MEMORY");
-      GTPV1U_GNB_TUNNEL_DATA_REQ(message_p).buffer              = gtpu_buffer_p;
-      GTPV1U_GNB_TUNNEL_DATA_REQ(message_p).length              = size-offset;
-      GTPV1U_GNB_TUNNEL_DATA_REQ(message_p).offset              = GTPU_HEADER_OVERHEAD_MAX;
-      GTPV1U_GNB_TUNNEL_DATA_REQ(message_p).rnti                = ue->rnti;
-      GTPV1U_GNB_TUNNEL_DATA_REQ(message_p).pdusession_id       = entity->pdusession_id;
+
+      gtpv1u_gnb_tunnel_data_req_t *req=&GTPV1U_GNB_TUNNEL_DATA_REQ(message_p);
+      gtpu_buffer_p = (uint8_t*)(req+1);
+      memcpy(gtpu_buffer_p+GTPU_HEADER_OVERHEAD_MAX, buf+offset, size-offset);
+      req->buffer              = gtpu_buffer_p;
+      req->length              = size-offset;
+      req->offset              = GTPU_HEADER_OVERHEAD_MAX;
+      req->rnti                = ue->rnti;
+      req->pdusession_id       = entity->pdusession_id;
       if (offset==1) {
         LOG_I(PDCP, "%s() (drb %d) SDAP header %2x\n",__func__, rb_id, buf[0]);
         sdap_gnb_ul_header_handler(buf[0]); // Handler for the UL gNB SDAP Header
@@ -703,18 +706,39 @@ rb_found:
   ctxt.frame = 0;
   ctxt.subframe = 0;
   ctxt.eNB_index = 0;
-  ctxt.configured = 1;
   ctxt.brOption = 0;
 
   ctxt.rnti = ue->rnti;
-
-  memblock = get_free_mem_block(size, __FUNCTION__);
-  memcpy(memblock->data, buf, size);
-
-  LOG_D(PDCP, "%s(): (srb %d) calling rlc_data_req size %d\n", __func__, rb_id, size);
-  //for (i = 0; i < size; i++) printf(" %2.2x", (unsigned char)memblock->data[i]);
-  //printf("\n");
-  enqueue_rlc_data_req(&ctxt, 0, MBMS_FLAG_NO, rb_id, sdu_id, 0, size, memblock, NULL, NULL);
+  if (RC.nrrrc != NULL && NODE_IS_CU(RC.nrrrc[0]->node_type)) {
+    MessageDef  *message_p = itti_alloc_new_message_sized(TASK_PDCP_ENB, 0,
+							  GTPV1U_GNB_TUNNEL_DATA_REQ,
+							  sizeof(gtpv1u_gnb_tunnel_data_req_t)
+							  + size
+							  + GTPU_HEADER_OVERHEAD_MAX);
+    AssertFatal(message_p != NULL, "OUT OF MEMORY");
+    gtpv1u_gnb_tunnel_data_req_t *req=&GTPV1U_GNB_TUNNEL_DATA_REQ(message_p);
+    uint8_t *gtpu_buffer_p = (uint8_t*)(req+1);
+    memcpy(gtpu_buffer_p+GTPU_HEADER_OVERHEAD_MAX, 
+	   buf, size);
+    req->buffer        = gtpu_buffer_p;
+    req->length        = size;
+    req->offset        = GTPU_HEADER_OVERHEAD_MAX;
+    req->rnti          = ue->rnti;
+    req->pdusession_id = rb_id;
+    LOG_D(PDCP, "%s() (drb %d) sending message to gtp size %d\n",
+	  __func__, rb_id, size);
+    extern instance_t CUuniqInstance;
+    itti_send_msg_to_task(TASK_VARIABLE, CUuniqInstance, message_p);
+  } else {
+    
+    memblock = get_free_mem_block(size, __FUNCTION__);
+    memcpy(memblock->data, buf, size);
+    
+    LOG_D(PDCP, "%s(): (srb %d) calling rlc_data_req size %d\n", __func__, rb_id, size);
+    //for (i = 0; i < size; i++) printf(" %2.2x", (unsigned char)memblock->data[i]);
+    //printf("\n");
+    enqueue_rlc_data_req(&ctxt, 0, MBMS_FLAG_NO, rb_id, sdu_id, 0, size, memblock);
+  }
 }
 
 static void deliver_sdu_srb(void *_ue, nr_pdcp_entity_t *entity,
@@ -791,18 +815,19 @@ srb_found:
     ctxt.frame = 0;
     ctxt.subframe = 0;
     ctxt.eNB_index = 0;
-    ctxt.configured = 1;
     ctxt.brOption = 0;
 
     ctxt.rnti = ue->rnti;
 
     memblock = get_free_mem_block(size, __FUNCTION__);
     memcpy(memblock->data, buf, size);
-    enqueue_rlc_data_req(&ctxt, 1, MBMS_FLAG_NO, srb_id, sdu_id, 0, size, memblock, NULL, NULL);
+    enqueue_rlc_data_req(&ctxt, 1, MBMS_FLAG_NO, srb_id, sdu_id, 0, size, memblock);
   }
   else {
     MessageDef  *message_p = itti_alloc_new_message (TASK_RRC_GNB, 0, F1AP_DL_RRC_MESSAGE);
-    F1AP_DL_RRC_MESSAGE (message_p).rrc_container        = (uint8_t*)buf;
+    uint8_t *message_buffer = itti_malloc (TASK_RRC_GNB, TASK_CU_F1, size);
+    memcpy (message_buffer, buf, size);
+    F1AP_DL_RRC_MESSAGE (message_p).rrc_container        = message_buffer;
     F1AP_DL_RRC_MESSAGE (message_p).rrc_container_length = size;
     F1AP_DL_RRC_MESSAGE (message_p).gNB_CU_ue_id         = 0;
     F1AP_DL_RRC_MESSAGE (message_p).gNB_DU_ue_id         = 0;
@@ -827,7 +852,6 @@ void pdcp_run(const protocol_ctxt_t *const  ctxt_pP)
                         .frame=-1,
                         .subframe=-1,
                         .eNB_index=0,
-                        .configured=true,
                         .brOption=false
                        };
 
@@ -1164,7 +1188,7 @@ void nr_DRB_preconfiguration(uint16_t crnti)
 
   NR_RLC_BearerConfig_t *RLC_BearerConfig = calloc(1,sizeof(*RLC_BearerConfig));
   nr_rlc_bearer_init(RLC_BearerConfig,NR_RLC_BearerConfig__servedRadioBearer_PR_drb_Identity);
-  nr_drb_config(RLC_BearerConfig->rlc_Config, NR_RLC_Config_PR_um_Bi_Directional);
+  nr_drb_config(RLC_BearerConfig->rlc_Config, NR_RLC_Config_PR_am);
   nr_rlc_bearer_init_ul_spec(RLC_BearerConfig->mac_LogicalChannelConfig);
 
   Rlc_Bearer_ToAdd_list = calloc(1,sizeof(*Rlc_Bearer_ToAdd_list));
@@ -1356,6 +1380,35 @@ static boolean_t pdcp_data_req_drb(
   return 1;
 }
 
+boolean_t cu_f1u_data_req(
+  protocol_ctxt_t  *ctxt_pP,
+  const srb_flag_t srb_flagP,
+  const rb_id_t rb_id,
+  const mui_t muiP,
+  const confirm_t confirmP,
+  const sdu_size_t sdu_buffer_size,
+  unsigned char *const sdu_buffer,
+  const pdcp_transmission_mode_t mode
+  ,const uint32_t *const sourceL2Id
+  ,const uint32_t *const destinationL2Id
+  ) {
+
+  //Force instance id to 0, OAI incoherent instance management
+  ctxt_pP->instance=0;
+  mem_block_t *memblock = get_free_mem_block(sdu_buffer_size, __func__);
+  if (memblock == NULL) {
+    LOG_E(RLC, "%s:%d:%s: ERROR: get_free_mem_block failed\n", __FILE__, __LINE__, __FUNCTION__);
+    exit(1);
+  }
+  memcpy(memblock->data,sdu_buffer, sdu_buffer_size);
+  int ret=pdcp_data_ind(ctxt_pP,srb_flagP, false, rb_id, sdu_buffer_size, memblock, NULL, NULL);
+  if (!ret) {
+    LOG_E(RLC, "%s:%d:%s: ERROR: pdcp_data_ind failed\n", __FILE__, __LINE__, __FUNCTION__);
+    /* what to do in case of failure? for the moment: nothing */
+  }
+  return ret;
+}
+
 boolean_t pdcp_data_req(
   protocol_ctxt_t  *ctxt_pP,
   const srb_flag_t srb_flagP,
diff --git a/openair2/LAYER2/nr_pdcp/nr_pdcp_timer_thread.c b/openair2/LAYER2/nr_pdcp/nr_pdcp_timer_thread.c
index 36e9b16024879db067a7784c66eb898e36527dc7..5f6939e165e3d44b62dff08f91ed9bc65af6326f 100644
--- a/openair2/LAYER2/nr_pdcp/nr_pdcp_timer_thread.c
+++ b/openair2/LAYER2/nr_pdcp/nr_pdcp_timer_thread.c
@@ -19,6 +19,7 @@
  *      contact@openairinterface.org
  */
 
+#define _GNU_SOURCE
 #include "nr_pdcp_timer_thread.h"
 
 #include <stdlib.h>
@@ -33,6 +34,7 @@ static volatile uint64_t timer_thread_curtime = 0;
 
 static void *nr_pdcp_timer_thread(void *_nr_pdcp_ue_manager)
 {
+  pthread_setname_np(pthread_self(),"pdcp_timer");
   nr_pdcp_ue_manager_t *nr_pdcp_ue_manager = (nr_pdcp_ue_manager_t *)_nr_pdcp_ue_manager;
   nr_pdcp_ue_t         **ue_list;
   int                  ue_count;
diff --git a/openair2/LAYER2/nr_rlc/nr_rlc_entity_am.c b/openair2/LAYER2/nr_rlc/nr_rlc_entity_am.c
index 7224449bc63c10995235896ee142b2cb618df0ee..d7923e5490bf0c0ebccb2b53044edc6efe4478cf 100644
--- a/openair2/LAYER2/nr_rlc/nr_rlc_entity_am.c
+++ b/openair2/LAYER2/nr_rlc/nr_rlc_entity_am.c
@@ -596,20 +596,20 @@ void nr_rlc_entity_am_recv_pdu(nr_rlc_entity_t *_entity,
 
   /* dicard PDU if no data */
   if (data_size <= 0) {
-    LOG_D(RLC, "%s:%d:%s: warning: discard PDU, no data\n",
+    LOG_W(RLC, "%s:%d:%s: warning: discard PDU, no data\n",
           __FILE__, __LINE__, __FUNCTION__);
     goto discard;
   }
 
   /* dicard PDU if rx buffer is full */
   if (entity->rx_size + data_size > entity->rx_maxsize) {
-    LOG_D(RLC, "%s:%d:%s: warning: discard PDU, RX buffer full\n",
+    LOG_W(RLC, "%s:%d:%s: warning: discard PDU, RX buffer full\n",
           __FILE__, __LINE__, __FUNCTION__);
     goto discard;
   }
 
   if (!sn_in_recv_window(entity, sn)) {
-    LOG_D(RLC, "%s:%d:%s: warning: discard PDU, sn out of window (sn %d rx_next %d)\n",
+    LOG_W(RLC, "%s:%d:%s: warning: discard PDU, sn out of window (sn %d rx_next %d)\n",
           __FILE__, __LINE__, __FUNCTION__,
            sn, entity->rx_next);
     goto discard;
@@ -617,7 +617,7 @@ void nr_rlc_entity_am_recv_pdu(nr_rlc_entity_t *_entity,
 
   /* discard segment if all the bytes of the segment are already there */
   if (segment_already_received(entity, sn, so, data_size)) {
-    LOG_D(RLC, "%s:%d:%s: warning: discard PDU, already received\n",
+    LOG_W(RLC, "%s:%d:%s: warning: discard PDU, already received\n",
           __FILE__, __LINE__, __FUNCTION__);
     goto discard;
   }
@@ -653,7 +653,7 @@ void nr_rlc_entity_am_recv_pdu(nr_rlc_entity_t *_entity,
 control:
   cpt = nr_rlc_pdu_decoder_get_bits(&decoder, 3); R(decoder);
   if (cpt != 0) {
-    LOG_D(RLC, "%s:%d:%s: warning: discard PDU, CPT not 0 (%d)\n",
+    LOG_W(RLC, "%s:%d:%s: warning: discard PDU, CPT not 0 (%d)\n",
           __FILE__, __LINE__, __FUNCTION__, cpt);
     goto discard;
   }
@@ -1660,7 +1660,7 @@ static void check_t_poll_retransmit(nr_rlc_entity_am_t *entity)
    */
   entity->force_poll = 1;
 
-  LOG_D(RLC, "%s:%d:%s: warning: t_poll_retransmit expired\n",
+  LOG_W(RLC, "%s:%d:%s: warning: t_poll_retransmit expired\n",
         __FILE__, __LINE__, __FUNCTION__);
 
   /* do we meet conditions of 38.322 5.3.3.4? */
diff --git a/openair2/LAYER2/nr_rlc/nr_rlc_entity_um.c b/openair2/LAYER2/nr_rlc/nr_rlc_entity_um.c
index 7336e8f9da64a922eac03dfaf27a2109c6dca1c3..b34a7dc89410f621ca0a3fc68980a7648e13355e 100644
--- a/openair2/LAYER2/nr_rlc/nr_rlc_entity_um.c
+++ b/openair2/LAYER2/nr_rlc/nr_rlc_entity_um.c
@@ -313,21 +313,21 @@ void nr_rlc_entity_um_recv_pdu(nr_rlc_entity_t *_entity,
 
   /* dicard PDU if no data */
   if (data_size <= 0) {
-    LOG_D(RLC, "%s:%d:%s: warning: discard PDU, no data\n",
+    LOG_W(RLC, "%s:%d:%s: warning: discard PDU, no data\n",
           __FILE__, __LINE__, __FUNCTION__);
     goto discard;
   }
 
   /* dicard PDU if rx buffer is full */
   if (entity->rx_size + data_size > entity->rx_maxsize) {
-    LOG_D(RLC, "%s:%d:%s: warning: discard PDU, RX buffer full\n",
+    LOG_W(RLC, "%s:%d:%s: warning: discard PDU, RX buffer full\n",
           __FILE__, __LINE__, __FUNCTION__);
     goto discard;
   }
 
   /* discard PDU if sn < rx_next_reassembly */
   if (sn_compare_rx(entity, sn, entity->rx_next_reassembly) < 0) {
-    LOG_D(RLC, "%s:%d:%s: warning: discard PDU, SN (%d) < rx_next_reassembly (%d)\n",
+    LOG_W(RLC, "%s:%d:%s: warning: discard PDU, SN (%d) < rx_next_reassembly (%d)\n",
           __FILE__, __LINE__, __FUNCTION__,
           sn, entity->rx_next_reassembly);
     goto discard;
@@ -534,7 +534,7 @@ void nr_rlc_entity_um_recv_sdu(nr_rlc_entity_t *_entity,
   }
 
   if (entity->tx_size + size > entity->tx_maxsize) {
-    LOG_D(RLC, "%s:%d:%s: warning: SDU rejected, SDU buffer full\n",
+    LOG_W(RLC, "%s:%d:%s: warning: SDU rejected, SDU buffer full\n",
           __FILE__, __LINE__, __FUNCTION__);
     return;
   }
diff --git a/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c b/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c
index 046696d12fad32d660a790a4d0e8fdbe8fc40fa5..78e06d37e2914fde662a0ffe26471f59e108f122 100644
--- a/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c
+++ b/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c
@@ -346,16 +346,16 @@ rlc_buffer_occupancy_t mac_rlc_get_buffer_occupancy_ind(
 
 
 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,
-                                  const mui_t        muiP,
-                                  confirm_t    confirmP,
-                                  sdu_size_t   sdu_sizeP,
-                                  mem_block_t *sdu_pP,
-  const uint32_t *const sourceL2Id,
-  const uint32_t *const destinationL2Id
-                                 )
+			const srb_flag_t   srb_flagP,
+			const MBMS_flag_t  MBMS_flagP,
+			const rb_id_t      rb_idP,
+			const mui_t        muiP,
+			confirm_t    confirmP,
+			sdu_size_t   sdu_sizeP,
+			mem_block_t *sdu_pP,
+                        const uint32_t *const sourceL2Id,
+                        const uint32_t *const destinationL2Id
+			)
 {
   int rnti = ctxt_pP->rnti;
   nr_rlc_ue_t *ue;
@@ -465,19 +465,11 @@ rb_found:
   LOG_D(RLC, "%s:%d:%s: delivering SDU (rnti %d is_srb %d rb_id %d) size %d\n",
         __FILE__, __LINE__, __FUNCTION__, ue->rnti, is_srb, rb_id, size);
 
-  memblock = get_free_mem_block(size, __func__);
-  if (memblock == NULL) {
-    LOG_E(RLC, "%s:%d:%s: ERROR: get_free_mem_block failed\n", __FILE__, __LINE__, __FUNCTION__);
-    exit(1);
-  }
-  memcpy(memblock->data, buf, size);
-
   /* unused fields? */
   ctx.instance = 0;
   ctx.frame = 0;
   ctx.subframe = 0;
   ctx.eNB_index = 0;
-  ctx.configured = 1;
   ctx.brOption = 0;
 
   /* used fields? */
@@ -502,19 +494,44 @@ rb_found:
     //   return;
     // }
 
-    if (NODE_IS_DU(type) && is_srb == 1) {
-      MessageDef *msg;
-      msg = itti_alloc_new_message(TASK_RLC_ENB, 0, F1AP_UL_RRC_MESSAGE);
-      F1AP_UL_RRC_MESSAGE(msg).rnti = ue->rnti;
-      F1AP_UL_RRC_MESSAGE(msg).srb_id = rb_id;
-      F1AP_UL_RRC_MESSAGE(msg).rrc_container = (unsigned char *)buf;
-      F1AP_UL_RRC_MESSAGE(msg).rrc_container_length = size;
-      itti_send_msg_to_task(TASK_DU_F1, ENB_MODULE_ID_TO_INSTANCE(0 /*ctxt_pP->module_id*/), msg);
-      return;
+    if (NODE_IS_DU(type)) {
+      if(is_srb) {
+	MessageDef *msg;
+	msg = itti_alloc_new_message(TASK_RLC_ENB, 0, F1AP_UL_RRC_MESSAGE);
+	uint8_t *message_buffer = itti_malloc (TASK_RLC_ENB, TASK_DU_F1, size);
+	memcpy (message_buffer, buf, size);
+	F1AP_UL_RRC_MESSAGE(msg).rnti = ue->rnti;
+	F1AP_UL_RRC_MESSAGE(msg).srb_id = rb_id;
+	F1AP_UL_RRC_MESSAGE(msg).rrc_container = message_buffer;
+	F1AP_UL_RRC_MESSAGE(msg).rrc_container_length = size;
+	itti_send_msg_to_task(TASK_DU_F1, ENB_MODULE_ID_TO_INSTANCE(0 /*ctxt_pP->module_id*/), msg);
+	return;
+      } else {
+	MessageDef *msg = itti_alloc_new_message_sized(TASK_RLC_ENB, 0, GTPV1U_GNB_TUNNEL_DATA_REQ,
+						       sizeof(gtpv1u_gnb_tunnel_data_req_t) + size);
+	gtpv1u_gnb_tunnel_data_req_t *req=&GTPV1U_GNB_TUNNEL_DATA_REQ(msg);
+	req->buffer=(uint8_t*)(req+1);
+	memcpy(req->buffer,buf,size);
+	req->length=size;
+	req->offset=0;
+	req->rnti=ue->rnti;
+	req->pdusession_id=rb_id;
+	LOG_D(RLC, "Received uplink user-plane traffic at RLC-DU to be sent to the CU, size %d \n", size);
+	extern instance_t DUuniqInstance;
+	itti_send_msg_to_task(OCP_GTPV1_U, DUuniqInstance, msg);
+	return;
+      }
     }
   }
 
-  if (!pdcp_data_ind(&ctx, is_srb, 0, rb_id, size, memblock)) {
+  memblock = get_free_mem_block(size, __func__);
+  if (memblock == NULL) {
+    LOG_E(RLC, "%s:%d:%s: ERROR: get_free_mem_block failed\n", __FILE__, __LINE__, __FUNCTION__);
+    exit(1);
+  }
+  memcpy(memblock->data, buf, size);
+  LOG_D(PDCP, "Calling PDCP layer from RLC in %s\n", __FUNCTION__);
+  if (!pdcp_data_ind(&ctx, is_srb, 0, rb_id, size, memblock, NULL, NULL)) {
     LOG_E(RLC, "%s:%d:%s: ERROR: pdcp_data_ind failed\n", __FILE__, __LINE__, __FUNCTION__);
     /* what to do in case of failure? for the moment: nothing */
   }
@@ -721,7 +738,7 @@ static void add_rlc_srb(int rnti, struct NR_SRB_ToAddMod *s, NR_RLC_BearerConfig
                                      sn_field_length);
     nr_rlc_ue_add_srb_rlc_entity(ue, srb_id, nr_rlc_am);
 
-    LOG_D(RLC, "%s:%d:%s: added srb %d to UE with RNTI 0x%x\n", __FILE__, __LINE__, __FUNCTION__, srb_id, rnti);
+    LOG_I(RLC, "%s:%d:%s: added srb %d to UE with RNTI 0x%x\n", __FILE__, __LINE__, __FUNCTION__, srb_id, rnti);
   }
   nr_rlc_manager_unlock(nr_rlc_ue_manager);
 }
@@ -803,7 +820,7 @@ static void add_drb_am(int rnti, struct NR_DRB_ToAddMod *s, NR_RLC_BearerConfig_
                                      sn_field_length);
     nr_rlc_ue_add_drb_rlc_entity(ue, drb_id, nr_rlc_am);
 
-    LOG_D(RLC, "%s:%d:%s: added drb %d to UE with RNTI 0x%x\n", __FILE__, __LINE__, __FUNCTION__, drb_id, rnti);
+    LOG_I(RLC, "%s:%d:%s: added drb %d to UE with RNTI 0x%x\n", __FILE__, __LINE__, __FUNCTION__, drb_id, rnti);
   }
   nr_rlc_manager_unlock(nr_rlc_ue_manager);
 }
@@ -918,10 +935,10 @@ rlc_op_status_t nr_rrc_rlc_config_asn1_req (const protocol_ctxt_t   * const ctxt
 
   if (/*ctxt_pP->enb_flag != 1 ||*/ ctxt_pP->module_id != 0 /*||
       ctxt_pP->instance != 0 || ctxt_pP->eNB_index != 0 ||
-      ctxt_pP->configured != 1 || ctxt_pP->brOption != 0 */) {
-    LOG_E(RLC, "%s: ctxt_pP not handled (%d %d %ld %d %d %d)\n", __FUNCTION__,
+      ctxt_pP->brOption != 0 */) {
+    LOG_E(RLC, "%s: ctxt_pP not handled (%d %d %ld %d %d)\n", __FUNCTION__,
           ctxt_pP->enb_flag , ctxt_pP->module_id, ctxt_pP->instance,
-          ctxt_pP->eNB_index, ctxt_pP->configured, ctxt_pP->brOption);
+          ctxt_pP->eNB_index,  ctxt_pP->brOption);
     exit(1);
   }
 
diff --git a/openair2/LAYER2/rlc_v2/rlc_oai_api.c b/openair2/LAYER2/rlc_v2/rlc_oai_api.c
index 0cf4b85fa2cb98145cc1bc24f0a0a41f5eca793f..16c3db0cae3912a551bcff985123cf01a13cbc9d 100644
--- a/openair2/LAYER2/rlc_v2/rlc_oai_api.c
+++ b/openair2/LAYER2/rlc_v2/rlc_oai_api.c
@@ -394,19 +394,12 @@ rb_found:
   LOG_D(RLC, "%s:%d:%s: delivering SDU (rnti %d is_srb %d rb_id %d) size %d",
         __FILE__, __LINE__, __FUNCTION__, ue->rnti, is_srb, rb_id, size);
 
-  memblock = get_free_mem_block(size, __func__);
-  if (memblock == NULL) {
-    LOG_E(RLC, "%s:%d:%s: ERROR: get_free_mem_block failed\n", __FILE__, __LINE__, __FUNCTION__);
-    exit(1);
-  }
-  memcpy(memblock->data, buf, size);
 
   /* unused fields? */
   ctx.instance = ue->module_id;
   ctx.frame = 0;
   ctx.subframe = 0;
   ctx.eNB_index = 0;
-  ctx.configured = 1;
   ctx.brOption = 0;
 
   /* used fields? */
@@ -425,17 +418,40 @@ rb_found:
     AssertFatal(type != ngran_eNB_CU && type != ngran_ng_eNB_CU && type != ngran_gNB_CU,
                 "Can't be CU, bad node type %d\n", type);
 
-    if (NODE_IS_DU(type) && is_srb == 1) {
-      MessageDef *msg = itti_alloc_new_message(TASK_RLC_ENB, 0, F1AP_UL_RRC_MESSAGE);
-      F1AP_UL_RRC_MESSAGE(msg).rnti = ue->rnti;
-      F1AP_UL_RRC_MESSAGE(msg).srb_id = rb_id;
-      F1AP_UL_RRC_MESSAGE(msg).rrc_container = (unsigned char *)buf;
-      F1AP_UL_RRC_MESSAGE(msg).rrc_container_length = size;
-      itti_send_msg_to_task(TASK_DU_F1, ENB_MODULE_ID_TO_INSTANCE(0 /*ctxt_pP->module_id*/), msg);
-      return;
+    if (NODE_IS_DU(type)) {
+      if (is_srb == 1) {
+	MessageDef *msg = itti_alloc_new_message_sized(TASK_RLC_ENB, 0, F1AP_UL_RRC_MESSAGE, sizeof(*msg) + size);
+	F1AP_UL_RRC_MESSAGE(msg).rrc_container = (uint8_t*)(msg+1);
+	memcpy(F1AP_UL_RRC_MESSAGE(msg).rrc_container, buf, size);
+	F1AP_UL_RRC_MESSAGE(msg).rnti = ue->rnti;
+	F1AP_UL_RRC_MESSAGE(msg).srb_id = rb_id;
+	F1AP_UL_RRC_MESSAGE(msg).rrc_container_length = size;
+	itti_send_msg_to_task(TASK_DU_F1, ENB_MODULE_ID_TO_INSTANCE(0 /*ctxt_pP->module_id*/), msg);
+	return;
+      }  else {
+	// Fixme: very dirty workaround of incomplete F1-U implementation
+	instance_t DUuniqInstance=0;
+	MessageDef *msg = itti_alloc_new_message(TASK_RLC_ENB, 0, GTPV1U_ENB_TUNNEL_DATA_REQ);
+	gtpv1u_enb_tunnel_data_req_t *req=&GTPV1U_ENB_TUNNEL_DATA_REQ(msg);
+	req->buffer=malloc(size);
+	memcpy(req->buffer,buf,size);
+	req->length=size;
+	req->offset=0;
+	req->rnti=ue->rnti;
+	req->rab_id=rb_id+4;
+	LOG_D(RLC, "Received uplink user-plane traffic at RLC-DU to be sent to the CU, size %d \n", size);
+	itti_send_msg_to_task(OCP_GTPV1_U, DUuniqInstance, msg);      
+	return;
+      }
     }
   }
-
+  
+  memblock = get_free_mem_block(size, __func__);
+  if (memblock == NULL) {
+    LOG_E(RLC, "%s:%d:%s: ERROR: get_free_mem_block failed\n", __FILE__, __LINE__, __FUNCTION__);
+    exit(1);
+  }
+  memcpy(memblock->data, buf, size);
   if (!get_pdcp_data_ind_func()(&ctx, is_srb, is_mbms, rb_id, size, memblock, NULL, NULL)) {
     LOG_E(RLC, "%s:%d:%s: ERROR: pdcp_data_ind failed (is_srb %d rb_id %d rnti %d)\n",
           __FILE__, __LINE__, __FUNCTION__,
@@ -832,10 +848,10 @@ rlc_op_status_t rrc_rlc_config_asn1_req (const protocol_ctxt_t   * const ctxt_pP
 
   if (0 /*||
       ctxt_pP->instance != 0 || ctxt_pP->eNB_index != 0 ||
-      ctxt_pP->configured != 1 || ctxt_pP->brOption != 0 */) {
-    LOG_E(RLC, "%s: ctxt_pP not handled (%d %d %ld %d %d %d)\n", __FUNCTION__,
+      ctxt_pP->brOption != 0 */) {
+    LOG_E(RLC, "%s: ctxt_pP not handled (%d %d %ld %d %d)\n", __FUNCTION__,
           ctxt_pP->enb_flag , ctxt_pP->module_id, ctxt_pP->instance,
-          ctxt_pP->eNB_index, ctxt_pP->configured, ctxt_pP->brOption);
+          ctxt_pP->eNB_index, ctxt_pP->brOption);
     exit(1);
   }
 
@@ -1040,5 +1056,12 @@ void du_rlc_data_req(const protocol_ctxt_t *const ctxt_pP,
                      confirm_t    confirmP,
                      sdu_size_t   sdu_sizeP,
                      mem_block_t *sdu_pP){
-
-}
\ No newline at end of file
+  rlc_data_req (ctxt_pP,
+		srb_flagP,
+		MBMS_flagP,
+		rb_idP,
+		muiP,
+		confirmP,
+		sdu_sizeP,
+		sdu_pP, NULL, NULL);
+}
diff --git a/openair2/NR_PHY_INTERFACE/NR_IF_Module.c b/openair2/NR_PHY_INTERFACE/NR_IF_Module.c
index cb5bef5ab0ed7e76648d75f16e7646fefecf7ed1..d4f4bff745ec7f9187059b1415c2eb2e229045b9 100644
--- a/openair2/NR_PHY_INTERFACE/NR_IF_Module.c
+++ b/openair2/NR_PHY_INTERFACE/NR_IF_Module.c
@@ -37,6 +37,8 @@
 #include "common/ran_context.h"
 #include "executables/softmodem-common.h"
 #include "nfapi/oai_integration/vendor_ext.h" 
+#include "nfapi/oai_integration/gnb_ind_vars.h"
+#include "openair2/PHY_INTERFACE/queue_t.h"
 
 #define MAX_IF_MODULES 100
 //#define UL_HARQ_PRINT
@@ -58,150 +60,372 @@ extern uint8_t nfapi_mode;
 extern uint16_t sf_ahead;
 extern uint16_t sl_ahead;
 
-void handle_nr_rach(NR_UL_IND_t *UL_info) {
+
+void handle_nr_rach(NR_UL_IND_t *UL_info)
+{
   if(NFAPI_MODE == NFAPI_MODE_PNF) {
-    if (UL_info->rach_ind.number_of_pdus>0) {
+    if (UL_info->rach_ind.number_of_pdus > 0) {
       LOG_D(PHY,"UL_info->UL_info->rach_ind.number_of_pdus:%d SFN/Slot:%d.%d \n", UL_info->rach_ind.number_of_pdus, UL_info->rach_ind.sfn,UL_info->rach_ind.slot);
       oai_nfapi_nr_rach_indication(&UL_info->rach_ind);
       UL_info->rach_ind.number_of_pdus = 0;
     }
+    return;
+  }
+  NR_UL_IND_t UL_INFO;
+  nfapi_nr_rach_indication_t *rach_ind = NULL;
+  if (get_softmodem_params()->emulate_l1)
+  {
+    if (gnb_rach_ind_queue.num_items == 0)
+      return; 
+    LOG_I(NR_MAC, "gnb_rach_ind_queue size = %zu\n", gnb_rach_ind_queue.num_items);
+    rach_ind = get_queue(&gnb_rach_ind_queue);
+
+    UL_INFO.rach_ind = *rach_ind;
+    UL_INFO.module_id = UL_info->module_id;
+    UL_INFO.CC_id = UL_info->CC_id;
+  }
+  else
+  {
+    UL_INFO.rach_ind = UL_info->rach_ind;
+    UL_INFO.module_id = UL_info->module_id;
+    UL_INFO.CC_id = UL_info->CC_id;
   }
-  else{
-    if (UL_info->rach_ind.number_of_pdus>0) {
-      LOG_D(MAC,"UL_info[Frame %d, Slot %d] Calling initiate_ra_proc RACH:SFN/SLOT:%d/%d\n",UL_info->frame,UL_info->slot, UL_info->rach_ind.sfn,UL_info->rach_ind.slot);
-      int npdus = UL_info->rach_ind.number_of_pdus;
-      for(int i = 0; i < npdus; i++) {
-        UL_info->rach_ind.number_of_pdus--;
-        if (UL_info->rach_ind.pdu_list[i].num_preamble>0)
-        AssertFatal(UL_info->rach_ind.pdu_list[i].num_preamble==1,
-                    "More than 1 preamble not supported\n");
-      
-        nr_initiate_ra_proc(UL_info->module_id,
-                            UL_info->CC_id,
-                            UL_info->rach_ind.sfn,
-                            UL_info->rach_ind.slot,
-                            UL_info->rach_ind.pdu_list[i].preamble_list[0].preamble_index,
-                            UL_info->rach_ind.pdu_list[i].freq_index,
-                            UL_info->rach_ind.pdu_list[i].symbol_index,
-                            UL_info->rach_ind.pdu_list[i].preamble_list[0].timing_advance);
+
+  int frame_diff = UL_info->frame - UL_INFO.rach_ind.sfn;
+  if (frame_diff < 0)
+  {
+    frame_diff += 1024;
+  }
+  bool in_timewindow = frame_diff == 0 || (frame_diff == 1 && UL_info->slot < 7);
+
+  if (UL_INFO.rach_ind.number_of_pdus>0 && in_timewindow) {
+    LOG_A(MAC,"UL_info[Frame %d, Slot %d] Calling initiate_ra_proc RACH:SFN/SLOT:%d/%d\n",
+          UL_info->frame, UL_info->slot, UL_INFO.rach_ind.sfn, UL_INFO.rach_ind.slot);
+    int npdus = UL_INFO.rach_ind.number_of_pdus;
+    for(int i = 0; i < npdus; i++) {
+      UL_INFO.rach_ind.number_of_pdus--;
+      UL_info->rach_ind.number_of_pdus--;
+      if (UL_INFO.rach_ind.pdu_list[i].num_preamble>0)
+      AssertFatal(UL_INFO.rach_ind.pdu_list[i].num_preamble==1,
+                  "More than 1 preamble not supported\n");
+    
+      nr_initiate_ra_proc(UL_INFO.module_id,
+                          UL_INFO.CC_id,
+                          UL_INFO.rach_ind.sfn,
+                          UL_INFO.rach_ind.slot,
+                          UL_INFO.rach_ind.pdu_list[i].preamble_list[0].preamble_index,
+                          UL_INFO.rach_ind.pdu_list[i].freq_index,
+                          UL_INFO.rach_ind.pdu_list[i].symbol_index,
+                          UL_INFO.rach_ind.pdu_list[i].preamble_list[0].timing_advance);
+    }
+  }
+  if (get_softmodem_params()->emulate_l1)
+  {
+    if (rach_ind && rach_ind->number_of_pdus > 0)
+    {
+      for(int i = 0; i < rach_ind->number_of_pdus; i++)
+      {
+        free(rach_ind->pdu_list[i].preamble_list);
+        rach_ind->pdu_list[i].preamble_list = NULL;
       }
+      free(rach_ind->pdu_list);
+      rach_ind->pdu_list = NULL;
     }
+    free(rach_ind);
+    rach_ind = NULL;
   }
 }
 
 
 void handle_nr_uci(NR_UL_IND_t *UL_info)
-{ 
+{
   if(NFAPI_MODE == NFAPI_MODE_PNF) {
-    if (UL_info->uci_ind.num_ucis>0) {
+    if (UL_info->uci_ind.num_ucis > 0) {
       LOG_D(PHY,"PNF Sending UL_info->num_ucis:%d PDU_type: %d, SFN/SF:%d.%d \n", UL_info->uci_ind.num_ucis, UL_info->uci_ind.uci_list[0].pdu_type ,UL_info->frame, UL_info->slot);
       oai_nfapi_nr_uci_indication(&UL_info->uci_ind);
       UL_info->uci_ind.num_ucis = 0;
     }
+    return;
   }
-  else{
-    const module_id_t mod_id = UL_info->module_id;
-    const frame_t frame = UL_info->frame;
-    const sub_frame_t slot = UL_info->slot;
-    int num_ucis = UL_info->uci_ind.num_ucis;
-    nfapi_nr_uci_t *uci_list = UL_info->uci_ind.uci_list;
-    LOG_D(MAC,"handling UCI SFN/slot: %d.%d, num_ucis: %d \n", frame,slot, num_ucis);
-    for (int i = 0; i < num_ucis; i++) {
-      switch (uci_list[i].pdu_type) {
-        case NFAPI_NR_UCI_PUSCH_PDU_TYPE:
-          LOG_E(MAC, "%s(): unhandled NFAPI_NR_UCI_PUSCH_PDU_TYPE\n", __func__);
-          break;
 
-        case NFAPI_NR_UCI_FORMAT_0_1_PDU_TYPE: {
-          const nfapi_nr_uci_pucch_pdu_format_0_1_t *uci_pdu = &uci_list[i].pucch_pdu_format_0_1;
-          handle_nr_uci_pucch_0_1(mod_id, frame, slot, uci_pdu);
-          break;
-        }
+  NR_UL_IND_t UL_INFO;
+  nfapi_nr_uci_indication_t *uci_ind = NULL;
+  if (get_softmodem_params()->emulate_l1)
+  {
+    if (gnb_uci_ind_queue.num_items == 0)
+      return; 
+    LOG_I(NR_MAC, "gnb_uci_ind_queue size = %zu\n", gnb_uci_ind_queue.num_items);
+    uci_ind = get_queue(&gnb_uci_ind_queue);
+    UL_INFO.uci_ind = *uci_ind;
+  }
+  else
+  {
+    UL_INFO.uci_ind = UL_info->uci_ind;
+  }
+
+  const module_id_t mod_id = UL_info->module_id;
+  const frame_t frame = UL_INFO.uci_ind.sfn;
+  const sub_frame_t slot = UL_INFO.uci_ind.slot;
+  int num_ucis = UL_INFO.uci_ind.num_ucis;
+  nfapi_nr_uci_t *uci_list = UL_INFO.uci_ind.uci_list;
+
+  for (int i = 0; i < num_ucis; i++) {
+    switch (uci_list[i].pdu_type) {
+      case NFAPI_NR_UCI_PUSCH_PDU_TYPE:
+        LOG_E(MAC, "%s(): unhandled NFAPI_NR_UCI_PUSCH_PDU_TYPE\n", __func__);
+        break;
+
+      case NFAPI_NR_UCI_FORMAT_0_1_PDU_TYPE: {
+        const nfapi_nr_uci_pucch_pdu_format_0_1_t *uci_pdu = &uci_list[i].pucch_pdu_format_0_1;
+        LOG_D(NR_MAC, "The received uci has sfn slot %d %d, num_ucis %d and pdu_size %d\n",
+                UL_INFO.uci_ind.sfn, UL_INFO.uci_ind.slot, num_ucis, uci_list[i].pdu_size);
+        handle_nr_uci_pucch_0_1(mod_id, frame, slot, uci_pdu);
+        break;
+      }
 
         case NFAPI_NR_UCI_FORMAT_2_3_4_PDU_TYPE: {
           const nfapi_nr_uci_pucch_pdu_format_2_3_4_t *uci_pdu = &uci_list[i].pucch_pdu_format_2_3_4;
           handle_nr_uci_pucch_2_3_4(mod_id, frame, slot, uci_pdu);
           break;
         }
-      }
       LOG_D(MAC, "UCI handled \n");
     }
   }
 
-  UL_info->uci_ind.num_ucis = 0;
+  if (get_softmodem_params()->emulate_l1)
+  {
+    for (int i = 0; i < num_ucis; i++) {
+      switch (uci_list[i].pdu_type) {
+        case NFAPI_NR_UCI_FORMAT_0_1_PDU_TYPE:
+          if (uci_list[i].pucch_pdu_format_0_1.harq) {
+            free(uci_list[i].pucch_pdu_format_0_1.harq->harq_list);
+            uci_list[i].pucch_pdu_format_0_1.harq->harq_list = NULL;
+          }
+          free(uci_list[i].pucch_pdu_format_0_1.harq);
+          uci_list[i].pucch_pdu_format_0_1.harq = NULL;
+          free(uci_list[i].pucch_pdu_format_0_1.sr);
+          uci_list[i].pucch_pdu_format_0_1.sr = NULL;
+          break;
+
+        case NFAPI_NR_UCI_FORMAT_2_3_4_PDU_TYPE:
+          free(uci_list[i].pucch_pdu_format_2_3_4.harq.harq_payload);
+          free(uci_list[i].pucch_pdu_format_2_3_4.csi_part1.csi_part1_payload);
+          free(uci_list[i].pucch_pdu_format_2_3_4.csi_part2.csi_part2_payload);
+          break;
+      }
+    }
+    if (uci_ind && num_ucis > 0) {
+      free(uci_list);
+      uci_list = NULL;
+    }
+    free(uci_ind);
+    uci_ind = NULL;
+  }
+  else
+  {
+    UL_info->uci_ind.num_ucis = 0;
+  }
+}
+
+static bool crc_sfn_slot_matcher(void *wanted, void *candidate)
+{
+  nfapi_p7_message_header_t *msg = candidate;
+  int sfn_sf = *(int*)wanted;
+
+  switch (msg->message_id)
+  {
+    case NFAPI_NR_PHY_MSG_TYPE_CRC_INDICATION:
+    {
+      nfapi_nr_crc_indication_t *ind = candidate;
+      return NFAPI_SFNSLOT2SFN(sfn_sf) == ind->sfn && NFAPI_SFNSLOT2SLOT(sfn_sf) == ind->slot;
+    }
+
+    default:
+      LOG_E(NR_MAC, "sfn_slot_match bad ID: %d\n", msg->message_id);
+
+  }
+  return false;
 }
 
 void handle_nr_ulsch(NR_UL_IND_t *UL_info)
 {
   if(NFAPI_MODE == NFAPI_MODE_PNF) {
-    if (UL_info->crc_ind.number_crcs>0) {
+    if (UL_info->crc_ind.number_crcs > 0) {
       LOG_D(PHY,"UL_info->UL_info->crc_ind.number_crcs:%d CRC_IND:SFN/Slot:%d.%d\n", UL_info->crc_ind.number_crcs, UL_info->crc_ind.sfn, UL_info->crc_ind.slot);
       oai_nfapi_nr_crc_indication(&UL_info->crc_ind);
       UL_info->crc_ind.number_crcs = 0;
     }
 
-    if (UL_info->rx_ind.number_of_pdus>0) {
+    if (UL_info->rx_ind.number_of_pdus > 0) {
       LOG_D(PHY,"UL_info->rx_ind.number_of_pdus:%d RX_IND:SFN/Slot:%d.%d \n", UL_info->rx_ind.number_of_pdus, UL_info->rx_ind.sfn, UL_info->rx_ind.slot);
       oai_nfapi_nr_rx_data_indication(&UL_info->rx_ind);
       UL_info->rx_ind.number_of_pdus = 0;
     }
+    return;
   }
-  else{
-    if (UL_info->rx_ind.number_of_pdus > 0 && UL_info->crc_ind.number_crcs > 0) {
-      for (int i = 0; i < UL_info->rx_ind.number_of_pdus; i++) {
-        for (int j = 0; j < UL_info->crc_ind.number_crcs; j++) {
-          // find crc_indication j corresponding rx_indication i
-          const nfapi_nr_rx_data_pdu_t *rx = &UL_info->rx_ind.pdu_list[i];
-          const nfapi_nr_crc_t *crc = &UL_info->crc_ind.crc_list[j];
-          LOG_D(PHY,
-                "UL_info->crc_ind.pdu_list[%d].rnti:%04x "
-                "UL_info->rx_ind.pdu_list[%d].rnti:%04x\n",
-                j,
-                crc->rnti,
-                i,
-                rx->rnti);
-
-          if (crc->rnti != rx->rnti)
-            continue;
-
-          LOG_D(MAC,
-                "%4d.%2d Calling rx_sdu (CRC %s/tb_crc_status %d)\n",
-                UL_info->frame,
-                UL_info->slot,
-                crc->tb_crc_status ? "error" : "ok",
-                crc->tb_crc_status);
-
-          /* if CRC passes, pass PDU, otherwise pass NULL as error indication */
-          nr_rx_sdu(UL_info->module_id,
-                    UL_info->CC_id,
-                    UL_info->rx_ind.sfn,
-                    UL_info->rx_ind.slot,
-                    rx->rnti,
-                    crc->tb_crc_status ? NULL : rx->pdu,
-                    rx->pdu_length,
-                    rx->timing_advance,
-                    rx->ul_cqi,
-                    rx->rssi);
-          handle_nr_ul_harq(UL_info->CC_id, UL_info->module_id, UL_info->frame, UL_info->slot, crc);
-          break;
-        } //    for (j=0;j<UL_info->crc_ind.number_crcs;j++)
-      } //   for (i=0;i<UL_info->rx_ind.number_of_pdus;i++)
 
+  NR_UL_IND_t UL_INFO;
+  nfapi_nr_rx_data_indication_t *rx_ind = NULL;
+  nfapi_nr_crc_indication_t *crc_ind = NULL;
+  if (get_softmodem_params()->emulate_l1)
+  {
+    rx_ind = get_queue(&gnb_rx_ind_queue);
+    if (!rx_ind)
+    {
+      LOG_D(NR_PHY, "No rx data indication (empty gnb_rx_ind_queue)\n");
+      return;
+    }
+
+    int sfn_slot = NFAPI_SFNSLOT2HEX(rx_ind->sfn, rx_ind->slot); 
+    
+    crc_ind = unqueue_matching(&gnb_crc_ind_queue,
+                               MAX_QUEUE_SIZE,
+                               crc_sfn_slot_matcher,
+                               &sfn_slot);
+    if (!crc_ind)
+    {
+      LOG_D(NR_PHY, "No crc indication with the same SFN SLOT of rx indication %u %u\n", rx_ind->sfn, rx_ind->slot);
+      put_queue(&gnb_rx_ind_queue, rx_ind);
+      return;
+    }
+
+    UL_INFO.rx_ind = *rx_ind;
+    UL_INFO.crc_ind = *crc_ind;
+    UL_INFO.module_id = UL_info->module_id;
+    UL_INFO.CC_id = UL_info->CC_id;
+  }
+  else
+  {
+    UL_INFO.rx_ind = UL_info->rx_ind;
+    UL_INFO.crc_ind = UL_info->crc_ind;
+    UL_INFO.module_id = UL_info->module_id;
+    UL_INFO.CC_id = UL_info->CC_id;
+  }
+
+  UL_INFO.frame = UL_INFO.rx_ind.sfn;
+  UL_INFO.slot = UL_INFO.rx_ind.slot;
+  UL_INFO.module_id = UL_info->module_id;
+  UL_INFO.CC_id = UL_info->CC_id;
+  LOG_D(NR_MAC, " UL_info frame slot vs rx_ind frame slot vs crc_ind slot frame slot = %u %u vs %u %u vs %u %u\n",
+                  UL_info->frame, UL_info->slot,
+                  UL_INFO.rx_ind.sfn, UL_INFO.rx_ind.slot,
+                  UL_INFO.crc_ind.sfn, UL_INFO.crc_ind.slot
+                  );
+
+  if (UL_INFO.rx_ind.number_of_pdus > 0 && UL_INFO.crc_ind.number_crcs > 0) {
+    for (int i = 0; i < UL_INFO.rx_ind.number_of_pdus; i++) {
+      int j;
+      for (j = 0; j < UL_INFO.crc_ind.number_crcs; j++) {
+        // find crc_indication j corresponding rx_indication i
+        const nfapi_nr_rx_data_pdu_t *rx = &UL_INFO.rx_ind.pdu_list[i];
+        const nfapi_nr_crc_t *crc = &UL_INFO.crc_ind.crc_list[j];
+        LOG_D(NR_PHY,
+              "UL_INFO.crc_ind.pdu_list[%d].rnti:%04x "
+              "UL_INFO.rx_ind.pdu_list[%d].rnti:%04x\n",
+              j,
+              crc->rnti,
+              i,
+              rx->rnti);
+
+        if (crc->rnti != rx->rnti)
+        {
+          LOG_D(NR_MAC, "mis-match between CRC rnti %04x and RX rnit %04x\n",  crc->rnti,  rx->rnti);
+          continue;
+        }
+
+        LOG_D(NR_MAC,
+              "%4d.%2d Calling rx_sdu (CRC %s/tb_crc_status %d)\n",
+              UL_INFO.frame,
+              UL_INFO.slot,
+              crc->tb_crc_status ? "error" : "ok",
+              crc->tb_crc_status);
+
+        /* if CRC passes, pass PDU, otherwise pass NULL as error indication */
+        nr_rx_sdu(UL_INFO.module_id,
+                  UL_INFO.CC_id,
+                  UL_INFO.rx_ind.sfn,
+                  UL_INFO.rx_ind.slot,
+                  rx->rnti,
+                  crc->tb_crc_status ? NULL : rx->pdu,
+                  rx->pdu_length,
+                  rx->timing_advance,
+                  rx->ul_cqi,
+                  rx->rssi);
+        handle_nr_ul_harq(UL_INFO.CC_id, UL_INFO.module_id, UL_INFO.frame, UL_INFO.slot, crc);
+        break;
+      } //    for (j=0;j<UL_INFO.crc_ind.number_crcs;j++)
+      if (get_softmodem_params()->emulate_l1)
+      {
+        int last = UL_INFO.crc_ind.number_crcs - 1;
+        if (j < last)
+        {
+          crc_ind->crc_list[j] = crc_ind->crc_list[last];
+          UL_INFO.crc_ind.number_crcs--;
+        }
+        else if (j == last)
+        {
+          UL_INFO.crc_ind.number_crcs--;
+        }
+
+        last = UL_INFO.rx_ind.number_of_pdus - 1;
+        if (i < last)
+        {
+          rx_ind->pdu_list[i] = rx_ind->pdu_list[last];
+          UL_INFO.rx_ind.number_of_pdus--;
+          i--;
+        }
+        else if (i == last)
+        {
+          UL_INFO.rx_ind.number_of_pdus--;
+        }
+      }
+    } //   for (i=0;i<UL_INFO.rx_ind.number_of_pdus;i++)
+    if (get_softmodem_params()->emulate_l1)
+    {
+      if (UL_INFO.crc_ind.number_crcs > 0)
+      {
+        crc_ind->number_crcs = UL_INFO.crc_ind.number_crcs;
+        requeue(&gnb_crc_ind_queue, crc_ind);
+      }
+
+      if (UL_INFO.rx_ind.number_of_pdus > 0)
+      {
+        rx_ind->number_of_pdus = UL_INFO.rx_ind.number_of_pdus;
+        requeue(&gnb_rx_ind_queue, rx_ind);
+      }
+
+      if (UL_INFO.crc_ind.number_crcs == 0)
+      {
+        free(crc_ind->crc_list);
+        crc_ind->crc_list = NULL;
+        free(crc_ind);
+        crc_ind = NULL;
+      }
+      if (UL_INFO.rx_ind.number_of_pdus == 0)
+      {
+        free(rx_ind->pdu_list);
+        rx_ind->pdu_list = NULL;
+        free(rx_ind);
+        rx_ind = NULL;
+      }
+    }
+    else
+    {
       UL_info->crc_ind.number_crcs = 0;
       UL_info->rx_ind.number_of_pdus = 0;
-    } else if (UL_info->rx_ind.number_of_pdus != 0
-              || UL_info->crc_ind.number_crcs != 0) {
-      LOG_E(PHY,
-            "hoping not to have mis-match between CRC ind and RX ind - "
-            "hopefully the missing message is coming shortly "
-            "rx_ind:%d(SFN/SL:%d/%d) crc_ind:%d(SFN/SL:%d/%d) \n",
-            UL_info->rx_ind.number_of_pdus,
-            UL_info->rx_ind.sfn,
-            UL_info->rx_ind.slot,
-            UL_info->crc_ind.number_crcs,
-            UL_info->rx_ind.sfn,
-            UL_info->rx_ind.slot);
     }
+  } else if ((UL_INFO.rx_ind.number_of_pdus != 0)
+             || (UL_INFO.crc_ind.number_crcs != 0)) {
+     LOG_E(NR_PHY,
+          "hoping not to have mis-match between CRC ind and RX ind - "
+          "hopefully the missing message is coming shortly "
+          "rx_ind:%d(SFN/SL:%d/%d) crc_ind:%d(SFN/SL:%d/%d) \n",
+          UL_INFO.rx_ind.number_of_pdus,
+          UL_INFO.rx_ind.sfn,
+          UL_INFO.rx_ind.slot,
+          UL_INFO.crc_ind.number_crcs,
+          UL_INFO.crc_ind.sfn,
+          UL_INFO.crc_ind.slot);
   }
 }
 
@@ -215,10 +439,10 @@ void NR_UL_indication(NR_UL_IND_t *UL_info) {
   NR_Sched_Rsp_t   *sched_info = &NR_Sched_INFO[module_id][CC_id];
   NR_IF_Module_t   *ifi        = nr_if_inst[module_id];
   gNB_MAC_INST     *mac        = RC.nrmac[module_id];
-  LOG_D(PHY,"SFN/SF:%d%d module_id:%d CC_id:%d UL_info[rach_pdus:%d rx_ind:%d crcs:%d]\n",
+  LOG_D(NR_PHY,"SFN/SLOT:%d.%d module_id:%d CC_id:%d UL_info[rach_pdus:%zu rx_ind:%zu crcs:%zu]\n",
         UL_info->frame,UL_info->slot,
-        module_id,CC_id, UL_info->rach_ind.number_of_pdus,
-        UL_info->rx_ind.number_of_pdus, UL_info->crc_ind.number_crcs);
+        module_id,CC_id, gnb_rach_ind_queue.num_items,
+        gnb_rx_ind_queue.num_items, gnb_crc_ind_queue.num_items);
 
   handle_nr_rach(UL_info);
   
@@ -250,7 +474,7 @@ void NR_UL_indication(NR_UL_IND_t *UL_info) {
       gNB_dlsch_ulsch_scheduler(module_id,
 				(UL_info->frame+((UL_info->slot>(spf-1-sl_ahead))?1:0)) % 1024,
 				(UL_info->slot+sl_ahead)%spf);
-      
+
       ifi->CC_mask            = 0;
       sched_info->module_id   = module_id;
       sched_info->CC_id       = CC_id;
@@ -274,7 +498,7 @@ void NR_UL_indication(NR_UL_IND_t *UL_info) {
         ifi->NR_Schedule_response(sched_info);
       }
 
-      LOG_D(PHY,"NR_Schedule_response: SFN_SF:%d%d dl_pdus:%d\n",
+      LOG_D(NR_PHY,"NR_Schedule_response: SFN SLOT:%d %d dl_pdus:%d\n",
 	    sched_info->frame,
 	    sched_info->slot,
 	    sched_info->DL_req->dl_tti_request_body.nPDUs);
diff --git a/openair2/NR_PHY_INTERFACE/NR_IF_Module.h b/openair2/NR_PHY_INTERFACE/NR_IF_Module.h
index d523d6e0f0dd948db17b42dc714b0389d3aad4a4..f857151763499653ee38e8ccf79995be93ddad83 100644
--- a/openair2/NR_PHY_INTERFACE/NR_IF_Module.h
+++ b/openair2/NR_PHY_INTERFACE/NR_IF_Module.h
@@ -124,6 +124,8 @@ void NR_IF_Module_kill(int Mod_id);
 
 void NR_UL_indication(NR_UL_IND_t *UL_INFO);
 
+void RCconfig_nr_ue_L1(void);
+
 /*Interface for Downlink, transmitting the DLSCH SDU, DCI SDU*/
 void NR_Schedule_Response(NR_Sched_Rsp_t *Sched_INFO);
 
diff --git a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c
index 66c7870f80a10526debd41306c98636fb80028e0..c7b54950d7c66eb9cc16653fa1276953100a033c 100644
--- a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c
+++ b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c
@@ -37,14 +37,967 @@
 #include "NR_MAC_UE/mac_extern.h"
 #include "SCHED_NR_UE/fapi_nr_ue_l1.h"
 #include "executables/softmodem-common.h"
-
+#include "openair2/RRC/NR_UE/rrc_proto.h"
+#include "openair2/GNB_APP/L1_nr_paramdef.h"
+#include "openair2/GNB_APP/gnb_paramdef.h"
+#include "targets/ARCH/ETHERNET/USERSPACE/LIB/if_defs.h"
 #include <stdio.h>
 
 #define MAX_IF_MODULES 100
 
-const char *dl_indication_type[] = {"MIB", "SIB", "DLSCH", "DCI", "RAR"};
+UL_IND_t *UL_INFO = NULL;
 
+static eth_params_t         stub_eth_params;
 static nr_ue_if_module_t *nr_ue_if_module_inst[MAX_IF_MODULES];
+static int ue_tx_sock_descriptor = -1;
+static int ue_rx_sock_descriptor = -1;
+static int g_harq_pid;
+sem_t sfn_slot_semaphore;
+
+queue_t nr_sfn_slot_queue;
+queue_t nr_chan_param_queue;
+queue_t nr_dl_tti_req_queue;
+queue_t nr_tx_req_queue;
+queue_t nr_ul_dci_req_queue;
+queue_t nr_ul_tti_req_queue;
+queue_t nr_wait_ul_tti_req_queue;
+
+void nrue_init_standalone_socket(int tx_port, int rx_port)
+{
+  {
+    struct sockaddr_in server_address;
+    int addr_len = sizeof(server_address);
+    memset(&server_address, 0, addr_len);
+    server_address.sin_family = AF_INET;
+    server_address.sin_port = htons(tx_port);
+
+    int sd = socket(server_address.sin_family, SOCK_DGRAM, 0);
+    if (sd < 0)
+    {
+      LOG_E(MAC, "Socket creation error standalone PNF\n");
+      return;
+    }
+
+    if (inet_pton(server_address.sin_family, stub_eth_params.remote_addr, &server_address.sin_addr) <= 0)
+    {
+      LOG_E(MAC, "Invalid standalone PNF Address\n");
+      close(sd);
+      return;
+    }
+
+    // Using connect to use send() instead of sendto()
+    if (connect(sd, (struct sockaddr *)&server_address, addr_len) < 0)
+    {
+      LOG_E(MAC, "Connection to standalone PNF failed: %s\n", strerror(errno));
+      close(sd);
+      return;
+    }
+    assert(ue_tx_sock_descriptor == -1);
+    ue_tx_sock_descriptor = sd;
+    LOG_D(NR_RRC, "Successfully set up tx_socket in %s.\n", __FUNCTION__);
+  }
+
+  {
+    struct sockaddr_in server_address;
+    int addr_len = sizeof(server_address);
+    memset(&server_address, 0, addr_len);
+    server_address.sin_family = AF_INET;
+    server_address.sin_addr.s_addr = INADDR_ANY;
+    server_address.sin_port = htons(rx_port);
+
+    int sd = socket(server_address.sin_family, SOCK_DGRAM, 0);
+    if (sd < 0)
+    {
+      LOG_E(MAC, "Socket creation error standalone PNF\n");
+      return;
+    }
+
+    if (bind(sd, (struct sockaddr *)&server_address, addr_len) < 0)
+    {
+      LOG_E(MAC, "Connection to standalone PNF failed: %s\n", strerror(errno));
+      close(sd);
+      return;
+    }
+    assert(ue_rx_sock_descriptor == -1);
+    ue_rx_sock_descriptor = sd;
+    LOG_D(NR_RRC, "Successfully set up rx_socket in %s.\n", __FUNCTION__);
+  }
+  LOG_I(NR_RRC, "NRUE standalone socket info: tx_port %d  rx_port %d on %s.\n",
+        tx_port, rx_port, stub_eth_params.remote_addr);
+}
+
+void send_nsa_standalone_msg(NR_UL_IND_t *UL_INFO, uint16_t msg_id)
+{
+  switch(msg_id)
+  {
+    case NFAPI_NR_PHY_MSG_TYPE_RACH_INDICATION:
+    {
+        char buffer[NFAPI_MAX_PACKED_MESSAGE_SIZE];
+        LOG_D(NR_MAC, "RACH header id :%d", UL_INFO->rach_ind.header.message_id);
+        int encoded_size = nfapi_nr_p7_message_pack(&UL_INFO->rach_ind, buffer, sizeof(buffer), NULL);
+        if (encoded_size <= 0)
+        {
+                LOG_E(NR_MAC, "nfapi_nr_p7_message_pack has failed. Encoded size = %d\n", encoded_size);
+                return;
+        }
+
+        LOG_I(NR_MAC, "NR_RACH_IND sent to Proxy, Size: %d Frame %d Slot %d Num PDUS %d\n", encoded_size,
+                UL_INFO->rach_ind.sfn, UL_INFO->rach_ind.slot, UL_INFO->rach_ind.number_of_pdus);
+        if (send(ue_tx_sock_descriptor, buffer, encoded_size, 0) < 0)
+        {
+                LOG_E(NR_MAC, "Send Proxy NR_UE failed\n");
+                return;
+        }
+        break;
+    }
+    case NFAPI_NR_PHY_MSG_TYPE_RX_DATA_INDICATION:
+    {
+        char buffer[NFAPI_MAX_PACKED_MESSAGE_SIZE];
+        LOG_D(NR_MAC, "RX header id :%d", UL_INFO->rx_ind.header.message_id);
+        int encoded_size = nfapi_nr_p7_message_pack(&UL_INFO->rx_ind, buffer, sizeof(buffer), NULL);
+        if (encoded_size <= 0)
+        {
+                LOG_E(NR_MAC, "nfapi_nr_p7_message_pack has failed. Encoded size = %d\n", encoded_size);
+                return;
+        }
+
+        LOG_I(NR_MAC, "NR_RX_IND sent to Proxy, Size: %d Frame %d Slot %d Num PDUS %d\n", encoded_size,
+                UL_INFO->rx_ind.sfn, UL_INFO->rx_ind.slot, UL_INFO->rx_ind.number_of_pdus);
+        if (send(ue_tx_sock_descriptor, buffer, encoded_size, 0) < 0)
+        {
+                LOG_E(NR_MAC, "Send Proxy NR_UE failed\n");
+                return;
+        }
+        break;
+    }
+    case NFAPI_NR_PHY_MSG_TYPE_CRC_INDICATION:
+    {
+        char buffer[NFAPI_MAX_PACKED_MESSAGE_SIZE];
+        LOG_D(NR_MAC, "CRC header id :%d", UL_INFO->crc_ind.header.message_id);
+        int encoded_size = nfapi_nr_p7_message_pack(&UL_INFO->crc_ind, buffer, sizeof(buffer), NULL);
+        if (encoded_size <= 0)
+        {
+                LOG_E(NR_MAC, "nfapi_nr_p7_message_pack has failed. Encoded size = %d\n", encoded_size);
+                return;
+        }
+
+        LOG_I(NR_MAC, "NR_CRC_IND sent to Proxy, Size: %d Frame %d Slot %d Num PDUS %d\n", encoded_size,
+                UL_INFO->crc_ind.sfn, UL_INFO->crc_ind.slot, UL_INFO->crc_ind.number_crcs);
+        if (send(ue_tx_sock_descriptor, buffer, encoded_size, 0) < 0)
+        {
+                LOG_E(NR_MAC, "Send Proxy NR_UE failed\n");
+                return;
+        }
+        break;
+    }
+    case NFAPI_NR_PHY_MSG_TYPE_UCI_INDICATION:
+    {
+        char buffer[NFAPI_MAX_PACKED_MESSAGE_SIZE];
+        LOG_I(NR_MAC, "UCI header id :%d", UL_INFO->uci_ind.header.message_id);
+        int encoded_size = nfapi_nr_p7_message_pack(&UL_INFO->uci_ind, buffer, sizeof(buffer), NULL);
+        if (encoded_size <= 0)
+        {
+                LOG_E(NR_MAC, "nfapi_nr_p7_message_pack has failed. Encoded size = %d\n", encoded_size);
+                return;
+        }
+
+        LOG_I(NR_MAC, "NR_UCI_IND sent to Proxy, Size: %d Frame %d Slot %d Num PDUS %d\n", encoded_size,
+                UL_INFO->uci_ind.sfn, UL_INFO->uci_ind.slot, UL_INFO->uci_ind.num_ucis);
+        if (send(ue_tx_sock_descriptor, buffer, encoded_size, 0) < 0)
+        {
+                LOG_E(NR_MAC, "Send Proxy NR_UE failed\n");
+                return;
+        }
+        break;
+    }
+    case NFAPI_NR_PHY_MSG_TYPE_SRS_INDICATION:
+    break;
+    default:
+    break;
+  }
+}
+
+static void fill_dl_info_with_pdcch(fapi_nr_dci_indication_t *dci, nfapi_nr_dl_dci_pdu_t *rx_dci, int idx)
+{
+    int num_bytes = (rx_dci->PayloadSizeBits + 7) / 8;
+    LOG_I(NR_PHY, "[%d, %d] PDCCH DCI (Payload) for rnti %x with PayloadSizeBits %d, num_bytes %d\n",
+          dci->SFN, dci->slot, rx_dci->RNTI, rx_dci->PayloadSizeBits, num_bytes);
+    for (int k = 0; k < num_bytes; k++)
+    {
+        LOG_I(NR_MAC, "PDCCH DCI PDU payload[%d] = %d\n", k, rx_dci->Payload[k]);
+        dci->dci_list[idx].payloadBits[k] = rx_dci->Payload[k];
+    }
+    dci->dci_list[idx].payloadSize = rx_dci->PayloadSizeBits;
+    dci->dci_list[idx].rnti = rx_dci->RNTI;
+    dci->number_of_dcis = idx + 1;
+}
+
+static void fill_mib_in_rx_ind(nfapi_nr_dl_tti_request_pdu_t *pdu_list, fapi_nr_rx_indication_t *rx_ind, int pdu_idx, int pdu_type)
+{
+    AssertFatal(pdu_idx < sizeof(rx_ind->rx_indication_body) / sizeof(rx_ind->rx_indication_body[0]),
+                "pdu_index (%d) is greater than rx_indication_body size!\n", pdu_idx);
+    AssertFatal(pdu_idx == rx_ind->number_pdus,  "Invalid pdu_idx %d!\n", pdu_idx);
+
+    LOG_D(NR_MAC, "Recevied an SSB and are filling rx_ind with the MIB!\n");
+
+    nfapi_nr_dl_tti_ssb_pdu_rel15_t *ssb_pdu = &pdu_list->ssb_pdu.ssb_pdu_rel15;
+    rx_ind->rx_indication_body[pdu_idx].ssb_pdu.cell_id = ssb_pdu->PhysCellId;
+    rx_ind->rx_indication_body[pdu_idx].ssb_pdu.pdu = MALLOC(3 * sizeof(*rx_ind->rx_indication_body[pdu_idx].ssb_pdu.pdu));
+    rx_ind->rx_indication_body[pdu_idx].ssb_pdu.pdu[0] = (ssb_pdu->bchPayload) & 0xff;
+    rx_ind->rx_indication_body[pdu_idx].ssb_pdu.pdu[1] = (ssb_pdu->bchPayload >> 8) & 0xff;
+    rx_ind->rx_indication_body[pdu_idx].ssb_pdu.pdu[2] = (ssb_pdu->bchPayload >> 16) & 0xff;
+    rx_ind->rx_indication_body[pdu_idx].ssb_pdu.rsrp_dBm = ssb_pdu->ssbRsrp;
+    rx_ind->rx_indication_body[pdu_idx].ssb_pdu.ssb_index = ssb_pdu->SsbBlockIndex;
+    rx_ind->rx_indication_body[pdu_idx].ssb_pdu.ssb_length = pdu_list->PDUSize;
+    rx_ind->rx_indication_body[pdu_idx].ssb_pdu.ssb_start_subcarrier = ssb_pdu->SsbSubcarrierOffset;
+    rx_ind->rx_indication_body[pdu_idx].pdu_type = pdu_type;
+    rx_ind->number_pdus = pdu_idx + 1;
+
+}
+
+static bool is_my_dci(NR_UE_MAC_INST_t *mac, nfapi_nr_dl_dci_pdu_t *received_pdu)
+{
+    /* For multiple UEs, we need to be able to filter the rx'd messages by
+       the RNTI. The filtering is different between NSA mode and SA mode.
+       NSA mode has a two step CFRA procedure and SA has a 4 step procedure.
+       We only need to check if the rx'd RNTI doesnt match the CRNTI if the RAR
+       has been processed already, in NSA mode.
+       In SA, depending on the RA state, we can have a SIB (0xffff), RAR (0x10b),
+       Msg3 (TC_RNTI) or an actual DCI message (CRNTI). When we get Msg3, the
+       MAC instance of the UE still has a CRNTI = 0. We should only check if the
+       CRNTI doesnt match the received RNTI in SA mode if Msg3 has been processed
+       already. Only once the RA procedure succeeds is the CRNTI value updated
+       to the TC_RNTI. */
+    if (get_softmodem_params()->nsa)
+    {
+        if (received_pdu->RNTI != mac->crnti &&
+            (received_pdu->RNTI != mac->ra.ra_rnti || mac->ra.RA_RAPID_found))
+            return false;
+    }
+    if (get_softmodem_params()->sa)
+    {
+        if (received_pdu->RNTI != mac->crnti && mac->ra.ra_state == RA_SUCCEEDED)
+            return false;
+        if (received_pdu->RNTI != mac->ra.t_crnti && mac->ra.ra_state == WAIT_CONTENTION_RESOLUTION)
+            return false;
+        if (received_pdu->RNTI != 0x10b && mac->ra.ra_state == WAIT_RAR)
+            return false;
+        if (received_pdu->RNTI != 0xFFFF && mac->ra.ra_state <= GENERATE_PREAMBLE)
+            return false;
+    }
+    return true;
+}
+
+static void copy_dl_tti_req_to_dl_info(nr_downlink_indication_t *dl_info, nfapi_nr_dl_tti_request_t *dl_tti_request)
+{
+    NR_UE_MAC_INST_t *mac = get_mac_inst(dl_info->module_id);
+    mac->nr_ue_emul_l1.expected_sib = false;
+    memset(mac->nr_ue_emul_l1.index_has_sib, 0, sizeof(*mac->nr_ue_emul_l1.index_has_sib));
+    mac->nr_ue_emul_l1.expected_rar = false;
+    memset(mac->nr_ue_emul_l1.index_has_rar, 0, sizeof(*mac->nr_ue_emul_l1.index_has_rar));
+    mac->nr_ue_emul_l1.expected_dci = false;
+    memset(mac->nr_ue_emul_l1.index_has_dci, 0, sizeof(*mac->nr_ue_emul_l1.index_has_dci));
+    int pdu_idx = 0;
+
+    int num_pdus = dl_tti_request->dl_tti_request_body.nPDUs;
+    AssertFatal(num_pdus >= 0, "Invalid dl_tti_request number of PDUS\n");
+
+    for (int i = 0; i < num_pdus; i++)
+    {
+        nfapi_nr_dl_tti_request_pdu_t *pdu_list = &dl_tti_request->dl_tti_request_body.dl_tti_pdu_list[i];
+        if (pdu_list->PDUType == NFAPI_NR_DL_TTI_PDSCH_PDU_TYPE)
+        {
+            LOG_I(NR_PHY, "[%d, %d] PDSCH PDU for rnti %x\n",
+                dl_tti_request->SFN, dl_tti_request->Slot, pdu_list->pdsch_pdu.pdsch_pdu_rel15.rnti);
+        }
+
+        if (pdu_list->PDUType == NFAPI_NR_DL_TTI_PDCCH_PDU_TYPE)
+        {
+            LOG_I(NR_PHY, "[%d, %d] PDCCH DCI PDU (Format for incoming PDSCH PDU)\n",
+                dl_tti_request->SFN, dl_tti_request->Slot);
+            uint16_t num_dcis = pdu_list->pdcch_pdu.pdcch_pdu_rel15.numDlDci;
+            if (num_dcis > 0)
+            {
+                if (!dl_info->dci_ind)
+                {
+                    dl_info->dci_ind = CALLOC(1, sizeof(fapi_nr_dci_indication_t));
+                }
+                dl_info->dci_ind->SFN = dl_tti_request->SFN;
+                dl_info->dci_ind->slot = dl_tti_request->Slot;
+                AssertFatal(num_dcis <= sizeof(dl_info->dci_ind->dci_list) / sizeof(dl_info->dci_ind->dci_list[0]),
+                            "The number of DCIs is greater than dci_list");
+                for (int j = 0; j < num_dcis; j++)
+                {
+                    nfapi_nr_dl_dci_pdu_t *dci_pdu_list = &pdu_list->pdcch_pdu.pdcch_pdu_rel15.dci_pdu[j];
+                    if (!is_my_dci(mac, dci_pdu_list))
+                    {
+                        continue;
+                    }
+                    fill_dl_info_with_pdcch(dl_info->dci_ind, dci_pdu_list, pdu_idx);
+                    if (dci_pdu_list->RNTI == 0xffff)
+                    {
+                        mac->nr_ue_emul_l1.expected_sib = true;
+                        mac->nr_ue_emul_l1.index_has_sib[j] = true;
+                        LOG_D(NR_MAC, "Setting index_has_sib[%d] = true\n", j);
+                    }
+                    else if (dci_pdu_list->RNTI == mac->ra.ra_rnti)
+                    {
+                        mac->nr_ue_emul_l1.expected_rar = true;
+                        mac->nr_ue_emul_l1.index_has_rar[j] = true;
+                        LOG_D(NR_MAC, "Setting index_has_rar[%d] = true\n", j);
+                    }
+                    else
+                    {
+                        mac->nr_ue_emul_l1.expected_dci = true;
+                        mac->nr_ue_emul_l1.index_has_dci[j] = true;
+                        LOG_D(NR_MAC, "Setting index_has_dci[%d] = true\n", j);
+                    }
+                    pdu_idx++;
+                }
+            }
+        }
+        if (pdu_list->PDUType == NFAPI_NR_DL_TTI_SSB_PDU_TYPE)
+        {
+            /* If we get a MIB, we want to handle it right away and then come back.
+               The MIB and SIB come in the same dl_tti_req but the MIB should be
+               processed first and then the DCI and payload of the SIB1 can be
+               processed. The MIB should be handled first and then the rx_ind
+               will be freed after handling. This is why the PDU index will
+               always be zero for the RX_IND becasue we should not have more than
+               one MIB. */
+            if (!dl_info->rx_ind)
+            {
+                dl_info->rx_ind = CALLOC(1, sizeof(*dl_info->rx_ind));
+            }
+            fapi_nr_rx_indication_t *rx_ind = dl_info->rx_ind;
+            rx_ind->sfn = dl_tti_request->SFN;
+            rx_ind->slot = dl_tti_request->Slot;
+            fill_mib_in_rx_ind(pdu_list, rx_ind, 0, FAPI_NR_RX_PDU_TYPE_SSB);
+            NR_UL_TIME_ALIGNMENT_t ul_time_alignment;
+            memset(&ul_time_alignment, 0, sizeof(ul_time_alignment));
+            nr_ue_dl_indication(&mac->dl_info, &ul_time_alignment);
+        }
+    }
+    dl_info->slot = dl_tti_request->Slot;
+    dl_info->frame = dl_tti_request->SFN;
+}
+
+static void fill_rx_ind(nfapi_nr_pdu_t *pdu_list, fapi_nr_rx_indication_t *rx_ind, int pdu_idx, int pdu_type)
+{
+    AssertFatal(pdu_list->num_TLV < sizeof(pdu_list->TLVs) / sizeof(pdu_list->TLVs[0]), "Num TLVs exceeds TLV array size");
+    int length = 0;
+    for (int j = 0; j < pdu_list->num_TLV; j++)
+    {
+        length += pdu_list->TLVs[j].length;
+    }
+    LOG_I(NR_PHY, "%s: num_tlv %d and length %d, pdu index %d\n",
+        __FUNCTION__, pdu_list->num_TLV, length, pdu_idx);
+    uint8_t *pdu = malloc(length);
+    AssertFatal(pdu != NULL, "%s: Out of memory in malloc", __FUNCTION__);
+    rx_ind->rx_indication_body[pdu_idx].pdsch_pdu.pdu = pdu;
+    for (int j = 0; j < pdu_list->num_TLV; j++)
+    {
+        const uint32_t *ptr;
+        if (pdu_list->TLVs[j].tag)
+            ptr = pdu_list->TLVs[j].value.ptr;
+        else
+            ptr = pdu_list->TLVs[j].value.direct;
+        memcpy(pdu, ptr, pdu_list->TLVs[j].length);
+        pdu += pdu_list->TLVs[j].length;
+    }
+    rx_ind->rx_indication_body[pdu_idx].pdsch_pdu.ack_nack = 1;
+    rx_ind->rx_indication_body[pdu_idx].pdsch_pdu.pdu_length = length;
+    rx_ind->rx_indication_body[pdu_idx].pdu_type = pdu_type;
+
+}
+
+
+static void copy_tx_data_req_to_dl_info(nr_downlink_indication_t *dl_info, nfapi_nr_tx_data_request_t *tx_data_request)
+{
+    NR_UE_MAC_INST_t *mac = get_mac_inst(dl_info->module_id);
+    int num_pdus = tx_data_request->Number_of_PDUs;
+    AssertFatal(num_pdus >= 0, "Invalid tx_data_request number of PDUS\n");
+
+    if (!dl_info->rx_ind)
+    {
+        dl_info->rx_ind = CALLOC(1, sizeof(fapi_nr_rx_indication_t));
+    }
+    AssertFatal(dl_info->rx_ind != NULL, "%s: Out of memory in calloc", __FUNCTION__);
+    fapi_nr_rx_indication_t *rx_ind = dl_info->rx_ind;
+    rx_ind->sfn = tx_data_request->SFN;
+    rx_ind->slot = tx_data_request->Slot;
+
+    int pdu_idx = 0;
+
+    for (int i = 0; i < num_pdus; i++)
+    {
+        nfapi_nr_pdu_t *pdu_list = &tx_data_request->pdu_list[i];
+        if (mac->nr_ue_emul_l1.index_has_sib[i])
+        {
+            AssertFatal(!get_softmodem_params()->nsa,
+                        "Should not be processing SIB in NSA mode, something bad happened\n");
+            fill_rx_ind(pdu_list, rx_ind, pdu_idx, FAPI_NR_RX_PDU_TYPE_SIB);
+            pdu_idx++;
+        }
+        else if (mac->nr_ue_emul_l1.index_has_rar[i])
+        {
+            fill_rx_ind(pdu_list, rx_ind, pdu_idx, FAPI_NR_RX_PDU_TYPE_RAR);
+            pdu_idx++;
+        }
+        else if (mac->nr_ue_emul_l1.index_has_dci[i])
+        {
+            fill_rx_ind(pdu_list, rx_ind, pdu_idx, FAPI_NR_RX_PDU_TYPE_DLSCH);
+            pdu_idx++;
+        }
+        else
+        {
+            LOG_D(NR_MAC, "mac->nr_ue_emul_l1.index_has_dci[%d] = 0, so this index contained a DCI for a different UE\n", i);
+        }
+
+    }
+    dl_info->slot = tx_data_request->Slot;
+    dl_info->frame = tx_data_request->SFN;
+    dl_info->rx_ind->number_pdus = pdu_idx;
+}
+
+static void copy_ul_dci_data_req_to_dl_info(nr_downlink_indication_t *dl_info, nfapi_nr_ul_dci_request_t *ul_dci_req)
+{
+    NR_UE_MAC_INST_t *mac = get_mac_inst(dl_info->module_id);
+    int pdu_idx = 0;
+
+    int num_pdus = ul_dci_req->numPdus;
+    AssertFatal(num_pdus >= 0, "Invalid ul_dci_request number of PDUS\n");
+
+    for (int i = 0; i < num_pdus; i++)
+    {
+        nfapi_nr_ul_dci_request_pdus_t *pdu_list = &ul_dci_req->ul_dci_pdu_list[i];
+        AssertFatal(pdu_list->PDUType == 0, "ul_dci_req pdu type != PUCCH");
+        LOG_I(NR_PHY, "[%d %d] PUCCH PDU in ul_dci for rnti %x and numDLDCI = %d\n",
+             ul_dci_req->SFN, ul_dci_req->Slot, pdu_list->pdcch_pdu.pdcch_pdu_rel15.dci_pdu->RNTI,
+             pdu_list->pdcch_pdu.pdcch_pdu_rel15.numDlDci);
+        uint16_t num_dci = pdu_list->pdcch_pdu.pdcch_pdu_rel15.numDlDci;
+        if (num_dci > 0)
+        {
+            if (!dl_info->dci_ind)
+            {
+                dl_info->dci_ind = CALLOC(1, sizeof(fapi_nr_dci_indication_t));
+            }
+            AssertFatal(dl_info->dci_ind != NULL, "%s: Out of memory in calloc", __FUNCTION__);
+            dl_info->dci_ind->SFN = ul_dci_req->SFN;
+            dl_info->dci_ind->slot = ul_dci_req->Slot;
+            AssertFatal(num_dci < sizeof(dl_info->dci_ind->dci_list) / sizeof(dl_info->dci_ind->dci_list[0]), "The number of DCIs is greater than dci_list");
+            for (int j = 0; j < num_dci; j++)
+            {
+                nfapi_nr_dl_dci_pdu_t *dci_pdu_list = &pdu_list->pdcch_pdu.pdcch_pdu_rel15.dci_pdu[j];
+                if (dci_pdu_list->RNTI != mac->crnti)
+                {
+                  LOG_D(NR_MAC, "dci_pdu_list->RNTI (%x) != mac->crnti (%x)\n", dci_pdu_list->RNTI, mac->crnti);
+                  continue;
+                }
+                fill_dl_info_with_pdcch(dl_info->dci_ind, dci_pdu_list, pdu_idx);
+                pdu_idx++;
+            }
+        }
+    }
+    dl_info->frame = ul_dci_req->SFN;
+    dl_info->slot = ul_dci_req->Slot;
+}
+
+static nfapi_nr_uci_indication_t *multiplex_uci_ind(NR_UE_MAC_INST_t *mac, int num_active_harqs)
+{
+    AssertFatal(num_active_harqs >= 0, "Invalid value for num_active_harqs %d\n", num_active_harqs);
+    if (num_active_harqs == 0)
+    {
+        return NULL;
+    }
+    if (num_active_harqs != nr_uci_ind_queue.num_items)
+    {
+        LOG_I(NR_MAC, "The number of active harqs %d doesn't match the number of UCIs in the queue %lu\n",
+                       num_active_harqs, nr_uci_ind_queue.num_items);
+        return NULL;
+    }
+
+    nfapi_nr_uci_indication_t *uci_ind = MALLOC(sizeof(*uci_ind));
+    uci_ind->header.message_id = NFAPI_NR_PHY_MSG_TYPE_UCI_INDICATION;
+    uci_ind->sfn = NFAPI_SFNSLOT2SFN(mac->nr_ue_emul_l1.active_harq_sfn_slot);
+    uci_ind->slot = NFAPI_SFNSLOT2SLOT(mac->nr_ue_emul_l1.active_harq_sfn_slot);
+    uci_ind->num_ucis = num_active_harqs;
+    uci_ind->uci_list = CALLOC(uci_ind->num_ucis, sizeof(*uci_ind->uci_list));
+    for (int i = 0; i < num_active_harqs; i++)
+    {
+        nfapi_nr_uci_indication_t *queued_uci_ind = get_queue(&nr_uci_ind_queue);
+        AssertFatal(queued_uci_ind, "There was not a UCI in the queue!\n");
+        nfapi_nr_uci_pucch_pdu_format_0_1_t *pdu_0_1 = &uci_ind->uci_list[i].pucch_pdu_format_0_1;
+
+        /* In openair1/SCHED_NR_UE/fapi_nr_ue_l1.c nr_ue_schedule_response_stub(), the
+        number of UCIs is hard coded to 1. This is why we always use index 0 of the
+        queued UCI indication to fill the new multiplexed UCI indication */
+        AssertFatal(queued_uci_ind->num_ucis == 1, "The number of UCIs from de-queueud UCI is not 1, its %d\n",
+                    queued_uci_ind->num_ucis);
+        uci_ind->uci_list[i].pdu_type = queued_uci_ind->uci_list[0].pdu_type;
+        uci_ind->uci_list[i].pdu_size = queued_uci_ind->uci_list[0].pdu_size;
+
+        nfapi_nr_uci_pucch_pdu_format_0_1_t *queued_pdu_0_1 = &queued_uci_ind->uci_list[0].pucch_pdu_format_0_1;
+        pdu_0_1->handle = queued_pdu_0_1->handle;
+        pdu_0_1->rnti = queued_pdu_0_1->rnti;
+        pdu_0_1->pucch_format = queued_pdu_0_1->pucch_format;
+        pdu_0_1->ul_cqi = queued_pdu_0_1->ul_cqi;
+        pdu_0_1->timing_advance = queued_pdu_0_1->timing_advance;
+        pdu_0_1->rssi = queued_pdu_0_1->rssi;
+        free(queued_uci_ind->uci_list);
+        queued_uci_ind->uci_list = NULL;
+        free(queued_uci_ind);
+        queued_uci_ind = NULL;
+    }
+    return uci_ind;
+}
+
+static void copy_ul_tti_data_req_to_dl_info(nr_downlink_indication_t *dl_info, nfapi_nr_ul_tti_request_t *ul_tti_req)
+{
+    NR_UE_MAC_INST_t *mac = get_mac_inst(dl_info->module_id);
+    int num_pdus = ul_tti_req->n_pdus;
+    AssertFatal(num_pdus >= 0, "Invalid ul_tti_request number of PDUS\n");
+    AssertFatal(num_pdus <= sizeof(ul_tti_req->pdus_list) / sizeof(ul_tti_req->pdus_list[0]),
+                "Too many pdus %d in ul_tti_req\n", num_pdus);
+
+    bool sent_uci = false;
+    for (int i = 0; i < num_pdus; i++)
+    {
+        nfapi_nr_ul_tti_request_number_of_pdus_t *pdu_list = &ul_tti_req->pdus_list[i];
+        LOG_D(NR_PHY, "This is the pdu type %d and rnti %x and SR flag %d and harq_pdu_len %d in in ul_tti_req\n",
+              pdu_list->pdu_type, ul_tti_req->pdus_list[i].pucch_pdu.rnti, pdu_list->pucch_pdu.sr_flag, pdu_list->pucch_pdu.bit_len_harq);
+        if (pdu_list->pdu_type == NFAPI_NR_UL_CONFIG_PUCCH_PDU_TYPE && pdu_list->pucch_pdu.rnti == mac->crnti)
+        {
+            AssertFatal(nr_uci_ind_queue.num_items >= 0, "Invalid num_items in UCI_ind queue %lu\n",
+                        nr_uci_ind_queue.num_items);
+            int num_active_harqs = pdu_list->pucch_pdu.bit_len_harq;
+            LOG_I(NR_MAC, "The number of active harqs %d from ul_tti_req\n", num_active_harqs);
+            nfapi_nr_uci_indication_t *uci_ind = multiplex_uci_ind(mac, num_active_harqs);
+
+            if (uci_ind && uci_ind->num_ucis > 0)
+            {
+                LOG_D(NR_MAC, "This is the SFN/SF [%d, %d] and RNTI %x of the UCI ind. ul_tti_req.pdu[%d]->rnti = %x \n",
+                        uci_ind->sfn, uci_ind->slot, uci_ind->uci_list[0].pucch_pdu_format_0_1.rnti, i, ul_tti_req->pdus_list[i].pucch_pdu.rnti);
+                uci_ind->sfn = ul_tti_req->SFN;
+                uci_ind->slot = ul_tti_req->Slot;
+                for (int j = 0; j < uci_ind->num_ucis; j++)
+                {
+                    nfapi_nr_uci_pucch_pdu_format_0_1_t *pdu_0_1 = &uci_ind->uci_list[j].pucch_pdu_format_0_1;
+                    if (pdu_list->pucch_pdu.sr_flag)
+                    {
+                        LOG_D(NR_MAC, "We have the SR flag in pdu i %d\n", i);
+                        pdu_0_1->pduBitmap = 1; // (value->pduBitmap >> 1) & 0x01) == HARQ and (value->pduBitmap) & 0x01) == SR
+                        pdu_0_1->sr = CALLOC(1, sizeof(*pdu_0_1->sr));
+                        pdu_0_1->sr->sr_confidence_level = 0;
+                        pdu_0_1->sr->sr_indication = 1;
+                    }
+                    if (pdu_list->pucch_pdu.bit_len_harq > 0)
+                    {
+                        LOG_D(NR_MAC, "We have the Harq len bits %d\n", pdu_list->pucch_pdu.bit_len_harq);
+                        pdu_0_1->pduBitmap = 2; // (value->pduBitmap >> 1) & 0x01) == HARQ and (value->pduBitmap) & 0x01) == SR
+                        pdu_0_1->harq = CALLOC(1, sizeof(*pdu_0_1->harq));
+                        pdu_0_1->harq->num_harq = 1;
+                        pdu_0_1->harq->harq_confidence_level = 0;
+                        pdu_0_1->harq->harq_list = CALLOC(pdu_0_1->harq->num_harq, sizeof(*pdu_0_1->harq->harq_list));
+                        for (int k = 0; k < pdu_0_1->harq->num_harq; k++)
+                        {
+                            pdu_0_1->harq->harq_list[k].harq_value = 0;
+                        }
+                    }
+                }
+                LOG_I(NR_MAC, "We have dequeued the previously filled uci_ind and updated the snf/slot to %d/%d.\n",
+                      uci_ind->sfn, uci_ind->slot);
+                NR_UL_IND_t UL_INFO = {
+                    .uci_ind = *uci_ind,
+                };
+                send_nsa_standalone_msg(&UL_INFO, uci_ind->header.message_id);
+                sent_uci = true;
+
+                for (int k = 0; k < uci_ind->num_ucis; k++)
+                {
+                    nfapi_nr_uci_pucch_pdu_format_0_1_t *pdu_0_1 = &uci_ind->uci_list[k].pucch_pdu_format_0_1;
+                    if (pdu_list->pucch_pdu.sr_flag)
+                    {
+                        free(pdu_0_1->sr);
+                        pdu_0_1->sr = NULL;
+                    }
+                    if (pdu_list->pucch_pdu.bit_len_harq > 1)
+                    {
+                        free(pdu_0_1->harq->harq_list);
+                        pdu_0_1->harq->harq_list = NULL;
+                        free(pdu_0_1->harq);
+                        pdu_0_1->harq = NULL;
+                    }
+                }
+                free(uci_ind->uci_list);
+                uci_ind->uci_list = NULL;
+                free(uci_ind);
+                uci_ind = NULL;
+            }
+        }
+    }
+    if (!sent_uci)
+    {
+        LOG_E(NR_MAC, "UCI ind not sent\n");
+        if (!put_queue(&nr_ul_tti_req_queue, ul_tti_req))
+        {
+            LOG_E(NR_PHY, "put_queue failed for ul_tti_req.\n");
+            free(ul_tti_req);
+            ul_tti_req = NULL;
+        }
+    }
+}
+
+static void fill_dci_from_dl_config(nr_downlink_indication_t*dl_ind, fapi_nr_dl_config_request_t *dl_config)
+{
+  if (!dl_ind->dci_ind)
+  {
+    return;
+  }
+
+  AssertFatal(dl_config->number_pdus < sizeof(dl_config->dl_config_list) / sizeof(dl_config->dl_config_list[0]),
+              "Too many dl_config pdus %d", dl_config->number_pdus);
+  for (int i = 0; i < dl_config->number_pdus; i++)
+  {
+    LOG_I(PHY, "In %s: filling DCI with a total of %d total DL PDUs (dl_config %p) \n",
+          __FUNCTION__, dl_config->number_pdus, dl_config);
+    fapi_nr_dl_config_dci_dl_pdu_rel15_t *rel15_dci = &dl_config->dl_config_list[i].dci_config_pdu.dci_config_rel15;
+    int num_dci_options = rel15_dci->num_dci_options;
+    if (num_dci_options <= 0)
+    {
+      LOG_I(NR_MAC, "num_dci_opts = %d for pdu[%d] in dl_config_list\n", rel15_dci->num_dci_options, i);
+    }
+    AssertFatal(num_dci_options <= sizeof(rel15_dci->dci_length_options) / sizeof(rel15_dci->dci_length_options[0]),
+                "num_dci_options %d > dci_length_options array\n", num_dci_options);
+    AssertFatal(num_dci_options <= sizeof(rel15_dci->dci_format_options) / sizeof(rel15_dci->dci_format_options[0]),
+                "num_dci_options %d > dci_format_options array\n", num_dci_options);
+
+    for (int j = 0; j < num_dci_options; j++)
+    {
+      int num_dcis = dl_ind->dci_ind->number_of_dcis;
+      AssertFatal(num_dcis <= sizeof(dl_ind->dci_ind->dci_list) / sizeof(dl_ind->dci_ind->dci_list[0]),
+                  "dl_config->number_pdus %d > dci_ind->dci_list array\n", num_dcis);
+      for (int k = 0; k < num_dcis; k++)
+      {
+        LOG_I(NR_PHY, "Received len %d, length options[%d] %d, format assigned %d, format options[%d] %d\n",
+                  dl_ind->dci_ind->dci_list[k].payloadSize, j, rel15_dci->dci_length_options[j],
+                  dl_ind->dci_ind->dci_list[k].dci_format, j, rel15_dci->dci_format_options[j]);
+        if (rel15_dci->dci_length_options[j] == dl_ind->dci_ind->dci_list[k].payloadSize)
+        {
+            dl_ind->dci_ind->dci_list[k].dci_format = rel15_dci->dci_format_options[j];
+        }
+        int CCEind = rel15_dci->CCE[j];
+        int L = rel15_dci->L[j];
+        dl_ind->dci_ind->dci_list[k].n_CCE = CCEind;
+        dl_ind->dci_ind->dci_list[k].N_CCE = L;
+      }
+    }
+  }
+}
+
+void check_and_process_dci(nfapi_nr_dl_tti_request_t *dl_tti_request,
+                           nfapi_nr_tx_data_request_t *tx_data_request,
+                           nfapi_nr_ul_dci_request_t *ul_dci_request,
+                           nfapi_nr_ul_tti_request_t *ul_tti_request)
+{
+    frame_t frame = 0;
+    int slot = 0;
+    NR_UE_MAC_INST_t *mac = get_mac_inst(0);
+
+    if (pthread_mutex_lock(&mac->mutex_dl_info)) abort();
+
+    if (dl_tti_request)
+    {
+        frame = dl_tti_request->SFN;
+        slot = dl_tti_request->Slot;
+        LOG_I(NR_PHY, "[%d, %d] dl_tti_request\n", frame, slot);
+        copy_dl_tti_req_to_dl_info(&mac->dl_info, dl_tti_request);
+    }
+    /* This checks if the previously recevied DCI matches our current RNTI
+       value. The assumption is that if the DCI matches our RNTI, then the
+       incoming tx_data_request is also destined for the current UE. If the
+       RAR hasn't been processed yet, we do not want to be filtering the
+       tx_data_requests. */
+    if (tx_data_request && (mac->nr_ue_emul_l1.expected_sib ||
+                            mac->nr_ue_emul_l1.expected_rar ||
+                            mac->nr_ue_emul_l1.expected_dci))
+    {
+        frame = tx_data_request->SFN;
+        slot = tx_data_request->Slot;
+        LOG_I(NR_PHY, "[%d, %d] PDSCH in tx_request\n", frame, slot);
+        copy_tx_data_req_to_dl_info(&mac->dl_info, tx_data_request);
+    }
+    else if (ul_dci_request)
+    {
+        frame = ul_dci_request->SFN;
+        slot = ul_dci_request->Slot;
+        LOG_I(NR_PHY, "[%d, %d] ul_dci_request\n", frame, slot);
+        copy_ul_dci_data_req_to_dl_info(&mac->dl_info, ul_dci_request);
+    }
+    else if (ul_tti_request)
+    {
+        frame = ul_tti_request->SFN;
+        slot = ul_tti_request->Slot;
+        LOG_I(NR_PHY, "[%d, %d] ul_tti_request\n", frame, slot);
+        copy_ul_tti_data_req_to_dl_info(&mac->dl_info, ul_tti_request);
+    }
+    else
+    {
+        if (pthread_mutex_unlock(&mac->mutex_dl_info)) abort();
+        LOG_E(NR_MAC, "Error! All indications were NULL\n");
+        return;
+    }
+
+
+    NR_UL_TIME_ALIGNMENT_t ul_time_alignment;
+    memset(&ul_time_alignment, 0, sizeof(ul_time_alignment));
+    fill_dci_from_dl_config(&mac->dl_info, &mac->dl_config_request);
+    nr_ue_dl_indication(&mac->dl_info, &ul_time_alignment);
+
+    if (pthread_mutex_unlock(&mac->mutex_dl_info)) abort();
+
+    // If we filled dl_info AFTER we got the slot indication, we want to check if we should fill tx_req:
+    nr_uplink_indication_t ul_info;
+    memset(&ul_info, 0, sizeof(ul_info));
+    int slots_per_frame = 20; //30 kHZ subcarrier spacing
+    int slot_ahead = 2; // TODO: Make this dynamic
+    ul_info.frame_rx = frame;
+    ul_info.slot_rx = slot;
+    ul_info.slot_tx = (slot + slot_ahead) % slots_per_frame;
+    ul_info.frame_tx = (ul_info.slot_rx + slot_ahead >= slots_per_frame) ? ul_info.frame_rx + 1 : ul_info.frame_rx;
+    ul_info.ue_sched_mode = SCHED_ALL;
+    if (mac->scc || mac->scc_SIB)
+    {
+        if (is_nr_UL_slot(mac->scc ?
+                          mac->scc->tdd_UL_DL_ConfigurationCommon :
+                          mac->scc_SIB->tdd_UL_DL_ConfigurationCommon,
+                          ul_info.slot_tx,
+                          mac->frame_type))
+            nr_ue_ul_indication(&ul_info);
+    }
+}
+
+void save_nr_measurement_info(nfapi_nr_dl_tti_request_t *dl_tti_request)
+{
+    int num_pdus = dl_tti_request->dl_tti_request_body.nPDUs;
+    char buffer[MAX_MESSAGE_SIZE];
+    if (num_pdus <= 0)
+    {
+        LOG_E(NR_PHY, "%s: dl_tti_request number of PDUS <= 0\n", __FUNCTION__);
+        abort();
+    }
+    LOG_D(NR_PHY, "%s: dl_tti_request number of PDUS: %d\n", __FUNCTION__, num_pdus);
+    for (int i = 0; i < num_pdus; i++)
+    {
+        nfapi_nr_dl_tti_request_pdu_t *pdu_list = &dl_tti_request->dl_tti_request_body.dl_tti_pdu_list[i];
+        if (pdu_list->PDUType == NFAPI_NR_DL_TTI_SSB_PDU_TYPE)
+        {
+            LOG_D(NR_PHY, "Cell_id: %d, the ssb_block_idx %d, sc_offset: %d and payload %d\n",
+                pdu_list->ssb_pdu.ssb_pdu_rel15.PhysCellId,
+                pdu_list->ssb_pdu.ssb_pdu_rel15.SsbBlockIndex,
+                pdu_list->ssb_pdu.ssb_pdu_rel15.SsbSubcarrierOffset,
+                pdu_list->ssb_pdu.ssb_pdu_rel15.bchPayload);
+            pdu_list->ssb_pdu.ssb_pdu_rel15.ssbRsrp = 60;
+            LOG_D(NR_RRC, "Setting pdulist[%d].ssbRsrp to %d\n", i, pdu_list->ssb_pdu.ssb_pdu_rel15.ssbRsrp);
+        }
+    }
+
+    size_t pack_len = nfapi_nr_p7_message_pack((void *)dl_tti_request,
+                                    buffer,
+                                    sizeof(buffer),
+                                    NULL);
+    if (pack_len < 0)
+    {
+        LOG_E(NR_PHY, "%s: Error packing nr p7 message.\n", __FUNCTION__);
+    }
+    nsa_sendmsg_to_lte_ue(buffer, pack_len, NR_UE_RRC_MEASUREMENT);
+    LOG_A(NR_RRC, "Populated NR_UE_RRC_MEASUREMENT information and sent to LTE UE\n");
+}
+
+static void enqueue_nr_nfapi_msg(void *buffer, ssize_t len, nfapi_p7_message_header_t header)
+{
+
+    switch (header.message_id)
+    {
+        case NFAPI_NR_PHY_MSG_TYPE_DL_TTI_REQUEST:
+        {
+            nfapi_nr_dl_tti_request_t *dl_tti_request = MALLOC(sizeof(*dl_tti_request));
+            if (nfapi_nr_p7_message_unpack(buffer, len, dl_tti_request,
+                                            sizeof(*dl_tti_request), NULL) < 0)
+            {
+                LOG_E(NR_PHY, "Message dl_tti_request failed to unpack\n");
+                break;
+            }
+            LOG_I(NR_PHY, "Received an NFAPI_NR_PHY_MSG_TYPE_DL_TTI_REQUEST message in sfn/slot %d %d. \n",
+                    dl_tti_request->SFN, dl_tti_request->Slot);
+            if (!put_queue(&nr_dl_tti_req_queue, dl_tti_request))
+            {
+                LOG_E(NR_PHY, "put_queue failed for dl_tti_request.\n");
+                free(dl_tti_request);
+                dl_tti_request = NULL;
+            }
+            break;
+        }
+
+        case NFAPI_NR_PHY_MSG_TYPE_TX_DATA_REQUEST:
+        {
+            nfapi_nr_tx_data_request_t *tx_data_request = MALLOC(sizeof(*tx_data_request));
+            if (nfapi_nr_p7_message_unpack(buffer, len, tx_data_request,
+                                        sizeof(*tx_data_request), NULL) < 0)
+            {
+                LOG_E(NR_PHY, "Message tx_data_request failed to unpack\n");
+                break;
+            }
+            LOG_I(NR_PHY, "Received an NFAPI_NR_PHY_MSG_TYPE_TX_DATA_REQUEST message in SFN/slot %d %d. \n",
+                    tx_data_request->SFN, tx_data_request->Slot);
+            if (!put_queue(&nr_tx_req_queue, tx_data_request))
+            {
+                LOG_E(NR_PHY, "put_queue failed for tx_request.\n");
+                free(tx_data_request);
+                tx_data_request = NULL;
+            }
+            break;
+        }
+
+        case NFAPI_NR_PHY_MSG_TYPE_UL_DCI_REQUEST:
+        {
+            nfapi_nr_ul_dci_request_t *ul_dci_request = MALLOC(sizeof(*ul_dci_request));
+            if (nfapi_nr_p7_message_unpack(buffer, len, ul_dci_request,
+                                            sizeof(*ul_dci_request), NULL) < 0)
+            {
+                LOG_E(NR_PHY, "Message ul_dci_request failed to unpack\n");
+                break;
+            }
+            LOG_I(NR_PHY, "Received an NFAPI_NR_PHY_MSG_TYPE_UL_DCI_REQUEST message in SFN/slot %d %d. \n",
+                    ul_dci_request->SFN, ul_dci_request->Slot);
+            if (!put_queue(&nr_ul_dci_req_queue, ul_dci_request))
+            {
+                LOG_E(NR_PHY, "put_queue failed for ul_dci_request.\n");
+                free(ul_dci_request);
+                ul_dci_request = NULL;
+            }
+            break;
+        }
+
+        case NFAPI_NR_PHY_MSG_TYPE_UL_TTI_REQUEST:
+        {
+            nfapi_nr_ul_tti_request_t *ul_tti_request = MALLOC(sizeof(*ul_tti_request));
+            if (nfapi_nr_p7_message_unpack(buffer, len, ul_tti_request,
+                                           sizeof(*ul_tti_request), NULL) < 0)
+            {
+                LOG_E(NR_PHY, "Message ul_tti_request failed to unpack\n");
+                break;
+            }
+            LOG_I(NR_PHY, "Received an NFAPI_NR_PHY_MSG_TYPE_UL_TTI_REQUEST message in SFN/slot %d %d.\n",
+                  ul_tti_request->SFN, ul_tti_request->Slot);
+            if (nr_uci_ind_queue.num_items > 0) //TODO: In the future UL_TTIs can be for ULSCH and SRS.
+            {
+                LOG_D(NR_MAC, "We added UL_TTI_REQ to queue for sfn slot %d %d\n",
+                      ul_tti_request->SFN, ul_tti_request->Slot);
+                if (!put_queue(&nr_ul_tti_req_queue, ul_tti_request))
+                {
+                    LOG_E(NR_PHY, "put_queue failed for ul_tti_request.\n");
+                    free(ul_tti_request);
+                    ul_tti_request = NULL;
+                }
+            }
+            /* TODO: This indicates that dl_tti_req was late or never arrived. If there are
+               not any prepared uci indications, the NRUE likely never had time to
+               populate the message is the dl_tti_req came in late and we received a
+               ul_tti_req immediately after the dl_tti_request. This is an attempt to
+               mitigate proxy timing issues. */
+            else if (nr_uci_ind_queue.num_items == 0)
+            {
+                LOG_D(NR_MAC, "We added UL_TTI_REQ to queue for sfn slot %d %d\n",
+                      ul_tti_request->SFN, ul_tti_request->Slot);
+                nfapi_nr_ul_tti_request_t *evicted_ul_tti_req = put_queue_replace(&nr_wait_ul_tti_req_queue, ul_tti_request);
+                free(evicted_ul_tti_req);
+            }
+            break;
+        }
+
+        default:
+            LOG_E(NR_PHY, "Invalid nFAPI message. Header ID %d\n",
+                  header.message_id);
+            break;
+    }
+    return;
+}
+
+void *nrue_standalone_pnf_task(void *context)
+{
+  struct sockaddr_in server_address;
+  socklen_t addr_len = sizeof(server_address);
+  int sd = ue_rx_sock_descriptor;
+  assert(sd > 0);
+
+  char buffer[NFAPI_MAX_PACKED_MESSAGE_SIZE];
+
+  LOG_I(NR_RRC, "Successfully started %s.\n", __FUNCTION__);
+
+  while (true)
+  {
+    ssize_t len = recvfrom(sd, buffer, sizeof(buffer), MSG_TRUNC, (struct sockaddr *)&server_address, &addr_len);
+    if (len == -1)
+    {
+      LOG_E(NR_PHY, "reading from standalone pnf sctp socket failed \n");
+      continue;
+    }
+    if (len > sizeof(buffer))
+    {
+      LOG_E(NR_PHY, "%s(%d). Message truncated. %zd\n", __FUNCTION__, __LINE__, len);
+      continue;
+    }
+    if (len == sizeof(uint16_t))
+    {
+      uint16_t *sfn_slot = CALLOC(1, sizeof(*sfn_slot));
+      memcpy(sfn_slot, buffer, sizeof(*sfn_slot));
+
+      LOG_I(NR_PHY, "Received from proxy sfn %d slot %d\n",
+            NFAPI_SFNSLOT2SFN(*sfn_slot), NFAPI_SFNSLOT2SLOT(*sfn_slot));
+
+      if (!put_queue(&nr_sfn_slot_queue, sfn_slot))
+      {
+        LOG_E(NR_PHY, "put_queue failed for sfn slot.\n");
+      }
+
+      if (sem_post(&sfn_slot_semaphore) != 0)
+      {
+        LOG_E(NR_PHY, "sem_post() error\n");
+        abort();
+      }
+    }
+    else if (len == sizeof(nr_phy_channel_params_t))
+    {
+      nr_phy_channel_params_t *ch_info = CALLOC(1, sizeof(*ch_info));
+      memcpy(ch_info, buffer, sizeof(*ch_info));
+
+      LOG_D(NR_PHY, "Received_SINR = %f, sfn:slot %d:%d\n",
+            ch_info->sinr, NFAPI_SFNSLOT2SFN(ch_info->sfn_slot), NFAPI_SFNSLOT2SLOT(ch_info->sfn_slot));
+
+      if (!put_queue(&nr_chan_param_queue, ch_info))
+      {
+        LOG_E(NR_PHY, "put_queue failed for sfn slot.\n");
+      }
+
+      if (sem_post(&sfn_slot_semaphore) != 0)
+      {
+        LOG_E(MAC, "sem_post() error\n");
+        abort();
+      }
+    }
+    else
+    {
+      nfapi_p7_message_header_t header;
+      if (nfapi_p7_message_header_unpack(buffer, len, &header, sizeof(header), NULL) < 0)
+      {
+        LOG_E(NR_PHY, "Header unpack failed for nrue_standalone pnf\n");
+        continue;
+      }
+      enqueue_nr_nfapi_msg(buffer, len, header);
+    }
+  } //while(true)
+}
 
 //  L2 Abstraction Layer
 int handle_bcch_bch(module_id_t module_id, int cc_id,
@@ -81,6 +1034,8 @@ int handle_dci(module_id_t module_id, int cc_id, unsigned int gNB_index, frame_t
 // Note: sdu should always be processed because data and timing advance updates are transmitted by the UE
 int8_t handle_dlsch(nr_downlink_indication_t *dl_info, NR_UL_TIME_ALIGNMENT_t *ul_time_alignment, int pdu_id){
 
+  dl_info->rx_ind->rx_indication_body[pdu_id].pdsch_pdu.harq_pid = g_harq_pid;
+
   update_harq_status(dl_info->module_id,
                      dl_info->rx_ind->rx_indication_body[pdu_id].pdsch_pdu.harq_pid,
                      dl_info->rx_ind->rx_indication_body[pdu_id].pdsch_pdu.ack_nack);
@@ -117,8 +1072,12 @@ int nr_ue_ul_indication(nr_uplink_indication_t *ul_info){
     ret = nr_ue_scheduler(NULL, ul_info);
     return 0;
   }
-  else if (ul_info->ue_sched_mode == SCHED_ALL)
+  if (ul_info->ue_sched_mode == SCHED_ALL) {
     ret = nr_ue_scheduler(NULL, ul_info);
+  }
+  else
+    LOG_D(NR_MAC, "In %s():%d not calling scheduler. sched mode = %d and mac->ra.ra_state = %d\n",
+        __FUNCTION__, __LINE__, ul_info->ue_sched_mode, mac->ra.ra_state);
 
   NR_TDD_UL_DL_ConfigCommon_t *tdd_UL_DL_ConfigurationCommon = mac->scc != NULL ? mac->scc->tdd_UL_DL_ConfigurationCommon : mac->scc_SIB->tdd_UL_DL_ConfigurationCommon;
 
@@ -146,20 +1105,19 @@ int nr_ue_ul_indication(nr_uplink_indication_t *ul_info){
 
 int nr_ue_dl_indication(nr_downlink_indication_t *dl_info, NR_UL_TIME_ALIGNMENT_t *ul_time_alignment){
 
-  int32_t i;
   uint32_t ret_mask = 0x0;
   module_id_t module_id = dl_info->module_id;
   NR_UE_MAC_INST_t *mac = get_mac_inst(module_id);
   fapi_nr_dl_config_request_t *dl_config = &mac->dl_config_request;
-  
-  if (!dl_info->dci_ind && !dl_info->rx_ind) {
+
+  if ((!dl_info->dci_ind && !dl_info->rx_ind)) {
     // UL indication to schedule DCI reception
     nr_ue_scheduler(dl_info, NULL);
   } else {
     // UL indication after reception of DCI or DL PDU
-    if(dl_info->dci_ind != NULL){
+    if (dl_info && dl_info->dci_ind && dl_info->dci_ind->number_of_dcis) {
       LOG_D(MAC,"[L2][IF MODULE][DL INDICATION][DCI_IND]\n");
-      for(i=0; i<dl_info->dci_ind->number_of_dcis; ++i){
+      for (int i = 0; i < dl_info->dci_ind->number_of_dcis; i++) {
         LOG_D(MAC,">>>NR_IF_Module i=%d, dl_info->dci_ind->number_of_dcis=%d\n",i,dl_info->dci_ind->number_of_dcis);
         nr_scheduled_response_t scheduled_response;
         int8_t ret = handle_dci(dl_info->module_id,
@@ -169,6 +1127,17 @@ int nr_ue_dl_indication(nr_downlink_indication_t *dl_info, NR_UL_TIME_ALIGNMENT_
                                 dl_info->slot,
                                 dl_info->dci_ind->dci_list+i);
 
+        fapi_nr_dci_indication_pdu_t *dci_index = dl_info->dci_ind->dci_list+i;
+
+        /* The check below filters out UL_DCIs (format 7) which are being processed as DL_DCIs. */
+        if (dci_index->dci_format == 7 && mac->ra.ra_state == RA_SUCCEEDED) {
+          LOG_D(NR_MAC, "We are filtering a UL_DCI to prevent it from being treated like a DL_DCI\n");
+          break;
+        }
+        dci_pdu_rel15_t *def_dci_pdu_rel15 = &mac->def_dci_pdu_rel15[dci_index->dci_format];
+        g_harq_pid = def_dci_pdu_rel15->harq_pid;
+        LOG_D(NR_MAC, "Setting harq_pid = %d and dci_index = %d (based on format)\n", g_harq_pid, dci_index->dci_format);
+
         ret_mask |= (ret << FAPI_NR_DCI_IND);
         if (ret >= 0) {
           AssertFatal( nr_ue_if_module_inst[module_id] != NULL, "IF module is NULL!\n" );
@@ -176,16 +1145,19 @@ int nr_ue_dl_indication(nr_downlink_indication_t *dl_info, NR_UL_TIME_ALIGNMENT_
           fill_scheduled_response(&scheduled_response, dl_config, NULL, NULL, dl_info->module_id, dl_info->cc_id, dl_info->frame, dl_info->slot, dl_info->thread_id);
           nr_ue_if_module_inst[module_id]->scheduled_response(&scheduled_response);
         }
+        memset(def_dci_pdu_rel15, 0, sizeof(*def_dci_pdu_rel15));
       }
+      free(dl_info->dci_ind);
+      dl_info->dci_ind = NULL;
     }
 
-    if(dl_info->rx_ind != NULL){
+    if (dl_info->rx_ind != NULL) {
 
-      for(i=0; i<dl_info->rx_ind->number_pdus; ++i){
+      for (int i=0; i<dl_info->rx_ind->number_pdus; ++i) {
 
-        LOG_D(MAC, "In %s sending DL indication to MAC. 1 PDU type %s of %d total number of PDUs \n",
+        LOG_D(MAC, "In %s sending DL indication to MAC. 1 PDU type %d of %d total number of PDUs \n",
           __FUNCTION__,
-          dl_indication_type[dl_info->rx_ind->rx_indication_body[i].pdu_type - 1],
+          dl_info->rx_ind->rx_indication_body[i].pdu_type,
           dl_info->rx_ind->number_pdus);
 
         switch(dl_info->rx_ind->rx_indication_body[i].pdu_type){
@@ -217,11 +1189,15 @@ int nr_ue_dl_indication(nr_downlink_indication_t *dl_info, NR_UL_TIME_ALIGNMENT_
             break;
         }
       }
+      free(dl_info->rx_ind);
+      dl_info->rx_ind = NULL;
     }
 
     //clean up nr_downlink_indication_t *dl_info
-    dl_info->rx_ind = NULL;
+    free(dl_info->dci_ind);
     dl_info->dci_ind = NULL;
+    free(dl_info->rx_ind);
+    dl_info->rx_ind  = NULL;
 
   }
   return 0;
@@ -237,7 +1213,10 @@ nr_ue_if_module_t *nr_ue_if_module_init(uint32_t module_id){
     nr_ue_if_module_inst[module_id]->current_frame = 0;
     nr_ue_if_module_inst[module_id]->current_slot = 0;
     nr_ue_if_module_inst[module_id]->phy_config_request = nr_ue_phy_config_request;
-    nr_ue_if_module_inst[module_id]->scheduled_response = nr_ue_scheduled_response;
+    if (get_softmodem_params()->emulate_l1)
+      nr_ue_if_module_inst[module_id]->scheduled_response = nr_ue_scheduled_response_stub;
+    else
+      nr_ue_if_module_inst[module_id]->scheduled_response = nr_ue_scheduled_response;
     nr_ue_if_module_inst[module_id]->dl_indication = nr_ue_dl_indication;
     nr_ue_if_module_inst[module_id]->ul_indication = nr_ue_ul_indication;
   }
@@ -266,3 +1245,32 @@ int nr_ue_dcireq(nr_dcireq_t *dcireq) {
 
   return 0;
 }
+
+void RCconfig_nr_ue_L1(void) {
+  int j;
+  paramdef_t L1_Params[] = L1PARAMS_DESC;
+  paramlist_def_t L1_ParamList = {CONFIG_STRING_L1_LIST, NULL, 0};
+
+  config_getlist(&L1_ParamList, L1_Params, sizeof(L1_Params) / sizeof(paramdef_t), NULL);
+  if (L1_ParamList.numelt > 0) {
+    for (j = 0; j < L1_ParamList.numelt; j++) {
+      if (strcmp(*(L1_ParamList.paramarray[j][L1_TRANSPORT_N_PREFERENCE_IDX].strptr), "nfapi") == 0) {
+        stub_eth_params.local_if_name = strdup(
+            *(L1_ParamList.paramarray[j][L1_LOCAL_N_IF_NAME_IDX].strptr));
+        stub_eth_params.my_addr = strdup(
+            *(L1_ParamList.paramarray[j][L1_LOCAL_N_ADDRESS_IDX].strptr));
+        stub_eth_params.remote_addr = strdup(
+            *(L1_ParamList.paramarray[j][L1_REMOTE_N_ADDRESS_IDX].strptr));
+        stub_eth_params.my_portc =
+            *(L1_ParamList.paramarray[j][L1_LOCAL_N_PORTC_IDX].iptr);
+        stub_eth_params.remote_portc =
+            *(L1_ParamList.paramarray[j][L1_REMOTE_N_PORTC_IDX].iptr);
+        stub_eth_params.my_portd =
+            *(L1_ParamList.paramarray[j][L1_LOCAL_N_PORTD_IDX].iptr);
+        stub_eth_params.remote_portd =
+            *(L1_ParamList.paramarray[j][L1_REMOTE_N_PORTD_IDX].iptr);
+        stub_eth_params.transp_preference = ETH_UDP_MODE;
+      }
+    }
+  }
+}
diff --git a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.h b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.h
index 1ba8238f1ec7d04c262bb1cc2df78e4889ebc246..2a8a5147694b8d86dd6d0c488f2cf717cb8ef9f3 100755
--- a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.h
+++ b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.h
@@ -35,10 +35,21 @@
 
 #include "platform_types.h"
 #include <openair1/PHY/thread_NR_UE.h>
+#include <semaphore.h>
 #include "fapi_nr_ue_interface.h"
+#include "openair2/PHY_INTERFACE/queue_t.h"
+#include "nfapi_nr_interface_scf.h"
+#include "openair2/NR_PHY_INTERFACE/NR_IF_Module.h"
 
 typedef struct NR_UL_TIME_ALIGNMENT NR_UL_TIME_ALIGNMENT_t;
 
+typedef struct nr_phy_channel_params_t
+{
+    uint16_t sfn_slot;
+    float sinr;
+    // Incomplete, need all channel parameters
+} nr_phy_channel_params_t;
+
 typedef enum {
   ONLY_PUSCH,
   NOT_PUSCH,
@@ -209,6 +220,25 @@ typedef struct nr_ue_if_module_s {
    \param module_id module id*/
 nr_ue_if_module_t *nr_ue_if_module_init(uint32_t module_id);
 
+void nrue_init_standalone_socket(int tx_port, int rx_port);
+
+void *nrue_standalone_pnf_task(void *context);
+extern sem_t sfn_slot_semaphore;
+
+typedef struct nfapi_dl_tti_config_req_tx_data_req_t
+{
+    nfapi_nr_dl_tti_request_pdu_t *dl_itti_config_req;
+    nfapi_nr_tx_data_request_t *tx_data_req_pdu_list;
+} nfapi_dl_tti_config_req_tx_data_req_t;
+
+void send_nsa_standalone_msg(NR_UL_IND_t *UL_INFO, uint16_t msg_id);
+
+void save_nr_measurement_info(nfapi_nr_dl_tti_request_t *dl_tti_request);
+
+void check_and_process_dci(nfapi_nr_dl_tti_request_t *dl_tti_request,
+                           nfapi_nr_tx_data_request_t *tx_data_request,
+                           nfapi_nr_ul_dci_request_t *ul_dci_request,
+                           nfapi_nr_ul_tti_request_t *ul_tti_request);
 
 /**\brief done free of memory allocation by module_id and release to pointer pool.
    \param module_id module id*/
diff --git a/openair2/PHY_INTERFACE/.gitignore b/openair2/PHY_INTERFACE/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..2dca7a7611a5ca3548d6f4cd2d35b0c063402adb
--- /dev/null
+++ b/openair2/PHY_INTERFACE/.gitignore
@@ -0,0 +1 @@
+/queue_test
diff --git a/openair2/PHY_INTERFACE/IF_Module.c b/openair2/PHY_INTERFACE/IF_Module.c
index ed3c9a5b7d2f7e84d59fc797e7730f0c1fa3c714..fba9e1d8b6382612736973a1b6a1f96b0b29838a 100644
--- a/openair2/PHY_INTERFACE/IF_Module.c
+++ b/openair2/PHY_INTERFACE/IF_Module.c
@@ -24,25 +24,31 @@ extern RAN_CONTEXT_t RC;
 uint16_t frame_cnt=0;
 void handle_rach(UL_IND_t *UL_info) {
   int i;
-
-  if(NFAPI_MODE == NFAPI_MODE_VNF) {
-    for(uint8_t j = 0; j < NUM_NFPAI_SUBFRAME; j++) {
-      if (UL_RCC_INFO.rach_ind[j].rach_indication_body.number_of_preambles>0) {
-        AssertFatal(UL_RCC_INFO.rach_ind[j].rach_indication_body.number_of_preambles==1,"More than 1 preamble not supported\n");
-        LOG_D(MAC,"UL_info[Frame %d, Subframe %d] Calling initiate_ra_proc RACH:SFN/SF:%d\n",UL_info->frame,UL_info->subframe, NFAPI_SFNSF2DEC(UL_RCC_INFO.rach_ind[j].sfn_sf));
-        initiate_ra_proc(UL_info->module_id,
-                         UL_info->CC_id,
-                         NFAPI_SFNSF2SFN(UL_RCC_INFO.rach_ind[j].sfn_sf),
-                         NFAPI_SFNSF2SF(UL_RCC_INFO.rach_ind[j].sfn_sf),
-                         UL_RCC_INFO.rach_ind[j].rach_indication_body.preamble_list[0].preamble_rel8.preamble,
-                         UL_RCC_INFO.rach_ind[j].rach_indication_body.preamble_list[0].preamble_rel8.timing_advance,
-                         UL_RCC_INFO.rach_ind[j].rach_indication_body.preamble_list[0].preamble_rel8.rnti,
-                         0
-                        );
-        free(UL_RCC_INFO.rach_ind[j].rach_indication_body.preamble_list);
-        UL_RCC_INFO.rach_ind[j].rach_indication_body.number_of_preambles = 0;
-        UL_RCC_INFO.rach_ind[j].header.message_id = 0;
+  int j = UL_info->subframe;
+  AssertFatal(j < sizeof(UL_RCC_INFO.rach_ind) / sizeof(UL_RCC_INFO.rach_ind[0]), "j index out of range of index of rach_ind\n");
+  if (NFAPI_MODE == NFAPI_MODE_VNF)
+  {
+    if (UL_RCC_INFO.rach_ind[j].rach_indication_body.number_of_preambles > 0)
+    {
+      if (UL_RCC_INFO.rach_ind[j].rach_indication_body.number_of_preambles > 1)
+      {
+        LOG_D(MAC, "handle_rach j: %d  UL_RCC_INFO.rach_ind[j].rach_indication_body.number_of_preambles: %d\n",
+          j, UL_RCC_INFO.rach_ind[j].rach_indication_body.number_of_preambles);
+        LOG_D(MAC, "UL_info[Frame %d, Subframe %d] Calling initiate_ra_proc RACH:Frame: %d Subframe: %d\n",
+          UL_info->frame, UL_info->subframe, NFAPI_SFNSF2SFN(UL_RCC_INFO.rach_ind[j].sfn_sf), NFAPI_SFNSF2SF(UL_RCC_INFO.rach_ind[j].sfn_sf));
       }
+      AssertFatal(UL_RCC_INFO.rach_ind[j].rach_indication_body.number_of_preambles == 1, "More than 1 preamble not supported\n"); // dump frame/sf and all things in UL_RCC_INFO
+      initiate_ra_proc(UL_info->module_id,
+                       UL_info->CC_id,
+                       NFAPI_SFNSF2SFN(UL_RCC_INFO.rach_ind[j].sfn_sf),
+                       NFAPI_SFNSF2SF(UL_RCC_INFO.rach_ind[j].sfn_sf),
+                       UL_RCC_INFO.rach_ind[j].rach_indication_body.preamble_list[0].preamble_rel8.preamble,
+                       UL_RCC_INFO.rach_ind[j].rach_indication_body.preamble_list[0].preamble_rel8.timing_advance,
+                       UL_RCC_INFO.rach_ind[j].rach_indication_body.preamble_list[0].preamble_rel8.rnti,
+                       0);
+      free(UL_RCC_INFO.rach_ind[j].rach_indication_body.preamble_list);
+      UL_RCC_INFO.rach_ind[j].rach_indication_body.number_of_preambles = 0;
+      UL_RCC_INFO.rach_ind[j].header.message_id = 0;
     }
   } else {
     if (UL_info->rach_ind.rach_indication_body.number_of_preambles>0) {
@@ -92,8 +98,9 @@ void handle_sr(UL_IND_t *UL_info) {
       oai_nfapi_sr_indication(&UL_info->sr_ind);
     }
   } else if(NFAPI_MODE == NFAPI_MODE_VNF) {
-    for(uint8_t j = 0; j < NUM_NFPAI_SUBFRAME; j++) {
+    for(uint8_t j = 0; j < NUM_NFAPI_SUBFRAME; j++) {
       if(UL_RCC_INFO.sr_ind[j].sr_indication_body.number_of_srs > 0) {
+        assert(UL_RCC_INFO.sr_ind[j].sr_indication_body.number_of_srs <= NFAPI_SR_IND_MAX_PDU);
         for (i=0; i<UL_RCC_INFO.sr_ind[j].sr_indication_body.number_of_srs; i++) {
           SR_indication(UL_info->module_id,
                         UL_info->CC_id,
@@ -109,6 +116,7 @@ void handle_sr(UL_IND_t *UL_info) {
       }
     }
   } else {
+    assert(UL_info->sr_ind.sr_indication_body.number_of_srs <= NFAPI_SR_IND_MAX_PDU);
     for (i=0; i<UL_info->sr_ind.sr_indication_body.number_of_srs; i++)
       SR_indication(UL_info->module_id,
                     UL_info->CC_id,
@@ -133,8 +141,9 @@ void handle_cqi(UL_IND_t *UL_info) {
       UL_info->cqi_ind.cqi_indication_body.number_of_cqis=0;
     }
   } else if (NFAPI_MODE == NFAPI_MODE_VNF) {
-    for(uint8_t j = 0; j < NUM_NFPAI_SUBFRAME; j++) {
+    for(uint8_t j = 0; j < NUM_NFAPI_SUBFRAME; j++) {
       if(UL_RCC_INFO.cqi_ind[j].cqi_indication_body.number_of_cqis > 0) {
+        assert(UL_RCC_INFO.cqi_ind[j].cqi_indication_body.number_of_cqis <= NFAPI_CQI_IND_MAX_PDU);
         for (i=0; i<UL_RCC_INFO.cqi_ind[j].cqi_indication_body.number_of_cqis; i++) {
           cqi_indication(UL_info->module_id,
                          UL_info->CC_id,
@@ -153,6 +162,7 @@ void handle_cqi(UL_IND_t *UL_info) {
       }
     }
   } else {
+    assert(UL_info->cqi_ind.cqi_indication_body.number_of_cqis <= NFAPI_CQI_IND_MAX_PDU);
     for (i=0; i<UL_info->cqi_ind.cqi_indication_body.number_of_cqis; i++)
       cqi_indication(UL_info->module_id,
                      UL_info->CC_id,
@@ -178,8 +188,9 @@ void handle_harq(UL_IND_t *UL_info) {
 
     UL_info->harq_ind.harq_indication_body.number_of_harqs = 0;
   } else if(NFAPI_MODE == NFAPI_MODE_VNF) {
-    for(uint8_t j = 0; j < NUM_NFPAI_SUBFRAME; j++) {
+    for(uint8_t j = 0; j < NUM_NFAPI_SUBFRAME; j++) {
       if(UL_RCC_INFO.harq_ind[j].harq_indication_body.number_of_harqs > 0) {
+        assert(UL_RCC_INFO.harq_ind[j].harq_indication_body.number_of_harqs <= NFAPI_HARQ_IND_MAX_PDU);
         for (int i=0; i<UL_RCC_INFO.harq_ind[j].harq_indication_body.number_of_harqs; i++) {
           harq_indication(UL_info->module_id,
                           UL_info->CC_id,
@@ -194,6 +205,7 @@ void handle_harq(UL_IND_t *UL_info) {
       }
     }
   } else {
+    assert(UL_info->harq_ind.harq_indication_body.number_of_harqs <= NFAPI_HARQ_IND_MAX_PDU);
     for (int i=0; i < UL_info->harq_ind.harq_indication_body.number_of_harqs; i++)
       harq_indication(UL_info->module_id,
                       UL_info->CC_id,
@@ -221,9 +233,11 @@ void handle_ulsch(UL_IND_t *UL_info) {
       UL_info->rx_ind.rx_indication_body.number_of_pdus = 0;
     }
   } else if(NFAPI_MODE == NFAPI_MODE_VNF) {
-    for(uint8_t k = 0; k < NUM_NFPAI_SUBFRAME; k++) {
+    for(uint8_t k = 0; k < NUM_NFAPI_SUBFRAME; k++) {
       if((UL_RCC_INFO.rx_ind[k].rx_indication_body.number_of_pdus>0) && (UL_RCC_INFO.crc_ind[k].crc_indication_body.number_of_crcs>0)) {
+        assert(UL_RCC_INFO.rx_ind[k].rx_indication_body.number_of_pdus <= NFAPI_RX_IND_MAX_PDU);
         for (i=0; i<UL_RCC_INFO.rx_ind[k].rx_indication_body.number_of_pdus; i++) {
+          assert(UL_RCC_INFO.crc_ind[k].crc_indication_body.number_of_crcs <= NFAPI_CRC_IND_MAX_PDU);
           for (j=0; j<UL_RCC_INFO.crc_ind[k].crc_indication_body.number_of_crcs; j++) {
             // find crc_indication j corresponding rx_indication i
             LOG_D(PHY,"UL_info->crc_ind.crc_indication_body.crc_pdu_list[%d].rx_ue_information.rnti:%04x UL_info->rx_ind.rx_indication_body.rx_pdu_list[%d].rx_ue_information.rnti:%04x\n",
@@ -251,16 +265,12 @@ void handle_ulsch(UL_IND_t *UL_info) {
                        NFAPI_SFNSF2SFN(UL_RCC_INFO.rx_ind[k].sfn_sf), //UL_info->frame,
                        NFAPI_SFNSF2SF(UL_RCC_INFO.rx_ind[k].sfn_sf), //UL_info->subframe,
                        UL_RCC_INFO.rx_ind[k].rx_indication_body.rx_pdu_list[i].rx_ue_information.rnti,
-                       UL_RCC_INFO.rx_ind[k].rx_indication_body.rx_pdu_list[i].data,
+                       UL_RCC_INFO.rx_ind[k].rx_indication_body.rx_pdu_list[i].rx_ind_data,
                        UL_RCC_INFO.rx_ind[k].rx_indication_body.rx_pdu_list[i].rx_indication_rel8.length,
                        UL_RCC_INFO.rx_ind[k].rx_indication_body.rx_pdu_list[i].rx_indication_rel8.timing_advance,
                        UL_RCC_INFO.rx_ind[k].rx_indication_body.rx_pdu_list[i].rx_indication_rel8.ul_cqi);
               }
 
-              if(UL_RCC_INFO.rx_ind[k].rx_indication_body.rx_pdu_list[i].data != NULL) {
-                free(UL_RCC_INFO.rx_ind[k].rx_indication_body.rx_pdu_list[i].data);
-              }
-
               break;
             } //if (UL_info->crc_ind.crc_pdu_list[j].rx_ue_information.rnti == UL_info->rx_ind.rx_pdu_list[i].rx_ue_information.rnti)
           } //    for (j=0;j<UL_info->crc_ind.crc_indication_body.number_of_crcs;j++)
@@ -276,7 +286,9 @@ void handle_ulsch(UL_IND_t *UL_info) {
     }
   } else {
     if (UL_info->rx_ind.rx_indication_body.number_of_pdus>0 && UL_info->crc_ind.crc_indication_body.number_of_crcs>0) {
+      assert(UL_info->rx_ind.rx_indication_body.number_of_pdus <= NFAPI_RX_IND_MAX_PDU);
       for (i=0; i<UL_info->rx_ind.rx_indication_body.number_of_pdus; i++) {
+        assert(UL_info->crc_ind.crc_indication_body.number_of_crcs <= NFAPI_CRC_IND_MAX_PDU);
         for (j=0; j<UL_info->crc_ind.crc_indication_body.number_of_crcs; j++) {
           // find crc_indication j corresponding rx_indication i
           LOG_D(PHY,"UL_info->crc_ind.crc_indication_body.crc_pdu_list[%d].rx_ue_information.rnti:%04x UL_info->rx_ind.rx_indication_body.rx_pdu_list[%d].rx_ue_information.rnti:%04x\n", j,
@@ -304,7 +316,7 @@ void handle_ulsch(UL_IND_t *UL_info) {
                      NFAPI_SFNSF2SFN(UL_info->rx_ind.sfn_sf), //UL_info->frame,
                      NFAPI_SFNSF2SF(UL_info->rx_ind.sfn_sf), //UL_info->subframe,
                      UL_info->rx_ind.rx_indication_body.rx_pdu_list[i].rx_ue_information.rnti,
-                     UL_info->rx_ind.rx_indication_body.rx_pdu_list[i].data,
+                     UL_info->rx_ind.rx_indication_body.rx_pdu_list[i].rx_ind_data,
                      UL_info->rx_ind.rx_indication_body.rx_pdu_list[i].rx_indication_rel8.length,
                      UL_info->rx_ind.rx_indication_body.rx_pdu_list[i].rx_indication_rel8.timing_advance,
                      UL_info->rx_ind.rx_indication_body.rx_pdu_list[i].rx_indication_rel8.ul_cqi);
@@ -790,6 +802,7 @@ IF_Module_t *IF_Module_init(int Mod_id) {
                 "allocation of if_inst[%d]->if_mutex fails\n",Mod_id);
   }
 
+  memset(&UL_RCC_INFO, 0, sizeof(UL_RCC_INFO));
   return if_inst[Mod_id];
 }
 
diff --git a/openair2/PHY_INTERFACE/IF_Module.h b/openair2/PHY_INTERFACE/IF_Module.h
index 096979c4fd195595ac9e6076d3d06d686cfa5745..b1123dce5f7ff735880ffcfe479eab4cd1d9c016 100644
--- a/openair2/PHY_INTERFACE/IF_Module.h
+++ b/openair2/PHY_INTERFACE/IF_Module.h
@@ -87,25 +87,25 @@ typedef struct {
 } UL_IND_t;
 
 // Downlink subframe P7
-#define NUM_NFPAI_SUBFRAME 5
+#define NUM_NFAPI_SUBFRAME 10
 typedef struct {
   /// harq indication list
-  nfapi_harq_indication_t harq_ind[NUM_NFPAI_SUBFRAME];
+  nfapi_harq_indication_t harq_ind[NUM_NFAPI_SUBFRAME];
 
   /// crc indication list
-  nfapi_crc_indication_t crc_ind[NUM_NFPAI_SUBFRAME];
+  nfapi_crc_indication_t crc_ind[NUM_NFAPI_SUBFRAME];
 
   /// SR indication list
-  nfapi_sr_indication_t sr_ind[NUM_NFPAI_SUBFRAME];
+  nfapi_sr_indication_t sr_ind[NUM_NFAPI_SUBFRAME];
 
   /// CQI indication list
-  nfapi_cqi_indication_t cqi_ind[NUM_NFPAI_SUBFRAME];
+  nfapi_cqi_indication_t cqi_ind[NUM_NFAPI_SUBFRAME];
 
   /// RACH indication list
-  nfapi_rach_indication_t rach_ind[NUM_NFPAI_SUBFRAME];
+  nfapi_rach_indication_t rach_ind[NUM_NFAPI_SUBFRAME];
 
   /// RX indication
-  nfapi_rx_indication_t rx_ind[NUM_NFPAI_SUBFRAME];
+  nfapi_rx_indication_t rx_ind[NUM_NFAPI_SUBFRAME];
 
 } UL_RCC_IND_t;
 
@@ -151,6 +151,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/phy_stub_UE.c b/openair2/PHY_INTERFACE/phy_stub_UE.c
index c212075934871c6b6a1994244eb0c490585f090a..1598e3d6203c91a80a838a538f55144544d7eaa4 100644
--- a/openair2/PHY_INTERFACE/phy_stub_UE.c
+++ b/openair2/PHY_INTERFACE/phy_stub_UE.c
@@ -30,10 +30,14 @@
 #include "targets/ARCH/ETHERNET/USERSPACE/LIB/if_defs.h"
 #include "common/config/config_load_configmodule.h"
 #include "common/config/config_userapi.h"
+#include <arpa/inet.h>
+#include <string.h>
+#include <errno.h>
 #include "openair2/NR_PHY_INTERFACE/NR_IF_Module.h"
 #include "openair1/PHY/defs_gNB.h"
 #include "nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface_scf.h"
 #include "openair1/PHY/LTE_TRANSPORT/transport_common.h"
+#include "softmodem-common.h"
 
 extern int oai_nfapi_rach_ind(nfapi_rach_indication_t *rach_ind);
 void configure_nfapi_pnf(char *vnf_ip_addr,
@@ -43,15 +47,33 @@ void configure_nfapi_pnf(char *vnf_ip_addr,
                          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 nfapi_tx_request_pdu_t* tx_request_pdu[1023][10][10];
+queue_t dl_config_req_tx_req_queue;
+queue_t ul_config_req_queue;
+queue_t hi_dci0_req_queue;
+
+FILL_UL_INFO_MUTEX_t fill_ul_mutex;
+
+int current_sfn_sf;
+sem_t sfn_semaphore;
+
+static sf_rnti_mcs_s sf_rnti_mcs[NUM_NFAPI_SUBFRAME];
+
+static int ue_tx_sock_descriptor = -1;
+static int ue_rx_sock_descriptor = -1;
+static int get_mcs_from_sinr(float sinr);
+static int get_cqi_from_mcs(void);
+static void read_channel_param(const nfapi_dl_config_request_pdu_t * pdu, int sf, int index);
+static bool did_drop_transport_block(int sf, uint16_t rnti);
+static float get_bler_val(uint8_t mcs, int sinr);
+static bool should_drop_transport_block(int sf, uint16_t rnti);
+static void save_dci_pdu_for_crnti(nfapi_dl_config_request_t *dl_config_req);
+
+extern nfapi_tx_request_pdu_t* tx_request_pdu[1023][NUM_NFAPI_SUBFRAME][10]; //TODO: NFAPI_TX_MAX_PDU for last dim? Check nfapi_pnf.c ln. 81
 //extern int timer_subframe;
 //extern int timer_frame;
 
+extern UE_RRC_INST *UE_rrc_inst;
 extern uint16_t sf_ahead;
 
 static eth_params_t         stub_eth_params;
@@ -65,14 +87,19 @@ void fill_rx_indication_UE_MAC(module_id_t Mod_id,
                                uint8_t *ulsch_buffer,
                                uint16_t buflen,
                                uint16_t rnti,
-                               int index) {
+                               int index,
+                               nfapi_ul_config_request_t *ul_config_req) {
   nfapi_rx_indication_pdu_t *pdu;
   int timing_advance_update;
 
+  pthread_mutex_lock(&fill_ul_mutex.rx_mutex);
+
+  UL_INFO->rx_ind.header.message_id = NFAPI_RX_ULSCH_INDICATION;
   UL_INFO->rx_ind.sfn_sf = frame << 4 | subframe;
   UL_INFO->rx_ind.rx_indication_body.tl.tag = NFAPI_RX_INDICATION_BODY_TAG;
   UL_INFO->rx_ind.vendor_extension = ul_config_req->vendor_extension;
 
+  assert(UL_INFO->rx_ind.rx_indication_body.number_of_pdus <= NFAPI_RX_IND_MAX_PDU);
   pdu = &UL_INFO->rx_ind.rx_indication_body
              .rx_pdu_list[UL_INFO->rx_ind.rx_indication_body.number_of_pdus];
   // pdu = &UL_INFO->rx_ind.rx_indication_body.rx_pdu_list[index];
@@ -87,8 +114,10 @@ void fill_rx_indication_UE_MAC(module_id_t Mod_id,
   pdu->rx_indication_rel9.timing_advance_r9 = 0;
 
   // ulsch_buffer is necessary to keep its value.
-  pdu->data = malloc(buflen);
-  memcpy(pdu->data, ulsch_buffer, buflen);
+  assert(buflen <= NFAPI_RX_IND_DATA_MAX);
+  memcpy(pdu->rx_ind_data, ulsch_buffer, buflen);
+  LOG_I(MAC, "buflen of rx_ind pdu_data = %u SFN.SF: %d.%d\n", buflen,
+        frame, subframe);
   // estimate timing advance for MAC
   timing_advance_update = 0; // Don't know what to put here
   pdu->rx_indication_rel8.timing_advance = timing_advance_update;
@@ -104,15 +133,21 @@ void fill_rx_indication_UE_MAC(module_id_t Mod_id,
 
   UL_INFO->rx_ind.rx_indication_body.number_of_pdus++;
   UL_INFO->rx_ind.sfn_sf = frame << 4 | subframe;
+
+  pthread_mutex_unlock(&fill_ul_mutex.rx_mutex);
 }
 
 void fill_sr_indication_UE_MAC(int Mod_id,
                                int frame,
                                int subframe,
                                UL_IND_t *UL_INFO,
-                               uint16_t rnti) {
+                               uint16_t rnti,
+                               nfapi_ul_config_request_t *ul_config_req) {
+  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;
+  assert(sr_ind_body->number_of_srs <= NFAPI_SR_IND_MAX_PDU);
   nfapi_sr_indication_pdu_t *pdu = &sr_ind_body->sr_pdu_list[sr_ind_body->number_of_srs];
   UL_INFO->sr_ind.vendor_extension = ul_config_req->vendor_extension;
 
@@ -139,6 +174,8 @@ void fill_sr_indication_UE_MAC(int Mod_id,
 
   // UL_INFO->rx_ind.rx_indication_body.number_of_pdus++;
   sr_ind_body->number_of_srs++;
+
+  pthread_mutex_unlock(&fill_ul_mutex.sr_mutex);
 }
 
 void fill_crc_indication_UE_MAC(int Mod_id,
@@ -147,7 +184,12 @@ void fill_crc_indication_UE_MAC(int Mod_id,
                                 UL_IND_t *UL_INFO,
                                 uint8_t crc_flag,
                                 int index,
-                                uint16_t rnti) {
+                                uint16_t rnti,
+                                nfapi_ul_config_request_t *ul_config_req) {
+  pthread_mutex_lock(&fill_ul_mutex.crc_mutex);
+  LOG_D(MAC, "fill crc_indication num_crcs: %u\n",
+        UL_INFO->crc_ind.crc_indication_body.number_of_crcs);
+  assert(UL_INFO->crc_ind.crc_indication_body.number_of_crcs < NUMBER_OF_UE_MAX);
   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];
@@ -171,6 +213,8 @@ void fill_crc_indication_UE_MAC(int Mod_id,
         __FUNCTION__,
         pdu->rx_ue_information.rnti,
         UL_INFO->crc_ind.crc_indication_body.number_of_crcs);
+
+  pthread_mutex_unlock(&fill_ul_mutex.crc_mutex);
 }
 
 void fill_rach_indication_UE_MAC(int Mod_id,
@@ -179,6 +223,8 @@ void fill_rach_indication_UE_MAC(int Mod_id,
                                  UL_IND_t *UL_INFO,
                                  uint8_t ra_PreambleIndex,
                                  uint16_t ra_RNTI) {
+  pthread_mutex_lock(&fill_ul_mutex.rach_mutex);
+
   UL_INFO->rach_ind.rach_indication_body.number_of_preambles = 1;
 
   UL_INFO->rach_ind.header.message_id = NFAPI_RACH_INDICATION;
@@ -221,8 +267,15 @@ void fill_rach_indication_UE_MAC(int Mod_id,
 
   // This function is currently defined only in the nfapi-RU-RAU-split so we
   // should call it when we merge with that branch.
-  oai_nfapi_rach_ind(&UL_INFO->rach_ind);
+  if (NFAPI_MODE == NFAPI_MODE_STANDALONE_PNF) {
+    send_standalone_msg(UL_INFO, UL_INFO->rach_ind.header.message_id);
+  } else {
+    oai_nfapi_rach_ind(&UL_INFO->rach_ind);
+  }
+
   free(UL_INFO->rach_ind.rach_indication_body.preamble_list);
+
+  pthread_mutex_unlock(&fill_ul_mutex.rach_mutex);
 }
 
 void fill_ulsch_cqi_indication_UE_MAC(int Mod_id,
@@ -230,6 +283,10 @@ void fill_ulsch_cqi_indication_UE_MAC(int Mod_id,
                                       uint8_t subframe,
                                       UL_IND_t *UL_INFO,
                                       uint16_t rnti) {
+  pthread_mutex_lock(&fill_ul_mutex.cqi_mutex);
+  LOG_D(MAC, "num_cqis: %u in fill_ulsch_cqi_indication_UE_MAC\n",
+        UL_INFO->cqi_ind.cqi_indication_body.number_of_cqis);
+  assert(UL_INFO->cqi_ind.cqi_indication_body.number_of_cqis <= NFAPI_CQI_IND_MAX_PDU);
   nfapi_cqi_indication_pdu_t *pdu =
       &UL_INFO->cqi_ind.cqi_indication_body
            .cqi_pdu_list[UL_INFO->cqi_ind.cqi_indication_body.number_of_cqis];
@@ -240,7 +297,7 @@ void fill_ulsch_cqi_indication_UE_MAC(int Mod_id,
   UL_INFO->cqi_ind.sfn_sf = frame << 4 | subframe;
   // because of nfapi_vnf.c:733, set message id to 0, not
   // NFAPI_RX_CQI_INDICATION;
-  UL_INFO->cqi_ind.header.message_id = 0;
+  UL_INFO->cqi_ind.header.message_id = NFAPI_RX_CQI_INDICATION;
   UL_INFO->cqi_ind.cqi_indication_body.tl.tag = NFAPI_CQI_INDICATION_BODY_TAG;
 
   pdu->rx_ue_information.tl.tag = NFAPI_RX_UE_INFORMATION_TAG;
@@ -256,13 +313,15 @@ void fill_ulsch_cqi_indication_UE_MAC(int Mod_id,
   pdu->cqi_indication_rel8.timing_advance = 0;
   // pdu->cqi_indication_rel8.number_of_cc_reported = 1;
   pdu->ul_cqi_information.tl.tag = NFAPI_UL_CQI_INFORMATION_TAG;
-  pdu->ul_cqi_information.channel = 1; // PUSCH
+  pdu->ul_cqi_information.channel = 1;
 
   // eNB_scheduler_primitives.c:4839: the upper four bits seem to be the CQI
-  const int cqi = 15;
+  const int cqi = get_cqi_from_mcs();
   raw_pdu->pdu[0] = cqi << 4;
 
   UL_INFO->cqi_ind.cqi_indication_body.number_of_cqis++;
+
+  pthread_mutex_unlock(&fill_ul_mutex.cqi_mutex);
 }
 
 void fill_ulsch_harq_indication_UE_MAC(
@@ -271,7 +330,11 @@ void fill_ulsch_harq_indication_UE_MAC(
     int subframe,
     UL_IND_t *UL_INFO,
     nfapi_ul_config_ulsch_harq_information *harq_information,
-    uint16_t rnti) {
+    uint16_t rnti,
+    nfapi_ul_config_request_t *ul_config_req) {
+  pthread_mutex_lock(&fill_ul_mutex.harq_mutex);
+
+  assert(UL_INFO->harq_ind.harq_indication_body.number_of_harqs <= NFAPI_HARQ_IND_MAX_PDU);
   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];
@@ -303,6 +366,8 @@ void fill_ulsch_harq_indication_UE_MAC(
   }
 
   UL_INFO->harq_ind.harq_indication_body.number_of_harqs++;
+
+  pthread_mutex_unlock(&fill_ul_mutex.harq_mutex);
 }
 
 void fill_uci_harq_indication_UE_MAC(int Mod_id,
@@ -310,9 +375,13 @@ void fill_uci_harq_indication_UE_MAC(int Mod_id,
 			      int subframe,
 			      UL_IND_t *UL_INFO,
 			      nfapi_ul_config_harq_information *harq_information,
-			      uint16_t rnti) {
+			      uint16_t rnti,
+            nfapi_ul_config_request_t *ul_config_req) {
+  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;
+  assert(UL_INFO->harq_ind.harq_indication_body.number_of_harqs <= NFAPI_HARQ_IND_MAX_PDU);
   nfapi_harq_indication_pdu_t *pdu =
       &body->harq_pdu_list[UL_INFO->harq_ind.harq_indication_body
                                .number_of_harqs];
@@ -330,7 +399,7 @@ void fill_uci_harq_indication_UE_MAC(int Mod_id,
 
   pdu->ul_cqi_information.tl.tag = NFAPI_UL_CQI_INFORMATION_TAG;
 
-  int SNRtimes10 = 640;
+  int SNRtimes10 = 640;  // TODO: Replace with EpiSci SNR * 10
 
   if (SNRtimes10 < -640)
     pdu->ul_cqi_information.ul_cqi = 0;
@@ -353,6 +422,17 @@ void fill_uci_harq_indication_UE_MAC(int Mod_id,
       pdu->harq_indication_fdd_rel13.harq_tb_n[0] =
           1; // Assuming always an ACK (No NACK or DTX)
 
+      // TODO: Fix ack/dtx -- needed for 5G
+      // 1.) if received dl_config_req (with c-rnti) store this info and corresponding subframe.
+      // 2.) if receiving ul_config_req for uci ack/nack or ulsch ack/nak in subframe n
+      //     go look to see if dl_config_req (with c-rnti) was received in subframe (n - 4)
+      // 3.) if the answer to #2 is yes then send ACK IF NOT send DTX
+      if (did_drop_transport_block(((subframe+6) % 10), rnti))  // TODO:  Handle DTX.  Also discuss handling PDCCH
+      {
+        pdu->harq_indication_fdd_rel13.harq_tb_n[0] = 2;
+        LOG_I(PHY, "Setting HARQ No ACK - Channel Model\n");
+      }
+
     } else if ((harq_information->harq_information_rel9_fdd.ack_nack_mode == 0)
                && (harq_information->harq_information_rel9_fdd.harq_size
                    == 2)) {
@@ -392,6 +472,8 @@ void fill_uci_harq_indication_UE_MAC(int Mod_id,
   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(&fill_ul_mutex.harq_mutex);
 }
 
 void handle_nfapi_ul_pdu_UE_MAC(module_id_t Mod_id,
@@ -399,7 +481,8 @@ void handle_nfapi_ul_pdu_UE_MAC(module_id_t Mod_id,
                                 uint16_t frame,
                                 uint8_t subframe,
                                 uint8_t srs_present,
-                                int index) {
+                                int index,
+                                nfapi_ul_config_request_t *ul_config_req) {
   if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_ULSCH_PDU_TYPE) {
     LOG_D(PHY,
           "Applying UL config for UE, rnti %x for frame %d, subframe %d\n",
@@ -418,7 +501,8 @@ void handle_nfapi_ul_pdu_UE_MAC(module_id_t Mod_id,
               Mod_id,
               frame,
               subframe);
-        fill_crc_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, 0, index, rnti);
+        fill_crc_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, 0, index, rnti,
+                                  ul_config_req);
         fill_rx_indication_UE_MAC(Mod_id,
                                   frame,
                                   subframe,
@@ -426,7 +510,8 @@ void handle_nfapi_ul_pdu_UE_MAC(module_id_t Mod_id,
                                   UE_mac_inst[Mod_id].RA_prach_resources.Msg3,
                                   buflen,
                                   rnti,
-                                  index);
+                                  index,
+                                  ul_config_req);
         Msg3_transmitted(Mod_id, 0, frame, 0);
         //  Modification
         UE_mac_inst[Mod_id].UE_mode[0] = PUSCH;
@@ -436,7 +521,7 @@ void handle_nfapi_ul_pdu_UE_MAC(module_id_t Mod_id,
         // UE_mac_inst[Mod_id].first_ULSCH_Tx = 0;
       } else {
         ue_get_sdu(Mod_id, 0, frame, subframe, 0, ulsch_buffer, buflen, &access_mode);
-        fill_crc_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, 0, index, rnti);
+        fill_crc_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, 0, index, rnti, ul_config_req);
         fill_rx_indication_UE_MAC(Mod_id,
                                   frame,
                                   subframe,
@@ -444,7 +529,8 @@ void handle_nfapi_ul_pdu_UE_MAC(module_id_t Mod_id,
                                   ulsch_buffer,
                                   buflen,
                                   rnti,
-                                  index);
+                                  index,
+                                  ul_config_req);
       }
     }
   }
@@ -462,8 +548,8 @@ void handle_nfapi_ul_pdu_UE_MAC(module_id_t Mod_id,
     uint16_t rnti = ul_config_pdu->ulsch_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti;
     uint8_t access_mode = SCHEDULED_ACCESS;
     if (buflen > 0) {
-      if (UE_mac_inst[Mod_id].first_ULSCH_Tx == 1) { // Msg3 case
-        fill_crc_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, 0, index, rnti);
+      if (UE_mac_inst[Mod_id].first_ULSCH_Tx == 1) {
+        fill_crc_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, 0, index, rnti, ul_config_req);
         fill_rx_indication_UE_MAC(Mod_id,
                                   frame,
                                   subframe,
@@ -471,7 +557,8 @@ void handle_nfapi_ul_pdu_UE_MAC(module_id_t Mod_id,
                                   UE_mac_inst[Mod_id].RA_prach_resources.Msg3,
                                   buflen,
                                   rnti,
-                                  index);
+                                  index,
+                                  ul_config_req);
         Msg3_transmitted(Mod_id, 0, frame, 0);
         // UE_mac_inst[Mod_id].first_ULSCH_Tx = 0;
         // Modification
@@ -479,7 +566,7 @@ void handle_nfapi_ul_pdu_UE_MAC(module_id_t Mod_id,
         UE_mac_inst[Mod_id].first_ULSCH_Tx = 0;
       } else {
         ue_get_sdu(Mod_id, 0, frame, subframe, 0, ulsch_buffer, buflen, &access_mode);
-        fill_crc_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, 0, index, rnti);
+        fill_crc_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, 0, index, rnti, ul_config_req);
         fill_rx_indication_UE_MAC(Mod_id,
                                   frame,
                                   subframe,
@@ -487,12 +574,13 @@ void handle_nfapi_ul_pdu_UE_MAC(module_id_t Mod_id,
                                   ulsch_buffer,
                                   buflen,
                                   rnti,
-                                  index);
+                                  index,
+                                  ul_config_req);
       }
     }
     if (ulsch_harq_information != NULL)
       fill_ulsch_harq_indication_UE_MAC(
-          Mod_id, frame, subframe, UL_INFO, ulsch_harq_information, rnti);
+          Mod_id, frame, subframe, UL_INFO, ulsch_harq_information, rnti, ul_config_req);
 
   } else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_ULSCH_CQI_RI_PDU_TYPE) {
     uint8_t ulsch_buffer[5477] __attribute__((aligned(32)));
@@ -502,7 +590,7 @@ void handle_nfapi_ul_pdu_UE_MAC(module_id_t Mod_id,
     uint8_t access_mode = SCHEDULED_ACCESS;
     if (buflen > 0) {
       if (UE_mac_inst[Mod_id].first_ULSCH_Tx == 1) { // Msg3 case
-        fill_crc_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, 0, index, rnti);
+        fill_crc_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, 0, index, rnti, ul_config_req);
         fill_rx_indication_UE_MAC(Mod_id,
                                   frame,
                                   subframe,
@@ -510,7 +598,8 @@ void handle_nfapi_ul_pdu_UE_MAC(module_id_t Mod_id,
                                   UE_mac_inst[Mod_id].RA_prach_resources.Msg3,
                                   buflen,
                                   rnti,
-                                  index);
+                                  index,
+                                  ul_config_req);
         Msg3_transmitted(Mod_id, 0, frame, 0);
         // UE_mac_inst[Mod_id].first_ULSCH_Tx = 0;
         // Modification
@@ -518,7 +607,7 @@ void handle_nfapi_ul_pdu_UE_MAC(module_id_t Mod_id,
         UE_mac_inst[Mod_id].first_ULSCH_Tx = 0;
       } else {
         ue_get_sdu(Mod_id, 0, frame, subframe, 0, ulsch_buffer, buflen, &access_mode);
-        fill_crc_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, 0, index, rnti);
+        fill_crc_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, 0, index, rnti, ul_config_req);
         fill_rx_indication_UE_MAC(Mod_id,
                                   frame,
                                   subframe,
@@ -526,7 +615,9 @@ void handle_nfapi_ul_pdu_UE_MAC(module_id_t Mod_id,
                                   ulsch_buffer,
                                   buflen,
                                   rnti,
-                                  index);
+                                  index,
+                                  ul_config_req);
+        fill_ulsch_cqi_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, rnti);
       }
     }
   } else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE) {
@@ -539,7 +630,7 @@ void handle_nfapi_ul_pdu_UE_MAC(module_id_t Mod_id,
     uint8_t access_mode = SCHEDULED_ACCESS;
     if (buflen > 0) {
       if (UE_mac_inst[Mod_id].first_ULSCH_Tx == 1) { // Msg3 case
-        fill_crc_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, 0, index, rnti);
+        fill_crc_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, 0, index, rnti, ul_config_req);
         fill_rx_indication_UE_MAC(Mod_id,
                                   frame,
                                   subframe,
@@ -547,7 +638,8 @@ void handle_nfapi_ul_pdu_UE_MAC(module_id_t Mod_id,
                                   UE_mac_inst[Mod_id].RA_prach_resources.Msg3,
                                   buflen,
                                   rnti,
-                                  index);
+                                  index,
+                                  ul_config_req);
         Msg3_transmitted(Mod_id, 0, frame, 0);
         // UE_mac_inst[Mod_id].first_ULSCH_Tx = 0;
         // Modification
@@ -555,7 +647,7 @@ void handle_nfapi_ul_pdu_UE_MAC(module_id_t Mod_id,
         UE_mac_inst[Mod_id].first_ULSCH_Tx = 0;
       } else {
         ue_get_sdu(Mod_id, 0, frame, subframe, 0, ulsch_buffer, buflen, &access_mode);
-        fill_crc_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, 0, index, rnti);
+        fill_crc_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, 0, index, rnti, ul_config_req);
         fill_rx_indication_UE_MAC(Mod_id,
                                   frame,
                                   subframe,
@@ -563,18 +655,20 @@ void handle_nfapi_ul_pdu_UE_MAC(module_id_t Mod_id,
                                   ulsch_buffer,
                                   buflen,
                                   rnti,
-                                  index);
+                                  index,
+                                  ul_config_req);
+        fill_ulsch_cqi_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, rnti);
       }
     }
 
     if (ulsch_harq_information != NULL)
-      fill_ulsch_harq_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, ulsch_harq_information, rnti);
+      fill_ulsch_harq_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, ulsch_harq_information, rnti, ul_config_req);
   } else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE) {
     uint16_t rnti = ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel8.rnti;
 
     nfapi_ul_config_harq_information *ulsch_harq_information = &ul_config_pdu->uci_harq_pdu.harq_information;
     if (ulsch_harq_information != NULL)
-      fill_uci_harq_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, ulsch_harq_information, rnti);
+      fill_uci_harq_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, ulsch_harq_information, rnti, ul_config_req);
   } else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_UCI_CQI_PDU_TYPE) {
     AssertFatal(1 == 0, "NFAPI_UL_CONFIG_UCI_CQI_PDU_TYPE not handled yet\n");
   } else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_UCI_CQI_HARQ_PDU_TYPE) {
@@ -588,7 +682,7 @@ void handle_nfapi_ul_pdu_UE_MAC(module_id_t Mod_id,
         ul_config_pdu->uci_sr_pdu.ue_information.ue_information_rel8.rnti;
 
     if (ue_get_SR(Mod_id, 0, frame, 0, rnti, subframe))
-      fill_sr_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, rnti);
+      fill_sr_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, rnti, ul_config_req);
 
   } else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE) {
     // AssertFatal((UE_id =
@@ -602,13 +696,13 @@ void handle_nfapi_ul_pdu_UE_MAC(module_id_t Mod_id,
     // We fill the sr_indication only if ue_get_sr() would normally instruct PHY
     // to send a SR.
     if (ue_get_SR(Mod_id, 0, frame, 0, rnti, subframe))
-      fill_sr_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, rnti);
+      fill_sr_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, rnti, ul_config_req);
 
     nfapi_ul_config_harq_information *ulsch_harq_information =
         &ul_config_pdu->uci_sr_harq_pdu.harq_information;
     if (ulsch_harq_information != NULL)
       fill_uci_harq_indication_UE_MAC(
-          Mod_id, frame, subframe, UL_INFO, ulsch_harq_information, rnti);
+          Mod_id, frame, subframe, UL_INFO, ulsch_harq_information, rnti, ul_config_req);
   }
 }
 
@@ -625,6 +719,9 @@ int ul_config_req_UE_MAC(nfapi_ul_config_request_t *req,
         req->ul_config_request_body.rach_prach_frequency_resources,
         req->ul_config_request_body.srs_present);
 
+  LOG_D(MAC, "ul_config_req Frame: %d Subframe: %d Proxy Frame: %u Subframe: %u\n",
+        NFAPI_SFNSF2SFN(req->sfn_sf), NFAPI_SFNSF2SF(req->sfn_sf),
+        timer_frame, timer_subframe);
   int sfn = NFAPI_SFNSF2SFN(req->sfn_sf);
   int sf = NFAPI_SFNSF2SF(req->sfn_sf);
 
@@ -654,10 +751,9 @@ int ul_config_req_UE_MAC(nfapi_ul_config_request_t *req,
         || (pdu_type == NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE
             && pdu->uci_cqi_sr_harq_pdu.ue_information.ue_information_rel8.rnti == rnti)) {
       handle_nfapi_ul_pdu_UE_MAC(
-          Mod_id, pdu, sfn, sf, req->ul_config_request_body.srs_present, i);
+          Mod_id, pdu, sfn, sf, req->ul_config_request_body.srs_present, i, req);
     } else {
-      // NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s() PDU:%i UNKNOWN type :%d\n",
-      // __FUNCTION__, i, ul_config_pdu_list[i].pdu_type);
+      LOG_D(MAC, "UNKNOWN UL_CONFIG_REQ PDU_TYPE or RNTI not matching pdu type: %d\n", pdu_type);
     }
   }
 
@@ -693,7 +789,8 @@ void dl_config_req_UE_MAC_dci(int sfn,
                               int sf,
                               nfapi_dl_config_request_pdu_t *dci,
                               nfapi_dl_config_request_pdu_t *dlsch,
-                              int num_ue) {
+                              int num_ue,
+                              nfapi_tx_req_pdu_list_t *tx_req_pdu_list) {
   DevAssert(dci->pdu_type == NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE);
   DevAssert(dlsch->pdu_type == NFAPI_DL_CONFIG_DLSCH_PDU_TYPE);
 
@@ -707,7 +804,7 @@ void dl_config_req_UE_MAC_dci(int sfn,
   }
 
   const int pdu_index = dlsch->dlsch_pdu.dlsch_pdu_rel8.pdu_index;
-  if (pdu_index < 0 || pdu_index >= tx_req_num_elems) {
+  if (pdu_index < 0 || pdu_index >= tx_req_pdu_list->num_pdus) {
     LOG_E(MAC,
           "%s(): Problem with receiving data: "
           "sfn/sf:%d.%d PDU size:%d, TX_PDU index: %d\n",
@@ -716,6 +813,8 @@ void dl_config_req_UE_MAC_dci(int sfn,
     return;
   }
 
+  LOG_I(MAC, "%s() rnti value: 0x%x rnti type: %d\n", __func__,
+        rnti, rnti_type);
   if (rnti_type == 1) { // C-RNTI (Normal DLSCH case)
     for (int ue_id = 0; ue_id < num_ue; ue_id++) {
       if (UE_mac_inst[ue_id].crnti == rnti) {
@@ -725,11 +824,18 @@ void dl_config_req_UE_MAC_dci(int sfn,
               __func__,
               sfn, sf, dci->pdu_size,
               dlsch->dlsch_pdu.dlsch_pdu_rel8.pdu_index,
-              tx_req_num_elems);
-        ue_send_sdu(ue_id, 0, sfn, sf,
-            tx_request_pdu_list[pdu_index].segments[0].segment_data,
-            tx_request_pdu_list[pdu_index].segments[0].segment_length,
-            0);
+              tx_req_pdu_list->num_pdus);
+        if (node_number > 0 || !should_drop_transport_block(sf, dci->dci_dl_pdu.dci_dl_pdu_rel8.rnti))
+        {
+          ue_send_sdu(ue_id, 0, sfn, sf,
+              tx_req_pdu_list->pdus[pdu_index].segments[0].segment_data,
+              tx_req_pdu_list->pdus[pdu_index].segments[0].segment_length,
+              0);
+        }
+        else
+        {
+          LOG_I(MAC, "Transport Block discarded - ue_send_sdu not called. sf: %d", sf);
+        }
         return;
       }
     }
@@ -738,18 +844,18 @@ void dl_config_req_UE_MAC_dci(int sfn,
       for (int ue_id = 0; ue_id < num_ue; ue_id++) {
         if (UE_mac_inst[ue_id].UE_mode[0] == NOT_SYNCHED)
           continue;
-
         ue_decode_si(ue_id, 0, sfn, 0,
-            tx_request_pdu_list[pdu_index].segments[0].segment_data,
-            tx_request_pdu_list[pdu_index].segments[0].segment_length);
+            tx_req_pdu_list->pdus[pdu_index].segments[0].segment_data,
+            tx_req_pdu_list->pdus[pdu_index].segments[0].segment_length);
       }
     } else if (rnti == 0xFFFE) { /* PI-RNTI */
       for (int ue_id = 0; ue_id < num_ue; ue_id++) {
         LOG_I(MAC, "%s() Received paging message: sfn/sf:%d.%d\n",
               __func__, sfn, sf);
+
         ue_decode_p(ue_id, 0, sfn, 0,
-                    tx_request_pdu_list[pdu_index].segments[0].segment_data,
-                    tx_request_pdu_list[pdu_index].segments[0].segment_length);
+                    tx_req_pdu_list->pdus[pdu_index].segments[0].segment_data,
+                    tx_req_pdu_list->pdus[pdu_index].segments[0].segment_length);
       }
     } else if (rnti == 0x0002) { /* RA-RNTI */
       for (int ue_id = 0; ue_id < num_ue; ue_id++) {
@@ -769,19 +875,21 @@ void dl_config_req_UE_MAC_dci(int sfn,
           LOG_E(MAC,
                 "%s(): Received RAR, PreambleIndex: %d\n",
                 __func__, UE_mac_inst[ue_id].RA_prach_resources.ra_PreambleIndex);
+
           ue_process_rar(ue_id, 0, sfn,
               ra_rnti, //RA-RNTI
-              tx_request_pdu_list[pdu_index].segments[0].segment_data,
+              tx_req_pdu_list->pdus[pdu_index].segments[0].segment_data,
               &UE_mac_inst[ue_id].crnti, //t-crnti
               UE_mac_inst[ue_id].RA_prach_resources.ra_PreambleIndex,
-              tx_request_pdu_list[pdu_index].segments[0].segment_data);
-          UE_mac_inst[ue_id].UE_mode[0] = RA_RESPONSE;
+              tx_req_pdu_list->pdus[pdu_index].segments[0].segment_data);
+          // UE_mac_inst[ue_id].UE_mode[0] = RA_RESPONSE;
+          LOG_I(MAC, "setting UE_MODE now: %d\n", UE_mac_inst[ue_id].UE_mode[0]);
           // Expecting an UL_CONFIG_ULSCH_PDU to enable Msg3 Txon (first
           // ULSCH Txon for the UE)
           UE_mac_inst[ue_id].first_ULSCH_Tx = 1;
         }
       }
-    } 
+    }
     //else if (dl_config_pdu_list[i].pdu_type == NFAPI_DL_CONFIG_BCH_PDU_TYPE) {
     //  // BCH case: Last parameter is 1 if first time synchronization and zero
     //  // otherwise.  Not sure which value to put for our case.
@@ -810,7 +918,7 @@ void dl_config_req_UE_MAC_dci(int sfn,
     //        tx_request_pdu_list[pdu_index].segments[0].segment_length,
     //        0,0);
 
-    //} 
+    //}
     else {
       LOG_W(MAC, "can not handle special RNTI %x\n", rnti);
     }
@@ -842,7 +950,8 @@ void dl_config_req_UE_MAC_bch(int sfn,
 void dl_config_req_UE_MAC_mch(int sfn,
                               int sf,
                               nfapi_dl_config_request_pdu_t *mch,
-                              int num_ue) {
+                              int num_ue,
+                              nfapi_tx_req_pdu_list_t *tx_req_pdu_list) {
   DevAssert(mch->pdu_type == NFAPI_DL_CONFIG_MCH_PDU_TYPE);
 
   for (int ue_id = 0; ue_id < num_ue; ue_id++) {
@@ -857,7 +966,7 @@ void dl_config_req_UE_MAC_mch(int sfn,
 
     } else {
 	 const int pdu_index = mch->mch_pdu.mch_pdu_rel8.pdu_index;
-  	if (pdu_index < 0 || pdu_index >= tx_req_num_elems) {
+	if (pdu_index < 0 || pdu_index >= tx_req_pdu_list->num_pdus) {
     	LOG_E(MAC,
           "%s(): Problem with receiving data: "
           "sfn/sf:%d.%d PDU size:%d, TX_PDU index: %d\n",
@@ -866,8 +975,8 @@ void dl_config_req_UE_MAC_mch(int sfn,
     	return;
   	}
         ue_send_mch_sdu(ue_id, 0, sfn,
-            tx_request_pdu_list[pdu_index].segments[0].segment_data,
-            tx_request_pdu_list[pdu_index].segments[0].segment_length,
+            tx_req_pdu_list->pdus[pdu_index].segments[0].segment_data,
+            tx_req_pdu_list->pdus[pdu_index].segments[0].segment_length,
             0,0);
     }
   }
@@ -885,7 +994,6 @@ void hi_dci0_req_UE_MAC(int sfn,
     return;
   for (int ue_id = 0; ue_id < num_ue; ue_id++) {
     if (dci->rnti == UE_mac_inst[ue_id].crnti) {
-      fill_ulsch_cqi_indication_UE_MAC(ue_id, sfn, sf, UL_INFO, dci->rnti);
       return;
     }
   }
@@ -893,114 +1001,147 @@ void hi_dci0_req_UE_MAC(int sfn,
 
 // The following set of memcpy functions should be getting called as callback
 // functions from pnf_p7_subframe_ind.
-int memcpy_dl_config_req(L1_rxtx_proc_t *proc, 
-			nfapi_pnf_p7_config_t *pnf_p7,
-                         nfapi_dl_config_request_t *req) {
-  dl_config_req = (nfapi_dl_config_request_t *)malloc(sizeof(nfapi_dl_config_request_t));
-
-  // UE_mac_inst[Mod_id].dl_config_req->header = req->header;
-  dl_config_req->sfn_sf = req->sfn_sf;
-
-  dl_config_req->vendor_extension = req->vendor_extension;
-
-  dl_config_req->dl_config_request_body.number_dci = req->dl_config_request_body.number_dci;
-  dl_config_req->dl_config_request_body.number_pdcch_ofdm_symbols = req->dl_config_request_body.number_pdcch_ofdm_symbols;
-  dl_config_req->dl_config_request_body.number_pdsch_rnti = req->dl_config_request_body.number_pdsch_rnti;
-  dl_config_req->dl_config_request_body.number_pdu = req->dl_config_request_body.number_pdu;
-
-  dl_config_req->dl_config_request_body.tl.tag = req->dl_config_request_body.tl.tag;
-  dl_config_req->dl_config_request_body.tl.length = req->dl_config_request_body.tl.length;
 
-  dl_config_req->dl_config_request_body.dl_config_pdu_list =
-      calloc(req->dl_config_request_body.number_pdu,
-             sizeof(nfapi_dl_config_request_pdu_t));
-  for (int i = 0; i < dl_config_req->dl_config_request_body.number_pdu; i++) {
-    dl_config_req->dl_config_request_body.dl_config_pdu_list[i] =
-        req->dl_config_request_body.dl_config_pdu_list[i];
+static bool is_my_ul_config_req(nfapi_ul_config_request_t *req)
+{
+  bool is_my_rnti = false;
+  const rnti_t rnti = UE_mac_inst[0].crnti; // 0 for standalone pnf mode. TODO: Make this more clear - Andrew
+  for (int i = 0; i < req->ul_config_request_body.number_of_pdus; i++)
+  {
+    nfapi_ul_config_request_pdu_t *pdu = &req->ul_config_request_body.ul_config_pdu_list[i];
+    const int pdu_type = pdu->pdu_type;
+    if ((pdu_type == NFAPI_UL_CONFIG_ULSCH_PDU_TYPE && pdu->ulsch_pdu.ulsch_pdu_rel8.rnti == rnti) ||
+        (pdu_type == NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE && pdu->ulsch_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti) ||
+        (pdu_type == NFAPI_UL_CONFIG_ULSCH_CQI_RI_PDU_TYPE && pdu->ulsch_cqi_ri_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti) ||
+        (pdu_type == NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE && pdu->ulsch_cqi_harq_ri_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti) ||
+        (pdu_type == NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE && pdu->uci_cqi_harq_pdu.ue_information.ue_information_rel8.rnti == rnti) ||
+        (pdu_type == NFAPI_UL_CONFIG_UCI_SR_PDU_TYPE && pdu->uci_sr_pdu.ue_information.ue_information_rel8.rnti == rnti) ||
+        (pdu_type == NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE && pdu->uci_cqi_sr_harq_pdu.ue_information.ue_information_rel8.rnti == rnti))
+    {
+      is_my_rnti = true;
+      break;
+    }
+    else
+    {
+      LOG_D(MAC, "UNKNOWN UL_CONFIG_REQ PDU_TYPE: %d or RNTI is not mine \n", pdu_type);
+    }
   }
 
-  return 0;
+  return is_my_rnti;
 }
 
-int memcpy_ul_config_req (L1_rxtx_proc_t *proc, nfapi_pnf_p7_config_t* pnf_p7, nfapi_ul_config_request_t* req)
+int memcpy_ul_config_req(L1_rxtx_proc_t *proc, nfapi_pnf_p7_config_t *pnf_p7, nfapi_ul_config_request_t *req)
 {
-  ul_config_req = malloc(sizeof(nfapi_ul_config_request_t));
+  if (!is_my_ul_config_req(req)) return 0;
 
+  nfapi_ul_config_request_t *p = malloc(sizeof(nfapi_ul_config_request_t));
 
-  ul_config_req->sfn_sf = req->sfn_sf;
-  ul_config_req->vendor_extension = req->vendor_extension;
+  p->sfn_sf = req->sfn_sf;
+  p->vendor_extension = req->vendor_extension;
 
-  ul_config_req->ul_config_request_body.number_of_pdus = req->ul_config_request_body.number_of_pdus;
-  ul_config_req->ul_config_request_body.rach_prach_frequency_resources = req->ul_config_request_body.rach_prach_frequency_resources;
-  ul_config_req->ul_config_request_body.srs_present = req->ul_config_request_body.srs_present;
+  p->ul_config_request_body.number_of_pdus = req->ul_config_request_body.number_of_pdus;
+  p->ul_config_request_body.rach_prach_frequency_resources = req->ul_config_request_body.rach_prach_frequency_resources;
+  p->ul_config_request_body.srs_present = req->ul_config_request_body.srs_present;
 
-  ul_config_req->ul_config_request_body.tl.tag = req->ul_config_request_body.tl.tag;
-  ul_config_req->ul_config_request_body.tl.length = req->ul_config_request_body.tl.length;
+  p->ul_config_request_body.tl.tag = req->ul_config_request_body.tl.tag;
+  p->ul_config_request_body.tl.length = req->ul_config_request_body.tl.length;
 
-  ul_config_req->ul_config_request_body.ul_config_pdu_list =
+  p->ul_config_request_body.ul_config_pdu_list =
       calloc(req->ul_config_request_body.number_of_pdus,
              sizeof(nfapi_ul_config_request_pdu_t));
-  for (int i = 0; i < ul_config_req->ul_config_request_body.number_of_pdus; i++) {
-    ul_config_req->ul_config_request_body.ul_config_pdu_list[i] =
+  for (int i = 0; i < p->ul_config_request_body.number_of_pdus; i++)
+  {
+    p->ul_config_request_body.ul_config_pdu_list[i] =
         req->ul_config_request_body.ul_config_pdu_list[i];
   }
 
+  if (!put_queue(&ul_config_req_queue, p))
+  {
+    free(p);
+  }
+
   return 0;
 }
 
-int memcpy_tx_req(nfapi_pnf_p7_config_t *pnf_p7, nfapi_tx_request_t *req) {
-  tx_req_num_elems = req->tx_request_body.number_of_pdus;
-  tx_request_pdu_list = calloc(tx_req_num_elems, sizeof(nfapi_tx_request_pdu_t));
-  for (int i = 0; i < tx_req_num_elems; i++) {
-    tx_request_pdu_list[i].num_segments = req->tx_request_body.tx_pdu_list[i].num_segments;
-    tx_request_pdu_list[i].pdu_index = req->tx_request_body.tx_pdu_list[i].pdu_index;
-    tx_request_pdu_list[i].pdu_length = req->tx_request_body.tx_pdu_list[i].pdu_length;
-    for (int j = 0; j < req->tx_request_body.tx_pdu_list[i].num_segments; j++) {
-      tx_request_pdu_list[i].segments[j].segment_length = req->tx_request_body.tx_pdu_list[i].segments[j].segment_length;
-      if (tx_request_pdu_list[i].segments[j].segment_length > 0) {
-        tx_request_pdu_list[i].segments[j].segment_data = calloc(
-            tx_request_pdu_list[i].segments[j].segment_length, sizeof(uint8_t));
-        memcpy(tx_request_pdu_list[i].segments[j].segment_data,
-               req->tx_request_body.tx_pdu_list[i].segments[j].segment_data,
-               tx_request_pdu_list[i].segments[j].segment_length);
-      }
+void nfapi_free_tx_req_pdu_list(nfapi_tx_req_pdu_list_t *list)
+{
+  // free all the p[i].segments[j].segment_data memory
+  int num_pdus = list->num_pdus;
+  nfapi_tx_request_pdu_t *pdus = list->pdus;
+  for (int i = 0; i < num_pdus; i++) {
+    int num_segments = pdus[i].num_segments;
+    for (int j = 0; j < num_segments; j++) {
+      free(pdus[i].segments[j].segment_data);
+      pdus[i].segments[j].segment_data = NULL;
     }
   }
+  free(list);
+}
 
-  return 0;
+static bool is_my_hi_dci0_req(nfapi_hi_dci0_request_t *hi_dci0_req)
+{
+  bool is_my_rnti = false;
+  const rnti_t rnti = UE_mac_inst[0].crnti; // This is 0 representing the num_ues is 1
+  nfapi_hi_dci0_request_body_t *hi_dci0_body = &hi_dci0_req->hi_dci0_request_body;
+  for (int i = 0; i < hi_dci0_body->number_of_dci + hi_dci0_body->number_of_hi; i++)
+  {
+    nfapi_hi_dci0_request_pdu_t *hi_dci0 = &hi_dci0_body->hi_dci0_pdu_list[i];
+    if (hi_dci0->pdu_type != NFAPI_HI_DCI0_DCI_PDU_TYPE || hi_dci0->dci_pdu.dci_pdu_rel8.cqi_csi_request)
+    {
+      continue;
+    }
+    if (hi_dci0->dci_pdu.dci_pdu_rel8.rnti == rnti)
+    {
+      is_my_rnti = true;
+      break;
+    }
+  }
+
+  return is_my_rnti;
 }
 
-int memcpy_hi_dci0_req (L1_rxtx_proc_t *proc, 
-			nfapi_pnf_p7_config_t* pnf_p7, 
+int memcpy_hi_dci0_req (L1_rxtx_proc_t *proc,
+			nfapi_pnf_p7_config_t* pnf_p7,
 			nfapi_hi_dci0_request_t* req) {
-  hi_dci0_req = (nfapi_hi_dci0_request_t *)malloc(sizeof(nfapi_hi_dci0_request_t));
+
+  if (!is_my_hi_dci0_req(req))
+  {
+    LOG_I(MAC, "Filtering hi_dci0_req\n");
+    return 0;
+  }
+  nfapi_hi_dci0_request_t *p = (nfapi_hi_dci0_request_t *)malloc(sizeof(nfapi_hi_dci0_request_t));
 	//if(req!=0){
 
 
-  hi_dci0_req->sfn_sf = req->sfn_sf;
-  hi_dci0_req->vendor_extension = req->vendor_extension;
+  p->sfn_sf = req->sfn_sf;
+  p->vendor_extension = req->vendor_extension;
 
-  hi_dci0_req->hi_dci0_request_body.number_of_dci = req->hi_dci0_request_body.number_of_dci;
-  hi_dci0_req->hi_dci0_request_body.number_of_hi = req->hi_dci0_request_body.number_of_hi;
-  hi_dci0_req->hi_dci0_request_body.sfnsf = req->hi_dci0_request_body.sfnsf;
+  p->hi_dci0_request_body.number_of_dci = req->hi_dci0_request_body.number_of_dci;
+  p->hi_dci0_request_body.number_of_hi = req->hi_dci0_request_body.number_of_hi;
+  p->hi_dci0_request_body.sfnsf = req->hi_dci0_request_body.sfnsf;
 
-  // UE_mac_inst[Mod_id].hi_dci0_req->hi_dci0_request_body.tl =
+  // UE_mac_inst[Mod_id].p->hi_dci0_request_body.tl =
   // req->hi_dci0_request_body.tl;
-  hi_dci0_req->hi_dci0_request_body.tl.tag = req->hi_dci0_request_body.tl.tag;
-  hi_dci0_req->hi_dci0_request_body.tl.length = req->hi_dci0_request_body.tl.length;
+  p->hi_dci0_request_body.tl.tag = req->hi_dci0_request_body.tl.tag;
+  p->hi_dci0_request_body.tl.length = req->hi_dci0_request_body.tl.length;
 
-  int total_pdus = hi_dci0_req->hi_dci0_request_body.number_of_dci
-                   + hi_dci0_req->hi_dci0_request_body.number_of_hi;
+  int total_pdus = p->hi_dci0_request_body.number_of_dci
+                   + p->hi_dci0_request_body.number_of_hi;
 
-  hi_dci0_req->hi_dci0_request_body.hi_dci0_pdu_list =
+  p->hi_dci0_request_body.hi_dci0_pdu_list =
       calloc(total_pdus, sizeof(nfapi_hi_dci0_request_pdu_t));
 
   for (int i = 0; i < total_pdus; i++) {
-    hi_dci0_req->hi_dci0_request_body.hi_dci0_pdu_list[i] = req->hi_dci0_request_body.hi_dci0_pdu_list[i];
+    p->hi_dci0_request_body.hi_dci0_pdu_list[i] = req->hi_dci0_request_body.hi_dci0_pdu_list[i];
     // LOG_I(MAC, "Original hi_dci0 req. type:%d, Copy type: %d
     // \n",req->hi_dci0_request_body.hi_dci0_pdu_list[i].pdu_type,
-    // UE_mac_inst[Mod_id].hi_dci0_req->hi_dci0_request_body.hi_dci0_pdu_list[i].pdu_type);
+    // UE_mac_inst[Mod_id].p->hi_dci0_request_body.hi_dci0_pdu_list[i].pdu_type);
+  }
+
+  if (!put_queue(&hi_dci0_req_queue, p)) {
+    free(p);
   }
+  LOG_I(MAC, "DCI0 QUEUE: %zu\n", hi_dci0_req_queue.num_items);
   return 0;
 }
 
@@ -1039,6 +1180,9 @@ void UE_config_stub_pnf(void) {
             *(L1_ParamList.paramarray[j][L1_REMOTE_N_PORTD_IDX].iptr);
         stub_eth_params.transp_preference = ETH_UDP_MODE;
 
+        if (NFAPI_MODE!=NFAPI_UE_STUB_PNF)
+          continue;
+
         sf_ahead = 2; // Cannot cope with 4 subframes betweem RX and TX - set it to 2
         // configure_nfapi_pnf(UE_mac_inst[0].eth_params_n.remote_addr,
         // UE_mac_inst[0].eth_params_n.remote_portc,
@@ -1055,79 +1199,934 @@ void UE_config_stub_pnf(void) {
   }
 }
 
-/* Dummy functions*/
+void ue_init_standalone_socket(int tx_port, int rx_port)
+{
+  {
+    struct sockaddr_in server_address;
+    int addr_len = sizeof(server_address);
+    memset(&server_address, 0, addr_len);
+    server_address.sin_family = AF_INET;
+    server_address.sin_port = htons(tx_port);
+
+    int sd = socket(server_address.sin_family, SOCK_DGRAM, 0);
+    if (sd < 0)
+    {
+      LOG_E(MAC, "Socket creation error standalone PNF\n");
+      return;
+    }
 
-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) {
+    if (inet_pton(server_address.sin_family, stub_eth_params.remote_addr, &server_address.sin_addr) <= 0)
+    {
+      LOG_E(MAC, "Invalid standalone PNF Address\n");
+      close(sd);
+      return;
+    }
+
+    // Using connect to use send() instead of sendto()
+    if (connect(sd, (struct sockaddr *)&server_address, addr_len) < 0)
+    {
+      LOG_E(MAC, "Connection to standalone PNF failed: %s\n", strerror(errno));
+      close(sd);
+      return;
+    }
+    assert(ue_tx_sock_descriptor == -1);
+    ue_tx_sock_descriptor = sd;
+  }
+
+  {
+    struct sockaddr_in server_address;
+    int addr_len = sizeof(server_address);
+    memset(&server_address, 0, addr_len);
+    server_address.sin_family = AF_INET;
+    server_address.sin_addr.s_addr = INADDR_ANY;
+    server_address.sin_port = htons(rx_port);
+
+    int sd = socket(server_address.sin_family, SOCK_DGRAM, 0);
+    if (sd < 0)
+    {
+      LOG_E(MAC, "Socket creation error standalone PNF\n");
+      return;
+    }
+
+    if (bind(sd, (struct sockaddr *)&server_address, addr_len) < 0)
+    {
+      LOG_E(MAC, "Connection to standalone PNF failed: %s\n", strerror(errno));
+      close(sd);
+      return;
+    }
+    assert(ue_rx_sock_descriptor == -1);
+    ue_rx_sock_descriptor = sd;
+  }
 }
 
-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 *ue_standalone_pnf_task(void *context)
+{
+  struct sockaddr_in server_address;
+  socklen_t addr_len = sizeof(server_address);
+  char buffer[NFAPI_MAX_PACKED_MESSAGE_SIZE];
+  int sd = ue_rx_sock_descriptor;
+  assert(sd > 0);
+
+  nfapi_tx_request_t tx_req;
+  nfapi_dl_config_request_t dl_config_req;
+  bool tx_req_valid = false;
+  bool dl_config_req_valid = false;
+  while (true)
+  {
+    ssize_t len = recvfrom(sd, buffer, sizeof(buffer), MSG_TRUNC, (struct sockaddr *)&server_address, &addr_len);
+    if (len == -1)
+    {
+      LOG_E(MAC, "reading from standalone pnf sctp socket failed \n");
+      continue;
+    }
+    if (len > sizeof(buffer))
+    {
+      LOG_E(MAC, "%s(%d). Message truncated. %zd\n", __FUNCTION__, __LINE__, len);
+      continue;
+    }
+
+    /* First we'll check for possible messages from the proxy. We do this by checking
+       the length of the message. This works because sizeof(uint16_t) < sizeof(nfapi_p7_message_header_t)
+       and sizeof(phy_channel_params_t) < sizeof(nfapi_p7_message_header_t) and
+       sizeof(uint16_t) != sizeof(phy_channel_params_t). */
+    if (len == sizeof(uint16_t))
+    {
+      uint16_t sfn_sf = 0;
+      memcpy((void *)&sfn_sf, buffer, sizeof(sfn_sf));
+      current_sfn_sf = sfn_sf;
+
+      if (sem_post(&sfn_semaphore) != 0)
+      {
+        LOG_E(MAC, "sem_post() error\n");
+        abort();
+      }
+    }
+    else if (len == sizeof(phy_channel_params_t))
+    {
+      phy_channel_params_t ch_info;
+      memcpy(&ch_info, buffer, sizeof(phy_channel_params_t));
+      current_sfn_sf = ch_info.sfn_sf;
+      if (sem_post(&sfn_semaphore) != 0)
+      {
+        LOG_E(MAC, "sem_post() error\n");
+        abort();
+      }
+      uint16_t sf = ch_info.sfn_sf & 15;
+      assert(sf < 10);
+
+      sf_rnti_mcs[sf].sinr = ch_info.sinr;
+      LOG_D(MAC, "Received_SINR = %f\n",ch_info.sinr);
+    }
+    else
+    {
+      nfapi_p7_message_header_t header;
+      if (nfapi_p7_message_header_unpack((void *)buffer, len, &header, sizeof(header), NULL) < 0)
+      {
+        LOG_E(MAC, "Header unpack failed for standalone pnf\n");
+        continue;
+      }
+      switch (header.message_id)
+      {
+      case NFAPI_DL_CONFIG_REQUEST:
+      {
+        if (dl_config_req_valid)
+        {
+          LOG_W(MAC, "Received consecutive dl_config_reqs. Previous dl_config_req frame: %u, subframe: %u\n",
+                dl_config_req.sfn_sf >> 4, dl_config_req.sfn_sf & 15);
+        }
+        if (nfapi_p7_message_unpack((void *)buffer, len, &dl_config_req,
+                                    sizeof(dl_config_req), NULL) < 0)
+        {
+          LOG_E(MAC, "Message dl_config_req failed to unpack\n");
+          break;
+        }
+
+        LOG_I(MAC, "dl_config_req Frame: %u Subframe: %u\n", dl_config_req.sfn_sf >> 4,
+              dl_config_req.sfn_sf & 15);
+
+        dl_config_req_valid = true;
+
+        save_dci_pdu_for_crnti(&dl_config_req);
+
+        if (tx_req_valid)
+        {
+          if (dl_config_req.sfn_sf != tx_req.sfn_sf)
+          {
+              LOG_W(MAC, "sfnsf mismatch. dl_config_req Frame: %u Subframe: %u, Discarding tx_req Frame: %u Subframe: %u\n",
+                    dl_config_req.sfn_sf >> 4, dl_config_req.sfn_sf & 15,
+                    tx_req.sfn_sf >> 4, tx_req.sfn_sf & 15);
+              tx_req_valid = false;
+              break;
+          }
+          enqueue_dl_config_req_tx_req(&dl_config_req, &tx_req);
+          dl_config_req_valid = false;
+          tx_req_valid = false;
+        }
+
+        break;
+      }
+      case NFAPI_TX_REQUEST:
+      {
+        if (tx_req_valid)
+        {
+          LOG_W(MAC, "Received consecutive tx_reqs. Previous tx_req frame: %u, subframe: %u\n",
+                tx_req.sfn_sf >> 4, tx_req.sfn_sf & 15);
+        }
+        if (nfapi_p7_message_unpack((void *)buffer, len, &tx_req,
+                                    sizeof(tx_req), NULL) < 0)
+        {
+          LOG_E(MAC, "Message tx_req failed to unpack\n");
+          break;
+        }
+
+        LOG_I(MAC, "tx_req Frame: %u Subframe: %u\n", tx_req.sfn_sf >> 4,
+              tx_req.sfn_sf & 15);
+
+        tx_req_valid = true;
+        if (dl_config_req_valid)
+        {
+          if (dl_config_req.sfn_sf != tx_req.sfn_sf)
+          {
+              LOG_W(MAC, "sfnsf mismatch. Discarding dl_config_req Frame: %u Subframe: %u, tx_req Frame: %u Subframe: %u\n",
+                    dl_config_req.sfn_sf >> 4, dl_config_req.sfn_sf & 15,
+                    tx_req.sfn_sf >> 4, tx_req.sfn_sf & 15);
+              dl_config_req_valid = false;
+              break;
+          }
+          enqueue_dl_config_req_tx_req(&dl_config_req, &tx_req);
+          dl_config_req_valid = false;
+          tx_req_valid = false;
+        }
+
+        break;
+      }
+      case NFAPI_HI_DCI0_REQUEST:
+      {
+        nfapi_hi_dci0_request_t hi_dci0_req;
+        // lock this hi_dci0_req
+        if (nfapi_p7_message_unpack((void *)buffer, len, &hi_dci0_req,
+                                    sizeof(hi_dci0_req), NULL) < 0)
+        {
+          LOG_E(MAC, "Message hi_dci0_req failed to unpack\n");
+          break;
+        }
+
+        // check to see if hi_dci0_req is null
+        memcpy_hi_dci0_req(NULL, NULL, &hi_dci0_req);
+
+        break;
+      }
+      case NFAPI_UL_CONFIG_REQUEST:
+      {
+        nfapi_ul_config_request_t ul_config_req;
+        // lock this ul_config_req
+        if (nfapi_p7_message_unpack((void *)buffer, len, &ul_config_req,
+                                    sizeof(ul_config_req), NULL) < 0)
+        {
+          LOG_E(MAC, "Message ul_config_req failed to unpack\n");
+          break;
+        }
+
+        // check to see if ul_config_req is null
+        memcpy_ul_config_req(NULL, NULL, &ul_config_req);
+
+        break;
+      }
+      default:
+        LOG_E(MAC, "Case Statement has no corresponding nfapi message\n");
+        break;
+      }
+    }
+  }
+}
+
+static void save_dci_pdu_for_crnti(nfapi_dl_config_request_t *dl_config_req)
+{
+  int count_sent = 0;
+  int number_of_dci = dl_config_req->dl_config_request_body.number_dci;
+  int number_of_pdu = dl_config_req->dl_config_request_body.number_pdu;
+  if (number_of_pdu <= 0)
+  {
+    LOG_E(MAC, "%s: dl_config_req pdu size <= 0\n", __FUNCTION__);
+    abort();
+  }
+  if (number_of_dci > 0)
+  {
+    for (int n = 0; n < number_of_pdu; n++)
+    {
+      const nfapi_dl_config_request_pdu_t *current_pdu_list = &dl_config_req->dl_config_request_body.dl_config_pdu_list[n];
+      int rnti_type = current_pdu_list->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type;
+      if (current_pdu_list->pdu_type == NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE && rnti_type == 1 && count_sent < number_of_dci)
+      {
+        read_channel_param(current_pdu_list, (dl_config_req->sfn_sf & 15), count_sent);
+        count_sent++;
+      }
+    }
+  }
+}
+
+void *memcpy_dl_config_req_standalone(nfapi_dl_config_request_t *dl_config_req)
+{
+  nfapi_dl_config_request_t *p = malloc(sizeof(nfapi_dl_config_request_t));
+
+  p->sfn_sf = dl_config_req->sfn_sf;
+
+  p->vendor_extension = dl_config_req->vendor_extension;
+
+  p->dl_config_request_body.number_dci = dl_config_req->dl_config_request_body.number_dci;
+  p->dl_config_request_body.number_pdcch_ofdm_symbols = dl_config_req->dl_config_request_body.number_pdcch_ofdm_symbols;
+  p->dl_config_request_body.number_pdsch_rnti = dl_config_req->dl_config_request_body.number_pdsch_rnti;
+  p->dl_config_request_body.number_pdu = dl_config_req->dl_config_request_body.number_pdu;
+
+  p->dl_config_request_body.tl.tag = dl_config_req->dl_config_request_body.tl.tag;
+  p->dl_config_request_body.tl.length = dl_config_req->dl_config_request_body.tl.length;
+
+  p->dl_config_request_body.dl_config_pdu_list =
+      calloc(dl_config_req->dl_config_request_body.number_pdu,
+             sizeof(nfapi_dl_config_request_pdu_t));
+  for (int i = 0; i < p->dl_config_request_body.number_pdu; i++) {
+    p->dl_config_request_body.dl_config_pdu_list[i] =
+        dl_config_req->dl_config_request_body.dl_config_pdu_list[i];
+  }
+  return p;
 }
 
-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 *memcpy_tx_req_standalone(nfapi_tx_request_t *tx_req)
+{
+  int num_pdus = tx_req->tx_request_body.number_of_pdus;
+
+  nfapi_tx_req_pdu_list_t *list = calloc(1, sizeof(nfapi_tx_req_pdu_list_t) + num_pdus * sizeof(nfapi_tx_request_pdu_t));
+  list->num_pdus = num_pdus;
+  nfapi_tx_request_pdu_t *p = list->pdus;
+
+  for (int i = 0; i < num_pdus; i++)
+  {
+    p[i].num_segments = tx_req->tx_request_body.tx_pdu_list[i].num_segments;
+    p[i].pdu_index = tx_req->tx_request_body.tx_pdu_list[i].pdu_index;
+    p[i].pdu_length = tx_req->tx_request_body.tx_pdu_list[i].pdu_length;
+    for (int j = 0; j < tx_req->tx_request_body.tx_pdu_list[i].num_segments; j++)
+    {
+      p[i].segments[j].segment_length = tx_req->tx_request_body.tx_pdu_list[i].segments[j].segment_length;
+      if (p[i].segments[j].segment_length > 0)
+      {
+        p[i].segments[j].segment_data = calloc(
+            p[i].segments[j].segment_length, sizeof(uint8_t));
+        memcpy(p[i].segments[j].segment_data,
+               tx_req->tx_request_body.tx_pdu_list[i].segments[j].segment_data,
+               p[i].segments[j].segment_length);
+      }
+    }
+  }
+  return list;
 }
 
-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) {
+static bool is_my_dl_config_req(const nfapi_dl_config_request_t *req)
+{
+
+  const rnti_t my_rnti = UE_mac_inst[0].crnti;
+  int num_pdus = req->dl_config_request_body.number_pdu;
+  // look through list of pdus for rnti type 1 with my_rnti (normal dlsch case)
+  for (int i = 0; i < num_pdus; i++)
+  {
+    nfapi_dl_config_request_pdu_t *pdu = &req->dl_config_request_body.dl_config_pdu_list[i];
+    const int pdu_type = pdu->pdu_type;
+    if (pdu_type == NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE)
+    {
+      const rnti_t dci_rnti = pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti;
+      const int rnti_type = pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type;
+      if (rnti_type == 1 && dci_rnti == my_rnti)
+      {
+        return true;
+      }
+    }
+    else if(pdu_type != NFAPI_DL_CONFIG_DLSCH_PDU_TYPE)
+    {
+      return true; // Because these two pdu_types are coupled and we have to accept all other pdu_types
+    }
+  }
+
+  // Look for broadcasted rnti types
+  for (int i = 0; i < num_pdus; i++)
+  {
+    nfapi_dl_config_request_pdu_t *pdu = &req->dl_config_request_body.dl_config_pdu_list[i];
+    const int pdu_type = pdu->pdu_type;
+    if (pdu_type == NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE)
+    {
+      const int rnti_type = pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type;
+      if (rnti_type != 1)
+      {
+        return true;
+      }
+    }
+  }
+
+
+  return false;
 }
 
-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 enqueue_dl_config_req_tx_req(nfapi_dl_config_request_t *dl_config_req, nfapi_tx_request_t *tx_req)
+{
+  if (!is_my_dl_config_req(dl_config_req))
+  {
+    LOG_I(MAC, "Filtering dl_config_req and tx_req\n");
+    return;
+  }
+
+  nfapi_dl_config_request_t *dl_config_req_temp = memcpy_dl_config_req_standalone(dl_config_req);
+  nfapi_tx_req_pdu_list_t *tx_req_temp = memcpy_tx_req_standalone(tx_req);
+  LOG_I(MAC, "This is the num_pdus for tx_req: %d\n", tx_req_temp->num_pdus);
+  LOG_I(MAC, "This is the num_pdus for dl_config_req and the sfn_sf: %d, %d:%d\n", dl_config_req_temp->dl_config_request_body.number_pdu,
+        NFAPI_SFNSF2SFN(dl_config_req_temp->sfn_sf), NFAPI_SFNSF2SF(dl_config_req_temp->sfn_sf));
+
+  nfapi_dl_config_req_tx_req_t *req = malloc(sizeof(nfapi_dl_config_req_tx_req_t));
+  req->dl_config_req = dl_config_req_temp;
+  req->tx_req_pdu_list = tx_req_temp;
+
+  if (!put_queue(&dl_config_req_tx_req_queue, req))
+  {
+    free(req->dl_config_req);
+    nfapi_free_tx_req_pdu_list(req->tx_req_pdu_list);
+    free(req);
+  }
 }
 
-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) {
+
+__attribute__((unused))
+static void print_rx_ind(nfapi_rx_indication_t *p)
+{
+  printf("Printing RX_IND fields\n");
+  printf("header.message_id: %u\n", p->header.message_id);
+  printf("header.phy_id: %u\n", p->header.phy_id);
+  printf("header.message_id: %u\n", p->header.message_id);
+  printf("header.m_segment_sequence: %u\n", p->header.m_segment_sequence);
+  printf("header.checksum: %u\n", p->header.checksum);
+  printf("header.transmit_timestamp: %u\n", p->header.transmit_timestamp);
+  printf("sfn_sf: %u\n", p->sfn_sf);
+  printf("rx_indication_body.tl.tag: 0x%x\n", p->rx_indication_body.tl.tag);
+  printf("rx_indication_body.tl.length: %u\n", p->rx_indication_body.tl.length);
+  printf("rx_indication_body.number_of_pdus: %u\n", p->rx_indication_body.number_of_pdus);
+
+  assert(p->rx_indication_body.number_of_pdus <= NFAPI_RX_IND_MAX_PDU);
+  nfapi_rx_indication_pdu_t *pdu = p->rx_indication_body.rx_pdu_list;
+  for (int i = 0; i < p->rx_indication_body.number_of_pdus; i++)
+  {
+    printf("pdu %d nfapi_rx_ue_information.tl.tag: 0x%x\n", i, pdu->rx_ue_information.tl.tag);
+    printf("pdu %d nfapi_rx_ue_information.tl.length: %u\n", i, pdu->rx_ue_information.tl.length);
+    printf("pdu %d nfapi_rx_ue_information.handle: %u\n", i, pdu->rx_ue_information.handle);
+    printf("pdu %d nfapi_rx_ue_information.rnti: %u\n", i, pdu->rx_ue_information.rnti);
+    printf("pdu %d nfapi_rx_indication_rel8.tl.tag: 0x%x\n", i, pdu->rx_indication_rel8.tl.tag);
+    printf("pdu %d nfapi_rx_indication_rel8.tl.length: %u\n", i, pdu->rx_indication_rel8.tl.length);
+    printf("pdu %d nfapi_rx_indication_rel8.length: %u\n", i, pdu->rx_indication_rel8.length);
+    printf("pdu %d nfapi_rx_indication_rel8.offset: %u\n", i, pdu->rx_indication_rel8.offset);
+    printf("pdu %d nfapi_rx_indication_rel8.ul_cqi: %u\n", i, pdu->rx_indication_rel8.ul_cqi);
+    printf("pdu %d nfapi_rx_indication_rel8.timing_advance: %u\n", i, pdu->rx_indication_rel8.timing_advance);
+    printf("pdu %d nfapi_rx_indication_rel9.tl.tag: 0x%x\n", i, pdu->rx_indication_rel9.tl.tag);
+    printf("pdu %d nfapi_rx_indication_rel9.tl.length: %u\n", i, pdu->rx_indication_rel9.tl.length);
+    printf("pdu %d nfapi_rx_indication_rel9.timing_advance_r9: %u\n", i, pdu->rx_indication_rel9.timing_advance_r9);
+  }
+
+  fflush(stdout);
 }
-void handle_nfapi_mch_pdu(PHY_VARS_eNB *eNB,
-                          L1_rxtx_proc_t *proc,
-                          nfapi_dl_config_request_pdu_t *dl_config_pdu,
-                          uint8_t *sdu) {
+
+  void send_standalone_msg(UL_IND_t *UL, nfapi_message_id_e msg_type)
+  {
+    int encoded_size = -1;
+    char buffer[NFAPI_MAX_PACKED_MESSAGE_SIZE];
+
+    switch (msg_type)
+    {
+    case NFAPI_RACH_INDICATION:
+      encoded_size = nfapi_p7_message_pack(&UL->rach_ind, buffer, sizeof(buffer), NULL);
+      LOG_A(MAC, "RACH_IND sent to Proxy, Size: %d Frame %d Subframe %d\n", encoded_size,
+            NFAPI_SFNSF2SFN(UL->rach_ind.sfn_sf), NFAPI_SFNSF2SF(UL->rach_ind.sfn_sf));
+      break;
+    case NFAPI_CRC_INDICATION:
+      encoded_size = nfapi_p7_message_pack(&UL->crc_ind, buffer, sizeof(buffer), NULL);
+      LOG_I(MAC, "CRC_IND sent to Proxy, Size: %d Frame %d Subframe %d num_crcs: %u\n", encoded_size,
+            NFAPI_SFNSF2SFN(UL->crc_ind.sfn_sf), NFAPI_SFNSF2SF(UL->crc_ind.sfn_sf),
+            UL->crc_ind.crc_indication_body.number_of_crcs);
+      break;
+    case NFAPI_RX_ULSCH_INDICATION:
+      encoded_size = nfapi_p7_message_pack(&UL->rx_ind, buffer, sizeof(buffer), NULL);
+      LOG_I(MAC, "RX_IND sent to Proxy, Size: %d Frame %d Subframe %d rx_ind.tl.length: %u num_pdus: %u\n",
+            encoded_size, NFAPI_SFNSF2SFN(UL->rx_ind.sfn_sf), NFAPI_SFNSF2SF(UL->rx_ind.sfn_sf),
+            UL->rx_ind.rx_indication_body.tl.length, UL->rx_ind.rx_indication_body.number_of_pdus);
+      break;
+    case NFAPI_RX_CQI_INDICATION:
+      encoded_size = nfapi_p7_message_pack(&UL->cqi_ind, buffer, sizeof(buffer), NULL);
+      LOG_I(MAC, "CQI_IND sent to Proxy, Size: %d num_cqis: %u\n", encoded_size,
+            UL->cqi_ind.cqi_indication_body.number_of_cqis);
+      break;
+    case NFAPI_HARQ_INDICATION:
+      encoded_size = nfapi_p7_message_pack(&UL->harq_ind, buffer, sizeof(buffer), NULL);
+      LOG_I(MAC, "HARQ_IND sent to Proxy, Size: %d Frame %d Subframe %d\n", encoded_size,
+            NFAPI_SFNSF2SFN(UL->harq_ind.sfn_sf), NFAPI_SFNSF2SF(UL->harq_ind.sfn_sf));
+      break;
+    case NFAPI_RX_SR_INDICATION:
+      encoded_size = nfapi_p7_message_pack(&UL->sr_ind, buffer, sizeof(buffer), NULL);
+      LOG_I(MAC, "SR_IND sent to Proxy, Size: %d\n", encoded_size);
+      break;
+    default:
+      LOG_I(MAC, "%s Unknown Message msg_type :: %u\n", __func__, msg_type);
+      return;
+    }
+    if (encoded_size < 0)
+    {
+      LOG_E(MAC, "standalone pack failed\n");
+      return;
+    }
+    if (send(ue_tx_sock_descriptor, buffer, encoded_size, 0) < 0)
+    {
+      LOG_E(MAC, "Send Proxy UE failed\n");
+      return;
+    }
+  }
+
+  void send_standalone_dummy()
+  {
+    static const uint16_t dummy[] = {0, 0};
+    if (send(ue_tx_sock_descriptor, dummy, sizeof(dummy), 0) < 0)
+    {
+      LOG_E(MAC, "send dummy to OAI UE failed: %s\n", strerror(errno));
+      return;
+    }
+  }
+
+const char *dl_pdu_type_to_string(uint8_t pdu_type)
+{
+  switch (pdu_type)
+  {
+    case NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE:
+      return "DCI_DL_PDU_TYPE";
+    case NFAPI_DL_CONFIG_BCH_PDU_TYPE:
+      return "BCH_PDU_TYPE";
+    case NFAPI_DL_CONFIG_MCH_PDU_TYPE:
+      return "MCH_PDU_TYPE";
+    case NFAPI_DL_CONFIG_DLSCH_PDU_TYPE:
+      return "DLSCH_PDU_TYPE";
+    case NFAPI_DL_CONFIG_PCH_PDU_TYPE:
+      return "PCH_PDU_TYPE";
+    case NFAPI_DL_CONFIG_PRS_PDU_TYPE:
+      return "PRS_PDU_TYPE";
+    case NFAPI_DL_CONFIG_CSI_RS_PDU_TYPE:
+      return "CSI_RS_PDU_TYPE";
+    case NFAPI_DL_CONFIG_EPDCCH_DL_PDU_TYPE:
+      return "EPDCCH_DL_PDU_TYPE";
+    case NFAPI_DL_CONFIG_MPDCCH_PDU_TYPE:
+      return "MPDCCH_PDU_TYPE";
+    case NFAPI_DL_CONFIG_NBCH_PDU_TYPE:
+      return "NBCH_PDU_TYPE";
+    case NFAPI_DL_CONFIG_NPDCCH_PDU_TYPE:
+      return "NPDCCH_PDU_TYPE";
+    case NFAPI_DL_CONFIG_NDLSCH_PDU_TYPE:
+      return "NDLSCH_PDU_TYPE";
+    default:
+      LOG_E(MAC, "%s No corresponding PDU for type: %u\n", __func__, pdu_type);
+      return "UNKNOWN";
+  }
 }
 
-void phy_config_request(PHY_Config_t *phy_config) {
+const char *ul_pdu_type_to_string(uint8_t pdu_type)
+{
+  switch (pdu_type)
+  {
+    case NFAPI_UL_CONFIG_ULSCH_PDU_TYPE:
+      return "UL_CONFIG_ULSCH_PDU_TYPE";
+    case NFAPI_UL_CONFIG_ULSCH_CQI_RI_PDU_TYPE:
+      return "UL_CONFIG_ULSCH_CQI_RI_PDU_TYPE";
+    case NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE:
+      return "UL_CONFIG_ULSCH_HARQ_PDU_TYPE";
+    case NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE:
+      return "UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE";
+    case NFAPI_UL_CONFIG_UCI_CQI_PDU_TYPE:
+      return "UL_CONFIG_UCI_CQI_PDU_TYPE";
+    case NFAPI_UL_CONFIG_UCI_SR_PDU_TYPE:
+      return "UCI_SR_PDU_TYPE";
+    case NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE:
+      return "UCI_HARQ_PDU_TYPE";
+    case NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE:
+      return "UCI_SR_HARQ_PDU_TYPE";
+    case NFAPI_UL_CONFIG_UCI_CQI_HARQ_PDU_TYPE:
+      return "UCI_CQI_HARQ_PDU_TYPE";
+    case NFAPI_UL_CONFIG_UCI_CQI_SR_PDU_TYPE:
+      return "UCI_CQI_SR_PDU_TYPE";
+    case NFAPI_UL_CONFIG_UCI_CQI_SR_HARQ_PDU_TYPE:
+      return "UCI_CQI_SR_HARQ_PDU_TYPE";
+    case NFAPI_UL_CONFIG_SRS_PDU_TYPE:
+      return "SRS_PDU_TYPE";
+    case NFAPI_UL_CONFIG_HARQ_BUFFER_PDU_TYPE:
+      return "HARQ_BUFFER_PDU_TYPE";
+    case NFAPI_UL_CONFIG_ULSCH_UCI_CSI_PDU_TYPE:
+      return "PDU_TYPE";
+    case NFAPI_UL_CONFIG_ULSCH_UCI_HARQ_PDU_TYPE:
+      return "ULSCH_UCI_HARQ_PDU_TYPE";
+    case NFAPI_UL_CONFIG_ULSCH_CSI_UCI_HARQ_PDU_TYPE:
+      return "ULSCH_CSI_UCI_HARQ_PDU_TYPE";
+    case NFAPI_UL_CONFIG_NULSCH_PDU_TYPE:
+      return "NULSCH_PDU_TYPE";
+    case NFAPI_UL_CONFIG_NRACH_PDU_TYPE:
+      return "NRACH_PDU_TYPE";
+    default:
+      LOG_E(MAC, "%s No corresponding PDU for type: %u\n", __func__, pdu_type);
+      return "UNKNOWN";
+  }
 }
 
-void phy_config_update_sib2_request(PHY_Config_t *phy_config) {
+char *nfapi_dl_config_req_to_string(nfapi_dl_config_request_t *req)
+{
+    const size_t max_result = 1024;
+    uint16_t num_pdus = req->dl_config_request_body.number_pdu;
+    int subframe = req->sfn_sf & 15;
+    int frame = req->sfn_sf >> 4;
+    char *result = malloc(max_result);
+    snprintf(result, max_result, "num_pdus=%u Frame=%d Subframe=%d",
+        num_pdus, frame, subframe);
+    for (size_t i = 0; i < num_pdus; ++i)
+    {
+        int len = strlen(result);
+        if (len >= max_result - 1)
+        {
+            break;
+        }
+        snprintf(result + len, max_result - len, " pdu_type=%s",
+            dl_pdu_type_to_string(req->dl_config_request_body.dl_config_pdu_list[i].pdu_type));
+    }
+    return result;
 }
 
-void phy_config_update_sib13_request(PHY_Config_t *phy_config) {
+char *nfapi_ul_config_req_to_string(nfapi_ul_config_request_t *req)
+{
+    const size_t max_result = 1024;
+    uint16_t num_pdus = req->ul_config_request_body.number_of_pdus;
+    int subframe = req->sfn_sf & 15;
+    int frame = req->sfn_sf >> 4;
+    char *result = malloc(max_result);
+    snprintf(result, max_result, "num_pdus=%u Frame=%d Subframe=%d",
+        num_pdus, frame, subframe);
+    for (size_t i = 0; i < num_pdus; ++i)
+    {
+        int len = strlen(result);
+        if (len >= max_result - 1)
+        {
+            break;
+        }
+        snprintf(result + len, max_result - len, " pdu_type=%s",
+            ul_pdu_type_to_string(req->ul_config_request_body.ul_config_pdu_list[i].pdu_type));
+    }
+    return result;
 }
 
-uint32_t from_earfcn(int eutra_bandP, uint32_t dl_earfcn) {
-  return (0);
+/* Dummy functions*/
+
+  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,
+      L1_rxtx_proc_t *proc,
+      nfapi_hi_dci0_request_pdu_t *hi_dci0_config_pdu)
+  {
+  }
+
+  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_bch_pdu(PHY_VARS_eNB * eNB,
+                            L1_rxtx_proc_t * proc,
+                            nfapi_dl_config_request_pdu_t * dl_config_pdu,
+                            uint8_t * sdu)
+  {
+  }
+
+  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,
+                           L1_rxtx_proc_t * proc,
+                           nfapi_ul_config_request_pdu_t * ul_config_pdu,
+                           uint16_t frame,
+                           uint8_t subframe,
+                           uint8_t srs_present)
+  {
+  }
+  void handle_nfapi_mch_pdu(PHY_VARS_eNB * eNB,
+                            L1_rxtx_proc_t * proc,
+                            nfapi_dl_config_request_pdu_t * dl_config_pdu,
+                            uint8_t * sdu)
+  {
+  }
+
+  void phy_config_request(PHY_Config_t * phy_config)
+  {
+  }
+
+  void phy_config_update_sib2_request(PHY_Config_t * phy_config)
+  {
+  }
+
+  void phy_config_update_sib13_request(PHY_Config_t * phy_config)
+  {
+  }
+
+  uint32_t from_earfcn(int eutra_bandP, uint32_t dl_earfcn)
+  {
+    return (0);
+  }
+
+  int32_t get_uldl_offset(int eutra_bandP)
+  {
+    return (0);
+  }
+
+  int l1_north_init_eNB(void)
+  {
+    return 0;
+  }
+
+  void init_eNB_afterRU(void)
+  {
+  }
+
+static int get_mcs_from_sinr(float sinr)
+{
+  if (sinr < (bler_data[0].bler_table[0][0]))
+  {
+    LOG_I(MAC, "The SINR was found is smaller than first MCS table\n");
+    return 0;
+  }
+
+  if (sinr > (bler_data[NUM_MCS-1].bler_table[bler_data[NUM_MCS-1].length - 1][0]))
+  {
+    LOG_I(MAC, "The SINR was found is larger than last MCS table\n");
+    return NUM_MCS-1;
+  }
+
+  for (int n = NUM_MCS-1; n >= 0; n--)
+  {
+    CHECK_INDEX(bler_data, n);
+    float largest_sinr = (bler_data[n].bler_table[bler_data[n].length - 1][0]);
+    float smallest_sinr = (bler_data[n].bler_table[0][0]);
+    if (sinr < largest_sinr && sinr > smallest_sinr)
+    {
+      LOG_I(MAC, "The SINR was found in MCS %d table\n", n);
+      return n;
+    }
+  }
+  LOG_E(MAC, "Unable to get an MCS value.\n");
+  abort();
 }
 
-int32_t get_uldl_offset(int eutra_bandP) {
-  return (0);
+static int get_cqi_from_mcs(void)
+{
+  static const int mcs_to_cqi[] = {0, 1, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15};
+  assert(NUM_ELEMENTS(mcs_to_cqi) == NUM_MCS);
+  int sf = 0;
+  while(sf < NUM_NFAPI_SUBFRAME)
+  {
+    if (sf_rnti_mcs[sf].latest)
+    {
+      int pdu_size = sf_rnti_mcs[sf].pdu_size;
+      if (pdu_size <= 0)
+      {
+        LOG_E(MAC, "%s: sf_rnti_mcs[%d].pdu_size = 0\n", __FUNCTION__, sf);
+        abort();
+      }
+
+      CHECK_INDEX(sf_rnti_mcs[sf].mcs, pdu_size);
+      int mcs = get_mcs_from_sinr(sf_rnti_mcs[sf].sinr);
+      CHECK_INDEX(mcs_to_cqi, mcs);
+      int cqi = mcs_to_cqi[mcs];
+      LOG_I(MAC, "SINR: %f -> MCS: %d -> CQI: %d\n", sf_rnti_mcs[sf].sinr, mcs, cqi);
+      return cqi;
+    }
+    sf++;
+  }
+  LOG_E(MAC, "Unable to get CQI value because no MCS found\n");
+  abort();
 }
 
-int l1_north_init_eNB(void) {
-  return 0;
+static void read_channel_param(const nfapi_dl_config_request_pdu_t * pdu, int sf, int index)
+{
+  if (pdu == NULL)
+  {
+    LOG_E(MAC,"PDU NULL\n");
+    abort();
+  }
+
+  /* This function is executed for every dci pdu type in a dl_config_req. We save
+     the assocaited MCS and RNTI value for each. The 'index' passed in is a count of
+     how many times we have called this function for a particular dl_config_req. It
+     allows us to save MCS/RNTI data in correct indicies when multiple dci's are received.*/
+  for (int i = 0; i < NUM_NFAPI_SUBFRAME; i++)
+  {
+    if (i == sf)
+    {
+      CHECK_INDEX(sf_rnti_mcs[sf].rnti, index);
+      CHECK_INDEX(sf_rnti_mcs[sf].mcs, index);
+      CHECK_INDEX(sf_rnti_mcs[sf].drop_flag, index);
+      sf_rnti_mcs[sf].rnti[index] = pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti;
+      sf_rnti_mcs[sf].mcs[index] = pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1;
+      sf_rnti_mcs[sf].drop_flag[index] = false;
+      sf_rnti_mcs[sf].pdu_size = index+1; //index starts at 0 so we incrament to get num of pdus
+      sf_rnti_mcs[sf].latest = true;
+      LOG_I(MAC, "Adding MCS %d and RNTI %x for sf_rnti_mcs[%d]\n", sf_rnti_mcs[sf].mcs[index], sf_rnti_mcs[sf].rnti[index], sf);
+    }
+    else
+    {
+      sf_rnti_mcs[i].latest = false;
+    }
+  }
+  return;
+}
+
+static bool did_drop_transport_block(int sf, uint16_t rnti)
+{
+  int pdu_size = sf_rnti_mcs[sf].pdu_size;
+  if(pdu_size <= 0)
+  {
+    LOG_E(MAC, "Problem, the PDU size is <= 0. We dropped this packet\n");
+    return true;
+  }
+  CHECK_INDEX(sf_rnti_mcs[sf].rnti, pdu_size);
+  CHECK_INDEX(sf_rnti_mcs[sf].drop_flag, pdu_size);
+  for (int n = 0; n < pdu_size; n++)
+  {
+    if (sf_rnti_mcs[sf].rnti[n] == rnti && sf_rnti_mcs[sf].drop_flag[n])
+    {
+      return true;
+    }
+  }
+  return false;
+}
+
+static float get_bler_val(uint8_t mcs, int sinr)
+{
+  // 4th col = dropped packets, 5th col = total packets
+  float bler_val = 0.0;
+  CHECK_INDEX(bler_data, mcs);
+  if (sinr < (int)(bler_data[mcs].bler_table[0][0] * 10))
+  {
+    LOG_I(MAC, "MCS %d table. SINR is smaller than lowest SINR, bler_val is set based on lowest SINR in table\n", mcs);
+    bler_val = bler_data[mcs].bler_table[0][4] / bler_data[mcs].bler_table[0][5];
+    return bler_val;
+  }
+  if (sinr > (int)(bler_data[mcs].bler_table[bler_data[mcs].length - 1][0] * 10))
+  {
+    LOG_I(MAC, "MCS %d table. SINR is greater than largest SINR. bler_val is set based on largest SINR in table\n", mcs);
+    bler_val = bler_data[mcs].bler_table[(bler_data[mcs].length - 1)][4] / bler_data[mcs].bler_table[(bler_data[mcs].length - 1)][5];
+    return bler_val;
+  }
+  // Loop through bler table to find sinr_index
+  for (int i = 0; i < bler_data[mcs].length; i++)
+  {
+    int temp_sinr = (int)(bler_data[mcs].bler_table[i][0] * 10);
+    if (temp_sinr == sinr)
+    {
+      bler_val = bler_data[mcs].bler_table[i][4] / bler_data[mcs].bler_table[i][5];
+      return bler_val;
+    }
+    // Linear interpolation when SINR is between indices
+    if (temp_sinr > sinr)
+    {
+      float bler_val1 = bler_data[mcs].bler_table[i - 1][4] / bler_data[mcs].bler_table[i - 1][5];
+      float bler_val2 = bler_data[mcs].bler_table[i][4] / bler_data[mcs].bler_table[i][5];
+      return ((bler_val1 + bler_val2) / 2);
+    }
+  }
+  LOG_E(MAC, "NO SINR INDEX FOUND!\n");
+  abort();
+
+}
+
+static inline bool is_channel_modeling(void)
+{
+  /* TODO: For now we enable channel modeling based on the node_number.
+     Replace with a command line option to enable/disable channel modeling.
+     The LTE UE will crash when channel modeling is conducted for NSA
+     mode. It does not crash for LTE mode. We have not implemented channel
+     modeling for NSA mode yet. For now, we ensure only do do chanel modeling
+     in LTE mode. */
+  return node_number == 0 && !get_softmodem_params()->nsa;
 }
 
-void init_eNB_afterRU(void) {
+static bool should_drop_transport_block(int sf, uint16_t rnti)
+{
+  if (!is_channel_modeling())
+  {
+    return false;
+  }
+
+  /* We want to avoid dropping setup messages because this would be pathological.
+     This assumes were in standalone_pnf mode where
+     UE_rrc_inst[0] is module_id = 0 and Info[0] is eNB_index = 0. */
+  UE_STATE_t state = UE_rrc_inst[0].Info[0].State;
+  if (state < RRC_CONNECTED)
+  {
+    LOG_I(MAC, "Not dropping because state: %d", state);
+    return false;
+  }
+
+  /* Get block error rate (bler_val) from table based on every saved
+     MCS and SINR to be used as the cutoff rate for dropping packets.
+     Generate random uniform vairable to compare against bler_val. */
+  int pdu_size = sf_rnti_mcs[sf].pdu_size;
+  assert(sf < 10 && sf >= 0);
+  assert(pdu_size > 0);
+  CHECK_INDEX(sf_rnti_mcs[sf].rnti, pdu_size);
+  CHECK_INDEX(sf_rnti_mcs[sf].mcs, pdu_size);
+  CHECK_INDEX(sf_rnti_mcs[sf].drop_flag, pdu_size);
+  int n = 0;
+  uint8_t mcs = 99;
+  for (n = 0; n < pdu_size; n++)
+  {
+    if (sf_rnti_mcs[sf].rnti[n] == rnti)
+    {
+      mcs = sf_rnti_mcs[sf].mcs[n];
+    }
+    if (mcs != 99)
+    {
+      /* Use MCS to get the bler value. Since there can be multiple MCS
+         values for a particular subframe, we verify that all PDUs are not
+         flagged for drop before returning. If even one is flagged for drop
+         we return immediately because we drop the entire packet. */
+      float bler_val = get_bler_val(mcs, ((int)(sf_rnti_mcs[sf].sinr * 10)));
+      double drop_cutoff = ((double) rand() / (RAND_MAX));
+      assert(drop_cutoff <= 1);
+      LOG_I(MAC, "SINR = %f, Bler_val = %f, MCS = %"PRIu8"\n", sf_rnti_mcs[sf].sinr, bler_val, sf_rnti_mcs[sf].mcs[n]);
+      if (drop_cutoff <= bler_val)
+      {
+        sf_rnti_mcs[sf].drop_flag[n] = true;
+        LOG_D(MAC, "We are dropping this packet. Bler_val = %f, MCS = %"PRIu8", sf = %d\n", bler_val, sf_rnti_mcs[sf].mcs[n], sf);
+        return sf_rnti_mcs[sf].drop_flag[n];
+      }
+    }
+
+  }
+
+  if (mcs == 99)
+  {
+    LOG_E(MAC, "NO MCS Found for rnti %x. sf_rnti_mcs[%d].mcs[%d] \n", rnti, sf, n);
+    abort();
+  }
+  return false;
 }
diff --git a/openair2/PHY_INTERFACE/phy_stub_UE.h b/openair2/PHY_INTERFACE/phy_stub_UE.h
index bdf8872371e5e7f6b752a407f33f24d7ffc37497..ebaae6e667b8aa7f8a7a88415871ba73df23f34f 100644
--- a/openair2/PHY_INTERFACE/phy_stub_UE.h
+++ b/openair2/PHY_INTERFACE/phy_stub_UE.h
@@ -13,16 +13,51 @@
 #include "openair2/PHY_INTERFACE/IF_Module.h"
 #include "nfapi_interface.h"
 #include "nfapi_pnf_interface.h"
+#include <pthread.h>
+#include <semaphore.h>
+#include "nfapi/oai_integration/vendor_ext.h"
 //#include "openair1/PHY/LTE_TRANSPORT/defs.h"
 //#include "openair1/PHY/defs.h"
 //#include "openair1/PHY/LTE_TRANSPORT/defs.h"
+#include "queue_t.h"
 
+#define NUM_MCS 28
+#define NUM_SINR 100
+#define NUM_BLER_COL 13
+
+// this mutex is used to set multiple UE's UL value in L2 FAPI simulator.
+extern 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.
 //below 3 difinitions move to phy_stub_UE.c to add initialization when difinition.
+
+//below 2 difinitions move to lte-ue.c to add initialization when difinition.
+//int next_ra_frame;
+//module_id_t next_Mod_id;
+
+typedef struct
+{
+    uint8_t sf;
+    uint16_t rnti[256];
+    uint8_t mcs[256];
+    float sinr;
+    uint16_t pdu_size;
+    bool drop_flag[256];
+    bool latest;
+
+} sf_rnti_mcs_s;
+
+typedef struct
+{
+    uint16_t length;
+    float bler_table[NUM_SINR][NUM_BLER_COL];
+} bler_struct;
+
+extern bler_struct bler_data[NUM_MCS];
+
+
 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;
@@ -52,16 +87,19 @@ void send_nfapi_UL_indications(UL_IND_t UL_INFO);
 
 //void fill_rx_indication_UE_MAC(module_id_t Mod_id,int frame,int subframe);
 
-void fill_rx_indication_UE_MAC(module_id_t Mod_id,int frame,int subframe, UL_IND_t *UL_INFO, uint8_t *ulsch_buffer, uint16_t buflen, uint16_t rnti, int index);
+void fill_rx_indication_UE_MAC(module_id_t Mod_id,int frame,int subframe, UL_IND_t *UL_INFO, uint8_t *ulsch_buffer, uint16_t buflen, uint16_t rnti, int index,
+                            nfapi_ul_config_request_t *ul_config_req);
 
 
 // This function should be indicating directly to the eNB when there is a planned scheduling request at the MAC layer
 // of the UE. It should get called from ue_get_SR()
-void fill_sr_indication_UE_MAC(int Mod_id,int frame,int subframe, UL_IND_t *UL_INFO, uint16_t rnti);
+void fill_sr_indication_UE_MAC(int Mod_id,int frame,int subframe, UL_IND_t *UL_INFO, uint16_t rnti,
+                            nfapi_ul_config_request_t *ul_config_req);
 
 // In our case the this function will be always indicating ACK to the MAC of the eNB (i.e. always assuming)
 // successful decoding.
-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);
+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,
+                                nfapi_ul_config_request_t *ul_config_req);
 
 
 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);
@@ -70,9 +108,11 @@ void fill_rach_indication_UE_MAC(int Mod_id,int frame,int subframe, UL_IND_t *UL
 void fill_ulsch_cqi_indication_UE_MAC(int Mod_id, uint16_t frame,uint8_t subframe, UL_IND_t *UL_INFO, uint16_t rnti);
 
 
-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);
+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,
+                                    nfapi_ul_config_request_t *ul_config_req);
 
-void fill_uci_harq_indication_UE_MAC(int Mod_id, int frame, int subframe, UL_IND_t *UL_INFO,nfapi_ul_config_harq_information *harq_information, uint16_t rnti
+void fill_uci_harq_indication_UE_MAC(int Mod_id, int frame, int subframe, UL_IND_t *UL_INFO,nfapi_ul_config_harq_information *harq_information, uint16_t rnti,
+                                    nfapi_ul_config_request_t *ul_config_req
 			      /*uint8_t tdd_mapping_mode,
 			      uint16_t tdd_multiplexing_mask*/);
 
@@ -80,13 +120,36 @@ int ul_config_req_UE_MAC(nfapi_ul_config_request_t* req, int frame, int subframe
 
 void handle_nfapi_ul_pdu_UE_MAC(module_id_t Mod_id,
                          nfapi_ul_config_request_pdu_t *ul_config_pdu,
-                         uint16_t frame,uint8_t subframe,uint8_t srs_present, int index);
+                         uint16_t frame,uint8_t subframe,uint8_t srs_present, int index,
+                         nfapi_ul_config_request_t *ul_config_req);
+
+typedef struct phy_channel_params_t
+{
+    uint16_t sfn_sf;
+    float sinr;
+    // Incomplete, need all channel parameters
+} phy_channel_params_t;
+
+typedef struct nfapi_tx_req_pdu_list_t
+{
+    int num_pdus;                  /* number .pdus[] objects */
+    nfapi_tx_request_pdu_t pdus[]; /* see "struct hack" */
+} nfapi_tx_req_pdu_list_t;
+
+typedef struct nfapi_dl_config_req_tx_req_t
+{
+    nfapi_dl_config_request_t *dl_config_req;
+    nfapi_tx_req_pdu_list_t *tx_req_pdu_list;
+} nfapi_dl_config_req_tx_req_t;
+
+void nfapi_free_tx_req_pdu_list(nfapi_tx_req_pdu_list_t *);
 
 void dl_config_req_UE_MAC_dci(int sfn,
                               int sf,
                               nfapi_dl_config_request_pdu_t *dci,
                               nfapi_dl_config_request_pdu_t *dlsch,
-                              int num_ue);
+                              int num_ue,
+                              nfapi_tx_req_pdu_list_t *);
 void dl_config_req_UE_MAC_bch(int sfn,
                               int sf,
                               nfapi_dl_config_request_pdu_t *bch,
@@ -94,7 +157,8 @@ void dl_config_req_UE_MAC_bch(int sfn,
 void dl_config_req_UE_MAC_mch(int sfn,
                               int sf,
                               nfapi_dl_config_request_pdu_t *bch,
-                              int num_ue);
+                              int num_ue,
+                              nfapi_tx_req_pdu_list_t *);
 
 int tx_req_UE_MAC(nfapi_tx_request_t* req);
 
@@ -107,19 +171,44 @@ void hi_dci0_req_UE_MAC(int sfn,
 // The following set of memcpy functions should be getting called as callback functions from
 // pnf_p7_subframe_ind.
 
-int memcpy_dl_config_req (L1_rxtx_proc_t *proc, nfapi_pnf_p7_config_t* pnf_p7, nfapi_dl_config_request_t* req);
+int memcpy_ul_config_req (L1_rxtx_proc_t *proc, nfapi_pnf_p7_config_t* pnf_p7, nfapi_ul_config_request_t* req);
 
+int memcpy_hi_dci0_req (L1_rxtx_proc_t *proc, nfapi_pnf_p7_config_t* pnf_p7, nfapi_hi_dci0_request_t* req);
 
-int memcpy_ul_config_req (L1_rxtx_proc_t *proc, nfapi_pnf_p7_config_t* pnf_p7, nfapi_ul_config_request_t* req);
+void UE_config_stub_pnf(void);
 
+void *memcpy_tx_req_standalone(nfapi_tx_request_t *tx_req);
 
-int memcpy_tx_req (nfapi_pnf_p7_config_t* pnf_p7, nfapi_tx_request_t* req);
+void *memcpy_dl_config_req_standalone(nfapi_dl_config_request_t *dl_config_req);
 
+// open an SCTP socket with a standalone PNF module
+void ue_init_standalone_socket(int tx_port, int rx_port);
 
-int memcpy_hi_dci0_req (L1_rxtx_proc_t *proc, nfapi_pnf_p7_config_t* pnf_p7, nfapi_hi_dci0_request_t* req);
+// read from standalone pnf socket call corresponding memcpy functions
+void *ue_standalone_pnf_task(void *context);
+void send_standalone_msg(UL_IND_t *UL, nfapi_message_id_e msg_type);
+void send_standalone_dummy(void);
+void enqueue_dl_config_req_tx_req(nfapi_dl_config_request_t *dl_config_req, nfapi_tx_request_t *tx_req);
 
-void UE_config_stub_pnf(void);
+// Convert downlink nfapi messages to a string.
+// Returned memory is malloc'ed, caller is responsible for freeing.
+char *nfapi_dl_config_req_to_string(nfapi_dl_config_request_t *req);
+char *nfapi_ul_config_req_to_string(nfapi_ul_config_request_t *req);
+
+// Convert downlink nfapi messages to a string.
+// Returned memory is statically allocated.
+const char *dl_pdu_type_to_string(uint8_t pdu_type);
+const char *ul_pdu_type_to_string(uint8_t pdu_type);
+
+extern queue_t dl_config_req_tx_req_queue;
+extern queue_t ul_config_req_queue;
+extern queue_t hi_dci0_req_queue;
+
+extern nfapi_ul_config_request_t* ul_config_req;
+extern nfapi_hi_dci0_request_t* hi_dci0_req;
 
+extern int current_sfn_sf;
 
+extern sem_t sfn_semaphore;
 
 #endif /* PHY_STUB_UE_H_ */
diff --git a/openair2/PHY_INTERFACE/queue_t.c b/openair2/PHY_INTERFACE/queue_t.c
new file mode 100644
index 0000000000000000000000000000000000000000..fd4b870676cf89391c682f0aab733e20aaf9e882
--- /dev/null
+++ b/openair2/PHY_INTERFACE/queue_t.c
@@ -0,0 +1,196 @@
+#include "queue_t.h"
+#include <string.h>
+#include <assert.h>
+
+#ifdef UNITTEST
+#include <stdio.h>
+#define LOG_ERROR(MSG) printf(MSG "\n")
+#else
+#include "common/utils/LOG/log.h"
+#define LOG_ERROR(MSG) LOG_E(PHY, MSG "\n")
+#endif
+
+void init_queue(queue_t *q)
+{
+    memset(q, 0, sizeof(*q));
+    pthread_mutex_init(&q->mutex, NULL);
+}
+
+void reset_queue(queue_t *q)
+{
+  void *p;
+  while ((p = get_queue(q)) != NULL)
+  {
+    free(p);
+  }
+}
+
+void *put_queue_replace(queue_t *q, void *item)
+{
+    assert(item != NULL);
+    if (pthread_mutex_lock(&q->mutex) != 0)
+    {
+        LOG_ERROR("put_queue: mutex_lock failed");
+        return false;
+    }
+
+    void *evicted = NULL;
+    if (q->num_items >= MAX_QUEUE_SIZE)
+    {
+        evicted = q->items[q->read_index];
+        assert(evicted != NULL);
+        q->items[q->read_index] = NULL;
+        q->read_index = (q->read_index + 1) % MAX_QUEUE_SIZE;
+        q->num_items--;
+    }
+    assert(q->items[q->write_index] == NULL);
+    q->items[q->write_index] = item;
+    q->write_index = (q->write_index + 1) % MAX_QUEUE_SIZE;
+    q->num_items++;
+
+    pthread_mutex_unlock(&q->mutex);
+    return evicted;
+}
+
+
+bool put_queue(queue_t *q, void *item)
+{
+    assert(item != NULL);
+    if (pthread_mutex_lock(&q->mutex) != 0)
+    {
+        LOG_ERROR("put_queue: mutex_lock failed");
+        return false;
+    }
+
+    bool queued;
+    if (q->num_items >= MAX_QUEUE_SIZE)
+    {
+        LOG_ERROR("put_queue: queue is full");
+        queued = false;
+    }
+    else
+    {
+        assert(q->items[q->write_index] == NULL);
+        q->items[q->write_index] = item;
+        q->write_index = (q->write_index + 1) % MAX_QUEUE_SIZE;
+        q->num_items++;
+        queued = true;
+    }
+
+    pthread_mutex_unlock(&q->mutex);
+    return queued;
+}
+
+void *get_queue(queue_t *q)
+{
+    void *item = NULL;
+    if (pthread_mutex_lock(&q->mutex) != 0)
+    {
+        LOG_ERROR("get_queue: mutex_lock failed");
+        return NULL;
+    }
+
+    if (q->num_items > 0)
+    {
+        item = q->items[q->read_index];
+        assert(item != NULL);
+        q->items[q->read_index] = NULL;
+        q->read_index = (q->read_index + 1) % MAX_QUEUE_SIZE;
+        q->num_items--;
+    }
+
+    pthread_mutex_unlock(&q->mutex);
+    return item;
+}
+
+bool requeue(queue_t *q, void *item)
+{
+    assert(item != NULL);
+    if (pthread_mutex_lock(&q->mutex) != 0)
+    {
+        LOG_ERROR("requeue: mutex_lock failed");
+        return false;
+    }
+
+    bool queued;
+    if (q->num_items >= MAX_QUEUE_SIZE)
+    {
+        LOG_ERROR("requeue: queue is full");
+        queued = false;
+    }
+    else
+    {
+        q->read_index = (q->read_index + MAX_QUEUE_SIZE - 1) % MAX_QUEUE_SIZE;
+        assert(q->items[q->read_index] == NULL);
+        q->items[q->read_index] = item;
+        q->num_items++;
+        queued = true;
+    }
+
+    pthread_mutex_unlock(&q->mutex);
+    return queued;
+}
+
+void *unqueue(queue_t *q)
+{
+    void *item = NULL;
+    if (pthread_mutex_lock(&q->mutex) != 0) {
+        LOG_ERROR("unqueue: mutex_lock failed");
+        return NULL;
+    }
+
+    if (q->num_items > 0) {
+        q->write_index = (q->write_index + MAX_QUEUE_SIZE - 1) % MAX_QUEUE_SIZE;
+        item = q->items[q->write_index];
+        q->items[q->write_index] = NULL;
+        q->num_items--;
+    }
+
+    pthread_mutex_unlock(&q->mutex);
+    return item;
+}
+
+void *unqueue_matching(queue_t *q, size_t max_depth, queue_matcher_t *matcher, void *wanted)
+{
+    if (pthread_mutex_lock(&q->mutex) != 0)
+    {
+        LOG_ERROR("unqueue_matching: mutex_lock failed");
+        return NULL;
+    }
+
+    void *item = NULL;
+    size_t endi = q->write_index;
+    for (size_t i = 0; i < q->num_items; i++)
+    {
+        if (max_depth == 0)
+        {
+            break;
+        }
+        --max_depth;
+
+        endi = (endi + MAX_QUEUE_SIZE - 1) % MAX_QUEUE_SIZE;
+        void *candidate = q->items[endi];
+        if (matcher(wanted, candidate))
+        {
+            item = candidate;
+            // delete item from the queue and move other items down
+            for (;;)
+            {
+                size_t j = (endi + 1) % MAX_QUEUE_SIZE;
+                if (j == q->write_index)
+                {
+                    q->items[endi] = NULL;
+                    q->write_index = endi;
+                    q->num_items--;
+                    break;
+                }
+                q->items[endi] = q->items[j];
+                endi = j;
+            }
+            break;
+        }
+    }
+
+    pthread_mutex_unlock(&q->mutex);
+    return item;
+}
diff --git a/openair2/PHY_INTERFACE/queue_t.h b/openair2/PHY_INTERFACE/queue_t.h
new file mode 100644
index 0000000000000000000000000000000000000000..4678e310301ac4934ca1f7e2c241e18f481a01c4
--- /dev/null
+++ b/openair2/PHY_INTERFACE/queue_t.h
@@ -0,0 +1,64 @@
+/*
+  queue_t is a basic thread-safe non-blocking fixed-size queue.
+
+  put_queue returns false if the queue is full.
+  get_queue returns NULL if the queue is empty.
+
+  Example usage:
+
+    // Initialization:
+    queue_t fooq;
+    init_queue(&fooq);
+
+    // Producer:
+    foo_t *item = new_foo();
+    if (!put_queue(&fooq, item))
+      delete_foo(item);
+
+    // Consumer:
+    foo_t *item = get_queue(&fooq);
+    if (item)
+    {
+      do_something_with_foo(item);
+      delete_foo(item);
+    }
+*/
+
+#pragma once
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <pthread.h>
+
+#define MAX_QUEUE_SIZE 512
+
+typedef struct queue_t
+{
+    void *items[MAX_QUEUE_SIZE];
+    size_t read_index, write_index;
+    size_t num_items;
+    pthread_mutex_t mutex;
+} queue_t;
+
+void init_queue(queue_t *q);
+void reset_queue(queue_t *q);
+void *put_queue_replace(queue_t *q, void *item);
+bool put_queue(queue_t *q, void *item);
+void *get_queue(queue_t *q);
+
+/* Put the given item back onto this queue at the head.
+   (The next call to put_queue would return this item.)
+   Return true if successful, false if the queue was full */
+bool requeue(queue_t *q, void *item);
+
+/* Remove the last item queued.
+   Return the item or NULL if the queue was empty */
+void *unqueue(queue_t *q);
+
+typedef bool queue_matcher_t(void *wanted, void *candidate);
+
+/* Unqueue the most recently queued item for which `matcher(wanted, candidate)`
+   returns true where `candidate` is an item currently on the queue.
+   Look only at the last `max_depth` items on the queue, at most.
+   Returns the candidate item, or NULL if none matches */
+void *unqueue_matching(queue_t *q, size_t max_depth, queue_matcher_t *matcher, void *wanted);
diff --git a/openair2/PHY_INTERFACE/queue_test.c b/openair2/PHY_INTERFACE/queue_test.c
new file mode 100644
index 0000000000000000000000000000000000000000..542b6a676b2a7f1a1f630f649e825aa37273f0ee
--- /dev/null
+++ b/openair2/PHY_INTERFACE/queue_test.c
@@ -0,0 +1,226 @@
+#include "queue_t.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+#define FAIL do {                                                       \
+    printf("\n*** FAILED at %s line %d\n", __FILE__, __LINE__);         \
+    pass = false;                                                       \
+} while (0)
+
+#define EQUAL(A, B) do {                                                \
+    if ((A) != (B))                                                     \
+        FAIL;                                                           \
+} while (0)
+
+typedef uint32_t Thing_t;       /* actual type doesn't matter */
+
+static Thing_t things[MAX_QUEUE_SIZE];
+static Thing_t thing1, thing2;
+
+static bool matcher(void *wanted, void *candidate)
+{
+    return wanted == candidate;
+}
+
+int main(void)
+{
+    bool pass = true;
+    queue_t queue;
+    init_queue(&queue);
+
+    for (int i = 0; i < MAX_QUEUE_SIZE; ++i)
+    {
+        if (!put_queue(&queue, &things[i]))
+        {
+            FAIL;
+        }
+    }
+
+    /* queue is full */
+    if (put_queue(&queue, &thing1))
+        FAIL;
+
+    Thing_t *p;
+    for (int i = 0; i < MAX_QUEUE_SIZE; ++i)
+    {
+        p = get_queue(&queue);
+        EQUAL(p, &things[i]);
+    }
+
+    /* queue is empty */
+    p = get_queue(&queue);
+    EQUAL(p, NULL);
+
+    for (int i = 0; i < MAX_QUEUE_SIZE; ++i)
+    {
+        if (!put_queue(&queue, &things[i]))
+        {
+            FAIL;
+        }
+    }
+
+    p = get_queue(&queue);
+    EQUAL(p, &things[0]);
+
+    p = get_queue(&queue);
+    EQUAL(p, &things[1]);
+
+    if (!requeue(&queue, &thing1))
+        FAIL;
+    if (!requeue(&queue, &thing2))
+        FAIL;
+    p = get_queue(&queue);
+    EQUAL(p, &thing2);
+    p = get_queue(&queue);
+    EQUAL(p, &thing1);
+
+    if (!requeue(&queue, &things[1]))
+        FAIL;
+    if (!requeue(&queue, &things[0]))
+        FAIL;
+
+    for (int i = 0; i < MAX_QUEUE_SIZE / 2; ++i)
+    {
+        p = get_queue(&queue);
+        EQUAL(p, &things[i]);
+    }
+
+    for (int i = MAX_QUEUE_SIZE / 2; i < MAX_QUEUE_SIZE; ++i)
+    {
+        if (!put_queue(&queue, &things[i]))
+            FAIL;
+    }
+
+    p = get_queue(&queue);
+    EQUAL(p, &things[MAX_QUEUE_SIZE / 2]);
+    p = get_queue(&queue);
+    EQUAL(p, &things[MAX_QUEUE_SIZE / 2 + 1]);
+
+    // ---- unqueue ----
+
+    init_queue(&queue);
+    for (int i = 0; i < MAX_QUEUE_SIZE; ++i)
+    {
+        if (!put_queue(&queue, &things[i]))
+        {
+            FAIL;
+        }
+    }
+    for (int i = MAX_QUEUE_SIZE; --i >= 0;)
+    {
+        p = unqueue(&queue);
+        EQUAL(p, &things[i]);
+        EQUAL(queue.num_items, i);
+    }
+    EQUAL(queue.num_items, 0);
+    if (!put_queue(&queue, &thing1))
+        FAIL;
+    if (!put_queue(&queue, &thing2))
+        FAIL;
+    EQUAL(queue.num_items, 2);
+    p = get_queue(&queue);
+    EQUAL(p, &thing1);
+    p = get_queue(&queue);
+    EQUAL(p, &thing2);
+
+    // ---- unqueue_matching ----
+
+    init_queue(&queue);
+
+    // empty queue
+    p = unqueue_matching(&queue, MAX_QUEUE_SIZE, matcher, &thing1);
+    EQUAL(p, NULL);
+    EQUAL(queue.num_items, 0);
+
+    // one item in queue
+    if (!put_queue(&queue, &thing1))
+        FAIL;
+    EQUAL(queue.num_items, 1);
+    p = unqueue_matching(&queue, MAX_QUEUE_SIZE, matcher, &thing2);
+    EQUAL(p, NULL);
+    EQUAL(queue.num_items, 1);
+
+    p = unqueue_matching(&queue, /*max_queue=*/ 0, matcher, &thing1);
+    EQUAL(p, NULL);
+    EQUAL(queue.num_items, 1);
+
+    p = unqueue_matching(&queue, /*max_queue=*/ 1, matcher, &thing1);
+    EQUAL(p, &thing1);
+    EQUAL(queue.num_items, 0);
+
+    // more max_queue values
+    for (int i = 0; i < MAX_QUEUE_SIZE; ++i)
+    {
+        if (!put_queue(&queue, &things[i]))
+        {
+            FAIL;
+        }
+    }
+    p = unqueue_matching(&queue, /*max_queue=*/ 0, matcher, &things[MAX_QUEUE_SIZE - 1]);
+    EQUAL(p, NULL);
+    p = unqueue_matching(&queue, /*max_queue=*/ 1, matcher, &things[MAX_QUEUE_SIZE - 1]);
+    EQUAL(p, &things[MAX_QUEUE_SIZE - 1]);
+    EQUAL(queue.num_items, MAX_QUEUE_SIZE - 1);
+    p = unqueue_matching(&queue, /*max_queue=*/ MAX_QUEUE_SIZE - 2, matcher, &things[0]);
+    EQUAL(p, NULL);
+    p = unqueue_matching(&queue, /*max_queue=*/ MAX_QUEUE_SIZE - 1, matcher, &things[0]);
+    EQUAL(p, &things[0]);
+    EQUAL(queue.num_items, MAX_QUEUE_SIZE - 2);
+
+    // fill the queue then remove every other item
+    init_queue(&queue);
+    for (int i = 0; i < MAX_QUEUE_SIZE; ++i)
+    {
+        if (!put_queue(&queue, &things[i]))
+        {
+            FAIL;
+        }
+    }
+    p = unqueue_matching(&queue, MAX_QUEUE_SIZE, matcher, &thing1);
+    EQUAL(p, NULL);
+    for (int i = MAX_QUEUE_SIZE - 1; i >= 0; i -= 2)
+    {
+        p = unqueue_matching(&queue, MAX_QUEUE_SIZE, matcher, &things[i]);
+        EQUAL(p, &things[i]);
+    }
+    EQUAL(queue.num_items, MAX_QUEUE_SIZE / 2);
+    p = unqueue_matching(&queue, MAX_QUEUE_SIZE, matcher, &thing1);
+    EQUAL(p, NULL);
+    for (int i = 0; i < MAX_QUEUE_SIZE; i += 2)
+    {
+        p = get_queue(&queue);
+        EQUAL(p, &things[i]);
+    }
+    EQUAL(queue.num_items, 0);
+
+    // fill the queue then remove every third item
+    for (int i = 0; i < MAX_QUEUE_SIZE; ++i)
+    {
+        if (!put_queue(&queue, &things[i]))
+        {
+            FAIL;
+        }
+    }
+    p = unqueue_matching(&queue, MAX_QUEUE_SIZE, matcher, &thing1);
+    EQUAL(p, NULL);
+    for (int i = 0; i < MAX_QUEUE_SIZE; i += 3)
+    {
+        p = unqueue_matching(&queue, MAX_QUEUE_SIZE, matcher, &things[i]);
+        EQUAL(p, &things[i]);
+    }
+    EQUAL(queue.num_items, MAX_QUEUE_SIZE * 2 / 3);
+    p = unqueue_matching(&queue, MAX_QUEUE_SIZE, matcher, &thing1);
+    EQUAL(p, NULL);
+    for (int i = 0; i < MAX_QUEUE_SIZE; ++i)
+    {
+        if (i % 3 == 0)
+            continue;
+        p = get_queue(&queue);
+        EQUAL(p, &things[i]);
+    }
+    EQUAL(queue.num_items, 0);
+
+    if (!pass)
+        return EXIT_FAILURE;
+    return EXIT_SUCCESS;
+}
diff --git a/openair2/PHY_INTERFACE/queue_test_run b/openair2/PHY_INTERFACE/queue_test_run
new file mode 100755
index 0000000000000000000000000000000000000000..afb3842eb334e4a99b18c109ee80114c706ba67d
--- /dev/null
+++ b/openair2/PHY_INTERFACE/queue_test_run
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+opts=(
+    -Wall -Werror
+    -Wno-error=int-to-pointer-cast
+    -Wno-int-to-pointer-cast
+    -DUNITTEST
+)
+
+set -x
+
+gcc "${opts[@]}" -fsanitize=address -o queue_test queue_test.c queue.c || exit
+./queue_test || exit
+
+gcc "${opts[@]}" -o queue_test queue_test.c queue.c || exit
+valgrind ./queue_test || exit
+
+: PASS
diff --git a/openair2/RRC/L2_INTERFACE/openair_rrc_L2_interface.c b/openair2/RRC/L2_INTERFACE/openair_rrc_L2_interface.c
deleted file mode 100644
index c64fd09bfcc1d0049f2ff260d7eefceb9e19a168..0000000000000000000000000000000000000000
--- a/openair2/RRC/L2_INTERFACE/openair_rrc_L2_interface.c
+++ /dev/null
@@ -1,247 +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 l2_interface.c
-* \brief layer 2 interface
-* \author Navid Nikaein and Raymond Knopp
-* \date 2011
-* \version 1.0
-* \company Eurecom
-* \email: navid.nikaein@eurecom.fr
-*/
-
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "platform_types.h"
-#include "openair_defs.h"
-
-#ifdef CELLULAR
-#include "rrc_L2_proto.h"
-#else
-#include "RRC/LTE/defs.h"
-#endif //CELLULAR
-#include "COMMON/mac_rrc_primitives.h"
-#include "openair_rrc_L2_interface.h"
-
-//------------------------------------------------------------------------------
-int8_t
-mac_rrc_data_req(
-  const module_id_t module_idP,
-  const int         CC_idP,
-  const frame_t     frameP,
-  const rb_id_t     srb_idP,
-  const uint8_t     nb_tbP,
-  uint8_t* const    buffer_pP,
-  const eNB_flag_t  eNB_flagP,
-  const uint8_t     eNB_indexP,
-  const uint8_t     mbsfn_sync_areaP
-)
-//------------------------------------------------------------------------------
-{
-  return(mac_rrc_lite_data_req(
-           module_idP,
-           CC_idP,
-           frameP,
-           srb_idP,
-           nb_tbP,
-           buffer_pP,
-           eNB_flagP,
-           eNB_indexP,
-           mbsfn_sync_areaP)
-        );
-}
-
-//------------------------------------------------------------------------------
-/*int8_t
-mac_rrc_data_ind(
-  const module_id_t     module_idP,
-  const int             CC_idP,
-  const frame_t         frameP,
-  const sub_frame_t     subframeP,
-  const rnti_t          rntiP,
-  const rb_id_t         srb_idP,
-  const uint8_t        *sduP,
-  const sdu_size_t      sdu_lenP,
-  const eNB_flag_t      eNB_flagP,
-  const mac_enb_index_t eNB_indexP,
-  const uint8_t         mbsfn_sync_area
-)
-//------------------------------------------------------------------------------
-{
-  return(mac_rrc_lite_data_ind(
-           module_idP,
-           CC_idP,
-           frameP,subframeP,
-           rntiP,
-           srb_idP,
-           sduP,
-           sdu_lenP,
-           eNB_flagP,
-           eNB_indexP,
-           mbsfn_sync_area)
-        );
-}*/
-
-//------------------------------------------------------------------------------
-void
-rlcrrc_data_ind(
-  const protocol_ctxt_t* const ctxt_pP,
-  const rb_id_t                srb_idP,
-  const sdu_size_t             sdu_lenP,
-  const uint8_t  * const       buffer_pP
-)
-//------------------------------------------------------------------------------
-{
-  rrc_data_ind(ctxt_pP,
-	       srb_idP,
-	       sdu_lenP,
-	       buffer_pP);
-}
-
-//------------------------------------------------------------------------------
-uint8_t
-pdcp_rrc_data_req(
-  const protocol_ctxt_t* const ctxt_pP,
-  const rb_id_t                rb_idP,
-  const mui_t                  muiP,
-  const confirm_t              confirmP,
-  const sdu_size_t             sdu_buffer_sizeP,
-  uint8_t* const               sdu_buffer_pP,
-  const pdcp_transmission_mode_t modeP
-)
-//------------------------------------------------------------------------------
-{
-  return rrc_lite_data_req (
-           ctxt_pP,
-           rb_idP,
-           muiP,
-           confirmP,
-           sdu_buffer_sizeP,
-           sdu_buffer_pP,
-           modeP);
-}
-
-//------------------------------------------------------------------------------
-void
-pdcp_rrc_data_ind(
-  const protocol_ctxt_t* const ctxt_pP,
-  const rb_id_t                srb_idP,
-  const sdu_size_t             sdu_sizeP,
-  uint8_t              * const buffer_pP
-)
-//------------------------------------------------------------------------------
-{
-  rrc_lite_data_ind(
-    ctxt_pP,
-    srb_idP,
-    sdu_sizeP,
-    buffer_pP);
-}
-
-//------------------------------------------------------------------------------
-void
-mac_rrc_meas_ind(
-  const module_id_t module_idP,
-  MAC_MEAS_REQ_ENTRY * const Meas_entry_pP
-)
-//------------------------------------------------------------------------------
-{
-  //  mac_rrc_meas_ind(module_idP,Meas_entry_pP);
-}
-
-//------------------------------------------------------------------------------
-void
-mac_sync_ind(
-  const  module_id_t module_idP,
-  const  uint8_t Status
-)
-//------------------------------------------------------------------------------
-{
-  mac_lite_sync_ind(module_idP,Status);
-}
-
-//------------------------------------------------------------------------------
-void
-mac_in_sync_ind(
-  const module_id_t module_idP,
-  const frame_t frameP,
-  const uint16_t eNB_indexP
-)
-//------------------------------------------------------------------------------
-{
-  rrc_lite_in_sync_ind(module_idP,frameP,eNB_indexP);
-}
-
-//------------------------------------------------------------------------------
-void
-mac_out_of_sync_ind(
-  const module_id_t module_idP,
-  const frame_t frameP,
-  const uint16_t eNB_indexP
-)
-//------------------------------------------------------------------------------
-{
-  rrc_lite_out_of_sync_ind(module_idP,frameP,eNB_indexP);
-}
-
-//------------------------------------------------------------------------------
-int
-mac_eNB_get_rrc_status(
-  const module_id_t   module_idP,
-  const rnti_t  rntiP
-)
-//------------------------------------------------------------------------------
-{
-  return mac_eNB_get_rrc_lite_status(module_idP, rntiP);
-}
-//------------------------------------------------------------------------------
-int
-mac_UE_get_rrc_status(
-  const module_id_t module_idP,
-  const uint8_t     sig_indexP
-)
-//------------------------------------------------------------------------------
-{
-  return mac_UE_get_rrc_lite_status(module_idP, sig_indexP);
-}
-
-//------------------------------------------------------------------------------
-char
-openair_rrc_ue_init(
-  const module_id_t   module_idP,
-  const unsigned char eNB_indexP
-)
-//------------------------------------------------------------------------------
-{
-  return openair_rrc_lite_ue_init(module_idP, eNB_indexP);
-}
-
-//------------------------------------------------------------------------------
-char
-openair_rrc_eNB_init(
-  const module_id_t module_idP
-)
-//------------------------------------------------------------------------------
-{
-  return openair_rrc_lite_eNB_init(module_idP);
-}
diff --git a/openair2/RRC/LTE/L2_interface.c b/openair2/RRC/LTE/L2_interface.c
index 0b767b8ad6efa203c3317cb8c876a35bb7adf803..37595192281a06d39cd55d7839b6c73f7e0b8aab 100644
--- a/openair2/RRC/LTE/L2_interface.c
+++ b/openair2/RRC/LTE/L2_interface.c
@@ -317,6 +317,12 @@ mac_rrc_data_ind(
       sdu_lenP,
       NULL,
       0);
+    struct rrc_eNB_ue_context_s *ue_context_p = rrc_eNB_allocate_new_UE_context(RC.rrc[module_idP]);
+    ue_context_p->ue_id_rnti                    = rntiP;
+    ue_context_p->ue_context.rnti               = rntiP;
+    ue_context_p->ue_context.random_ue_identity = rntiP;
+    ue_context_p->ue_context.Srb0.Active        = 1;
+    RB_INSERT(rrc_ue_tree_s, &RC.rrc[module_idP]->rrc_ue_head, ue_context_p);
     return(0);
   }
 
diff --git a/openair2/RRC/LTE/MESSAGES/asn1_msg.c b/openair2/RRC/LTE/MESSAGES/asn1_msg.c
index ce26aeef871a192f171d994e7449fdad95b63a72..b1f2e6d9b3c2f26c4cb9da378a353b7c34e03bf9 100644
--- a/openair2/RRC/LTE/MESSAGES/asn1_msg.c
+++ b/openair2/RRC/LTE/MESSAGES/asn1_msg.c
@@ -2129,7 +2129,7 @@ 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, size_t buffer_size, uint8_t *rv) {
   asn_enc_rval_t enc_rval;
   uint8_t buf[5],buf2=0;
   LTE_UL_CCCH_Message_t ul_ccch_msg;
@@ -2178,7 +2178,7 @@ uint8_t do_RRCConnectionRequest(uint8_t Mod_id, uint8_t *buffer,uint8_t *rv) {
                                    NULL,
                                    (void *)&ul_ccch_msg,
                                    buffer,
-                                   100);
+                                   buffer_size);
   AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n", 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);
@@ -2378,12 +2378,39 @@ uint8_t do_RRCConnectionSetupComplete(uint8_t Mod_id, uint8_t *buffer, const uin
   return((enc_rval.encoded+7)/8);
 }
 
+static void assign_scg_ConfigResponseNR_r15(LTE_RRCConnectionReconfigurationComplete_t *rrc, OCTET_STRING_t *str)
+{
+  LTE_RRCConnectionReconfigurationComplete_r8_IEs_t *rrc_r8 = &rrc->criticalExtensions.choice.
+                                                    rrcConnectionReconfigurationComplete_r8;
+  typeof(rrc_r8->nonCriticalExtension) nce1;
+  rrc_r8->nonCriticalExtension = nce1 = CALLOC(1, sizeof(*nce1));
+
+  typeof(nce1->nonCriticalExtension) nce2;
+  nce1->nonCriticalExtension = nce2 = CALLOC(1, sizeof(*nce2));
+
+  typeof(nce2->nonCriticalExtension) nce3;
+  nce2->nonCriticalExtension = nce3 = CALLOC(1, sizeof(*nce3));
+
+  typeof(nce3->nonCriticalExtension) nce4;
+  nce3->nonCriticalExtension = nce4 = CALLOC(1, sizeof(*nce4));
+
+  typeof(nce4->nonCriticalExtension) nce5;
+  nce4->nonCriticalExtension = nce5 = CALLOC(1, sizeof(*nce5));
+
+  typeof(nce5->nonCriticalExtension) nce6;
+  nce5->nonCriticalExtension = nce6 = CALLOC(1, sizeof(*nce6));
+
+  nce6->scg_ConfigResponseNR_r15 = str;
+}
+
 //------------------------------------------------------------------------------
-uint8_t
+size_t
 do_RRCConnectionReconfigurationComplete(
   const protocol_ctxt_t *const ctxt_pP,
   uint8_t *buffer,
-  const uint8_t Transaction_id
+  size_t buffer_size,
+  const uint8_t Transaction_id,
+  OCTET_STRING_t *str
 )
 //------------------------------------------------------------------------------
 {
@@ -2397,7 +2424,13 @@ do_RRCConnectionReconfigurationComplete(
   rrcConnectionReconfigurationComplete->rrc_TransactionIdentifier = Transaction_id;
   rrcConnectionReconfigurationComplete->criticalExtensions.present =
     LTE_RRCConnectionReconfigurationComplete__criticalExtensions_PR_rrcConnectionReconfigurationComplete_r8;
-  rrcConnectionReconfigurationComplete->criticalExtensions.choice.rrcConnectionReconfigurationComplete_r8.nonCriticalExtension=NULL;
+  if (str != NULL) {
+    assign_scg_ConfigResponseNR_r15(rrcConnectionReconfigurationComplete, str);
+    LOG_D(RRC, "Successfully assigned scg_ConfigResponseNR_r15\n");
+  }
+  else {
+    rrcConnectionReconfigurationComplete->criticalExtensions.choice.rrcConnectionReconfigurationComplete_r8.nonCriticalExtension=NULL;
+  }
 
   if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
     xer_fprint(stdout, &asn_DEF_LTE_UL_DCCH_Message, (void *)&ul_dcch_msg);
@@ -2407,7 +2440,7 @@ do_RRCConnectionReconfigurationComplete(
                                    NULL,
                                    (void *)&ul_dcch_msg,
                                    buffer,
-                                   100);
+                                   buffer_size);
   AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n",
                enc_rval.failed_type->name, enc_rval.encoded);
   LOG_D(RRC,"RRCConnectionReconfigurationComplete Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);
@@ -3142,6 +3175,7 @@ uint8_t do_RRCConnectionSetup_BR(
 uint8_t do_SecurityModeCommand(
   const protocol_ctxt_t *const ctxt_pP,
   uint8_t *const buffer,
+  size_t buffer_size,
   const uint8_t Transaction_id,
   const uint8_t cipheringAlgorithm,
   const uint8_t integrityProtAlgorithm
@@ -3171,7 +3205,7 @@ uint8_t do_SecurityModeCommand(
                                    NULL,
                                    (void *)&dl_dcch_msg,
                                    buffer,
-                                   100);
+                                   buffer_size);
 
   if(enc_rval.encoded == -1) {
     LOG_I(RRC, "[eNB AssertFatal]ASN1 message encoding failed (%s, %lu)!\n",
@@ -3200,6 +3234,7 @@ uint8_t do_SecurityModeCommand(
 //------------------------------------------------------------------------------
 uint8_t do_UECapabilityEnquiry( const protocol_ctxt_t *const ctxt_pP,
                                 uint8_t               *const buffer,
+                                size_t                       buffer_size,
                                 const uint8_t                Transaction_id,
                                 int16_t              eutra_band,
                                 uint32_t              nr_band)
@@ -3220,58 +3255,56 @@ uint8_t do_UECapabilityEnquiry( const protocol_ctxt_t *const ctxt_pP,
   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);
+
+  /* request NR configuration */
   LTE_UECapabilityEnquiry_r8_IEs_t *r8 = &dl_dcch_msg.message.choice.c1.choice.ueCapabilityEnquiry.criticalExtensions.choice.c1.choice.ueCapabilityEnquiry_r8;
   LTE_UECapabilityEnquiry_v8a0_IEs_t r8_a0;
   LTE_UECapabilityEnquiry_v1180_IEs_t r11_80;
   LTE_UECapabilityEnquiry_v1310_IEs_t r13_10;
   LTE_UECapabilityEnquiry_v1430_IEs_t r14_30;
   LTE_UECapabilityEnquiry_v1510_IEs_t r15_10;
-  OCTET_STRING_t req_freq;
-
-  if (nr_band>0) {
-
-    /* request NR configuration */
 
-    memset(&r8_a0, 0, sizeof(r8_a0));
-    memset(&r11_80, 0, sizeof(r11_80));
-    memset(&r13_10, 0, sizeof(r13_10));
-    memset(&r14_30, 0, sizeof(r14_30));
-    memset(&r15_10, 0, sizeof(r15_10));
+  memset(&r8_a0, 0, sizeof(r8_a0));
+  memset(&r11_80, 0, sizeof(r11_80));
+  memset(&r13_10, 0, sizeof(r13_10));
+  memset(&r14_30, 0, sizeof(r14_30));
+  memset(&r15_10, 0, sizeof(r15_10));
 
-    r8->nonCriticalExtension = &r8_a0;
-    r8_a0.nonCriticalExtension = &r11_80;
-    r11_80.nonCriticalExtension = &r13_10;
-    r13_10.nonCriticalExtension = &r14_30;
-    r14_30.nonCriticalExtension = &r15_10;
+  r8->nonCriticalExtension = &r8_a0;
+  r8_a0.nonCriticalExtension = &r11_80;
+  r11_80.nonCriticalExtension = &r13_10;
+  r13_10.nonCriticalExtension = &r14_30;
+  r14_30.nonCriticalExtension = &r15_10;
 
-    /* TODO: no hardcoded values here */
+  /* TODO: no hardcoded values here */
 
-    nsa_band_list = (NR_FreqBandList_t *)calloc(1, sizeof(NR_FreqBandList_t));
+  nsa_band_list = (NR_FreqBandList_t *)calloc(1, sizeof(NR_FreqBandList_t));
 
-    nsa_band = (NR_FreqBandInformation_t *) calloc(1,sizeof(NR_FreqBandInformation_t));
-    nsa_band->present = NR_FreqBandInformation_PR_bandInformationEUTRA;
-    nsa_band->choice.bandInformationEUTRA = (NR_FreqBandInformationEUTRA_t *) calloc(1, sizeof(NR_FreqBandInformationEUTRA_t));
-    nsa_band->choice.bandInformationEUTRA->bandEUTRA = eutra_band;
-    ASN_SEQUENCE_ADD(&nsa_band_list->list, nsa_band);
+  nsa_band = (NR_FreqBandInformation_t *) calloc(1,sizeof(NR_FreqBandInformation_t));
+  nsa_band->present = NR_FreqBandInformation_PR_bandInformationEUTRA;
+  nsa_band->choice.bandInformationEUTRA = (NR_FreqBandInformationEUTRA_t *) calloc(1, sizeof(NR_FreqBandInformationEUTRA_t));
+  nsa_band->choice.bandInformationEUTRA->bandEUTRA = eutra_band;
+  ASN_SEQUENCE_ADD(&nsa_band_list->list, nsa_band);
 
-    nsa_band = (NR_FreqBandInformation_t *) calloc(1,sizeof(NR_FreqBandInformation_t));
-    nsa_band->present = NR_FreqBandInformation_PR_bandInformationNR;
-    nsa_band->choice.bandInformationNR = (NR_FreqBandInformationNR_t *) calloc(1, sizeof(NR_FreqBandInformationNR_t));
-  //if(nr_band > 0)
+  nsa_band = (NR_FreqBandInformation_t *) calloc(1,sizeof(NR_FreqBandInformation_t));
+  nsa_band->present = NR_FreqBandInformation_PR_bandInformationNR;
+  nsa_band->choice.bandInformationNR = (NR_FreqBandInformationNR_t *) calloc(1, sizeof(NR_FreqBandInformationNR_t));
+  if(nr_band > 0)
     nsa_band->choice.bandInformationNR->bandNR = nr_band;
-  //else
-  //  nsa_band->choice.bandInformationNR->bandNR = 78;
-    ASN_SEQUENCE_ADD(&nsa_band_list->list, nsa_band);
+  else
+    nsa_band->choice.bandInformationNR->bandNR = 78;
+  ASN_SEQUENCE_ADD(&nsa_band_list->list, nsa_band);
 
+  OCTET_STRING_t req_freq;
   //unsigned char req_freq_buf[5] = { 0x00, 0x20, 0x1a, 0x02, 0x68 };  // bands 7 & nr78
-    unsigned char req_freq_buf[1024];
-    enc_rval = uper_encode_to_buffer(&asn_DEF_NR_FreqBandList,
-                                NULL,
-                                (void *)nsa_band_list,
-                                req_freq_buf,
-                                1024);
+  unsigned char req_freq_buf[1024];
+  enc_rval = uper_encode_to_buffer(&asn_DEF_NR_FreqBandList,
+                              NULL,
+                              (void *)nsa_band_list,
+                              req_freq_buf,
+                              1024);
 
-    xer_fprint(stdout, &asn_DEF_NR_FreqBandList, (void *)nsa_band_list);
+  xer_fprint(stdout, &asn_DEF_NR_FreqBandList, (void *)nsa_band_list);
 
 
 
@@ -3282,22 +3315,20 @@ uint8_t do_UECapabilityEnquiry( const protocol_ctxt_t *const ctxt_pP,
 //0x01, 0x60, 0x18, 0x05, 0x80, 0xc0, 0x04, 0x04, 0xc1, 0x2c, 0x10, 0x08, 0x20, 0x30, 0x40, 0xe0, 0x82, 0x40, 0x28, 0x80, 0x9a
 //  };
 
-    req_freq.buf = req_freq_buf;
-    req_freq.size = (enc_rval.encoded+7)/8;
+  req_freq.buf = req_freq_buf;
+  req_freq.size = (enc_rval.encoded+7)/8;
 //  req_freq.size = 21;
 
-    r15_10.requestedFreqBandsNR_MRDC_r15 = &req_freq;
-    // Add request for eutra-nr 
-  }
-//  if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
+  r15_10.requestedFreqBandsNR_MRDC_r15 = &req_freq;
+  if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
     xer_fprint(stdout, &asn_DEF_LTE_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,
-                                   100);
+                                   buffer_size);
 
   if(enc_rval.encoded == -1) {
     LOG_I(RRC, "[eNB AssertFatal]ASN1 message encoding failed (%s, %lu)!\n",
@@ -3324,6 +3355,7 @@ uint8_t do_UECapabilityEnquiry( const protocol_ctxt_t *const ctxt_pP,
 //------------------------------------------------------------------------------
 uint8_t do_NR_UECapabilityEnquiry( const protocol_ctxt_t *const ctxt_pP,
                                    uint8_t               *const buffer,
+                                   size_t                       buffer_size,
                                    const uint8_t                Transaction_id,
                                    int16_t              eutra_band,
                                    uint32_t             nr_band)
@@ -3417,7 +3449,7 @@ uint8_t do_NR_UECapabilityEnquiry( const protocol_ctxt_t *const ctxt_pP,
                                    NULL,
                                    (void *)&dl_dcch_msg,
                                    buffer,
-                                   100);
+                                   buffer_size);
 
   if(enc_rval.encoded == -1) {
     LOG_I(RRC, "[eNB AssertFatal]ASN1 message encoding failed (%s, %lu)!\n",
@@ -3444,6 +3476,7 @@ uint8_t do_NR_UECapabilityEnquiry( const protocol_ctxt_t *const ctxt_pP,
 
 uint16_t do_RRCConnectionReconfiguration_BR(const protocol_ctxt_t        *const ctxt_pP,
     uint8_t                            *buffer,
+    size_t                              buffer_size,
     uint8_t                             Transaction_id,
     LTE_SRB_ToAddModList_t                 *SRB_list,
     LTE_DRB_ToAddModList_t                 *DRB_list,
@@ -3545,7 +3578,7 @@ uint16_t do_RRCConnectionReconfiguration_BR(const protocol_ctxt_t        *const
                                    NULL,
                                    (void *)&dl_dcch_msg,
                                    buffer,
-                                   RRC_BUF_SIZE);
+                                   buffer_size);
   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) ) {
@@ -3562,6 +3595,7 @@ uint16_t do_RRCConnectionReconfiguration_BR(const protocol_ctxt_t        *const
  */
 uint16_t do_RRCConnectionReconfiguration(const protocol_ctxt_t *const ctxt_pP,
     uint8_t                                *buffer,
+    size_t                                  buffer_size,
     uint8_t                                 Transaction_id,
     LTE_SRB_ToAddModList_t                 *SRB_list,
     LTE_DRB_ToAddModList_t                 *DRB_list,
@@ -3722,7 +3756,7 @@ uint16_t do_RRCConnectionReconfiguration(const protocol_ctxt_t *const ctxt_pP,
                                    NULL,
                                    (void *)&dl_dcch_msg,
                                    buffer,
-                                   RRC_BUF_SIZE);
+                                   buffer_size);
 
   if(enc_rval.encoded == -1) {
     LOG_I(RRC, "[eNB AssertFatal]ASN1 message encoding failed (%s, %lu)!\n",
@@ -3977,6 +4011,7 @@ uint8_t do_RRCConnectionReject(uint8_t                    Mod_id,
 
 uint8_t do_RRCConnectionRelease(uint8_t                             Mod_id,
                                 uint8_t                            *buffer,
+                                size_t                              buffer_size,
                                 uint8_t                             Transaction_id) {
   asn_enc_rval_t enc_rval;
   LTE_DL_DCCH_Message_t dl_dcch_msg;
@@ -3998,7 +4033,7 @@ uint8_t do_RRCConnectionRelease(uint8_t                             Mod_id,
                                    NULL,
                                    (void *)&dl_dcch_msg,
                                    buffer,
-                                   RRC_BUF_SIZE);
+                                   buffer_size);
   return((enc_rval.encoded+7)/8);
 }
 
@@ -4008,6 +4043,7 @@ uint8_t TMGI[5] = {4,3,2,1,0};//TMGI is a string of octet, ref. TS 24.008 fig. 1
 uint8_t do_MBSFNAreaConfig(uint8_t Mod_id,
                            uint8_t sync_area,
                            uint8_t *buffer,
+                           size_t buffer_size,
                            LTE_MCCH_Message_t *mcch_message,
                            LTE_MBSFNAreaConfiguration_r9_t **mbsfnAreaConfiguration) {
   asn_enc_rval_t enc_rval;
@@ -4114,7 +4150,7 @@ uint8_t do_MBSFNAreaConfig(uint8_t Mod_id,
                                    NULL,
                                    (void *)mcch_message,
                                    buffer,
-                                   100);
+                                   buffer_size);
 
   if(enc_rval.encoded == -1) {
     LOG_I(RRC, "[eNB AssertFatal]ASN1 message encoding failed (%s, %lu)!\n",
@@ -4133,7 +4169,9 @@ uint8_t do_MBSFNAreaConfig(uint8_t Mod_id,
 }
 
 
-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, size_t buffer_size,
+                             int measid, int phy_id, long rsrp_s, long rsrq_s,
+                             long rsrp_t, long rsrq_t) {
   asn_enc_rval_t enc_rval;
   LTE_UL_DCCH_Message_t ul_dcch_msg;
   LTE_MeasurementReport_t  *measurementReport;
@@ -4205,7 +4243,7 @@ uint8_t do_MeasurementReport(uint8_t Mod_id, uint8_t *buffer,int measid,int phy_
                                    NULL,
                                    (void *)&ul_dcch_msg,
                                    buffer,
-                                   100);
+                                   buffer_size);
 
   if(enc_rval.encoded == -1) {
     LOG_I(RRC, "[eNB AssertFatal]ASN1 message encoding failed (%s, %lu)!\n",
@@ -4220,6 +4258,64 @@ uint8_t do_MeasurementReport(uint8_t Mod_id, uint8_t *buffer,int measid,int phy_
   return((enc_rval.encoded+7)/8);
 }
 
+#define asn1cCallocOne(VaR, VaLue) \
+  VaR = calloc(1,sizeof(*VaR)); *VaR=VaLue;
+#define asn1cCalloc(VaR, lOcPtr) \
+  typeof(VaR) lOcPtr = VaR = calloc(1,sizeof(*VaR));
+#define asn1cSequenceAdd(VaR, TyPe, lOcPtr) \
+  TyPe *lOcPtr= calloc(1,sizeof(TyPe)); \
+  ASN_SEQUENCE_ADD(&VaR,lOcPtr);
+
+ssize_t do_nrMeasurementReport(uint8_t *buffer,
+                               size_t bufsize,
+                               LTE_MeasId_t measid,
+                               LTE_PhysCellIdNR_r15_t phy_id,
+                               long rsrp_s,
+                               long rsrq_s,
+                               long rsrp_tar,
+                               long rsrq_tar) {
+
+  LTE_UL_DCCH_Message_t ul_dcch_msg={0};
+  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;
+
+  LTE_MeasurementReport_t *measurementReport = &ul_dcch_msg.message.choice.c1.choice.measurementReport;
+  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;
+  measurementReport->criticalExtensions.choice.c1.choice.measurementReport_r8.measResults.measResultPCell.rsrpResult = rsrp_s;
+  measurementReport->criticalExtensions.choice.c1.choice.measurementReport_r8.measResults.measResultPCell.rsrqResult = rsrq_s;
+  asn1cCalloc(measurementReport->criticalExtensions.choice.c1.choice.measurementReport_r8.measResults.measResultNeighCells,  
+              measResultNeighCells); 
+  measResultNeighCells->present = LTE_MeasResults__measResultNeighCells_PR_measResultNeighCellListNR_r15;
+  LTE_MeasResultListEUTRA_t  *measResultListEUTRA2=&measResultNeighCells->choice.measResultListEUTRA;
+  asn1cSequenceAdd(measResultListEUTRA2->list, struct LTE_MeasResultEUTRA, measresulteutra_list);
+  measresulteutra_list->physCellId = phy_id;
+  asn1cCalloc(measresulteutra_list->cgi_Info, measresult_cgi2);
+  //measresult_cgi2->cellGlobalId= {0};
+  //measresult_cgi2->trackingAreaCode= {0};
+  struct LTE_MeasResultEUTRA__measResult* measResult= &measresulteutra_list->measResult;
+  asn1cCallocOne(measResult->rsrpResult, rsrp_tar);
+  asn1cCallocOne(measResult->rsrqResult, rsrq_tar);
+  
+  
+  asn_enc_rval_t enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_UL_DCCH_Message,
+                                   NULL,
+                                   &ul_dcch_msg,
+                                   buffer,
+                                   bufsize);
+  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);
+    SEQUENCE_free(&asn_DEF_LTE_UL_DCCH_Message, &ul_dcch_msg, ASFM_FREE_UNDERLYING_AND_RESET);
+    return -1;
+  }
+
+  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) {
   ssize_t encoded;
   LTE_DL_DCCH_Message_t dl_dcch_msg;
@@ -4237,7 +4333,8 @@ uint8_t do_DLInformationTransfer(uint8_t Mod_id, uint8_t **buffer, uint8_t trans
   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, size_t buffer_size,
+                  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;
   LTE_PCCH_Message_t pcch_msg;
@@ -4289,7 +4386,8 @@ uint8_t do_Paging(uint8_t Mod_id, uint8_t *buffer, ue_paging_identity_t ue_pagin
   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);
-  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_LTE_PCCH_Message, NULL, (void *)&pcch_msg,
+                                   buffer, buffer_size);
 
   if(enc_rval.encoded == -1) {
     LOG_I(RRC, "[eNB AssertFatal]ASN1 message encoding failed (%s, %lu)!\n",
@@ -4378,7 +4476,161 @@ int do_HandoverCommand(char *ho_buf, int ho_size, char *rrc_buf, int rrc_size) {
   return((enc_rval.encoded+7)/8);
 }
 
-OAI_UECapability_t *fill_ue_capability(char *UE_EUTRA_Capability_xer_fname) {
+//-----------------------------------------------------------------------------
+int
+is_en_dc_supported(
+  LTE_UE_EUTRA_Capability_t *c
+)
+//-----------------------------------------------------------------------------
+{
+  LOG_D(RRC, "Entered %s \n", __FUNCTION__);
+  /* to be refined - check that the bands supported by the UE include
+   * the band of the gNB
+   */
+#define NCE nonCriticalExtension
+  return c != NULL
+         && c->NCE != NULL
+         && c->NCE->NCE != NULL
+         && c->NCE->NCE->NCE != NULL
+         && c->NCE->NCE->NCE->NCE != NULL
+         && c->NCE->NCE->NCE->NCE->NCE != NULL
+         && c->NCE->NCE->NCE->NCE->NCE->NCE != NULL
+         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE != NULL
+         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE != NULL
+         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE != NULL
+         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE != NULL
+         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE != NULL
+         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE != NULL
+         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE != NULL
+         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE != NULL
+         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE != NULL
+         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE != NULL
+         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE != NULL
+         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE != NULL
+         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE != NULL
+         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE != NULL
+         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE != NULL
+         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE != NULL
+         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE != NULL
+         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE != NULL
+         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->irat_ParametersNR_r15 != NULL
+         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->irat_ParametersNR_r15->en_DC_r15 != NULL
+         && *c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->irat_ParametersNR_r15->en_DC_r15 ==
+         LTE_IRAT_ParametersNR_r15__en_DC_r15_supported;
+#undef NCE
+}
+
+void allocate_en_DC_r15(LTE_UE_EUTRA_Capability_t *cap)
+{
+  LOG_D(RRC, "Entered %s\n", __FUNCTION__);
+  if (!cap->nonCriticalExtension)
+    cap->nonCriticalExtension = CALLOC(1, sizeof(*cap->nonCriticalExtension));
+
+  typeof(cap->nonCriticalExtension) nce1 = cap->nonCriticalExtension;
+  if (!nce1->nonCriticalExtension)
+    nce1->nonCriticalExtension = CALLOC(1, sizeof(*nce1->nonCriticalExtension));
+
+  typeof(nce1->nonCriticalExtension) nce2 = nce1->nonCriticalExtension;
+  if (!nce2->nonCriticalExtension)
+    nce2->nonCriticalExtension = CALLOC(1, sizeof(*nce2->nonCriticalExtension));
+
+  typeof(nce2->nonCriticalExtension) nce3 = nce2->nonCriticalExtension;
+  if (!nce3->nonCriticalExtension)
+    nce3->nonCriticalExtension = CALLOC(1, sizeof(*nce3->nonCriticalExtension));
+
+  typeof(nce3->nonCriticalExtension) nce4 = nce3->nonCriticalExtension;
+  if (!nce4->nonCriticalExtension)
+    nce4->nonCriticalExtension = CALLOC(1, sizeof(*nce4->nonCriticalExtension));
+
+  typeof(nce4->nonCriticalExtension) nce5 = nce4->nonCriticalExtension;
+  if (!nce5->nonCriticalExtension)
+    nce5->nonCriticalExtension = CALLOC(1, sizeof(*nce5->nonCriticalExtension));
+
+  typeof(nce5->nonCriticalExtension) nce6 = nce5->nonCriticalExtension;
+  if (!nce6->nonCriticalExtension)
+    nce6->nonCriticalExtension = CALLOC(1, sizeof(*nce6->nonCriticalExtension));
+
+  typeof(nce6->nonCriticalExtension) nce7 = nce6->nonCriticalExtension;
+  if (!nce7->nonCriticalExtension)
+    nce7->nonCriticalExtension = CALLOC(1, sizeof(*nce7->nonCriticalExtension));
+
+  typeof(nce7->nonCriticalExtension) nce8 = nce7->nonCriticalExtension;
+  if (!nce8->nonCriticalExtension)
+    nce8->nonCriticalExtension = CALLOC(1, sizeof(*nce8->nonCriticalExtension));
+
+  typeof(nce8->nonCriticalExtension) nce9 = nce8->nonCriticalExtension;
+  if (!nce9->nonCriticalExtension)
+    nce9->nonCriticalExtension = CALLOC(1, sizeof(*nce9->nonCriticalExtension));
+
+  typeof(nce9->nonCriticalExtension) nce10 = nce9->nonCriticalExtension;
+  if (!nce10->nonCriticalExtension)
+    nce10->nonCriticalExtension = CALLOC(1, sizeof(*nce10->nonCriticalExtension));
+
+  typeof(nce10->nonCriticalExtension) nce11 = nce10->nonCriticalExtension;
+  if (!nce11->nonCriticalExtension)
+    nce11->nonCriticalExtension = CALLOC(1, sizeof(*nce11->nonCriticalExtension));
+
+  typeof(nce11->nonCriticalExtension) nce12 = nce11->nonCriticalExtension;
+  if (!nce12->nonCriticalExtension)
+    nce12->nonCriticalExtension = CALLOC(1, sizeof(*nce12->nonCriticalExtension));
+
+  typeof(nce12->nonCriticalExtension) nce13 = nce12->nonCriticalExtension;
+  if (!nce13->nonCriticalExtension)
+    nce13->nonCriticalExtension = CALLOC(1, sizeof(*nce13->nonCriticalExtension));
+
+  typeof(nce13->nonCriticalExtension) nce14 = nce13->nonCriticalExtension;
+  if (!nce14->nonCriticalExtension)
+    nce14->nonCriticalExtension = CALLOC(1, sizeof(*nce14->nonCriticalExtension));
+
+  typeof(nce14->nonCriticalExtension) nce15 = nce14->nonCriticalExtension;
+  if (!nce15->nonCriticalExtension)
+    nce15->nonCriticalExtension = CALLOC(1, sizeof(*nce15->nonCriticalExtension));
+
+  typeof(nce15->nonCriticalExtension) nce16 = nce15->nonCriticalExtension;
+  if (!nce16->nonCriticalExtension)
+    nce16->nonCriticalExtension = CALLOC(1, sizeof(*nce16->nonCriticalExtension));
+
+  typeof(nce16->nonCriticalExtension) nce17 = nce16->nonCriticalExtension;
+  if (!nce17->nonCriticalExtension)
+    nce17->nonCriticalExtension = CALLOC(1, sizeof(*nce17->nonCriticalExtension));
+
+  typeof(nce17->nonCriticalExtension) nce18 = nce17->nonCriticalExtension;
+  if (!nce18->nonCriticalExtension)
+    nce18->nonCriticalExtension = CALLOC(1, sizeof(*nce18->nonCriticalExtension));
+
+  typeof(nce18->nonCriticalExtension) nce19 = nce18->nonCriticalExtension;
+  if (!nce19->nonCriticalExtension)
+    nce19->nonCriticalExtension = CALLOC(1, sizeof(*nce19->nonCriticalExtension));
+
+  typeof(nce19->nonCriticalExtension) nce20 = nce19->nonCriticalExtension;
+  if (!nce20->nonCriticalExtension)
+    nce20->nonCriticalExtension = CALLOC(1, sizeof(*nce20->nonCriticalExtension));
+
+  typeof(nce20->nonCriticalExtension) nce21 = nce20->nonCriticalExtension;
+  if (!nce21->nonCriticalExtension)
+    nce21->nonCriticalExtension = CALLOC(1, sizeof(*nce21->nonCriticalExtension));
+
+  typeof(nce21->nonCriticalExtension) nce22 = nce21->nonCriticalExtension;
+  if (!nce22->nonCriticalExtension)
+    nce22->nonCriticalExtension = CALLOC(1, sizeof(*nce22->nonCriticalExtension));
+
+  typeof(nce22->nonCriticalExtension) nce23 = nce22->nonCriticalExtension;
+  if (!nce23->nonCriticalExtension)
+    nce23->nonCriticalExtension = CALLOC(1, sizeof(*nce23->nonCriticalExtension));
+
+  typeof(nce23->nonCriticalExtension) nce24 = nce23->nonCriticalExtension;
+  if (!nce24->irat_ParametersNR_r15)
+    nce24->irat_ParametersNR_r15 = CALLOC(1, sizeof(*nce24->irat_ParametersNR_r15));
+
+  typeof(nce24->irat_ParametersNR_r15) irat = nce24->irat_ParametersNR_r15;
+  if (!irat->en_DC_r15)
+    irat->en_DC_r15 = CALLOC(1, sizeof(*irat->en_DC_r15));
+
+  *irat->en_DC_r15 = LTE_IRAT_ParametersNR_r15__en_DC_r15_supported;
+
+}
+
+OAI_UECapability_t *fill_ue_capability(char *UE_EUTRA_Capability_xer_fname, bool received_nr_msg) {
   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
@@ -4476,7 +4728,13 @@ OAI_UECapability_t *fill_ue_capability(char *UE_EUTRA_Capability_xer_fname) {
       UE_EUTRA_Capability->featureGroupIndicators = bit_string;
     }
 
-    // UE_EUTRA_Capability->interRAT_Parameters     // null
+    if (get_softmodem_params()->nsa && received_nr_msg)
+    {
+       allocate_en_DC_r15(UE_EUTRA_Capability);
+       if (!is_en_dc_supported(UE_EUTRA_Capability)){
+         LOG_E(RRC, "We did not properly allocate en_DC_r15 for UE_EUTRA_Capability\n");
+       }
+    }
   } else {
     FILE *f = fopen(UE_EUTRA_Capability_xer_fname, "r");
     assert(f);
diff --git a/openair2/RRC/LTE/MESSAGES/asn1_msg.h b/openair2/RRC/LTE/MESSAGES/asn1_msg.h
index 0d9fe65aeb0a03ed3e6eb49ac36e574f887d40cc..d1d1d3febe15254bac219f28f439bd1578b8a749 100644
--- a/openair2/RRC/LTE/MESSAGES/asn1_msg.h
+++ b/openair2/RRC/LTE/MESSAGES/asn1_msg.h
@@ -41,6 +41,7 @@
 
 #include "RRC/LTE/rrc_defs.h"
 #include "LTE_SL-DestinationInfoList-r12.h"
+#include "OctetString.h"
 
 /*
  * The variant of the above function which dumps the BASIC-XER (XER_F_BASIC)
@@ -52,6 +53,14 @@
  */
 int xer_sprint(char *string, size_t string_size, struct asn_TYPE_descriptor_s *td, void *sptr);
 
+#define asn1cCallocOne(VaR, VaLue) \
+  VaR = calloc(1,sizeof(*VaR)); *VaR=VaLue;
+#define asn1cCalloc(VaR, lOcPtr) \
+  typeof(VaR) lOcPtr = VaR = calloc(1,sizeof(*VaR));
+#define asn1cSequenceAdd(VaR, TyPe, lOcPtr) \
+  TyPe *lOcPtr= calloc(1,sizeof(TyPe)); \
+  ASN_SEQUENCE_ADD(&VaR,lOcPtr);
+
 uint16_t get_adjacent_cell_id(uint8_t Mod_id,uint8_t index);
 
 uint8_t get_adjacent_cell_mod_id(uint16_t phyCellId);
@@ -129,7 +138,7 @@ routine only generates an mo-data establishment cause.
 @param rv 5 byte random string or S-TMSI
 @returns Size of encoded bit stream in bytes*/
 
-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, size_t buffer_size, uint8_t *rv);
 
 /**
 \brief Generate an SidelinkUEInformation UL-DCCH-Message (UE).
@@ -156,7 +165,9 @@ uint8_t
 do_RRCConnectionReconfigurationComplete(
   const protocol_ctxt_t *const ctxt_pP,
   uint8_t *buffer,
-  const uint8_t Transaction_id
+  size_t buffer_size,
+  const uint8_t Transaction_id,
+  OCTET_STRING_t *str
 );
 
 /**
@@ -204,6 +215,7 @@ uint16_t
 do_RRCConnectionReconfiguration_BR(
   const protocol_ctxt_t        *const ctxt_pP,
   uint8_t                            *buffer,
+  size_t                              buffer_size,
   uint8_t                             Transaction_id,
   LTE_SRB_ToAddModList_t                 *SRB_list,
   LTE_DRB_ToAddModList_t                 *DRB_list,
@@ -249,6 +261,7 @@ uint16_t
 do_RRCConnectionReconfiguration(
   const protocol_ctxt_t                  *const ctxt_pP,
   uint8_t                                *buffer,
+  size_t                                 buffer_size,
   uint8_t                                Transaction_id,
   LTE_SRB_ToAddModList_t                 *SRB_list,
   LTE_DRB_ToAddModList_t                 *DRB_list,
@@ -322,14 +335,8 @@ routine only generates an mo-data establishment cause.
 @param transaction_id Transaction index
 @returns Size of encoded bit stream in bytes*/
 
-uint8_t do_RRCConnectionRelease(uint8_t Mod_id, uint8_t *buffer,int Transaction_id);
+uint8_t do_RRCConnectionRelease(uint8_t Mod_id, uint8_t *buffer, size_t buffer_size, int Transaction_id);
 
-/***
- * \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
- * @returns Size of encoded bit stream in bytes
-*/
-uint8_t do_MCCHMessage(uint8_t *buffer);
 /***
  * \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
@@ -338,14 +345,28 @@ uint8_t do_MCCHMessage(uint8_t *buffer);
 uint8_t do_MBSFNAreaConfig(uint8_t Mod_id,
                            uint8_t sync_area,
                            uint8_t *buffer,
+                           size_t buffer_size,
                            LTE_MCCH_Message_t *mcch_message,
                            LTE_MBSFNAreaConfiguration_r9_t **mbsfnAreaConfiguration);
 
-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);
+ssize_t do_MeasurementReport(uint8_t Mod_id, uint8_t *buffer, size_t buffer_size,
+                             int measid, int phy_id,
+                             long rsrp_s, long rsrq_s,
+                             long rsrp_t, long rsrq_t);
+
+ssize_t do_nrMeasurementReport(uint8_t *buffer,
+                               size_t bufsize,
+                               LTE_MeasId_t measid,
+                               LTE_PhysCellIdNR_r15_t phy_id,
+                               long rsrp_s,
+                               long rsrq_s,
+                               long rsrp_tar,
+                               long rsrq_tar);
 
 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_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, size_t buffer_size,
+                  ue_paging_identity_t ue_paging_identity, cn_domain_t cn_domain);
 
 uint8_t do_ULInformationTransfer(uint8_t **buffer, uint32_t pdu_length, uint8_t *pdu_buffer);
 
@@ -353,12 +374,17 @@ int do_HandoverPreparation(char *ho_buf, int ho_size, LTE_UE_EUTRA_Capability_t
 
 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);
+OAI_UECapability_t *fill_ue_capability(char *LTE_UE_EUTRA_Capability_xer, bool received_nr_msg);
+
+int is_en_dc_supported(LTE_UE_EUTRA_Capability_t *c);
+
+void allocate_en_DC_r15(LTE_UE_EUTRA_Capability_t *cap);
 
 uint8_t
 do_UECapabilityEnquiry(
   const protocol_ctxt_t *const ctxt_pP,
   uint8_t               *const buffer,
+  size_t                       buffer_size,
   const uint8_t                Transaction_id,
   int16_t              eutra_band,
   uint32_t              nr_band);
@@ -367,6 +393,7 @@ uint8_t
 do_NR_UECapabilityEnquiry(
   const protocol_ctxt_t *const ctxt_pP,
   uint8_t               *const buffer,
+  size_t                       buffer_size,
   const uint8_t                Transaction_id,
   int16_t              eutra_band,
   uint32_t             nr_band);
@@ -374,6 +401,7 @@ do_NR_UECapabilityEnquiry(
 uint8_t do_SecurityModeCommand(
   const protocol_ctxt_t *const ctxt_pP,
   uint8_t *const buffer,
+  size_t buffer_size,
   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 350a8baf77faec3e25b78207c1a46b51488f349f..d13dcb9918c828f46d4dfb6a51ac2be4d592fb26 100644
--- a/openair2/RRC/LTE/MESSAGES/asn1_msg_NB_IoT.c
+++ b/openair2/RRC/LTE/MESSAGES/asn1_msg_NB_IoT.c
@@ -834,6 +834,7 @@ uint8_t do_UECapabilityEnquiry_NB_IoT(
 uint16_t do_RRCConnectionReconfiguration_NB_IoT(
   const protocol_ctxt_t        *const ctxt_pP,
   uint8_t                            *buffer,
+  size_t                              buffer_size,
   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)
@@ -886,7 +887,7 @@ uint16_t do_RRCConnectionReconfiguration_NB_IoT(
                                    NULL,
                                    (void *)&dl_dcch_msg_NB_IoT,
                                    buffer,
-                                   RRC_BUF_SIZE);
+                                   buffer_size);
 
   if (enc_rval.encoded <= 0) {
     LOG_E(RRC, "ASN1 message encoding failed %s, %li\n",
@@ -1020,7 +1021,8 @@ 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,
+  uint8_t *buffer,
+  size_t buffer_size,
   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?
@@ -1046,7 +1048,7 @@ uint8_t do_RRCConnectionReestablishment_NB_IoT(
                                    NULL,
                                    (void *)&dl_ccch_msg_NB_IoT,
                                    buffer,
-                                   RRC_BUF_SIZE);
+                                   buffer_size);
 
   if (enc_rval.encoded <= 0) {
     LOG_E(RRC, "ASN1 message encoding failed (%s, %li)!\n",
@@ -1065,6 +1067,7 @@ uint8_t do_RRCConnectionReestablishment_NB_IoT(
 uint8_t do_RRCConnectionRelease_NB_IoT(
   uint8_t                             Mod_id,
   uint8_t                            *buffer,
+  size_t                              buffer_size,
   const uint8_t                             Transaction_id) {
   asn_enc_rval_t enc_rval;
   LTE_DL_DCCH_Message_NB_t dl_dcch_msg_NB_IoT;
@@ -1087,7 +1090,7 @@ uint8_t do_RRCConnectionRelease_NB_IoT(
                                    NULL,
                                    (void *)&dl_dcch_msg_NB_IoT,
                                    buffer,
-                                   RRC_BUF_SIZE);//check
+                                   buffer_size);
   return((enc_rval.encoded+7)/8);
 }
 
diff --git a/openair2/RRC/LTE/MESSAGES/asn1_msg_NB_IoT.h b/openair2/RRC/LTE/MESSAGES/asn1_msg_NB_IoT.h
index a862af783680c134aa859918a08f73256cc056a4..b52fdb76e03b88398519012624adc23285afbbd9 100644
--- a/openair2/RRC/LTE/MESSAGES/asn1_msg_NB_IoT.h
+++ b/openair2/RRC/LTE/MESSAGES/asn1_msg_NB_IoT.h
@@ -125,10 +125,12 @@ uint8_t do_RRCConnectionSetupComplete_NB_IoT(uint8_t Mod_id, uint8_t* buffer, co
 @param Transaction_id
 @returns Size of encoded bit stream in bytes*/
 
-uint8_t do_RRCConnectionReconfigurationComplete_NB_IoT(
+size_t do_RRCConnectionReconfigurationComplete_NB_IoT(
   const protocol_ctxt_t* const ctxt_pP,
   uint8_t* buffer,
-  const uint8_t Transaction_id
+  size_t buffer_size,
+  const uint8_t Transaction_id,
+  OCTET_STRING_t *str
 );
 
 /**
@@ -178,6 +180,7 @@ uint16_t
 do_RRCConnectionReconfiguration_NB_IoT(
   const protocol_ctxt_t*        const ctxt_pP,
     uint8_t                            *buffer,
+    size_t                              buffer_size,
     uint8_t                             Transaction_id,
     SRB_ToAddModList_NB_r13_t          *SRB_list_NB_IoT,
     DRB_ToAddModList_NB_r13_t          *DRB_list_NB_IoT,
@@ -249,8 +252,8 @@ do_RRCConnectionReject_NB_IoT(
 @param transaction_id Transaction index
 @returns Size of encoded bit stream in bytes*/
 
-uint8_t do_RRCConnectionRelease_NB_IoT(uint8_t Mod_id, uint8_t *buffer,int Transaction_id);
-
+uint8_t do_RRCConnectionRelease_NB_IoT(uint8_t Mod_id, uint8_t *buffer, size_t buffer_size,
+                                       int Transaction_id);
 
 uint8_t do_DLInformationTransfer_NB_IoT(
 		uint8_t Mod_id,
@@ -273,7 +276,8 @@ uint8_t do_DLInformationTransfer_NB_IoT(
 
 uint8_t do_RRCConnectionReestablishment_NB_IoT(
 		uint8_t Mod_id,
-		uint8_t* const buffer,
+		uint8_t* buffer,
+		size_t buffer_size,
 		const uint8_t     Transaction_id,
 		const NB_IoT_DL_FRAME_PARMS* const frame_parms, //to be changed
 		SRB_ToAddModList_NB_r13_t**             SRB_configList_NB_IoT
diff --git a/openair2/RRC/LTE/defs_NB_IoT.h b/openair2/RRC/LTE/defs_NB_IoT.h
index 3907d2321d89aa6f2ee66ccfdb2c0211c5f9cbe8..37a26086b55902a4818aa37f3841bf27d7139780 100644
--- a/openair2/RRC/LTE/defs_NB_IoT.h
+++ b/openair2/RRC/LTE/defs_NB_IoT.h
@@ -148,7 +148,7 @@ typedef struct UE_RRC_INFO_NB_IoT_s {
 //Measurement Report not supported in NB-IoT
 
 #define PAYLOAD_SIZE_MAX 1024
-#define RRC_BUF_SIZE 8192
+#define RRC_BUF_SIZE 512
 #define UNDEF_SECURITY_MODE 0xff
 #define NO_SECURITY_MODE 0x20
 
diff --git a/openair2/RRC/LTE/rrc_UE.c b/openair2/RRC/LTE/rrc_UE.c
index 4b862fa11da37475ccb6b07882e8630c9843fd58..d0b89abb51e316f7af0a3cf18f410011523d2e8d 100644
--- a/openair2/RRC/LTE/rrc_UE.c
+++ b/openair2/RRC/LTE/rrc_UE.c
@@ -75,7 +75,7 @@
 #include <common/utils/system.h>
 
 #include "intertask_interface.h"
-
+#include "targets/RT/USER/lte-softmodem.h"
 
 #include "SIMULATION/TOOLS/sim.h" // for taus
 
@@ -92,8 +92,10 @@
 
 //for D2D
 int ctrl_sock_fd;
-#define BUFSIZE 1024
 struct sockaddr_in prose_app_addr;
+static const char nsa_ipaddr[] = "127.0.0.1";
+static int from_nr_ue_fd = -1;
+static int to_nr_ue_fd = -1;
 int slrb_id;
 int send_ue_information = 0;
 
@@ -123,6 +125,26 @@ static int decode_SIB1( const protocol_ctxt_t *const ctxt_pP, const uint8_t eNB_
 
 static int decode_SIB1_MBMS( const protocol_ctxt_t *const ctxt_pP, const uint8_t eNB_index, const uint8_t rsrq, const uint8_t rsrp );
 
+typedef struct rrc_dcch_data_copy_t
+{
+    LTE_DL_DCCH_Message_t *dl_dcch_msg;
+} rrc_dcch_data_copy_t;
+
+typedef struct rrc_nrue_cap_info_t
+{
+    uint8_t mesg[RRC_BUF_SIZE];
+    size_t mesg_len;
+    LTE_DL_DCCH_Message_t *dl_dcch_msg;
+} rrc_nrue_cap_info_t;
+
+static void rrc_ue_process_ueCapabilityEnquiry(const protocol_ctxt_t *const ctxt_pP,
+                                               LTE_UECapabilityEnquiry_t *UECapabilityEnquiry,
+                                               uint8_t eNB_index);
+
+static void rrc_ue_process_nrueCapabilityEnquiry(const protocol_ctxt_t *const ctxt_pP,
+                                                 LTE_UECapabilityEnquiry_t *UECapabilityEnquiry,
+                                                 rrc_nrue_cap_info_t *nrue_cap_info,
+                                                 uint8_t eNB_index);
 
 /** \brief Generates/Encodes RRCConnnectionSetupComplete message at UE
  *  \param ctxt_pP Running context
@@ -141,10 +163,15 @@ static void rrc_ue_generate_RRCConnectionSetupComplete(
  *  \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,
+                                                                 OCTET_STRING_t *str);
 
 static void rrc_ue_generate_MeasurementReport(protocol_ctxt_t *const ctxt_pP, uint8_t eNB_index );
 
+static void rrc_ue_generate_nrMeasurementReport(protocol_ctxt_t *const ctxt_pP, uint8_t eNB_index );
+
 static uint8_t check_trigger_meas_event(
   module_id_t module_idP,
   frame_t frameP,
@@ -166,7 +193,9 @@ rrc_ue_process_MBMSCountingRequest(
   LTE_MBMSCountingRequest_r10_t *MBMSCountingRequest,
   uint8_t eNB_index
 		);
- 
+
+static void process_nr_nsa_msg(nsa_msg_t *msg, int msg_len);
+static void nsa_sendmsg_to_nrue(const void *message, size_t msg_len, Rrc_Msg_Type_t msg_type);
 protocol_ctxt_t ctxt_pP_local;
 
 
@@ -399,12 +428,12 @@ char openair_rrc_ue_init( const module_id_t ue_mod_idP, const unsigned char eNB_
 
 //-----------------------------------------------------------------------------
 void rrc_ue_generate_RRCConnectionRequest( const protocol_ctxt_t *const ctxt_pP, const uint8_t eNB_index ) {
-  uint8_t i=0,rv[6];
+  uint8_t 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++) {
+    for (int i=0; i<6; i++) {
 #ifdef SMBV
       // if SMBV is configured the contention resolution needs to be fix for the connection procedure to succeed
       rv[i]=i;
@@ -419,12 +448,13 @@ void rrc_ue_generate_RRCConnectionRequest( const protocol_ctxt_t *const ctxt_pP,
       do_RRCConnectionRequest(
         ctxt_pP->module_id,
         (uint8_t *)UE_rrc_inst[ctxt_pP->module_id].Srb0[eNB_index].Tx_buffer.Payload,
+        sizeof(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);
 
-    for (i=0; i<UE_rrc_inst[ctxt_pP->module_id].Srb0[eNB_index].Tx_buffer.payload_size; i++) {
-      LOG_T(RRC,"%x.",UE_rrc_inst[ctxt_pP->module_id].Srb0[eNB_index].Tx_buffer.Payload[i]);
+    for (int i=0; i<UE_rrc_inst[ctxt_pP->module_id].Srb0[eNB_index].Tx_buffer.payload_size; i++) {
+      LOG_T(RRC,"%x.\n",UE_rrc_inst[ctxt_pP->module_id].Srb0[eNB_index].Tx_buffer.Payload[i]);
     }
 
     LOG_T(RRC,"\n");
@@ -529,13 +559,16 @@ static void rrc_ue_generate_RRCConnectionSetupComplete(
 }
 
 //-----------------------------------------------------------------------------
-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",
+void rrc_ue_generate_RRCConnectionReconfigurationComplete(const protocol_ctxt_t *const ctxt_pP,
+                                                          const uint8_t eNB_index,
+                                                          const uint8_t Transaction_id,
+                                                          OCTET_STRING_t *str) {
+  uint8_t buffer[RRC_BUF_SIZE];
+  size_t size = do_RRCConnectionReconfigurationComplete(ctxt_pP, buffer, sizeof(buffer), Transaction_id, str);
+  LOG_I(RRC,PROTOCOL_RRC_CTXT_UE_FMT" Logical Channel UL-DCCH (SRB1), Generating RRCConnectionReconfigurationComplete (bytes %zu, eNB_index %d)\n",
         PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP), size, eNB_index);
   LOG_D(RLC,
-        "[FRAME %05d][RRC_UE][INST %02d][][--- PDCP_DATA_REQ/%d Bytes (RRCConnectionReconfigurationComplete to eNB %d MUI %d) --->][PDCP][INST %02d][RB %02d]\n",
+        "[FRAME %05d][RRC_UE][INST %02d][][--- PDCP_DATA_REQ/%zu Bytes (RRCConnectionReconfigurationComplete to eNB %d MUI %d) --->][PDCP][INST %02d][RB %02d]\n",
         ctxt_pP->frame,
         UE_MODULE_ID_TO_INSTANCE(ctxt_pP->module_id),
         size,
@@ -614,7 +647,7 @@ int rrc_ue_decode_ccch( const protocol_ctxt_t *const ctxt_pP, const SRB_INFO *co
           break;
 
         case LTE_DL_CCCH_MessageType__c1_PR_rrcConnectionSetup:
-          LOG_I(RRC,
+          LOG_A(RRC,
                 "[UE%d][RAPROC] Frame %d : Logical Channel DL-CCCH (SRB0), Received RRCConnectionSetup RNTI %x\n",
                 ctxt_pP->module_id,
                 ctxt_pP->frame,
@@ -761,38 +794,60 @@ rrc_ue_process_measConfig(
   int i;
   long ind;
   LTE_MeasObjectToAddMod_t *measObj;
+  UE_RRC_INST *ue = &UE_rrc_inst[ctxt_pP->module_id];
 
   if (measConfig->measObjectToRemoveList != NULL) {
-    for (i=0; i<measConfig->measObjectToRemoveList->list.count; i++) {
-      ind   = *measConfig->measObjectToRemoveList->list.array[i];
-      free(UE_rrc_inst[ctxt_pP->module_id].MeasObj[eNB_index][ind-1]);
+    for (i = 0; i < measConfig->measObjectToRemoveList->list.count; i++) {
+      ind = *measConfig->measObjectToRemoveList->list.array[i];
+      free(ue->MeasObj[eNB_index][ind-1]);
+      ue->MeasObj[eNB_index][ind-1] = NULL;
     }
   }
 
   if (measConfig->measObjectToAddModList != NULL) {
-    LOG_D(RRC,"Measurement Object List is present\n");
+    LOG_I(RRC,"Measurement Object List is present\n");
 
-    for (i=0; i<measConfig->measObjectToAddModList->list.count; i++) {
+    for (i = 0; i < measConfig->measObjectToAddModList->list.count; i++) {
       measObj = measConfig->measObjectToAddModList->list.array[i];
-      ind   = measConfig->measObjectToAddModList->list.array[i]->measObjectId;
-
-      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],
+      ind = measConfig->measObjectToAddModList->list.array[i]->measObjectId;
+      AssertFatal(ind > 0 && ind <= MAX_MEAS_OBJ && eNB_index >= 0 && eNB_index < NB_CNX_UE,
+                 "measObjectId is out of bounds. ind = %ld, eNB_index = %d, i = %d.\n", ind, eNB_index, i);
+      if (ue->MeasObj[eNB_index][ind-1]) {
+        LOG_D(RRC, "Modifying measurement object [%d][%ld]\n", eNB_index, ind);
+        memcpy((char *)ue->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 == 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,
-                measObj->measObject.choice.measObjectEUTRA.presenceAntennaPort1,
-                measObj->measObject.choice.measObjectEUTRA.neighCellConfig.buf[0]);
-          UE_rrc_inst[ctxt_pP->module_id].MeasObj[eNB_index][ind-1]=measObj;
+          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,
+                  measObj->measObject.choice.measObjectEUTRA.presenceAntennaPort1,
+                  measObj->measObject.choice.measObjectEUTRA.neighCellConfig.buf[0]);
+          } else if (measObj->measObject.present == LTE_MeasObjectToAddMod__measObject_PR_measObjectNR_r15) {
+            ue->subframeCount = 0;
+            LOG_I(RRC, "NR_r15 Measurement: carrierFreq: %ld\n",
+                  measObj->measObject.choice.measObjectNR_r15.carrierFreq_r15);
+            if (!get_softmodem_params()->nsa) {
+              LOG_E(RRC, "Not in NSA mode but attempting to send measurement request to NR-UE\n");
+              return;
+            }
+            uint8_t buffer[RRC_BUF_SIZE];
+            asn_enc_rval_t enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_MeasObjectToAddMod,
+                                                            NULL,
+                                                            measObj,
+                                                            buffer,
+                                                            sizeof(buffer));
+            AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %zu)!\n",
+                          enc_rval.failed_type->name, enc_rval.encoded);
+            nsa_sendmsg_to_nrue(buffer, (enc_rval.encoded + 7)/8, RRC_MEASUREMENT_PROCEDURE);
+            LOG_A(RRC, "Encoded measurement object %zu bits (%zu bytes) and sent to NR UE\n",
+                  enc_rval.encoded, (enc_rval.encoded + 7)/8);
+          }
+          LOG_D(RRC, "Adding measurement object [%d][%ld]\n", eNB_index, ind);
+          ue->MeasObj[eNB_index][ind-1]=measObj;
         }
-      }
+        measConfig->measObjectToAddModList->list.array[i] = NULL;
     }
 
     LOG_I(RRC,"call rrc_mac_config_req \n");
@@ -800,7 +855,7 @@ rrc_ue_process_measConfig(
                           (LTE_RadioResourceConfigCommonSIB_t *)NULL,
                           (struct LTE_PhysicalConfigDedicated *)NULL,
                           (LTE_SCellToAddMod_r10_t *)NULL,
-                          UE_rrc_inst[ctxt_pP->module_id].MeasObj[eNB_index],
+                          ue->MeasObj[eNB_index],
                           (LTE_MAC_MainConfig_t *)NULL,
                           0,
                           (struct LTE_LogicalChannelConfig *)NULL,
@@ -828,109 +883,120 @@ rrc_ue_process_measConfig(
   if (measConfig->reportConfigToRemoveList != NULL) {
     for (i=0; i<measConfig->reportConfigToRemoveList->list.count; i++) {
       ind   = *measConfig->reportConfigToRemoveList->list.array[i];
-      free(UE_rrc_inst[ctxt_pP->module_id].ReportConfig[eNB_index][ind-1]);
+      free(ue->ReportConfig[eNB_index][ind-1]);
+      ue->ReportConfig[eNB_index][ind-1] = NULL;
     }
   }
 
   if (measConfig->reportConfigToAddModList != NULL) {
     LOG_I(RRC,"Report Configuration List is present\n");
 
-    for (i=0; i<measConfig->reportConfigToAddModList->list.count; i++) {
-      ind   = measConfig->reportConfigToAddModList->list.array[i]->reportConfigId;
-
-      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],
+    for (i=0; i < measConfig->reportConfigToAddModList->list.count; i++) {
+      ind = measConfig->reportConfigToAddModList->list.array[i]->reportConfigId;
+      AssertFatal(ind > 0 && ind <= MAX_MEAS_CONFIG && eNB_index >= 0 && eNB_index < NB_CNX_UE,
+                 "ReportConfigId is out of bounds. ind = %ld, eNB_index = %d, i = %d.\n", ind, eNB_index, i);
+      if (ue->ReportConfig[eNB_index][ind-1]) {
+        LOG_D(RRC,"Modifying ReportConfig [%d][%ld]\n", eNB_index, ind-1);
+        memcpy((char *)ue->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];
+        LOG_D(RRC,"Adding ReportConfig [%d][%ld]\n", eNB_index, ind-1);
+        ue->ReportConfig[eNB_index][ind-1] = measConfig->reportConfigToAddModList->list.array[i];
       }
+      measConfig->reportConfigToAddModList->list.array[i] = NULL;
     }
   }
 
   if (measConfig->quantityConfig != NULL) {
-    if (UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index]) {
+    if (ue->QuantityConfig[eNB_index]) {
       LOG_D(RRC,"Modifying Quantity Configuration \n");
-      memcpy((char *)UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index],
+      memcpy((char *)ue->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;
+      ue->QuantityConfig[eNB_index] = measConfig->quantityConfig;
     }
+    measConfig->quantityConfig = NULL;
   }
 
   if (measConfig->measIdToRemoveList != NULL) {
     for (i=0; i<measConfig->measIdToRemoveList->list.count; i++) {
       ind   = *measConfig->measIdToRemoveList->list.array[i];
-      free(UE_rrc_inst[ctxt_pP->module_id].MeasId[eNB_index][ind-1]);
+      free(ue->MeasId[eNB_index][ind-1]);
+      ue->MeasId[eNB_index][ind-1] = NULL;
     }
   }
 
   if (measConfig->measIdToAddModList != NULL) {
     for (i=0; i<measConfig->measIdToAddModList->list.count; i++) {
       ind   = measConfig->measIdToAddModList->list.array[i]->measId;
-
-      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],
+      AssertFatal(ind > 0 && ind <= MAX_MEAS_ID && eNB_index >= 0 && eNB_index < NB_CNX_UE,
+                 "measId is out of bounds. ind = %ld, eNB_index = %d, i = %d.\n", ind, eNB_index, i);
+      if (ue->MeasId[eNB_index][ind-1]) {
+        LOG_I(RRC,"Modifying Measurement ID [%d][%ld]\n", eNB_index, ind-1);
+        memcpy((char *)ue->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];
+        LOG_I(RRC,"Adding Measurement ID [%d][%ld]\n", eNB_index, ind-1);
+        ue->MeasId[eNB_index][ind-1] = measConfig->measIdToAddModList->list.array[i];
       }
+      measConfig->measIdToAddModList->list.array[i] = NULL;
     }
   }
 
   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],
+    if (ue->measGapConfig[eNB_index]) {
+      memcpy((char *)ue->measGapConfig[eNB_index],
              (char *)measConfig->measGapConfig,
              sizeof(LTE_MeasGapConfig_t));
     } else {
-      UE_rrc_inst[ctxt_pP->module_id].measGapConfig[eNB_index] = measConfig->measGapConfig;
+      ue->measGapConfig[eNB_index] = measConfig->measGapConfig;
     }
+    measConfig->measGapConfig = NULL;
   }
 
   if (measConfig->quantityConfig != NULL) {
-    if (UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index]) {
+    if (ue->QuantityConfig[eNB_index]) {
       LOG_I(RRC,"Modifying Quantity Configuration \n");
-      memcpy((char *)UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index],
+      memcpy((char *)ue->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;
+      ue->QuantityConfig[eNB_index] = measConfig->quantityConfig;
     }
+    measConfig->quantityConfig = NULL;
 
-    UE_rrc_inst[ctxt_pP->module_id].filter_coeff_rsrp = 1./pow(2,
-        (*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);
+    ue->filter_coeff_rsrp = 1./pow(2,
+        (*ue->QuantityConfig[eNB_index]->quantityConfigEUTRA->filterCoefficientRSRP)/4);
+    ue->filter_coeff_rsrq = 1./pow(2,
+        (*ue->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,
-          *UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index]->quantityConfigEUTRA->filterCoefficientRSRQ,
-          UE_rrc_inst[ctxt_pP->module_id].filter_coeff_rsrp,
-          UE_rrc_inst[ctxt_pP->module_id].filter_coeff_rsrq);
+          *ue->QuantityConfig[eNB_index]->quantityConfigEUTRA->filterCoefficientRSRP,
+          *ue->QuantityConfig[eNB_index]->quantityConfigEUTRA->filterCoefficientRSRQ,
+          ue->filter_coeff_rsrp,
+          ue->filter_coeff_rsrq);
   }
 
   if (measConfig->s_Measure != NULL) {
-    UE_rrc_inst[ctxt_pP->module_id].s_measure = *measConfig->s_Measure;
+    ue->s_measure = *measConfig->s_Measure;
   }
+  measConfig->s_Measure = NULL;
 
   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 LTE_MeasConfig__speedStatePars));
+    if (ue->speedStatePars) {
+      memcpy((char *)ue->speedStatePars,(char *)measConfig->speedStatePars,sizeof(struct LTE_MeasConfig__speedStatePars));
     } else {
-      UE_rrc_inst[ctxt_pP->module_id].speedStatePars = measConfig->speedStatePars;
+      ue->speedStatePars = measConfig->speedStatePars;
     }
+    measConfig->speedStatePars = NULL;
 
     LOG_I(RRC,"[UE %d] Configuring mobility optimization params for UE %d \n",
-          ctxt_pP->module_id,UE_rrc_inst[ctxt_pP->module_id].Info[0].UE_index);
+          ctxt_pP->module_id,ue->Info[0].UE_index);
   }
 }
 
@@ -1141,6 +1207,7 @@ rrc_ue_process_radioResourceConfigDedicated(
       LOG_I(RRC,"Init physicalConfigDedicated UE_rrc_inst to radioResourceConfigDedicated->physicalConfigDedicated\n");
       UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index] = radioResourceConfigDedicated->physicalConfigDedicated;
     }
+    radioResourceConfigDedicated->physicalConfigDedicated = NULL;
   }
 
   // Apply macMainConfig if present
@@ -1163,6 +1230,7 @@ rrc_ue_process_radioResourceConfigDedicated(
     } else {
       UE_rrc_inst[ctxt_pP->module_id].sps_Config[eNB_index] = radioResourceConfigDedicated->sps_Config;
     }
+    radioResourceConfigDedicated->sps_Config = NULL;
   }
 
   // Establish SRBs if present
@@ -1211,7 +1279,7 @@ rrc_ue_process_radioResourceConfigDedicated(
         } 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]);
-
+          radioResourceConfigDedicated->srb_ToAddModList->list.array[cnt] = NULL;
           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 == LTE_SRB_ToAddMod__logicalChannelConfig_PR_explicitValue) {
               SRB1_logicalChannelConfig = &UE_rrc_inst[ctxt_pP->module_id].SRB1_config[eNB_index]->logicalChannelConfig->choice.explicitValue;
@@ -1259,7 +1327,7 @@ rrc_ue_process_radioResourceConfigDedicated(
         } 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]);
-
+          radioResourceConfigDedicated->srb_ToAddModList->list.array[cnt] = NULL;
           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 == LTE_SRB_ToAddMod__logicalChannelConfig_PR_explicitValue) {
               LOG_I(RRC,"Applying Explicit SRB2 logicalChannelConfig\n");
@@ -1368,6 +1436,7 @@ rrc_ue_process_radioResourceConfigDedicated(
               radioResourceConfigDedicated->drb_ToAddModList->list.array[i]->drb_Identity,
               eNB_index,
               ctxt_pP->module_id);
+        radioResourceConfigDedicated->drb_ToAddModList->list.array[i] = NULL;
         rrc_mac_config_req_ue(ctxt_pP->module_id,0,eNB_index,
                               (LTE_RadioResourceConfigCommonSIB_t *)NULL,
                               UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index],
@@ -1629,6 +1698,101 @@ rrc_ue_process_MBMSCountingRequest(
 }
 
 
+//-----------------------------------------------------------------------------
+void
+rrc_ue_process_nrueCapabilityEnquiry(
+  const protocol_ctxt_t *const ctxt_pP,
+  LTE_UECapabilityEnquiry_t *UECapabilityEnquiry,
+  rrc_nrue_cap_info_t *nrue_cap_info,
+  uint8_t eNB_index
+)
+//-----------------------------------------------------------------------------
+{
+  asn_enc_rval_t enc_rval;
+  uint8_t buffer[RRC_BUF_SIZE];
+  LOG_I(RRC,"[UE %d] Frame %d: Receiving from SRB1 (DL-DCCH), Processing NRUECapabilityEnquiry (eNB %d)\n",
+        ctxt_pP->module_id,
+        ctxt_pP->frame,
+        eNB_index);
+  LTE_UL_DCCH_Message_t ul_dcch_msg;
+  memset(&ul_dcch_msg, 0, sizeof(ul_dcch_msg));
+  LTE_UECapabilityInformation_t *ue_cap = &ul_dcch_msg.message.choice.c1.choice.ueCapabilityInformation;
+  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;
+  ue_cap->rrc_TransactionIdentifier = UECapabilityEnquiry->rrc_TransactionIdentifier;
+
+  NR_UE_CapabilityRAT_Container_t ue_CapabilityRAT_Container;
+  memset(&ue_CapabilityRAT_Container, 0, sizeof(ue_CapabilityRAT_Container));
+  ue_CapabilityRAT_Container.rat_Type = NR_RAT_Type_nr;
+  OCTET_STRING_fromBuf(&ue_CapabilityRAT_Container.ue_CapabilityRAT_Container,
+                       (const char *)nrue_cap_info->mesg,
+                       nrue_cap_info->mesg_len);
+  # if(1) // TODO: The MRDC capabilites should be filled in the NR UE
+  NR_UE_CapabilityRAT_Container_t ue_CapabilityRAT_Container_mrdc;
+  memset(&ue_CapabilityRAT_Container_mrdc, 0, sizeof(ue_CapabilityRAT_Container_mrdc));
+  uint8_t buffer_mrdc[RRC_BUF_SIZE];
+  NR_UE_MRDC_Capability_t *UE_Capability_MRDC = CALLOC(1, sizeof(NR_UE_MRDC_Capability_t));
+  asn_enc_rval_t enc_rval_mrdc = uper_encode_to_buffer(&asn_DEF_NR_UE_MRDC_Capability,
+                                   NULL,
+                                   (void *)UE_Capability_MRDC,
+                                   &buffer_mrdc,
+                                   sizeof(buffer_mrdc));
+  AssertFatal (enc_rval_mrdc.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n",
+               enc_rval_mrdc.failed_type->name, enc_rval_mrdc.encoded);
+  LOG_I(RRC, "[NR_RRC] NRUE MRDC Capability encoded, %ld bytes (%ld bits)\n",
+        (enc_rval_mrdc.encoded + 7) / 8, enc_rval_mrdc.encoded + 7);
+
+  ue_CapabilityRAT_Container_mrdc.rat_Type = NR_RAT_Type_eutra_nr;
+  OCTET_STRING_fromBuf(&ue_CapabilityRAT_Container_mrdc.ue_CapabilityRAT_Container,
+                       (const char *)buffer_mrdc,
+                       (enc_rval_mrdc.encoded + 7) / 8);
+  #endif
+
+  ue_cap->criticalExtensions.present           = LTE_UECapabilityInformation__criticalExtensions_PR_c1;
+  ue_cap->criticalExtensions.choice.c1.present = LTE_UECapabilityInformation__criticalExtensions__c1_PR_ueCapabilityInformation_r8;
+  ue_cap->criticalExtensions.choice.c1.choice.ueCapabilityInformation_r8.ue_CapabilityRAT_ContainerList.list.count = 0;
+  int count = UECapabilityEnquiry->criticalExtensions.choice.c1.choice.ueCapabilityEnquiry_r8.ue_CapabilityRequest.list.count;
+  xer_fprint(stdout, &asn_DEF_NR_UE_CapabilityRAT_Container, (void *)&ue_CapabilityRAT_Container);
+  LTE_UE_CapabilityRequest_t *cap_req = &UECapabilityEnquiry->criticalExtensions.choice.c1.choice.ueCapabilityEnquiry_r8.ue_CapabilityRequest;
+  for (int i = 0; i < count; i++) {
+    enc_rval.encoded = 0;
+    if (*cap_req->list.array[i] == LTE_RAT_Type_nr) {
+        ASN_SEQUENCE_ADD(&ue_cap->criticalExtensions.choice.c1.choice.ueCapabilityInformation_r8.ue_CapabilityRAT_ContainerList.list,
+                         &ue_CapabilityRAT_Container);
+        ue_cap->criticalExtensions.choice.c1.choice.ueCapabilityInformation_r8.ue_CapabilityRAT_ContainerList.list.array[i]->rat_Type = LTE_RAT_Type_nr;
+        asn_enc_rval_t enc_rval_nr = uper_encode_to_buffer(&asn_DEF_LTE_UL_DCCH_Message, NULL, (void *) &ul_dcch_msg, buffer, sizeof(buffer));
+        AssertFatal (enc_rval_nr.encoded > 0, "ASN1 message encoding failed (%s, %jd)!\n",
+                     enc_rval_nr.failed_type->name, enc_rval_nr.encoded);
+        enc_rval.encoded = enc_rval.encoded + enc_rval_nr.encoded;
+        xer_fprint(stdout, &asn_DEF_LTE_UL_DCCH_Message, (void *)&ul_dcch_msg);
+        LOG_A(RRC, "%s: NR_UECapInfo LTE_RAT_Type_nr Encoded %zd bits (%zd bytes)\n",
+              __FUNCTION__, enc_rval.encoded, (enc_rval.encoded+7)/8);
+    }
+    else if (*cap_req->list.array[i] == LTE_RAT_Type_eutra_nr) {
+        ASN_SEQUENCE_ADD(&ue_cap->criticalExtensions.choice.c1.choice.ueCapabilityInformation_r8.ue_CapabilityRAT_ContainerList.list,
+                         &ue_CapabilityRAT_Container_mrdc);
+        ue_cap->criticalExtensions.choice.c1.choice.ueCapabilityInformation_r8.ue_CapabilityRAT_ContainerList.list.array[i]->rat_Type = LTE_RAT_Type_eutra_nr;
+        asn_enc_rval_t enc_rval_eutra_nr = uper_encode_to_buffer(&asn_DEF_LTE_UL_DCCH_Message, NULL, (void *) &ul_dcch_msg, buffer, sizeof(buffer));
+        AssertFatal (enc_rval_eutra_nr.encoded > 0, "ASN1 message encoding failed (%s, %jd)!\n",
+                     enc_rval_eutra_nr.failed_type->name, enc_rval_eutra_nr.encoded);
+        enc_rval.encoded = enc_rval.encoded + enc_rval_eutra_nr.encoded;
+        xer_fprint(stdout, &asn_DEF_LTE_UL_DCCH_Message, (void *)&ul_dcch_msg);
+        LOG_A(RRC, "%s: NR_UECapInfo LTE_RAT_Type_eutra_nr Encoded %zd bits (%zd bytes)\n",
+              __FUNCTION__, 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);
+  }
+}
+
+
+
 //-----------------------------------------------------------------------------
 void
 rrc_ue_process_ueCapabilityEnquiry(
@@ -1686,7 +1850,8 @@ rrc_ue_process_ueCapabilityEnquiry(
         xer_fprint(stdout, &asn_DEF_LTE_UL_DCCH_Message, (void *)&ul_dcch_msg);
       }
 
-      LOG_I(RRC,"UECapabilityInformation Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);
+      LOG_A(RRC, "%s: UECapabilityInformation Encoded %zd bits (%zd bytes)\n",
+            __FUNCTION__, enc_rval.encoded,(enc_rval.encoded+7)/8);
       rrc_data_req_ue (
         ctxt_pP,
         DCCH,
@@ -1696,9 +1861,57 @@ rrc_ue_process_ueCapabilityEnquiry(
         buffer,
         PDCP_TRANSMISSION_MODE_CONTROL);
     }
+    else if (*UECapabilityEnquiry->criticalExtensions.choice.c1.choice.ueCapabilityEnquiry_r8.ue_CapabilityRequest.list.array[i]
+            == LTE_RAT_Type_nr) {
+        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_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);
+
+        if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
+          xer_fprint(stdout, &asn_DEF_LTE_UL_DCCH_Message, (void *)&ul_dcch_msg);
+        }
+
+        LOG_A(RRC, "%s: NR_UECapabilityInformation Encoded %zd bits (%zd bytes)\n",
+              __FUNCTION__, 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);
+        }
   }
 }
 
+static bool is_nr_r15_config_present(LTE_RRCConnectionReconfiguration_r8_IEs_t *c)
+{
+#define NCE nonCriticalExtension
+#define chk(x) do { \
+  if ((x) == NULL) { \
+    LOG_I(RRC, "NULL at %d\n", __LINE__); \
+    return false; \
+  } \
+} while(0)
+  chk(c);
+  chk(c->NCE);
+  chk(c->NCE->NCE);
+  chk(c->NCE->NCE->NCE);
+  chk(c->NCE->NCE->NCE->NCE);
+  chk(c->NCE->NCE->NCE->NCE->NCE);
+  chk(c->NCE->NCE->NCE->NCE->NCE->NCE);
+  chk(c->NCE->NCE->NCE->NCE->NCE->NCE->NCE);
+  chk(c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE);
+  return c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->nr_Config_r15->present ==
+         LTE_RRCConnectionReconfiguration_v1510_IEs__nr_Config_r15_PR_setup;
+
+#undef NCE
+#undef chk
+}
 
 //-----------------------------------------------------------------------------
 void
@@ -1712,53 +1925,89 @@ rrc_ue_process_rrcConnectionReconfiguration(
   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 == LTE_RRCConnectionReconfiguration__criticalExtensions_PR_c1) {
+  if (rrcConnectionReconfiguration->criticalExtensions.present ==
+      LTE_RRCConnectionReconfiguration__criticalExtensions_PR_c1) {
     if (rrcConnectionReconfiguration->criticalExtensions.choice.c1.present ==
         LTE_RRCConnectionReconfiguration__criticalExtensions__c1_PR_rrcConnectionReconfiguration_r8) {
-      LTE_RRCConnectionReconfiguration_r8_IEs_t *rrcConnectionReconfiguration_r8 =
-        &rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8;
+      LTE_RRCConnectionReconfiguration_r8_IEs_t *r_r8 = &rrcConnectionReconfiguration->
+                                                         criticalExtensions.choice.c1.
+                                                         choice.rrcConnectionReconfiguration_r8;
+
+      if (is_nr_r15_config_present(r_r8)) {
+          OCTET_STRING_t *nr_RadioBearer = r_r8->nonCriticalExtension->nonCriticalExtension->
+                                            nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->
+                                            nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->
+                                            nr_RadioBearerConfig1_r15;
+          OCTET_STRING_t *nr_SecondaryCellGroup = r_r8->nonCriticalExtension->nonCriticalExtension->
+                                            nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->
+                                            nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->
+                                            nr_Config_r15->choice.setup.nr_SecondaryCellGroupConfig_r15;
+          uint32_t total_size = nr_RadioBearer->size + nr_SecondaryCellGroup->size;
+          struct msg {
+                uint32_t RadioBearer_size;
+                uint32_t SecondaryCellGroup_size;
+                uint8_t trans_id;
+                uint8_t padding[3];
+                uint8_t buffer[total_size];
+          } msg;
+
+          msg.RadioBearer_size = nr_RadioBearer->size;
+          msg.SecondaryCellGroup_size = nr_SecondaryCellGroup->size;
+          msg.trans_id = rrcConnectionReconfiguration->rrc_TransactionIdentifier;
+          memcpy(msg.buffer, nr_RadioBearer->buf, nr_RadioBearer->size);
+          memcpy(msg.buffer + nr_RadioBearer->size, nr_SecondaryCellGroup->buf, nr_SecondaryCellGroup->size);
+
+          LOG_D(RRC, "nr_RadioBearerConfig1_r15 size %ld nr_SecondaryCellGroupConfig_r15 size %ld, sizeof(msg) = %zu\n",
+                      nr_RadioBearer->size,
+                      nr_SecondaryCellGroup->size,
+                      sizeof(msg));
+
+          nsa_sendmsg_to_nrue(&msg, sizeof(msg), RRC_CONFIG_COMPLETE_REQ);
+          LOG_A(RRC, "Sent RRC_CONFIG_COMPLETE_REQ to the NR UE\n");
+      }
 
-      if (rrcConnectionReconfiguration_r8->mobilityControlInfo) {
+      if (r_r8->mobilityControlInfo) {
         LOG_I(RRC,"Mobility Control Information is present\n");
         rrc_ue_process_mobilityControlInfo(
           ctxt_pP,
           eNB_index,
-          rrcConnectionReconfiguration_r8->mobilityControlInfo);
+          r_r8->mobilityControlInfo);
       }
 
-      if (rrcConnectionReconfiguration_r8->measConfig != NULL) {
+      if (r_r8->measConfig != NULL) {
         LOG_I(RRC,"Measurement Configuration is present\n");
         rrc_ue_process_measConfig(ctxt_pP,
                                   eNB_index,
-                                  rrcConnectionReconfiguration_r8->measConfig);
+                                  r_r8->measConfig);
+        r_r8->measConfig = NULL;
       }
 
-      if (rrcConnectionReconfiguration_r8->radioResourceConfigDedicated) {
+      if (r_r8->radioResourceConfigDedicated) {
         LOG_I(RRC,"Radio Resource Configuration is present\n");
-        rrc_ue_process_radioResourceConfigDedicated(ctxt_pP,eNB_index, rrcConnectionReconfiguration_r8->radioResourceConfigDedicated);
+        rrc_ue_process_radioResourceConfigDedicated(ctxt_pP,
+                                                    eNB_index,
+                                                    r_r8->radioResourceConfigDedicated);
+        r_r8->radioResourceConfigDedicated = NULL;
       }
 
       //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
+      if ((r_r8->nonCriticalExtension != NULL)
+          && (r_r8->nonCriticalExtension->nonCriticalExtension != NULL)
+          && (r_r8->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension != NULL)
+          && (r_r8->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension != NULL)
+          && (r_r8->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension
               != NULL)
-          && (rrcConnectionReconfiguration_r8->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension
-              != NULL)
-          && (rrcConnectionReconfiguration_r8->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->sl_CommConfig_r12
+          && (r_r8->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->sl_CommConfig_r12
               != NULL)) {
-        if (rrcConnectionReconfiguration_r8->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->sl_CommConfig_r12->commTxResources_r12->present !=
+        if (r_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,
+              r_r8->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->sl_CommConfig_r12,
               (LTE_SL_DiscConfig_r12_t *)NULL
                                                      );
         }
@@ -1766,36 +2015,37 @@ rrc_ue_process_rrcConnectionReconfiguration(
 
       /*
             //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 ){
+            if (r_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
+                     r_r8->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->sl_DiscConfig_r12
                      );
             }
       */
 
       /* Check if there is dedicated NAS information to forward to NAS */
-      if (rrcConnectionReconfiguration_r8->dedicatedInfoNASList != NULL) {
+      if (r_r8->dedicatedInfoNASList != NULL) {
         int list_count;
         uint32_t pdu_length;
         uint8_t *pdu_buffer;
         MessageDef *msg_p;
 
-        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;
+        for (list_count = 0; list_count < r_r8->dedicatedInfoNASList->list.count; list_count++) {
+          pdu_length = r_r8->dedicatedInfoNASList->list.array[list_count]->size;
+          pdu_buffer = r_r8->dedicatedInfoNASList->list.array[list_count]->buf;
           msg_p = itti_alloc_new_message(TASK_RRC_UE, 0, 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);
         }
+        LOG_D(RRC, "Sent NAS_CONN_ESTABLI_CNF to NAS layer via itti!\n");
 
-        free (rrcConnectionReconfiguration_r8->dedicatedInfoNASList);
+        free (r_r8->dedicatedInfoNASList);
       }
 
 #if ENABLE_RAL
@@ -1945,6 +2195,7 @@ rrc_ue_decode_dcch(
   const protocol_ctxt_t *const ctxt_pP,
   const rb_id_t                Srb_id,
   const uint8_t         *const Buffer,
+  const uint32_t               Buffer_size,
   const uint8_t                eNB_indexP
 )
 //-----------------------------------------------------------------------------
@@ -1962,11 +2213,18 @@ rrc_ue_decode_dcch(
     return;
   }
 
-  uper_decode(NULL,
+  asn_dec_rval_t dec_rval = uper_decode(NULL,
               &asn_DEF_LTE_DL_DCCH_Message,
               (void **)&dl_dcch_msg,
               (uint8_t *)Buffer,
-              RRC_BUF_SIZE,0,0);
+              Buffer_size, 0, 0);
+
+  if (dec_rval.code != RC_OK && dec_rval.consumed == 0)
+  {
+    LOG_E(RRC, "%s: Failed to decode LTE_DL_DCC_Msg\n", __FUNCTION__);
+    SEQUENCE_free(&asn_DEF_LTE_DL_DCCH_Message, dl_dcch_msg, ASFM_FREE_EVERYTHING);
+    return;
+  }
 
   if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
     xer_fprint(stdout,&asn_DEF_LTE_DL_DCCH_Message,(void *)dl_dcch_msg);
@@ -2055,7 +2313,8 @@ rrc_ue_decode_dcch(
             rrc_ue_generate_RRCConnectionReconfigurationComplete(
               ctxt_pP,
               target_eNB_index,
-              dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.rrc_TransactionIdentifier);
+              dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.rrc_TransactionIdentifier,
+              NULL);
             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",
@@ -2109,7 +2368,8 @@ rrc_ue_decode_dcch(
             rrc_ue_generate_RRCConnectionReconfigurationComplete(
               ctxt_pP,
               eNB_indexP,
-              dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.rrc_TransactionIdentifier);
+              dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.rrc_TransactionIdentifier,
+              NULL);
             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,
@@ -2178,6 +2438,12 @@ rrc_ue_decode_dcch(
             send_ue_information ++;
           }
 
+          UE_RRC_INFO *info = &UE_rrc_inst[ctxt_pP->module_id].Info[eNB_indexP];
+          if (info->dl_dcch_msg != NULL) {
+              SEQUENCE_free(&asn_DEF_LTE_DL_DCCH_Message, info->dl_dcch_msg, ASFM_FREE_EVERYTHING);
+          }
+          info->dl_dcch_msg = dl_dcch_msg;
+          dl_dcch_msg = NULL;
           break;
 
         case LTE_DL_DCCH_MessageType__c1_PR_rrcConnectionRelease:
@@ -2212,10 +2478,53 @@ rrc_ue_decode_dcch(
           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);
+
+          LTE_UE_CapabilityRequest_t *ue_cap = &dl_dcch_msg->message.choice.c1.choice.ueCapabilityEnquiry.criticalExtensions.
+                                                choice.c1.choice.ueCapabilityEnquiry_r8.ue_CapabilityRequest;
+          bool have_received_nrue_cap = false;
+          for (int i = 0; i < ue_cap->list.count; i++) {
+            if (*ue_cap->list.array[i] == LTE_RAT_Type_nr || *ue_cap->list.array[i] == LTE_RAT_Type_eutra_nr) {
+                have_received_nrue_cap = true;
+                break;
+            }
+          }
+          if (have_received_nrue_cap) {
+                LTE_UECapabilityEnquiry_t *ueCapabilityEnquiry_nsa = &dl_dcch_msg->message.choice.c1.choice.ueCapabilityEnquiry;
+                OCTET_STRING_t * requestedFreqBandsNR = ueCapabilityEnquiry_nsa->
+                                      criticalExtensions.choice.c1.choice.ueCapabilityEnquiry_r8.nonCriticalExtension->
+                                      nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->
+                                      nonCriticalExtension->requestedFreqBandsNR_MRDC_r15;
+                nsa_sendmsg_to_nrue(requestedFreqBandsNR->buf, requestedFreqBandsNR->size, NRUE_CAPABILITY_ENQUIRY);
+                LOG_A(RRC, "Second ueCapabilityEnquiry (request for NR capabilities) sent to NR UE with size %zu\n",
+                      requestedFreqBandsNR->size);
+                // Save ueCapabilityEnquiry so we can use in nsa mode after nrUE response is received
+                UE_RRC_INFO *info = &UE_rrc_inst[ctxt_pP->module_id].Info[eNB_indexP];
+                if (info->dl_dcch_msg != NULL) {
+                  info->dl_dcch_msg = NULL;
+                }
+                info->dl_dcch_msg = dl_dcch_msg;
+                dl_dcch_msg = NULL;
+          } else if (get_softmodem_params()->nsa && !have_received_nrue_cap) {
+              LTE_UECapabilityEnquiry_t *ueCapabilityEnquiry_nsa = &dl_dcch_msg->message.choice.c1.choice.ueCapabilityEnquiry;
+              OCTET_STRING_t * requestedFreqBandsNR = ueCapabilityEnquiry_nsa->
+                                    criticalExtensions.choice.c1.choice.ueCapabilityEnquiry_r8.nonCriticalExtension->
+                                    nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->
+                                    nonCriticalExtension->requestedFreqBandsNR_MRDC_r15;
+              nsa_sendmsg_to_nrue(requestedFreqBandsNR->buf, requestedFreqBandsNR->size, UE_CAPABILITY_ENQUIRY);
+              LOG_A(RRC, "Initial ueCapabilityEnquiry sent to NR UE with size %zu\n", requestedFreqBandsNR->size);
+              // Save ueCapabilityEnquiry so we can use in nsa mode after nrUE response is received
+              UE_RRC_INFO *info = &UE_rrc_inst[ctxt_pP->module_id].Info[eNB_indexP];
+              if (info->dl_dcch_msg != NULL) {
+                info->dl_dcch_msg = NULL;
+              }
+              info->dl_dcch_msg = dl_dcch_msg;
+              dl_dcch_msg = NULL;
+          } else {
+            rrc_ue_process_ueCapabilityEnquiry(
+              ctxt_pP,
+              &dl_dcch_msg->message.choice.c1.choice.ueCapabilityEnquiry,
+              eNB_indexP);
+          }
           break;
 
         case LTE_DL_DCCH_MessageType__c1_PR_counterCheck:
@@ -2872,16 +3181,18 @@ int decode_SIB1( const protocol_ctxt_t *const ctxt_pP, const uint8_t eNB_index,
     }
 
     LOG_I( RRC, "PLMN %d MCC %0*d, MNC %0*d\n", i + 1, mccdigits, mcc, mncdigits, mnc);
-    // search internal table for provider name
-    int plmn_ind = 0;
 
-    while (plmn_data[plmn_ind].mcc > 0) {
+    // search internal table for provider name
+    const size_t num_plmn_data = sizeof(plmn_data) / sizeof(plmn_data[0]);
+    for (size_t plmn_ind = 0;; ++plmn_ind) {
+      if (plmn_ind == num_plmn_data) {
+        LOG_E( RRC, "Did not find name from internal table for %u %u\n", mcc, mnc);
+        break;
+      }
       if ((plmn_data[plmn_ind].mcc == mcc) && (plmn_data[plmn_ind].mnc == mnc)) {
         LOG_I( RRC, "Found %s (name from internal table)\n", plmn_data[plmn_ind].oper_short );
         break;
       }
-
-      plmn_ind++;
     }
   }
   LOG_I( RRC, "TAC 0x%04x\n",
@@ -4019,12 +4330,48 @@ 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_nrMeasurementReport(protocol_ctxt_t *const ctxt_pP, uint8_t eNB_index ) {
+  uint8_t buffer[RRC_BUF_SIZE];
+  UE_RRC_INST *ue = &UE_rrc_inst[ctxt_pP->module_id];
+  uint8_t target_eNB_offset = ue->Info[0].handoverTarget;
+  LTE_PhysCellId_t targetCellId = ue->HandoverInfoUe.targetCellId;
+
+  for (int i = 0; i < MAX_MEAS_ID; i++) {
+    if (ue->measReportList[eNB_index][i] != NULL) {
+      LTE_MeasId_t measId = ue->measReportList[eNB_index][i]->measId;
+      long rsrp_s = binary_search_float(RSRP_meas_mapping, 98, ue->rsrp_db_filtered[eNB_index]);
+      long rsrq_s = binary_search_float(RSRQ_meas_mapping, 35, ue->rsrq_db_filtered[eNB_index]);
+      long rsrp_tar = binary_search_float(RSRP_meas_mapping, 98, ue->rsrp_db_filtered[target_eNB_offset]);
+      long rsrq_tar = binary_search_float(RSRQ_meas_mapping, 35, ue->rsrq_db_filtered[target_eNB_offset]);
+
+      LOG_I(RRC,"[UE %d] Frame %d: source eNB: %d target eNB: %d servingCell(%d) targetCell(%ld)\n",
+            ctxt_pP->module_id,
+            ctxt_pP->frame,
+            eNB_index,
+            target_eNB_offset,
+            get_adjacent_cell_id(ctxt_pP->module_id, eNB_index),
+            targetCellId);
+
+      if (ctxt_pP->frame != 0) {
+        LOG_I(RRC, "measId %ld, targetCellId %ld, rsrp_s %ld, rsrq_s %ld, rsrp_t %ld, rsrq_t %ld\n",
+                    measId, targetCellId, rsrp_s, rsrq_s, rsrp_tar, rsrq_tar);
+        ssize_t size = do_nrMeasurementReport(buffer, sizeof(buffer), measId, targetCellId, rsrp_s, rsrq_s, rsrp_tar, rsrq_tar);
+        AssertFatal(size >= 0, "do_nrMeasurementReport failed \n");
+        LOG_I(RRC, "[UE %d] Frame %d : Generating Measurement Report for eNB %d\n",
+              ctxt_pP->module_id, ctxt_pP->frame, eNB_index);
+        int result = pdcp_data_req(ctxt_pP,  SRB_FLAG_YES, DCCH, rrc_mui++, 0, size, buffer, PDCP_TRANSMISSION_MODE_DATA,NULL, NULL);
+        AssertFatal (result == TRUE, "PDCP data request failed!\n");
+      }
+    }
+  }
+}
 
 //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 ) {
-  uint8_t             buffer[32], size;
-  uint8_t             i;
+  uint8_t             buffer[RRC_BUF_SIZE];
   uint8_t             target_eNB_offset;
   LTE_MeasId_t        measId;
   LTE_PhysCellId_t    targetCellId;
@@ -4038,7 +4385,7 @@ void rrc_ue_generate_MeasurementReport(protocol_ctxt_t *const ctxt_pP, uint8_t e
   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
 
-  for (i=0; i<MAX_MEAS_ID; i++) {
+  for (int 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
@@ -4046,7 +4393,7 @@ void rrc_ue_generate_MeasurementReport(protocol_ctxt_t *const ctxt_pP, uint8_t e
       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",
+      LOG_I(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,
             eNB_index,
@@ -4056,7 +4403,7 @@ void rrc_ue_generate_MeasurementReport(protocol_ctxt_t *const ctxt_pP, uint8_t e
             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",
+      LOG_I(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,
             target_eNB_offset,
@@ -4069,7 +4416,7 @@ void rrc_ue_generate_MeasurementReport(protocol_ctxt_t *const ctxt_pP, uint8_t e
 
       if (pframe!=ctxt_pP->frame) {
         pframe=ctxt_pP->frame;
-        LOG_D(RRC, "[UE %d] Frame %ld: doing MeasReport: servingCell(%ld) targetCell(%ld) rsrp_s(%ld) rsrq_s(%ld) rsrp_t(%ld) rsrq_t(%ld) \n",
+        LOG_I(RRC, "[UE %d] Frame %ld: doing MeasReport: servingCell(%ld) targetCell(%ld) rsrp_s(%ld) rsrq_s(%ld) rsrp_t(%ld) rsrq_t(%ld) \n",
               ctxt_pP->module_id,
               (long int)ctxt_pP->frame,
               (long int)get_adjacent_cell_id(ctxt_pP->module_id, eNB_index),
@@ -4078,9 +4425,11 @@ void rrc_ue_generate_MeasurementReport(protocol_ctxt_t *const ctxt_pP, uint8_t e
               (long int)rsrq_s,
               (long int)rsrp_t,
               (long int)rsrq_t);
-        size = do_MeasurementReport(ctxt_pP->module_id, buffer,measId,targetCellId,rsrp_s,rsrq_s,rsrp_t,rsrq_t);
-        LOG_I(RRC, "[UE %d] Frame %d : Generating Measurement Report for eNB %d\n",
-              ctxt_pP->module_id, ctxt_pP->frame, eNB_index);
+        ssize_t size = do_MeasurementReport(ctxt_pP->module_id, buffer, sizeof(buffer),
+                                            measId, targetCellId, rsrp_s, rsrq_s, rsrp_t, rsrq_t);
+        AssertFatal(size >= 0, "do_MeasurementReport failed \n");
+        LOG_I(RRC, "[UE %d] Frame %d : Generating Measurement Report for eNB %d. Size is %zu\n",
+              ctxt_pP->module_id, ctxt_pP->frame, eNB_index, size);
         result = pdcp_data_req(ctxt_pP,  SRB_FLAG_YES, DCCH, rrc_mui++, 0, size, buffer, PDCP_TRANSMISSION_MODE_DATA,NULL, NULL);
         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);
@@ -4092,6 +4441,39 @@ void rrc_ue_generate_MeasurementReport(protocol_ctxt_t *const ctxt_pP, uint8_t e
   }
 }
 
+static bool does_rrcConnReconfig_have_nr(const UE_RRC_INST *ue) {
+  for (int i = 0; i < NB_CNX_UE; i++) {
+    for (int j = 0; j < MAX_MEAS_ID; j++) {
+      LTE_ReportConfigId_t reportConfigId = ue->MeasId[i][j]->reportConfigId;
+      AssertFatal(reportConfigId >= 1 && reportConfigId <= MAX_MEAS_CONFIG, "Bad index\n");
+      const LTE_ReportConfigToAddMod_t *rc = ue->ReportConfig[i][reportConfigId-1];
+      if (rc == NULL) {
+        LOG_D(RRC, "UE_rrc_inst[ctxt_pP->module_id]->ReportConfig[%d][%ld] = NULL\n", i, reportConfigId-1);
+        continue;
+      }
+      if (rc->reportConfig.present != LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigInterRAT) {
+        LOG_D(RRC, "reportConfig.present = %d, not LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigInterRAT\n",
+              rc->reportConfig.present);
+        continue;
+      }
+      LTE_ReportConfigInterRAT_t irat = rc->reportConfig.choice.reportConfigInterRAT;
+      if (irat.triggerType.present != LTE_ReportConfigInterRAT__triggerType_PR_event) {
+        LOG_D(RRC, "irat.triggerType.present = %d, not LTE_ReportConfigInterRAT__triggerType_PR_event\n",
+              irat.triggerType.present);
+        continue;
+      }
+      if (irat.triggerType.choice.event.eventId.present != LTE_ReportConfigInterRAT__triggerType__event__eventId_PR_eventB1_NR_r15) {
+        LOG_D(RRC, "irat.triggerType.choice.event.eventId.present = %d\n",
+              irat.triggerType.choice.event.eventId.present);
+        continue;
+      }
+      return true;
+    }
+  }
+  return false;
+}
+
+
 // 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 ) {
@@ -4105,35 +4487,34 @@ void ue_measurement_report_triggering(protocol_ctxt_t *const ctxt_pP, const uint
   long             a3_offset;
   LTE_MeasObjectId_t   measObjId;
   LTE_ReportConfigId_t reportConfigId;
-
+  UE_RRC_INST *ue = &UE_rrc_inst[ctxt_pP->module_id];
   for(i=0 ; i<NB_CNX_UE ; i++) {
     for(j=0 ; j<MAX_MEAS_ID ; j++) {
-      if(UE_rrc_inst[ctxt_pP->module_id].MeasId[i][j] != NULL) {
-        measObjId = UE_rrc_inst[ctxt_pP->module_id].MeasId[i][j]->measObjectId;
-        reportConfigId = UE_rrc_inst[ctxt_pP->module_id].MeasId[i][j]->reportConfigId;
+      if(ue->MeasId[i][j] != NULL) {
+        measObjId = ue->MeasId[i][j]->measObjectId;
+        reportConfigId = ue->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 == LTE_MeasObjectToAddMod__measObject_PR_measObjectEUTRA) {
+        if(ue->MeasObj[i][measObjId-1] != NULL) {
+          if(ue->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 == LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA) &&
-                (UE_rrc_inst[ctxt_pP->module_id].ReportConfig[i][reportConfigId-1]->reportConfig.choice.reportConfigEUTRA.triggerType.present ==
+            //    LOG_I(RRC,"event %d %d %p \n", measObjId,reportConfigId, ue->ReportConfig[i][reportConfigId-1]);
+            if((ue->ReportConfig[i][reportConfigId-1] != NULL) &&
+                (ue->ReportConfig[i][reportConfigId-1]->reportConfig.present == LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA) &&
+                (ue->ReportConfig[i][reportConfigId-1]->reportConfig.choice.reportConfigEUTRA.triggerType.present ==
                  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
+              hys = ue->ReportConfig[i][reportConfigId-1]->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.hysteresis;
+              ttt_ms = timeToTrigger_ms[ue->ReportConfig[i][reportConfigId
                                         -1]->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.timeToTrigger];
               // Freq specific offset of neighbor cell freq
-              ofn = 5;//((UE_rrc_inst[ctxt_pP->module_id].MeasObj[i][measObjId-1]->measObject.choice.measObjectEUTRA.offsetFreq != NULL) ?
-              // *UE_rrc_inst[ctxt_pP->module_id].MeasObj[i][measObjId-1]->measObject.choice.measObjectEUTRA.offsetFreq : 15); //  /* 15 is the Default */
+              ofn = 5;//((ue->MeasObj[i][measObjId-1]->measObject.choice.measObjectEUTRA.offsetFreq != NULL) ?
+              // *ue->MeasObj[i][measObjId-1]->measObject.choice.measObjectEUTRA.offsetFreq : 15); //  /* 15 is the Default */
               // cellIndividualOffset of neighbor cell - not defined yet
               ocn = 0;
-              a3_offset = UE_rrc_inst[ctxt_pP->module_id].ReportConfig[i][reportConfigId
-                          -1]->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA3.a3_Offset;
+              a3_offset = ue->ReportConfig[i][reportConfigId-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) {
+              switch (ue->ReportConfig[i][reportConfigId-1]->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present) {
                 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);
@@ -4153,28 +4534,25 @@ void ue_measurement_report_triggering(protocol_ctxt_t *const ctxt_pP, const uint
                          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)) {
+                      (ue->Info[0].State >= RRC_CONNECTED) &&
+                      (ue->Info[0].T304_active == 0 )      &&
+                      (ue->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));
+                    if (ue->measReportList[i][j] == NULL) {
+                      ue->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;
+                    ue->measReportList[i][j]->measId = ue->MeasId[i][j]->measId;
+                    ue->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);
+                    ue->HandoverInfoUe.measFlag = 1;
                   } else {
-                    if(UE_rrc_inst[ctxt_pP->module_id].measReportList[i][j] != NULL) {
-                      free(UE_rrc_inst[ctxt_pP->module_id].measReportList[i][j]);
+                    if(ue->measReportList[i][j] != NULL) {
+                      free(ue->measReportList[i][j]);
                     }
-
-                    UE_rrc_inst[ctxt_pP->module_id].measReportList[i][j] = NULL;
+                    ue->measReportList[i][j] = NULL;
                   }
 
                   break;
@@ -4191,11 +4569,54 @@ void ue_measurement_report_triggering(protocol_ctxt_t *const ctxt_pP, const uint
 
                 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);
+                        ue->ReportConfig[i][j]->reportConfig.choice.reportConfigEUTRA.triggerType.present);
                   break;
               }
             }
           }
+
+          if (ue->MeasObj[i][measObjId-1]->measObject.present == LTE_MeasObjectToAddMod__measObject_PR_measObjectNR_r15) {
+            if (!does_rrcConnReconfig_have_nr(ue))
+              break;
+            LTE_ReportConfigInterRAT_t *rc = &ue->ReportConfig[i][reportConfigId-1]->reportConfig.choice.reportConfigInterRAT;
+            LTE_TimeToTrigger_t trig_per = rc->triggerType.choice.event.timeToTrigger;
+            ttt_ms = timeToTrigger_ms[trig_per];
+            LOG_D(RRC, "[UE %d] Frame %d: B1_NR_r15 event. count %d, ttt %ld\n",
+                  ctxt_pP->module_id, ctxt_pP->frame, ue->subframeCount, ttt_ms);
+            if (ue->subframeCount < ttt_ms) {
+              ++ue->subframeCount;
+              break;
+            }
+            ue->subframeCount = 0;
+            bool is_state_connected = false;
+            bool is_t304_inactive = false;
+            bool have_meas_flag = false;
+            if (ue->Info[0].State >= RRC_CONNECTED)
+              is_state_connected = true;
+            if (ue->Info[0].T304_active == 0)
+              is_t304_inactive = true;
+            if (ue->HandoverInfoUe.measFlag == 1)
+              have_meas_flag = true;
+
+            if (is_state_connected && is_t304_inactive && have_meas_flag) {
+              LOG_I(RRC,"[UE %d] Frame %d: Triggering generation of Meas Report for NR_r15. count = %d\n",
+                    ctxt_pP->module_id, ctxt_pP->frame, ue->subframeCount);
+              if (ue->measReportList[i][j] == NULL) {
+                ue->measReportList[i][j] = malloc(sizeof(MEAS_REPORT_LIST));
+              }
+              ue->measReportList[i][j]->measId = ue->MeasId[i][j]->measId;
+              ue->measReportList[i][j]->numberOfReportsSent = 0;
+              rrc_ue_generate_nrMeasurementReport(ctxt_pP, eNB_index);
+              ue->HandoverInfoUe.measFlag = 1;
+              LOG_I(RRC,"[UE %d] Frame %d: RSRB detected, state: %d \n",
+                    ctxt_pP->module_id, ctxt_pP->frame, ue->Info[0].State);
+            } else {
+                if(ue->measReportList[i][j] != NULL) {
+                  free(ue->measReportList[i][j]);
+                }
+                ue->measReportList[i][j] = NULL;
+            }
+          }
         }
       }
     }
@@ -4221,10 +4642,12 @@ uint8_t check_trigger_meas_event(
   uint8_t eNB_offset;
   //  uint8_t currentCellIndex = frame_parms->Nid_cell;
   uint8_t tmp_offset;
-  LOG_D(RRC,"[UE %d] ofn(%ld) ocn(%ld) hys(%ld) ofs(%ld) ocs(%ld) a3_offset(%ld) ttt(%ld) rssi %3.1f\n",
+  LOG_D(RRC,"[UE %d] ofn(%ld) ocn(%ld) hys(%ld) ofs(%ld) ocs(%ld) ttt(%ld) rssi %3.1f\n",
         ue_mod_idP,
-        ofn,ocn,hys,ofs,ocs,a3_offset,ttt,
+        ofn,ocn,hys,ofs,ocs,ttt,
         10*log10(get_RSSI(ue_mod_idP,0))-get_rx_total_gain_dB(ue_mod_idP,0));
+  LOG_D(RRC, "[UE %d] Frame %d: num_adj: %d eNB_idx: %d, NB_eNB_INST: %d\n",
+        ue_mod_idP, frameP, get_n_adj_cells(ue_mod_idP,0), eNB_index, NB_eNB_INST);
 
   for (eNB_offset = 0; eNB_offset<1+get_n_adj_cells(ue_mod_idP,0); eNB_offset++) {
     /* RHS: Verify that idx 0 corresponds to currentCellIndex in rsrp array */
@@ -4447,6 +4870,7 @@ void *rrc_ue_task( void *args_p ) {
     instance = ITTI_MSG_DESTINATION_INSTANCE (msg_p);
     ue_mod_id = UE_INSTANCE_TO_MODULE_ID(instance);
 
+    /* TODO: Add case to handle nr-UE messages we want from nrUE RRC layer */
     switch (ITTI_MSG_ID(msg_p)) {
       case TERMINATE_MESSAGE:
         LOG_W(RRC, " *** Exiting RRC thread\n");
@@ -4566,12 +4990,66 @@ void *rrc_ue_task( void *args_p ) {
           &ctxt,
           RRC_DCCH_DATA_IND (msg_p).dcch_index,
           RRC_DCCH_DATA_IND (msg_p).sdu_p,
+          RRC_DCCH_DATA_IND (msg_p).sdu_size,
           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_COPY_IND:
+      {
+        PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, RRC_DCCH_DATA_COPY_IND (msg_p).module_id,
+                                       ENB_FLAG_NO, RRC_DCCH_DATA_COPY_IND (msg_p).rnti,
+                                       RRC_DCCH_DATA_COPY_IND (msg_p).frame,
+                                       0,
+                                       RRC_DCCH_DATA_COPY_IND (msg_p).eNB_index);
+        LOG_I(RRC, "[UE %d] Received %s. Now calling rrc_ue_process_ueCapabilityEnquiry\n",
+              ue_mod_id, ITTI_MSG_NAME (msg_p));
+        rrc_dcch_data_copy_t *dl_dcch_buffer = (void *)RRC_DCCH_DATA_COPY_IND (msg_p).sdu_p;
+        AssertFatal(RRC_DCCH_DATA_COPY_IND (msg_p).sdu_size == sizeof(*dl_dcch_buffer), "Size of dl_dcch_buffer incorrect\n");
+        rrc_ue_process_ueCapabilityEnquiry(
+              &ctxt,
+              &dl_dcch_buffer->dl_dcch_msg->message.choice.c1.choice.ueCapabilityEnquiry,
+              RRC_DCCH_DATA_COPY_IND (msg_p).eNB_index);
+        SEQUENCE_free(&asn_DEF_LTE_DL_DCCH_Message, dl_dcch_buffer->dl_dcch_msg, ASFM_FREE_EVERYTHING);
+        result = itti_free (ITTI_MSG_ORIGIN_ID(msg_p), RRC_DCCH_DATA_COPY_IND (msg_p).sdu_p);
+        AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
+        break;
+      }
+
+      case RRC_NRUE_CAP_INFO_IND:
+      {
+        PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, RRC_NRUE_CAP_INFO_IND (msg_p).module_id,
+                                       ENB_FLAG_NO, RRC_NRUE_CAP_INFO_IND (msg_p).rnti,
+                                       RRC_NRUE_CAP_INFO_IND (msg_p).frame,
+                                       0,
+                                       RRC_NRUE_CAP_INFO_IND (msg_p).eNB_index);
+        LOG_I(RRC, "[UE %d] Received %s. Now calling rrc_ue_process_nrueCapabilityEnquiry\n",
+              ue_mod_id, ITTI_MSG_NAME (msg_p));
+        rrc_nrue_cap_info_t *nrue_cap_info = (void *)RRC_NRUE_CAP_INFO_IND (msg_p).sdu_p;
+        AssertFatal(RRC_NRUE_CAP_INFO_IND (msg_p).sdu_size == sizeof(*nrue_cap_info), "Size of nrue_cap_info incorrect\n");
+        rrc_ue_process_nrueCapabilityEnquiry(
+              &ctxt,
+              &nrue_cap_info->dl_dcch_msg->message.choice.c1.choice.ueCapabilityEnquiry,
+              nrue_cap_info,
+              RRC_NRUE_CAP_INFO_IND (msg_p).eNB_index);
+        SEQUENCE_free(&asn_DEF_LTE_DL_DCCH_Message, nrue_cap_info->dl_dcch_msg, ASFM_FREE_EVERYTHING);
+        result = itti_free (ITTI_MSG_ORIGIN_ID(msg_p), RRC_NRUE_CAP_INFO_IND (msg_p).sdu_p);
+        AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
+        break;
+      }
+      case NAS_OAI_TUN_NSA:
+      {
+        LOG_D(NAS, "Received %s: length %lu. About to send this to the NR UE\n", ITTI_MSG_NAME (msg_p),
+              sizeof(NAS_OAI_TUN_NSA (msg_p).buffer));
+        char buffer[RRC_BUF_SIZE];
+        memcpy(buffer, NAS_OAI_TUN_NSA(msg_p).buffer, sizeof(buffer));
+        nsa_sendmsg_to_nrue(buffer, sizeof(buffer), OAI_TUN_IFACE_NSA);
+        break;
+      }
+
+
       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 = "
@@ -4900,7 +5378,8 @@ openair_rrc_top_init_ue(
     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);
+    bool received_nr_msg = false;
+    UECap = fill_ue_capability (uecap_xer, received_nr_msg);
 
     for (module_id = 0; module_id < NB_UE_INST; module_id++) {
       UE_rrc_inst[module_id].UECap = UECap;
@@ -5191,9 +5670,6 @@ void rrc_control_socket_init() {
 
 //--------------------------------------------------------
 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;
@@ -5212,20 +5688,28 @@ void *rrc_control_socket_thread_fct(void *arg) {
   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);
+    char receive_buf[MAX_MESSAGE_SIZE];
+    memset(receive_buf, 0, sizeof(receive_buf));
+    socklen_t prose_addr_len = sizeof(prose_app_addr);
+    n = recvfrom(ctrl_sock_fd, receive_buf, sizeof(receive_buf), MSG_TRUNC,
+                 (struct sockaddr *) &prose_app_addr, &prose_addr_len);
 
     if (n < 0) {
       LOG_E(RRC, "ERROR: Failed to receive from ProSe App\n");
       exit(EXIT_FAILURE);
     }
+    if (n == 0) {
+      LOG_E(RRC, "%s(%d). EOF for ctrl_sock_fd\n", __FUNCTION__, __LINE__);
+    }
+    if (n > MAX_MESSAGE_SIZE) {
+      LOG_E(RRC, "%s(%d). Message truncated. %d\n", __FUNCTION__, __LINE__, 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
     //sl_ctrl_msg_recv = (struct sidelink_ctrl_element *) receive_buf;
@@ -5233,6 +5717,7 @@ void *rrc_control_socket_thread_fct(void *arg) {
     memcpy((void *)sl_ctrl_msg_recv, (void *)receive_buf, sizeof(struct sidelink_ctrl_element));
 
     //process the message
+    char send_buf[MAX_MESSAGE_SIZE];
     switch (sl_ctrl_msg_recv->type) {
       case SESSION_INIT_REQ:
         if (LOG_DEBUGFLAG(DEBUG_CTRLSOCKET)) {
@@ -5241,14 +5726,14 @@ void *rrc_control_socket_thread_fct(void *arg) {
 
         //TODO: get SL_UE_STATE from lower layer
         LOG_I(RRC,"Send UEStateInformation to ProSe App \n");
-        memset(send_buf, 0, BUFSIZE);
+        memset(send_buf, 0, MAX_MESSAGE_SIZE);
         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);
+        n = sendto(ctrl_sock_fd, (char *)send_buf, sizeof(struct sidelink_ctrl_element), 0,
+                   (struct sockaddr *)&prose_app_addr, sizeof(prose_app_addr));
 
         if (n < 0) {
           LOG_E(RRC, "ERROR: Failed to send to ProSe App\n");
@@ -5394,14 +5879,14 @@ void *rrc_control_socket_thread_fct(void *arg) {
                               (LTE_MBSFN_AreaInfoList_r9_t *)NULL
                              );
         LOG_I(RRC,"Send GroupCommunicationEstablishResp to ProSe App\n");
-        memset(send_buf, 0, BUFSIZE);
+        memset(send_buf, 0, MAX_MESSAGE_SIZE);
         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);
+        n = sendto(ctrl_sock_fd, (char *)send_buf, sizeof(struct sidelink_ctrl_element), 0,
+                   (struct sockaddr *)&prose_app_addr, sizeof(prose_app_addr));
 
         if (n < 0) {
           LOG_E(RRC, "ERROR: Failed to send to ProSe App\n");
@@ -5455,7 +5940,7 @@ void *rrc_control_socket_thread_fct(void *arg) {
                               (LTE_MBSFN_AreaInfoList_r9_t *)NULL
                              );
         LOG_I(RRC,"Send GroupCommunicationReleaseResponse to ProSe App \n");
-        memset(send_buf, 0, BUFSIZE);
+        memset(send_buf, 0, MAX_MESSAGE_SIZE);
         sl_ctrl_msg_send = calloc(1, sizeof(struct sidelink_ctrl_element));
         sl_ctrl_msg_send->type = GROUP_COMMUNICATION_RELEASE_RSP;
 
@@ -5469,8 +5954,8 @@ void *rrc_control_socket_thread_fct(void *arg) {
 
         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);
+        n = sendto(ctrl_sock_fd, (char *)send_buf, sizeof(struct sidelink_ctrl_element), 0,
+                   (struct sockaddr *)&prose_app_addr, sizeof(prose_app_addr));
 
         if (n < 0) {
           LOG_E(RRC, "ERROR: Failed to send to ProSe App\n");
@@ -5598,14 +6083,14 @@ void *rrc_control_socket_thread_fct(void *arg) {
                               (LTE_MBSFN_AreaInfoList_r9_t *)NULL
                              );
         LOG_I(RRC,"Send DirectCommunicationEstablishResp to ProSe App\n");
-        memset(send_buf, 0, BUFSIZE);
+        memset(send_buf, 0, MAX_MESSAGE_SIZE);
         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);
+        n = sendto(ctrl_sock_fd, (char *)send_buf, sizeof(struct sidelink_ctrl_element), 0,
+                   (struct sockaddr *)&prose_app_addr, sizeof(prose_app_addr));
 
         if (n < 0) {
           LOG_E(RRC, "ERROR: Failed to send to ProSe App\n");
@@ -5785,15 +6270,15 @@ void *rrc_control_socket_thread_fct(void *arg) {
         }
 
         LOG_I(RRC,"Send PC5EstablishRsp to ProSe App\n");
-        memset(send_buf, 0, BUFSIZE);
+        memset(send_buf, 0, MAX_MESSAGE_SIZE);
         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);
+        n = sendto(ctrl_sock_fd, (char *)send_buf, sizeof(struct sidelink_ctrl_element), 0,
+                   (struct sockaddr *)&prose_app_addr, sizeof(prose_app_addr));
 
         //         free(sl_ctrl_msg_send);
         if (n < 0) {
@@ -5833,27 +6318,24 @@ int decode_SL_Discovery_Message(
   const uint8_t                eNB_index,
   const uint8_t               *Sdu,
   const uint8_t                Sdu_len) {
-  int prose_addr_len;
-  char send_buf[BUFSIZE];
+  char send_buf[MAX_MESSAGE_SIZE];
   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);
+  memset(send_buf, 0, MAX_MESSAGE_SIZE);
   //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);
+  n = sendto(ctrl_sock_fd, (char *)send_buf, sizeof(struct sidelink_ctrl_element), 0,
+             (struct sockaddr *)&prose_app_addr, sizeof(prose_app_addr));
 
   if (n < 0) {
     // TODO:  We should not just exit if the Prose App has not yet attached.  It creates a race condition.
@@ -5977,3 +6459,235 @@ rrc_rx_tx_ue(
   return (RRC_OK);
 }
 
+void *recv_msgs_from_nr_ue(void *args_p)
+{
+    itti_mark_task_ready (TASK_RRC_NSA_UE);
+    for (;;)
+    {
+        nsa_msg_t msg;
+        int recvLen = recvfrom(from_nr_ue_fd, &msg, sizeof(msg),
+                               MSG_WAITALL | MSG_TRUNC, NULL, NULL);
+        if (recvLen == -1)
+        {
+            LOG_E(RRC, "%s: recvfrom: %s\n", __func__, strerror(errno));
+            continue;
+        }
+        if (recvLen > sizeof(msg))
+        {
+            LOG_E(NR_RRC, "%s: Received a truncated message %d\n", __func__, recvLen);
+            continue;
+        }
+        LOG_D(RRC, "We have received a %d msg (%d bytes). Calling process_nr_nsa_msg\n", msg.msg_type, recvLen);
+        process_nr_nsa_msg(&msg, recvLen);
+    }
+
+}
+
+void nsa_sendmsg_to_nrue(const void *message, size_t msg_len, Rrc_Msg_Type_t msg_type)
+{
+    LOG_I(RRC, "Entered %s \n", __FUNCTION__);
+    nsa_msg_t n_msg;
+    if (msg_len > sizeof(n_msg.msg_buffer))
+    {
+        LOG_E(RRC, "%s: message too big: %zu\n", __func__, msg_len);
+        abort();
+    }
+    n_msg.msg_type = msg_type;
+    memcpy(n_msg.msg_buffer, message, msg_len);
+    size_t to_send = sizeof(n_msg.msg_type) + msg_len;
+
+    struct sockaddr_in sa =
+    {
+        .sin_family = AF_INET,
+        .sin_port = htons(6008 + ue_id_g * 2),
+    };
+    int sent = sendto(to_nr_ue_fd, &n_msg, to_send, 0,
+                      (struct sockaddr *)&sa, sizeof(sa));
+    if (sent == -1)
+    {
+        LOG_E(RRC, "%s: sendto: %s\n", __func__, strerror(errno));
+        return;
+    }
+    if (sent != to_send)
+    {
+        LOG_E(RRC, "%s: Short send %d != %zu\n", __func__, sent, to_send);
+        return;
+    }
+    LOG_I(RRC, "Sent a %d message to the nrUE (%d bytes) \n", msg_type, sent);
+}
+
+void init_connections_with_nr_ue()
+{
+    struct sockaddr_in sa =
+    {
+        .sin_family = AF_INET,
+        .sin_port = htons(6007 + ue_id_g * 2),
+    };
+    AssertFatal(from_nr_ue_fd == -1, "from_nr_ue_fd was assigned already");
+    from_nr_ue_fd = socket(AF_INET, SOCK_DGRAM, 0);
+    if (from_nr_ue_fd == -1)
+    {
+        LOG_E(RRC, "%s: Error opening socket %d (%d:%s)\n", __FUNCTION__, from_nr_ue_fd, errno, strerror(errno));
+        abort();
+    }
+
+    if (inet_aton(nsa_ipaddr, &sa.sin_addr) == 0)
+    {
+        LOG_E(RRC, "Bad nsa_ipaddr '%s'\n", nsa_ipaddr);
+        abort();
+    }
+
+    if (bind(from_nr_ue_fd, (struct sockaddr *) &sa, sizeof(sa)) == -1)
+    {
+        LOG_E(RRC,"%s: Failed to bind the socket\n", __FUNCTION__);
+        abort();
+    }
+
+    AssertFatal(to_nr_ue_fd == -1, "to_nr_ue_fd was assigned already");
+    to_nr_ue_fd = socket(AF_INET, SOCK_DGRAM, 0);
+    if (to_nr_ue_fd == -1)
+    {
+        LOG_E(RRC, "%s: Error opening socket %d (%d:%s)\n", __FUNCTION__, to_nr_ue_fd, errno, strerror(errno));
+        abort();
+    }
+
+}
+
+void process_nr_nsa_msg(nsa_msg_t *msg, int msg_len)
+{
+    if (msg_len < sizeof(msg->msg_type))
+    {
+        LOG_E(RRC, "Msg_len = %d\n", msg_len);
+        return;
+    }
+    LOG_D(RRC, "We are processing an NSA message %d \n", msg->msg_type);
+    Rrc_Msg_Type_t msg_type = msg->msg_type;
+    uint8_t *const msg_buffer = msg->msg_buffer;
+    msg_len -= sizeof(msg->msg_type);
+    bool received_nr_msg = true;
+    protocol_ctxt_t ctxt;
+    module_id_t module_id = 0;
+    eNB_index_t eNB_index = 0;
+
+    switch (msg_type)
+    {
+        case NRUE_CAPABILITY_INFO:
+        {
+            LOG_I(RRC, "Create itti msg to send received NRUE_CAPABILITY_INFO to eNB\n");
+
+            MessageDef *message_p;
+            rrc_nrue_cap_info_t *nrue_cap_buf = itti_malloc (TASK_RRC_NSA_UE,
+                                                             TASK_RRC_UE,
+                                                             sizeof(rrc_nrue_cap_info_t));
+            AssertFatal(msg_len <= sizeof(nrue_cap_buf->mesg), "msg_len = %d\n", msg_len);
+            memcpy(nrue_cap_buf->mesg, msg_buffer, msg_len);
+            nrue_cap_buf->mesg_len = msg_len;
+            UE_RRC_INFO *info = &UE_rrc_inst[module_id].Info[eNB_index];
+            nrue_cap_buf->dl_dcch_msg = info->dl_dcch_msg;
+            info->dl_dcch_msg = NULL;
+            message_p = itti_alloc_new_message (TASK_RRC_UE, 0, RRC_NRUE_CAP_INFO_IND);
+            RRC_NRUE_CAP_INFO_IND (message_p).sdu_p = (void *)nrue_cap_buf;
+            RRC_NRUE_CAP_INFO_IND (message_p).sdu_size = sizeof(*nrue_cap_buf);
+            RRC_NRUE_CAP_INFO_IND (message_p).module_id = module_id;
+            RRC_NRUE_CAP_INFO_IND (message_p).rnti = info->rnti;
+            RRC_NRUE_CAP_INFO_IND (message_p).eNB_index = eNB_index;
+            itti_send_msg_to_task (TASK_RRC_UE, 0, message_p);
+            LOG_I(RRC, "Sent itti RRC_NRUE_CAP_INFO_IND\n");
+            break;
+        }
+        case UE_CAPABILITY_DUMMY:
+        {
+            fill_ue_capability(NULL, received_nr_msg);
+            UE_rrc_inst[module_id].UECap = UE_rrc_inst->UECap;
+            UE_rrc_inst[module_id].UECapability = UE_rrc_inst->UECap->sdu;
+            UE_rrc_inst[module_id].UECapability_size = UE_rrc_inst->UECap->sdu_size;
+
+            if (!is_en_dc_supported(UE_rrc_inst->UECap->UE_EUTRA_Capability))
+            {
+              LOG_E(RRC, "en_dc is NOT supported! Not sending RRC_DCCH_DATA_COPY_IND to update UE_Capability_INFO\n");
+              break;
+            }
+
+            LOG_I(RRC, "Send itti msg to trigger processing of capabilites b/c we have a UE_CAPABILITY_DUMMY\n");
+            MessageDef *message_p;
+            rrc_dcch_data_copy_t *dl_dcch_buffer = itti_malloc (TASK_RRC_NSA_UE,
+                                                                TASK_RRC_UE,
+                                                                sizeof(rrc_dcch_data_copy_t));
+            UE_RRC_INFO *info = &UE_rrc_inst[module_id].Info[eNB_index];
+            dl_dcch_buffer->dl_dcch_msg = info->dl_dcch_msg;
+            info->dl_dcch_msg = NULL;
+            message_p = itti_alloc_new_message (TASK_RRC_UE, 0, RRC_DCCH_DATA_COPY_IND);
+            RRC_DCCH_DATA_COPY_IND (message_p).sdu_p = (void *)dl_dcch_buffer;
+            RRC_DCCH_DATA_COPY_IND (message_p).sdu_size = sizeof(rrc_dcch_data_copy_t);
+            RRC_DCCH_DATA_COPY_IND (message_p).module_id = module_id;
+            RRC_DCCH_DATA_COPY_IND (message_p).rnti = info->rnti;
+            RRC_DCCH_DATA_COPY_IND (message_p).eNB_index = eNB_index;
+            itti_send_msg_to_task (TASK_RRC_UE, 0, message_p);
+            LOG_I(RRC, "Sent itti RRC_DCCH_DATA_COPY_IND\n");
+            break;
+        }
+
+        case NR_UE_RRC_MEASUREMENT:
+        {
+            nfapi_p7_message_header_t header;
+            if (nfapi_p7_message_header_unpack((void *)msg_buffer, msg_len, &header, sizeof(header), NULL) < 0)
+            {
+                LOG_E(MAC, "Header unpack failed in %s \n", __FUNCTION__);
+                break;
+            }
+            if (header.message_id != NFAPI_NR_PHY_MSG_TYPE_DL_TTI_REQUEST)
+            {
+                LOG_E(MAC, "%s: Unexpected nfapi message type: %d\n", __FUNCTION__, header.message_id);
+                break;
+            }
+
+            nfapi_nr_dl_tti_request_t dl_tti_request;
+            int unpack_len = nfapi_nr_p7_message_unpack((void *)msg_buffer,
+                                                         msg_len,
+                                                         &dl_tti_request,
+                                                         sizeof(nfapi_nr_dl_tti_request_t),
+                                                         NULL);
+            if (unpack_len < 0)
+            {
+                LOG_E(RRC, "%s: SSB PDU unpack failed \n", __FUNCTION__);
+                break;
+            }
+            int num_pdus = dl_tti_request.dl_tti_request_body.nPDUs;
+            if (num_pdus <= 0)
+            {
+                LOG_E(RRC, "%s: dl_tti_request number of PDUS <= 0\n", __FUNCTION__);
+                abort();
+            }
+            for (int i = 0; i < num_pdus; i++)
+            {
+                nfapi_nr_dl_tti_request_pdu_t *pdu_list = &dl_tti_request.dl_tti_request_body.dl_tti_pdu_list[i];
+                if (pdu_list->PDUType == NFAPI_NR_DL_TTI_SSB_PDU_TYPE)
+                {
+                    LOG_I(RRC, "Got an NR_UE_RRC_MEASUREMENT. pdulist[%d].ssbRsrp = %d\n",
+                         i, pdu_list->ssb_pdu.ssb_pdu_rel15.ssbRsrp);
+                }
+            }
+            break;
+        }
+
+        case NR_RRC_CONFIG_COMPLETE_REQ:
+        {
+            LOG_I(RRC, "Got an NR_RRC_CONFIG_COMPLETE_REQ. Now make octet string and call below!\n");
+            OCTET_STRING_t rrcConfigurationComplete;
+            memset(&rrcConfigurationComplete, 0, sizeof(rrcConfigurationComplete));
+            OCTET_STRING_fromBuf(&rrcConfigurationComplete,
+                                (const char *)msg_buffer,
+                                msg_len);
+            UE_RRC_INFO *info = &UE_rrc_inst[module_id].Info[eNB_index];
+            uint8_t t_id = info->dl_dcch_msg->message.choice.c1.choice.
+                           rrcConnectionReconfiguration.rrc_TransactionIdentifier;
+            PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, module_id,
+                                           ENB_FLAG_NO, info->rnti,
+                                           0, 0, eNB_index);
+            rrc_ue_generate_RRCConnectionReconfigurationComplete(&ctxt, ctxt.eNB_index, t_id, &rrcConfigurationComplete);
+            break;
+        }
+        default:
+            LOG_E(RRC, "No NSA Message Found\n");
+    }
+}
diff --git a/openair2/RRC/LTE/rrc_UE_ral.c b/openair2/RRC/LTE/rrc_UE_ral.c
deleted file mode 100644
index 1ebba43d8b276ba04cb78a4def9288434406e5e9..0000000000000000000000000000000000000000
--- a/openair2/RRC/LTE/rrc_UE_ral.c
+++ /dev/null
@@ -1,238 +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_UE_ral.c
- * \brief rrc procedures for handling RAL messages
- * \author Lionel GAUTHIER
- * \date 2013
- * \version 1.0
- * \company Eurecom
- * \email: lionel.gauthier@eurecom.fr
- */
-#define RRC_UE
-#define RRC_UE_RAL_C
-//-----------------------------------------------------------------------------
-#include "rrc_UE_ral.h"
-#include "assertions.h"
-#include "collection/hashtable/obj_hashtable.h"
-#include "RRC/LTE/defs.h"
-#include "RRC/LTE/extern.h"
-
-
-//-----------------------------------------------------------------------------
-int rrc_ue_ral_delete_all_thresholds_type(unsigned int mod_idP, ral_link_param_type_t *param_type_pP)
-//-----------------------------------------------------------------------------
-{
-  hashtable_rc_t           rc;
-  rrc_ral_threshold_key_t *key;
-  rrc_ral_threshold_key_t *keys = NULL;
-  unsigned int             num_keys = 0;
-  int                      return_code = 0;
-  rc =  obj_hashtable_get_keys(UE_rrc_inst[mod_idP].ral_meas_thresholds, (void *)&keys, &num_keys);
-
-  if (rc == HASH_TABLE_OK) {
-    key = keys;
-
-    while (num_keys > 0) {
-      if (memcmp(&key->link_param_type, param_type_pP, sizeof(ral_link_param_type_t)) == 0) {
-        rc = obj_hashtable_remove (UE_rrc_inst[mod_idP].ral_meas_thresholds, key, sizeof(rrc_ral_threshold_key_t));
-
-        if (rc != HASH_TABLE_OK) {
-          return_code = -1;
-        }
-      }
-
-      key = &key[1];
-      num_keys--;
-    }
-  } else {
-    return_code = -1;
-  }
-
-  if (keys != NULL) {
-    free(keys);
-  }
-
-  return return_code;
-}
-
-
-//-----------------------------------------------------------------------------
-int rrc_ue_ral_delete_threshold(unsigned int mod_idP, ral_link_param_type_t *param_type_pP, ral_threshold_t *threshold_pP)
-//-----------------------------------------------------------------------------
-{
-  hashtable_rc_t           rc;
-  rrc_ral_threshold_key_t  ref_key;
-  memcpy(&ref_key.link_param_type, param_type_pP, sizeof(ral_link_param_type_t));
-  memcpy(&ref_key.threshold,       threshold_pP,  sizeof(ral_threshold_t));
-  rc = obj_hashtable_remove (UE_rrc_inst[mod_idP].ral_meas_thresholds, (void *)&ref_key, sizeof(rrc_ral_threshold_key_t));
-
-  if (rc == HASH_TABLE_OK) {
-    return 0;
-  } else {
-    return -1;
-  }
-}
-
-
-//-----------------------------------------------------------------------------
-int rrc_ue_ral_handle_configure_threshold_request(unsigned int mod_idP, MessageDef *msg_pP)
-//-----------------------------------------------------------------------------
-{
-  ral_transaction_id_t               transaction_id            = 0;
-  rrc_ral_configure_threshold_req_t *configure_threshold_req_p = NULL;
-  ral_link_cfg_param_t              *link_cfg_param_p          = NULL;
-  ral_threshold_t                   *threshold_p               = NULL;
-  MessageDef                        *message_p                 = NULL;
-  unsigned int                       ix_param                  = 0;
-  unsigned int                       ix_thresholds             = 0;
-  DevAssert(msg_pP != NULL);
-  LOG_I(RRC, "[UE %d] Received %s\n", mod_idP, ITTI_MSG_NAME (msg_pP));
-  configure_threshold_req_p = &RRC_RAL_CONFIGURE_THRESHOLD_REQ(msg_pP);
-  transaction_id = configure_threshold_req_p->transaction_id;
-
-  for (ix_param = 0; ix_param < configure_threshold_req_p->num_link_cfg_params; ix_param++) {
-    link_cfg_param_p = &configure_threshold_req_p->link_cfg_params[ix_param];
-
-    switch (link_cfg_param_p->th_action) {
-      case RAL_TH_ACTION_SET_NORMAL_THRESHOLD:
-      case RAL_TH_ACTION_SET_ONE_SHOT_THRESHOLD:
-        switch (link_cfg_param_p->link_param_type.choice) {
-          case RAL_LINK_PARAM_TYPE_CHOICE_GEN:
-            switch (link_cfg_param_p->link_param_type._union.link_param_gen) {
-              case RAL_LINK_PARAM_GEN_DATA_RATE:
-              case RAL_LINK_PARAM_GEN_SIGNAL_STRENGTH:
-              case RAL_LINK_PARAM_GEN_SINR:
-              case RAL_LINK_PARAM_GEN_THROUGHPUT:
-              case RAL_LINK_PARAM_GEN_PACKET_ERROR_RATE:
-                message_p = itti_alloc_new_message (TASK_RRC_UE, PHY_MEAS_THRESHOLD_REQ);
-                PHY_MEAS_THRESHOLD_REQ(message_p).transaction_id  = transaction_id;
-                memcpy (&PHY_MEAS_THRESHOLD_REQ(message_p).cfg_param, (void *) link_cfg_param_p, sizeof(ral_link_cfg_param_t));
-                itti_send_msg_to_task (TASK_PHY_UE, ITTI_MSG_DESTINATION_INSTANCE(msg_pP), message_p);
-                break;
-
-              default:
-                LOG_E(RRC, "Message RRC_RAL_CONFIGURE_THRESHOLD_REQ malformed, unknown link_param_gen %d\n", link_cfg_param_p->link_param_type._union.link_param_gen);
-                return -1;
-            }
-
-            break;
-
-          case RAL_LINK_PARAM_TYPE_CHOICE_QOS:
-            switch (link_cfg_param_p->link_param_type._union.link_param_qos) {
-              case RAL_LINK_PARAM_QOS_MAX_NUM_DIF_COS_SUPPORTED:
-              case RAL_LINK_PARAM_QOS_MIN_PACKET_TRANSFER_DELAY_ALL_COS:
-              case RAL_LINK_PARAM_QOS_AVG_PACKET_TRANSFER_DELAY_ALL_COS:
-              case RAL_LINK_PARAM_QOS_MAX_PACKET_TRANSFER_DELAY_ALL_COS:
-              case RAL_LINK_PARAM_QOS_STD_DEVIATION_PACKET_TRANSFER_DELAY:
-              case RAL_LINK_PARAM_QOS_PACKET_LOSS_RATE_ALL_COS_FRAME_RATIO:
-                message_p = itti_alloc_new_message (TASK_RRC_UE, PHY_MEAS_THRESHOLD_REQ);
-                PHY_MEAS_THRESHOLD_REQ(message_p).transaction_id  = transaction_id;
-                memcpy (&PHY_MEAS_THRESHOLD_REQ(message_p).cfg_param, (void *) link_cfg_param_p, sizeof(ral_link_cfg_param_t));
-                itti_send_msg_to_task (TASK_MAC_UE, ITTI_MSG_DESTINATION_INSTANCE(msg_pP), message_p);
-                break;
-
-              default:
-                LOG_E(RRC, "Message RRC_RAL_CONFIGURE_THRESHOLD_REQ malformed, unknown link_param_qos %d\n", link_cfg_param_p->link_param_type._union.link_param_qos);
-                return -1;
-            }
-
-            break;
-
-          case RAL_LINK_PARAM_TYPE_CHOICE_LTE:
-            switch (link_cfg_param_p->link_param_type._union.link_param_lte) {
-              // group by dest task id
-              case RAL_LINK_PARAM_LTE_UE_RSRP:
-              case RAL_LINK_PARAM_LTE_UE_RSRQ:
-              case RAL_LINK_PARAM_LTE_UE_CQI:
-                message_p = itti_alloc_new_message (TASK_RRC_UE, PHY_MEAS_THRESHOLD_REQ);
-                PHY_MEAS_THRESHOLD_REQ(message_p).transaction_id  = transaction_id;
-                memcpy (&PHY_MEAS_THRESHOLD_REQ(message_p).cfg_param, (void *) link_cfg_param_p, sizeof(ral_link_cfg_param_t));
-                itti_send_msg_to_task (TASK_PHY_UE, ITTI_MSG_DESTINATION_INSTANCE(msg_pP), message_p);
-                break;
-
-              case RAL_LINK_PARAM_LTE_AVAILABLE_BW:
-              case RAL_LINK_PARAM_LTE_PACKET_LOSS_RATE:
-              case RAL_LINK_PARAM_LTE_L2_BUFFER_STATUS:
-              case RAL_LINK_PARAM_LTE_PACKET_DELAY:
-                message_p = itti_alloc_new_message (TASK_RRC_UE, PHY_MEAS_THRESHOLD_REQ);
-                PHY_MEAS_THRESHOLD_REQ(message_p).transaction_id  = transaction_id;
-                memcpy (&PHY_MEAS_THRESHOLD_REQ(message_p).cfg_param, (void *) link_cfg_param_p, sizeof(ral_link_cfg_param_t));
-                itti_send_msg_to_task (TASK_MAC_UE, ITTI_MSG_DESTINATION_INSTANCE(msg_pP), message_p);
-                break;
-
-              case RAL_LINK_PARAM_LTE_MOBILE_NODE_CAPABILITIES:
-              case RAL_LINK_PARAM_LTE_EMBMS_CAPABILITY:
-              case RAL_LINK_PARAM_LTE_JUMBO_FEASIBILITY:
-              case RAL_LINK_PARAM_LTE_JUMBO_SETUP_STATUS:
-              case RAL_LINK_PARAM_LTE_NUM_ACTIVE_EMBMS_RECEIVERS_PER_FLOW:
-#warning "TO DO MIH LTE LINK PARAMS IN RRC UE"
-                break;
-
-              default:
-                LOG_E(RRC, "Message RRC_RAL_CONFIGURE_THRESHOLD_REQ malformed, unknown link_param_lte %d\n", link_cfg_param_p->link_param_type._union.link_param_lte);
-                return -1;
-            }
-
-            break;
-
-          default:
-            LOG_E(RRC, "Message RRC_RAL_CONFIGURE_THRESHOLD_REQ malformed, unknown link_param_type choice %d\n", link_cfg_param_p->link_param_type.choice);
-            return -1;
-        }
-
-        for (ix_thresholds=0; ix_thresholds < link_cfg_param_p->num_thresholds; ix_thresholds++) {
-          threshold_p = &link_cfg_param_p->thresholds[ix_thresholds];
-        }
-
-        break;
-
-      case RAL_TH_ACTION_CANCEL_THRESHOLD:
-
-        // IEEE Std 802.21-2008, Table F4, Data type name=LINK_CFG_PARAM (page 228):
-        // When “Cancel threshold” is selected and no thresholds are specified, then all
-        // currently configured thresholds for the given LINK_PARAM_TYPE are cancelled.
-        if (link_cfg_param_p->num_thresholds == 0) {
-          rrc_ue_ral_delete_all_thresholds_type(mod_idP, &link_cfg_param_p->link_param_type);
-        } else {
-          //
-          // When “Cancel threshold” is selected and thresholds are specified only those
-          // configured thresholds for the given LINK_PARAM_TYPE and whose threshold value match what was
-          // specified are cancelled.
-          for (ix_thresholds=0; ix_thresholds < link_cfg_param_p->num_thresholds; ix_thresholds++) {
-            threshold_p = &link_cfg_param_p->thresholds[ix_thresholds];
-            rrc_ue_ral_delete_threshold(mod_idP, &link_cfg_param_p->link_param_type, threshold_p);
-          }
-        }
-
-        LOG_E(RRC, "Message RRC_RAL_CONFIGURE_THRESHOLD_REQ with RAL_TH_ACTION_CANCEL_THRESHOLD\n");
-        break;
-
-      default:
-        LOG_E(RRC, "Message RRC_RAL_CONFIGURE_THRESHOLD_REQ malformed, unknown th_action %d\n", link_cfg_param_p->th_action);
-        return -1;
-    }
-  }
-
-  return 0;
-}
-
-
diff --git a/openair2/RRC/LTE/rrc_defs.h b/openair2/RRC/LTE/rrc_defs.h
index 40aad67a06be702dbb1bc71b03d6845f8fca925d..f537dcbbd2bc8f6312da98955a10e855e7fb7c8b 100644
--- a/openair2/RRC/LTE/rrc_defs.h
+++ b/openair2/RRC/LTE/rrc_defs.h
@@ -52,7 +52,7 @@
 
 //for D2D
 #define DEBUG_CTRL_SOCKET
-#define BUFSIZE                1024
+
 #define CONTROL_SOCKET_PORT_NO 8888
 #define MAX_NUM_DEST           10
 //netlink
@@ -311,12 +311,12 @@ typedef enum SL_TRIGGER_e {
 #define RRM_CALLOC(t,n)   (t *) malloc16( sizeof(t) * n)
 #define RRM_CALLOC2(t,s)  (t *) malloc16( s )
 
-#define MAX_MEAS_OBJ 6
-#define MAX_MEAS_CONFIG 6
-#define MAX_MEAS_ID 6
+#define MAX_MEAS_OBJ 7
+#define MAX_MEAS_CONFIG 7
+#define MAX_MEAS_ID 7
 
 #define PAYLOAD_SIZE_MAX 1024
-#define RRC_BUF_SIZE 8192
+#define RRC_BUF_SIZE 512
 #define UNDEF_SECURITY_MODE 0xff
 #define NO_SECURITY_MODE 0x20
 
@@ -363,6 +363,7 @@ typedef struct UE_RRC_INFO_s {
   uint32_t N310_cnt;
   uint32_t N311_cnt;
   rnti_t   rnti;
+  struct LTE_DL_DCCH_Message *dl_dcch_msg;
 } __attribute__ ((__packed__)) UE_RRC_INFO;
 
 typedef struct UE_S_TMSI_s {
@@ -916,6 +917,7 @@ typedef struct UE_RRC_INST_s {
   float                           rsrq_db[7];
   float                           rsrp_db_filtered[7];
   float                           rsrq_db_filtered[7];
+  int                             subframeCount;
   /* KeNB as computed from parameters within USIM card */
   uint8_t kenb[32];
   uint8_t nh[32];
diff --git a/openair2/RRC/LTE/rrc_eNB.c b/openair2/RRC/LTE/rrc_eNB.c
index 9283b64ded28281919b1a9e2f1f51b7f5a6ee64d..260b6fceaa69a4d4539a9518b8f077472fd3ba5f 100644
--- a/openair2/RRC/LTE/rrc_eNB.c
+++ b/openair2/RRC/LTE/rrc_eNB.c
@@ -90,6 +90,7 @@
 #include <openair3/ocp-gtpu/gtp_itf.h>
 
 #include "intertask_interface.h"
+#include "softmodem-common.h"
 
 #if ENABLE_RAL
   #include "rrc_eNB_ral.h"
@@ -100,7 +101,6 @@
 #define ASN_MAX_ENCODE_SIZE 4096
 #define NUMBEROF_DRBS_TOBE_ADDED 1
 static int encode_CG_ConfigInfo(char *buffer,int buffer_size,rrc_eNB_ue_context_t *const ue_context_pP,int *enc_size);
-static int is_en_dc_supported(LTE_UE_EUTRA_Capability_t *c);
 
 extern RAN_CONTEXT_t RC;
 
@@ -152,7 +152,7 @@ init_SI(
   LOG_D(RRC,"%s()\n\n\n\n",__FUNCTION__);
 
   if(configuration->radioresourceconfig[CC_id].mbms_dedicated_serving_cell == TRUE) {
-    LOG_I(RRC, "Configuring MIB FeMBMS (N_RB_DL %d)\n",
+    LOG_A(RRC, "Configuring MIB FeMBMS (N_RB_DL %d)\n",
           (int)configuration->N_RB_DL[CC_id]);
     RC.rrc[ctxt_pP->module_id]->carrier[CC_id].MIB_FeMBMS = (uint8_t *) malloc16(4);
     do_MIB_FeMBMS(&RC.rrc[ctxt_pP->module_id]->carrier[CC_id],
@@ -253,7 +253,7 @@ init_SI(
     carrier->N_RB_DL         = configuration->N_RB_DL[CC_id];
     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]);
-    LOG_I(RRC, "Configuring MIB (N_RB_DL %d,phich_Resource %d,phich_Duration %d)\n",
+    LOG_A(RRC, "Configuring MIB (N_RB_DL %d,phich_Resource %d,phich_Duration %d)\n",
           (int)configuration->N_RB_DL[CC_id],
           (int)configuration->radioresourceconfig[CC_id].phich_resource,
           (int)configuration->radioresourceconfig[CC_id].phich_duration);
@@ -538,6 +538,7 @@ init_MCCH(
     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],
+        32, /* TODO: what is the actual size of .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",
@@ -1196,7 +1197,7 @@ rrc_eNB_process_RRCConnectionSetupComplete(
 )
 //-----------------------------------------------------------------------------
 {
-  LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel UL-DCCH, " "processing LTE_RRCConnectionSetupComplete from UE (SRB1 Active)\n",
+  LOG_A(RRC, 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.StatusRrc = RRC_CONNECTED;
@@ -1224,13 +1225,14 @@ rrc_eNB_generate_SecurityModeCommand(
 )
 //-----------------------------------------------------------------------------
 {
-  uint8_t                             buffer[100];
+  uint8_t                             buffer[100]={0};
   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,
+           sizeof(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);
@@ -1285,6 +1287,7 @@ rrc_eNB_generate_UECapabilityEnquiry(
   size = do_UECapabilityEnquiry(
            ctxt_pP,
            buffer,
+           sizeof(buffer),
            rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),
            eutra_band,
            nr_band);
@@ -1335,10 +1338,11 @@ rrc_eNB_generate_NR_UECapabilityEnquiry(
   size = do_NR_UECapabilityEnquiry(
            ctxt_pP,
            buffer,
+           sizeof(buffer),
            rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),
            eutra_band,
            nr_band);
-  LOG_I(RRC,
+  LOG_A(RRC,
         PROTOCOL_RRC_CTXT_UE_FMT" Logical Channel DL-DCCH, Generate NR UECapabilityEnquiry (bytes %d)\n",
         PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
         size);
@@ -2001,9 +2005,10 @@ rrc_eNB_process_RRCConnectionReestablishmentComplete(
   measurements_enabled = RC.rrc[ENB_INSTANCE_TO_MODULE_ID(ctxt_pP->instance)]->configuration.enable_x2 ||
                          RC.rrc[ENB_INSTANCE_TO_MODULE_ID(ctxt_pP->instance)]->configuration.enable_measurement_reports;
   // send LTE_RRCConnectionReconfiguration
-  memset(buffer, 0, RRC_BUF_SIZE);
+  memset(buffer, 0, sizeof(buffer));
   size = do_RRCConnectionReconfiguration(ctxt_pP,
                                          buffer,
+                                         sizeof(buffer),
                                          next_xid,   //Transaction_id,
                                          (LTE_SRB_ToAddModList_t *)*SRB_configList2, // SRB_configList
                                          (LTE_DRB_ToAddModList_t *)DRB_configList,
@@ -2196,10 +2201,9 @@ rrc_eNB_generate_RRCConnectionRelease(
 )
 //-----------------------------------------------------------------------------
 {
-  uint8_t buffer[RRC_BUF_SIZE];
+  uint8_t buffer[RRC_BUF_SIZE]={0};
   uint16_t size = 0;
   int release_num;
-  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));
 #if 0
@@ -2211,7 +2215,8 @@ rrc_eNB_generate_RRCConnectionRelease(
   }
 
 #endif
-  size = do_RRCConnectionRelease(ctxt_pP->module_id, buffer,rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id));
+  size = do_RRCConnectionRelease(ctxt_pP->module_id, buffer, sizeof(buffer),
+                                 rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id));
   ue_context_pP->ue_context.ue_reestablishment_timer = 0;
   ue_context_pP->ue_context.ue_release_timer = 0;
   ue_context_pP->ue_context.ue_rrc_inactivity_timer = 0;
@@ -2487,9 +2492,10 @@ rrc_eNB_generate_dedicatedRRCConnectionReconfiguration(const protocol_ctxt_t *co
     LOG_W(RRC,"dedlicated NAS list is empty\n");
   }
 
-  memset(buffer, 0, RRC_BUF_SIZE);
+  memset(buffer, 0, sizeof(buffer));
   size = do_RRCConnectionReconfiguration(ctxt_pP,
                                          buffer,
+                                         sizeof(buffer),
                                          xid,
                                          (LTE_SRB_ToAddModList_t *)NULL,
                                          (LTE_DRB_ToAddModList_t *)*DRB_configList2,
@@ -2734,9 +2740,9 @@ rrc_eNB_modify_dedicatedRRCConnectionReconfiguration(const protocol_ctxt_t *cons
     LOG_W(RRC,"dedlicated NAS list is empty\n");
   }
 
-  memset(buffer, 0, RRC_BUF_SIZE);
+  memset(buffer, 0, sizeof(buffer));
   size = do_RRCConnectionReconfiguration(ctxt_pP,
-                                         buffer,
+                                         buffer, sizeof(buffer),
                                          xid,
                                          (LTE_SRB_ToAddModList_t *)NULL,
                                          (LTE_DRB_ToAddModList_t *)DRB_configList2,
@@ -2835,9 +2841,10 @@ rrc_eNB_generate_dedicatedRRCConnectionReconfiguration_release(  const protocol_
     LOG_W(RRC,"dedlicated NAS list is empty\n");
   }
 
-  memset(buffer, 0, RRC_BUF_SIZE);
+  memset(buffer, 0, sizeof(buffer));
   size = do_RRCConnectionReconfiguration(ctxt_pP,
                                          buffer,
+                                         sizeof(buffer),
                                          xid,
                                          NULL,
                                          NULL,
@@ -3465,6 +3472,7 @@ void rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt_t
     ReportConfig_NR->reportConfig.choice.reportConfigInterRAT.ext7->reportQuantityCellNR_r15->ss_rsrq = TRUE;
     ReportConfig_NR->reportConfig.choice.reportConfigInterRAT.ext7->reportQuantityCellNR_r15->ss_sinr = TRUE;
     ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_NR);
+    LOG_A(RRC, "Generating RRCCConnectionReconfigurationRequest (NRUE Measurement Report Request).\n");
   }
 
   //  LTE_RRCConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->reportConfigToAddModList = ReportConfig_list;
@@ -3545,9 +3553,10 @@ void rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt_t
 
   measurements_enabled = RC.rrc[ENB_INSTANCE_TO_MODULE_ID(ctxt_pP->instance)]->configuration.enable_x2 ||
                          RC.rrc[ENB_INSTANCE_TO_MODULE_ID(ctxt_pP->instance)]->configuration.enable_measurement_reports;
-  memset(buffer, 0, RRC_BUF_SIZE);
+  memset(buffer, 0, sizeof(buffer));
   size = do_RRCConnectionReconfiguration(ctxt_pP,
                                          buffer,
+                                         sizeof(buffer),
                                          xid, // Transaction_id,
                                          (LTE_SRB_ToAddModList_t *) *SRB_configList2, // SRB_configList
                                          (LTE_DRB_ToAddModList_t *) *DRB_configList,
@@ -4257,9 +4266,10 @@ flexran_rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt
 
   measurements_enabled = RC.rrc[ENB_INSTANCE_TO_MODULE_ID(ctxt_pP->instance)]->configuration.enable_x2 ||
                          RC.rrc[ENB_INSTANCE_TO_MODULE_ID(ctxt_pP->instance)]->configuration.enable_measurement_reports;
-  memset(buffer, 0, RRC_BUF_SIZE);
+  memset(buffer, 0, sizeof(buffer));
   size = do_RRCConnectionReconfiguration(ctxt_pP,
                                          buffer,
+                                         sizeof(buffer),
                                          xid, // Transaction_id,
                                          (LTE_SRB_ToAddModList_t *) *SRB_configList2, // SRB_configList
                                          (LTE_DRB_ToAddModList_t *) *DRB_configList,
@@ -4357,6 +4367,7 @@ rrc_eNB_generate_RRCConnectionReconfiguration_SCell(
 
   size = do_RRCConnectionReconfiguration(ctxt_pP,
                                          buffer,
+                                         sizeof(buffer),
                                          rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),//Transaction_id,
                                          (LTE_SRB_ToAddModList_t *)NULL,
                                          (LTE_DRB_ToAddModList_t *)NULL,
@@ -4421,7 +4432,6 @@ static int encode_CG_ConfigInfo(
   struct NR_CG_ConfigInfo *cg_configinfo = NULL;
   struct NR_RadioBearerConfig *rb_config = NULL;
   asn_enc_rval_t enc_rval;
-  int RRC_OK = 1;
   char temp_buff[ASN_MAX_ENCODE_SIZE];
   NR_UE_CapabilityRAT_ContainerList_t *ue_cap_rat_container_list = NULL;
   NR_UE_CapabilityRAT_Container_t *ue_cap_rat_container_MRDC = NULL;
@@ -4441,7 +4451,6 @@ static int encode_CG_ConfigInfo(
     = calloc(1,sizeof(struct NR_CG_ConfigInfo_IEs));
   AssertFatal(cg_configinfo->criticalExtensions.choice.c1->choice.cg_ConfigInfo != NULL,
               "failed to allocate memory for cg_configinfo_IEs");
-
   if(ue_context_pP->ue_context.UE_Capability_MRDC) {
     RAT_Container_count++;
     enc_rval = uper_encode_to_buffer(&asn_DEF_NR_UE_MRDC_Capability,NULL,
@@ -4611,6 +4620,7 @@ rrc_eNB_process_MeasurementReport(
           //= measResults2->measResultNeighCells->choice.measResultNeighCellListNR_r15.list.array[0]->pci_r15;
           = measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[0]->physCellId;
 
+        X2AP_ENDC_SGNB_ADDITION_REQ(msg).target_physCellId = 0;
         //For the moment we have a single E-RAB which will be the one to be added to the gNB
         //Not sure how to select bearers to be added if there are multiple.
         X2AP_ENDC_SGNB_ADDITION_REQ(msg).nb_e_rabs_tobeadded = 1;
@@ -4624,7 +4634,7 @@ rrc_eNB_process_MeasurementReport(
                  sizeof(transport_layer_addr_t));
         }
 
-        LOG_I(RRC,
+        LOG_A(RRC,
               "[eNB %d] frame %d subframe %d: UE rnti %x switching to NSA mode\n",
               ctxt_pP->module_id, ctxt_pP->frame, ctxt_pP->subframe, ctxt_pP->rnti);
         itti_send_msg_to_task(TASK_X2AP, ENB_MODULE_ID_TO_INSTANCE(ctxt_pP->module_id), msg);
@@ -4668,6 +4678,10 @@ rrc_eNB_process_MeasurementReport(
     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));
     }
+    if (!ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array) {
+        ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array =
+        calloc(neighboring_cells, sizeof(*ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array));
+    }
 
     for (i=0; i < neighboring_cells; i++) {
       if (i>=ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.count) {
@@ -4677,6 +4691,11 @@ rrc_eNB_process_MeasurementReport(
 
       ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->physCellId =
         measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->physCellId;
+
+      if (!ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->measResult.rsrpResult)
+        ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->measResult.rsrpResult = calloc(1, sizeof(*ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->measResult.rsrpResult));
+      if (!ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->measResult.rsrqResult)
+        ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->measResult.rsrqResult = calloc(1, sizeof(*ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->measResult.rsrqResult));
       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 =
@@ -4973,19 +4992,17 @@ void rrc_eNB_handover_ue_context_release(
   struct rrc_eNB_ue_context_s *ue_context_p) {
   int e_rab = 0;
   //MessageDef *msg_release_p = NULL;
-  MessageDef *msg_delete_tunnels_p = NULL;
   uint32_t eNB_ue_s1ap_id = ue_context_p->ue_context.eNB_ue_s1ap_id;
   //msg_release_p = itti_alloc_new_message(TASK_RRC_ENB, 0, S1AP_UE_CONTEXT_RELEASE);
   //itti_send_msg_to_task(TASK_S1AP, ctxt_pP->module_id, msg_release_p);
   s1ap_ue_context_release(ctxt_pP->instance, ue_context_p->ue_context.eNB_ue_s1ap_id);
   //MSC_LOG_TX_MESSAGE(MSC_RRC_ENB, MSC_GTPU_ENB, NULL,0, "0 GTPV1U_ENB_DELETE_TUNNEL_REQ rnti %x ", eNB_ue_s1ap_id);
-  msg_delete_tunnels_p = itti_alloc_new_message(TASK_RRC_ENB, 0, 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;
-  GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p).from_gnb = 0;
+  gtpv1u_enb_delete_tunnel_req_t delete_tunnels={0};
+  delete_tunnels.rnti = ue_context_p->ue_context.rnti;
+  delete_tunnels.from_gnb = 0;
 
   for (e_rab = 0; e_rab < ue_context_p->ue_context.nb_of_e_rabs; e_rab++) {
-    GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p).eps_bearer_id[GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p).num_erab++] =
+    delete_tunnels.eps_bearer_id[delete_tunnels.num_erab++] =
       ue_context_p->ue_context.enb_gtp_ebi[e_rab];
     // erase data
     ue_context_p->ue_context.enb_gtp_teid[e_rab] = 0;
@@ -4993,7 +5010,7 @@ void rrc_eNB_handover_ue_context_release(
     ue_context_p->ue_context.enb_gtp_ebi[e_rab] = 0;
   }
 
-  itti_send_msg_to_task(TASK_VARIABLE, ctxt_pP->module_id, msg_delete_tunnels_p);
+  gtpv1u_delete_s1u_tunnel(ctxt_pP->module_id, &delete_tunnels);
   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, eNB_ue_s1ap_id);
 
@@ -5144,7 +5161,9 @@ check_handovers(
         // Configure target
         ue_context_p->ue_context.handover_info->state = HO_FORWARDING;
         msg = itti_alloc_new_message(TASK_RRC_ENB, 0, X2AP_HANDOVER_REQ_ACK);
-        rrc_eNB_generate_HO_RRCConnectionReconfiguration(ctxt_pP, ue_context_p, X2AP_HANDOVER_REQ_ACK(msg).rrc_buffer,
+        rrc_eNB_generate_HO_RRCConnectionReconfiguration(ctxt_pP, ue_context_p,
+            X2AP_HANDOVER_REQ_ACK(msg).rrc_buffer,
+            sizeof(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);
         X2AP_HANDOVER_REQ_ACK(msg).rnti = ue_context_p->ue_context.rnti;
@@ -5306,6 +5325,7 @@ 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,
+    size_t                 buffer_size,
     int                    *_size
     //const uint8_t        ho_state
                                                 )
@@ -6247,11 +6267,12 @@ rrc_eNB_generate_HO_RRCConnectionReconfiguration(const protocol_ctxt_t *const ct
 
   measurements_enabled = RC.rrc[ENB_INSTANCE_TO_MODULE_ID(ctxt_pP->instance)]->configuration.enable_x2 ||
                          RC.rrc[ENB_INSTANCE_TO_MODULE_ID(ctxt_pP->instance)]->configuration.enable_measurement_reports;
-  memset(buffer, 0, RRC_BUF_SIZE);
+  memset(buffer, 0, buffer_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,
+             sizeof(rrc_buf),
              xid,   //Transaction_id,
              NULL, // SRB_configList
              NULL,
@@ -6287,7 +6308,7 @@ rrc_eNB_generate_HO_RRCConnectionReconfiguration(const protocol_ctxt_t *const ct
   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 */,
+              ho_buf, buffer_size,
               rrc_buf,
               rrc_size);
   *_size = size = ho_size;
@@ -7791,47 +7812,6 @@ is_ul_256QAM_supported(
          && *c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->rf_Parameters_v1430->supportedBandCombination_v1430->list.array[0]->bandParameterList_v1430->list.array[0]->ul_256QAM_r14==LTE_BandParameters_v1430__ul_256QAM_r14_supported;
 }
 
-static int
-is_en_dc_supported(
-  LTE_UE_EUTRA_Capability_t *c
-)
-//-----------------------------------------------------------------------------
-{
-  /* to be refined - check that the bands supported by the UE include
-   * the band of the gNB
-   */
-  return c != NULL  // R8
-         && c->NCE != NULL // R92
-         && c->NCE->NCE != NULL // R94
-         && c->NCE->NCE->NCE != NULL // R102
-         && c->NCE->NCE->NCE->NCE != NULL // R106
-         && c->NCE->NCE->NCE->NCE->NCE != NULL // R109
-         && c->NCE->NCE->NCE->NCE->NCE->NCE != NULL // R113
-         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE != NULL // R117
-         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE != NULL // R118
-         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE != NULL // R11a
-         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE != NULL // R125
-         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE != NULL // R126
-         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE != NULL // 127
-         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE != NULL // 128
-         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE != NULL //131
-         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE != NULL //132
-         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE != NULL //133
-         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE != NULL //134
-         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE != NULL //135
-         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE != NULL //136
-         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE != NULL //143
-         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE != NULL //144
-         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE != NULL //145
-         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE != NULL //146
-         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE != NULL //151
-         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->irat_ParametersNR_r15 != NULL
-         && c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->irat_ParametersNR_r15->en_DC_r15 != NULL
-         && *c->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->NCE->irat_ParametersNR_r15->en_DC_r15 ==
-         LTE_IRAT_ParametersNR_r15__en_DC_r15_supported;
-#undef NCE
-}
-
 int to_nr_rsrpq(long rsrpq_result,int nr_band) {
 
     switch(nr_band) {
@@ -7886,7 +7866,6 @@ rrc_eNB_decode_dcch(
   LTE_UL_DCCH_Message_t               *ul_dcch_msg = NULL; //&uldcchmsg;
   int i;
   struct rrc_eNB_ue_context_s        *ue_context_p = NULL;
-  MessageDef                         *msg_delete_tunnels_p = NULL;
   uint8_t                             xid;
   int dedicated_DRB=0;
   T(T_ENB_RRC_UL_DCCH_DATA_IN, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
@@ -7902,7 +7881,6 @@ rrc_eNB_decode_dcch(
           Srb_id);
   }
 
-  //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(
@@ -7994,7 +7972,7 @@ rrc_eNB_decode_dcch(
           /*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.*/
           int flexran_agent_handover = 0;
 
-          if (EPC_MODE_ENABLED) {
+          if (EPC_MODE_ENABLED || get_softmodem_params()->emulate_l1) {
             if (ue_context_p->ue_context.StatusRrc == RRC_RECONFIGURED) {
               dedicated_DRB = 1;
               LOG_I(RRC,
@@ -8067,6 +8045,7 @@ rrc_eNB_decode_dcch(
                             rrc_eNB_send_E_RAB_Modification_Indication(ctxt_pP, ue_context_p);
                             /* send reconfiguration complete to gNB */
                             rrc_eNB_process_reconfiguration_complete_endc(ctxt_pP, ue_context_p);
+                            LOG_A(RRC, "Sent rrcReconfigurationComplete to gNB\n");
                           }
                         }
                       }
@@ -8124,21 +8103,19 @@ rrc_eNB_decode_dcch(
               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, 0, 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;
-              GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p).from_gnb = 0;
+              gtpv1u_enb_delete_tunnel_req_t delete_tunnels={0};
+              delete_tunnels.rnti = ue_context_p->ue_context.rnti;
+              delete_tunnels.from_gnb = 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];
+                  delete_tunnels.eps_bearer_id[delete_tunnels.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);
+	      gtpv1u_delete_s1u_tunnel(ctxt_pP->instance, &delete_tunnels);
               //S1AP_E_RAB_RELEASE_RESPONSE
               rrc_eNB_send_S1AP_E_RAB_RELEASE_RESPONSE(ctxt_pP,
                   ue_context_p,
@@ -8430,12 +8407,13 @@ rrc_eNB_decode_dcch(
           xer_fprint(stdout, &asn_DEF_LTE_UL_DCCH_Message, (void *)ul_dcch_msg);
         }
 
-        LOG_I(RRC, "got UE capabilities for UE %x\n", ctxt_pP->rnti);
+        LOG_A(RRC, "got UE capabilities for UE %x\n", ctxt_pP->rnti);
         int eutra_index = -1;
 
         for (i = 0; i < ul_dcch_msg->message.choice.c1.choice.ueCapabilityInformation.criticalExtensions.choice.c1.choice.ueCapabilityInformation_r8.ue_CapabilityRAT_ContainerList.list.count; i++) {
           if (ul_dcch_msg->message.choice.c1.choice.ueCapabilityInformation.criticalExtensions.choice.c1.choice.ueCapabilityInformation_r8.ue_CapabilityRAT_ContainerList.list.array[i]->rat_Type ==
               LTE_RAT_Type_nr) {
+              LOG_A(RRC, "got nrUE capabilities for UE %x\n", ctxt_pP->rnti);
             if(ue_context_p->ue_context.UE_Capability_nr) {
               ASN_STRUCT_FREE(asn_DEF_NR_UE_NR_Capability,ue_context_p->ue_context.UE_Capability_nr);
               ue_context_p->ue_context.UE_Capability_nr = 0;
@@ -8541,7 +8519,13 @@ rrc_eNB_decode_dcch(
         if (dec_rval.code == RC_OK) {
           /* do NR only if at least one gNB connected */
           if (RC.rrc[ctxt_pP->module_id]->num_gnb_cells != 0)
+          {
+            allocate_en_DC_r15(ue_context_p->ue_context.UE_Capability);
+            if (!is_en_dc_supported(ue_context_p->ue_context.UE_Capability)){
+                    LOG_E(RRC, "We did not properly allocate en_DC_r15 for UE_EUTRA_Capability\n");
+            }
             ue_context_p->ue_context.does_nr = is_en_dc_supported(ue_context_p->ue_context.UE_Capability);
+          }
           else
             ue_context_p->ue_context.does_nr = 0;
         }
@@ -8767,9 +8751,9 @@ void handle_f1_setup_req(f1ap_setup_req_t *f1_setup_req) {
     for (int j=0; j<RC.nb_inst; j++) {
       eNB_RRC_INST *rrc = RC.rrc[j];
 
-      if (rrc->configuration.mcc[0] == f1_setup_req->mcc[i] &&
-          rrc->configuration.mnc[0] == f1_setup_req->mnc[i] &&
-          rrc->nr_cellid == f1_setup_req->nr_cellid[i]) {
+      if (rrc->configuration.mcc[0] == f1_setup_req->cell[i].mcc &&
+          rrc->configuration.mnc[0] == f1_setup_req->cell[i].mnc &&
+          rrc->nr_cellid == f1_setup_req->cell[i].nr_cellid) {
         // check that CU rrc instance corresponds to mcc/mnc/cgi (normally cgi should be enough, but just in case)
         rrc->carrier[0].MIB = malloc(f1_setup_req->mib_length[i]);
         rrc->carrier[0].sizeof_MIB = f1_setup_req->mib_length[i];
@@ -8809,7 +8793,7 @@ void handle_f1_setup_req(f1ap_setup_req_t *f1_setup_req) {
         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];
+        rrc->carrier[0].physCellId = f1_setup_req->cell[i].nr_pci;
         // prepare F1_SETUP_RESPONSE
 
         if (msg_p == NULL) {
@@ -8821,7 +8805,7 @@ void handle_f1_setup_req(f1ap_setup_req_t *f1_setup_req) {
         F1AP_SETUP_RESP (msg_p).cells_to_activate[cu_cell_ind].mnc                           = rrc->configuration.mnc[0];
         F1AP_SETUP_RESP (msg_p).cells_to_activate[cu_cell_ind].mnc_digit_length              = rrc->configuration.mnc_digit_length[0];
         F1AP_SETUP_RESP (msg_p).cells_to_activate[cu_cell_ind].nr_cellid                     = rrc->nr_cellid;
-        F1AP_SETUP_RESP (msg_p).cells_to_activate[cu_cell_ind].nrpci                         = f1_setup_req->nr_pci[i];
+        F1AP_SETUP_RESP (msg_p).cells_to_activate[cu_cell_ind].nrpci                         = f1_setup_req->cell[i].nr_pci;
         int num_SI= 0;
         if (rrc->carrier[0].SIB23) {
           F1AP_SETUP_RESP (msg_p).cells_to_activate[cu_cell_ind].SI_container[2+num_SI]        = rrc->carrier[0].SIB23;
@@ -8842,7 +8826,7 @@ void handle_f1_setup_req(f1ap_setup_req_t *f1_setup_req) {
         break;
       } else {// setup_req mcc/mnc match rrc internal list element
         LOG_W(RRC,"[Inst %d] No matching MCC/MNC: rrc->mcc/f1_setup_req->mcc %d/%d rrc->mnc/f1_setup_req->mnc %d/%d \n",
-              j, rrc->configuration.mcc[0], f1_setup_req->mcc[i],rrc->configuration.mnc[0], f1_setup_req->mnc[i]);
+              j, rrc->configuration.mcc[0], f1_setup_req->cell[i].mcc,rrc->configuration.mnc[0], f1_setup_req->cell[i].mnc);
       }
     }// for (int j=0;j<RC.nb_inst;j++)
 
@@ -10053,7 +10037,7 @@ rrc_eNB_generate_RRCConnectionReconfiguration_Sidelink(
 {
   uint8_t                             buffer[RRC_BUF_SIZE];
   uint16_t                            size = 0;
-  memset(buffer, 0, RRC_BUF_SIZE);
+  memset(buffer, 0, sizeof(buffer));
 
   // allocate dedicated pools for UE -sl-CommConfig/sl-DiscConfig (sl-V2X-ConfigDedicated)
   //populate dedicated resources for SL communication (sl-CommConfig)
@@ -10066,6 +10050,7 @@ rrc_eNB_generate_RRCConnectionReconfiguration_Sidelink(
     sl_CommConfig[0] = rrc_eNB_get_sidelink_commTXPool(ctxt_pP, ue_context_pP, destinationInfoList);
     size = do_RRCConnectionReconfiguration(ctxt_pP,
                                            buffer,
+                                           sizeof(buffer),
                                            rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),   //Transaction_id
                                            (LTE_SRB_ToAddModList_t *)NULL,
                                            (LTE_DRB_ToAddModList_t *)NULL,
@@ -10088,6 +10073,7 @@ rrc_eNB_generate_RRCConnectionReconfiguration_Sidelink(
     sl_DiscConfig[0] = rrc_eNB_get_sidelink_discTXPool(ctxt_pP, ue_context_pP, n_discoveryMessages );
     size = do_RRCConnectionReconfiguration(ctxt_pP,
                                            buffer,
+                                           sizeof(buffer),
                                            rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),   //Transaction_id
                                            (LTE_SRB_ToAddModList_t *)NULL,
                                            (LTE_DRB_ToAddModList_t *)NULL,
diff --git a/openair2/RRC/LTE/rrc_eNB_GTPV1U.c b/openair2/RRC/LTE/rrc_eNB_GTPV1U.c
index a6af6a4163a7f941e49ba89079b541799a6d1dc2..3fa17bcd6bdba76cee9054bd8af09e7c09eac88d 100644
--- a/openair2/RRC/LTE/rrc_eNB_GTPV1U.c
+++ b/openair2/RRC/LTE/rrc_eNB_GTPV1U.c
@@ -261,23 +261,33 @@ boolean_t gtpv_data_req_new (
 
 void rrc_eNB_send_GTPV1U_ENB_DELETE_TUNNEL_REQ(
   module_id_t enb_mod_idP,
-  const rrc_eNB_ue_context_t* const ue_context_pP
+  rrc_eNB_ue_context_t*  ue_context_pP
 )
 {
   if (!ue_context_pP) {
     LOG_W(RRC, "[eNB] In %s: invalid UE\n", __func__);
     return;
   }
+  eNB_RRC_UE_t *ue = &ue_context_pP->ue_context;
   gtpv1u_enb_delete_tunnel_req_t tmp={0};
 
-  tmp.rnti = ue_context_pP->ue_context.rnti;
+  tmp.rnti = ue->rnti;
   tmp.from_gnb = 0;
-  tmp.num_erab = ue_context_pP->ue_context.nb_of_e_rabs;
-  for (int e_rab = 0; e_rab < ue_context_pP->ue_context.nb_of_e_rabs; e_rab++) {
-    const rb_id_t gtp_ebi = ue_context_pP->ue_context.enb_gtp_ebi[e_rab];
+  tmp.num_erab = ue->nb_of_e_rabs;
+  for (int e_rab = 0; e_rab < ue->nb_of_e_rabs; e_rab++) {
+    const rb_id_t gtp_ebi = ue->enb_gtp_ebi[e_rab];
     tmp.eps_bearer_id[e_rab] = gtp_ebi;
   }
-  gtpv1u_delete_s1u_tunnel(enb_mod_idP,&tmp); 
+  gtpv1u_delete_s1u_tunnel(enb_mod_idP,&tmp);
+  if ( ue->ue_release_timer_rrc > 0
+       && (ue->handover_info == NULL ||
+	   (ue->handover_info->state != HO_RELEASE &&
+	    ue->handover_info->state != HO_CANCEL
+	   )
+       )
+    )
+    ue->ue_release_timer_rrc = ue->ue_release_timer_thres_rrc;
+  
 }
 
 
diff --git a/openair2/RRC/LTE/rrc_eNB_GTPV1U.h b/openair2/RRC/LTE/rrc_eNB_GTPV1U.h
index 6318ed4927cc051a1a3b3c2c70956fc22e85eeae..ab789099caeee90bee21c38ce0e9eea9c6160cb9 100644
--- a/openair2/RRC/LTE/rrc_eNB_GTPV1U.h
+++ b/openair2/RRC/LTE/rrc_eNB_GTPV1U.h
@@ -57,7 +57,7 @@ rrc_gNB_process_GTPV1U_CREATE_TUNNEL_RESP(
  */
 void rrc_eNB_send_GTPV1U_ENB_DELETE_TUNNEL_REQ(
   module_id_t enb_mod_idP,
-  const rrc_eNB_ue_context_t* const ue_context_pP
+  rrc_eNB_ue_context_t* ue_context_pP
 );
 
 boolean_t
diff --git a/openair2/RRC/LTE/rrc_eNB_S1AP.c b/openair2/RRC/LTE/rrc_eNB_S1AP.c
index 1cb575d1ddb323877700097692265f82ee28a0f8..1a5fe55c26feb2732bc731efedd1a468eb060551 100644
--- a/openair2/RRC/LTE/rrc_eNB_S1AP.c
+++ b/openair2/RRC/LTE/rrc_eNB_S1AP.c
@@ -62,11 +62,6 @@
 #include "executables/softmodem-common.h"
 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;
 
@@ -169,7 +164,6 @@ rrc_eNB_S1AP_get_ue_ids(
   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;
 
@@ -257,29 +251,7 @@ rrc_eNB_S1AP_get_ue_ids(
             LOG_E(RRC, "Removing UE context eNB_ue_s1ap_id %u: did not find context\n",ue_desc_p->eNB_ue_s1ap_id);
           }
 
-          return NULL; //skip the operation below to avoid loop
-          result = rrc_eNB_S1AP_get_ue_ids(rrc_instance_pP, ue_desc_p->ue_initial_id, eNB_ue_s1ap_id);
-
-          if (ue_desc_p->ue_initial_id != UE_INITIAL_ID_INVALID) {
-            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] S1AP context found but ue_initial_id is invalid (0)\n", rrc_instance_pP - RC.rrc[0]);
-            return NULL;
-          }
+          return NULL; 
         } else {
           LOG_E(S1AP, "[eNB %ld] In hashtable_get, couldn't find in s1ap_id2_s1ap_ids eNB_ue_s1ap_id %"PRIu32", because ue_initial_id is invalid in S1AP context\n",
                 rrc_instance_pP - RC.rrc[0],
@@ -593,14 +565,20 @@ rrc_eNB_send_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;
 
   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_DONE) {
+   if (ue_context_pP->ue_context.e_rab[e_rab].status == E_RAB_STATUS_DONE || ue_context_pP->ue_context.e_rab[e_rab].status == E_RAB_STATUS_TOMODIFY) {
       e_rabs_done++;
       S1AP_INITIAL_CONTEXT_SETUP_RESP (msg_p).e_rabs[e_rab].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_INITIAL_CONTEXT_SETUP_RESP (msg_p).e_rabs[e_rab].gtp_teid = ue_context_pP->ue_context.enb_gtp_teid[e_rab];
       S1AP_INITIAL_CONTEXT_SETUP_RESP (msg_p).e_rabs[e_rab].eNB_addr = ue_context_pP->ue_context.enb_gtp_addrs[e_rab];
       S1AP_INITIAL_CONTEXT_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;
+      if (ue_context_pP->ue_context.e_rab[e_rab].status == E_RAB_STATUS_DONE) {
+        ue_context_pP->ue_context.e_rab[e_rab].status = E_RAB_STATUS_ESTABLISHED;
+        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);
+      }
+
     } else {
       e_rabs_failed++;
       ue_context_pP->ue_context.e_rab[e_rab].status = E_RAB_STATUS_FAILED;
@@ -619,9 +597,6 @@ 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);
 }
 
 //------------------------------------------------------------------------------
@@ -1078,29 +1053,43 @@ int rrc_eNB_process_S1AP_INITIAL_CONTEXT_SETUP_REQ(MessageDef *msg_p, const char
       rrc_eNB_send_S1AP_INITIAL_CONTEXT_SETUP_RESP(&ctxt,ue_context_p);
     }
 
-    /*
-        if ((RC.rrc[ctxt.module_id]->node_type == ngran_eNB_CU) ||
-            (RC.rrc[ctxt.module_id]->node_type == ngran_ng_eNB_CU) ||
-            (RC.rrc[ctxt.module_id]->node_type == ngran_gNB_CU) ){
-
-          message_p = itti_alloc_new_message (TASK_RRC_ENB, 0, 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");
-
-        }
-    */
-    return (0);
+    
+    if ((RC.rrc[ctxt.module_id]->node_type == ngran_eNB_CU) ||
+	(RC.rrc[ctxt.module_id]->node_type == ngran_ng_eNB_CU) ||
+	(RC.rrc[ctxt.module_id]->node_type == ngran_gNB_CU) ){
+      struct eNB_RRC_INST_s *rrc= RC.rrc[0];
+      MessageDef *message_p = itti_alloc_new_message (TASK_RRC_ENB, 0, F1AP_UE_CONTEXT_SETUP_REQ);
+      f1ap_ue_context_setup_t *req=&F1AP_UE_CONTEXT_SETUP_REQ (message_p);
+      req->gNB_CU_ue_id     = 0;
+      req->gNB_DU_ue_id = 0;
+      req->rnti = ue_context_p->ue_context.rnti;
+      req->mcc  = rrc->configuration.mcc[0];
+      req->mnc  = rrc->configuration.mnc[0];
+      req->mnc_digit_length = rrc->configuration.mnc_digit_length[0];
+      req->nr_cellid        = rrc->nr_cellid;
+      req->srbs_to_be_setup = malloc(sizeof(f1ap_srb_to_be_setup_t));
+      req->srbs_to_be_setup_length = 1;
+      f1ap_srb_to_be_setup_t *SRBs=req->srbs_to_be_setup;
+      SRBs[0].srb_id=CCCH;
+      req->drbs_to_be_setup_length = S1AP_INITIAL_CONTEXT_SETUP_REQ (msg_p).nb_of_e_rabs;
+      req->drbs_to_be_setup = malloc(req->drbs_to_be_setup_length * sizeof(f1ap_drb_to_be_setup_t));
+      f1ap_drb_to_be_setup_t *DRBs=req->drbs_to_be_setup;
+      for (int i = 0; i < req->drbs_to_be_setup_length ; i++) {
+	DRBs[i].drb_id=S1AP_INITIAL_CONTEXT_SETUP_REQ (msg_p).e_rab_param[i].e_rab_id;
+	DRBs[i].rlc_mode = RLC_MODE_AM;
+	DRBs[i].up_ul_tnl[0].tl_address = inet_addr(rrc->eth_params_s.my_addr);
+	DRBs[i].up_ul_tnl[0].port=rrc->eth_params_s.my_portd;
+	DRBs[i].up_ul_tnl_length = 1;
+	DRBs[i].up_dl_tnl[0].tl_address = inet_addr(rrc->eth_params_s.remote_addr);
+	DRBs[i].up_dl_tnl[0].port=rrc->eth_params_s.remote_portd;
+	DRBs[i].up_dl_tnl_length = 1;
+      }
+      LOG_I(RRC, "Send F1AP_UE_CONTEXT_SETUP_REQ with ITTI\n");
+      itti_send_msg_to_task (TASK_CU_F1, 0, message_p);
+    }
   }
+  
+  return (0);
 }
 
 /*------------------------------------------------------------------------------*/
@@ -1706,7 +1695,6 @@ int rrc_eNB_process_S1AP_E_RAB_RELEASE_COMMAND(MessageDef *msg_p, const char *ms
   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;
@@ -1774,21 +1762,19 @@ int rrc_eNB_process_S1AP_E_RAB_RELEASE_COMMAND(MessageDef *msg_p, const char *ms
       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, 0, 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;
-      GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p).from_gnb = 0;
+      gtpv1u_enb_delete_tunnel_req_t  delete_tunnels={0};
+      delete_tunnels.rnti = ue_context_p->ue_context.rnti;
+      delete_tunnels.from_gnb = 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];
+          delete_tunnels.eps_bearer_id[delete_tunnels.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_VARIABLE, instance, msg_delete_tunnels_p);
+      gtpv1u_delete_s1u_tunnel(instance,&delete_tunnels);
       //S1AP_E_RAB_RELEASE_RESPONSE
       rrc_eNB_send_S1AP_E_RAB_RELEASE_RESPONSE(&ctxt, ue_context_p, xid);
     }
@@ -1967,7 +1953,7 @@ int rrc_eNB_process_PAGING_IND(MessageDef *msg_p, const char *msg_name, instance
           message_p = itti_alloc_new_message (TASK_RRC_ENB, 0, RRC_PCCH_DATA_REQ);
           /* Create message for PDCP (DLInformationTransfer_t) */
           length = do_Paging (instance,
-                              buffer,
+                              buffer, sizeof(buffer),
                               S1AP_PAGING_IND(msg_p).ue_paging_identity,
                               S1AP_PAGING_IND(msg_p).cn_domain);
 
@@ -2253,8 +2239,16 @@ int rrc_eNB_process_S1AP_PATH_SWITCH_REQ_ACK (MessageDef *msg_p,
                                &delete_tunnel_req);
       /* TBD: release the DRB not admitted */
       //rrc_eNB_generate_dedicatedRRCConnectionReconfiguration(&ctxt, ue_context_p, 0);
-    }
-
+      if ( ue_context_p->ue_context.ue_release_timer_rrc > 0 &&
+	   (ue_context_p->ue_context.handover_info == NULL ||
+	    (ue_context_p->ue_context.handover_info->state != HO_RELEASE &&
+	     ue_context_p->ue_context.handover_info->state != HO_CANCEL
+	     )
+	    )
+	   )
+      ue_context_p->ue_context.ue_release_timer_rrc = ue_context_p->ue_context.ue_release_timer_thres_rrc;
+  }
+  
     /* 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,
diff --git a/openair2/RRC/LTE/rrc_eNB_endc.c b/openair2/RRC/LTE/rrc_eNB_endc.c
index 3d3d9787b5954e03d2a9149afabf53179dfa95d7..a2792adba59289ccaf5997d390f67ab3b1178196 100644
--- a/openair2/RRC/LTE/rrc_eNB_endc.c
+++ b/openair2/RRC/LTE/rrc_eNB_endc.c
@@ -171,8 +171,10 @@ int rrc_eNB_generate_RRCConnectionReconfiguration_endc(protocol_ctxt_t *ctxt,
 
   OCTET_STRING_t dummy_scg_conf;
   unsigned char scg_conf_buf[4] = { 0, 0, 0, 0 };
-  if (scg_group_config!=NULL)
+  if (scg_group_config!=NULL) {
 	  nr.choice.setup.nr_SecondaryCellGroupConfig_r15 = scg_group_config; //&scg_conf;
+          LOG_E(RRC, "setting scg_group_config\n");
+  }
   else{
 	  nr.choice.setup.nr_SecondaryCellGroupConfig_r15 = &dummy_scg_conf;
 	  dummy_scg_conf.buf = scg_conf_buf;
@@ -197,8 +199,10 @@ int rrc_eNB_generate_RRCConnectionReconfiguration_endc(protocol_ctxt_t *ctxt,
   OCTET_STRING_t dummy_nr1_conf;
   unsigned char nr1_buf[4] = { 0, 0, 0, 0 };
 
-  if(scg_RB_config!=NULL)
+  if(scg_RB_config!=NULL) {
 	  cr_1510.nr_RadioBearerConfig1_r15 = scg_RB_config;
+          LOG_E(RRC, "setting scg_RB_config\n");
+  }
   else{
 	  cr_1510.nr_RadioBearerConfig1_r15 = &dummy_nr1_conf;
 	  dummy_nr1_conf.buf = nr1_buf;
@@ -230,7 +234,8 @@ int rrc_eNB_generate_RRCConnectionReconfiguration_endc(protocol_ctxt_t *ctxt,
                                    (void *)&dl_dcch_msg,
                                    buffer,
                                    buffer_size);
-
+  AssertFatal (enc_rval.encoded > 0, "asn_DEF_LTE_DL_DCCH_Message message encoding failed (%s, %jd)!\n",
+                 enc_rval.failed_type->name, enc_rval.encoded);
 {
 int len = (enc_rval.encoded + 7) / 8;
 int i;
diff --git a/openair2/RRC/LTE/rrc_eNB_ral.c b/openair2/RRC/LTE/rrc_eNB_ral.c
deleted file mode 100644
index 9e1486f6d8a3e4d8e1fd8081973cd13256bbe725..0000000000000000000000000000000000000000
--- a/openair2/RRC/LTE/rrc_eNB_ral.c
+++ /dev/null
@@ -1,236 +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_eNB_ral.c
- * \brief rrc procedures for handling RAL messages
- * \author Lionel GAUTHIER
- * \date 2013
- * \version 1.0
- * \company Eurecom
- * \email: lionel.gauthier@eurecom.fr
- */
-#define RRC_ENB
-#define RRC_ENB_RAL_C
-//-----------------------------------------------------------------------------
-#include "rrc_eNB_ral.h"
-#include "assertions.h"
-#include "collection/hashtable/obj_hashtable.h"
-#include "RRC/LTE/defs.h"
-#include "RRC/LTE/extern.h"
-
-
-//-----------------------------------------------------------------------------
-int rrc_enb_ral_delete_all_thresholds_type(unsigned int mod_idP, ral_link_param_type_t *param_type_pP)
-//-----------------------------------------------------------------------------
-{
-  hashtable_rc_t           rc;
-  rrc_ral_threshold_key_t *key;
-  rrc_ral_threshold_key_t *keys = NULL;
-  unsigned int             num_keys = 0;
-  int                      return_code = 0;
-  rc =  obj_hashtable_get_keys(eNB_rrc_inst[mod_idP].ral_meas_thresholds, (void *)&keys, &num_keys);
-
-  if (rc == HASH_TABLE_OK) {
-    key = keys;
-
-    while (num_keys > 0) {
-      if (memcmp(&key->link_param_type, param_type_pP, sizeof(ral_link_param_type_t)) == 0) {
-        rc = obj_hashtable_remove (eNB_rrc_inst[mod_idP].ral_meas_thresholds, key, sizeof(rrc_ral_threshold_key_t));
-
-        if (rc != HASH_TABLE_OK) {
-          return_code = -1;
-        }
-      }
-
-      key = &key[1];
-      num_keys--;
-    }
-  } else {
-    return_code = -1;
-  }
-
-  if (keys != NULL) {
-    free(keys);
-  }
-
-  return return_code;
-}
-
-
-//-----------------------------------------------------------------------------
-int rrc_enb_ral_delete_threshold(unsigned int mod_idP, ral_link_param_type_t *param_type_pP, ral_threshold_t *threshold_pP)
-//-----------------------------------------------------------------------------
-{
-  hashtable_rc_t           rc;
-  rrc_ral_threshold_key_t  ref_key;
-  memcpy(&ref_key.link_param_type, param_type_pP, sizeof(ral_link_param_type_t));
-  memcpy(&ref_key.threshold,       threshold_pP,  sizeof(ral_threshold_t));
-  rc = obj_hashtable_remove (eNB_rrc_inst[mod_idP].ral_meas_thresholds, (void *)&ref_key, sizeof(rrc_ral_threshold_key_t));
-
-  if (rc == HASH_TABLE_OK) {
-    return 0;
-  } else {
-    return -1;
-  }
-}
-
-
-//-----------------------------------------------------------------------------
-int rrc_enb_ral_handle_configure_threshold_request(unsigned int mod_idP, MessageDef *msg_pP)
-//-----------------------------------------------------------------------------
-{
-  ral_transaction_id_t               transaction_id            = 0;
-  rrc_ral_configure_threshold_req_t *configure_threshold_req_p = NULL;
-  ral_link_cfg_param_t              *link_cfg_param_p          = NULL;
-  ral_threshold_t                   *threshold_p               = NULL;
-  MessageDef                        *message_p                 = NULL;
-  unsigned int                       ix_param                  = 0;
-  unsigned int                       ix_thresholds             = 0;
-  DevAssert(msg_pP != NULL);
-  LOG_I(RRC, "[eNB %d] Received %s\n", mod_idP, ITTI_MSG_NAME (msg_pP));
-  configure_threshold_req_p = &RRC_RAL_CONFIGURE_THRESHOLD_REQ(msg_pP);
-  transaction_id = configure_threshold_req_p->transaction_id;
-
-  for (ix_param = 0; ix_param < configure_threshold_req_p->num_link_cfg_params; ix_param++) {
-    link_cfg_param_p = &configure_threshold_req_p->link_cfg_params[ix_param];
-
-    switch (link_cfg_param_p->th_action) {
-      case RAL_TH_ACTION_SET_NORMAL_THRESHOLD:
-      case RAL_TH_ACTION_SET_ONE_SHOT_THRESHOLD:
-        switch (link_cfg_param_p->link_param_type.choice) {
-          case RAL_LINK_PARAM_TYPE_CHOICE_GEN:
-            switch (link_cfg_param_p->link_param_type._union.link_param_gen) {
-              case RAL_LINK_PARAM_GEN_DATA_RATE:
-              case RAL_LINK_PARAM_GEN_SIGNAL_STRENGTH:
-              case RAL_LINK_PARAM_GEN_SINR:
-              case RAL_LINK_PARAM_GEN_THROUGHPUT:
-              case RAL_LINK_PARAM_GEN_PACKET_ERROR_RATE:
-                message_p = itti_alloc_new_message (TASK_RRC_ENB, PHY_MEAS_THRESHOLD_REQ);
-                PHY_MEAS_THRESHOLD_REQ(message_p).transaction_id  = transaction_id;
-                memcpy (&PHY_MEAS_THRESHOLD_REQ(message_p).cfg_param, (void *) link_cfg_param_p, sizeof(ral_link_cfg_param_t));
-                itti_send_msg_to_task (TASK_PHY_ENB, ITTI_MSG_DESTINATION_INSTANCE(msg_pP), message_p);
-                break;
-
-              default:
-                LOG_E(RRC, "Message RRC_RAL_CONFIGURE_THRESHOLD_REQ malformed, unknown link_param_gen %d\n", link_cfg_param_p->link_param_type._union.link_param_gen);
-                return -1;
-            }
-
-            break;
-
-          case RAL_LINK_PARAM_TYPE_CHOICE_QOS:
-            switch (link_cfg_param_p->link_param_type._union.link_param_qos) {
-              case RAL_LINK_PARAM_QOS_MAX_NUM_DIF_COS_SUPPORTED:
-              case RAL_LINK_PARAM_QOS_MIN_PACKET_TRANSFER_DELAY_ALL_COS:
-              case RAL_LINK_PARAM_QOS_AVG_PACKET_TRANSFER_DELAY_ALL_COS:
-              case RAL_LINK_PARAM_QOS_MAX_PACKET_TRANSFER_DELAY_ALL_COS:
-              case RAL_LINK_PARAM_QOS_STD_DEVIATION_PACKET_TRANSFER_DELAY:
-              case RAL_LINK_PARAM_QOS_PACKET_LOSS_RATE_ALL_COS_FRAME_RATIO:
-                message_p = itti_alloc_new_message (TASK_RRC_ENB, PHY_MEAS_THRESHOLD_REQ);
-                PHY_MEAS_THRESHOLD_REQ(message_p).transaction_id  = transaction_id;
-                memcpy (&PHY_MEAS_THRESHOLD_REQ(message_p).cfg_param, (void *) link_cfg_param_p, sizeof(ral_link_cfg_param_t));
-                itti_send_msg_to_task (TASK_MAC_ENB, ITTI_MSG_DESTINATION_INSTANCE(msg_pP), message_p);
-                break;
-
-              default:
-                LOG_E(RRC, "Message RRC_RAL_CONFIGURE_THRESHOLD_REQ malformed, unknown link_param_qos %d\n", link_cfg_param_p->link_param_type._union.link_param_qos);
-                return -1;
-            }
-
-            break;
-
-          case RAL_LINK_PARAM_TYPE_CHOICE_LTE:
-            switch (link_cfg_param_p->link_param_type._union.link_param_lte) {
-              // group by dest task id
-              case RAL_LINK_PARAM_LTE_UE_RSRP:
-              case RAL_LINK_PARAM_LTE_UE_RSRQ:
-              case RAL_LINK_PARAM_LTE_UE_CQI:
-                message_p = itti_alloc_new_message (TASK_RRC_ENB, PHY_MEAS_THRESHOLD_REQ);
-                PHY_MEAS_THRESHOLD_REQ(message_p).transaction_id  = transaction_id;
-                memcpy (&PHY_MEAS_THRESHOLD_REQ(message_p).cfg_param, (void *) link_cfg_param_p, sizeof(ral_link_cfg_param_t));
-                itti_send_msg_to_task (TASK_PHY_ENB, ITTI_MSG_DESTINATION_INSTANCE(msg_pP), message_p);
-                break;
-
-              case RAL_LINK_PARAM_LTE_AVAILABLE_BW:
-              case RAL_LINK_PARAM_LTE_PACKET_LOSS_RATE:
-              case RAL_LINK_PARAM_LTE_L2_BUFFER_STATUS:
-              case RAL_LINK_PARAM_LTE_PACKET_DELAY:
-                message_p = itti_alloc_new_message (TASK_RRC_ENB, PHY_MEAS_THRESHOLD_REQ);
-                PHY_MEAS_THRESHOLD_REQ(message_p).transaction_id  = transaction_id;
-                memcpy (&PHY_MEAS_THRESHOLD_REQ(message_p).cfg_param, (void *) link_cfg_param_p, sizeof(ral_link_cfg_param_t));
-                itti_send_msg_to_task (TASK_MAC_ENB, ITTI_MSG_DESTINATION_INSTANCE(msg_pP), message_p);
-                break;
-
-              case RAL_LINK_PARAM_LTE_MOBILE_NODE_CAPABILITIES:
-              case RAL_LINK_PARAM_LTE_EMBMS_CAPABILITY:
-              case RAL_LINK_PARAM_LTE_JUMBO_FEASIBILITY:
-              case RAL_LINK_PARAM_LTE_JUMBO_SETUP_STATUS:
-              case RAL_LINK_PARAM_LTE_NUM_ACTIVE_EMBMS_RECEIVERS_PER_FLOW:
-#warning "TO DO MIH LTE LINK PARAMS IN RRC ENB"
-                break;
-
-              default:
-                LOG_E(RRC, "Message RRC_RAL_CONFIGURE_THRESHOLD_REQ malformed, unknown link_param_lte %d\n", link_cfg_param_p->link_param_type._union.link_param_lte);
-                return -1;
-            }
-
-            break;
-
-          default:
-            LOG_E(RRC, "Message RRC_RAL_CONFIGURE_THRESHOLD_REQ malformed, unknown link_param_type choice %d\n", link_cfg_param_p->link_param_type.choice);
-            return -1;
-        }
-
-        for (ix_thresholds=0; ix_thresholds < link_cfg_param_p->num_thresholds; ix_thresholds++) {
-          threshold_p = &link_cfg_param_p->thresholds[ix_thresholds];
-        }
-
-        break;
-
-      case RAL_TH_ACTION_CANCEL_THRESHOLD:
-
-        // IEEE Std 802.21-2008, Table F4, Data type name=LINK_CFG_PARAM (page 228):
-        // When “Cancel threshold” is selected and no thresholds are specified, then all
-        // currently configured thresholds for the given LINK_PARAM_TYPE are cancelled.
-        if (link_cfg_param_p->num_thresholds == 0) {
-          rrc_enb_ral_delete_all_thresholds_type(mod_idP, &link_cfg_param_p->link_param_type);
-        } else {
-          //
-          // When “Cancel threshold” is selected and thresholds are specified only those
-          // configured thresholds for the given LINK_PARAM_TYPE and whose threshold value match what was
-          // specified are cancelled.
-          for (ix_thresholds=0; ix_thresholds < link_cfg_param_p->num_thresholds; ix_thresholds++) {
-            threshold_p = &link_cfg_param_p->thresholds[ix_thresholds];
-            rrc_enb_ral_delete_threshold(mod_idP, &link_cfg_param_p->link_param_type, threshold_p);
-          }
-        }
-
-        break;
-
-      default:
-        LOG_E(RRC, "Message RRC_RAL_CONFIGURE_THRESHOLD_REQ malformed, unknown th_action %d\n", link_cfg_param_p->th_action);
-        return -1;
-    }
-  }
-
-  return 0;
-}
-
diff --git a/openair2/RRC/LTE/rrc_proto.h b/openair2/RRC/LTE/rrc_proto.h
index c50ddf3189e9fcb3e7d463835871d065baefa0ce..f0456005f5270a5a073aabe8134c87243d758e3e 100644
--- a/openair2/RRC/LTE/rrc_proto.h
+++ b/openair2/RRC/LTE/rrc_proto.h
@@ -31,6 +31,8 @@
  *  @{
  */
 
+#pragma once
+
 #include "RRC/LTE/rrc_defs.h"
 #include "x2ap_messages_types.h"
 #include "flexran_agent_extern.h"
@@ -103,6 +105,7 @@ rrc_ue_decode_dcch(
   const protocol_ctxt_t *const ctxt_pP,
   const rb_id_t                Srb_id,
   const uint8_t         *const Buffer,
+  const uint32_t               Buffer_size,
   const uint8_t                eNB_indexP
 );
 
@@ -310,6 +313,7 @@ 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,
+    size_t                 buffer_size,
     int                    *_size
     //const uint8_t        ho_state
                                                 );
@@ -354,6 +358,12 @@ void *rrc_enb_task(void *args_p);
    \param void *args_p Pointer on arguments to start the task. */
 void *rrc_ue_task(void *args_p);
 
+/**\brief RRC NSA UE task.
+   \param void *args_p Pointer on arguments to start the task. */
+void *recv_msgs_from_nr_ue(void *args_p);
+
+void init_connections_with_nr_ue(void);
+
 void rrc_eNB_process_x2_setup_request(int mod_id, x2ap_setup_req_t *m);
 
 void rrc_eNB_process_x2_setup_response(int mod_id, x2ap_setup_resp_t *m);
diff --git a/openair2/RRC/LTE/rrc_types.h b/openair2/RRC/LTE/rrc_types.h
index 9c1e37494f1eda3b3546709d458fced10d5b6de3..6b339af563beebf27f07da9ea182c7bc93ec47c8 100644
--- a/openair2/RRC/LTE/rrc_types.h
+++ b/openair2/RRC/LTE/rrc_types.h
@@ -61,4 +61,18 @@ typedef enum Rrc_Sub_State_e {
   RRC_SUB_STATE_CONNECTED_LAST = RRC_SUB_STATE_CONNECTED,
 } Rrc_Sub_State_t;
 
+typedef enum Rrc_Msg_Type_e {
+  UE_CAPABILITY_DUMMY = 0xa0,
+  UE_CAPABILITY_ENQUIRY,
+  NRUE_CAPABILITY_ENQUIRY,
+  UE_CAPABILITY_INFO,
+  NRUE_CAPABILITY_INFO,
+  RRC_MEASUREMENT_PROCEDURE,
+  NR_UE_RRC_MEASUREMENT,
+  RRC_CONFIG_COMPLETE_REQ,
+  NR_RRC_CONFIG_COMPLETE_REQ,
+  OAI_TUN_IFACE_NSA
+} Rrc_Msg_Type_t;
+
+
 #endif /* RRC_TYPES_H_ */
diff --git a/openair2/RRC/LTE/rrc_vars.h b/openair2/RRC/LTE/rrc_vars.h
index b1a0121c0018185f4a379d091fe190a118f1dcb8..dfb019193c14ea41a8b551471ba1d56c2d530e26 100644
--- a/openair2/RRC/LTE/rrc_vars.h
+++ b/openair2/RRC/LTE/rrc_vars.h
@@ -42,6 +42,8 @@ UE_RRC_INST *UE_rrc_inst = NULL;
 #include "LAYER2/MAC/mac_extern.h"
 #define MAX_U32 0xFFFFFFFF
 
+extern uint16_t ue_id_g;
+
 uint8_t DRB2LCHAN[8];
 
 long logicalChannelGroup0 = 0;
diff --git a/openair2/RRC/NR/L2_nr_interface.c b/openair2/RRC/NR/L2_nr_interface.c
index d781cb7e9bfbd4498eee2dd5629f123c60f3ae0e..eb402092b9a44aa82e6a1f4ea9ee41a7a775ae8f 100644
--- a/openair2/RRC/NR/L2_nr_interface.c
+++ b/openair2/RRC/NR/L2_nr_interface.c
@@ -323,31 +323,37 @@ int8_t nr_mac_rrc_data_ind(const module_id_t     module_idP,
     // call do_RRCSetup like full procedure and extract masterCellGroup
     NR_CellGroupConfig_t cellGroupConfig;
     NR_ServingCellConfigCommon_t *scc=RC.nrrrc[module_idP]->carrier.servingcellconfigcommon;
-    uint8_t sdu2[100];
     memset(&cellGroupConfig,0,sizeof(cellGroupConfig));
+
     fill_initial_cellGroupConfig(rntiP,&cellGroupConfig,scc,&RC.nrrrc[module_idP]->carrier);
+    MessageDef* tmp=itti_alloc_new_message_sized(TASK_RRC_GNB, 0, F1AP_INITIAL_UL_RRC_MESSAGE, sizeof(f1ap_initial_ul_rrc_message_t) + sdu_lenP);
+    f1ap_initial_ul_rrc_message_t *msg = &F1AP_INITIAL_UL_RRC_MESSAGE(tmp);
+
     asn_enc_rval_t enc_rval = uper_encode_to_buffer(&asn_DEF_NR_CellGroupConfig,
 						    NULL,
 						    (void *)&cellGroupConfig,
-						    sdu2,
-						    100);
+						    msg->du2cu_rrc_container,
+						    1024); //sizeof(msg->du2cu_rrc_container));
 
-    int sdu2_len = (enc_rval.encoded+7)/8;
     if (enc_rval.encoded == -1) {
       LOG_E(F1AP,"Could not encoded cellGroupConfig, failed element %s\n",enc_rval.failed_type->name);
       exit(-1);
     }
     /* do ITTI message */
-    DU_send_INITIAL_UL_RRC_MESSAGE_TRANSFER(
-      module_idP,
-      CC_id,
-      UE_id,
-      rntiP,
-      sduP,
-      sdu_lenP,
-      (const int8_t*)sdu2,
-      sdu2_len
-    );
+    msg->du2cu_rrc_container_length = (enc_rval.encoded+7)/8;
+    msg->crnti=rntiP;
+    msg->rrc_container=(uint8_t*) (msg+1); // Made extra room after the struct with itti_alloc_msg_sized()
+    memcpy(msg->rrc_container, sduP, sdu_lenP);
+    msg->rrc_container_length=sdu_lenP;
+    itti_send_msg_to_task(TASK_DU_F1, 0, tmp);
+    
+    struct rrc_gNB_ue_context_s *ue_context_p = rrc_gNB_allocate_new_UE_context(RC.nrrrc[module_idP]);
+    ue_context_p->ue_id_rnti                    = rntiP;
+    ue_context_p->ue_context.rnti               = rntiP;
+    ue_context_p->ue_context.random_ue_identity = rntiP;
+    ue_context_p->ue_context.Srb0.Active        = 1;
+    RB_INSERT(rrc_nr_ue_tree_s, &RC.nrrrc[module_idP]->rrc_ue_head, ue_context_p);
+    
     return(0);
   }
 
diff --git a/openair2/RRC/NR/MESSAGES/asn1_msg.c b/openair2/RRC/NR/MESSAGES/asn1_msg.c
index bdd1cf5261eddf641a6a1e5ad87fa62a1b8955d5..84a0cf75d192af0f5a0d1ddd31b2f8a81adb0198 100755
--- a/openair2/RRC/NR/MESSAGES/asn1_msg.c
+++ b/openair2/RRC/NR/MESSAGES/asn1_msg.c
@@ -297,15 +297,6 @@ uint8_t do_SIB1_NR(rrc_gNB_carrier_data_t *carrier,
                   ) {
   asn_enc_rval_t enc_rval;
 
-  // TODO : Add support for more than one PLMN
-  int num_plmn = 1; // int num_plmn = configuration->num_plmn;
-  struct NR_PLMN_Identity *nr_plmn = CALLOC(1, sizeof(struct NR_PLMN_Identity) * num_plmn);
-  NR_MCC_MNC_Digit_t (*nr_mcc_digit)[3] = (NR_MCC_MNC_Digit_t(*)[3])CALLOC(1, sizeof(NR_MCC_MNC_Digit_t)*num_plmn*3);
-  NR_MCC_MNC_Digit_t (*nr_mnc_digit)[3] = (NR_MCC_MNC_Digit_t(*)[3])CALLOC(1, sizeof(NR_MCC_MNC_Digit_t)*num_plmn*3);;
-  memset(nr_plmn,0,sizeof(struct NR_PLMN_Identity) * num_plmn);
-  memset(nr_mcc_digit,0,sizeof(NR_MCC_MNC_Digit_t)*num_plmn*3);
-  memset(nr_mnc_digit,0,sizeof(NR_MCC_MNC_Digit_t)*num_plmn*3);
-
   NR_BCCH_DL_SCH_Message_t *sib1_message = CALLOC(1,sizeof(NR_BCCH_DL_SCH_Message_t));
   carrier->siblock1 = sib1_message;
   sib1_message->message.present = NR_BCCH_DL_SCH_MessageType_PR_c1;
@@ -317,51 +308,52 @@ uint8_t do_SIB1_NR(rrc_gNB_carrier_data_t *carrier,
 
   // cellSelectionInfo
   sib1->cellSelectionInfo = CALLOC(1,sizeof(struct NR_SIB1__cellSelectionInfo));
+  // Fixme: should be in config file
+  //The IE Q-RxLevMin is used to indicate for cell selection/ re-selection the required minimum received RSRP level in the (NR) cell.
+  //Corresponds to parameter Qrxlevmin in TS38.304.
+  //Actual value Qrxlevmin = field value * 2 [dBm].
   sib1->cellSelectionInfo->q_RxLevMin = -65;
 
   // cellAccessRelatedInfo
-  struct NR_PLMN_IdentityInfo *nr_plmn_info=CALLOC(1,sizeof(struct NR_PLMN_IdentityInfo));
-  asn_set_empty(&nr_plmn_info->plmn_IdentityList.list);
+  // TODO : Add support for more than one PLMN
+  int num_plmn = 1; // int num_plmn = configuration->num_plmn;
+  asn1cSequenceAdd(sib1->cellAccessRelatedInfo.plmn_IdentityList.list, struct NR_PLMN_IdentityInfo, nr_plmn_info);
   for (int i = 0; i < num_plmn; ++i) {
-    nr_mcc_digit[i][0] = (configuration->mcc[i]/100)%10;
-    nr_mcc_digit[i][1] = (configuration->mcc[i]/10)%10;
-    nr_mcc_digit[i][2] = (configuration->mcc[i])%10;
-    nr_plmn[i].mcc = CALLOC(1,sizeof(struct NR_MCC));
-    asn_set_empty(&nr_plmn[i].mcc->list);
-    ASN_SEQUENCE_ADD(&nr_plmn[i].mcc->list, &nr_mcc_digit[i][0]);
-    ASN_SEQUENCE_ADD(&nr_plmn[i].mcc->list, &nr_mcc_digit[i][1]);
-    ASN_SEQUENCE_ADD(&nr_plmn[i].mcc->list, &nr_mcc_digit[i][2]);
-    if(configuration->mnc_digit_length[i] == 3) nr_mnc_digit[i][0] = (configuration->mnc[i]/100)%10;
-    nr_mnc_digit[i][1] = (configuration->mnc[i]/10)%10;
-    nr_mnc_digit[i][2] = (configuration->mnc[i])%10;
-    nr_plmn[i].mnc.list.size=0;
-    nr_plmn[i].mnc.list.count=0;
-    if(configuration->mnc_digit_length[i] == 3) ASN_SEQUENCE_ADD(&nr_plmn[i].mnc.list, &nr_mnc_digit[i][0]);
-    ASN_SEQUENCE_ADD(&nr_plmn[i].mnc.list, &nr_mnc_digit[i][1]);
-    ASN_SEQUENCE_ADD(&nr_plmn[i].mnc.list, &nr_mnc_digit[i][2]);
-    ASN_SEQUENCE_ADD(&nr_plmn_info->plmn_IdentityList.list, &nr_plmn[i]);
+    asn1cSequenceAdd(nr_plmn_info->plmn_IdentityList.list, struct NR_PLMN_Identity, nr_plmn);
+    asn1cCalloc(nr_plmn->mcc,  mcc);
+    int confMcc=configuration->mcc[i];
+    asn1cSequenceAdd(mcc->list, NR_MCC_MNC_Digit_t, mcc0);
+    *mcc0=(confMcc/100)%10;
+    asn1cSequenceAdd(mcc->list, NR_MCC_MNC_Digit_t, mcc1);
+    *mcc1=(confMcc/10)%10;
+    asn1cSequenceAdd(mcc->list, NR_MCC_MNC_Digit_t, mcc2);
+    *mcc2=confMcc%10;
+    int mnc=configuration->mnc[i];
+    if(configuration->mnc_digit_length[i] == 3) {
+      asn1cSequenceAdd(nr_plmn->mnc.list, NR_MCC_MNC_Digit_t, mnc0);
+      *mnc0=(configuration->mnc[i]/100)%10;
+      mnc/=10;
+    }
+    asn1cSequenceAdd(nr_plmn->mnc.list, NR_MCC_MNC_Digit_t, mnc1);
+    *mnc1=(mnc/10)%10;
+    asn1cSequenceAdd(nr_plmn->mnc.list, NR_MCC_MNC_Digit_t, mnc2);
+    *mnc2=(mnc)%10;
   }//end plmn loop
 
   nr_plmn_info->cellIdentity.buf = CALLOC(1,5);
-  nr_plmn_info->cellIdentity.buf[0]= (configuration->cell_identity >> 28) & 0xff;
-  nr_plmn_info->cellIdentity.buf[1]= (configuration->cell_identity >> 20) & 0xff;
-  nr_plmn_info->cellIdentity.buf[2]= (configuration->cell_identity >> 12) & 0xff;
-  nr_plmn_info->cellIdentity.buf[3]= (configuration->cell_identity >> 4) & 0xff;
-  nr_plmn_info->cellIdentity.buf[4]= (configuration->cell_identity << 4) & 0xff;
   nr_plmn_info->cellIdentity.size= 5;
   nr_plmn_info->cellIdentity.bits_unused= 4;
+  uint64_t tmp=htobe64(configuration->cell_identity)<<4;
+  memcpy(nr_plmn_info->cellIdentity.buf, ((char*)&tmp)+3, 5);
   nr_plmn_info->cellReservedForOperatorUse = NR_PLMN_IdentityInfo__cellReservedForOperatorUse_notReserved;
 
   nr_plmn_info->trackingAreaCode = CALLOC(1,sizeof(NR_TrackingAreaCode_t));
+  uint32_t tmp2=htobe32(configuration->tac);
   nr_plmn_info->trackingAreaCode->buf = CALLOC(1,3);
-  nr_plmn_info->trackingAreaCode->buf[0] = ( ((uint32_t)configuration->tac) >> 16) & 0xff;
-  nr_plmn_info->trackingAreaCode->buf[1] = ( ((uint32_t)configuration->tac) >> 8) & 0xff;
-  nr_plmn_info->trackingAreaCode->buf[2] = ( ((uint32_t)configuration->tac) >> 0) & 0xff;
+  memcpy(nr_plmn_info->trackingAreaCode->buf, ((char*) &tmp2)+1, 3);
   nr_plmn_info->trackingAreaCode->size = 3;
   nr_plmn_info->trackingAreaCode->bits_unused = 0;
 
-  ASN_SEQUENCE_ADD(&sib1->cellAccessRelatedInfo.plmn_IdentityList.list, nr_plmn_info);
-
   // connEstFailureControl
   // TODO: add connEstFailureControl
 
@@ -397,19 +389,19 @@ uint8_t do_SIB1_NR(rrc_gNB_carrier_data_t *carrier,
   ASN_SEQUENCE_ADD(&sib1->si_SchedulingInfo->schedulingInfoList.list,schedulingInfo);*/
 
   // servingCellConfigCommon
-  sib1->servingCellConfigCommon = CALLOC(1,sizeof(struct NR_ServingCellConfigCommonSIB));
+  asn1cCalloc(sib1->servingCellConfigCommon,  ServCellCom);
+  NR_BWP_DownlinkCommon_t  *initialDownlinkBWP=&ServCellCom->downlinkConfigCommon.initialDownlinkBWP;
+  initialDownlinkBWP->genericParameters=
+    configuration->scc->downlinkConfigCommon->initialDownlinkBWP->genericParameters;
+  
 
-  asn_set_empty(&sib1->servingCellConfigCommon->downlinkConfigCommon.frequencyInfoDL.frequencyBandList.list);
-  asn_set_empty(&sib1->servingCellConfigCommon->downlinkConfigCommon.frequencyInfoDL.scs_SpecificCarrierList.list);
-  sib1->servingCellConfigCommon->downlinkConfigCommon.initialDownlinkBWP.genericParameters.locationAndBandwidth = configuration->scc->downlinkConfigCommon->initialDownlinkBWP->genericParameters.locationAndBandwidth;
-  sib1->servingCellConfigCommon->downlinkConfigCommon.initialDownlinkBWP.genericParameters.subcarrierSpacing = configuration->scc->downlinkConfigCommon->initialDownlinkBWP->genericParameters.subcarrierSpacing;
-  sib1->servingCellConfigCommon->downlinkConfigCommon.initialDownlinkBWP.genericParameters.cyclicPrefix = configuration->scc->downlinkConfigCommon->initialDownlinkBWP->genericParameters.cyclicPrefix;
   for(int i = 0; i< configuration->scc->downlinkConfigCommon->frequencyInfoDL->frequencyBandList.list.count; i++) {
-    struct NR_NR_MultiBandInfo *nrMultiBandInfo = CALLOC(1,sizeof(struct NR_NR_MultiBandInfo));
+    asn1cSequenceAdd(ServCellCom->downlinkConfigCommon.frequencyInfoDL.frequencyBandList.list,
+		     struct NR_NR_MultiBandInfo, nrMultiBandInfo);
     nrMultiBandInfo->freqBandIndicatorNR = configuration->scc->downlinkConfigCommon->frequencyInfoDL->frequencyBandList.list.array[i];
-    ASN_SEQUENCE_ADD(&sib1->servingCellConfigCommon->downlinkConfigCommon.frequencyInfoDL.frequencyBandList.list,nrMultiBandInfo);
   }
 
+
   int scs_scaling0 = 1<<(configuration->scc->downlinkConfigCommon->initialDownlinkBWP->genericParameters.subcarrierSpacing);
   int scs_scaling  = scs_scaling0;
   int scs_scaling2 = scs_scaling0;
@@ -432,17 +424,19 @@ uint8_t do_SIB1_NR(rrc_gNB_carrier_data_t *carrier,
         absolute_diff,scs_scaling2,scs_scaling,(int)sib1->servingCellConfigCommon->downlinkConfigCommon.frequencyInfoDL.offsetToPointA);
 
   for(int i = 0; i< configuration->scc->downlinkConfigCommon->frequencyInfoDL->scs_SpecificCarrierList.list.count; i++) {
-    ASN_SEQUENCE_ADD(&sib1->servingCellConfigCommon->downlinkConfigCommon.frequencyInfoDL.scs_SpecificCarrierList.list,configuration->scc->downlinkConfigCommon->frequencyInfoDL->scs_SpecificCarrierList.list.array[i]);
+    ASN_SEQUENCE_ADD(&ServCellCom->downlinkConfigCommon.frequencyInfoDL.scs_SpecificCarrierList.list,
+		     configuration->scc->downlinkConfigCommon->frequencyInfoDL->scs_SpecificCarrierList.list.array[i]);
   }
 
-  sib1->servingCellConfigCommon->downlinkConfigCommon.initialDownlinkBWP.pdcch_ConfigCommon = configuration->scc->downlinkConfigCommon->initialDownlinkBWP->pdcch_ConfigCommon;
-  sib1->servingCellConfigCommon->downlinkConfigCommon.initialDownlinkBWP.pdcch_ConfigCommon->choice.setup->commonSearchSpaceList = CALLOC(1,sizeof(struct NR_PDCCH_ConfigCommon__commonSearchSpaceList));
-  asn_set_empty(&sib1->servingCellConfigCommon->downlinkConfigCommon.initialDownlinkBWP.pdcch_ConfigCommon->choice.setup->commonSearchSpaceList->list);
+  initialDownlinkBWP->pdcch_ConfigCommon = 
+      configuration->scc->downlinkConfigCommon->initialDownlinkBWP->pdcch_ConfigCommon;
+  initialDownlinkBWP->pdcch_ConfigCommon->choice.setup->commonSearchSpaceList = 
+       CALLOC(1,sizeof(struct NR_PDCCH_ConfigCommon__commonSearchSpaceList));
 
-  NR_SearchSpace_t *ss1 = calloc(1,sizeof(*ss1));
+  asn1cSequenceAdd(initialDownlinkBWP->pdcch_ConfigCommon->choice.setup->commonSearchSpaceList->list,
+		   NR_SearchSpace_t, ss1);
   ss1->searchSpaceId = 1;
-  ss1->controlResourceSetId=calloc(1,sizeof(*ss1->controlResourceSetId));
-  *ss1->controlResourceSetId=0;
+  asn1cCallocOne(ss1->controlResourceSetId, 0);
   ss1->monitoringSlotPeriodicityAndOffset = calloc(1,sizeof(*ss1->monitoringSlotPeriodicityAndOffset));
   ss1->monitoringSlotPeriodicityAndOffset->present = NR_SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl1;
   ss1->monitoringSymbolsWithinSlot = calloc(1,sizeof(*ss1->monitoringSymbolsWithinSlot));
@@ -462,9 +456,9 @@ uint8_t do_SIB1_NR(rrc_gNB_carrier_data_t *carrier,
   ss1->searchSpaceType->present = NR_SearchSpace__searchSpaceType_PR_common;
   ss1->searchSpaceType->choice.common=calloc(1,sizeof(*ss1->searchSpaceType->choice.common));
   ss1->searchSpaceType->choice.common->dci_Format0_0_AndFormat1_0 = calloc(1,sizeof(*ss1->searchSpaceType->choice.common->dci_Format0_0_AndFormat1_0));
-  ASN_SEQUENCE_ADD(&sib1->servingCellConfigCommon->downlinkConfigCommon.initialDownlinkBWP.pdcch_ConfigCommon->choice.setup->commonSearchSpaceList->list,ss1);
 
-  NR_SearchSpace_t *ss5 = calloc(1,sizeof(*ss5));
+  asn1cSequenceAdd(initialDownlinkBWP->pdcch_ConfigCommon->choice.setup->commonSearchSpaceList->list,
+		   NR_SearchSpace_t, ss5);
   ss5->searchSpaceId = 5;
   ss5->controlResourceSetId=calloc(1,sizeof(*ss5->controlResourceSetId));
   *ss5->controlResourceSetId=0;
@@ -490,9 +484,9 @@ uint8_t do_SIB1_NR(rrc_gNB_carrier_data_t *carrier,
   ss5->searchSpaceType->present = NR_SearchSpace__searchSpaceType_PR_common;
   ss5->searchSpaceType->choice.common=calloc(1,sizeof(*ss5->searchSpaceType->choice.common));
   ss5->searchSpaceType->choice.common->dci_Format0_0_AndFormat1_0 = calloc(1,sizeof(*ss5->searchSpaceType->choice.common->dci_Format0_0_AndFormat1_0));
-  ASN_SEQUENCE_ADD(&sib1->servingCellConfigCommon->downlinkConfigCommon.initialDownlinkBWP.pdcch_ConfigCommon->choice.setup->commonSearchSpaceList->list,ss5);
 
-  NR_SearchSpace_t *ss7 = calloc(1,sizeof(*ss7));
+  asn1cSequenceAdd(initialDownlinkBWP->pdcch_ConfigCommon->choice.setup->commonSearchSpaceList->list,
+		   NR_SearchSpace_t, ss7);
   ss7->searchSpaceId = 7;
   ss7->controlResourceSetId=calloc(1,sizeof(*ss7->controlResourceSetId));
   *ss7->controlResourceSetId=0;
@@ -515,63 +509,59 @@ uint8_t do_SIB1_NR(rrc_gNB_carrier_data_t *carrier,
   ss7->searchSpaceType->present = NR_SearchSpace__searchSpaceType_PR_common;
   ss7->searchSpaceType->choice.common=calloc(1,sizeof(*ss7->searchSpaceType->choice.common));
   ss7->searchSpaceType->choice.common->dci_Format0_0_AndFormat1_0 = calloc(1,sizeof(*ss7->searchSpaceType->choice.common->dci_Format0_0_AndFormat1_0));
-  ASN_SEQUENCE_ADD(&sib1->servingCellConfigCommon->downlinkConfigCommon.initialDownlinkBWP.pdcch_ConfigCommon->choice.setup->commonSearchSpaceList->list,ss7);
-
-  sib1->servingCellConfigCommon->downlinkConfigCommon.initialDownlinkBWP.pdcch_ConfigCommon->choice.setup->searchSpaceSIB1 = calloc(1,sizeof(NR_SearchSpaceId_t));
-  *sib1->servingCellConfigCommon->downlinkConfigCommon.initialDownlinkBWP.pdcch_ConfigCommon->choice.setup->searchSpaceSIB1 = 0;
-  sib1->servingCellConfigCommon->downlinkConfigCommon.initialDownlinkBWP.pdcch_ConfigCommon->choice.setup->searchSpaceOtherSystemInformation = calloc(1,sizeof(NR_SearchSpaceId_t));
-  *sib1->servingCellConfigCommon->downlinkConfigCommon.initialDownlinkBWP.pdcch_ConfigCommon->choice.setup->searchSpaceOtherSystemInformation = 7;
-  sib1->servingCellConfigCommon->downlinkConfigCommon.initialDownlinkBWP.pdcch_ConfigCommon->choice.setup->pagingSearchSpace = calloc(1,sizeof(NR_SearchSpaceId_t));
-  *sib1->servingCellConfigCommon->downlinkConfigCommon.initialDownlinkBWP.pdcch_ConfigCommon->choice.setup->pagingSearchSpace = 5;
-  sib1->servingCellConfigCommon->downlinkConfigCommon.initialDownlinkBWP.pdcch_ConfigCommon->choice.setup->ra_SearchSpace = calloc(1,sizeof(NR_SearchSpaceId_t));
-  *sib1->servingCellConfigCommon->downlinkConfigCommon.initialDownlinkBWP.pdcch_ConfigCommon->choice.setup->ra_SearchSpace = 1;
-
-  sib1->servingCellConfigCommon->downlinkConfigCommon.initialDownlinkBWP.pdsch_ConfigCommon = configuration->scc->downlinkConfigCommon->initialDownlinkBWP->pdsch_ConfigCommon;
-  sib1->servingCellConfigCommon->downlinkConfigCommon.bcch_Config.modificationPeriodCoeff = NR_BCCH_Config__modificationPeriodCoeff_n2;
-  sib1->servingCellConfigCommon->downlinkConfigCommon.pcch_Config.defaultPagingCycle = NR_PagingCycle_rf256;
-  sib1->servingCellConfigCommon->downlinkConfigCommon.pcch_Config.nAndPagingFrameOffset.present = NR_PCCH_Config__nAndPagingFrameOffset_PR_quarterT;
-  sib1->servingCellConfigCommon->downlinkConfigCommon.pcch_Config.nAndPagingFrameOffset.choice.quarterT = 1;
-  sib1->servingCellConfigCommon->downlinkConfigCommon.pcch_Config.ns = NR_PCCH_Config__ns_one;
-
-  sib1->servingCellConfigCommon->downlinkConfigCommon.pcch_Config.firstPDCCH_MonitoringOccasionOfPO = calloc(1,sizeof(struct NR_PCCH_Config__firstPDCCH_MonitoringOccasionOfPO));
-  sib1->servingCellConfigCommon->downlinkConfigCommon.pcch_Config.firstPDCCH_MonitoringOccasionOfPO->present = NR_PCCH_Config__firstPDCCH_MonitoringOccasionOfPO_PR_sCS120KHZoneT_SCS60KHZhalfT_SCS30KHZquarterT_SCS15KHZoneEighthT;
-
-  sib1->servingCellConfigCommon->downlinkConfigCommon.pcch_Config.firstPDCCH_MonitoringOccasionOfPO->choice.sCS120KHZoneT_SCS60KHZhalfT_SCS30KHZquarterT_SCS15KHZoneEighthT = CALLOC(1,sizeof(struct NR_PCCH_Config__firstPDCCH_MonitoringOccasionOfPO__sCS120KHZoneT_SCS60KHZhalfT_SCS30KHZquarterT_SCS15KHZoneEighthT));
-  asn_set_empty(&sib1->servingCellConfigCommon->downlinkConfigCommon.pcch_Config.firstPDCCH_MonitoringOccasionOfPO->choice.sCS120KHZoneT_SCS60KHZhalfT_SCS30KHZquarterT_SCS15KHZoneEighthT->list);
-
-  long *sCS120KHZoneT_SCS60KHZhalfT_SCS30KHZquarterT_SCS15KHZoneEighthT = calloc(1,sizeof(long));
-  *sCS120KHZoneT_SCS60KHZhalfT_SCS30KHZquarterT_SCS15KHZoneEighthT = 0;
-  ASN_SEQUENCE_ADD(&sib1->servingCellConfigCommon->downlinkConfigCommon.pcch_Config.firstPDCCH_MonitoringOccasionOfPO->choice.sCS120KHZoneT_SCS60KHZhalfT_SCS30KHZquarterT_SCS15KHZoneEighthT->list,sCS120KHZoneT_SCS60KHZhalfT_SCS30KHZquarterT_SCS15KHZoneEighthT);
-
-  sib1->servingCellConfigCommon->uplinkConfigCommon = CALLOC(1,sizeof(struct NR_UplinkConfigCommonSIB));
-  asn_set_empty(&sib1->servingCellConfigCommon->uplinkConfigCommon->frequencyInfoUL.scs_SpecificCarrierList.list);
+
+  
+  asn1cCallocOne(initialDownlinkBWP->pdcch_ConfigCommon->choice.setup->searchSpaceSIB1,  0);
+  asn1cCallocOne(initialDownlinkBWP->pdcch_ConfigCommon->choice.setup->searchSpaceOtherSystemInformation, 7);
+  asn1cCallocOne(initialDownlinkBWP->pdcch_ConfigCommon->choice.setup->pagingSearchSpace, 5);
+  asn1cCallocOne( initialDownlinkBWP->pdcch_ConfigCommon->choice.setup->ra_SearchSpace, 1);
+   
+  initialDownlinkBWP->pdsch_ConfigCommon = configuration->scc->downlinkConfigCommon->initialDownlinkBWP->pdsch_ConfigCommon;
+  ServCellCom->downlinkConfigCommon.bcch_Config.modificationPeriodCoeff = NR_BCCH_Config__modificationPeriodCoeff_n2;
+  ServCellCom->downlinkConfigCommon.pcch_Config.defaultPagingCycle = NR_PagingCycle_rf256;
+  ServCellCom->downlinkConfigCommon.pcch_Config.nAndPagingFrameOffset.present = NR_PCCH_Config__nAndPagingFrameOffset_PR_quarterT;
+  ServCellCom->downlinkConfigCommon.pcch_Config.nAndPagingFrameOffset.choice.quarterT = 1;
+  ServCellCom->downlinkConfigCommon.pcch_Config.ns = NR_PCCH_Config__ns_one;
+
+  asn1cCalloc(ServCellCom->downlinkConfigCommon.pcch_Config.firstPDCCH_MonitoringOccasionOfPO,
+	      P0);
+  P0->present = NR_PCCH_Config__firstPDCCH_MonitoringOccasionOfPO_PR_sCS120KHZoneT_SCS60KHZhalfT_SCS30KHZquarterT_SCS15KHZoneEighthT;
+
+  asn1cCalloc(P0->choice.sCS120KHZoneT_SCS60KHZhalfT_SCS30KHZquarterT_SCS15KHZoneEighthT,
+	      Z8);
+  asn1cSequenceAdd(Z8->list,
+		   long,
+		   ZoneEight);
+  asn1cCallocOne(ZoneEight, 0);
+
+  asn1cCalloc(ServCellCom->uplinkConfigCommon, UL)
+  asn_set_empty(&UL->frequencyInfoUL.scs_SpecificCarrierList.list);
   for(int i = 0; i< configuration->scc->uplinkConfigCommon->frequencyInfoUL->scs_SpecificCarrierList.list.count; i++) {
-    ASN_SEQUENCE_ADD(&sib1->servingCellConfigCommon->uplinkConfigCommon->frequencyInfoUL.scs_SpecificCarrierList.list,configuration->scc->uplinkConfigCommon->frequencyInfoUL->scs_SpecificCarrierList.list.array[i]);
+    ASN_SEQUENCE_ADD(&UL->frequencyInfoUL.scs_SpecificCarrierList.list,
+		     configuration->scc->uplinkConfigCommon->frequencyInfoUL->scs_SpecificCarrierList.list.array[i]);
   }
 
-  sib1->servingCellConfigCommon->uplinkConfigCommon->frequencyInfoUL.p_Max = CALLOC(1,sizeof(NR_P_Max_t));
-  *sib1->servingCellConfigCommon->uplinkConfigCommon->frequencyInfoUL.p_Max = 23;
-
-  sib1->servingCellConfigCommon->uplinkConfigCommon->initialUplinkBWP.genericParameters = configuration->scc->uplinkConfigCommon->initialUplinkBWP->genericParameters;
-  sib1->servingCellConfigCommon->uplinkConfigCommon->initialUplinkBWP.rach_ConfigCommon = configuration->scc->uplinkConfigCommon->initialUplinkBWP->rach_ConfigCommon;
+  asn1cCallocOne(UL->frequencyInfoUL.p_Max, 23);
 
-  sib1->servingCellConfigCommon->uplinkConfigCommon->initialUplinkBWP.pusch_ConfigCommon = configuration->scc->uplinkConfigCommon->initialUplinkBWP->pusch_ConfigCommon;
-  sib1->servingCellConfigCommon->uplinkConfigCommon->initialUplinkBWP.pusch_ConfigCommon->choice.setup->groupHoppingEnabledTransformPrecoding = null;
+  UL->initialUplinkBWP.genericParameters = configuration->scc->uplinkConfigCommon->initialUplinkBWP->genericParameters;
+  UL->initialUplinkBWP.rach_ConfigCommon = configuration->scc->uplinkConfigCommon->initialUplinkBWP->rach_ConfigCommon;
+  UL->initialUplinkBWP.pusch_ConfigCommon = configuration->scc->uplinkConfigCommon->initialUplinkBWP->pusch_ConfigCommon;
+  UL->initialUplinkBWP.pusch_ConfigCommon->choice.setup->groupHoppingEnabledTransformPrecoding = null;
 
-  sib1->servingCellConfigCommon->uplinkConfigCommon->initialUplinkBWP.pucch_ConfigCommon = configuration->scc->uplinkConfigCommon->initialUplinkBWP->pucch_ConfigCommon;
+  UL->initialUplinkBWP.pucch_ConfigCommon = configuration->scc->uplinkConfigCommon->initialUplinkBWP->pucch_ConfigCommon;
 
-  sib1->servingCellConfigCommon->uplinkConfigCommon->timeAlignmentTimerCommon = NR_TimeAlignmentTimer_infinity;
+  UL->timeAlignmentTimerCommon = NR_TimeAlignmentTimer_infinity;
 
-  sib1->servingCellConfigCommon->n_TimingAdvanceOffset = configuration->scc->n_TimingAdvanceOffset;
+  ServCellCom->n_TimingAdvanceOffset = configuration->scc->n_TimingAdvanceOffset;
 
-  sib1->servingCellConfigCommon->ssb_PositionsInBurst.inOneGroup.buf = calloc(1, sizeof(uint8_t));
+  ServCellCom->ssb_PositionsInBurst.inOneGroup.buf = calloc(1, sizeof(uint8_t));
   uint8_t bitmap8,temp_bitmap=0;
   switch (configuration->scc->ssb_PositionsInBurst->present) {
     case NR_ServingCellConfigCommon__ssb_PositionsInBurst_PR_shortBitmap:
-      sib1->servingCellConfigCommon->ssb_PositionsInBurst.inOneGroup = configuration->scc->ssb_PositionsInBurst->choice.shortBitmap;
+      ServCellCom->ssb_PositionsInBurst.inOneGroup = configuration->scc->ssb_PositionsInBurst->choice.shortBitmap;
       break;
     case NR_ServingCellConfigCommon__ssb_PositionsInBurst_PR_mediumBitmap:
-      sib1->servingCellConfigCommon->ssb_PositionsInBurst.inOneGroup = configuration->scc->ssb_PositionsInBurst->choice.mediumBitmap;
+      ServCellCom->ssb_PositionsInBurst.inOneGroup = configuration->scc->ssb_PositionsInBurst->choice.mediumBitmap;
       break;
     /*
     groupPresence: This field is present when maximum number of SS/PBCH blocks per half frame equals to 64 as defined in TS 38.213 [13], clause 4.1.
@@ -582,14 +572,13 @@ uint8_t do_SIB1_NR(rrc_gNB_carrier_data_t *carrier,
                 (i.e., to SSB index 1, 9, and so on), and so on. Value 0 in the bitmap indicates that the corresponding SS/PBCH block is not transmitted while value 1 indicates that the corresponding SS/PBCH block is transmitted.
     */
     case NR_ServingCellConfigCommon__ssb_PositionsInBurst_PR_longBitmap:
-      sib1->servingCellConfigCommon->ssb_PositionsInBurst.inOneGroup.size = 1;
-      sib1->servingCellConfigCommon->ssb_PositionsInBurst.inOneGroup.bits_unused = 0;
-      sib1->servingCellConfigCommon->ssb_PositionsInBurst.groupPresence = calloc(1, sizeof(BIT_STRING_t));
-      memset(sib1->servingCellConfigCommon->ssb_PositionsInBurst.groupPresence, 0, sizeof(BIT_STRING_t));
-      sib1->servingCellConfigCommon->ssb_PositionsInBurst.groupPresence->size = 1;
-      sib1->servingCellConfigCommon->ssb_PositionsInBurst.groupPresence->bits_unused = 0;
-      sib1->servingCellConfigCommon->ssb_PositionsInBurst.groupPresence->buf = calloc(1, sizeof(uint8_t));
-      sib1->servingCellConfigCommon->ssb_PositionsInBurst.groupPresence->buf[0] = 0;
+      ServCellCom->ssb_PositionsInBurst.inOneGroup.size = 1;
+      ServCellCom->ssb_PositionsInBurst.inOneGroup.bits_unused = 0;
+      ServCellCom->ssb_PositionsInBurst.groupPresence = calloc(1, sizeof(BIT_STRING_t));
+      ServCellCom->ssb_PositionsInBurst.groupPresence->size = 1;
+      ServCellCom->ssb_PositionsInBurst.groupPresence->bits_unused = 0;
+      ServCellCom->ssb_PositionsInBurst.groupPresence->buf = calloc(1, sizeof(uint8_t));
+      ServCellCom->ssb_PositionsInBurst.groupPresence->buf[0] = 0;
       for (int i=0; i<8; i++){
         bitmap8 = configuration->scc->ssb_PositionsInBurst->choice.longBitmap.buf[i];
         if (bitmap8!=0){
@@ -598,8 +587,8 @@ uint8_t do_SIB1_NR(rrc_gNB_carrier_data_t *carrier,
           else
             AssertFatal(temp_bitmap==bitmap8,"For longBitmap the groups of 8 SSBs containing at least 1 transmitted SSB should be all the same\n");
 
-          sib1->servingCellConfigCommon->ssb_PositionsInBurst.inOneGroup.buf[0] = bitmap8;
-          sib1->servingCellConfigCommon->ssb_PositionsInBurst.groupPresence->buf[0] |= 1<<(7-i);
+          ServCellCom->ssb_PositionsInBurst.inOneGroup.buf[0] = bitmap8;
+          ServCellCom->ssb_PositionsInBurst.groupPresence->buf[0] |= 1<<(7-i);
         }
       }
       break;
@@ -608,12 +597,12 @@ uint8_t do_SIB1_NR(rrc_gNB_carrier_data_t *carrier,
       break;
   }
 
-  sib1->servingCellConfigCommon->ssb_PeriodicityServingCell = *configuration->scc->ssb_periodicityServingCell;
-  sib1->servingCellConfigCommon->tdd_UL_DL_ConfigurationCommon = CALLOC(1,sizeof(struct NR_TDD_UL_DL_ConfigCommon));
-  sib1->servingCellConfigCommon->tdd_UL_DL_ConfigurationCommon->referenceSubcarrierSpacing = configuration->scc->tdd_UL_DL_ConfigurationCommon->referenceSubcarrierSpacing;
-  sib1->servingCellConfigCommon->tdd_UL_DL_ConfigurationCommon->pattern1 = configuration->scc->tdd_UL_DL_ConfigurationCommon->pattern1;
-  sib1->servingCellConfigCommon->tdd_UL_DL_ConfigurationCommon->pattern2 = configuration->scc->tdd_UL_DL_ConfigurationCommon->pattern2;
-  sib1->servingCellConfigCommon->ss_PBCH_BlockPower = configuration->scc->ss_PBCH_BlockPower;
+  ServCellCom->ssb_PeriodicityServingCell = *configuration->scc->ssb_periodicityServingCell;
+  ServCellCom->tdd_UL_DL_ConfigurationCommon = CALLOC(1,sizeof(struct NR_TDD_UL_DL_ConfigCommon));
+  ServCellCom->tdd_UL_DL_ConfigurationCommon->referenceSubcarrierSpacing = configuration->scc->tdd_UL_DL_ConfigurationCommon->referenceSubcarrierSpacing;
+  ServCellCom->tdd_UL_DL_ConfigurationCommon->pattern1 = configuration->scc->tdd_UL_DL_ConfigurationCommon->pattern1;
+  ServCellCom->tdd_UL_DL_ConfigurationCommon->pattern2 = configuration->scc->tdd_UL_DL_ConfigurationCommon->pattern2;
+  ServCellCom->ss_PBCH_BlockPower = configuration->scc->ss_PBCH_BlockPower;
 
   // ims-EmergencySupport
   // TODO: add ims-EmergencySupport
@@ -1778,6 +1767,7 @@ uint8_t do_NR_SA_UECapabilityEnquiry( const protocol_ctxt_t *const ctxt_pP,
 
 
 uint8_t do_NR_RRCRelease(uint8_t                            *buffer,
+                         size_t                              buffer_size,
                          uint8_t                             Transaction_id) {
   asn_enc_rval_t enc_rval;
   NR_DL_DCCH_Message_t dl_dcch_msg;
@@ -1803,7 +1793,7 @@ uint8_t do_NR_RRCRelease(uint8_t                            *buffer,
                                    NULL,
                                    (void *)&dl_dcch_msg,
                                    buffer,
-                                   RRC_BUF_SIZE);
+                                   buffer_size);
   if(enc_rval.encoded == -1) {
     LOG_I(NR_RRC, "[gNB AssertFatal]ASN1 message encoding failed (%s, %lu)!\n",
         enc_rval.failed_type->name, enc_rval.encoded);
@@ -1816,6 +1806,7 @@ uint8_t do_NR_RRCRelease(uint8_t                            *buffer,
 int16_t do_RRCReconfiguration(
     const protocol_ctxt_t        *const ctxt_pP,
     uint8_t                      *buffer,
+    size_t                        buffer_size,
     uint8_t                       Transaction_id,
     NR_SRB_ToAddModList_t        *SRB_configList,
     NR_DRB_ToAddModList_t        *DRB_configList,
@@ -1911,7 +1902,7 @@ int16_t do_RRCReconfiguration(
                                     NULL,
                                     (void *)&dl_dcch_msg,
                                     buffer,
-                                    1000);
+                                    buffer_size);
 
     if(enc_rval.encoded == -1) {
         LOG_I(NR_RRC, "[gNB AssertFatal]ASN1 message encoding failed (%s, %lu)!\n",
@@ -1936,7 +1927,7 @@ int16_t do_RRCReconfiguration(
 }
 
 
-uint8_t do_RRCSetupRequest(uint8_t Mod_id, uint8_t *buffer,uint8_t *rv) {
+uint8_t do_RRCSetupRequest(uint8_t Mod_id, uint8_t *buffer, size_t buffer_size, uint8_t *rv) {
   asn_enc_rval_t enc_rval;
   uint8_t buf[5],buf2=0;
   NR_UL_CCCH_Message_t ul_ccch_msg;
@@ -1980,16 +1971,51 @@ uint8_t do_RRCSetupRequest(uint8_t Mod_id, uint8_t *buffer,uint8_t *rv) {
                                    NULL,
                                    (void *)&ul_ccch_msg,
                                    buffer,
-                                   100);
+                                   buffer_size);
   AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n", enc_rval.failed_type->name, enc_rval.encoded);
   LOG_D(NR_RRC,"[UE] RRCSetupRequest Encoded %zd bits (%zd bytes)\n", enc_rval.encoded, (enc_rval.encoded+7)/8);
   return((enc_rval.encoded+7)/8);
 }
+
+//------------------------------------------------------------------------------
+uint8_t
+do_NR_RRCReconfigurationComplete_for_nsa(
+  uint8_t *buffer,
+  size_t buffer_size,
+  NR_RRC_TransactionIdentifier_t Transaction_id
+)
+//------------------------------------------------------------------------------
+{
+  NR_RRCReconfigurationComplete_t rrc_complete_msg;
+  memset(&rrc_complete_msg, 0, sizeof(rrc_complete_msg));
+  rrc_complete_msg.rrc_TransactionIdentifier = Transaction_id;
+  rrc_complete_msg.criticalExtensions.choice.rrcReconfigurationComplete =
+        CALLOC(1, sizeof(*rrc_complete_msg.criticalExtensions.choice.rrcReconfigurationComplete));
+  rrc_complete_msg.criticalExtensions.present =
+	NR_RRCReconfigurationComplete__criticalExtensions_PR_rrcReconfigurationComplete;
+  rrc_complete_msg.criticalExtensions.choice.rrcReconfigurationComplete->nonCriticalExtension = NULL;
+  rrc_complete_msg.criticalExtensions.choice.rrcReconfigurationComplete->lateNonCriticalExtension = NULL;
+  if (0) {
+    xer_fprint(stdout, &asn_DEF_NR_RRCReconfigurationComplete, (void *)&rrc_complete_msg);
+  }
+
+  asn_enc_rval_t enc_rval = uper_encode_to_buffer(&asn_DEF_NR_RRCReconfigurationComplete,
+                                                  NULL,
+                                                  (void *)&rrc_complete_msg,
+                                                  buffer,
+                                                  buffer_size);
+  AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n",
+               enc_rval.failed_type->name, enc_rval.encoded);
+  LOG_A(NR_RRC, "rrcReconfigurationComplete Encoded %zd bits (%zd bytes)\n", enc_rval.encoded, (enc_rval.encoded+7)/8);
+  return((enc_rval.encoded+7)/8);
+}
+
 //------------------------------------------------------------------------------
 uint8_t
 do_NR_RRCReconfigurationComplete(
   const protocol_ctxt_t *const ctxt_pP,
   uint8_t *buffer,
+  size_t buffer_size,
   const uint8_t Transaction_id
 )
 //------------------------------------------------------------------------------
@@ -2017,14 +2043,15 @@ do_NR_RRCReconfigurationComplete(
                                    NULL,
                                    (void *)&ul_dcch_msg,
                                    buffer,
-                                   100);
+                                   buffer_size);
   AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n",
                enc_rval.failed_type->name, enc_rval.encoded);
   LOG_I(NR_RRC,"rrcReconfigurationComplete Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);
   return((enc_rval.encoded+7)/8);
 }
 
-uint8_t do_RRCSetupComplete(uint8_t Mod_id, uint8_t *buffer, const uint8_t Transaction_id, uint8_t sel_plmn_id, const int dedicatedInfoNASLength, const char *dedicatedInfoNAS){
+uint8_t do_RRCSetupComplete(uint8_t Mod_id, uint8_t *buffer, size_t buffer_size,
+                            const uint8_t Transaction_id, uint8_t sel_plmn_id, const int dedicatedInfoNASLength, const char *dedicatedInfoNAS){
   asn_enc_rval_t enc_rval;
   
   NR_UL_DCCH_Message_t  ul_dcch_msg;
@@ -2067,7 +2094,7 @@ enc_rval = uper_encode_to_buffer(&asn_DEF_NR_UL_DCCH_Message,
                                  NULL,
                                  (void *)&ul_dcch_msg,
                                  buffer,
-                                 100);
+                                 buffer_size);
 AssertFatal(enc_rval.encoded > 0,"ASN1 message encoding failed (%s, %lu)!\n",
     enc_rval.failed_type->name,enc_rval.encoded);
 LOG_D(NR_RRC,"RRCSetupComplete Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);
@@ -2182,6 +2209,7 @@ const protocol_ctxt_t     *const ctxt_pP,
 rrc_gNB_ue_context_t      *const ue_context_pP,
 int                              CC_id,
 uint8_t                   *const buffer,
+size_t                           buffer_size,
 //const uint8_t                    transmission_mode,
 const uint8_t                    Transaction_id,
 NR_SRB_ToAddModList_t               **SRB_configList
@@ -2304,7 +2332,7 @@ NR_SRB_ToAddModList_t               **SRB_configList
 }
 
 uint8_t 
-do_RRCReestablishmentComplete(uint8_t *buffer, int64_t rrc_TransactionIdentifier) {
+do_RRCReestablishmentComplete(uint8_t *buffer, size_t buffer_size, int64_t rrc_TransactionIdentifier) {
   asn_enc_rval_t enc_rval;
   NR_UL_DCCH_Message_t ul_dcch_msg;
   NR_RRCReestablishmentComplete_t *rrcReestablishmentComplete;
@@ -2330,7 +2358,7 @@ do_RRCReestablishmentComplete(uint8_t *buffer, int64_t rrc_TransactionIdentifier
                                    NULL,
                                    (void *)&ul_dcch_msg,
                                    buffer,
-                                   100);
+                                   buffer_size);
   AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n", enc_rval.failed_type->name, enc_rval.encoded);
   LOG_D(NR_RRC,"[UE] RRCReestablishmentComplete Encoded %zd bits (%zd bytes)\n", enc_rval.encoded, (enc_rval.encoded+7)/8);
   return((enc_rval.encoded+7)/8);
diff --git a/openair2/RRC/NR/MESSAGES/asn1_msg.h b/openair2/RRC/NR/MESSAGES/asn1_msg.h
index 7b38de2bb960844f6a5fbea7c22f4ccbeb1b30be..6803cf21d7e7e4742359c968dc4a731c666afb49 100644
--- a/openair2/RRC/NR/MESSAGES/asn1_msg.h
+++ b/openair2/RRC/NR/MESSAGES/asn1_msg.h
@@ -28,6 +28,8 @@
 * \email: raymond.knopp@eurecom.fr and  navid.nikaein@eurecom.fr, kroempa@gmail.com
 */
 
+#pragma once
+
 #include <stdio.h>
 #include <sys/types.h>
 #include <stdlib.h> /* for atoi(3) */
@@ -53,6 +55,15 @@
  */
 int xer_sprint_NR(char *string, size_t string_size, struct asn_TYPE_descriptor_s *td, void *sptr);
 
+
+#define asn1cCallocOne(VaR, VaLue) \
+  VaR = calloc(1,sizeof(*VaR)); *VaR=VaLue;
+#define asn1cCalloc(VaR, lOcPtr) \
+  typeof(VaR) lOcPtr = VaR = calloc(1,sizeof(*VaR));
+#define asn1cSequenceAdd(VaR, TyPe, lOcPtr) \
+  TyPe *lOcPtr= calloc(1,sizeof(TyPe)); \
+  ASN_SEQUENCE_ADD(&VaR,lOcPtr);
+
 uint8_t do_MIB_NR(gNB_RRC_INST *rrc,
                   uint32_t frame);
 
@@ -119,12 +130,13 @@ uint8_t do_NR_SA_UECapabilityEnquiry( const protocol_ctxt_t *const ctxt_pP,
                                    uint8_t               *const buffer,
                                    const uint8_t                Transaction_id);
 
-uint8_t do_NR_RRCRelease(uint8_t *buffer,
+uint8_t do_NR_RRCRelease(uint8_t *buffer, size_t buffer_size,
                          uint8_t Transaction_id);
 
 int16_t do_RRCReconfiguration(
     const protocol_ctxt_t        *const ctxt_pP,
     uint8_t                      *buffer,
+    size_t                        buffer_size,
     uint8_t                       Transaction_id,
     NR_SRB_ToAddModList_t        *SRB_configList,
     NR_DRB_ToAddModList_t        *DRB_configList,
@@ -135,19 +147,23 @@ int16_t do_RRCReconfiguration(
     struct NR_RRCReconfiguration_v1530_IEs__dedicatedNAS_MessageList *dedicatedNAS_MessageList,
     NR_MAC_CellGroupConfig_t     *mac_CellGroupConfig,
     NR_CellGroupConfig_t         *cellGroupConfig);
-                    
-uint8_t do_RRCSetupComplete(uint8_t Mod_id, 
-                            uint8_t *buffer, 
-                            const uint8_t Transaction_id, 
-                            uint8_t sel_plmn_id, 
-                            const int dedicatedInfoNASLength, 
+
+uint8_t do_RRCSetupComplete(uint8_t Mod_id,
+                            uint8_t *buffer,
+                            size_t buffer_size,
+                            const uint8_t Transaction_id,
+                            uint8_t sel_plmn_id,
+                            const int dedicatedInfoNASLength,
                             const char *dedicatedInfoNAS);
 
-uint8_t do_RRCSetupRequest(uint8_t Mod_id, uint8_t *buffer,uint8_t *rv);
+uint8_t do_RRCSetupRequest(uint8_t Mod_id, uint8_t *buffer, size_t buffer_size, uint8_t *rv);
+
+uint8_t do_NR_RRCReconfigurationComplete_for_nsa(uint8_t *buffer, size_t buffer_size, NR_RRC_TransactionIdentifier_t Transaction_id);
 
 uint8_t do_NR_RRCReconfigurationComplete(
                         const protocol_ctxt_t *const ctxt_pP,
                         uint8_t *buffer,
+                        size_t buffer_size,
                         const uint8_t Transaction_id
                       );
 
@@ -172,6 +188,7 @@ do_RRCReestablishment(
   rrc_gNB_ue_context_t      *const ue_context_pP,
   int                              CC_id,
   uint8_t                   *const buffer,
+  size_t                           buffer_size,
   //const uint8_t                    transmission_mode,
   const uint8_t                    Transaction_id,
   NR_SRB_ToAddModList_t               **SRB_configList
@@ -179,6 +196,6 @@ do_RRCReestablishment(
 
 uint8_t 
 do_RRCReestablishmentComplete(
-    uint8_t *buffer, 
+    uint8_t *buffer, size_t buffer_size,
     int64_t rrc_TransactionIdentifier);
 
diff --git a/openair2/RRC/NR/nr_rrc_defs.h b/openair2/RRC/NR/nr_rrc_defs.h
index 7f0612dbddc917e39aa6248538b57cdaad8bca5b..a92cf9861c9e8cc0f38775f4554e9b4af625b5f0 100644
--- a/openair2/RRC/NR/nr_rrc_defs.h
+++ b/openair2/RRC/NR/nr_rrc_defs.h
@@ -123,12 +123,12 @@ typedef enum UE_STATE_NR_e {
 #define RRM_CALLOC(t,n)   (t *) malloc16( sizeof(t) * n)
 #define RRM_CALLOC2(t,s)  (t *) malloc16( s )
 
-#define MAX_MEAS_OBJ                                  6
-#define MAX_MEAS_CONFIG                               6
-#define MAX_MEAS_ID                                   6
+#define MAX_MEAS_OBJ                                  7
+#define MAX_MEAS_CONFIG                               7
+#define MAX_MEAS_ID                                   7
 
 #define PAYLOAD_SIZE_MAX                              1024
-#define RRC_BUF_SIZE                                  8192
+#define RRC_BUF_SIZE                                  512
 #define UNDEF_SECURITY_MODE                           0xff
 #define NO_SECURITY_MODE                              0x20
 
@@ -367,6 +367,8 @@ typedef struct gNB_RRC_UE_s {
   transport_layer_addr_t             gnb_gtp_addrs[S1AP_MAX_E_RAB];
   rb_id_t                            gnb_gtp_ebi[S1AP_MAX_E_RAB];
   rb_id_t                            gnb_gtp_psi[S1AP_MAX_E_RAB];
+  //GTPV1 F1-U TUNNELS
+  uint32_t                           incoming_teid[S1AP_MAX_E_RAB]; 
 
   uint32_t                           ul_failure_timer;
   uint32_t                           ue_release_timer;
diff --git a/openair2/RRC/NR/rrc_gNB.c b/openair2/RRC/NR/rrc_gNB.c
index 184bfd6384513252e20813a84cc32e7a8a188da6..2c2020412d4084df0ba6658fb9bcf497d0792aeb 100755
--- a/openair2/RRC/NR/rrc_gNB.c
+++ b/openair2/RRC/NR/rrc_gNB.c
@@ -47,6 +47,12 @@
 #include "NR_BCCH-BCH-Message.h"
 #include "NR_UL-DCCH-Message.h"
 #include "NR_DL-DCCH-Message.h"
+#include "NR_DL-CCCH-Message.h"
+#include "NR_UL-CCCH-Message.h"
+#include "NR_RRCReject.h"
+#include "NR_RejectWaitTime.h"
+#include "NR_RRCSetup.h"
+
 #include "NR_CellGroupConfig.h"
 #include "NR_MeasResults.h"
 #include "LTE_UECapabilityInformation.h"
@@ -88,6 +94,7 @@
 #include "executables/softmodem-common.h"
 #include <openair2/RRC/NR/rrc_gNB_UE_context.h>
 #include <openair2/X2AP/x2ap_eNB.h>
+#include <openair3/ocp-gtpu/gtp_itf.h>
 
 #include "BIT_STRING.h"
 #include "assertions.h"
@@ -125,6 +132,23 @@ uint8_t first_rrcreconfiguration = 0;
 ///---------------------------------------------------------------------------------------------------------------///
 ///---------------------------------------------------------------------------------------------------------------///
 
+boolean_t DURecvCb( protocol_ctxt_t  *ctxt_pP,
+                    const srb_flag_t     srb_flagP,
+                    const rb_id_t        rb_idP,
+                    const mui_t          muiP,
+                    const confirm_t      confirmP,
+                    const sdu_size_t     sdu_buffer_sizeP,
+                    unsigned char *const sdu_buffer_pP,
+                    const pdcp_transmission_mode_t modeP,
+                    const uint32_t *sourceL2Id,
+                    const uint32_t *destinationL2Id) {
+  // The buffer comes from the stack in gtp-u thread, we have a make a separate buffer to enqueue in a inter-thread message queue
+  mem_block_t *sdu=get_free_mem_block(sdu_buffer_sizeP, __func__);
+  memcpy(sdu->data,  sdu_buffer_pP,  sdu_buffer_sizeP);
+  du_rlc_data_req(ctxt_pP,srb_flagP, false,  rb_idP,muiP, confirmP,  sdu_buffer_sizeP, sdu);
+  return true;
+}
+
 void openair_nr_rrc_on(const protocol_ctxt_t *const ctxt_pP) {
   LOG_I(NR_RRC, PROTOCOL_NR_RRC_CTXT_FMT" gNB:OPENAIR NR RRC IN....\n",PROTOCOL_NR_RRC_CTXT_ARGS(ctxt_pP));
   rrc_config_nr_buffer (&RC.nrrrc[ctxt_pP->module_id]->carrier.SI, BCCH, 1);
@@ -248,6 +272,8 @@ void rrc_gNB_process_AdditionRequestInformation(const module_id_t gnb_mod_idP, x
   AssertFatal(cg_configinfo->criticalExtensions.choice.c1->present == NR_CG_ConfigInfo__criticalExtensions__c1_PR_cg_ConfigInfo,
               "ueCapabilityInformation not present\n");
   parse_CG_ConfigInfo(rrc,cg_configinfo,m);
+  LOG_A(NR_RRC, "Successfully parsed CG_ConfigInfo of size %zu bits. (%zu bytes)\n",
+        dec_rval.consumed, (dec_rval.consumed +7/8));
 }
 
 
@@ -281,7 +307,7 @@ void apply_macrlc_config(gNB_RRC_INST *rrc,
 
       nr_rrc_rlc_config_asn1_req(ctxt_pP,
                                  ue_context_pP->ue_context.SRB_configList,
-                                 NULL,
+                                 ue_context_pP->ue_context.DRB_configList,
                                  NULL,
                                  NULL,
                                  get_softmodem_params()->sa ? ue_context_pP->ue_context.masterCellGroup->rlc_BearerToAddModList : NULL);
@@ -722,8 +748,8 @@ rrc_gNB_generate_defaultRRCReconfiguration(
     dedicatedNAS_MessageList = NULL;
   }
 
-  memset(buffer, 0, RRC_BUF_SIZE);
-  size = do_RRCReconfiguration(ctxt_pP, buffer,
+  memset(buffer, 0, sizeof(buffer));
+  size = do_RRCReconfiguration(ctxt_pP, buffer, sizeof(buffer),
                                 xid,
                                 NULL, //*SRB_configList2,
                                 NULL, //*DRB_configList,
@@ -990,10 +1016,10 @@ rrc_gNB_generate_dedicatedRRCReconfiguration(
     dedicatedNAS_MessageList = NULL;
   }
 
-  memset(buffer, 0, RRC_BUF_SIZE);
+  memset(buffer, 0, sizeof(buffer));
   cellGroupConfig = calloc(1, sizeof(NR_CellGroupConfig_t));
   fill_mastercellGroupConfig(cellGroupConfig, ue_context_pP->ue_context.masterCellGroup);
-  size = do_RRCReconfiguration(ctxt_pP, buffer,
+  size = do_RRCReconfiguration(ctxt_pP, buffer, sizeof(buffer),
                                 xid,
                                 *SRB_configList2,
                                 *DRB_configList,
@@ -1101,8 +1127,8 @@ rrc_gNB_generate_dedicatedRRCReconfiguration_release(
     LOG_W(NR_RRC,"dedlicated NAS list is empty\n");
   }
 
-  memset(buffer, 0, RRC_BUF_SIZE);
-  size = do_RRCReconfiguration(ctxt_pP, buffer, xid,
+  memset(buffer, 0, sizeof(buffer));
+  size = do_RRCReconfiguration(ctxt_pP, buffer, sizeof(buffer), xid,
                                NULL,
                                NULL,
                                *DRB_Release_configList2,
@@ -1181,7 +1207,7 @@ rrc_gNB_process_RRCReconfigurationComplete(
   NR_SRB_ToAddModList_t              *SRB_configList = ue_context_pP->ue_context.SRB_configList2[xid];
   NR_DRB_ToReleaseList_t             *DRB_Release_configList2 = ue_context_pP->ue_context.DRB_Release_configList2[xid];
   NR_DRB_Identity_t                  *drb_id_p      = NULL;
-//  uint8_t                             nr_DRB2LCHAN[8];
+  //  uint8_t                             nr_DRB2LCHAN[8];
   gNB_RRC_INST *rrc = RC.nrrrc[ctxt_pP->module_id];
 
   ue_context_pP->ue_context.ue_reestablishment_timer = 0;
@@ -1245,6 +1271,49 @@ rrc_gNB_process_RRCReconfigurationComplete(
                                NULL,
                                get_softmodem_params()->sa ? ue_context_pP->ue_context.masterCellGroup->rlc_BearerToAddModList : NULL);
   }
+  else if(SRB_configList!=NULL || DRB_configList!=NULL){
+    MessageDef *message_p;
+    message_p = itti_alloc_new_message (TASK_RRC_GNB, 0, F1AP_UE_CONTEXT_SETUP_REQ);
+    f1ap_ue_context_setup_t *req=&F1AP_UE_CONTEXT_SETUP_REQ (message_p);
+    req->gNB_CU_ue_id     = 0;
+    req->gNB_DU_ue_id = 0;
+    req->rnti = ue_context_pP->ue_context.rnti;
+    req->mcc              = rrc->configuration.mcc[0];
+    req->mnc              = rrc->configuration.mnc[0];
+    req->mnc_digit_length = rrc->configuration.mnc_digit_length[0];
+    req->nr_cellid        = rrc->nr_cellid;
+    if(SRB_configList!=NULL){
+      req->srbs_to_be_setup = malloc(SRB_configList->list.count*sizeof(f1ap_srb_to_be_setup_t));
+      req->srbs_to_be_setup_length = SRB_configList->list.count;
+      f1ap_srb_to_be_setup_t *SRBs=req->srbs_to_be_setup;
+      for (int i = 0; i < SRB_configList->list.count; i++){
+        if(SRB_configList->list.array[i]->srb_Identity > 1){
+          SRBs[i].srb_id = SRB_configList->list.array[i]->srb_Identity;
+          SRBs[i].lcid = SRB_configList->list.array[i]->srb_Identity;
+        }
+      }
+    }
+    if(DRB_configList!=NULL){
+      gtpv1u_gnb_create_tunnel_req_t  create_tunnel_req;
+      memset(&create_tunnel_req, 0, sizeof(gtpv1u_gnb_create_tunnel_req_t));
+      req->drbs_to_be_setup = malloc(DRB_configList->list.count*sizeof(f1ap_drb_to_be_setup_t));
+      req->drbs_to_be_setup_length = DRB_configList->list.count;
+      f1ap_drb_to_be_setup_t *DRBs=req->drbs_to_be_setup;
+      LOG_I(RRC, "Length of DRB list:%d, %d \n", DRB_configList->list.count, req->drbs_to_be_setup_length);
+      for (int i = 0; i < DRB_configList->list.count; i++){
+        DRBs[i].drb_id = DRB_configList->list.array[i]->drb_Identity;
+        DRBs[i].rlc_mode = RLC_MODE_AM;
+        DRBs[i].up_ul_tnl[0].tl_address = inet_addr(rrc->eth_params_s.my_addr);
+        DRBs[i].up_ul_tnl[0].port=rrc->eth_params_s.my_portd;
+        DRBs[i].up_ul_tnl_length = 1;
+        DRBs[i].up_dl_tnl[0].tl_address = inet_addr(rrc->eth_params_s.remote_addr);
+        DRBs[i].up_dl_tnl[0].port=rrc->eth_params_s.remote_portd;
+        DRBs[i].up_dl_tnl_length = 1;
+      }
+      LOG_I(RRC, "Send F1AP_UE_CONTEXT_SETUP_REQ with ITTI\n");
+    }
+    itti_send_msg_to_task (TASK_CU_F1, ctxt_pP->module_id, message_p);
+  }
 #endif
 
   /* Set the SRB active in UE context */
@@ -1369,6 +1438,7 @@ rrc_gNB_generate_RRCReestablishment(
         ue_context_pP,
         CC_id,
         (uint8_t *) ue_context->Srb0.Tx_buffer.Payload,
+        sizeof(ue_context->Srb0.Tx_buffer.Payload),
         //(uint8_t) carrier->p_gNB, // at this point we do not have the UE capability information, so it can only be TM1 or TM2
         rrc_gNB_get_next_transaction_identifier(module_id),
         SRB_configList
@@ -1554,11 +1624,11 @@ rrc_gNB_process_RRCConnectionReestablishmentComplete(
       if (ue_context_pP->ue_context.pduSession[i].status == PDU_SESSION_STATUS_ESTABLISHED || ue_context_pP->ue_context.pduSession[i].status == PDU_SESSION_STATUS_DONE) {
         create_tunnel_req.pdusession_id[j]   = ue_context_pP->ue_context.pduSession[i].param.pdusession_id;
         create_tunnel_req.incoming_rb_id[j]  = i+1;
-        create_tunnel_req.upf_NGu_teid[j]  = ue_context_pP->ue_context.pduSession[i].param.gtp_teid;
-        memcpy(create_tunnel_req.upf_addr[j].buffer,
+        create_tunnel_req.outgoing_teid[j]  = ue_context_pP->ue_context.pduSession[i].param.gtp_teid;
+        memcpy(create_tunnel_req.dst_addr[j].buffer,
                ue_context_pP->ue_context.pduSession[i].param.upf_addr.buffer,
                 sizeof(uint8_t)*20);
-        create_tunnel_req.upf_addr[j].length = ue_context_pP->ue_context.pduSession[i].param.upf_addr.length;
+        create_tunnel_req.dst_addr[j].length = ue_context_pP->ue_context.pduSession[i].param.upf_addr.length;
         j++;
       }
     }
@@ -1624,9 +1694,9 @@ rrc_gNB_process_RRCConnectionReestablishmentComplete(
           i, ue_context_pP->ue_context.pduSession[i].status, "PDU_SESSION_STATUS_DONE");
   }
 
-  memset(buffer, 0, RRC_BUF_SIZE);
+  memset(buffer, 0, sizeof(buffer));
 
-  size = do_RRCReconfiguration(ctxt_pP, buffer,
+  size = do_RRCReconfiguration(ctxt_pP, buffer, sizeof(buffer),
                                 xid,
                                *SRB_configList2,
                                 DRB_configList,
@@ -2619,16 +2689,19 @@ rrc_gNB_decode_dcch(
 void rrc_gNB_process_f1_setup_req(f1ap_setup_req_t *f1_setup_req) {
   LOG_I(NR_RRC,"Received F1 Setup Request from gNB_DU %llu (%s)\n",(unsigned long long int)f1_setup_req->gNB_DU_id,f1_setup_req->gNB_DU_name);
   int cu_cell_ind = 0;
-  MessageDef *msg_p = NULL,*msg_p2=NULL;
+  MessageDef *msg_p =itti_alloc_new_message (TASK_RRC_GNB, 0, F1AP_SETUP_RESP);
+  F1AP_SETUP_RESP (msg_p).num_cells_to_activate = 0;
+  MessageDef *msg_p2=itti_alloc_new_message (TASK_RRC_GNB, 0, F1AP_GNB_CU_CONFIGURATION_UPDATE);
 
   for (int i = 0; i < f1_setup_req->num_cells_available; i++) {
-    int found_cell=0;
     for (int j=0; j<RC.nb_nr_inst; j++) {
       gNB_RRC_INST *rrc = RC.nrrrc[j];
 
-      if (rrc->configuration.mcc[0] == f1_setup_req->mcc[i] &&
-          rrc->configuration.mnc[0] == f1_setup_req->mnc[i] &&
-          rrc->nr_cellid == f1_setup_req->nr_cellid[i]) {
+      if (rrc->configuration.mcc[0] == f1_setup_req->cell[i].mcc &&
+          rrc->configuration.mnc[0] == f1_setup_req->cell[i].mnc &&
+          rrc->nr_cellid == f1_setup_req->cell[i].nr_cellid) {
+	//fixme: multi instance is not consistent here
+	F1AP_SETUP_RESP (msg_p).gNB_CU_name  = rrc->node_name;
         // check that CU rrc instance corresponds to mcc/mnc/cgi (normally cgi should be enough, but just in case)
         rrc->carrier.MIB = malloc(f1_setup_req->mib_length[i]);
         rrc->carrier.sizeof_MIB = f1_setup_req->mib_length[i];
@@ -2641,7 +2714,7 @@ void rrc_gNB_process_f1_setup_req(f1ap_setup_req_t *f1_setup_req) {
                                   f1_setup_req->mib[i],
                                   f1_setup_req->mib_length[i]);
         AssertFatal(dec_rval.code == RC_OK,
-                    "[gNB_DU %"PRIu8"] Failed to decode NR_BCCH_BCH_MESSAGE (%zu bits)\n",
+                    "[gNB_CU %"PRIu8"] Failed to decode NR_BCCH_BCH_MESSAGE (%zu bits)\n",
                     j,
                     dec_rval.consumed );
         NR_BCCH_BCH_Message_t *mib = &rrc->carrier.mib;
@@ -2671,27 +2744,14 @@ void rrc_gNB_process_f1_setup_req(f1ap_setup_req_t *f1_setup_req) {
         AssertFatal(bcch_message->message.choice.c1->present == NR_BCCH_DL_SCH_MessageType__c1_PR_systemInformationBlockType1,
                     "bcch_message->message.choice.c1->present != NR_BCCH_DL_SCH_MessageType__c1_PR_systemInformationBlockType1\n");
         rrc->carrier.sib1 = bcch_message->message.choice.c1->choice.systemInformationBlockType1;
-        rrc->carrier.physCellId = f1_setup_req->nr_pci[i];
-	if (cu_cell_ind == 0) {
-	  // prepare F1_SETUP_RESPONSE + GNB_CU_CONFIGURATION_UPDATE
-	  if (msg_p == NULL) {
-	    msg_p = itti_alloc_new_message (TASK_RRC_GNB, 0, F1AP_SETUP_RESP);
-	  }
-	  if (msg_p2 == NULL) {
-	    msg_p2 = itti_alloc_new_message (TASK_RRC_GNB, 0, F1AP_GNB_CU_CONFIGURATION_UPDATE);
-	  }
-
-	  F1AP_SETUP_RESP (msg_p).gNB_CU_name                                = rrc->node_name;
-	  F1AP_SETUP_RESP (msg_p).num_cells_to_activate = 0;
-
-	}
+        rrc->carrier.physCellId = f1_setup_req->cell[i].nr_pci;
 
 	F1AP_GNB_CU_CONFIGURATION_UPDATE (msg_p2).gNB_CU_name                                = rrc->node_name;
 	F1AP_GNB_CU_CONFIGURATION_UPDATE (msg_p2).cells_to_activate[cu_cell_ind].mcc                           = rrc->configuration.mcc[0];
 	F1AP_GNB_CU_CONFIGURATION_UPDATE (msg_p2).cells_to_activate[cu_cell_ind].mnc                           = rrc->configuration.mnc[0];
 	F1AP_GNB_CU_CONFIGURATION_UPDATE (msg_p2).cells_to_activate[cu_cell_ind].mnc_digit_length              = rrc->configuration.mnc_digit_length[0];
 	F1AP_GNB_CU_CONFIGURATION_UPDATE (msg_p2).cells_to_activate[cu_cell_ind].nr_cellid                     = rrc->nr_cellid;
-	F1AP_GNB_CU_CONFIGURATION_UPDATE (msg_p2).cells_to_activate[cu_cell_ind].nrpci                         = f1_setup_req->nr_pci[i];
+	F1AP_GNB_CU_CONFIGURATION_UPDATE (msg_p2).cells_to_activate[cu_cell_ind].nrpci                         = f1_setup_req->cell[i].nr_pci;
         int num_SI= 0;
 
         if (rrc->carrier.SIB23) {
@@ -2702,22 +2762,20 @@ void rrc_gNB_process_f1_setup_req(f1ap_setup_req_t *f1_setup_req) {
 
         F1AP_GNB_CU_CONFIGURATION_UPDATE (msg_p2).cells_to_activate[cu_cell_ind].num_SI = num_SI;
         cu_cell_ind++;
-        found_cell=1;
 	F1AP_GNB_CU_CONFIGURATION_UPDATE (msg_p2).num_cells_to_activate = cu_cell_ind;
 	// send
         break;
       } else {// setup_req mcc/mnc match rrc internal list element
         LOG_W(NR_RRC,"[Inst %d] No matching MCC/MNC: rrc->mcc/f1_setup_req->mcc %d/%d rrc->mnc/f1_setup_req->mnc %d/%d rrc->nr_cellid/f1_setup_req->nr_cellid %ld/%ld \n",
-              j, rrc->configuration.mcc[0], f1_setup_req->mcc[i],
-                 rrc->configuration.mnc[0], f1_setup_req->mnc[i],
-                 rrc->nr_cellid, f1_setup_req->nr_cellid[i]);
+              j, rrc->configuration.mcc[0], f1_setup_req->cell[i].mcc,
+                 rrc->configuration.mnc[0], f1_setup_req->cell[i].mnc,
+                 rrc->nr_cellid, f1_setup_req->cell[i].nr_cellid);
       }
     }// for (int j=0;j<RC.nb_inst;j++)
 
-    if (found_cell == 0) {
+    if (cu_cell_ind == 0) {
       AssertFatal(1 == 0, "No cell found\n");
-    }
-    else {
+    }  else {
       // send ITTI message to F1AP-CU task
       itti_send_msg_to_task (TASK_CU_F1, 0, msg_p);
 
@@ -2741,6 +2799,421 @@ void rrc_gNB_process_dc_overall_timeout(const module_id_t gnb_mod_idP, x2ap_ENDC
   rrc_remove_nsa_user(rrc, m->rnti);
 }
 
+static int  rrc_process_DU_DL(MessageDef *msg_p, const char *msg_name, instance_t instance) {
+  NRDuDlReq_t * req=&NRDuDlReq(msg_p);
+  protocol_ctxt_t ctxt;
+  ctxt.rnti      = req->rnti;
+  ctxt.module_id = instance;
+  ctxt.instance  = instance;
+  ctxt.enb_flag  = 1;
+  gNB_RRC_INST *rrc = RC.nrrrc[ctxt.module_id];
+  struct rrc_gNB_ue_context_s *ue_context_p =
+    rrc_gNB_get_ue_context(rrc, ctxt.rnti);
+
+  if (req->srb_id == 0) {
+    NR_DL_CCCH_Message_t *dl_ccch_msg=NULL;
+    asn_dec_rval_t dec_rval;
+    dec_rval = uper_decode(NULL,
+                           &asn_DEF_NR_DL_CCCH_Message,
+                           (void **)&dl_ccch_msg,
+                           req->buf->data,
+                           req->buf->size,0,0);
+    AssertFatal(dec_rval.code == RC_OK, "could not decode F1AP message\n");
+
+    switch (dl_ccch_msg->message.choice.c1->present) {
+    case NR_DL_CCCH_MessageType__c1_PR_NOTHING:
+      LOG_I(F1AP,"Received PR_NOTHING on DL-CCCH-Message\n");
+      break;
+
+    case NR_DL_CCCH_MessageType__c1_PR_rrcReject:
+      LOG_I(F1AP,"Logical Channel DL-CCCH (SRB0), Received RRCReject\n");
+      break;
+
+    case NR_DL_CCCH_MessageType__c1_PR_rrcSetup: {
+      LOG_I(F1AP, "Logical Channel DL-CCCH (SRB0), Received RRCSetup RNTI %x\n",
+	    req->rnti);
+      // Get configuration
+      NR_RRCSetup_t *rrcSetup = dl_ccch_msg->message.choice.c1->choice.rrcSetup;
+      AssertFatal(rrcSetup!=NULL, "rrcSetup is null\n");
+      NR_RRCSetup_IEs_t *rrcSetup_ies = rrcSetup->criticalExtensions.choice.rrcSetup;
+      ue_context_p->ue_context.SRB_configList = rrcSetup_ies->radioBearerConfig.srb_ToAddModList;
+      AssertFatal(rrcSetup_ies->masterCellGroup.buf!=NULL,"masterCellGroup is null\n");
+      asn_dec_rval_t dec_rval;
+      dec_rval = uper_decode(NULL,
+			     &asn_DEF_NR_CellGroupConfig,
+			     (void **)&ue_context_p->ue_context.masterCellGroup,
+			     rrcSetup_ies->masterCellGroup.buf,
+			     rrcSetup_ies->masterCellGroup.size,0,0);
+      AssertFatal(dec_rval.code == RC_OK, "could not decode masterCellGroup\n");
+      apply_macrlc_config(rrc,ue_context_p,&ctxt);
+      gNB_RRC_UE_t *ue_p = &ue_context_p->ue_context;
+      AssertFatal(ue_p->Srb0.Active == 1,"SRB0 is not active\n");
+      memcpy((void *)ue_p->Srb0.Tx_buffer.Payload,
+	     (void *)req->buf->data,
+	     req->buf->size); // ie->value.choice.RRCContainer.size
+      ue_p->Srb0.Tx_buffer.payload_size = req->buf->size;
+      break;
+    } // case
+      
+    case NR_DL_CCCH_MessageType__c1_PR_spare2:
+      LOG_I(F1AP,
+	    "Logical Channel DL-CCCH (SRB0), Received spare2\n");
+      break;
+      
+    case NR_DL_CCCH_MessageType__c1_PR_spare1:
+      LOG_I(F1AP,
+	    "Logical Channel DL-CCCH (SRB0), Received spare1\n");
+      break;
+      
+    default:
+      AssertFatal(1==0,
+		  "Unknown message\n");
+      break;
+    }// switch case
+    
+    return(0);
+  } else if (req->srb_id == 1) {
+    NR_DL_DCCH_Message_t *dl_dcch_msg=NULL;
+    asn_dec_rval_t dec_rval;
+    dec_rval = uper_decode(NULL,
+			   &asn_DEF_NR_DL_DCCH_Message,
+			   (void **)&dl_dcch_msg,
+			   &req->buf->data[2], // buf[0] includes the pdcp header
+			   req->buf->size-6,0,0);
+    
+    if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0))
+      LOG_E(F1AP," Failed to decode DL-DCCH (%zu bytes)\n",dec_rval.consumed);
+    else
+      LOG_D(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 == NR_DL_DCCH_MessageType_PR_c1) {
+      switch (dl_dcch_msg->message.choice.c1->present) {
+      case NR_DL_DCCH_MessageType__c1_PR_NOTHING:
+	LOG_I(F1AP, "Received PR_NOTHING on DL-DCCH-Message\n");
+	return 0;
+	
+      case NR_DL_DCCH_MessageType__c1_PR_rrcReconfiguration:
+	// handle RRCReconfiguration
+	LOG_I(F1AP, "Logical Channel DL-DCCH (SRB1), Received RRCReconfiguration RNTI %x\n",
+	      req->rnti);
+	NR_RRCReconfiguration_t *rrcReconfiguration = dl_dcch_msg->message.choice.c1->choice.rrcReconfiguration;
+	
+	if (rrcReconfiguration->criticalExtensions.present == NR_RRCReconfiguration__criticalExtensions_PR_rrcReconfiguration) {
+	  NR_RRCReconfiguration_IEs_t *rrcReconfiguration_ies =
+	    rrcReconfiguration->criticalExtensions.choice.rrcReconfiguration;
+	  
+	  if (rrcReconfiguration_ies->measConfig != NULL) {
+	    LOG_I(F1AP, "Measurement Configuration is present\n");
+	  }
+	  
+	  if (rrcReconfiguration_ies->radioBearerConfig) {
+	    LOG_I(F1AP, "Radio Resource Configuration is present\n");
+	    long drb_id;
+	    int i;
+	    NR_DRB_ToAddModList_t  *DRB_configList  = rrcReconfiguration_ies->radioBearerConfig->drb_ToAddModList;
+	    NR_SRB_ToAddModList_t  *SRB_configList  = rrcReconfiguration_ies->radioBearerConfig->srb_ToAddModList;
+	    
+	    // NR_DRB_ToReleaseList_t *DRB_ReleaseList = rrcReconfiguration_ies->radioBearerConfig->drb_ToReleaseList;
+	    
+	    // rrc_rlc_config_asn1_req
+	    
+	    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_p->ue_context.Srb1.Active=1;
+		} else if (SRB_configList->list.array[i]->srb_Identity == 2 )  {
+		  ue_context_p->ue_context.Srb2.Active=1;
+		  ue_context_p->ue_context.Srb2.Srb_info.Srb_id=2;
+		  LOG_I(F1AP, "[DU %d] SRB2 is now active\n",ctxt.module_id);
+		} else {
+		  LOG_W(F1AP, "[DU %d] invalide SRB identity %ld\n",ctxt.module_id,
+			SRB_configList->list.array[i]->srb_Identity);
+		}
+	      }
+	    }
+	    
+	    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;
+		  LOG_I(F1AP,
+			"[DU %d] Logical Channel UL-DCCH, Received RRCConnectionReconfiguration for UE rnti %x, reconfiguring DRB %d\n",
+			ctxt.module_id,
+			ctxt.rnti,
+			(int)DRB_configList->list.array[i]->drb_Identity);
+		  
+		  // (int)*DRB_configList->list.array[i]->logicalChannelIdentity);
+		  
+		  if (ue_context_p->ue_context.DRB_active[drb_id] == 0) {
+		    ue_context_p->ue_context.DRB_active[drb_id] = 1;
+		    // logicalChannelIdentity
+		    // rrc_mac_config_req_eNB
+		  }
+		} else {        // remove LCHAN from MAC/PHY
+		  AssertFatal(1==0,"Can't handle this yet in DU\n");
+		}
+	      }
+	    }
+	  }
+	}
+	
+	break;
+	
+      case NR_DL_DCCH_MessageType__c1_PR_rrcResume:
+	LOG_I(F1AP,"Received rrcResume\n");
+	break;
+	
+      case NR_DL_DCCH_MessageType__c1_PR_rrcRelease:
+	LOG_I(F1AP,"Received rrcRelease\n");
+	break;
+	
+      case NR_DL_DCCH_MessageType__c1_PR_rrcReestablishment:
+	LOG_I(F1AP,"Received rrcReestablishment\n");
+	break;
+	
+      case NR_DL_DCCH_MessageType__c1_PR_securityModeCommand:
+	LOG_I(F1AP,"Received securityModeCommand\n");
+	break;
+	
+      case NR_DL_DCCH_MessageType__c1_PR_dlInformationTransfer:
+	LOG_I(F1AP, "Received dlInformationTransfer\n");
+	break;
+	
+      case NR_DL_DCCH_MessageType__c1_PR_ueCapabilityEnquiry:
+	LOG_I(F1AP, "Received ueCapabilityEnquiry\n");
+	break;
+	
+      case NR_DL_DCCH_MessageType__c1_PR_counterCheck:
+	LOG_I(F1AP, "Received counterCheck\n");
+	break;
+	
+      case NR_DL_DCCH_MessageType__c1_PR_mobilityFromNRCommand:
+      case NR_DL_DCCH_MessageType__c1_PR_dlDedicatedMessageSegment_r16:
+      case NR_DL_DCCH_MessageType__c1_PR_ueInformationRequest_r16:
+      case NR_DL_DCCH_MessageType__c1_PR_dlInformationTransferMRDC_r16:
+      case NR_DL_DCCH_MessageType__c1_PR_loggedMeasurementConfiguration_r16:
+      case NR_DL_DCCH_MessageType__c1_PR_spare3:
+      case NR_DL_DCCH_MessageType__c1_PR_spare2:
+      case NR_DL_DCCH_MessageType__c1_PR_spare1:
+	break;
+      }
+    }
+  } else if (req->srb_id == 2) {
+    // TODO
+    //abort();
+  }
+  
+  LOG_I(F1AP, "Received DL RRC Transfer on srb_id %ld\n", req->srb_id);
+  //   rlc_op_status_t    rlc_status;
+  //   boolean_t          ret             = TRUE;
+  
+  //LOG_I(F1AP, "PRRCContainer size %lu:", ie->value.choice.RRCContainer.size);
+  //for (int i = 0; i < ie->value.choice.RRCContainer.size; i++)
+  //  printf("%02x ", ie->value.choice.RRCContainer.buf[i]);
+  
+  //printf (", PDCP PDU size %d:", rrc_dl_sdu_len);
+  //for (int i=0;i<rrc_dl_sdu_len;i++) printf("%2x ",pdcp_pdu_p->data[i]);
+  //printf("\n");
+  
+  du_rlc_data_req(&ctxt, 1, 0, req->srb_id , 1, 0, req->buf->size, req->buf);
+  //   rlc_status = rlc_data_req(&ctxt
+  //                             , 1
+  //                             , MBMS_FLAG_NO
+  //                             , srb_id
+  //                             , 0
+  //                             , 0
+  //                             , rrc_dl_sdu_len
+  //                             , pdcp_pdu_p
+  //                             ,NULL
+  //                             ,NULL
+  //                             );
+  //   switch (rlc_status) {
+  //     case RLC_OP_STATUS_OK:
+  //       //LOG_I(F1AP, "Data sending request over RLC succeeded!\n");
+  //       ret=TRUE;
+  //       break;
+  //     case RLC_OP_STATUS_BAD_PARAMETER:
+  //       LOG_W(F1AP, "Data sending request over RLC failed with 'Bad Parameter' reason!\n");
+  //       ret= FALSE;
+  //       break;
+  //     case RLC_OP_STATUS_INTERNAL_ERROR:
+  //       LOG_W(F1AP, "Data sending request over RLC failed with 'Internal Error' reason!\n");
+  //       ret= FALSE;
+  //       break;
+  //     case RLC_OP_STATUS_OUT_OF_RESSOURCES:
+  //       LOG_W(F1AP, "Data sending request over RLC failed with 'Out of Resources' reason!\n");
+  //       ret= FALSE;
+  //       break;
+  //     default:
+  //       LOG_W(F1AP, "RLC returned an unknown status code after PDCP placed the order to send some data (Status Code:%d)\n", rlc_status);
+  //       ret= FALSE;
+  //       break;
+  //   } // switch case
+  //   return ret;
+return 0;
+}
+
+static void rrc_DU_process_ue_context_setup_request(MessageDef *msg_p, const char *msg_name, instance_t instance){
+
+  f1ap_ue_context_setup_t * req=&F1AP_UE_CONTEXT_SETUP_REQ(msg_p);
+  protocol_ctxt_t ctxt;
+  ctxt.rnti      = req->rnti;
+  ctxt.module_id = instance;
+  ctxt.instance  = instance;
+  ctxt.enb_flag  = 1;
+  gNB_RRC_INST *rrc = RC.nrrrc[ctxt.module_id];
+  gNB_MAC_INST *mac = RC.nrmac[ctxt.module_id];
+  struct rrc_gNB_ue_context_s *ue_context_p =
+      rrc_gNB_get_ue_context(rrc, ctxt.rnti);
+  MessageDef *message_p;
+  message_p = itti_alloc_new_message (TASK_RRC_GNB, 0, F1AP_UE_CONTEXT_SETUP_RESP);
+  f1ap_ue_context_setup_t * resp=&F1AP_UE_CONTEXT_SETUP_RESP(message_p);
+  uint32_t incoming_teid = 0;
+
+
+  NR_CellGroupConfig_t *cellGroupConfig;
+  cellGroupConfig = calloc(1, sizeof(NR_CellGroupConfig_t));
+  fill_mastercellGroupConfig(cellGroupConfig, ue_context_p->ue_context.masterCellGroup);
+
+  /* Configure SRB2 */
+  NR_SRB_ToAddMod_t            *SRB2_config          = NULL;
+  NR_SRB_ToAddModList_t        *SRB_configList       = NULL;
+  uint8_t SRBs_before_new_addition = 0;
+
+  if(req->srbs_to_be_setup_length>0){
+    if(ue_context_p->ue_context.SRB_configList == NULL){
+      LOG_W(NR_RRC, "The SRB list of the UE context is empty before the addition of new SRB at the DU \n");
+      ue_context_p->ue_context.SRB_configList = CALLOC(1, sizeof(*ue_context_p->ue_context.SRB_configList));
+    }
+    SRB_configList = ue_context_p->ue_context.SRB_configList;
+    SRBs_before_new_addition = SRB_configList->list.count;
+    for (int i=0; i<req->srbs_to_be_setup_length; i++){
+      SRB2_config = CALLOC(1, sizeof(*SRB2_config));
+      SRB2_config->srb_Identity = req->srbs_to_be_setup[i].srb_id;
+      ASN_SEQUENCE_ADD(&SRB_configList->list, SRB2_config);
+    }
+  }
+
+  /* Configure DRB */
+  NR_DRB_ToAddMod_t            *DRB_config          = NULL;
+  NR_DRB_ToAddModList_t        *DRB_configList      = NULL;
+  if(req->drbs_to_be_setup_length>0){
+    if(ue_context_p->ue_context.DRB_configList == NULL){
+      ue_context_p->ue_context.DRB_configList = CALLOC(1, sizeof(*ue_context_p->ue_context.DRB_configList));
+    }
+    DRB_configList = ue_context_p->ue_context.DRB_configList;
+    for (int i=0; i<req->drbs_to_be_setup_length; i++){
+      DRB_config = CALLOC(1, sizeof(*DRB_config));
+      DRB_config->drb_Identity = req->drbs_to_be_setup[i].drb_id;
+      ASN_SEQUENCE_ADD(&DRB_configList->list, DRB_config);
+      f1ap_drb_to_be_setup_t drb_p = req->drbs_to_be_setup[i];
+      transport_layer_addr_t addr;
+      memcpy(addr.buffer, &drb_p.up_ul_tnl[0].tl_address, sizeof(drb_p.up_ul_tnl[0].tl_address));
+      addr.length=sizeof(drb_p.up_ul_tnl[0].tl_address)*8;
+      extern instance_t DUuniqInstance;
+      incoming_teid=newGtpuCreateTunnel(DUuniqInstance,
+          req->rnti,
+          drb_p.drb_id,
+          drb_p.drb_id,
+          drb_p.up_ul_tnl[0].teid,
+          addr,
+          drb_p.up_ul_tnl[0].port,
+          DURecvCb);
+    }
+  }
+
+  apply_macrlc_config(rrc, ue_context_p, &ctxt);
+  /* Fill the UE context setup response ITTI message to send to F1AP */
+  resp->gNB_CU_ue_id = req->gNB_CU_ue_id;
+  resp->rnti = ctxt.rnti;
+  if(DRB_configList){ 
+    if(DRB_configList->list.count > 0){
+      resp->drbs_to_be_setup = calloc(1,DRB_configList->list.count*sizeof(f1ap_drb_to_be_setup_t));
+      resp->drbs_to_be_setup_length = DRB_configList->list.count;
+      for (int i=0; i<DRB_configList->list.count; i++){
+        resp->drbs_to_be_setup[i].drb_id = DRB_configList->list.array[i]->drb_Identity;
+        resp->drbs_to_be_setup[i].rlc_mode = RLC_MODE_AM;
+        resp->drbs_to_be_setup[i].up_dl_tnl[0].teid = incoming_teid;
+        resp->drbs_to_be_setup[i].up_dl_tnl[0].tl_address = inet_addr(mac->eth_params_n.my_addr);
+        resp->drbs_to_be_setup[i].up_dl_tnl_length = 1;
+      }
+    }
+    else{
+      LOG_W(NR_RRC, "No DRB added upon reception of F1 UE context setup request with a DRB to setup list\n");
+    }
+  }
+  if(SRB_configList){
+    if(SRB_configList->list.count >0 && SRBs_before_new_addition < SRB_configList->list.count){
+      resp->srbs_to_be_setup = calloc(1,req->srbs_to_be_setup_length*sizeof(f1ap_srb_to_be_setup_t));
+      resp->srbs_to_be_setup_length = req->srbs_to_be_setup_length;
+      for (int i=SRBs_before_new_addition; i<SRB_configList->list.count; i++){
+        resp->srbs_to_be_setup[i-SRBs_before_new_addition].srb_id = SRB_configList->list.array[i]->srb_Identity;
+      }
+    }
+    else{
+      LOG_W(NR_RRC, "No SRB added upon reception of F1 UE Context setup request at the DU\n");
+    }
+  }
+  else{
+    LOG_W(NR_RRC, "No SRB added upon reception of F1 UE Context setup request at the DU\n");
+  }
+  resp->du_to_cu_rrc_information = calloc(1,1024*sizeof(uint8_t));
+  asn_enc_rval_t enc_rval = uper_encode_to_buffer(&asn_DEF_NR_CellGroupConfig,
+                                NULL,
+                                (void *)cellGroupConfig,
+                                resp->du_to_cu_rrc_information,
+                                1024);
+  resp->du_to_cu_rrc_information_length = (enc_rval.encoded+7)>>3;
+  free(cellGroupConfig);
+  itti_send_msg_to_task (TASK_DU_F1, ctxt.module_id, message_p);
+}
+
+static void rrc_CU_process_ue_context_setup_response(MessageDef *msg_p, const char *msg_name, instance_t instance){
+
+  f1ap_ue_context_setup_t * resp=&F1AP_UE_CONTEXT_SETUP_RESP(msg_p);
+  protocol_ctxt_t ctxt;
+  ctxt.rnti      = resp->rnti;
+  ctxt.module_id = instance;
+  ctxt.instance  = instance;
+  ctxt.enb_flag  = 1;
+  gNB_RRC_INST *rrc = RC.nrrrc[ctxt.module_id];
+  struct rrc_gNB_ue_context_s *ue_context_p = rrc_gNB_get_ue_context(rrc, ctxt.rnti);
+  NR_CellGroupConfig_t *cellGroupConfig = NULL;
+
+  asn_dec_rval_t dec_rval = uper_decode_complete( NULL,
+    &asn_DEF_NR_CellGroupConfig,
+    (void **)&cellGroupConfig,
+    (uint8_t *)resp->du_to_cu_rrc_information,
+    (int) resp->du_to_cu_rrc_information_length);
+
+  if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0)) {
+    AssertFatal(1==0,"Cell group config decode error\n");
+    // free the memory
+    SEQUENCE_free( &asn_DEF_NR_CellGroupConfig, cellGroupConfig, 1 );
+    return;
+  }
+  //xer_fprint(stdout,&asn_DEF_NR_CellGroupConfig, cellGroupConfig);
+
+  if(ue_context_p->ue_context.masterCellGroup == NULL){
+    ue_context_p->ue_context.masterCellGroup = calloc(1, sizeof(NR_CellGroupConfig_t));
+  }
+  if(cellGroupConfig->rlc_BearerToAddModList!=NULL){
+    if(ue_context_p->ue_context.masterCellGroup->rlc_BearerToAddModList != NULL){
+      LOG_I(NR_RRC, "rlc_BearerToAddModList not empty before filling it \n");
+      free(ue_context_p->ue_context.masterCellGroup->rlc_BearerToAddModList);
+    }
+    ue_context_p->ue_context.masterCellGroup->rlc_BearerToAddModList = calloc(1, sizeof(*cellGroupConfig->rlc_BearerToAddModList));
+    memcpy(ue_context_p->ue_context.masterCellGroup->rlc_BearerToAddModList, cellGroupConfig->rlc_BearerToAddModList,
+        sizeof(*cellGroupConfig->rlc_BearerToAddModList));
+  }
+  xer_fprint(stdout,&asn_DEF_NR_CellGroupConfig, ue_context_p->ue_context.masterCellGroup);
+
+  free(cellGroupConfig->rlc_BearerToAddModList);
+  free(cellGroupConfig);
+
+}
+
 unsigned int mask_flip(unsigned int x) {
   return((((x>>8) + (x<<8))&0xffff)>>6);
 }
@@ -3053,7 +3526,6 @@ void *rrc_gnb_task(void *args_p) {
                         .frame=-1,
                         .subframe=-1,
                         .eNB_index=0,
-                        .configured=true,
                         .brOption=false
                        };
   itti_mark_task_ready(TASK_RRC_GNB);
@@ -3085,36 +3557,46 @@ void *rrc_gnb_task(void *args_p) {
 
       /* Messages from MAC */
       case NR_RRC_MAC_CCCH_DATA_IND:
-        PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt,
-            NR_RRC_MAC_CCCH_DATA_IND(msg_p).gnb_index,
-            GNB_FLAG_YES,
-            NR_RRC_MAC_CCCH_DATA_IND(msg_p).rnti,
-            msg_p->ittiMsgHeader.lte_time.frame,
-            msg_p->ittiMsgHeader.lte_time.slot);
-        LOG_I(NR_RRC,"Decoding CCCH : ue %d, inst %ld, CC_id %d, ctxt %p, sib_info_p->Rx_buffer.payload_size %d\n",
-            ctxt.rnti,
-            instance,
-            NR_RRC_MAC_CCCH_DATA_IND(msg_p).CC_id,
-            &ctxt,
-            NR_RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size);
-
-        if (NR_RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size >= CCCH_SDU_SIZE) {
-          LOG_I(NR_RRC, "CCCH message has size %d > %d\n",
-              NR_RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size,CCCH_SDU_SIZE);
-          break;
-      }
-
-      nr_rrc_gNB_decode_ccch(&ctxt,
-                             (uint8_t *)NR_RRC_MAC_CCCH_DATA_IND(msg_p).sdu,
-                             NR_RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size,
-                             NR_RRC_MAC_CCCH_DATA_IND(msg_p).du_to_cu_rrc_container,
-                             NR_RRC_MAC_CCCH_DATA_IND(msg_p).CC_id);
-
-      if (NR_RRC_MAC_CCCH_DATA_IND(msg_p).du_to_cu_rrc_container) {
-        free(NR_RRC_MAC_CCCH_DATA_IND(msg_p).du_to_cu_rrc_container->buf);
-        free(NR_RRC_MAC_CCCH_DATA_IND(msg_p).du_to_cu_rrc_container);
-      }
+	{
+	  instance_t i;
+	  for (i=0; i<RC.nb_nr_inst; i++) {
+	    // first get RRC instance (note, no the ITTI instance)
+	    gNB_RRC_INST *rrc = RC.nrrrc[i];
+	    
+	    if (rrc->nr_cellid == NR_RRC_MAC_CCCH_DATA_IND(msg_p).nr_cellid)
+	      break;
+	  }
+	  AssertFatal(i!=RC.nb_nr_inst, "Cell_id not found\n");
+	  PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt,
+					i,
+					GNB_FLAG_YES,
+					NR_RRC_MAC_CCCH_DATA_IND(msg_p).rnti,
+					msg_p->ittiMsgHeader.lte_time.frame,
+					msg_p->ittiMsgHeader.lte_time.slot);
+	  LOG_I(NR_RRC,"Decoding CCCH : ue %d, inst %ld, CC_id %d, ctxt %p, sib_info_p->Rx_buffer.payload_size %d\n",
+		ctxt.rnti,
+		i,
+		NR_RRC_MAC_CCCH_DATA_IND(msg_p).CC_id,
+		&ctxt,
+		NR_RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size);
+	  
+	  if (NR_RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size >= CCCH_SDU_SIZE) {
+	    LOG_I(NR_RRC, "CCCH message has size %d > %d\n",
+		  NR_RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size,CCCH_SDU_SIZE);
+	    break;
+	  }
 
+	  nr_rrc_gNB_decode_ccch(&ctxt,
+				 (uint8_t *)NR_RRC_MAC_CCCH_DATA_IND(msg_p).sdu,
+				 NR_RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size,
+				 NR_RRC_MAC_CCCH_DATA_IND(msg_p).du_to_cu_rrc_container,
+				 NR_RRC_MAC_CCCH_DATA_IND(msg_p).CC_id);
+	  
+	  if (NR_RRC_MAC_CCCH_DATA_IND(msg_p).du_to_cu_rrc_container) {
+	    free(NR_RRC_MAC_CCCH_DATA_IND(msg_p).du_to_cu_rrc_container->buf);
+	    free(NR_RRC_MAC_CCCH_DATA_IND(msg_p).du_to_cu_rrc_container);
+	  }
+	}
       break;
 
       /* Messages from PDCP */
@@ -3170,6 +3652,18 @@ void *rrc_gnb_task(void *args_p) {
         LOG_I(NR_RRC,"[gNB %ld] Received %s : %p\n", instance, msg_name_p, &F1AP_SETUP_REQ(msg_p));
         rrc_gNB_process_f1_setup_req(&F1AP_SETUP_REQ(msg_p));
         break;
+	
+    case NR_DU_RRC_DL_INDICATION:
+      rrc_process_DU_DL(msg_p, msg_name_p, instance);
+      break;
+      
+    case F1AP_UE_CONTEXT_SETUP_REQ:
+      rrc_DU_process_ue_context_setup_request(msg_p, msg_name_p, instance);
+      break;
+
+    case F1AP_UE_CONTEXT_SETUP_RESP:
+      rrc_CU_process_ue_context_setup_response(msg_p, msg_name_p, instance);
+      break;
 
       /* Messages from X2AP */
       case X2AP_ENDC_SGNB_ADDITION_REQ:
@@ -3178,7 +3672,7 @@ void *rrc_gnb_task(void *args_p) {
         break;
 
       case X2AP_ENDC_SGNB_RECONF_COMPLETE:
-        LOG_I(NR_RRC, "Handling of reconfiguration complete message at RRC gNB is pending \n");
+        LOG_A(NR_RRC, "Handling of reconfiguration complete message at RRC gNB is pending \n");
         break;
 
       case NGAP_INITIAL_CONTEXT_SETUP_REQ:
@@ -3405,9 +3899,10 @@ rrc_gNB_generate_RRCRelease(
   uint8_t buffer[RRC_BUF_SIZE];
   uint16_t size = 0;
 
-  memset(buffer, 0, RRC_BUF_SIZE);
+  memset(buffer, 0, sizeof(buffer));
 
-  size = do_NR_RRCRelease(buffer,rrc_gNB_get_next_transaction_identifier(ctxt_pP->module_id));
+  size = do_NR_RRCRelease(buffer, sizeof(buffer),
+                          rrc_gNB_get_next_transaction_identifier(ctxt_pP->module_id));
   ue_context_pP->ue_context.ue_reestablishment_timer = 0;
   ue_context_pP->ue_context.ue_release_timer = 0;
   ue_context_pP->ue_context.ul_failure_timer = 0;
diff --git a/openair2/RRC/NR/rrc_gNB_NGAP.c b/openair2/RRC/NR/rrc_gNB_NGAP.c
index 60ee99a172a36a76116add718febf1c720c44ae0..043d136604582415d6239ac67a54219a412a1e09 100644
--- a/openair2/RRC/NR/rrc_gNB_NGAP.c
+++ b/openair2/RRC/NR/rrc_gNB_NGAP.c
@@ -306,7 +306,9 @@ nr_rrc_pdcp_config_security(
   uint8_t                            *kRRCenc = NULL;
   uint8_t                            *kRRCint = NULL;
   uint8_t                            *kUPenc = NULL;
-  static int                         print_keys= 1;
+  //uint8_t                            *k_kdf  = NULL;
+  static int                          print_keys= 1;
+
 
   /* Derive the keys from kgnb */
   if (SRB_configList != NULL) {
@@ -481,7 +483,7 @@ rrc_gNB_process_NGAP_INITIAL_CONTEXT_SETUP_REQ(
     uint16_t                        ue_initial_id;
     uint32_t                        gNB_ue_ngap_id;
     rrc_gNB_ue_context_t            *ue_context_p = NULL;
-    protocol_ctxt_t                 ctxt;
+    protocol_ctxt_t                 ctxt={0};
     uint8_t                         pdu_sessions_done = 0;
     gtpv1u_gnb_create_tunnel_req_t  create_tunnel_req;
     gtpv1u_gnb_create_tunnel_resp_t create_tunnel_resp;
@@ -520,14 +522,14 @@ rrc_gNB_process_NGAP_INITIAL_CONTEXT_SETUP_REQ(
           ue_context_p->ue_context.pduSession[i].param         = NGAP_INITIAL_CONTEXT_SETUP_REQ (msg_p).pdusession_param[pdu_sessions_done];
           create_tunnel_req.pdusession_id[pdu_sessions_done]   = NGAP_INITIAL_CONTEXT_SETUP_REQ (msg_p).pdusession_param[pdu_sessions_done].pdusession_id;
           create_tunnel_req.incoming_rb_id[pdu_sessions_done]  = i+1;
-          create_tunnel_req.upf_NGu_teid[pdu_sessions_done]    = NGAP_INITIAL_CONTEXT_SETUP_REQ (msg_p).pdusession_param[pdu_sessions_done].gtp_teid;
-          create_tunnel_req.upf_addr[pdu_sessions_done].length = NGAP_INITIAL_CONTEXT_SETUP_REQ (msg_p).pdusession_param[pdu_sessions_done].upf_addr.length;
-          memcpy(create_tunnel_req.upf_addr[pdu_sessions_done].buffer,
+          create_tunnel_req.outgoing_teid[pdu_sessions_done]    = NGAP_INITIAL_CONTEXT_SETUP_REQ (msg_p).pdusession_param[pdu_sessions_done].gtp_teid;
+          create_tunnel_req.dst_addr[pdu_sessions_done].length = NGAP_INITIAL_CONTEXT_SETUP_REQ (msg_p).pdusession_param[pdu_sessions_done].upf_addr.length;
+          memcpy(create_tunnel_req.dst_addr[pdu_sessions_done].buffer,
                   NGAP_INITIAL_CONTEXT_SETUP_REQ (msg_p).pdusession_param[pdu_sessions_done].upf_addr.buffer,
                   sizeof(uint8_t)*20);
           LOG_I(NR_RRC, "PDUSESSION SETUP: local index %d teid %u, pdusession id %d \n",
                 i,
-                create_tunnel_req.upf_NGu_teid[pdu_sessions_done],
+                create_tunnel_req.outgoing_teid[pdu_sessions_done],
                 create_tunnel_req.pdusession_id[pdu_sessions_done]);
           inde_list[pdu_sessions_done] = i;
           pdu_sessions_done++;
@@ -1053,7 +1055,7 @@ rrc_gNB_process_NGAP_PDUSESSION_SETUP_REQ(
     uint8_t nb_pdusessions_tosetup = NGAP_PDUSESSION_SETUP_REQ(msg_p).nb_pdusessions_tosetup;
     pdu_sessions_done = 0;
 
-    PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, GNB_FLAG_YES, ue_context_p->ue_context.rnti, 0, 0);
+    PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, 0, GNB_FLAG_YES, ue_context_p->ue_context.rnti, 0, 0, 0);
     for (int i = 0; i < NR_NB_RB_MAX - 3; i++) {
       if(ue_context_p->ue_context.pduSession[i].status >= PDU_SESSION_STATUS_DONE)
         continue;
@@ -1061,14 +1063,14 @@ rrc_gNB_process_NGAP_PDUSESSION_SETUP_REQ(
       ue_context_p->ue_context.pduSession[i].param       = NGAP_PDUSESSION_SETUP_REQ(msg_p).pdusession_setup_params[pdu_sessions_done];
       create_tunnel_req.pdusession_id[pdu_sessions_done] = NGAP_PDUSESSION_SETUP_REQ(msg_p).pdusession_setup_params[pdu_sessions_done].pdusession_id;
       create_tunnel_req.incoming_rb_id[pdu_sessions_done]= i+1;
-      create_tunnel_req.upf_NGu_teid[pdu_sessions_done]  = NGAP_PDUSESSION_SETUP_REQ(msg_p).pdusession_setup_params[pdu_sessions_done].gtp_teid;
-      memcpy(create_tunnel_req.upf_addr[pdu_sessions_done].buffer,
+      create_tunnel_req.outgoing_teid[pdu_sessions_done]  = NGAP_PDUSESSION_SETUP_REQ(msg_p).pdusession_setup_params[pdu_sessions_done].gtp_teid;
+      memcpy(create_tunnel_req.dst_addr[pdu_sessions_done].buffer,
               NGAP_PDUSESSION_SETUP_REQ(msg_p).pdusession_setup_params[pdu_sessions_done].upf_addr.buffer,
               sizeof(uint8_t)*20);
-      create_tunnel_req.upf_addr[pdu_sessions_done].length = NGAP_PDUSESSION_SETUP_REQ(msg_p).pdusession_setup_params[pdu_sessions_done].upf_addr.length;
+      create_tunnel_req.dst_addr[pdu_sessions_done].length = NGAP_PDUSESSION_SETUP_REQ(msg_p).pdusession_setup_params[pdu_sessions_done].upf_addr.length;
       LOG_I(NR_RRC,"NGAP PDUSESSION SETUP REQ: local index %d teid %u, pdusession id %d \n",
             i,
-            create_tunnel_req.upf_NGu_teid[pdu_sessions_done],
+            create_tunnel_req.outgoing_teid[pdu_sessions_done],
             create_tunnel_req.pdusession_id[pdu_sessions_done]);
       inde_list[pdu_sessions_done] = i;
       pdu_sessions_done++;
diff --git a/openair2/RRC/NR/rrc_gNB_nsa.c b/openair2/RRC/NR/rrc_gNB_nsa.c
index 5ac2f4ee025f4ed2202e6e7c8c8f5211ddeb66c9..414d6d809d55035983c8c6b18ac373fe71d60e37 100644
--- a/openair2/RRC/NR/rrc_gNB_nsa.c
+++ b/openair2/RRC/NR/rrc_gNB_nsa.c
@@ -124,6 +124,7 @@ void rrc_parse_ue_capabilities(gNB_RRC_INST *rrc, NR_UE_CapabilityRAT_ContainerL
   if ( LOG_DEBUGFLAG(DEBUG_ASN1) && ueCapabilityRAT_Container_MRDC != NULL ) {
     xer_fprint(stdout, &asn_DEF_NR_UE_MRDC_Capability, ue_context_p->ue_context.UE_Capability_MRDC);
   }
+  LOG_A(NR_RRC, "Successfully decoded UE NR capabilities (NR and MRDC)\n");
 
   rrc_add_nsa_user(rrc,ue_context_p, m);
 }
@@ -320,14 +321,18 @@ void rrc_add_nsa_user(gNB_RRC_INST *rrc,struct rrc_gNB_ue_context_s *ue_context_
       create_tunnel_req.num_tunnels    = m->nb_e_rabs_tobeadded;
       RB_INSERT(rrc_nr_ue_tree_s, &RC.nrrrc[rrc->module_id]->rrc_ue_head, ue_context_p);
       PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, rrc->module_id, GNB_FLAG_YES, ue_context_p->ue_id_rnti, 0, 0,rrc->module_id);
-      gtpv1u_create_s1u_tunnel(
-        ctxt.instance,
-        &create_tunnel_req,
-        &create_tunnel_resp);
-      rrc_gNB_process_GTPV1U_CREATE_TUNNEL_RESP(
-        &ctxt,
-        &create_tunnel_resp,
-        &inde_list[0]);
+      memset(&create_tunnel_resp, 0, sizeof(create_tunnel_resp));
+      if (!IS_SOFTMODEM_NOS1) {
+        LOG_D(RRC, "Calling gtpv1u_create_s1u_tunnel()\n");
+        gtpv1u_create_s1u_tunnel(
+          ctxt.instance,
+          &create_tunnel_req,
+          &create_tunnel_resp);
+        rrc_gNB_process_GTPV1U_CREATE_TUNNEL_RESP(
+          &ctxt,
+          &create_tunnel_resp,
+          &inde_list[0]);
+      }
       X2AP_ENDC_SGNB_ADDITION_REQ_ACK(msg).nb_e_rabs_admitted_tobeadded = m->nb_e_rabs_tobeadded;
       X2AP_ENDC_SGNB_ADDITION_REQ_ACK(msg).target_assoc_id = m->target_assoc_id;
 
@@ -365,7 +370,7 @@ void rrc_add_nsa_user(gNB_RRC_INST *rrc,struct rrc_gNB_ue_context_s *ue_context_
                               NULL,
                               (void *)CG_Config,
                               X2AP_ENDC_SGNB_ADDITION_REQ_ACK(msg).rrc_buffer,
-                              1024);
+                              sizeof(X2AP_ENDC_SGNB_ADDITION_REQ_ACK(msg).rrc_buffer));
     X2AP_ENDC_SGNB_ADDITION_REQ_ACK(msg).rrc_buffer_size = (enc_rval.encoded+7)>>3;
     itti_send_msg_to_task(TASK_X2AP, ENB_MODULE_ID_TO_INSTANCE(0), msg); //Check right id instead of hardcoding
   } else if (get_softmodem_params()->do_ra || get_softmodem_params()->sa) {
diff --git a/openair2/RRC/NR_UE/L2_interface_ue.c b/openair2/RRC/NR_UE/L2_interface_ue.c
index 5c9293dcf9c0951a61251bbca17d51d917c7b540..6f0c7fc27fa2c868ec456b0a4aa539fdd79ba774 100644
--- a/openair2/RRC/NR_UE/L2_interface_ue.c
+++ b/openair2/RRC/NR_UE/L2_interface_ue.c
@@ -149,7 +149,7 @@ int8_t nr_mac_rrc_data_req_ue(const module_id_t Mod_idP,
 }
 
 uint8_t
-rrc_data_req_ue(
+rrc_data_req_nr_ue(
   const protocol_ctxt_t   *const ctxt_pP,
   const rb_id_t                  rb_idP,
   const mui_t                    muiP,
diff --git a/openair2/RRC/NR_UE/rrc_UE.c b/openair2/RRC/NR_UE/rrc_UE.c
index b0d84960e868ae987027c319235f47c47e7834cb..21ccd4226b621d1c25276a44905b3796548da27c 100644
--- a/openair2/RRC/NR_UE/rrc_UE.c
+++ b/openair2/RRC/NR_UE/rrc_UE.c
@@ -49,10 +49,12 @@
 #include "rrc_defs.h"
 #include "rrc_proto.h"
 #include "rrc_vars.h"
+#include "rrc_extern.h"
 #include "LAYER2/NR_MAC_UE/mac_proto.h"
 
 #include "intertask_interface.h"
 
+#include "nr-uesoftmodem.h"
 #include "executables/softmodem-common.h"
 #include "plmn_data.h"
 #include "pdcp.h"
@@ -105,7 +107,7 @@ nr_rrc_ue_process_ueCapabilityEnquiry(
 );
 
 void
-nr_sa_rrc_ue_process_radioBearerConfig(
+nr_rrc_ue_process_RadioBearerConfig(
     const protocol_ctxt_t *const       ctxt_pP,
     const uint8_t                      gNB_index,
     NR_RadioBearerConfig_t *const      radioBearerConfig
@@ -114,11 +116,10 @@ nr_sa_rrc_ue_process_radioBearerConfig(
 uint8_t do_NR_RRCReconfigurationComplete(
                         const protocol_ctxt_t *const ctxt_pP,
                         uint8_t *buffer,
+                        size_t buffer_size,
                         const uint8_t Transaction_id
                       );
 
-void rrc_ue_generate_RRCReestablishmentRequest( const protocol_ctxt_t *const ctxt_pP, const uint8_t gNB_index );
-
 void
 nr_rrc_ue_generate_rrcReestablishmentComplete(
   const protocol_ctxt_t *const ctxt_pP,
@@ -233,16 +234,6 @@ int8_t nr_rrc_ue_decode_secondary_cellgroup_config(const module_id_t module_id,
   return 0;
 }
 
-int8_t nr_rrc_ue_process_RadioBearerConfig(NR_RadioBearerConfig_t *RadioBearerConfig){
-
-  if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
-    xer_fprint(stdout, &asn_DEF_NR_RadioBearerConfig, (const void *) RadioBearerConfig);
-  }
-  // Configure PDCP
-
-  return 0;
-}
-
 // from LTE-RRC DL-DCCH RRCConnectionReconfiguration nr-secondary-cell-group-config (decoded)
 // RRCReconfiguration
 int8_t nr_rrc_ue_process_rrcReconfiguration(const module_id_t module_id, NR_RRCReconfiguration_t *rrcReconfiguration){
@@ -253,12 +244,15 @@ int8_t nr_rrc_ue_process_rrcReconfiguration(const module_id_t module_id, NR_RRCR
         if(NR_UE_rrc_inst[module_id].radio_bearer_config == NULL){
           NR_UE_rrc_inst[module_id].radio_bearer_config = rrcReconfiguration->criticalExtensions.choice.rrcReconfiguration->radioBearerConfig;                
         }else{
-          nr_rrc_ue_process_RadioBearerConfig(rrcReconfiguration->criticalExtensions.choice.rrcReconfiguration->radioBearerConfig);
+          if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
+            struct NR_RadioBearerConfig *RadioBearerConfig = rrcReconfiguration->criticalExtensions.choice.rrcReconfiguration->radioBearerConfig;
+            xer_fprint(stdout, &asn_DEF_NR_RadioBearerConfig, (const void *) RadioBearerConfig);
+          }
         }
       }
       if(rrcReconfiguration->criticalExtensions.choice.rrcReconfiguration->secondaryCellGroup != NULL){
 
-        if(get_softmodem_params()->sa) {
+        if(get_softmodem_params()->sa || get_softmodem_params()->nsa) {
 
           NR_CellGroupConfig_t *cellGroupConfig = NULL;
           uper_decode(NULL,
@@ -336,6 +330,10 @@ int8_t nr_rrc_ue_process_scg_config(const module_id_t module_id, NR_CellGroupCon
   }else{
     //  maintain list
     if(cell_group_config->spCellConfig != NULL){
+      if (get_softmodem_params()->nsa) {
+        nr_rrc_mac_config_req_ue(0, 0, 0, NULL, NULL, cell_group_config, NULL);
+        LOG_D(NR_RRC, "Filled scc now \n");
+      }
       if(cell_group_config->spCellConfig->spCellConfigDedicated != NULL){
         //  process element of list to be add by RRC message
         if(cell_group_config->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList != NULL){
@@ -375,7 +373,7 @@ void process_nsa_message(NR_UE_RRC_INST_t *rrc, nsa_message_t nsa_message_type,
                                 msg_len); 
         
         if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0)) {
-          LOG_E(RRC,"NR_RRCReconfiguration decode error\n");
+          LOG_E(NR_RRC, "NR_RRCReconfiguration decode error\n");
           // free the memory
           SEQUENCE_free( &asn_DEF_NR_RRCReconfiguration, RRCReconfiguration, 1 );
           return;
@@ -394,12 +392,26 @@ void process_nsa_message(NR_UE_RRC_INST_t *rrc, nsa_message_t nsa_message_type,
                                 msg_len); 
         
         if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0)) {
-          LOG_E(RRC,"NR_RadioBearerConfig decode error\n");
+          LOG_E(NR_RRC, "NR_RadioBearerConfig decode error\n");
           // free the memory
           SEQUENCE_free( &asn_DEF_NR_RadioBearerConfig, RadioBearerConfig, 1 );
           return;
         }
-        nr_rrc_ue_process_RadioBearerConfig(RadioBearerConfig);
+        if (get_softmodem_params()->nsa) {
+          protocol_ctxt_t ctxt;
+          NR_UE_MAC_INST_t *mac = get_mac_inst(module_id);
+          PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, module_id, ENB_FLAG_YES, mac->crnti, 0, 0, 0);
+          xer_fprint(stdout, &asn_DEF_NR_RadioBearerConfig, (const void*)RadioBearerConfig);
+          LOG_D(NR_RRC, "Calling fill_default_rbconfig_ue at %d with: e_rab_id = %ld, drbID = %ld, cipher_algo = %ld, key = %ld \n",
+                          __LINE__, RadioBearerConfig->drb_ToAddModList->list.array[0]->cnAssociation->choice.eps_BearerIdentity,
+                          RadioBearerConfig->drb_ToAddModList->list.array[0]->drb_Identity,
+                          RadioBearerConfig->securityConfig->securityAlgorithmConfig->cipheringAlgorithm,
+                          *RadioBearerConfig->securityConfig->keyToUse);
+          nr_rrc_ue_process_RadioBearerConfig(&ctxt, 0, RadioBearerConfig);
+        }
+        else if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
+          xer_fprint(stdout, &asn_DEF_NR_RadioBearerConfig, (const void *) RadioBearerConfig);
+        }
       }
       break;
     
@@ -413,8 +425,7 @@ void process_nsa_message(NR_UE_RRC_INST_t *rrc, nsa_message_t nsa_message_type,
 NR_UE_RRC_INST_t* openair_rrc_top_init_ue_nr(char* uecap_file, char* rrc_config_path){
   int nr_ue;
   if(NB_NR_UE_INST > 0){
-    NR_UE_rrc_inst = (NR_UE_RRC_INST_t *)malloc(NB_NR_UE_INST * sizeof(NR_UE_RRC_INST_t));
-    memset(NR_UE_rrc_inst, 0, NB_NR_UE_INST * sizeof(NR_UE_RRC_INST_t));
+    NR_UE_rrc_inst = (NR_UE_RRC_INST_t *)calloc(NB_NR_UE_INST , sizeof(NR_UE_RRC_INST_t));
     for(nr_ue=0;nr_ue<NB_NR_UE_INST;nr_ue++){
       // fill UE-NR-Capability @ UE-CapabilityRAT-Container here.
       NR_UE_rrc_inst[nr_ue].selected_plmn_identity = 1;
@@ -519,6 +530,10 @@ NR_UE_RRC_INST_t* openair_rrc_top_init_ue_nr(char* uecap_file, char* rrc_config_
       fclose(fd);
       process_nsa_message(NR_UE_rrc_inst, nr_RadioBearerConfigX_r15, buffer,msg_len); 
     }
+    else if (get_softmodem_params()->nsa)
+    {
+      LOG_D(NR_RRC, "In NSA mode \n");
+    }
   }
   else{
     NR_UE_rrc_inst = NULL;
@@ -564,7 +579,8 @@ int8_t nr_rrc_ue_decode_NR_BCCH_BCH_Message(
 
     if (NR_UE_rrc_inst[module_id].mib != NULL)
       SEQUENCE_free( &asn_DEF_NR_BCCH_BCH_Message, (void *)bcch_message, 1 );
-    else LOG_I(NR_RRC,"Configuring MAC for first MIB reception\n");
+    else
+        LOG_A(NR_RRC, "Configuring MAC for first MIB reception\n");
 
     asn_dec_rval_t dec_rval = uper_decode_complete(NULL,
                                                    &asn_DEF_NR_BCCH_BCH_Message,
@@ -592,13 +608,6 @@ int8_t nr_rrc_ue_decode_NR_BCCH_BCH_Message(
     return 0;
 }
 
-const char  siWindowLength[10][5] = {"5s", "10s", "20s", "40s", "80s", "160s", "320s", "640s", "1280s","ERR"};// {"1ms","2ms","5ms","10ms","15ms","20ms","40ms","80ms","ERR"};
-const short siWindowLength_int[9] = {5,10,20,40,80,160,320,640,1280};//{1,2,5,10,15,20,40,80};
-
-const char SIBType[12][6]        = {"SIB3","SIB4","SIB5","SIB6","SIB7","SIB8","SIB9","SIB10","SIB11","SIB12","SIB13","Spare"};
-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 *nr_SIBreserved( long value ) {
   if (value < 0 || value > 1)
     return "ERR";
@@ -1028,7 +1037,7 @@ int nr_decode_SI( const protocol_ctxt_t *const ctxt_pP, const uint8_t gNB_index
   //  if (NR_UE_rrc_inst[ctxt_pP->module_id].Info[gNB_index].SIcnt == sib1->schedulingInfoList.list.count)
   //    rrc_set_sub_state( ctxt_pP->module_id, RRC_SUB_STATE_IDLE_SIB_COMPLETE );
 
-  //  LOG_I(RRC,"SIStatus %x, SIcnt %d/%d\n",
+  //  LOG_I(NR_RRC, "SIStatus %x, SIcnt %d/%d\n",
   //        NR_UE_rrc_inst[ctxt_pP->module_id].Info[gNB_index].SIStatus,
   //        NR_UE_rrc_inst[ctxt_pP->module_id].Info[gNB_index].SIcnt,
   //        sib1->schedulingInfoList.list.count);
@@ -1038,7 +1047,7 @@ int nr_decode_SI( const protocol_ctxt_t *const ctxt_pP, const uint8_t gNB_index
   return 0;
 }
 
-int8_t check_requested_SI_List(module_id_t module_id, BIT_STRING_t requested_SI_List, NR_SIB1_t sib1) {
+static int8_t check_requested_SI_List(module_id_t module_id, BIT_STRING_t requested_SI_List, NR_SIB1_t sib1) {
 
   if(sib1.si_SchedulingInfo) {
 
@@ -1188,7 +1197,7 @@ int8_t nr_rrc_ue_decode_NR_BCCH_DL_SCH_Message(module_id_t module_id,
             if( g_log->log_component[NR_RRC].level >= OAILOG_DEBUG ) {
               xer_fprint(stdout, &asn_DEF_NR_SIB1, (const void *) NR_UE_rrc_inst[module_id].sib1[gNB_index]);
             }
-            LOG_I(NR_RRC, "SIB1 decoded\n");
+            LOG_A(NR_RRC, "SIB1 decoded\n");
 
             ///	    dump_SIB1();
             // FIXME: improve condition for the RA trigger
@@ -1196,8 +1205,8 @@ int8_t nr_rrc_ue_decode_NR_BCCH_DL_SCH_Message(module_id_t module_id,
             check_requested_SI_List(module_id, NR_UE_rrc_inst[module_id].requested_SI_List, *sib1);
             if( nr_rrc_get_state(module_id) <= RRC_STATE_IDLE_NR ) {
               NR_UE_rrc_inst[module_id].ra_trigger = INITIAL_ACCESS_FROM_RRC_IDLE;
-              LOG_D(PHY,"Setting state to NR_RRC_SI_RECEIVED\n");
-              nr_rrc_set_state (module_id, NR_RRC_SI_RECEIVED);
+              LOG_D(PHY,"Setting state to RRC_STATE_IDLE_NR\n");
+              nr_rrc_set_state (module_id, RRC_STATE_IDLE_NR);
             }
             // take ServingCellConfigCommon and configure L1/L2
             NR_UE_rrc_inst[module_id].servingCellConfigCommonSIB = sib1->servingCellConfigCommon;
@@ -1283,7 +1292,8 @@ nr_rrc_ue_process_masterCellGroup(
   if( cellGroupConfig->rlc_BearerToAddModList != NULL){
     //TODO (perform the RLC bearer addition/modification as specified in 5.3.5.5.4)
     if(NR_UE_rrc_inst[ctxt_pP->module_id].cell_group_config->rlc_BearerToAddModList != NULL){
-      free(NR_UE_rrc_inst[ctxt_pP->module_id].cell_group_config->rlc_BearerToAddModList);
+       // Laurent: there are cases where the not NULL value is also not coming from a previous malloc
+      // so it is better to let the potential memory leak than corrupting the heap     //free(NR_UE_rrc_inst[ctxt_pP->module_id].cell_group_config->rlc_BearerToAddModList);
     }
     NR_UE_rrc_inst[ctxt_pP->module_id].cell_group_config->rlc_BearerToAddModList = calloc(1, sizeof(struct NR_CellGroupConfig__rlc_BearerToAddModList));
     memcpy(NR_UE_rrc_inst[ctxt_pP->module_id].cell_group_config->rlc_BearerToAddModList,cellGroupConfig->rlc_BearerToAddModList,
@@ -1295,7 +1305,9 @@ nr_rrc_ue_process_masterCellGroup(
     LOG_I(RRC, "Received mac_CellGroupConfig from gNB\n");
     if(NR_UE_rrc_inst[ctxt_pP->module_id].cell_group_config->mac_CellGroupConfig != NULL){
       LOG_E(RRC, "UE RRC instance already contains mac CellGroupConfig which will be overwritten\n");
-      free(NR_UE_rrc_inst[ctxt_pP->module_id].cell_group_config->mac_CellGroupConfig);
+      // Laurent: there are cases where the not NULL value is also not coming from a previous malloc
+      // so it is better to let the potential memory leak than corrupting the heap
+      //free(NR_UE_rrc_inst[ctxt_pP->module_id].cell_group_config->mac_CellGroupConfig);
     }
     NR_UE_rrc_inst[ctxt_pP->module_id].cell_group_config->mac_CellGroupConfig = malloc(sizeof(struct NR_MAC_CellGroupConfig));
     memcpy(NR_UE_rrc_inst[ctxt_pP->module_id].cell_group_config->mac_CellGroupConfig,cellGroupConfig->mac_CellGroupConfig,
@@ -1375,7 +1387,8 @@ static void rrc_ue_generate_RRCSetupComplete(
     nas_msg         = nr_nas_attach_req_imsi;
     nas_msg_length  = sizeof(nr_nas_attach_req_imsi);
   }
-  size = do_RRCSetupComplete(ctxt_pP->module_id,buffer,Transaction_id,sel_plmn_id,nas_msg_length,nas_msg);
+  size = do_RRCSetupComplete(ctxt_pP->module_id, buffer, sizeof(buffer),
+                             Transaction_id, sel_plmn_id, nas_msg_length, nas_msg);
   LOG_I(NR_RRC,"[UE %d][RAPROC] Frame %d : Logical Channel UL-DCCH (SRB1), Generating RRCSetupComplete (bytes%d, gNB %d)\n",
    ctxt_pP->module_id,ctxt_pP->frame, size, gNB_index);
   LOG_D(NR_RRC,
@@ -1386,7 +1399,7 @@ static void rrc_ue_generate_RRCSetupComplete(
   //printf("\n");
 
    // ctxt_pP_local.rnti = ctxt_pP->rnti;
-  rrc_data_req_ue(ctxt_pP,
+  rrc_data_req_nr_ue(ctxt_pP,
                   DCCH,
                   nr_rrc_mui++,
                   SDU_CONFIRM_NO,
@@ -1464,10 +1477,9 @@ int8_t nr_rrc_ue_decode_ccch( const protocol_ctxt_t *const ctxt_pP, const NR_SRB
 					   ctxt_pP,
 					   gNB_index,
 					   &dl_ccch_msg->message.choice.c1->choice.rrcSetup->criticalExtensions.choice.rrcSetup->masterCellGroup);
-	 nr_sa_rrc_ue_process_radioBearerConfig(
-						ctxt_pP,
-						gNB_index,
-						&dl_ccch_msg->message.choice.c1->choice.rrcSetup->criticalExtensions.choice.rrcSetup->radioBearerConfig);
+	 nr_rrc_ue_process_RadioBearerConfig(ctxt_pP,
+					     gNB_index,
+					     &dl_ccch_msg->message.choice.c1->choice.rrcSetup->criticalExtensions.choice.rrcSetup->radioBearerConfig);
 	 nr_rrc_set_state (ctxt_pP->module_id, RRC_STATE_CONNECTED);
 	 nr_rrc_set_sub_state (ctxt_pP->module_id, RRC_SUB_STATE_CONNECTED);
 	 NR_UE_rrc_inst[ctxt_pP->module_id].Info[gNB_index].rnti = ctxt_pP->rnti;
@@ -1737,7 +1749,7 @@ int8_t nr_rrc_ue_decode_ccch( const protocol_ctxt_t *const ctxt_pP, const NR_SRB
      GNB_RRC_DCCH_DATA_IND (message_p).size    = (enc_rval.encoded + 7) / 8;
      itti_send_msg_to_task (TASK_RRC_GNB_SIM, ctxt_pP->instance, message_p);
  #else
-     rrc_data_req_ue (ctxt_pP,
+     rrc_data_req_nr_ue (ctxt_pP,
                       DCCH,
                       nr_rrc_mui++,
                       SDU_CONFIRM_NO,
@@ -1775,6 +1787,7 @@ int8_t nr_rrc_ue_decode_ccch( const protocol_ctxt_t *const ctxt_pP, const NR_SRB
 	do_RRCSetupRequest(
 	  module_id,
 	  (uint8_t *)NR_UE_rrc_inst[module_id].Srb0[gNB_index].Tx_buffer.Payload,
+          sizeof(NR_UE_rrc_inst[module_id].Srb0[gNB_index].Tx_buffer.Payload),
 	  rv);
      LOG_I(NR_RRC,"[UE %d] : Logical Channel UL-CCCH (SRB0), Generating RRCSetupRequest (bytes %d, gNB %d)\n",
 	   module_id, NR_UE_rrc_inst[module_id].Srb0[gNB_index].Tx_buffer.payload_size, gNB_index);
@@ -2015,7 +2028,7 @@ nr_rrc_ue_establish_srb2(
 
  //-----------------------------------------------------------------------------
  void
- nr_sa_rrc_ue_process_radioBearerConfig(
+ nr_rrc_ue_process_RadioBearerConfig(
      const protocol_ctxt_t *const       ctxt_pP,
      const uint8_t                      gNB_index,
      NR_RadioBearerConfig_t *const      radioBearerConfig
@@ -2206,7 +2219,7 @@ nr_rrc_ue_establish_srb2(
  }
 
  //-----------------------------------------------------------------------------
- void
+ static void
  rrc_ue_process_rrcReconfiguration(
    const protocol_ctxt_t *const  ctxt_pP,
    NR_RRCReconfiguration_t       *rrcReconfiguration,
@@ -2236,7 +2249,7 @@ nr_rrc_ue_establish_srb2(
 
      if (ie->radioBearerConfig != NULL) {
        LOG_I(NR_RRC, "radio Bearer Configuration is present\n");
-       nr_sa_rrc_ue_process_radioBearerConfig(ctxt_pP, gNB_index, ie->radioBearerConfig);
+       nr_rrc_ue_process_RadioBearerConfig(ctxt_pP, gNB_index, ie->radioBearerConfig);
      }
 
      /* Check if there is dedicated NAS information to forward to NAS */
@@ -2264,7 +2277,7 @@ nr_rrc_ue_establish_srb2(
  //-----------------------------------------------------------------------------
  void nr_rrc_ue_generate_RRCReconfigurationComplete( const protocol_ctxt_t *const ctxt_pP, const uint8_t gNB_index, const uint8_t Transaction_id ) {
    uint8_t buffer[32], size;
-   size = do_NR_RRCReconfigurationComplete(ctxt_pP, buffer, Transaction_id);
+   size = do_NR_RRCReconfigurationComplete(ctxt_pP, buffer, sizeof(buffer), Transaction_id);
    LOG_I(NR_RRC,PROTOCOL_RRC_CTXT_UE_FMT" Logical Channel UL-DCCH (SRB1), Generating RRCReconfigurationComplete (bytes %d, gNB_index %d)\n",
 	 PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP), size, gNB_index);
    LOG_D(RLC,
@@ -2289,7 +2302,7 @@ nr_rrc_ue_establish_srb2(
    itti_send_msg_to_task (TASK_RRC_GNB_SIM, ctxt_pP->instance, message_p);
 
  #else
-   rrc_data_req_ue (
+   rrc_data_req_nr_ue (
      ctxt_pP,
      DCCH,
      nr_rrc_mui++,
@@ -2308,6 +2321,7 @@ nr_rrc_ue_establish_srb2(
    const protocol_ctxt_t *const ctxt_pP,
    const srb_id_t               Srb_id,
    const uint8_t         *const Buffer,
+   size_t                       Buffer_size,
    const uint8_t                gNB_indexP
  )
  //-----------------------------------------------------------------------------
@@ -2328,7 +2342,7 @@ nr_rrc_ue_establish_srb2(
 			   &asn_DEF_NR_DL_DCCH_Message,
 			   (void **)&dl_dcch_msg,
 			   Buffer,
-			   RRC_BUF_SIZE,
+			   Buffer_size,
 			   0,
 			   0);
 
@@ -2510,6 +2524,7 @@ nr_rrc_ue_establish_srb2(
           &ctxt,
           NR_RRC_DCCH_DATA_IND (msg_p).dcch_index,
           NR_RRC_DCCH_DATA_IND (msg_p).sdu_p,
+          NR_RRC_DCCH_DATA_IND (msg_p).sdu_size,
           NR_RRC_DCCH_DATA_IND (msg_p).gNB_index);
         break;
 
@@ -2561,14 +2576,14 @@ nr_rrc_ue_establish_srb2(
 #else
         // check if SRB2 is created, if yes request data_req on DCCH1 (SRB2)
         if(NR_UE_rrc_inst[ue_mod_id].SRB2_config[0] == NULL) {
-          rrc_data_req_ue (&ctxt,
+          rrc_data_req_nr_ue (&ctxt,
                            DCCH,
                            nr_rrc_mui++,
                            SDU_CONFIRM_NO,
                            length, buffer,
                            PDCP_TRANSMISSION_MODE_CONTROL);
         } else {
-          rrc_data_req_ue (&ctxt,
+          rrc_data_req_nr_ue (&ctxt,
                            DCCH1,
                            nr_rrc_mui++,
                            SDU_CONFIRM_NO,
@@ -2692,6 +2707,11 @@ nr_rrc_ue_process_ueCapabilityEnquiry(
   OCTET_STRING_fromBuf(&ue_CapabilityRAT_Container.ue_CapabilityRAT_Container,
                        (const char *)NR_UE_rrc_inst[ctxt_pP->module_id].UECapability,
                        NR_UE_rrc_inst[ctxt_pP->module_id].UECapability_size);
+
+  if (get_softmodem_params()->nsa == 1) {
+    OCTET_STRING_t * requestedFreqBandsNR = UECapabilityEnquiry->criticalExtensions.choice.ueCapabilityEnquiry->ue_CapabilityEnquiryExt;
+    nsa_sendmsg_to_lte_ue(requestedFreqBandsNR->buf, requestedFreqBandsNR->size, UE_CAPABILITY_INFO);
+  }
   //  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 == NR_UECapabilityEnquiry__criticalExtensions_PR_ueCapabilityEnquiry,
@@ -2717,7 +2737,7 @@ nr_rrc_ue_process_ueCapabilityEnquiry(
         xer_fprint(stdout, &asn_DEF_NR_UL_DCCH_Message, (void *)&ul_dcch_msg);
       }
 
-      LOG_I(RRC,"UECapabilityInformation Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);
+      LOG_I(NR_RRC, "UECapabilityInformation Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);
 #ifdef ITTI_SIM
       MessageDef *message_p;
       uint8_t *message_buffer;
@@ -2731,7 +2751,7 @@ nr_rrc_ue_process_ueCapabilityEnquiry(
       GNB_RRC_DCCH_DATA_IND (message_p).size  = (enc_rval.encoded + 7) / 8;
       itti_send_msg_to_task (TASK_RRC_GNB_SIM, ctxt_pP->instance, message_p);
 #else
-      rrc_data_req_ue (
+      rrc_data_req_nr_ue (
         ctxt_pP,
         DCCH,
         nr_rrc_mui++,
@@ -2744,36 +2764,6 @@ nr_rrc_ue_process_ueCapabilityEnquiry(
   }
 }
 
-//-----------------------------------------------------------------------------
-void rrc_ue_generate_RRCReestablishmentRequest( const protocol_ctxt_t *const ctxt_pP, const uint8_t gNB_index ) 
-{
-  NR_UE_rrc_inst[ctxt_pP->module_id].Srb0[gNB_index].Tx_buffer.payload_size =
-    do_RRCReestablishmentRequest(
-      ctxt_pP->module_id,
-      (uint8_t *)NR_UE_rrc_inst[ctxt_pP->module_id].Srb0[gNB_index].Tx_buffer.Payload, 1);
-  LOG_I(NR_RRC,"[UE %d] : Frame %d, Logical Channel UL-CCCH (SRB0), Generating RRCReestablishmentRequest (bytes %d, gNB %d)\n",
-        ctxt_pP->module_id, ctxt_pP->frame, NR_UE_rrc_inst[ctxt_pP->module_id].Srb0[gNB_index].Tx_buffer.payload_size, gNB_index);
-
-  for (int i=0; i<NR_UE_rrc_inst[ctxt_pP->module_id].Srb0[gNB_index].Tx_buffer.payload_size; i++) {
-    LOG_T(NR_RRC,"%x.",NR_UE_rrc_inst[ctxt_pP->module_id].Srb0[gNB_index].Tx_buffer.Payload[i]);
-  }
-
-  LOG_T(NR_RRC,"\n");
-
-#ifdef ITTI_SIM
-  MessageDef *message_p;
-  uint8_t *message_buffer;
-  message_buffer = itti_malloc (TASK_RRC_NRUE,TASK_RRC_GNB_SIM,
-        NR_UE_rrc_inst[ctxt_pP->module_id].Srb0[gNB_index].Tx_buffer.payload_size);
-  memcpy (message_buffer, (uint8_t*)NR_UE_rrc_inst[ctxt_pP->module_id].Srb0[gNB_index].Tx_buffer.Payload,
-        NR_UE_rrc_inst[ctxt_pP->module_id].Srb0[gNB_index].Tx_buffer.payload_size);
-  message_p = itti_alloc_new_message (TASK_RRC_NRUE, 0, UE_RRC_CCCH_DATA_IND);
-  UE_RRC_CCCH_DATA_IND (message_p).sdu = message_buffer;
-  UE_RRC_CCCH_DATA_IND (message_p).size  = NR_UE_rrc_inst[ctxt_pP->module_id].Srb0[gNB_index].Tx_buffer.payload_size;
-  itti_send_msg_to_task (TASK_RRC_GNB_SIM, ctxt_pP->instance, message_p);
-#endif
-}
-
 void
 nr_rrc_ue_generate_rrcReestablishmentComplete(
   const protocol_ctxt_t *const ctxt_pP,
@@ -2784,7 +2774,8 @@ nr_rrc_ue_generate_rrcReestablishmentComplete(
 {
     uint32_t length;
     uint8_t buffer[100];
-    length = do_RRCReestablishmentComplete(buffer, rrcReestablishment->rrc_TransactionIdentifier);
+    length = do_RRCReestablishmentComplete(buffer, sizeof(buffer),
+                                           rrcReestablishment->rrc_TransactionIdentifier);
     LOG_I(NR_RRC,"[UE %d][RAPROC] Frame %d : Logical Channel UL-DCCH (SRB1), Generating RRCReestablishmentComplete (bytes%d, gNB %d)\n",
           ctxt_pP->module_id,ctxt_pP->frame, length, gNB_index);
 #ifdef ITTI_SIM
@@ -2801,3 +2792,224 @@ nr_rrc_ue_generate_rrcReestablishmentComplete(
 
 #endif
 }
+
+void *recv_msgs_from_lte_ue(void *args_p)
+{
+    itti_mark_task_ready (TASK_RRC_NSA_NRUE);
+    int from_lte_ue_fd = get_from_lte_ue_fd();
+    for (;;)
+    {
+        nsa_msg_t msg;
+        int recvLen = recvfrom(from_lte_ue_fd, &msg, sizeof(msg),
+                               MSG_WAITALL | MSG_TRUNC, NULL, NULL);
+        if (recvLen == -1)
+        {
+            LOG_E(NR_RRC, "%s: recvfrom: %s\n", __func__, strerror(errno));
+            continue;
+        }
+        if (recvLen > sizeof(msg))
+        {
+            LOG_E(NR_RRC, "%s: Received truncated message %d\n", __func__, recvLen);
+            continue;
+        }
+        process_lte_nsa_msg(&msg, recvLen);
+    }
+    return NULL;
+}
+
+void start_oai_nrue_threads()
+{
+    init_queue(&nr_rach_ind_queue);
+    init_queue(&nr_rx_ind_queue);
+    init_queue(&nr_crc_ind_queue);
+    init_queue(&nr_uci_ind_queue);
+    init_queue(&nr_sfn_slot_queue);
+    init_queue(&nr_chan_param_queue);
+    init_queue(&nr_dl_tti_req_queue);
+    init_queue(&nr_tx_req_queue);
+    init_queue(&nr_ul_dci_req_queue);
+    init_queue(&nr_ul_tti_req_queue);
+    init_queue(&nr_wait_ul_tti_req_queue);
+
+    if (sem_init(&sfn_slot_semaphore, 0, 0) != 0)
+    {
+      LOG_E(MAC, "sem_init() error\n");
+      abort();
+    }
+
+    init_nrUE_standalone_thread(ue_id_g);
+
+}
+
+static void nsa_rrc_ue_process_ueCapabilityEnquiry(void)
+{
+  NR_UE_NR_Capability_t *UE_Capability_nr = CALLOC(1, sizeof(NR_UE_NR_Capability_t));
+  NR_BandNR_t *nr_bandnr = CALLOC(1, sizeof(NR_BandNR_t));
+  nr_bandnr->bandNR = 78;
+  ASN_SEQUENCE_ADD(&UE_Capability_nr->rf_Parameters.supportedBandListNR.list, nr_bandnr);
+  OAI_NR_UECapability_t *UECap = CALLOC(1, sizeof(OAI_NR_UECapability_t));
+  UECap->UE_NR_Capability = UE_Capability_nr;
+
+  asn_enc_rval_t enc_rval = uper_encode_to_buffer(&asn_DEF_NR_UE_NR_Capability,
+                                   NULL,
+                                   (void *)UE_Capability_nr,
+                                   &UECap->sdu[0],
+                                   MAX_UE_NR_CAPABILITY_SIZE);
+  AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n",
+               enc_rval.failed_type->name, enc_rval.encoded);
+  UECap->sdu_size = (enc_rval.encoded + 7) / 8;
+  LOG_A(NR_RRC, "[NR_RRC] NRUE Capability encoded, %d bytes (%zd bits)\n",
+        UECap->sdu_size, enc_rval.encoded + 7);
+
+  NR_UE_rrc_inst[0].UECap = UECap;
+  NR_UE_rrc_inst[0].UECapability = UECap->sdu;
+  NR_UE_rrc_inst[0].UECapability_size = UECap->sdu_size;
+
+  NR_UE_CapabilityRAT_Container_t ue_CapabilityRAT_Container;
+  memset(&ue_CapabilityRAT_Container, 0, sizeof(NR_UE_CapabilityRAT_Container_t));
+  ue_CapabilityRAT_Container.rat_Type = NR_RAT_Type_nr;
+  OCTET_STRING_fromBuf(&ue_CapabilityRAT_Container.ue_CapabilityRAT_Container,
+                       (const char *)NR_UE_rrc_inst[0].UECapability,
+                       NR_UE_rrc_inst[0].UECapability_size);
+
+  nsa_sendmsg_to_lte_ue(ue_CapabilityRAT_Container.ue_CapabilityRAT_Container.buf,
+                        ue_CapabilityRAT_Container.ue_CapabilityRAT_Container.size,
+                        NRUE_CAPABILITY_INFO);
+}
+
+void process_lte_nsa_msg(nsa_msg_t *msg, int msg_len)
+{
+    if (msg_len < sizeof(msg->msg_type))
+    {
+        LOG_E(RRC, "Msg_len = %d\n", msg_len);
+        return;
+    }
+    LOG_D(NR_RRC, "Processing an NSA message\n");
+    Rrc_Msg_Type_t msg_type = msg->msg_type;
+    uint8_t *const msg_buffer = msg->msg_buffer;
+    msg_len -= sizeof(msg->msg_type);
+    switch (msg_type)
+    {
+        case UE_CAPABILITY_ENQUIRY:
+        {
+            LOG_D(NR_RRC, "We are processing a %d message \n", msg_type);
+            NR_FreqBandList_t *nr_freq_band_list = NULL;
+            asn_dec_rval_t dec_rval = uper_decode_complete(NULL,
+                            &asn_DEF_NR_FreqBandList,
+                            (void **)&nr_freq_band_list,
+                            msg_buffer,
+                            msg_len);
+            if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0))
+            {
+              SEQUENCE_free(&asn_DEF_NR_FreqBandList, nr_freq_band_list, ASFM_FREE_EVERYTHING);
+              LOG_E(RRC, "Failed to decode UECapabilityInfo (%zu bits)\n", dec_rval.consumed);
+              break;
+            }
+            for (int i = 0; i < nr_freq_band_list->list.count; i++)
+            {
+                LOG_D(NR_RRC, "Received NR band information: %ld.\n",
+                     nr_freq_band_list->list.array[i]->choice.bandInformationNR->bandNR);
+            }
+            MessageDef *dummy_msg = itti_alloc_new_message(TASK_RRC_NSA_UE, 0, UE_CAPABILITY_DUMMY);
+            LOG_D(NR_RRC, "We are calling nsa_sendmsg_to_lte_ue to send a UE_CAPABILITY_DUMMY\n");
+            nsa_sendmsg_to_lte_ue(dummy_msg, sizeof(dummy_msg), UE_CAPABILITY_DUMMY);
+            LOG_A(NR_RRC, "Sent initial NRUE Capability response to LTE UE\n");
+            break;
+        }
+
+        case NRUE_CAPABILITY_ENQUIRY:
+        {
+            LOG_I(NR_RRC, "We are processing a %d message \n", msg_type);
+            NR_FreqBandList_t *nr_freq_band_list = NULL;
+            asn_dec_rval_t dec_rval = uper_decode_complete(NULL,
+                            &asn_DEF_NR_FreqBandList,
+                            (void **)&nr_freq_band_list,
+                            msg_buffer,
+                            msg_len);
+            if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0))
+            {
+              SEQUENCE_free(&asn_DEF_NR_FreqBandList, nr_freq_band_list, ASFM_FREE_EVERYTHING);
+              LOG_E(NR_RRC, "Failed to decode UECapabilityInfo (%zu bits)\n", dec_rval.consumed);
+              break;
+            }
+            LOG_I(NR_RRC, "Calling nsa_rrc_ue_process_ueCapabilityEnquiry\n");
+            nsa_rrc_ue_process_ueCapabilityEnquiry();
+            break;
+        }
+
+        case RRC_MEASUREMENT_PROCEDURE:
+        {
+            LOG_I(NR_RRC, "We are processing a %d message \n", msg_type);
+
+            LTE_MeasObjectToAddMod_t *nr_meas_obj = NULL;
+            asn_dec_rval_t dec_rval = uper_decode_complete(NULL,
+                            &asn_DEF_LTE_MeasObjectToAddMod,
+                            (void **)&nr_meas_obj,
+                            msg_buffer,
+                            msg_len);
+            if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0))
+            {
+              SEQUENCE_free(&asn_DEF_LTE_MeasObjectToAddMod, nr_meas_obj, ASFM_FREE_EVERYTHING);
+              LOG_E(RRC, "Failed to decode measurement object (%zu bits) %d\n", dec_rval.consumed, dec_rval.code);
+              break;
+            }
+            LOG_D(NR_RRC, "NR carrierFreq_r15 (ssb): %ld and sub carrier spacing:%ld\n",
+                  nr_meas_obj->measObject.choice.measObjectNR_r15.carrierFreq_r15,
+                  nr_meas_obj->measObject.choice.measObjectNR_r15.rs_ConfigSSB_r15.subcarrierSpacingSSB_r15);
+            start_oai_nrue_threads();
+            break;
+        }
+        case RRC_CONFIG_COMPLETE_REQ:
+        {
+            struct msg {
+                uint32_t RadioBearer_size;
+                uint32_t SecondaryCellGroup_size;
+                uint8_t trans_id;
+                uint8_t padding[3];
+                uint8_t buffer[];
+            } hdr;
+            AssertFatal(msg_len >= sizeof(hdr), "Bad received msg\n");
+            memcpy(&hdr, msg_buffer, sizeof(hdr));
+            LOG_I(NR_RRC, "We got an RRC_CONFIG_COMPLETE_REQ\n");
+            uint32_t nr_RadioBearer_size = hdr.RadioBearer_size;
+            uint32_t nr_SecondaryCellGroup_size = hdr.SecondaryCellGroup_size;
+            AssertFatal(sizeof(hdr) + nr_RadioBearer_size + nr_SecondaryCellGroup_size <= msg_len,
+                      "nr_RadioBearerConfig1_r15 size %d nr_SecondaryCellGroupConfig_r15 size %d sizeof(hdr) %zu, msg_len = %d\n",
+                      nr_RadioBearer_size,
+                      nr_SecondaryCellGroup_size,
+                      sizeof(hdr), msg_len);
+            NR_RRC_TransactionIdentifier_t t_id = hdr.trans_id;
+            LOG_I(NR_RRC, "nr_RadioBearerConfig1_r15 size %d nr_SecondaryCellGroupConfig_r15 size %d t_id %ld\n",
+                      nr_RadioBearer_size,
+                      nr_SecondaryCellGroup_size,
+                      t_id);
+
+            uint8_t *nr_RadioBearer_buffer = msg_buffer + offsetof(struct msg, buffer);
+            uint8_t *nr_SecondaryCellGroup_buffer = nr_RadioBearer_buffer + nr_RadioBearer_size;
+            process_nsa_message(NR_UE_rrc_inst, nr_SecondaryCellGroupConfig_r15, nr_SecondaryCellGroup_buffer,
+                                nr_SecondaryCellGroup_size);
+            process_nsa_message(NR_UE_rrc_inst, nr_RadioBearerConfigX_r15, nr_RadioBearer_buffer, nr_RadioBearer_size);
+            LOG_I(NR_RRC, "Calling do_NR_RRCReconfigurationComplete. t_id %ld \n", t_id);
+            uint8_t buffer[RRC_BUF_SIZE];
+            size_t size = do_NR_RRCReconfigurationComplete_for_nsa(buffer, sizeof(buffer), t_id);
+            nsa_sendmsg_to_lte_ue(buffer, size, NR_RRC_CONFIG_COMPLETE_REQ);
+            break;
+        }
+
+        case OAI_TUN_IFACE_NSA:
+        {
+          LOG_I(NR_RRC, "We got an OAI_TUN_IFACE_NSA!!\n");
+          char cmd_line[RRC_BUF_SIZE];
+          memcpy(cmd_line, msg_buffer, sizeof(cmd_line));
+          LOG_D(NR_RRC, "Command line: %s\n", cmd_line);
+          if (background_system(cmd_line) != 0)
+          {
+            LOG_E(NR_RRC, "ESM-PROC - failed command '%s'", cmd_line);
+          }
+          break;
+        }
+
+        default:
+            LOG_E(NR_RRC, "No NSA Message Found\n");
+    }
+}
diff --git a/openair2/RRC/NR_UE/rrc_defs.h b/openair2/RRC/NR_UE/rrc_defs.h
index 3aa98951f27684ada0bc01da1814d4784826d2e5..bf2c99c219f381d5f26c2293fdfa89a6530f8ff0 100644
--- a/openair2/RRC/NR_UE/rrc_defs.h
+++ b/openair2/RRC/NR_UE/rrc_defs.h
@@ -59,9 +59,9 @@
 #define NB_CNX_UE 2//MAX_MANAGED_RG_PER_MOBILE
 #define NB_SIG_CNX_UE 2 //MAX_MANAGED_RG_PER_MOBILE
 
-#define MAX_MEAS_OBJ 6
-#define MAX_MEAS_CONFIG 6
-#define MAX_MEAS_ID 6
+#define MAX_MEAS_OBJ 7
+#define MAX_MEAS_CONFIG 7
+#define MAX_MEAS_ID 7
 
 typedef uint32_t channel_t;
 
diff --git a/openair2/RRC/NR_UE/rrc_nsa.c b/openair2/RRC/NR_UE/rrc_nsa.c
new file mode 100644
index 0000000000000000000000000000000000000000..9e62243c658698e472feb9c4c110b86b89eaef26
--- /dev/null
+++ b/openair2/RRC/NR_UE/rrc_nsa.c
@@ -0,0 +1,85 @@
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include "common/utils/LOG/log.h"
+#include "openair2/RRC/NR_UE/rrc_proto.h"
+
+static const char nsa_ipaddr[] = "127.0.0.1";
+static int from_lte_ue_fd = -1;
+static int to_lte_ue_fd = -1;
+uint16_t ue_id_g;
+
+int get_from_lte_ue_fd()
+{
+    return from_lte_ue_fd;
+}
+
+void nsa_sendmsg_to_lte_ue(const void *message, size_t msg_len, MessagesIds msg_type)
+{
+    LOG_I(NR_RRC, "Entered %s \n", __FUNCTION__);
+    nsa_msg_t n_msg;
+    if (msg_len > sizeof(n_msg.msg_buffer))
+    {
+        LOG_E(NR_RRC, "%s: message too big: %zu\n", __func__, msg_len);
+        abort();
+    }
+    n_msg.msg_type = msg_type;
+    memcpy(n_msg.msg_buffer, message, msg_len);
+    size_t to_send = sizeof(n_msg.msg_type) + msg_len;
+
+    struct sockaddr_in sa =
+    {
+        .sin_family = AF_INET,
+        .sin_port = htons(6007 + ue_id_g * 2),
+    };
+    int sent = sendto(from_lte_ue_fd, &n_msg, to_send, 0,
+                      (struct sockaddr *)&sa, sizeof(sa));
+    if (sent == -1)
+    {
+        LOG_E(NR_RRC, "%s: sendto: %s\n", __func__, strerror(errno));
+        return;
+    }
+    if (sent != to_send)
+    {
+        LOG_E(NR_RRC, "%s: Short send %d != %zu\n", __func__, sent, to_send);
+        return;
+    }
+    LOG_D(NR_RRC, "Sent a %d message to the LTE UE (%d bytes) \n", msg_type, sent);
+}
+
+void init_connections_with_lte_ue(void)
+{
+    struct sockaddr_in sa =
+    {
+        .sin_family = AF_INET,
+        .sin_port = htons(6008 + ue_id_g * 2),
+    };
+    AssertFatal(from_lte_ue_fd == -1, "from_lte_ue_fd %d was assigned already", from_lte_ue_fd);
+    from_lte_ue_fd = socket(AF_INET, SOCK_DGRAM, 0);
+    if (from_lte_ue_fd == -1)
+    {
+        LOG_E(NR_RRC, "%s: Error opening socket %d (%d:%s)\n", __FUNCTION__, from_lte_ue_fd, errno, strerror(errno));
+        abort();
+    }
+
+    if (inet_aton(nsa_ipaddr, &sa.sin_addr) == 0)
+    {
+        LOG_E(NR_RRC, "Bad nsa_ipaddr '%s'\n", nsa_ipaddr);
+        abort();
+    }
+
+    if (bind(from_lte_ue_fd, (struct sockaddr *) &sa, sizeof(sa)) == -1)
+    {
+        LOG_E(NR_RRC,"%s: Failed to bind the socket\n", __FUNCTION__);
+        abort();
+    }
+
+    AssertFatal(to_lte_ue_fd == -1, "to_lte_ue_fd was assigned already");
+    to_lte_ue_fd = socket(AF_INET, SOCK_DGRAM, 0);
+    if (to_lte_ue_fd == -1)
+    {
+        LOG_E(NR_RRC, "%s: Error opening socket %d (%d:%s)\n", __FUNCTION__, to_lte_ue_fd, errno, strerror(errno));
+        abort();
+    }
+    LOG_I(NR_RRC, "Started LTE-NR link in the nr-UE\n");
+}
diff --git a/openair2/RRC/NR_UE/rrc_proto.h b/openair2/RRC/NR_UE/rrc_proto.h
index 78237a709cca2ffba1d96ff69c66c911b71b7216..62d9167251300a064289082f07ddb7a6e6ed5fe5 100644
--- a/openair2/RRC/NR_UE/rrc_proto.h
+++ b/openair2/RRC/NR_UE/rrc_proto.h
@@ -39,6 +39,19 @@
 #include "NR_MeasConfig.h"
 #include "NR_CellGroupConfig.h"
 #include "NR_RadioBearerConfig.h"
+#include "openair2/PHY_INTERFACE/queue_t.h"
+
+extern queue_t nr_rach_ind_queue;
+extern queue_t nr_rx_ind_queue;
+extern queue_t nr_crc_ind_queue;
+extern queue_t nr_uci_ind_queue;
+extern queue_t nr_sfn_slot_queue;
+extern queue_t nr_chan_param_queue;
+extern queue_t nr_dl_tti_req_queue;
+extern queue_t nr_tx_req_queue;
+extern queue_t nr_ul_dci_req_queue;
+extern queue_t nr_ul_tti_req_queue;
+extern queue_t nr_wait_ul_tti_req_queue;
 //
 //  main_rrc.c
 //
@@ -133,15 +146,40 @@ int8_t nr_mac_rrc_data_req_ue(const module_id_t Mod_idP,
                               const rb_id_t     Srb_id,
                               uint8_t           *buffer_pP);
 
+uint8_t
+rrc_data_req_nr_ue(
+  const protocol_ctxt_t   *const ctxt_pP,
+  const rb_id_t                  rb_idP,
+  const mui_t                    muiP,
+  const confirm_t                confirmP,
+  const sdu_size_t               sdu_sizeP,
+  uint8_t                 *const buffer_pP,
+  const pdcp_transmission_mode_t modeP
+);
+
 /**\brief RRC UE task.
    \param void *args_p Pointer on arguments to start the task. */
 void *rrc_nrue_task(void *args_p);
 
+/**\brief RRC NSA UE task.
+   \param void *args_p Pointer on arguments to start the task. */
+void *recv_msgs_from_lte_ue(void *args_p);
+
+void init_connections_with_lte_ue(void);
+
+void nsa_sendmsg_to_lte_ue(const void *message, size_t msg_len, MessagesIds msg_type);
+
+void start_oai_nrue_threads(void);
+
 /**\brief RRC UE generate RRCSetupRequest message.
    \param module_id  module id
    \param gNB_index  gNB index  */
 void nr_rrc_ue_generate_RRCSetupRequest(module_id_t module_id, const uint8_t gNB_index);
 
+void process_lte_nsa_msg(nsa_msg_t *msg, int msg_len);
+
+int get_from_lte_ue_fd();
+
 /** @}*/
 #endif
 
diff --git a/openair2/RRC/NR_UE/rrc_vars.h b/openair2/RRC/NR_UE/rrc_vars.h
index 30c74debdd2db39cc5f203782078627d24988800..ecb9335131af30de82e5765342a2c66dc528a7a0 100644
--- a/openair2/RRC/NR_UE/rrc_vars.h
+++ b/openair2/RRC/NR_UE/rrc_vars.h
@@ -37,5 +37,6 @@
 #include "rrc_defs.h"
 
 extern NR_UE_RRC_INST_t *NR_UE_rrc_inst;
+extern uint16_t ue_id_g;
 
 #endif
diff --git a/openair2/SIMULATION/NR_RRC/itti_sim.c b/openair2/SIMULATION/NR_RRC/itti_sim.c
index 67a03d8b06711fa58176f0d31136ce57f6e9b570..e3792dca77d19425940a700569b816874c93997f 100644
--- a/openair2/SIMULATION/NR_RRC/itti_sim.c
+++ b/openair2/SIMULATION/NR_RRC/itti_sim.c
@@ -383,7 +383,7 @@ void terminate_task(task_id_t task_id, module_id_t mod_id) {
 //extern void  free_transport(PHY_VARS_gNB *);
 extern void  nr_phy_free_RU(RU_t *);
 
-void init_pdcp(void) {
+statis void init_pdcp(void) {
   //if (!NODE_IS_DU(RC.rrc[0]->node_type)) {
   pdcp_layer_init();
   uint32_t pdcp_initmask = (IS_SOFTMODEM_NOS1) ?
@@ -394,10 +394,10 @@ void init_pdcp(void) {
     pdcp_initmask = pdcp_initmask | ENB_NAS_USE_TUN_BIT | SOFTMODEM_NOKRNMOD_BIT  ;
   }
 
-  pdcp_module_init(pdcp_initmask);
+  pdcp_module_init(pdcp_initmask, 0);
 
-  pdcp_set_rlc_data_req_func((send_rlc_data_req_func_t) rlc_data_req);
-  pdcp_set_pdcp_data_ind_func((pdcp_data_ind_func_t) pdcp_data_ind);
+  pdcp_set_rlc_data_req_func(rlc_data_req);
+  pdcp_set_pdcp_data_ind_func(pdcp_data_ind);
 }
 
 
@@ -406,7 +406,7 @@ int create_tasks_nrue(uint32_t ue_nb) {
   itti_wait_ready(1);
 
   if (ue_nb > 0) {
-    printf("create TASK_RRC_NRUE\n");
+    LOG_D(NR_RRC, "create TASK_RRC_NRUE\n");
     if (itti_create_task (TASK_RRC_NRUE, rrc_nrue_task, NULL) < 0) {
       LOG_E(NR_RRC, "Create task for RRC UE failed\n");
       return -1;
diff --git a/openair2/UTIL/ASYNC_IF/socket_link.c b/openair2/UTIL/ASYNC_IF/socket_link.c
index 51c55116752ca0ae52e465bd4f77e3de7c86165f..eac0b910696820ecad427ccf04ac4a44172143d9 100644
--- a/openair2/UTIL/ASYNC_IF/socket_link.c
+++ b/openair2/UTIL/ASYNC_IF/socket_link.c
@@ -409,10 +409,14 @@ static int socket_udp_receive(int socket_fd, void *buf, int size)
   socklen_t slen = sizeof(client);
   int   l;
 
-  l = recvfrom(socket_fd, buf, size, 0, (struct sockaddr *) &client, &slen);
+  l = recvfrom(socket_fd, buf, size, MSG_TRUNC, (struct sockaddr *) &client, &slen);
   //getsockname(socket_fd, (struct sockaddr *)&client, &slen);
   if (l == -1) goto error;
   if (l == 0) goto socket_closed;
+  if (l > size) {
+    LOG_E(MAC, "%s(%d). Message truncated. %d\n", __FUNCTION__, __LINE__, l);
+    return -1;
+  }
 
   return l;
 
diff --git a/openair2/UTIL/OPT/vars.h b/openair2/UTIL/OPT/vars.h
deleted file mode 100644
index 0da315aa8b06b50fd96eded1f5bc4549c466d0c1..0000000000000000000000000000000000000000
--- a/openair2/UTIL/OPT/vars.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
- */
-
-/*____________________________OPT/var.h___________________________
-Authors: Navid NIKAIEN
-Company: EURECOM
-Emails:
-*/
-extern mac_lte_tap_info *WS_mac_lte_tap_info;
-extern mac_lte_info     *WS_mac_lte_info;
diff --git a/openair2/X2AP/x2ap_eNB_generate_messages.c b/openair2/X2AP/x2ap_eNB_generate_messages.c
index 7c3a89e7f4bff4b0a652f8224d1b94161b375cf0..9724e0cc381b0435256fb69f5fd3120631ee6640 100644
--- a/openair2/X2AP/x2ap_eNB_generate_messages.c
+++ b/openair2/X2AP/x2ap_eNB_generate_messages.c
@@ -1734,7 +1734,9 @@ int x2ap_eNB_generate_ENDC_x2_SgNB_addition_request(
         X2AP_ERROR("Failed to encode ENDC X2 SgNB_addition request message\n");
         return -1;
     }
+    # if 0 // TODO: Sanitizer complains we are trying to access this after free.
 	free(ie->value.choice.MeNBtoSgNBContainer.buf);
+    #endif
     MSC_LOG_TX_MESSAGE (MSC_X2AP_SRC_ENB, MSC_X2AP_TARGET_ENB, NULL, 0, "0 X2Setup/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, 0);
diff --git a/openair3/GTPV1-U/gtpv1u_eNB.c b/openair3/GTPV1-U/gtpv1u_eNB.c
index 0fe2741d7bd1f3bd9d3b3357b64e8d01a32ce807..6f5ef004b5936d727afedb62635b392935044099 100644
--- a/openair3/GTPV1-U/gtpv1u_eNB.c
+++ b/openair3/GTPV1-U/gtpv1u_eNB.c
@@ -222,7 +222,7 @@ NwGtpv1uRcT gtpv1u_eNB_process_stack_req(
      * - END-MARKER
      */
     case NW_GTPV1U_ULP_API_RECV_TPDU: {
-      uint8_t              buffer[4096];
+      uint8_t              buffer[NFAPI_MAX_PACKED_MESSAGE_SIZE];
       uint32_t             buffer_len;
       struct rrc_eNB_ue_context_s        *ue_context_p;
       uint16_t             msgType = NW_GTP_GPDU;
@@ -432,11 +432,7 @@ NwGtpv1uRcT gtpv1u_eNB_process_stack_req(
                  );
 
         if ( result == FALSE ) {
-          if (ctxt.configured == FALSE )
-            LOG_W(GTPU, "PDCP data request failed, cause: [UE:%x]RB is not configured!\n", ctxt.rnti) ;
-          else
-            LOG_W(GTPU, "PDCP data request failed\n");
-
+          LOG_W(GTPU, "PDCP data request failed\n");
           return NW_GTPV1U_FAILURE;
         }
       } else {
@@ -912,7 +908,8 @@ gtpv1u_create_s1u_tunnel(
 
     do {
       s1u_teid = gtpv1u_new_teid();
-      LOG_D(GTPU, "gtpv1u_create_s1u_tunnel() 0x%x %u(dec)\n", s1u_teid, s1u_teid);
+      LOG_I(GTPU, "gtpv1u_data_g %p\n", RC.gtpv1u_data_g);
+      LOG_I(GTPU, "gtpv1u_create_s1u_tunnel() 0x%x %u(dec)\n", s1u_teid, s1u_teid);
       stack_req.apiInfo.createTunnelEndPointInfo.teid          = s1u_teid;
       stack_req.apiInfo.createTunnelEndPointInfo.hUlpSession   = 0;
       stack_req.apiInfo.createTunnelEndPointInfo.hStackSession = 0;
diff --git a/openair3/GTPV1-U/gtpv1u_gNB.c b/openair3/GTPV1-U/gtpv1u_gNB.c
index d3f26aeff11dce59553b8457263ca1003bcf1c58..ff7c8c06042ada5c623c3090ac655e52d616012e 100644
--- a/openair3/GTPV1-U/gtpv1u_gNB.c
+++ b/openair3/GTPV1-U/gtpv1u_gNB.c
@@ -191,9 +191,6 @@ NwGtpv1uRcT gtpv1u_gNB_process_stack_req(
                  );
 
         if ( result == FALSE ) {
-          if (ctxt.configured == FALSE )
-            LOG_W(GTPU, "gNB node PDCP data request failed, cause: [UE:%x]RB is not configured!\n", ctxt.rnti) ;
-          else
             LOG_W(GTPU, "PDCP data request failed\n");
 
           return NW_GTPV1U_FAILURE;
@@ -390,9 +387,6 @@ NwGtpv1uRcT nr_gtpv1u_gNB_process_stack_req(
                  );
 
         if ( result == FALSE ) {
-          if (ctxt.configured == FALSE )
-            LOG_W(GTPU, "gNB node PDCP data request failed, cause: [UE:%x]RB is not configured!\n", ctxt.rnti) ;
-          else
             LOG_W(GTPU, "PDCP data request failed\n");
 
           return NW_GTPV1U_FAILURE;
@@ -528,7 +522,7 @@ gtpv1u_create_ngu_tunnel(
     MSC_AS_TIME_FMT" CREATE_TUNNEL_REQ RNTI %"PRIx16" inst %u ntuns %u psid %u upf-ngu teid %u",
     0,0,create_tunnel_req_pP->rnti, instanceP,
     create_tunnel_req_pP->num_tunnels, create_tunnel_req_pP->pdusession_id[0],
-    create_tunnel_req_pP->upf_NGu_teid[0]);
+    create_tunnel_req_pP->outgoing_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;
@@ -579,16 +573,16 @@ gtpv1u_create_ngu_tunnel(
      
       LOG_I(GTPU,"Configured GTPu address : %x\n",RC.nr_gtpv1u_data_g->gnb_ip_address_for_NGu_up);
       create_tunnel_resp_pP->gnb_addr.length = sizeof (in_addr_t);
-      addrs_length_in_bytes = create_tunnel_req_pP->upf_addr[i].length / 8;
+      addrs_length_in_bytes = create_tunnel_req_pP->dst_addr[i].length / 8;
       AssertFatal((addrs_length_in_bytes == 4) ||
                   (addrs_length_in_bytes == 16) ||
                   (addrs_length_in_bytes == 20),
                   "Bad transport layer address length %d (bits) %d (bytes)",
-                  create_tunnel_req_pP->upf_addr[i].length, addrs_length_in_bytes);
+                  create_tunnel_req_pP->dst_addr[i].length, addrs_length_in_bytes);
 
       if ((addrs_length_in_bytes == 4) ||
           (addrs_length_in_bytes == 20)) {
-        in_addr = *((in_addr_t *)create_tunnel_req_pP->upf_addr[i].buffer);
+        in_addr = *((in_addr_t *)create_tunnel_req_pP->dst_addr[i].buffer);
         ip_offset = 4;
         gtpv1u_ue_data_p->bearers[pdusession_id - GTPV1U_BEARER_OFFSET].upf_ip_addr = in_addr;
       }
@@ -596,14 +590,14 @@ gtpv1u_create_ngu_tunnel(
       if ((addrs_length_in_bytes == 16) ||
           (addrs_length_in_bytes == 20)) {
         memcpy(gtpv1u_ue_data_p->bearers[pdusession_id - GTPV1U_BEARER_OFFSET].upf_ip6_addr.s6_addr,
-               &create_tunnel_req_pP->upf_addr[i].buffer[ip_offset],
+               &create_tunnel_req_pP->dst_addr[i].buffer[ip_offset],
                16);
       }
 
       gtpv1u_ue_data_p->bearers[pdusession_id - GTPV1U_BEARER_OFFSET].state                  = BEARER_IN_CONFIG;
       gtpv1u_ue_data_p->bearers[pdusession_id - GTPV1U_BEARER_OFFSET].teid_gNB               = ngu_teid;
       gtpv1u_ue_data_p->bearers[pdusession_id - GTPV1U_BEARER_OFFSET].teid_gNB_stack_session = stack_req.apiInfo.createTunnelEndPointInfo.hStackSession;
-      gtpv1u_ue_data_p->bearers[pdusession_id - GTPV1U_BEARER_OFFSET].teid_upf               = create_tunnel_req_pP->upf_NGu_teid[i];
+      gtpv1u_ue_data_p->bearers[pdusession_id - GTPV1U_BEARER_OFFSET].teid_upf               = create_tunnel_req_pP->outgoing_teid[i];
       gtpv1u_ue_data_p->num_bearers++;
       create_tunnel_resp_pP->gnb_NGu_teid[i] = ngu_teid;
 
@@ -861,7 +855,7 @@ static int gtpv1u_gnb_tunnel_data_req(gtpv1u_gnb_tunnel_data_req_t *gnb_tunnel_d
   hashtable_rc_t                hash_rc              = HASH_TABLE_KEY_NOT_EXISTS;
   nr_gtpv1u_ue_data_t          *gtpv1u_ue_data_p     = NULL;
   teid_t                        gnb_ngu_teid         = 0;
-  teid_t                        upf_ngu_teid         = 0;
+  teid_t                        outgoing_teid         = 0;
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_GTPV1U_PROCESS_TUNNEL_DATA_REQ, VCD_FUNCTION_IN);
   data_req_p = gnb_tunnel_data_req;
 
@@ -873,13 +867,13 @@ static int gtpv1u_gnb_tunnel_data_req(gtpv1u_gnb_tunnel_data_req_t *gnb_tunnel_d
   } else {
     if ((data_req_p->pdusession_id >= GTPV1U_BEARER_OFFSET) && (data_req_p->pdusession_id < max_val_NR_DRB_Identity)) {
       gnb_ngu_teid                        = gtpv1u_ue_data_p->bearers[data_req_p->pdusession_id - GTPV1U_BEARER_OFFSET].teid_gNB;
-      upf_ngu_teid                        = gtpv1u_ue_data_p->bearers[data_req_p->pdusession_id - GTPV1U_BEARER_OFFSET].teid_upf;
+      outgoing_teid                        = gtpv1u_ue_data_p->bearers[data_req_p->pdusession_id - GTPV1U_BEARER_OFFSET].teid_upf;
       stack_req.apiType                   = NW_GTPV1U_ULP_API_SEND_TPDU;
-      stack_req.apiInfo.sendtoInfo.teid   = upf_ngu_teid;
+      stack_req.apiInfo.sendtoInfo.teid   = outgoing_teid;
       stack_req.apiInfo.sendtoInfo.ipAddr = gtpv1u_ue_data_p->bearers[data_req_p->pdusession_id - GTPV1U_BEARER_OFFSET].upf_ip_addr;
       rc = nwGtpv1uGpduMsgNew(
               RC.nr_gtpv1u_data_g->gtpv1u_stack,
-              upf_ngu_teid,
+              outgoing_teid,
               NW_FALSE,
               RC.nr_gtpv1u_data_g->seq_num++,
               data_req_p->buffer,
@@ -890,7 +884,7 @@ static int gtpv1u_gnb_tunnel_data_req(gtpv1u_gnb_tunnel_data_req_t *gnb_tunnel_d
       if (rc != NW_GTPV1U_OK) {
         LOG_E(GTPU, "nwGtpv1uGpduMsgNew failed: 0x%x\n", rc);
         MSC_LOG_EVENT(MSC_GTPU_GNB,"0 Failed send G-PDU ltid %u rtid %u size %u",
-                      gnb_ngu_teid,upf_ngu_teid,data_req_p->length);
+                      gnb_ngu_teid,outgoing_teid,data_req_p->length);
         (void)gnb_ngu_teid; /* avoid gcc warning "set but not used" */
       } else {
         rc = nwGtpv1uProcessUlpReq(RC.nr_gtpv1u_data_g->gtpv1u_stack, &stack_req);
@@ -898,7 +892,7 @@ static int gtpv1u_gnb_tunnel_data_req(gtpv1u_gnb_tunnel_data_req_t *gnb_tunnel_d
         if (rc != NW_GTPV1U_OK) {
           LOG_E(GTPU, "nwGtpv1uProcessUlpReq failed: 0x%x\n", rc);
           MSC_LOG_EVENT(MSC_GTPU_GNB,"0 Failed send G-PDU ltid %u rtid %u size %u",
-                        gnb_ngu_teid,upf_ngu_teid,data_req_p->length);
+                        gnb_ngu_teid,outgoing_teid,data_req_p->length);
         } else {
           MSC_LOG_TX_MESSAGE(
             MSC_GTPU_GNB,
@@ -908,7 +902,7 @@ static int gtpv1u_gnb_tunnel_data_req(gtpv1u_gnb_tunnel_data_req_t *gnb_tunnel_d
             MSC_AS_TIME_FMT" G-PDU ltid %u rtid %u size %u",
             0,0,
             gnb_ngu_teid,
-            upf_ngu_teid,
+            outgoing_teid,
             data_req_p->length);
         }
 
diff --git a/openair3/GTPV1-U/gtpv1u_task.c b/openair3/GTPV1-U/gtpv1u_task.c
deleted file mode 100644
index 1339839cf971edd203f2e9100a769a7b4df9ac26..0000000000000000000000000000000000000000
--- a/openair3/GTPV1-U/gtpv1u_task.c
+++ /dev/null
@@ -1,485 +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 gtpv1u_task.c
-* \brief
-* \author Sebastien ROUX, Lionel Gauthier
-* \company Eurecom
-* \email: lionel.gauthier@eurecom.fr
-*/
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-#include <sys/time.h>
-
-#include "mme_config.h"
-
-#include "assertions.h"
-#include "intertask_interface.h"
-
-#include "gtpv1u.h"
-#include "NwGtpv1u.h"
-#include "NwGtpv1uMsg.h"
-#include "NwLog.h"
-#include "gtpv1u_sgw_defs.h"
-#include "NwGtpv1uPrivate.h"
-#include "msc.h"
-
-//static NwGtpv1uStackHandleT gtpv1u_stack = 0;
-static gtpv1u_data_t        gtpv1u_sgw_data;
-
-
-static int gtpv1u_create_s1u_tunnel(Gtpv1uCreateTunnelReq *create_tunnel_reqP);
-static int gtpv1u_delete_s1u_tunnel(Teid_t context_teidP, Teid_t S1U_teidP);
-static int gtpv1u_update_s1u_tunnel(Gtpv1uUpdateTunnelReq *reqP);
-static void *gtpv1u_thread(void *args);
-
-NwGtpv1uRcT gtpv1u_send_udp_msg(
-  NwGtpv1uUdpHandleT udpHandle,
-  uint8_t *buffer,
-  uint32_t buffer_len,
-  uint32_t buffer_offset,
-  uint32_t peerIpAddr,
-  uint32_t peerPort);
-
-NwGtpv1uRcT gtpv1u_log_request(
-  NwGtpv1uLogMgrHandleT hLogMgr,
-  uint32_t logLevel,
-  NwCharT *file,
-  uint32_t line,
-  NwCharT *logStr);
-
-NwGtpv1uRcT gtpv1u_process_stack_req(
-  NwGtpv1uUlpHandleT hUlp,
-  NwGtpv1uUlpApiT *pUlpApi);
-
-
-//-----------------------------------------------------------------------------
-void gtpu_print_hex_octets(unsigned char* dataP, unsigned long sizeP)
-//-----------------------------------------------------------------------------
-{
-  unsigned long octet_index = 0;
-  unsigned long buffer_marker = 0;
-  unsigned char aindex;
-#define GTPU_2_PRINT_BUFFER_LEN 8000
-  char gtpu_2_print_buffer[GTPU_2_PRINT_BUFFER_LEN];
-  struct timeval tv;
-  struct timezone tz;
-  char timeofday[64];
-  unsigned int h,m,s;
-
-  if (dataP == NULL) {
-    return;
-  }
-
-  gettimeofday(&tv, &tz);
-  h = tv.tv_sec/3600/24;
-  m = (tv.tv_sec / 60) % 60;
-  s = tv.tv_sec % 60;
-  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);
-  GTPU_DEBUG("%s------+-------------------------------------------------|\n",timeofday);
-
-  for (octet_index = 0; octet_index < sizeP; octet_index++) {
-    if (GTPU_2_PRINT_BUFFER_LEN < (buffer_marker + 32))  {
-      buffer_marker+=snprintf(&gtpu_2_print_buffer[buffer_marker], GTPU_2_PRINT_BUFFER_LEN - buffer_marker,
-                              "... (print buffer overflow)");
-      GTPU_DEBUG("%s%s",timeofday,gtpu_2_print_buffer);
-      return;
-    }
-
-    if ((octet_index % 16) == 0) {
-      if (octet_index != 0) {
-        buffer_marker+=snprintf(&gtpu_2_print_buffer[buffer_marker], GTPU_2_PRINT_BUFFER_LEN - buffer_marker, " |\n");
-        GTPU_DEBUG("%s%s",timeofday, gtpu_2_print_buffer);
-        buffer_marker = 0;
-      }
-
-      buffer_marker+=snprintf(&gtpu_2_print_buffer[buffer_marker], GTPU_2_PRINT_BUFFER_LEN - buffer_marker, " %04lu |", octet_index);
-    }
-
-    /*
-     * Print every single octet in hexadecimal form
-     */
-    buffer_marker+=snprintf(&gtpu_2_print_buffer[buffer_marker], GTPU_2_PRINT_BUFFER_LEN - buffer_marker, " %02x", dataP[octet_index]);
-    /*
-     * Align newline and pipes according to the octets in groups of 2
-     */
-  }
-
-  /*
-   * Append enough spaces and put final pipe
-   */
-  for (aindex = octet_index; aindex < 16; ++aindex)
-    buffer_marker+=snprintf(&gtpu_2_print_buffer[buffer_marker], GTPU_2_PRINT_BUFFER_LEN - buffer_marker, "   ");
-
-  //GTPU_DEBUG("   ");
-  buffer_marker+=snprintf(&gtpu_2_print_buffer[buffer_marker], GTPU_2_PRINT_BUFFER_LEN - buffer_marker, " |\n");
-  GTPU_DEBUG("%s%s",timeofday,gtpu_2_print_buffer);
-}
-
-
-NwGtpv1uRcT gtpv1u_log_request(NwGtpv1uLogMgrHandleT hLogMgr,
-                               uint32_t logLevel,
-                               NwCharT *file,
-                               uint32_t line,
-                               NwCharT *logStr)
-{
-  GTPU_DEBUG("%s\n", logStr);
-  return NW_GTPV1U_OK;
-}
-
-NwGtpv1uRcT gtpv1u_send_udp_msg(
-  NwGtpv1uUdpHandleT udpHandle,
-  uint8_t *buffer,
-  uint32_t buffer_len,
-  uint32_t buffer_offset,
-  uint32_t peerIpAddr,
-  uint32_t peerPort)
-{
-  // Create and alloc new message
-  MessageDef     *message_p;
-  udp_data_req_t *udp_data_req_p;
-
-  message_p = itti_alloc_new_message(TASK_GTPV1_U, UDP_DATA_REQ);
-
-  udp_data_req_p = &message_p->ittiMsg.udp_data_req;
-
-  udp_data_req_p->peer_address  = peerIpAddr;
-  udp_data_req_p->peer_port     = peerPort;
-  udp_data_req_p->buffer        = buffer;
-  udp_data_req_p->buffer_length = buffer_len;
-  udp_data_req_p->buffer_offset = buffer_offset;
-
-  return itti_send_msg_to_task(TASK_UDP, INSTANCE_DEFAULT, message_p);
-}
-
-/* Callback called when a gtpv1u message arrived on UDP interface */
-NwGtpv1uRcT gtpv1u_process_stack_req(
-  NwGtpv1uUlpHandleT hUlp,
-  NwGtpv1uUlpApiT *pUlpApi)
-{
-  switch(pUlpApi->apiType) {
-    /* Here there are two type of messages handled:
-     * - T-PDU
-     * - END-MARKER
-     */
-  case NW_GTPV1U_ULP_API_RECV_TPDU: {
-    //uint8_t              buffer[4096];
-    //uint32_t             buffer_len;
-    MessageDef          *message_p  = NULL;
-    Gtpv1uTunnelDataInd *data_ind_p = NULL;
-
-    /* Nw-gptv1u stack has processed a PDU. we can forward it to IPV4
-     * task for transmission.
-     */
-    /*if (NW_GTPV1U_OK != nwGtpv1uMsgGetTpdu(pUlpApi->apiInfo.recvMsgInfo.hMsg,
-        buffer, (uint32_t *)&buffer_len)) {
-        GTPU_ERROR("Error while retrieving T-PDU\n");
-    }*/
-    GTPU_DEBUG("Received TPDU from gtpv1u stack %u with size %d\n",
-               pUlpApi->apiInfo.recvMsgInfo.teid,
-               ((NwGtpv1uMsgT*)pUlpApi->apiInfo.recvMsgInfo.hMsg)->msgBufLen);
-
-    message_p = itti_alloc_new_message(TASK_GTPV1_U, GTPV1U_TUNNEL_DATA_IND);
-
-    if (message_p == NULL) {
-      return -1;
-    }
-
-    data_ind_p                       = &message_p->ittiMsg.gtpv1uTunnelDataInd;
-    data_ind_p->buffer               = ((NwGtpv1uMsgT*)pUlpApi->apiInfo.recvMsgInfo.hMsg)->msgBuf;
-    data_ind_p->length               = ((NwGtpv1uMsgT*)pUlpApi->apiInfo.recvMsgInfo.hMsg)->msgBufLen;
-    data_ind_p->offset               = ((NwGtpv1uMsgT*)pUlpApi->apiInfo.recvMsgInfo.hMsg)->msgBufOffset;
-    data_ind_p->local_S1u_teid       = pUlpApi->apiInfo.recvMsgInfo.teid;
-
-    if (data_ind_p->buffer == NULL) {
-      GTPU_ERROR("Failed to allocate new buffer\n");
-      itti_free(ITTI_MSG_ORIGIN_ID(message_p), message_p);
-      message_p = NULL;
-    } else {
-      //memcpy(data_ind_p->buffer, buffer, buffer_len);
-      //data_ind_p->length = buffer_len;
-      if (itti_send_msg_to_task(TASK_FW_IP, INSTANCE_DEFAULT, message_p) < 0) {
-        GTPU_ERROR("Failed to send message to task\n");
-        itti_free(ITTI_MSG_ORIGIN_ID(message_p), message_p);
-        message_p = NULL;
-      }
-    }
-  }
-  break;
-
-  case NW_GTPV1U_ULP_API_CREATE_TUNNEL_ENDPOINT: {
-  }
-  break;
-
-  default: {
-    GTPU_ERROR("Received undefined UlpApi (%02x) from gtpv1u stack!\n",
-               pUlpApi->apiType);
-  }
-  }
-
-  return NW_GTPV1U_OK;
-}
-
-static int gtpv1u_create_s1u_tunnel(Gtpv1uCreateTunnelReq *create_tunnel_reqP)
-{
-  /* Create a new nw-gtpv1-u stack req using API */
-  NwGtpv1uUlpApiT          stack_req;
-  NwGtpv1uRcT              rc;
-  /* Local tunnel end-point identifier */
-  uint32_t                 s1u_teid             = 0;
-  gtpv1u_teid2enb_info_t  *gtpv1u_teid2enb_info = NULL;
-  MessageDef              *message_p            = NULL;
-  hashtable_rc_t           hash_rc;
-
-  GTPU_DEBUG("Rx GTPV1U_CREATE_TUNNEL_REQ Context %d\n", create_tunnel_reqP->context_teid);
-  memset(&stack_req, 0, sizeof(NwGtpv1uUlpApiT));
-
-  stack_req.apiType = NW_GTPV1U_ULP_API_CREATE_TUNNEL_ENDPOINT;
-
-  do {
-    s1u_teid = gtpv1u_new_teid();
-    GTPU_DEBUG("gtpv1u_create_s1u_tunnel() %u\n", s1u_teid);
-    stack_req.apiInfo.createTunnelEndPointInfo.teid          = s1u_teid;
-    stack_req.apiInfo.createTunnelEndPointInfo.hUlpSession   = 0;
-    stack_req.apiInfo.createTunnelEndPointInfo.hStackSession = 0;
-
-    rc = nwGtpv1uProcessUlpReq(gtpv1u_sgw_data.gtpv1u_stack, &stack_req);
-    GTPU_DEBUG(".\n");
-  } while (rc != NW_GTPV1U_OK);
-
-  gtpv1u_teid2enb_info = malloc (sizeof(gtpv1u_teid2enb_info_t));
-  memset(gtpv1u_teid2enb_info, 0, sizeof(gtpv1u_teid2enb_info_t));
-  gtpv1u_teid2enb_info->state       = BEARER_IN_CONFIG;
-
-  //#warning !!! hack because missing modify session request, so force enb address
-  //    gtpv1u_teid2enb_info->enb_ip_addr.pdn_type = IPv4;
-  //    gtpv1u_teid2enb_info->enb_ip_addr.address.ipv4_address[0] = 192;
-  //    gtpv1u_teid2enb_info->enb_ip_addr.address.ipv4_address[1] = 168;
-  //    gtpv1u_teid2enb_info->enb_ip_addr.address.ipv4_address[2] = 1;
-  //    gtpv1u_teid2enb_info->enb_ip_addr.address.ipv4_address[3] = 2;
-
-
-  message_p = itti_alloc_new_message(TASK_GTPV1_U, GTPV1U_CREATE_TUNNEL_RESP);
-  message_p->ittiMsg.gtpv1uCreateTunnelResp.S1u_teid      = s1u_teid;
-  message_p->ittiMsg.gtpv1uCreateTunnelResp.context_teid  = create_tunnel_reqP->context_teid;
-  message_p->ittiMsg.gtpv1uCreateTunnelResp.eps_bearer_id = create_tunnel_reqP->eps_bearer_id;
-
-  hash_rc = hashtable_is_key_exists(gtpv1u_sgw_data.S1U_mapping, s1u_teid);
-
-  if (hash_rc == HASH_TABLE_KEY_NOT_EXISTS) {
-    hash_rc = hashtable_insert(gtpv1u_sgw_data.S1U_mapping, s1u_teid, gtpv1u_teid2enb_info);
-    message_p->ittiMsg.gtpv1uCreateTunnelResp.status       = 0;
-  } else {
-    message_p->ittiMsg.gtpv1uCreateTunnelResp.status       = 0xFF;
-  }
-
-  GTPU_DEBUG("Tx GTPV1U_CREATE_TUNNEL_RESP Context %u teid %u eps bearer id %u status %d\n",
-             message_p->ittiMsg.gtpv1uCreateTunnelResp.context_teid,
-             message_p->ittiMsg.gtpv1uCreateTunnelResp.S1u_teid,
-             message_p->ittiMsg.gtpv1uCreateTunnelResp.eps_bearer_id,
-             message_p->ittiMsg.gtpv1uCreateTunnelResp.status);
-  return itti_send_msg_to_task(TASK_SPGW_APP, INSTANCE_DEFAULT, message_p);
-}
-
-
-
-static int gtpv1u_delete_s1u_tunnel(Teid_t context_teidP, Teid_t S1U_teidP)
-{
-  /* Local tunnel end-point identifier */
-  MessageDef              *message_p;
-
-  GTPU_DEBUG("Rx GTPV1U_DELETE_TUNNEL Context %u S1U teid %u\n", context_teidP, S1U_teidP);
-  message_p = itti_alloc_new_message(TASK_GTPV1_U, GTPV1U_DELETE_TUNNEL_RESP);
-
-  message_p->ittiMsg.gtpv1uDeleteTunnelResp.S1u_teid     = S1U_teidP;
-  message_p->ittiMsg.gtpv1uDeleteTunnelResp.context_teid = context_teidP;
-
-  if (hashtable_remove(gtpv1u_sgw_data.S1U_mapping, S1U_teidP) == HASH_TABLE_OK ) {
-    message_p->ittiMsg.gtpv1uDeleteTunnelResp.status       = 0;
-  } else {
-    message_p->ittiMsg.gtpv1uDeleteTunnelResp.status       = -1;
-  }
-
-  GTPU_DEBUG("Tx SGW_S1U_ENDPOINT_CREATED Context %u teid %u status %d\n", context_teidP, S1U_teidP, message_p->ittiMsg.gtpv1uDeleteTunnelResp.status);
-  return itti_send_msg_to_task(TASK_SPGW_APP, INSTANCE_DEFAULT, message_p);
-}
-
-
-static int gtpv1u_update_s1u_tunnel(Gtpv1uUpdateTunnelReq *reqP)
-{
-  hashtable_rc_t           hash_rc;
-  gtpv1u_teid2enb_info_t  *gtpv1u_teid2enb_info;
-  MessageDef              *message_p;
-
-  GTPU_DEBUG("Rx GTPV1U_UPDATE_TUNNEL_REQ Context %u, S-GW S1U teid %u, eNB S1U teid %u\n",
-             reqP->context_teid,
-             reqP->sgw_S1u_teid,
-             reqP->enb_S1u_teid);
-  message_p = itti_alloc_new_message(TASK_GTPV1_U, GTPV1U_UPDATE_TUNNEL_RESP);
-
-  hash_rc = hashtable_get(gtpv1u_sgw_data.S1U_mapping, reqP->sgw_S1u_teid, (void**)&gtpv1u_teid2enb_info);
-
-  if (hash_rc == HASH_TABLE_OK) {
-    gtpv1u_teid2enb_info->teid_enb    = reqP->enb_S1u_teid;
-    gtpv1u_teid2enb_info->enb_ip_addr = reqP->enb_ip_address_for_S1u;
-    gtpv1u_teid2enb_info->state       = BEARER_UP;
-    gtpv1u_teid2enb_info->port        = GTPV1U_UDP_PORT;
-    message_p->ittiMsg.gtpv1uUpdateTunnelResp.status = 0;           ///< Status (Failed = 0xFF or Success = 0x0)
-  } else {
-    GTPU_ERROR("Mapping not found\n");
-    message_p->ittiMsg.gtpv1uUpdateTunnelResp.status = 0xFF;           ///< Status (Failed = 0xFF or Success = 0x0)
-  }
-
-  message_p->ittiMsg.gtpv1uUpdateTunnelResp.context_teid  = reqP->context_teid;
-  message_p->ittiMsg.gtpv1uUpdateTunnelResp.sgw_S1u_teid  = reqP->sgw_S1u_teid;
-  message_p->ittiMsg.gtpv1uUpdateTunnelResp.enb_S1u_teid  = reqP->enb_S1u_teid;
-  message_p->ittiMsg.gtpv1uUpdateTunnelResp.eps_bearer_id = reqP->eps_bearer_id;
-  return itti_send_msg_to_task(TASK_SPGW_APP, INSTANCE_DEFAULT, message_p);
-}
-
-
-static NwGtpv1uRcT gtpv1u_start_timer_wrapper(
-  NwGtpv1uTimerMgrHandleT tmrMgrHandle,
-  uint32_t                  timeoutSec,
-  uint32_t                  timeoutUsec,
-  uint32_t                  tmrType,
-  void                   *timeoutArg,
-  NwGtpv1uTimerHandleT   *hTmr)
-{
-
-  NwGtpv1uRcT rc = NW_GTPV1U_OK;
-  long        timer_id;
-
-  if (tmrType == NW_GTPV1U_TMR_TYPE_ONE_SHOT) {
-    timer_setup(timeoutSec,
-                timeoutUsec,
-                TASK_GTPV1_U,
-                INSTANCE_DEFAULT,
-                TIMER_ONE_SHOT,
-                timeoutArg,
-                &timer_id);
-  } else {
-    timer_setup(timeoutSec,
-                timeoutUsec,
-                TASK_GTPV1_U,
-                INSTANCE_DEFAULT,
-                TIMER_PERIODIC,
-                timeoutArg,
-                &timer_id);
-  }
-
-  return rc;
-}
-
-static NwGtpv1uRcT gtpv1u_stop_timer_wrapper(
-  NwGtpv1uTimerMgrHandleT tmrMgrHandle,
-  NwGtpv1uTimerHandleT hTmr)
-{
-
-  NwGtpv1uRcT rc = NW_GTPV1U_OK;
-
-  return rc;
-}
-
-static void *gtpv1u_thread(void *args)
-{
-  itti_mark_task_ready(TASK_GTPV1_U);
-  MSC_START_USE();
-
-  while(1) {
-    /* 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.
-     */
-    MessageDef *received_message_p = NULL;
-    itti_receive_msg(TASK_GTPV1_U, &received_message_p);
-    DevAssert(received_message_p != NULL);
-
-
-    switch (ITTI_MSG_ID(received_message_p)) {
-
-    case TERMINATE_MESSAGE: {
-      GTPU_WARN(" *** Exiting GTPU thread\n");
-      itti_exit_task();
-    }
-    break;
-
-    // DATA COMING FROM UDP
-    case UDP_DATA_IND: {
-      udp_data_ind_t *udp_data_ind_p;
-      udp_data_ind_p = &received_message_p->ittiMsg.udp_data_ind;
-      nwGtpv1uProcessUdpReq(gtpv1u_sgw_data.gtpv1u_stack,
-                             udp_data_ind_p->buffer,
-                             udp_data_ind_p->buffer_length,
-                             udp_data_ind_p->peer_port,
-                             udp_data_ind_p->peer_address);
-       //itti_free(ITTI_MSG_ORIGIN_ID(received_message_p), udp_data_ind_p->buffer);
-    }
-    break;
-
-    case TIMER_HAS_EXPIRED:
-      nwGtpv1uProcessTimeout(&received_message_p->ittiMsg.timer_has_expired.arg);
-      break;
-
-    default: {
-      GTPU_ERROR("Unkwnon message ID %d:%s\n",
-                 ITTI_MSG_ID(received_message_p),
-                 ITTI_MSG_NAME(received_message_p));
-    }
-    break;
-    }
-
-    itti_free(ITTI_MSG_ORIGIN_ID(received_message_p), received_message_p);
-    received_message_p = NULL;
-  }
-
-  return NULL;
-}
-
-int gtpv1u_init(const mme_config_t *mme_config_p)
-{
-  int                     ret = 0;
-  NwGtpv1uRcT             rc  = 0;
-  NwGtpv1uUlpEntityT      ulp;
-  NwGtpv1uUdpEntityT      udp;
-  NwGtpv1uLogMgrEntityT   log;
-  NwGtpv1uTimerMgrEntityT tmr;
-
-  GTPU_DEBUG("Initializing GTPV1U interface\n");
-
-  memset(&gtpv1u_sgw_data, 0, sizeof(gtpv1u_sgw_data));
-
-  gtpv1u_sgw_data.sgw_ip_address_for_S1u_S12_S4_up = mme_config_p->ipv4.sgw_ip_address_for_S1u_S12_S4_up;
-
-  if (itti_create_task(TASK_GTPV1_U, &gtpv1u_thread, NULL) < 0) {
-    GTPU_ERROR("gtpv1u phtread_create: %s", strerror(errno));
-    return -1;
-  }
-
-  GTPU_DEBUG("Initializing GTPV1U interface: DONE\n");
-
-  return ret;
-}
diff --git a/openair3/NAS/NR_UE/nr_nas_msg_sim.c b/openair3/NAS/NR_UE/nr_nas_msg_sim.c
index ad2f2c7c3c6795789e059bc8523f5b5e1be443c2..2628c5b0b25681e3d603b6e5a923e35acb808be9 100644
--- a/openair3/NAS/NR_UE/nr_nas_msg_sim.c
+++ b/openair3/NAS/NR_UE/nr_nas_msg_sim.c
@@ -43,6 +43,7 @@
 #include <openair3/UICC/usim_interface.h>
 #include <openair3/NAS/COMMON/NR_NAS_defs.h>
 #include <openair1/PHY/phy_extern_nr_ue.h>
+#include <openair1/SIMULATION/ETH_TRANSPORT/proto.h>
 
 uint8_t  *registration_request_buf;
 uint32_t  registration_request_len;
@@ -775,6 +776,30 @@ static void generatePduSessionEstablishRequest(int Mod_id, uicc_t * uicc, as_nas
 }
 
 
+uint8_t get_msg_type(uint8_t *pdu_buffer, uint32_t length) {
+  uint8_t          msg_type = 0;
+  uint8_t          offset   = 0;
+
+  if ((pdu_buffer != NULL) && (length > 0)) {
+    if (((nas_msg_header_t *)(pdu_buffer))->choice.security_protected_nas_msg_header_t.security_header_type > 0) {
+      offset += SECURITY_PROTECTED_5GS_NAS_MESSAGE_HEADER_LENGTH;
+      if (offset < length) {
+        msg_type = ((mm_msg_header_t *)(pdu_buffer + offset))->message_type;
+
+        if (msg_type == FGS_DOWNLINK_NAS_TRANSPORT) {
+          msg_type = ((dl_nas_transport_t *)(pdu_buffer+ offset))->sm_nas_msg_header.message_type;
+        }
+      }
+    } else { // plain 5GS NAS message
+      msg_type = ((nas_msg_header_t *)(pdu_buffer))->choice.plain_nas_msg_header.message_type;
+    }
+  } else {
+    LOG_I(NAS, "[UE] Received invalid downlink message\n");
+  }
+
+  return msg_type;
+}
+
 void *nas_nrue_task(void *args_p)
 {
   MessageDef           *msg_p;
@@ -848,23 +873,8 @@ void *nas_nrue_task(void *args_p)
               NAS_CONN_ESTABLI_CNF (msg_p).errCode, NAS_CONN_ESTABLI_CNF (msg_p).nasMsg.length);
 
         pdu_buffer = NAS_CONN_ESTABLI_CNF (msg_p).nasMsg.data;
-        if((pdu_buffer + 1) != NULL){
-          if (*(pdu_buffer + 1) > 0 ) {
-            if((pdu_buffer + 9) != NULL){
-                msg_type = *(pdu_buffer + 9);
-            } else {
-              LOG_W(NAS, "[UE] Received invalid downlink message\n");
-              break;
-            }
-          } else {
-            if((pdu_buffer + 2) != NULL){
-              msg_type = *(pdu_buffer + 2);
-            } else {
-                LOG_W(NAS, "[UE] Received invalid downlink message\n");
-                break;
-            }
-          }
-        }
+        msg_type = get_msg_type(pdu_buffer, NAS_CONN_ESTABLI_CNF (msg_p).nasMsg.length);
+
         if(msg_type == REGISTRATION_ACCEPT){
           LOG_I(NAS, "[UE] Received REGISTRATION ACCEPT message\n");
 
@@ -893,20 +903,39 @@ void *nas_nrue_task(void *args_p)
             itti_send_msg_to_task(TASK_RRC_NRUE, instance, message_p);
             LOG_I(NAS, "Send NAS_UPLINK_DATA_REQ message(PduSessionEstablishRequest)\n");
           }
-        }
-        else if((pdu_buffer + 16) != NULL){
-          msg_type = *(pdu_buffer + 16);
-          if(msg_type == FGS_PDU_SESSION_ESTABLISHMENT_ACC){
-            if(baseNetAddress==NULL) {
-              baseNetAddress = calloc(1,8);
+        } else if(msg_type == FGS_PDU_SESSION_ESTABLISHMENT_ACC){
+            uint8_t offset = 0;
+            uint8_t *payload_container = NULL;
+            offset += SECURITY_PROTECTED_5GS_NAS_MESSAGE_HEADER_LENGTH;
+            uint16_t payload_container_length = htons(((dl_nas_transport_t *)(pdu_buffer + offset))->payload_container_length);
+            if ((payload_container_length >= PAYLOAD_CONTAINER_LENGTH_MIN) && (payload_container_length <= PAYLOAD_CONTAINER_LENGTH_MAX)) {
+              offset += (PLAIN_5GS_NAS_MESSAGE_HEADER_LENGTH + 3);
+            }
+
+            if (offset < NAS_CONN_ESTABLI_CNF(msg_p).nasMsg.length) {
+              payload_container = pdu_buffer + offset;
+            }
+            offset = 0;
+
+            while(offset < payload_container_length) {
+	      // Fixme: this is not good 'type' 0x29 searching in TLV like structure
+	      // AND fix dirsty code copy hereafter of the same!!!
+              if (*(payload_container + offset) == 0x29) { // PDU address IEI
+                if ((*(payload_container+offset+1) == 0x05) && (*(payload_container +offset+2) == 0x01)) { // IPV4
+                  nas_getparams();
+                  sprintf(baseNetAddress, "%d.%d", *(payload_container+offset+3), *(payload_container+offset+4));
+                  int third_octet = *(payload_container+offset+5);
+                  int fourth_octet = *(payload_container+offset+6);
+                  LOG_I(NAS, "Received PDU Session Establishment Accept, UE IP: %d.%d.%d.%d\n",
+                    *(payload_container+offset+3), *(payload_container+offset+4),
+                    *(payload_container+offset+5), *(payload_container+offset+6));
+                  nas_config(1,third_octet,fourth_octet,"oaitun_ue");
+                  break;
+                }
+              }
+              offset++;
             }
-            sprintf(baseNetAddress, "%d.%d", *(pdu_buffer + 39),*(pdu_buffer + 40));
-            int third_octet = *(pdu_buffer + 41);
-            int fourth_octet = *(pdu_buffer + 42);
-            LOG_I(NAS, "Received PDU Session Establishment Accept\n");
-            nas_config(1,third_octet,fourth_octet,"ue");
           }
-        }
 
         break;
       }
@@ -933,19 +962,10 @@ void *nas_nrue_task(void *args_p)
         as_nas_info_t initialNasMsg={0};
 
         pdu_buffer = NAS_DOWNLINK_DATA_IND(msg_p).nasMsg.data;
-        if((pdu_buffer + 1) != NULL){
-          if (*(pdu_buffer + 1) > 0 ) {
-            msg_type = *(pdu_buffer + 9);
-          } else {
-            msg_type = *(pdu_buffer + 2);
-          }
-        }
-        if((pdu_buffer + 2) == NULL){
-          LOG_W(NAS, "[UE] Received invalid downlink message\n");
-          return 0;
-        }
+        msg_type = get_msg_type(pdu_buffer, NAS_DOWNLINK_DATA_IND(msg_p).nasMsg.length);
 
         switch(msg_type){
+
           case FGS_IDENTITY_REQUEST:
 	            generateIdentityResponse(&initialNasMsg,*(pdu_buffer+3), uicc);
               break;
@@ -959,7 +979,36 @@ void *nas_nrue_task(void *args_p)
           case FGS_DOWNLINK_NAS_TRANSPORT:
             decodeDownlinkNASTransport(&initialNasMsg, pdu_buffer);
             break;
-
+	case FGS_PDU_SESSION_ESTABLISHMENT_ACC:
+	  {
+	    uint8_t offset = 0;
+	    uint8_t *payload_container = pdu_buffer;
+	    offset += SECURITY_PROTECTED_5GS_NAS_MESSAGE_HEADER_LENGTH;
+	    uint16_t payload_container_length = htons(((dl_nas_transport_t *)(pdu_buffer + offset))->payload_container_length);
+	    if ((payload_container_length >= PAYLOAD_CONTAINER_LENGTH_MIN) &&
+		(payload_container_length <= PAYLOAD_CONTAINER_LENGTH_MAX))
+	      offset += (PLAIN_5GS_NAS_MESSAGE_HEADER_LENGTH + 3);
+	    if (offset < NAS_CONN_ESTABLI_CNF(msg_p).nasMsg.length) 
+	      payload_container = pdu_buffer + offset;
+	    
+	    while(offset < payload_container_length) {
+	      if (*(payload_container + offset) == 0x29) { // PDU address IEI
+		if ((*(payload_container+offset+1) == 0x05) && (*(payload_container +offset+2) == 0x01)) { // IPV4
+		  nas_getparams();
+		  sprintf(baseNetAddress, "%d.%d", *(payload_container+offset+3), *(payload_container+offset+4));
+		  int third_octet = *(payload_container+offset+5);
+		  int fourth_octet = *(payload_container+offset+6);
+		  LOG_I(NAS, "Received PDU Session Establishment Accept, UE IP: %d.%d.%d.%d\n",
+			*(payload_container+offset+3), *(payload_container+offset+4),
+			*(payload_container+offset+5), *(payload_container+offset+6));
+		  nas_config(1,third_octet,fourth_octet,"oaitun_ue");
+		  break;
+		}
+	      }
+	      offset++;
+	    }
+	  }
+	  break;
           default:
               LOG_W(NR_RRC,"unknow message type %d\n",msg_type);
               break;
@@ -970,13 +1019,13 @@ void *nas_nrue_task(void *args_p)
           message_p = itti_alloc_new_message(TASK_NAS_NRUE, 0, NAS_UPLINK_DATA_REQ);
           NAS_UPLINK_DATA_REQ(message_p).UEid          = Mod_id;
           NAS_UPLINK_DATA_REQ(message_p).nasMsg.data   = (uint8_t *)initialNasMsg.data;
+
           NAS_UPLINK_DATA_REQ(message_p).nasMsg.length = initialNasMsg.length;
           itti_send_msg_to_task(TASK_RRC_NRUE, instance, message_p);
           LOG_I(NAS, "Send NAS_UPLINK_DATA_REQ message\n");
         }
-
-        break;
       }
+        break;
 
       default:
         LOG_E(NAS, "[UE %d] Received unexpected message %s\n", Mod_id,  ITTI_MSG_NAME (msg_p));
diff --git a/openair3/NAS/NR_UE/nr_nas_msg_sim.h b/openair3/NAS/NR_UE/nr_nas_msg_sim.h
index 1b593660376a966ba9fed53cbb87135b4c8e504c..9655f87130f472f13a18ce1ce182bf9a6eef3b3b 100644
--- a/openair3/NAS/NR_UE/nr_nas_msg_sim.h
+++ b/openair3/NAS/NR_UE/nr_nas_msg_sim.h
@@ -64,6 +64,11 @@
 
 #define INITIAL_REGISTRATION                               0b001
 
+#define PLAIN_5GS_NAS_MESSAGE_HEADER_LENGTH                3
+#define SECURITY_PROTECTED_5GS_NAS_MESSAGE_HEADER_LENGTH   7
+#define PAYLOAD_CONTAINER_LENGTH_MIN                       3
+#define PAYLOAD_CONTAINER_LENGTH_MAX                       65537
+
 /* Security Key for SA UE */
 typedef struct {
   uint8_t kausf[32];
@@ -75,6 +80,7 @@ typedef struct {
   uint8_t kgnb[32];
 } ue_sa_security_key_t;
 
+
 typedef enum fgs_protocol_discriminator_e {
   /* Protocol discriminator identifier for 5GS Mobility Management */
   FGS_MOBILITY_MANAGEMENT_MESSAGE =   0x7E,
@@ -126,6 +132,33 @@ typedef union {
   fgs_nas_message_plain_t plain;
 } fgs_nas_message_t;
 
+typedef struct {
+  union {
+    mm_msg_header_t plain_nas_msg_header;
+    struct security_protected_nas_msg_header_s {
+      uint8_t  ex_protocol_discriminator;
+      uint8_t  security_header_type;
+      uint16_t message_authentication_code1;
+      uint16_t message_authentication_code2;
+      uint8_t  sequence_number;
+    } security_protected_nas_msg_header_t;
+  } choice;
+} nas_msg_header_t;
+
+typedef struct {
+  uint8_t ex_protocol_discriminator;
+  uint8_t pdu_session_id;
+  uint8_t PTI;
+  uint8_t message_type;
+} fgs_sm_nas_msg_header_t;
+
+typedef struct {
+    mm_msg_header_t         plain_nas_msg_header;
+    uint8_t                 payload_container_type;
+    uint16_t                payload_container_length;
+    fgs_sm_nas_msg_header_t sm_nas_msg_header;
+} dl_nas_transport_t;
+
 void generateRegistrationRequest(as_nas_info_t *initialNasMsg, int Mod_id);
 void *nas_nrue_task(void *args_p);
 
diff --git a/openair3/NAS/TOOLS/display.c b/openair3/NAS/TOOLS/display.c
index 363fae76b8eed58ee56e959058a03a3df705403a..0828eeb67383582d7cb97a5072437dab03a6d93f 100644
--- a/openair3/NAS/TOOLS/display.c
+++ b/openair3/NAS/TOOLS/display.c
@@ -262,10 +262,10 @@ void display_usim_data(const char *filename) {
 	kasme[USIM_K_ASME_SIZE] = '\0';
 	memcpy(kasme, data.securityctx.Kasme.value, USIM_K_ASME_SIZE);
 	printf("\tKasme\t: \"%s\"\n", kasme);
-	printf("\tulNAScount\t: 0x%.8x\n",
+	/*printf("\tulNAScount\t: 0x%.8x\n",
 			*(uint32_t*) data.securityctx.ulNAScount.value);
 	printf("\tdlNAScount\t: 0x%.8x\n",
-			*(uint32_t*) data.securityctx.dlNAScount.value);
+			*(uint32_t*) data.securityctx.dlNAScount.value);*/
 	printf("\talgorithmID\t: 0x%.2x\n\n",
 			data.securityctx.algorithmID.value[0]);
 
diff --git a/openair3/NAS/UE/API/USIM/usim_api.c b/openair3/NAS/UE/API/USIM/usim_api.c
index b882689f9b072e34f53438ec97af067fc09206cb..7facdaba792d612b338e4b3ca654f18942042cc4 100644
--- a/openair3/NAS/UE/API/USIM/usim_api.c
+++ b/openair3/NAS/UE/API/USIM/usim_api.c
@@ -249,7 +249,9 @@ int usim_api_authenticate_test(usim_data_t *usim_data,
     LOG_TRACE(INFO,
               "USIM-API  - Comparing the XMAC with the MAC included in AUTN Succeeded");
     /* Verify that the received sequence number SQN is in the correct range */
-    rc = _usim_api_check_sqn(*(uint32_t*)(sqn), sqn[USIM_API_SQN_SIZE - 1]);
+    uint32_t v;
+    memcpy(&v, sqn, sizeof(v));
+    rc = _usim_api_check_sqn(v, sqn[USIM_API_SQN_SIZE - 1]);
   }
 
 
@@ -392,7 +394,9 @@ int usim_api_authenticate(usim_data_t *usim_data, const OctetString* rand_pP, co
     LOG_TRACE(INFO,
               "USIM-API  - Comparing the XMAC with the MAC included in AUTN Succeeded");
     /* Verify that the received sequence number SQN is in the correct range */
-    rc = _usim_api_check_sqn(*(uint32_t*)(sqn), sqn[USIM_API_SQN_SIZE - 1]);
+    uint32_t v;
+    memcpy(&v, sqn, sizeof(v));
+    rc = _usim_api_check_sqn(v, sqn[USIM_API_SQN_SIZE - 1]);
   }
 
 
diff --git a/openair3/NAS/UE/ESM/PdnConnectivity.c b/openair3/NAS/UE/ESM/PdnConnectivity.c
index 3b5bad7529d386bca0eb92b4afca5bbe8de16d8a..d17b5fde3c72341a94af41151acffbd4f2960c5e 100644
--- a/openair3/NAS/UE/ESM/PdnConnectivity.c
+++ b/openair3/NAS/UE/ESM/PdnConnectivity.c
@@ -356,7 +356,7 @@ int esm_proc_pdn_connectivity_accept(nas_user_t *user, int pti, esm_proc_pdn_typ
     int     pid = RETURNerror;
     char    apn_first_char[4];
 
-    LOG_VAR(char,    str[128]);
+    char str[128] __attribute__((unused));
 
     if (isprint(apn->value[0])) {
         apn_first_char[0] = '\0';
diff --git a/openair3/NAS/UE/ESM/esm_ebr_context.c b/openair3/NAS/UE/ESM/esm_ebr_context.c
index 0c79fa3e3af330a22e1d294ffc6cd96f7e276327..b801ca2ad54e788a884f0e5cb2a6ee28a3a5f263 100644
--- a/openair3/NAS/UE/ESM/esm_ebr_context.c
+++ b/openair3/NAS/UE/ESM/esm_ebr_context.c
@@ -51,6 +51,7 @@ Description Defines functions used to handle EPS bearer contexts.
 #include "assertions.h"
 #include "pdcp.h"
 #include "nfapi/oai_integration/vendor_ext.h"
+#include "executables/softmodem-common.h"
 
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -262,8 +263,7 @@ int esm_ebr_context_create(
                 netmask = 32;
                 strcpy(broadcast, ipv4_addr);
               }
-
-              res = sprintf(command_line,
+              LOG_D(NAS, "setting commandline string: "
                             "ip address add %s/%d broadcast %s dev %s%d && "
                             "ip link set %s%d up && "
                             "ip rule add from %s/32 table %d && "
@@ -276,26 +276,67 @@ int esm_ebr_context_create(
                             ipv4_addr, ueid + 10000,
                             UE_NAS_USE_TUN ? "oaitun_ue" : "oip",
                             ueid + 1, ueid + 10000);
-
-              if ( res<0 ) {
-                LOG_TRACE(WARNING, "ESM-PROC  - Failed to system command string");
-              }
-
-              LOG_TRACE(INFO, "ESM-PROC  - executing %s ",
+              if (!get_softmodem_params()->nsa)
+              {
+                res = sprintf(command_line,
+                              "ip address add %s/%d broadcast %s dev %s%d && "
+                              "ip link set %s%d up && "
+                              "ip rule add from %s/32 table %d && "
+                              "ip rule add to %s/32 table %d && "
+                              "ip route add default dev %s%d table %d",
+                              ipv4_addr, netmask, broadcast,
+                              UE_NAS_USE_TUN ? "oaitun_ue" : "oip", ueid + 1,
+                              UE_NAS_USE_TUN ? "oaitun_ue" : "oip", ueid + 1,
+                              ipv4_addr, ueid + 10000,
+                              ipv4_addr, ueid + 10000,
+                              UE_NAS_USE_TUN ? "oaitun_ue" : "oip",
+                              ueid + 1, ueid + 10000);
+
+                if ( res<0 ) {
+                  LOG_TRACE(WARNING, "ESM-PROC  - Failed to system command string");
+                }
+
+                /* Calling system() here disrupts UE's realtime processing in some cases.
+                * This may be because of the call to fork(), which, for some
+                * unidentified reason, interacts badly with other (realtime) threads.
+                * background_system() is a replacement mechanism relying on a
+                * background process that does the system() and reports result to
+                * the parent process (lte-softmodem, oaisim, ...). The background
+                * process is created very early in the life of the parent process.
+                * The processes interact through standard pipes. See
+                * common/utils/system.c for details.
+                */
+
+                LOG_TRACE(INFO, "ESM-PROC  - executing %s ",
                         command_line);
-
-              /* Calling system() here disrupts UE's realtime processing in some cases.
-               * This may be because of the call to fork(), which, for some
-               * unidentified reason, interacts badly with other (realtime) threads.
-               * background_system() is a replacement mechanism relying on a
-               * background process that does the system() and reports result to
-               * the parent process (lte-softmodem, oaisim, ...). The background
-               * process is created very early in the life of the parent process.
-               * The processes interact through standard pipes. See
-               * common/utils/system.c for details.
-               */
-              if (background_system(command_line) != 0)
-                LOG_TRACE(ERROR, "ESM-PROC - failed command '%s'", command_line);
+                if (background_system(command_line) != 0)
+                {
+                  LOG_TRACE(ERROR, "ESM-PROC - failed command '%s'", command_line);
+                }
+              }
+              else if (get_softmodem_params()->nsa) {
+                res = sprintf(command_line,
+                              "ip address add %s/%d broadcast %s dev %s%d && "
+                              "ip link set %s%d up && "
+                              "ip rule add from %s/32 table %d && "
+                              "ip rule add to %s/32 table %d && "
+                              "ip route add default dev %s%d table %d",
+                              ipv4_addr, netmask, broadcast,
+                              UE_NAS_USE_TUN ? "oaitun_nru" : "oip", ueid + 1,
+                              UE_NAS_USE_TUN ? "oaitun_nru" : "oip", ueid + 1,
+                              ipv4_addr, ueid + 10000,
+                              ipv4_addr, ueid + 10000,
+                              UE_NAS_USE_TUN ? "oaitun_nru" : "oip",
+                              ueid + 1, ueid + 10000);
+
+                if ( res<0 ) {
+                  LOG_TRACE(WARNING, "ESM-PROC  - Failed to system command string");
+                }
+                LOG_D(NAS, "Sending NAS_OAI_TUN_NSA msg to LTE UE via itti\n");
+                MessageDef *msg_p = itti_alloc_new_message(TASK_NAS_UE, 0, NAS_OAI_TUN_NSA);
+                memcpy(NAS_OAI_TUN_NSA(msg_p).buffer, command_line, sizeof(NAS_OAI_TUN_NSA(msg_p).buffer));
+                itti_send_msg_to_task(TASK_RRC_UE, 0, msg_p);
+              }
 
               break;
 
diff --git a/openair3/NAS/UE/nas_ue_task.c b/openair3/NAS/UE/nas_ue_task.c
index be887623bb56e49abaa0b17114c6032e67a1f260..88938c3c376e0aea7614192395e77c794114eebe 100644
--- a/openair3/NAS/UE/nas_ue_task.c
+++ b/openair3/NAS/UE/nas_ue_task.c
@@ -24,7 +24,7 @@
 # include "intertask_interface.h"
 # include "nas_ue_task.h"
 # include "common/utils/LOG/log.h"
-
+# include "vendor_ext.h"
 # include "user_defs.h"
 # include "user_api.h"
 # include "nas_parser.h"
@@ -42,6 +42,8 @@
 extern unsigned char NB_eNB_INST;
 extern uint16_t NB_UE_INST;
 
+uint16_t ue_idx_standalone = 0xFFFF;
+
 char *make_port_str_from_ueid(const char *base_port_str, int ueid);
 
 static int nas_ue_process_events(nas_user_container_t *users, struct epoll_event *events, int nb_events)
@@ -96,41 +98,89 @@ void *nas_ue_task(void *args_p)
 
   itti_mark_task_ready (TASK_NAS_UE);
   MSC_START_USE();
+  LOG_I(NAS, "ue_idx_standalone val:: %u\n", ue_idx_standalone);
   /* Initialize UE NAS (EURECOM-NAS) */
-  for (int i=0; i < users->count; i++)
+  // Intead of for loop for standalone mode
+  if (ue_idx_standalone == 0xFFFF)
   {
-    nas_user_t *user = &users->item[i];
-    user->ueid=i;
+    for (int i = 0; i < users->count; i++)
+    {
+      nas_user_t *user = &users->item[i];
+      user->ueid = i;
+
+      /* Get USIM data application filename */
+      user->usim_data_store = memory_get_path_from_ueid(USIM_API_NVRAM_DIRNAME, USIM_API_NVRAM_FILENAME, user->ueid);
+      if (user->usim_data_store == NULL)
+      {
+        LOG_E(NAS, "[UE %d] - Failed to get USIM data application filename", user->ueid);
+        exit(EXIT_FAILURE);
+      }
 
-    /* Get USIM data application filename */
-    user->usim_data_store = memory_get_path_from_ueid(USIM_API_NVRAM_DIRNAME, USIM_API_NVRAM_FILENAME, user->ueid);
-    if ( user->usim_data_store == NULL ) {
-      LOG_E(NAS, "[UE %d] - Failed to get USIM data application filename", user->ueid);
-      exit(EXIT_FAILURE);
-    }
+      /* Get UE's data pathname */
+      user->user_nvdata_store = memory_get_path_from_ueid(USER_NVRAM_DIRNAME, USER_NVRAM_FILENAME, user->ueid);
+      if (user->user_nvdata_store == NULL)
+      {
+        LOG_E(NAS, "[UE %d] - Failed to get USIM nvdata filename", user->ueid);
+        exit(EXIT_FAILURE);
+      }
 
-    /* Get UE's data pathname */
-    user->user_nvdata_store = memory_get_path_from_ueid(USER_NVRAM_DIRNAME, USER_NVRAM_FILENAME, user->ueid);
-    if ( user->user_nvdata_store == NULL ) {
-      LOG_E(NAS, "[UE %d] - Failed to get USIM nvdata filename", user->ueid);
-      exit(EXIT_FAILURE);
-    }
+      /* Get EMM data pathname */
+      user->emm_nvdata_store = memory_get_path_from_ueid(EMM_NVRAM_DIRNAME, EMM_NVRAM_FILENAME, user->ueid);
+      if (user->emm_nvdata_store == NULL)
+      {
+        LOG_E(NAS, "[UE %d] - Failed to get EMM nvdata filename", user->ueid);
+        exit(EXIT_FAILURE);
+      }
 
-    /* Get EMM data pathname */
-    user->emm_nvdata_store = memory_get_path_from_ueid(EMM_NVRAM_DIRNAME, EMM_NVRAM_FILENAME, user->ueid);
-    if ( user->emm_nvdata_store == NULL ) {
-      LOG_E(NAS, "[UE %d] - Failed to get EMM nvdata filename", user->ueid);
-      exit(EXIT_FAILURE);
+      /* Initialize user interface (to exchange AT commands with user process) */
+      nas_user_api_id_initialize(user);
+      /* allocate needed structures */
+      user->user_at_commands = calloc_or_fail(sizeof(user_at_commands_t));
+      user->at_response = calloc_or_fail(sizeof(at_response_t));
+      user->lowerlayer_data = calloc_or_fail(sizeof(lowerlayer_data_t));
+      /* Initialize NAS user */
+      nas_user_initialize(user, &user_api_emm_callback, &user_api_esm_callback, FIRMWARE_VERSION);
     }
-
-    /* Initialize user interface (to exchange AT commands with user process) */
-    nas_user_api_id_initialize(user);
-    /* allocate needed structures */
-    user->user_at_commands = calloc_or_fail(sizeof(user_at_commands_t));
-    user->at_response = calloc_or_fail(sizeof(at_response_t));
-    user->lowerlayer_data = calloc_or_fail(sizeof(lowerlayer_data_t));
-    /* Initialize NAS user */
-    nas_user_initialize (user, &user_api_emm_callback, &user_api_esm_callback, FIRMWARE_VERSION);
+  }
+  else
+  {
+    // use new parameter passed into lte-uesoftmodem which instead of looping
+    // calls functions on specific UE index.
+
+      nas_user_t *user = &users->item[0];
+      user->ueid = ue_idx_standalone;
+      LOG_I(NAS, "[UE %d] Configuring\n", user->ueid);
+
+      /* Get USIM data application filename */ //
+      user->usim_data_store = memory_get_path_from_ueid(USIM_API_NVRAM_DIRNAME, USIM_API_NVRAM_FILENAME, user->ueid);
+      if (user->usim_data_store == NULL)
+      {
+        LOG_E(NAS, "[UE %d] - Failed to get USIM data application filename", user->ueid);
+        exit(EXIT_FAILURE);
+      }
+      /* Get UE's data pathname */
+      user->user_nvdata_store = memory_get_path_from_ueid(USER_NVRAM_DIRNAME, USER_NVRAM_FILENAME, user->ueid);
+      if (user->user_nvdata_store == NULL)
+      {
+        LOG_E(NAS, "[UE %d] - Failed to get USIM nvdata filename", user->ueid);
+        exit(EXIT_FAILURE);
+      }
+      /* Get EMM data pathname */
+      user->emm_nvdata_store = memory_get_path_from_ueid(EMM_NVRAM_DIRNAME, EMM_NVRAM_FILENAME, user->ueid);
+      if (user->emm_nvdata_store == NULL)
+      {
+        LOG_E(NAS, "[UE %d] - Failed to get EMM nvdata filename", user->ueid);
+        exit(EXIT_FAILURE);
+      }
+      /* Initialize user interface (to exchange AT commands with user process) */
+      nas_user_api_id_initialize(user);
+      /* allocate needed structures */
+      user->user_at_commands = calloc_or_fail(sizeof(user_at_commands_t));
+      user->at_response = calloc_or_fail(sizeof(at_response_t));
+      user->lowerlayer_data = calloc_or_fail(sizeof(lowerlayer_data_t));
+      /* Initialize NAS user */
+      nas_user_initialize(user, &user_api_emm_callback, &user_api_esm_callback, FIRMWARE_VERSION);
+      user->ueid = 0;
   }
 
   /* Set UE activation state */
diff --git a/openair3/S1AP/s1ap_common.h b/openair3/S1AP/s1ap_common.h
index efac0201a31feaa1aa5dd5380e6ab5dcb7f2dd56..3c07f92a7f5b1dd6e91ad3a833772709caf300c4 100644
--- a/openair3/S1AP/s1ap_common.h
+++ b/openair3/S1AP/s1ap_common.h
@@ -82,7 +82,6 @@ extern int asn1_xer_print;
 # define S1AP_INFO(x, args...) LOG_I(S1AP, x, ##args)
 # define S1AP_DEBUG(x, args...) LOG_I(S1AP, x, ##args)
 #else
-# include "mme_default_values.h"
 # define S1AP_ERROR(x, args...) do { fprintf(stdout, "[S1AP][E]"x, ##args); } while(0)
 # define S1AP_WARN(x, args...)  do { fprintf(stdout, "[S1AP][W]"x, ##args); } while(0)
 # define S1AP_TRAF(x, args...)  do { fprintf(stdout, "[S1AP][T]"x, ##args); } while(0)
diff --git a/openair3/SCTP/sctp_eNB_task.c b/openair3/SCTP/sctp_eNB_task.c
index a14d4b9780c487b8f1cf01d3b510de2bc486041a..8d0166f80534436b6017cb415a284d7fd7b86848 100644
--- a/openair3/SCTP/sctp_eNB_task.c
+++ b/openair3/SCTP/sctp_eNB_task.c
@@ -451,9 +451,9 @@ sctp_handle_new_association_req(
 
             if (s > 0 ) {
                 if (((struct sockaddr_in*)ifa->ifa_addr)->sin_addr.s_addr == in.s_addr) {
-                    struct sockaddr_in locaddr;
+                    struct sockaddr_in locaddr={0};
                     locaddr.sin_family = AF_INET;
-                    locaddr.sin_port = htons(sctp_new_association_req_p->port);
+                    locaddr.sin_port = 0;
                     locaddr.sin_addr.s_addr = in.s_addr;
 
                     if (sctp_bindx(sd, (struct sockaddr*)&locaddr, 1, SCTP_BINDX_ADD_ADDR) < 0) {
@@ -693,7 +693,7 @@ static int sctp_create_new_listener(
     sctp_init_t     *init_p,
     int server_type)
 {
-    struct sctp_event_subscribe   event;
+    struct sctp_event_subscribe   event={0};
     struct sockaddr              *addr      = NULL;
     struct sctp_cnx_list_elm_s   *sctp_cnx  = NULL;
     uint16_t                      i  = 0, j = 0;
@@ -925,21 +925,14 @@ void
 sctp_eNB_read_from_socket(
     struct sctp_cnx_list_elm_s *sctp_cnx)
 {
-    int                    flags = 0, n;
-    socklen_t              from_len;
-    struct sctp_sndrcvinfo sinfo;
-
-    struct sockaddr_in addr;
-    uint8_t buffer[SCTP_RECV_BUFFER_SIZE];
-
     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));
+    int    flags = 0;
+    struct sctp_sndrcvinfo sinfo={0};
+    uint8_t buffer[SCTP_RECV_BUFFER_SIZE];
 
-    n = sctp_recvmsg(sctp_cnx->sd, (void *)buffer, SCTP_RECV_BUFFER_SIZE,
-                     (struct sockaddr *)&addr, &from_len,
+    int n = sctp_recvmsg(sctp_cnx->sd, (void *)buffer, SCTP_RECV_BUFFER_SIZE,
+                    NULL, NULL, 
                      &sinfo, &flags);
 
     if (n < 0) {
@@ -1050,8 +1043,8 @@ sctp_eNB_read_from_socket(
                        sctp_cnx->ppid);
         }
 
-        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),
+        SCTP_DEBUG("[%d][%d] Msg of length %d received, on stream %d, PPID %d\n",
+                   sinfo.sinfo_assoc_id, sctp_cnx->sd, n, 
                    sinfo.sinfo_stream, ntohl(sinfo.sinfo_ppid));
 
         sctp_itti_send_new_message_ind(sctp_cnx->task_id,
diff --git a/openair3/UDP/udp_eNB_task.c b/openair3/UDP/udp_eNB_task.c
index 05729ba6b1e8666e4162e9f06a2aefeab5b36832..8b9fc77bb14ebcff3ce765504113a385a2d408bf 100644
--- a/openair3/UDP/udp_eNB_task.c
+++ b/openair3/UDP/udp_eNB_task.c
@@ -235,7 +235,7 @@ udp_eNB_send_to(
 
 void udp_eNB_receiver(struct udp_socket_desc_s *udp_sock_pP)
 {
-  uint8_t                   l_buffer[2048];
+  uint8_t                   l_buffer[NFAPI_MAX_PACKED_MESSAGE_SIZE];
   int                n;
   socklen_t          from_len;
   struct sockaddr_in addr;
@@ -246,10 +246,13 @@ void udp_eNB_receiver(struct udp_socket_desc_s *udp_sock_pP)
   if (1) {
     from_len = (socklen_t)sizeof(struct sockaddr_in);
 
-    if ((n = recvfrom(udp_sock_pP->sd, l_buffer, sizeof(l_buffer), 0,
+    if ((n = recvfrom(udp_sock_pP->sd, l_buffer, sizeof(l_buffer), MSG_TRUNC,
                       (struct sockaddr *)&addr, &from_len)) < 0) {
       LOG_E(UDP_, "Recvfrom failed %s\n", strerror(errno));
       return;
+    } else if (n > sizeof(l_buffer)) {
+      LOG_E(UDP_, "%s(%d). Message truncated. %d\n", __FUNCTION__, __LINE__, n);
+      return;
     } else if (n == 0) {
       LOG_W(UDP_, "Recvfrom returned 0\n");
       return;
diff --git a/openair3/UTILS/conversions.h b/openair3/UTILS/conversions.h
index cfb2c8cdfc5c4ec56934d9abee19142053eed40e..00b650a3025af8748abde760f2daf14d58820459 100644
--- a/openair3/UTILS/conversions.h
+++ b/openair3/UTILS/conversions.h
@@ -400,10 +400,10 @@ do {                                                    \
 #define TRANSPORT_LAYER_ADDRESS_IPv4_TO_BIT_STRING(mACRO, bITsTRING)    \
 do {                                                    \
     (bITsTRING)->buf = calloc(4, sizeof(uint8_t));      \
-    (bITsTRING)->buf[0] = (mACRO) >> 24 & 0xFF;         \
-    (bITsTRING)->buf[1] = (mACRO) >> 16 & 0xFF;         \
-    (bITsTRING)->buf[2] = (mACRO) >> 8 & 0xFF;          \
-    (bITsTRING)->buf[3] = (mACRO) >> 4 & 0xFF;          \
+    (bITsTRING)->buf[3] = (mACRO) >> 24 & 0xFF;         \
+    (bITsTRING)->buf[2] = (mACRO) >> 16 & 0xFF;         \
+    (bITsTRING)->buf[1] = (mACRO) >> 8 & 0xFF;          \
+    (bITsTRING)->buf[0] = (mACRO) &  0xFF;              \
     (bITsTRING)->size = 4;                              \
     (bITsTRING)->bits_unused = 0;                       \
 } while(0)
@@ -412,10 +412,10 @@ do {                                                    \
 do {                                                                    \
     DevCheck((bITsTRING)->size == 4, (bITsTRING)->size, 4, 0);          \
     DevCheck((bITsTRING)->bits_unused == 0, (bITsTRING)->bits_unused, 0, 0); \
-    mACRO = ((bITsTRING)->buf[0] << 24) +                               \
-            ((bITsTRING)->buf[1] << 16) +                               \
-            ((bITsTRING)->buf[2] << 8) +                                \
-            ((bITsTRING)->buf[3]);                                      \
+    mACRO = ((bITsTRING)->buf[3] << 24) +                               \
+            ((bITsTRING)->buf[2] << 16) +                               \
+            ((bITsTRING)->buf[1] << 8) +                                \
+            ((bITsTRING)->buf[0]);                                      \
 } while (0)
 
 
diff --git a/openair3/ocp-gtpu/gtp_itf.cpp b/openair3/ocp-gtpu/gtp_itf.cpp
index a3eeb26540ce29fb7f42863867e5490000940978..64146bc7cac61caaf12b19a46629288f12ba16e2 100644
--- a/openair3/ocp-gtpu/gtp_itf.cpp
+++ b/openair3/ocp-gtpu/gtp_itf.cpp
@@ -93,7 +93,7 @@ class gtpEndPoints {
 gtpEndPoints globGtp;
 
 // note TEid 0 is reserved for specific usage: echo req/resp, error and supported extensions
-static  uint32_t gtpv1uNewTeid(void) {
+static  teid_t gtpv1uNewTeid(void) {
 #ifdef GTPV1U_LINEAR_TEID_ALLOCATION
   g_gtpv1u_teid = g_gtpv1u_teid + 1;
   return g_gtpv1u_teid;
@@ -102,13 +102,13 @@ static  uint32_t gtpv1uNewTeid(void) {
 #endif
 }
 
-int legacyInstanceMapping=0;
+instance_t legacyInstanceMapping=0;
 #define compatInst(a) ((a)==0 || (a)==INSTANCE_DEFAULT?legacyInstanceMapping:a)
 
 #define GTPV1U_HEADER_SIZE                                  (8)
-
-
-static  int gtpv1uCreateAndSendMsg(int h, uint32_t peerIp, uint16_t peerPort, teid_t teid, uint8_t *Msg,int msgLen,
+  
+  
+  static int gtpv1uCreateAndSendMsg(int h, uint32_t peerIp, uint16_t peerPort, int msgType, teid_t teid, uint8_t *Msg,int msgLen,
                                    bool seqNumFlag, bool  npduNumFlag, bool extHdrFlag, int seqNum, int npduNum, int extHdrType) {
   AssertFatal(extHdrFlag==false,"Not developped");
   int headerAdditional=0;
@@ -116,9 +116,8 @@ static  int gtpv1uCreateAndSendMsg(int h, uint32_t peerIp, uint16_t peerPort, te
   if ( seqNumFlag || npduNumFlag || extHdrFlag)
     headerAdditional=4;
 
-  uint8_t *buffer;
   int fullSize=GTPV1U_HEADER_SIZE+headerAdditional+msgLen;
-  AssertFatal((buffer=(uint8_t *) malloc(fullSize)) != NULL, "");
+  uint8_t buffer[fullSize];
   Gtpv1uMsgHeaderT      *msgHdr = (Gtpv1uMsgHeaderT *)buffer ;
   // N should be 0 for us (it was used only in 2G and 3G)
   msgHdr->PN=npduNumFlag;
@@ -128,10 +127,12 @@ static  int gtpv1uCreateAndSendMsg(int h, uint32_t peerIp, uint16_t peerPort, te
   //PT=0 is for GTP' TS 32.295 (charging)
   msgHdr->PT=1;
   msgHdr->version=1;
-  msgHdr->msgType=GTP_GPDU;
+  msgHdr->msgType=msgType;
   msgHdr->msgLength=htons(msgLen);
+
   if ( seqNumFlag || extHdrFlag || npduNumFlag)
     msgHdr->msgLength+=4;
+
   msgHdr->teid=htonl(teid);
 
   if(seqNumFlag || extHdrFlag || npduNumFlag) {
@@ -147,16 +148,13 @@ static  int gtpv1uCreateAndSendMsg(int h, uint32_t peerIp, uint16_t peerPort, te
   to.sin_port        = htons(peerPort);
   to.sin_addr.s_addr = peerIp ;
   LOG_D(GTPU,"sending packet size: %d to %s\n",fullSize, inet_ntoa(to.sin_addr) );
-
-  if (sendto(h, (void *)buffer, (size_t)fullSize, 0,(struct sockaddr *)&to, sizeof(to) ) != fullSize ) {
-    LOG_E(GTPU,
-          "[SD %d] Failed to send data to " IPV4_ADDR " on port %d, buffer size %u\n",
-          h, IPV4_ADDR_FORMAT(peerIp), peerPort, fullSize);
-    free(buffer);
+  int ret;
+  if ((ret=sendto(h, (void *)buffer, (size_t)fullSize, 0,(struct sockaddr *)&to, sizeof(to) )) != fullSize ) {
+    LOG_E(GTPU, "[SD %d] Failed to send data to " IPV4_ADDR " on port %d, buffer size %u, ret: %d, errno: %d\n",
+          h, IPV4_ADDR_FORMAT(peerIp), peerPort, fullSize, ret, errno);
     return GTPNOK;
   }
 
-  free(buffer);
   return  !GTPNOK;
 }
 
@@ -170,33 +168,35 @@ static void gtpv1uSend(instance_t instance, gtpv1u_enb_tunnel_data_req_t *req, b
   auto ptrRnti=inst->ue2te_mapping.find(rnti);
 
   if (  ptrRnti==inst->ue2te_mapping.end() ) {
-    LOG_E(GTPU, "gtpv1uSend failed: while getting ue rnti %x in hashtable ue_mapping\n", rnti);
+    LOG_E(GTPU, "[%ld] gtpv1uSend failed: while getting ue rnti %x in hashtable ue_mapping\n", instance, rnti);
     pthread_mutex_unlock(&globGtp.gtp_lock);
     return;
   }
 
-  auto ptr=ptrRnti->second.bearers;
+  map<int, ocp_gtpv1u_bearer_t>::iterator ptr2=ptrRnti->second.bearers.find(rab_id);
 
-  if ( ptr.find(rab_id) == ptr.end() ) {
-    LOG_E(GTPU,"sending a packet to a non existant RNTI:RAB: %x/%x\n", rnti, rab_id);
+  if ( ptr2 == ptrRnti->second.bearers.end() ) {
+    LOG_E(GTPU,"[%ld] GTP-U instance: sending a packet to a non existant RNTI:RAB: %x/%x\n", instance, rnti, rab_id);
     pthread_mutex_unlock(&globGtp.gtp_lock);
     return;
-  } else
-    LOG_D(GTPU,"sending a packet to RNTI:RAB:teid %x/%x/%x, len %lu, oldseq %d, oldnum %d\n",
-          rnti, rab_id,ptr[rab_id].teid_outgoing,length,  ptr[rab_id].seqNum,ptr[rab_id].npduNum );
+  }
+
+  LOG_D(GTPU,"[%ld] sending a packet to RNTI:RAB:teid %x/%x/%x, len %lu, oldseq %d, oldnum %d\n",
+        instance, rnti, rab_id,ptr2->second.teid_outgoing,length, ptr2->second.seqNum,ptr2->second.npduNum );
 
   if(seqNumFlag)
-    ptr[rab_id].seqNum++;
+    ptr2->second.seqNum++;
 
   if(npduNumFlag)
-    ptr[rab_id].npduNum++;
+    ptr2->second.npduNum++;
 
-  // We will release the lock, let's copy data before
-  ocp_gtpv1u_bearer_t tmp=ptr[rab_id];
+  // copy to release the mutex
+  ocp_gtpv1u_bearer_t tmp=ptr2->second;
   pthread_mutex_unlock(&globGtp.gtp_lock);
   gtpv1uCreateAndSendMsg(compatInst(instance),
                          tmp.outgoing_ip_addr,
                          tmp.outgoing_port,
+			 GTP_GPDU,
                          tmp.teid_outgoing,
                          buffer, length, seqNumFlag, npduNumFlag, false, tmp.seqNum, tmp.npduNum, 0) ;
 }
@@ -211,33 +211,35 @@ static void gtpv1uSend2(instance_t instance, gtpv1u_gnb_tunnel_data_req_t *req,
   auto ptrRnti=inst->ue2te_mapping.find(rnti);
 
   if (  ptrRnti==inst->ue2te_mapping.end() ) {
-    LOG_E(GTPU, "gtpv1uSend failed: while getting ue rnti %x in hashtable ue_mapping\n", rnti);
+    LOG_E(GTPU, "[%ld] GTP-U gtpv1uSend failed: while getting ue rnti %x in hashtable ue_mapping\n", instance, rnti);
     pthread_mutex_unlock(&globGtp.gtp_lock);
     return;
   }
 
-  auto ptr=ptrRnti->second.bearers;
+  map<int, ocp_gtpv1u_bearer_t>::iterator ptr2=ptrRnti->second.bearers.find(rab_id);
 
-  if ( ptr.find(rab_id) == ptr.end() ) {
-    LOG_E(GTPU,"sending a packet to a non existant RNTI:RAB: %x/%x\n", rnti, rab_id);
+  if ( ptr2 == ptrRnti->second.bearers.end() ) {
+    LOG_D(GTPU,"GTP-U instance: %ld sending a packet to a non existant RNTI:RAB: %x/%x\n", instance, rnti, rab_id);
     pthread_mutex_unlock(&globGtp.gtp_lock);
     return;
-  } else
-    LOG_D(GTPU,"sending a packet to RNTI:RAB:teid %x/%x/%x, len %lu, oldseq %d, oldnum %d\n",
-          rnti, rab_id,ptr[rab_id].teid_outgoing,length,  ptr[rab_id].seqNum,ptr[rab_id].npduNum );
+  }
+
+  LOG_D(GTPU,"[%ld] GTP-U sending a packet to RNTI:RAB:teid %x/%x/%x, len %lu, oldseq %d, oldnum %d\n",
+        instance, rnti, rab_id,ptr2->second.teid_outgoing,length, ptr2->second.seqNum,ptr2->second.npduNum );
 
   if(seqNumFlag)
-    ptr[rab_id].seqNum++;
+    ptr2->second.seqNum++;
 
   if(npduNumFlag)
-    ptr[rab_id].npduNum++;
+    ptr2->second.npduNum++;
 
-  // We will release the lock, let's copy data before
-  ocp_gtpv1u_bearer_t tmp=ptr[rab_id];
+  // copy to release the mutex
+  ocp_gtpv1u_bearer_t tmp=ptr2->second;
   pthread_mutex_unlock(&globGtp.gtp_lock);
   gtpv1uCreateAndSendMsg(compatInst(instance),
                          tmp.outgoing_ip_addr,
                          tmp.outgoing_port,
+			 GTP_GPDU,
                          tmp.teid_outgoing,
                          buffer, length, seqNumFlag, npduNumFlag, false, tmp.seqNum, tmp.npduNum, 0) ;
 }
@@ -250,22 +252,22 @@ static void gtpv1uEndTunnel(instance_t instance, gtpv1u_enb_tunnel_data_req_t *r
   auto ptrRnti=inst->ue2te_mapping.find(rnti);
 
   if (  ptrRnti==inst->ue2te_mapping.end() ) {
-    LOG_E(GTPU, "gtpv1uSend failed: while getting ue rnti %x in hashtable ue_mapping\n", rnti);
+    LOG_E(GTPU, "[%ld] gtpv1uSend failed: while getting ue rnti %x in hashtable ue_mapping\n", instance, rnti);
     pthread_mutex_unlock(&globGtp.gtp_lock);
     return;
   }
 
-  auto ptr=ptrRnti->second.bearers;
+  map<int, ocp_gtpv1u_bearer_t>::iterator ptr2=ptrRnti->second.bearers.find(rab_id);
 
-  if ( ptr.find(rab_id) == ptr.end() ) {
-    LOG_E(GTPU,"sending a packet to a non existant RNTI:RAB: %x/%x\n", rnti, rab_id);
+  if ( ptr2 == ptrRnti->second.bearers.end() ) {
+    LOG_E(GTPU,"[%ld] GTP-U sending a packet to a non existant RNTI:RAB: %x/%x\n", instance, rnti, rab_id);
     pthread_mutex_unlock(&globGtp.gtp_lock);
     return;
-  } else
-    LOG_D(GTPU,"sending a end packet packet to RNTI:RAB:teid %x/%x/%x\n",
-          rnti, rab_id,ptr[rab_id].teid_outgoing);
+  }
 
-  ocp_gtpv1u_bearer_t tmp=ptr[rab_id];
+  LOG_D(GTPU,"[%ld] sending a end packet packet to RNTI:RAB:teid %x/%x/%x\n",
+        instance, rnti, rab_id,ptr2->second.teid_outgoing);
+  ocp_gtpv1u_bearer_t tmp=ptr2->second;
   pthread_mutex_unlock(&globGtp.gtp_lock);
   Gtpv1uMsgHeaderT  msgHdr;
   // N should be 0 for us (it was used only in 2G and 3G)
@@ -284,14 +286,13 @@ static void gtpv1uEndTunnel(instance_t instance, gtpv1u_enb_tunnel_data_req_t *r
   to.sin_family      = AF_INET;
   to.sin_port        = htons(tmp.outgoing_port);
   to.sin_addr.s_addr = tmp.outgoing_ip_addr;
-
   char ip4[INET_ADDRSTRLEN];
   //char ip6[INET6_ADDRSTRLEN];
-  LOG_D(GTPU,"sending end packet to %s\n", inet_ntoa(to.sin_addr) );
+  LOG_D(GTPU,"[%ld] sending end packet to %s\n", instance, inet_ntoa(to.sin_addr) );
 
   if (sendto(compatInst(instance), (void *)&msgHdr, sizeof(msgHdr), 0,(struct sockaddr *)&to, sizeof(to) ) !=  sizeof(msgHdr)) {
     LOG_E(GTPU,
-          "[SD %ld] Failed to send data to %s on port %d, buffer size %lu\n",
+          "[%ld] Failed to send data to %s on port %d, buffer size %lu\n",
           compatInst(instance), inet_ntop(AF_INET, &tmp.outgoing_ip_addr, ip4, INET_ADDRSTRLEN), tmp.outgoing_port, sizeof(msgHdr));
   }
 }
@@ -378,7 +379,7 @@ static  int udpServerSocket(openAddr_s addr) {
 
   int sendbuff = 1000*1000*10;
   AssertFatal(0==setsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, &sendbuff, sizeof(sendbuff)),"");
-  LOG_D(GTPU,"Created listener for paquets to: %s:%s, send buffer size: %d\n", addr.originHost, addr.originService,sendbuff);
+  LOG_D(GTPU,"[%d] Created listener for paquets to: %s:%s, send buffer size: %d\n", sockfd, addr.originHost, addr.originService,sendbuff);
   return sockfd;
 }
 
@@ -392,24 +393,51 @@ instance_t ocp_gtpv1Init(openAddr_t context) {
     LOG_E(GTPU,"can't create GTP-U instance\n");
 
   pthread_mutex_unlock(&globGtp.gtp_lock);
+  LOG_I(GTPU, "Created gtpu instance id: %d\n", id);
   return id;
 }
 
+void GtpuUpdateTunnelOutgoingTeid(instance_t instance, rnti_t rnti, ebi_t bearer_id, teid_t newOutgoingTeid) {
+  pthread_mutex_lock(&globGtp.gtp_lock);
+  auto inst=&globGtp.instances[compatInst(instance)];
+  auto ptrRnti=inst->ue2te_mapping.find(rnti);
+
+  if ( ptrRnti == inst->ue2te_mapping.end() ) {
+    LOG_E(GTPU,"[%ld] Update tunnel for a not existing rnti %x\n", instance, rnti);
+    pthread_mutex_unlock(&globGtp.gtp_lock);
+    return;
+  }
+
+  map<int, ocp_gtpv1u_bearer_t>::iterator ptr2=ptrRnti->second.bearers.find(bearer_id);
+
+  if ( ptr2 == ptrRnti->second.bearers.end() ) {
+    LOG_E(GTPU,"[%ld] Update tunnel for a existing rnti %x, but wrong bearer_id %u\n", instance, rnti, bearer_id);
+    pthread_mutex_unlock(&globGtp.gtp_lock);
+    return;
+  }
+
+  ptr2->second.teid_outgoing = newOutgoingTeid;
+  LOG_I(GTPU, "[%ld] Tunnel Outgoing TEID updated to %x \n", instance, ptr2->second.teid_outgoing);
+  pthread_mutex_unlock(&globGtp.gtp_lock);
+  return;
+}
+
 teid_t newGtpuCreateTunnel(instance_t instance, rnti_t rnti, int incoming_bearer_id, int outgoing_bearer_id, teid_t outgoing_teid,
                            transport_layer_addr_t remoteAddr, int port, gtpCallback callBack) {
   pthread_mutex_lock(&globGtp.gtp_lock);
+  instance=compatInst(instance);
   auto inst=&globGtp.instances[instance];
   auto it=inst->ue2te_mapping.find(rnti);
 
   if ( it != inst->ue2te_mapping.end() ) {
-    LOG_W(GTPU,"Create a config for a already existing GTP tunnel (rnti %x)\n", rnti);
+    LOG_W(GTPU,"[%ld] Create a config for a already existing GTP tunnel (rnti %x)\n", instance, rnti);
     inst->ue2te_mapping.erase(it);
   }
 
-  uint32_t incoming_teid=gtpv1uNewTeid();
+  teid_t incoming_teid=gtpv1uNewTeid();
 
   while ( inst->te2ue_mapping.find(incoming_teid) != inst->te2ue_mapping.end() ) {
-    LOG_W(GTPU, "generated a random Teid that exists, re-generating (%x)\n",incoming_teid);
+    LOG_W(GTPU, "[%ld] generated a random Teid that exists, re-generating (%x)\n", instance, incoming_teid);
     incoming_teid=gtpv1uNewTeid();
   };
 
@@ -419,7 +447,7 @@ teid_t newGtpuCreateTunnel(instance_t instance, rnti_t rnti, int incoming_bearer
 
   inst->te2ue_mapping[incoming_teid].callBack=callBack;
 
-  auto tmp=&inst->ue2te_mapping[rnti].bearers[outgoing_bearer_id];
+  ocp_gtpv1u_bearer_t *tmp=&inst->ue2te_mapping[rnti].bearers[outgoing_bearer_id];
 
   int addrs_length_in_bytes = remoteAddr.length / 8;
 
@@ -449,21 +477,21 @@ teid_t newGtpuCreateTunnel(instance_t instance, rnti_t rnti, int incoming_bearer
   pthread_mutex_unlock(&globGtp.gtp_lock);
   char ip4[INET_ADDRSTRLEN];
   char ip6[INET6_ADDRSTRLEN];
-
-  LOG_I(GTPU, "Created tunnel for RNTI %x, teid for DL: %d, teid for UL %d to remote IPv4: %s, IPv6 %s\n",
+  LOG_I(GTPU, "[%ld] Created tunnel for RNTI %x, teid for DL: %x, teid for UL %x to remote IPv4: %s, IPv6 %s\n",
+        instance,
         rnti,
         tmp->teid_incoming,
         tmp->teid_outgoing,
-        inet_ntop(AF_INET,(void*)&tmp->outgoing_ip_addr, ip4,INET_ADDRSTRLEN ),
-        inet_ntop(AF_INET6,(void*)&tmp->outgoing_ip6_addr.s6_addr, ip6, INET6_ADDRSTRLEN));
-
+        inet_ntop(AF_INET,(void *)&tmp->outgoing_ip_addr, ip4,INET_ADDRSTRLEN ),
+        inet_ntop(AF_INET6,(void *)&tmp->outgoing_ip6_addr.s6_addr, ip6, INET6_ADDRSTRLEN));
   return incoming_teid;
 }
 
 int ocp_gtpv1u_create_s1u_tunnel(instance_t instance,
                                  const gtpv1u_enb_create_tunnel_req_t  *create_tunnel_req,
                                  gtpv1u_enb_create_tunnel_resp_t *create_tunnel_resp) {
-  LOG_D(GTPU, "Start create tunnels for RNTI %x, num_tunnels %d, sgw_S1u_teid %x\n",
+  LOG_D(GTPU, "[%ld] Start create tunnels for RNTI %x, num_tunnels %d, sgw_S1u_teid %x\n",
+        instance,
         create_tunnel_req->rnti,
         create_tunnel_req->num_tunnels,
         create_tunnel_req->sgw_S1u_teid[0]);
@@ -498,7 +526,8 @@ int ocp_gtpv1u_update_s1u_tunnel(
   const gtpv1u_enb_create_tunnel_req_t *const  create_tunnel_req,
   const rnti_t                                  prior_rnti
 ) {
-  LOG_D(GTPU, "Start update tunnels for old RNTI %x, new RNTI %x, num_tunnels %d, sgw_S1u_teid %x, eps_bearer_id %x\n",
+  LOG_D(GTPU, "[%ld] Start update tunnels for old RNTI %x, new RNTI %x, num_tunnels %d, sgw_S1u_teid %x, eps_bearer_id %x\n",
+        instance,
         prior_rnti,
         create_tunnel_req->rnti,
         create_tunnel_req->num_tunnels,
@@ -508,13 +537,13 @@ int ocp_gtpv1u_update_s1u_tunnel(
   auto inst=&globGtp.instances[compatInst(instance)];
 
   if ( inst->ue2te_mapping.find(create_tunnel_req->rnti) == inst->ue2te_mapping.end() ) {
-    LOG_E(GTPU,"Update not already existing tunnel (new rnti %x, old rnti %x)\n", create_tunnel_req->rnti, prior_rnti);
+    LOG_E(GTPU,"[%ld] Update not already existing tunnel (new rnti %x, old rnti %x)\n", instance, create_tunnel_req->rnti, prior_rnti);
   }
 
   auto it=inst->ue2te_mapping.find(prior_rnti);
 
   if ( it != inst->ue2te_mapping.end() ) {
-    LOG_W(GTPU,"Update a not existing tunnel, start create the new one (new rnti %x, old rnti %x)\n", create_tunnel_req->rnti, prior_rnti);
+    LOG_W(GTPU,"[%ld] Update a not existing tunnel, start create the new one (new rnti %x, old rnti %x)\n", instance, create_tunnel_req->rnti, prior_rnti);
     pthread_mutex_unlock(&globGtp.gtp_lock);
     gtpv1u_enb_create_tunnel_resp_t tmp;
     (void)ocp_gtpv1u_create_s1u_tunnel(instance, create_tunnel_req, &tmp);
@@ -530,17 +559,18 @@ int ocp_gtpv1u_update_s1u_tunnel(
 int gtpv1u_create_ngu_tunnel(  const instance_t instance,
                                const gtpv1u_gnb_create_tunnel_req_t   *const create_tunnel_req,
                                gtpv1u_gnb_create_tunnel_resp_t *const create_tunnel_resp) {
-  LOG_D(GTPU, "Start create tunnels for RNTI %x, num_tunnels %d, sgw_S1u_teid %x\n",
+  LOG_D(GTPU, "[%ld] Start create tunnels for RNTI %x, num_tunnels %d, sgw_S1u_teid %x\n",
+        instance,
         create_tunnel_req->rnti,
         create_tunnel_req->num_tunnels,
-        create_tunnel_req->upf_NGu_teid[0]);
+        create_tunnel_req->outgoing_teid[0]);
   tcp_udp_port_t dstport=globGtp.instances[compatInst(instance)].get_dstport();
   for (int i = 0; i < create_tunnel_req->num_tunnels; i++) {
-    teid_t teid=newGtpuCreateTunnel(compatInst(instance), create_tunnel_req->rnti,
+    teid_t teid=newGtpuCreateTunnel(instance, create_tunnel_req->rnti,
                                     create_tunnel_req->incoming_rb_id[i],
                                     create_tunnel_req->pdusession_id[i],
-                                    create_tunnel_req->upf_NGu_teid[i],
-                                    create_tunnel_req->upf_addr[i], dstport,
+				    create_tunnel_req->outgoing_teid[i],
+                                    create_tunnel_req->dst_addr[i], dstport,
                                     sdap_gnb_data_req);
     create_tunnel_resp->status=0;
     create_tunnel_resp->rnti=create_tunnel_req->rnti;
@@ -571,14 +601,14 @@ int ocp_gtpv1u_create_x2u_tunnel(
 }
 
 int newGtpuDeleteTunnel(instance_t instance, rnti_t rnti) {
-  LOG_D(GTPU, "Start delete tunnels for RNTI %x\n",
-        rnti);
+  LOG_D(GTPU, "[%ld] Start delete tunnels for RNTI %x\n",
+        instance, rnti);
   pthread_mutex_lock(&globGtp.gtp_lock);
   auto inst=&globGtp.instances[compatInst(instance)];
   auto it=inst->ue2te_mapping.find(rnti);
 
   if ( it == inst->ue2te_mapping.end() ) {
-    LOG_W(GTPU,"Delete a non existing GTP tunnel\n");
+    LOG_W(GTPU,"[%ld] Delete GTP tunnels for rnti: %x, but no tunnel exits\n", instance, rnti);
     pthread_mutex_unlock(&globGtp.gtp_lock);
     return -1;
   }
@@ -594,7 +624,7 @@ int newGtpuDeleteTunnel(instance_t instance, rnti_t rnti) {
 
   inst->ue2te_mapping.erase(it);
   pthread_mutex_unlock(&globGtp.gtp_lock);
-  LOG_I(GTPU, "Deleted all tunnels for RNTI %d (%d tunnels deleted)\n", rnti, nb);
+  LOG_I(GTPU, "[%ld] Deleted all tunnels for RNTI %x (%d tunnels deleted)\n", instance, rnti, nb);
   return !GTPNOK;
 }
 
@@ -616,9 +646,26 @@ static int Gtpv1uHandleEchoReq(int h,
                                uint32_t msgBufLen,
                                uint16_t peerPort,
                                uint32_t peerIp) {
-  LOG_E(GTPU,"to be dev\n");
-  int rc = GTPNOK;
-  return rc;
+  Gtpv1uMsgHeaderT      *msgHdr = (Gtpv1uMsgHeaderT *) msgBuf;
+   
+  if ( msgHdr->version != 1 ||  msgHdr->PT != 1 ) {
+    LOG_E(GTPU, "[%d] Received a packet that is not GTP header\n", h);
+    return GTPNOK;
+  }
+
+  if ( msgHdr->S != 1 ) {
+    LOG_E(GTPU, "[%d] Received a echo request packet with no sequence number \n", h);
+    return GTPNOK;
+  }
+
+  uint16_t seq=ntohs(*(uint16_t*)(msgHdr+1));
+  LOG_D(GTPU, "[%d] Received a echo request, TEID: %d, seq: %hu\n", h, msgHdr->teid, seq);
+  uint8_t recovery[2]={14,0};
+  
+  return gtpv1uCreateAndSendMsg(h, peerIp, peerPort, GTP_ECHO_RSP, ntohl(msgHdr->teid),
+			 recovery, sizeof recovery,
+			 1, 0, 0, seq, 0, 0);
+
 }
 
 static int Gtpv1uHandleError(int h,
@@ -626,7 +673,7 @@ static int Gtpv1uHandleError(int h,
                              uint32_t msgBufLen,
                              uint16_t peerPort,
                              uint32_t peerIp) {
-  LOG_E(GTPU,"to be dev\n");
+  LOG_E(GTPU,"Hadle error to be dev\n");
   int rc = GTPNOK;
   return rc;
 }
@@ -636,7 +683,7 @@ static int Gtpv1uHandleSupportedExt(int h,
                                     uint32_t msgBufLen,
                                     uint16_t peerPort,
                                     uint32_t peerIp) {
-  LOG_E(GTPU,"to be dev\n");
+  LOG_E(GTPU,"Supported extensions to be dev\n");
   int rc = GTPNOK;
   return rc;
 }
@@ -652,7 +699,7 @@ static int Gtpv1uHandleEndMarker(int h,
   Gtpv1uMsgHeaderT      *msgHdr = (Gtpv1uMsgHeaderT *) msgBuf;
 
   if ( msgHdr->version != 1 ||  msgHdr->PT != 1 ) {
-    LOG_E(GTPU, "Received a packet that is not GTP header\n");
+    LOG_E(GTPU, "[%d] Received a packet that is not GTP header\n", h);
     return GTPNOK;
   }
 
@@ -662,7 +709,7 @@ static int Gtpv1uHandleEndMarker(int h,
   auto tunnel=inst->te2ue_mapping.find(ntohl(msgHdr->teid));
 
   if ( tunnel == inst->te2ue_mapping.end() ) {
-    LOG_E(GTPU,"Received a incoming packet on unknown teid (%x) Dropping!\n", msgHdr->teid);
+    LOG_E(GTPU,"[%d] Received a incoming packet on unknown teid (%x) Dropping!\n", h, msgHdr->teid);
     pthread_mutex_unlock(&globGtp.gtp_lock);
     return GTPNOK;
   }
@@ -678,7 +725,6 @@ static int Gtpv1uHandleEndMarker(int h,
   ctxt.frame = 0;
   ctxt.subframe = 0;
   ctxt.eNB_index = 0;
-  ctxt.configured = 0;
   ctxt.brOption = 0;
   const srb_flag_t     srb_flag=SRB_FLAG_NO;
   const rb_id_t        rb_id=tunnel->second.incoming_rb_id;
@@ -699,9 +745,9 @@ static int Gtpv1uHandleEndMarker(int h,
                                 mode,
                                 &sourceL2Id,
                                 &destinationL2Id) )
-    LOG_E(GTPU,"down layer refused incoming packet\n");
+    LOG_E(GTPU,"[%d] down layer refused incoming packet\n", h);
 
-  LOG_D(GTPU,"Received END marker packet for: teid:%x\n", ntohl(msgHdr->teid));
+  LOG_D(GTPU,"[%d] Received END marker packet for: teid:%x\n", h, ntohl(msgHdr->teid));
   return !GTPNOK;
 }
 
@@ -713,7 +759,7 @@ static int Gtpv1uHandleGpdu(int h,
   Gtpv1uMsgHeaderT      *msgHdr = (Gtpv1uMsgHeaderT *) msgBuf;
 
   if ( msgHdr->version != 1 ||  msgHdr->PT != 1 ) {
-    LOG_E(GTPU, "Received a packet that is not GTP header\n");
+    LOG_E(GTPU, "[%d] Received a packet that is not GTP header\n", h);
     return GTPNOK;
   }
 
@@ -723,7 +769,7 @@ static int Gtpv1uHandleGpdu(int h,
   auto tunnel=inst->te2ue_mapping.find(ntohl(msgHdr->teid));
 
   if ( tunnel == inst->te2ue_mapping.end() ) {
-    LOG_E(GTPU,"Received a incoming packet on unknown teid (%x) Dropping!\n", msgHdr->teid);
+    LOG_E(GTPU,"[%d] Received a incoming packet on unknown teid (%x) Dropping!\n", h, ntohl(msgHdr->teid));
     pthread_mutex_unlock(&globGtp.gtp_lock);
     return GTPNOK;
   }
@@ -744,7 +790,6 @@ static int Gtpv1uHandleGpdu(int h,
   ctxt.frame = 0;
   ctxt.subframe = 0;
   ctxt.eNB_index = 0;
-  ctxt.configured = 0;
   ctxt.brOption = 0;
   const srb_flag_t     srb_flag=SRB_FLAG_NO;
   const rb_id_t        rb_id=tunnel->second.incoming_rb_id;
@@ -767,9 +812,9 @@ static int Gtpv1uHandleGpdu(int h,
                                 mode,
                                 &sourceL2Id,
                                 &destinationL2Id) )
-    LOG_E(GTPU,"down layer refused incoming packet\n");
+    LOG_E(GTPU,"[%d] down layer refused incoming packet\n", h);
 
-  LOG_D(GTPU,"Received a %d bytes packet for: teid:%x\n",
+  LOG_D(GTPU,"[%d] Received a %d bytes packet for: teid:%x\n", h,
         msgBufLen-offset,
         ntohl(msgHdr->teid));
   return !GTPNOK;
@@ -784,14 +829,14 @@ void gtpv1uReceiver(int h) {
 
   if ((udpDataLen = recvfrom(h, udpData, sizeof(udpData), 0,
                              (struct sockaddr *)&addr, &from_len)) < 0) {
-    LOG_E(GTPU, "Recvfrom failed on %d (%s)\n", h, strerror(errno));
+    LOG_E(GTPU, "[%d] Recvfrom failed (%s)\n", h, strerror(errno));
     return;
   } else if (udpDataLen == 0) {
-    LOG_W(GTPU, "Recvfrom returned 0\n");
+    LOG_W(GTPU, "[%d] Recvfrom returned 0\n", h);
     return;
   } else {
     uint8_t msgType = *((uint8_t *)(udpData + 1));
-    LOG_D(GTPU, "Received GTP data, msg type: %x\n", msgType);
+    LOG_D(GTPU, "[%d] Received GTP data, msg type: %x\n", h, msgType);
 
     switch(msgType) {
       case GTP_ECHO_RSP:
@@ -818,7 +863,7 @@ void gtpv1uReceiver(int h) {
         break;
 
       default:
-        LOG_E(GTPU, "Received a GTP packet of unknown type: %d\n",msgType);
+        LOG_E(GTPU, "[%d] Received a GTP packet of unknown type: %d\n", h, msgType);
         break;
     }
   }
@@ -850,7 +895,6 @@ void *ocp_gtpv1uTask(void *args)  {
         case GTPV1U_GNB_TUNNEL_DATA_REQ: {
           gtpv1uSend2(compatInst(ITTI_MSG_DESTINATION_INSTANCE(message_p)),
                       &GTPV1U_GNB_TUNNEL_DATA_REQ(message_p), false, false);
-          itti_free(OCP_GTPV1_U, GTPV1U_GNB_TUNNEL_DATA_REQ(message_p).buffer);
         }
         break;
 
@@ -874,18 +918,10 @@ void *ocp_gtpv1uTask(void *args)  {
           abort();
           break;
 
-        case GTPV1U_ENB_S1_REQ:
-          // to be dev: should be removed, to use API
-          strcpy(addr.originHost, GTPV1U_ENB_S1_REQ(message_p).addrStr);
-          strcpy(addr.originService, GTPV1U_ENB_S1_REQ(message_p).portStr);
-          strcpy(addr.destinationService,addr.originService);
-          AssertFatal((legacyInstanceMapping=ocp_gtpv1Init(addr))!=0,"Instance 0 reserved for legacy\n");
-          break;
-
-        case GTPV1U_GNB_NG_REQ:
+        case GTPV1U_REQ:
           // to be dev: should be removed, to use API
-          strcpy(addr.originHost, GTPV1U_ENB_S1_REQ(message_p).addrStr);
-          strcpy(addr.originService, GTPV1U_ENB_S1_REQ(message_p).portStr);
+          strcpy(addr.originHost, GTPV1U_REQ(message_p).localAddrStr);
+          strcpy(addr.originService, GTPV1U_REQ(message_p).localPortStr);
           strcpy(addr.destinationService,addr.originService);
           AssertFatal((legacyInstanceMapping=ocp_gtpv1Init(addr))!=0,"Instance 0 reserved for legacy\n");
           break;
diff --git a/openair3/ocp-gtpu/gtp_itf.h b/openair3/ocp-gtpu/gtp_itf.h
index dd406e27cddc579eca574453c96b7ce2a2abd40b..3893acf40f0416b98b153b70e9b6153d79d49b09 100644
--- a/openair3/ocp-gtpu/gtp_itf.h
+++ b/openair3/ocp-gtpu/gtp_itf.h
@@ -1,5 +1,6 @@
 #ifndef __GTPUNEW_ITF_H__
 #define __GTPUNEW_ITF_H__
+
 #define GTPNOK -1
 
 # define GTPU_HEADER_OVERHEAD_MAX 64
@@ -31,7 +32,7 @@ typedef boolean_t (*gtpCallback)(
   const pdcp_transmission_mode_t modeP,
   const uint32_t *sourceL2Id,
   const uint32_t *destinationL2Id);
-
+  
 typedef struct openAddr_s {
   char originHost[HOST_NAME_MAX];
   char originService[HOST_NAME_MAX];
@@ -62,6 +63,7 @@ int ocp_gtpv1u_create_x2u_tunnel(
 // New API
 teid_t newGtpuCreateTunnel(instance_t instance, rnti_t rnti, int incoming_bearer_id, int outgoing_rb_id, teid_t teid,
                            transport_layer_addr_t remoteAddr, int port, gtpCallback callBack);
+void GtpuUpdateTunnelOutgoingTeid(instance_t instance, rnti_t rnti, ebi_t bearer_id, teid_t newOutgoingTeid);
 instance_t ocp_gtpv1Init(openAddr_t context);
 void *ocp_gtpv1uTask(void *args);
 
diff --git a/targets/ARCH/COMMON/common_lib.c b/targets/ARCH/COMMON/common_lib.c
index 2758d01de3f11ae06217a1a7d705194d42e96520..c4f4e3ead5905648eccfeba6ebf7fb14702285e5 100644
--- a/targets/ARCH/COMMON/common_lib.c
+++ b/targets/ARCH/COMMON/common_lib.c
@@ -148,7 +148,8 @@ int openair0_device_load(openair0_device *device,
       LOG_E(HW, "%s %d:Unsupported radio head\n", __FILE__, __LINE__);
       return -1;
 	}
-  }
+  } else
+    AssertFatal(false, "can't open the radio device: %s\n", get_devname(device->type));
 
   return rc;
 }
diff --git a/targets/COMMON/create_tasks.c b/targets/COMMON/create_tasks.c
index ffeb368e73786ac09e7aa98b81879d5d3f2d5f55..4463228dc7386d850d4af8b044966c998d270c8f 100644
--- a/targets/COMMON/create_tasks.c
+++ b/targets/COMMON/create_tasks.c
@@ -59,7 +59,7 @@ int create_tasks(uint32_t enb_nb) {
   rc = itti_create_task (TASK_RRC_ENB, rrc_enb_task, NULL);
   AssertFatal(rc >= 0, "Create task for RRC eNB failed\n");
 
-  if (EPC_MODE_ENABLED && ! ( split73==SPLIT73_DU ) ) {
+  if (get_softmodem_params()->emulate_l1 || (EPC_MODE_ENABLED && split73 != SPLIT73_DU)) {
     rc = itti_create_task(TASK_SCTP, sctp_eNB_task, NULL);
     AssertFatal(rc >= 0, "Create task for SCTP failed\n");
   }
@@ -73,12 +73,13 @@ int create_tasks(uint32_t enb_nb) {
     }
     rc = itti_create_task(TASK_GTPV1_U, gtpv1u_eNB_task, NULL);
     AssertFatal(rc >= 0, "Create task for GTPV1U failed\n");
-    if (is_x2ap_enabled()) {
+  }
+
+  if (is_x2ap_enabled()) {
       rc = itti_create_task(TASK_X2AP, x2ap_task, NULL);
       AssertFatal(rc >= 0, "Create task for X2AP failed\n");
-    } else {
+  } else {
       LOG_I(X2AP, "X2AP is disabled.\n");
-    }
   }
 
   if (NODE_IS_CU(type)) {
@@ -89,6 +90,9 @@ int create_tasks(uint32_t enb_nb) {
   if (NODE_IS_DU(type)) {
     rc = itti_create_task(TASK_DU_F1, F1AP_DU_task, NULL);
     AssertFatal(rc >= 0, "Create task for DU F1AP failed\n");
+    // DU is now GTP-U instead of protobuf
+    rc = itti_create_task(TASK_GTPV1_U, gtpv1u_eNB_task, NULL);
+    AssertFatal(rc >= 0, "Create task for GTPV1U failed\n");
   }
 
   if (!NODE_IS_CU(type)) {
diff --git a/targets/COMMON/create_tasks_mbms.c b/targets/COMMON/create_tasks_mbms.c
index 8b1736853f2c648da1b962923d7608afc171cf16..1cd3bb2f3a75747ca4adfd9a58c3cd8eba0ef370 100644
--- a/targets/COMMON/create_tasks_mbms.c
+++ b/targets/COMMON/create_tasks_mbms.c
@@ -51,6 +51,7 @@
 int create_tasks_mbms(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;
+  AssertFatal(!get_softmodem_params()->nsa, "In NSA mode\n");
   int rc;
 
   if (enb_nb == 0) return 0;
diff --git a/targets/COMMON/create_tasks_ue.c b/targets/COMMON/create_tasks_ue.c
index 3b9b7cf7bb324e0d93cd9c79ef8af1fd1534d7fa..9341107af9bd53bb68132e1080a6103fc5054e49 100644
--- a/targets/COMMON/create_tasks_ue.c
+++ b/targets/COMMON/create_tasks_ue.c
@@ -22,6 +22,7 @@
 # include "intertask_interface.h"
 # include "create_tasks.h"
 # include "common/utils/LOG/log.h"
+# include "executables/softmodem-common.h"
 
   #include "sctp_eNB_task.h"
   #include "s1ap_eNB.h"
@@ -63,6 +64,15 @@ int create_tasks_ue(uint32_t ue_nb) {
       LOG_E(RRC, "Create task for RRC UE failed\n");
       return -1;
     }
+
+    if (get_softmodem_params()->nsa) {
+      init_connections_with_nr_ue();
+      LOG_I(RRC, "Started LTE-NR link in the LTE UE\n");
+      if (itti_create_task (TASK_RRC_NSA_UE, recv_msgs_from_nr_ue, NULL) < 0) {
+        LOG_E(RRC, "Create task for RRC NSA UE failed\n");
+        return -1;
+      }
+    }
   }
 
   itti_wait_ready(0);
diff --git a/targets/COMMON/openairinterface5g_limits.h b/targets/COMMON/openairinterface5g_limits.h
index 9260fe2701ff85b02e9c16faeb36c039845afd80..d68292bd3913c79e11acf014e9a9fd87ea3682c5 100644
--- a/targets/COMMON/openairinterface5g_limits.h
+++ b/targets/COMMON/openairinterface5g_limits.h
@@ -28,7 +28,7 @@
 
 #        ifndef PHYSIM
 #            ifndef UE_EXPANSION
-#                    define NUMBER_OF_UE_MAX 4
+#                    define NUMBER_OF_UE_MAX 40
 #                    define NUMBER_OF_NR_UE_MAX 4
 #                    define NUMBER_OF_CONNECTED_eNB_MAX 1
 #                    define NUMBER_OF_CONNECTED_gNB_MAX 1
diff --git a/targets/PROJECTS/GENERIC-NR-5GC/CONF/du_gnb.conf b/targets/PROJECTS/GENERIC-NR-5GC/CONF/du_gnb.conf
index 7f9e4d2d4411c8e8dd4683f6ade8dddb0b7d5ade..417e937edf15fd7948b20327566fdf7bb858ad18 100644
--- a/targets/PROJECTS/GENERIC-NR-5GC/CONF/du_gnb.conf
+++ b/targets/PROJECTS/GENERIC-NR-5GC/CONF/du_gnb.conf
@@ -79,9 +79,10 @@ gNBs =
 # 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120  
         initialDLBWPsubcarrierSpacing                                           = 1;
       #pdcch-ConfigCommon
-        initialDLBWPcontrolResourceSetZero                                      = 12;
+        initialDLBWPcontrolResourceSetZero                                      = 11;
         initialDLBWPsearchSpaceZero                                             = 0;
 
+
   #uplinkConfigCommon 
      #frequencyInfoUL
       ul_frequencyBand                                                 = 78;
@@ -135,6 +136,7 @@ gNBs =
 # 0=unrestricted, 1=restricted type A, 2=restricted type B
         restrictedSetConfig                                         = 0,
 
+
         msg3_DeltaPreamble                                          = 1;
         p0_NominalWithGrant                                         =-90;
 
diff --git a/targets/RT/USER/lte-enb.c b/targets/RT/USER/lte-enb.c
index 632a47707b4294f635f19676743d5762fb4be9d2..f20f8267ed7950890dae31411ed6bb0ca12a61a5 100644
--- a/targets/RT/USER/lte-enb.c
+++ b/targets/RT/USER/lte-enb.c
@@ -398,8 +398,20 @@ static void *L1_thread( void *param ) {
   // set default return value
   eNB_thread_rxtx_status = 0;
   sprintf(thread_name,"RXn_TXnp4_%d\n",&eNB->proc.L1_proc == proc ? 0 : 1);
+#if 1
+  {
+    struct sched_param sparam =
+    {
+      .sched_priority = 79,
+    };
+    if (pthread_setschedparam(pthread_self(), SCHED_RR, &sparam) != 0)
+    {
+      LOG_E(PHY,"pthread_setschedparam: %s\n", strerror(errno));
+    }
+  }
+#else
   thread_top_init(thread_name,1,470000,500000,500000);
-  pthread_setname_np( pthread_self(),"rxtx processing");
+#endif
   LOG_I(PHY,"thread rxtx created id=%ld\n", syscall(__NR_gettid));
 
   while (!oai_exit) {
@@ -943,7 +955,16 @@ void init_eNB_proc(int inst) {
       //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 );
+      if (pthread_setname_np(L1_proc->pthread, "oai:enb-L1-rx") != 0)
+      {
+          LOG_E(PHY, "pthread_setname_np: %s\n", strerror(errno));
+      }
+
       pthread_create( &L1_proc_tx->pthread, attr1, L1_thread, L1_proc_tx);
+      if (pthread_setname_np(L1_proc_tx->pthread, "oai:enb-L1-tx") != 0)
+      {
+          LOG_E(PHY, "pthread_setname_np: %s\n", strerror(errno));
+      }
     }
 
     if (NFAPI_MODE!=NFAPI_MODE_VNF) {
diff --git a/targets/RT/USER/lte-ru.c b/targets/RT/USER/lte-ru.c
index 10ba121c44ce51b462c7a01b840abf24c02a0963..20644388c85473a2a940305730b3cf45be4f6bf5 100644
--- a/targets/RT/USER/lte-ru.c
+++ b/targets/RT/USER/lte-ru.c
@@ -1490,6 +1490,7 @@ static void *ru_stats_thread(void *param) {
 static void *ru_thread_tx( void *param ) {
   RU_t *ru         = (RU_t *)param;
   RU_proc_t *proc  = &ru->proc;
+  __attribute__((unused))
   LTE_DL_FRAME_PARMS *fp = ru->frame_parms;
   PHY_VARS_eNB *eNB;
   L1_proc_t *eNB_proc;
@@ -1917,7 +1918,8 @@ static void *ru_thread( void *param ) {
 // This thread run the initial synchronization like a UE
 void *ru_thread_synch(void *arg) {
   RU_t *ru = (RU_t *)arg;
-  LTE_DL_FRAME_PARMS *fp;
+  __attribute__((unused))
+  LTE_DL_FRAME_PARMS *fp = ru->frame_parms;
   int64_t peak_val, avg;
   static int ru_thread_synch_status = 0;
   int cnt=0;
diff --git a/targets/RT/USER/lte-softmodem.c b/targets/RT/USER/lte-softmodem.c
index ed9daf23f68ef2747f5f8385017f881fcd17f3e3..8cc693623b227eb07cfc79653d8a56a407f9563a 100644
--- a/targets/RT/USER/lte-softmodem.c
+++ b/targets/RT/USER/lte-softmodem.c
@@ -94,6 +94,9 @@ unsigned short config_frames[4] = {2,9,11,13};
 #include "NB_IoT_interface.h"
 #include <executables/split_headers.h>
 
+#if USING_GPROF
+#  include "sys/gmon.h"
+#endif
 
 pthread_cond_t nfapi_sync_cond;
 pthread_mutex_t nfapi_sync_mutex;
@@ -178,7 +181,6 @@ eth_params_t *eth_params;
 double cpuf;
 
 int oaisim_flag=0;
-uint8_t proto_agent_flag = 0;
 
 
 /* forward declarations */
@@ -479,7 +481,7 @@ int restart_L1L2(module_id_t enb_id) {
   return 0;
 }
 
-void init_pdcp(void) {
+static void init_pdcp(void) {
   if (!NODE_IS_DU(RC.rrc[0]->node_type)) {
     pdcp_layer_init();
     uint32_t pdcp_initmask = (IS_SOFTMODEM_NOS1) ?
@@ -490,16 +492,16 @@ void init_pdcp(void) {
 
     pdcp_initmask = pdcp_initmask | ENB_NAS_USE_TUN_W_MBMS_BIT;
 
-    pdcp_module_init(pdcp_initmask);
+    pdcp_module_init(pdcp_initmask, 0);
 
     if (NODE_IS_CU(RC.rrc[0]->node_type)) {
-      pdcp_set_rlc_data_req_func((send_rlc_data_req_func_t)proto_agent_send_rlc_data_req);
+      pdcp_set_rlc_data_req_func(cu_send_to_du);
     } else {
-      pdcp_set_rlc_data_req_func((send_rlc_data_req_func_t) rlc_data_req);
-      pdcp_set_pdcp_data_ind_func((pdcp_data_ind_func_t) pdcp_data_ind);
+      pdcp_set_rlc_data_req_func(rlc_data_req);
+      pdcp_set_pdcp_data_ind_func(pdcp_data_ind);
     }
   } else {
-    pdcp_set_pdcp_data_ind_func((pdcp_data_ind_func_t) proto_agent_send_pdcp_data_ind);
+    pdcp_set_pdcp_data_ind_func(proto_agent_send_pdcp_data_ind);
   }
 }
 
@@ -516,6 +518,13 @@ static  void wait_nfapi_init(char *thread_name) {
 
 int main ( int argc, char **argv )
 {
+  set_priority(79);
+  if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1)
+  {
+    fprintf(stderr, "mlockall: %s\n", strerror(errno));
+    return EXIT_FAILURE;
+  }
+
   int i;
   int CC_id = 0;
   int ru_id;
@@ -742,10 +751,19 @@ int main ( int argc, char **argv )
   if(IS_SOFTMODEM_DOSCOPE)
      load_softscope("enb",NULL);
   itti_wait_tasks_end();
+
+#if USING_GPROF
+  // Save the gprof data now (rather than via atexit) in case we crash while shutting down
+  fprintf(stderr, "Recording gprof data...\n");
+  _mcleanup();
+  fprintf(stderr, "Recording gprof data...done\n");
+#endif // USING_GPROF
+
   oai_exit=1;
   LOG_I(ENB_APP,"oai_exit=%d\n",oai_exit);
   // stop threads
 
+  #if 0 //Disable clean up because this tends to crash (and unnecessary)
   if (RC.nb_inst == 0 || !NODE_IS_CU(node_type)) {
     if(IS_SOFTMODEM_DOSCOPE)
       end_forms();
@@ -787,7 +805,9 @@ int main ( int argc, char **argv )
       }
     }
   }
+  #endif
 
+  pdcp_module_cleanup();
   terminate_opt();
   logClean();
   printf("Bye.\n");
diff --git a/targets/RT/USER/lte-softmodem.h b/targets/RT/USER/lte-softmodem.h
index a1b261f26361722dbbd96fc44fd93102d1a2b3ab..4154d6c8db1cd0e44e324972dadb161dd60aff4f 100644
--- a/targets/RT/USER/lte-softmodem.h
+++ b/targets/RT/USER/lte-softmodem.h
@@ -114,7 +114,9 @@
     {"usrp-args",         CONFIG_HLP_USRP_ARGS,   0,               strptr:(char **)&usrp_args,         defstrval:"type=b200",TYPE_STRING,   0},   \
     {"mmapped-dma",       CONFIG_HLP_DMAMAP,      PARAMFLAG_BOOL,  uptr:&mmapped_dma,                  defintval:0,          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}    \
+    {"A",                 CONFIG_HLP_TADV,        0,               iptr:&(timingadv),                  defintval:0,          TYPE_INT,      0},   \
+    {"ue-idx-standalone", NULL,                   0,               u16ptr:&ue_idx_standalone,          defuintval:0xFFFF,    TYPE_UINT16,   0},   \
+    {"node-number",       NULL,                   0,               u16ptr:&node_number,                defuintval:2,         TYPE_UINT16,   0},   \
   }
 
 /*-----------------------------------------------------------------------------------------------------------------------------*/
@@ -138,6 +140,9 @@ extern pthread_cond_t sync_cond;
 extern pthread_mutex_t sync_mutex;
 extern int sync_var;
 
+extern uint16_t ue_id_g;
+extern uint16_t node_number;
+
 extern uint64_t downlink_frequency[MAX_NUM_CCs][4];
 extern int32_t  uplink_frequency_offset[MAX_NUM_CCs][4];
 
@@ -208,7 +213,10 @@ extern int stop_L1L2(module_id_t enb_id);
 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 void init_UE_standalone_thread(int ue_idx);
 
 extern PHY_VARS_UE *init_ue_vars(LTE_DL_FRAME_PARMS *frame_parms, uint8_t UE_id, uint8_t abstraction_flag);
 
+extern void init_bler_table(void);
+
 #endif
diff --git a/targets/RT/USER/lte-ue.c b/targets/RT/USER/lte-ue.c
index 1fae6c1e6621596cef3c8ba47c5d756b45a2cfb9..70e4677943168994f6c709e4cada76f0cc8e63c9 100644
--- a/targets/RT/USER/lte-ue.c
+++ b/targets/RT/USER/lte-ue.c
@@ -81,18 +81,10 @@ void init_UE_threads(int);
 void init_UE_threads_stub(int);
 void init_UE_single_thread_stub(int);
 void *UE_thread(void *arg);
-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);
-void init_UE_stub(int nb_inst,int,int,char *);
-void init_UE_stub_single_thread(int nb_inst,int,int,char *);
 int init_timer_thread(void);
-extern void oai_subframe_ind(uint16_t sfn, uint16_t sf);
 extern void multicast_link_start(void (*rx_handlerP) (unsigned int, char *),
-                                 unsigned char _multicast_group, char *multicast_ifname);
-extern int oai_nfapi_crc_indication(nfapi_crc_indication_t *crc_ind);
-extern int oai_nfapi_cqi_indication(nfapi_cqi_indication_t *cqi_ind);
-extern int oai_nfapi_harq_indication(nfapi_harq_indication_t *harq_ind);
-extern int oai_nfapi_sr_indication(nfapi_sr_indication_t *ind);
-extern int oai_nfapi_rx_ind(nfapi_rx_indication_t *ind);
+                                 unsigned char _multicast_group,
+                                 char *multicast_ifname);
 extern int multicast_link_write_sock(int groupP, char *dataP, uint32_t sizeP);
 
 
@@ -194,7 +186,7 @@ PHY_VARS_UE *init_ue_vars(LTE_DL_FRAME_PARMS *frame_parms,
   ue->mac_enabled = 1;
 
   // In phy_stub_UE (MAC-to-MAC) mode these init functions don't need to get called. Is this correct?
-  if (NFAPI_MODE!=NFAPI_UE_STUB_PNF) {
+  if (NFAPI_MODE!=NFAPI_UE_STUB_PNF && NFAPI_MODE!=NFAPI_MODE_STANDALONE_PNF) {
     // initialize all signal buffers
     init_lte_ue_signal(ue,1,abstraction_flag);
     // intialize transport
@@ -413,15 +405,31 @@ void init_UE_stub_single_thread(int nb_inst,
     // PHY_vars_UE_g[inst][0] = init_ue_vars(NULL,inst,0);
   }
 
-  init_timer_thread();
+  if(NFAPI_MODE != NFAPI_MODE_STANDALONE_PNF) {
+    init_timer_thread();
+  }
+
   init_UE_single_thread_stub(nb_inst);
   printf("UE threads created \n");
-  LOG_I(PHY,"Starting multicast link on %s\n",emul_iface);
 
-  if(NFAPI_MODE!=NFAPI_UE_STUB_PNF)
+  if(NFAPI_MODE!=NFAPI_UE_STUB_PNF && NFAPI_MODE!=NFAPI_MODE_STANDALONE_PNF) {
+    LOG_I(PHY,"Starting multicast link on %s\n",emul_iface);
     multicast_link_start(ue_stub_rx_handler,0,emul_iface);
+  }
 }
 
+void init_UE_standalone_thread(int ue_idx)
+{
+  int standalone_tx_port = 3211 + ue_idx * 2;
+  int standalone_rx_port = 3212 + ue_idx * 2;
+  ue_init_standalone_socket(standalone_tx_port, standalone_rx_port);
+
+  pthread_t thread;
+  if (pthread_create(&thread, NULL, ue_standalone_pnf_task, NULL) != 0) {
+    LOG_E(MAC, "pthread_create failed for calling ue_standalone_pnf_task");
+  }
+  pthread_setname_np(thread, "oai:ue-stand");
+}
 
 void init_UE_stub(int nb_inst,
                   int eMBMS_active,
@@ -449,7 +457,7 @@ void init_UE_stub(int nb_inst,
   printf("UE threads created \n");
   LOG_I(PHY,"Starting multicast link on %s\n",emul_iface);
 
-  if(NFAPI_MODE!=NFAPI_UE_STUB_PNF)
+  if(NFAPI_MODE!=NFAPI_UE_STUB_PNF && NFAPI_MODE!=NFAPI_MODE_STANDALONE_PNF)
     multicast_link_start(ue_stub_rx_handler,0,emul_iface);
 }
 
@@ -956,6 +964,396 @@ void ue_stub_rx_handler(unsigned int num_bytes,
   }
 }
 
+uint64_t clock_usec(void)
+{
+    struct timespec t;
+    if (clock_gettime(CLOCK_MONOTONIC, &t) == -1)
+    {
+        abort();
+    }
+    return (uint64_t)t.tv_sec * 1000000 + (t.tv_nsec / 1000);
+}
+/*!
+ * \brief This is the UE thread for RX subframe n and TX subframe n+4.
+ * This thread performs the phy_procedures_UE_RX() on every received slot.
+ * then, if TX is enabled it performs TX for n+4.
+ * \param arg is a pointer to a \ref PHY_VARS_UE structure.
+ * \returns a pointer to an int. The storage is not on the heap and must not be freed.
+ */
+
+static void *UE_phy_stub_standalone_pnf_task(void *arg)
+{
+#if 1
+  {
+    struct sched_param sparam =
+    {
+      .sched_priority = 79,
+    };
+    if (pthread_setschedparam(pthread_self(), SCHED_RR, &sparam) != 0)
+    {
+      LOG_E(PHY,"pthread_setschedparam: %s\n", strerror(errno));
+    }
+  }
+#else
+  thread_top_init("UE_phy_stub_thread_rxn_txnp4", 1, 870000L, 1000000L, 1000000L);
+#endif
+
+  // 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
+  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;
+  // 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;
+  proc = &PHY_vars_UE_g[0][0]->proc.proc_rxtx[0];
+
+  UE = rtd->UE;
+
+  UL_INFO = (UL_IND_t *)calloc(1, sizeof(UL_IND_t));
+  UL_INFO->rx_ind.rx_indication_body.rx_pdu_list = calloc(NFAPI_RX_IND_MAX_PDU, sizeof(nfapi_rx_indication_pdu_t));
+  UL_INFO->rx_ind.rx_indication_body.number_of_pdus = 0;
+  UL_INFO->crc_ind.crc_indication_body.crc_pdu_list = calloc(NFAPI_CRC_IND_MAX_PDU, sizeof(nfapi_crc_indication_pdu_t));
+  UL_INFO->crc_ind.crc_indication_body.number_of_crcs = 0;
+  UL_INFO->harq_ind.harq_indication_body.harq_pdu_list = calloc(NFAPI_HARQ_IND_MAX_PDU, sizeof(nfapi_harq_indication_pdu_t));
+  UL_INFO->harq_ind.harq_indication_body.number_of_harqs = 0;
+  UL_INFO->sr_ind.sr_indication_body.sr_pdu_list = calloc(NFAPI_SR_IND_MAX_PDU, sizeof(nfapi_sr_indication_pdu_t));
+  UL_INFO->sr_ind.sr_indication_body.number_of_srs = 0;
+  UL_INFO->cqi_ind.cqi_indication_body.cqi_pdu_list = calloc(NFAPI_CQI_IND_MAX_PDU, sizeof(nfapi_cqi_indication_pdu_t));
+  UL_INFO->cqi_ind.cqi_indication_body.cqi_raw_pdu_list = calloc(NFAPI_CQI_IND_MAX_PDU, sizeof(nfapi_cqi_indication_raw_pdu_t));
+  UL_INFO->cqi_ind.cqi_indication_body.number_of_cqis = 0;
+
+  proc->subframe_rx = proc->sub_frame_start;
+  proc->subframe_tx = -1;
+  proc->frame_rx = -1;
+  proc->frame_tx = -1;
+  // Initializations for nfapi-L2-emulator mode
+  sync_var = 0;
+
+  //PANOS: CAREFUL HERE!
+  wait_sync("UE_phy_stub_standalone_pnf_task");
+
+  int last_sfn_sf = -1;
+
+  LOG_I(MAC, "Clearing Queues\n");
+  reset_queue(&dl_config_req_tx_req_queue);
+  reset_queue(&ul_config_req_queue);
+  reset_queue(&hi_dci0_req_queue);
+
+  while (!oai_exit) {
+    bool sent_any = false;
+    if (sem_wait(&sfn_semaphore) != 0) {
+      LOG_E(MAC, "sem_wait() error\n");
+      abort();
+    }
+
+    int sfn_sf = current_sfn_sf;
+    if (sfn_sf == last_sfn_sf)
+    {
+      LOG_W(MAC, "repeated sfn_sf = %d.%d\n",
+            sfn_sf >> 4, sfn_sf & 15);
+      continue;
+    }
+    last_sfn_sf = sfn_sf;
+
+    nfapi_dl_config_req_tx_req_t *dl_config_req_tx_req = get_queue(&dl_config_req_tx_req_queue);
+    nfapi_ul_config_request_t *ul_config_req = get_queue(&ul_config_req_queue);
+    nfapi_hi_dci0_request_t *hi_dci0_req = get_queue(&hi_dci0_req_queue);
+
+    LOG_I(MAC, "received from proxy frame %d subframe %d\n",
+          NFAPI_SFNSF2SFN(sfn_sf), NFAPI_SFNSF2SF(sfn_sf));
+
+    if (ul_config_req != NULL) {
+      uint8_t ul_num_pdus = ul_config_req->ul_config_request_body.number_of_pdus;
+      if (ul_num_pdus > 0) {
+        char *ul_str = nfapi_ul_config_req_to_string(ul_config_req);
+        LOG_I(MAC, "ul_config_req: %s\n", ul_str);
+        free(ul_str);
+      }
+    }
+    if (hi_dci0_req != NULL) {
+      LOG_D(MAC, "hi_dci0_req pdus: %u Frame: %d Subframe: %d\n",
+      hi_dci0_req->hi_dci0_request_body.number_of_dci,
+      NFAPI_SFNSF2SFN(hi_dci0_req->sfn_sf), NFAPI_SFNSF2SF(hi_dci0_req->sfn_sf));
+    }
+
+    if (dl_config_req_tx_req != NULL) {
+
+      nfapi_tx_req_pdu_list_t *tx_req_pdu_list = dl_config_req_tx_req->tx_req_pdu_list;
+      nfapi_dl_config_request_t *dl_config_req = dl_config_req_tx_req->dl_config_req;
+
+      uint16_t dl_num_pdus = dl_config_req->dl_config_request_body.number_pdu;
+      LOG_I(MAC, "(OAI UE) Received dl_config_req from proxy at Frame: %d, Subframe: %d,"
+            " with number of PDUs: %u\n",
+            NFAPI_SFNSF2SFN(dl_config_req->sfn_sf), NFAPI_SFNSF2SF(dl_config_req->sfn_sf),
+            dl_num_pdus);
+      if (dl_num_pdus > 0) {
+        char *dl_str = nfapi_dl_config_req_to_string(dl_config_req);
+        LOG_I(MAC, "dl_config_req: %s\n", dl_str);
+        free(dl_str);
+      }
+      LOG_D(MAC, "tx_req pdus: %d\n", tx_req_pdu_list->num_pdus);
+
+      // Handling dl_config_req and tx_req:
+      nfapi_dl_config_request_body_t *dl_config_req_body = &dl_config_req->dl_config_request_body;
+      for (int i = 0; i < dl_config_req_body->number_pdu; ++i) {
+        nfapi_dl_config_request_pdu_t *pdu = &dl_config_req_body->dl_config_pdu_list[i];
+        if (pdu->pdu_type == NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE) {
+          i += 1;
+          AssertFatal(i < dl_config_req->dl_config_request_body.number_pdu,
+                      "Need PDU following DCI at index %d, but not found\n",
+                      i);
+          nfapi_dl_config_request_pdu_t *dlsch = &dl_config_req_body->dl_config_pdu_list[i];
+          if (dlsch->pdu_type != NFAPI_DL_CONFIG_DLSCH_PDU_TYPE) {
+            LOG_E(MAC, "expected DLSCH PDU at index %d\n", i);
+            continue;
+          }
+          dl_config_req_UE_MAC_dci(NFAPI_SFNSF2SFN(dl_config_req->sfn_sf),
+                                   NFAPI_SFNSF2SF(dl_config_req->sfn_sf),
+                                   pdu,
+                                   dlsch,
+                                   ue_num,
+                                   tx_req_pdu_list);
+        } else if (pdu->pdu_type == NFAPI_DL_CONFIG_BCH_PDU_TYPE) {
+          dl_config_req_UE_MAC_bch(NFAPI_SFNSF2SFN(dl_config_req->sfn_sf),
+                                   NFAPI_SFNSF2SF(dl_config_req->sfn_sf),
+                                   pdu,
+                                   ue_num);
+        } else if (pdu->pdu_type == NFAPI_DL_CONFIG_MCH_PDU_TYPE) {
+          dl_config_req_UE_MAC_mch(NFAPI_SFNSF2SFN(dl_config_req->sfn_sf),
+                                   NFAPI_SFNSF2SF(dl_config_req->sfn_sf),
+                                   pdu,
+                                   ue_num,
+                                   tx_req_pdu_list);
+        }
+      }
+    }
+    if (hi_dci0_req) {
+      nfapi_hi_dci0_request_body_t *hi_dci0_body = &hi_dci0_req->hi_dci0_request_body;
+      for (int i = 0; i < hi_dci0_body->number_of_dci + hi_dci0_body->number_of_hi; i++) {
+        nfapi_hi_dci0_request_pdu_t *pdu = &hi_dci0_body->hi_dci0_pdu_list[i];
+        hi_dci0_req_UE_MAC(NFAPI_SFNSF2SFN(hi_dci0_req->sfn_sf),
+                           NFAPI_SFNSF2SF(hi_dci0_req->sfn_sf),
+                           pdu,
+                           ue_num); // This function doesnt do anything? - Andrew
+      }
+    }
+
+    for (ue_index = 0; ue_index < ue_num; ue_index++) {
+      ue_Mod_id = ue_thread_id + NB_THREAD_INST * ue_index; // Always 0 in standalone pnf mode
+      UE = PHY_vars_UE_g[ue_Mod_id][0];
+
+#if UE_TIMING_TRACE
+      start_meas(&UE->generic_stat);
+#endif
+      int rx_frame = NFAPI_SFNSF2SF(sfn_sf) < 4 ? (NFAPI_SFNSF2SFN(sfn_sf) + 1023) % 1024 : NFAPI_SFNSF2SFN(sfn_sf); // subtracting 4 from subframe_tx
+      int rx_subframe = NFAPI_SFNSF2SF(sfn_sf) < 4 ? NFAPI_SFNSF2SF(sfn_sf) + 6 : NFAPI_SFNSF2SF(sfn_sf) - 4;
+      LOG_D(MAC, "rx_frame %d rx_subframe %d\n", rx_frame, rx_subframe);
+      if (UE->mac_enabled == 1) {
+        ret = ue_scheduler(ue_Mod_id,
+                           rx_frame,
+                           rx_subframe,
+                           NFAPI_SFNSF2SFN(sfn_sf),
+                           NFAPI_SFNSF2SF(sfn_sf),
+                           subframe_select(&UE->frame_parms, NFAPI_SFNSF2SF(sfn_sf)),
+                           0,
+                           0 /*FIXME CC_id*/);
+
+        if (ret != CONNECTION_OK) {
+          LOG_E(PHY, "[UE %" PRIu8 "] Frame %" PRIu32 ", subframe %u %s\n",
+                UE->Mod_id, rx_frame, NFAPI_SFNSF2SF(sfn_sf), get_connectionloss_errstr(ret));
+        }
+      }
+
+#if UE_TIMING_TRACE
+      stop_meas(&UE->generic_stat);
+#endif
+
+      // Prepare the future Tx data
+      if ((subframe_select(&UE->frame_parms, NFAPI_SFNSF2SF(sfn_sf)) == SF_UL) ||
+          (UE->frame_parms.frame_type == FDD))
+      {
+        if (UE->mode != loop_through_memory)
+        {
+          // 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 && rx_frame >= UE_mac_inst[Mod_id-1].ra_frame + 20) ) {
+          if (UE_mac_inst[ue_Mod_id].UE_mode[0] == RA_RESPONSE &&
+              is_prach_subframe(&UE->frame_parms, NFAPI_SFNSF2SFN(sfn_sf), NFAPI_SFNSF2SF(sfn_sf)))
+          {
+            UE_mac_inst[ue_Mod_id].UE_mode[0] = PRACH;
+          }
+          LOG_D(MAC, "UE_mode: %d\n", UE_mac_inst[ue_Mod_id].UE_mode[0]);
+          if (UE_mac_inst[ue_Mod_id].UE_mode[0] == PRACH)
+          { //&& ue_Mod_id == next_Mod_id) {
+            next_ra_frame++;
+            if (next_ra_frame > 500)
+            {
+              // check if we have PRACH opportunity
+              if (is_prach_subframe(&UE->frame_parms, NFAPI_SFNSF2SFN(sfn_sf), NFAPI_SFNSF2SF(sfn_sf)) && UE_mac_inst[ue_Mod_id].SI_Decoded == 1)
+              {
+                // The one working strangely...
+                //if (is_prach_subframe(&UE->frame_parms,NFAPI_SFNSF2SFN(sfn_sf), NFAPI_SFNSF2SF(sfn_sf) && Mod_id == (module_id_t) init_ra_UE) ) {
+                PRACH_RESOURCES_t *prach_resources = ue_get_rach(ue_Mod_id, 0, NFAPI_SFNSF2SFN(sfn_sf), 0, NFAPI_SFNSF2SF(sfn_sf));
+                if (prach_resources != NULL)
+                {
+                  LOG_I(MAC, "preamble_received_tar_power: %d\n",
+                        prach_resources->ra_PREAMBLE_RECEIVED_TARGET_POWER);
+                  UE_mac_inst[ue_Mod_id].ra_frame = NFAPI_SFNSF2SFN(sfn_sf);
+                  LOG_D(MAC, "UE_phy_stub_thread_rxn_txnp4 before RACH, Mod_id: %d frame %d subframe %d\n", ue_Mod_id, NFAPI_SFNSF2SFN(sfn_sf), NFAPI_SFNSF2SF(sfn_sf));
+                  fill_rach_indication_UE_MAC(ue_Mod_id, NFAPI_SFNSF2SFN(sfn_sf), NFAPI_SFNSF2SF(sfn_sf), UL_INFO, prach_resources->ra_PreambleIndex, prach_resources->ra_RNTI);
+                  sent_any = true;
+                  Msg1_transmitted(ue_Mod_id, 0, NFAPI_SFNSF2SFN(sfn_sf), 0);
+                  UE_mac_inst[ue_Mod_id].UE_mode[0] = RA_RESPONSE;
+                  next_Mod_id = ue_Mod_id + 1;
+                  //next_ra_frame = (rx_frame + 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, NFAPI_SFNSF2SFN(sfn_sf), NFAPI_SFNSF2SF(sfn_sf), ue_Mod_id);
+          }
+        }
+
+        phy_procedures_UE_SL_RX(UE, proc);
+      }
+      else
+      {
+        LOG_I(MAC, "Skipping subframe select statement proxy SFN.SF: %d.%d\n",
+        NFAPI_SFNSF2SFN(sfn_sf), NFAPI_SFNSF2SF(sfn_sf));
+        if (ul_config_req != NULL)
+        {
+          LOG_I(MAC, "Skipping subframe select statement ul_config_req SFN.SF: %d.%d\n",
+          NFAPI_SFNSF2SFN(ul_config_req->sfn_sf), NFAPI_SFNSF2SF(ul_config_req->sfn_sf));
+        }
+      }
+    } //for (Mod_id=0; Mod_id<NB_UE_INST; Mod_id++)
+
+    if (UL_INFO->crc_ind.crc_indication_body.number_of_crcs > 0) {
+      //LOG_D(PHY,"UL_info->crc_ind.crc_indication_body.number_of_crcs:%d CRC_IND:SFN/SF:%d\n", UL_info->crc_ind.crc_indication_body.number_of_crcs, NFAPI_SFNSF2DEC(UL_info->crc_ind.sfn_sf));
+      //LOG_I(MAC, "ul_config_req_UE_MAC 2.2, SFN/SF of PNF counter:%d.%d, number_of_crcs: %d \n", timer_frame, timer_subframe, UL_INFO->crc_ind.crc_indication_body.number_of_crcs);
+      send_standalone_msg(UL_INFO, UL_INFO->crc_ind.header.message_id);
+      sent_any = true;
+      //LOG_I(MAC, "ul_config_req_UE_MAC 2.21 \n");
+      UL_INFO->crc_ind.crc_indication_body.number_of_crcs = 0;
+    }
+
+    if (UL_INFO->rx_ind.rx_indication_body.number_of_pdus > 0) {
+
+      //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);
+      send_standalone_msg(UL_INFO, UL_INFO->rx_ind.header.message_id);
+      sent_any = true;
+
+      //LOG_I(MAC, "ul_config_req_UE_MAC 2.31 \n");
+      UL_INFO->rx_ind.rx_indication_body.number_of_pdus = 0;
+    }
+
+    if (UL_INFO->cqi_ind.cqi_indication_body.number_of_cqis > 0) {
+      send_standalone_msg(UL_INFO, UL_INFO->cqi_ind.header.message_id);
+      sent_any = true;
+      UL_INFO->cqi_ind.cqi_indication_body.number_of_cqis = 0;
+    }
+
+    if (UL_INFO->harq_ind.harq_indication_body.number_of_harqs > 0) {
+      //LOG_D(MAC, "ul_config_req_UE_MAC 2.4, SFN/SF of PNF counter:%d.%d, number_of_harqs: %d \n", timer_frame, timer_subframe, UL_INFO->harq_ind.harq_indication_body.number_of_harqs);
+        send_standalone_msg(UL_INFO, UL_INFO->harq_ind.header.message_id);
+        sent_any = true;
+      //LOG_I(MAC, "ul_config_req_UE_MAC 2.41 \n");
+      UL_INFO->harq_ind.harq_indication_body.number_of_harqs = 0;
+    }
+
+    if (UL_INFO->sr_ind.sr_indication_body.number_of_srs > 0) {
+      //LOG_I(MAC, "ul_config_req_UE_MAC 2.5, SFN/SF of PNF counter:%d.%d, number_of_srs: %d \n", timer_frame, timer_subframe, UL_INFO->sr_ind.sr_indication_body.number_of_srs);
+        send_standalone_msg(UL_INFO, UL_INFO->sr_ind.header.message_id);
+        sent_any = true;
+      //LOG_I(MAC, "ul_config_req_UE_MAC 2.51 \n");
+      UL_INFO->sr_ind.sr_indication_body.number_of_srs = 0;
+    }
+
+    // De-allocate memory of nfapi requests copies before next subframe round
+    if (dl_config_req_tx_req != NULL) {
+      if (dl_config_req_tx_req->dl_config_req->vendor_extension != NULL) {
+        free(dl_config_req_tx_req->dl_config_req->vendor_extension);
+        dl_config_req_tx_req->dl_config_req->vendor_extension = NULL;
+      }
+
+      if (dl_config_req_tx_req->dl_config_req->dl_config_request_body.dl_config_pdu_list != NULL) {
+        free(dl_config_req_tx_req->dl_config_req->dl_config_request_body.dl_config_pdu_list);
+        dl_config_req_tx_req->dl_config_req->dl_config_request_body.dl_config_pdu_list = NULL;
+      }
+      nfapi_free_tx_req_pdu_list(dl_config_req_tx_req->tx_req_pdu_list);
+      dl_config_req_tx_req->tx_req_pdu_list = NULL;
+
+      free(dl_config_req_tx_req->dl_config_req);
+      dl_config_req_tx_req->dl_config_req = NULL;
+
+      free(dl_config_req_tx_req);
+      dl_config_req_tx_req = NULL;
+    }
+
+    if (ul_config_req != NULL) {
+      if (ul_config_req->ul_config_request_body.ul_config_pdu_list != NULL) {
+        free(ul_config_req->ul_config_request_body.ul_config_pdu_list);
+        ul_config_req->ul_config_request_body.ul_config_pdu_list = NULL;
+      }
+
+      free(ul_config_req);
+      ul_config_req = NULL;
+    }
+
+    if (hi_dci0_req != NULL) {
+      if (hi_dci0_req->hi_dci0_request_body.hi_dci0_pdu_list != NULL) {
+        free(hi_dci0_req->hi_dci0_request_body.hi_dci0_pdu_list);
+        hi_dci0_req->hi_dci0_request_body.hi_dci0_pdu_list = NULL;
+      }
+
+      free(hi_dci0_req);
+      hi_dci0_req = NULL;
+    }
+    if (!sent_any)
+    {
+     send_standalone_dummy();
+    }
+  }
+
+  // Free UL_INFO messages
+  free(UL_INFO->cqi_ind.cqi_indication_body.cqi_raw_pdu_list);
+  UL_INFO->cqi_ind.cqi_indication_body.cqi_raw_pdu_list = NULL;
+  free(UL_INFO->cqi_ind.cqi_indication_body.cqi_pdu_list);
+  UL_INFO->cqi_ind.cqi_indication_body.cqi_pdu_list = NULL;
+  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->harq_ind.harq_indication_body.harq_pdu_list);
+  UL_INFO->harq_ind.harq_indication_body.harq_pdu_list = NULL;
+  free(UL_INFO->crc_ind.crc_indication_body.crc_pdu_list);
+  UL_INFO->crc_ind.crc_indication_body.crc_pdu_list = NULL;
+  free(UL_INFO->rx_ind.rx_indication_body.rx_pdu_list);
+  UL_INFO->rx_ind.rx_indication_body.rx_pdu_list = NULL;
+  free(UL_INFO);
+  UL_INFO = NULL;
+
+  // thread finished
+  free(arg);
+  return NULL;
+}
 
 /*!
  * \brief This is the UE thread for RX subframe n and TX subframe n+4.
@@ -967,6 +1365,7 @@ void ue_stub_rx_handler(unsigned int num_bytes,
 
 static void *UE_phy_stub_single_thread_rxn_txnp4(void *arg)
 {
+#if 0 // TODO: doesn't currently compile, obviated by multi-ue proxy
   thread_top_init("UE_phy_stub_thread_rxn_txnp4",1,870000L,1000000L,1000000L);
   // for multipule UE's L2-emulator
   //module_id_t Mod_id = 0;
@@ -1012,7 +1411,7 @@ static void *UE_phy_stub_single_thread_rxn_txnp4(void *arg)
     dl_config_req = NULL;
     ul_config_req = NULL;
     hi_dci0_req        = NULL;
-    tx_request_pdu_list = NULL;
+    tx_req_pdu_list = NULL;
 
     // waiting for all UE's threads set phy_stub_ticking->num_single_thread[ue_thread_id] = -1.
     do {
@@ -1108,7 +1507,7 @@ static void *UE_phy_stub_single_thread_rxn_txnp4(void *arg)
       }
     }
 
-    if (dl_config_req && tx_request_pdu_list) {
+    if (dl_config_req && tx_req_pdu_list) {
       nfapi_dl_config_request_body_t* dl_config_req_body = &dl_config_req->dl_config_request_body;
       for (int i = 0; i < dl_config_req_body->number_pdu; ++i) {
         nfapi_dl_config_request_pdu_t* pdu = &dl_config_req_body->dl_config_pdu_list[i];
@@ -1322,16 +1721,16 @@ static void *UE_phy_stub_single_thread_rxn_txnp4(void *arg)
         dl_config_req = NULL;
       }
 
-      if(tx_request_pdu_list!=NULL) {
+      if(tx_req_pdu_list!=NULL) {
         for (int i = 0; i < tx_req_num_elems; i++) {
-          for (int j = 0; j < tx_request_pdu_list[i].num_segments; j++) {
-            free(tx_request_pdu_list[i].segments[j].segment_data);
-            tx_request_pdu_list[i].segments[j].segment_data = NULL;
+          for (int j = 0; j < tx_req_pdu_list[i].num_segments; j++) {
+            free(tx_req_pdu_list[i].segments[j].segment_data);
+            tx_req_pdu_list[i].segments[j].segment_data = NULL;
           }
         }
         tx_req_num_elems = 0;
-        free(tx_request_pdu_list);
-        tx_request_pdu_list = NULL;
+        free(tx_req_pdu_list);
+        tx_req_pdu_list = NULL;
       }
 
       if(ul_config_req!=NULL) {
@@ -1371,10 +1770,11 @@ static void *UE_phy_stub_single_thread_rxn_txnp4(void *arg)
   UL_INFO->rx_ind.rx_indication_body.rx_pdu_list = NULL;
   free(UL_INFO);
   UL_INFO = NULL;
+#endif // disabled UE_phy_stub_single_thread_rxn_txnp4
 
   // thread finished
   free(arg);
-  return &UE_thread_rxtx_retval;
+  return NULL;
 }
 
 
@@ -1388,6 +1788,7 @@ static void *UE_phy_stub_single_thread_rxn_txnp4(void *arg)
 
 static void *UE_phy_stub_thread_rxn_txnp4(void *arg)
 {
+  #if 0
   thread_top_init("UE_phy_stub_thread_rxn_txnp4",1,870000L,1000000L,1000000L);
   module_id_t Mod_id = 0;
   static __thread int UE_thread_rxtx_retval;
@@ -1536,10 +1937,10 @@ static void *UE_phy_stub_thread_rxn_txnp4(void *arg)
 
     phy_procedures_UE_SL_RX(UE,proc);
   }
-
+  #endif // disabled
   // thread finished
   free(arg);
-  return &UE_thread_rxtx_retval;
+  return NULL; //return &UE_thread_rxtx_retval;
 }
 
 
@@ -1607,6 +2008,8 @@ void *UE_thread(void *arg)
     oai_exit=1;
   }
 
+  log_scheduler(__func__);
+
   while (!oai_exit) {
     if (IS_SOFTMODEM_BASICSIM)
       while (!(UE->proc.instance_cnt_synch < 0)) {
@@ -1973,7 +2376,7 @@ void init_UE_single_thread_stub(int nb_inst)
     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==NFAPI_UE_STUB_PNF) {
+    if(NFAPI_MODE==NFAPI_UE_STUB_PNF || NFAPI_MODE==NFAPI_MODE_STANDALONE_PNF) {
 #ifdef NAS_UE
       MessageDef *message_p;
       message_p = itti_alloc_new_message(TASK_NAS_UE, 0, INITIALIZE_MESSAGE);
@@ -1993,6 +2396,13 @@ void init_UE_single_thread_stub(int nb_inst)
   //int nb_threads=RX_NB_TH;
   int nb_threads=1;
 
+  void* (*task_func)(void*);
+  if (NFAPI_MODE == NFAPI_MODE_STANDALONE_PNF) {
+    task_func = UE_phy_stub_standalone_pnf_task;
+  } else {
+    task_func = UE_phy_stub_single_thread_rxn_txnp4;
+  }
+
   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];
 
@@ -2009,7 +2419,8 @@ void init_UE_single_thread_stub(int nb_inst)
       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);
+      pthread_create(&UE->proc.proc_rxtx[i].pthread_rxtx, NULL, task_func, rtd);
+      pthread_setname_np(UE->proc.proc_rxtx[i].pthread_rxtx, "oai:ue-phy");
     }
   }
 
@@ -2239,7 +2650,7 @@ static void *timer_thread( void *param )
       pdu.header.packet_type = TTI_SYNC;
       pdu.header.absSF = (timer_frame*10)+timer_subframe;
 
-      if (NFAPI_MODE != NFAPI_UE_STUB_PNF) {
+      if (NFAPI_MODE != NFAPI_UE_STUB_PNF && NFAPI_MODE != NFAPI_MODE_STANDALONE_PNF) {
         multicast_link_write_sock(0,
                                   (char *)&pdu,
                                   sizeof(UE_tport_header_t));
diff --git a/targets/RT/USER/lte-uesoftmodem.c b/targets/RT/USER/lte-uesoftmodem.c
index da9b0fdfbacecaedef66ffbed1c99e6c54fc4275..dcbecc85acb42b4b5b7d0788c7b10c454dc1d00f 100644
--- a/targets/RT/USER/lte-uesoftmodem.c
+++ b/targets/RT/USER/lte-uesoftmodem.c
@@ -66,6 +66,7 @@
 #include "LAYER2/MAC/mac_proto.h"
 #include "RRC/LTE/rrc_vars.h"
 #include "PHY_INTERFACE/phy_interface_vars.h"
+#include "PHY_INTERFACE/phy_stub_UE.h"
 #include "PHY/TOOLS/phy_scope_interface.h"
 #include "common/utils/LOG/log.h"
 #include "nfapi/oai_integration/vendor_ext.h"
@@ -78,12 +79,10 @@
 #include "create_tasks.h"
 #include "system.h"
 
-
 #include "lte-softmodem.h"
-
+#include "executables/softmodem-common.h"
 
 /* temporary compilation wokaround (UE/eNB split */
-uint16_t sf_ahead;
 
 
 pthread_cond_t nfapi_sync_cond;
@@ -91,7 +90,7 @@ pthread_mutex_t nfapi_sync_mutex;
 int nfapi_sync_var=-1; //!< protected by mutex \ref nfapi_sync_mutex
 
 
-uint16_t sf_ahead=2;
+uint16_t sf_ahead=4;
 int tddflag;
 char *emul_iface;
 
@@ -188,9 +187,10 @@ int oaisim_flag=0;
  */
 uint8_t abstraction_flag=0;
 
+bler_struct bler_data[NUM_MCS];
 // needed for pdcp.c
 RAN_CONTEXT_t RC;
-
+instance_t CUuniqInstance=0;
 /* forward declarations */
 void set_default_frame_parms(LTE_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs]);
 
@@ -276,7 +276,7 @@ void exit_function(const char *file, const char *function, const int line, const
 }
 
 extern int16_t dlsch_demod_shift;
-
+uint16_t node_number;
 static void get_options(void) {
   int CC_id=0;
   int tddflag=0;
@@ -520,7 +520,7 @@ int restart_L1L2(module_id_t enb_id) {
   return 0;
 }
 
-void init_pdcp(void) {
+static void init_pdcp(int ue_id) {
   uint32_t pdcp_initmask = (!IS_SOFTMODEM_NOS1) ? LINK_ENB_PDCP_TO_GTPV1U_BIT : (LINK_ENB_PDCP_TO_GTPV1U_BIT | PDCP_USE_NETLINK_BIT | LINK_ENB_PDCP_TO_IP_DRIVER_BIT);
 
   if (IS_SOFTMODEM_BASICSIM || IS_SOFTMODEM_RFSIM || (nfapi_getmode()==NFAPI_UE_STUB_PNF)) {
@@ -530,7 +530,7 @@ void init_pdcp(void) {
   if (IS_SOFTMODEM_NOKRNMOD)
     pdcp_initmask = pdcp_initmask | UE_NAS_USE_TUN_BIT;
 
-  pdcp_module_init(pdcp_initmask);
+  pdcp_module_init(pdcp_initmask, ue_id);
   pdcp_set_rlc_data_req_func((send_rlc_data_req_func_t) rlc_data_req);
   pdcp_set_pdcp_data_ind_func((pdcp_data_ind_func_t) pdcp_data_ind);
 }
@@ -542,6 +542,13 @@ AssertFatal(false,"");
 }
 
 int main( int argc, char **argv ) {
+  set_priority(79);
+  if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1)
+  {
+    fprintf(stderr, "mlockall: %s\n", strerror(errno));
+    return EXIT_FAILURE;
+  }
+
   int CC_id;
   uint8_t  abstraction_flag=0;
   // Default value for the number of UEs. It will hold,
@@ -566,6 +573,11 @@ int main( int argc, char **argv ) {
 
   get_options ();
 
+  if (NFAPI_MODE == NFAPI_MODE_STANDALONE_PNF) {
+    sf_ahead = 1;
+  }
+  printf("sf_ahead = %d\n", sf_ahead);
+
   EPC_MODE_ENABLED = !IS_SOFTMODEM_NOS1;
   printf("Running with %d UE instances\n",NB_UE_INST);
 
@@ -600,7 +612,16 @@ int main( int argc, char **argv ) {
 
   MSC_INIT(MSC_E_UTRAN, ADDED_QUEUES_MAX+TASK_MAX);
   init_opt();
-  init_pdcp();
+  ue_id_g = (node_number == 0) ? 0 : node_number-2; //ue_id_g = 0, 1, ...,
+  if(node_number == 0)
+  {
+    init_pdcp(0);
+  }
+  else
+  {
+    init_pdcp(node_number-1);
+  }
+
   //TTN for D2D
   printf ("RRC control socket\n");
   rrc_control_socket_init();
@@ -623,7 +644,7 @@ int main( int argc, char **argv ) {
 
   NB_INST=1;
 
-  if(NFAPI_MODE==NFAPI_UE_STUB_PNF) {
+  if(NFAPI_MODE==NFAPI_UE_STUB_PNF || NFAPI_MODE==NFAPI_MODE_STANDALONE_PNF) {
     PHY_vars_UE_g = malloc(sizeof(PHY_VARS_UE **)*NB_UE_INST);
 
     for (int i=0; i<NB_UE_INST; i++) {
@@ -641,10 +662,10 @@ int main( int argc, char **argv ) {
 
 
   cpuf=get_cpu_freq_GHz();
-  
-  
+
+
 #if 0 // #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;
@@ -656,7 +677,7 @@ int main( int argc, char **argv ) {
   if (get_nprocs() > 2) {
     for (j = 2; j < get_nprocs(); j++)
       CPU_SET(j, &cpuset);
-    
+
     s = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
 
     if (s != 0) {
@@ -693,7 +714,7 @@ int main( int argc, char **argv ) {
     exit(-1); // need a softer mode
   }
 
-  if (NFAPI_MODE==NFAPI_UE_STUB_PNF) { // UE-STUB-PNF
+  if (NFAPI_MODE==NFAPI_UE_STUB_PNF || NFAPI_MODE==NFAPI_MODE_STANDALONE_PNF) { // UE-STUB-PNF
     UE_config_stub_pnf();
   }
 
@@ -708,6 +729,21 @@ int main( int argc, char **argv ) {
     //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 if (NFAPI_MODE==NFAPI_MODE_STANDALONE_PNF) {
+    init_queue(&dl_config_req_tx_req_queue);
+    init_queue(&hi_dci0_req_queue);
+    init_queue(&ul_config_req_queue);
+
+    init_bler_table();
+
+    config_sync_var=0;
+    if (sem_init(&sfn_semaphore, 0, 0) != 0)
+    {
+      LOG_E(MAC, "sem_init() error\n");
+      abort();
+    }
+    init_UE_stub_single_thread(NB_UE_INST,eMBMS_active,uecap_xer_in,emul_iface);
+    init_UE_standalone_thread(ue_id_g);
   } 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]);
@@ -780,8 +816,73 @@ int main( int argc, char **argv ) {
   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);
 
+  pdcp_module_cleanup();
   terminate_opt();
   logClean();
   printf("Bye.\n");
   return 0;
 }
+
+
+// Read in each MCS file and build BLER-SINR-TB table
+void init_bler_table(void)
+{
+  size_t bufSize = 1024;
+  char * line = NULL;
+  char * token;
+  char * temp = NULL;
+  const char *openair_dir = getenv("OPENAIR_DIR");
+  if (!openair_dir)
+  {
+    LOG_E(MAC, "No $OPENAIR_DIR\n");
+    abort();
+  }
+
+  // Maybe not needed... and may not work.
+  memset(bler_data, 0, sizeof(bler_data));
+
+  for (unsigned int i = 0; i < NUM_MCS; i++)
+  {
+    char fName[1024];
+    snprintf(fName, sizeof(fName), "%s/openair1/SIMULATION/LTE_PHY/BLER_SIMULATIONS/AWGN/AWGN_results/bler_tx1_chan18_nrx1_mcs%d.csv", openair_dir, i);
+    FILE *pFile = fopen(fName, "r");
+    if (!pFile)
+    {
+      LOG_E(MAC, "Bler File ERROR! - fopen(), file: %s\n", fName);
+      abort();
+    }
+    int nlines = 0;
+    while (getline(&line, &bufSize, pFile) > 0)
+    {
+      if (!strncmp(line,"SNR",3))
+      {
+        continue;
+      }
+
+      if (nlines > NUM_SINR)
+      {
+        LOG_E(MAC, "BLER FILE ERROR - num lines greater than expected - file: %s\n", fName);
+        abort();
+      }
+
+      token = strtok_r(line, ";", &temp);
+      int ncols = 0;
+      while (token != NULL)
+      {
+        if (ncols > NUM_BLER_COL)
+        {
+          LOG_E(MAC, "BLER FILE ERROR - num of cols greater than expected\n");
+          abort();
+        }
+
+        bler_data[i].bler_table[nlines][ncols] = strtof(token, NULL);
+        ncols++;
+
+        token = strtok_r(NULL, ";", &temp);
+      }
+      nlines++;
+    }
+    bler_data[i].length = nlines;
+    fclose(pFile);
+  }
+}