nr_ue_dci_configuration.c 22.7 KB
Newer Older
Raymond Knopp's avatar
Raymond Knopp committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */

/* \file nr_ue_dci_configuration.c
 * \brief functions for generating dci search procedures based on RRC Serving Cell Group Configuration
cig's avatar
cig committed
24
 * \author R. Knopp, G. Casati
Raymond Knopp's avatar
Raymond Knopp committed
25
 * \date 2020
cig's avatar
cig committed
26 27 28
 * \version 0.2
 * \company Eurecom, Fraunhofer IIS
 * \email: knopp@eurecom.fr, guido.casati@iis.fraunhofer.de
Raymond Knopp's avatar
Raymond Knopp committed
29 30 31 32 33 34 35 36 37
 * \note
 * \warning
 */

#include "mac_proto.h"
#include "mac_defs.h"
#include "assertions.h"
#include "LAYER2/NR_MAC_UE/mac_extern.h"
#include "mac_defs.h"
cig's avatar
cig committed
38
#include "common/utils/nr/nr_common.h"
cig's avatar
cig committed
39
#include "executables/softmodem-common.h"
Raymond Knopp's avatar
Raymond Knopp committed
40
#include <stdio.h>
41
#include "nfapi_nr_interface.h"
Raymond Knopp's avatar
Raymond Knopp committed
42

Sakthivel Velumani's avatar
Sakthivel Velumani committed
43
void fill_dci_search_candidates(const NR_SearchSpace_t *ss,
44
                                fapi_nr_dl_config_dci_dl_pdu_rel15_t *rel15,
Sakthivel Velumani's avatar
Sakthivel Velumani committed
45
                                const uint32_t Y)
46
{
Eurecom's avatar
Eurecom committed
47
  LOG_D(NR_MAC,"Filling search candidates for DCI\n");
48

49 50
  int i = 0;
  for (int maxL = 16; maxL > 0; maxL >>= 1) {
51
    uint8_t aggregation, max_number_of_candidates;
52
    find_aggregation_candidates(&aggregation,
53
                                &max_number_of_candidates,
54 55
                                ss,
                                maxL);
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
    if (max_number_of_candidates == 0)
      continue;
    LOG_D(NR_MAC,"L %d, max number of candidates %d, aggregation %d\n", maxL, max_number_of_candidates, aggregation);
    int N_cce_sym = 0; // nb of rbs of coreset per symbol
    for (int f = 0; f < 6; f++) {
      for (int t = 0; t < 8; t++) {
        N_cce_sym += ((rel15->coreset.frequency_domain_resource[f] >> t) & 1);
      }
    }
    int N_cces = N_cce_sym * rel15->coreset.duration;
    if (N_cces < aggregation)
      continue;
    for (int j = 0; j < max_number_of_candidates; j++) {
      int first_cce = aggregation * ((Y + ((j * N_cces) / (aggregation * max_number_of_candidates)) + 0) % (N_cces / aggregation));
      LOG_D(NR_MAC,"Candidate %d of %d first_cce %d (L %d N_cces %d Y %d)\n", j, max_number_of_candidates, first_cce, aggregation, N_cces, Y);
      // to avoid storing more than one candidate with the same aggregation and starting CCE (duplicated candidate)
      bool duplicated = false;
      for (int k = 0; k < i; k++) {
        if (rel15->CCE[k] == first_cce && rel15->L[k] == aggregation) {
          duplicated = true;
          LOG_D(NR_MAC, "Candidate %d of %d is duplicated\n", j, max_number_of_candidates);
77 78
        }
      }
79
      if (!duplicated) {
80
        rel15->CCE[i] = first_cce;
Eurecom's avatar
Eurecom committed
81
        rel15->L[i] = aggregation;
82
        i++;
Eurecom's avatar
Eurecom committed
83
      }
84
    }
85
  }
86
  rel15->number_of_candidates = i;
Raymond Knopp's avatar
Raymond Knopp committed
87 88
}

89
NR_ControlResourceSet_t *ue_get_coreset(const NR_BWP_PDCCH_t *config, const int coreset_id)
90
{
91
  if (config->commonControlResourceSet && coreset_id == config->commonControlResourceSet->controlResourceSetId)
92
    return config->commonControlResourceSet;
93
  NR_ControlResourceSet_t *coreset = NULL;
94 95 96
  for (int i = 0; i < config->list_Coreset.count; i++) {
    if (config->list_Coreset.array[i]->controlResourceSetId == coreset_id) {
      coreset = config->list_Coreset.array[i];
97 98 99 100 101 102 103 104
      break;
    }
  }
  AssertFatal(coreset, "Couldn't find coreset with id %d\n", coreset_id);
  return coreset;
}


105 106
void config_dci_pdu(NR_UE_MAC_INST_t *mac,
                    fapi_nr_dl_config_request_t *dl_config,
Sakthivel Velumani's avatar
Sakthivel Velumani committed
107 108 109
                    const int rnti_type,
                    const int slot,
                    const NR_SearchSpace_t *ss)
110
{
111 112
  const NR_UE_DL_BWP_t *current_DL_BWP = mac->current_DL_BWP;
  const NR_UE_UL_BWP_t *current_UL_BWP = mac->current_UL_BWP;
113
  NR_BWP_Id_t dl_bwp_id = current_DL_BWP ? current_DL_BWP->bwp_id : 0;
114
  NR_BWP_PDCCH_t *pdcch_config = &mac->config_BWP_PDCCH[dl_bwp_id];
115

116
  fapi_nr_dl_config_dci_dl_pdu_rel15_t *rel15 = &dl_config->dl_config_list[dl_config->number_pdus].dci_config_pdu.dci_config_rel15;
117

Sakthivel Velumani's avatar
Sakthivel Velumani committed
118
  const int coreset_id = *ss->controlResourceSetId;
119
  NR_ControlResourceSet_t *coreset;
120
  if(coreset_id > 0) {
121
    coreset = ue_get_coreset(pdcch_config, coreset_id);
122
    rel15->coreset.CoreSetType = NFAPI_NR_CSET_CONFIG_PDCCH_CONFIG;
123
  } else {
124
    coreset = mac->coreset0;
125
    rel15->coreset.CoreSetType = NFAPI_NR_CSET_CONFIG_MIB_SIB1;
126
  }
127 128

  rel15->coreset.duration = coreset->duration;
129

130 131
  for (int i = 0; i < 6; i++)
    rel15->coreset.frequency_domain_resource[i] = coreset->frequencyDomainResources.buf[i];
132 133
  rel15->coreset.CceRegMappingType = coreset->cce_REG_MappingType.present ==
    NR_ControlResourceSet__cce_REG_MappingType_PR_interleaved ? FAPI_NR_CCE_REG_MAPPING_TYPE_INTERLEAVED : FAPI_NR_CCE_REG_MAPPING_TYPE_NON_INTERLEAVED;
134 135 136 137
  if (rel15->coreset.CceRegMappingType == FAPI_NR_CCE_REG_MAPPING_TYPE_INTERLEAVED) {
    struct NR_ControlResourceSet__cce_REG_MappingType__interleaved *interleaved = coreset->cce_REG_MappingType.choice.interleaved;
    rel15->coreset.RegBundleSize = (interleaved->reg_BundleSize == NR_ControlResourceSet__cce_REG_MappingType__interleaved__reg_BundleSize_n6) ? 6 : (2 + interleaved->reg_BundleSize);
    rel15->coreset.InterleaverSize = (interleaved->interleaverSize == NR_ControlResourceSet__cce_REG_MappingType__interleaved__interleaverSize_n6) ? 6 : (2 + interleaved->interleaverSize);
138
    rel15->coreset.ShiftIndex = interleaved->shiftIndex != NULL ? *interleaved->shiftIndex : mac->physCellId;
139 140 141 142
  } else {
    rel15->coreset.RegBundleSize = 0;
    rel15->coreset.InterleaverSize = 0;
    rel15->coreset.ShiftIndex = 0;
cig's avatar
cig committed
143
  }
144

145 146 147
  rel15->coreset.precoder_granularity = coreset->precoderGranularity;

  // Scrambling RNTI
148
  rel15->coreset.scrambling_rnti = 0;
149 150
  if (coreset->pdcch_DMRS_ScramblingID) {
    rel15->coreset.pdcch_dmrs_scrambling_id = *coreset->pdcch_DMRS_ScramblingID;
151 152
    if (ss->searchSpaceType->present == NR_SearchSpace__searchSpaceType_PR_ue_Specific)
      rel15->coreset.scrambling_rnti = mac->crnti;
153
  } else {
154
    rel15->coreset.pdcch_dmrs_scrambling_id = mac->physCellId;
cig's avatar
cig committed
155
  }
156

157
  rel15->num_dci_options = (mac->ra.ra_state == WAIT_RAR || rnti_type == TYPE_SI_RNTI_) ? 1 : 2;
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176

  if (ss->searchSpaceType->present == NR_SearchSpace__searchSpaceType_PR_ue_Specific) {
    if (ss->searchSpaceType->choice.ue_Specific->dci_Formats ==
        NR_SearchSpace__searchSpaceType__ue_Specific__dci_Formats_formats0_0_And_1_0) {
      rel15->dci_format_options[0] = NR_DL_DCI_FORMAT_1_0;
      rel15->dci_format_options[1] = NR_UL_DCI_FORMAT_0_0;
    }
    else {
      rel15->dci_format_options[0] = NR_DL_DCI_FORMAT_1_1;
      rel15->dci_format_options[1] = NR_UL_DCI_FORMAT_0_1;
    }
  }
  else { // common
    AssertFatal(ss->searchSpaceType->choice.common->dci_Format0_0_AndFormat1_0,
                "Only supporting format 10 and 00 for common SS\n");
    rel15->dci_format_options[0] = NR_DL_DCI_FORMAT_1_0;
    rel15->dci_format_options[1] = NR_UL_DCI_FORMAT_0_0;
  }

177
  NR_UE_ServingCell_Info_t *sc_info = &mac->sc_info;
178
  // loop over RNTI type and configure resource allocation for DCI
179
  for (int i = 0; i < rel15->num_dci_options; i++) {
180
    rel15->ss_type_options[i] = ss->searchSpaceType->present;
181 182 183 184 185
    const int dci_format = rel15->dci_format_options[i];
    uint16_t alt_size = 0;
    if(current_DL_BWP) {
      // computing alternative size for padding
      dci_pdu_rel15_t temp_pdu;
186
      if(dci_format == NR_DL_DCI_FORMAT_1_0)
187 188 189 190 191 192 193 194 195 196 197 198
        alt_size = nr_dci_size(current_DL_BWP,
                               current_UL_BWP,
                               sc_info,
                               mac->pdsch_HARQ_ACK_Codebook,
                               &temp_pdu,
                               NR_UL_DCI_FORMAT_0_0,
                               rnti_type,
                               coreset,
                               dl_bwp_id,
                               ss->searchSpaceType->present,
                               mac->type0_PDCCH_CSS_config.num_rbs,
                               0);
199
      if(dci_format == NR_UL_DCI_FORMAT_0_0)
200 201 202 203 204 205 206 207 208 209 210 211
        alt_size = nr_dci_size(current_DL_BWP,
                               current_UL_BWP,
                               sc_info,
                               mac->pdsch_HARQ_ACK_Codebook,
                               &temp_pdu,
                               NR_DL_DCI_FORMAT_1_0,
                               rnti_type,
                               coreset,
                               dl_bwp_id,
                               ss->searchSpaceType->present,
                               mac->type0_PDCCH_CSS_config.num_rbs,
                               0);
212
    }
213

214 215
    rel15->dci_length_options[i] = nr_dci_size(current_DL_BWP,
                                               current_UL_BWP,
216
                                               sc_info,
217
                                               mac->pdsch_HARQ_ACK_Codebook,
218
                                               &mac->def_dci_pdu_rel15[dl_config->slot][dci_format],
219
                                               dci_format,
220
                                               rnti_type,
221 222 223 224 225
                                               coreset,
                                               dl_bwp_id,
                                               ss->searchSpaceType->present,
                                               mac->type0_PDCCH_CSS_config.num_rbs,
                                               alt_size);
226
  }
227

228 229
  rel15->BWPStart = coreset_id == 0 ? mac->type0_PDCCH_CSS_config.cset_start_rb : current_DL_BWP->BWPStart;
  rel15->BWPSize = coreset_id == 0 ? mac->type0_PDCCH_CSS_config.num_rbs : current_DL_BWP->BWPSize;
rmagueta's avatar
rmagueta committed
230

231 232
  uint16_t monitoringSymbolsWithinSlot = 0;
  int sps = 0;
233

234
  switch(rnti_type) {
235
    case TYPE_C_RNTI_:
236 237 238 239 240 241 242
      // we use DL BWP dedicated
      sps = current_DL_BWP->cyclicprefix ? 12 : 14;
      // for SPS=14 8 MSBs in positions 13 down to 6
      monitoringSymbolsWithinSlot = (ss->monitoringSymbolsWithinSlot->buf[0]<<(sps-8)) | (ss->monitoringSymbolsWithinSlot->buf[1]>>(16-sps));
      rel15->rnti = mac->crnti;
      rel15->SubcarrierSpacing = current_DL_BWP->scs;
      break;
243
    case TYPE_RA_RNTI_:
244 245 246 247 248 249
      // we use the initial DL BWP
      sps = current_DL_BWP->cyclicprefix == NULL ? 14 : 12;
      monitoringSymbolsWithinSlot = (ss->monitoringSymbolsWithinSlot->buf[0]<<(sps-8)) | (ss->monitoringSymbolsWithinSlot->buf[1]>>(16-sps));
      rel15->rnti = mac->ra.ra_rnti;
      rel15->SubcarrierSpacing = current_DL_BWP->scs;
      break;
250
    case TYPE_P_RNTI_:
251
      break;
252
    case TYPE_CS_RNTI_:
253
      break;
254
    case TYPE_TC_RNTI_:
255 256 257 258 259 260
      // we use the initial DL BWP
      sps = current_DL_BWP->cyclicprefix == NULL ? 14 : 12;
      monitoringSymbolsWithinSlot = (ss->monitoringSymbolsWithinSlot->buf[0]<<(sps-8)) | (ss->monitoringSymbolsWithinSlot->buf[1]>>(16-sps));
      rel15->rnti = mac->ra.t_crnti;
      rel15->SubcarrierSpacing = current_DL_BWP->scs;
      break;
261
    case TYPE_SP_CSI_RNTI_:
262
      break;
263
    case TYPE_SI_RNTI_:
264
      sps = 14;
265 266 267 268 269 270 271
      // for SPS=14 8 MSBs in positions 13 down to 6
      monitoringSymbolsWithinSlot = (ss->monitoringSymbolsWithinSlot->buf[0]<<(sps-8)) | (ss->monitoringSymbolsWithinSlot->buf[1]>>(16-sps));
      rel15->rnti = SI_RNTI; // SI-RNTI - 3GPP TS 38.321 Table 7.1-1: RNTI values
      rel15->SubcarrierSpacing = mac->mib->subCarrierSpacingCommon;
      if(mac->frequency_range == FR2)
        rel15->SubcarrierSpacing = mac->mib->subCarrierSpacingCommon + 2;
      break;
272
    case TYPE_SFI_RNTI_:
273
      break;
274
    case TYPE_INT_RNTI_:
275
      break;
276
    case TYPE_TPC_PUSCH_RNTI_:
277
      break;
278
    case TYPE_TPC_PUCCH_RNTI_:
279
      break;
280
    case TYPE_TPC_SRS_RNTI_:
281 282 283
      break;
    default:
      break;
cig's avatar
cig committed
284
  }
285

286 287 288 289
  for (int i = 0; i < sps; i++) {
    if ((monitoringSymbolsWithinSlot >> (sps - 1 - i)) & 1) {
      rel15->coreset.StartSymbolIndex = i;
      break;
Raymond Knopp's avatar
Raymond Knopp committed
290
    }
291
  }
292 293 294 295 296
  uint32_t Y = 0;
  if (ss->searchSpaceType->present == NR_SearchSpace__searchSpaceType_PR_ue_Specific)
    Y = get_Y(ss, slot, rel15->rnti);
  fill_dci_search_candidates(ss, rel15, Y);

297
  #ifdef DEBUG_DCI
298 299 300 301 302 303 304 305 306 307 308
    for (int i = 0; i < rel15->num_dci_options; i++) {
      LOG_D(MAC, "[DCI_CONFIG] Configure DCI PDU: rnti_type %d BWPSize %d BWPStart %d rel15->SubcarrierSpacing %d rel15->dci_format %d rel15->dci_length %d sps %d monitoringSymbolsWithinSlot %d \n",
            rnti_type,
            rel15->BWPSize,
            rel15->BWPStart,
            rel15->SubcarrierSpacing,
            rel15->dci_format_options[i],
            rel15->dci_length_options[i],
            sps,
            monitoringSymbolsWithinSlot);
    }
309 310 311
  #endif
  // add DCI
  dl_config->dl_config_list[dl_config->number_pdus].pdu_type = FAPI_NR_DL_CONFIG_TYPE_DCI;
cig's avatar
cig committed
312
  dl_config->number_pdus += 1;
313
}
cig's avatar
cig committed
314

315

Sakthivel Velumani's avatar
Sakthivel Velumani committed
316
void get_monitoring_period_offset(const NR_SearchSpace_t *ss, int *period, int *offset)
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
{
  switch(ss->monitoringSlotPeriodicityAndOffset->present) {
    case NR_SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl1:
      *period = 1;
      *offset = 0;
      break;
    case NR_SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl2:
      *period = 2;
      *offset = ss->monitoringSlotPeriodicityAndOffset->choice.sl2;
      break;
    case NR_SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl4:
      *period = 4;
      *offset = ss->monitoringSlotPeriodicityAndOffset->choice.sl4;
      break;
    case NR_SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl5:
      *period = 5;
      *offset = ss->monitoringSlotPeriodicityAndOffset->choice.sl5;
      break;
    case NR_SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl8:
      *period = 8;
      *offset = ss->monitoringSlotPeriodicityAndOffset->choice.sl8;
      break;
    case NR_SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl10:
      *period = 10;
      *offset = ss->monitoringSlotPeriodicityAndOffset->choice.sl10;
      break;
    case NR_SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl16:
      *period = 16;
      *offset = ss->monitoringSlotPeriodicityAndOffset->choice.sl16;
      break;
    case NR_SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl20:
      *period = 20;
      *offset = ss->monitoringSlotPeriodicityAndOffset->choice.sl20;
      break;
    case NR_SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl40:
      *period = 40;
      *offset = ss->monitoringSlotPeriodicityAndOffset->choice.sl40;
      break;
    case NR_SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl80:
      *period = 80;
      *offset = ss->monitoringSlotPeriodicityAndOffset->choice.sl80;
      break;
    case NR_SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl160:
      *period = 160;
      *offset = ss->monitoringSlotPeriodicityAndOffset->choice.sl160;
      break;
    case NR_SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl320:
      *period = 320;
      *offset = ss->monitoringSlotPeriodicityAndOffset->choice.sl320;
      break;
    case NR_SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl640:
      *period = 640;
      *offset = ss->monitoringSlotPeriodicityAndOffset->choice.sl640;
      break;
    case NR_SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl1280:
      *period = 1280;
      *offset = ss->monitoringSlotPeriodicityAndOffset->choice.sl1280;
      break;
    case NR_SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl2560:
      *period = 2560;
      *offset = ss->monitoringSlotPeriodicityAndOffset->choice.sl2560;
      break;
  default:
    AssertFatal(1==0,"Invalid monitoring slot periodicity value\n");
    break;
  }
}
384

Sakthivel Velumani's avatar
Sakthivel Velumani committed
385
bool is_ss_monitor_occasion(const int frame, const int slot, const int slots_per_frame, const NR_SearchSpace_t *ss)
386
{
Sakthivel Velumani's avatar
Sakthivel Velumani committed
387
  const int duration = ss->duration ? *ss->duration : 1;
388 389 390 391 392 393 394 395 396 397 398 399
  bool monitor = false;
  int period, offset;
  get_monitoring_period_offset(ss, &period, &offset);
  // The UE monitors PDCCH candidates for search space set ss for 'duration' consecutive slots
  for (int i = 0; i < duration; i++) {
    if (((frame * slots_per_frame + slot - offset - i) % period) == 0) {
      monitor = true;
      break;
    }
  }
  return monitor;
}
400

401 402 403 404 405
bool monitior_dci_for_other_SI(NR_UE_MAC_INST_t *mac,
                               const NR_SearchSpace_t *ss,
                               const int slots_per_frame,
                               const int frame,
                               const int slot)
francescomani's avatar
francescomani committed
406 407 408 409 410 411 412
{
  const struct NR_SI_SchedulingInfo *si_SchedulingInfo = mac->si_SchedulingInfo;
  // 5.2.2.3.2 in 331
  if (!si_SchedulingInfo)
    return false;
  const int si_window_slots = 5 << si_SchedulingInfo->si_WindowLength;
  const int abs_slot = frame * slots_per_frame + slot;
413
  const int bwp_id = mac->current_DL_BWP->bwp_id;
francescomani's avatar
francescomani committed
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
  for (int n = 0; n < si_SchedulingInfo->schedulingInfoList.list.count; n++) {
    struct NR_SchedulingInfo *sched_Info = si_SchedulingInfo->schedulingInfoList.list.array[n];
    if(mac->si_window_start == -1) {
      int x = n * si_window_slots;
      int T = 8 << sched_Info->si_Periodicity; // radio frame periodicity
      if ((frame % T) == (x / slots_per_frame) &&
          (x % slots_per_frame == 0))
        mac->si_window_start = abs_slot; // in terms of absolute slot number
    }
    if (mac->si_window_start == -1) {
      // out of window
      return false;
    }
    else if (abs_slot > mac->si_window_start + si_window_slots) {
      // window expired
      mac->si_window_start = -1;
      return false;
    }
    else {
      const int duration = ss->duration ? *ss->duration : 1;
      int period, offset;
      get_monitoring_period_offset(ss, &period, &offset);
      for (int i = 0; i < duration; i++) {
        if (((frame * slots_per_frame + slot - offset - i) % period) == 0) {
438
          int N = mac->ssb_list[bwp_id].nb_tx_ssb;
francescomani's avatar
francescomani committed
439 440
          int K = 0; // k_th transmitted SSB
          for (int i = 0; i < mac->mib_ssb; i++) {
441
            if(mac->ssb_list[bwp_id].tx_ssb[i].transmitted)
francescomani's avatar
francescomani committed
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
              K++;
          }
          // numbering current frame and slot in terms of monitoring occasions in window
          int current_monitor_occasion = ((abs_slot - mac->si_window_start) % period) +
                                         (duration * (abs_slot - mac->si_window_start) / period);
          if (current_monitor_occasion % N == K)
            return true;
          else
           return false;
        }
      }
    }
  }
  return false;
}


Sakthivel Velumani's avatar
Sakthivel Velumani committed
459
void ue_dci_configuration(NR_UE_MAC_INST_t *mac, fapi_nr_dl_config_request_t *dl_config, const frame_t frame, const int slot)
460
{
461 462 463 464
  const NR_UE_DL_BWP_t *current_DL_BWP = mac->current_DL_BWP;
  NR_BWP_Id_t dl_bwp_id = current_DL_BWP ? current_DL_BWP->bwp_id : 0;
  NR_BWP_PDCCH_t *pdcch_config = &mac->config_BWP_PDCCH[dl_bwp_id];
  int scs = current_DL_BWP ? current_DL_BWP->scs : get_softmodem_params()->numerology;
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485
  const int slots_per_frame = nr_slots_per_frame[scs];
  if (mac->get_sib1) {
    int ssb_sc_offset_norm;
    if (mac->ssb_subcarrier_offset < 24 && mac->frequency_range == FR1)
      ssb_sc_offset_norm = mac->ssb_subcarrier_offset >> scs;
    else
      ssb_sc_offset_norm = mac->ssb_subcarrier_offset;
    uint16_t ssb_offset_point_a = (mac->ssb_start_subcarrier - ssb_sc_offset_norm) / 12;
    int ssb_start_symbol = get_ssb_start_symbol(mac->nr_band, scs, mac->mib_ssb);
    get_type0_PDCCH_CSS_config_parameters(&mac->type0_PDCCH_CSS_config,
                                          mac->mib_frame,
                                          mac->mib,
                                          slots_per_frame,
                                          ssb_sc_offset_norm,
                                          ssb_start_symbol,
                                          scs,
                                          mac->frequency_range,
                                          mac->nr_band,
                                          mac->mib_ssb,
                                          1, // If the UE is not configured with a periodicity, the UE assumes a periodicity of a half frame
                                          ssb_offset_point_a);
486 487 488 489 490 491 492
    if (mac->search_space_zero == NULL)
      mac->search_space_zero = calloc(1, sizeof(*mac->search_space_zero));
    if (mac->coreset0 == NULL)
      mac->coreset0 = calloc(1, sizeof(*mac->coreset0));
    fill_coresetZero(mac->coreset0, &mac->type0_PDCCH_CSS_config);
    fill_searchSpaceZero(mac->search_space_zero, slots_per_frame, &mac->type0_PDCCH_CSS_config);
    if (is_ss_monitor_occasion(frame, slot, slots_per_frame, mac->search_space_zero)) {
493
      LOG_D(NR_MAC, "Monitoring DCI for SIB1 in frame %d slot %d\n", frame, slot);
494
      config_dci_pdu(mac, dl_config, TYPE_SI_RNTI_, slot, mac->search_space_zero);
495 496
    }
  }
497 498 499 500
  if (mac->get_otherSI) {
    // If searchSpaceOtherSystemInformation is set to zero,
    // PDCCH monitoring occasions for SI message reception in SI-window
    // are same as PDCCH monitoring occasions for SIB1
501
    const NR_SearchSpace_t *ss = pdcch_config->otherSI_SS ? pdcch_config->otherSI_SS : mac->search_space_zero;
502
    // TODO configure SI-window
503
    if (monitior_dci_for_other_SI(mac, ss, slots_per_frame, frame, slot)) {
francescomani's avatar
francescomani committed
504
      LOG_D(NR_MAC, "Monitoring DCI for other SIs in frame %d slot %d\n", frame, slot);
505
      config_dci_pdu(mac, dl_config, TYPE_SI_RNTI_, slot, ss);
francescomani's avatar
francescomani committed
506
    }
507
  }
508 509 510
  if (mac->state == UE_PERFORMING_RA &&
      mac->ra.ra_state >= WAIT_RAR) {
    // if RA is ongoing use RA search space
511
    if (is_ss_monitor_occasion(frame, slot, slots_per_frame, pdcch_config->ra_SS)) {
512
      int rnti_type = mac->ra.ra_state == WAIT_RAR ? TYPE_RA_RNTI_ : TYPE_TC_RNTI_;
513
      config_dci_pdu(mac, dl_config, rnti_type, slot, pdcch_config->ra_SS);
514
    }
Raymond Knopp's avatar
Raymond Knopp committed
515
  }
516
  else if (mac->state == UE_CONNECTED) {
517 518 519
    for (int i = 0; i < pdcch_config->list_SS.count; i++) {
      NR_SearchSpace_t *ss = pdcch_config->list_SS.array[i];
      if (is_ss_monitor_occasion(frame, slot, slots_per_frame, ss))
520
        config_dci_pdu(mac, dl_config, TYPE_C_RNTI_, slot, ss);
521
    }
522
    if (pdcch_config->list_SS.count == 0 && pdcch_config->ra_SS) {
523 524 525 526
      // If the UE has not been provided a Type3-PDCCH CSS set or a USS set and
      // the UE has received a C-RNTI and has been provided a Type1-PDCCH CSS set,
      // the UE monitors PDCCH candidates for DCI format 0_0 and DCI format 1_0
      // with CRC scrambled by the C-RNTI in the Type1-PDCCH CSS set
527
      if (is_ss_monitor_occasion(frame, slot, slots_per_frame, pdcch_config->ra_SS))
528
        config_dci_pdu(mac, dl_config, TYPE_C_RNTI_, slot, pdcch_config->ra_SS);
529
    }
530
  }
Raymond Knopp's avatar
Raymond Knopp committed
531
}