From 10ff80815f43f30f11693e3558cd3c4d9e4056ca Mon Sep 17 00:00:00 2001 From: Laurent THOMAS Date: Fri, 27 Jun 2025 15:21:13 +0200 Subject: [PATCH 1/2] when we try to detect a specific PCI, and it fails, the SSS detection return successful detection, with wrong frequency offset --- openair1/PHY/NR_UE_TRANSPORT/sss_nr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openair1/PHY/NR_UE_TRANSPORT/sss_nr.c b/openair1/PHY/NR_UE_TRANSPORT/sss_nr.c index 0a13462d8c..da27ca8603 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/sss_nr.c +++ b/openair1/PHY/NR_UE_TRANSPORT/sss_nr.c @@ -499,7 +499,7 @@ bool rx_sss_nr(const NR_DL_FRAME_PARMS *frame_parms, int re = 0; int im = 0; - if (Nid1 == N_ID_1_NUMBER) { + if (Nid1 == Nid1_end) { LOG_D(PHY, "Failed to detect SSS after PSS, metric of SSS %d, threshold to consider SSS valid %d, detected PCI: %d\n", *tot_metric, From fb85a8cda309bbd94cd4b4b1eccddb098dc4492e Mon Sep 17 00:00:00 2001 From: Laurent THOMAS Date: Fri, 27 Jun 2025 15:21:47 +0200 Subject: [PATCH 2/2] clarify and indent correctly the function initial sync --- .../PHY/NR_UE_TRANSPORT/nr_initial_sync.c | 130 +++++++++--------- 1 file changed, 66 insertions(+), 64 deletions(-) diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c index 422e8d6484..d5c2514634 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c @@ -311,7 +311,7 @@ nr_initial_sync_t nr_initial_sync(UE_nr_rxtx_proc_t *proc, fp->dl_CarrierFreq, fp->N_RB_DL, numGscn); - + DevAssert(numGscn); task_ans_t ans; init_task_ans(&ans, numGscn); nr_ue_ssb_scan_t ssb_info[numGscn]; @@ -342,39 +342,38 @@ nr_initial_sync_t nr_initial_sync(UE_nr_rxtx_proc_t *proc, } // Collect the scan results - nr_ue_ssb_scan_t res = {0}; - if (numGscn > 0) { - join_task_ans(&ans); - for (int i = 0; i < numGscn; i++) { - nr_ue_ssb_scan_t *ssbInfo = &ssb_info[i]; - if (ssbInfo->syncRes.cell_detected) { - LOG_I(NR_PHY, - "Cell Detected with GSCN: %d, SSB SC offset: %d, SSB Ref: %lf, PSS Corr peak: %d dB, PSS Corr Average: %d\n", - ssbInfo->gscnInfo.gscn, - ssbInfo->gscnInfo.ssbFirstSC, - ssbInfo->gscnInfo.ssRef, - ssbInfo->pssCorrPeakPower, - ssbInfo->pssCorrAvgPower); - if (!res.syncRes.cell_detected) { // take the first cell detected - res = *ssbInfo; - } - } - for (int ant = 0; ant < fp->nb_antennas_rx; ant++) { - free(ssbInfo->rxdata[ant]); - } - free(ssbInfo->rxdata); + nr_ue_ssb_scan_t *res = NULL; + join_task_ans(&ans); + for (int i = 0; i < numGscn; i++) { + nr_ue_ssb_scan_t *ssbInfo = &ssb_info[i]; + if (ssbInfo->syncRes.cell_detected) { + LOG_I(NR_PHY, + "Cell Detected with GSCN: %d, SSB SC offset: %d, SSB Ref: %lf, PSS Corr peak: %d dB, PSS Corr Average: %d\n", + ssbInfo->gscnInfo.gscn, + ssbInfo->gscnInfo.ssbFirstSC, + ssbInfo->gscnInfo.ssRef, + ssbInfo->pssCorrPeakPower, + ssbInfo->pssCorrAvgPower); + // take the first cell detected + if (!res) + res = ssbInfo; } + for (int ant = 0; ant < fp->nb_antennas_rx; ant++) { + free(ssbInfo->rxdata[ant]); + } + free(ssbInfo->rxdata); + ssbInfo->rxdata = NULL; } // Set globals based on detected cell - if (res.syncRes.cell_detected) { - fp->Nid_cell = res.nidCell; - fp->ssb_start_subcarrier = res.gscnInfo.ssbFirstSC; - fp->half_frame_bit = res.halfFrameBit; - fp->ssb_index = res.ssbIndex; - ue->symbol_offset = res.symbolOffset; - ue->common_vars.freq_offset = res.freqOffset; - ue->adjust_rxgain = res.adjust_rxgain; + if (res) { + fp->Nid_cell = res->nidCell; + fp->ssb_start_subcarrier = res->gscnInfo.ssbFirstSC; + fp->half_frame_bit = res->halfFrameBit; + fp->ssb_index = res->ssbIndex; + ue->symbol_offset = res->symbolOffset; + ue->common_vars.freq_offset = res->freqOffset; + ue->adjust_rxgain = res->adjust_rxgain; } // In initial sync, we indicate PBCH to MAC after the scan is complete. @@ -389,7 +388,7 @@ nr_initial_sync_t nr_initial_sync(UE_nr_rxtx_proc_t *proc, NULL, number_pdus, proc, - res.syncRes.cell_detected ? (void *)&res.pbchResult : NULL, + res ? (void *)&res->pbchResult : NULL, NULL); if (ue->if_inst && ue->if_inst->dl_indication) @@ -398,73 +397,76 @@ nr_initial_sync_t nr_initial_sync(UE_nr_rxtx_proc_t *proc, LOG_D(PHY, "nr_initial sync ue RB_DL %d\n", fp->N_RB_DL); - if (res.syncRes.cell_detected) { + if (res) { // digital compensation of FFO for SSB symbols - if (res.freqOffset && ue->UE_fo_compensation) { + if (res->freqOffset && ue->UE_fo_compensation) { // In SA we need to perform frequency offset correction until the end of buffer because we need to decode SIB1 // and we do not know yet in which slot it goes. - compensate_freq_offset(ue->common_vars.rxdata, fp, res.freqOffset, res.syncRes.frame_id); + compensate_freq_offset(ue->common_vars.rxdata, fp, res->freqOffset, res->syncRes.frame_id); } // sync at symbol ue->symbol_offset // computing the offset wrt the beginning of the frame int mu = fp->numerology_index; // number of symbols with different prefix length // every 7*(1<symbolOffset / (7 * (1 << mu))) + 1; const int sync_pos_frame = n_symb_prefix0 * (fp->ofdm_symbol_size + fp->nb_prefix_samples0) - + (res.symbolOffset - n_symb_prefix0) * (fp->ofdm_symbol_size + fp->nb_prefix_samples); + + (res->symbolOffset - n_symb_prefix0) * (fp->ofdm_symbol_size + fp->nb_prefix_samples); // for a correct computation of frame number to sync with the one decoded at MIB we need to take into account in which of // the n_frames we got sync - ue->init_sync_frame = n_frames - 1 - res.syncRes.frame_id; + ue->init_sync_frame = n_frames - 1 - res->syncRes.frame_id; // we also need to take into account the shift by samples_per_frame in case the if is true - if (res.ssbOffset < sync_pos_frame) { - res.syncRes.rx_offset = fp->samples_per_frame - sync_pos_frame + res.ssbOffset; + if (res->ssbOffset < sync_pos_frame) { + res->syncRes.rx_offset = fp->samples_per_frame - sync_pos_frame + res->ssbOffset; ue->init_sync_frame += 1; } else - res.syncRes.rx_offset = res.ssbOffset - sync_pos_frame; + res->syncRes.rx_offset = res->ssbOffset - sync_pos_frame; } - if (res.syncRes.cell_detected) { - LOG_I(PHY, "[UE%d] In synch, rx_offset %d samples\n", ue->Mod_id, res.syncRes.rx_offset); - LOG_I(PHY, "[UE %d] Measured Carrier Frequency offset %d Hz\n", ue->Mod_id, res.freqOffset); - } else { + if (res) { + LOG_I(PHY, "[UE%d] In synch, rx_offset %d samples\n", ue->Mod_id, res->syncRes.rx_offset); + LOG_I(PHY, "[UE %d] Measured Carrier Frequency offset %d Hz\n", ue->Mod_id, res->freqOffset); + } else { #ifdef DEBUG_INITIAL_SYNC LOG_I(PHY,"[UE%d] Initial sync : PBCH not ok\n",ue->Mod_id); LOG_I(PHY, "[UE%d] Initial sync : Estimated PSS position %d, Nid2 %d\n", ue->Mod_id, sync_pos, ue->common_vars.nid2); LOG_I(PHY,"[UE%d] Initial sync : Estimated Nid_cell %d, Frame_type %d\n",ue->Mod_id, fp->Nid_cell,fp->frame_type); #endif - } + } // gain control - if (!res.syncRes.cell_detected) { // we are not synched, so we cannot use rssi measurement (which is based on channel estimates) - int rx_power = 0; + if (!res) { // we are not synched, so we cannot use rssi measurement (which is based on channel estimates) + int rx_power = 0; - // do a measurement on the best guess of the PSS - // for (aarx=0; aarxnb_antennas_rx; aarx++) - // rx_power += signal_energy(&ue->common_vars.rxdata[aarx][sync_pos2], - // frame_parms->ofdm_symbol_size+frame_parms->nb_prefix_samples); + // do a measurement on the best guess of the PSS + // for (aarx=0; aarxnb_antennas_rx; aarx++) + // rx_power += signal_energy(&ue->common_vars.rxdata[aarx][sync_pos2], + // frame_parms->ofdm_symbol_size+frame_parms->nb_prefix_samples); - /* - // do a measurement on the full frame - for (aarx=0; aarxnb_antennas_rx; aarx++) - rx_power += signal_energy(&ue->common_vars.rxdata[aarx][0], - frame_parms->samples_per_subframe*10); - */ + /* + // do a measurement on the full frame + for (aarx=0; aarxnb_antennas_rx; aarx++) + rx_power += signal_energy(&ue->common_vars.rxdata[aarx][0], + frame_parms->samples_per_subframe*10); + */ - // we might add a low-pass filter here later - ue->measurements.rx_power_avg[0] = rx_power / fp->nb_antennas_rx; + // we might add a low-pass filter here later + ue->measurements.rx_power_avg[0] = rx_power / fp->nb_antennas_rx; - ue->measurements.rx_power_avg_dB[0] = dB_fixed(ue->measurements.rx_power_avg[0]); + ue->measurements.rx_power_avg_dB[0] = dB_fixed(ue->measurements.rx_power_avg[0]); #ifdef DEBUG_INITIAL_SYNCH LOG_I(PHY, "[UE%d] Initial sync failed : Estimated power: %d dB\n", ue->Mod_id, ue->measurements.rx_power_avg_dB[0]); #endif - } else { - LOG_A(PHY, "Initial sync successful, PCI: %d\n",fp->Nid_cell); - } + } else { + LOG_A(PHY, "Initial sync successful, PCI: %d\n", fp->Nid_cell); + } // exit_fun("debug exit"); VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_NR_INITIAL_UE_SYNC, VCD_FUNCTION_OUT); - return res.syncRes; + if (res) + return res->syncRes; + else + return (nr_initial_sync_t){.cell_detected = false}; }