nr_mac.h 20.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * 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_mac.h
cig's avatar
cig committed
23
 * \brief      common MAC data structures and constants
24 25 26
 * \author     R. Knopp, K.H. HSU, G. Casati
 * \date       2019
 * \version    0.1
27 28
 * \company    Eurecom / NTUST / Fraunhofer IIS
 * \email:     knopp@eurecom.fr, kai-hsiang.hsu@eurecom.fr, guido.casati@iis.fraunhofer.de
29 30 31 32 33 34 35 36 37 38
 * \note
 * \warning
 */

#ifndef __LAYER2_NR_MAC_H__
#define __LAYER2_NR_MAC_H__

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
39
#include <stdbool.h>
40 41
#include "common/utils/nr/nr_common.h"
#include "NR_CellGroupConfig.h"
42

43 44 45
#define NR_SHORT_BSR_TABLE_SIZE 32
#define NR_LONG_BSR_TABLE_SIZE 256

46 47 48 49 50 51 52 53 54 55 56 57 58
#define TABLE_38213_13_1_NUM_INDEXES 15
#define TABLE_38213_13_2_NUM_INDEXES 14
#define TABLE_38213_13_3_NUM_INDEXES 9
#define TABLE_38213_13_4_NUM_INDEXES 16
#define TABLE_38213_13_5_NUM_INDEXES 9
#define TABLE_38213_13_6_NUM_INDEXES 10
#define TABLE_38213_13_7_NUM_INDEXES 12
#define TABLE_38213_13_8_NUM_INDEXES 8
#define TABLE_38213_13_9_NUM_INDEXES 4
#define TABLE_38213_13_10_NUM_INDEXES 8
#define TABLE_38213_13_11_NUM_INDEXES 16
#define TABLE_38213_13_12_NUM_INDEXES 14

cig's avatar
cig committed
59
// Definitions for MAC control and data
60 61
#define NR_BCCH_DL_SCH 3 // SI
#define NR_BCCH_BCH 5    // MIB
62
#define CCCH_PAYLOAD_SIZE_MAX 512 
63
#define RAR_PAYLOAD_SIZE_MAX  128
64
#define MAX_CSI_REPORTCONFIG  48
cig's avatar
cig committed
65

mjoang's avatar
mjoang committed
66 67 68 69 70
#define NR_BSR_TRIGGER_NONE      (0) /* No BSR Trigger */
#define NR_BSR_TRIGGER_REGULAR   (1) /* For Regular and ReTxBSR Expiry Triggers */
#define NR_BSR_TRIGGER_PERIODIC  (2) /* For BSR Periodic Timer Expiry Trigger */
#define NR_BSR_TRIGGER_PADDING   (4) /* For Padding BSR Trigger */

71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
//  For both DL/UL-SCH
//  Except:
//   - UL/DL-SCH: fixed-size MAC CE(known by LCID)
//   - UL/DL-SCH: padding
//   - UL-SCH:    MSG3 48-bits
//  |0|1|2|3|4|5|6|7|  bit-wise
//  |R|F|   LCID    |
//  |       L       |
//  |0|1|2|3|4|5|6|7|  bit-wise
//  |R|F|   LCID    |
//  |       L       |
//  |       L       |

//  For both DL/UL-SCH
//  For:
//   - UL/DL-SCH: fixed-size MAC CE(known by LCID)
//   - UL/DL-SCH: padding, for single/multiple 1-oct padding CE(s)
//   - UL-SCH:    MSG3 48-bits
//  |0|1|2|3|4|5|6|7|  bit-wise
//  |R|R|   LCID    |
//  LCID: The Logical Channel ID field identifies the logical channel instance of the corresponding MAC SDU or the type of the corresponding MAC CE or padding as described in Tables 6.2.1-1 and 6.2.1-2 for the DL-SCH and UL-SCH respectively. There is one LCID field per MAC subheader. The LCID field size is 6 bits;
//  L: The Length field indicates the length of the corresponding MAC SDU or variable-sized MAC CE in bytes. There is one L field per MAC subheader except for subheaders corresponding to fixed-sized MAC CEs and padding. The size of the L field is indicated by the F field;
//  F: lenght of L is 0:8 or 1:16 bits wide
//  R: Reserved bit, set to zero.

typedef struct {
97 98 99 100
  uint8_t LCID: 6;    // octet 1 [5:0]
  uint8_t F: 1;       // octet 1 [6]
  uint8_t R: 1;       // octet 1 [7]
  uint8_t L: 8;       // octet 2 [7:0]
101 102 103
} __attribute__ ((__packed__)) NR_MAC_SUBHEADER_SHORT;

typedef struct {
Robert Schmidt's avatar
Robert Schmidt committed
104 105 106 107
  uint8_t LCID: 6;
  uint8_t F: 1;
  uint8_t R: 1;
  uint16_t L: 16;
108 109 110
} __attribute__ ((__packed__)) NR_MAC_SUBHEADER_LONG;

typedef struct {
111 112
  uint8_t LCID: 6;    // octet 1 [5:0]
  uint8_t R: 2;       // octet 1 [7:6]
113 114
} __attribute__ ((__packed__)) NR_MAC_SUBHEADER_FIXED;

Laurent THOMAS's avatar
Laurent THOMAS committed
115
static inline int get_mac_len(uint8_t* pdu, int pdu_len, uint16_t *mac_ce_len, uint16_t *mac_subheader_len) {
Thomas Schlichter's avatar
Thomas Schlichter committed
116
  if ( pdu_len < (int)sizeof(NR_MAC_SUBHEADER_SHORT))
Laurent THOMAS's avatar
Laurent THOMAS committed
117
    return false;
Robert Schmidt's avatar
Robert Schmidt committed
118 119
  NR_MAC_SUBHEADER_SHORT *s = (NR_MAC_SUBHEADER_SHORT*) pdu;
  NR_MAC_SUBHEADER_LONG *l = (NR_MAC_SUBHEADER_LONG*) pdu;
Thomas Schlichter's avatar
Thomas Schlichter committed
120
  if (s->F && pdu_len < (int)sizeof(NR_MAC_SUBHEADER_LONG))
Laurent THOMAS's avatar
Laurent THOMAS committed
121
    return false;
122
  if (s->F) {
Robert Schmidt's avatar
Robert Schmidt committed
123 124
    *mac_subheader_len = sizeof(*l);
    *mac_ce_len = ntohs(l->L);
125
  } else {
Robert Schmidt's avatar
Robert Schmidt committed
126 127
    *mac_subheader_len = sizeof(*s);
    *mac_ce_len = s->L;
128
  }
Laurent THOMAS's avatar
Laurent THOMAS committed
129
  return true;
130 131
}
    
cig's avatar
cig committed
132 133 134 135
// BSR MAC CEs
// TS 38.321 ch. 6.1.3.1
// Short BSR for a specific logical channel group ID
typedef struct {
136 137
  uint8_t Buffer_size: 5;  // octet 1 LSB
  uint8_t LcgID: 3;        // octet 1 MSB
cig's avatar
cig committed
138 139 140 141 142 143
} __attribute__ ((__packed__)) NR_BSR_SHORT;

typedef NR_BSR_SHORT NR_BSR_SHORT_TRUNCATED;

// Long BSR for all logical channel group ID
typedef struct {
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
  uint8_t LcgID0: 1;        // octet 1 [0]
  uint8_t LcgID1: 1;        // octet 1 [1]
  uint8_t LcgID2: 1;        // octet 1 [2]
  uint8_t LcgID3: 1;        // octet 1 [3]
  uint8_t LcgID4: 1;        // octet 1 [4]
  uint8_t LcgID5: 1;        // octet 1 [5]
  uint8_t LcgID6: 1;        // octet 1 [6]
  uint8_t LcgID7: 1;        // octet 1 [7]
  uint8_t Buffer_size0: 8;  // octet 2 [7:0]
  uint8_t Buffer_size1: 8;  // octet 3 [7:0]
  uint8_t Buffer_size2: 8;  // octet 4 [7:0]
  uint8_t Buffer_size3: 8;  // octet 5 [7:0]
  uint8_t Buffer_size4: 8;  // octet 6 [7:0]
  uint8_t Buffer_size5: 8;  // octet 7 [7:0]
  uint8_t Buffer_size6: 8;  // octet 8 [7:0]
  uint8_t Buffer_size7: 8;  // octet 9 [7:0]
cig's avatar
cig committed
160 161 162 163
} __attribute__ ((__packed__)) NR_BSR_LONG;

typedef NR_BSR_LONG NR_BSR_LONG_TRUNCATED;

164 165
// 38.321 ch. 6.1.3.4
typedef struct {
166 167
  uint8_t TA_COMMAND: 6;  // octet 1 [5:0]
  uint8_t TAGID: 2;       // octet 1 [7:6]
168 169
} __attribute__ ((__packed__)) NR_MAC_CE_TA;

cig's avatar
cig committed
170 171 172
// single Entry PHR MAC CE
// TS 38.321 ch. 6.1.3.8
typedef struct {
173 174 175 176
  uint8_t PH: 6;    // octet 1 [5:0]
  uint8_t R1: 2;    // octet 1 [7:6]
  uint8_t PCMAX: 6; // octet 2 [5:0]
  uint8_t R2: 2;    // octet 2 [7:6]
cig's avatar
cig committed
177 178
} __attribute__ ((__packed__)) NR_SINGLE_ENTRY_PHR_MAC_CE;

179 180 181 182

// SP ZP CSI-RS Resource Set Activation/Deactivation MAC CE
// 38.321 ch. 6.1.3.19
typedef struct {
183 184 185 186 187
  uint8_t BWPID: 2;       // octet 1 [1:0]
  uint8_t CELLID: 5;      // octet 1 [6:2]
  uint8_t A_D: 1;         // octet 1 [7]
  uint8_t CSIRS_RSC_ID: 4; // octet 2 [3:0]
  uint8_t R: 4;            // octet 2 [7:4]
188 189 190 191
} __attribute__ ((__packed__)) NR_MAC_CE_SP_ZP_CSI_RS_RES_SET;

//TS 38.321 Sec 6.1.3.15, TCI State indicaton for UE-Specific PDCCH MAC CE
typedef struct {
192 193 194 195
  uint8_t CoresetId1: 3;   //Octect 1 [2:0]
  uint8_t ServingCellId: 5; //Octect 1 [7:3]
  uint8_t TciStateId: 7;   //Octect 2 [6:0]
  uint8_t CoresetId2: 1;   //Octect 2 [7]
196 197 198 199
} __attribute__ ((__packed__)) NR_TCI_PDCCH;

//TS 38.321 Sec 6.1.3.14, TCI State activation/deactivation for UE Specific PDSCH MAC CE
typedef struct {
200 201 202 203
  uint8_t BWP_Id: 2;       //Octect 1 [1:0]
  uint8_t ServingCellId: 5; //Octect 1 [6:2]
  uint8_t R: 1;            //Octect 1 [7]
  uint8_t T[];             //Octects 2 to MAX TCI States/8
204 205 206 207
} __attribute__ ((__packed__)) NR_TCI_PDSCH_APERIODIC_CSI;

//TS 6.1.3.16, SP CSI reporting on PUCCH Activation/Deactivation MAC CE
typedef struct {
208 209 210 211 212 213 214 215
  uint8_t BWP_Id: 2;      //Octect 1 [1:0]
  uint8_t ServingCellId: 5; //Octect 1 [6:2]
  uint8_t R1: 1;        //Octect 1 [7]
  uint8_t S0: 1;        //Octect 2 [0]
  uint8_t S1: 1;        //Octect 2 [1]
  uint8_t S2: 1;        //Octect 2 [2]
  uint8_t S3: 1;        //Octect 2 [3]
  uint8_t R2: 4;        //Octect 2 [7:4]
216 217 218 219 220 221
} __attribute__ ((__packed__)) NR_PUCCH_CSI_REPORTING;


//TS 38.321 sec 6.1.3.12
//SP CSI-RS / CSI-IM Resource Set Activation/Deactivation MAC CE
typedef struct {
222 223 224 225 226 227 228 229 230 231 232 233
  uint8_t BWP_ID: 2;
  uint8_t SCID: 5;
  uint8_t A_D: 1;
  uint8_t SP_CSI_RSID: 6;
  uint8_t IM: 1;
  uint8_t R1: 1;
  uint8_t SP_CSI_IMID: 6;
  uint8_t R2: 2;
  struct TCI_S {
    uint8_t TCI_STATE_ID: 6;
    uint8_t R: 2;
  } __attribute__ ((__packed__)) TCI_STATE;
234 235 236
} __attribute__ ((__packed__)) CSI_RS_CSI_IM_ACT_DEACT_MAC_CE;


cig's avatar
cig committed
237 238 239 240 241 242 243 244
//* RAR MAC subheader // TS 38.321 ch. 6.1.5, 6.2.2 *//
// - E: The Extension field is a flag indicating if the MAC subPDU including this MAC subheader is the last MAC subPDU or not in the MAC PDU
// - T: The Type field is a flag indicating whether the MAC subheader contains a Random Access Preamble ID or a Backoff Indicator (0, BI) (1, RAPID)
// - R: Reserved bit, set to "0"
// - BI: The Backoff Indicator field identifies the overload condition in the cell.
// - RAPID: The Random Access Preamble IDentifier field identifies the transmitted Random Access Preamble

/*!\brief RAR MAC subheader with RAPID */
245
typedef struct {
246 247 248
  uint8_t RAPID: 6;
  uint8_t T: 1;
  uint8_t E: 1;
249 250
} __attribute__ ((__packed__)) NR_RA_HEADER_RAPID;

cig's avatar
cig committed
251
/*!\brief RAR MAC subheader with Backoff Indicator */
252
typedef struct {
253 254 255 256
  uint8_t BI: 4;
  uint8_t R: 2;
  uint8_t T: 1;
  uint8_t E: 1;
257 258
} __attribute__ ((__packed__)) NR_RA_HEADER_BI;

cig's avatar
cig committed
259 260
// TS 38.321 ch. 6.2.3
typedef struct {
261 262 263 264 265 266 267 268 269
  uint8_t TA1: 7;         // octet 1 [6:0]
  uint8_t R: 1;           // octet 1 [7]
  uint8_t UL_GRANT_1: 3;  // octet 2 [2:0]
  uint8_t TA2: 5;         // octet 2 [7:3]
  uint8_t UL_GRANT_2: 8;  // octet 3 [7:0]
  uint8_t UL_GRANT_3: 8;  // octet 4 [7:0]
  uint8_t UL_GRANT_4: 8;  // octet 5 [7:0]
  uint8_t TCRNTI_1: 8;    // octet 6 [7:0]
  uint8_t TCRNTI_2: 8;    // octet 7 [7:0]
cig's avatar
cig committed
270 271
} __attribute__ ((__packed__)) NR_MAC_RAR;

272
// DCI pdu structures. Used by both gNB and UE.
273
typedef struct {
274
  uint32_t val;
275 276 277
  uint8_t nbits;
} dci_field_t;

278 279 280 281 282
typedef struct {
  /* The active harq sfn/slot field was created to save the
     scheduled SFN/Slot transmission for the ACK/NAK. If we
     do not save it, then we have to calculate it again as the
     NRUE MAC layer already does in get_downlink_ack(). */
Melissa Elkadi's avatar
Melissa Elkadi committed
283 284 285
  int active_dl_harq_sfn;
  int active_dl_harq_slot;
  int active_ul_harq_sfn_slot;
286 287 288
  bool active;
} emul_l1_harq_t;

289 290
typedef struct {
  bool expected_sib;
Melissa Elkadi's avatar
Melissa Elkadi committed
291
  bool index_has_sib[NR_MAX_HARQ_PROCESSES];
292
  bool expected_rar;
Melissa Elkadi's avatar
Melissa Elkadi committed
293
  bool index_has_rar[NR_MAX_HARQ_PROCESSES];
294
  bool expected_dci;
Melissa Elkadi's avatar
Melissa Elkadi committed
295 296
  bool index_has_dci[NR_MAX_HARQ_PROCESSES];
  emul_l1_harq_t harq[NR_MAX_HARQ_PROCESSES];
297
  int active_uci_sfn_slot;
298 299 300
  int num_srs;
  int num_harqs;
  int num_csi_reports;
Melissa Elkadi's avatar
Melissa Elkadi committed
301 302 303
  uint8_t pmi;
  uint8_t ri;
  uint8_t cqi;
304 305
} nr_emulated_l1_t;

306 307
typedef struct {

308 309 310 311 312 313 314 315 316 317 318 319 320 321
  uint8_t     format_indicator; //1 bit
  uint8_t     ra_preamble_index; //6 bits
  uint8_t     ss_pbch_index; //6 bits
  uint8_t     prach_mask_index; //4 bits
  uint8_t     mcs; //5 bits
  uint8_t     ndi; //1 bit
  uint8_t     rv; //2 bits
  uint8_t     harq_pid; //4 bits
  uint8_t     tpc; //2 bits
  uint8_t     short_messages_indicator; //2 bits
  uint8_t     short_messages; //8 bits
  uint8_t     tb_scaling; //2 bits
  uint8_t     pucch_resource_indicator; //3 bits
  uint8_t     system_info_indicator; //1 bit
322
  uint8_t     ulsch_indicator;
323 324
  uint8_t     slot_format_indicator_count;
  uint8_t     *slot_format_indicators;
325
 
326 327
  uint8_t     pre_emption_indication_count;
  uint16_t    *pre_emption_indications; //14 bit each
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
  uint8_t     block_number_count;
  uint8_t     *block_numbers;
  uint8_t     padding;

  dci_field_t mcs2; //variable
  dci_field_t ndi2; //variable
  dci_field_t rv2; //variable
  dci_field_t frequency_domain_assignment; //variable
  dci_field_t time_domain_assignment; //variable
  dci_field_t frequency_hopping_flag; //variable
  dci_field_t vrb_to_prb_mapping; //variable
  dci_field_t dai[2]; //variable
  dci_field_t pdsch_to_harq_feedback_timing_indicator; //variable
  dci_field_t carrier_indicator; //variable
  dci_field_t bwp_indicator; //variable
  dci_field_t prb_bundling_size_indicator; //variable
  dci_field_t rate_matching_indicator; //variable
  dci_field_t zp_csi_rs_trigger; //variable
  dci_field_t transmission_configuration_indication; //variable
  dci_field_t srs_request; //variable
  dci_field_t cbgti; //variable
  dci_field_t cbgfi; //variable
  dci_field_t srs_resource_indicator; //variable
  dci_field_t precoding_information; //variable
  dci_field_t csi_request; //variable
  dci_field_t ptrs_dmrs_association; //variable
  dci_field_t beta_offset_indicator; //variable
  dci_field_t cloded_loop_indicator; //variable
  dci_field_t ul_sul_indicator; //variable
  dci_field_t antenna_ports; //variable
359
  dci_field_t dmrs_sequence_initialization;
360
  dci_field_t reserved; //1_0/C-RNTI:10 bits, 1_0/P-RNTI: 6 bits, 1_0/SI-&RA-RNTI: 16 bits
361 362 363

} dci_pdu_rel15_t;

364 365 366 367
//  38.321 ch6.2.1, 38.331
#define DL_SCH_LCID_CCCH                           0x00
#define DL_SCH_LCID_DCCH                           0x01
#define DL_SCH_LCID_DCCH1                          0x02
368
#define DL_SCH_LCID_DTCH                           0x04
369 370 371 372 373 374 375 376
#define DL_SCH_LCID_RECOMMENDED_BITRATE            0x2F
#define DL_SCH_LCID_SP_ZP_CSI_RS_RES_SET_ACT       0x30
#define DL_SCH_LCID_PUCCH_SPATIAL_RELATION_ACT     0x31
#define DL_SCH_LCID_SP_SRS_ACTIVATION              0x32
#define DL_SCH_LCID_SP_CSI_REP_PUCCH_ACT           0x33
#define DL_SCH_LCID_TCI_STATE_IND_UE_SPEC_PDCCH    0x34
#define DL_SCH_LCID_TCI_STATE_ACT_UE_SPEC_PDSCH    0x35
#define DL_SCH_LCID_APERIODIC_CSI_TRI_STATE_SUBSEL 0x36
377
#define DL_SCH_LCID_SP_CSI_RS_CSI_IM_RES_SET_ACT   0X37
378 379 380 381 382 383 384 385 386
#define DL_SCH_LCID_DUPLICATION_ACT                0X38
#define DL_SCH_LCID_SCell_ACT_4_OCT                0X39
#define DL_SCH_LCID_SCell_ACT_1_OCT                0X3A
#define DL_SCH_LCID_L_DRX                          0x3B
#define DL_SCH_LCID_DRX                            0x3C
#define DL_SCH_LCID_TA_COMMAND                     0x3D
#define DL_SCH_LCID_CON_RES_ID                     0x3E
#define DL_SCH_LCID_PADDING                        0x3F

387
#define UL_SCH_LCID_CCCH1                          0x00
388 389
#define UL_SCH_LCID_SRB1                           0x01
#define UL_SCH_LCID_SRB2                           0x02
390
#define UL_SCH_LCID_SRB3                           0x03
cig's avatar
cig committed
391
#define UL_SCH_LCID_DTCH                           0x04
392
#define UL_SCH_LCID_CCCH                           0x34
393 394 395 396 397 398 399 400 401 402 403 404
#define UL_SCH_LCID_RECOMMENDED_BITRATE_QUERY      0x35
#define UL_SCH_LCID_MULTI_ENTRY_PHR_4_OCT          0x36
#define UL_SCH_LCID_CONFIGURED_GRANT_CONFIRMATION  0x37
#define UL_SCH_LCID_MULTI_ENTRY_PHR_1_OCT          0x38
#define UL_SCH_LCID_SINGLE_ENTRY_PHR               0x39
#define UL_SCH_LCID_C_RNTI                         0x3A
#define UL_SCH_LCID_S_TRUNCATED_BSR                0x3B
#define UL_SCH_LCID_L_TRUNCATED_BSR                0x3C
#define UL_SCH_LCID_S_BSR                          0x3D
#define UL_SCH_LCID_L_BSR                          0x3E
#define UL_SCH_LCID_PADDING                        0x3F

405 406 407
#define NR_MAX_NUM_LCID                32
#define NR_MAX_NUM_LCGID              8
#define MAX_RLC_SDU_SUBHEADER_SIZE          3
408

cig's avatar
cig committed
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470
//===========
// PRACH defs
//===========

// ===============================================
// SSB to RO mapping public defines and structures
// ===============================================
#define MAX_SSB_PER_RO (16) // Maximum number of SSBs that can be mapped to a single RO
#define MAX_TDM (7) // Maximum nb of PRACH occasions TDMed in a slot
#define MAX_FDM (8) // Maximum nb of PRACH occasions FDMed in a slot

// PRACH occasion details
typedef struct prach_occasion_info {
  uint8_t start_symbol; // 0 - 13 (14 symbols in a slot)
  uint8_t fdm; // 0-7 (possible values of msg1-FDM: 1, 2, 4 or 8)
  uint8_t slot; // 0 - 159 (maximum number of slots in a 10ms frame - @ 240kHz)
  uint8_t frame; // 0 - 15 (maximum number of frames in a 160ms association pattern)
  uint8_t mapped_ssb_idx[MAX_SSB_PER_RO]; // List of mapped SSBs
  uint8_t nb_mapped_ssb;
  uint16_t format; // RO preamble format
} prach_occasion_info_t;

// PRACH occasion slot details
// A PRACH occasion slot is a series of PRACH occasions in time (symbols) and frequency
typedef struct prach_occasion_slot {
  prach_occasion_info_t prach_occasion[MAX_TDM][MAX_FDM]; // Starting symbol of each PRACH occasions in a slot
  uint8_t nb_of_prach_occasion_in_time;
  uint8_t nb_of_prach_occasion_in_freq;
} prach_occasion_slot_t;

//=========
// DCI defs
//=========

typedef enum {
  NR_DL_DCI_FORMAT_1_0 = 0,
  NR_DL_DCI_FORMAT_1_1,
  NR_DL_DCI_FORMAT_2_0,
  NR_DL_DCI_FORMAT_2_1,
  NR_DL_DCI_FORMAT_2_2,
  NR_DL_DCI_FORMAT_2_3,
  NR_UL_DCI_FORMAT_0_0,
  NR_UL_DCI_FORMAT_0_1
} nr_dci_format_t;

typedef enum {
  NR_RNTI_new = 0,
  NR_RNTI_C,
  NR_RNTI_RA,
  NR_RNTI_P,
  NR_RNTI_CS,
  NR_RNTI_TC,
  NR_RNTI_SP_CSI,
  NR_RNTI_SI,
  NR_RNTI_SFI,
  NR_RNTI_INT,
  NR_RNTI_TPC_PUSCH,
  NR_RNTI_TPC_PUCCH,
  NR_RNTI_TPC_SRS,
  NR_RNTI_MCS_C,
} nr_rnti_type_t;

471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503
typedef enum channel_bandwidth_e {
  bw_5MHz   = 0x1,
  bw_10MHz  = 0x2,
  bw_20MHz  = 0x4,
  bw_40MHz  = 0x8,
  bw_80MHz  = 0x16,
  bw_100MHz = 0x32
} channel_bandwidth_t;

typedef enum nr_ssb_and_cset_mux_pattern_type_e {
  NR_SSB_AND_CSET_MUX_PATTERN_TYPE1=1,
  NR_SSB_AND_CSET_MUX_PATTERN_TYPE2,
  NR_SSB_AND_CSET_MUX_PATTERN_TYPE3
} nr_ssb_and_cset_mux_pattern_type_t;

typedef enum {
  SFN_C_MOD_2_EQ_0,
  SFN_C_MOD_2_EQ_1,
  SFN_C_IMPOSSIBLE
} SFN_C_TYPE;

typedef struct Type0_PDCCH_CSS_config_s {
  int32_t num_rbs;
  int32_t num_symbols;
  int32_t rb_offset; // Offset from SSB RB0
  uint32_t type0_pdcch_ss_mux_pattern;
  uint16_t frame;
  SFN_C_TYPE sfn_c;
  uint32_t n_c;
  uint32_t n_0;
  uint32_t number_of_search_space_per_slot;
  uint32_t first_symbol_index;
  uint32_t search_space_duration;
504
  uint32_t search_space_frame_period;  // in slots
505 506 507
  uint32_t ssb_length;
  uint32_t ssb_index;
  uint32_t cset_start_rb;
508
  NR_SubcarrierSpacing_t scs_pdcch;
509
  bool active;
510
} NR_Type0_PDCCH_CSS_config_t;
511

512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538
typedef struct {
  uint8_t nb_ssbri_cri;
  uint8_t cri_ssbri_bitlen;
  uint8_t rsrp_bitlen;
  uint8_t diff_rsrp_bitlen;
} L1_RSRP_bitlen_t;

typedef struct{
  uint8_t ri_restriction;
  uint8_t cri_bitlen;
  uint8_t ri_bitlen;
  uint8_t li_bitlen[8];
  uint8_t pmi_x1_bitlen[8];
  uint8_t pmi_x2_bitlen[8];
  uint8_t cqi_bitlen[8];
} CSI_Meas_bitlen_t;

typedef struct nr_csi_report {
  NR_CSI_ReportConfig__reportQuantity_PR reportQuantity_type;
  long periodicity;
  uint16_t offset;
  long ** SSB_Index_list;
  long ** CSI_Index_list;
//  uint8_t nb_of_nzp_csi_report;
  uint8_t nb_of_csi_ssb_report;
  L1_RSRP_bitlen_t CSI_report_bitlen;
  CSI_Meas_bitlen_t csi_meas_bitlen;
Roberto Louro Magueta's avatar
Roberto Louro Magueta committed
539 540 541
  int codebook_mode;
  int N1;
  int N2;
542 543
} nr_csi_report_t;

544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563
typedef enum {
  NR_SRS_SRI_0 = 0,
  NR_SRS_SRI_1,
  NR_SRS_SRI_2,
  NR_SRS_SRI_3,
  NR_SRS_SRI_0_1,
  NR_SRS_SRI_0_2,
  NR_SRS_SRI_0_3,
  NR_SRS_SRI_1_2,
  NR_SRS_SRI_1_3,
  NR_SRS_SRI_2_3,
  NR_SRS_SRI_0_1_2,
  NR_SRS_SRI_0_1_3,
  NR_SRS_SRI_0_2_3,
  NR_SRS_SRI_1_2_3,
  NR_SRS_SRI_0_1_2_3
} nr_srs_sri_t;

typedef struct nr_srs_feedback {
  uint8_t sri;
564
  uint8_t ul_ri;
565 566 567
  uint8_t tpmi;
} nr_srs_feedback_t;

568 569 570 571 572 573 574 575 576
typedef struct NR_UE_DL_BWP {
  NR_BWP_Id_t bwp_id;
  int n_dl_bwp;
  int scs;
  long *cyclicprefix;
  uint16_t BWPSize;
  uint16_t BWPStart;
  uint16_t initial_BWPSize;
  uint16_t initial_BWPStart;
577
  NR_PDSCH_TimeDomainResourceAllocationList_t *tdaList_Common;
578 579
  NR_PDSCH_Config_t *pdsch_Config;
  NR_PDSCH_ServingCellConfig_t *pdsch_servingcellconfig;
580
  long *pdsch_HARQ_ACK_Codebook;
581 582 583 584 585 586 587 588 589 590 591 592 593
  uint8_t mcsTableIdx;
  nr_dci_format_t dci_format;
} NR_UE_DL_BWP_t;

typedef struct NR_UE_UL_BWP {
  NR_BWP_Id_t bwp_id;
  int n_ul_bwp;
  int scs;
  long *cyclicprefix;
  uint16_t BWPSize;
  uint16_t BWPStart;
  uint16_t initial_BWPSize;
  uint16_t initial_BWPStart;
594
  NR_RACH_ConfigCommon_t *rach_ConfigCommon;
595
  NR_PUSCH_ServingCellConfig_t *pusch_servingcellconfig;
596
  NR_PUSCH_TimeDomainResourceAllocationList_t *tdaList_Common;
597
  NR_ConfiguredGrantConfig_t *configuredGrantConfig;
598 599 600
  NR_PUSCH_Config_t *pusch_Config;
  NR_PUCCH_Config_t *pucch_Config;
  NR_PUCCH_ConfigCommon_t *pucch_ConfigCommon;
601
  long *harq_ACK_SpatialBundlingPUCCH;
602 603
  NR_CSI_MeasConfig_t *csi_MeasConfig;
  NR_SRS_Config_t *srs_Config;
604
  long *msg3_DeltaPreamble;
605 606 607 608 609 610
  uint8_t transform_precoding;
  uint8_t mcs_table;
  nr_dci_format_t dci_format;
  int max_fb_time;
} NR_UE_UL_BWP_t;

611 612 613 614 615 616 617 618 619 620
typedef enum {
  defaultA = 0,
  defaultB = 1,
  defaultC = 2
} default_table_type_t;

typedef enum {
  typeA = 0,
  typeB = 1
} mappingType_t;
621

622
typedef struct NR_tda_info {
623 624 625 626
  mappingType_t mapping_type;
  int startSymbolIndex;
  int nrOfSymbols;
  long k2;
627
} NR_tda_info_t;
628

629 630
#endif /*__LAYER2_MAC_H__ */