nr_rrc_defs.h 18.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/* 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
 */

yilmazt's avatar
yilmazt committed
21
/*! \file RRC/NR/nr_rrc_defs.h
22
* \brief NR RRC struct definitions and function prototypes
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
23
* \author Navid Nikaein, Raymond Knopp, WEI-TAI CHEN
24 25
* \date 2010 - 2014, 2018
* \version 1.0
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
26 27
* \company Eurecom, NTSUT
* \email: navid.nikaein@eurecom.fr, raymond.knopp@eurecom.fr, kroempa@gmail.com
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
*/

#ifndef __OPENAIR_RRC_DEFS_NR_H__
#define __OPENAIR_RRC_DEFS_NR_H__


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "collection/tree.h"
#include "nr_rrc_types.h"

#include "COMMON/platform_constants.h"
#include "COMMON/platform_types.h"
#include "RRC/LTE/rrc_defs.h"
//#include "LAYER2/RLC/rlc.h"

//#include "COMMON/mac_rrc_primitives.h"
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
47

48 49 50
#include "NR_SIB1.h"
#include "NR_RRCReconfigurationComplete.h"
#include "NR_RRCReconfiguration.h"
51
#include "NR_RRCReestablishmentRequest.h"
52
#include "NR_BCCH-BCH-Message.h"
53
#include "NR_BCCH-DL-SCH-Message.h"
54
#include "NR_BCCH-BCH-Message.h"
55 56
#include "NR_PLMN-IdentityInfo.h"
#include "NR_MCC-MNC-Digit.h"
57
#include "NR_NG-5G-S-TMSI.h"
58 59 60 61 62 63
//#include "MCCH-Message.h"
//#include "MBSFNAreaConfiguration-r9.h"
//#include "SCellToAddMod-r10.h"
//#include "AS-Config.h"
//#include "AS-Context.h"
#include "NR_UE-NR-Capability.h"
64
#include "NR_UE-MRDC-Capability.h"
65 66
#include "NR_MeasResults.h"
#include "NR_CellGroupConfig.h"
67
#include "NR_ServingCellConfigCommon.h"
68
#include "NR_EstablishmentCause.h"
69 70
//-------------------

71
#include "intertask_interface.h"
72 73 74 75 76

/* TODO: be sure this include is correct.
 * It solves a problem of compilation of the RRH GW,
 * issue #186.
 */
77
  #include "as_message.h"
78

79
  #include "commonDef.h"
80 81 82 83 84


/*I will change the name of the structure for compile purposes--> hope not to undo this process*/

typedef unsigned int uid_nr_t;
Raymond Knopp's avatar
Raymond Knopp committed
85
#define NR_UID_LINEAR_ALLOCATOR_BITMAP_SIZE (((MAX_MOBILES_PER_GNB/8)/sizeof(unsigned int)) + 1)
86

87
typedef struct nr_uid_linear_allocator_s {
88
  unsigned int   bitmap[NR_UID_LINEAR_ALLOCATOR_BITMAP_SIZE];
89
} nr_uid_allocator_t;
90 91 92
    

#define PROTOCOL_NR_RRC_CTXT_UE_FMT                PROTOCOL_CTXT_FMT
Xue Song's avatar
Xue Song committed
93
#define PROTOCOL_NR_RRC_CTXT_UE_ARGS(CTXT_Pp)      PROTOCOL_NR_CTXT_ARGS(CTXT_Pp)
94 95

#define PROTOCOL_NR_RRC_CTXT_FMT                   PROTOCOL_CTXT_FMT
Xue Song's avatar
Xue Song committed
96
#define PROTOCOL_NR_RRC_CTXT_ARGS(CTXT_Pp)         PROTOCOL_NR_CTXT_ARGS(CTXT_Pp)
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152


#define NR_UE_MODULE_INVALID ((module_id_t) ~0) // FIXME attention! depends on type uint8_t!!!
#define NR_UE_INDEX_INVALID  ((module_id_t) ~0) // FIXME attention! depends on type uint8_t!!! used to be -1

typedef enum {
  NR_RRC_OK=0,
  NR_RRC_ConnSetup_failed,
  NR_RRC_PHY_RESYNCH,
  NR_RRC_Handover_failed,
  NR_RRC_HO_STARTED
} NR_RRC_status_t;

typedef enum UE_STATE_NR_e {
  NR_RRC_INACTIVE=0,
  NR_RRC_IDLE,
  NR_RRC_SI_RECEIVED,
  NR_RRC_CONNECTED,
  NR_RRC_RECONFIGURED,
  NR_RRC_HO_EXECUTION
} NR_UE_STATE_t;


#define RRM_FREE(p)       if ( (p) != NULL) { free(p) ; p=NULL ; }
#define RRM_MALLOC(t,n)   (t *) malloc16( sizeof(t) * n )
#define RRM_CALLOC(t,n)   (t *) malloc16( sizeof(t) * n)
#define RRM_CALLOC2(t,s)  (t *) malloc16( s )

#define MAX_MEAS_OBJ                                  6
#define MAX_MEAS_CONFIG                               6
#define MAX_MEAS_ID                                   6

#define PAYLOAD_SIZE_MAX                              1024
#define RRC_BUF_SIZE                                  255
#define UNDEF_SECURITY_MODE                           0xff
#define NO_SECURITY_MODE                              0x20

/* TS 36.331: RRC-TransactionIdentifier ::= INTEGER (0..3) */
#define NR_RRC_TRANSACTION_IDENTIFIER_NUMBER             3

typedef struct {
  unsigned short                                      transport_block_size;      /*!< \brief Minimum PDU size in bytes provided by RLC to MAC layer interface */
  unsigned short                                      max_transport_blocks;      /*!< \brief Maximum PDU size in bytes provided by RLC to MAC layer interface */
  unsigned long                                       Guaranteed_bit_rate;       /*!< \brief Guaranteed Bit Rate (average) to be offered by MAC layer scheduling*/
  unsigned long                                       Max_bit_rate;              /*!< \brief Maximum Bit Rate that can be offered by MAC layer scheduling*/
  uint8_t                                             Delay_class;               /*!< \brief Delay class offered by MAC layer scheduling*/
  uint8_t                                             Target_bler;               /*!< \brief Target Average Transport Block Error rate*/
  uint8_t                                             Lchan_t;                   /*!< \brief Logical Channel Type (BCCH,CCCH,DCCH,DTCH_B,DTCH,MRBCH)*/
} __attribute__ ((__packed__))  NR_LCHAN_DESC;

typedef struct UE_RRC_INFO_NR_s {
  NR_UE_STATE_t                                       State;
  uint8_t                                             SIB1systemInfoValueTag;
  uint32_t                                            SIStatus;
  uint32_t                                            SIcnt;
  uint8_t                                             MCCHStatus[8];             // MAX_MBSFN_AREA
yaojie's avatar
yaojie committed
153
  uint16_t                                            SIwindowsize;              //!< Corresponds to the SIB1 si-WindowLength parameter. The unit is ms. Possible values are (final): 1,2,5,10,15,20,40
154 155
  uint8_t                                             handoverTarget;
  //HO_STATE_t ho_state;
156 157
  uint16_t
  SIperiod;                  //!< Corresponds to the SIB1 si-Periodicity parameter (multiplied by 10). Possible values are (final): 80,160,320,640,1280,2560,5120
158 159 160 161 162 163 164 165 166 167 168 169 170 171
  unsigned short                                      UE_index;
  uint32_t                                            T300_active;
  uint32_t                                            T300_cnt;
  uint32_t                                            T304_active;
  uint32_t                                            T304_cnt;
  uint32_t                                            T310_active;
  uint32_t                                            T310_cnt;
  uint32_t                                            N310_cnt;
  uint32_t                                            N311_cnt;
  rnti_t                                              rnti;
} __attribute__ ((__packed__)) NR_UE_RRC_INFO;

typedef struct UE_S_TMSI_NR_s {
  boolean_t                                           presence;
Xue Song's avatar
Xue Song committed
172 173 174
  uint16_t                                            amf_set_id;
  uint8_t                                             amf_pointer;
  uint32_t                                            fiveg_tmsi;
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
} __attribute__ ((__packed__)) NR_UE_S_TMSI;


typedef enum nr_e_rab_satus_e {
  NR_E_RAB_STATUS_NEW,
  NR_E_RAB_STATUS_DONE,           // from the gNB perspective
  NR_E_RAB_STATUS_ESTABLISHED,    // get the reconfigurationcomplete form UE
  NR_E_RAB_STATUS_FAILED,
} nr_e_rab_status_t;

typedef struct nr_e_rab_param_s {
  e_rab_t param;
  uint8_t status;
  uint8_t xid; // transaction_id
} __attribute__ ((__packed__)) nr_e_rab_param_t;


typedef struct HANDOVER_INFO_NR_s {
  uint8_t                                             ho_prepare;
  uint8_t                                             ho_complete;
  uint8_t                                             modid_s;            //module_idP of serving cell
  uint8_t                                             modid_t;            //module_idP of target cell
  uint8_t                                             ueid_s;             //UE index in serving cell
  uint8_t                                             ueid_t;             //UE index in target cell

  // NR not define at this moment
  //AS_Config_t                                       as_config;          /* these two parameters are taken from 36.331 section 10.2.2: HandoverPreparationInformation-r8-IEs */
  //AS_Context_t                                      as_context;         /* They are mandatory for HO */

  uint8_t                                             buf[RRC_BUF_SIZE];  /* ASN.1 encoded handoverCommandMessage */
  int                                                 size;               /* size of above message in bytes */
} NR_HANDOVER_INFO;


#define NR_RRC_HEADER_SIZE_MAX 64
#define NR_RRC_BUFFER_SIZE_MAX 1024

typedef struct {
  char                                                Payload[NR_RRC_BUFFER_SIZE_MAX];
  char                                                Header[NR_RRC_HEADER_SIZE_MAX];
  char                                                payload_size;
} NR_RRC_BUFFER;

#define NR_RRC_BUFFER_SIZE                            sizeof(RRC_BUFFER_NR)


typedef struct RB_INFO_NR_s {
  uint16_t                                            Rb_id;  //=Lchan_id
223
  NR_LCHAN_DESC Lchan_desc[2];
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
  //MAC_MEAS_REQ_ENTRY *Meas_entry; //may not needed for NB-IoT
} NR_RB_INFO;

typedef struct NR_SRB_INFO_s {
  uint16_t                                            Srb_id;         //=Lchan_id
  NR_RRC_BUFFER                                          Rx_buffer;
  NR_RRC_BUFFER                                          Tx_buffer;
  NR_LCHAN_DESC                                          Lchan_desc[2];
  unsigned int                                        Trans_id;
  uint8_t                                             Active;
} NR_SRB_INFO;


typedef struct RB_INFO_TABLE_ENTRY_NR_s {
  NR_RB_INFO                                          Rb_info;
  uint8_t                                             Active;
  uint32_t                                            Next_check_frame;
  uint8_t                                             Status;
} NR_RB_INFO_TABLE_ENTRY;

typedef struct SRB_INFO_TABLE_ENTRY_NR_s {
  NR_SRB_INFO                                         Srb_info;
  uint8_t                                             Active;
  uint8_t                                             Status;
  uint32_t                                            Next_check_frame;
} NR_SRB_INFO_TABLE_ENTRY;

Xue Song's avatar
Xue Song committed
251 252 253 254 255 256 257 258
typedef struct nr_rrc_guami_s {
  uint16_t mcc;
  uint16_t mnc;
  uint8_t  mnc_len;
  uint8_t  amf_region_id;
  uint16_t amf_set_id;
  uint8_t  amf_pointer;
} nr_rrc_guami_t;
259 260 261

typedef struct gNB_RRC_UE_s {
  uint8_t                            primaryCC_id;
yilmazt's avatar
yilmazt committed
262
  LTE_SCellToAddMod_r10_t            sCell_config[2];
263 264 265 266 267
  NR_SRB_ToAddModList_t             *SRB_configList;
  NR_SRB_ToAddModList_t             *SRB_configList2[RRC_TRANSACTION_IDENTIFIER_NUMBER];
  NR_DRB_ToAddModList_t             *DRB_configList;
  NR_DRB_ToAddModList_t             *DRB_configList2[RRC_TRANSACTION_IDENTIFIER_NUMBER];
  NR_DRB_ToReleaseList_t            *DRB_Release_configList2[RRC_TRANSACTION_IDENTIFIER_NUMBER];
268 269 270 271 272 273
  uint8_t                            DRB_active[8];

  SRB_INFO                           SI;
  SRB_INFO                           Srb0;
  SRB_INFO_TABLE_ENTRY               Srb1;
  SRB_INFO_TABLE_ENTRY               Srb2;
274 275 276
  NR_MeasConfig_t                   *measConfig;
  HANDOVER_INFO                     *handover_info;
  NR_MeasResults_t                  *measResults;
277 278


279
  NR_UE_NR_Capability_t*             UE_Capability_nr;
280
  int                                UE_Capability_size;
281
  NR_UE_MRDC_Capability_t*           UE_Capability_MRDC;
282
  int                                UE_MRDC_Capability_size;
283

Raymond Knopp's avatar
Raymond Knopp committed
284 285 286 287
  NR_CellGroupConfig_t               *secondaryCellGroup;
  NR_RRCReconfiguration_t            *reconfig;
  NR_RadioBearerConfig_t             *rb_config;

288 289
  ImsiMobileIdentity_t               imsi;

290 291 292
  /* KgNB as derived from KASME received from EPC */
  uint8_t kgnb[32];
  int8_t  kgnb_ncc;
293 294
  uint8_t nh[32];
  int8_t  nh_ncc;
Xue Song's avatar
Xue Song committed
295

296
  /* Used integrity/ciphering algorithms */
297 298
  NR_CipheringAlgorithm_t            ciphering_algorithm;
  e_NR_IntegrityProtAlgorithm        integrity_algorithm;
299 300 301 302 303

  uint8_t                            Status;
  rnti_t                             rnti;
  uint64_t                           random_ue_identity;

304
  /* Information from UE RRC Setup Request */
Xue Song's avatar
Xue Song committed
305 306 307
  NR_UE_S_TMSI                       Initialue_identity_5g_s_TMSI;
  uint64_t                           ng_5G_S_TMSI_Part1;
  uint16_t                           ng_5G_S_TMSI_Part2;
308
  NR_EstablishmentCause_t            establishment_cause;
309 310

  /* Information from UE RRC ConnectionReestablishmentRequest */
311
  NR_ReestablishmentCause_t             reestablishment_cause;
312 313 314 315 316 317

  /* UE id for initial connection to S1AP */
  uint16_t                           ue_initial_id;

  /* Information from S1AP initial_context_setup_req */
  uint32_t                           gNB_ue_s1ap_id :24;
318 319
  uint32_t                           gNB_ue_ngap_id;
  uint64_t                           amf_ue_ngap_id:40;
Xue Song's avatar
Xue Song committed
320
  nr_rrc_guami_t                     ue_guami;
321

322
  ngap_security_capabilities_t       security_capabilities;
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337

  /* Total number of e_rab already setup in the list */
  uint8_t                           setup_e_rabs;
  /* Number of e_rab to be setup in the list */
  uint8_t                            nb_of_e_rabs;
  /* Number of e_rab to be modified in the list */
  uint8_t                            nb_of_modify_e_rabs;
  uint8_t                            nb_of_failed_e_rabs;
  e_rab_param_t                      modify_e_rab[NB_RB_MAX];//[S1AP_MAX_E_RAB];
  /* list of e_rab to be setup by RRC layers */
  e_rab_param_t                      e_rab[NB_RB_MAX];//[S1AP_MAX_E_RAB];
  //release e_rabs
  uint8_t                            nb_release_of_e_rabs;
  e_rab_failed_t                     e_rabs_release_failed[S1AP_MAX_E_RAB];
  // LG: For GTPV1 TUNNELS
338 339 340
  uint32_t                           gnb_gtp_teid[S1AP_MAX_E_RAB];
  transport_layer_addr_t             gnb_gtp_addrs[S1AP_MAX_E_RAB];
  rb_id_t                            gnb_gtp_ebi[S1AP_MAX_E_RAB];
341

342 343 344 345 346 347 348 349 350 351
  uint32_t                           ul_failure_timer;
  uint32_t                           ue_release_timer;
  uint32_t                           ue_release_timer_thres;
  uint32_t                           ue_release_timer_s1;
  uint32_t                           ue_release_timer_thres_s1;
  uint32_t                           ue_release_timer_rrc;
  uint32_t                           ue_release_timer_thres_rrc;
  uint32_t                           ue_reestablishment_timer;
  uint32_t                           ue_reestablishment_timer_thres;
  uint8_t                            e_rab_release_command_flag;
352
  //------------------------------------------------------------------------------//
353 354 355 356 357 358 359 360
  NR_CellGroupId_t                                      cellGroupId;
  struct NR_SpCellConfig                                *spCellConfig;
  struct NR_CellGroupConfig__sCellToAddModList          *sCellconfig;
  struct NR_CellGroupConfig__sCellToReleaseList         *sCellconfigRelease;
  struct NR_CellGroupConfig__rlc_BearerToAddModList     *rlc_BearerBonfig;
  struct NR_CellGroupConfig__rlc_BearerToReleaseList    *rlc_BearerRelease;
  struct NR_MAC_CellGroupConfig                         *mac_CellGroupConfig;
  struct NR_PhysicalCellGroupConfig                     *physicalCellGroupConfig;
361

Xue Song's avatar
Xue Song committed
362 363 364 365
  /* Nas Pdu */
  uint8_t                        nas_pdu_flag;
  ngap_nas_pdu_t                 nas_pdu;

366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
} gNB_RRC_UE_t;

typedef uid_t ue_uid_t;

typedef struct rrc_gNB_ue_context_s {
  /* Tree related data */
  RB_ENTRY(rrc_gNB_ue_context_s) entries;

  /* Uniquely identifies the UE between MME and eNB within the eNB.
   * This id is encoded on 24bits.
   */
  rnti_t         ue_id_rnti;

  // another key for protocol layers but should not be used as a key for RB tree
  ue_uid_t       local_uid;

  /* UE id for initial connection to S1AP */
  struct gNB_RRC_UE_s   ue_context;
} rrc_gNB_ue_context_t;


387 388 389
typedef struct {

  // buffer that contains the encoded messages
390 391
  uint8_t                                   *MIB;
  uint8_t                                   sizeof_MIB;
392

393 394
  uint8_t                                   *SIB1;
  uint8_t                                   sizeof_SIB1;
395

396 397
  uint8_t                                   *ServingCellConfigCommon;
  uint8_t                                   sizeof_servingcellconfigcommon;
398 399

  NR_BCCH_BCH_Message_t                     mib;
400
  int ssb_SubcarrierOffset;                  
401
  int pdsch_AntennaPorts;
402
  int pusch_TargetSNRx10;
403
  int pucch_TargetSNRx10;
404
  NR_BCCH_DL_SCH_Message_t                  *siblock1;
405
  NR_ServingCellConfigCommon_t              *servingcellconfigcommon;
406
  NR_PDCCH_ConfigSIB1_t                     *pdcch_ConfigSIB1;
407
  NR_CellGroupConfig_t                      *secondaryCellGroup[MAX_NR_RRC_UE_CONTEXTS];
408 409
  NR_SRB_INFO                               SI;
  NR_SRB_INFO                               Srb0;
Raymond Knopp's avatar
Raymond Knopp committed
410 411
  int                                       initial_csi_index[MAX_NR_RRC_UE_CONTEXTS];

412 413 414 415 416 417 418 419
} rrc_gNB_carrier_data_t;
//---------------------------------------------------



//---NR---(completely change)---------------------
typedef struct gNB_RRC_INST_s {

420
  int                                                 module_id;
421
  eth_params_t                                        eth_params_s;
422
  rrc_gNB_carrier_data_t                              carrier;
423
  nr_uid_allocator_t                                     uid_allocator; // for rrc_ue_head
424
  RB_HEAD(rrc_nr_ue_tree_s, rrc_gNB_ue_context_s)     rrc_ue_head; // ue_context tree key search by rnti
425
  int                                                 Nb_ue;
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
  hash_table_t                                        *initial_id2_s1ap_ids; // key is    content is rrc_ue_s1ap_ids_t
  hash_table_t                                        *s1ap_id2_s1ap_ids   ; // key is    content is rrc_ue_s1ap_ids_t

  // other PLMN parameters
  /// Mobile country code
  int mcc;
  /// Mobile network code
  int mnc;
  /// number of mnc digits
  int mnc_digit_length;

  // other RAN parameters
  int srb1_timer_poll_retransmit;
  int srb1_poll_pdu;
  int srb1_poll_byte;
  int srb1_max_retx_threshold;
  int srb1_timer_reordering;
  int srb1_timer_status_prohibit;
  int srs_enable[MAX_NUM_CCs];

} gNB_RRC_INST;


#include "nr_rrc_proto.h" //should be put here otherwise compilation error

#endif
/** @} */