nr_rrc_defs.h 15.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
*/

#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"
39
#include "collection/linear_alloc.h"
40
#include "common/utils/ds/seq_arr.h"
41
#include "nr_rrc_common.h"
42
#include "ds/byte_array.h"
43

laurent's avatar
laurent committed
44
#include "common/platform_constants.h"
45
#include "common/platform_types.h"
46
#include "mac_rrc_dl.h"
47
#include "cucp_cuup_if.h"
48 49 50 51

#include "NR_SIB1.h"
#include "NR_RRCReconfigurationComplete.h"
#include "NR_RRCReconfiguration.h"
52
#include "NR_RRCReestablishmentRequest.h"
53
#include "NR_BCCH-BCH-Message.h"
54
#include "NR_BCCH-DL-SCH-Message.h"
55
#include "NR_BCCH-BCH-Message.h"
56 57
#include "NR_PLMN-IdentityInfo.h"
#include "NR_MCC-MNC-Digit.h"
58
#include "NR_NG-5G-S-TMSI.h"
francescomani's avatar
francescomani committed
59

60
#include "NR_UE-NR-Capability.h"
61
#include "NR_UE-MRDC-Capability.h"
62 63
#include "NR_MeasResults.h"
#include "NR_CellGroupConfig.h"
64
#include "NR_ServingCellConfigCommon.h"
65
#include "NR_EstablishmentCause.h"
66
#include "NR_MeasurementTimingConfiguration.h"
67

68 69
//-------------------

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

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

78
  #include "commonDef.h"
79 80

#define PROTOCOL_NR_RRC_CTXT_UE_FMT                PROTOCOL_CTXT_FMT
Xue Song's avatar
Xue Song committed
81
#define PROTOCOL_NR_RRC_CTXT_UE_ARGS(CTXT_Pp)      PROTOCOL_NR_CTXT_ARGS(CTXT_Pp)
82 83

#define PROTOCOL_NR_RRC_CTXT_FMT                   PROTOCOL_CTXT_FMT
Xue Song's avatar
Xue Song committed
84
#define PROTOCOL_NR_RRC_CTXT_ARGS(CTXT_Pp)         PROTOCOL_NR_CTXT_ARGS(CTXT_Pp)
85

86
// 3GPP TS 38.331 Section 12 Table 12.1-1: UE performance requirements for RRC procedures for UEs
87 88 89
#define NR_RRC_SETUP_DELAY_MS           10
#define NR_RRC_RECONFIGURATION_DELAY_MS 10
#define NR_RRC_BWP_SWITCHING_DELAY_MS   6
90

91 92 93 94 95 96
// 3GPP TS 38.133 - Section 8 - Table 8.2.1.2.7-2: Parameters which cause interruption other than SCS
// This table was recently added to 3GPP. It shows that changing the parameters locationAndBandwidth, nrofSRS-Ports or
// maxMIMO-Layers-r16 causes an interruption. This parameter is not yet being used in code, but has been placed here
// for future reference.
#define NR_OF_SRS_PORTS_SWITCHING_DELAY_MS 30

97 98
#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
99

100 101 102 103 104 105 106 107 108 109 110 111 112
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;

#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 )

113 114 115
#define MAX_MEAS_OBJ                                  7
#define MAX_MEAS_CONFIG                               7
#define MAX_MEAS_ID                                   7
116 117

#define PAYLOAD_SIZE_MAX                              1024
118
#define RRC_BUF_SIZE                                  1024
119 120 121 122
#define UNDEF_SECURITY_MODE                           0xff
#define NO_SECURITY_MODE                              0x20

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

typedef struct UE_S_TMSI_NR_s {
126
  bool                                                presence;
Xue Song's avatar
Xue Song committed
127 128 129
  uint16_t                                            amf_set_id;
  uint8_t                                             amf_pointer;
  uint32_t                                            fiveg_tmsi;
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
} __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_BUFFER_SIZE                            sizeof(RRC_BUFFER_NR)

Xue Song's avatar
Xue Song committed
165 166 167 168 169 170 171 172
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;
173

174
typedef enum pdu_session_satus_e {
Xue Song's avatar
Xue Song committed
175 176 177
  PDU_SESSION_STATUS_NEW,
  PDU_SESSION_STATUS_DONE,
  PDU_SESSION_STATUS_ESTABLISHED,
178
  PDU_SESSION_STATUS_REESTABLISHED, // after HO
179
  PDU_SESSION_STATUS_TOMODIFY, // ENDC NSA
Xue Song's avatar
Xue Song committed
180
  PDU_SESSION_STATUS_FAILED,
181 182
  PDU_SESSION_STATUS_TORELEASE, // to release DRB between eNB and UE
  PDU_SESSION_STATUS_RELEASED
183 184 185 186
} pdu_session_status_t;

typedef struct pdu_session_param_s {
  pdusession_t param;
187
  pdu_session_status_t status;
188
  uint8_t xid; // transaction_id
189
  ngap_Cause_t cause;
190
  uint8_t cause_value;
laurent's avatar
tmp  
laurent committed
191
} rrc_pdu_session_param_t;
192

193 194 195 196 197 198 199 200 201 202
/**
 * @brief F1-U tunnel configuration
*/
typedef struct f1u_tunnel_s {
  /* Downlink F1-U Tunnel Endpoint Identifier (CU-UP/DU) */
  uint32_t cuup_teid_f1u;
  /* DL F1-U Transport Layer */
  transport_layer_addr_t cuup_addr_f1u;
} f1u_tunnel_t;

203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
typedef struct drb_s {
  int status;
  int defaultDRBid;
  int drb_id;
  int reestablishPDCP;
  int recoverPDCP;
  int daps_Config_r16;
  struct cnAssociation_s {
    int present;
    int eps_BearerIdentity;
    struct sdap_config_s {
      bool defaultDRB;
      int pdusession_id;
      int sdap_HeaderDL;
      int sdap_HeaderUL;
      int mappedQoS_FlowsToAdd[QOSFLOW_MAX_VALUE];
    } sdap_config;
  } cnAssociation;
  struct pdcp_config_s {
    int discardTimer;
    int pdcp_SN_SizeUL;
    int pdcp_SN_SizeDL;
    int t_Reordering;
    int integrityProtection;
227
    struct headerCompression_s {
228 229 230 231 232 233 234
      int NotUsed;
      int present;
    } headerCompression;
    struct ext1_s {
      int cipheringDisabled;
    } ext1;
  } pdcp_config;
235 236
  // F1-U
  f1u_tunnel_t f1u_tunnel_config;
237 238
} drb_t;

239
typedef enum {
240
  RRC_ACTION_NONE, /* no transaction ongoing */
241 242 243 244 245 246 247
  RRC_SETUP,
  RRC_SETUP_FOR_REESTABLISHMENT,
  RRC_REESTABLISH,
  RRC_REESTABLISH_COMPLETE,
  RRC_DEDICATED_RECONF,
  RRC_PDUSESSION_ESTABLISH,
  RRC_PDUSESSION_MODIFY,
248 249
  RRC_PDUSESSION_RELEASE,
  RRC_UECAPABILITY_ENQUIRY,
250 251
} rrc_action_t;

252
typedef struct gNB_RRC_UE_s {
253 254
  time_t last_seen; // last time this UE has been accessed

255
  drb_t                              established_drbs[MAX_DRBS_PER_UE];
256
  NR_DRB_ToReleaseList_t            *DRB_ReleaseList;
257

258
  NR_SRB_INFO_TABLE_ENTRY Srb[NR_NUM_SRB];
259
  NR_MeasConfig_t                   *measConfig;
260
  NR_HANDOVER_INFO                  *handover_info;
261
  NR_MeasResults_t                  *measResults;
262

263
  bool as_security_active;
264
  bool f1_ue_context_active;
265

266
  byte_array_t ue_cap_buffer;
267
  NR_UE_NR_Capability_t*             UE_Capability_nr;
268
  int                                UE_Capability_size;
269
  NR_UE_MRDC_Capability_t*           UE_Capability_MRDC;
270
  int                                UE_MRDC_Capability_size;
271

272
  NR_CellGroupConfig_t               *masterCellGroup;
Raymond Knopp's avatar
Raymond Knopp committed
273 274
  NR_RadioBearerConfig_t             *rb_config;

275 276
  ImsiMobileIdentity_t               imsi;

277 278 279
  /* KgNB as derived from KASME received from EPC */
  uint8_t kgnb[32];
  int8_t  kgnb_ncc;
280 281
  uint8_t nh[32];
  int8_t  nh_ncc;
Xue Song's avatar
Xue Song committed
282

283
  /* Used integrity/ciphering algorithms */
284 285
  NR_CipheringAlgorithm_t            ciphering_algorithm;
  e_NR_IntegrityProtAlgorithm        integrity_algorithm;
286 287 288 289

  rnti_t                             rnti;
  uint64_t                           random_ue_identity;

290
  /* Information from UE RRC Setup Request */
Xue Song's avatar
Xue Song committed
291 292
  NR_UE_S_TMSI                       Initialue_identity_5g_s_TMSI;
  uint64_t                           ng_5G_S_TMSI_Part1;
293
  NR_EstablishmentCause_t            establishment_cause;
294

295
  uint32_t                           rrc_ue_id;
296
  uint64_t amf_ue_ngap_id;
Xue Song's avatar
Xue Song committed
297
  nr_rrc_guami_t                     ue_guami;
298

299
  ngap_security_capabilities_t       security_capabilities;
300 301
  //NSA block
  /* Number of NSA e_rab */
302
  int                                nb_of_e_rabs;
303
  /* list of pdu session to be setup by RRC layers */
304
  nr_e_rab_param_t                   e_rab[NB_RB_MAX];//[S1AP_MAX_E_RAB];
305 306 307 308
  uint32_t                           nsa_gtp_teid[S1AP_MAX_E_RAB];
  transport_layer_addr_t             nsa_gtp_addrs[S1AP_MAX_E_RAB];
  rb_id_t                            nsa_gtp_ebi[S1AP_MAX_E_RAB];
  rb_id_t                            nsa_gtp_psi[S1AP_MAX_E_RAB];
309

310 311 312 313 314 315
  //SA block
  int nb_of_pdusessions;
  rrc_pdu_session_param_t pduSession[NGAP_MAX_PDU_SESSION];
  rrc_action_t xids[NR_RRC_TRANSACTION_IDENTIFIER_NUMBER];
  uint8_t e_rab_release_command_flag;
  uint32_t ue_rrc_inactivity_timer;
316
  uint32_t                           ue_reestablishment_counter;
317
  uint32_t                           ue_reconfiguration_counter;
318

319 320 321 322 323
  /* NGUEContextSetup might come with PDU sessions, but setup needs to be
   * delayed after security (and capability); PDU sessions are stored here */
  int n_initial_pdu;
  pdusession_t *initial_pdus;

Xue Song's avatar
Xue Song committed
324
  /* Nas Pdu */
laurent's avatar
tmp  
laurent committed
325
  ngap_pdu_t nas_pdu;
Xue Song's avatar
Xue Song committed
326

327 328 329 330 331
} gNB_RRC_UE_t;

typedef struct rrc_gNB_ue_context_s {
  /* Tree related data */
  RB_ENTRY(rrc_gNB_ue_context_s) entries;
332
  /* UE id for initial connection to NGAP */
333 334 335
  struct gNB_RRC_UE_s   ue_context;
} rrc_gNB_ue_context_t;

336 337
typedef struct {

338
  uint8_t                                   *SIB23;
339
  int                                       sizeof_SIB23;
340

341 342 343 344
} rrc_gNB_carrier_data_t;
//---------------------------------------------------


345 346 347 348 349 350 351 352
typedef struct {
  /* nea0 = 0, nea1 = 1, ... */
  int ciphering_algorithms[4];
  int ciphering_algorithms_count;

  /* nia0 = 0, nia1 = 1, ... */
  int integrity_algorithms[4];
  int integrity_algorithms_count;
353 354 355 356

  /* flags to enable/disable ciphering and integrity for DRBs */
  int do_drb_ciphering;
  int do_drb_integrity;
357
} nr_security_configuration_t;
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 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
typedef struct {
  long maxReportCells;
  bool includeBeamMeasurements;
} nr_per_event_t;

typedef struct {
  long threshold_RSRP;
  long timeToTrigger;
} nr_a2_event_t;

typedef struct {
  int cell_id;
  long a3_offset;
  long hysteresis;
  long timeToTrigger;
} nr_a3_event_t;

typedef struct {
  nr_per_event_t *per_event;
  nr_a2_event_t *a2_event;
  seq_arr_t *a3_event_list;
  bool is_default_a3_configuration_exists;
} nr_measurement_configuration_t;

typedef struct {
  uint32_t gNB_ID;
  uint64_t nrcell_id;
  int physicalCellId;
  int absoluteFrequencySSB;
  int subcarrierSpacing;
  plmn_identity_t plmn;
  uint32_t tac;
  bool isIntraFrequencyNeighbour;
} nr_neighbour_gnb_configuration_t;

typedef struct neighbour_cell_configuration_s {
  int nr_cell_id;
  seq_arr_t *neighbour_cells;
} neighbour_cell_configuration_t;

399
typedef struct nr_mac_rrc_dl_if_s {
Xin Zhe Khooi's avatar
Xin Zhe Khooi committed
400 401
  f1_reset_cu_initiated_func_t f1_reset;
  f1_reset_acknowledge_du_initiated_func_t f1_reset_acknowledge;
402 403
  f1_setup_response_func_t f1_setup_response;
  f1_setup_failure_func_t f1_setup_failure;
404
  gnb_du_configuration_update_ack_func_t gnb_du_configuration_update_acknowledge;
405
  ue_context_setup_request_func_t ue_context_setup_request;
406
  ue_context_modification_request_func_t ue_context_modification_request;
407 408
  ue_context_modification_confirm_func_t ue_context_modification_confirm;
  ue_context_modification_refuse_func_t ue_context_modification_refuse;
409
  ue_context_release_command_func_t ue_context_release_command;
410 411 412
  dl_rrc_message_transfer_func_t dl_rrc_message_transfer;
} nr_mac_rrc_dl_if_t;

413 414 415
typedef struct cucp_cuup_if_s {
  cucp_cuup_bearer_context_setup_func_t bearer_context_setup;
  cucp_cuup_bearer_context_setup_func_t bearer_context_mod;
416
  cucp_cuup_bearer_context_release_func_t bearer_context_release;
417 418
} cucp_cuup_if_t;

419
typedef struct nr_rrc_du_container_t {
Robert Schmidt's avatar
Robert Schmidt committed
420 421 422
  /* Tree-related data */
  RB_ENTRY(nr_rrc_du_container_t) entries;

423
  sctp_assoc_t assoc_id;
424
  f1ap_setup_req_t *setup_req;
Robert Schmidt's avatar
Robert Schmidt committed
425
  NR_MIB_t *mib;
Robert Schmidt's avatar
Robert Schmidt committed
426
  NR_SIB1_t *sib1;
427
  NR_MeasurementTimingConfiguration_t *mtc;
428 429
} nr_rrc_du_container_t;

430
typedef struct nr_rrc_cuup_container_t {
431 432 433
  /* Tree-related data */
  RB_ENTRY(nr_rrc_cuup_container_t) entries;

434
  e1ap_setup_req_t *setup_req;
435
  sctp_assoc_t assoc_id;
436 437
} nr_rrc_cuup_container_t;

438 439 440
//---NR---(completely change)---------------------
typedef struct gNB_RRC_INST_s {

Xue Song's avatar
Xue Song committed
441 442 443
  ngran_node_t                                        node_type;
  uint32_t                                            node_id;
  char                                               *node_name;
444
  int                                                 module_id;
445
  eth_params_t                                        eth_params_s;
446
  rrc_gNB_carrier_data_t                              carrier;
447
  uid_allocator_t                                     uid_allocator;
448
  RB_HEAD(rrc_nr_ue_tree_s, rrc_gNB_ue_context_s) rrc_ue_head; // ue_context tree key search by rnti
Xue Song's avatar
Xue Song committed
449 450 451
  /// NR cell id
  uint64_t nr_cellid;

Xue Song's avatar
Xue Song committed
452 453 454
  // RRC configuration
  gNB_RrcConfigurationReq configuration;

455 456 457
  // gNB N3 GTPU instance
  instance_t e1_inst;

458 459
  char *uecap_file;

460 461
  // security configuration (preferred algorithms)
  nr_security_configuration_t security;
462 463

  nr_mac_rrc_dl_if_t mac_rrc;
464
  cucp_cuup_if_t cucp_cuup;
465 466
  seq_arr_t *neighbour_cell_configuration;
  nr_measurement_configuration_t measurementConfiguration;
467

Robert Schmidt's avatar
Robert Schmidt committed
468 469 470
  RB_HEAD(rrc_du_tree, nr_rrc_du_container_t) dus; // DUs, indexed by assoc_id
  size_t num_dus;

471 472
  RB_HEAD(rrc_cuup_tree, nr_rrc_cuup_container_t) cuups; // CU-UPs, indexed by assoc_id
  size_t num_cuups;
473

474 475 476 477 478
} gNB_RRC_INST;

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

#endif