diff --git a/common/utils/time_meas.h b/common/utils/time_meas.h index 1bca9c3466..3b5e194c2c 100644 --- a/common/utils/time_meas.h +++ b/common/utils/time_meas.h @@ -153,15 +153,17 @@ static inline void start_meas(time_stats_t *ts) { static inline void stop_meas(time_stats_t *ts) { if (opp_enabled) { long long out = rdtsc_oai(); - ts->diff += (out-ts->in); - /// process duration is the difference between two clock points - ts->p_time = (out-ts->in); - ts->diff_square += ((double)out-ts->in)*((double)out-ts->in); + if (ts->in) { + ts->diff += (out - ts->in); + /// process duration is the difference between two clock points + ts->p_time = (out - ts->in); + ts->diff_square += ((double)out - ts->in) * ((double)out - ts->in); - if ((out-ts->in) > ts->max) - ts->max = out-ts->in; + if ((out - ts->in) > ts->max) + ts->max = out - ts->in; - ts->meas_flag=0; + ts->meas_flag = 0; + } } } diff --git a/openair1/PHY/CODING/crc_byte.c b/openair1/PHY/CODING/crc_byte.c index 261119d283..6b1fcebd80 100644 --- a/openair1/PHY/CODING/crc_byte.c +++ b/openair1/PHY/CODING/crc_byte.c @@ -44,16 +44,16 @@ /*ref 36-212 v8.6.0 , pp 8-9 */ /* the highest degree is set by default */ -unsigned int poly24a = 0x864cfb00; // 1000 0110 0100 1100 1111 1011 - // D^24 + D^23 + D^18 + D^17 + D^14 + D^11 + D^10 + D^7 + D^6 + D^5 + D^4 + D^3 + D + 1 -unsigned int poly24b = 0x80006300; // 1000 0000 0000 0000 0110 0011 - // D^24 + D^23 + D^6 + D^5 + D + 1 -unsigned int poly24c = 0xb2b11700; // 1011 0010 1011 0001 0001 0111 - // D^24+D^23+D^21+D^20+D^17+D^15+D^13+D^12+D^8+D^4+D^2+D+1 +uint32_t poly24a = 0x864cfb00; // 1000 0110 0100 1100 1111 1011 + // D^24 + D^23 + D^18 + D^17 + D^14 + D^11 + D^10 + D^7 + D^6 + D^5 + D^4 + D^3 + D + 1 +uint32_t poly24b = 0x80006300; // 1000 0000 0000 0000 0110 0011 + // D^24 + D^23 + D^6 + D^5 + D + 1 +uint32_t poly24c = 0xb2b11700; // 1011 0010 1011 0001 0001 0111 + // D^24+D^23+D^21+D^20+D^17+D^15+D^13+D^12+D^8+D^4+D^2+D+1 -unsigned int poly16 = 0x10210000; // 0001 0000 0010 0001 D^16 + D^12 + D^5 + 1 -unsigned int poly12 = 0x80F00000; // 1000 0000 1111 D^12 + D^11 + D^3 + D^2 + D + 1 -unsigned int poly8 = 0x9B000000; // 1001 1011 D^8 + D^7 + D^4 + D^3 + D + 1 +uint32_t poly16 = 0x10210000; // 0001 0000 0010 0001 D^16 + D^12 + D^5 + 1 +uint32_t poly12 = 0x80F00000; // 1000 0000 1111 D^12 + D^11 + D^3 + D^2 + D + 1 +uint32_t poly8 = 0x9B000000; // 1001 1011 D^8 + D^7 + D^4 + D^3 + D + 1 uint32_t poly6 = 0x84000000; // 10000100000... -> D^6+D^5+1 uint32_t poly11 = 0xc4200000; //11000100001000... -> D^11+D^10+D^9+D^5+1 @@ -65,14 +65,12 @@ For initialization && verification purposes, The first bit is in the MSB of each byte *********************************************************/ -unsigned int crcbit (unsigned char * inputptr, - int octetlen, - unsigned int poly) +uint32_t crcbit(unsigned char* inputptr, int octetlen, uint32_t poly) { - unsigned int i, crc = 0, c; + uint32_t i, crc = 0, c; while (octetlen-- > 0) { - c = ((unsigned int)(*inputptr++)) << 24; + c = ((uint32_t)(*inputptr++)) << 24; for (i = 8; i != 0; i--) { if ((1U << 31) & (c ^ crc)) @@ -92,14 +90,14 @@ unsigned int crcbit (unsigned char * inputptr, crc table initialization *********************************************************/ -static unsigned int crc24aTable[256]; -static unsigned int crc24bTable[256]; -static unsigned int crc24cTable[256]; -static unsigned int crc16Table[256]; -static unsigned int crc12Table[256]; -static unsigned int crc11Table[256]; -static unsigned int crc8Table[256]; -static unsigned int crc6Table[256]; +static uint32_t crc24aTable[256]; +static uint32_t crc24bTable[256]; +static uint32_t crc24cTable[256]; +static uint32_t crc16Table[256]; +static uint32_t crc12Table[256]; +static uint32_t crc11Table[256]; +static uint32_t crc8Table[256]; +static uint32_t crc6Table[256]; #if USE_INTEL_CRC static DECLARE_ALIGNED(struct crc_pclmulqdq_ctx lte_crc24a_pclmulqdq, 16) = { @@ -151,19 +149,18 @@ assuming initial byte is 0 padded (in MSB) if necessary can use SIMD optimized Intel CRC for LTE/NR 24a/24b variants *********************************************************/ -unsigned int crc24a (unsigned char * inptr, - int bitlen) +uint32_t crc24a(unsigned char* inptr, int bitlen) { int octetlen = bitlen / 8; /* Change in octets */ if ( bitlen % 8 || !USE_INTEL_CRC ) { - unsigned int crc = 0; - int resbit= (bitlen % 8); + uint32_t crc = 0; + int resbit = (bitlen % 8); - while (octetlen-- > 0) { - // printf("crc24a: in %x => crc %x\n",crc,*inptr); - crc = (crc << 8) ^ crc24aTable[(*inptr++) ^ (crc >> 24)]; - } + while (octetlen-- > 0) { + // printf("crc24a: in %x => crc %x\n",crc,*inptr); + crc = (crc << 8) ^ crc24aTable[(*inptr++) ^ (crc >> 24)]; + } if (resbit > 0) crc = (crc << resbit) ^ crc24aTable[((*inptr) >> (8 - resbit)) ^ (crc >> (32 - resbit))]; @@ -188,19 +185,18 @@ static DECLARE_ALIGNED(struct crc_pclmulqdq_ctx lte_crc24b_pclmulqdq, 16) = { 0ULL /**< res */ }; #endif -unsigned int crc24b (unsigned char * inptr, - int bitlen) +uint32_t crc24b(unsigned char* inptr, int bitlen) { int octetlen = bitlen / 8; /* Change in octets */ if ( bitlen % 8 || !USE_INTEL_CRC ) { - unsigned int crc = 0; - int resbit = (bitlen % 8); + uint32_t crc = 0; + int resbit = (bitlen % 8); - while (octetlen-- > 0) { - // printf("crc24b: in %x => crc %x (%x)\n",crc,*inptr,crc24bTable[(*inptr) ^ (crc >> 24)]); - crc = (crc << 8) ^ crc24bTable[(*inptr++) ^ (crc >> 24)]; - } + while (octetlen-- > 0) { + // printf("crc24b: in %x => crc %x (%x)\n",crc,*inptr,crc24bTable[(*inptr) ^ (crc >> 24)]); + crc = (crc << 8) ^ crc24bTable[(*inptr++) ^ (crc >> 24)]; + } if (resbit > 0) crc = (crc << resbit) ^ crc24bTable[((*inptr) >> (8 - resbit)) ^ (crc >> (32 - resbit))]; @@ -215,11 +211,10 @@ unsigned int crc24b (unsigned char * inptr, #endif } -unsigned int crc24c (unsigned char * inptr, - int bitlen) +uint32_t crc24c(unsigned char* inptr, int bitlen) { int octetlen, resbit; - unsigned int crc = 0; + uint32_t crc = 0; octetlen = bitlen / 8; /* Change in octets */ resbit = (bitlen % 8); @@ -234,11 +229,10 @@ unsigned int crc24c (unsigned char * inptr, return crc; } -unsigned int -crc16 (unsigned char * inptr, int bitlen) +uint32_t crc16(unsigned char* inptr, int bitlen) { int octetlen, resbit; - unsigned int crc = 0; + uint32_t crc = 0; octetlen = bitlen / 8; /* Change in octets */ resbit = (bitlen % 8); @@ -253,11 +247,10 @@ crc16 (unsigned char * inptr, int bitlen) return crc; } -unsigned int -crc12 (unsigned char * inptr, int bitlen) +uint32_t crc12(unsigned char* inptr, int bitlen) { int octetlen, resbit; - unsigned int crc = 0; + uint32_t crc = 0; octetlen = bitlen / 8; /* Change in octets */ resbit = (bitlen % 8); @@ -271,11 +264,10 @@ crc12 (unsigned char * inptr, int bitlen) return crc; } -unsigned int -crc11 (unsigned char * inptr, int bitlen) +uint32_t crc11(unsigned char* inptr, int bitlen) { int octetlen, resbit; - unsigned int crc = 0; + uint32_t crc = 0; octetlen = bitlen / 8; /* Change in octets */ resbit = (bitlen % 8); @@ -289,29 +281,27 @@ crc11 (unsigned char * inptr, int bitlen) return crc; } -unsigned int -crc8 (unsigned char * inptr, int bitlen) +uint32_t crc8(unsigned char* inptr, int bitlen) { int octetlen, resbit; - unsigned int crc = 0; + uint32_t crc = 0; octetlen = bitlen / 8; /* Change in octets */ resbit = (bitlen % 8); while (octetlen-- > 0) { - crc = ((unsigned int)crc8Table[(*inptr++) ^ (crc >> 24)]) << 24; + crc = ((uint32_t)crc8Table[(*inptr++) ^ (crc >> 24)]) << 24; } if (resbit > 0) - crc = (crc << resbit) ^ ((unsigned int)(crc8Table[((*inptr) >> (8 - resbit)) ^ (crc >> (32 - resbit))]) << 24); + crc = (crc << resbit) ^ ((uint32_t)(crc8Table[((*inptr) >> (8 - resbit)) ^ (crc >> (32 - resbit))]) << 24); return crc; } -unsigned int -crc6 (unsigned char * inptr, int bitlen) +uint32_t crc6(unsigned char* inptr, int bitlen) { int octetlen, resbit; - unsigned int crc = 0; + uint32_t crc = 0; octetlen = bitlen / 8; /* Change in octets */ resbit = (bitlen % 8); diff --git a/openair1/PHY/INIT/nr_init.c b/openair1/PHY/INIT/nr_init.c index 36561b110c..916cbd1cbf 100644 --- a/openair1/PHY/INIT/nr_init.c +++ b/openair1/PHY/INIT/nr_init.c @@ -753,7 +753,9 @@ void phy_free_nr_gNB(PHY_VARS_gNB *gNB) const int Prx = gNB->gNB_config.carrier_config.num_rx_ant.value; const int max_ul_mimo_layers = 4; // taken from phy_init_nr_gNB() const int n_buf = Prx * max_ul_mimo_layers; - + PHY_MEASUREMENTS_gNB *meas=&gNB->measurements; + free_and_zero(meas->n0_subband_power); + free_and_zero(meas->n0_subband_power_dB); int max_dl_mimo_layers =(fp->nb_antennas_txnb_antennas_tx : NR_MAX_NB_LAYERS; if (fp->nb_antennas_tx>1) { for (int nl = 0; nl < max_dl_mimo_layers; nl++) { diff --git a/openair1/PHY/LTE_ESTIMATION/lte_ue_measurements.c b/openair1/PHY/LTE_ESTIMATION/lte_ue_measurements.c index 6735e251ba..68d7b87984 100644 --- a/openair1/PHY/LTE_ESTIMATION/lte_ue_measurements.c +++ b/openair1/PHY/LTE_ESTIMATION/lte_ue_measurements.c @@ -1024,7 +1024,7 @@ void lte_ue_measurements(PHY_VARS_UE *ue, #elif defined(__arm__) || defined(__aarch64__) int16x8_t *dl_ch0_128, *dl_ch1_128; #endif - int *dl_ch0,*dl_ch1; + int *dl_ch0=NULL,*dl_ch1=NULL; LTE_DL_FRAME_PARMS *frame_parms = &ue->frame_parms; int nb_subbands,subband_size,last_subband_size; diff --git a/openair1/PHY/LTE_TRANSPORT/dci_tools_common.c b/openair1/PHY/LTE_TRANSPORT/dci_tools_common.c index 86a4c08e2e..19686eec6f 100644 --- a/openair1/PHY/LTE_TRANSPORT/dci_tools_common.c +++ b/openair1/PHY/LTE_TRANSPORT/dci_tools_common.c @@ -352,16 +352,16 @@ void conv_rballoc(uint8_t ra_header,uint32_t rb_alloc,uint32_t N_RB_DL,uint32_t if (ra_header==0) { for (i=16; i>0; i--) { - if ((rb_alloc&(1<> 5] |= (7U << ((3 * (16 - i)) % 32)); + if ((rb_alloc & (1 << i)) != 0) + rb_alloc2[(3 * (16 - i)) >> 5] |= (7U << ((3 * (16 - i)) % 32)); } // bit mask across if ((rb_alloc2[0]>>31)==1) - rb_alloc2[1] |= 1; + rb_alloc2[1] |= 1; if ((rb_alloc&1) != 0) - rb_alloc2[1] |= (3<<16); + rb_alloc2[1] |= (3 << 16); } else { LOG_W(PHY,"resource type 1 not supported for N_RB_DL=50\n"); @@ -371,10 +371,10 @@ void conv_rballoc(uint8_t ra_header,uint32_t rb_alloc,uint32_t N_RB_DL,uint32_t case 100: if (ra_header==0) { for (i=0; i<25; i++) { - if ((rb_alloc&(1<<(24-i))) != 0) - rb_alloc2[(4 * i) >> 5] |= (0xfU << ((4 * i) % 32)); + if ((rb_alloc & (1 << (24 - i))) != 0) + rb_alloc2[(4 * i) >> 5] |= (0xfU << ((4 * i) % 32)); - // printf("rb_alloc2[%d] (type 0) %x (%d)\n",(4*i)>>5,rb_alloc2[(4*i)>>5],rb_alloc&(1<>5,rb_alloc2[(4*i)>>5],rb_alloc&(1<tdd_config); - ret=255; + LOG_E(PHY, "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", subframe, frame_parms->tdd_config); + ret = 255; } else ret = (subframe/7); break; @@ -996,8 +996,7 @@ uint8_t subframe2harq_pid(LTE_DL_FRAME_PARMS *frame_parms,uint32_t frame,uint8_t } } - AssertFatal(ret!=255, - "invalid harq_pid(%d) at SFN/SF = %d/%d\n", (int8_t)ret, frame, subframe); + AssertFatal(ret != 255, "invalid harq_pid(%d) at SFN/SF = %d/%d\n", (int8_t)ret, frame, subframe); return ret; } diff --git a/openair1/PHY/LTE_UE_TRANSPORT/dlsch_demodulation.c b/openair1/PHY/LTE_UE_TRANSPORT/dlsch_demodulation.c index fc48d0c1de..54633fbc18 100644 --- a/openair1/PHY/LTE_UE_TRANSPORT/dlsch_demodulation.c +++ b/openair1/PHY/LTE_UE_TRANSPORT/dlsch_demodulation.c @@ -4706,11 +4706,8 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF, } if (rb_alloc_ind==1) { - int tmp = (rb >> 2) << 1; - if (tmp >= 16) - *pmi_ext = 0; - else - *pmi_ext = (pmi >> tmp) & 3; + uint32_t tmp = (rb >> 2) << 1; + *pmi_ext = tmp >= 16 ? 0 : (pmi >> tmp) & 3; memcpy(dl_ch0_ext,dl_ch0,12*sizeof(int)); /* diff --git a/openair1/PHY/NR_ESTIMATION/nr_measurements_gNB.c b/openair1/PHY/NR_ESTIMATION/nr_measurements_gNB.c index 495f767798..a26a1d0574 100644 --- a/openair1/PHY/NR_ESTIMATION/nr_measurements_gNB.c +++ b/openair1/PHY/NR_ESTIMATION/nr_measurements_gNB.c @@ -150,13 +150,15 @@ void gNB_I0_measurements(PHY_VARS_gNB *gNB,int slot, int first_symb,int num_symb unsigned int, gNB->measurements.n0_subband_power, frame_parms->nb_antennas_rx, - frame_parms->N_RB_UL); + frame_parms->N_RB_UL, + false); clearArray(gNB->measurements.n0_subband_power, unsigned int); allocCast2D(n0_subband_power_dB, unsigned int, gNB->measurements.n0_subband_power_dB, frame_parms->nb_antennas_rx, - frame_parms->N_RB_UL); + frame_parms->N_RB_UL, + false); for (int s=first_symb;s<(first_symb+num_symb);s++) { int offset0 = ((slot&3)*frame_parms->symbols_per_slot + s) * frame_parms->ofdm_symbol_size; @@ -233,31 +235,26 @@ void nr_gnb_measurements(PHY_VARS_gNB *gNB, PHY_MEASUREMENTS_gNB *meas = &gNB->measurements; NR_DL_FRAME_PARMS *fp = &gNB->frame_parms; int ch_offset = fp->ofdm_symbol_size * symbol; + int N_RB_UL = ulsch->harq_process->ulsch_pdu.rb_size; + ulsch_measurements_gNB *ulsch_measurements = &ulsch->ulsch_measurements; - int N_RB_UL = gNB->ulsch->harq_processes->ulsch_pdu.rb_size; - int rx_power[NUMBER_OF_NR_ULSCH_MAX][fp->nb_antennas_rx]; - rx_power_tot[ulsch_id] = 0; - allocCast3D(rx_spatial_power, int, meas->rx_spatial_power, NUMBER_OF_NR_ULSCH_MAX, nrOfLayers, fp->nb_antennas_rx); - allocCast3D(rx_spatial_power_dB, - unsigned short, - meas->rx_spatial_power_dB, - NUMBER_OF_NR_ULSCH_MAX, - nrOfLayers, - fp->nb_antennas_rx); + int rx_power[fp->nb_antennas_rx]; + allocCast2D(rx_spatial_power, int, ulsch_measurements->rx_spatial_power, nrOfLayers, fp->nb_antennas_rx, true); + allocCast2D(rx_spatial_power_dB, unsigned short, ulsch_measurements->rx_spatial_power_dB, nrOfLayers, fp->nb_antennas_rx, true); for (int aarx = 0; aarx < fp->nb_antennas_rx; aarx++){ rx_power[aarx] = 0; for (int aatx = 0; aatx < nrOfLayers; aatx++){ - rx_spatial_power[ulsch_id][aatx][aarx] = - (signal_energy_nodc(&gNB->pusch_vars[ulsch_id]->ul_ch_estimates[aatx * fp->nb_antennas_rx + aarx][ch_offset], + rx_spatial_power[aatx][aarx] = + (signal_energy_nodc(&pusch_vars->ul_ch_estimates[aatx * fp->nb_antennas_rx + aarx][ch_offset], N_RB_UL * NR_NB_SC_PER_RB)); - if (rx_spatial_power[ulsch_id][aatx][aarx] < 0) { - rx_spatial_power[ulsch_id][aatx][aarx] = 0; + if (rx_spatial_power[aatx][aarx] < 0) { + rx_spatial_power[aatx][aarx] = 0; } - rx_spatial_power_dB[ulsch_id][aatx][aarx] = (unsigned short)dB_fixed(rx_spatial_power[ulsch_id][aatx][aarx]); - rx_power[ulsch_id][aarx] += rx_spatial_power[ulsch_id][aatx][aarx]; + rx_spatial_power_dB[aatx][aarx] = (unsigned short)dB_fixed(rx_spatial_power[aatx][aarx]); + rx_power[aarx] += rx_spatial_power[aatx][aarx]; } LOG_D(PHY, "[RNTI %04x] RX power in antenna %d = %d\n", ulsch->rnti, aarx, rx_power[aarx]); diff --git a/openair1/PHY/NR_TRANSPORT/nr_ulsch.c b/openair1/PHY/NR_TRANSPORT/nr_ulsch.c index e7863d3820..352967c7f5 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_ulsch.c +++ b/openair1/PHY/NR_TRANSPORT/nr_ulsch.c @@ -88,8 +88,7 @@ void nr_fill_ulsch(PHY_VARS_gNB *gNB, int frame, int slot, nfapi_nr_pusch_pdu_t harq->round++; memcpy(&ulsch->harq_process->ulsch_pdu, ulsch_pdu, sizeof(ulsch->harq_process->ulsch_pdu)); - - LOG_D(PHY, "Initializing nFAPI for ULSCH, harq_pid %d\n", harq_pid); + LOG_D(PHY, "Initializing nFAPI for ULSCH, harq_pid %d, layers %d\n", harq_pid, ulsch_pdu->nrOfLayers); } void reset_active_ulsch(PHY_VARS_gNB *gNB, int frame) diff --git a/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c b/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c index 410ffc89d5..bcd73c58a9 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c +++ b/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c @@ -93,7 +93,7 @@ NR_gNB_ULSCH_t new_gNB_ulsch(uint8_t max_ldpc_iterations, uint16_t N_RB_UL) } uint32_t ulsch_bytes = a_segments * 1056; // allocated bytes per segment - NR_gNB_ULSCH_t ulsch; + NR_gNB_ULSCH_t ulsch = {0}; ulsch.max_ldpc_iterations = max_ldpc_iterations; ulsch.harq_pid = -1; diff --git a/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c b/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c index 0e7e77c54c..0b83222732 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c +++ b/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c @@ -1909,7 +1909,8 @@ void nr_rx_pusch(PHY_VARS_gNB *gNB, unsigned int, gNB->measurements.n0_subband_power, frame_parms->nb_antennas_rx, - frame_parms->N_RB_UL); + frame_parms->N_RB_UL, + false); for (aarx = 0; aarx < frame_parms->nb_antennas_rx; aarx++) { if (symbol == rel15_ul->start_symbol_index) { pusch_vars->ulsch_power[aarx] = 0; diff --git a/openair1/PHY/NR_UE_ESTIMATION/nr_ue_measurements.c b/openair1/PHY/NR_UE_ESTIMATION/nr_ue_measurements.c index 04e9c17788..be1515072d 100644 --- a/openair1/PHY/NR_UE_ESTIMATION/nr_ue_measurements.c +++ b/openair1/PHY/NR_UE_ESTIMATION/nr_ue_measurements.c @@ -92,14 +92,16 @@ void nr_ue_measurements(PHY_VARS_NR_UE *ue, int, ue->measurements.rx_spatial_power, NUMBER_OF_CONNECTED_gNB_MAX, + frame_parms->nb_antenna_ports_gNB, frame_parms->nb_antennas_rx, - frame_parms->nb_antenna_ports_gNB); + false); allocCast3D(rx_spatial_power_dB, unsigned short, ue->measurements.rx_spatial_power_dB, NUMBER_OF_CONNECTED_gNB_MAX, + frame_parms->nb_antenna_ports_gNB, frame_parms->nb_antennas_rx, - frame_parms->nb_antenna_ports_gNB); + false); // signal measurements for (gNB_id = 0; gNB_id < ue->n_connected_gNB; gNB_id++){ @@ -111,7 +113,8 @@ void nr_ue_measurements(PHY_VARS_NR_UE *ue, ue->measurements.rx_power[gNB_id][aarx] = 0; for (aatx = 0; aatx < frame_parms->nb_antenna_ports_gNB; aatx++){ - rx_spatial_power[gNB_id][aatx][aarx] = (signal_energy_nodc(&dl_ch_estimates[gNB_id][ch_offset], N_RB_DL * NR_NB_SC_PER_RB)); + const int z=signal_energy_nodc(&dl_ch_estimates[gNB_id][ch_offset], N_RB_DL * NR_NB_SC_PER_RB); + rx_spatial_power[gNB_id][aatx][aarx] = z; if (rx_spatial_power[gNB_id][aatx][aarx] < 0) rx_spatial_power[gNB_id][aatx][aarx] = 0; diff --git a/openair1/PHY/NR_UE_TRANSPORT/srs_modulation_nr.c b/openair1/PHY/NR_UE_TRANSPORT/srs_modulation_nr.c index 7b602c2e81..2cbd2afbd5 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/srs_modulation_nr.c +++ b/openair1/PHY/NR_UE_TRANSPORT/srs_modulation_nr.c @@ -403,7 +403,7 @@ int generate_srs_nr(nfapi_nr_srs_pdu_t *srs_config_pdu, LOG_I(NR_PHY,"(%d) \t%i\t%i\n", subcarrier_log, (int16_t)(r_real_amp&0xFFFF), (int16_t)(r_imag_amp&0xFFFF)); #endif - txdataF[p_index][symbol_offset+l_line_offset+subcarrier] = (r_real_amp & 0xFFFF) + ((r_imag_amp<<16)&0xFFFF0000); + *(c16_t *)&txdataF[p_index][symbol_offset + l_line_offset + subcarrier] = (c16_t){r_real_amp, r_imag_amp}; // Subcarrier increment subcarrier += K_TC; diff --git a/openair1/PHY/TOOLS/tools_defs.h b/openair1/PHY/TOOLS/tools_defs.h index b7dbbe8c42..e584d9f492 100644 --- a/openair1/PHY/TOOLS/tools_defs.h +++ b/openair1/PHY/TOOLS/tools_defs.h @@ -100,6 +100,7 @@ extern "C" { int dim2; int dim3; int dim4; + uint8_t data[]; } fourDimArray_t; static inline fourDimArray_t *allocateFourDimArray(int elmtSz, int dim1, int dim2, int dim3, int dim4) @@ -115,49 +116,55 @@ extern "C" { sz *= dim4; } } - fourDimArray_t *tmp = (fourDimArray_t *)malloc16(sizeof(*tmp) + sz); + fourDimArray_t *tmp = (fourDimArray_t *)malloc16_clear(sizeof(*tmp) + sz); AssertFatal(tmp, "no more memory\n"); *tmp = (fourDimArray_t){dim1, dim2, dim3, dim4}; return tmp; } -#define CheckArrAllocated(workingVar, elementType, ArraY, diM1, diM2, diM3, diM4) \ - if (!(ArraY)) \ - ArraY = allocateFourDimArray(sizeof(elementType), diM1, diM2, diM3, diM4); \ - else { \ - DevAssert((diM1) == (ArraY)->dim1 && (diM2) == (ArraY)->dim2 && (diM3) == (ArraY)->dim3 && (diM4) == (ArraY)->dim4); \ +#define CheckArrAllocated(workingVar, elementType, ArraY, diM1, diM2, diM3, diM4, resizeAllowed) \ + if (!(ArraY)) \ + ArraY = allocateFourDimArray(sizeof(elementType), diM1, diM2, diM3, diM4); \ + else { \ + if ((resizeAllowed) \ + && ((diM1) != (ArraY)->dim1 || (diM2) != (ArraY)->dim2 || (diM3) != (ArraY)->dim3 || (diM4) != (ArraY)->dim4)) { \ + LOG_I(PHY, "resizing %s to %d/%d/%d/%d\n", #ArraY, (diM1), (diM2), (diM3), (diM4)); \ + free(ArraY); \ + ArraY = allocateFourDimArray(sizeof(elementType), diM1, diM2, diM3, diM4); \ + } else \ + DevAssert((diM1) == (ArraY)->dim1 && (diM2) == (ArraY)->dim2 && (diM3) == (ArraY)->dim3 && (diM4) == (ArraY)->dim4); \ } -#define cast1Darray(workingVar, elementType, ArraY) elementType *workingVar = (elementType *)((ArraY) + 1); +#define cast1Darray(workingVar, elementType, ArraY) elementType *workingVar = (elementType *)((ArraY)->data); -#define allocCast1D(workingVar, elementType, ArraY, dim1) \ - CheckArrAllocated(workingVar, elementType, ArraY, dim1, 0, 0, 0); \ +#define allocCast1D(workingVar, elementType, ArraY, dim1, resizeAllowed) \ + CheckArrAllocated(workingVar, elementType, ArraY, dim1, 0, 0, 0, resizeAllowed); \ cast1Darray(workingVar, elementType, ArraY); #define cast2Darray(workingVar, elementType, ArraY) \ - elementType(*workingVar)[(ArraY)->dim2] = (elementType(*)[(ArraY)->dim2])((ArraY) + 1); + elementType(*workingVar)[(ArraY)->dim2] = (elementType(*)[(ArraY)->dim2])((ArraY)->data); -#define allocCast2D(workingVar, elementType, ArraY, dim1, dim2) \ - CheckArrAllocated(workingVar, elementType, ArraY, dim1, dim2, 0, 0); \ +#define allocCast2D(workingVar, elementType, ArraY, dim1, dim2, resizeAllowed) \ + CheckArrAllocated(workingVar, elementType, ArraY, dim1, dim2, 0, 0, resizeAllowed); \ cast2Darray(workingVar, elementType, ArraY); #define cast3Darray(workingVar, elementType, ArraY) \ - elementType(*workingVar)[(ArraY)->dim2][(ArraY)->dim3] = (elementType(*)[(ArraY)->dim2][(ArraY)->dim3])((ArraY) + 1); + elementType(*workingVar)[(ArraY)->dim2][(ArraY)->dim3] = (elementType(*)[(ArraY)->dim2][(ArraY)->dim3])((ArraY)->data); -#define allocCast3D(workingVar, elementType, ArraY, dim1, dim2, dim3) \ - CheckArrAllocated(workingVar, elementType, ArraY, dim1, dim2, dim3, 0); \ +#define allocCast3D(workingVar, elementType, ArraY, dim1, dim2, dim3, resizeAllowed) \ + CheckArrAllocated(workingVar, elementType, ArraY, dim1, dim2, dim3, 0, resizeAllowed); \ cast3Darray(workingVar, elementType, ArraY); #define cast4Darray(workingVar, elementType, ArraY) \ elementType(*workingVar)[(ArraY)->dim2][(ArraY)->dim3][(ArraY)->dim4] = \ - (elementType(*)[(ArraY)->dim2][(ArraY)->dim3][(ArraY)->dim4])((ArraY) + 1); + (elementType(*)[(ArraY)->dim2][(ArraY)->dim3][(ArraY)->dim4])((ArraY)->data); -#define allocCast4D(workingVar, elementType, ArraY, dim1, dim2, dim3, dim4) \ - CheckArrAllocated(workingVar, elementType, ArraY, dim1, dim2, dim3, dim4); \ +#define allocCast4D(workingVar, elementType, ArraY, dim1, dim2, dim3, dim4, resizeAllowed) \ + CheckArrAllocated(workingVar, elementType, ArraY, dim1, dim2, dim3, dim4, resizeAllowed); \ cast4Darray(workingVar, elementType, ArraY); #define clearArray(ArraY, elementType) \ - memset((ArraY) + 1, \ + memset((ArraY)->data, \ 0, \ sizeof(elementType) * (ArraY)->dim1 * max((ArraY)->dim2, 1) * max((ArraY)->dim3, 1) * max((ArraY)->dim4, 1)) diff --git a/openair1/PHY/defs_gNB.h b/openair1/PHY/defs_gNB.h index bcc4e29a6e..bfbcbd981f 100644 --- a/openair1/PHY/defs_gNB.h +++ b/openair1/PHY/defs_gNB.h @@ -229,9 +229,9 @@ typedef struct { typedef struct { //! estimated received spatial signal power (linear) - unsigned int rx_spatial_power[NB_ANTENNAS_TX][NB_ANTENNAS_RX]; + fourDimArray_t * rx_spatial_power; //! estimated received spatial signal power (dB) - unsigned int rx_spatial_power_dB[NB_ANTENNAS_TX][NB_ANTENNAS_RX]; + fourDimArray_t * rx_spatial_power_dB; //! estimated rssi (dBm) int rx_rssi_dBm; //! estimated correlation (wideband linear) between spatial channels (computed in dlsch_demodulation) diff --git a/openair1/SCHED_NR/phy_procedures_nr_gNB.c b/openair1/SCHED_NR/phy_procedures_nr_gNB.c index 24cacd092f..0b37171aac 100644 --- a/openair1/SCHED_NR/phy_procedures_nr_gNB.c +++ b/openair1/SCHED_NR/phy_procedures_nr_gNB.c @@ -631,7 +631,8 @@ void fill_ul_rb_mask(PHY_VARS_gNB *gNB, int frame_rx, int slot_rx) { nfapi_nr_srs_pdu_t *srs_pdu = &srs->srs_pdu; for(int symbol = 0; symbol<(1<num_symbols); symbol++) { for(rb = srs_pdu->bwp_start; rb < (srs_pdu->bwp_start+srs_pdu->bwp_size); rb++) { - gNB->rb_mask_ul[gNB->frame_parms.symbols_per_slot-srs_pdu->time_start_position-1+symbol][rb>>5] |= 1<<(rb&31); + gNB->rb_mask_ul[gNB->frame_parms.symbols_per_slot - srs_pdu->time_start_position - 1 + symbol][rb >> 5] |= 1U + << (rb & 31); } } } diff --git a/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c b/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c index adc5a013e6..b953c287ac 100644 --- a/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c +++ b/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c @@ -341,9 +341,6 @@ int8_t nr_ue_scheduled_response(nr_scheduled_response_t *scheduled_response){ int slot = scheduled_response->slot; // Note: we have to handle the thread IDs for this. To be revisited completely. - NR_UE_DLSCH_t *dlsch0 = &((nr_phy_data_t *)scheduled_response->phy_data)->dlsch[0]; - NR_UE_ULSCH_t *ulsch = &((nr_phy_data_tx_t *)scheduled_response->phy_data)->ulsch; - NR_UE_PUCCH *pucch_vars = &((nr_phy_data_tx_t *)scheduled_response->phy_data)->pucch_vars; NR_UE_CSI_IM *csiim_vars = PHY_vars_UE_g[module_id][cc_id]->csiim_vars[0]; NR_UE_CSI_RS *csirs_vars = PHY_vars_UE_g[module_id][cc_id]->csirs_vars[0]; NR_UE_PDCCH_CONFIG *phy_pdcch_config = NULL; @@ -384,27 +381,30 @@ int8_t nr_ue_scheduled_response(nr_scheduled_response_t *scheduled_response){ memcpy((void*)&(csirs_vars->csirs_config_pdu), (void*)csirs_config_pdu, sizeof(fapi_nr_dl_config_csirs_pdu_rel15_t)); csirs_vars->active = true; break; - case FAPI_NR_DL_CONFIG_TYPE_RA_DLSCH: + case FAPI_NR_DL_CONFIG_TYPE_RA_DLSCH: { dlsch_config_pdu = &dl_config->dl_config_list[i].dlsch_config_pdu.dlsch_config_rel15; + NR_UE_DLSCH_t *dlsch0 = &((nr_phy_data_t *)scheduled_response->phy_data)->dlsch[0]; dlsch0->rnti_type = _RA_RNTI_; dlsch0->dlsch_config = *dlsch_config_pdu; configure_dlsch(dlsch0, PHY_vars_UE_g[module_id][cc_id]->dl_harq_processes[0], dlsch_config_pdu, module_id, dl_config->dl_config_list[i].dlsch_config_pdu.rnti); - break; - case FAPI_NR_DL_CONFIG_TYPE_SI_DLSCH: + } break; + case FAPI_NR_DL_CONFIG_TYPE_SI_DLSCH: { dlsch_config_pdu = &dl_config->dl_config_list[i].dlsch_config_pdu.dlsch_config_rel15; + NR_UE_DLSCH_t *dlsch0 = &((nr_phy_data_t *)scheduled_response->phy_data)->dlsch[0]; dlsch0->rnti_type = _SI_RNTI_; dlsch0->dlsch_config = *dlsch_config_pdu; configure_dlsch(dlsch0, PHY_vars_UE_g[module_id][cc_id]->dl_harq_processes[0], dlsch_config_pdu, module_id, dl_config->dl_config_list[i].dlsch_config_pdu.rnti); - break; - case FAPI_NR_DL_CONFIG_TYPE_DLSCH: + } break; + case FAPI_NR_DL_CONFIG_TYPE_DLSCH: { dlsch_config_pdu = &dl_config->dl_config_list[i].dlsch_config_pdu.dlsch_config_rel15; + NR_UE_DLSCH_t *dlsch0 = &((nr_phy_data_t *)scheduled_response->phy_data)->dlsch[0]; dlsch0->rnti_type = _C_RNTI_; dlsch0->dlsch_config = *dlsch_config_pdu; configure_dlsch(dlsch0, PHY_vars_UE_g[module_id][cc_id]->dl_harq_processes[0], dlsch_config_pdu, module_id, dl_config->dl_config_list[i].dlsch_config_pdu.rnti); - break; + } break; } } dl_config->number_pdus = 0; @@ -435,90 +435,136 @@ int8_t nr_ue_scheduled_response(nr_scheduled_response_t *scheduled_response){ fapi_nr_ul_config_srs_pdu *srs_config_pdu; switch (pdu_type){ + case FAPI_NR_UL_CONFIG_TYPE_PUSCH: { + // pusch config pdu + pusch_config_pdu = &ul_config->ul_config_list[i].pusch_config_pdu; + current_harq_pid = pusch_config_pdu->pusch_data.harq_process_id; + NR_UL_UE_HARQ_t *harq_process_ul_ue = &PHY_vars_UE_g[module_id][cc_id]->ul_harq_processes[current_harq_pid]; + NR_UE_ULSCH_t *ulsch = &((nr_phy_data_tx_t *)scheduled_response->phy_data)->ulsch; + nfapi_nr_ue_pusch_pdu_t *pusch_pdu = &ulsch->pusch_pdu; - case (FAPI_NR_UL_CONFIG_TYPE_PUSCH): - // pusch config pdu - pusch_config_pdu = &ul_config->ul_config_list[i].pusch_config_pdu; - current_harq_pid = pusch_config_pdu->pusch_data.harq_process_id; - NR_UL_UE_HARQ_t *harq_process_ul_ue = &PHY_vars_UE_g[module_id][cc_id]->ul_harq_processes[current_harq_pid]; + LOG_D(PHY, + "In %s i %d: copy pusch_config_pdu nrOfLayers:%d, num_dmrs_cdm_grps_no_data:%d \n", + __FUNCTION__, + i, + pusch_config_pdu->nrOfLayers, + pusch_config_pdu->num_dmrs_cdm_grps_no_data); - nfapi_nr_ue_pusch_pdu_t *pusch_pdu = &ulsch->pusch_pdu; + memcpy(pusch_pdu, pusch_config_pdu, sizeof(nfapi_nr_ue_pusch_pdu_t)); + if (scheduled_response->tx_request) { + for (int j = 0; j < scheduled_response->tx_request->number_of_pdus; j++) { + fapi_nr_tx_request_body_t *tx_req_body = &scheduled_response->tx_request->tx_request_body[j]; + if ((tx_req_body->pdu_index == i) && (tx_req_body->pdu_length > 0)) { + LOG_D(PHY, + "%d.%d Copying %d bytes to harq_process_ul_ue->a (harq_pid %d)\n", + scheduled_response->frame, + slot, + tx_req_body->pdu_length, + current_harq_pid); + memcpy(harq_process_ul_ue->a, tx_req_body->pdu, tx_req_body->pdu_length); + break; + } + } - LOG_D(PHY, "In %s i %d: copy pusch_config_pdu nrOfLayers:%d, num_dmrs_cdm_grps_no_data:%d \n", __FUNCTION__, i, pusch_config_pdu->nrOfLayers,pusch_config_pdu->num_dmrs_cdm_grps_no_data); + harq_process_ul_ue->status = ACTIVE; + ul_config->ul_config_list[i].pdu_type = FAPI_NR_UL_CONFIG_TYPE_DONE; // not handle it any more + pdu_done++; + LOG_D(PHY, + "%d.%d ul A ul_config %p t %d pdu_done %d number_pdus %d\n", + scheduled_response->frame, + slot, + ul_config, + pdu_type, + pdu_done, + ul_config->number_pdus); - memcpy(pusch_pdu, pusch_config_pdu, sizeof(nfapi_nr_ue_pusch_pdu_t)); - if (scheduled_response->tx_request) { - for (int j=0; jtx_request->number_of_pdus; j++) { - fapi_nr_tx_request_body_t *tx_req_body = &scheduled_response->tx_request->tx_request_body[j]; - if ((tx_req_body->pdu_index == i) && (tx_req_body->pdu_length > 0)) { - LOG_D(PHY,"%d.%d Copying %d bytes to harq_process_ul_ue->a (harq_pid %d)\n",scheduled_response->frame,slot,tx_req_body->pdu_length,current_harq_pid); - memcpy(harq_process_ul_ue->a, tx_req_body->pdu, tx_req_body->pdu_length); + } else { + LOG_E(PHY, "[phy_procedures_nrUE_TX] harq_process_ul_ue is NULL !!\n"); + return -1; + } + } break; + + case FAPI_NR_UL_CONFIG_TYPE_PUCCH: { + NR_UE_PUCCH *pucch_vars = &((nr_phy_data_tx_t *)scheduled_response->phy_data)->pucch_vars; + found = false; + pucch_config_pdu = &ul_config->ul_config_list[i].pucch_config_pdu; + for (int j = 0; j < 2; j++) { + if (pucch_vars->active[j] == false) { + LOG_D(PHY, "%d.%d Copying pucch pdu to UE PHY\n", scheduled_response->frame, slot); + memcpy((void *)&(pucch_vars->pucch_pdu[j]), (void *)pucch_config_pdu, sizeof(fapi_nr_ul_config_pucch_pdu)); + pucch_vars->active[j] = true; + found = true; + ul_config->ul_config_list[i].pdu_type = FAPI_NR_UL_CONFIG_TYPE_DONE; // not handle it any more + pdu_done++; + LOG_D(PHY, + "%d.%d ul A ul_config %p t %d pdu_done %d number_pdus %d\n", + scheduled_response->frame, + slot, + ul_config, + pdu_type, + pdu_done, + ul_config->number_pdus); break; } } + if (!found) + LOG_E(PHY, "Couldn't find allocation for PUCCH PDU in PUCCH VARS\n"); + } break; - harq_process_ul_ue->status = ACTIVE; + case FAPI_NR_UL_CONFIG_TYPE_PRACH: + // prach config pdu + prach_config_pdu = &ul_config->ul_config_list[i].prach_config_pdu; + memcpy((void *)&(PHY_vars_UE_g[module_id][cc_id]->prach_vars[gNB_id]->prach_pdu), + (void *)prach_config_pdu, + sizeof(fapi_nr_ul_config_prach_pdu)); + PHY_vars_UE_g[module_id][cc_id]->prach_vars[gNB_id]->active = true; ul_config->ul_config_list[i].pdu_type = FAPI_NR_UL_CONFIG_TYPE_DONE; // not handle it any more pdu_done++; - LOG_D(PHY, "%d.%d ul A ul_config %p t %d pdu_done %d number_pdus %d\n", scheduled_response->frame, slot, ul_config, pdu_type, pdu_done, ul_config->number_pdus); + LOG_D(PHY, + "%d.%d ul A ul_config %p t %d pdu_done %d number_pdus %d\n", + scheduled_response->frame, + slot, + ul_config, + pdu_type, + pdu_done, + ul_config->number_pdus); + break; - } else { + case FAPI_NR_UL_CONFIG_TYPE_DONE: + pdu_done++; // count the no of pdu processed + LOG_D(PHY, + "%d.%d ul A ul_config %p t %d pdu_done %d number_pdus %d\n", + scheduled_response->frame, + slot, + ul_config, + pdu_type, + pdu_done, + ul_config->number_pdus); + break; - LOG_E(PHY, "[phy_procedures_nrUE_TX] harq_process_ul_ue is NULL !!\n"); - return -1; + case FAPI_NR_UL_CONFIG_TYPE_SRS: + // srs config pdu + srs_config_pdu = &ul_config->ul_config_list[i].srs_config_pdu; + memcpy((void *)&(PHY_vars_UE_g[module_id][cc_id]->srs_vars[gNB_id]->srs_config_pdu), + (void *)srs_config_pdu, + sizeof(fapi_nr_ul_config_srs_pdu)); + PHY_vars_UE_g[module_id][cc_id]->srs_vars[gNB_id]->active = true; + ul_config->ul_config_list[i].pdu_type = FAPI_NR_UL_CONFIG_TYPE_DONE; // not handle it any more + pdu_done++; + break; - } - - break; - - case (FAPI_NR_UL_CONFIG_TYPE_PUCCH): - found = false; - pucch_config_pdu = &ul_config->ul_config_list[i].pucch_config_pdu; - for(int j=0; j<2; j++) { - if(pucch_vars->active[j] == false) { - LOG_D(PHY,"%d.%d Copying pucch pdu to UE PHY\n",scheduled_response->frame,slot); - memcpy((void*)&(pucch_vars->pucch_pdu[j]), (void*)pucch_config_pdu, sizeof(fapi_nr_ul_config_pucch_pdu)); - pucch_vars->active[j] = true; - found = true; - ul_config->ul_config_list[i].pdu_type = FAPI_NR_UL_CONFIG_TYPE_DONE; // not handle it any more - pdu_done++; - LOG_D(PHY, "%d.%d ul A ul_config %p t %d pdu_done %d number_pdus %d\n", scheduled_response->frame, slot, ul_config, pdu_type, pdu_done, ul_config->number_pdus); - break; - } - } - if (!found) - LOG_E(PHY, "Couldn't find allocation for PUCCH PDU in PUCCH VARS\n"); - break; - - case (FAPI_NR_UL_CONFIG_TYPE_PRACH): - // prach config pdu - prach_config_pdu = &ul_config->ul_config_list[i].prach_config_pdu; - memcpy((void*)&(PHY_vars_UE_g[module_id][cc_id]->prach_vars[gNB_id]->prach_pdu), (void*)prach_config_pdu, sizeof(fapi_nr_ul_config_prach_pdu)); - PHY_vars_UE_g[module_id][cc_id]->prach_vars[gNB_id]->active = true; - ul_config->ul_config_list[i].pdu_type = FAPI_NR_UL_CONFIG_TYPE_DONE; // not handle it any more - pdu_done++; - LOG_D(PHY, "%d.%d ul A ul_config %p t %d pdu_done %d number_pdus %d\n", scheduled_response->frame, slot, ul_config, pdu_type, pdu_done, ul_config->number_pdus); - break; - - case (FAPI_NR_UL_CONFIG_TYPE_DONE): - pdu_done++; // count the no of pdu processed - LOG_D(PHY, "%d.%d ul A ul_config %p t %d pdu_done %d number_pdus %d\n", scheduled_response->frame, slot, ul_config, pdu_type, pdu_done, ul_config->number_pdus); - break; - - case (FAPI_NR_UL_CONFIG_TYPE_SRS): - // srs config pdu - srs_config_pdu = &ul_config->ul_config_list[i].srs_config_pdu; - memcpy((void*)&(PHY_vars_UE_g[module_id][cc_id]->srs_vars[gNB_id]->srs_config_pdu), (void*)srs_config_pdu, sizeof(fapi_nr_ul_config_srs_pdu)); - PHY_vars_UE_g[module_id][cc_id]->srs_vars[gNB_id]->active = true; - ul_config->ul_config_list[i].pdu_type = FAPI_NR_UL_CONFIG_TYPE_DONE; // not handle it any more - pdu_done++; - break; - - default: - ul_config->ul_config_list[i].pdu_type = FAPI_NR_UL_CONFIG_TYPE_DONE; // not handle it any more - pdu_done++; // count the no of pdu processed - LOG_D(PHY, "%d.%d ul A ul_config %p t %d pdu_done %d number_pdus %d\n", scheduled_response->frame, slot, ul_config, pdu_type, pdu_done, ul_config->number_pdus); - break; + default: + ul_config->ul_config_list[i].pdu_type = FAPI_NR_UL_CONFIG_TYPE_DONE; // not handle it any more + pdu_done++; // count the no of pdu processed + LOG_D(PHY, + "%d.%d ul A ul_config %p t %d pdu_done %d number_pdus %d\n", + scheduled_response->frame, + slot, + ul_config, + pdu_type, + pdu_done, + ul_config->number_pdus); + break; } } diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c index 664cddcfdf..470d5fd627 100644 --- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c +++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c @@ -544,7 +544,7 @@ int nr_ue_pdsch_procedures(PHY_VARS_NR_UE *ue, if (!(NR_MAX_NB_LAYERS>4)) { NR_UE_DLSCH_t *dlsch0 = &dlsch[0]; int harq_pid = dlsch0->dlsch_config.harq_process_nbr; - NR_DL_UE_HARQ_t *dlsch0_harq = ue->dl_harq_processes[harq_pid]; + NR_DL_UE_HARQ_t *dlsch0_harq = &ue->dl_harq_processes[0][harq_pid]; uint16_t BWPStart = dlsch0->dlsch_config.BWPStart; uint16_t pdsch_start_rb = dlsch0->dlsch_config.start_rb; uint16_t pdsch_nb_rb = dlsch0->dlsch_config.number_rbs; diff --git a/openair1/SIMULATION/LTE_PHY/ulsim.c b/openair1/SIMULATION/LTE_PHY/ulsim.c index 9a49802909..f3c2352084 100644 --- a/openair1/SIMULATION/LTE_PHY/ulsim.c +++ b/openair1/SIMULATION/LTE_PHY/ulsim.c @@ -53,8 +53,7 @@ #include "executables/lte-softmodem.h" #include "common/ran_context.h" #include "PHY/LTE_ESTIMATION/lte_estimation.h" -#include "openair1/PHY/LTE_TRANSPORT/dlsch_tbs.h" - +#include "openair1/PHY/LTE_TRANSPORT/dlsch_tbs_full.h" const char *__asan_default_options() { /* don't do leak checking in ulsim, not finished yet */ @@ -806,7 +805,7 @@ int main(int argc, char **argv) { if (cqi_flag == 1) coded_bits_per_codeword-=UE->ulsch[0]->O; - rate = (double)dlsch_tbs25[get_I_TBS(mcs)][nb_rb - 1] / (coded_bits_per_codeword); + rate = (double)TBStable[get_I_TBS(mcs)][nb_rb - 1] / (coded_bits_per_codeword); printf("Rate = %f (mod %d), coded bits %u\n",rate,get_Qm_ul(mcs),coded_bits_per_codeword); for (ch_realization=0; ch_realizationframe_parms,frame_parms,sizeof(NR_DL_FRAME_PARMS)); UE->frame_parms.nb_antennas_rx = n_rx; + UE->frame_parms.nb_antenna_ports_gNB = n_tx; UE->max_ldpc_iterations = max_ldpc_iterations; if (run_initial_sync==1) diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c index 3c4fe6c2ee..8899dc5918 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c @@ -2609,6 +2609,7 @@ uint8_t get_ssb_rsrp_payload(NR_UE_MAC_INST_t *mac, int ssbri_bits = ceil(log2(nb_ssb)); int ssb_rsrp[2][nb_meas]; // the array contains index and RSRP of each SSB to be reported (nb_meas highest RSRPs) + memset(ssb_rsrp, 0, sizeof(ssb_rsrp)); //TODO replace the following 2 lines with a function to order the nb_meas highest SSB RSRPs for (int i=0; ibyte = 0; encoder->bit = 0; - encoder->buffer = buffer; + encoder->buffer = (unsigned char *)buffer; encoder->size = size; } diff --git a/openair2/LAYER2/nr_rlc/nr_rlc_pdu.h b/openair2/LAYER2/nr_rlc/nr_rlc_pdu.h index 8e9872522f..0f5cd6c6d0 100644 --- a/openair2/LAYER2/nr_rlc/nr_rlc_pdu.h +++ b/openair2/LAYER2/nr_rlc/nr_rlc_pdu.h @@ -71,7 +71,7 @@ int nr_rlc_pdu_decoder_get_bits(nr_rlc_pdu_decoder_t *decoder, int count); typedef struct { int byte; /* next byte to encode */ int bit; /* next bit in next byte to encode */ - char *buffer; + unsigned char *buffer; int size; } nr_rlc_pdu_encoder_t; diff --git a/openair3/NAS/COMMON/EMM/MSG/FGSUplinkNasTransport.c b/openair3/NAS/COMMON/EMM/MSG/FGSUplinkNasTransport.c index d94df434b2..741ec095c3 100644 --- a/openair3/NAS/COMMON/EMM/MSG/FGSUplinkNasTransport.c +++ b/openair3/NAS/COMMON/EMM/MSG/FGSUplinkNasTransport.c @@ -55,9 +55,11 @@ int encode_fgs_payload_container(FGSPayloadContainer *paycontainer, uint8_t iei, encoded += encode_result; } if(iei > 0){ - *(uint16_t*) (buffer+1) = htons(encoded - 3); + uint16_t tmp = htons(encoded - 3); + memcpy(buffer + 1, &tmp, sizeof(tmp)); } else { - *(uint16_t*) (buffer) = htons(encoded - 2); + uint16_t tmp = htons(encoded - 2); + memcpy(buffer, &tmp, sizeof(tmp)); } return encoded; diff --git a/openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishmentAccept.c b/openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishmentAccept.c index ddda52e5f7..72dedb3f7a 100644 --- a/openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishmentAccept.c +++ b/openair3/NAS/COMMON/ESM/MSG/PduSessionEstablishmentAccept.c @@ -35,14 +35,18 @@ void capture_pdu_session_establishment_accept_msg(uint8_t *buffer, uint32_t msg_ pdu_session_establishment_accept_msg_t psea_msg; sec_nas_hdr.epd = *(buffer + (offset++)); sec_nas_hdr.sht = *(buffer + (offset++)); - sec_nas_hdr.mac = htonl(*(uint32_t *)(buffer + offset)); + uint32_t tmp; + memcpy(&tmp, buffer + offset, sizeof(tmp)); + sec_nas_hdr.mac = htonl(tmp); offset+=sizeof(sec_nas_hdr.mac); sec_nas_hdr.sqn = *(buffer + (offset++)); sec_nas_msg.epd = *(buffer + (offset++)); sec_nas_msg.sht = *(buffer + (offset++)); sec_nas_msg.msg_type = *(buffer + (offset++)); sec_nas_msg.payload_type = *(buffer + (offset++)); - sec_nas_msg.payload_len = htons(*(uint16_t *)(buffer + offset)); + uint16_t tmp16; + memcpy(&tmp16, buffer + offset, sizeof(tmp16)); + sec_nas_msg.payload_len = htons(tmp16); offset+=sizeof(sec_nas_msg.payload_len); /* Mandatory Presence IEs */ psea_msg.epd = *(buffer + (offset++)); @@ -51,12 +55,14 @@ void capture_pdu_session_establishment_accept_msg(uint8_t *buffer, uint32_t msg_ psea_msg.msg_type = *(buffer + (offset++)); psea_msg.pdu_type = *(buffer + offset) & 0x0f; psea_msg.ssc_mode = (*(buffer + (offset++)) & 0xf0) >> 4; - psea_msg.qos_rules.length = htons(*(uint16_t *)(buffer + offset)); + memcpy(&tmp16, buffer + offset, sizeof(tmp16)); + psea_msg.qos_rules.length = htons(tmp16); offset+=sizeof(psea_msg.qos_rules.length); /* Supports the capture of only one QoS Rule, it should be changed for multiple QoS Rules */ qos_rule_t qos_rule; qos_rule.id = *(buffer + (offset++)); - qos_rule.length = htons(*(uint16_t *)(buffer + offset)); + memcpy(&tmp16, buffer + offset, sizeof(tmp16)); + qos_rule.length = htons(tmp16); offset+=sizeof(qos_rule.length); qos_rule.oc = (*(buffer + offset) & 0xE0) >> 5; qos_rule.dqr = (*(buffer + offset) & 0x10) >> 4; diff --git a/openair3/NAS/COMMON/IES/FGCNasMessageContainer.c b/openair3/NAS/COMMON/IES/FGCNasMessageContainer.c index 874f61e7b3..4e8de951a5 100644 --- a/openair3/NAS/COMMON/IES/FGCNasMessageContainer.c +++ b/openair3/NAS/COMMON/IES/FGCNasMessageContainer.c @@ -76,7 +76,8 @@ int encode_fgc_nas_message_container(FGCNasMessageContainer *nasmessagecontainer if ((encode_result = encode_octet_string(&nasmessagecontainer->nasmessagecontainercontents, buffer + encoded, len - encoded)) < 0) { return encode_result; } else { - *(uint16_t*) (buffer+1) = htons(encoded + encode_result - 3); + uint16_t tmp = htons(encoded + encode_result - 3); + memcpy(buffer + 1, &tmp, sizeof(tmp)); encoded += encode_result; } diff --git a/openair3/NAS/COMMON/IES/FGSMobileIdentity.c b/openair3/NAS/COMMON/IES/FGSMobileIdentity.c index 872fc8e53c..ea877481e6 100644 --- a/openair3/NAS/COMMON/IES/FGSMobileIdentity.c +++ b/openair3/NAS/COMMON/IES/FGSMobileIdentity.c @@ -53,8 +53,9 @@ int decode_5gs_mobile_identity(FGSMobileIdentity *fgsmobileidentity, uint8_t iei CHECK_IEI_DECODER(iei, *buffer); decoded++; } - - ielen = *(uint16_t*)(buffer + decoded); /* length is two bytes */ + uint16_t tmp; + memcpy(&tmp, buffer + decoded, sizeof(tmp)); + ielen = (uint8_t)tmp; decoded += 2; CHECK_LENGTH_DECODER(len - decoded, ielen); @@ -106,9 +107,11 @@ int encode_5gs_mobile_identity(FGSMobileIdentity *fgsmobileidentity, uint8_t iei } if(iei > 0){ - *(uint16_t*) (buffer+1) = htons(encoded + encoded_rc - 3); + uint16_t tmp = htons(encoded + encoded_rc - 3); + memcpy(buffer + 1, &tmp, sizeof(tmp)); } else { - *(uint16_t*) buffer = htons(encoded + encoded_rc - 2); + uint16_t tmp = htons(encoded + encoded_rc - 2); + memcpy(buffer, &tmp, sizeof(tmp)); } return (encoded + encoded_rc); diff --git a/openair3/NAS/COMMON/UTIL/TLVDecoder.h b/openair3/NAS/COMMON/UTIL/TLVDecoder.h index e8dce87d8d..941cbd850b 100644 --- a/openair3/NAS/COMMON/UTIL/TLVDecoder.h +++ b/openair3/NAS/COMMON/UTIL/TLVDecoder.h @@ -41,9 +41,13 @@ vALUE = ntohl(*(uint32_t*)(bUFFER)) >> 8; \ sIZE += sizeof(uint8_t) + sizeof(uint16_t) -#define DECODE_U32(bUFFER, vALUE, sIZE) \ - vALUE = ntohl(*(uint32_t*)(bUFFER)); \ - sIZE += sizeof(uint32_t) +#define DECODE_U32(bUFFER, vALUE, sIZE) \ + { \ + uint32_t v; \ + memcpy(&v, bUFFER, sizeof(v)); \ + vALUE = ntohl(v); \ + } \ + sIZE += sizeof(uint32_t) #if (BYTE_ORDER == LITTLE_ENDIAN) # define DECODE_LENGTH_U16(bUFFER, vALUE, sIZE) \ diff --git a/openair3/NAS/COMMON/UTIL/TLVEncoder.h b/openair3/NAS/COMMON/UTIL/TLVEncoder.h index df5b58a07f..a46de3fbba 100644 --- a/openair3/NAS/COMMON/UTIL/TLVEncoder.h +++ b/openair3/NAS/COMMON/UTIL/TLVEncoder.h @@ -36,9 +36,12 @@ *(uint32_t*)(buffer) = htonl(value); \ size += sizeof(uint8_t) + sizeof(uint16_t) -#define ENCODE_U32(buffer, value, size) \ - *(uint32_t*)(buffer) = htonl(value); \ - size += sizeof(uint32_t) +#define ENCODE_U32(buffer, value, size) \ + { \ + uint32_t tmp = htonl(value); \ + memcpy(buffer, &tmp, sizeof(tmp)); \ + } \ + size += sizeof(uint32_t) #define IES_ENCODE_U8(buffer, encoded, value) \ ENCODE_U8(buffer + encoded, value, encoded) diff --git a/openair3/NAS/NR_UE/nr_nas_msg_sim.c b/openair3/NAS/NR_UE/nr_nas_msg_sim.c index e20a0fc99e..e57e3800de 100644 --- a/openair3/NAS/NR_UE/nr_nas_msg_sim.c +++ b/openair3/NAS/NR_UE/nr_nas_msg_sim.c @@ -883,7 +883,9 @@ uint8_t get_msg_type(uint8_t *pdu_buffer, uint32_t length) { msg_type = ((mm_msg_header_t *)(pdu_buffer + offset))->message_type; if (msg_type == FGS_DOWNLINK_NAS_TRANSPORT) { - msg_type = ((dl_nas_transport_t *)(pdu_buffer+ offset))->sm_nas_msg_header.message_type; + dl_nas_transport_t tmp; + memcpy(&tmp, pdu_buffer + offset, sizeof(tmp)); + msg_type = tmp.sm_nas_msg_header.message_type; } } } else { // plain 5GS NAS message