rrc_gNB_nsa.c 6.93 KB
Newer Older
knopp's avatar
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 24 25 26 27 28 29
/*
 * 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 rrc_gNB_nsa.c
 * \brief rrc NSA procedures for gNB
 * \author Raymond Knopp
 * \date 2019
 * \version 1.0
 * \company Eurecom
 * \email: raymond.knopp@eurecom.fr
 */
30
#ifndef RRC_GNB_NSA_C
knopp's avatar
knopp committed
31 32
#define RRC_GNB_NSA_C

33
#include "nr_rrc_defs.h"
knopp's avatar
knopp committed
34
#include "NR_RRCReconfiguration.h"
35
#include "NR_UE-NR-Capability.h"
36 37
//#include "NR_UE-CapabilityRAT-ContainerList.h"
#include "LTE_UE-CapabilityRAT-ContainerList.h"
knopp's avatar
knopp committed
38
#include "NR_CG-Config.h"
39

40
void rrc_parse_ue_capabilities(gNB_RRC_INST *rrc,LTE_UE_CapabilityRAT_ContainerList_t *UE_CapabilityRAT_ContainerList) {
41 42 43

  struct rrc_gNB_ue_context_s        *ue_context_p = NULL;
  int rnti = taus()&65535;
knopp's avatar
knopp committed
44 45
  OCTET_STRING_t *ueCapabilityRAT_Container_nr;
  OCTET_STRING_t *ueCapabilityRAT_Container_MRDC;
46
  int list_size;
knopp's avatar
knopp committed
47
  AssertFatal(UE_CapabilityRAT_ContainerList!=NULL,"UE_CapabilityRAT_ContainerList is null\n");
48 49 50 51 52
  AssertFatal((list_size=UE_CapabilityRAT_ContainerList->list.count) >= 2, "UE_CapabilityRAT_ContainerList->list.size %d < 2\n",UE_CapabilityRAT_ContainerList->list.count);
  for (int i=0;i<list_size;i++) {
    if (UE_CapabilityRAT_ContainerList->list.array[i]->rat_Type == LTE_RAT_Type_nr) ueCapabilityRAT_Container_nr = &UE_CapabilityRAT_ContainerList->list.array[i]->ueCapabilityRAT_Container;
    else if (UE_CapabilityRAT_ContainerList->list.array[i]->rat_Type == LTE_RAT_Type_eutra_nr) ueCapabilityRAT_Container_MRDC = &UE_CapabilityRAT_ContainerList->list.array[i]->ueCapabilityRAT_Container;
  }    
53 54 55 56

  AssertFatal(ueCapabilityRAT_Container_nr!=NULL,"ueCapabilityRAT_Container_nr is NULL\n");
  AssertFatal(ueCapabilityRAT_Container_MRDC!=NULL,"ueCapabilityRAT_Container_MRDC is NULL\n");
  // decode and store capabilities
knopp's avatar
knopp committed
57 58
  ue_context_p = rrc_gNB_allocate_new_UE_context(rrc);
  ue_context_p->ue_id_rnti = rnti;
59 60 61 62 63 64 65 66
  
  asn_dec_rval_t dec_rval = uper_decode(NULL,
					&asn_DEF_NR_UE_NR_Capability,
					(void **)&ue_context_p->ue_context.UE_Capability_nr,
					ueCapabilityRAT_Container_nr->buf,
					ueCapabilityRAT_Container_nr->size, 0, 0);

  if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0)) {
67
    LOG_E(RRC, "Failed to decode UE NR capabilities (%zu bytes) container size %d\n", dec_rval.consumed,ueCapabilityRAT_Container_nr->size);
68 69 70 71 72
      ASN_STRUCT_FREE(asn_DEF_NR_UE_NR_Capability,
                      ue_context_p->ue_context.UE_Capability_nr);
      ue_context_p->ue_context.UE_Capability_nr = 0;
      AssertFatal(1==0,"exiting\n");
  }
knopp's avatar
knopp committed
73

74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
  dec_rval = uper_decode(NULL,
			 &asn_DEF_NR_UE_MRDC_Capability,
			 (void **)&ue_context_p->ue_context.UE_Capability_MRDC,
			 ueCapabilityRAT_Container_MRDC->buf,
			 ueCapabilityRAT_Container_MRDC->size, 0, 0);

  if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0)) {
      LOG_E(RRC, "Failed to decode UE MRDC capabilities (%zu bytes)\n", dec_rval.consumed);
      ASN_STRUCT_FREE(asn_DEF_NR_UE_MRDC_Capability,
                      ue_context_p->ue_context.UE_Capability_MRDC);
      ue_context_p->ue_context.UE_Capability_MRDC = 0;
      AssertFatal(1==0,"exiting\n");
  }

  // dump ue_capabilities

90
//  if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
91
     xer_fprint(stdout, &asn_DEF_NR_UE_NR_Capability, ue_context_p->ue_context.UE_Capability_nr);
92
//  }  
93

94
//  if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
95
     xer_fprint(stdout, &asn_DEF_NR_UE_MRDC_Capability, ue_context_p->ue_context.UE_Capability_MRDC);
96
//  }  
knopp's avatar
knopp committed
97

knopp's avatar
knopp committed
98
  rrc_add_nsa_user(rrc,ue_context_p);
knopp's avatar
knopp committed
99 100
}

knopp's avatar
knopp committed
101
void rrc_add_nsa_user(gNB_RRC_INST *rrc,struct rrc_gNB_ue_context_s *ue_context_p) {
knopp's avatar
knopp committed
102 103 104

// generate nr-Config-r15 containers for LTE RRC : inside message for X2 EN-DC (CG-Config Message from 38.331)

105
  rrc_gNB_carrier_data_t *carrier=&rrc->carrier;
knopp's avatar
knopp committed
106

107 108 109
  MessageDef *msg;
  msg = itti_alloc_new_message(TASK_RRC_ENB, X2AP_ENDC_SGNB_ADDITION_REQ_ACK);

knopp's avatar
knopp committed
110 111
// NR RRCReconfiguration

112
  AssertFatal(rrc->Nb_ue < MAX_NR_RRC_UE_CONTEXTS,"cannot add another UE\n");
knopp's avatar
knopp committed
113

knopp's avatar
knopp committed
114 115 116 117 118
  ue_context_p->ue_context.reconfig = calloc(1,sizeof(NR_RRCReconfiguration_t));
  ue_context_p->ue_context.secondaryCellGroup = calloc(1,sizeof(NR_CellGroupConfig_t));
  memset((void*)ue_context_p->ue_context.reconfig,0,sizeof(NR_RRCReconfiguration_t));
  ue_context_p->ue_context.reconfig->rrc_TransactionIdentifier=0;
  ue_context_p->ue_context.reconfig->criticalExtensions.present = NR_RRCReconfiguration__criticalExtensions_PR_rrcReconfiguration;
knopp's avatar
knopp committed
119
  NR_RRCReconfiguration_IEs_t *reconfig_ies=calloc(1,sizeof(NR_RRCReconfiguration_IEs_t));
knopp's avatar
knopp committed
120
  ue_context_p->ue_context.reconfig->criticalExtensions.choice.rrcReconfiguration = reconfig_ies;
121 122
  carrier->initial_csi_index[rrc->Nb_ue] = 0;
  carrier->n_physical_antenna_ports = 1;
knopp's avatar
knopp committed
123
  fill_default_reconfig(carrier->servingcellconfigcommon,
knopp's avatar
knopp committed
124
			reconfig_ies,
knopp's avatar
knopp committed
125
			ue_context_p->ue_context.secondaryCellGroup,
knopp's avatar
knopp committed
126
			carrier->n_physical_antenna_ports,
127
			carrier->initial_csi_index[rrc->Nb_ue]);
knopp's avatar
knopp committed
128 129 130 131 132

  ue_context_p->ue_context.rb_config = calloc(1,sizeof(NR_RRCReconfiguration_t));

  fill_default_rbconfig(ue_context_p->ue_context.rb_config);

knopp's avatar
knopp committed
133 134
  NR_CG_Config_t *CG_Config = calloc(1,sizeof(*CG_Config));
  memset((void*)CG_Config,0,sizeof(*CG_Config));
135
  int CG_Config_size = generate_CG_Config(rrc,CG_Config,ue_context_p->ue_context.reconfig,ue_context_p->ue_context.rb_config);
136

137
  //X2AP_ENDC_SGNB_ADDITION_REQ_ACK(msg).rrc_buffer_size = CG_Config_size; //Need to verify correct value for the buffer_size
knopp's avatar
knopp committed
138
  // Send to X2 entity to transport to MeNB
139 140 141 142
  asn_enc_rval_t enc_rval = uper_encode_to_buffer(&asn_DEF_NR_CG_Config,
          	  	  	  	  	  	  	  	  	  	  NULL,
          	  	  	  	  	  	  	  	  	  	  (void *)CG_Config,
          	  	  	  	  	  	  	  	  	  	  X2AP_ENDC_SGNB_ADDITION_REQ_ACK(msg).rrc_buffer,
143 144 145
												  1024);

  X2AP_ENDC_SGNB_ADDITION_REQ_ACK(msg).rrc_buffer_size = (enc_rval.encoded+7)>>3;
146 147

  itti_send_msg_to_task(TASK_X2AP, ENB_MODULE_ID_TO_INSTANCE(0), msg); //Check right id instead of hardcoding
knopp's avatar
knopp committed
148

149
  rrc->Nb_ue++;
150 151 152 153 154 155 156
  // configure MAC and RLC
  rrc_mac_config_req_gNB(rrc->module_id,
			 rrc->carrier.ssb_SubcarrierOffset,
			 NULL,
			 1, // add_ue flag
			 ue_context_p->ue_id_rnti,
			 ue_context_p->ue_context.secondaryCellGroup);
knopp's avatar
knopp committed
157 158 159 160
}


#endif