diff --git a/d2d_emulator_setup.txt b/d2d_emulator_setup.txt
index a6b87e923aa937f36ccf7024c8cadb8bf00c4b13..346eb49c9ed528020cb8efdc54e23b69dae26f47 100644
--- a/d2d_emulator_setup.txt
+++ b/d2d_emulator_setup.txt
@@ -33,8 +33,8 @@ OAI build/execute
  - cp ../../../targets/bin/.ue* .
  - cp ../../../targets/bin/.usim* .
  - sudo insmod ../../../targets/bin/ue_ip.ko
- 
- UE1: 
+
+UE1: 
  - sudo ifconfig oip0 10.0.0.1
  - sudo iptables -A POSTROUTING  -t mangle -o oip0 -d 224.0.0.1 -j MARK --set-mark 3
  - (if necessary) sudo route add default gw 10.10.10.1 eth0
@@ -42,8 +42,11 @@ UE2:
  - sudo ifconfig oip1 10.0.0.2
  - sudo iptables -A POSTROUTING  -t mangle -o oip1 -d 224.0.0.1 -j MARK --set-mark 3
  - (if necessary) sudo route add default gw 10.10.10.1 eth0
-Run UE1, then UE2
-- sudo ./lte-softmodem-stub -U --emul_iface eth0
+
+TEST ONE-TO-MANY
+Run UE1 then UE2, for example:
+UE1: sudo ./lte-softmodem-stub -U --emul_iface eth0
+UE2: sudo ./lte-softmodem-stub -U --emul_iface eno1
 
 Test with Ping
 - Sender - UE1: ping -I oip0 224.0.0.1
@@ -53,8 +56,6 @@ Test with Iperf
 - Sender - UE1: iperf -c 224.0.0.1 -u -b 0.1M --bind 10.0.0.1 -t 100
 - Receiver - UE2: sudo ./mcreceive 224.0.0.1 5001 
 
-
-
  
  
 
diff --git a/openair2/LAYER2/MAC/defs.h b/openair2/LAYER2/MAC/defs.h
index 8722afa33128b9b8095360e3d847a8a1cc676e62..be0bff8f73f50fad80a7a39d8ea6766a045582c5 100644
--- a/openair2/LAYER2/MAC/defs.h
+++ b/openair2/LAYER2/MAC/defs.h
@@ -1368,6 +1368,7 @@ typedef struct {
   int sltx_active;
   SLSCH_t slsch;
   ULSCH_PDU slsch_pdu;
+  int slsch_lcid;
 #endif
   /// number of attempt for rach
   uint8_t RA_attempt_number;
diff --git a/openair2/LAYER2/MAC/ue_procedures.c b/openair2/LAYER2/MAC/ue_procedures.c
index 8adf78bb605669f1976770cd0f6cc96c1eed26eb..1880b0ae86f3e4ab6fecfca2e96cbacd6caa0fea 100644
--- a/openair2/LAYER2/MAC/ue_procedures.c
+++ b/openair2/LAYER2/MAC/ue_procedures.c
@@ -77,6 +77,7 @@ extern UL_IND_t *UL_INFO;
 extern uint8_t  nfapi_mode;
 
 /*
+ *
 #ifndef USER_MODE
 #define msg debug_msg
 #endif
@@ -753,7 +754,6 @@ void ue_send_sl_sdu(module_id_t module_idP,
 
   int rlc_sdu_len;
   char *rlc_sdu;
-  uint32_t sourceL2Id;
   uint32_t destinationL2Id =0x00000000;
 
   // Notes: 1. no control elements are supported yet
@@ -762,7 +762,7 @@ void ue_send_sl_sdu(module_id_t module_idP,
   // extract header
   SLSCH_SUBHEADER_24_Bit_DST_LONG *longh = (SLSCH_SUBHEADER_24_Bit_DST_LONG *)sdu;
   AssertFatal(longh->E==0,"E is non-zero\n");
-  AssertFatal(longh->LCID==3,"LCID is %d (not 3)\n",longh->LCID);
+  AssertFatal(((longh->LCID==3)|(longh->LCID==10)),"LCID is %d (not 3 or 10)\n",longh->LCID);
   //filter incoming packet based on destination address
   destinationL2Id = (longh->DST07<<16) | (longh->DST815 <<8) | (longh->DST1623);
   LOG_I( MAC, "[DestinationL2Id:  %"PRIu32"]  \n", destinationL2Id );
@@ -771,7 +771,6 @@ void ue_send_sl_sdu(module_id_t module_idP,
      LOG_I( MAC, "[Destination Id is neither matched with Source Id nor with Group Id, drop the packet!!! \n");
      return;
   }
-  //AssertFatal(((destinationL2Id == UE_mac_inst[module_idP].sourceL2Id) | (destinationL2Id == UE_mac_inst[module_idP].groupL2Id)), "Destination Id is neither matched with Source Id nor with Group Id \n")
 
   if (longh->F==1) {
     rlc_sdu_len = ((longh->L_MSB<<8)&0x7F00)|(longh->L_LSB&0xFF);
@@ -788,7 +787,7 @@ void ue_send_sl_sdu(module_id_t module_idP,
 		   frameP,
 		   ENB_FLAG_NO,
 		   MBMS_FLAG_NO,
-		   3,
+		   longh->LCID, //3/10
 		   rlc_sdu,
 		   rlc_sdu_len,
 		   1,
@@ -2736,11 +2735,12 @@ SLDCH_t *ue_get_sldch(module_id_t Mod_id,int CC_id,frame_t frame_tx,sub_frame_t
 
 SLSCH_t *ue_get_slsch(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subframeP) {
 
-  mac_rlc_status_resp_t rlc_status;
+  mac_rlc_status_resp_t rlc_status, rlc_status_data;
   uint32_t absSF = (frameP*10)+subframeP;
   UE_MAC_INST *ue = &UE_mac_inst[module_idP];
   int rvtab[4] = {0,2,3,1};
   int sdu_length;
+
   // Note: this is hard-coded for now for the default SL configuration (4 SF PSCCH, 36 SF PSSCH)
   SLSCH_t *slsch = &UE_mac_inst[module_idP].slsch;
 
@@ -2748,13 +2748,25 @@ SLSCH_t *ue_get_slsch(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_
 
   if ((absSF%40) == 0) { // fill PSCCH data later in first subframe of SL period
     ue->sltx_active = 0;
+
     rlc_status = mac_rlc_status_ind(module_idP, 0x1234,0,frameP,subframeP,ENB_FLAG_NO,MBMS_FLAG_NO,
-				    3,
-				    0xFFFF);
-    if (rlc_status.bytes_in_buffer > 2) {
-      LOG_I(MAC,"SFN.SF %d.%d: Scheduling for %d bytes in Sidelink buffer\n",frameP,subframeP,rlc_status.bytes_in_buffer);
-      // Fill in group id for off-network communications
-      ue->sltx_active = 1;
+				    10,
+				    0xFFFF);//for signaling - hardcoded
+    rlc_status_data = mac_rlc_status_ind(module_idP, 0x1234,0,frameP,subframeP,ENB_FLAG_NO,MBMS_FLAG_NO,
+                3,
+                0xFFFF); //for data - hardcoded
+
+    if (rlc_status.bytes_in_buffer > 2){
+       LOG_I(MAC,"SFN.SF %d.%d: Scheduling for %d bytes in Sidelink buffer\n",frameP,subframeP,rlc_status.bytes_in_buffer);
+       // Fill in group id for off-network communications
+       ue->sltx_active = 1;
+       ue->slsch_lcid = 10;
+    }
+    else if (rlc_status_data.bytes_in_buffer >2){
+       LOG_I(MAC,"SFN.SF %d.%d: Scheduling for %d bytes in Sidelink buffer\n",frameP,subframeP,rlc_status_data.bytes_in_buffer);
+       // Fill in group id for off-network communications
+       ue->sltx_active = 1;
+       ue->slsch_lcid = 3;
     }
   } // we're not in the SCCH period
   else if (((absSF & 3) == 0 ) && 
@@ -2762,14 +2774,15 @@ SLSCH_t *ue_get_slsch(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_
     // 10 PRBs, mcs 19
     int TBS = 4584/8;
     int req;
-    
-    
-    rlc_status = mac_rlc_status_ind(module_idP, 0x1234,0,frameP,subframeP,ENB_FLAG_NO,MBMS_FLAG_NO,
-				    3,
-				    0xFFFF);
+
+    if (ue->slsch_lcid == 10) {
     if (TBS<=rlc_status.bytes_in_buffer) req=TBS;
     else req = rlc_status.bytes_in_buffer;
-    
+    } else if (ue->slsch_lcid == 3){
+       if (TBS<=rlc_status_data.bytes_in_buffer) req=TBS;
+       else req = rlc_status_data.bytes_in_buffer;
+    }
+
     if (req>0) {
       sdu_length = mac_rlc_data_req(module_idP,
 				    0x1234,
@@ -2777,7 +2790,7 @@ SLSCH_t *ue_get_slsch(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_
 				    frameP,
 				    ENB_FLAG_NO,
 				    MBMS_FLAG_NO,
-				    3,				    
+				    ue->slsch_lcid,
 				    req,
 				    (char*)(ue->slsch_pdu.payload + sizeof(SLSCH_SUBHEADER_24_Bit_DST_LONG)));
       
@@ -2787,8 +2800,8 @@ SLSCH_t *ue_get_slsch(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_
       if (sdu_length > 0) {
 
 	LOG_I(MAC,"SFN.SF %d.%d : got %d bytes from Sidelink buffer (%d requested)\n",frameP,subframeP,sdu_length,req);
-	LOG_I(MAC,"sourceL2Id %d: \n",ue->sourceL2Id);
-	LOG_I(MAC,"groupL2Id %d: \n",ue->groupL2Id);
+	LOG_I(MAC,"sourceL2Id: %d \n",ue->sourceL2Id);
+	LOG_I(MAC,"groupL2Id: %d \n",ue->groupL2Id);
 
 	slsch->payload = (unsigned char*)ue->slsch_pdu.payload;
 	if (sdu_length < 128) { 
@@ -2797,14 +2810,7 @@ SLSCH_t *ue_get_slsch(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_
 	  shorth->F=0;
 	  shorth->L=sdu_length;
 	  shorth->E=0;
-	  shorth->LCID=3;
-	  /* shorth->SRC07=0x12;
-	  shorth->SRC1623=0x56;
-	  shorth->SRC815=0x34;
-	  shorth->DST07=0x78;
-	  shorth->DST815=0x9A;
-	  shorth->DST1623=0xBC;*/
-
+	  shorth->LCID=ue->slsch_lcid;
 	  shorth->SRC07 = (ue->sourceL2Id>>16) & 0x000000ff;
 	  shorth->SRC815 = (ue->sourceL2Id>>8) & 0x000000ff;
 	  shorth->SRC1623 = ue->sourceL2Id & 0x000000ff;
@@ -2820,15 +2826,7 @@ SLSCH_t *ue_get_slsch(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_
 	  longh->L_LSB=sdu_length&0xff;
 	  longh->L_MSB=(sdu_length>>8)&0x7f;
 	  longh->E=0;
-	  longh->LCID=3;
-	  /*
-	  longh->SRC07=0x12;
-	  longh->SRC815=0x34;
-	  longh->SRC1623=0x56;
-	  longh->DST07=0x78;
-	  longh->DST815=0x9A;
-	  longh->DST1623=0xBC;
-	  */
+	  longh->LCID=ue->slsch_lcid;
 	  longh->SRC07 = (ue->sourceL2Id >>16) & 0x000000ff;
 	  longh->SRC815 = (ue->sourceL2Id>>8) & 0x000000ff;
 	  longh->SRC1623 = ue->sourceL2Id & 0x000000ff;
diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp.h b/openair2/LAYER2/PDCP_v10.1.0/pdcp.h
index 30a45acc72fc9d7183b156a4bd85f5e8112bf251..8a955e55cd5369e9e9d82443a232e8a9162f9c36 100644
--- a/openair2/LAYER2/PDCP_v10.1.0/pdcp.h
+++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp.h
@@ -403,6 +403,54 @@ struct pdcp_netlink_element_s {
   uint8_t *data;
 };
 
+//TTN for D2D (PC5S)
+#ifdef Rel14
+#define PDCP_SOCKET_PORT_NO 9999 //temporary value
+int pdcp_pc5_sockfd;
+struct sockaddr_in prose_app_addr;
+struct sockaddr_in pdcp_sin;
+int pdcp_pc5_socket_init();
+
+typedef enum SL_PC5S_TYPES_e {
+  SL_PC5S_INIT=1,
+  SL_DIRECT_COMMUNICATION_REQUEST,
+  SL_DIRECT_COMMUNICATION_ACCEPT,
+  SL_DIRECT_COMMUNICATION_REJECT,
+  SL_DIRECT_SECURITY_MODE_COMMAND,
+  SL_DIRECT_SECURITY_MODE_COMPLETE
+} SL_PC5S_TYPES_t;
+
+typedef struct  {
+   SL_PC5S_TYPES_t   msg_type;
+   uint16_t  rb_id;
+   int32_t   data_size;
+   uint8_t   inst;
+} __attribute__((__packed__)) pdcp_data_header_t;
+
+//should be completed with other IEs (3GPP TS 24.334)
+typedef struct {
+   uint16_t sequenceNumber;
+   uint8_t ipAddressConfig;
+} __attribute__((__packed__)) PC5SDirectCommunicationRequest;
+
+typedef struct {
+   uint16_t sequenceNumber;
+   uint8_t ipAddressConfig;
+} __attribute__((__packed__)) PC5SDirectCommunicationAccept;
+
+//example of PC5-S messages
+typedef struct  {
+   pdcp_data_header_t pdcp_data_header;
+   union {
+      PC5SDirectCommunicationRequest pc5s_direct_communication_req;
+      PC5SDirectCommunicationAccept pc5s_direct_communication_accept;
+      uint8_t status;
+   } pc5sPrimitive;
+} __attribute__((__packed__)) sidelink_pc5s_element;
+
+#endif
+
+
 #if 0
 /*
  * Missing PDU information struct, a copy of this will be enqueued
diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c
index 4733e247c0c69846a4b3fc23368ae303dc4e4bad..fb94bb6ffa341d24f3e4bc006c8a2612e3a034f6 100644
--- a/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c
+++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c
@@ -64,6 +64,7 @@ extern int otg_enabled;
 #include "UTIL/LOG/vcd_signal_dumper.h"
 #include "platform_constants.h"
 #include "msc.h"
+#include "pdcp.h"
 
 #include "assertions.h"
 
@@ -114,528 +115,794 @@ pdcp_data_req_header_t pdcp_read_header_g;
 //-----------------------------------------------------------------------------
 int pdcp_fifo_flush_sdus(const protocol_ctxt_t* const  ctxt_pP)
 {
-  //-----------------------------------------------------------------------------
+   //-----------------------------------------------------------------------------
 
-//#if defined(PDCP_USE_NETLINK) && defined(LINUX)
-  int ret = 0;
-//#endif
+   //#if defined(PDCP_USE_NETLINK) && defined(LINUX)
+   int ret = 0;
+   //#endif
 
 #ifdef DEBUG_PDCP_FIFO_FLUSH_SDU
 #define THREAD_NAME_LEN 16
-  static char threadname[THREAD_NAME_LEN];
-  ret = pthread_getname_np(pthread_self(), threadname, THREAD_NAME_LEN);
-  if (ret != 0)
-  {
-   perror("pthread_getname_np : ");
-   exit_fun("Error getting thread name");
-  }
+   static char threadname[THREAD_NAME_LEN];
+   ret = pthread_getname_np(pthread_self(), threadname, THREAD_NAME_LEN);
+   if (ret != 0)
+   {
+      perror("pthread_getname_np : ");
+      exit_fun("Error getting thread name");
+   }
 #undef THREAD_NAME_LEN
 #endif
 
 #ifdef PDCP_SDU_FLUSH_LOCK
-  ret = pthread_mutex_trylock(&mtex);
-  if (ret == EBUSY) {
+   ret = pthread_mutex_trylock(&mtex);
+   if (ret == EBUSY) {
 #ifdef DEBUG_PDCP_FIFO_FLUSH_SDU
-    LOG_W(PDCP, "[%s] at SFN/SF=%d/%d wait for PDCP FIFO to be unlocked\n",
-        threadname, ctxt_pP->frame, ctxt_pP->subframe);
+      LOG_W(PDCP, "[%s] at SFN/SF=%d/%d wait for PDCP FIFO to be unlocked\n",
+            threadname, ctxt_pP->frame, ctxt_pP->subframe);
 #endif
-    if (pthread_mutex_lock(&mtex)) {
-      exit_fun("PDCP_SDU_FLUSH_LOCK lock error!");
-    }
+      if (pthread_mutex_lock(&mtex)) {
+         exit_fun("PDCP_SDU_FLUSH_LOCK lock error!");
+      }
 #ifdef DEBUG_PDCP_FIFO_FLUSH_SDU
-    LOG_I(PDCP, "[%s] at SFN/SF=%d/%d PDCP FIFO is unlocked\n",
-        threadname, ctxt_pP->frame, ctxt_pP->subframe);
+      LOG_I(PDCP, "[%s] at SFN/SF=%d/%d PDCP FIFO is unlocked\n",
+            threadname, ctxt_pP->frame, ctxt_pP->subframe);
 #endif
-  } else if (ret != 0) {
-    exit_fun("PDCP_SDU_FLUSH_LOCK trylock error!");
-  }
+   } else if (ret != 0) {
+      exit_fun("PDCP_SDU_FLUSH_LOCK trylock error!");
+   }
 
 #endif
 
-  mem_block_t     *sdu_p            = list_get_head (&pdcp_sdu_list);
-  int              bytes_wrote      = 0;
-  int              pdcp_nb_sdu_sent = 0;
-  uint8_t          cont             = 1;
+   mem_block_t     *sdu_p            = list_get_head (&pdcp_sdu_list);
+   int              bytes_wrote      = 0;
+   int              pdcp_nb_sdu_sent = 0;
+   uint8_t          cont             = 1;
 #if defined(LINK_ENB_PDCP_TO_GTPV1U)
-  //MessageDef      *message_p        = NULL;
+   //MessageDef      *message_p        = NULL;
 #endif
 
-  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_FLUSH, 1 );
-  while (sdu_p && cont) {
+   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_FLUSH, 1 );
+   while (sdu_p && cont) {
 
 #ifdef DEBUG_PDCP_FIFO_FLUSH_SDU
-    LOG_D(PDCP, "[%s] SFN/SF=%d/%d inst=%d size=%d\n",
-        threadname, ctxt_pP->frame, ctxt_pP->subframe,
-        ((pdcp_data_ind_header_t*) sdu_p->data)->inst,
-        ((pdcp_data_ind_header_t *) sdu_p->data)->data_size);
+      LOG_D(PDCP, "[%s] SFN/SF=%d/%d inst=%d size=%d\n",
+            threadname, ctxt_pP->frame, ctxt_pP->subframe,
+            ((pdcp_data_ind_header_t*) sdu_p->data)->inst,
+            ((pdcp_data_ind_header_t *) sdu_p->data)->data_size);
 #else
 #if ! defined(OAI_EMU)
-    /* TODO: do we have to reset to 0 or not? not for a scenario with 1 UE at least */
-//    ((pdcp_data_ind_header_t *)(sdu_p->data))->inst = 0;
+      /* TODO: do we have to reset to 0 or not? not for a scenario with 1 UE at least */
+      //    ((pdcp_data_ind_header_t *)(sdu_p->data))->inst = 0;
 #endif
 #endif
 
 #if defined(LINK_ENB_PDCP_TO_GTPV1U)
 
-    if (ctxt_pP->enb_flag) {
-      AssertFatal(0, "Now execution should not go here");
-      LOG_D(PDCP,"Sending to GTPV1U %d bytes\n", ((pdcp_data_ind_header_t *)(sdu_p->data))->data_size);
-      gtpv1u_new_data_req(
-			  ctxt_pP->module_id, //gtpv1u_data_t *gtpv1u_data_p,
-			  ctxt_pP->rnti,//rb_id/maxDRB, TO DO UE ID
-			  ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id + 4,
-			  &(((uint8_t *) sdu_p->data)[sizeof (pdcp_data_ind_header_t)]),
-			  ((pdcp_data_ind_header_t *)(sdu_p->data))->data_size,
-			  0);
-
-      list_remove_head (&pdcp_sdu_list);
-      free_mem_block (sdu_p, __func__);
-      cont = 1;
-      pdcp_nb_sdu_sent += 1;
-      sdu_p = list_get_head (&pdcp_sdu_list);
-      LOG_D(OTG,"After  GTPV1U\n");
-      continue; // loop again
-    }
+      if (ctxt_pP->enb_flag) {
+         AssertFatal(0, "Now execution should not go here");
+         LOG_D(PDCP,"Sending to GTPV1U %d bytes\n", ((pdcp_data_ind_header_t *)(sdu_p->data))->data_size);
+         gtpv1u_new_data_req(
+               ctxt_pP->module_id, //gtpv1u_data_t *gtpv1u_data_p,
+               ctxt_pP->rnti,//rb_id/maxDRB, TO DO UE ID
+               ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id + 4,
+               &(((uint8_t *) sdu_p->data)[sizeof (pdcp_data_ind_header_t)]),
+               ((pdcp_data_ind_header_t *)(sdu_p->data))->data_size,
+               0);
+
+         list_remove_head (&pdcp_sdu_list);
+         free_mem_block (sdu_p, __func__);
+         cont = 1;
+         pdcp_nb_sdu_sent += 1;
+         sdu_p = list_get_head (&pdcp_sdu_list);
+         LOG_D(OTG,"After  GTPV1U\n");
+         continue; // loop again
+      }
 
 #endif /* defined(ENABLE_USE_MME) */
 #ifdef PDCP_DEBUG
-    LOG_D(PDCP, "PDCP->IP TTI %d INST %d: Preparing %d Bytes of data from rab %d to Nas_mesh\n",
-          ctxt_pP->frame, ((pdcp_data_ind_header_t *)(sdu_p->data))->inst,
-          ((pdcp_data_ind_header_t *)(sdu_p->data))->data_size, ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id);
+      LOG_D(PDCP, "PDCP->IP TTI %d INST %d: Preparing %d Bytes of data from rab %d to Nas_mesh\n",
+            ctxt_pP->frame, ((pdcp_data_ind_header_t *)(sdu_p->data))->inst,
+            ((pdcp_data_ind_header_t *)(sdu_p->data))->data_size, ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id);
 #endif //PDCP_DEBUG
-    cont = 0;
+      cont = 0;
+
+//TTN - for D2D (PC5S)
+#ifdef Rel14
+      sidelink_pc5s_element *sl_pc5s_msg_recv = NULL;
+      sidelink_pc5s_element *sl_pc5s_msg_send = NULL;
+      char send_buf[BUFSIZE];
+
+      if ((((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id) == 10) { //hardcoded for PC5-Signaling
+
+#ifdef PDCP_DEBUG
+         sl_pc5s_msg_recv = calloc(1, sizeof(sidelink_pc5s_element));
+         memcpy((void*)sl_pc5s_msg_recv, (void*)(sdu_p->data+sizeof(pdcp_data_ind_header_t)), sizeof(sidelink_pc5s_element));
+
+         LOG_D(PDCP,"[pdcp_fifo_flush_sdus]: Received DirectCommunicationRequest (PC5-S), header msg_type: %d)\n", sl_pc5s_msg_recv->pdcp_data_header.msg_type);
+         LOG_D(PDCP,"[pdcp_fifo_flush_sdus]: Received DirectCommunicationRequest (PC5-S), header rb_id: %d)\n", sl_pc5s_msg_recv->pdcp_data_header.rb_id);
+         LOG_D(PDCP,"[pdcp_fifo_flush_sdus]: Received DirectCommunicationRequest (PC5-S), header data_size: %d)\n", sl_pc5s_msg_recv->pdcp_data_header.data_size);
+         LOG_D(PDCP,"[pdcp_fifo_flush_sdus]: Received DirectCommunicationRequest (PC5-S), header inst: %d)\n", sl_pc5s_msg_recv->pdcp_data_header.inst);
+
+         if (sl_pc5s_msg_recv->pdcp_data_header.msg_type == SL_DIRECT_COMMUNICATION_REQUEST){
+            LOG_D(PDCP,"[pdcp_pc5_socket_thread_fct]: Received DirectCommunicationRequest (PC5-S), seqno: %d)\n", sl_pc5s_msg_recv->pc5sPrimitive.pc5s_direct_communication_req.sequenceNumber);
+            LOG_D(PDCP,"[pdcp_pc5_socket_thread_fct]: Received DirectCommunicationRequest (PC5-S), ipAddressConfig: %d)\n", sl_pc5s_msg_recv->pc5sPrimitive.pc5s_direct_communication_req.ipAddressConfig);
+         }
+         //send to ProSe app
+         LOG_D(RRC,"[pdcp_fifo_flush_sdus]: Send DirectCommunicationRequest to ProSe App \n");
+#endif
+         memset(send_buf, 0, BUFSIZE);
+         //memcpy((void *)send_buf, (void *)sl_pc5s_msg_recv, sizeof(sidelink_pc5s_element));
+         memcpy((void *)send_buf, (void*)(sdu_p->data+sizeof(pdcp_data_ind_header_t)), sizeof(sidelink_pc5s_element));
+         //free(sl_ctrl_msg_send);
+
+         int prose_addr_len = sizeof(prose_app_addr);
+         int n = sendto(pdcp_pc5_sockfd, (char *)send_buf, sizeof(sidelink_pc5s_element), 0, (struct sockaddr *)&prose_app_addr, prose_addr_len);
+         if (n < 0) {
+            LOG_E(PDCP, "ERROR: Failed to send to ProSe App\n");
+            exit(EXIT_FAILURE);
+         }
 
-    if (!pdcp_output_sdu_bytes_to_write) {
-      if (!pdcp_output_header_bytes_to_write) {
-        pdcp_output_header_bytes_to_write = sizeof (pdcp_data_ind_header_t);
       }
+#endif
+
+      if (!pdcp_output_sdu_bytes_to_write) {
+         if (!pdcp_output_header_bytes_to_write) {
+            pdcp_output_header_bytes_to_write = sizeof (pdcp_data_ind_header_t);
+         }
 
 #ifdef PDCP_USE_RT_FIFO
-      bytes_wrote = rtf_put (PDCP2PDCP_USE_RT_FIFO,
-                             &(((uint8_t *) sdu->data)[sizeof (pdcp_data_ind_header_t) - pdcp_output_header_bytes_to_write]),
-                             pdcp_output_header_bytes_to_write);
+         bytes_wrote = rtf_put (PDCP2PDCP_USE_RT_FIFO,
+               &(((uint8_t *) sdu->data)[sizeof (pdcp_data_ind_header_t) - pdcp_output_header_bytes_to_write]),
+               pdcp_output_header_bytes_to_write);
 
 #else
 #ifdef PDCP_USE_NETLINK
 #ifdef LINUX
-      memcpy(NLMSG_DATA(nas_nlh_tx), &(((uint8_t *) sdu_p->data)[sizeof (pdcp_data_ind_header_t) - pdcp_output_header_bytes_to_write]),
-             pdcp_output_header_bytes_to_write);
-      nas_nlh_tx->nlmsg_len = pdcp_output_header_bytes_to_write;
+         memcpy(NLMSG_DATA(nas_nlh_tx), &(((uint8_t *) sdu_p->data)[sizeof (pdcp_data_ind_header_t) - pdcp_output_header_bytes_to_write]),
+               pdcp_output_header_bytes_to_write);
+         nas_nlh_tx->nlmsg_len = pdcp_output_header_bytes_to_write;
 #endif //LINUX
 #endif //PDCP_USE_NETLINK
 
-      bytes_wrote = pdcp_output_header_bytes_to_write;
+         bytes_wrote = pdcp_output_header_bytes_to_write;
 #endif //PDCP_USE_RT_FIFO
 
 #ifdef PDCP_DEBUG
-      LOG_D(PDCP, "Frame %d Sent %d Bytes of header to Nas_mesh\n",
-            ctxt_pP->frame,
-            bytes_wrote);
+         LOG_D(PDCP, "Frame %d Sent %d Bytes of header to Nas_mesh\n",
+               ctxt_pP->frame,
+               bytes_wrote);
 #endif //PDCP_DEBUG
 
-      if (bytes_wrote > 0) {
-        pdcp_output_header_bytes_to_write = pdcp_output_header_bytes_to_write - bytes_wrote;
+         if (bytes_wrote > 0) {
+            pdcp_output_header_bytes_to_write = pdcp_output_header_bytes_to_write - bytes_wrote;
 
-        if (!pdcp_output_header_bytes_to_write) { // continue with sdu
-          pdcp_output_sdu_bytes_to_write = ((pdcp_data_ind_header_t *) sdu_p->data)->data_size;
-          AssertFatal(pdcp_output_sdu_bytes_to_write >= 0, "invalid data_size!");
+            if (!pdcp_output_header_bytes_to_write) { // continue with sdu
+               pdcp_output_sdu_bytes_to_write = ((pdcp_data_ind_header_t *) sdu_p->data)->data_size;
+               AssertFatal(pdcp_output_sdu_bytes_to_write >= 0, "invalid data_size!");
 
 #ifdef PDCP_USE_RT_FIFO
-          bytes_wrote = rtf_put (PDCP2PDCP_USE_RT_FIFO, &(sdu->data[sizeof (pdcp_data_ind_header_t)]), pdcp_output_sdu_bytes_to_write);
+               bytes_wrote = rtf_put (PDCP2PDCP_USE_RT_FIFO, &(sdu->data[sizeof (pdcp_data_ind_header_t)]), pdcp_output_sdu_bytes_to_write);
 #else
 
 #ifdef PDCP_USE_NETLINK
 #ifdef LINUX
-          memcpy(NLMSG_DATA(nas_nlh_tx)+sizeof(pdcp_data_ind_header_t), &(sdu_p->data[sizeof (pdcp_data_ind_header_t)]), pdcp_output_sdu_bytes_to_write);
-          nas_nlh_tx->nlmsg_len += pdcp_output_sdu_bytes_to_write;
-          VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_UE_PDCP_FLUSH_SIZE, pdcp_output_sdu_bytes_to_write);
-          VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_FLUSH_BUFFER, 1 );
-          ret = sendmsg(nas_sock_fd,&nas_msg_tx,0);
-          VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_FLUSH_BUFFER, 0 );
-          VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_UE_PDCP_FLUSH_ERR, ret );
-
-          if (ret<0) {
-            LOG_E(PDCP, "[PDCP_FIFOS] sendmsg returns %d (errno: %d)\n", ret, errno);
-      	    MSC_LOG_TX_MESSAGE_FAILED(
-      	      (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
-      	      (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_IP_ENB:MSC_IP_UE,
-      	      NULL,
-      	      0,
-      	      MSC_AS_TIME_FMT" DATA-IND RNTI %"PRIx16" rb %u size %u",
-      	      MSC_AS_TIME_ARGS(ctxt_pP),
-      	      ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id,
-      	      ((pdcp_data_ind_header_t *)(sdu_p->data))->data_size);
-	    AssertFatal(1==0,"sendmsg failed for nas_sock_fd\n");
-            break;
-          } else {
-        	  MSC_LOG_TX_MESSAGE(
-        	    (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
-        	    (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_IP_ENB:MSC_IP_UE,
-        	    NULL,
-        	    0,
-        	    MSC_AS_TIME_FMT" DATA-IND RNTI %"PRIx16" rb %u size %u",
-        	    MSC_AS_TIME_ARGS(ctxt_pP),
-        	    ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id,
-        	    ((pdcp_data_ind_header_t *)(sdu_p->data))->data_size);
-          }
+               memcpy(NLMSG_DATA(nas_nlh_tx)+sizeof(pdcp_data_ind_header_t), &(sdu_p->data[sizeof (pdcp_data_ind_header_t)]), pdcp_output_sdu_bytes_to_write);
+               nas_nlh_tx->nlmsg_len += pdcp_output_sdu_bytes_to_write;
+               VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_UE_PDCP_FLUSH_SIZE, pdcp_output_sdu_bytes_to_write);
+               VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_FLUSH_BUFFER, 1 );
+               ret = sendmsg(nas_sock_fd,&nas_msg_tx,0);
+               VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_FLUSH_BUFFER, 0 );
+               VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_UE_PDCP_FLUSH_ERR, ret );
+
+               if (ret<0) {
+                  LOG_E(PDCP, "[PDCP_FIFOS] sendmsg returns %d (errno: %d)\n", ret, errno);
+                  MSC_LOG_TX_MESSAGE_FAILED(
+                        (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
+                              (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_IP_ENB:MSC_IP_UE,
+                                    NULL,
+                                    0,
+                                    MSC_AS_TIME_FMT" DATA-IND RNTI %"PRIx16" rb %u size %u",
+                                    MSC_AS_TIME_ARGS(ctxt_pP),
+                                    ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id,
+                                    ((pdcp_data_ind_header_t *)(sdu_p->data))->data_size);
+                  AssertFatal(1==0,"sendmsg failed for nas_sock_fd\n");
+                  break;
+               } else {
+                  MSC_LOG_TX_MESSAGE(
+                        (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
+                              (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_IP_ENB:MSC_IP_UE,
+                                    NULL,
+                                    0,
+                                    MSC_AS_TIME_FMT" DATA-IND RNTI %"PRIx16" rb %u size %u",
+                                    MSC_AS_TIME_ARGS(ctxt_pP),
+                                    ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id,
+                                    ((pdcp_data_ind_header_t *)(sdu_p->data))->data_size);
+               }
 
 #endif // LINUX
 #endif //PDCP_USE_NETLINK
-          bytes_wrote= pdcp_output_sdu_bytes_to_write;
+               bytes_wrote= pdcp_output_sdu_bytes_to_write;
 #endif // PDCP_USE_RT_FIFO
 
 #ifdef PDCP_DEBUG
-          LOG_D(PDCP, "PDCP->IP Frame %d INST %d: Sent %d Bytes of data from rab %d to higher layers\n",
-                ctxt_pP->frame,
-                ((pdcp_data_ind_header_t *)(sdu_p->data))->inst,
-                bytes_wrote,
-                ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id);
+               LOG_D(PDCP, "PDCP->IP Frame %d INST %d: Sent %d Bytes of data from rab %d to higher layers\n",
+                     ctxt_pP->frame,
+                     ((pdcp_data_ind_header_t *)(sdu_p->data))->inst,
+                     bytes_wrote,
+                     ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id);
 #endif //PDCP_DEBUG
 
-          if (bytes_wrote > 0) {
-            pdcp_output_sdu_bytes_to_write -= bytes_wrote;
-
-            if (!pdcp_output_sdu_bytes_to_write) { // OK finish with this SDU
-              // LOG_D(PDCP, "rb sent a sdu qos_sap %d\n", sapiP);
-              LOG_D(PDCP,
-                    "[FRAME %05d][xxx][PDCP][MOD xx/xx][RB %u][--- PDCP_DATA_IND / %d Bytes --->][IP][INSTANCE %u][RB %u]\n",
-                    ctxt_pP->frame,
-                    ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id,
-                    ((pdcp_data_ind_header_t *)(sdu_p->data))->data_size,
-                    ((pdcp_data_ind_header_t *)(sdu_p->data))->inst,
-                    ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id);
-
-              list_remove_head (&pdcp_sdu_list);
-              free_mem_block (sdu_p, __func__);
-              cont = 1;
-              pdcp_nb_sdu_sent += 1;
-              sdu_p = list_get_head (&pdcp_sdu_list);
+               if (bytes_wrote > 0) {
+                  pdcp_output_sdu_bytes_to_write -= bytes_wrote;
+
+                  if (!pdcp_output_sdu_bytes_to_write) { // OK finish with this SDU
+                     // LOG_D(PDCP, "rb sent a sdu qos_sap %d\n", sapiP);
+                     LOG_D(PDCP,
+                           "[FRAME %05d][xxx][PDCP][MOD xx/xx][RB %u][--- PDCP_DATA_IND / %d Bytes --->][IP][INSTANCE %u][RB %u]\n",
+                           ctxt_pP->frame,
+                           ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id,
+                           ((pdcp_data_ind_header_t *)(sdu_p->data))->data_size,
+                           ((pdcp_data_ind_header_t *)(sdu_p->data))->inst,
+                           ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id);
+
+                     list_remove_head (&pdcp_sdu_list);
+                     free_mem_block (sdu_p, __func__);
+                     cont = 1;
+                     pdcp_nb_sdu_sent += 1;
+                     sdu_p = list_get_head (&pdcp_sdu_list);
+                  } else {
+                     LOG_D(PDCP, "1 skip free_mem_block: pdcp_output_sdu_bytes_to_write = %d\n", pdcp_output_sdu_bytes_to_write);
+                     AssertFatal(pdcp_output_sdu_bytes_to_write > 0, "pdcp_output_sdu_bytes_to_write cannot be negative!");
+                  }
+               } else {
+                  LOG_W(PDCP, "2: RADIO->IP SEND SDU CONGESTION!\n");
+               }
             } else {
-              LOG_D(PDCP, "1 skip free_mem_block: pdcp_output_sdu_bytes_to_write = %d\n", pdcp_output_sdu_bytes_to_write);
-              AssertFatal(pdcp_output_sdu_bytes_to_write > 0, "pdcp_output_sdu_bytes_to_write cannot be negative!");
+               LOG_W(PDCP, "3: RADIO->IP SEND SDU CONGESTION!\n");
             }
-          } else {
-            LOG_W(PDCP, "2: RADIO->IP SEND SDU CONGESTION!\n");
-          }
-        } else {
-          LOG_W(PDCP, "3: RADIO->IP SEND SDU CONGESTION!\n");
-        }
+         } else {
+            LOG_D(PDCP, "4 skip free_mem_block: bytes_wrote = %d\n", bytes_wrote);
+         }
       } else {
-        LOG_D(PDCP, "4 skip free_mem_block: bytes_wrote = %d\n", bytes_wrote);
-      }
-    } else {
-      // continue writing sdu
+         // continue writing sdu
 #ifdef PDCP_USE_RT_FIFO
-      bytes_wrote = rtf_put (PDCP2PDCP_USE_RT_FIFO,
-                             (uint8_t *) (&(sdu_p->data[sizeof (pdcp_data_ind_header_t) + ((pdcp_data_ind_header_t *) sdu_p->data)->data_size - pdcp_output_sdu_bytes_to_write])),
-                             pdcp_output_sdu_bytes_to_write);
+         bytes_wrote = rtf_put (PDCP2PDCP_USE_RT_FIFO,
+               (uint8_t *) (&(sdu_p->data[sizeof (pdcp_data_ind_header_t) + ((pdcp_data_ind_header_t *) sdu_p->data)->data_size - pdcp_output_sdu_bytes_to_write])),
+               pdcp_output_sdu_bytes_to_write);
 #else  // PDCP_USE_RT_FIFO
-      bytes_wrote = pdcp_output_sdu_bytes_to_write;
+         bytes_wrote = pdcp_output_sdu_bytes_to_write;
 #endif  // PDCP_USE_RT_FIFO
+         LOG_D(PDCP, "THINH 2 bytes_wrote = %d\n", bytes_wrote);
 
-      if (bytes_wrote > 0) {
-        pdcp_output_sdu_bytes_to_write -= bytes_wrote;
-
-        if (!pdcp_output_sdu_bytes_to_write) {     // OK finish with this SDU
-          //PRINT_RB_SEND_OUTPUT_SDU ("[PDCP] RADIO->IP SEND SDU\n");
-          list_remove_head (&pdcp_sdu_list);
-          free_mem_block (sdu_p, __func__);
-          cont = 1;
-          pdcp_nb_sdu_sent += 1;
-          sdu_p = list_get_head (&pdcp_sdu_list);
-          // LOG_D(PDCP, "rb sent a sdu from rab\n");
-        } else {
-          LOG_D(PDCP, "5 skip free_mem_block: pdcp_output_sdu_bytes_to_write = %d\n", pdcp_output_sdu_bytes_to_write);
-        }
-      } else {
-        LOG_D(PDCP, "6 skip free_mem_block: bytes_wrote = %d\n", bytes_wrote);
+         if (bytes_wrote > 0) {
+            pdcp_output_sdu_bytes_to_write -= bytes_wrote;
+
+            if (!pdcp_output_sdu_bytes_to_write) {     // OK finish with this SDU
+               //PRINT_RB_SEND_OUTPUT_SDU ("[PDCP] RADIO->IP SEND SDU\n");
+               list_remove_head (&pdcp_sdu_list);
+               free_mem_block (sdu_p, __func__);
+               cont = 1;
+               pdcp_nb_sdu_sent += 1;
+               sdu_p = list_get_head (&pdcp_sdu_list);
+               // LOG_D(PDCP, "rb sent a sdu from rab\n");
+            } else {
+               LOG_D(PDCP, "5 skip free_mem_block: pdcp_output_sdu_bytes_to_write = %d\n", pdcp_output_sdu_bytes_to_write);
+            }
+         } else {
+            LOG_D(PDCP, "6 skip free_mem_block: bytes_wrote = %d\n", bytes_wrote);
+         }
       }
-    }
-  }
-  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_FLUSH, 0 );
+   }
+   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_FLUSH, 0 );
 
 #ifdef PDCP_USE_RT_FIFO
 
-  if ((pdcp_nb_sdu_sent)) {
-    if ((pdcp_2_nas_irq > 0)) {
+   if ((pdcp_nb_sdu_sent)) {
+      if ((pdcp_2_nas_irq > 0)) {
 #ifdef PDCP_DEBUG
-      LOG_D(PDCP, "Frame %d : Trigger NAS RX interrupt\n",
-            ctxt_pP->frame);
+         LOG_D(PDCP, "Frame %d : Trigger NAS RX interrupt\n",
+               ctxt_pP->frame);
 #endif //PDCP_DEBUG
-      rt_pend_linux_srq (pdcp_2_nas_irq);
+         rt_pend_linux_srq (pdcp_2_nas_irq);
 
-    } else {
-      LOG_E(PDCP, "Frame %d: ERROR IF IP STACK WANTED : NOTIF PACKET(S) pdcp_2_nas_irq not initialized : %d\n",
-            ctxt_pP->frame,
-            pdcp_2_nas_irq);
-    }
-  }
+      } else {
+         LOG_E(PDCP, "Frame %d: ERROR IF IP STACK WANTED : NOTIF PACKET(S) pdcp_2_nas_irq not initialized : %d\n",
+               ctxt_pP->frame,
+               pdcp_2_nas_irq);
+      }
+   }
 
 #endif  //PDCP_USE_RT_FIFO
 
 #ifdef PDCP_SDU_FLUSH_LOCK
-  if (pthread_mutex_unlock(&mtex)) exit_fun("PDCP_SDU_FLUSH_LOCK unlock error!");
+   if (pthread_mutex_unlock(&mtex)) exit_fun("PDCP_SDU_FLUSH_LOCK unlock error!");
 #endif
 
-  return pdcp_nb_sdu_sent;
+   return pdcp_nb_sdu_sent;
 }
 
 //-----------------------------------------------------------------------------
 int pdcp_fifo_read_input_sdus (const protocol_ctxt_t* const  ctxt_pP)
 {
 #ifdef PDCP_USE_NETLINK
-  protocol_ctxt_t                ctxt_cpy = *ctxt_pP;
-  protocol_ctxt_t                ctxt;
-  hash_key_t                     key       = HASHTABLE_NOT_A_KEY_VALUE;
-  hashtable_rc_t                 h_rc;
-  struct pdcp_netlink_element_s* data_p    = NULL;
-  /* avoid gcc warnings */
-  (void)data_p;
-  module_id_t                    ue_id     = 0;
-  pdcp_t*                        pdcp_p    = NULL;
-# if defined(PDCP_USE_NETLINK_QUEUES)
-  rb_id_t                        rab_id    = 0;
+   protocol_ctxt_t                ctxt_cpy = *ctxt_pP;
+   protocol_ctxt_t                ctxt;
+   hash_key_t                     key       = HASHTABLE_NOT_A_KEY_VALUE;
+   hashtable_rc_t                 h_rc;
+   struct pdcp_netlink_element_s* data_p    = NULL;
+   /* avoid gcc warnings */
+   (void)data_p;
+   module_id_t                    ue_id     = 0;
+   pdcp_t*                        pdcp_p    = NULL;
+
+//TTN for D2D (PC5S)
+#ifdef Rel14
+   int prose_addr_len;
+   char send_buf[BUFSIZE], receive_buf[BUFSIZE];
+   int optval;
+   int bytes_received;
+   sidelink_pc5s_element *sl_pc5s_msg_recv = NULL;
+   sidelink_pc5s_element *sl_pc5s_msg_send = NULL;
+   uint32_t sourceL2Id;
+   uint32_t groupL2Id;
+   module_id_t         module_id = 0;
+   pdcp_data_header_t *pdcp_data_header;
+#endif
 
-  pdcp_transmission_mode_t       pdcp_mode = PDCP_TRANSMISSION_MODE_UNKNOWN;
+# if defined(PDCP_USE_NETLINK_QUEUES)
+   rb_id_t                        rab_id    = 0;
+
+   pdcp_transmission_mode_t       pdcp_mode = PDCP_TRANSMISSION_MODE_UNKNOWN;
+
+
+   while (pdcp_netlink_dequeue_element(ctxt_pP, &data_p) != 0) {
+      DevAssert(data_p != NULL);
+      rab_id = data_p->pdcp_read_header.rb_id % maxDRB;
+      // ctxt_pP->rnti is NOT_A_RNTI
+      ctxt_cpy.rnti = pdcp_module_id_to_rnti[ctxt_cpy.module_id][data_p->pdcp_read_header.inst];
+      key = PDCP_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_cpy.rnti, ctxt_pP->enb_flag, rab_id, SRB_FLAG_NO);
+      h_rc = hashtable_get(pdcp_coll_p, key, (void**)&pdcp_p);
+
+      if (h_rc != HASH_TABLE_OK) {
+         LOG_W(PDCP, PROTOCOL_CTXT_FMT" Dropped IP PACKET cause no PDCP instanciated\n",
+               PROTOCOL_CTXT_ARGS(ctxt_pP));
+         free(data_p->data);
+         free(data_p);
+         data_p = NULL;
+         continue;
+      }
 
+      CHECK_CTXT_ARGS(&ctxt_cpy);
 
-  while (pdcp_netlink_dequeue_element(ctxt_pP, &data_p) != 0) {
-    DevAssert(data_p != NULL);
-    rab_id = data_p->pdcp_read_header.rb_id % maxDRB;
-    // ctxt_pP->rnti is NOT_A_RNTI
-    ctxt_cpy.rnti = pdcp_module_id_to_rnti[ctxt_cpy.module_id][data_p->pdcp_read_header.inst];
-    key = PDCP_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_cpy.rnti, ctxt_pP->enb_flag, rab_id, SRB_FLAG_NO);
-    h_rc = hashtable_get(pdcp_coll_p, key, (void**)&pdcp_p);
+      AssertFatal (rab_id    < maxDRB,                       "RB id is too high (%u/%d)!\n", rab_id, maxDRB);
 
-    if (h_rc != HASH_TABLE_OK) {
-      LOG_W(PDCP, PROTOCOL_CTXT_FMT" Dropped IP PACKET cause no PDCP instanciated\n",
-            PROTOCOL_CTXT_ARGS(ctxt_pP));
-      free(data_p->data);
-      free(data_p);
-      data_p = NULL;
-      continue;
-    }
-
-    CHECK_CTXT_ARGS(&ctxt_cpy);
-
-    AssertFatal (rab_id    < maxDRB,                       "RB id is too high (%u/%d)!\n", rab_id, maxDRB);
-
-    if (rab_id != 0) {
-        LOG_I(PDCP, "[FRAME %05d][%s][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ "
-            "/ %d Bytes --->][PDCP][MOD %u][RB %u]\n",
-              ctxt_cpy.frame,
-              (ctxt_cpy.enb_flag) ? "eNB" : "UE",
-            data_p->pdcp_read_header.inst,
-            data_p->pdcp_read_header.rb_id,
-            data_p->pdcp_read_header.data_size,
-            ctxt_cpy.module_id,
-              rab_id);
+      if (rab_id != 0) {
+         LOG_I(PDCP, "[FRAME %05d][%s][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ "
+               "/ %d Bytes --->][PDCP][MOD %u][RB %u]\n",
+               ctxt_cpy.frame,
+               (ctxt_cpy.enb_flag) ? "eNB" : "UE",
+                     data_p->pdcp_read_header.inst,
+                     data_p->pdcp_read_header.rb_id,
+                     data_p->pdcp_read_header.data_size,
+                     ctxt_cpy.module_id,
+                     rab_id);
 #ifdef  OAI_NW_DRIVER_TYPE_ETHERNET
 
-      if ((data_p->pdcp_read_header.traffic_type == TRAFFIC_IPV6_TYPE_MULTICAST) /*TRAFFIC_IPV6_TYPE_MULTICAST */ ||
-          (data_p->pdcp_read_header.traffic_type == TRAFFIC_IPV4_TYPE_MULTICAST) /*TRAFFIC_IPV4_TYPE_MULTICAST */ ||
-          (data_p->pdcp_read_header.traffic_type == TRAFFIC_IPV4_TYPE_BROADCAST) /*TRAFFIC_IPV4_TYPE_BROADCAST */ ) {
+         if ((data_p->pdcp_read_header.traffic_type == TRAFFIC_IPV6_TYPE_MULTICAST) /*TRAFFIC_IPV6_TYPE_MULTICAST */ ||
+               (data_p->pdcp_read_header.traffic_type == TRAFFIC_IPV4_TYPE_MULTICAST) /*TRAFFIC_IPV4_TYPE_MULTICAST */ ||
+               (data_p->pdcp_read_header.traffic_type == TRAFFIC_IPV4_TYPE_BROADCAST) /*TRAFFIC_IPV4_TYPE_BROADCAST */ ) {
 #if defined(Rel10) || defined(Rel14)
-          PDCP_TRANSMISSION_MODE_TRANSPARENT;
+            PDCP_TRANSMISSION_MODE_TRANSPARENT;
 #else
-          pdcp_mode= PDCP_TRANSMISSION_MODE_DATA;
+            pdcp_mode= PDCP_TRANSMISSION_MODE_DATA;
 #endif
-      } else if ((data_p->pdcp_read_header.traffic_type == TRAFFIC_IPV6_TYPE_UNICAST) /* TRAFFIC_IPV6_TYPE_UNICAST */ ||
-                 (data_p->pdcp_read_header.traffic_type == TRAFFIC_IPV4_TYPE_UNICAST) /*TRAFFIC_IPV4_TYPE_UNICAST*/ ) {
-          pdcp_mode=  PDCP_TRANSMISSION_MODE_DATA;
-        } else {
-          pdcp_mode= PDCP_TRANSMISSION_MODE_DATA;
-          LOG_W(PDCP,"unknown IP traffic type \n");
-        }
+         } else if ((data_p->pdcp_read_header.traffic_type == TRAFFIC_IPV6_TYPE_UNICAST) /* TRAFFIC_IPV6_TYPE_UNICAST */ ||
+               (data_p->pdcp_read_header.traffic_type == TRAFFIC_IPV4_TYPE_UNICAST) /*TRAFFIC_IPV4_TYPE_UNICAST*/ ) {
+            pdcp_mode=  PDCP_TRANSMISSION_MODE_DATA;
+         } else {
+            pdcp_mode= PDCP_TRANSMISSION_MODE_DATA;
+            LOG_W(PDCP,"unknown IP traffic type \n");
+         }
 
 #else // OAI_NW_DRIVER_TYPE_ETHERNET NASMESH driver does not curreenlty support multicast traffic
-        pdcp_mode = PDCP_TRANSMISSION_MODE_DATA;
+         pdcp_mode = PDCP_TRANSMISSION_MODE_DATA;
 #endif
-      pdcp_data_req(&ctxt_cpy,
-                      SRB_FLAG_NO,
-                      rab_id % maxDRB,
-                      RLC_MUI_UNDEFINED,
-                      RLC_SDU_CONFIRM_NO,
-                    data_p->pdcp_read_header.data_size,
-                    data_p->data,
-                      pdcp_mode);
-    } else if (ctxt_cpy.enb_flag) {
-      /* rb_id = 0, thus interpreated as broadcast and transported as
-       * multiple unicast is a broadcast packet, we have to send this
-       * packet on all default RABS of all connected UEs
-       */
-      LOG_D(PDCP, "eNB Try Forcing send on DEFAULT_RAB_ID first_ue_local %u nb_ue_local %u\n", oai_emulation.info.first_ue_local, oai_emulation.info.nb_ue_local);
+         pdcp_data_req(&ctxt_cpy,
+               SRB_FLAG_NO,
+               rab_id % maxDRB,
+               RLC_MUI_UNDEFINED,
+               RLC_SDU_CONFIRM_NO,
+               data_p->pdcp_read_header.data_size,
+               data_p->data,
+               pdcp_mode);
+      } else if (ctxt_cpy.enb_flag) {
+         /* rb_id = 0, thus interpreated as broadcast and transported as
+          * multiple unicast is a broadcast packet, we have to send this
+          * packet on all default RABS of all connected UEs
+          */
+         LOG_D(PDCP, "eNB Try Forcing send on DEFAULT_RAB_ID first_ue_local %u nb_ue_local %u\n", oai_emulation.info.first_ue_local, oai_emulation.info.nb_ue_local);
+
+         for (ue_id = 0; ue_id < NB_UE_INST; ue_id++) {
+            if (pdcp_module_id_to_rnti[ctxt_cpy.module_id][ue_id] != NOT_A_RNTI) {
+               LOG_D(PDCP, "eNB Try Forcing send on DEFAULT_RAB_ID UE %d\n", ue_id);
+               ctxt.module_id     = ctxt_cpy.module_id;
+               ctxt.rnti          = ctxt_cpy.pdcp_module_id_to_rnti[ctxt_cpy.module_id][ue_id];
+               ctxt.frame         = ctxt_cpy.frame;
+               ctxt.enb_flag      = ctxt_cpy.enb_flag;
+
+               pdcp_data_req(
+                     &ctxt,
+                     SRB_FLAG_NO,
+                     DEFAULT_RAB_ID,
+                     RLC_MUI_UNDEFINED,
+                     RLC_SDU_CONFIRM_NO,
+                     data_p->pdcp_read_header.data_size,
+                     data_p->data,
+                     PDCP_TRANSMISSION_MODE_DATA);
+            }
+         }
+      } else {
+         LOG_D(PDCP, "Forcing send on DEFAULT_RAB_ID\n");
+         pdcp_data_req(
+               &ctxt_cpy,
+               SRB_FLAG_NO,
+               DEFAULT_RAB_ID,
+               RLC_MUI_UNDEFINED,
+               RLC_SDU_CONFIRM_NO,
+               data_p->pdcp_read_header.data_size,
+               data_p->data,
+               PDCP_TRANSMISSION_MODE_DATA);
+      }
 
-      for (ue_id = 0; ue_id < NB_UE_INST; ue_id++) {
-        if (pdcp_module_id_to_rnti[ctxt_cpy.module_id][ue_id] != NOT_A_RNTI) {
-          LOG_D(PDCP, "eNB Try Forcing send on DEFAULT_RAB_ID UE %d\n", ue_id);
-          ctxt.module_id     = ctxt_cpy.module_id;
-          ctxt.rnti          = ctxt_cpy.pdcp_module_id_to_rnti[ctxt_cpy.module_id][ue_id];
-          ctxt.frame         = ctxt_cpy.frame;
-          ctxt.enb_flag      = ctxt_cpy.enb_flag;
+      free(data_p->data);
+      free(data_p);
+      data_p = NULL;
+   }
 
-          pdcp_data_req(
-            &ctxt,
-            SRB_FLAG_NO,
-            DEFAULT_RAB_ID,
-            RLC_MUI_UNDEFINED,
-            RLC_SDU_CONFIRM_NO,
-            data_p->pdcp_read_header.data_size,
-            data_p->data,
-            PDCP_TRANSMISSION_MODE_DATA);
-        }
-      }
-    } else {
-      LOG_D(PDCP, "Forcing send on DEFAULT_RAB_ID\n");
-      pdcp_data_req(
-        &ctxt_cpy,
-        SRB_FLAG_NO,
-        DEFAULT_RAB_ID,
-        RLC_MUI_UNDEFINED,
-        RLC_SDU_CONFIRM_NO,
-        data_p->pdcp_read_header.data_size,
-        data_p->data,
-        PDCP_TRANSMISSION_MODE_DATA);
-    }
-
-    free(data_p->data);
-    free(data_p);
-    data_p = NULL;
-  }
-
-  return 0;
+   return 0;
 # else /* PDCP_USE_NETLINK_QUEUES*/
-  int              len = 1;
-  int  msg_len;
-  rb_id_t          rab_id  = 0;
-  int rlc_data_req_flag = 3;
- 
-  while ((len > 0) && (rlc_data_req_flag !=0))  {
-    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_READ, 1 );
-    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_READ_BUFFER, 1 );
-    len = recvmsg(nas_sock_fd, &nas_msg_rx, 0);
-    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_READ_BUFFER, 0 );
-
-    if (len<=0) {
-      // nothing in pdcp NAS socket
-      //LOG_D(PDCP, "[PDCP][NETLINK] Nothing in socket, length %d \n", len);
-    } else {
-    
-      msg_len = len;
-      for (nas_nlh_rx = (struct nlmsghdr *) nl_rx_buf;
-           NLMSG_OK (nas_nlh_rx, msg_len);
-           nas_nlh_rx = NLMSG_NEXT (nas_nlh_rx, msg_len)) {
-
-        if (nas_nlh_rx->nlmsg_type == NLMSG_DONE) {
-          LOG_D(PDCP, "[PDCP][NETLINK] RX NLMSG_DONE\n");
-          //return;
-        }
-
-        if (nas_nlh_rx->nlmsg_type == NLMSG_ERROR) {
-          LOG_D(PDCP, "[PDCP][NETLINK] RX NLMSG_ERROR\n");
-        }
-
-        if (pdcp_read_state_g == 0) {
-          if (nas_nlh_rx->nlmsg_len == sizeof (pdcp_data_req_header_t) + sizeof(struct nlmsghdr)) {
-            pdcp_read_state_g = 1;  //get
-            memcpy((void *)&pdcp_read_header_g, (void *)NLMSG_DATA(nas_nlh_rx), sizeof(pdcp_data_req_header_t));
-            LOG_D(PDCP, "[PDCP][NETLINK] RX pdcp_data_req_header_t inst %u, rb_id %u data_size %d\n",
-                  pdcp_read_header_g.inst, pdcp_read_header_g.rb_id, pdcp_read_header_g.data_size);
-          } else {
-            LOG_E(PDCP, "[PDCP][NETLINK] WRONG size %d should be sizeof (pdcp_data_req_header_t) + sizeof(struct nlmsghdr)\n",
-                  nas_nlh_rx->nlmsg_len);
-          }
-        } else {
-          pdcp_read_state_g = 0;
-          // print_active_requests()
+   int              len = 1;
+   int  msg_len;
+   rb_id_t          rab_id  = 0;
+   int rlc_data_req_flag = 3;
+
+
+//TTN for D2D (PC5S)
+#ifdef Rel14
+  // module_id = 0 ; //hardcoded for testing only
+   prose_addr_len = sizeof(prose_app_addr);
+   // receive a message from ProSe App
+   memset(receive_buf, 0, BUFSIZE);
+   bytes_received = recvfrom(pdcp_pc5_sockfd, receive_buf, BUFSIZE, 0,
+         (struct sockaddr *) &prose_app_addr, &prose_addr_len);
+   //  if (bytes_received < 0){
+   //    LOG_E(RRC, "ERROR: Failed to receive from ProSe App\n");
+   //    exit(EXIT_FAILURE);
+   // }
+   if (bytes_received > 0) {
+      pdcp_data_header = calloc(1, sizeof(pdcp_data_header_t));
+      memcpy((void *)pdcp_data_header, (void *)receive_buf, sizeof(pdcp_data_header_t));
+
+      if (pdcp_data_header->msg_type == SL_PC5S_INIT){
+         //send reply to ProSe app
+         LOG_D(PDCP,"[pdcp_fifo_read_input_sdus]: Send response to ProSe App [PDCP socket]\n");
+         memset(send_buf, 0, BUFSIZE);
+         sl_pc5s_msg_send = calloc(1, sizeof(sidelink_pc5s_element));
+         sl_pc5s_msg_send->pdcp_data_header.msg_type = SL_PC5S_INIT;
+         sl_pc5s_msg_send->pc5sPrimitive.status = 1;
+
+         memcpy((void *)send_buf, (void *)sl_pc5s_msg_send, sizeof(sidelink_pc5s_element));
+         int prose_addr_len = sizeof(prose_app_addr);
+         int bytes_sent = sendto(pdcp_pc5_sockfd, (char *)send_buf, sizeof(sidelink_pc5s_element), 0, (struct sockaddr *)&prose_app_addr, prose_addr_len);
+         if (bytes_sent < 0) {
+            LOG_E(PDCP, "ERROR: Failed to send to ProSe App\n");
+            exit(EXIT_FAILURE);
+         }
+      } else if (pdcp_data_header->msg_type > SL_PC5S_INIT) { //if containing PC5-S message -> send to other UE
 #ifdef PDCP_DEBUG
-          LOG_D(PDCP, "[PDCP][NETLINK] Something in socket, length %zu\n",
-                nas_nlh_rx->nlmsg_len - sizeof(struct nlmsghdr));
+         LOG_D(PDCP,"[pdcp_fifo_read_input_sdus] Received PC5-S message, msg_type: %d)\n", pdcp_data_header->msg_type);
+         LOG_D(PDCP,"[pdcp_fifo_read_input_sdus] Received PC5-S message, rbid: %d)\n", pdcp_data_header->rb_id);
+         LOG_D(PDCP,"[pdcp_fifo_read_input_sdus] Received PC5-S message, data_size: %d)\n", pdcp_data_header->data_size);
+         LOG_D(PDCP,"[pdcp_fifo_read_input_sdus] Received PC5-S message, inst: %d)\n", pdcp_data_header->inst);
+
+         sl_pc5s_msg_recv = calloc(1, sizeof(sidelink_pc5s_element));
+         memcpy((void *)sl_pc5s_msg_recv, (void *)receive_buf, sizeof(sidelink_pc5s_element));
+         if (pdcp_data_header->msg_type == SL_DIRECT_COMMUNICATION_REQUEST){
+            LOG_D(PDCP,"[pdcp_fifo_read_input_sdus] Received DirectCommunicationRequest (PC5-S), seqno: %d)\n", sl_pc5s_msg_recv->pc5sPrimitive.pc5s_direct_communication_req.sequenceNumber);
+            LOG_D(PDCP,"[pdcp_fifo_read_input_sdus] Received DirectCommunicationRequest (PC5-S), ipAddressConfig: %d)\n", sl_pc5s_msg_recv->pc5sPrimitive.pc5s_direct_communication_req.ipAddressConfig);
+         }
 #endif
 
 #ifdef OAI_EMU
 
-          // overwrite function input parameters, because only one netlink socket for all instances
-          if (pdcp_read_header_g.inst < oai_emulation.info.nb_enb_local) {
+         // overwrite function input parameters, because only one netlink socket for all instances
+         if (pdcp_data_header->inst < oai_emulation.info.nb_enb_local) {
             ctxt.frame         = ctxt_cpy.frame;
             ctxt.enb_flag      = ENB_FLAG_YES;
-            ctxt.module_id     = pdcp_read_header_g.inst  +  oai_emulation.info.first_enb_local;
-            ctxt.rnti          = oai_emulation.info.eNB_ue_module_id_to_rnti[ctxt.module_id ][pdcp_read_header_g.rb_id / maxDRB + oai_emulation.info.first_ue_local];
-            rab_id    = pdcp_read_header_g.rb_id % maxDRB;
-          } else {
+            ctxt.module_id     = pdcp_data_header.inst  +  oai_emulation.info.first_enb_local;
+            ctxt.rnti          = oai_emulation.info.eNB_ue_module_id_to_rnti[ctxt.module_id ][pdcp_data_header->rb_id / maxDRB + oai_emulation.info.first_ue_local];
+            rab_id    = pdcp_data_header->rb_id % maxDRB;
+         } else {
             ctxt.frame         = ctxt_cpy.frame;
             ctxt.enb_flag      = ENB_FLAG_NO;
-            ctxt.module_id     = pdcp_read_header_g.inst - oai_emulation.info.nb_enb_local + oai_emulation.info.first_ue_local;
+            ctxt.module_id     = pdcp_data_header->inst - oai_emulation.info.nb_enb_local + oai_emulation.info.first_ue_local;
+            ctxt.rnti          = pdcp_UE_UE_module_id_to_rnti[ctxt.module_id];
+            rab_id    = pdcp_data_header->rb_id % maxDRB;
+         }
+
+         CHECK_CTXT_ARGS(&ctxt);
+         AssertFatal (rab_id    < maxDRB,                       "RB id is too high (%u/%d)!\n", rab_id, maxDRB);
+         /*LGpdcp_read_header.inst = (pdcp_data_header.inst >= oai_emulation.info.nb_enb_local) ? \
+                  pdcp_data_header.inst - oai_emulation.info.nb_enb_local+ NB_eNB_INST + oai_emulation.info.first_ue_local :
+                  pdcp_data_header.inst +  oai_emulation.info.first_enb_local;*/
+#else // OAI_EMU
+         /* TODO: do we have to reset to 0 or not? not for a scenario with 1 UE at least */
+         //          pdcp_data_header.inst = 0;
+         //#warning "TO DO CORRCT VALUES FOR ue mod id, enb mod id"
+         ctxt.frame         = ctxt_cpy.frame;
+         ctxt.enb_flag      = ctxt_cpy.enb_flag;
+
+         LOG_I(PDCP, "[PDCP] pdcp_data_header->rb_id = %d\n", pdcp_data_header->rb_id);
+
+         if (ctxt_cpy.enb_flag) {
+            ctxt.module_id = 0;
+            rab_id      = pdcp_data_header->rb_id % maxDRB;
+            ctxt.rnti          = pdcp_eNB_UE_instance_to_rnti[pdcp_eNB_UE_instance_to_rnti_index];
+         } else {
+            ctxt.module_id = 0;
+            rab_id      = pdcp_data_header->rb_id % maxDRB;
             ctxt.rnti          = pdcp_UE_UE_module_id_to_rnti[ctxt.module_id];
-            rab_id    = pdcp_read_header_g.rb_id % maxDRB;
-          }
+         }
+#endif
+
+         //UE
+         if (!ctxt.enb_flag) {
+            if (rab_id != 0) {
+               if (rab_id == UE_IP_DEFAULT_RAB_ID) {
+                  LOG_I(PDCP, "PDCP_COLL_KEY_DEFAULT_DRB_VALUE(module_id=%d, rnti=%x, enb_flag=%d)\n",
+                        ctxt.module_id, ctxt.rnti, ctxt.enb_flag);
+                  key = PDCP_COLL_KEY_DEFAULT_DRB_VALUE(ctxt.module_id, ctxt.rnti, ctxt.enb_flag);
+                  h_rc = hashtable_get(pdcp_coll_p, key, (void**)&pdcp_p);
+                  LOG_I(PDCP,"request key %x : (%d,%x,%d,%d)\n",
+                        key,ctxt.module_id, ctxt.rnti, ctxt.enb_flag, rab_id);
+               } else {
+                  rab_id = rab_id % maxDRB;
+                  LOG_I(PDCP, "PDCP_COLL_KEY_VALUE(module_id=%d, rnti=%x, enb_flag=%d, rab_id=%d, SRB_FLAG=%d)\n",
+                        ctxt.module_id, ctxt.rnti, ctxt.enb_flag, rab_id, SRB_FLAG_NO);
+                  key = PDCP_COLL_KEY_VALUE(ctxt.module_id, ctxt.rnti, ctxt.enb_flag, rab_id, SRB_FLAG_NO);
+                  h_rc = hashtable_get(pdcp_coll_p, key, (void**)&pdcp_p);
+                  LOG_I(PDCP,"request key %x : (%d,%x,%d,%d)\n",
+                        key,ctxt.module_id, ctxt.rnti, ctxt.enb_flag, rab_id);
+               }
+
+               if (h_rc == HASH_TABLE_OK) {
+                  rab_id = pdcp_p->rb_id;
+#ifdef PDCP_DEBUG
+                  LOG_I(PDCP, "[FRAME %5u][UE][NETLINK][IP->PDCP] INST %d: Received socket with length %d  on Rab %d \n",
+                        ctxt.frame,
+                        pdcp_data_header->inst,
+                        bytes_received,
+                        pdcp_data_header->rb_id);
+
+                  LOG_I(PDCP, "[FRAME %5u][UE][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ / %d Bytes --->][PDCP][MOD %u][UE %u][RB %u]\n",
+                        ctxt.frame,
+                        pdcp_data_header->inst,
+                        pdcp_data_header->rb_id,
+                        pdcp_data_header->data_size,
+                        ctxt.module_id,
+                        ctxt.rnti,
+                        rab_id);
+#endif
+                  MSC_LOG_RX_MESSAGE(
+                        (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
+                              (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_IP_ENB:MSC_IP_UE,
+                                    NULL,
+                                    0,
+                                    MSC_AS_TIME_FMT" DATA-REQ inst %u rb %u rab %u size %u",
+                                    MSC_AS_TIME_ARGS(ctxt_pP),
+                                    pdcp_data_header.inst,
+                                    pdcp_data_header.rb_id,
+                                    rab_id,
+                                    pdcp_data_header.data_size);
+
+                  pdcp_data_req(
+                        &ctxt,
+                        SRB_FLAG_NO,
+                        rab_id,
+                        RLC_MUI_UNDEFINED,
+                        RLC_SDU_CONFIRM_NO,
+                        pdcp_data_header->data_size,
+                        (unsigned char *)receive_buf,
+                        PDCP_TRANSMISSION_MODE_DATA);
+               } else {
+                  MSC_LOG_RX_DISCARDED_MESSAGE(
+                        (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
+                              (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_IP_ENB:MSC_IP_UE,
+                                    NULL,
+                                    0,
+                                    MSC_AS_TIME_FMT" DATA-REQ inst %u rb %u rab %u size %u",
+                                    MSC_AS_TIME_ARGS(ctxt_pP),
+                                    pdcp_data_header.inst,
+                                    pdcp_data_header.rb_id,
+                                    rab_id,
+                                    pdcp_data_header.data_size);
+                  LOG_D(PDCP,
+                        "[FRAME %5u][UE][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ / %d Bytes ---X][PDCP][MOD %u][UE %u][RB %u] NON INSTANCIATED INSTANCE key 0x%"PRIx64", DROPPED\n",
+                        ctxt.frame,
+                        pdcp_data_header->inst,
+                        pdcp_data_header->rb_id,
+                        pdcp_data_header->data_size,
+                        ctxt.module_id,
+                        ctxt.rnti,
+                        rab_id,
+                        key);
+               }
+            }  else { //if (rab_id == 0)
+               LOG_D(PDCP, "Forcing send on DEFAULT_RAB_ID\n");
+               LOG_D(PDCP, "[FRAME %5u][eNB][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ / %d Bytes --->][PDCP][MOD %u][UE %u][RB DEFAULT_RAB_ID %u]\n",
+                     ctxt.frame,
+                     pdcp_data_header->inst,
+                     pdcp_data_header->rb_id,
+                     pdcp_data_header->data_size,
+                     ctxt.module_id,
+                     ctxt.rnti,
+                     DEFAULT_RAB_ID);
+               MSC_LOG_RX_MESSAGE(
+                     (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
+                           (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_IP_ENB:MSC_IP_UE,
+                                 NULL,0,
+                                 MSC_AS_TIME_FMT" DATA-REQ inst %u rb %u default rab %u size %u",
+                                 MSC_AS_TIME_ARGS(ctxt_pP),
+                                 pdcp_data_header->inst,
+                                 pdcp_data_header->rb_id,
+                                 DEFAULT_RAB_ID,
+                                 pdcp_data_header->data_size);
+
+               pdcp_data_req (
+                     &ctxt,
+                     SRB_FLAG_NO,
+                     DEFAULT_RAB_ID,
+                     RLC_MUI_UNDEFINED,
+                     RLC_SDU_CONFIRM_NO,
+                     pdcp_data_header->data_size,
+                     (unsigned char *)receive_buf,
+                     PDCP_TRANSMISSION_MODE_DATA);
+            }
+         }
+          free (sl_pc5s_msg_recv);
+          free (sl_pc5s_msg_send);
+      }
+   }
+
+#endif
+
+   while ((len > 0) && (rlc_data_req_flag !=0))  {
+      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_READ, 1 );
+      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_READ_BUFFER, 1 );
+      len = recvmsg(nas_sock_fd, &nas_msg_rx, 0);
+      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_READ_BUFFER, 0 );
+
+      if (len<=0) {
+         // nothing in pdcp NAS socket
+         //LOG_D(PDCP, "[PDCP][NETLINK] Nothing in socket, length %d \n", len);
+      } else {
+
+         msg_len = len;
+         for (nas_nlh_rx = (struct nlmsghdr *) nl_rx_buf;
+               NLMSG_OK (nas_nlh_rx, msg_len);
+               nas_nlh_rx = NLMSG_NEXT (nas_nlh_rx, msg_len)) {
+
+            if (nas_nlh_rx->nlmsg_type == NLMSG_DONE) {
+               LOG_D(PDCP, "[PDCP][NETLINK] RX NLMSG_DONE\n");
+               //return;
+            }
+
+            if (nas_nlh_rx->nlmsg_type == NLMSG_ERROR) {
+               LOG_D(PDCP, "[PDCP][NETLINK] RX NLMSG_ERROR\n");
+            }
+
+            if (pdcp_read_state_g == 0) {
+               if (nas_nlh_rx->nlmsg_len == sizeof (pdcp_data_req_header_t) + sizeof(struct nlmsghdr)) {
+                  pdcp_read_state_g = 1;  //get
+                  memcpy((void *)&pdcp_read_header_g, (void *)NLMSG_DATA(nas_nlh_rx), sizeof(pdcp_data_req_header_t));
+                  LOG_D(PDCP, "[PDCP][NETLINK] RX pdcp_data_req_header_t inst %u, rb_id %u data_size %d\n",
+                        pdcp_read_header_g.inst, pdcp_read_header_g.rb_id, pdcp_read_header_g.data_size);
+               } else {
+                  LOG_E(PDCP, "[PDCP][NETLINK] WRONG size %d should be sizeof (pdcp_data_req_header_t) + sizeof(struct nlmsghdr)\n",
+                        nas_nlh_rx->nlmsg_len);
+               }
+            } else {
+               pdcp_read_state_g = 0;
+               // print_active_requests()
+#ifdef PDCP_DEBUG
+               LOG_D(PDCP, "[PDCP][NETLINK] Something in socket, length %zu\n",
+                     nas_nlh_rx->nlmsg_len - sizeof(struct nlmsghdr));
+#endif
+
+#ifdef OAI_EMU
 
-          CHECK_CTXT_ARGS(&ctxt);
-          AssertFatal (rab_id    < maxDRB,                       "RB id is too high (%u/%d)!\n", rab_id, maxDRB);
-          /*LGpdcp_read_header.inst = (pdcp_read_header_g.inst >= oai_emulation.info.nb_enb_local) ? \
+
+               // overwrite function input parameters, because only one netlink socket for all instances
+               if (pdcp_read_header_g.inst < oai_emulation.info.nb_enb_local) {
+                  ctxt.frame         = ctxt_cpy.frame;
+                  ctxt.enb_flag      = ENB_FLAG_YES;
+                  ctxt.module_id     = pdcp_read_header_g.inst  +  oai_emulation.info.first_enb_local;
+                  ctxt.rnti          = oai_emulation.info.eNB_ue_module_id_to_rnti[ctxt.module_id ][pdcp_read_header_g.rb_id / maxDRB + oai_emulation.info.first_ue_local];
+                  rab_id    = pdcp_read_header_g.rb_id % maxDRB;
+               } else {
+                  ctxt.frame         = ctxt_cpy.frame;
+                  ctxt.enb_flag      = ENB_FLAG_NO;
+                  ctxt.module_id     = pdcp_read_header_g.inst - oai_emulation.info.nb_enb_local + oai_emulation.info.first_ue_local;
+                  ctxt.rnti          = pdcp_UE_UE_module_id_to_rnti[ctxt.module_id];
+                  rab_id    = pdcp_read_header_g.rb_id % maxDRB;
+               }
+
+               CHECK_CTXT_ARGS(&ctxt);
+               AssertFatal (rab_id    < maxDRB,                       "RB id is too high (%u/%d)!\n", rab_id, maxDRB);
+               /*LGpdcp_read_header.inst = (pdcp_read_header_g.inst >= oai_emulation.info.nb_enb_local) ? \
                   pdcp_read_header_g.inst - oai_emulation.info.nb_enb_local+ NB_eNB_INST + oai_emulation.info.first_ue_local :
                   pdcp_read_header_g.inst +  oai_emulation.info.first_enb_local;*/
 #else // OAI_EMU
-          /* TODO: do we have to reset to 0 or not? not for a scenario with 1 UE at least */
-//          pdcp_read_header_g.inst = 0;
-//#warning "TO DO CORRCT VALUES FOR ue mod id, enb mod id"
-          ctxt.frame         = ctxt_cpy.frame;
-          ctxt.enb_flag      = ctxt_cpy.enb_flag;
+               /* TODO: do we have to reset to 0 or not? not for a scenario with 1 UE at least */
+               //          pdcp_read_header_g.inst = 0;
+               //#warning "TO DO CORRCT VALUES FOR ue mod id, enb mod id"
+               ctxt.frame         = ctxt_cpy.frame;
+               ctxt.enb_flag      = ctxt_cpy.enb_flag;
 
 #ifdef PDCP_DEBUG
-          LOG_I(PDCP, "[PDCP][NETLINK] pdcp_read_header_g.rb_id = %d\n", pdcp_read_header_g.rb_id);
+               LOG_I(PDCP, "[PDCP][NETLINK] pdcp_read_header_g.rb_id = %d\n", pdcp_read_header_g.rb_id);
 #endif
 
-          if (ctxt_cpy.enb_flag) {
-            ctxt.module_id = 0;
-            rab_id      = pdcp_read_header_g.rb_id % maxDRB;
-            ctxt.rnti          = pdcp_eNB_UE_instance_to_rnti[pdcp_eNB_UE_instance_to_rnti_index];
-          } else {
-            ctxt.module_id = 0;
-            rab_id      = pdcp_read_header_g.rb_id % maxDRB;
-            ctxt.rnti          = pdcp_UE_UE_module_id_to_rnti[ctxt.module_id];
-          }
+               if (ctxt_cpy.enb_flag) {
+                  ctxt.module_id = 0;
+                  rab_id      = pdcp_read_header_g.rb_id % maxDRB;
+                  ctxt.rnti          = pdcp_eNB_UE_instance_to_rnti[pdcp_eNB_UE_instance_to_rnti_index];
+               } else {
+                  ctxt.module_id = 0;
+                  rab_id      = pdcp_read_header_g.rb_id % maxDRB;
+                  ctxt.rnti          = pdcp_UE_UE_module_id_to_rnti[ctxt.module_id];
+               }
 
 
 #endif
 
-          if (ctxt.enb_flag) {
-            if (rab_id != 0) {
-              rab_id = rab_id % maxDRB;
-              key = PDCP_COLL_KEY_VALUE(ctxt.module_id, ctxt.rnti, ctxt.enb_flag, rab_id, SRB_FLAG_NO);
-              h_rc = hashtable_get(pdcp_coll_p, key, (void**)&pdcp_p);
+               if (ctxt.enb_flag) {
+                  if (rab_id != 0) {
+                     rab_id = rab_id % maxDRB;
+                     key = PDCP_COLL_KEY_VALUE(ctxt.module_id, ctxt.rnti, ctxt.enb_flag, rab_id, SRB_FLAG_NO);
+                     h_rc = hashtable_get(pdcp_coll_p, key, (void**)&pdcp_p);
 
-              if (h_rc == HASH_TABLE_OK) {
+                     if (h_rc == HASH_TABLE_OK) {
 #ifdef PDCP_DEBUG
-                LOG_D(PDCP, "[FRAME %5u][eNB][NETLINK][IP->PDCP] INST %d: Received socket with length %d (nlmsg_len = %zu) on Rab %d \n",
-                      ctxt.frame,
-                      pdcp_read_header_g.inst,
-                      len,
-                      nas_nlh_rx->nlmsg_len-sizeof(struct nlmsghdr),
-                      pdcp_read_header_g.rb_id);
+                        LOG_D(PDCP, "[FRAME %5u][eNB][NETLINK][IP->PDCP] INST %d: Received socket with length %d (nlmsg_len = %zu) on Rab %d \n",
+                              ctxt.frame,
+                              pdcp_read_header_g.inst,
+                              len,
+                              nas_nlh_rx->nlmsg_len-sizeof(struct nlmsghdr),
+                              pdcp_read_header_g.rb_id);
 #endif
 
-          	    MSC_LOG_RX_MESSAGE(
-          	      (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
-                  (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_IP_ENB:MSC_IP_UE,
-          	      NULL,
-          	      0,
-          	      MSC_AS_TIME_FMT" DATA-REQ inst %u rb %u rab %u size %u",
-          	      MSC_AS_TIME_ARGS(ctxt_pP),
-                  pdcp_read_header_g.inst,
-          	      pdcp_read_header_g.rb_id,
-          	      rab_id,
-          	      pdcp_read_header_g.data_size);
-                LOG_D(PDCP, "[FRAME %5u][eNB][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ / %d Bytes --->][PDCP][MOD %u]UE %u][RB %u]\n",
-                      ctxt_cpy.frame,
-                      pdcp_read_header_g.inst,
-                      pdcp_read_header_g.rb_id,
-                      pdcp_read_header_g.data_size,
-                      ctxt.module_id,
-                      ctxt.rnti,
-                      rab_id);
-
-                pdcp_data_req(&ctxt,
+                        MSC_LOG_RX_MESSAGE(
+                              (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
+                                    (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_IP_ENB:MSC_IP_UE,
+                                          NULL,
+                                          0,
+                                          MSC_AS_TIME_FMT" DATA-REQ inst %u rb %u rab %u size %u",
+                                          MSC_AS_TIME_ARGS(ctxt_pP),
+                                          pdcp_read_header_g.inst,
+                                          pdcp_read_header_g.rb_id,
+                                          rab_id,
+                                          pdcp_read_header_g.data_size);
+                        LOG_D(PDCP, "[FRAME %5u][eNB][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ / %d Bytes --->][PDCP][MOD %u]UE %u][RB %u]\n",
+                              ctxt_cpy.frame,
+                              pdcp_read_header_g.inst,
+                              pdcp_read_header_g.rb_id,
+                              pdcp_read_header_g.data_size,
+                              ctxt.module_id,
+                              ctxt.rnti,
+                              rab_id);
+
+                        pdcp_data_req(&ctxt,
                               SRB_FLAG_NO,
                               rab_id,
                               RLC_MUI_UNDEFINED,
@@ -643,324 +910,325 @@ int pdcp_fifo_read_input_sdus (const protocol_ctxt_t* const  ctxt_pP)
                               pdcp_read_header_g.data_size,
                               (unsigned char *)NLMSG_DATA(nas_nlh_rx),
                               PDCP_TRANSMISSION_MODE_DATA);
-              } else {
-                LOG_D(PDCP, "[FRAME %5u][eNB][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ / %d Bytes ---X][PDCP][MOD %u][UE %u][RB %u] NON INSTANCIATED INSTANCE, DROPPED\n",
-                      ctxt.frame,
-                      pdcp_read_header_g.inst,
-                      pdcp_read_header_g.rb_id,
-                      pdcp_read_header_g.data_size,
-                      ctxt.module_id,
-                      ctxt.rnti,
-                      rab_id);
-              }
-            } else  { // rb_id =0, thus interpreated as broadcast and transported as multiple unicast
-              // is a broadcast packet, we have to send this packet on all default RABS of all connected UEs
-//#warning CODE TO BE REVIEWED, ONLY WORK FOR SIMPLE TOPOLOGY CASES
-              for (ue_id = 0; ue_id < NB_UE_INST; ue_id++) {
-                if (oai_emulation.info.eNB_ue_module_id_to_rnti[ctxt_cpy.module_id][ue_id] != NOT_A_RNTI) {
-                  ctxt.rnti = oai_emulation.info.eNB_ue_module_id_to_rnti[ctxt_cpy.module_id][ue_id];
-                  LOG_D(PDCP, "[FRAME %5u][eNB][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ / %d Bytes --->][PDCP][MOD %u][UE %u][RB DEFAULT_RAB_ID %u]\n",
-                        ctxt.frame,
-                        pdcp_read_header_g.inst,
-                        pdcp_read_header_g.rb_id,
-                        pdcp_read_header_g.data_size,
-                        ctxt.module_id,
-                        ctxt.rnti,
-                        DEFAULT_RAB_ID);
-                  pdcp_data_req (
-                    &ctxt,
-                    SRB_FLAG_NO,
-                    DEFAULT_RAB_ID,
-                    RLC_MUI_UNDEFINED,
-                    RLC_SDU_CONFIRM_NO,
-                    pdcp_read_header_g.data_size,
-                    (unsigned char *)NLMSG_DATA(nas_nlh_rx),
-                    PDCP_TRANSMISSION_MODE_DATA);
-                }
-              }
-            }
-          } else { // enb_flag
-            if (rab_id != 0) {
-              if (rab_id == UE_IP_DEFAULT_RAB_ID) {
-                LOG_I(PDCP, "PDCP_COLL_KEY_DEFAULT_DRB_VALUE(module_id=%d, rnti=%x, enb_flag=%d)\n",
-                    ctxt.module_id, ctxt.rnti, ctxt.enb_flag);
-                key = PDCP_COLL_KEY_DEFAULT_DRB_VALUE(ctxt.module_id, ctxt.rnti, ctxt.enb_flag);
-                h_rc = hashtable_get(pdcp_coll_p, key, (void**)&pdcp_p);
-		LOG_I(PDCP,"request key %x : (%d,%x,%d,%d)\n",
-		      key,ctxt.module_id, ctxt.rnti, ctxt.enb_flag, rab_id);
-              } else {
-                rab_id = rab_id % maxDRB;
-                LOG_I(PDCP, "PDCP_COLL_KEY_VALUE(module_id=%d, rnti=%x, enb_flag=%d, rab_id=%d, SRB_FLAG=%d)\n",
-                    ctxt.module_id, ctxt.rnti, ctxt.enb_flag, rab_id, SRB_FLAG_NO);
-                key = PDCP_COLL_KEY_VALUE(ctxt.module_id, ctxt.rnti, ctxt.enb_flag, rab_id, SRB_FLAG_NO);
-                h_rc = hashtable_get(pdcp_coll_p, key, (void**)&pdcp_p);
-		LOG_I(PDCP,"request key %x : (%d,%x,%d,%d)\n",
-		      key,ctxt.module_id, ctxt.rnti, ctxt.enb_flag, rab_id);
-              }
-
-              if (h_rc == HASH_TABLE_OK) {
-                rab_id = pdcp_p->rb_id;
+                     } else {
+                        LOG_D(PDCP, "[FRAME %5u][eNB][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ / %d Bytes ---X][PDCP][MOD %u][UE %u][RB %u] NON INSTANCIATED INSTANCE, DROPPED\n",
+                              ctxt.frame,
+                              pdcp_read_header_g.inst,
+                              pdcp_read_header_g.rb_id,
+                              pdcp_read_header_g.data_size,
+                              ctxt.module_id,
+                              ctxt.rnti,
+                              rab_id);
+                     }
+                  } else  { // rb_id =0, thus interpreated as broadcast and transported as multiple unicast
+                     // is a broadcast packet, we have to send this packet on all default RABS of all connected UEs
+                     //#warning CODE TO BE REVIEWED, ONLY WORK FOR SIMPLE TOPOLOGY CASES
+                     for (ue_id = 0; ue_id < NB_UE_INST; ue_id++) {
+                        if (oai_emulation.info.eNB_ue_module_id_to_rnti[ctxt_cpy.module_id][ue_id] != NOT_A_RNTI) {
+                           ctxt.rnti = oai_emulation.info.eNB_ue_module_id_to_rnti[ctxt_cpy.module_id][ue_id];
+                           LOG_D(PDCP, "[FRAME %5u][eNB][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ / %d Bytes --->][PDCP][MOD %u][UE %u][RB DEFAULT_RAB_ID %u]\n",
+                                 ctxt.frame,
+                                 pdcp_read_header_g.inst,
+                                 pdcp_read_header_g.rb_id,
+                                 pdcp_read_header_g.data_size,
+                                 ctxt.module_id,
+                                 ctxt.rnti,
+                                 DEFAULT_RAB_ID);
+                           pdcp_data_req (
+                                 &ctxt,
+                                 SRB_FLAG_NO,
+                                 DEFAULT_RAB_ID,
+                                 RLC_MUI_UNDEFINED,
+                                 RLC_SDU_CONFIRM_NO,
+                                 pdcp_read_header_g.data_size,
+                                 (unsigned char *)NLMSG_DATA(nas_nlh_rx),
+                                 PDCP_TRANSMISSION_MODE_DATA);
+                        }
+                     }
+                  }
+               } else { // enb_flag
+                  if (rab_id != 0) {
+                     if (rab_id == UE_IP_DEFAULT_RAB_ID) {
+                        LOG_I(PDCP, "PDCP_COLL_KEY_DEFAULT_DRB_VALUE(module_id=%d, rnti=%x, enb_flag=%d)\n",
+                              ctxt.module_id, ctxt.rnti, ctxt.enb_flag);
+                        key = PDCP_COLL_KEY_DEFAULT_DRB_VALUE(ctxt.module_id, ctxt.rnti, ctxt.enb_flag);
+                        h_rc = hashtable_get(pdcp_coll_p, key, (void**)&pdcp_p);
+                        LOG_I(PDCP,"request key %x : (%d,%x,%d,%d)\n",
+                              key,ctxt.module_id, ctxt.rnti, ctxt.enb_flag, rab_id);
+                     } else {
+                        rab_id = rab_id % maxDRB;
+                        LOG_I(PDCP, "PDCP_COLL_KEY_VALUE(module_id=%d, rnti=%x, enb_flag=%d, rab_id=%d, SRB_FLAG=%d)\n",
+                              ctxt.module_id, ctxt.rnti, ctxt.enb_flag, rab_id, SRB_FLAG_NO);
+                        key = PDCP_COLL_KEY_VALUE(ctxt.module_id, ctxt.rnti, ctxt.enb_flag, rab_id, SRB_FLAG_NO);
+                        h_rc = hashtable_get(pdcp_coll_p, key, (void**)&pdcp_p);
+                        LOG_I(PDCP,"request key %x : (%d,%x,%d,%d)\n",
+                              key,ctxt.module_id, ctxt.rnti, ctxt.enb_flag, rab_id);
+                     }
+
+                     if (h_rc == HASH_TABLE_OK) {
+                        rab_id = pdcp_p->rb_id;
 #ifdef PDCP_DEBUG
-                LOG_I(PDCP, "[FRAME %5u][UE][NETLINK][IP->PDCP] INST %d: Received socket with length %d (nlmsg_len = %zu) on Rab %d \n",
-                      ctxt.frame,
-                      pdcp_read_header_g.inst,
-                      len,
-                      nas_nlh_rx->nlmsg_len-sizeof(struct nlmsghdr),
-                      pdcp_read_header_g.rb_id);
-
-                LOG_I(PDCP, "[FRAME %5u][UE][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ / %d Bytes --->][PDCP][MOD %u][UE %u][RB %u]\n",
-                      ctxt.frame,
-                      pdcp_read_header_g.inst,
-                      pdcp_read_header_g.rb_id,
-                      pdcp_read_header_g.data_size,
-                      ctxt.module_id,
-                      ctxt.rnti,
-                      rab_id);
+                        LOG_I(PDCP, "[FRAME %5u][UE][NETLINK][IP->PDCP] INST %d: Received socket with length %d (nlmsg_len = %zu) on Rab %d \n",
+                              ctxt.frame,
+                              pdcp_read_header_g.inst,
+                              len,
+                              nas_nlh_rx->nlmsg_len-sizeof(struct nlmsghdr),
+                              pdcp_read_header_g.rb_id);
+
+                        LOG_I(PDCP, "[FRAME %5u][UE][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ / %d Bytes --->][PDCP][MOD %u][UE %u][RB %u]\n",
+                              ctxt.frame,
+                              pdcp_read_header_g.inst,
+                              pdcp_read_header_g.rb_id,
+                              pdcp_read_header_g.data_size,
+                              ctxt.module_id,
+                              ctxt.rnti,
+                              rab_id);
 #endif
-          	    MSC_LOG_RX_MESSAGE(
-          	      (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
-                  (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_IP_ENB:MSC_IP_UE,
-          	      NULL,
-          	      0,
-          	      MSC_AS_TIME_FMT" DATA-REQ inst %u rb %u rab %u size %u",
-          	      MSC_AS_TIME_ARGS(ctxt_pP),
-                  pdcp_read_header_g.inst,
-          	      pdcp_read_header_g.rb_id,
-          	      rab_id,
-          	      pdcp_read_header_g.data_size);
-
-                pdcp_data_req(
-                  &ctxt,
-                  SRB_FLAG_NO,
-                  rab_id,
-                  RLC_MUI_UNDEFINED,
-                  RLC_SDU_CONFIRM_NO,
-                  pdcp_read_header_g.data_size,
-                  (unsigned char *)NLMSG_DATA(nas_nlh_rx),
-                  PDCP_TRANSMISSION_MODE_DATA);
-              } else {
-            	MSC_LOG_RX_DISCARDED_MESSAGE(
-                  (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
-                  (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_IP_ENB:MSC_IP_UE,
-                  NULL,
-                  0,
-                  MSC_AS_TIME_FMT" DATA-REQ inst %u rb %u rab %u size %u",
-                  MSC_AS_TIME_ARGS(ctxt_pP),
-                  pdcp_read_header_g.inst,
-                  pdcp_read_header_g.rb_id,
-                  rab_id,
-                  pdcp_read_header_g.data_size);
-                LOG_D(PDCP,
-                      "[FRAME %5u][UE][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ / %d Bytes ---X][PDCP][MOD %u][UE %u][RB %u] NON INSTANCIATED INSTANCE key 0x%"PRIx64", DROPPED\n",
-                      ctxt.frame,
-                      pdcp_read_header_g.inst,
-                      pdcp_read_header_g.rb_id,
-                      pdcp_read_header_g.data_size,
-                      ctxt.module_id,
-                      ctxt.rnti,
-                      rab_id,
-                      key);
-              }
-            }  else {
-              LOG_D(PDCP, "Forcing send on DEFAULT_RAB_ID\n");
-              LOG_D(PDCP, "[FRAME %5u][eNB][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ / %d Bytes --->][PDCP][MOD %u][UE %u][RB DEFAULT_RAB_ID %u]\n",
-                    ctxt.frame,
-                    pdcp_read_header_g.inst,
-                    pdcp_read_header_g.rb_id,
-                    pdcp_read_header_g.data_size,
-                    ctxt.module_id,
-                    ctxt.rnti,
-                    DEFAULT_RAB_ID);
-          	  MSC_LOG_RX_MESSAGE(
-                (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
-                (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_IP_ENB:MSC_IP_UE,
-                NULL,0,
-                MSC_AS_TIME_FMT" DATA-REQ inst %u rb %u default rab %u size %u",
-                MSC_AS_TIME_ARGS(ctxt_pP),
-                pdcp_read_header_g.inst,
-                pdcp_read_header_g.rb_id,
-                DEFAULT_RAB_ID,
-                pdcp_read_header_g.data_size);
-
-              pdcp_data_req (
-                &ctxt,
-                SRB_FLAG_NO,
-                DEFAULT_RAB_ID,
-                RLC_MUI_UNDEFINED,
-                RLC_SDU_CONFIRM_NO,
-                pdcp_read_header_g.data_size,
-                (unsigned char *)NLMSG_DATA(nas_nlh_rx),
-                PDCP_TRANSMISSION_MODE_DATA);
-            }
-          }
+                        MSC_LOG_RX_MESSAGE(
+                              (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
+                                    (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_IP_ENB:MSC_IP_UE,
+                                          NULL,
+                                          0,
+                                          MSC_AS_TIME_FMT" DATA-REQ inst %u rb %u rab %u size %u",
+                                          MSC_AS_TIME_ARGS(ctxt_pP),
+                                          pdcp_read_header_g.inst,
+                                          pdcp_read_header_g.rb_id,
+                                          rab_id,
+                                          pdcp_read_header_g.data_size);
+
+                        pdcp_data_req(
+                              &ctxt,
+                              SRB_FLAG_NO,
+                              rab_id,
+                              RLC_MUI_UNDEFINED,
+                              RLC_SDU_CONFIRM_NO,
+                              pdcp_read_header_g.data_size,
+                              (unsigned char *)NLMSG_DATA(nas_nlh_rx),
+                              PDCP_TRANSMISSION_MODE_DATA);
+                     } else {
+                        MSC_LOG_RX_DISCARDED_MESSAGE(
+                              (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
+                                    (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_IP_ENB:MSC_IP_UE,
+                                          NULL,
+                                          0,
+                                          MSC_AS_TIME_FMT" DATA-REQ inst %u rb %u rab %u size %u",
+                                          MSC_AS_TIME_ARGS(ctxt_pP),
+                                          pdcp_read_header_g.inst,
+                                          pdcp_read_header_g.rb_id,
+                                          rab_id,
+                                          pdcp_read_header_g.data_size);
+                        LOG_D(PDCP,
+                              "[FRAME %5u][UE][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ / %d Bytes ---X][PDCP][MOD %u][UE %u][RB %u] NON INSTANCIATED INSTANCE key 0x%"PRIx64", DROPPED\n",
+                              ctxt.frame,
+                              pdcp_read_header_g.inst,
+                              pdcp_read_header_g.rb_id,
+                              pdcp_read_header_g.data_size,
+                              ctxt.module_id,
+                              ctxt.rnti,
+                              rab_id,
+                              key);
+                     }
+                  }  else {
+                     LOG_D(PDCP, "Forcing send on DEFAULT_RAB_ID\n");
+                     LOG_D(PDCP, "[FRAME %5u][eNB][IP][INSTANCE %u][RB %u][--- PDCP_DATA_REQ / %d Bytes --->][PDCP][MOD %u][UE %u][RB DEFAULT_RAB_ID %u]\n",
+                           ctxt.frame,
+                           pdcp_read_header_g.inst,
+                           pdcp_read_header_g.rb_id,
+                           pdcp_read_header_g.data_size,
+                           ctxt.module_id,
+                           ctxt.rnti,
+                           DEFAULT_RAB_ID);
+                     MSC_LOG_RX_MESSAGE(
+                           (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
+                                 (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_IP_ENB:MSC_IP_UE,
+                                       NULL,0,
+                                       MSC_AS_TIME_FMT" DATA-REQ inst %u rb %u default rab %u size %u",
+                                       MSC_AS_TIME_ARGS(ctxt_pP),
+                                       pdcp_read_header_g.inst,
+                                       pdcp_read_header_g.rb_id,
+                                       DEFAULT_RAB_ID,
+                                       pdcp_read_header_g.data_size);
+
+                     pdcp_data_req (
+                           &ctxt,
+                           SRB_FLAG_NO,
+                           DEFAULT_RAB_ID,
+                           RLC_MUI_UNDEFINED,
+                           RLC_SDU_CONFIRM_NO,
+                           pdcp_read_header_g.data_size,
+                           (unsigned char *)NLMSG_DATA(nas_nlh_rx),
+                           PDCP_TRANSMISSION_MODE_DATA);
+                  }
+               }
 
-        }
+            }
+         }
       }
-    }
-    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_READ, 0 );
-  }
+      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_FIFO_READ, 0 );
+   }
+
 
-  return len;
+   return len;
 # endif
 #else // neither PDCP_USE_NETLINK nor PDCP_USE_RT_FIFO
-  return 0;
+   return 0;
 #endif // PDCP_USE_NETLINK
 }
 
 
 void pdcp_fifo_read_input_sdus_from_otg (const protocol_ctxt_t* const  ctxt_pP) {
 
-  unsigned char       *otg_pkt=NULL;
-  module_id_t          dst_id; // dst for otg
-  rb_id_t              rb_id;
-  unsigned int         pkt_size=0;
+   unsigned char       *otg_pkt=NULL;
+   module_id_t          dst_id; // dst for otg
+   rb_id_t              rb_id;
+   unsigned int         pkt_size=0;
 #if defined(USER_MODE) && defined(OAI_EMU)
-  module_id_t          src_id;
-  static unsigned int  pkt_cnt_enb=0, pkt_cnt_ue=0;
+   module_id_t          src_id;
+   static unsigned int  pkt_cnt_enb=0, pkt_cnt_ue=0;
 
-  Packet_otg_elt_t    *otg_pkt_info=NULL;
-  int                  result;
-  uint8_t              pdcp_mode, is_ue=0;
+   Packet_otg_elt_t    *otg_pkt_info=NULL;
+   int                  result;
+   uint8_t              pdcp_mode, is_ue=0;
 #endif
-  protocol_ctxt_t      ctxt;
-  // we need to add conditions to avoid transmitting data when the UE is not RRC connected.
+   protocol_ctxt_t      ctxt;
+   // we need to add conditions to avoid transmitting data when the UE is not RRC connected.
 #if defined(USER_MODE) && defined(OAI_EMU)
 
-  if (oai_emulation.info.otg_enabled ==1 ) {
-    // module_id is source id
-    while ((otg_pkt_info = pkt_list_remove_head(&(otg_pdcp_buffer[ctxt_pP->instance]))) != NULL) {
-      LOG_I(OTG,"Mod_id %d Frame %d Got a packet (%p), HEAD of otg_pdcp_buffer[%d] is %p and Nb elements is %d\n",
-            ctxt_pP->module_id,
-            ctxt_pP->frame,
-            otg_pkt_info,
-            ctxt_pP->instance,
-            pkt_list_get_head(&(otg_pdcp_buffer[ctxt_pP->instance])),
-            otg_pdcp_buffer[ctxt_pP->instance].nb_elements);
-      //otg_pkt_info = pkt_list_remove_head(&(otg_pdcp_buffer[module_id]));
-      dst_id    = (otg_pkt_info->otg_pkt).dst_id; // type is module_id_t
-      src_id    = (otg_pkt_info->otg_pkt).module_id; // type is module_id_t
-      rb_id     = (otg_pkt_info->otg_pkt).rb_id;
-      is_ue     = (otg_pkt_info->otg_pkt).is_ue;
-      pdcp_mode = (otg_pkt_info->otg_pkt).mode;
-      //    LOG_I(PDCP,"pdcp_fifo, pdcp mode is= %d\n",pdcp_mode);
-
-      // generate traffic if the ue is rrc reconfigured state
-      // if (mac_get_rrc_status(module_id, ctxt_pP->enb_flag, dst_id ) > 2 /*RRC_CONNECTED*/) { // not needed: this test is already done in update_otg_enb
-      otg_pkt = (unsigned char*) (otg_pkt_info->otg_pkt).sdu_buffer;
-      pkt_size = (otg_pkt_info->otg_pkt).sdu_buffer_size;
-
-      if (otg_pkt != NULL) {
-        if (is_ue == 0 ) {
-          PROTOCOL_CTXT_SET_BY_MODULE_ID(
-            &ctxt,
-            src_id,
-            ENB_FLAG_YES,
-            oai_emulation.info.eNB_ue_module_id_to_rnti[ctxt.module_id][dst_id],
-            ctxt_pP->frame,
-            ctxt_pP->subframe,
-	    src_id);
-
-          LOG_D(OTG,"[eNB %d] Frame %d sending packet %d from module %d on rab id %d (src %d, dst %d/%x) pkt size %d for pdcp mode %d\n",
-                ctxt.module_id,
-                ctxt.frame,
-                pkt_cnt_enb++,
-                src_id,
-                rb_id,
-                src_id,
-                dst_id,
-		oai_emulation.info.eNB_ue_module_id_to_rnti[ctxt.module_id][dst_id],
-                pkt_size,
-                pdcp_mode);
-          result = pdcp_data_req(&ctxt,
-                                 SRB_FLAG_NO,
-                                 rb_id,
-                                 RLC_MUI_UNDEFINED,
-                                 RLC_SDU_CONFIRM_NO,
-                                 pkt_size,
-                                 otg_pkt,
-                                 pdcp_mode);
-          if (result != TRUE) {
-            LOG_W(OTG,"PDCP data request failed!\n");
-          }
-        } else {
-          //rb_id= eNB_index * MAX_NUM_RB + DTCH;
-
-
-          LOG_D(OTG,"[UE %d] Frame %d: sending packet %d from module %d on rab id %d (src %d/%x, dst %d) pkt size %d\n",
-                ctxt_pP->module_id,
-                ctxt_pP->frame,
-                pkt_cnt_ue++,
-                ctxt_pP->module_id,
-                rb_id,
-                src_id,
-		pdcp_UE_UE_module_id_to_rnti[ctxt_pP->module_id], // [src_id]
-                dst_id,
-                pkt_size);
-          PROTOCOL_CTXT_SET_BY_MODULE_ID(
-            &ctxt,
-            ctxt_pP->module_id, //src_id,
-            ENB_FLAG_NO,
-            pdcp_UE_UE_module_id_to_rnti[ctxt_pP->module_id],// [src_id]
-            ctxt_pP->frame,
-            ctxt_pP->subframe,
-	    dst_id);
-
-          result = pdcp_data_req( &ctxt,
-                                  SRB_FLAG_NO,
-                                  rb_id,
-                                  RLC_MUI_UNDEFINED,
-                                  RLC_SDU_CONFIRM_NO,
-                                  pkt_size,
-                                  otg_pkt,
-                                  PDCP_TRANSMISSION_MODE_DATA);
-          if (result != TRUE) {
-            LOG_W(OTG,"PDCP data request failed!\n");
-          }
-        }
-
-        free(otg_pkt);
-        otg_pkt = NULL;
-      }
+   if (oai_emulation.info.otg_enabled ==1 ) {
+      // module_id is source id
+      while ((otg_pkt_info = pkt_list_remove_head(&(otg_pdcp_buffer[ctxt_pP->instance]))) != NULL) {
+         LOG_I(OTG,"Mod_id %d Frame %d Got a packet (%p), HEAD of otg_pdcp_buffer[%d] is %p and Nb elements is %d\n",
+               ctxt_pP->module_id,
+               ctxt_pP->frame,
+               otg_pkt_info,
+               ctxt_pP->instance,
+               pkt_list_get_head(&(otg_pdcp_buffer[ctxt_pP->instance])),
+               otg_pdcp_buffer[ctxt_pP->instance].nb_elements);
+         //otg_pkt_info = pkt_list_remove_head(&(otg_pdcp_buffer[module_id]));
+         dst_id    = (otg_pkt_info->otg_pkt).dst_id; // type is module_id_t
+         src_id    = (otg_pkt_info->otg_pkt).module_id; // type is module_id_t
+         rb_id     = (otg_pkt_info->otg_pkt).rb_id;
+         is_ue     = (otg_pkt_info->otg_pkt).is_ue;
+         pdcp_mode = (otg_pkt_info->otg_pkt).mode;
+         //    LOG_I(PDCP,"pdcp_fifo, pdcp mode is= %d\n",pdcp_mode);
+
+         // generate traffic if the ue is rrc reconfigured state
+         // if (mac_get_rrc_status(module_id, ctxt_pP->enb_flag, dst_id ) > 2 /*RRC_CONNECTED*/) { // not needed: this test is already done in update_otg_enb
+         otg_pkt = (unsigned char*) (otg_pkt_info->otg_pkt).sdu_buffer;
+         pkt_size = (otg_pkt_info->otg_pkt).sdu_buffer_size;
+
+         if (otg_pkt != NULL) {
+            if (is_ue == 0 ) {
+               PROTOCOL_CTXT_SET_BY_MODULE_ID(
+                     &ctxt,
+                     src_id,
+                     ENB_FLAG_YES,
+                     oai_emulation.info.eNB_ue_module_id_to_rnti[ctxt.module_id][dst_id],
+                     ctxt_pP->frame,
+                     ctxt_pP->subframe,
+                     src_id);
+
+               LOG_D(OTG,"[eNB %d] Frame %d sending packet %d from module %d on rab id %d (src %d, dst %d/%x) pkt size %d for pdcp mode %d\n",
+                     ctxt.module_id,
+                     ctxt.frame,
+                     pkt_cnt_enb++,
+                     src_id,
+                     rb_id,
+                     src_id,
+                     dst_id,
+                     oai_emulation.info.eNB_ue_module_id_to_rnti[ctxt.module_id][dst_id],
+                     pkt_size,
+                     pdcp_mode);
+               result = pdcp_data_req(&ctxt,
+                     SRB_FLAG_NO,
+                     rb_id,
+                     RLC_MUI_UNDEFINED,
+                     RLC_SDU_CONFIRM_NO,
+                     pkt_size,
+                     otg_pkt,
+                     pdcp_mode);
+               if (result != TRUE) {
+                  LOG_W(OTG,"PDCP data request failed!\n");
+               }
+            } else {
+               //rb_id= eNB_index * MAX_NUM_RB + DTCH;
+
+
+               LOG_D(OTG,"[UE %d] Frame %d: sending packet %d from module %d on rab id %d (src %d/%x, dst %d) pkt size %d\n",
+                     ctxt_pP->module_id,
+                     ctxt_pP->frame,
+                     pkt_cnt_ue++,
+                     ctxt_pP->module_id,
+                     rb_id,
+                     src_id,
+                     pdcp_UE_UE_module_id_to_rnti[ctxt_pP->module_id], // [src_id]
+                     dst_id,
+                     pkt_size);
+               PROTOCOL_CTXT_SET_BY_MODULE_ID(
+                     &ctxt,
+                     ctxt_pP->module_id, //src_id,
+                     ENB_FLAG_NO,
+                     pdcp_UE_UE_module_id_to_rnti[ctxt_pP->module_id],// [src_id]
+                     ctxt_pP->frame,
+                     ctxt_pP->subframe,
+                     dst_id);
+
+               result = pdcp_data_req( &ctxt,
+                     SRB_FLAG_NO,
+                     rb_id,
+                     RLC_MUI_UNDEFINED,
+                     RLC_SDU_CONFIRM_NO,
+                     pkt_size,
+                     otg_pkt,
+                     PDCP_TRANSMISSION_MODE_DATA);
+               if (result != TRUE) {
+                  LOG_W(OTG,"PDCP data request failed!\n");
+               }
+            }
+
+            free(otg_pkt);
+            otg_pkt = NULL;
+         }
 
-      // } //else LOG_D(OTG,"ctxt_pP->frame %d enb %d-> ue %d link not yet established state %d  \n", ctxt_pP->frame, eNB_index,dst_id - NB_eNB_INST, mac_get_rrc_status(module_id, ctxt_pP->enb_flag, dst_id - NB_eNB_INST));
+         // } //else LOG_D(OTG,"ctxt_pP->frame %d enb %d-> ue %d link not yet established state %d  \n", ctxt_pP->frame, eNB_index,dst_id - NB_eNB_INST, mac_get_rrc_status(module_id, ctxt_pP->enb_flag, dst_id - NB_eNB_INST));
 
-    }
-  }
+      }
+   }
 
 #else
 
-  if ((otg_enabled==1) && (ctxt_pP->enb_flag == ENB_FLAG_YES)) { // generate DL traffic
-    unsigned int ctime=0;
-    ctime = ctxt_pP->frame * 100;
+   if ((otg_enabled==1) && (ctxt_pP->enb_flag == ENB_FLAG_YES)) { // generate DL traffic
+      unsigned int ctime=0;
+      ctime = ctxt_pP->frame * 100;
 
-    /*if  ((mac_get_rrc_status(eNB_index, ctxt_pP->enb_flag, 0 ) > 2) &&
+      /*if  ((mac_get_rrc_status(eNB_index, ctxt_pP->enb_flag, 0 ) > 2) &&
     (mac_get_rrc_status(eNB_index, ctxt_pP->enb_flag, 1 ) > 2)) { */
-    PROTOCOL_CTXT_SET_BY_MODULE_ID(
-      &ctxt,
-      ctxt_pP->module_id,
-      ctxt_pP->enb_flag,
-      NOT_A_RNTI,
-      ctxt_pP->frame,
-      ctxt_pP->subframe,
-      ctxt_pP->module_id);
-
-    for (dst_id = 0; dst_id<NUMBER_OF_UE_MAX; dst_id++) {
-      ctxt.rnti = oai_emulation.info.eNB_ue_module_id_to_rnti[ctxt.module_id][dst_id];
-
-      if (ctxt.rnti != NOT_A_RNTI) {
-        if (mac_eNB_get_rrc_status(ctxt.module_id, ctxt.rnti ) > 2 /*RRC_SI_RECEIVED*/) {
-        unsigned int temp = 0;
-          otg_pkt=packet_gen(
-                    ENB_MODULE_ID_TO_INSTANCE(ctxt.module_id),
-                    UE_MODULE_ID_TO_INSTANCE(dst_id),
-                    0,
-                    ctime,
-                    &temp);
-        pkt_size = temp;
-
-        if (otg_pkt != NULL) {
-          rb_id = dst_id * maxDRB + DTCH;
-          pdcp_data_req(&ctxt,
+      PROTOCOL_CTXT_SET_BY_MODULE_ID(
+            &ctxt,
+            ctxt_pP->module_id,
+            ctxt_pP->enb_flag,
+            NOT_A_RNTI,
+            ctxt_pP->frame,
+            ctxt_pP->subframe,
+            ctxt_pP->module_id);
+
+      for (dst_id = 0; dst_id<NUMBER_OF_UE_MAX; dst_id++) {
+         ctxt.rnti = oai_emulation.info.eNB_ue_module_id_to_rnti[ctxt.module_id][dst_id];
+
+         if (ctxt.rnti != NOT_A_RNTI) {
+            if (mac_eNB_get_rrc_status(ctxt.module_id, ctxt.rnti ) > 2 /*RRC_SI_RECEIVED*/) {
+               unsigned int temp = 0;
+               otg_pkt=packet_gen(
+                     ENB_MODULE_ID_TO_INSTANCE(ctxt.module_id),
+                     UE_MODULE_ID_TO_INSTANCE(dst_id),
+                     0,
+                     ctime,
+                     &temp);
+               pkt_size = temp;
+
+               if (otg_pkt != NULL) {
+                  rb_id = dst_id * maxDRB + DTCH;
+                  pdcp_data_req(&ctxt,
                         SRB_FLAG_NO,
                         rb_id,
                         RLC_MUI_UNDEFINED,
@@ -968,15 +1236,130 @@ void pdcp_fifo_read_input_sdus_from_otg (const protocol_ctxt_t* const  ctxt_pP)
                         pkt_size,
                         otg_pkt,
                         PDCP_TRANSMISSION_MODE_DATA);
-            LOG_I(OTG,
-                  "send packet from module %d on rab id %d (src %d, dst %d) pkt size %d\n",
-                  ctxt_pP->module_id, rb_id, ctxt_pP->module_id, dst_id, pkt_size);
-            free(otg_pkt);
-          }
-        }
+                  LOG_I(OTG,
+                        "send packet from module %d on rab id %d (src %d, dst %d) pkt size %d\n",
+                        ctxt_pP->module_id, rb_id, ctxt_pP->module_id, dst_id, pkt_size);
+                  free(otg_pkt);
+               }
+            }
+         }
+      }
+   }
+
+#endif
+}
+
+//TTN for D2D (PC5S)
+#ifdef Rel14
+
+int
+pdcp_pc5_socket_init() {
+   pthread_attr_t     attr;
+   struct sched_param sched_param;
+   int optval; // flag value for setsockopt
+   int n; // message byte size
+
+   //create PDCP socket
+   pdcp_pc5_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
+   if (pdcp_pc5_sockfd < 0){
+      LOG_E(PDCP,"[pdcp_pc5_socket_init] Error opening socket %d (%d:%s)\n",pdcp_pc5_sockfd,errno, strerror(errno));
+      exit(EXIT_FAILURE);
+   }
+
+   optval = 1;
+   setsockopt(pdcp_pc5_sockfd, SOL_SOCKET, SO_REUSEADDR,
+         (const void *)&optval , sizeof(int));
+
+   fcntl(pdcp_pc5_sockfd,F_SETFL,O_NONBLOCK);
+
+   bzero((char *) &pdcp_sin, sizeof(pdcp_sin));
+   pdcp_sin.sin_family = AF_INET;
+   pdcp_sin.sin_addr.s_addr = htonl(INADDR_ANY);
+   pdcp_sin.sin_port = htons(PDCP_SOCKET_PORT_NO);
+   // associate the parent socket with a port
+   if (bind(pdcp_pc5_sockfd, (struct sockaddr *) &pdcp_sin,
+         sizeof(pdcp_sin)) < 0) {
+      LOG_E(PDCP,"[pdcp_pc5_socket_init] ERROR: Failed on binding the socket\n");
+      exit(1);
+   }
+
+}
+
+
+
+//--------------------------------------------------------
+void *pdcp_pc5_socket_thread_fct(void *arg)
+{
+
+   int prose_addr_len;
+   char send_buf[BUFSIZE];
+   char receive_buf[BUFSIZE];
+   int optval; // flag value for setsockopt
+   int n; // message byte size
+   sidelink_pc5s_element *sl_pc5s_msg_recv = NULL;
+   sidelink_pc5s_element *sl_pc5s_msg_send = NULL;
+   uint32_t sourceL2Id;
+   uint32_t groupL2Id;
+   module_id_t         module_id;
+
+   module_id = 0 ; //hardcoded for testing only
+
+   LOG_I(PDCP,"*****************[pdcp_pc5_socket_thread_fct]**************\n");
+   //from the main program, listen for the incoming messages from control socket (ProSe App)
+   prose_addr_len = sizeof(prose_app_addr);
+
+   while (1) {
+      LOG_I(RRC,"[pdcp_pc5_socket_thread_fct]: Listening to incoming connection from ProSe App \n");
+      // receive a message from ProSe App
+      memset(receive_buf, 0, BUFSIZE);
+      n = recvfrom(pdcp_pc5_sockfd, receive_buf, BUFSIZE, 0,
+            (struct sockaddr *) &prose_app_addr, &prose_addr_len);
+      if (n < 0){
+         LOG_E(RRC, "ERROR: Failed to receive from ProSe App\n");
+         exit(EXIT_FAILURE);
       }
-    }
-  }
 
+      sl_pc5s_msg_recv = calloc(1, sizeof(sidelink_pc5s_element));
+      memcpy((void *)sl_pc5s_msg_recv, (void *)receive_buf, sizeof(sidelink_pc5s_element));
+
+      //process the message (in reality, we don't need to do that, thus, forward to other ue)
+
+     // LOG_I(RRC,"[pdcp_pc5_socket_thread_fct]: Received DirectCommunicationRequest (PC5-S) on socket from ProSe App (msg type: %d)\n", sl_pc5s_msg_recv->type);
+
+      //TODO: get SL_UE_STATE from lower layer
+      /*
+         LOG_I(RRC,"[rrc_control_socket_thread_fct]: Send UEStateInformation to ProSe App \n");
+         memset(send_buf, 0, BUFSIZE);
+
+         sl_ctrl_msg_send = calloc(1, sizeof(struct sidelink_ctrl_element));
+         sl_ctrl_msg_send->type = UE_STATUS_INFO;
+         sl_ctrl_msg_send->sidelinkPrimitive.ue_state = UE_STATE_OFF_NETWORK; //off-network
+         memcpy((void *)send_buf, (void *)sl_ctrl_msg_send, sizeof(struct sidelink_ctrl_element));
+         free(sl_ctrl_msg_send);
+
+         prose_addr_len = sizeof(prose_app_addr);
+         n = sendto(ctrl_sock_fd, (char *)send_buf, sizeof(struct sidelink_ctrl_element), 0, (struct sockaddr *)&prose_app_addr, prose_addr_len);
+         if (n < 0) {
+            LOG_E(RRC, "ERROR: Failed to send to ProSe App\n");
+            exit(EXIT_FAILURE);
+         }
+
+
+#ifdef DEBUG_CTRL_SOCKET
+         struct sidelink_ctrl_element *ptr_ctrl_msg = NULL;
+         ptr_ctrl_msg = (struct sidelink_ctrl_element *) send_buf;
+         LOG_I(RRC,"[rrc_control_socket_thread_fct][UEStateInformation] msg type: %d\n",ptr_ctrl_msg->type);
+         LOG_I(RRC,"[rrc_control_socket_thread_fct][UEStateInformation] UE state: %d\n",ptr_ctrl_msg->sidelinkPrimitive.ue_state);
 #endif
+       */
+
+   }
+   free (sl_pc5s_msg_recv);
+   return 0;
 }
+
+
+
+#endif
+
+
diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp_netlink.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp_netlink.c
index eddd42c34b5317588889bd111153ae3a0b641b1b..f0288f21a97d60bc8ada511f4804ebf51c88aa1a 100644
--- a/openair2/LAYER2/PDCP_v10.1.0/pdcp_netlink.c
+++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp_netlink.c
@@ -84,8 +84,6 @@ static uint32_t *pdcp_netlink_nb_element_ue = NULL;
 
 time_stats_t ip_pdcp_stats_tmp;
 
-static void *pdcp_netlink_thread_fct(void *arg);
-
 //-----------------------------------------------------------------------------
 int
 pdcp_netlink_init(
@@ -152,6 +150,8 @@ pdcp_netlink_init(
       exit(EXIT_FAILURE);
     }
 
+
+
     sched_param.sched_priority = 10;
 
     pthread_attr_setschedpolicy(&attr, SCHED_RR);
@@ -168,6 +168,7 @@ pdcp_netlink_init(
     }
 
     pthread_setname_np( pdcp_netlink_thread, "PDCP netlink" );
+
   }
 
   return 0;
@@ -218,6 +219,7 @@ void *pdcp_netlink_thread_fct(void *arg)
 
     len = recvmsg(nas_sock_fd, &nas_msg_rx, 0);
 
+
     if (len == 0) {
       /* Other peer (kernel) has performed an orderly shutdown
        */
@@ -311,8 +313,11 @@ void *pdcp_netlink_thread_fct(void *arg)
         }
       }
     }
+
   }
 
   return NULL;
 }
 #endif
+
+
diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp_proto_extern.h b/openair2/LAYER2/PDCP_v10.1.0/pdcp_proto_extern.h
index afcc2fdd0255dc0f11d15df8e670ee29dec8119f..fb4eff596ddd1dd4b0487eb14295f7ee746db13d 100644
--- a/openair2/LAYER2/PDCP_v10.1.0/pdcp_proto_extern.h
+++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp_proto_extern.h
@@ -63,4 +63,7 @@ extern void     pdcp_process_input_sdus_tr (struct pdcp_entity *pdcpP);
 extern void     init_pdcp (struct pdcp_entity *pdcpP, struct rb_dispatcher *rbP, uint8_t rb_idP);
 extern void    *pdcp_tx (void *argP);
 #endif
+
+void pdcp_pc5_socket_init();
+
 #endif
diff --git a/openair2/RRC/LITE/defs.h b/openair2/RRC/LITE/defs.h
index e14c14f4159f1578fe2e56ef2f3dfcccb73a496c..6fd9ffcffbeb2afcfd5c9e2ec0f0ba08bcda192a 100644
--- a/openair2/RRC/LITE/defs.h
+++ b/openair2/RRC/LITE/defs.h
@@ -104,11 +104,19 @@ struct GroupCommunicationEstablishReq {
    uint8_t pppp;
 };
 
+struct GroupCommunicationReleaseReq {
+   uint32_t sourceL2Id;
+   uint32_t groupL2Id;
+   int slrb_id;
+};
+
 struct DirectCommunicationEstablishReq {
    uint32_t sourceL2Id;
    uint32_t destinationL2Id;
+   uint32_t pppp;
 };
 
+
 struct sidelink_ctrl_element {
    unsigned short type;
    union {
@@ -117,6 +125,7 @@ struct sidelink_ctrl_element {
       Group_Communication_Status_t group_comm_release_rsp;
       //struct DirectCommunicationReleaseReq  direct_comm_release_req;
       SL_UE_STATE_t ue_state;
+      //struct GroupCommunicationReleaseReq group_comm_release_req;
       int slrb_id;
 
    } sidelinkPrimitive;
@@ -693,13 +702,19 @@ typedef struct UE_RRC_INST_s {
   SystemInformationBlockType11_t *sib11[NB_CNX_UE];
   uint8_t                           *MIB;
 #ifdef Rel14
-  //TTN - SIB18
+  //SIB18
   SystemInformationBlockType18_r12_t *sib18[NB_CNX_UE];
   SystemInformationBlockType19_r12_t *sib19[NB_CNX_UE];
 
   SBCCH_SL_BCH_MessageType_t   mib_sl[NB_CNX_UE];
   /// Preconfiguration for Sidelink
   struct SL_Preconfiguration_r12 *SL_Preconfiguration[NB_CNX_UE];
+  //source L2 Id
+  uint32_t sourceL2Id;
+  //group L2 Id
+  uint32_t groupL2Id;
+  //destination L2 Id
+  uint32_t destinationL2Id;
 #endif
 
 #if defined(Rel10) || defined(Rel14)
diff --git a/openair2/RRC/LITE/rrc_UE.c b/openair2/RRC/LITE/rrc_UE.c
index 2439cacf53ceb1ed2ef0ad7c193665a02692e80a..a2f790968c1ea8136796e1504b71c2b069656709 100644
--- a/openair2/RRC/LITE/rrc_UE.c
+++ b/openair2/RRC/LITE/rrc_UE.c
@@ -369,8 +369,15 @@ void init_SL_preconfig(UE_RRC_INST *UE, const uint8_t eNB_index )
   UE->DRB_config[0][0]->logicalChannelIdentity = CALLOC(1, sizeof(long));
   *(UE->DRB_config[0][0]->logicalChannelIdentity) = UE->DRB_config[0][0]->drb_Identity; //(long) (ue_context_pP->ue_context.e_rab[i].param.e_rab_id + 2); // value : x+2
   
-
-
+  // TTN - Establish a new SLRB for PC5-S (using DRB 10 for now)
+  UE->DRB_config[0][1] = CALLOC(1,sizeof(struct DRB_ToAddMod));
+  UE->DRB_config[0][1]->eps_BearerIdentity = CALLOC(1, sizeof(long));
+  UE->DRB_config[0][1]->drb_Identity =  10;
+  UE->DRB_config[0][1]->eps_BearerIdentity = CALLOC(1, sizeof(long));
+  // allowed value 5..15, value : x+4
+  *(UE->DRB_config[0][1]->eps_BearerIdentity) = 10;
+  UE->DRB_config[0][1]->logicalChannelIdentity = CALLOC(1, sizeof(long));
+  *(UE->DRB_config[0][1]->logicalChannelIdentity) = UE->DRB_config[0][1]->drb_Identity; //(long) (ue_context_pP->ue_context.e_rab[i].param.e_rab_id + 2); // value : x+2
 
   struct RLC_Config                  *DRB_rlc_config                   = CALLOC(1,sizeof(struct RLC_Config));
   struct PDCP_Config                 *DRB_pdcp_config                  = CALLOC(1,sizeof(struct PDCP_Config));
@@ -385,9 +392,11 @@ void init_SL_preconfig(UE_RRC_INST *UE, const uint8_t eNB_index )
   DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
   DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering = T_Reordering_ms35;
   UE->DRB_config[0][0]->rlc_Config = DRB_rlc_config;
+  UE->DRB_config[0][1]->rlc_Config = DRB_rlc_config;
 
   DRB_pdcp_config = CALLOC(1, sizeof(*DRB_pdcp_config));
   UE->DRB_config[0][0]->pdcp_Config = DRB_pdcp_config;
+  UE->DRB_config[0][1]->pdcp_Config = DRB_pdcp_config;
   DRB_pdcp_config->discardTimer = CALLOC(1, sizeof(long));
   *DRB_pdcp_config->discardTimer = PDCP_Config__discardTimer_infinity;
   DRB_pdcp_config->rlc_AM = NULL;
@@ -401,6 +410,7 @@ void init_SL_preconfig(UE_RRC_INST *UE, const uint8_t eNB_index )
   DRB_pdcp_config->headerCompression.present = PDCP_Config__headerCompression_PR_notUsed;
 
   UE->DRB_config[0][0]->logicalChannelConfig = DRB_lchan_config;
+  UE->DRB_config[0][1]->logicalChannelConfig = DRB_lchan_config;
   DRB_ul_SpecificParameters = CALLOC(1, sizeof(*DRB_ul_SpecificParameters));
   DRB_lchan_config->ul_SpecificParameters = DRB_ul_SpecificParameters;
 
@@ -417,6 +427,7 @@ void init_SL_preconfig(UE_RRC_INST *UE, const uint8_t eNB_index )
 
   UE->DRB_configList = CALLOC(1,sizeof(DRB_ToAddModList_t));
   ASN_SEQUENCE_ADD(&UE->DRB_configList->list,UE->DRB_config[0][0]);
+  ASN_SEQUENCE_ADD(&UE->DRB_configList->list,UE->DRB_config[0][1]);
 
   rrc_pdcp_config_asn1_req(&ctxt,
 			   (SRB_ToAddModList_t *) NULL,
@@ -5422,6 +5433,7 @@ void *rrc_control_socket_thread_fct(void *arg)
    uint32_t groupL2Id;
    module_id_t         module_id;
 
+   module_id = 0 ; //hardcoded for testing only
 
    //from the main program, listen for the incoming messages from control socket (ProSe App)
    prose_addr_len = sizeof(prose_app_addr);
@@ -5488,8 +5500,7 @@ void *rrc_control_socket_thread_fct(void *arg)
       case GROUP_COMMUNICATION_ESTABLISH_REQ:
          sourceL2Id = sl_ctrl_msg_recv->sidelinkPrimitive.group_comm_establish_req.sourceL2Id;
          groupL2Id = sl_ctrl_msg_recv->sidelinkPrimitive.group_comm_establish_req.groupL2Id;
-         //sourceL2Id = 0x123456;
-         //groupL2Id = 0x789ABC;
+
 #ifdef DEBUG_CTRL_SOCKET
          LOG_I(RRC,"[rrc_control_socket_thread_fct][GroupCommunicationEstablishReq] Received on socket from ProSe App (msg type: %d)\n",sl_ctrl_msg_recv->type);
          LOG_I(RRC,"[rrc_control_socket_thread_fct][GroupCommunicationEstablishReq] type: %d\n",sl_ctrl_msg_recv->sidelinkPrimitive.group_comm_establish_req.type);
@@ -5497,10 +5508,14 @@ void *rrc_control_socket_thread_fct(void *arg)
          LOG_I(RRC,"[rrc_control_socket_thread_fct][GroupCommunicationEstablishReq] group Id: %d\n",sl_ctrl_msg_recv->sidelinkPrimitive.group_comm_establish_req.groupL2Id);
          LOG_I(RRC,"[rrc_control_socket_thread_fct][GroupCommunicationEstablishReq] group IP Address: " IPV4_ADDR "\n",IPV4_ADDR_FORMAT(sl_ctrl_msg_recv->sidelinkPrimitive.group_comm_establish_req.groupIpAddress));
 #endif
+
+         //store sourceL2Id
+         UE_rrc_inst[module_id].sourceL2Id = sourceL2Id;
+         UE_rrc_inst[module_id].groupL2Id = groupL2Id;
          // configure lower layers PDCP/MAC/PHY for this communication
          //init_SL_preconfig()
          //configure MAC with sourceL2Id/groupL2ID (to be used in MAC/ue_procedures.c)
-         module_id = 0 ; //hardcoded for testing only
+
          rrc_mac_config_req_ue(module_id,0,0, //eNB_index =0
                 (RadioResourceConfigCommonSIB_t *)NULL,
                 (struct PhysicalConfigDedicated *)NULL,
@@ -5573,12 +5588,56 @@ void *rrc_control_socket_thread_fct(void *arg)
          LOG_I(RRC,"[rrc_control_socket_thread_fct][GroupCommunicationEstablishResponse]  slrb_id: %d\n",ptr_ctrl_msg->sidelinkPrimitive.slrb_id);
 #endif
          break;
+
       case GROUP_COMMUNICATION_RELEASE_REQ:
          printf("-----------------------------------\n");
 #ifdef DEBUG_CTRL_SOCKET
          LOG_I(RRC,"[rrc_control_socket_thread_fct][GroupCommunicationReleaseRequest] Received on socket from ProSe App (msg type: %d)\n",sl_ctrl_msg_recv->type);
          LOG_I(RRC,"[rrc_control_socket_thread_fct][GroupCommunicationReleaseRequest] Slrb Id: %i\n",sl_ctrl_msg_recv->sidelinkPrimitive.slrb_id);
 #endif
+         //reset groupL2ID from MAC LAYER
+         UE_rrc_inst[module_id].groupL2Id = 0x00000000;
+         sourceL2Id = UE_rrc_inst[module_id].sourceL2Id;
+
+         rrc_mac_config_req_ue(module_id,0,0, //eNB_index =0
+                    (RadioResourceConfigCommonSIB_t *)NULL,
+                    (struct PhysicalConfigDedicated *)NULL,
+         #if defined(Rel10) || defined(Rel14)
+                    (SCellToAddMod_r10_t *)NULL,
+                    //struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
+         #endif
+                    (MeasObjectToAddMod_t **)NULL,
+                    (MAC_MainConfig_t *)NULL,
+                    0,
+                    (struct LogicalChannelConfig *)NULL,
+                    (MeasGapConfig_t *)NULL,
+                    (TDD_Config_t *)NULL,
+                    (MobilityControlInfo_t *)NULL,
+                    NULL,
+                    NULL,
+                    NULL,
+                    NULL,
+                    NULL,
+                    NULL
+         #if defined(Rel10) || defined(Rel14)
+                    ,0,
+                    (MBSFN_AreaInfoList_r9_t *)NULL,
+                    (PMCH_InfoList_r9_t *)NULL
+
+         #endif
+         #ifdef CBA
+                    ,
+                    0,
+                    0
+         #endif
+         #if defined(Rel10) || defined(Rel14)
+                    ,
+                    &sourceL2Id,
+                    NULL
+         #endif
+                    );
+
+
          LOG_I(RRC,"[rrc_control_socket_thread_fct]Send GroupCommunicationReleaseResponse to ProSe App \n");
          memset(send_buf, 0, BUFSIZE);
 
diff --git a/targets/RT/USER/lte-softmodem-stub.c b/targets/RT/USER/lte-softmodem-stub.c
index cd048a007507fece05014a93c8e7101a4dd8428a..3fe1f851822e680d7bcd955e679a9a45c565785e 100644
--- a/targets/RT/USER/lte-softmodem-stub.c
+++ b/targets/RT/USER/lte-softmodem-stub.c
@@ -1067,6 +1067,8 @@ int main( int argc, char **argv )
 #ifdef Rel14
   printf ("RRC control socket\n");
   rrc_control_socket_init();
+  printf ("PDCP PC5S socket\n");
+  pdcp_pc5_socket_init();
 #endif