Commit 9c5c78e4 authored by Laurent THOMAS's avatar Laurent THOMAS

dirty fixes that fix the UL malformed packets (detected in wireshark), and...

dirty fixes that fix the UL malformed packets (detected in wireshark), and also internally memory corrpution
parent 45a1370f
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include "PHY/NR_UE_TRANSPORT/nr_transport_ue.h" #include "PHY/NR_UE_TRANSPORT/nr_transport_ue.h"
#include "common/utils/LOG/vcd_signal_dumper.h" #include "common/utils/LOG/vcd_signal_dumper.h"
#include "LAYER2/NR_MAC_gNB/mac_proto.h" #include "LAYER2/NR_MAC_gNB/mac_proto.h"
#include <openair2/UTIL/OPT/opt.h>
//#define DEBUG_ULSCH_CODING //#define DEBUG_ULSCH_CODING
...@@ -256,7 +257,7 @@ int nr_ulsch_encoding(NR_UE_ULSCH_t *ulsch, ...@@ -256,7 +257,7 @@ int nr_ulsch_encoding(NR_UE_ULSCH_t *ulsch,
Ilbrm = 0; Ilbrm = 0;
Tbslbrm = 950984; //max tbs Tbslbrm = 950984; //max tbs
Coderate = 0.0; Coderate = 0.0;
trace_NRpdu(DIRECTION_UPLINK, harq_process->a, harq_process->pusch_pdu.pusch_data.tb_size, 0, WS_C_RNTI, 0, 0, 0,0, 0);
/////////// ///////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
......
...@@ -2117,22 +2117,19 @@ uint16_t nr_generate_ulsch_pdu(uint8_t *sdus_payload, ...@@ -2117,22 +2117,19 @@ uint16_t nr_generate_ulsch_pdu(uint8_t *sdus_payload,
uint16_t buflen) { uint16_t buflen) {
NR_MAC_SUBHEADER_FIXED *mac_pdu_ptr = (NR_MAC_SUBHEADER_FIXED *) pdu; NR_MAC_SUBHEADER_FIXED *mac_pdu_ptr = (NR_MAC_SUBHEADER_FIXED *) pdu;
unsigned char last_size = 0, i, mac_header_control_elements[16], *ce_ptr, bsr = 0;
int mac_ce_size;
uint16_t offset = 0;
LOG_D(MAC, "[UE] Generating ULSCH PDU : num_sdus %d\n", num_sdus); LOG_D(MAC, "[UE] Generating ULSCH PDU : num_sdus %d\n", num_sdus);
#ifdef DEBUG_HEADER_PARSING #ifdef DEBUG_HEADER_PARSING
for (i = 0; i < num_sdus; i++) for (int i = 0; i < num_sdus; i++)
LOG_D(MAC, "[UE] MAC subPDU %d (lcid %d length %d bytes \n", i, sdu_lcids[i], sdu_lengths[i]); LOG_D(MAC, "[UE] MAC subPDU %d (lcid %d length %d bytes \n", i, sdu_lcids[i], sdu_lengths[i]);
#endif #endif
// Generating UL MAC subPDUs including MAC SDU and subheader // Generating UL MAC subPDUs including MAC SDU and subheader
for (i = 0; i < num_sdus; i++) { for (int i = 0; i < num_sdus; i++) {
LOG_D(MAC, "[UE] Generating UL MAC subPDUs for SDU with lenght %d ( num_sdus %d )\n", sdu_lengths[i], num_sdus); LOG_D(MAC, "[UE] Generating UL MAC subPDUs for SDU with lenght %d ( num_sdus %d )\n", sdu_lengths[i], num_sdus);
if (sdu_lcids[i] != UL_SCH_LCID_CCCH){ if (sdu_lcids[i] != UL_SCH_LCID_CCCH){
...@@ -2141,23 +2138,21 @@ uint16_t nr_generate_ulsch_pdu(uint8_t *sdus_payload, ...@@ -2141,23 +2138,21 @@ uint16_t nr_generate_ulsch_pdu(uint8_t *sdus_payload,
((NR_MAC_SUBHEADER_SHORT *) mac_pdu_ptr)->F = 0; ((NR_MAC_SUBHEADER_SHORT *) mac_pdu_ptr)->F = 0;
((NR_MAC_SUBHEADER_SHORT *) mac_pdu_ptr)->LCID = sdu_lcids[i]; ((NR_MAC_SUBHEADER_SHORT *) mac_pdu_ptr)->LCID = sdu_lcids[i];
((NR_MAC_SUBHEADER_SHORT *) mac_pdu_ptr)->L = (unsigned char) sdu_lengths[i]; ((NR_MAC_SUBHEADER_SHORT *) mac_pdu_ptr)->L = (unsigned char) sdu_lengths[i];
last_size = 2; mac_pdu_ptr += sizeof(NR_MAC_SUBHEADER_SHORT);
} else { } else {
((NR_MAC_SUBHEADER_LONG *) mac_pdu_ptr)->R = 0; ((NR_MAC_SUBHEADER_LONG *) mac_pdu_ptr)->R = 0;
((NR_MAC_SUBHEADER_LONG *) mac_pdu_ptr)->F = 1; ((NR_MAC_SUBHEADER_LONG *) mac_pdu_ptr)->F = 1;
((NR_MAC_SUBHEADER_LONG *) mac_pdu_ptr)->LCID = sdu_lcids[i]; ((NR_MAC_SUBHEADER_LONG *) mac_pdu_ptr)->LCID = sdu_lcids[i];
((NR_MAC_SUBHEADER_LONG *) mac_pdu_ptr)->L1 = ((unsigned short) sdu_lengths[i] >> 8) & 0x7f; ((NR_MAC_SUBHEADER_LONG *) mac_pdu_ptr)->L1 = ((unsigned short) sdu_lengths[i] >> 8) & 0x7f;
((NR_MAC_SUBHEADER_LONG *) mac_pdu_ptr)->L2 = (unsigned short) sdu_lengths[i] & 0xff; ((NR_MAC_SUBHEADER_LONG *) mac_pdu_ptr)->L2 = (unsigned short) sdu_lengths[i] & 0xff;
last_size = 3; mac_pdu_ptr += sizeof(NR_MAC_SUBHEADER_LONG);
} }
} else { // UL CCCH SDU } else { // UL CCCH SDU
((NR_MAC_SUBHEADER_FIXED *) mac_pdu_ptr)->R = 0; mac_pdu_ptr->R = 0;
((NR_MAC_SUBHEADER_FIXED *) mac_pdu_ptr)->LCID = sdu_lcids[i]; mac_pdu_ptr->LCID = sdu_lcids[i];
last_size = 1; mac_pdu_ptr ++;
} }
mac_pdu_ptr += last_size;
// cycle through SDUs, compute each relevant and place ulsch_buffer in // cycle through SDUs, compute each relevant and place ulsch_buffer in
memcpy((void *) mac_pdu_ptr, (void *) sdus_payload, sdu_lengths[i]); memcpy((void *) mac_pdu_ptr, (void *) sdus_payload, sdu_lengths[i]);
sdus_payload += sdu_lengths[i]; sdus_payload += sdu_lengths[i];
...@@ -2166,8 +2161,6 @@ uint16_t nr_generate_ulsch_pdu(uint8_t *sdus_payload, ...@@ -2166,8 +2161,6 @@ uint16_t nr_generate_ulsch_pdu(uint8_t *sdus_payload,
// Generating UL MAC subPDUs including MAC CEs (MAC CE and subheader) // Generating UL MAC subPDUs including MAC CEs (MAC CE and subheader)
ce_ptr = &mac_header_control_elements[0];
if (power_headroom) { if (power_headroom) {
// MAC CE fixed subheader // MAC CE fixed subheader
mac_pdu_ptr->R = 0; mac_pdu_ptr->R = 0;
...@@ -2175,17 +2168,11 @@ uint16_t nr_generate_ulsch_pdu(uint8_t *sdus_payload, ...@@ -2175,17 +2168,11 @@ uint16_t nr_generate_ulsch_pdu(uint8_t *sdus_payload,
mac_pdu_ptr++; mac_pdu_ptr++;
// PHR MAC CE (1 octet) // PHR MAC CE (1 octet)
((NR_SINGLE_ENTRY_PHR_MAC_CE *) ce_ptr)->PH = power_headroom; ((NR_SINGLE_ENTRY_PHR_MAC_CE *) mac_pdu_ptr)->PH = power_headroom;
((NR_SINGLE_ENTRY_PHR_MAC_CE *) ce_ptr)->R1 = 0; ((NR_SINGLE_ENTRY_PHR_MAC_CE *) mac_pdu_ptr)->R1 = 0;
((NR_SINGLE_ENTRY_PHR_MAC_CE *) ce_ptr)->PCMAX = 0; // todo ((NR_SINGLE_ENTRY_PHR_MAC_CE *) mac_pdu_ptr)->PCMAX = 0; // todo
((NR_SINGLE_ENTRY_PHR_MAC_CE *) ce_ptr)->R2 = 0; ((NR_SINGLE_ENTRY_PHR_MAC_CE *) mac_pdu_ptr)->R2 = 0;
mac_pdu_ptr += sizeof(NR_SINGLE_ENTRY_PHR_MAC_CE);
mac_ce_size = sizeof(NR_SINGLE_ENTRY_PHR_MAC_CE);
// Copying bytes for PHR MAC CEs to the mac pdu pointer
memcpy((void *) mac_pdu_ptr, (void *) ce_ptr, mac_ce_size);
ce_ptr += mac_ce_size;
mac_pdu_ptr += (unsigned char) mac_ce_size;
} }
if (crnti) { if (crnti) {
...@@ -2195,13 +2182,8 @@ uint16_t nr_generate_ulsch_pdu(uint8_t *sdus_payload, ...@@ -2195,13 +2182,8 @@ uint16_t nr_generate_ulsch_pdu(uint8_t *sdus_payload,
mac_pdu_ptr++; mac_pdu_ptr++;
// C-RNTI MAC CE (2 octets) // C-RNTI MAC CE (2 octets)
* (uint16_t *) ce_ptr = crnti; * (uint16_t *) mac_pdu_ptr = crnti;
mac_ce_size = sizeof(uint16_t); mac_pdu_ptr += sizeof(uint16_t);
// Copying bytes for CRNTI MAC CE to the mac pdu pointer
memcpy((void *) mac_pdu_ptr, (void *) ce_ptr, mac_ce_size);
ce_ptr += mac_ce_size;
mac_pdu_ptr += (unsigned char) mac_ce_size;
} }
if (truncated_bsr) { if (truncated_bsr) {
...@@ -2211,11 +2193,9 @@ uint16_t nr_generate_ulsch_pdu(uint8_t *sdus_payload, ...@@ -2211,11 +2193,9 @@ uint16_t nr_generate_ulsch_pdu(uint8_t *sdus_payload,
mac_pdu_ptr++; mac_pdu_ptr++;
// Short truncated BSR MAC CE (1 octet) // Short truncated BSR MAC CE (1 octet)
((NR_BSR_SHORT_TRUNCATED *) ce_ptr)-> Buffer_size = truncated_bsr; ((NR_BSR_SHORT_TRUNCATED *) mac_pdu_ptr)-> Buffer_size = truncated_bsr;
((NR_BSR_SHORT_TRUNCATED *) ce_ptr)-> LcgID = 0; // todo ((NR_BSR_SHORT_TRUNCATED *) mac_pdu_ptr)-> LcgID = 0; // todo
mac_ce_size = sizeof(NR_BSR_SHORT_TRUNCATED); mac_pdu_ptr+= sizeof(NR_BSR_SHORT_TRUNCATED);
bsr = 1 ;
} else if (short_bsr) { } else if (short_bsr) {
// MAC CE fixed subheader // MAC CE fixed subheader
mac_pdu_ptr->R = 0; mac_pdu_ptr->R = 0;
...@@ -2223,11 +2203,9 @@ uint16_t nr_generate_ulsch_pdu(uint8_t *sdus_payload, ...@@ -2223,11 +2203,9 @@ uint16_t nr_generate_ulsch_pdu(uint8_t *sdus_payload,
mac_pdu_ptr++; mac_pdu_ptr++;
// Short truncated BSR MAC CE (1 octet) // Short truncated BSR MAC CE (1 octet)
((NR_BSR_SHORT *) ce_ptr)->Buffer_size = short_bsr; ((NR_BSR_SHORT *) mac_pdu_ptr)->Buffer_size = short_bsr;
((NR_BSR_SHORT *) ce_ptr)->LcgID = 0; // todo ((NR_BSR_SHORT *) mac_pdu_ptr)->LcgID = 0; // todo
mac_ce_size = sizeof(NR_BSR_SHORT); mac_pdu_ptr+= sizeof(NR_BSR_SHORT);
bsr = 1 ;
} else if (long_bsr) { } else if (long_bsr) {
// MAC CE variable subheader // MAC CE variable subheader
// todo ch 6.1.3.1. TS 38.321 // todo ch 6.1.3.1. TS 38.321
...@@ -2243,36 +2221,19 @@ uint16_t nr_generate_ulsch_pdu(uint8_t *sdus_payload, ...@@ -2243,36 +2221,19 @@ uint16_t nr_generate_ulsch_pdu(uint8_t *sdus_payload,
// ((NR_BSR_LONG *) ce_ptr)->LCGID0 = 0; // ((NR_BSR_LONG *) ce_ptr)->LCGID0 = 0;
// mac_ce_size = sizeof(NR_BSR_LONG); // size is variable // mac_ce_size = sizeof(NR_BSR_LONG); // size is variable
} }
// compute offset before adding padding (if necessary)
if (bsr){ int padding_bytes = 0;
// Copying bytes for BSR MAC CE to the mac pdu pointer
memcpy((void *) mac_pdu_ptr, (void *) ce_ptr, mac_ce_size);
ce_ptr += mac_ce_size;
mac_pdu_ptr += (unsigned char) mac_ce_size;
}
// compute offset before adding padding (if necessary)
offset = ((unsigned char *) mac_pdu_ptr - pdu);
uint16_t padding_bytes = 0;
if(buflen > 0) // If the buflen is provided if(buflen > 0) // If the buflen is provided
padding_bytes = buflen - offset; padding_bytes = buflen + pdu - (unsigned char *) mac_pdu_ptr;
AssertFatal(padding_bytes>=0,"");
// Compute final offset for padding // Compute final offset for padding
if (post_padding > 0 || padding_bytes>0) { if (post_padding || padding_bytes>0) {
((NR_MAC_SUBHEADER_FIXED *) mac_pdu_ptr)->R = 0; ((NR_MAC_SUBHEADER_FIXED *) mac_pdu_ptr)->R = 0;
((NR_MAC_SUBHEADER_FIXED *) mac_pdu_ptr)->LCID = UL_SCH_LCID_PADDING; ((NR_MAC_SUBHEADER_FIXED *) mac_pdu_ptr)->LCID = UL_SCH_LCID_PADDING;
mac_pdu_ptr++; mac_pdu_ptr++;
} else { }
// no MAC subPDU with padding return (uint8_t *)mac_pdu_ptr-pdu;
}
// compute final offset
offset = ((unsigned char *) mac_pdu_ptr - pdu);
//printf("Offset %d \n", ((unsigned char *) mac_pdu_ptr - pdu));
return offset;
} }
///////////////////////////////////// /////////////////////////////////////
......
...@@ -1962,7 +1962,9 @@ nr_ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP, ...@@ -1962,7 +1962,9 @@ nr_ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP,
ENB_FLAG_NO, ENB_FLAG_NO,
MBMS_FLAG_NO, MBMS_FLAG_NO,
lcid, lcid,
buflen_remain, buflen_remain-MAX_RLC_SDU_SUBHEADER_SIZE,
//Fixme: Laurent I removed MAX_RLC_SDU_SUBHEADER_SIZE because else we get out the buffer silently
// the interface with nr_generate_ulsch_pdu() looks over complex and not CPU optimized
(char *)&ulsch_sdus[sdu_length_total],0, (char *)&ulsch_sdus[sdu_length_total],0,
0); 0);
...@@ -1981,9 +1983,10 @@ nr_ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP, ...@@ -1981,9 +1983,10 @@ nr_ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP,
} }
/* Get updated BO after multiplexing this PDU */ /* Get updated BO after multiplexing this PDU */
lcid_buffer_occupancy_new = mac_rlc_get_buffer_occupancy_ind(module_idP,mac->crnti,eNB_index,frameP, subframe, ENB_FLAG_NO, lcid); lcid_buffer_occupancy_new =
mac_rlc_get_buffer_occupancy_ind(module_idP,mac->crnti,eNB_index,frameP, subframe, ENB_FLAG_NO, lcid);
buflen_remain = buflen_remain =
buflen - (total_rlc_pdu_header_len + sdu_length_total + MAX_RLC_SDU_SUBHEADER_SIZE); buflen - (total_rlc_pdu_header_len + sdu_length_total + MAX_RLC_SDU_SUBHEADER_SIZE);
} }
} }
} }
......
...@@ -65,9 +65,11 @@ static void nr_pdcp_entity_recv_pdu(nr_pdcp_entity_t *entity, ...@@ -65,9 +65,11 @@ static void nr_pdcp_entity_recv_pdu(nr_pdcp_entity_t *entity,
buffer[2]; buffer[2];
header_size = 3; header_size = 3;
} }
// FIXME: DRB creation is with integrity, but we don't receive it
if ( entity->type != NR_PDCP_SRB )
entity->has_integrity=0;
/* SRBs always have MAC-I, even if integrity is not active */ /* SRBs always have MAC-I, even if integrity is not active */
if ( // FIXME: DRB creation is with integrity, but we don't receive it if ( entity->has_integrity ||
// entity->has_integrity ||
entity->type == NR_PDCP_SRB) { entity->type == NR_PDCP_SRB) {
integrity_size = 4; integrity_size = 4;
} else { } else {
......
...@@ -1529,7 +1529,7 @@ static int tx_list_size(nr_rlc_entity_am_t *entity, ...@@ -1529,7 +1529,7 @@ static int tx_list_size(nr_rlc_entity_am_t *entity,
{ {
int ret = 0; int ret = 0;
while (l != NULL) { while (l != NULL && ret < maxsize) {
ret += compute_pdu_header_size(entity, l) + l->size; ret += compute_pdu_header_size(entity, l) + l->size;
l = l->next; l = l->next;
} }
......
...@@ -497,7 +497,7 @@ static int tx_list_size(nr_rlc_entity_um_t *entity, ...@@ -497,7 +497,7 @@ static int tx_list_size(nr_rlc_entity_um_t *entity,
{ {
int ret = 0; int ret = 0;
while (l != NULL) { while (l != NULL && ret < maxsize) {
ret += compute_pdu_header_size(entity, l) + l->size; ret += compute_pdu_header_size(entity, l) + l->size;
l = l->next; l = l->next;
} }
......
...@@ -323,7 +323,8 @@ rlc_buffer_occupancy_t mac_rlc_get_buffer_occupancy_ind( ...@@ -323,7 +323,8 @@ rlc_buffer_occupancy_t mac_rlc_get_buffer_occupancy_ind(
* reports '> 81338368' (table 6.1.3.1-2). Passing 100000000 is thus * reports '> 81338368' (table 6.1.3.1-2). Passing 100000000 is thus
* more than enough. * more than enough.
*/ */
buf_stat = rb->buffer_status(rb, 100000000); // Fixme : Laurent reduced size for CPU saving
buf_stat = rb->buffer_status(rb, 10000000);
ret = buf_stat.status_size ret = buf_stat.status_size
+ buf_stat.retx_size + buf_stat.retx_size
+ buf_stat.tx_size; + buf_stat.tx_size;
......
...@@ -1264,7 +1264,7 @@ nr_rrc_ue_process_masterCellGroup( ...@@ -1264,7 +1264,7 @@ nr_rrc_ue_process_masterCellGroup(
// NSA procedures // NSA procedures
} }
if(NR_UE_rrc_inst[ctxt_pP->module_id].cell_group_config == NULL){ if(NR_UE_rrc_inst[ctxt_pP->module_id].cell_group_config == NULL){
NR_UE_rrc_inst[ctxt_pP->module_id].cell_group_config = malloc(sizeof(NR_CellGroupConfig_t)); NR_UE_rrc_inst[ctxt_pP->module_id].cell_group_config = calloc(1,sizeof(NR_CellGroupConfig_t));
} }
......
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