diff --git a/ci-scripts/cls_cluster.py b/ci-scripts/cls_cluster.py
index a98dbf390d2608980d60fc0a9df8a0e2bf3812a2..7293e252a16f3d2c60e54114ba1410e595c8afd5 100644
--- a/ci-scripts/cls_cluster.py
+++ b/ci-scripts/cls_cluster.py
@@ -315,9 +315,9 @@ class Cluster:
 
 		# delete old images by Sagar Arora <sagar.arora@openairinterface.org>:
 		# 1. retrieve all images and their timestamp
-		# 2. awk retrieves those whose timestamp is older than 4 weeks
+		# 2. awk retrieves those whose timestamp is older than 3 weeks
 		# 3. issue delete command on corresponding istags (the images are dangling and will be cleaned by the registry)
-		delete_cmd = "oc get istag -o go-template --template '{{range .items}}{{.metadata.name}} {{.metadata.creationTimestamp}}{{\"\\n\"}}{{end}}' | awk '$2 <= \"'$(date -d '-4weeks' -Ins --utc | sed 's/+0000/Z/')'\" { print $1 }' | xargs --no-run-if-empty oc delete istag"
+		delete_cmd = "oc get istag -o go-template --template '{{range .items}}{{.metadata.name}} {{.metadata.creationTimestamp}}{{\"\\n\"}}{{end}}' | awk '$2 <= \"'$(date -d '-3weeks' -Ins --utc | sed 's/+0000/Z/')'\" { print $1 }' | xargs --no-run-if-empty oc delete istag"
 		response = self.cmd.run(delete_cmd)
 		logging.debug(f"deleted images:\n{response.stdout}")
 
diff --git a/ci-scripts/datalog_rt_stats.100.2x2.yaml b/ci-scripts/datalog_rt_stats.100.2x2.yaml
index c54fb130180d41ed7fe2a55f5822850d7c7731ad..7b5c8cbbeb97b9c8b57ecb2d218196e2864ccebc 100644
--- a/ci-scripts/datalog_rt_stats.100.2x2.yaml
+++ b/ci-scripts/datalog_rt_stats.100.2x2.yaml
@@ -9,14 +9,14 @@ ColNames :
 Ref : 
   feprx : 150.0
   feptx_prec : 0.0
-  feptx_ofdm : 65.0
-  feptx_total : 177.0
-  L1 Tx processing : 700.0
-  DLSCH encoding : 226.0
-  L1 Rx processing : 640.0
-  PUSCH inner-receiver : 400.0
+  feptx_ofdm : 60.0
+  feptx_total : 150.0
+  L1 Tx processing : 530.0
+  DLSCH encoding : 220.0
+  L1 Rx processing : 530.0
+  PUSCH inner-receiver : 360.0
   Schedule Response : 3.0
-  DL & UL scheduling timing : 15.0
+  DL & UL scheduling timing : 17.0
   UL Indication : 3.0
   Slot Indication : 17.0
 DeviationThreshold :
diff --git a/ci-scripts/datalog_rt_stats.1x1.60.yaml b/ci-scripts/datalog_rt_stats.1x1.60.yaml
index f2cd345737d6c35551b7c628be39f36893284607..acd8251525c28e585eb40488a1c94c7bd68096da 100644
--- a/ci-scripts/datalog_rt_stats.1x1.60.yaml
+++ b/ci-scripts/datalog_rt_stats.1x1.60.yaml
@@ -7,16 +7,16 @@ ColNames :
   - Average; Max; Count
   - Average vs Reference Deviation (Reference Value; Acceptability Deviation Threshold)
 Ref :
-  feprx : 46.0
+  feprx : 40.0
   feptx_prec : 15.0
-  feptx_ofdm : 35.0
-  feptx_total : 50.0
-  L1 Tx processing : 260.0
-  DLSCH encoding : 160.0
-  L1 Rx processing : 420.0
-  PUSCH inner-receiver : 170.0
+  feptx_ofdm : 30.0
+  feptx_total : 45.0
+  L1 Tx processing : 205.0
+  DLSCH encoding : 140.0
+  L1 Rx processing : 345.0
+  PUSCH inner-receiver : 150.0
   Schedule Response : 3.0
-  DL & UL scheduling timing : 8.0
+  DL & UL scheduling timing : 7.0
   UL Indication : 3.0
   Slot Indication : 8.0
 DeviationThreshold :
diff --git a/ci-scripts/datalog_rt_stats.60.2x2.yaml b/ci-scripts/datalog_rt_stats.60.2x2.yaml
index 66ab367e7ca8b916b64845a79cc2228a64ea6772..a196695c4b45d1dcbf1b73df371421775358c60a 100644
--- a/ci-scripts/datalog_rt_stats.60.2x2.yaml
+++ b/ci-scripts/datalog_rt_stats.60.2x2.yaml
@@ -7,18 +7,18 @@ ColNames :
   - Average; Max; Count
   - Average vs Reference Deviation (Reference Value; Acceptability Deviation Threshold)
 Ref : 
-  feprx : 84.0
+  feprx : 75.0
   feptx_prec : 14.0
-  feptx_ofdm : 35.0
-  feptx_total : 100.0
-  L1 Tx processing : 400.0
-  DLSCH encoding : 177.0
+  feptx_ofdm : 30.0
+  feptx_total : 80.0
+  L1 Tx processing : 315.0
+  DLSCH encoding : 155.0
   L1 Rx processing : 345.0
-  PUSCH inner-receiver : 200.0
+  PUSCH inner-receiver : 155.0
   Schedule Response : 3.0
   DL & UL scheduling timing : 13.0
   UL Indication : 3.0
-  Slot Indication : 15.0
+  Slot Indication : 12.0
 DeviationThreshold :
   feprx : 0.25
   feptx_prec : 0.25
diff --git a/ci-scripts/datalog_rt_stats.default.yaml b/ci-scripts/datalog_rt_stats.default.yaml
index 1b83aed7837053c7d6de80c2fc858ce6e1ec54be..045768829c2e356c8050bcd65410d9c762dc709e 100644
--- a/ci-scripts/datalog_rt_stats.default.yaml
+++ b/ci-scripts/datalog_rt_stats.default.yaml
@@ -7,17 +7,17 @@ ColNames :
   - Average; Max; Count
   - Average vs Reference Deviation (Reference Value; Acceptability Deviation Threshold)
 Ref : 
-  feprx : 43.0
+  feprx : 40.0
   feptx_prec : 13.0
-  feptx_ofdm : 33.0
-  feptx_total : 50.0
-  L1 Tx processing : 200.0
+  feptx_ofdm : 30.0
+  feptx_total : 45.0
+  L1 Tx processing : 160.0
   DLSCH encoding : 100.0
-  L1 Rx processing : 330.0
-  PUSCH inner-receiver : 120.0
+  L1 Rx processing : 290.0
+  PUSCH inner-receiver : 115.0
   Schedule Response : 3.0
   DL & UL scheduling timing : 6.0
-  UL Indication : 3.0
+  UL Indication : 2.0
   Slot Indication : 7.0
 DeviationThreshold :
   feprx : 0.25
diff --git a/ci-scripts/xml_files/ldpc_gpu_test.xml b/ci-scripts/xml_files/ldpc_gpu_test.xml
index f129d6bd2b7e5921e95a087712501abc88e8e094..bee9035c8b2cd7f172ac8aa7288f8b0da8649488 100644
--- a/ci-scripts/xml_files/ldpc_gpu_test.xml
+++ b/ci-scripts/xml_files/ldpc_gpu_test.xml
@@ -25,7 +25,10 @@
 	<htmlTabRef>test-ldpc-gpu</htmlTabRef>
 	<htmlTabName>Test-ldpc-GPU</htmlTabName>
 	<htmlTabIcon>tasks</htmlTabIcon>
-	<TestCaseRequestedList>000002 000003 000004 000005 000006 000007 000008 000009 000010 000011 000012 000013 000014 000015 000016 000017 000018 000019 000020 000021</TestCaseRequestedList>
+	<TestCaseRequestedList>
+		000002 000003 000004 000005 000006 000007 000008 000009 000010 000011 000012 000013 000014 000015 000016 000017 000018 000019 000020 000021
+		000022 000023 000024 000025 000026 000027 000028 000029 000030 000031 000032 000033 000034 000035 000036 000037 000038 000039 000040 000041
+	</TestCaseRequestedList>
 	<TestCaseExclusionList></TestCaseExclusionList>
 
 	<testCase id="000002">
@@ -188,6 +191,166 @@
 		<physim_run_args>-l 8448 -s10 -n100 -G 1</physim_run_args>
 	</testCase>
 
+	<testCase id="000022">
+		<class>Run_Physim</class>
+		<desc>Run LDPC Test with CPU</desc>
+		<always_exec>true</always_exec>
+		<physim_test>ldpctest</physim_test>
+		<physim_run_args>-l 1 -s10 -n100</physim_run_args>
+	</testCase>
+
+	<testCase id="000023">
+		<class>Run_Physim</class>
+		<desc>Run LDPC Test with GPU</desc>
+		<always_exec>true</always_exec>
+		<physim_test>ldpctest</physim_test>
+		<physim_run_args>-l 1 -s10 -n100 -G 1</physim_run_args>
+	</testCase>
+
+	<testCase id="000024">
+		<class>Run_Physim</class>
+		<desc>Run LDPC Test with CPU</desc>
+		<always_exec>true</always_exec>
+		<physim_test>ldpctest</physim_test>
+		<physim_run_args>-l 100 -s10 -n100</physim_run_args>
+	</testCase>
+
+	<testCase id="000025">
+		<class>Run_Physim</class>
+		<desc>Run LDPC Test with GPU</desc>
+		<always_exec>true</always_exec>
+		<physim_test>ldpctest</physim_test>
+		<physim_run_args>-l 100 -s10 -n100 -G 1</physim_run_args>
+	</testCase>
+
+	<testCase id="000026">
+		<class>Run_Physim</class>
+		<desc>Run LDPC Test with CPU</desc>
+		<always_exec>true</always_exec>
+		<physim_test>ldpctest</physim_test>
+		<physim_run_args>-l 193 -s10 -n100</physim_run_args>
+	</testCase>
+
+	<testCase id="000027">
+		<class>Run_Physim</class>
+		<desc>Run LDPC Test with GPU</desc>
+		<always_exec>true</always_exec>
+		<physim_test>ldpctest</physim_test>
+		<physim_run_args>-l 193 -s10 -n100 -G 1</physim_run_args>
+	</testCase>
+
+	<testCase id="000028">
+		<class>Run_Physim</class>
+		<desc>Run LDPC Test with CPU</desc>
+		<always_exec>true</always_exec>
+		<physim_test>ldpctest</physim_test>
+		<physim_run_args>-l 500 -s10 -n100</physim_run_args>
+	</testCase>
+
+	<testCase id="000029">
+		<class>Run_Physim</class>
+		<desc>Run LDPC Test with GPU</desc>
+		<always_exec>true</always_exec>
+		<physim_test>ldpctest</physim_test>
+		<physim_run_args>-l 500 -s10 -n100 -G 1</physim_run_args>
+	</testCase>
+
+	<testCase id="000030">
+		<class>Run_Physim</class>
+		<desc>Run LDPC Test with CPU</desc>
+		<always_exec>true</always_exec>
+		<physim_test>ldpctest</physim_test>
+		<physim_run_args>-l 561 -s10 -n100</physim_run_args>
+	</testCase>
+
+	<testCase id="000031">
+		<class>Run_Physim</class>
+		<desc>Run LDPC Test with GPU</desc>
+		<always_exec>true</always_exec>
+		<physim_test>ldpctest</physim_test>
+		<physim_run_args>-l 561 -s10 -n100 -G 1</physim_run_args>
+	</testCase>
+
+	<testCase id="000032">
+		<class>Run_Physim</class>
+		<desc>Run LDPC Test with CPU</desc>
+		<always_exec>true</always_exec>
+		<physim_test>ldpctest</physim_test>
+		<physim_run_args>-l 600 -s10 -n100</physim_run_args>
+	</testCase>
+
+	<testCase id="000033">
+		<class>Run_Physim</class>
+		<desc>Run LDPC Test with GPU</desc>
+		<always_exec>true</always_exec>
+		<physim_test>ldpctest</physim_test>
+		<physim_run_args>-l 600 -s10 -n100 -G 1</physim_run_args>
+	</testCase>
+
+	<testCase id="000034">
+		<class>Run_Physim</class>
+		<desc>Run LDPC Test with CPU</desc>
+		<always_exec>true</always_exec>
+		<physim_test>ldpctest</physim_test>
+		<physim_run_args>-l 641 -s10 -n100</physim_run_args>
+	</testCase>
+
+	<testCase id="000035">
+		<class>Run_Physim</class>
+		<desc>Run LDPC Test with GPU</desc>
+		<always_exec>true</always_exec>
+		<physim_test>ldpctest</physim_test>
+		<physim_run_args>-l 641 -s10 -n100 -G 1</physim_run_args>
+	</testCase>
+
+	<testCase id="000036">
+		<class>Run_Physim</class>
+		<desc>Run LDPC Test with CPU</desc>
+		<always_exec>true</always_exec>
+		<physim_test>ldpctest</physim_test>
+		<physim_run_args>-l 2000 -s10 -n100</physim_run_args>
+	</testCase>
+
+	<testCase id="000037">
+		<class>Run_Physim</class>
+		<desc>Run LDPC Test with GPU</desc>
+		<always_exec>true</always_exec>
+		<physim_test>ldpctest</physim_test>
+		<physim_run_args>-l 2000 -s10 -n100 -G 1</physim_run_args>
+	</testCase>
+
+	<testCase id="000038">
+		<class>Run_Physim</class>
+		<desc>Run LDPC Test with CPU</desc>
+		<always_exec>true</always_exec>
+		<physim_test>ldpctest</physim_test>
+		<physim_run_args>-l 3000 -s10 -n100</physim_run_args>
+	</testCase>
+
+	<testCase id="000039">
+		<class>Run_Physim</class>
+		<desc>Run LDPC Test with GPU</desc>
+		<always_exec>true</always_exec>
+		<physim_test>ldpctest</physim_test>
+		<physim_run_args>-l 3000 -s10 -n100 -G 1</physim_run_args>
+	</testCase>
+
+	<testCase id="000040">
+		<class>Run_Physim</class>
+		<desc>Run LDPC Test with CPU</desc>
+		<always_exec>true</always_exec>
+		<physim_test>ldpctest</physim_test>
+		<physim_run_args>-l 3840 -s10 -n100</physim_run_args>
+	</testCase>
+
+	<testCase id="000041">
+		<class>Run_Physim</class>
+		<desc>Run LDPC Test with GPU</desc>
+		<always_exec>true</always_exec>
+		<physim_test>ldpctest</physim_test>
+		<physim_run_args>-l 3840 -s10 -n100 -G 1</physim_run_args>
+	</testCase>
+
 
 
 </testCaseList>
diff --git a/cmake_targets/autotests/test_case_list.xml b/cmake_targets/autotests/test_case_list.xml
index 80f18e98a7a000965756cae3c7f43ba98ed83b4c..6d9d64bce2eba70814a44d730d0c5c749cb7af7a 100755
--- a/cmake_targets/autotests/test_case_list.xml
+++ b/cmake_targets/autotests/test_case_list.xml
@@ -66,16 +66,26 @@
     </testCase>
 
     <testCase id="ldpctest">
-      <desc>ldpc Test cases. (Test1: block length = 3872),
-             (Test2: block length = 4224),
-             (Test3: block length = 4576),
-             (Test4: block length = 4928),
-             (Test5: block length = 5280),
-             (Test6: block length = 5632),
-             (Test7: block length = 6336),
-             (Test8: block length = 7040),
-             (Test9: block length = 7744),
-             (Test10: block length = 8448)</desc>
+      <desc>ldpc Test cases. (Test1: block length = 3872, BG1),
+             (Test2: block length = 4224, BG1),
+             (Test3: block length = 4576, BG1),
+             (Test4: block length = 4928, BG1),
+             (Test5: block length = 5280, BG1),
+             (Test6: block length = 5632, BG1),
+             (Test7: block length = 6336, BG1),
+             (Test8: block length = 7040, BG1),
+             (Test9: block length = 7744, BG1),
+             (Test10: block length = 8448, BG1),
+             (Test11: block length = 1, BG2),
+             (Test12: block length = 100, BG2),
+             (Test13: block length = 193, BG2),
+             (Test14: block length = 500, BG2),
+             (Test15: block length = 561, BG2),
+             (Test16: block length = 600, BG2),
+             (Test17: block length = 641, BG2),
+             (Test18: block length = 2000, BG2),
+             (Test19: block length = 3000, BG2),
+             (Test20: block length = 3840, BG2)</desc>
       <main_exec>ldpctest</main_exec>
       <main_exec_args>-l3872 -s10 -n100
                       -l4224 -s10 -n100
@@ -87,9 +97,17 @@
                       -l7040 -s10 -n100
                       -l7744 -s10 -n100
                       -l8448 -s10 -n100
-                      -l561 -s10 -n1
-                      -l500 -s10 -n1</main_exec_args>
-      <tags>test1 test2 test3 test4 test5 test6 test7 test8 test9 test10</tags>
+                      -l1 -s10 -n100
+                      -l100 -s10 -n100
+                      -l193 -s10 -n100
+                      -l500 -s10 -n100
+                      -l561 -s10 -n100
+                      -l600 -s10 -n100
+                      -l641 -s10 -n100
+                      -l2000 -s10 -n100
+                      -l3000 -s10 -n100
+                      -l3840 -s10 -n100</main_exec_args>
+      <tags>test1 test2 test3 test4 test5 test6 test7 test8 test9 test10 test11 test12 test13 test14 test15 test16 test17 test18 test19 test20</tags>
       <search_expr_true>BLER 0.000000</search_expr_true>
       <search_expr_false>segmentation fault|assertion|exiting|fatal|differ</search_expr_false>
       <nruns>3</nruns>
diff --git a/cmake_targets/tools/build_helper b/cmake_targets/tools/build_helper
index 5fee5ac48d3c57bb384131d08f8853718f10e059..3fc1db7b56f597bde23b9c38a04d2e4b32a27b6e 100755
--- a/cmake_targets/tools/build_helper
+++ b/cmake_targets/tools/build_helper
@@ -674,8 +674,8 @@ install_simde_from_source(){
     if [[ -v SIMDE_VERSION ]]; then
       git checkout -f $SIMDE_VERSION
     else
-      # At time of writing, last working commit for OAI: 1a09d3bc
-      git checkout 1a09d3bc9de47c4d9a5daa23eb753d5322748201
+      # At time of writing, last working commit for OAI: c7f26b7
+      git checkout c7f26b73ba8e874b95c2cec2b497826ad2188f68
     fi
     # Showing which version is used
     git log -n1
diff --git a/openair1/PHY/CODING/TESTBENCH/ldpctest.c b/openair1/PHY/CODING/TESTBENCH/ldpctest.c
index 0fa81f360bb01dbc30f7b9cbfe25979a6ac85287..5912c9d0b489e85cf268f75e9afdd1edc0318d34 100644
--- a/openair1/PHY/CODING/TESTBENCH/ldpctest.c
+++ b/openair1/PHY/CODING/TESTBENCH/ldpctest.c
@@ -29,7 +29,7 @@
 #include "common/config/config_userapi.h"
 #include "common/utils/load_module_shlib.h"
 #include "PHY/CODING/nrLDPC_extern.h"
-//#include "openair1/SIMULATION/NR_PHY/nr_unitary_defs.h"
+// #include "openair1/SIMULATION/NR_PHY/nr_unitary_defs.h"
 #include "openair1/PHY/CODING/nrLDPC_decoder_LYC/nrLDPC_decoder_LYC.h"
 #include "openair1/PHY/defs_nr_common.h"
 #include "coding_unitary_defs.h"
@@ -38,7 +38,7 @@
 #define MAX_BLOCK_LENGTH 8448
 
 #ifndef malloc16
-#    define malloc16(x) memalign(32,x)
+#define malloc16(x) memalign(32, x)
 #endif
 
 #define NR_LDPC_PROFILER_DETAIL
@@ -46,10 +46,10 @@
 ldpc_interface_t ldpc_orig, ldpc_toCompare;
 
 // 4-bit quantizer
-int8_t quantize4bit(double D,double x)
+int8_t quantize4bit(double D, double x)
 {
   double qxd;
-  qxd = floor(x/D);
+  qxd = floor(x / D);
   //  printf("x=%f,qxd=%f\n",x,qxd);
 
   if (qxd <= -8)
@@ -57,25 +57,25 @@ int8_t quantize4bit(double D,double x)
   else if (qxd > 7)
     qxd = 7;
 
-  return((int8_t)qxd);
+  return ((int8_t)qxd);
 }
 
-int8_t quantize8bit(double D,double x)
+int8_t quantize8bit(double D, double x)
 {
   double qxd;
-  //int8_t maxlev;
-  qxd = floor(x/D);
+  // int8_t maxlev;
+  qxd = floor(x / D);
 
-  //maxlev = 1<<(B-1);
+  // maxlev = 1<<(B-1);
 
-  //printf("x=%f,qxd=%f,maxlev=%d\n",x,qxd, maxlev);
+  // printf("x=%f,qxd=%f,maxlev=%d\n",x,qxd, maxlev);
 
   if (qxd <= -128)
     qxd = -128;
   else if (qxd >= 128)
     qxd = 127;
 
-  return((int8_t)qxd);
+  return ((int8_t)qxd);
 }
 
 typedef struct {
@@ -102,61 +102,50 @@ one_measurement_t test_ldpc(short max_iterations,
                             int denom_rate,
                             double SNR,
                             unsigned char qbits,
-                            short block_length,
+                            short Kprime,
                             unsigned int ntrials,
                             int n_segments)
 {
   one_measurement_t ret = {0};
   reset_meas(&ret.time_optim);
   reset_meas(&ret.time_decoder);
-  //clock initiate
-  //time_stats_t time,time_optim,tinput,tprep,tparity,toutput, time_decoder;
-  time_stats_t time, tinput,tprep,tparity,toutput;
+  // clock initiate
+  // time_stats_t time,time_optim,tinput,tprep,tparity,toutput, time_decoder;
+  time_stats_t time, tinput, tprep, tparity, toutput;
   double n_iter_mean = 0;
   double n_iter_std = 0;
   int n_iter_max = 0;
 
   double sigma;
-  sigma = 1.0/sqrt(2*SNR);
+  sigma = 1.0 / sqrt(2 * SNR);
   cpu_meas_enabled = 1;
-  //short test_input[block_length];
   uint8_t *test_input[MAX_NUM_NR_DLSCH_SEGMENTS_PER_LAYER * NR_MAX_NB_LAYERS];
-  uint8_t estimated_output[MAX_NUM_DLSCH_SEGMENTS][block_length];
+  uint8_t estimated_output[MAX_NUM_DLSCH_SEGMENTS][Kprime];
   memset(estimated_output, 0, sizeof(estimated_output));
   uint8_t *channel_input[MAX_NUM_DLSCH_SEGMENTS];
   uint8_t *channel_input_optim[MAX_NUM_DLSCH_SEGMENTS];
-  //double channel_output[68 * 384];
-  double modulated_input[MAX_NUM_DLSCH_SEGMENTS][68 * 384] = { 0 };
-  int8_t channel_output_fixed[MAX_NUM_DLSCH_SEGMENTS][68  * 384] = { 0 };
-  short BG=0,nrows=0;//,ncols;
+  // double channel_output[68 * 384];
+  double modulated_input[MAX_NUM_DLSCH_SEGMENTS][68 * 384] = {0};
+  int8_t channel_output_fixed[MAX_NUM_DLSCH_SEGMENTS][68 * 384] = {0};
+  short BG = 0, nrows = 0; //,ncols;
   int i1, Kb = 0;
   int R_ind = 0;
-  //int n_segments=1;
+  // int n_segments=1;
   int code_rate_vec[8] = {15, 13, 25, 12, 23, 34, 56, 89};
-  //double code_rate_actual_vec[8] = {0.2, 0.33333, 0.4, 0.5, 0.66667, 0.73333, 0.81481, 0.88};
+  // double code_rate_actual_vec[8] = {0.2, 0.33333, 0.4, 0.5, 0.66667, 0.73333, 0.81481, 0.88};
 
-  t_nrLDPC_dec_params decParams[MAX_NUM_DLSCH_SEGMENTS]={0};
+  t_nrLDPC_dec_params decParams[MAX_NUM_DLSCH_SEGMENTS] = {0};
 
   t_nrLDPC_time_stats decoder_profiler = {0};
 
   int32_t n_iter = 0;
 
-  // generate input block
-  for(int j=0;j<MAX_NUM_DLSCH_SEGMENTS;j++) {
-    test_input[j] = malloc16(block_length / 8);
-    memset(test_input[j], 0, block_length / 8);
-    channel_input[j] = malloc16(68 * 384);
-    memset(channel_input[j], 0, 68 * 384);
-    channel_input_optim[j] = malloc16(68 * 384);
-    memset(channel_input_optim[j], 0, 68 * 384);
-  }
-
   reset_meas(&time);
   reset_meas(&tinput);
   reset_meas(&tprep);
   reset_meas(&tparity);
   reset_meas(&toutput);
-  //Reset Decoder profiles
+  // Reset Decoder profiles
   reset_meas(&decoder_profiler.llr2llrProcBuf);
   reset_meas(&decoder_profiler.llr2CnProcBuf);
   reset_meas(&decoder_profiler.cnProc);
@@ -167,15 +156,10 @@ one_measurement_t test_ldpc(short max_iterations,
   reset_meas(&decoder_profiler.bn2cnProcBuf);
   reset_meas(&decoder_profiler.llrRes2llrOut);
   reset_meas(&decoder_profiler.llr2bit);
-  //reset_meas(&decoder_profiler.total);
-
-  // Fill a input packet with random values
-  for (int j = 0; j < MAX_NUM_DLSCH_SEGMENTS; j++)
-    for (int i = 0; i < block_length / 8; i++)
-      test_input[j][i] = (uint8_t)rand();
+  // reset_meas(&decoder_profiler.total);
 
-  //determine number of bits in codeword
-  if (block_length > 3840) {
+  // determine number of bits in codeword
+  if (Kprime > 3840) {
     BG = 1;
     Kb = 22;
     nrows = 46; // parity check bits
@@ -184,11 +168,11 @@ one_measurement_t test_ldpc(short max_iterations,
     BG = 2;
     nrows = 42; // parity check bits
     // ncols=10; // info bits
-    if (block_length > 640)
+    if (Kprime > 640)
       Kb = 10;
-    else if (block_length > 560)
+    else if (Kprime > 560)
       Kb = 9;
-    else if (block_length > 192)
+    else if (Kprime > 192)
       Kb = 8;
     else
       Kb = 6;
@@ -237,21 +221,37 @@ one_measurement_t test_ldpc(short max_iterations,
   // find minimum value in all sets of lifting size
   int Zc = 0;
   const short lift_size[51] = {2,  3,   4,   5,   6,   7,   8,   9,   10,  11,  12,  13,  14,  15,  16,  18,  20,
-                         22, 24,  26,  28,  30,  32,  36,  40,  44,  48,  52,  56,  60,  64,  72,  80,  88,
-                         96, 104, 112, 120, 128, 144, 160, 176, 192, 208, 224, 240, 256, 288, 320, 352, 384};
+                               22, 24,  26,  28,  30,  32,  36,  40,  44,  48,  52,  56,  60,  64,  72,  80,  88,
+                               96, 104, 112, 120, 128, 144, 160, 176, 192, 208, 224, 240, 256, 288, 320, 352, 384};
   for (i1 = 0; i1 < 51; i1++) {
-    if (lift_size[i1] >= (double)block_length / Kb) {
+    if (lift_size[i1] >= (double)Kprime / Kb) {
       Zc = lift_size[i1];
       break;
     }
   }
 
-  printf("ldpc_test: codeword_length %d, n_segments %d, block_length %d, BG %d, Zc %d, Kb %d\n",n_segments *block_length, n_segments, block_length, BG, Zc, Kb);
-  const int no_punctured_columns =
-      (int)((nrows - 2) * Zc + block_length - block_length * (1 / ((float)nom_rate / (float)denom_rate))) / Zc;
+  // K: Segment size = number of columns in the parity check matrix * lifting size (number of columns of the square parity check
+  // sub-matrix)
+  int K = 0;
+  if (BG == 1) {
+    K = 22 * Zc;
+  } else if (BG == 2) {
+    K = 10 * Zc;
+  } else {
+    printf("Not supported: BG: %d\n", BG);
+    exit(1);
+  }
+
+  printf("ldpc_test: codeword_length %d, n_segments %d, Kprime %d, BG %d, Zc %d, Kb %d\n",
+         n_segments * K,
+         n_segments,
+         Kprime,
+         BG,
+         Zc,
+         Kb);
+  const int no_punctured_columns = (int)((nrows - 2) * Zc + K - K * (1 / ((float)nom_rate / (float)denom_rate))) / Zc;
   //  printf("puncture:%d\n",no_punctured_columns);
-  const int removed_bit =
-      (nrows - no_punctured_columns - 2) * Zc + block_length - (int)(block_length / ((float)nom_rate / (float)denom_rate));
+  const int removed_bit = (nrows - no_punctured_columns - 2) * Zc + K - (int)(K / ((float)nom_rate / (float)denom_rate));
 
   printf("nrows: %d\n", nrows);
   printf("no_punctured_columns: %d\n", no_punctured_columns);
@@ -259,12 +259,34 @@ one_measurement_t test_ldpc(short max_iterations,
   printf("To: %d\n", (Kb + nrows - no_punctured_columns) * Zc - removed_bit);
   printf("number of undecoded bits: %d\n", (Kb + nrows - no_punctured_columns - 2) * Zc - removed_bit);
 
-  encoder_implemparams_t impp = {.Zc = Zc, .Kb = Kb, .BG = BG, .K = block_length};
+  // generate input block
+  for (int j = 0; j < MAX_NUM_DLSCH_SEGMENTS; j++) {
+    test_input[j] = malloc16(((K + 7) & ~7) / 8);
+    memset(test_input[j], 0, ((K + 7) & ~7) / 8);
+    channel_input[j] = malloc16(68 * 384);
+    memset(channel_input[j], 0, 68 * 384);
+    channel_input_optim[j] = malloc16(68 * 384);
+    memset(channel_input_optim[j], 0, 68 * 384);
+  }
+
+  // Fill input segments with random values
+  for (int j = 0; j < MAX_NUM_DLSCH_SEGMENTS; j++) {
+    int i = 0;
+    for (i = 0; i < ((Kprime + 7) & ~7) / 8; i++)
+      test_input[j][i] = (uint8_t)rand();
+    // Mask the last byte in order to keep filler bits to 0
+    if (Kprime % 8 != 0) {
+      uint8_t last_byte_mask = (1 << (Kprime % 8)) - 1;
+      test_input[j][i - 1] = test_input[j][i - 1] & last_byte_mask;
+    }
+  }
+
+  encoder_implemparams_t impp = {.Zc = Zc, .Kb = Kb, .BG = BG, .K = K};
   impp.gen_code = 2;
 
-  if (ntrials==0)
+  if (ntrials == 0)
     ldpc_orig.LDPCencoder(test_input, channel_input, &impp);
-  impp.gen_code=0;
+  impp.gen_code = 0;
   decode_abort_t dec_abort;
   init_abort(&dec_abort);
   for (int trial = 0; trial < ntrials; trial++) {
@@ -286,11 +308,12 @@ one_measurement_t test_ldpc(short max_iterations,
 
     if (ntrials == 1)
       for (int j = 0; j < n_segments; j++)
-        for (int i = 0; i < block_length + (nrows - no_punctured_columns) * Zc - removed_bit; i++)
+        for (int i = 0; i < K + (nrows - no_punctured_columns) * Zc - removed_bit; i++) {
           if (channel_input[j][i] != channel_input_optim[j][i]) {
             printf("differ in seg %d pos %d (%u,%u)\n", j, i, channel_input[j][i], channel_input_optim[j][i]);
             return ret;
           }
+        }
 
     for (int j = 0; j < n_segments; j++) {
       for (int i = 2 * Zc; i < (Kb + nrows - no_punctured_columns) * Zc - removed_bit; i++) {
@@ -314,47 +337,48 @@ one_measurement_t test_ldpc(short max_iterations,
       }
 
 #ifdef DEBUG_CODER
-        printf("\n");
-        exit(-1);
+      printf("\n");
+      exit(-1);
 #endif
 
-        decParams[j].BG = BG;
-        decParams[j].Z = Zc;
-        decParams[j].R = code_rate_vec[R_ind]; // 13;
-        decParams[j].numMaxIter = max_iterations;
-        decParams[j].outMode = nrLDPC_outMode_BIT;
-        decParams[j].Kprime = block_length;
-        ldpc_toCompare.LDPCinit();
+      decParams[j].BG = BG;
+      decParams[j].Z = Zc;
+      decParams[j].R = code_rate_vec[R_ind]; // 13;
+      decParams[j].numMaxIter = max_iterations;
+      decParams[j].outMode = nrLDPC_outMode_BIT;
+      decParams[j].Kprime = Kprime;
+      ldpc_toCompare.LDPCinit();
     }
     for (int j = 0; j < n_segments; j++) {
       start_meas(&ret.time_decoder);
       set_abort(&dec_abort, false);
 
       n_iter = ldpc_toCompare.LDPCdecoder(&decParams[j],
-					  0,
-					  0,
-					  0,
-					  (int8_t *)channel_output_fixed[j],
-					  (int8_t *)estimated_output[j],
-					  &decoder_profiler,
-					  &dec_abort);
+                                          0,
+                                          0,
+                                          0,
+                                          (int8_t *)channel_output_fixed[j],
+                                          (int8_t *)estimated_output[j],
+                                          &decoder_profiler,
+                                          &dec_abort);
       stop_meas(&ret.time_decoder);
+
       // count errors
-      if (memcmp(estimated_output[j], test_input[j], block_length / 8) != 0) {
-	segment_bler++;
+      if (memcmp(estimated_output[j], test_input[j], ((Kprime + 7) & ~7) / 8) != 0) {
+        segment_bler++;
       }
-      for (int i = 0; i < block_length; i++) {
-	unsigned char estoutputbit = (estimated_output[j][i / 8] & (1 << (i & 7))) >> (i & 7);
-	unsigned char inputbit = (test_input[j][i / 8] & (1 << (i & 7))) >> (i & 7); // Further correct for multiple segments
-	if (estoutputbit != inputbit)
-	  ret.errors_bit++;
+      for (int i = 0; i < Kprime; i++) {
+        unsigned char estoutputbit = (estimated_output[j][i / 8] & (1 << (i & 7))) >> (i & 7);
+        unsigned char inputbit = (test_input[j][i / 8] & (1 << (i & 7))) >> (i & 7); // Further correct for multiple segments
+        if (estoutputbit != inputbit)
+          ret.errors_bit++;
       }
 
       n_iter_mean += n_iter;
       n_iter_std += pow(n_iter - 1, 2);
 
       if (n_iter > n_iter_max)
-	n_iter_max = n_iter;
+        n_iter_max = n_iter;
 
     } // end segments
 
@@ -364,7 +388,7 @@ one_measurement_t test_ldpc(short max_iterations,
 
   ret.dec_iter.n_iter_mean = n_iter_mean / (double)ntrials / (double)n_segments - 1;
   ret.dec_iter.n_iter_std =
-    sqrt(n_iter_std / (double)ntrials / (double)n_segments - pow(n_iter_mean / (double)ntrials / (double)n_segments - 1, 2));
+      sqrt(n_iter_std / (double)ntrials / (double)n_segments - pow(n_iter_mean / (double)ntrials / (double)n_segments - 1, 2));
   ret.dec_iter.n_iter_max = n_iter_max - 1;
 
   ret.errors_bit_uncoded = ret.errors_bit_uncoded / (double)((Kb + nrows - no_punctured_columns - 2) * Zc - removed_bit);
@@ -375,24 +399,24 @@ one_measurement_t test_ldpc(short max_iterations,
     free(channel_input_optim[j]);
   }
 
-  print_meas(&time,"ldpc_encoder",NULL,NULL);
+  print_meas(&time, "ldpc_encoder", NULL, NULL);
   print_meas(&ret.time_optim, "ldpc_encoder_optim", NULL, NULL);
-  print_meas(&tinput,"ldpc_encoder_optim(input)",NULL,NULL);
-  print_meas(&tprep,"ldpc_encoder_optim(prep)",NULL,NULL);
-  print_meas(&tparity,"ldpc_encoder_optim(parity)",NULL,NULL);
-  print_meas(&toutput,"ldpc_encoder_optim(output)",NULL,NULL);
+  print_meas(&tinput, "ldpc_encoder_optim(input)", NULL, NULL);
+  print_meas(&tprep, "ldpc_encoder_optim(prep)", NULL, NULL);
+  print_meas(&tparity, "ldpc_encoder_optim(parity)", NULL, NULL);
+  print_meas(&toutput, "ldpc_encoder_optim(output)", NULL, NULL);
   printf("\n");
   print_meas(&ret.time_decoder, "ldpc_decoder", NULL, NULL);
-  print_meas(&decoder_profiler.llr2llrProcBuf,"llr2llrProcBuf",NULL,NULL);
-  print_meas(&decoder_profiler.llr2CnProcBuf,"llr2CnProcBuf",NULL,NULL);
-  print_meas(&decoder_profiler.cnProc,"cnProc (per iteration)",NULL,NULL);
-  print_meas(&decoder_profiler.cnProcPc,"cnProcPc (per iteration)",NULL,NULL);
-  print_meas(&decoder_profiler.bnProc,"bnProc (per iteration)",NULL,NULL);
-  print_meas(&decoder_profiler.bnProcPc,"bnProcPc(per iteration)",NULL,NULL);
-  print_meas(&decoder_profiler.cn2bnProcBuf,"cn2bnProcBuf (per iteration)",NULL,NULL);
-  print_meas(&decoder_profiler.bn2cnProcBuf,"bn2cnProcBuf (per iteration)",NULL,NULL);
-  print_meas(&decoder_profiler.llrRes2llrOut,"llrRes2llrOut",NULL,NULL);
-  print_meas(&decoder_profiler.llr2bit,"llr2bit",NULL,NULL);
+  print_meas(&decoder_profiler.llr2llrProcBuf, "llr2llrProcBuf", NULL, NULL);
+  print_meas(&decoder_profiler.llr2CnProcBuf, "llr2CnProcBuf", NULL, NULL);
+  print_meas(&decoder_profiler.cnProc, "cnProc (per iteration)", NULL, NULL);
+  print_meas(&decoder_profiler.cnProcPc, "cnProcPc (per iteration)", NULL, NULL);
+  print_meas(&decoder_profiler.bnProc, "bnProc (per iteration)", NULL, NULL);
+  print_meas(&decoder_profiler.bnProcPc, "bnProcPc(per iteration)", NULL, NULL);
+  print_meas(&decoder_profiler.cn2bnProcBuf, "cn2bnProcBuf (per iteration)", NULL, NULL);
+  print_meas(&decoder_profiler.bn2cnProcBuf, "bn2cnProcBuf (per iteration)", NULL, NULL);
+  print_meas(&decoder_profiler.llrRes2llrOut, "llrRes2llrOut", NULL, NULL);
+  print_meas(&decoder_profiler.llr2bit, "llr2bit", NULL, NULL);
   printf("\n");
 
   return ret;
@@ -401,18 +425,18 @@ one_measurement_t test_ldpc(short max_iterations,
 configmodule_interface_t *uniqCfg = NULL;
 int main(int argc, char *argv[])
 {
-  short block_length=8448; // decoder supports length: 1201 -> 1280, 2401 -> 2560
+  short Kprime = 8448;
   // default to check output inside ldpc, the NR version checks the outer CRC defined by 3GPP
   char *ldpc_version = "";
   /* version of the ldpc decoder library to use (XXX suffix to use when loading libldpc_XXX.so */
-  short max_iterations=5;
-  int n_segments=1;
-  //double rate=0.333;
-  
-  int nom_rate=1;
-  int denom_rate=3;
-  double SNR0=-2.0;
-  uint8_t qbits=8;
+  short max_iterations = 5;
+  int n_segments = 1;
+  // double rate=0.333;
+
+  int nom_rate = 1;
+  int denom_rate = 3;
+  double SNR0 = -2.0;
+  uint8_t qbits = 8;
   unsigned int decoded_errors[10000]; // initiate the size of matrix equivalent to size of SNR
   int c, i = 0;
 
@@ -420,7 +444,7 @@ int main(int argc, char *argv[])
   double SNR_step = 0.1;
 
   randominit(0);
-  int test_uncoded= 0;
+  int test_uncoded = 0;
   n_iter_stats_t dec_iter[400] = {0};
 
   short BG = 0, Zc;
@@ -430,14 +454,13 @@ int main(int argc, char *argv[])
   }
   logInit();
 
-  while ((c = getopt (argc, argv, "--:O:q:r:s:S:l:G:n:d:i:t:u:hv:")) != -1) {
-
+  while ((c = getopt(argc, argv, "--:O:q:r:s:S:l:G:n:d:i:t:u:hv:")) != -1) {
     /* ignore long options starting with '--', option '-O' and their arguments that are handled by configmodule */
     /* with this opstring getopt returns 1 for non-option arguments, refer to 'man 3 getopt' */
     if (c == 1 || c == '-' || c == 'O')
       continue;
 
-    printf("handling optarg %c\n",c);
+    printf("handling optarg %c\n", c);
     switch (c) {
       case 'q':
         qbits = atoi(optarg);
@@ -452,11 +475,11 @@ int main(int argc, char *argv[])
         break;
 
       case 'l':
-        block_length = atoi(optarg);
+        Kprime = atoi(optarg);
         break;
-		
+
       case 'G':
-        ldpc_version="_cuda";
+        ldpc_version = "_cuda";
         break;
 
       case 'n':
@@ -488,13 +511,13 @@ int main(int argc, char *argv[])
       case 'h':
       default:
         printf("CURRENTLY SUPPORTED CODE RATES: \n");
-        printf("BG1 (blocklength > 3840): 1/3, 2/3, 22/25 (8/9) \n");
-        printf("BG2 (blocklength <= 3840): 1/5, 1/3, 2/3 \n\n");
+        printf("BG1 (K' > 3840): 1/3, 2/3, 22/25 (8/9) \n");
+        printf("BG2 (K' <= 3840): 1/5, 1/3, 2/3 \n\n");
         printf("-h This message\n");
         printf("-q Quantization bits, Default: 8\n");
         printf("-r Nominator rate, (1, 2, 22), Default: 1\n");
         printf("-d Denominator rate, (3, 5, 25), Default: 1\n");
-        printf("-l Block length (l > 3840 -> BG1, rest BG2 ), Default: 8448\n");
+        printf("-l Length of payload bits in a segment (K' in 38.212-5.2.2), [1, 8448], Default: 8448\n");
         printf("-G give 1 to run cuda for LDPC, Default: 0\n");
         printf("-n Number of simulation trials, Default: 1\n");
         // printf("-M MCS2 for TB 2\n");
@@ -503,30 +526,29 @@ int main(int argc, char *argv[])
         printf("-t SNR simulation step, Default: 0.1\n");
         printf("-i Max decoder iterations, Default: 5\n");
         printf("-u Set SNR per coded bit, Default: 0\n");
-        printf("-v XXX Set ldpc shared library version. libldpc_XXX.so will be used \n");
+        printf("-v _XXX Set ldpc shared library version. libldpc_XXX.so will be used \n");
         exit(1);
         break;
     }
   }
-  //printf("the decoder supports BG2, Kb=10, Z=128 & 256\n");
-  //printf(" range of blocklength: 1201 -> 1280, 2401 -> 2560\n");
-  printf("block length %d: \n", block_length);
+  printf("block length %d: \n", Kprime);
   printf("n_trials %d: \n", n_trials);
   printf("SNR0 %f: \n", SNR0);
 
   load_LDPClib(ldpc_version, &ldpc_toCompare);
   load_LDPClib("_orig", &ldpc_orig);
-  //for (block_length=8;block_length<=MAX_BLOCK_LENGTH;block_length+=8)
 
-  //find minimum value in all sets of lifting size
-  Zc=0;
+  // find minimum value in all sets of lifting size
+  Zc = 0;
 
   char fname[200];
-  sprintf(fname,"ldpctest_BG_%d_Zc_%d_rate_%d-%d_block_length_%d_maxit_%d.txt",BG,Zc,nom_rate,denom_rate,block_length, max_iterations);
-  FILE *fd=fopen(fname,"w");
-  AssertFatal(fd!=NULL,"cannot open %s\n",fname);
+  sprintf(fname, "ldpctest_BG_%d_Zc_%d_rate_%d-%d_Kprime_%d_maxit_%d.txt", BG, Zc, nom_rate, denom_rate, Kprime, max_iterations);
+  FILE *fd = fopen(fname, "w");
+  AssertFatal(fd != NULL, "cannot open %s\n", fname);
 
-  fprintf(fd,"SNR BLER BER UNCODED_BER ENCODER_MEAN ENCODER_STD ENCODER_MAX DECODER_TIME_MEAN DECODER_TIME_STD DECODER_TIME_MAX DECODER_ITER_MEAN DECODER_ITER_STD DECODER_ITER_MAX\n");
+  fprintf(fd,
+          "SNR BLER BER UNCODED_BER ENCODER_MEAN ENCODER_STD ENCODER_MAX DECODER_TIME_MEAN DECODER_TIME_STD DECODER_TIME_MAX "
+          "DECODER_ITER_MEAN DECODER_ITER_STD DECODER_ITER_MAX\n");
 
   for (double SNR = SNR0; SNR < SNR0 + 20.0; SNR += SNR_step) {
     double SNR_lin;
@@ -540,13 +562,14 @@ int main(int argc, char *argv[])
                                       denom_rate,
                                       SNR_lin, // noise standard deviation
                                       qbits,
-                                      block_length, // block length bytes
+                                      Kprime, // block length bytes
                                       n_trials,
                                       n_segments);
+
     decoded_errors[i] = res.errors;
     dec_iter[i] = res.dec_iter;
     dec_iter[i].snr = SNR;
-    dec_iter[i].ber = (float)res.errors_bit / (float)n_trials / (float)block_length / (double)n_segments;
+    dec_iter[i].ber = (float)res.errors_bit / (float)n_trials / (float)Kprime / (double)n_segments;
     dec_iter[i].bler = (float)decoded_errors[i] / (float)n_trials;
     printf("SNR %f, BLER %f (%u/%d)\n", SNR, dec_iter[i].bler, decoded_errors[i], n_trials);
     printf("SNR %f, BER %f (%u/%d)\n", SNR, dec_iter[i].ber, decoded_errors[i], n_trials);
@@ -559,33 +582,42 @@ int main(int argc, char *argv[])
     printf("SNR %f, Std iterations: %f\n", SNR, dec_iter[i].n_iter_std);
     printf("SNR %f, Max iterations: %d\n", SNR, dec_iter[i].n_iter_max);
     printf("\n");
-    printf("Encoding time mean: %15.3f us\n",(double)res.time_optim.diff/res.time_optim.trials/1000.0/get_cpu_freq_GHz());
-    printf("Encoding time std: %15.3f us\n",sqrt((double)res.time_optim.diff_square/res.time_optim.trials/pow(1000,2)/pow(get_cpu_freq_GHz(),2)-pow((double)res.time_optim.diff/res.time_optim.trials/1000.0/get_cpu_freq_GHz(),2)));
-    printf("Encoding time max: %15.3f us\n",(double)res.time_optim.max/1000.0/get_cpu_freq_GHz());
+
+    double cpu_freq = get_cpu_freq_GHz();
+    time_stats_t *t_optim = &res.time_optim;
+    printf("Encoding time mean: %15.3f us\n", (double)t_optim->diff / t_optim->trials / 1000.0 / cpu_freq);
+    printf("Encoding time std: %15.3f us\n",
+           sqrt((double)t_optim->diff_square / t_optim->trials / pow(1000, 2) / pow(cpu_freq, 2)
+                - pow((double)t_optim->diff / t_optim->trials / 1000.0 / cpu_freq, 2)));
+    printf("Encoding time max: %15.3f us\n", (double)t_optim->max / 1000.0 / cpu_freq);
     printf("\n");
-    printf("Decoding time mean: %15.3f us\n",(double)res.time_decoder.diff/res.time_decoder.trials/1000.0/get_cpu_freq_GHz());
-    printf("Decoding time std: %15.3f us\n",sqrt((double)res.time_decoder.diff_square/res.time_decoder.trials/pow(1000,2)/pow(get_cpu_freq_GHz(),2)-pow((double)res.time_decoder.diff/res.time_decoder.trials/1000.0/get_cpu_freq_GHz(),2)));
-    printf("Decoding time max: %15.3f us\n",(double)res.time_decoder.max/1000.0/get_cpu_freq_GHz());
+
+    time_stats_t *t_decoder = &res.time_decoder;
+    printf("Decoding time mean: %15.3f us\n", (double)t_decoder->diff / t_decoder->trials / 1000.0 / cpu_freq);
+    printf("Decoding time std: %15.3f us\n",
+           sqrt((double)t_decoder->diff_square / t_decoder->trials / pow(1000, 2) / pow(cpu_freq, 2)
+                - pow((double)t_decoder->diff / t_decoder->trials / 1000.0 / cpu_freq, 2)));
+    printf("Decoding time max: %15.3f us\n", (double)t_decoder->max / 1000.0 / cpu_freq);
 
     fprintf(fd,
             "%f %f %f %f %f %f %f %f %f %f %f %f %d \n",
             SNR,
             (double)decoded_errors[i] / (double)n_trials,
-            (double)res.errors_bit / (double)n_trials / (double)block_length / (double)n_segments,
+            (double)res.errors_bit / (double)n_trials / (double)Kprime / (double)n_segments,
             res.errors_bit_uncoded / (double)n_trials / (double)n_segments,
-            (double)res.time_optim.diff / res.time_optim.trials / 1000.0 / get_cpu_freq_GHz(),
-            sqrt((double)res.time_optim.diff_square / res.time_optim.trials / pow(1000, 2) / pow(get_cpu_freq_GHz(), 2)
-                 - pow((double)res.time_optim.diff / res.time_optim.trials / 1000.0 / get_cpu_freq_GHz(), 2)),
-            (double)res.time_optim.max / 1000.0 / get_cpu_freq_GHz(),
-            (double)res.time_decoder.diff / res.time_decoder.trials / 1000.0 / get_cpu_freq_GHz(),
-            sqrt((double)res.time_decoder.diff_square / res.time_decoder.trials / pow(1000, 2) / pow(get_cpu_freq_GHz(), 2)
-                 - pow((double)res.time_decoder.diff / res.time_decoder.trials / 1000.0 / get_cpu_freq_GHz(), 2)),
-            (double)res.time_decoder.max / 1000.0 / get_cpu_freq_GHz(),
+            (double)t_optim->diff / t_optim->trials / 1000.0 / cpu_freq,
+            sqrt((double)t_optim->diff_square / t_optim->trials / pow(1000, 2) / pow(cpu_freq, 2)
+                 - pow((double)t_optim->diff / t_optim->trials / 1000.0 / cpu_freq, 2)),
+            (double)t_optim->max / 1000.0 / cpu_freq,
+            (double)t_decoder->diff / t_decoder->trials / 1000.0 / cpu_freq,
+            sqrt((double)t_decoder->diff_square / t_decoder->trials / pow(1000, 2) / pow(cpu_freq, 2)
+                 - pow((double)t_decoder->diff / t_decoder->trials / 1000.0 / cpu_freq, 2)),
+            (double)t_decoder->max / 1000.0 / cpu_freq,
             dec_iter[i].n_iter_mean,
             dec_iter[i].n_iter_std,
             dec_iter[i].n_iter_max);
 
-    i=i+1;
+    i = i + 1;
     if (decoded_errors[i - 1] == 0)
       break;
   }
@@ -598,5 +630,5 @@ int main(int argc, char *argv[])
   loader_reset();
   logTerm();
 
-  return(0);
+  return (0);
 }
diff --git a/openair1/PHY/CODING/nrLDPC_coding/nrLDPC_coding_segment/nrLDPC_coding_segment_encoder.c b/openair1/PHY/CODING/nrLDPC_coding/nrLDPC_coding_segment/nrLDPC_coding_segment_encoder.c
index 95141e88454a9873f0a90e18d8cdb4dddb23da83..b51712ed71b8dda8fe0dc91af2bd2c20290d5451 100644
--- a/openair1/PHY/CODING/nrLDPC_coding/nrLDPC_coding_segment/nrLDPC_coding_segment_encoder.c
+++ b/openair1/PHY/CODING/nrLDPC_coding/nrLDPC_coding_segment/nrLDPC_coding_segment_encoder.c
@@ -49,7 +49,7 @@ typedef struct ldpc8blocks_args_s {
   encoder_implemparams_t impp;
 } ldpc8blocks_args_t;
 
-static void ldpc8blocks_coding_segment(void *p)
+static void ldpc8blocks(void *p)
 {
   ldpc8blocks_args_t *args = (ldpc8blocks_args_t *)p;
   nrLDPC_TB_encoding_parameters_t *nrLDPC_TB_encoding_parameters = args->nrLDPC_TB_encoding_parameters;
@@ -192,7 +192,7 @@ static int nrLDPC_prepare_TB_encoding(nrLDPC_slot_encoding_parameters_t *nrLDPC_
     perJobImpp->impp = impp;
     perJobImpp->nrLDPC_TB_encoding_parameters = nrLDPC_TB_encoding_parameters;
 
-    task_t t = {.func = ldpc8blocks_coding_segment, .args = perJobImpp};
+    task_t t = {.func = ldpc8blocks, .args = perJobImpp};
     pushTpool(nrLDPC_slot_encoding_parameters->threadPool, t);
   }
   return n_seg;
diff --git a/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c b/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c
index d64c32059c1a08ff5bcfa64fac0243c59067d968..29ea38232c2f84086f4ea940d9ca115c6d6e823a 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c
@@ -20,8 +20,8 @@
  */
 
 /*! \file PHY/NR_TRANSPORT/nr_dlsch_coding_slot.c
-* \brief Top-level routines for implementing LDPC-coded (DLSCH) transport channels from 38-212, 15.2
-*/
+ * \brief Top-level routines for implementing LDPC-coded (DLSCH) transport channels from 38-212, 15.2
+ */
 
 #include "PHY/defs_gNB.h"
 #include "PHY/CODING/coding_extern.h"
@@ -39,17 +39,17 @@
 #include <syscall.h>
 #include <openair2/UTIL/OPT/opt.h>
 
-//#define DEBUG_DLSCH_CODING
-//#define DEBUG_DLSCH_FREE 1
+// #define DEBUG_DLSCH_CODING
+// #define DEBUG_DLSCH_FREE 1
 
 void free_gNB_dlsch(NR_gNB_DLSCH_t *dlsch, uint16_t N_RB, const NR_DL_FRAME_PARMS *frame_parms)
 {
-  int max_layers = (frame_parms->nb_antennas_tx<NR_MAX_NB_LAYERS) ? frame_parms->nb_antennas_tx : NR_MAX_NB_LAYERS;
-  uint16_t a_segments = MAX_NUM_NR_DLSCH_SEGMENTS_PER_LAYER*max_layers;
+  int max_layers = (frame_parms->nb_antennas_tx < NR_MAX_NB_LAYERS) ? frame_parms->nb_antennas_tx : NR_MAX_NB_LAYERS;
+  uint16_t a_segments = MAX_NUM_NR_DLSCH_SEGMENTS_PER_LAYER * max_layers;
 
   if (N_RB != 273) {
-    a_segments = a_segments*N_RB;
-    a_segments = a_segments/273 +1;
+    a_segments = a_segments * N_RB;
+    a_segments = a_segments / 273 + 1;
   }
 
   NR_DL_gNB_HARQ_t *harq = &dlsch->harq_process;
@@ -70,16 +70,16 @@ void free_gNB_dlsch(NR_gNB_DLSCH_t *dlsch, uint16_t N_RB, const NR_DL_FRAME_PARM
 
 NR_gNB_DLSCH_t new_gNB_dlsch(NR_DL_FRAME_PARMS *frame_parms, uint16_t N_RB)
 {
-  int max_layers = (frame_parms->nb_antennas_tx<NR_MAX_NB_LAYERS) ? frame_parms->nb_antennas_tx : NR_MAX_NB_LAYERS;
-  uint16_t a_segments = MAX_NUM_NR_DLSCH_SEGMENTS_PER_LAYER*max_layers;  //number of segments to be allocated
+  int max_layers = (frame_parms->nb_antennas_tx < NR_MAX_NB_LAYERS) ? frame_parms->nb_antennas_tx : NR_MAX_NB_LAYERS;
+  uint16_t a_segments = MAX_NUM_NR_DLSCH_SEGMENTS_PER_LAYER * max_layers; // number of segments to be allocated
 
   if (N_RB != 273) {
-    a_segments = a_segments*N_RB;
-    a_segments = a_segments/273 +1;
+    a_segments = a_segments * N_RB;
+    a_segments = a_segments / 273 + 1;
   }
 
-  LOG_D(PHY,"Allocating %d segments (MAX %d, N_PRB %d)\n",a_segments,MAX_NUM_NR_DLSCH_SEGMENTS_PER_LAYER,N_RB);
-  uint32_t dlsch_bytes = a_segments*1056;  // allocated bytes per segment
+  LOG_D(PHY, "Allocating %d segments (MAX %d, N_PRB %d)\n", a_segments, MAX_NUM_NR_DLSCH_SEGMENTS_PER_LAYER, N_RB);
+  uint32_t dlsch_bytes = a_segments * 1056; // allocated bytes per segment
   NR_gNB_DLSCH_t dlsch;
 
   NR_DL_gNB_HARQ_t *harq = &dlsch.harq_process;
@@ -88,7 +88,7 @@ NR_gNB_DLSCH_t new_gNB_dlsch(NR_DL_FRAME_PARMS *frame_parms, uint16_t N_RB)
   AssertFatal(harq->b, "cannot allocate memory for harq->b\n");
   bzero(harq->b, dlsch_bytes);
 
-  harq->c = (uint8_t **)malloc16(a_segments*sizeof(uint8_t *));
+  harq->c = (uint8_t **)malloc16(a_segments * sizeof(uint8_t *));
   for (int r = 0; r < a_segments; r++) {
     // account for filler in first segment and CRCs for multiple segment case
     // [hna] 8448 is the maximum CB size in NR
@@ -103,7 +103,7 @@ NR_gNB_DLSCH_t new_gNB_dlsch(NR_DL_FRAME_PARMS *frame_parms, uint16_t N_RB)
   AssertFatal(harq->f, "cannot allocate harq->f\n");
   bzero(harq->f, N_RB * NR_SYMBOLS_PER_SLOT * NR_NB_SC_PER_RB * 8 * NR_MAX_NB_LAYERS);
 
-  return(dlsch);
+  return (dlsch);
 }
 
 int nr_dlsch_encoding(PHY_VARS_gNB *gNB,
@@ -120,34 +120,30 @@ int nr_dlsch_encoding(PHY_VARS_gNB *gNB,
                       time_stats_t *dlsch_interleaving_stats,
                       time_stats_t *dlsch_segmentation_stats)
 {
-
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_gNB_DLSCH_ENCODING, VCD_FUNCTION_IN);
 
   nrLDPC_TB_encoding_parameters_t TBs[msgTx->num_pdsch_slot];
   memset(TBs, 0, sizeof(TBs));
-  nrLDPC_slot_encoding_parameters_t slot_parameters = {
-    .frame = frame,
-    .slot = slot,
-    .nb_TBs = msgTx->num_pdsch_slot,
-    .threadPool = &gNB->threadPool,
-    .tinput = tinput,
-    .tprep = tprep,
-    .tparity = tparity,
-    .toutput = toutput,
-    .TBs = TBs
-  };
+  nrLDPC_slot_encoding_parameters_t slot_parameters = {.frame = frame,
+                                                       .slot = slot,
+                                                       .nb_TBs = msgTx->num_pdsch_slot,
+                                                       .threadPool = &gNB->threadPool,
+                                                       .tinput = tinput,
+                                                       .tprep = tprep,
+                                                       .tparity = tparity,
+                                                       .toutput = toutput,
+                                                       .TBs = TBs};
 
   int num_segments = 0;
 
-  for (int dlsch_id=0; dlsch_id<msgTx->num_pdsch_slot; dlsch_id++) {
-
+  for (int dlsch_id = 0; dlsch_id < msgTx->num_pdsch_slot; dlsch_id++) {
     NR_gNB_DLSCH_t *dlsch = msgTx->dlsch[dlsch_id];
 
     NR_DL_gNB_HARQ_t *harq = &dlsch->harq_process;
-    unsigned int crc=1;
+    unsigned int crc = 1;
     nfapi_nr_dl_tti_pdsch_pdu_rel15_t *rel15 = &harq->pdsch_pdu.pdsch_pdu_rel15;
-    uint32_t A = rel15->TBSize[0]<<3;
-    unsigned char *a=harq->pdu;
+    uint32_t A = rel15->TBSize[0] << 3;
+    unsigned char *a = harq->pdu;
     if (rel15->rnti != SI_RNTI) {
       ws_trace_t tmp = {.nr = true,
                         .direction = DIRECTION_DOWNLINK,
@@ -175,38 +171,30 @@ int nr_dlsch_encoding(PHY_VARS_gNB *gNB,
       phy_stats->dlsch_stats.current_Qm = rel15->qamModOrder[0];
     }
 
-    int max_bytes = MAX_NUM_NR_DLSCH_SEGMENTS_PER_LAYER*rel15->nrOfLayers*1056;
+    int max_bytes = MAX_NUM_NR_DLSCH_SEGMENTS_PER_LAYER * rel15->nrOfLayers * 1056;
     int B;
     if (A > NR_MAX_PDSCH_TBS) {
       // Add 24-bit crc (polynomial A) to payload
-      crc = crc24a(a,A)>>8;
-      a[A>>3] = ((uint8_t *)&crc)[2];
-      a[1+(A>>3)] = ((uint8_t *)&crc)[1];
-      a[2+(A>>3)] = ((uint8_t *)&crc)[0];
-      //printf("CRC %x (A %d)\n",crc,A);
-      //printf("a0 %d a1 %d a2 %d\n", a[A>>3], a[1+(A>>3)], a[2+(A>>3)]);
+      crc = crc24a(a, A) >> 8;
+      a[A >> 3] = ((uint8_t *)&crc)[2];
+      a[1 + (A >> 3)] = ((uint8_t *)&crc)[1];
+      a[2 + (A >> 3)] = ((uint8_t *)&crc)[0];
+      // printf("CRC %x (A %d)\n",crc,A);
+      // printf("a0 %d a1 %d a2 %d\n", a[A>>3], a[1+(A>>3)], a[2+(A>>3)]);
       B = A + 24;
       //    harq->b = a;
-      AssertFatal((A / 8) + 4 <= max_bytes,
-                  "A %d is too big (A/8+4 = %d > %d)\n",
-                  A,
-                  (A / 8) + 4,
-                  max_bytes);
+      AssertFatal((A / 8) + 4 <= max_bytes, "A %d is too big (A/8+4 = %d > %d)\n", A, (A / 8) + 4, max_bytes);
       memcpy(harq->b, a, (A / 8) + 4); // why is this +4 if the CRC is only 3 bytes?
     } else {
       // Add 16-bit crc (polynomial A) to payload
-      crc = crc16(a,A)>>16;
-      a[A>>3] = ((uint8_t *)&crc)[1];
-      a[1+(A>>3)] = ((uint8_t *)&crc)[0];
-      //printf("CRC %x (A %d)\n",crc,A);
-      //printf("a0 %d a1 %d \n", a[A>>3], a[1+(A>>3)]);
+      crc = crc16(a, A) >> 16;
+      a[A >> 3] = ((uint8_t *)&crc)[1];
+      a[1 + (A >> 3)] = ((uint8_t *)&crc)[0];
+      // printf("CRC %x (A %d)\n",crc,A);
+      // printf("a0 %d a1 %d \n", a[A>>3], a[1+(A>>3)]);
       B = A + 16;
       //    harq->b = a;
-      AssertFatal((A / 8) + 3 <= max_bytes,
-                  "A %d is too big (A/8+3 = %d > %d)\n",
-                  A,
-                  (A / 8) + 3,
-                  max_bytes);
+      AssertFatal((A / 8) + 3 <= max_bytes, "A %d is too big (A/8+3 = %d > %d)\n", A, (A / 8) + 3, max_bytes);
       memcpy(harq->b, a, (A / 8) + 3); // using 3 bytes to mimic the case of 24 bit crc
     }
 
@@ -228,12 +216,11 @@ int nr_dlsch_encoding(PHY_VARS_gNB *gNB,
                                         TB_parameters->BG);
     stop_meas(dlsch_segmentation_stats);
 
-    if (TB_parameters->C>MAX_NUM_NR_DLSCH_SEGMENTS_PER_LAYER*rel15->nrOfLayers) {
+    if (TB_parameters->C > MAX_NUM_NR_DLSCH_SEGMENTS_PER_LAYER * rel15->nrOfLayers) {
       LOG_E(PHY, "nr_segmentation.c: too many segments %d, B %d\n", TB_parameters->C, B);
-      return(-1);
+      return (-1);
     }
     num_segments += TB_parameters->C;
-
   }
 
   nrLDPC_segment_encoding_parameters_t segments[num_segments];
@@ -284,18 +271,13 @@ int nr_dlsch_encoding(PHY_VARS_gNB *gNB,
     for (int r = 0; r < TB_parameters->C; r++) {
       nrLDPC_segment_encoding_parameters_t *segment_parameters = &TB_parameters->segments[r];
       segment_parameters->c = harq->c[r];
-      segment_parameters->E = nr_get_E(TB_parameters->G,
-                                       TB_parameters->C,
-                                       TB_parameters->Qm,
-                                       rel15->nrOfLayers,
-                                       r);
+      segment_parameters->E = nr_get_E(TB_parameters->G, TB_parameters->C, TB_parameters->Qm, rel15->nrOfLayers, r);
       segment_parameters->output = &output[dlsch_offset + r_offset];
       r_offset += segment_parameters->E;
 
       reset_meas(&segment_parameters->ts_interleave);
       reset_meas(&segment_parameters->ts_rate_match);
       reset_meas(&segment_parameters->ts_ldpc_encode);
-
     }
 
     segments_offset += TB_parameters->C;
@@ -309,6 +291,16 @@ int nr_dlsch_encoding(PHY_VARS_gNB *gNB,
 
   gNB->nrLDPC_coding_interface.nrLDPC_coding_encoder(&slot_parameters);
 
+  for (int dlsch_id = 0; dlsch_id < msgTx->num_pdsch_slot; dlsch_id++) {
+    nrLDPC_TB_encoding_parameters_t *TB_parameters = &TBs[dlsch_id];
+    for (int r = 0; r < TB_parameters->C; r++) {
+      nrLDPC_segment_encoding_parameters_t *segment_parameters = &TB_parameters->segments[r];
+      merge_meas(dlsch_interleaving_stats, &segment_parameters->ts_interleave);
+      merge_meas(dlsch_rate_matching_stats, &segment_parameters->ts_rate_match);
+      // merge_meas(, &segment_parameters->ts_ldpc_encode);
+    }
+  }
+
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_gNB_DLSCH_ENCODING, VCD_FUNCTION_OUT);
   return 0;
 }
diff --git a/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c b/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c
index c61898e9bbb025a8dd40526dd0f6d5d293cb5aea..667c7146b01d3e03ab4e444c9ddc5b4550e5e565 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c
@@ -20,9 +20,8 @@
  */
 
 /*! \file PHY/NR_TRANSPORT/nr_ulsch_decoding_slot.c
-* \brief Top-level routines for decoding  LDPC (ULSCH) transport channels from 38.212, V15.4.0 2018-12
-*/
-
+ * \brief Top-level routines for decoding  LDPC (ULSCH) transport channels from 38.212, V15.4.0 2018-12
+ */
 
 // [from gNB coding]
 #include "PHY/defs_gNB.h"
@@ -41,27 +40,26 @@
 #include "common/utils/LOG/vcd_signal_dumper.h"
 #include "common/utils/LOG/log.h"
 #include <syscall.h>
-//#define DEBUG_ULSCH_DECODING
-//#define gNB_DEBUG_TRACE
+// #define DEBUG_ULSCH_DECODING
+// #define gNB_DEBUG_TRACE
 
-#define OAI_UL_LDPC_MAX_NUM_LLR 27000//26112 // NR_LDPC_NCOL_BG1*NR_LDPC_ZMAX = 68*384
-//#define DEBUG_CRC
+#define OAI_UL_LDPC_MAX_NUM_LLR 27000 // 26112 // NR_LDPC_NCOL_BG1*NR_LDPC_ZMAX = 68*384
+// #define DEBUG_CRC
 #ifdef DEBUG_CRC
 #define PRINT_CRC_CHECK(a) a
 #else
 #define PRINT_CRC_CHECK(a)
 #endif
 
-//extern double cpuf;
+// extern double cpuf;
 
 void free_gNB_ulsch(NR_gNB_ULSCH_t *ulsch, uint16_t N_RB_UL)
 {
-
-  uint16_t a_segments = MAX_NUM_NR_ULSCH_SEGMENTS_PER_LAYER*NR_MAX_NB_LAYERS;  //number of segments to be allocated
+  uint16_t a_segments = MAX_NUM_NR_ULSCH_SEGMENTS_PER_LAYER * NR_MAX_NB_LAYERS; // number of segments to be allocated
 
   if (N_RB_UL != 273) {
-    a_segments = a_segments*N_RB_UL;
-    a_segments = a_segments/273 +1;
+    a_segments = a_segments * N_RB_UL;
+    a_segments = a_segments / 273 + 1;
   }
 
   if (ulsch->harq_process) {
@@ -83,12 +81,11 @@ void free_gNB_ulsch(NR_gNB_ULSCH_t *ulsch, uint16_t N_RB_UL)
 
 NR_gNB_ULSCH_t new_gNB_ulsch(uint8_t max_ldpc_iterations, uint16_t N_RB_UL)
 {
-
-  uint16_t a_segments = MAX_NUM_NR_ULSCH_SEGMENTS_PER_LAYER*NR_MAX_NB_LAYERS;  //number of segments to be allocated
+  uint16_t a_segments = MAX_NUM_NR_ULSCH_SEGMENTS_PER_LAYER * NR_MAX_NB_LAYERS; // number of segments to be allocated
 
   if (N_RB_UL != 273) {
-    a_segments = a_segments*N_RB_UL;
-    a_segments = a_segments/273 +1;
+    a_segments = a_segments * N_RB_UL;
+    a_segments = a_segments / 273 + 1;
   }
 
   uint32_t ulsch_bytes = a_segments * 1056; // allocated bytes per segment
@@ -110,7 +107,7 @@ NR_gNB_ULSCH_t new_gNB_ulsch(uint8_t max_ldpc_iterations, uint16_t N_RB_UL)
   }
   harq->d_to_be_cleared = calloc(a_segments, sizeof(bool));
   AssertFatal(harq->d_to_be_cleared != NULL, "out of memory\n");
-  return(ulsch);
+  return (ulsch);
 }
 
 int nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB,
@@ -121,18 +118,15 @@ int nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB,
                       uint8_t *ULSCH_ids,
                       int nb_pusch)
 {
-
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_gNB_ULSCH_DECODING, 1);
 
   nrLDPC_TB_decoding_parameters_t TBs[nb_pusch];
   memset(TBs, 0, sizeof(TBs));
-  nrLDPC_slot_decoding_parameters_t slot_parameters = {
-    .frame = frame,
-    .slot = nr_tti_rx,
-    .nb_TBs = nb_pusch,
-    .threadPool = &phy_vars_gNB->threadPool,
-    .TBs = TBs
-  };
+  nrLDPC_slot_decoding_parameters_t slot_parameters = {.frame = frame,
+                                                       .slot = nr_tti_rx,
+                                                       .nb_TBs = nb_pusch,
+                                                       .threadPool = &phy_vars_gNB->threadPool,
+                                                       .TBs = TBs};
 
   int max_num_segments = 0;
 
@@ -154,17 +148,17 @@ int nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB,
 
     // The harq_pid is not unique among the active HARQ processes in the instance so we use ULSCH_id instead
     TB_parameters->harq_unique_pid = ULSCH_id;
-  
+
     // ------------------------------------------------------------------
     TB_parameters->nb_rb = pusch_pdu->rb_size;
     TB_parameters->Qm = pusch_pdu->qam_mod_order;
     TB_parameters->mcs = pusch_pdu->mcs_index;
     TB_parameters->nb_layers = pusch_pdu->nrOfLayers;
     // ------------------------------------------------------------------
-  
+
     TB_parameters->processedSegments = &harq_process->processedSegments;
     harq_process->TBS = pusch_pdu->pusch_data.tb_size;
-  
+
     TB_parameters->BG = pusch_pdu->maintenance_parms_v3.ldpcBaseGraph;
     TB_parameters->A = (harq_process->TBS) << 3;
     NR_gNB_PHY_STATS_t *stats = get_phy_stats(phy_vars_gNB, ulsch->rnti);
@@ -181,7 +175,7 @@ int nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB,
         stats->ulsch_stats.total_bytes_tx += harq_process->TBS;
       }
     }
-  
+
     uint8_t harq_pid = ulsch->harq_pid;
     LOG_D(PHY,
           "ULSCH Decoding, harq_pid %d rnti %x TBS %d G %d mcs %d Nl %d nb_rb %d, Qm %d, Coderate %f RV %d round %d new RX %d\n",
@@ -197,7 +191,7 @@ int nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB,
           pusch_pdu->pusch_data.rv_index,
           harq_process->round,
           harq_process->harq_to_be_cleared);
-  
+
     // [hna] Perform nr_segmenation with input and output set to NULL to calculate only (C, K, Z, F)
     nr_segmentation(NULL,
                     NULL,
@@ -211,40 +205,34 @@ int nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB,
     harq_process->K = TB_parameters->K;
     harq_process->Z = TB_parameters->Z;
     harq_process->F = TB_parameters->F;
-  
+
     uint16_t a_segments = MAX_NUM_NR_ULSCH_SEGMENTS_PER_LAYER * TB_parameters->nb_layers; // number of segments to be allocated
     if (TB_parameters->C > a_segments) {
       LOG_E(PHY, "nr_segmentation.c: too many segments %d, A %d\n", harq_process->C, TB_parameters->A);
-      return(-1);
+      return (-1);
     }
     if (TB_parameters->nb_rb != 273) {
-      a_segments = a_segments*TB_parameters->nb_rb;
-      a_segments = a_segments/273 +1;
+      a_segments = a_segments * TB_parameters->nb_rb;
+      a_segments = a_segments / 273 + 1;
     }
     if (TB_parameters->C > a_segments) {
-      LOG_E(PHY,"Illegal harq_process->C %d > %d\n",harq_process->C,a_segments);
+      LOG_E(PHY, "Illegal harq_process->C %d > %d\n", harq_process->C, a_segments);
       return -1;
     }
     max_num_segments = max(max_num_segments, TB_parameters->C);
-  
+
 #ifdef DEBUG_ULSCH_DECODING
     printf("ulsch decoding nr segmentation Z %d\n", TB_parameters->Z);
     if (!frame % 100)
-      printf("K %d C %d Z %d \n",
-             TB_parameters->K,
-             TB_parameters->C,
-             TB_parameters->Z);
-    printf("Segmentation: C %d, K %d\n",
-           TB_parameters->C,
-           TB_parameters->K);
+      printf("K %d C %d Z %d \n", TB_parameters->K, TB_parameters->C, TB_parameters->Z);
+    printf("Segmentation: C %d, K %d\n", TB_parameters->C, TB_parameters->K);
 #endif
-  
+
     TB_parameters->max_ldpc_iterations = ulsch->max_ldpc_iterations;
     TB_parameters->rv_index = pusch_pdu->pusch_data.rv_index;
     TB_parameters->tbslbrm = pusch_pdu->maintenance_parms_v3.tbSizeLbrmBytes;
     TB_parameters->abort_decode = &harq_process->abort_decode;
     set_abort(&harq_process->abort_decode, false);
-
   }
 
   nrLDPC_segment_decoding_parameters_t segments[nb_pusch][max_num_segments];
@@ -267,11 +255,7 @@ int nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB,
     uint32_t r_offset = 0;
     for (int r = 0; r < TB_parameters->C; r++) {
       nrLDPC_segment_decoding_parameters_t *segment_parameters = &TB_parameters->segments[r];
-      segment_parameters->E = nr_get_E(TB_parameters->G,
-                                       TB_parameters->C,
-                                       TB_parameters->Qm,
-                                       TB_parameters->nb_layers,
-                                       r);
+      segment_parameters->E = nr_get_E(TB_parameters->G, TB_parameters->C, TB_parameters->Qm, TB_parameters->nb_layers, r);
       segment_parameters->R = nr_get_R_ldpc_decoder(TB_parameters->rv_index,
                                                     segment_parameters->E,
                                                     TB_parameters->BG,
@@ -296,7 +280,6 @@ int nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB,
       }
       harq_process->harq_to_be_cleared = false;
     }
-
   }
 
   int ret_decoder = phy_vars_gNB->nrLDPC_coding_interface.nrLDPC_coding_decoder(&slot_parameters);
@@ -314,7 +297,9 @@ int nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB,
       nrLDPC_segment_decoding_parameters_t nrLDPC_segment_decoding_parameters = TB_parameters.segments[r];
       // Copy c to b in case of decoding success
       if (nrLDPC_segment_decoding_parameters.decodeSuccess) {
-        memcpy(harq_process->b + offset, harq_process->c[r], (harq_process->K >> 3) - (harq_process->F >> 3) - ((harq_process->C > 1) ? 3 : 0));
+        memcpy(harq_process->b + offset,
+               harq_process->c[r],
+               (harq_process->K >> 3) - (harq_process->F >> 3) - ((harq_process->C > 1) ? 3 : 0));
       } else {
         LOG_D(PHY, "uplink segment error %d/%d\n", r, harq_process->C);
         LOG_D(PHY, "ULSCH %d in error\n", ULSCH_id);
diff --git a/openair1/SIMULATION/TOOLS/DOC/channel_simulation.md b/openair1/SIMULATION/TOOLS/DOC/channel_simulation.md
index 070ee61ca0c6c68a395f3e6bbb83638f96644242..30cc68e66262302e28a4f3c88cc542091479d765 100644
--- a/openair1/SIMULATION/TOOLS/DOC/channel_simulation.md
+++ b/openair1/SIMULATION/TOOLS/DOC/channel_simulation.md
@@ -142,6 +142,7 @@ Channel simulation parameters can also be specified on the command line by using
 |:---                 |:----       |:----               |:----|
 |`modellist`          |char string |`DefaultChannelList`|select and load the `modellist` from the config file.|
 |`max_chan`           |integer     |10                  |set the maximum number of channel models that can be defined in the system. Must be greater than the number of model definitions in the model list loaded at init time.|
+|`noise_power_dBFS`   |integer     |0                   |Noise power in dBFS. If set, noise per channel is not applied. To achieve positive SNR use values below the default gNB/nrUE amp backoff value (-36dBFS)|
 
 Example usage:
 ```bash
diff --git a/openair1/SIMULATION/TOOLS/random_channel.c b/openair1/SIMULATION/TOOLS/random_channel.c
index 4c715498a8314fd64ffd74cd288418ed1f234c9e..b9ae9e3fff563d4f19dc45880d67927d4b01a67f 100644
--- a/openair1/SIMULATION/TOOLS/random_channel.c
+++ b/openair1/SIMULATION/TOOLS/random_channel.c
@@ -73,6 +73,7 @@ static telnetshell_vardef_t channelmod_vardef[] = {{"", 0, 0, NULL}};
 static unsigned int max_chan;
 static channel_desc_t **defined_channels;
 static char *modellist_name;
+static int noise_power_dBFS = INVALID_DBFS_VALUE;
 
 void fill_channel_desc(channel_desc_t *chan_desc,
                        uint8_t nb_tx,
@@ -2365,6 +2366,10 @@ int load_channellist(uint8_t nb_tx, uint8_t nb_rx, double sampling_rate, uint64_
   return channel_list.numelt;
 } /* load_channelist */
 
+int get_noise_power_dBFS(void) {
+  return noise_power_dBFS;
+}
+
 #ifdef RANDOM_CHANNEL_MAIN
 #define sampling_rate 5.0
 #define Td 2.0
diff --git a/openair1/SIMULATION/TOOLS/sim.h b/openair1/SIMULATION/TOOLS/sim.h
index 8297d9c3659d1514af5ac13805fa7481a2d76559..d6b20a9eb97412fcb0e8df9db5a9efb70d11421e 100644
--- a/openair1/SIMULATION/TOOLS/sim.h
+++ b/openair1/SIMULATION/TOOLS/sim.h
@@ -278,10 +278,15 @@ typedef enum {
 #define CHANNELMOD_MODELLIST_PARANAME "modellist"
 
 #define CHANNELMOD_HELP_MODELLIST "<list name> channel list name in config file describing the model type and its parameters\n"
+#define CHANNELMOD_HELP_NOISE_POWER \
+  "Noise power in dBFS. If set, noise per channel is not applied. To achieve positive SNR use values below -36dBFS\n"
+
+#define INVALID_DBFS_VALUE 100
 // clang-format off
 #define CHANNELMOD_PARAMS_DESC {  \
   {"max_chan",                    "Max number of runtime models",     0,                                  .uptr=&max_chan,              .defintval=10,                    TYPE_UINT,   0}, \
   {CHANNELMOD_MODELLIST_PARANAME, CHANNELMOD_HELP_MODELLIST,          0,                                  .strptr=&modellist_name,      .defstrval="DefaultChannelList",  TYPE_STRING, 0}, \
+  {"noise_power_dBFS",            CHANNELMOD_HELP_NOISE_POWER,        0,                                  .iptr=&noise_power_dBFS,      .defintval=INVALID_DBFS_VALUE,    TYPE_INT,    0 },\
 }
 // clang-format on
 
@@ -585,5 +590,6 @@ void do_DL_sig(sim_t *sim,
                int CC_id);
 
 void do_UL_sig(sim_t *sim, uint16_t subframe, uint8_t abstraction_flag, LTE_DL_FRAME_PARMS *frame_parms, uint32_t frame, int ru_id, uint8_t CC_id, int NB_UEs);
+int get_noise_power_dBFS(void);
 
 #endif
diff --git a/openair2/COMMON/as_message.h b/openair2/COMMON/as_message.h
index 5a29d6881bd816986691a847797d7f86d109a481..31d53d12fe5ff151ae78ac44e2fd24be310fe411 100644
--- a/openair2/COMMON/as_message.h
+++ b/openair2/COMMON/as_message.h
@@ -404,6 +404,13 @@ typedef struct nas_detach_req_s {
   bool wait_release;
 } nas_detach_req_t;
 
+/**
+ * @brief 5GS mobility management information
+ * @ref   clause 9.11.3 of 3GPP TS 24.501
+ */
+typedef struct nas_5gmm_ind_s {
+  uint64_t fiveG_STMSI;
+} nas_5gmm_ind_t;
 /*
  * --------------------------------------------------------------------------
  *              NAS information transfer
@@ -578,6 +585,7 @@ typedef struct as_message_s {
     rab_establish_cnf_t rab_establish_cnf;
     rab_release_req_t rab_release_req;
     rab_release_ind_t rab_release_ind;
+    nas_5gmm_ind_t Nas5GMMInd;
   } __attribute__((__packed__)) msg;
 } as_message_t;
 
diff --git a/openair2/COMMON/rrc_messages_def.h b/openair2/COMMON/rrc_messages_def.h
index cb4805ff5e1464731ab722cd541d15361f57ce4a..841c44d612c8ac71b8b675f1dd22ff73deb73524 100644
--- a/openair2/COMMON/rrc_messages_def.h
+++ b/openair2/COMMON/rrc_messages_def.h
@@ -63,6 +63,7 @@ MESSAGE_DEF(NAS_CONN_ESTABLI_REQ, MESSAGE_PRIORITY_MED, nas_establish_req_t, nas
 MESSAGE_DEF(NAS_UPLINK_DATA_REQ, MESSAGE_PRIORITY_MED, ul_info_transfer_req_t, nas_ul_data_req)
 MESSAGE_DEF(NAS_DETACH_REQ, MESSAGE_PRIORITY_MED, nas_detach_req_t, nas_detach_req)
 MESSAGE_DEF(NAS_DEREGISTRATION_REQ, MESSAGE_PRIORITY_MED, nas_deregistration_req_t, nas_deregistration_req)
+MESSAGE_DEF(NAS_5GMM_IND, MESSAGE_PRIORITY_MED, nas_5gmm_ind_t, nas_5gmm_ind)
 
 MESSAGE_DEF(NAS_RAB_ESTABLI_RSP, MESSAGE_PRIORITY_MED, rab_establish_rsp_t, nas_rab_est_rsp)
 
@@ -74,6 +75,7 @@ MESSAGE_DEF(NAS_CELL_SELECTION_IND, MESSAGE_PRIORITY_MED, cell_info_ind_t, nas_c
 MESSAGE_DEF(NAS_PAGING_IND, MESSAGE_PRIORITY_MED, paging_ind_t, nas_paging_ind)
 MESSAGE_DEF(NAS_CONN_ESTABLI_CNF, MESSAGE_PRIORITY_MED, nas_establish_cnf_t, nas_conn_establi_cnf)
 MESSAGE_DEF(NAS_CONN_RELEASE_IND, MESSAGE_PRIORITY_MED, nas_release_ind_t, nas_conn_release_ind)
+MESSAGE_DEF(NR_NAS_CONN_ESTABLISH_IND, MESSAGE_PRIORITY_MED, nas_establish_ind_t, nr_nas_conn_establish_ind)
 MESSAGE_DEF(NR_NAS_CONN_RELEASE_IND,    MESSAGE_PRIORITY_MED,       NRNasConnReleaseInd,        nr_nas_conn_release_ind)
 MESSAGE_DEF(NAS_UPLINK_DATA_CNF, MESSAGE_PRIORITY_MED, ul_info_transfer_cnf_t, nas_ul_data_cnf)
 MESSAGE_DEF(NAS_DOWNLINK_DATA_IND, MESSAGE_PRIORITY_MED, dl_info_transfer_ind_t, nas_dl_data_ind)
diff --git a/openair2/COMMON/rrc_messages_types.h b/openair2/COMMON/rrc_messages_types.h
index 5dc1e27f931c1fc5ffea385058df297a1e188ee7..2446bbe4b37acaa4bcadcf5d2b0ecb30aee8ca86 100644
--- a/openair2/COMMON/rrc_messages_types.h
+++ b/openair2/COMMON/rrc_messages_types.h
@@ -76,6 +76,7 @@
 #define NAS_UPLINK_DATA_REQ(mSGpTR)     (mSGpTR)->ittiMsg.nas_ul_data_req
 #define NAS_DETACH_REQ(mSGpTR)          (mSGpTR)->ittiMsg.nas_detach_req
 #define NAS_DEREGISTRATION_REQ(mSGpTR)  (mSGpTR)->ittiMsg.nas_deregistration_req
+#define NAS_5GMM_IND(mSGpTR)            (mSGpTR)->ittiMsg.nas_5gmm_ind
 
 #define NAS_RAB_ESTABLI_RSP(mSGpTR)     (mSGpTR)->ittiMsg.nas_rab_est_rsp
 
@@ -84,6 +85,7 @@
 #define NAS_PAGING_IND(mSGpTR)          (mSGpTR)->ittiMsg.nas_paging_ind
 #define NAS_CONN_ESTABLI_CNF(mSGpTR)    (mSGpTR)->ittiMsg.nas_conn_establi_cnf
 #define NAS_CONN_RELEASE_IND(mSGpTR)    (mSGpTR)->ittiMsg.nas_conn_release_ind
+#define NR_NAS_CONN_ESTABLISH_IND(mSGpTR) (mSGpTR)->ittiMsg.nr_nas_conn_establish_ind
 #define NR_NAS_CONN_RELEASE_IND(mSGpTR) (mSGpTR)->ittiMsg.nr_nas_conn_release_ind
 #define NAS_UPLINK_DATA_CNF(mSGpTR)     (mSGpTR)->ittiMsg.nas_ul_data_cnf
 #define NAS_DOWNLINK_DATA_IND(mSGpTR)   (mSGpTR)->ittiMsg.nas_dl_data_ind
diff --git a/openair2/F1AP/lib/f1ap_interface_management.c b/openair2/F1AP/lib/f1ap_interface_management.c
index 08f324a6188a48be99b45332231906261e8de28a..4d8c4fcccf11c1c80798c53d9725ebfe5480b290 100644
--- a/openair2/F1AP/lib/f1ap_interface_management.c
+++ b/openair2/F1AP/lib/f1ap_interface_management.c
@@ -404,6 +404,31 @@ static int read_slice_info(const F1AP_ServedPLMNs_Item_t *plmn, nssai_t *nssai,
   return ssl->list.count;
 }
 
+static F1AP_ProtocolExtensionContainer_10696P34_t *write_slice_info(int num_ssi, const nssai_t *nssai)
+{
+  if (num_ssi == 0)
+    return NULL;
+
+  F1AP_ProtocolExtensionContainer_10696P34_t *p = calloc_or_fail(1, sizeof(*p));
+  asn1cSequenceAdd(p->list, F1AP_ServedPLMNs_ItemExtIEs_t, served_plmns_itemExtIEs);
+  served_plmns_itemExtIEs->criticality = F1AP_Criticality_ignore;
+  served_plmns_itemExtIEs->id = F1AP_ProtocolIE_ID_id_TAISliceSupportList;
+  served_plmns_itemExtIEs->extensionValue.present = F1AP_ServedPLMNs_ItemExtIEs__extensionValue_PR_SliceSupportList;
+  F1AP_SliceSupportList_t *slice_support_list = &served_plmns_itemExtIEs->extensionValue.choice.SliceSupportList;
+
+  for (int s = 0; s < num_ssi; s++) {
+    asn1cSequenceAdd(slice_support_list->list, F1AP_SliceSupportItem_t, slice);
+    const nssai_t *n = &nssai[s];
+    INT8_TO_OCTET_STRING(n->sst, &slice->sNSSAI.sST);
+    if (n->sd != 0xffffff) {
+      asn1cCalloc(slice->sNSSAI.sD, tmp);
+      INT24_TO_OCTET_STRING(n->sd, tmp);
+    }
+  }
+
+  return p;
+}
+
 /**
  * @brief F1AP Setup Request memory management
  */
@@ -468,6 +493,8 @@ static F1AP_Served_Cell_Information_t encode_served_cell_info(const f1ap_served_
   asn1cSequenceAdd(scell_info.servedPLMNs.list, F1AP_ServedPLMNs_Item_t, servedPLMN_item);
   // PLMN Identity (M)
   MCC_MNC_TO_PLMNID(c->plmn.mcc, c->plmn.mnc, c->plmn.mnc_digit_length, &servedPLMN_item->pLMN_Identity);
+  // NSSAIs (O)
+  servedPLMN_item->iE_Extensions = (struct F1AP_ProtocolExtensionContainer *)write_slice_info(c->num_ssi, c->nssai);
   // NR-Mode-Info (M)
   F1AP_NR_Mode_Info_t *nR_Mode_Info = &scell_info.nR_Mode_Info;
   if (c->mode == F1AP_MODE_FDD) { // FDD Info
diff --git a/openair2/F1AP/lib/f1ap_lib_common.c b/openair2/F1AP/lib/f1ap_lib_common.c
index c49a87c57cca6a37c9eb2afd74f8d343a7223f5e..3673fa3cc7dfe6a1a5271780e387334486c54b74 100644
--- a/openair2/F1AP/lib/f1ap_lib_common.c
+++ b/openair2/F1AP/lib/f1ap_lib_common.c
@@ -57,6 +57,11 @@ bool eq_f1ap_cell_info(const f1ap_served_cell_info_t *a, const f1ap_served_cell_
     return false;
   if (a->tac)
     _F1_EQ_CHECK_INT(*a->tac, *b->tac);
+  _F1_EQ_CHECK_INT(a->num_ssi, b->num_ssi);
+  for (int i = 0; i < a->num_ssi; ++i) {
+    _F1_EQ_CHECK_INT(a->nssai[i].sst, b->nssai[i].sst);
+    _F1_EQ_CHECK_INT(a->nssai[i].sd, b->nssai[i].sd);
+  }
   _F1_EQ_CHECK_INT(a->mode, b->mode);
   if (a->mode == F1AP_MODE_TDD) {
     /* TDD */
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 f6e3129ce931cc7b8fcf9467f81ebcbdd51de514..77319d201322a573754983140e1e741e007c3992 100644
--- a/openair2/LAYER2/NR_MAC_UE/nr_ue_dci_configuration.c
+++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_dci_configuration.c
@@ -39,9 +39,7 @@
 #include "executables/softmodem-common.h"
 #include <stdio.h>
 
-void fill_dci_search_candidates(const NR_SearchSpace_t *ss,
-                                fapi_nr_dl_config_dci_dl_pdu_rel15_t *rel15,
-                                const uint32_t Y)
+void fill_dci_search_candidates(const NR_SearchSpace_t *ss, fapi_nr_dl_config_dci_dl_pdu_rel15_t *rel15, const uint32_t Y)
 {
   LOG_T(NR_MAC_DCI, "Filling search candidates for DCI\n");
 
@@ -320,6 +318,11 @@ void config_dci_pdu(NR_UE_MAC_INST_t *mac,
   if (ss->searchSpaceType->present == NR_SearchSpace__searchSpaceType_PR_ue_Specific)
     Y = get_Y(ss, slot, rel15->rnti);
   fill_dci_search_candidates(ss, rel15, Y);
+  // not scheduling DCI reception if there are no candidates
+  if (rel15->number_of_candidates == 0) {
+    LOG_E(NR_MAC, "No candidates in this DCI, not scheduling it");
+    return;
+  }
 
   #ifdef DEBUG_DCI
     for (int i = 0; i < rel15->num_dci_options; i++) {
diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c
index d4b9c973eeb36a6e4a73a15f663ec62c1cb8de98..a8c434b62c665d44f49ee2239d471821a660bdb9 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c
@@ -2248,7 +2248,13 @@ static void nr_generate_Msg4_MsgB(module_id_t module_idP,
       nr_clear_ra_proc(ra);
     } else {
       ra->ra_state = nrRA_WAIT_Msg4_MsgB_ACK;
-      LOG_I(NR_MAC,"UE %04x Generate msg4: feedback at %4d.%2d, payload %d bytes, next state WAIT_Msg4_ACK\n", ra->rnti, pucch->frame, pucch->ul_slot, harq->tb_size);
+      LOG_I(NR_MAC,
+            "UE %04x Generate %s: feedback at %4d.%2d, payload %d bytes, next state nrRA_WAIT_Msg4_MsgB_ACK\n",
+            ra->rnti,
+            ra_type_str,
+            pucch->frame,
+            pucch->ul_slot,
+            harq->tb_size);
     }
   }
 }
@@ -2294,7 +2300,7 @@ static void nr_check_Msg4_MsgB_Ack(module_id_t module_id, int CC_id, frame_t fra
         remove_nr_list(&sched_ctrl->retrans_dl_harq, current_harq_pid);
       }
     } else {
-      LOG_I(NR_MAC, "(UE %04x) Received Nack in %s, preparing retransmission!\n", ra->rnti, nrra_text[ra->ra_state]);
+      LOG_I(NR_MAC, "(UE %04x) Received Nack in %s, preparing retransmission!\n", ra->rnti, ra_type_str);
       ra->ra_state = ra->ra_type == RA_4_STEP ? nrRA_Msg4 : nrRA_MsgB;
     }
   }
diff --git a/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h b/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h
index a464611ec856a3d187e553464e51f97dd7d6d02b..b9045e15a0fe1c45e9238596fd32d534e0d20c23 100644
--- a/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h
+++ b/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h
@@ -126,7 +126,7 @@ typedef enum {
 } RA_gNB_state_t;
 
 static const char *const nrra_text[] =
-    {"IDLE", "Msg2", "WAIT_MsgA_PUSCH", "WAIT_Msg3", "Msg3_retransmission", "Msg3_dcch_dtch", "Msg4", "MsgB", "WAIT_Msg4_ACK"};
+    {"IDLE", "Msg2", "WAIT_MsgA_PUSCH", "WAIT_Msg3", "Msg3_retransmission", "Msg4", "MsgB", "WAIT_Msg4_MsgB_ACK"};
 
 typedef struct {
   int idx;
diff --git a/openair2/RRC/NR/MESSAGES/asn1_msg.c b/openair2/RRC/NR/MESSAGES/asn1_msg.c
index b66625e6b26ae9f05fb45fb21b0e8a7eee83e84c..e3df557d3dc334e779f2dda998a419e55854bd94 100644
--- a/openair2/RRC/NR/MESSAGES/asn1_msg.c
+++ b/openair2/RRC/NR/MESSAGES/asn1_msg.c
@@ -765,7 +765,7 @@ int do_RRCReconfiguration(const gNB_RRC_UE_t *UE,
     return((enc_rval.encoded+7)/8);
 }
 
-int do_RRCSetupRequest(uint8_t *buffer, size_t buffer_size, uint8_t *rv)
+int do_RRCSetupRequest(uint8_t *buffer, size_t buffer_size, uint8_t *rv, uint64_t fiveG_S_TMSI)
 {
   NR_UL_CCCH_Message_t ul_ccch_msg = {0};
   ul_ccch_msg.message.present           = NR_UL_CCCH_MessageType_PR_c1;
@@ -773,24 +773,34 @@ int do_RRCSetupRequest(uint8_t *buffer, size_t buffer_size, uint8_t *rv)
   c1->present = NR_UL_CCCH_MessageType__c1_PR_rrcSetupRequest;
   asn1cCalloc(c1->choice.rrcSetupRequest, rrcSetupRequest);
 
-  if (1) {
+  if (fiveG_S_TMSI == UINT64_MAX) {
+    /* set the ue-Identity to a random value */
     rrcSetupRequest->rrcSetupRequest.ue_Identity.present = NR_InitialUE_Identity_PR_randomValue;
     BIT_STRING_t *str = &rrcSetupRequest->rrcSetupRequest.ue_Identity.choice.randomValue;
     str->size = 5;
     str->bits_unused = 1;
-    str->buf = CALLOC(1, str->size);
+    str->buf = calloc_or_fail(str->size, sizeof(str->buf[0]));
     str->buf[0] = rv[0];
     str->buf[1] = rv[1];
     str->buf[2] = rv[2];
     str->buf[3] = rv[3];
     str->buf[4] = rv[4] & 0xfe;
   } else {
+    uint64_t fiveG_S_TMSI_part1 = fiveG_S_TMSI & ((1ULL << 39) - 1);
+    /** set the ue-Identity to ng-5G-S-TMSI-Part1
+     * ng-5G-S-TMSI-Part1: the rightmost 39 bits of 5G-S-TMSI
+     * BIT STRING (SIZE (39)) - 3GPP TS 38.331 */
+    LOG_D(NR_RRC, "5G-S-TMSI: %lu, set the ue-Identity to ng-5G-S-TMSI-Part1 %lu\n", fiveG_S_TMSI, fiveG_S_TMSI_part1);
     rrcSetupRequest->rrcSetupRequest.ue_Identity.present = NR_InitialUE_Identity_PR_ng_5G_S_TMSI_Part1;
     BIT_STRING_t *str = &rrcSetupRequest->rrcSetupRequest.ue_Identity.choice.ng_5G_S_TMSI_Part1;
-    str->size = 1;
-    str->bits_unused = 0;
-    str->buf = CALLOC(1, str->size);
-    str->buf[0] = 0x12;
+    str->size = 5;
+    str->bits_unused = 1;
+    str->buf = calloc_or_fail(str->size, sizeof(str->buf[0]));
+    str->buf[0] = (fiveG_S_TMSI_part1 >> 31) & 0xff;
+    str->buf[1] = (fiveG_S_TMSI_part1 >> 23) & 0xff;
+    str->buf[2] = (fiveG_S_TMSI_part1 >> 15) & 0xff;
+    str->buf[3] = (fiveG_S_TMSI_part1 >> 7) & 0xff;
+    str->buf[4] = (fiveG_S_TMSI_part1 << 1) & 0xff;
   }
 
   rrcSetupRequest->rrcSetupRequest.establishmentCause = NR_EstablishmentCause_mo_Signalling; //EstablishmentCause_mo_Data;
@@ -872,6 +882,8 @@ int do_RRCSetupComplete(uint8_t *buffer,
                         size_t buffer_size,
                         const uint8_t Transaction_id,
                         uint8_t sel_plmn_id,
+                        bool is_rrc_connection_setup,
+                        uint64_t fiveG_s_tmsi,
                         const int dedicatedInfoNASLength,
                         const char *dedicatedInfoNAS)
 {
@@ -887,7 +899,31 @@ int do_RRCSetupComplete(uint8_t *buffer,
   NR_RRCSetupComplete_IEs_t *ies = RrcSetupComplete->criticalExtensions.choice.rrcSetupComplete;
   ies->selectedPLMN_Identity = sel_plmn_id;
   ies->registeredAMF = NULL;
-  ies->ng_5G_S_TMSI_Value = NULL;
+  /* RRCSetup is received in response to an RRCSetupRequest
+   * set the ng-5G-S-TMSI-Value to ng-5G-S-TMSI-Part2
+   * i.e. the leftmost 9 bits of 5G-S-TMSI (5.3.3.4 of 3GPP TS 38.331) */
+  if (fiveG_s_tmsi != UINT64_MAX) {
+    if (is_rrc_connection_setup) {
+      ies->ng_5G_S_TMSI_Value = calloc_or_fail(1, sizeof(*ies->ng_5G_S_TMSI_Value));
+      ies->ng_5G_S_TMSI_Value->present = NR_RRCSetupComplete_IEs__ng_5G_S_TMSI_Value_PR_ng_5G_S_TMSI_Part2;
+      BIT_STRING_t *str = &ies->ng_5G_S_TMSI_Value->choice.ng_5G_S_TMSI_Part2;
+      str->size = 2;
+      str->bits_unused = 7;
+      str->buf = calloc_or_fail(str->size, sizeof(str->buf[0]));
+      uint16_t fiveG_s_tmsi_part2 = (fiveG_s_tmsi >> 39) & ((1ULL << 9) - 1);
+      str->buf[0] = (fiveG_s_tmsi_part2 >> (8 - str->bits_unused)) & 0xFF;
+      str->buf[1] = (fiveG_s_tmsi_part2 << str->bits_unused) & 0xFF;
+      LOG_D(NR_RRC, "5G-S-TMSI part 2 %d in RRCSetupComplete (5G-S-TMSI %ld)\n", fiveG_s_tmsi_part2, fiveG_s_tmsi);
+    } else {
+      ies->ng_5G_S_TMSI_Value = CALLOC(1, sizeof(struct NR_RRCSetupComplete_IEs__ng_5G_S_TMSI_Value));
+      ies->ng_5G_S_TMSI_Value->present = NR_RRCSetupComplete_IEs__ng_5G_S_TMSI_Value_PR_ng_5G_S_TMSI;
+      FIVEG_S_TMSI_TO_BIT_STRING(fiveG_s_tmsi, &ies->ng_5G_S_TMSI_Value->choice.ng_5G_S_TMSI);
+      LOG_D(NR_RRC, "5G-S-TMSI %lu in RRCSetupComplete\n", fiveG_s_tmsi);
+    }
+  } else {
+    LOG_D(NR_RRC, "5G-S-TMSI is not available!\n");
+    ies->ng_5G_S_TMSI_Value = NULL;
+  }
 
   memset(&ies->dedicatedNAS_Message,0,sizeof(OCTET_STRING_t));
   OCTET_STRING_fromBuf(&ies->dedicatedNAS_Message, dedicatedInfoNAS, dedicatedInfoNASLength);
diff --git a/openair2/RRC/NR/MESSAGES/asn1_msg.h b/openair2/RRC/NR/MESSAGES/asn1_msg.h
index d7642ca663a35676fea11367fb62be0e5bb7a6e3..a6c5e25aeceffc79262442c00e2d83a35e33fc4d 100644
--- a/openair2/RRC/NR/MESSAGES/asn1_msg.h
+++ b/openair2/RRC/NR/MESSAGES/asn1_msg.h
@@ -119,12 +119,14 @@ int do_RRCSetupComplete(uint8_t *buffer,
                         size_t buffer_size,
                         const uint8_t Transaction_id,
                         uint8_t sel_plmn_id,
+                        bool is_rrc_connection_setup,
+                        uint64_t fiveG_S_TMSI,
                         const int dedicatedInfoNASLength,
                         const char *dedicatedInfoNAS);
 
 int do_NR_HandoverPreparationInformation(const uint8_t *uecap_buf, int uecap_buf_size, uint8_t *buf, int buf_size);
 
-int do_RRCSetupRequest(uint8_t *buffer, size_t buffer_size, uint8_t *rv);
+int do_RRCSetupRequest(uint8_t *buffer, size_t buffer_size, uint8_t *rv, uint64_t fiveG_S_TMSI_part1);
 
 int do_NR_RRCReconfigurationComplete_for_nsa(uint8_t *buffer, size_t buffer_size, NR_RRC_TransactionIdentifier_t Transaction_id);
 
diff --git a/openair2/RRC/NR_UE/L2_interface_ue.c b/openair2/RRC/NR_UE/L2_interface_ue.c
index b6aa5f0463bd1be9ae4118214301812b4bfb3be7..7fd34ff91c5d3b72b086b75f95e3cd8ff8ae6c0e 100644
--- a/openair2/RRC/NR_UE/L2_interface_ue.c
+++ b/openair2/RRC/NR_UE/L2_interface_ue.c
@@ -149,6 +149,7 @@ void process_msg_rcc_to_mac(MessageDef *msg)
     default:
       LOG_E(NR_MAC, "Unexpected msg from RRC: %d\n", ITTI_MSG_ID(msg));
   }
+  itti_free(ITTI_MSG_ORIGIN_ID(msg), msg);
 }
 
 void nr_mac_rrc_inactivity_timer_ind(const module_id_t mod_id)
diff --git a/openair2/RRC/NR_UE/rrc_UE.c b/openair2/RRC/NR_UE/rrc_UE.c
index 85adc82328c9c6d079fcc79f6de51bb4dbb8d362..f61ce49494fadfff7e0053e9cc34fa8f5b399636 100644
--- a/openair2/RRC/NR_UE/rrc_UE.c
+++ b/openair2/RRC/NR_UE/rrc_UE.c
@@ -276,7 +276,7 @@ static void nr_rrc_ue_prepare_RRCSetupRequest(NR_UE_RRC_INST_t *rrc)
   }
 
   uint8_t buf[1024];
-  int len = do_RRCSetupRequest(buf, sizeof(buf), rv);
+  int len = do_RRCSetupRequest(buf, sizeof(buf), rv, rrc->fiveG_S_TMSI);
 
   nr_rlc_srb_recv_sdu(rrc->ue_id, 0, buf, len);
 }
@@ -601,6 +601,8 @@ NR_UE_RRC_INST_t* nr_rrc_init_ue(char* uecap_file, int nb_inst, int num_ant_tx)
     rrc->as_security_activated = false;
     rrc->detach_after_release = false;
     rrc->reconfig_after_reestab = false;
+    /* 5G-S-TMSI */
+    rrc->fiveG_S_TMSI = UINT64_MAX;
 
     FILE *f = NULL;
     if (uecap_file)
@@ -1123,26 +1125,38 @@ static void nr_rrc_ue_process_masterCellGroup(NR_UE_RRC_INST_t *rrc,
 static void rrc_ue_generate_RRCSetupComplete(const NR_UE_RRC_INST_t *rrc, const uint8_t Transaction_id)
 {
   uint8_t buffer[100];
-  const char *nas_msg;
-  int   nas_msg_length;
+  as_nas_info_t initialNasMsg;
 
   if (IS_SA_MODE(get_softmodem_params())) {
-    as_nas_info_t initialNasMsg;
     nr_ue_nas_t *nas = get_ue_nas_info(rrc->ue_id);
     // Send Initial NAS message (Registration Request) before Security Mode control procedure
     generateRegistrationRequest(&initialNasMsg, nas, false);
-    nas_msg = (char *)initialNasMsg.nas_data;
-    nas_msg_length = initialNasMsg.length;
+    if (!initialNasMsg.nas_data) {
+      LOG_E(NR_RRC, "Failed to complete RRCSetup. NAS InitialUEMessage message not found.\n");
+      return;
+    }
   } else {
-    nas_msg = nr_nas_attach_req_imsi_dummy_NSA_case;
-    nas_msg_length = sizeof(nr_nas_attach_req_imsi_dummy_NSA_case);
+    initialNasMsg.length = sizeof(nr_nas_attach_req_imsi_dummy_NSA_case);
+    initialNasMsg.nas_data = malloc_or_fail(initialNasMsg.length);
+    memcpy(initialNasMsg.nas_data, nr_nas_attach_req_imsi_dummy_NSA_case, initialNasMsg.length);
   }
 
-  int size = do_RRCSetupComplete(buffer, sizeof(buffer), Transaction_id, rrc->selected_plmn_identity, nas_msg_length, nas_msg);
+  // Encode RRCSetupComplete
+  int size = do_RRCSetupComplete(buffer,
+                                 sizeof(buffer),
+                                 Transaction_id,
+                                 rrc->selected_plmn_identity,
+                                 rrc->ra_trigger == RRC_CONNECTION_SETUP,
+                                 rrc->fiveG_S_TMSI,
+                                 (const uint32_t)initialNasMsg.length,
+                                 (const char*)initialNasMsg.nas_data);
+
+  // Free dynamically allocated data (heap allocated in both SA and NSA)
+  free(initialNasMsg.nas_data);
+
   LOG_I(NR_RRC, "[UE %ld][RAPROC] Logical Channel UL-DCCH (SRB1), Generating RRCSetupComplete (bytes%d)\n", rrc->ue_id, size);
   int srb_id = 1; // RRC setup complete on SRB1
   LOG_D(NR_RRC, "[RRC_UE %ld] PDCP_DATA_REQ/%d Bytes RRCSetupComplete ---> %d\n", rrc->ue_id, size, srb_id);
-
   nr_pdcp_data_req_srb(rrc->ue_id, srb_id, 0, size, buffer, deliver_pdu_srb_rlc, NULL);
 }
 
@@ -1182,6 +1196,10 @@ static void nr_rrc_process_rrcsetup(NR_UE_RRC_INST_t *rrc,
   // enter RRC_CONNECTED
   rrc->nrRrcState = RRC_STATE_CONNECTED_NR;
 
+  // Indicate to NAS that the RRC connection has been established (5.3.1.3 of 3GPP TS 24.501)
+  MessageDef *msg_p = itti_alloc_new_message(TASK_RRC_NRUE, 0, NR_NAS_CONN_ESTABLISH_IND);
+  itti_send_msg_to_task(TASK_NAS_NRUE, rrc->ue_id, msg_p);
+
   // set the content of RRCSetupComplete message
   // TODO procedues described in 5.3.3.4 seems more complex than what we actualy do
   rrc_ue_generate_RRCSetupComplete(rrc, rrcSetup->rrc_TransactionIdentifier);
@@ -2094,6 +2112,12 @@ void *rrc_nrue(void *notUsed)
     break;
   }
 
+  case NAS_5GMM_IND: {
+    nas_5gmm_ind_t *req = &NAS_5GMM_IND(msg_p);
+    rrc->fiveG_S_TMSI = req->fiveG_STMSI;
+    break;
+  }
+
   default:
     LOG_E(NR_RRC, "[UE %ld] Received unexpected message %s\n", rrc->ue_id, ITTI_MSG_NAME(msg_p));
     break;
@@ -2538,6 +2562,8 @@ void nr_rrc_going_to_IDLE(NR_UE_RRC_INST_t *rrc,
 
   // discard the keys (only kgnb is stored)
   memset(rrc->kgnb, 0, sizeof(rrc->kgnb));
+  rrc->integrityProtAlgorithm = 0;
+  rrc->cipheringAlgorithm = 0;
 
   // release all radio resources, including release of the RLC entity,
   // the MAC configuration and the associated PDCP entity
diff --git a/openair2/RRC/NR_UE/rrc_defs.h b/openair2/RRC/NR_UE/rrc_defs.h
index 29c03afd5fb2278289129ed94fa7cbdf8eb3aa2d..ee46a343d78a7f185ad6822727a5d0a84a32c44f 100644
--- a/openair2/RRC/NR_UE/rrc_defs.h
+++ b/openair2/RRC/NR_UE/rrc_defs.h
@@ -239,6 +239,9 @@ typedef struct NR_UE_RRC_INST_s {
   Rrc_State_NR_t nrRrcState;
   // flag to identify 1st reconfiguration after reestablishment
   bool reconfig_after_reestab;
+  // 5G-S-TMSI
+  uint64_t fiveG_S_TMSI;
+
   //Sidelink params
   NR_SL_PreconfigurationNR_r16_t *sl_preconfig;
   // NTN params
diff --git a/openair3/NAS/NR_UE/nr_nas_msg.c b/openair3/NAS/NR_UE/nr_nas_msg.c
index 3c8da56280caae97f1d35cf6df9e6ffb34e6f641..64a541aa788a1ff9b0344c99226b84ce33cdc593 100644
--- a/openair3/NAS/NR_UE/nr_nas_msg.c
+++ b/openair3/NAS/NR_UE/nr_nas_msg.c
@@ -77,6 +77,8 @@ static nr_ue_nas_t nr_ue_nas[MAX_NAS_UE] = {0};
   TYPE_DEF(NAS_SECURITY_INTEGRITY_PASSED, 4)     \
   TYPE_DEF(NAS_SECURITY_BAD_INPUT, 5)
 
+const char *nr_release_cause_desc[] = {"RRC_CONNECTION_FAILURE", "RRC_RESUME_FAILURE", "OTHER"};
+
 typedef enum { FOREACH_STATE(TO_ENUM) } security_state_t;
 
 static const text_info_t security_state_info[] = {FOREACH_STATE(TO_TEXT)};
@@ -661,6 +663,12 @@ void generateRegistrationRequest(as_nas_info_t *initialNasMsg, nr_ue_nas_t *nas,
       nasmessagecontainercontents->length = mm_msg_encode(&full_mm, nasmessagecontainercontents->value, size_nct);
       size += (nasmessagecontainercontents->length + 2);
       rr->presencemask |= REGISTRATION_REQUEST_NAS_MESSAGE_CONTAINER_PRESENT;
+      // Workaround to pass integrity in RRC_IDLE
+      uint8_t *kamf = nas->security.kamf;
+      uint8_t *kgnb = nas->security.kgnb;
+      derive_kgnb(kamf, nas->security.nas_count_ul, kgnb);
+      int nas_itti_kgnb_refresh_req(instance_t instance, const uint8_t kgnb[32]);
+      nas_itti_kgnb_refresh_req(nas->UE_id, nas->security.kgnb);
     }
     // Allocate buffer (including NAS message container size)
     initialNasMsg->nas_data = malloc_or_fail(size * sizeof(*initialNasMsg->nas_data));
@@ -1365,6 +1373,15 @@ static void send_nas_detach_req(nr_ue_nas_t *nas, bool wait_release)
   itti_send_msg_to_task(TASK_RRC_NRUE, nas->UE_id, msg);
 }
 
+static void send_nas_5gmm_ind(instance_t instance, const Guti5GSMobileIdentity_t *guti)
+{
+  MessageDef *msg = itti_alloc_new_message(TASK_NAS_NRUE, 0, NAS_5GMM_IND);
+  nas_5gmm_ind_t *ind = &NAS_5GMM_IND(msg);
+  LOG_I(NR_RRC, "5G-GUTI: AMF pointer %u, AMF Set ID %u, 5G-TMSI %u \n", guti->amfpointer, guti->amfsetid, guti->tmsi);
+  ind->fiveG_STMSI = ((uint64_t)guti->amfsetid << 38) | ((uint64_t)guti->amfpointer << 32) | guti->tmsi;
+  itti_send_msg_to_task(TASK_RRC_NRUE, instance, msg);
+}
+
 static void request_default_pdusession(nr_ue_nas_t *nas)
 {
   MessageDef *message_p = itti_alloc_new_message(TASK_NAS_NRUE, nas->UE_id, NAS_PDU_SESSION_REQ);
@@ -1439,6 +1456,9 @@ static void handle_registration_accept(nr_ue_nas_t *nas, const uint8_t *pdu_buff
     LOG_W(NAS, "no GUTI in registration accept\n");
   }
 
+  if(nas->guti)
+    send_nas_5gmm_ind(nas->UE_id, nas->guti);
+
   as_nas_info_t initialNasMsg = {0};
   generateRegistrationComplete(nas, &initialNasMsg, NULL);
   if (initialNasMsg.length > 0) {
@@ -1481,11 +1501,6 @@ void *nas_nrue(void *args_p)
               NAS_CELL_SELECTION_CNF(msg_p).errCode,
               NAS_CELL_SELECTION_CNF(msg_p).cellID,
               NAS_CELL_SELECTION_CNF(msg_p).tac);
-        // as_stmsi_t s_tmsi={0, 0};
-        // as_nas_info_t nas_info;
-        // plmn_t plmnID={0, 0, 0, 0};
-        // generateRegistrationRequest(&nas_info);
-        // nr_nas_itti_nas_establish_req(0, AS_TYPE_ORIGINATING_SIGNAL, s_tmsi, plmnID, nas_info.data, nas_info.length, 0);
         break;
 
       case NAS_CELL_SELECTION_IND:
@@ -1516,6 +1531,16 @@ void *nas_nrue(void *args_p)
         break;
       }
 
+      case NR_NAS_CONN_ESTABLISH_IND: {
+        nas->fiveGMM_mode = FGS_CONNECTED;
+        LOG_I(NAS,
+              "[UE %ld] Received %s: asCause %u\n",
+              nas->UE_id,
+              ITTI_MSG_NAME(msg_p),
+              NR_NAS_CONN_ESTABLISH_IND(msg_p).asCause);
+        break;
+      }
+
       case NAS_CONN_ESTABLI_CNF: {
         LOG_I(NAS,
               "[UE %ld] Received %s: errCode %u, length %u\n",
@@ -1546,8 +1571,12 @@ void *nas_nrue(void *args_p)
         break;
       }
 
-      case NR_NAS_CONN_RELEASE_IND:
-        LOG_I(NAS, "[UE %ld] Received %s: cause %u\n", nas->UE_id, ITTI_MSG_NAME(msg_p), NR_NAS_CONN_RELEASE_IND(msg_p).cause);
+      case NR_NAS_CONN_RELEASE_IND: {
+        LOG_I(NAS, "[UE %ld] Received %s: cause %s\n",
+              nas->UE_id, ITTI_MSG_NAME (msg_p), nr_release_cause_desc[NR_NAS_CONN_RELEASE_IND (msg_p).cause]);
+        /* In N1 mode, upon indication from lower layers that the access stratum connection has been released,
+           the UE shall enter 5GMM-IDLE mode and consider the N1 NAS signalling connection released (3GPP TS 24.501) */
+        nas->fiveGMM_mode = FGS_IDLE;
         // TODO handle connection release
         if (nas->termination_procedure) {
           /* the following is not clean, but probably necessary: we need to give
@@ -1558,7 +1587,7 @@ void *nas_nrue(void *args_p)
           itti_wait_tasks_unblock(); /* will unblock ITTI to stop nr-uesoftmodem */
         }
         break;
-
+      }
       case NAS_UPLINK_DATA_CNF:
         LOG_I(NAS,
               "[UE %ld] Received %s: UEid %u, errCode %u\n",
diff --git a/radio/rfsimulator/apply_channelmod.c b/radio/rfsimulator/apply_channelmod.c
index cb8e75abdf1dadd84f8297f058f814c06a9d3f33..60d3afbe8339fb234aaa7444b7abece301b82db1 100644
--- a/radio/rfsimulator/apply_channelmod.c
+++ b/radio/rfsimulator/apply_channelmod.c
@@ -42,12 +42,13 @@
   legacy: we regenerate each sub frame in UL, and each frame only in DL
 */
 void rxAddInput(const c16_t *input_sig,
-                c16_t *after_channel_sig,
+                cf_t *after_channel_sig,
                 int rxAnt,
                 channel_desc_t *channelDesc,
                 int nbSamples,
                 uint64_t TS,
-                uint32_t CirSize)
+                uint32_t CirSize,
+                bool add_noise)
 {
   if ((channelDesc->sat_height > 0) && (channelDesc->enable_dynamic_delay || channelDesc->enable_dynamic_Doppler)) { // model for transparent satellite on circular orbit
     /* assumptions:
@@ -127,12 +128,12 @@ void rxAddInput(const c16_t *input_sig,
   const double pathLossLinear = pow(10,channelDesc->path_loss_dB/20.0);
   // Energy in one sample to calibrate input noise
   // the normalized OAI value seems to be 256 as average amplitude (numerical amplification = 1)
-  const double noise_per_sample = pow(10,channelDesc->noise_power_dB/10.0) * 256;
+  const double noise_per_sample = add_noise ? pow(10,channelDesc->noise_power_dB/10.0) * 256 : 0;
   const uint64_t dd = channelDesc->channel_offset;
   const int nbTx=channelDesc->nb_tx;
 
   for (int i=0; i<nbSamples; i++) {
-    struct complex16 *out_ptr=after_channel_sig+i;
+    cf_t *out_ptr = after_channel_sig + i;
     struct complexd rx_tmp= {0};
 
     for (int txAnt=0; txAnt < nbTx; txAnt++) {
@@ -166,8 +167,8 @@ void rxAddInput(const c16_t *input_sig,
       channelDesc->Doppler_phase_cur[rxAnt] += channelDesc->Doppler_phase_inc;
     }
 
-    out_ptr->r = lround(rx_tmp.r*pathLossLinear + noise_per_sample*gaussZiggurat(0.0,1.0));
-    out_ptr->i = lround(rx_tmp.i*pathLossLinear + noise_per_sample*gaussZiggurat(0.0,1.0));
+    out_ptr->r += rx_tmp.r * pathLossLinear + noise_per_sample * gaussZiggurat(0.0, 1.0);
+    out_ptr->i += rx_tmp.i * pathLossLinear + noise_per_sample * gaussZiggurat(0.0, 1.0);
     out_ptr++;
   }
 
diff --git a/radio/rfsimulator/rfsimulator.h b/radio/rfsimulator/rfsimulator.h
index 068250a149f5cd218ba65f4d3916908e9de8eab5..11a57193ca6f7554c215f531dba3ffae22c28496 100644
--- a/radio/rfsimulator/rfsimulator.h
+++ b/radio/rfsimulator/rfsimulator.h
@@ -23,13 +23,15 @@
 
 #ifndef __RFSIMULATOR_H
 #define  __RFSIMULATOR_H
+#include <stdbool.h>
 void rxAddInput( const c16_t *input_sig,
-                 c16_t *after_channel_sig,
+                 cf_t *after_channel_sig,
                  int rxAnt,
                  channel_desc_t *channelDesc,
                  int nbSamples,
                  uint64_t TS,
-                 uint32_t CirSize
+                 uint32_t CirSize,
+                 bool apply_noise
                );
 
 #endif
diff --git a/radio/rfsimulator/simulator.c b/radio/rfsimulator/simulator.c
index 262cb87deb28a8ba7d56653abdcb17da081c5a29..c733f4c8a26e11fa5b0cbf8024742a88e9f1421d 100644
--- a/radio/rfsimulator/simulator.c
+++ b/radio/rfsimulator/simulator.c
@@ -177,7 +177,6 @@ typedef struct {
   double chan_pathloss;
   double chan_forgetfact;
   uint64_t chan_offset;
-  float  noise_power_dB;
   void *telnetcmd_qid;
   poll_telnetcmdq_func_t poll_telnetcmdq;
   int wait_timeout;
@@ -456,7 +455,7 @@ static int rfsimu_setchanmod_cmd(char *buff, int debug, telnet_printfunc_t prnt,
                                                           t->chan_forgetfact, // forgetting_factor
                                                           t->chan_offset, // propagation delay in samples
                                                           t->chan_pathloss,
-                                                          t->noise_power_dB); // path_loss in dB
+                                                          0); // noise_power
           set_channeldesc_owner(newmodel, RFSIMU_MODULEID);
           set_channeldesc_name(newmodel,modelname);
           random_channel(newmodel,false);
@@ -1004,10 +1003,17 @@ static int rfsimulator_read(openair0_device *device, openair0_timestamp *ptimest
     } while (have_to_wait);
   }
 
+
+  struct timespec start_time;
+  int ret = clock_gettime(CLOCK_REALTIME, &start_time);
+  AssertFatal(ret == 0, "clock_gettime() failed: errno %d, %s\n", errno, strerror(errno));
+
   // Clear the output buffer
   for (int a=0; a<nbAnt; a++)
     memset(samplesVoid[a],0,sampleToByte(nsamps,1));
-
+  cf_t temp_array[nbAnt][nsamps];
+  bool apply_noise_per_channel = get_noise_power_dBFS() == INVALID_DBFS_VALUE;
+  int num_chanmod_channels = 0;
   // Add all input nodes signal in the output buffer
   for (int sock = 0; sock < MAX_FD_RFSIMU; sock++) {
     buffer_t *ptr=&t->buf[sock];
@@ -1025,12 +1031,18 @@ static int rfsimulator_read(openair0_device *device, openair0_timestamp *ptimest
 
       for (int a=0; a<nbAnt; a++) {//loop over number of Rx antennas
         if ( ptr->channel_model != NULL ) { // apply a channel model
-          rxAddInput(ptr->circularBuf, (c16_t *) samplesVoid[a],
+          if (num_chanmod_channels == 0) {
+            memset(temp_array, 0, sizeof(temp_array));
+          }
+          num_chanmod_channels++;
+          rxAddInput(ptr->circularBuf,
+                     temp_array[a],
                      a,
                      ptr->channel_model,
                      nsamps,
                      t->nextRxTstamp,
-                     CirSize);
+                     CirSize,
+                     apply_noise_per_channel);
         }
         else { // no channel modeling
           int nbAnt_tx = ptr->th.nbAnt; // number of Tx antennas
@@ -1064,6 +1076,37 @@ static int rfsimulator_read(openair0_device *device, openair0_timestamp *ptimest
       } // end for a (number of rx antennas)
     }
   }
+  if (apply_noise_per_channel && num_chanmod_channels > 0) {
+    // Noise is already applied through the channel model
+    for (int a = 0; a < nbAnt; a++) {
+      sample_t *out = (sample_t *)samplesVoid[a];
+      for (int i = 0; i < nsamps; i++) {
+        out[i].r += lroundf(temp_array[a][i].r);
+        out[i].i += lroundf(temp_array[a][i].i);
+      }
+    }
+  } else if (num_chanmod_channels > 0) {
+    // Apply noise from global setting
+    int16_t noise_power = (int16_t)(32767.0 / powf(10.0, .05 * -get_noise_power_dBFS()));
+    for (int a = 0; a < nbAnt; a++) {
+      sample_t *out = (sample_t *)samplesVoid[a];
+      for (int i = 0; i < nsamps; i++) {
+        out[i].r += lroundf(temp_array[a][i].r + noise_power * gaussZiggurat(0.0, 1.0));
+        out[i].i += lroundf(temp_array[a][i].i + noise_power * gaussZiggurat(0.0, 1.0));
+      }
+    }
+  }
+
+  struct timespec end_time;
+  ret = clock_gettime(CLOCK_REALTIME, &end_time);
+  AssertFatal(ret == 0, "clock_gettime() failed: errno %d, %s\n", errno, strerror(errno));
+  double diff_ns = (end_time.tv_sec - start_time.tv_sec) * 1000000000 + (end_time.tv_nsec - start_time.tv_nsec);
+  static double average = 0.0;
+  average = (average * 0.98) + ( nsamps / (diff_ns / 1e9) * 0.02);
+  static int calls = 0;
+  if (calls++ % 10000 == 0) {
+    LOG_D(HW, "Rfsimulator: velocity %.2f Msps, realtime requirements %.2f Msps\n", average / 1e6, t->sample_rate / 1e6);
+  }
 
   *ptimestamp = t->nextRxTstamp; // return the time of the first sample
   t->nextRxTstamp+=nsamps;