Commit b735f8be authored by laurent's avatar laurent Committed by Robert Schmidt

ubsan fixes

parent 8a10d1b2
......@@ -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);
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);
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;
}
}
}
......
......@@ -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
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
unsigned int poly24b = 0x80006300; // 1000 0000 0000 0000 0110 0011
uint32_t 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
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,14 +149,13 @@ 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);
......@@ -188,13 +185,12 @@ 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;
uint32_t crc = 0;
int resbit = (bitlen % 8);
while (octetlen-- > 0) {
......@@ -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);
......
......@@ -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_tx<NR_MAX_NB_LAYERS) ? fp->nb_antennas_tx : NR_MAX_NB_LAYERS;
if (fp->nb_antennas_tx>1) {
for (int nl = 0; nl < max_dl_mimo_layers; nl++) {
......
......@@ -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;
......
......@@ -352,7 +352,7 @@ 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<<i)) != 0)
if ((rb_alloc & (1 << i)) != 0)
rb_alloc2[(3 * (16 - i)) >> 5] |= (7U << ((3 * (16 - i)) % 32));
}
......@@ -361,7 +361,7 @@ void conv_rballoc(uint8_t ra_header,uint32_t rb_alloc,uint32_t N_RB_DL,uint32_t
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,7 +371,7 @@ 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)
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<<i));
......@@ -960,8 +960,8 @@ uint8_t subframe2harq_pid(LTE_DL_FRAME_PARMS *frame_parms,uint32_t frame,uint8_t
case 2:
if ((subframe!=2) && (subframe!=7)) {
LOG_E(PHY,"subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",subframe,frame_parms->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;
}
......
......@@ -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));
/*
......
......@@ -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]);
......
......@@ -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)
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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) \
#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))
......
......@@ -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)
......
......@@ -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<<srs_pdu->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);
}
}
}
......
This diff is collapsed.
......@@ -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;
......
......@@ -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_realization<n_ch_rlz; ch_realization++) {
......
......@@ -831,6 +831,7 @@ int main(int argc, char **argv)
PHY_vars_UE_g[0][0] = UE;
memcpy(&UE->frame_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)
......
......@@ -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; i<nb_ssb; i++) {
......
......@@ -151,7 +151,7 @@ void nr_rlc_pdu_encoder_init(nr_rlc_pdu_encoder_t *encoder,
{
encoder->byte = 0;
encoder->bit = 0;
encoder->buffer = buffer;
encoder->buffer = (unsigned char *)buffer;
encoder->size = size;
}
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -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);
......
......@@ -42,7 +42,11 @@
sIZE += sizeof(uint8_t) + sizeof(uint16_t)
#define DECODE_U32(bUFFER, vALUE, sIZE) \
vALUE = ntohl(*(uint32_t*)(bUFFER)); \
{ \
uint32_t v; \
memcpy(&v, bUFFER, sizeof(v)); \
vALUE = ntohl(v); \
} \
sIZE += sizeof(uint32_t)
#if (BYTE_ORDER == LITTLE_ENDIAN)
......
......@@ -37,7 +37,10 @@
size += sizeof(uint8_t) + sizeof(uint16_t)
#define ENCODE_U32(buffer, value, size) \
*(uint32_t*)(buffer) = htonl(value); \
{ \
uint32_t tmp = htonl(value); \
memcpy(buffer, &tmp, sizeof(tmp)); \
} \
size += sizeof(uint32_t)
#define IES_ENCODE_U8(buffer, encoded, value) \
......
......@@ -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
......
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