Commit 36fab59e authored by laurent's avatar laurent

fix pdcp race condition

parent d21a4006
......@@ -503,8 +503,6 @@ pdcp_data_ind(
//-----------------------------------------------------------------------------
{
pdcp_t *pdcp_p = NULL;
list_t *sdu_list_p = NULL;
mem_block_t *new_sdu_p = NULL;
uint8_t pdcp_header_len = 0;
uint8_t pdcp_tailer_len = 0;
pdcp_sn_t sequence_number = 0;
......@@ -576,7 +574,6 @@ pdcp_data_ind(
}
}
sdu_list_p = &pdcp_sdu_list;
if (sdu_buffer_sizeP == 0) {
LOG_W(PDCP, "SDU buffer size is zero! Ignoring this chunk!\n");
......@@ -974,9 +971,8 @@ pdcp_data_ind(
#endif
if (FALSE == packet_forwarded) {
new_sdu_p = get_free_mem_block(sdu_buffer_sizeP - payload_offset + sizeof (pdcp_data_ind_header_t), __func__);
notifiedFIFO_elt_t * new_sdu_p = newNotifiedFIFO_elt(sdu_buffer_sizeP - payload_offset + sizeof (pdcp_data_ind_header_t), 0, NULL, NULL);
if (new_sdu_p) {
if ((MBMS_flagP == 0) && (pdcp_p->rlc_mode == RLC_MODE_AM)) {
pdcp_p->last_submitted_pdcp_rx_sn = sequence_number;
}
......@@ -984,14 +980,15 @@ pdcp_data_ind(
/*
* Prepend PDCP indication header which is going to be removed at pdcp_fifo_flush_sdus()
*/
memset(new_sdu_p->data, 0, sizeof (pdcp_data_ind_header_t));
((pdcp_data_ind_header_t *) new_sdu_p->data)->data_size = sdu_buffer_sizeP - payload_offset;
pdcp_data_ind_header_t * pdcpHead=(pdcp_data_ind_header_t *)NotifiedFifoData(new_sdu_p);
memset(pdcpHead, 0, sizeof (pdcp_data_ind_header_t));
pdcpHead->data_size = sdu_buffer_sizeP - payload_offset;
AssertFatal((sdu_buffer_sizeP - payload_offset >= 0), "invalid PDCP SDU size!");
// Here there is no virtualization possible
// set ((pdcp_data_ind_header_t *) new_sdu_p->data)->inst for IP layer here
// set pdcpHead->inst for IP layer here
if (ctxt_pP->enb_flag == ENB_FLAG_NO) {
((pdcp_data_ind_header_t *) new_sdu_p->data)->rb_id = rb_id;
pdcpHead->rb_id = rb_id;
if (EPC_MODE_ENABLED) {
/* for the UE compiled in S1 mode, we need 1 here
......@@ -1002,45 +999,40 @@ pdcp_data_ind(
#ifdef UESIM_EXPANSION
if (UE_NAS_USE_TUN) {
((pdcp_data_ind_header_t *) new_sdu_p->data)->inst = ctxt_pP->module_id;
pdcpHead->inst = ctxt_pP->module_id;
} else {
((pdcp_data_ind_header_t *) new_sdu_p->data)->inst = 0;
pdcpHead->inst = 0;
}
#else
((pdcp_data_ind_header_t *) new_sdu_p->data)->inst = ctxt_pP->module_id;
pdcpHead->inst = ctxt_pP->module_id;
#endif
} else { // nfapi_mode
if (UE_NAS_USE_TUN) {
((pdcp_data_ind_header_t *) new_sdu_p->data)->inst = ctxt_pP->module_id;
pdcpHead->inst = ctxt_pP->module_id;
} else {
((pdcp_data_ind_header_t *) new_sdu_p->data)->inst = 1;
pdcpHead->inst = 1;
}
} // nfapi_mode
}
} else {
((pdcp_data_ind_header_t *) new_sdu_p->data)->rb_id = rb_id + (ctxt_pP->module_id * LTE_maxDRB);
((pdcp_data_ind_header_t *) new_sdu_p->data)->inst = ctxt_pP->module_id;
pdcpHead->rb_id = rb_id + (ctxt_pP->module_id * LTE_maxDRB);
pdcpHead->inst = ctxt_pP->module_id;
}
if( LOG_DEBUGFLAG(DEBUG_PDCP) ) {
static uint32_t pdcp_inst = 0;
((pdcp_data_ind_header_t *) new_sdu_p->data)->inst = pdcp_inst++;
LOG_D(PDCP, "inst=%d size=%d\n", ((pdcp_data_ind_header_t *) new_sdu_p->data)->inst, ((pdcp_data_ind_header_t *) new_sdu_p->data)->data_size);
pdcpHead->inst = pdcp_inst++;
LOG_D(PDCP, "inst=%d size=%d\n", pdcpHead->inst, pdcpHead->data_size);
}
memcpy(&new_sdu_p->data[sizeof (pdcp_data_ind_header_t)],
memcpy(pdcpHead+1,
&sdu_buffer_pP->data[payload_offset],
sdu_buffer_sizeP - payload_offset);
#if defined(ENABLE_PDCP_PAYLOAD_DEBUG)
LOG_I(PDCP, "Printing first bytes of PDCP SDU before adding it to the list: \n");
for (int i=0; i<30; i++){
LOG_I(PDCP, "%x", sdu_buffer_pP->data[i]);
}
#endif
list_add_tail_eurecom (new_sdu_p, sdu_list_p);
}
if( LOG_DEBUGFLAG(DEBUG_PDCP) )
log_dump(PDCP, pdcpHead+1, min(sdu_buffer_sizeP - payload_offset,30) , LOG_DUMP_CHAR,
"Printing first bytes of PDCP SDU before adding it to the list: \n");
pushNotifiedFIFO(&pdcp_sdu_list, new_sdu_p);
/* Print octets of incoming data in hexadecimal form */
LOG_D(PDCP, "Following content has been received from RLC (%d,%d)(PDCP header has already been removed):\n",
......@@ -2467,7 +2459,7 @@ void pdcp_layer_init(void)
/*
* Initialize SDU list
*/
list_init(&pdcp_sdu_list, NULL);
initNotifiedFIFO(&pdcp_sdu_list);
pdcp_coll_p = hashtable_create ((LTE_maxDRB + 2) * NUMBER_OF_UE_MAX, NULL, pdcp_free);
AssertFatal(pdcp_coll_p != NULL, "UNRECOVERABLE error, PDCP hashtable_create failed");
......@@ -2540,7 +2532,8 @@ void pdcp_layer_init(void)
void pdcp_layer_cleanup (void)
//-----------------------------------------------------------------------------
{
list_free (&pdcp_sdu_list);
//list_free (&pdcp_sdu_list);
while(pollNotifiedFIFO(&pdcp_sdu_list)) {};
hashtable_destroy(&pdcp_coll_p);
#ifdef MBMS_MULTICAST_OUT
......
......@@ -522,7 +522,7 @@ pdcp_mbms_t pdcp_mbms_array_eNB[NUMBER_OF_eNB_MAX][LTE_maxServiceC
sdu_size_t pdcp_output_sdu_bytes_to_write;
sdu_size_t pdcp_output_header_bytes_to_write;
list_t pdcp_sdu_list;
notifiedFIFO_t pdcp_sdu_list;
int pdcp_sent_a_sdu;
pdcp_data_req_header_t pdcp_input_header;
unsigned char pdcp_input_sdu_buffer[MAX_IP_PACKET_SIZE];
......
......@@ -111,69 +111,59 @@ void debug_pdcp_pc5s_sdu(sidelink_pc5s_element *sl_pc5s_msg, char *title) {
}
//-----------------------------------------------------------------------------
int pdcp_fifo_flush_sdus(const protocol_ctxt_t *const ctxt_pP) {
mem_block_t *sdu_p;
notifiedFIFO_elt_t *sdu_p;
int pdcp_nb_sdu_sent = 0;
int ret=0;
while ((sdu_p = pollNotifiedFIFO(&pdcp_sdu_list)) != NULL ) {
pdcp_data_ind_header_t * pdcpHead=(pdcp_data_ind_header_t *)NotifiedFifoData(sdu_p);
AssertFatal(pdcpHead->inst==ctxt_pP->module_id, "To implement correctly multi module id\n");
while ((sdu_p = list_get_head (&pdcp_sdu_list)) != NULL && ((pdcp_data_ind_header_t *)(sdu_p->data))->inst == ctxt_pP->module_id) {
((pdcp_data_ind_header_t *)(sdu_p->data))->inst = 0;
int rb_id = ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id;
int rb_id = pdcpHead->rb_id;
int sizeToWrite= sizeof (pdcp_data_ind_header_t) +
((pdcp_data_ind_header_t *) sdu_p->data)->data_size;
pdcpHead->data_size;
void * pdcpData=(void*)(pdcpHead+1);
if (rb_id == 10) { //hardcoded for PC5-Signaling
if( LOG_DEBUGFLAG(DEBUG_PDCP) ) {
debug_pdcp_pc5s_sdu((sidelink_pc5s_element *)&(sdu_p->data[sizeof(pdcp_data_ind_header_t)]),
debug_pdcp_pc5s_sdu((sidelink_pc5s_element *)pdcpData,
"pdcp_fifo_flush_sdus sends a aPC5S message");
}
ret = sendto(pdcp_pc5_sockfd, &(sdu_p->data[sizeof(pdcp_data_ind_header_t)]),
ret = sendto(pdcp_pc5_sockfd, pdcpData,
sizeof(sidelink_pc5s_element), 0, (struct sockaddr *)&prose_pdcp_addr,sizeof(prose_pdcp_addr) );
} else if (UE_NAS_USE_TUN) {
//ret = write(nas_sock_fd[ctxt_pP->module_id], &(sdu_p->data[sizeof(pdcp_data_ind_header_t)]),sizeToWrite );
//ret = write(nas_sock_fd[ctxt_pP->module_id], pdcpData,sizeToWrite );
if(rb_id == mbms_rab_id){
ret = write(nas_sock_mbms_fd, &(sdu_p->data[sizeof(pdcp_data_ind_header_t)]),sizeToWrite );
LOG_I(PDCP,"[PDCP_FIFOS] ret %d TRIED TO PUSH MBMS DATA TO rb_id %d handle %d sizeToWrite %d\n",ret,rb_id,nas_sock_fd[ctxt_pP->module_id],sizeToWrite);
ret = write(nas_sock_mbms_fd, pdcpData,sizeToWrite );
LOG_I(PDCP,"[PDCP_FIFOS] ret %d TRIED TO PUSH MBMS DATA TO rb_id %d handle %d sizeToWrite %d\n",
ret,rb_id,nas_sock_fd[ctxt_pP->module_id],sizeToWrite);
}
else
{
#if defined(ENABLE_PDCP_PAYLOAD_DEBUG)
LOG_I(PHY, "PDCP output to be sent to TUN interface: \n");
for (int i = sizeof(pdcp_data_ind_header_t); i < sizeToWrite; i++) {
printf("%02x ",(unsigned char)sdu_p->data[i]);
}
printf("\n");
#endif
ret = write(nas_sock_fd[ctxt_pP->module_id], &(sdu_p->data[sizeof(pdcp_data_ind_header_t)]),sizeToWrite );
//LOG_I(PDCP,"[PDCP_FIFOS] ret %d TRIED TO PUSH DATA TO rb_id %d handle %d sizeToWrite %d\n",ret,rb_id,nas_sock_fd[ctxt_pP->module_id],sizeToWrite);
if( LOG_DEBUGFLAG(DEBUG_PDCP) )
log_dump(PDCP, pdcpData, sizeToWrite, LOG_DUMP_CHAR,"PDCP output to be sent to TUN interface: \n");
ret = write(nas_sock_fd[ctxt_pP->module_id], pdcpData,sizeToWrite );
LOG_T(PDCP,"[UE PDCP_FIFOS] ret %d TRIED TO PUSH DATA TO rb_id %d handle %d sizeToWrite %d\n",
ret,rb_id,nas_sock_fd[ctxt_pP->module_id],sizeToWrite);
}
} else if (ENB_NAS_USE_TUN) {
#if defined(ENABLE_PDCP_PAYLOAD_DEBUG)
LOG_I(PHY, "PDCP output to be sent to TUN interface: \n");
for (int i = sizeof(pdcp_data_ind_header_t); i < sizeToWrite; i++) {
printf("%02x ",(unsigned char)sdu_p->data[i]);
}
printf("\n");
#endif
ret = write(nas_sock_fd[0], &(sdu_p->data[sizeof(pdcp_data_ind_header_t)]), sizeToWrite);
if( LOG_DEBUGFLAG(DEBUG_PDCP) )
log_dump(PDCP, pdcpData, sizeToWrite, LOG_DUMP_CHAR,"PDCP output to be sent to TUN interface: \n");
ret = write(nas_sock_fd[0], pdcpData, sizeToWrite);
LOG_T(PDCP,"[NB PDCP_FIFOS] ret %d TRIED TO PUSH DATA TO rb_id %d handle %d sizeToWrite %d\n",ret,rb_id,nas_sock_fd[0],sizeToWrite);
} else if (PDCP_USE_NETLINK) {
memcpy(NLMSG_DATA(nas_nlh_tx), (uint8_t *) sdu_p->data, sizeToWrite);
memcpy(NLMSG_DATA(nas_nlh_tx), (uint8_t *) pdcpHead, sizeToWrite);
nas_nlh_tx->nlmsg_len = sizeToWrite;
ret = sendmsg(nas_sock_fd[0],&nas_msg_tx,0);
} // PDCP_USE_NETLINK
AssertFatal(ret >= 0,"[PDCP_FIFOS] pdcp_fifo_flush_sdus (errno: %d %s), nas_sock_fd[0]: %d\n", errno, strerror(errno), nas_sock_fd[0]);
#if defined(ENABLE_PDCP_PAYLOAD_DEBUG)
LOG_I(PDCP, "Printing first bytes of PDCP SDU before removing it from the list: \n");
for (int i=0; i<30; i++){
LOG_I(PDCP, "%x", sdu_p->data[i]);
}
#endif
list_remove_head (&pdcp_sdu_list);
free_mem_block (sdu_p, __func__);
if( LOG_DEBUGFLAG(DEBUG_PDCP) )
log_dump(PDCP, pdcpData, min(sizeToWrite,30) , LOG_DUMP_CHAR,
"Printing first bytes of PDCP SDU before removing it from the list: \n");
delNotifiedFIFO_elt (sdu_p);
pdcp_nb_sdu_sent ++;
}
......@@ -181,12 +171,14 @@ int pdcp_fifo_flush_sdus(const protocol_ctxt_t *const ctxt_pP) {
}
int pdcp_fifo_flush_mbms_sdus(const protocol_ctxt_t *const ctxt_pP) {
mem_block_t *sdu_p;
notifiedFIFO_elt_t *sdu_p;
int pdcp_nb_sdu_sent = 0;
//int ret=0;
while ((sdu_p = list_get_head (&pdcp_sdu_list)) != NULL && ((pdcp_data_ind_header_t *)(sdu_p->data))->inst == ctxt_pP->module_id) {
((pdcp_data_ind_header_t *)(sdu_p->data))->inst = 0;
while ((sdu_p = pollNotifiedFIFO(&pdcp_sdu_list)) != NULL ) {
pdcp_data_ind_header_t * pdcpHead=(pdcp_data_ind_header_t *)NotifiedFifoData(sdu_p);
AssertFatal(pdcpHead->inst==ctxt_pP->module_id, "To implement correctly multi module id\n");
//int rb_id = ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id;
//int sizeToWrite= sizeof (pdcp_data_ind_header_t) +
//((pdcp_data_ind_header_t *) sdu_p->data)->data_size;
......@@ -212,8 +204,7 @@ int pdcp_fifo_flush_mbms_sdus(const protocol_ctxt_t *const ctxt_pP) {
//} // PDCP_USE_NETLINK
//AssertFatal(ret >= 0,"[PDCP_FIFOS] pdcp_fifo_flush_sdus (errno: %d %s)\n", errno, strerror(errno));
list_remove_head (&pdcp_sdu_list);
free_mem_block (sdu_p, __func__);
delNotifiedFIFO_elt (sdu_p);
pdcp_nb_sdu_sent ++;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment