From 9c00f4b782e324832836088dde6fc8fd0ba0f515 Mon Sep 17 00:00:00 2001
From: Tien-Thinh Nguyen <tien-thinh.nguyen@eurecom.fr>
Date: Fri, 12 Jan 2018 11:43:15 +0100
Subject: [PATCH] update RRC_UE to support PC5-S

---
 openair2/LAYER2/MAC/config.c        |  11 ++-
 openair2/LAYER2/MAC/proto.h         |   3 +-
 openair2/LAYER2/MAC/ue_procedures.c |  23 ++---
 openair2/RRC/LITE/defs.h            |  16 +++-
 openair2/RRC/LITE/rrc_UE.c          | 129 ++++++++++++++++++++++------
 5 files changed, 143 insertions(+), 39 deletions(-)

diff --git a/openair2/LAYER2/MAC/config.c b/openair2/LAYER2/MAC/config.c
index 65a55a21c4d..52a4e345dab 100644
--- a/openair2/LAYER2/MAC/config.c
+++ b/openair2/LAYER2/MAC/config.c
@@ -1049,7 +1049,8 @@ rrc_mac_config_req_ue(
 #endif
 #if defined(Rel14)
   ,uint32_t                        *sourceL2Id,
-  uint32_t                         *groupL2Id
+  uint32_t                         *groupL2Id,
+  uint32_t                         *destinationL2Id
 #endif
 
                       )
@@ -1369,12 +1370,20 @@ rrc_mac_config_req_ue(
 
   // Panos: Call to the phy_config_request_ue() function of the interface to copy the UE_PHY_Config_t interface
   // configuration to the PHY common and dedicated configuration originating from RRC.
+
 //for D2D
 #if defined(Rel10) || defined(Rel14)
   if ( sourceL2Id && groupL2Id) {
      UE_mac_inst[Mod_idP].sourceL2Id = *sourceL2Id;
      UE_mac_inst[Mod_idP].groupL2Id = *groupL2Id;
+  } else if (sourceL2Id) { //reset groupL2Id
+     UE_mac_inst[Mod_idP].groupL2Id = 0x00000000;
+  }
+  if ( sourceL2Id && destinationL2Id) {
+       UE_mac_inst[Mod_idP].sourceL2Id = *sourceL2Id;
+       UE_mac_inst[Mod_idP].destinationL2Id = *destinationL2Id;
   }
+
 #endif
 
   return(0);
diff --git a/openair2/LAYER2/MAC/proto.h b/openair2/LAYER2/MAC/proto.h
index b14b6d8367b..58083b934eb 100644
--- a/openair2/LAYER2/MAC/proto.h
+++ b/openair2/LAYER2/MAC/proto.h
@@ -932,7 +932,8 @@ int rrc_mac_config_req_ue(module_id_t     module_idP,
 #if defined(Rel14)
            ,
            uint32_t *sourceL2Id,
-           uint32_t *groupL2Id
+           uint32_t *groupL2Id,
+           uint32_t *destinationL2Id
 #endif
 			  );
 
diff --git a/openair2/LAYER2/MAC/ue_procedures.c b/openair2/LAYER2/MAC/ue_procedures.c
index 1880b0ae86f..5889b8da0db 100644
--- a/openair2/LAYER2/MAC/ue_procedures.c
+++ b/openair2/LAYER2/MAC/ue_procedures.c
@@ -2740,6 +2740,7 @@ SLSCH_t *ue_get_slsch(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_
   UE_MAC_INST *ue = &UE_mac_inst[module_idP];
   int rvtab[4] = {0,2,3,1};
   int sdu_length;
+  uint32_t destL2Id; //groupL2Id/destinationL2Id
 
   // 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;
@@ -2776,11 +2777,13 @@ SLSCH_t *ue_get_slsch(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_
     int req;
 
     if (ue->slsch_lcid == 10) {
-    if (TBS<=rlc_status.bytes_in_buffer) req=TBS;
-    else req = rlc_status.bytes_in_buffer;
+       if (TBS<=rlc_status.bytes_in_buffer) req=TBS;
+       else req = rlc_status.bytes_in_buffer;
+       destL2Id = ue->destinationL2Id;
     } else if (ue->slsch_lcid == 3){
        if (TBS<=rlc_status_data.bytes_in_buffer) req=TBS;
        else req = rlc_status_data.bytes_in_buffer;
+       destL2Id = ue->groupL2Id;
     }
 
     if (req>0) {
@@ -2800,8 +2803,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: 0x%08x \n",ue->sourceL2Id);
+	LOG_I(MAC,"groupL2Id/destinationL2Id: 0x%08x \n",destL2Id);
 
 	slsch->payload = (unsigned char*)ue->slsch_pdu.payload;
 	if (sdu_length < 128) { 
@@ -2814,9 +2817,9 @@ SLSCH_t *ue_get_slsch(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_
 	  shorth->SRC07 = (ue->sourceL2Id>>16) & 0x000000ff;
 	  shorth->SRC815 = (ue->sourceL2Id>>8) & 0x000000ff;
 	  shorth->SRC1623 = ue->sourceL2Id & 0x000000ff;
-     shorth->DST07 = (ue->groupL2Id >>16) & 0x000000ff;
-     shorth->DST815 = (ue->groupL2Id>>8) & 0x000000ff;
-	  shorth->DST1623 = ue->groupL2Id & 0x000000ff;
+     shorth->DST07 = (destL2Id >>16) & 0x000000ff;
+     shorth->DST815 = (destL2Id>>8) & 0x000000ff;
+	  shorth->DST1623 = destL2Id & 0x000000ff;
 
 	  shorth->V=0x1;
 	}
@@ -2830,9 +2833,9 @@ SLSCH_t *ue_get_slsch(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_
 	  longh->SRC07 = (ue->sourceL2Id >>16) & 0x000000ff;
 	  longh->SRC815 = (ue->sourceL2Id>>8) & 0x000000ff;
 	  longh->SRC1623 = ue->sourceL2Id & 0x000000ff;
-	  longh->DST07 = (ue->groupL2Id >>16) & 0x000000ff;
-	  longh->DST815 = (ue->groupL2Id>>8) & 0x000000ff;
-	  longh->DST1623 = ue->groupL2Id & 0x000000ff;
+	  longh->DST07 = (destL2Id >>16) & 0x000000ff;
+	  longh->DST815 = (destL2Id>>8) & 0x000000ff;
+	  longh->DST1623 = destL2Id & 0x000000ff;
 
 	  longh->V=0x1;
 	}
diff --git a/openair2/RRC/LITE/defs.h b/openair2/RRC/LITE/defs.h
index 6fd9ffcffbe..3477e73c516 100644
--- a/openair2/RRC/LITE/defs.h
+++ b/openair2/RRC/LITE/defs.h
@@ -85,6 +85,9 @@
 #define DIRECT_COMMUNICATION_ESTABLISH_RSP  6
 #define GROUP_COMMUNICATION_RELEASE_REQ     7
 #define GROUP_COMMUNICATION_RELEASE_RSP     8
+#define PC5S_ESTABLISH_REQ                  9
+#define PC5S_ESTABLISH_RSP                  10
+
 
 typedef enum {
    UE_STATE_OFF_NETWORK,
@@ -116,6 +119,16 @@ struct DirectCommunicationEstablishReq {
    uint32_t pppp;
 };
 
+struct PC5SEstablishReq{
+   uint32_t sourceL2Id;
+   uint32_t destinationL2Id;
+};
+
+struct PC5SEstablishRsp{
+   uint32_t sourceL2Id;
+   uint32_t destinationL2Id;
+   uint8_t status;
+};
 
 struct sidelink_ctrl_element {
    unsigned short type;
@@ -127,7 +140,8 @@ struct sidelink_ctrl_element {
       SL_UE_STATE_t ue_state;
       //struct GroupCommunicationReleaseReq group_comm_release_req;
       int slrb_id;
-
+      struct PC5SEstablishReq pc5s_establish_req;
+      struct PC5SEstablishRsp pc5s_establish_rsp;
    } sidelinkPrimitive;
 };
 
diff --git a/openair2/RRC/LITE/rrc_UE.c b/openair2/RRC/LITE/rrc_UE.c
index a2f790968c1..f36b6019c14 100644
--- a/openair2/RRC/LITE/rrc_UE.c
+++ b/openair2/RRC/LITE/rrc_UE.c
@@ -1046,6 +1046,7 @@ rrc_ue_process_measConfig(
 #if defined(Rel14)
            ,
            NULL,
+           NULL,
            NULL
 #endif
 			  );
@@ -1563,6 +1564,7 @@ rrc_ue_process_radioResourceConfigDedicated(
 #if defined(Rel14)
            ,
            NULL,
+           NULL,
            NULL
 #endif
 				);
@@ -1627,6 +1629,7 @@ rrc_ue_process_radioResourceConfigDedicated(
 #if defined(Rel14)
            ,
            NULL,
+           NULL,
            NULL
 #endif
 				);
@@ -1739,6 +1742,7 @@ rrc_ue_process_radioResourceConfigDedicated(
 #if defined(Rel14)
            ,
            NULL,
+           NULL,
            NULL
 #endif
 			      );
@@ -2327,6 +2331,7 @@ rrc_ue_process_mobilityControlInfo(
 #if defined(Rel14)
            ,
            NULL,
+           NULL,
            NULL
 #endif
 			);
@@ -3194,6 +3199,7 @@ int decode_SIB1( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index,
 #if defined(Rel14)
            ,
            NULL,
+           NULL,
            NULL
 #endif
 			);
@@ -3878,6 +3884,7 @@ uint64_t arfcn_to_freq(long arfcn) {
 #if defined(Rel14)
            ,
            NULL,
+           NULL,
            NULL
 #endif
 			      );
@@ -4063,6 +4070,7 @@ uint64_t arfcn_to_freq(long arfcn) {
 #if defined(Rel14)
            ,
            NULL,
+           NULL,
            NULL
 #endif
 			      );
@@ -4564,6 +4572,7 @@ int decode_MCCH_Message( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB
 #if defined(Rel14)
            ,
            NULL,
+           NULL,
            NULL
 #endif
 			);
@@ -5425,21 +5434,18 @@ void *rrc_control_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
+   int optval;
+   int n;
    struct sidelink_ctrl_element *sl_ctrl_msg_recv = NULL;
    struct sidelink_ctrl_element *sl_ctrl_msg_send = NULL;
-   uint32_t sourceL2Id;
-   uint32_t groupL2Id;
-   module_id_t         module_id;
-
-   module_id = 0 ; //hardcoded for testing only
+   uint32_t sourceL2Id, groupL2Id, destinationL2Id;
+   module_id_t         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);
    int enable_notification = 1;
    while (1) {
-      LOG_I(RRC,"[rrc_control_socket_thread_fct]: Listening to incoming connection from ProSe App \n");
+      LOG_I(RRC,"Listening to incoming connection from ProSe App \n");
       // receive a message from ProSe App
       memset(receive_buf, 0, BUFSIZE);
       n = recvfrom(ctrl_sock_fd, receive_buf, BUFSIZE, 0,
@@ -5450,7 +5456,6 @@ void *rrc_control_socket_thread_fct(void *arg)
       }
       //TODO: should store the address of ProSeApp [UE_rrc_inst] to be able to send UE state notification to the App
 
-
       //sl_ctrl_msg_recv = (struct sidelink_ctrl_element *) receive_buf;
       sl_ctrl_msg_recv = calloc(1, sizeof(struct sidelink_ctrl_element));
       memcpy((void *)sl_ctrl_msg_recv, (void *)receive_buf, sizeof(struct sidelink_ctrl_element));
@@ -5459,11 +5464,11 @@ void *rrc_control_socket_thread_fct(void *arg)
       switch (sl_ctrl_msg_recv->type) {
       case SESSION_INIT_REQ:
 #ifdef DEBUG_CTRL_SOCKET
-         LOG_I(RRC,"[rrc_control_socket_thread_fct]: Received SessionInitializationRequest on socket from ProSe App (msg type: %d)\n", sl_ctrl_msg_recv->type);
+         LOG_I(RRC,"Received SessionInitializationRequest on socket from ProSe App (msg type: %d)\n", sl_ctrl_msg_recv->type);
 #endif
          //TODO: get SL_UE_STATE from lower layer
 
-         LOG_I(RRC,"[rrc_control_socket_thread_fct]: Send UEStateInformation to ProSe App \n");
+         LOG_I(RRC,"Send UEStateInformation to ProSe App \n");
          memset(send_buf, 0, BUFSIZE);
 
          sl_ctrl_msg_send = calloc(1, sizeof(struct sidelink_ctrl_element));
@@ -5483,8 +5488,8 @@ void *rrc_control_socket_thread_fct(void *arg)
 #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);
+         LOG_I(RRC,"[UEStateInformation] msg type: %d\n",ptr_ctrl_msg->type);
+         LOG_I(RRC,"[UEStateInformation] UE state: %d\n",ptr_ctrl_msg->sidelinkPrimitive.ue_state);
 #endif
 
          /*  if (enable_notification > 0) {
@@ -5502,11 +5507,11 @@ void *rrc_control_socket_thread_fct(void *arg)
          groupL2Id = sl_ctrl_msg_recv->sidelinkPrimitive.group_comm_establish_req.groupL2Id;
 
 #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);
-         LOG_I(RRC,"[rrc_control_socket_thread_fct][GroupCommunicationEstablishReq] source Id: %d\n",sl_ctrl_msg_recv->sidelinkPrimitive.group_comm_establish_req.sourceL2Id);
-         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));
+         LOG_I(RRC,"[GroupCommunicationEstablishReq] Received on socket from ProSe App (msg type: %d)\n",sl_ctrl_msg_recv->type);
+         LOG_I(RRC,"[GroupCommunicationEstablishReq] type: %d\n",sl_ctrl_msg_recv->sidelinkPrimitive.group_comm_establish_req.type);
+         LOG_I(RRC,"[GroupCommunicationEstablishReq] source Id: %d\n",sl_ctrl_msg_recv->sidelinkPrimitive.group_comm_establish_req.sourceL2Id);
+         LOG_I(RRC,"[GroupCommunicationEstablishReq] group Id: %d\n",sl_ctrl_msg_recv->sidelinkPrimitive.group_comm_establish_req.groupL2Id);
+         LOG_I(RRC,"[GroupCommunicationEstablishReq] group IP Address: " IPV4_ADDR "\n",IPV4_ADDR_FORMAT(sl_ctrl_msg_recv->sidelinkPrimitive.group_comm_establish_req.groupIpAddress));
 #endif
 
          //store sourceL2Id
@@ -5550,18 +5555,19 @@ void *rrc_control_socket_thread_fct(void *arg)
      #if defined(Rel10) || defined(Rel14)
                 ,
                 &sourceL2Id,
-                &groupL2Id
+                &groupL2Id,
+                NULL
      #endif
                 );
 
-         LOG_I(RRC,"[rrc_control_socket_thread_fct]Send GroupCommunicationEstablishResp to ProSe App\n");
+         LOG_I(RRC,"Send GroupCommunicationEstablishResp to ProSe App\n");
          memset(send_buf, 0, BUFSIZE);
          sl_ctrl_msg_send = calloc(1, sizeof(struct sidelink_ctrl_element));
          sl_ctrl_msg_send->type = GROUP_COMMUNICATION_ESTABLISH_RSP;
          //in case of TX, assign a new SLRB and prepare for the filter
          if (sl_ctrl_msg_recv->sidelinkPrimitive.group_comm_establish_req.type == 1) {
 #ifdef DEBUG_CTRL_SOCKET
-            LOG_I(RRC,"[rrc_control_socket_thread_fct][GroupCommunicationEstablishReq]  PPPP: %d\n",sl_ctrl_msg_recv->sidelinkPrimitive.group_comm_establish_req.pppp);
+            LOG_I(RRC,"[GroupCommunicationEstablishReq]  PPPP: %d\n",sl_ctrl_msg_recv->sidelinkPrimitive.group_comm_establish_req.pppp);
 #endif
             sl_ctrl_msg_send->sidelinkPrimitive.slrb_id = SLRB_ID; //slrb_id
             //pthread_mutex_lock(&slrb_mutex);
@@ -5584,16 +5590,16 @@ void *rrc_control_socket_thread_fct(void *arg)
 
 #ifdef DEBUG_CTRL_SOCKET
          ptr_ctrl_msg = (struct sidelink_ctrl_element *) send_buf;
-         LOG_I(RRC,"[rrc_control_socket_thread_fct][GroupCommunicationEstablishResponse]  msg type: %d\n",ptr_ctrl_msg->type);
-         LOG_I(RRC,"[rrc_control_socket_thread_fct][GroupCommunicationEstablishResponse]  slrb_id: %d\n",ptr_ctrl_msg->sidelinkPrimitive.slrb_id);
+         LOG_I(RRC,"[GroupCommunicationEstablishResponse]  msg type: %d\n",ptr_ctrl_msg->type);
+         LOG_I(RRC,"[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);
+         LOG_I(RRC,"[GroupCommunicationReleaseRequest] Received on socket from ProSe App (msg type: %d)\n",sl_ctrl_msg_recv->type);
+         LOG_I(RRC,"[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;
@@ -5633,12 +5639,13 @@ void *rrc_control_socket_thread_fct(void *arg)
          #if defined(Rel10) || defined(Rel14)
                     ,
                     &sourceL2Id,
+                    NULL,
                     NULL
          #endif
                     );
 
 
-         LOG_I(RRC,"[rrc_control_socket_thread_fct]Send GroupCommunicationReleaseResponse to ProSe App \n");
+         LOG_I(RRC,"Send GroupCommunicationReleaseResponse to ProSe App \n");
          memset(send_buf, 0, BUFSIZE);
 
          sl_ctrl_msg_send = calloc(1, sizeof(struct sidelink_ctrl_element));
@@ -5663,6 +5670,76 @@ void *rrc_control_socket_thread_fct(void *arg)
          }
          break;
 
+
+      case PC5S_ESTABLISH_REQ:
+         sourceL2Id = sl_ctrl_msg_recv->sidelinkPrimitive.pc5s_establish_req.sourceL2Id;
+         destinationL2Id = sl_ctrl_msg_recv->sidelinkPrimitive.pc5s_establish_req.destinationL2Id;
+#ifdef DEBUG_CTRL_SOCKET
+         LOG_I(RRC,"[PC5EstablishReq] Received on socket from ProSe App (msg type: %d)\n",sl_ctrl_msg_recv->type);
+         LOG_I(RRC,"[PC5EstablishReq] source Id: 0x%08x \n",sl_ctrl_msg_recv->sidelinkPrimitive.pc5s_establish_req.sourceL2Id);
+         LOG_I(RRC,"[PC5EstablishReq] destination Id: 0x%08x \n",sl_ctrl_msg_recv->sidelinkPrimitive.pc5s_establish_req.destinationL2Id);
+#endif
+         //store sourceL2Id, destinationL2Id
+         UE_rrc_inst[module_id].sourceL2Id = sourceL2Id;
+         UE_rrc_inst[module_id].destinationL2Id = destinationL2Id;
+         // configure lower layers PDCP/MAC/PHY
+         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,
+                &destinationL2Id,
+                &destinationL2Id
+     #endif
+                );
+
+         LOG_I(RRC,"Send PC5EstablishRsp to ProSe App\n");
+         memset(send_buf, 0, BUFSIZE);
+         sl_ctrl_msg_send = calloc(1, sizeof(struct sidelink_ctrl_element));
+         sl_ctrl_msg_send->type = PC5S_ESTABLISH_RSP;
+         sl_ctrl_msg_send->sidelinkPrimitive.pc5s_establish_rsp.sourceL2Id = sourceL2Id;
+         sl_ctrl_msg_send->sidelinkPrimitive.pc5s_establish_rsp.destinationL2Id = destinationL2Id;
+         sl_ctrl_msg_send->sidelinkPrimitive.pc5s_establish_rsp.status = 1;
+         memcpy((void *)send_buf, (void *)sl_ctrl_msg_send, sizeof(struct sidelink_ctrl_element));
+
+         prose_addr_len = sizeof(prose_app_addr);
+         n = sendto(ctrl_sock_fd, (char *)send_buf, sizeof(struct sidelink_ctrl_element), 0, (struct sockaddr *)&prose_app_addr, prose_addr_len);
+         free(sl_ctrl_msg_send);
+         if (n < 0){
+            LOG_E(RRC, "ERROR: Failed to send to ProSe App\n");
+            exit(EXIT_FAILURE);
+         }
+         break;
+
       default:
          break;
       }
-- 
GitLab