rrc_eNB.c 380 KB
Newer Older
1 2 3 4 5
/*
 * 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
6
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
7 8 9 10 11 12 13 14 15 16 17 18 19 20
 * 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
 */
21 22 23

/*! \file rrc_eNB.c
 * \brief rrc procedures for eNB
24
 * \author Navid Nikaein and  Raymond Knopp
25
 * \date 2011 - 2014
26 27
 * \version 1.0
 * \company Eurecom
28
 * \email: navid.nikaein@eurecom.fr and raymond.knopp@eurecom.fr
29
 */
Lionel Gauthier's avatar
Lionel Gauthier committed
30 31
#define RRC_ENB
#define RRC_ENB_C
32 33 34
#include <asn_application.h>
#include <asn_internal.h> /* for _ASN_DEFAULT_STACK_MAX */
#include <per_encoder.h>
35 36
#include "rrc_defs.h"
#include "rrc_extern.h"
37
#include "assertions.h"
38
#include "common/ran_context.h"
39
#include "asn1_conversions.h"
40
#include "asn_internal.h"
41 42
#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"
#include "LAYER2/RLC/rlc.h"
43
#include "LAYER2/MAC/mac_proto.h"
44
#include "common/utils/LOG/log.h"
45
#include "COMMON/mac_rrc_primitives.h"
46
#include "RRC/LTE/MESSAGES/asn1_msg.h"
47
#include "RRCConnectionRequest.h"
48 49
#include "RRCConnectionReestablishmentRequest.h"
//#include "ReestablishmentCause.h"
50
#include "BCCH-BCH-Message.h"
51 52 53 54 55
#include "UL-CCCH-Message.h"
#include "DL-CCCH-Message.h"
#include "UL-DCCH-Message.h"
#include "DL-DCCH-Message.h"
#include "TDD-Config.h"
56
#include "HandoverCommand.h"
57
#include "rlc.h"
58 59 60
#include "rrc_eNB_UE_context.h"
#include "platform_types.h"
#include "msc.h"
61 62 63
#include "SL-CommConfig-r12.h"
#include "PeriodicBSR-Timer-r12.h"
#include "RetxBSR-Timer-r12.h"
64
#include "common/utils/LOG/vcd_signal_dumper.h"
65

66 67
#include "T.h"

68
//#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
69
#include "MeasResults.h"
70 71
//#endif

72 73 74 75
#include "RRC/NAS/nas_config.h"
#include "RRC/NAS/rb_config.h"
#include "OCG.h"
#include "OCG_extern.h"
76

77
#if defined(ENABLE_SECURITY)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
78
#   include "UTIL/OSA/osa_defs.h"
79 80
#endif

81
#if defined(ENABLE_USE_MME)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
82
#   include "rrc_eNB_S1AP.h"
83
#   include "rrc_eNB_GTPV1U.h"
Lionel Gauthier's avatar
 
Lionel Gauthier committed
84 85 86 87
#   if defined(ENABLE_ITTI)
#   else
#      include "../../S1AP/s1ap_eNB.h"
#   endif
frtabu's avatar
frtabu committed
88 89
#else
# define EPC_MODE_ENABLED 0
90 91
#endif

92
#include "pdcp.h"
93
#include "gtpv1u_eNB_task.h"
94 95

#if defined(ENABLE_ITTI)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
96
#   include "intertask_interface.h"
97 98
#endif

99
#if ENABLE_RAL
Lionel Gauthier's avatar
 
Lionel Gauthier committed
100
#   include "rrc_eNB_ral.h"
Lionel Gauthier's avatar
Lionel Gauthier committed
101 102
#endif

103
#include "SIMULATION/TOOLS/sim.h" // for taus
104

105

106 107
extern RAN_CONTEXT_t RC;

108
#ifdef PHY_EMUL
Lionel Gauthier's avatar
 
Lionel Gauthier committed
109
extern EMULATION_VARS              *Emul_vars;
110
#endif
Lionel Gauthier's avatar
 
Lionel Gauthier committed
111 112
extern eNB_MAC_INST                *eNB_mac_inst;
extern UE_MAC_INST                 *UE_mac_inst;
113
#ifdef BIGPHYSAREA
114
extern void*                        bigphys_malloc(int);
115 116
#endif

Lionel Gauthier's avatar
 
Lionel Gauthier committed
117
extern uint16_t                     two_tier_hexagonal_cellIds[7];
winckel's avatar
RRC:  
winckel committed
118

Lionel Gauthier's avatar
 
Lionel Gauthier committed
119
mui_t                               rrc_eNB_mui = 0;
winckel's avatar
RRC:  
winckel committed
120

121 122 123 124 125 126 127 128 129 130 131 132 133
void
openair_rrc_on(
  const protocol_ctxt_t* const ctxt_pP
)
//-----------------------------------------------------------------------------
{
  int            CC_id;

    LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" ENB:OPENAIR RRC IN....\n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
    for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
      rrc_config_buffer (&RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SI, BCCH, 1);
      RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SI.Active = 1;
134 135
      //      rrc_config_buffer (&RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0, CCCH, 1);
      //      RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Active = 1;
136 137 138
    }
}

139 140 141
//-----------------------------------------------------------------------------
static void
init_SI(
142 143
  const protocol_ctxt_t* const ctxt_pP,
  const int              CC_id
winckel's avatar
winckel committed
144
#if defined(ENABLE_ITTI)
145 146
  ,
  RrcConfigurationReq * configuration
winckel's avatar
winckel committed
147
#endif
148
)
149
//-----------------------------------------------------------------------------
150
{
151
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
152 153
  int                                 i;
#endif
154

155
#if (RRC_VERSION >= MAKE_VERSION(13, 1, 0))
156 157 158
  SystemInformationBlockType1_v1310_IEs_t *sib1_v13ext=(SystemInformationBlockType1_v1310_IEs_t *)NULL;
#endif

Cedric Roux's avatar
Cedric Roux committed
159
  LOG_D(RRC,"%s()\n\n\n\n",__FUNCTION__);
160 161
  eNB_RRC_INST *rrc = RC.rrc[ctxt_pP->module_id];
  rrc_eNB_carrier_data_t *carrier=&rrc->carrier[CC_id];
162

163 164 165 166 167 168 169 170
  carrier->MIB = (uint8_t*) malloc16(4);
  carrier->sizeof_SIB1 = 0;
  carrier->sizeof_SIB23 = 0;
  carrier->SIB1 = (uint8_t*) malloc16(32);
  
  AssertFatal(carrier->SIB1!=NULL,PROTOCOL_RRC_CTXT_FMT" init_SI: FATAL, no memory for SIB1 allocated\n",
	      PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));

171
  LOG_I(RRC,"[eNB %d] Node type %d \n ", ctxt_pP->module_id, rrc->node_type);
172 173
  if ((rrc->node_type == ngran_eNB_DU)    || 
      (rrc->node_type == ngran_eNB)       ) {
174 175 176 177 178 179
    // copy basic Cell parameters
    carrier->physCellId      = configuration->Nid_cell[CC_id];
    carrier->p_eNB           = configuration->nb_antenna_ports[CC_id];
    carrier->Ncp             = configuration->prefix_type[CC_id];
    carrier->dl_CarrierFreq  = configuration->downlink_frequency[CC_id];
    carrier->ul_CarrierFreq  = configuration->downlink_frequency[CC_id]+ configuration->uplink_frequency_offset[CC_id];
180
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
181
    carrier->pbch_repetition = configuration->pbch_repetition[CC_id];
182
#endif
183 184 185 186 187

    LOG_I(RRC, "Configuring MIB (N_RB_DL %d,phich_Resource %d,phich_Duration %d)\n", 
	  (int)configuration->N_RB_DL[CC_id],
	  (int)configuration->phich_resource[CC_id],
	  (int)configuration->phich_duration[CC_id]);
188

189
    carrier->sizeof_MIB= do_MIB(&rrc->carrier[CC_id],
190
#ifdef ENABLE_ITTI
191 192 193
	   configuration->N_RB_DL[CC_id],
	   configuration->phich_resource[CC_id],
	   configuration->phich_duration[CC_id]
194
#else
195
	   50,0,0
196
#endif
197 198 199 200
	   ,0);
    
    
    carrier->sizeof_SIB1 = do_SIB1(&rrc->carrier[CC_id],ctxt_pP->module_id,CC_id
winckel's avatar
winckel committed
201
#if defined(ENABLE_ITTI)
202
				   , configuration
winckel's avatar
winckel committed
203
#endif
204 205 206
				   );
    
    AssertFatal(carrier->sizeof_SIB1 != 255,"FATAL, RC.rrc[enb_mod_idP].carrier[CC_id].sizeof_SIB1 == 255");
207

208
  }
209 210 211
  if (rrc->node_type != ngran_eNB_DU) { 

  	/*if ((rrc->node_type == ngran_eNB_CU)  || 
212
      (rrc->node_type == ngran_ng_eNB_CU) ||
213
      (rrc->node_type == ngran_eNB)) { */ 
214 215 216 217 218 219
    carrier->SIB23 = (uint8_t*) malloc16(64);
    AssertFatal(carrier->SIB23!=NULL,"cannot allocate memory for SIB");
    carrier->sizeof_SIB23 = do_SIB23(
				     ctxt_pP->module_id,
				     
				     CC_id
220
#if defined(ENABLE_ITTI)
221
				     , configuration
Lionel Gauthier's avatar
 
Lionel Gauthier committed
222
#endif
223 224
				     );
    
225 226
    LOG_I(RRC,"do_SIB23, size %d \n ", carrier->sizeof_SIB23);
    
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
    AssertFatal(carrier->sizeof_SIB23 != 255,"FATAL, RC.rrc[mod].carrier[CC_id].sizeof_SIB23 == 255");
    
    
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" SIB2/3 Contents (partial)\n",
	  PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.n_SB = %ld\n",
	  PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
	  carrier->sib2->radioResourceConfigCommon.pusch_ConfigCommon.
	  pusch_ConfigBasic.n_SB);
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.hoppingMode = %ld\n",
	  PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
	  carrier->sib2->radioResourceConfigCommon.pusch_ConfigCommon.
	  pusch_ConfigBasic.hoppingMode);
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.pusch_HoppingOffset = %ld\n",
	  PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
	  carrier->sib2->radioResourceConfigCommon.pusch_ConfigCommon.
	  pusch_ConfigBasic.pusch_HoppingOffset);
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.enable64QAM = %d\n",
	  PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
	  (int)carrier->sib2->radioResourceConfigCommon.pusch_ConfigCommon.
	  pusch_ConfigBasic.enable64QAM);
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.groupHoppingEnabled = %d\n",
	  PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
	  (int)carrier->sib2->radioResourceConfigCommon.pusch_ConfigCommon.
	  ul_ReferenceSignalsPUSCH.groupHoppingEnabled);
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.groupAssignmentPUSCH = %ld\n",
	  PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
	  carrier->sib2->radioResourceConfigCommon.pusch_ConfigCommon.
	  ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH);
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.sequenceHoppingEnabled = %d\n",
	  PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
	  (int)carrier->sib2->radioResourceConfigCommon.pusch_ConfigCommon.
	  ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled);
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.cyclicShift  = %ld\n",
	  PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
	  carrier->sib2->radioResourceConfigCommon.pusch_ConfigCommon.
	  ul_ReferenceSignalsPUSCH.cyclicShift);
    
265
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
    
    if (carrier->MBMS_flag > 0) {
      for (i = 0; i < carrier->sib2->mbsfn_SubframeConfigList->list.count; i++) {
	// SIB 2
	//   LOG_D(RRC, "[eNB %d] mbsfn_SubframeConfigList.list.count = %ld\n", enb_mod_idP, RC.rrc[enb_mod_idP].sib2->mbsfn_SubframeConfigList->list.count);
	LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" SIB13 contents for MBSFN subframe allocation %d/%d(partial)\n",
	      PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
	      i,
	      carrier->sib2->mbsfn_SubframeConfigList->list.count);
	LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" mbsfn_Subframe_pattern is  = %x\n",
	      PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
	      carrier->sib2->mbsfn_SubframeConfigList->list.array[i]->subframeAllocation.choice.oneFrame.buf[0] >> 0);
	LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" radioframe_allocation_period  = %ld (just index number, not the real value)\n",
	      PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
	      carrier->sib2->mbsfn_SubframeConfigList->list.array[i]->radioframeAllocationPeriod);   // need to display the real value, using array of char (like in dumping SIB2)
	LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" radioframe_allocation_offset  = %ld\n",
	      PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
	      carrier->sib2->mbsfn_SubframeConfigList->list.array[i]->radioframeAllocationOffset);
      }
      
#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
      //   SIB13
      for (i = 0; i < carrier->sib13->mbsfn_AreaInfoList_r9.list.count; i++) {
	LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" SIB13 contents for MBSFN sync area %d/%d (partial)\n",
	      PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
	      i,
	      carrier->sib13->mbsfn_AreaInfoList_r9.list.count);
	LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" MCCH Repetition Period: %ld (just index number, not real value)\n",
	      PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
	      carrier->sib13->mbsfn_AreaInfoList_r9.list.array[i]->mcch_Config_r9.mcch_RepetitionPeriod_r9);
	LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" MCCH Offset: %ld\n",
	      PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
	      carrier->sib13->mbsfn_AreaInfoList_r9.list.array[i]->mcch_Config_r9.mcch_Offset_r9);
      }
#endif
    }
    else memset((void*)&carrier->sib13,0,sizeof(carrier->sib13));
    
    //TTN - SIB 18
    for (int j = 0; j < carrier->sib18->commConfig_r12->commRxPool_r12.list.count; j++) {
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Contents of SIB18 %d/%d \n",
	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
	    j+1,
	    carrier->sib18->commConfig_r12->commRxPool_r12.list.count);
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 rxPool_sc_CP_Len: %ld \n",
	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
	    carrier->sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_CP_Len_r12);
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 sc_Period_r12: %ld \n",
	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
	    carrier->sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_Period_r12);
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 data_CP_Len_r12: %ld \n",
317
	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
318 319
	    carrier->sib18->commConfig_r12->commRxPool_r12.list.array[j]->data_CP_Len_r12);
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 prb_Num_r12: %ld \n",
320
	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
321 322
	    carrier->sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_TF_ResourceConfig_r12.prb_Num_r12);
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 prb_Start_r12: %ld \n",
323
	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
324 325
	    carrier->sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_TF_ResourceConfig_r12.prb_Start_r12);
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 prb_End_r12: %ld \n",
326
	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
327 328 329 330 331 332 333 334
	    carrier->sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_TF_ResourceConfig_r12.prb_End_r12);
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 offsetIndicator: %ld \n",
	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
	    carrier->sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_TF_ResourceConfig_r12.offsetIndicator_r12.choice.small_r12);
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 subframeBitmap_choice_bs_buf: %s \n",
	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
	    carrier->sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs16_r12.buf);
      
335
    }
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
    
    //TTN - SIB 19
    for (int j = 0; j < carrier->sib19->discConfig_r12->discRxPool_r12.list.count; j++) {
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Contents of SIB19 %d/%d \n",
	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
	    j+1,
	    carrier->sib19->discConfig_r12->discRxPool_r12.list.count);
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 cp_Len_r12: %ld \n",
	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
	    carrier->sib19->discConfig_r12->discRxPool_r12.list.array[j]->cp_Len_r12);
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 discPeriod_r12: %ld \n",
	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
	    carrier->sib19->discConfig_r12->discRxPool_r12.list.array[j]->discPeriod_r12);
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 numRetx_r12: %ld \n",
	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
	    carrier->sib19->discConfig_r12->discRxPool_r12.list.array[j]->numRetx_r12);
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 numRepetition_r12: %ld \n",
	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
	    carrier->sib19->discConfig_r12->discRxPool_r12.list.array[j]->numRepetition_r12);
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 tf_ResourceConfig_r12 prb_Num_r12: %ld \n",
356
	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
357 358
	    carrier->sib19->discConfig_r12->discRxPool_r12.list.array[j]->tf_ResourceConfig_r12.prb_Num_r12);
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 tf_ResourceConfig_r12 prb_Start_r12: %ld \n",
359
	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
360 361
	    carrier->sib19->discConfig_r12->discRxPool_r12.list.array[j]->tf_ResourceConfig_r12.prb_Start_r12);
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 tf_ResourceConfig_r12 prb_End_r12: %ld \n",
362
	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
363 364 365 366 367 368 369 370
	    carrier->sib19->discConfig_r12->discRxPool_r12.list.array[j]->tf_ResourceConfig_r12.prb_End_r12);
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 tf_ResourceConfig_r12 offsetIndicator: %ld \n",
	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
	    carrier->sib19->discConfig_r12->discRxPool_r12.list.array[j]->tf_ResourceConfig_r12.offsetIndicator_r12.choice.small_r12);
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 tf_ResourceConfig_r12 subframeBitmap_choice_bs_buf: %s \n",
	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
	    carrier->sib19->discConfig_r12->discRxPool_r12.list.array[j]->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs16_r12.buf);
      
371
    }
372
 
373
#endif
374
  }
375
   
376 377 378
  LOG_D(RRC,
	PROTOCOL_RRC_CTXT_FMT" RRC_UE --- MAC_CONFIG_REQ (SIB1.tdd & SIB2 params) ---> MAC_UE\n",
	PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
379

380 381
  // LTE-M stuff here (take out CU-DU for now)
  if (rrc->node_type == ngran_eNB) {
382
#if (RRC_VERSION >= MAKE_VERSION(13, 0, 0))
383 384 385
    if ((carrier->mib.message.schedulingInfoSIB1_BR_r13>0) && 
	(carrier->sib1_BR!=NULL)) {
      AssertFatal(carrier->sib1_BR->nonCriticalExtension!=NULL,
Raymond Knopp's avatar
Raymond Knopp committed
386
		  "sib2_br->nonCriticalExtension is null (v8.9)\n");
387
      AssertFatal(carrier->sib1_BR->nonCriticalExtension->nonCriticalExtension!=NULL,
Raymond Knopp's avatar
Raymond Knopp committed
388
		  "sib2_br->nonCriticalExtension is null (v9.2)\n");
389
      AssertFatal(carrier->sib1_BR->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension!=NULL,
Raymond Knopp's avatar
Raymond Knopp committed
390
		  "sib2_br->nonCriticalExtension is null (v11.3)\n");
391
      AssertFatal(carrier->sib1_BR->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension!=NULL,
Raymond Knopp's avatar
Raymond Knopp committed
392
		  "sib2_br->nonCriticalExtension is null (v12.5)\n");
393
      AssertFatal(carrier->sib1_BR->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension!=NULL,
394
		  "sib2_br->nonCriticalExtension is null (v13.10)\n");
395 396
      sib1_v13ext = carrier->sib1_BR->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension;
    }
397
#endif
398 399
  
  }
400
  /*
401 402 403 404 405 406 407 408 409
  if (rrc->node_type == ngran_eNB_DU) {
    LOG_D(RRC, "About to call rrc_mac_config_req_eNB for ngran_eNB_DU\n");
    
    rrc_mac_config_req_eNB(ctxt_pP->module_id, CC_id,
			   carrier->physCellId,
			   carrier->p_eNB,
			   carrier->Ncp,
			   carrier->sib1->freqBandIndicator,
			   carrier->dl_CarrierFreq,
410
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
411
			   carrier->pbch_repetition,
412
#endif
413 414 415 416
			   0, // rnti
			   (BCCH_BCH_Message_t *)
			   &carrier->mib,
			   (RadioResourceConfigCommonSIB_t *) NULL,
417
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
418
			   (RadioResourceConfigCommonSIB_t *) NULL,
419
#endif
420
			   (struct PhysicalConfigDedicated *)NULL,
421
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
			   (SCellToAddMod_r10_t *)NULL,
			   //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
#endif
			   (MeasObjectToAddMod_t **) NULL,
			   (MAC_MainConfig_t *) NULL, 0,
			   (struct LogicalChannelConfig *)NULL,
			   (MeasGapConfig_t *) NULL,
			   carrier->sib1->tdd_Config,
			   NULL,
			   &carrier->sib1->schedulingInfoList,
			   carrier->ul_CarrierFreq,
			   NULL,
			   NULL,
			   NULL
#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
			   ,
			   carrier->MBMS_flag,
			   NULL,
			   (PMCH_InfoList_r9_t *) NULL
441
#endif
442 443 444 445 446 447
#if (RRC_VERSION >= MAKE_VERSION(13, 0, 0))
			   , 
			   NULL
#endif
			   );
  }
448 449 450
  else 
  */
  if (rrc->node_type == ngran_eNB) {
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
    LOG_D(RRC, "About to call rrc_mac_config_req_eNB for ngran_eNB\n");
    
    rrc_mac_config_req_eNB(ctxt_pP->module_id, CC_id,
			   carrier->physCellId,
			   carrier->p_eNB,
			   carrier->Ncp,
			   carrier->sib1->freqBandIndicator,
			   carrier->dl_CarrierFreq,
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
			   carrier->pbch_repetition,
#endif
			   0, // rnti
			   (BCCH_BCH_Message_t *)
			   &carrier->mib,
			   (RadioResourceConfigCommonSIB_t *) &
			   carrier->sib2->radioResourceConfigCommon,
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
			   (RadioResourceConfigCommonSIB_t *) &
			   carrier->sib2_BR->radioResourceConfigCommon,
#endif
			   (struct PhysicalConfigDedicated *)NULL,
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
			   (SCellToAddMod_r10_t *)NULL,
			   //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
#endif
			   (MeasObjectToAddMod_t **) NULL,
			   (MAC_MainConfig_t *) NULL, 0,
			   (struct LogicalChannelConfig *)NULL,
			   (MeasGapConfig_t *) NULL,
			   carrier->sib1->tdd_Config,
			   NULL,
			   &carrier->sib1->schedulingInfoList,
			   carrier->ul_CarrierFreq,
			   carrier->sib2->freqInfo.ul_Bandwidth,
			   &carrier->sib2->freqInfo.additionalSpectrumEmission,
			   (MBSFN_SubframeConfigList_t*) carrier->sib2->mbsfn_SubframeConfigList
487
#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
488 489 490 491
			   ,
			   carrier->MBMS_flag,
			   (MBSFN_AreaInfoList_r9_t*) & carrier->sib13->mbsfn_AreaInfoList_r9,
			   (PMCH_InfoList_r9_t *) NULL
492
#endif
493
#if (RRC_VERSION >= MAKE_VERSION(13, 0, 0))
494 495
			   , 
			   sib1_v13ext
496
#endif
497 498 499 500 501 502
			   );
  }
  // set flag to indicate that cell information is configured. This is required in DU to trigger  F1AP_SETUP procedure.
  pthread_mutex_lock(&rrc->cell_info_mutex);
  rrc->cell_info_configured=1;
  pthread_mutex_unlock(&rrc->cell_info_mutex);
503 504
}

505
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
winckel's avatar
winckel committed
506
/*------------------------------------------------------------------------------*/
507 508
static void
init_MCCH(
509 510
  module_id_t enb_mod_idP,
  int CC_id
511 512
)
//-----------------------------------------------------------------------------
513
{
Lionel Gauthier's avatar
 
Lionel Gauthier committed
514

515 516
  int                                 sync_area = 0;
  // initialize RRC_eNB_INST MCCH entry
517 518
  eNB_RRC_INST *rrc = RC.rrc[enb_mod_idP];

519 520
  RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESSAGE =
    malloc(RC.rrc[enb_mod_idP]->carrier[CC_id].num_mbsfn_sync_area * sizeof(uint8_t*));
Lionel Gauthier's avatar
 
Lionel Gauthier committed
521

522
  for (sync_area = 0; sync_area < RC.rrc[enb_mod_idP]->carrier[CC_id].num_mbsfn_sync_area; sync_area++) {
Lionel Gauthier's avatar
 
Lionel Gauthier committed
523

524 525
    RC.rrc[enb_mod_idP]->carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] = 0;
    RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESSAGE[sync_area] = (uint8_t *) malloc16(32);
526

527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551
    AssertFatal(RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESSAGE[sync_area] != NULL,
		"[eNB %d]init_MCCH: FATAL, no memory for MCCH MESSAGE allocated \n", enb_mod_idP);
    RC.rrc[enb_mod_idP]->carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] = do_MBSFNAreaConfig(enb_mod_idP,
											    sync_area,
											    (uint8_t *)RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESSAGE[sync_area],
											    &RC.rrc[enb_mod_idP]->carrier[CC_id].mcch,
											    &RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message);
    
    LOG_I(RRC, "mcch message pointer %p for sync area %d \n",
	  RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESSAGE[sync_area],
	  sync_area);
    LOG_D(RRC, "[eNB %d] MCCH_MESSAGE  contents for Sync Area %d (partial)\n", enb_mod_idP, sync_area);
    LOG_D(RRC, "[eNB %d] CommonSF_AllocPeriod_r9 %ld\n", enb_mod_idP,
	  RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->commonSF_AllocPeriod_r9);
    LOG_D(RRC,
	  "[eNB %d] CommonSF_Alloc_r9.list.count (number of MBSFN Subframe Pattern) %d\n",
	  enb_mod_idP, RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->commonSF_Alloc_r9.list.count);
    LOG_D(RRC, "[eNB %d] MBSFN Subframe Pattern: %02x (in hex)\n",
	  enb_mod_idP,
	  RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->commonSF_Alloc_r9.list.array[0]->subframeAllocation.
	  choice.oneFrame.buf[0]);
    
    AssertFatal(RC.rrc[enb_mod_idP]->carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] != 255,
		"RC.rrc[enb_mod_idP]->carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] == 255");
    RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESS[sync_area].Active = 1;
552
  }
553
  
Lionel Gauthier's avatar
 
Lionel Gauthier committed
554

555
  //Set the RC.rrc[enb_mod_idP]->MCCH_MESS.Active to 1 (allow to  transfer MCCH message RRC->MAC in function mac_rrc_data_req)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
556

557 558 559
  // ??Configure MCCH logical channel
  // call mac_config_req with appropriate structure from ASN.1 description

560

561 562
  //  LOG_I(RRC, "DUY: serviceID is %d\n",RC.rrc[enb_mod_idP]->mcch_message->pmch_InfoList_r9.list.array[0]->mbms_SessionInfoList_r9.list.array[0]->tmgi_r9.serviceId_r9.buf[2]);
  //  LOG_I(RRC, "DUY: session ID is %d\n",RC.rrc[enb_mod_idP]->mcch_message->pmch_InfoList_r9.list.array[0]->mbms_SessionInfoList_r9.list.array[0]->sessionId_r9->buf[0]);
563 564 565
  if (rrc->node_type == ngran_eNB) {
    rrc_mac_config_req_eNB(enb_mod_idP, CC_id,
			   0,0,0,0,0,
566
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
567
			   0,
568
#endif
569 570 571
			   0,//rnti
			   (BCCH_BCH_Message_t *)NULL,
			   (RadioResourceConfigCommonSIB_t *) NULL,
572
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
573
			   (RadioResourceConfigCommonSIB_t *) NULL,
574
#endif
575
			   (struct PhysicalConfigDedicated *)NULL,
576
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
577 578
			   (SCellToAddMod_r10_t *)NULL,
			   //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
579
#endif
580 581 582 583 584 585 586 587 588
			   (MeasObjectToAddMod_t **) NULL,
			   (MAC_MainConfig_t *) NULL,
			   0,
			   (struct LogicalChannelConfig *)NULL,
			   (MeasGapConfig_t *) NULL,
			   (TDD_Config_t *) NULL,
			   (MobilityControlInfo_t *)NULL, 
			   (SchedulingInfoList_t *) NULL, 
			   0, NULL, NULL, (MBSFN_SubframeConfigList_t *) NULL
589
#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
590 591 592 593
			   ,
			   0,
			   (MBSFN_AreaInfoList_r9_t *) NULL,
			   (PMCH_InfoList_r9_t *) & (RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->pmch_InfoList_r9)
594 595
#endif
#if (RRC_VERSION >= MAKE_VERSION(13, 0, 0))
596 597
			   ,
			   (SystemInformationBlockType1_v1310_IEs_t *)NULL
598
#endif
599 600
			   );
  }
601
  //LOG_I(RRC,"DUY: lcid after rrc_mac_config_req is %02d\n",RC.rrc[enb_mod_idP]->mcch_message->pmch_InfoList_r9.list.array[0]->mbms_SessionInfoList_r9.list.array[0]->logicalChannelIdentity_r9);
602

603 604
}

605
//-----------------------------------------------------------------------------
Lionel Gauthier's avatar
 
Lionel Gauthier committed
606
static void init_MBMS(
607
  module_id_t enb_mod_idP,
608
  int         CC_id,
609 610 611
  frame_t frameP
)
//-----------------------------------------------------------------------------
612 613 614
{
  // init the configuration for MTCH
  protocol_ctxt_t               ctxt;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
615

616
  if (RC.rrc[enb_mod_idP]->carrier[CC_id].MBMS_flag > 0) {
617
    PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, enb_mod_idP, ENB_FLAG_YES, NOT_A_RNTI, frameP, 0,enb_mod_idP);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
618

619 620
    LOG_D(RRC, "[eNB %d] Frame %d : Radio Bearer config request for MBMS\n", enb_mod_idP, frameP);   //check the lcid
    // Configuring PDCP and RLC for MBMS Radio Bearer
Lionel Gauthier's avatar
 
Lionel Gauthier committed
621

622 623 624 625 626 627 628 629
    rrc_pdcp_config_asn1_req(&ctxt,
                             (SRB_ToAddModList_t  *)NULL,  // SRB_ToAddModList
                             (DRB_ToAddModList_t  *)NULL,  // DRB_ToAddModList
                             (DRB_ToReleaseList_t *)NULL,
                             0,     // security mode
                             NULL,  // key rrc encryption
                             NULL,  // key rrc integrity
                             NULL   // key encryption
630
#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
631
                             , &(RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->pmch_InfoList_r9)
632
#endif
633
                             ,NULL);
634
    
635 636 637
    if ( (RC.rrc[enb_mod_idP]->node_type  != ngran_eNB_CU) ||
	 (RC.rrc[enb_mod_idP]->node_type  != ngran_ng_eNB_CU) ||
	 (RC.rrc[enb_mod_idP]->node_type  != ngran_gNB_CU)   ) {
638 639 640 641 642
      rrc_rlc_config_asn1_req(&ctxt,
			      NULL, // SRB_ToAddModList
			      NULL,   // DRB_ToAddModList
			      NULL,   // DRB_ToReleaseList
			      &(RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->pmch_InfoList_r9)
643

644
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
645
			      ,0, 0
646
#endif
647 648
			      );
    }
649
	    //rrc_mac_config_req();
650
  }
651 652 653
}
#endif

654 655 656 657 658 659
//-----------------------------------------------------------------------------
uint8_t
rrc_eNB_get_next_transaction_identifier(
  module_id_t enb_mod_idP
)
//-----------------------------------------------------------------------------
660
{
661 662
  static uint8_t                      rrc_transaction_identifier[NUMBER_OF_eNB_MAX];
  rrc_transaction_identifier[enb_mod_idP] = (rrc_transaction_identifier[enb_mod_idP] + 1) % RRC_TRANSACTION_IDENTIFIER_NUMBER;
663
  LOG_T(RRC,"generated xid is %d\n",rrc_transaction_identifier[enb_mod_idP]);
664 665 666 667 668
  return rrc_transaction_identifier[enb_mod_idP];
}
/*------------------------------------------------------------------------------*/
/* Functions to handle UE index in eNB UE list */

winckel's avatar
winckel committed
669

670 671 672 673 674 675 676 677 678 679 680 681 682 683
////-----------------------------------------------------------------------------
//static module_id_t
//rrc_eNB_get_UE_index(
//                module_id_t enb_mod_idP,
//                uint64_t    UE_identity
//)
////-----------------------------------------------------------------------------
//{
//
//    boolean_t      reg = FALSE;
//    module_id_t    i;
//
//    AssertFatal(enb_mod_idP < NB_eNB_INST, "eNB index invalid (%d/%d)!", enb_mod_idP, NB_eNB_INST);
//
684
//    for (i = 0; i < MAX_MOBILES_PER_ENB; i++) {
685
//        if (RC.rrc[enb_mod_idP]->Info.UE_list[i] == UE_identity) {
686 687 688 689 690 691 692 693 694 695 696 697 698
//            // UE_identity already registered
//            reg = TRUE;
//            break;
//        }
//    }
//
//    if (reg == FALSE) {
//        return (UE_MODULE_INVALID);
//    } else
//        return (i);
//}


699
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
700 701
// return the ue context if there is already an UE with ue_identityP, NULL otherwise
static struct rrc_eNB_ue_context_s*
702 703 704 705 706 707 708
rrc_eNB_ue_context_random_exist(
  const protocol_ctxt_t* const ctxt_pP,
  const uint64_t               ue_identityP
)
//-----------------------------------------------------------------------------
{
  struct rrc_eNB_ue_context_s*        ue_context_p = NULL;
709
  RB_FOREACH(ue_context_p, rrc_ue_tree_s, &(RC.rrc[ctxt_pP->module_id]->rrc_ue_head)) {
710
    if (ue_context_p->ue_context.random_ue_identity == ue_identityP)
gauthier's avatar
gauthier committed
711
      return ue_context_p;
712
  }
gauthier's avatar
gauthier committed
713 714 715 716 717 718 719 720 721 722 723 724 725
  return NULL;
}
//-----------------------------------------------------------------------------
// return the ue context if there is already an UE with the same S-TMSI(MMEC+M-TMSI), NULL otherwise
static struct rrc_eNB_ue_context_s*
rrc_eNB_ue_context_stmsi_exist(
  const protocol_ctxt_t* const ctxt_pP,
  const mme_code_t             mme_codeP,
  const m_tmsi_t               m_tmsiP
)
//-----------------------------------------------------------------------------
{
  struct rrc_eNB_ue_context_s*        ue_context_p = NULL;
726
  RB_FOREACH(ue_context_p, rrc_ue_tree_s, &(RC.rrc[ctxt_pP->module_id]->rrc_ue_head)) {
kaltenbe's avatar
kaltenbe committed
727 728 729 730
    LOG_I(RRC,"checking for UE S-TMSI %x, mme %x (%p): rnti %x",
	  m_tmsiP, mme_codeP, ue_context_p, 
	  ue_context_p->ue_context.rnti);
    if (ue_context_p->ue_context.Initialue_identity_s_TMSI.presence == TRUE) {
731
      printf("=> S-TMSI %x, MME %x\n",
kaltenbe's avatar
kaltenbe committed
732 733
	    ue_context_p->ue_context.Initialue_identity_s_TMSI.m_tmsi,
	    ue_context_p->ue_context.Initialue_identity_s_TMSI.mme_code);
gauthier's avatar
gauthier committed
734 735 736
      if (ue_context_p->ue_context.Initialue_identity_s_TMSI.m_tmsi == m_tmsiP)
        if (ue_context_p->ue_context.Initialue_identity_s_TMSI.mme_code == mme_codeP)
          return ue_context_p;
kaltenbe's avatar
kaltenbe committed
737 738 739 740
    }
    else
      printf("\n");

gauthier's avatar
gauthier committed
741 742
  }
  return NULL;
743 744
}

745 746
//-----------------------------------------------------------------------------
// return a new ue context structure if ue_identityP, ctxt_pP->rnti not found in collection
747
struct rrc_eNB_ue_context_s*
748 749 750 751 752 753 754 755
rrc_eNB_get_next_free_ue_context(
  const protocol_ctxt_t* const ctxt_pP,
  const uint64_t               ue_identityP
)
//-----------------------------------------------------------------------------
{
  struct rrc_eNB_ue_context_s*        ue_context_p = NULL;
  ue_context_p = rrc_eNB_get_ue_context(
756 757
					RC.rrc[ctxt_pP->module_id],
					ctxt_pP->rnti);
758 759

  if (ue_context_p == NULL) {
760
    ue_context_p = rrc_eNB_allocate_new_UE_context(RC.rrc[ctxt_pP->module_id]);
winckel's avatar
winckel committed
761

762 763 764 765 766
    if (ue_context_p == NULL) {
      LOG_E(RRC,
            PROTOCOL_RRC_CTXT_UE_FMT" Cannot create new UE context, no memory\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
      return NULL;
767
    }
768

769 770 771
    ue_context_p->ue_id_rnti                    = ctxt_pP->rnti; // here ue_id_rnti is just a key, may be something else
    ue_context_p->ue_context.rnti               = ctxt_pP->rnti; // yes duplicate, 1 may be removed
    ue_context_p->ue_context.random_ue_identity = ue_identityP;
772
    RB_INSERT(rrc_ue_tree_s, &RC.rrc[ctxt_pP->module_id]->rrc_ue_head, ue_context_p);
773 774 775 776 777
    LOG_D(RRC,
          PROTOCOL_RRC_CTXT_UE_FMT" Created new UE context uid %u\n",
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
          ue_context_p->local_uid);
    return ue_context_p;
winckel's avatar
winckel committed
778

779 780 781 782 783 784
  } else {
    LOG_E(RRC,
          PROTOCOL_RRC_CTXT_UE_FMT" Cannot create new UE context, already exist\n",
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
    return NULL;
  }
785
  return(ue_context_p);
winckel's avatar
winckel committed
786 787
}

788 789 790 791 792
//-----------------------------------------------------------------------------
void
rrc_eNB_free_mem_UE_context(
  const protocol_ctxt_t*               const ctxt_pP,
  struct rrc_eNB_ue_context_s*         const ue_context_pP
793
)
794
//-----------------------------------------------------------------------------
Lionel Gauthier's avatar
Lionel Gauthier committed
795
{
796 797
  int i;
  LOG_T(RRC,
Cedric Roux's avatar
Cedric Roux committed
798
        PROTOCOL_RRC_CTXT_UE_FMT" Clearing UE context 0x%p (free internal structs)\n",
799 800
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
        ue_context_pP);
801
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
802 803 804 805 806 807 808 809
  ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_SCellToAddMod_r10, &ue_context_pP->ue_context.sCell_config[0]);
  ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_SCellToAddMod_r10, &ue_context_pP->ue_context.sCell_config[1]);
#endif

  if (ue_context_pP->ue_context.SRB_configList) {
    ASN_STRUCT_FREE(asn_DEF_SRB_ToAddModList, ue_context_pP->ue_context.SRB_configList);
    ue_context_pP->ue_context.SRB_configList = NULL;
  }
810

811 812 813 814 815 816 817
  for(i = 0;i < RRC_TRANSACTION_IDENTIFIER_NUMBER;i++){
      if (ue_context_pP->ue_context.SRB_configList2[i]) {
          free(ue_context_pP->ue_context.SRB_configList2[i]);
          ue_context_pP->ue_context.SRB_configList2[i] = NULL;
      }
  }

818 819 820 821
  if (ue_context_pP->ue_context.DRB_configList) {
    ASN_STRUCT_FREE(asn_DEF_DRB_ToAddModList, ue_context_pP->ue_context.DRB_configList);
    ue_context_pP->ue_context.DRB_configList = NULL;
  }
822

823 824 825 826 827 828 829 830 831 832 833
  for(i = 0;i < RRC_TRANSACTION_IDENTIFIER_NUMBER;i++){
      if (ue_context_pP->ue_context.DRB_configList2[i]) {
          free(ue_context_pP->ue_context.DRB_configList2[i]);
          ue_context_pP->ue_context.DRB_configList2[i] = NULL;
      }
      if (ue_context_pP->ue_context.DRB_Release_configList2[i]) {
          free(ue_context_pP->ue_context.DRB_Release_configList2[i]);
          ue_context_pP->ue_context.DRB_Release_configList2[i] = NULL;
      }
  }

834
  memset(ue_context_pP->ue_context.DRB_active, 0, sizeof(ue_context_pP->ue_context.DRB_active));
835

836 837 838
  if (ue_context_pP->ue_context.physicalConfigDedicated) {
    ASN_STRUCT_FREE(asn_DEF_PhysicalConfigDedicated, ue_context_pP->ue_context.physicalConfigDedicated);
    ue_context_pP->ue_context.physicalConfigDedicated = NULL;
839 840
  }

841 842 843
  if (ue_context_pP->ue_context.sps_Config) {
    ASN_STRUCT_FREE(asn_DEF_SPS_Config, ue_context_pP->ue_context.sps_Config);
    ue_context_pP->ue_context.sps_Config = NULL;
844 845
  }

846 847 848 849 850
  for (i=0; i < MAX_MEAS_OBJ; i++) {
    if (ue_context_pP->ue_context.MeasObj[i] != NULL) {
      ASN_STRUCT_FREE(asn_DEF_MeasObjectToAddMod, ue_context_pP->ue_context.MeasObj[i]);
      ue_context_pP->ue_context.MeasObj[i] = NULL;
    }
851
  }
852

853 854 855 856 857 858
  for (i=0; i < MAX_MEAS_CONFIG; i++) {
    if (ue_context_pP->ue_context.ReportConfig[i] != NULL) {
      ASN_STRUCT_FREE(asn_DEF_ReportConfigToAddMod, ue_context_pP->ue_context.ReportConfig[i]);
      ue_context_pP->ue_context.ReportConfig[i] = NULL;
    }
  }
859

860 861 862 863
  if (ue_context_pP->ue_context.QuantityConfig) {
    ASN_STRUCT_FREE(asn_DEF_QuantityConfig, ue_context_pP->ue_context.QuantityConfig);
    ue_context_pP->ue_context.QuantityConfig = NULL;
  }
864

865 866 867 868
  if (ue_context_pP->ue_context.mac_MainConfig) {
    ASN_STRUCT_FREE(asn_DEF_MAC_MainConfig, ue_context_pP->ue_context.mac_MainConfig);
    ue_context_pP->ue_context.mac_MainConfig = NULL;
  }
869

870
/*  if (ue_context_pP->ue_context.measGapConfig) {
871 872
    ASN_STRUCT_FREE(asn_DEF_MeasGapConfig, ue_context_pP->ue_context.measGapConfig);
    ue_context_pP->ue_context.measGapConfig = NULL;
873 874 875 876 877
  }*/
    if (ue_context_pP->ue_context.handover_info) {
      ASN_STRUCT_FREE(asn_DEF_Handover, ue_context_pP->ue_context.handover_info);
      ue_context_pP->ue_context.handover_info = NULL;
    }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
878

879 880 881 882 883 884 885
  //SRB_INFO                           SI;
  //SRB_INFO                           Srb0;
  //SRB_INFO_TABLE_ENTRY               Srb1;
  //SRB_INFO_TABLE_ENTRY               Srb2;
  if (ue_context_pP->ue_context.measConfig) {
    ASN_STRUCT_FREE(asn_DEF_MeasConfig, ue_context_pP->ue_context.measConfig);
    ue_context_pP->ue_context.measConfig = NULL;
886
  }
887

888 889 890
  if (ue_context_pP->ue_context.measConfig) {
    ASN_STRUCT_FREE(asn_DEF_MeasConfig, ue_context_pP->ue_context.measConfig);
    ue_context_pP->ue_context.measConfig = NULL;
891
  }
892

893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914
  //HANDOVER_INFO                     *handover_info;
#if defined(ENABLE_SECURITY)
  //uint8_t kenb[32];
#endif
  //e_SecurityAlgorithmConfig__cipheringAlgorithm     ciphering_algorithm;
  //e_SecurityAlgorithmConfig__integrityProtAlgorithm integrity_algorithm;
  //uint8_t                            Status;
  //rnti_t                             rnti;
  //uint64_t                           random_ue_identity;
#if defined(ENABLE_ITTI)
  //UE_S_TMSI                          Initialue_identity_s_TMSI;
  //EstablishmentCause_t               establishment_cause;
  //ReestablishmentCause_t             reestablishment_cause;
  //uint16_t                           ue_initial_id;
  //uint32_t                           eNB_ue_s1ap_id :24;
  //security_capabilities_t            security_capabilities;
  //uint8_t                            nb_of_e_rabs;
  //e_rab_param_t                      e_rab[S1AP_MAX_E_RAB];
  //uint32_t                           enb_gtp_teid[S1AP_MAX_E_RAB];
  //transport_layer_addr_t             enb_gtp_addrs[S1AP_MAX_E_RAB];
  //rb_id_t                            enb_gtp_ebi[S1AP_MAX_E_RAB];
#endif
915 916
}

917
//-----------------------------------------------------------------------------
918
// should be called when UE is lost by eNB
919
void
920
rrc_eNB_free_UE(const module_id_t enb_mod_idP,const struct rrc_eNB_ue_context_s*        const ue_context_pP)
921
//-----------------------------------------------------------------------------
Lionel Gauthier's avatar
Lionel Gauthier committed
922
{
Raymond Knopp's avatar
 
Raymond Knopp committed
923

924

925
  protocol_ctxt_t                     ctxt;
926
  rnti_t rnti = ue_context_pP->ue_context.rnti;
927 928 929 930
  if (enb_mod_idP >= NB_eNB_INST) {
      LOG_I(RRC, "eNB inst invalid (%d/%d) for UE %x!\n",enb_mod_idP, NB_eNB_INST,rnti);
      return;
  }
931
  /*  ue_context_p = rrc_eNB_get_ue_context(
932
                   &RC.rrc[enb_mod_idP],
933 934
                   rntiP
                 );
935 936 937 938
  */
  if (NULL != ue_context_pP) {
    PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, enb_mod_idP, ENB_FLAG_YES, rnti, 0, 0,enb_mod_idP);
    LOG_W(RRC, "[eNB %d] Removing UE RNTI %x\n", enb_mod_idP, rnti);
Lionel Gauthier's avatar
Lionel Gauthier committed
939

940 941 942 943 944 945 946 947 948 949 950 951 952
   if(EPC_MODE_ENABLED) {

     if((ue_context_pP->ue_context.ul_failure_timer >= 20000) &&
  	(mac_eNB_get_rrc_status(enb_mod_idP,rnti) >= RRC_CONNECTED)) {
      LOG_I(RRC, "[eNB %d] S1AP_UE_CONTEXT_RELEASE_REQ RNTI %x\n", enb_mod_idP, rnti);
      rrc_eNB_send_S1AP_UE_CONTEXT_RELEASE_REQ(enb_mod_idP, ue_context_pP, S1AP_CAUSE_RADIO_NETWORK, 21); // send cause 21: connection with ue lost
      /* From 3GPP 36300v10 p129 : 19.2.2.2.2 S1 UE Context Release Request (eNB triggered)
       * If the E-UTRAN internal reason is a radio link failure detected in the eNB, the eNB shall wait a sufficient time before
       *  triggering the S1 UE Context Release Request procedure
       *  in order to allow the UE to perform the NAS recovery
       *  procedure, see TS 23.401 [17].
       */
       return;
953
    }
954
  }
955 956 957
    // add UE info to freeList
    LOG_I(RRC, "put UE %x into freeList\n", rnti);
    put_UE_in_freelist(enb_mod_idP, rnti, 1);
958
  }
959 960
}

961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990
void remove_UE_from_freelist(module_id_t mod_id, rnti_t rnti)
{

    eNB_MAC_INST                             *eNB_MAC = RC.mac[mod_id];
    pthread_mutex_lock(&lock_ue_freelist);
    UE_free_list_t                           *free_list = &eNB_MAC->UE_free_list;
    free_list->UE_free_ctrl[free_list->head_freelist].rnti = 0;
    free_list->head_freelist = (free_list->head_freelist + 1) % (NUMBER_OF_UE_MAX+1);
    free_list->num_UEs--;
    pthread_mutex_unlock(&lock_ue_freelist);
}

void put_UE_in_freelist(module_id_t mod_id, rnti_t rnti, boolean_t removeFlag)
{
    UE_free_list_t                           *free_list = NULL;
    eNB_MAC_INST                             *eNB_MAC = RC.mac[mod_id];
    pthread_mutex_lock(&lock_ue_freelist);
    free_list = &eNB_MAC->UE_free_list;
    free_list->UE_free_ctrl[free_list->tail_freelist].rnti = rnti;
    free_list->UE_free_ctrl[free_list->tail_freelist].removeContextFlg = removeFlag;
    free_list->num_UEs++;
    free_list->tail_freelist = (free_list->tail_freelist + 1) % (NUMBER_OF_UE_MAX+1);
    pthread_mutex_unlock(&lock_ue_freelist);
}

void release_UE_in_freeList(module_id_t mod_id)
{
    int i, j , CC_id, pdu_number;
    protocol_ctxt_t                           ctxt;
    LTE_eNB_ULSCH_t                          *ulsch = NULL;
991
    LTE_eNB_DLSCH_t                          *dlsch = NULL;
992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019
    nfapi_ul_config_request_body_t           *ul_req_tmp = NULL;
    PHY_VARS_eNB                             *eNB_PHY = NULL;
    struct rrc_eNB_ue_context_s              *ue_context_pP = NULL;
    eNB_MAC_INST                             *eNB_MAC = RC.mac[mod_id];
    boolean_t                                 remove_UEContext;
    rnti_t                                    rnti;
    int                                       head, tail, ue_num;

    pthread_mutex_lock(&lock_ue_freelist);
    head = eNB_MAC->UE_free_list.head_freelist;
    tail = eNB_MAC->UE_free_list.tail_freelist;
    if(head == tail){
        pthread_mutex_unlock(&lock_ue_freelist);
        return;
    }
    if(tail < head){
        tail = head + eNB_MAC->UE_free_list.num_UEs;
    }
    pthread_mutex_unlock(&lock_ue_freelist);

    for(ue_num = head; ue_num < tail; ue_num++){
        ue_num = ue_num % (NUMBER_OF_UE_MAX+1);
        rnti = eNB_MAC->UE_free_list.UE_free_ctrl[ue_num].rnti;
        if(rnti != 0){
            remove_UEContext = eNB_MAC->UE_free_list.UE_free_ctrl[ue_num].removeContextFlg;
            PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, mod_id, ENB_FLAG_YES, rnti, 0, 0,mod_id);
            for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
              eNB_PHY = RC.eNB[mod_id][CC_id];
1020
              for (i=0; i<MAX_MOBILES_PER_ENB; i++) {
1021 1022
                ulsch = eNB_PHY->ulsch[i];
                if((ulsch != NULL) && (ulsch->rnti == rnti)){
1023
                  void clean_eNb_ulsch(LTE_eNB_ULSCH_t *ulsch);
1024 1025 1026 1027 1028 1029 1030 1031
                  LOG_I(RRC, "clean_eNb_ulsch ulsch[%d] UE %x\n", i, rnti);
                  clean_eNb_ulsch(ulsch);
                }
                if(eNB_PHY->uci_vars[i].rnti == rnti){
                  LOG_I(MAC, "clean eNb uci_vars[%d] UE %x \n",i, rnti);
                  memset(&eNB_PHY->uci_vars[i],0,sizeof(LTE_eNB_UCI));
                }
              }
1032
              for (i=0; i<MAX_MOBILES_PER_ENB; i++) {
1033 1034
                dlsch = eNB_PHY->dlsch[i][0];
                if((dlsch != NULL) && (dlsch->rnti == rnti)){
1035
                  void clean_eNb_dlsch(LTE_eNB_DLSCH_t *dlsch);
1036 1037 1038
                  LOG_I(RRC, "clean_eNb_dlsch dlsch[%d] UE %x \n", i, rnti);
                  clean_eNb_dlsch(dlsch);
                }
1039 1040
              }

1041 1042 1043 1044 1045
              if (rrc_agent_registered[mod_id]) {
                agent_rrc_xface[mod_id]->flexran_agent_notify_ue_state_change(mod_id,
                            rnti, PROTOCOL__FLEX_UE_STATE_CHANGE_TYPE__FLUESC_DEACTIVATED);
              }

1046 1047 1048 1049 1050
              for(j = 0; j < 10; j++){
                ul_req_tmp = &eNB_MAC->UL_req_tmp[CC_id][j].ul_config_request_body;
                if(ul_req_tmp){
                  pdu_number = ul_req_tmp->number_of_pdus;
                  for(int pdu_index = pdu_number-1; pdu_index >= 0; pdu_index--){
1051 1052 1053 1054 1055 1056 1057 1058 1059 1060
                    if((ul_req_tmp->ul_config_pdu_list[pdu_index].ulsch_pdu.ulsch_pdu_rel8.rnti == rnti) ||
                       (ul_req_tmp->ul_config_pdu_list[pdu_index].uci_harq_pdu.ue_information.ue_information_rel8.rnti == rnti) ||
                       (ul_req_tmp->ul_config_pdu_list[pdu_index].uci_cqi_pdu.ue_information.ue_information_rel8.rnti == rnti) ||
                       (ul_req_tmp->ul_config_pdu_list[pdu_index].uci_sr_pdu.ue_information.ue_information_rel8.rnti == rnti) ||
                       (ul_req_tmp->ul_config_pdu_list[pdu_index].srs_pdu.srs_pdu_rel8.rnti == rnti)){
                        LOG_I(RRC, "remove UE %x from ul_config_pdu_list %d/%d\n", rnti, pdu_index, pdu_number);
                        if(pdu_index < pdu_number -1){
                          memcpy(&ul_req_tmp->ul_config_pdu_list[pdu_index], &ul_req_tmp->ul_config_pdu_list[pdu_index+1], (pdu_number-1-pdu_index) * sizeof(nfapi_ul_config_request_pdu_t));
                        }
                        ul_req_tmp->number_of_pdus--;
1061 1062 1063 1064 1065
                    }
                  }
                }
              }
            }
Raymond Knopp's avatar
Raymond Knopp committed
1066 1067 1068 1069 1070 1071 1072 1073
            if (RC.rrc[mod_id]->node_type == ngran_eNB) {
              rrc_mac_remove_ue(mod_id,rnti);
              rrc_rlc_remove_ue(&ctxt);
            }
            else if (RC.rrc[mod_id]->node_type == ngran_eNB_CU || RC.rrc[mod_id]->node_type == ngran_ng_eNB_CU) {
              // send UE_CONTEXT_RELEASE
                AssertFatal(1==0,"Need to added context removal\n");
            }
1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088
            pdcp_remove_UE(&ctxt);

            if(remove_UEContext){
                ue_context_pP = rrc_eNB_get_ue_context(
                                 RC.rrc[mod_id],rnti);
                if(ue_context_pP){
                    rrc_eNB_remove_ue_context(&ctxt,RC.rrc[mod_id],
                        (struct rrc_eNB_ue_context_s*) ue_context_pP);
                }
            }
            LOG_I(RRC, "[release_UE_in_freeList] remove UE %x from freeList\n", rnti);
            remove_UE_from_freelist(mod_id, rnti);
        }
    }
}
1089

1090 1091 1092 1093
//-----------------------------------------------------------------------------
void
rrc_eNB_process_RRCConnectionSetupComplete(
  const protocol_ctxt_t* const ctxt_pP,
1094
  rrc_eNB_ue_context_t*         ue_context_pP,
1095 1096
  RRCConnectionSetupComplete_r8_IEs_t * rrcConnectionSetupComplete
)
1097
//-----------------------------------------------------------------------------
Lionel Gauthier's avatar
Lionel Gauthier committed
1098
{
1099
  LOG_I(RRC,
1100
        PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel UL-DCCH, " "processing RRCConnectionSetupComplete from UE (SRB1 Active)\n",
1101
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
winckel's avatar
winckel committed
1102

nikaeinn's avatar
nikaeinn committed
1103
  ue_context_pP->ue_context.Srb1.Active=1;  
Cedric Roux's avatar
Cedric Roux committed
1104 1105 1106
  T(T_ENB_RRC_CONNECTION_SETUP_COMPLETE, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

1107 1108
  if (EPC_MODE_ENABLED == 1) {
    // Forward message to S1AP layer
1109 1110 1111 1112
    rrc_eNB_send_S1AP_NAS_FIRST_REQ(
      ctxt_pP,
      ue_context_pP,
      rrcConnectionSetupComplete);
1113
  } else {
1114
    // RRC loop back (no S1AP), send SecurityModeCommand to UE
1115 1116 1117
    rrc_eNB_generate_SecurityModeCommand(
      ctxt_pP,
      ue_context_pP);
1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137
/*
	 if ((RC.rrc[ctxt_pP->module_id]->node_type  == ngran_eNB_CU) ||
		 (RC.rrc[ctxt_pP->module_id]->node_type  == ngran_gNB_CU)   ||
		 (RC.rrc[ctxt_pP->module_id]->node_type  == ngran_ng_eNB_CU)) {

message_p = itti_alloc_new_message (TASK_RRC_ENB, F1AP_UE_CONTEXT_SETUP_REQ);
      F1AP_UE_CONTEXT_SETUP_REQ (message_p).rrc_container =  ue_p->Srb0.Tx_buffer.Payload;

      F1AP_UE_CONTEXT_SETUP_REQ (message_p).rrc_container_length = ue_p->Srb0.Tx_buffer.payload_size;
      F1AP_UE_CONTEXT_SETUP_REQ (message_p).gNB_CU_ue_id     = 0;  
      F1AP_UE_CONTEXT_SETUP_REQ (message_p).gNB_DU_ue_id = 0;
      F1AP_UE_CONTEXT_SETUP_REQ (message_p).old_gNB_DU_ue_id  = 0xFFFFFFFF; // unknown 
      F1AP_UE_CONTEXT_SETUP_REQ (message_p).rnti = ue_p->rnti; 
      F1AP_UE_CONTEXT_SETUP_REQ (message_p).srb_id = CCCH;  
      F1AP_UE_CONTEXT_SETUP_REQ (message_p).execute_duplication      = 1;
      F1AP_UE_CONTEXT_SETUP_REQ (message_p).RAT_frequency_priority_information.en_dc      = 0; 
      itti_send_msg_to_task (TASK_CU_F1, ctxt_pP->module_id, message_p);
      LOG_D(RRC, "Send F1AP_UE_CONTEXT_SETUP_REQ with ITTI\n");
  }
*/ 
1138
    // rrc_eNB_generate_UECapabilityEnquiry(enb_mod_idP,frameP,ue_mod_idP);
1139

1140
  }
winckel's avatar
winckel committed
1141 1142
}

1143 1144 1145 1146 1147
//-----------------------------------------------------------------------------
void
rrc_eNB_generate_SecurityModeCommand(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t*          const ue_context_pP
1148
)
1149
//-----------------------------------------------------------------------------
Lionel Gauthier's avatar
Lionel Gauthier committed
1150
{
1151 1152
  uint8_t                             buffer[100];
  uint8_t                             size;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1153

Cedric Roux's avatar
Cedric Roux committed
1154 1155 1156
  T(T_ENB_RRC_SECURITY_MODE_COMMAND, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

1157 1158 1159 1160 1161 1162
  size = do_SecurityModeCommand(
           ctxt_pP,
           buffer,
           rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),
           ue_context_pP->ue_context.ciphering_algorithm,
           ue_context_pP->ue_context.integrity_algorithm);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1163

1164

1165
  LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)buffer,size,"[MSG] RRC Security Mode Command\n");
1166

1167
  LOG_I(RRC,
1168 1169 1170
        PROTOCOL_RRC_CTXT_UE_FMT" Logical Channel DL-DCCH, Generate SecurityModeCommand (bytes %d)\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
        size);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1171

1172
  LOG_D(RRC,
1173 1174 1175 1176 1177
        PROTOCOL_RRC_CTXT_UE_FMT" --- PDCP_DATA_REQ/%d Bytes (securityModeCommand to UE MUI %d) --->[PDCP][RB %02d]\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
        size,
        rrc_eNB_mui,
        DCCH);
1178 1179

  MSC_LOG_TX_MESSAGE(
1180 1181 1182 1183 1184 1185 1186 1187 1188
    MSC_RRC_ENB,
    MSC_RRC_UE,
    buffer,
    size,
    MSC_AS_TIME_FMT" securityModeCommand UE %x MUI %d size %u",
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP->ue_context.rnti,
    rrc_eNB_mui,
    size);
1189

1190 1191 1192 1193
 if ((RC.rrc[ctxt_pP->module_id]->node_type  != ngran_eNB_DU) ||
	   (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_gNB_DU)) {
  LOG_I(RRC,"calling rrc_data_req :securityModeCommand\n");

1194
    rrc_data_req(
1195 1196 1197 1198 1199 1200 1201
	       ctxt_pP,
	       DCCH,
	       rrc_eNB_mui++,
	       SDU_CONFIRM_NO,
	       size,
	       buffer,
	       PDCP_TRANSMISSION_MODE_CONTROL);
1202
 }
1203 1204 1205

}

1206 1207 1208 1209 1210 1211 1212
//-----------------------------------------------------------------------------
void
rrc_eNB_generate_UECapabilityEnquiry(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t*          const ue_context_pP
)
//-----------------------------------------------------------------------------
1213
{
1214

1215 1216
  uint8_t                             buffer[100];
  uint8_t                             size;
1217

Cedric Roux's avatar
Cedric Roux committed
1218 1219 1220
  T(T_ENB_RRC_UE_CAPABILITY_ENQUIRY, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

1221 1222 1223 1224
  size = do_UECapabilityEnquiry(
           ctxt_pP,
           buffer,
           rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id));
winckel's avatar
winckel committed
1225

1226
  LOG_I(RRC,
1227 1228 1229
        PROTOCOL_RRC_CTXT_UE_FMT" Logical Channel DL-DCCH, Generate UECapabilityEnquiry (bytes %d)\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
        size);
winckel's avatar
winckel committed
1230

1231
  LOG_D(RRC,
1232 1233 1234 1235 1236
        PROTOCOL_RRC_CTXT_UE_FMT" --- PDCP_DATA_REQ/%d Bytes (UECapabilityEnquiry MUI %d) --->[PDCP][RB %02d]\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
        size,
        rrc_eNB_mui,
        DCCH);
1237 1238

  MSC_LOG_TX_MESSAGE(
1239 1240 1241 1242 1243 1244 1245 1246 1247
    MSC_RRC_ENB,
    MSC_RRC_UE,
    buffer,
    size,
    MSC_AS_TIME_FMT" rrcUECapabilityEnquiry UE %x MUI %d size %u",
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP->ue_context.rnti,
    rrc_eNB_mui,
    size);
1248

1249 1250 1251 1252 1253 1254 1255 1256
  rrc_data_req(
	       ctxt_pP,
	       DCCH,
	       rrc_eNB_mui++,
	       SDU_CONFIRM_NO,
	       size,
	       buffer,
	       PDCP_TRANSMISSION_MODE_CONTROL);
1257 1258 1259

}

1260 1261 1262 1263 1264 1265 1266 1267 1268 1269
//-----------------------------------------------------------------------------
void
rrc_eNB_generate_RRCConnectionReject(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t*          const ue_context_pP,
  const int                    CC_id
)
//-----------------------------------------------------------------------------
{

Cedric Roux's avatar
Cedric Roux committed
1270 1271 1272
  T(T_ENB_RRC_CONNECTION_REJECT, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

1273 1274
  eNB_RRC_UE_t *ue_p = &ue_context_pP->ue_context; 
  ue_p->Srb0.Tx_buffer.payload_size =
1275
    do_RRCConnectionReject(ctxt_pP->module_id,
1276
                          (uint8_t*) ue_p->Srb0.Tx_buffer.Payload);
1277

1278
  LOG_DUMPMSG(RRC,DEBUG_RRC,
1279 1280
              (char *)(ue_p->Srb0.Tx_buffer.Payload),
	      ue_p->Srb0.Tx_buffer.payload_size,
1281
              "[MSG] RRCConnectionReject\n");
1282 1283 1284 1285

  MSC_LOG_TX_MESSAGE(
    MSC_RRC_ENB,
    MSC_RRC_UE,
1286 1287
    ue_p->Srb0.Tx_buffer.Header,
    ue_p->Srb0.Tx_buffer.payload_size,
1288 1289 1290
    MSC_AS_TIME_FMT" RRCConnectionReject UE %x size %u",
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP == NULL ? -1 : ue_context_pP->ue_context.rnti,
1291
    ue_p->Srb0.Tx_buffer.payload_size);
1292 1293 1294 1295

  LOG_I(RRC,
        PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel DL-CCCH, Generating RRCConnectionReject (bytes %d)\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
1296
        ue_p->Srb0.Tx_buffer.payload_size);
1297 1298
}

1299 1300
//-----------------------------------------------------------------------------
void
1301 1302
rrc_eNB_generate_RRCConnectionReestablishment(
  const protocol_ctxt_t*         const ctxt_pP,
1303
  rrc_eNB_ue_context_t*          const ue_context_pP,
1304
  const int                            CC_id
1305 1306 1307
)
//-----------------------------------------------------------------------------
{
1308 1309 1310
  LogicalChannelConfig_t             *SRB1_logicalChannelConfig;
  SRB_ToAddModList_t                 **SRB_configList;
  SRB_ToAddMod_t                     *SRB1_config;
1311 1312
  int                                 cnt;

1313
  T(T_ENB_RRC_CONNECTION_REESTABLISHMENT, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
Cedric Roux's avatar
Cedric Roux committed
1314 1315
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

1316 1317 1318 1319 1320
  eNB_RRC_UE_t *ue_p = &ue_context_pP->ue_context; 

  SRB_configList = &ue_p->SRB_configList;

  ue_p->Srb0.Tx_buffer.payload_size =
1321 1322 1323
    do_RRCConnectionReestablishment(ctxt_pP,
                                    ue_context_pP,
                                    CC_id,
1324
                                    (uint8_t*) ue_p->Srb0.Tx_buffer.Payload,
1325 1326 1327 1328
                                    (uint8_t) RC.rrc[ctxt_pP->module_id]->carrier[CC_id].p_eNB, //at this point we do not have the UE capability information, so it can only be TM1 or TM2
                                    rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),
                                    SRB_configList,
                                    &ue_context_pP->ue_context.physicalConfigDedicated);
1329
  LOG_DUMPMSG(RRC,DEBUG_RRC,
1330 1331
              (char *)(ue_p->Srb0.Tx_buffer.Payload),
              ue_p->Srb0.Tx_buffer.payload_size,
1332 1333
              "[MSG] RRCConnectionReestablishment\n"
              );
1334
  // configure SRB1 for UE
1335

1336 1337 1338 1339
  if (*SRB_configList != NULL) {
    for (cnt = 0; cnt < (*SRB_configList)->list.count; cnt++) {
      if ((*SRB_configList)->list.array[cnt]->srb_Identity == 1) {
        SRB1_config = (*SRB_configList)->list.array[cnt];
1340

1341 1342 1343 1344 1345 1346 1347 1348 1349 1350
        if (SRB1_config->logicalChannelConfig) {
          if (SRB1_config->logicalChannelConfig->present ==
              SRB_ToAddMod__logicalChannelConfig_PR_explicitValue) {
            SRB1_logicalChannelConfig = &SRB1_config->logicalChannelConfig->choice.explicitValue;
          } else {
            SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
          }
        } else {
          SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
        }
Raymond Knopp's avatar
 
Raymond Knopp committed
1351

1352 1353 1354
        LOG_D(RRC,
              PROTOCOL_RRC_CTXT_UE_FMT" RRC_eNB --- MAC_CONFIG_REQ  (SRB1) ---> MAC_eNB\n",
              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
1355
	if (RC.rrc[ctxt_pP->module_id]->node_type == ngran_eNB) {
1356 1357 1358
	  rrc_mac_config_req_eNB(ctxt_pP->module_id,
				 ue_context_pP->ue_context.primaryCC_id,
				 0,0,0,0,0,
1359
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
1360
				 0,
1361
#endif
1362 1363 1364
				 ctxt_pP->rnti,
				 (BCCH_BCH_Message_t *) NULL, 
				 (RadioResourceConfigCommonSIB_t *) NULL,
1365
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
1366
				 (RadioResourceConfigCommonSIB_t *) NULL,
1367
#endif
1368
				 (struct PhysicalConfigDedicated* ) ue_context_pP->ue_context.physicalConfigDedicated,
1369
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
1370 1371
				 (SCellToAddMod_r10_t *)NULL,
				 //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
1372
#endif
1373 1374 1375 1376 1377 1378 1379 1380 1381
				 (MeasObjectToAddMod_t **) NULL,
				 ue_context_pP->ue_context.mac_MainConfig,
				 1,
				 SRB1_logicalChannelConfig,
				 ue_context_pP->ue_context.measGapConfig,
				 (TDD_Config_t *) NULL,
				 NULL,
				 (SchedulingInfoList_t *) NULL,
				 0, NULL, NULL, (MBSFN_SubframeConfigList_t *) NULL
1382
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
1383
				 , 0, (MBSFN_AreaInfoList_r9_t *) NULL, (PMCH_InfoList_r9_t *) NULL
1384
#endif
1385
#if (RRC_VERSION >= MAKE_VERSION(13, 0, 0))
1386
				 ,(SystemInformationBlockType1_v1310_IEs_t *)NULL 
1387
#endif
1388 1389
				 );
	}
1390 1391 1392 1393
        break;
      }
    }
  }
Raymond Knopp's avatar
 
Raymond Knopp committed
1394

1395 1396
  MSC_LOG_TX_MESSAGE(MSC_RRC_ENB,
                     MSC_RRC_UE,
1397 1398
                     ue_p->Srb0.Tx_buffer.Header,
                     ue_p->Srb0.Tx_buffer.payload_size,
1399 1400 1401
                     MSC_AS_TIME_FMT" RRCConnectionReestablishment UE %x size %u",
                     MSC_AS_TIME_ARGS(ctxt_pP),
                     ue_context_pP->ue_context.rnti,
1402
                     ue_p->Srb0.Tx_buffer.payload_size);
Cedric Roux's avatar
Cedric Roux committed
1403

1404
  LOG_I(RRC,
1405
        PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel DL-CCCH, Generating RRCConnectionReestablishment (bytes %d)\n",
1406
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
1407
        ue_p->Srb0.Tx_buffer.payload_size);
1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422
  	if ( (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_eNB_CU) &&
       (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_ng_eNB_CU)&& 
       (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_gNB_CU)   ) { 	
	  int UE_id = find_UE_id(ctxt_pP->module_id, ctxt_pP->rnti);
	  if(UE_id != -1){
	    // activate release timer, if RRCComplete not received after 100 frames, remove UE
	    RC.mac[ctxt_pP->module_id]->UE_list.UE_sched_ctrl[UE_id].ue_reestablishment_reject_timer = 1;
	    // remove UE after 100 frames after RRCConnectionReestablishmentRelease is triggered
	    RC.mac[ctxt_pP->module_id]->UE_list.UE_sched_ctrl[UE_id].ue_reestablishment_reject_timer_thres = 1000;
	  }else{
	    LOG_E(RRC,
	             PROTOCOL_RRC_CTXT_UE_FMT" Generating RRCConnectionReestablishment without UE_id(MAC) rnti %x\n",
	            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ctxt_pP->rnti);
	  }
	}	
1423 1424
  // activate release timer, if RRCComplete not received after 100 frames, remove UE
  ue_context_pP->ue_context.ue_reestablishment_timer = 1;
1425
  // remove UE after 100 frames after RRCConnectionReestablishmentRelease is triggered
1426
  ue_context_pP->ue_context.ue_reestablishment_timer_thres = 1000;
Raymond Knopp's avatar
 
Raymond Knopp committed
1427
}
1428

1429 1430
//-----------------------------------------------------------------------------
void
1431 1432
rrc_eNB_process_RRCConnectionReestablishmentComplete(
  const protocol_ctxt_t* const ctxt_pP,
Cedric Roux's avatar
Cedric Roux committed
1433
  const rnti_t reestablish_rnti,
1434 1435 1436 1437
  rrc_eNB_ue_context_t*         ue_context_pP,
  const uint8_t xid,
  RRCConnectionReestablishmentComplete_r8_IEs_t * rrcConnectionReestablishmentComplete
)
1438 1439
//-----------------------------------------------------------------------------
{
1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453
  LOG_I(RRC,
        PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel UL-DCCH, processing RRCConnectionReestablishmentComplete from UE (SRB1 Active)\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));

  T(T_ENB_RRC_CONNECTION_REESTABLISHMENT_COMPLETE, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

  DRB_ToAddModList_t*                 DRB_configList = ue_context_pP->ue_context.DRB_configList;
  SRB_ToAddModList_t*                 SRB_configList = ue_context_pP->ue_context.SRB_configList;
  SRB_ToAddModList_t**                SRB_configList2 = NULL;
  DRB_ToAddModList_t**                DRB_configList2 = NULL;
  struct SRB_ToAddMod                *SRB2_config = NULL;
  struct DRB_ToAddMod                *DRB_config = NULL;
  int i = 0;
1454 1455
  uint8_t                             buffer[RRC_BUF_SIZE];
  uint16_t                            size;
1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467
  MeasObjectToAddModList_t           *MeasObj_list                     = NULL;
  MeasObjectToAddMod_t               *MeasObj                          = NULL;
  ReportConfigToAddModList_t         *ReportConfig_list                = NULL;
  ReportConfigToAddMod_t             *ReportConfig_per, *ReportConfig_A1,
                                     *ReportConfig_A2, *ReportConfig_A3, *ReportConfig_A4, *ReportConfig_A5;
  MeasIdToAddModList_t               *MeasId_list                      = NULL;
  MeasIdToAddMod_t                   *MeasId0, *MeasId1, *MeasId2, *MeasId3, *MeasId4, *MeasId5;
  RSRP_Range_t                       *rsrp                             = NULL;
  struct MeasConfig__speedStatePars  *Sparams                          = NULL;
  QuantityConfig_t                   *quantityConfig                   = NULL;
  CellsToAddMod_t                    *CellToAdd                        = NULL;
  CellsToAddModList_t                *CellsToAddModList                = NULL;
1468 1469
  struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList = NULL;
  DedicatedInfoNAS_t                 *dedicatedInfoNas                 = NULL;
1470 1471
  /* for no gcc warnings */
  (void)dedicatedInfoNas;
1472 1473 1474 1475
  C_RNTI_t                           *cba_RNTI                         = NULL;
  uint8_t next_xid = rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id);

  ue_context_pP->ue_context.Status = RRC_CONNECTED;
1476
  ue_context_pP->ue_context.reestablishment_xid = next_xid;
1477 1478 1479 1480

  SRB_configList2 = &ue_context_pP->ue_context.SRB_configList2[xid];
  // get old configuration of SRB2
  if (*SRB_configList2 != NULL) {
1481 1482
    if((*SRB_configList2)->list.count!=0){
      LOG_D(RRC, "SRB_configList2(%p) count is %d\n           SRB_configList2->list.array[0] addr is %p",
1483
          SRB_configList2, (*SRB_configList2)->list.count,  (*SRB_configList2)->list.array[0]);
1484
    }
1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495
    for (i = 0; (i < (*SRB_configList2)->list.count) && (i < 3); i++) {
      if ((*SRB_configList2)->list.array[i]->srb_Identity == 2 ){
        LOG_D(RRC, "get SRB2_config from (ue_context_pP->ue_context.SRB_configList2[%d])\n", xid);
        SRB2_config = (*SRB_configList2)->list.array[i];
        break;
      }
    }
  }
  SRB_configList2 = &ue_context_pP->ue_context.SRB_configList2[next_xid];
  DRB_configList2 = &ue_context_pP->ue_context.DRB_configList2[next_xid];

1496 1497 1498 1499 1500 1501 1502
  if(SRB_configList2!=NULL){
    if (*SRB_configList2) {
      free(*SRB_configList2);
      LOG_D(RRC, "free(ue_context_pP->ue_context.SRB_configList2[%d])\n", next_xid);
    }
  }else{
      LOG_E(RRC, "SRB_configList2 is null\n");
1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519
  }
  *SRB_configList2 = CALLOC(1, sizeof(**SRB_configList2));
  if (SRB2_config != NULL) {
    // Add SRB2 to SRB configuration list

    ASN_SEQUENCE_ADD(&SRB_configList->list, SRB2_config);
    ASN_SEQUENCE_ADD(&(*SRB_configList2)->list, SRB2_config);

    LOG_D(RRC, "Add SRB2_config (srb_Identity:%ld) to ue_context_pP->ue_context.SRB_configList\n",
            SRB2_config->srb_Identity);
    LOG_D(RRC, "Add SRB2_config (srb_Identity:%ld) to ue_context_pP->ue_context.SRB_configList2[%d]\n",
                SRB2_config->srb_Identity, next_xid);
  } else {
    // SRB configuration list only contains SRB1.
    LOG_W(RRC,"SRB2 configuration does not exist in SRB configuration list\n");
  }

1520

1521

1522 1523 1524 1525 1526 1527 1528
  if(DRB_configList2!=NULL){
    if (*DRB_configList2) {
      free(*DRB_configList2);
      LOG_D(RRC, "free(ue_context_pP->ue_context.DRB_configList2[%d])\n", next_xid);
    }
  }else{
      LOG_E(RRC, "DRB_configList2 is null\n");
1529
  }
1530
  *DRB_configList2 = CALLOC(1, sizeof(**DRB_configList2));
Navid Nikaein's avatar
Navid Nikaein committed
1531

1532 1533 1534 1535 1536 1537 1538
  if (DRB_configList != NULL) {
    LOG_D(RRC, "get DRB_config from (ue_context_pP->ue_context.DRB_configList)\n");
    for (i = 0; (i < DRB_configList->list.count) && (i < 3); i++) {
      DRB_config = DRB_configList->list.array[i];

      // Add DRB to DRB configuration list, for RRCConnectionReconfigurationComplete
      ASN_SEQUENCE_ADD(&(*DRB_configList2)->list, DRB_config);
1539
    }
1540 1541 1542 1543
  }
  ue_context_pP->ue_context.Srb1.Active = 1;
  //ue_context_pP->ue_context.Srb2.Srb_info.Srb_id = 2;

frtabu's avatar
frtabu committed
1544
#if defined(ENABLE_USE_MME) 
1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555
    hashtable_rc_t    h_rc;
    int               j;
    rrc_ue_s1ap_ids_t* rrc_ue_s1ap_ids_p = NULL;
    uint16_t ue_initial_id = ue_context_pP->ue_context.ue_initial_id;
    uint32_t eNB_ue_s1ap_id = ue_context_pP->ue_context.eNB_ue_s1ap_id;
    eNB_RRC_INST *rrc_instance_p = RC.rrc[ENB_INSTANCE_TO_MODULE_ID(ctxt_pP->instance)];
    if (eNB_ue_s1ap_id > 0) {
      h_rc = hashtable_get(rrc_instance_p->s1ap_id2_s1ap_ids, (hash_key_t)eNB_ue_s1ap_id, (void**)&rrc_ue_s1ap_ids_p);
      if  (h_rc == HASH_TABLE_OK) {
  	rrc_ue_s1ap_ids_p->ue_rnti = ctxt_pP->rnti;
      }
1556
    }
1557 1558 1559 1560 1561
    if (ue_initial_id != 0) {
      h_rc = hashtable_get(rrc_instance_p->initial_id2_s1ap_ids, (hash_key_t)ue_initial_id, (void**)&rrc_ue_s1ap_ids_p);
      if  (h_rc == HASH_TABLE_OK) {
  	rrc_ue_s1ap_ids_p->ue_rnti = ctxt_pP->rnti;
      }
1562
    }
1563

1564
    gtpv1u_enb_create_tunnel_req_t  create_tunnel_req;
1565

1566 1567
    /* Save e RAB information for later */
    memset(&create_tunnel_req, 0 , sizeof(create_tunnel_req));
1568

1569 1570 1571 1572
    for ( j = 0, i = 0; i < NB_RB_MAX; i++) {
      if (ue_context_pP->ue_context.e_rab[i].status == E_RAB_STATUS_ESTABLISHED || ue_context_pP->ue_context.e_rab[i].status == E_RAB_STATUS_DONE) {
  	create_tunnel_req.eps_bearer_id[j]	 = ue_context_pP->ue_context.e_rab[i].param.e_rab_id;
  	create_tunnel_req.sgw_S1u_teid[j]	 = ue_context_pP->ue_context.e_rab[i].param.gtp_teid;
1573

1574 1575 1576 1577 1578
  	memcpy(&create_tunnel_req.sgw_addr[j],
  	       &ue_context_pP->ue_context.e_rab[i].param.sgw_addr,
  	       sizeof(transport_layer_addr_t));
  	j++;
      }
1579
    }
1580

1581 1582
    create_tunnel_req.rnti       = ctxt_pP->rnti; // warning put zero above
    create_tunnel_req.num_tunnels    = j;
1583

1584 1585 1586 1587
    gtpv1u_update_s1u_tunnel(
              ctxt_pP->instance,
              &create_tunnel_req,
              reestablish_rnti);
1588 1589 1590 1591
#endif
  /* Update RNTI in ue_context */
  ue_context_pP->ue_id_rnti                    = ctxt_pP->rnti; // here ue_id_rnti is just a key, may be something else
  ue_context_pP->ue_context.rnti               = ctxt_pP->rnti;
frtabu's avatar
frtabu committed
1592
#if defined(ENABLE_USE_MME)
1593 1594 1595 1596 1597 1598
    uint8_t send_security_mode_command = FALSE;
    rrc_pdcp_config_security(
        ctxt_pP,
        ue_context_pP,
        send_security_mode_command);
    LOG_D(RRC, "set security successfully \n");
1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920
#endif
  // Measurement ID list
  MeasId_list = CALLOC(1, sizeof(*MeasId_list));
  memset((void *)MeasId_list, 0, sizeof(*MeasId_list));

  MeasId0 = CALLOC(1, sizeof(*MeasId0));
  MeasId0->measId = 1;
  MeasId0->measObjectId = 1;
  MeasId0->reportConfigId = 1;
  ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId0);

  MeasId1 = CALLOC(1, sizeof(*MeasId1));
  MeasId1->measId = 2;
  MeasId1->measObjectId = 1;
  MeasId1->reportConfigId = 2;
  ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId1);

  MeasId2 = CALLOC(1, sizeof(*MeasId2));
  MeasId2->measId = 3;
  MeasId2->measObjectId = 1;
  MeasId2->reportConfigId = 3;
  ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId2);

  MeasId3 = CALLOC(1, sizeof(*MeasId3));
  MeasId3->measId = 4;
  MeasId3->measObjectId = 1;
  MeasId3->reportConfigId = 4;
  ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId3);

  MeasId4 = CALLOC(1, sizeof(*MeasId4));
  MeasId4->measId = 5;
  MeasId4->measObjectId = 1;
  MeasId4->reportConfigId = 5;
  ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId4);

  MeasId5 = CALLOC(1, sizeof(*MeasId5));
  MeasId5->measId = 6;
  MeasId5->measObjectId = 1;
  MeasId5->reportConfigId = 6;
  ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId5);

  //  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->measIdToAddModList = MeasId_list;

  // Add one EUTRA Measurement Object
  MeasObj_list = CALLOC(1, sizeof(*MeasObj_list));
  memset((void *)MeasObj_list, 0, sizeof(*MeasObj_list));

  // Configure MeasObject

  MeasObj = CALLOC(1, sizeof(*MeasObj));
  memset((void *)MeasObj, 0, sizeof(*MeasObj));

  MeasObj->measObjectId = 1;
  MeasObj->measObject.present = MeasObjectToAddMod__measObject_PR_measObjectEUTRA;
  MeasObj->measObject.choice.measObjectEUTRA.carrierFreq = 3350; //band 7, 2.68GHz
  //MeasObj->measObject.choice.measObjectEUTRA.carrierFreq = 36090; //band 33, 1.909GHz
  MeasObj->measObject.choice.measObjectEUTRA.allowedMeasBandwidth = AllowedMeasBandwidth_mbw25;
  MeasObj->measObject.choice.measObjectEUTRA.presenceAntennaPort1 = 1;
  MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.buf = CALLOC(1, sizeof(uint8_t));
  MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.buf[0] = 0;
  MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.size = 1;
  MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.bits_unused = 6;
  MeasObj->measObject.choice.measObjectEUTRA.offsetFreq = NULL;   // Default is 15 or 0dB

  MeasObj->measObject.choice.measObjectEUTRA.cellsToAddModList =
    (CellsToAddModList_t *) CALLOC(1, sizeof(*CellsToAddModList));

  CellsToAddModList = MeasObj->measObject.choice.measObjectEUTRA.cellsToAddModList;

  // Add adjacent cell lists (6 per eNB)
  for (i = 0; i < 6; i++) {
    CellToAdd = (CellsToAddMod_t *) CALLOC(1, sizeof(*CellToAdd));
    CellToAdd->cellIndex = i + 1;
    CellToAdd->physCellId = get_adjacent_cell_id(ctxt_pP->module_id, i);
    CellToAdd->cellIndividualOffset = Q_OffsetRange_dB0;

    ASN_SEQUENCE_ADD(&CellsToAddModList->list, CellToAdd);
  }

  ASN_SEQUENCE_ADD(&MeasObj_list->list, MeasObj);
  //  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->measObjectToAddModList = MeasObj_list;

  // Report Configurations for periodical, A1-A5 events
  ReportConfig_list = CALLOC(1, sizeof(*ReportConfig_list));

  ReportConfig_per = CALLOC(1, sizeof(*ReportConfig_per));

  ReportConfig_A1 = CALLOC(1, sizeof(*ReportConfig_A1));

  ReportConfig_A2 = CALLOC(1, sizeof(*ReportConfig_A2));

  ReportConfig_A3 = CALLOC(1, sizeof(*ReportConfig_A3));

  ReportConfig_A4 = CALLOC(1, sizeof(*ReportConfig_A4));

  ReportConfig_A5 = CALLOC(1, sizeof(*ReportConfig_A5));

  ReportConfig_per->reportConfigId = 1;
  ReportConfig_per->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerType.present =
    ReportConfigEUTRA__triggerType_PR_periodical;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerType.choice.periodical.purpose =
    ReportConfigEUTRA__triggerType__periodical__purpose_reportStrongestCells;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerQuantity = ReportConfigEUTRA__triggerQuantity_rsrp;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportInterval = ReportInterval_ms120;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;

  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_per);

  ReportConfig_A1->reportConfigId = 2;
  ReportConfig_A1->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.present =
    ReportConfigEUTRA__triggerType_PR_event;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
    ReportConfigEUTRA__triggerType__event__eventId_PR_eventA1;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA1.
  a1_Threshold.present = ThresholdEUTRA_PR_threshold_RSRP;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA1.
  a1_Threshold.choice.threshold_RSRP = 10;

  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerQuantity = ReportConfigEUTRA__triggerQuantity_rsrp;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportInterval = ReportInterval_ms120;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;

  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A1);

  if (RC.rrc[ctxt_pP->module_id]->HO_flag == 1 /*HO_MEASURMENT */ ) {
    LOG_I(RRC, "[eNB %d] frame %d: requesting A2, A3, A4, A5, and A6 event reporting\n",
          ctxt_pP->module_id, ctxt_pP->frame);
    ReportConfig_A2->reportConfigId = 3;
    ReportConfig_A2->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.present =
      ReportConfigEUTRA__triggerType_PR_event;
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
      ReportConfigEUTRA__triggerType__event__eventId_PR_eventA2;
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
    eventA2.a2_Threshold.present = ThresholdEUTRA_PR_threshold_RSRP;
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
    eventA2.a2_Threshold.choice.threshold_RSRP = 10;

    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerQuantity =
      ReportConfigEUTRA__triggerQuantity_rsrp;
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportInterval = ReportInterval_ms120;
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;

    ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A2);

    ReportConfig_A3->reportConfigId = 4;
    ReportConfig_A3->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.present =
      ReportConfigEUTRA__triggerType_PR_event;
    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
      ReportConfigEUTRA__triggerType__event__eventId_PR_eventA3;

    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA3.a3_Offset = 1;   //10;
    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
    eventA3.reportOnLeave = 1;

    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerQuantity =
      ReportConfigEUTRA__triggerQuantity_rsrp;
    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportInterval = ReportInterval_ms120;
    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;

    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.hysteresis = 0.5; // FIXME ...hysteresis is of type long!
    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.timeToTrigger =
      TimeToTrigger_ms40;
    ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A3);

    ReportConfig_A4->reportConfigId = 5;
    ReportConfig_A4->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.present =
      ReportConfigEUTRA__triggerType_PR_event;
    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
      ReportConfigEUTRA__triggerType__event__eventId_PR_eventA4;
    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
    eventA4.a4_Threshold.present = ThresholdEUTRA_PR_threshold_RSRP;
    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
    eventA4.a4_Threshold.choice.threshold_RSRP = 10;

    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerQuantity =
      ReportConfigEUTRA__triggerQuantity_rsrp;
    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportInterval = ReportInterval_ms120;
    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;

    ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A4);

    ReportConfig_A5->reportConfigId = 6;
    ReportConfig_A5->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.present =
      ReportConfigEUTRA__triggerType_PR_event;
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
      ReportConfigEUTRA__triggerType__event__eventId_PR_eventA5;
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
    eventA5.a5_Threshold1.present = ThresholdEUTRA_PR_threshold_RSRP;
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
    eventA5.a5_Threshold2.present = ThresholdEUTRA_PR_threshold_RSRP;
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
    eventA5.a5_Threshold1.choice.threshold_RSRP = 10;
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
    eventA5.a5_Threshold2.choice.threshold_RSRP = 10;

    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerQuantity =
      ReportConfigEUTRA__triggerQuantity_rsrp;
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportInterval = ReportInterval_ms120;
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;

    ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A5);
    //  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->reportConfigToAddModList = ReportConfig_list;

    rsrp = CALLOC(1, sizeof(RSRP_Range_t));
    *rsrp = 20;

    Sparams = CALLOC(1, sizeof(*Sparams));
    Sparams->present = MeasConfig__speedStatePars_PR_setup;
    Sparams->choice.setup.timeToTrigger_SF.sf_High = SpeedStateScaleFactors__sf_Medium_oDot75;
    Sparams->choice.setup.timeToTrigger_SF.sf_Medium = SpeedStateScaleFactors__sf_High_oDot5;
    Sparams->choice.setup.mobilityStateParameters.n_CellChangeHigh = 10;
    Sparams->choice.setup.mobilityStateParameters.n_CellChangeMedium = 5;
    Sparams->choice.setup.mobilityStateParameters.t_Evaluation = MobilityStateParameters__t_Evaluation_s60;
    Sparams->choice.setup.mobilityStateParameters.t_HystNormal = MobilityStateParameters__t_HystNormal_s120;

    quantityConfig = CALLOC(1, sizeof(*quantityConfig));
    memset((void *)quantityConfig, 0, sizeof(*quantityConfig));
    quantityConfig->quantityConfigEUTRA = CALLOC(1, sizeof(struct QuantityConfigEUTRA));
    memset((void *)quantityConfig->quantityConfigEUTRA, 0, sizeof(*quantityConfig->quantityConfigEUTRA));
    quantityConfig->quantityConfigCDMA2000 = NULL;
    quantityConfig->quantityConfigGERAN = NULL;
    quantityConfig->quantityConfigUTRA = NULL;
    quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP =
      CALLOC(1, sizeof(*(quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP)));
    quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ =
      CALLOC(1, sizeof(*(quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ)));
    *quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP = FilterCoefficient_fc4;
    *quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ = FilterCoefficient_fc4;

    LOG_I(RRC,
          "[eNB %d] Frame %d: potential handover preparation: store the information in an intermediate structure in case of failure\n",
          ctxt_pP->module_id, ctxt_pP->frame);
    // store the information in an intermediate structure for Hanodver management
    //rrc_inst->handover_info.as_config.sourceRadioResourceConfig.srb_ToAddModList = CALLOC(1,sizeof());
    ue_context_pP->ue_context.handover_info = CALLOC(1, sizeof(*(ue_context_pP->ue_context.handover_info)));
    //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.srb_ToAddModList,(void *)SRB_list,sizeof(SRB_ToAddModList_t));
    ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.srb_ToAddModList = *SRB_configList2;
    //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.drb_ToAddModList,(void *)DRB_list,sizeof(DRB_ToAddModList_t));
    ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.drb_ToAddModList = DRB_configList;
    ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.drb_ToReleaseList = NULL;
    ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig =
      CALLOC(1, sizeof(*ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig));
    memcpy((void*)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig,
           (void *)ue_context_pP->ue_context.mac_MainConfig, sizeof(MAC_MainConfig_t));
    ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.physicalConfigDedicated =
      CALLOC(1, sizeof(PhysicalConfigDedicated_t));
    memcpy((void*)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.physicalConfigDedicated,
           (void*)ue_context_pP->ue_context.physicalConfigDedicated, sizeof(PhysicalConfigDedicated_t));
    ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.sps_Config = NULL;
    //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.sps_Config,(void *)rrc_inst->sps_Config[ue_mod_idP],sizeof(SPS_Config_t));

  }

#ifdef CBA
  //struct PUSCH_CBAConfigDedicated_vlola  *pusch_CBAConfigDedicated_vlola;
  uint8_t                            *cba_RNTI_buf;
  cba_RNTI = CALLOC(1, sizeof(C_RNTI_t));
  cba_RNTI_buf = CALLOC(1, 2 * sizeof(uint8_t));
  cba_RNTI->buf = cba_RNTI_buf;
  cba_RNTI->size = 2;
  cba_RNTI->bits_unused = 0;

  // associate UEs to the CBa groups as a function of their UE id
  if (rrc_inst->num_active_cba_groups) {
    cba_RNTI->buf[0] = rrc_inst->cba_rnti[ue_mod_idP % rrc_inst->num_active_cba_groups] & 0xff;
    cba_RNTI->buf[1] = 0xff;
    LOG_D(RRC,
          "[eNB %d] Frame %d: cba_RNTI = %x in group %d is attribued to UE %d\n",
          enb_mod_idP, frameP,
          rrc_inst->cba_rnti[ue_mod_idP % rrc_inst->num_active_cba_groups],
          ue_mod_idP % rrc_inst->num_active_cba_groups, ue_mod_idP);
  } else {
    cba_RNTI->buf[0] = 0x0;
    cba_RNTI->buf[1] = 0x0;
    LOG_D(RRC, "[eNB %d] Frame %d: no cba_RNTI is configured for UE %d\n", enb_mod_idP, frameP, ue_mod_idP);
  }

#endif

#if defined(ENABLE_ITTI)
  /* Initialize NAS list */
  dedicatedInfoNASList = CALLOC(1, sizeof(struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList));

  /* Add all NAS PDUs to the list */
  for (i = 0; i < ue_context_pP->ue_context.nb_of_e_rabs; i++) {
    if (ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer != NULL) {
      dedicatedInfoNas = CALLOC(1, sizeof(DedicatedInfoNAS_t));
      memset(dedicatedInfoNas, 0, sizeof(OCTET_STRING_t));
      OCTET_STRING_fromBuf(dedicatedInfoNas,
         (char*)ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer,
                           ue_context_pP->ue_context.e_rab[i].param.nas_pdu.length);
      LOG_D(RRC, "Add dedicatedInfoNas(%d) to dedicatedInfoNASList\n", i);
      ASN_SEQUENCE_ADD(&dedicatedInfoNASList->list, dedicatedInfoNas);
    }

    /* TODO parameters yet to process ... */
    {
      //      ue_context_pP->ue_context.e_rab[i].param.qos;
      //      ue_context_pP->ue_context.e_rab[i].param.sgw_addr;
      //      ue_context_pP->ue_context.e_rab[i].param.gtp_teid;
    }

    /* TODO should test if e RAB are Ok before! */
    ue_context_pP->ue_context.e_rab[i].status = E_RAB_STATUS_DONE;
1921
    ue_context_pP->ue_context.e_rab[i].xid    = xid;
1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958
    LOG_D(RRC, "setting the status for the default DRB (index %d) to (%d,%s)\n",
    i, ue_context_pP->ue_context.e_rab[i].status, "E_RAB_STATUS_DONE");
  }

  /* If list is empty free the list and reset the address */
  if (dedicatedInfoNASList->list.count == 0) {
    free(dedicatedInfoNASList);
    dedicatedInfoNASList = NULL;
  }

#endif

  // send RRCConnectionReconfiguration
  memset(buffer, 0, RRC_BUF_SIZE);

  size = do_RRCConnectionReconfiguration(ctxt_pP,
                                         buffer,
                                         next_xid,   //Transaction_id,
                                         (SRB_ToAddModList_t*)*SRB_configList2, // SRB_configList
                                         (DRB_ToAddModList_t*)DRB_configList,
                                         (DRB_ToReleaseList_t*)NULL,  // DRB2_list,
                                         (struct SPS_Config*)NULL,    // maybe ue_context_pP->ue_context.sps_Config,
                                         (struct PhysicalConfigDedicated*)ue_context_pP->ue_context.physicalConfigDedicated,
#ifdef EXMIMO_IOT
                                         NULL, NULL, NULL,NULL,
#else
                                         (MeasObjectToAddModList_t*)MeasObj_list,  // MeasObj_list,
                                         (ReportConfigToAddModList_t*)ReportConfig_list,  // ReportConfig_list,
                                         (QuantityConfig_t*)quantityConfig,  //quantityConfig,
                                         (MeasIdToAddModList_t*)NULL,
#endif
                                         (MAC_MainConfig_t*)ue_context_pP->ue_context.mac_MainConfig,
                                         (MeasGapConfig_t*)NULL,
                                         (MobilityControlInfo_t*)NULL,
                                         (struct MeasConfig__speedStatePars*)Sparams, // Sparams,
                                         (RSRP_Range_t*)rsrp, // rsrp,
                                         (C_RNTI_t*)cba_RNTI,  // cba_RNTI
1959 1960 1961
                                         (struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList*)dedicatedInfoNASList, //dedicatedInfoNASList
                                         (SL_CommConfig_r12_t*)NULL,
                                         (SL_DiscConfig_r12_t*)NULL
1962
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
1963 1964 1965
                                         , (SCellToAddMod_r10_t*)NULL
#endif
                                        );
1966 1967
  LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)buffer,size,
              "[MSG] RRC Connection Reconfiguration\n");
1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981


#if defined(ENABLE_ITTI)

  /* Free all NAS PDUs */
  for (i = 0; i < ue_context_pP->ue_context.nb_of_e_rabs; i++) {
    if (ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer != NULL) {
      /* Free the NAS PDU buffer and invalidate it */
      free(ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer);
      ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer = NULL;
    }
  }

#endif
1982 1983 1984 1985 1986 1987 1988 1989
  if(size==65535){
    LOG_E(RRC,"RRC decode err!!! do_RRCConnectionReconfiguration\n");
    put_UE_in_freelist(ctxt_pP->module_id, reestablish_rnti, 0);
    return;
  }else{
    LOG_I(RRC,
          "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate RRCConnectionReconfiguration (bytes %d, UE id %x)\n",
          ctxt_pP->module_id, ctxt_pP->frame, size, ue_context_pP->ue_context.rnti);
1990

1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014
    LOG_D(RRC,
          "[FRAME %05d][RRC_eNB][MOD %u][][--- PDCP_DATA_REQ/%d Bytes (rrcConnectionReconfiguration to UE %x MUI %d) --->][PDCP][MOD %u][RB %u]\n",
          ctxt_pP->frame, ctxt_pP->module_id, size, ue_context_pP->ue_context.rnti, rrc_eNB_mui, ctxt_pP->module_id, DCCH);

    MSC_LOG_TX_MESSAGE(
      MSC_RRC_ENB,
      MSC_RRC_UE,
      buffer,
      size,
      MSC_AS_TIME_FMT" rrcConnectionReconfiguration UE %x MUI %d size %u",
      MSC_AS_TIME_ARGS(ctxt_pP),
      ue_context_pP->ue_context.rnti,
      rrc_eNB_mui,
      size);

    rrc_data_req(
           ctxt_pP,
           DCCH,
           rrc_eNB_mui++,
           SDU_CONFIRM_NO,
           size,
           buffer,
           PDCP_TRANSMISSION_MODE_CONTROL);
  }
2015
  // delete UE data of prior RNTI.  UE use current RNTI.
2016 2017 2018 2019 2020 2021 2022 2023 2024
//  protocol_ctxt_t ctxt_prior = *ctxt_pP;
//  ctxt_prior.rnti = reestablish_rnti;
//
//  LTE_eNB_ULSCH_t *ulsch = NULL;
//  nfapi_ul_config_request_body_t *ul_req_tmp = NULL;
//  PHY_VARS_eNB *eNB_PHY = NULL;
//  eNB_MAC_INST *eNB_MAC = RC.mac[ctxt_prior.module_id];
//  for (int CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
//    eNB_PHY = RC.eNB[ctxt_prior.module_id][CC_id];
2025
//    for (int i=0; i<MAX_MOBILES_PER_ENB; i++) {
2026 2027
//      ulsch = eNB_PHY->ulsch[i];
//      if((ulsch != NULL) && (ulsch->rnti == ctxt_prior.rnti)){
2028
//        void clean_eNb_ulsch(LTE_eNB_ULSCH_t *ulsch);
2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056
//        LOG_I(RRC, "clean_eNb_ulsch UE %x \n", ctxt_prior.rnti);
//        clean_eNb_ulsch(ulsch);
//        break;
//      }
//    }
//
//    for(int j = 0; j < 10; j++){
//      ul_req_tmp = &eNB_MAC->UL_req_tmp[CC_id][j].ul_config_request_body;
//      if(ul_req_tmp){
//        int pdu_number = ul_req_tmp->number_of_pdus;
//        for(int pdu_index = pdu_number-1; pdu_index >= 0; pdu_index--){
//          if(ul_req_tmp->ul_config_pdu_list[pdu_index].ulsch_pdu.ulsch_pdu_rel8.rnti == ctxt_prior.rnti){
//            LOG_I(RRC, "remove UE %x from ul_config_pdu_list %d/%d\n", ctxt_prior.rnti, pdu_index, pdu_number);
//            if(pdu_index < pdu_number -1){
//               memcpy(&ul_req_tmp->ul_config_pdu_list[pdu_index], &ul_req_tmp->ul_config_pdu_list[pdu_index+1], (pdu_number-1-pdu_index) * sizeof(nfapi_ul_config_request_pdu_t));
//            }
//            ul_req_tmp->number_of_pdus--;
//          }
//        }
//      }
//    }
//  }
//  rrc_mac_remove_ue(ctxt_prior.module_id, ctxt_prior.rnti);
//  rrc_rlc_remove_ue(&ctxt_prior);
//  pdcp_remove_UE(&ctxt_prior);
  // add UE info to freeList for RU_thread to remove the UE instead of remove it here
  LOG_I(RRC, "[RRCConnectionReestablishment]put UE %x into freeList\n", reestablish_rnti);
  put_UE_in_freelist(ctxt_pP->module_id, reestablish_rnti, 0);
2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067
}

//-----------------------------------------------------------------------------
void
rrc_eNB_generate_RRCConnectionReestablishmentReject(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t*          const ue_context_pP,
  const int                    CC_id
)
//-----------------------------------------------------------------------------
{
2068 2069 2070
 if ( (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_eNB_CU) &&
       (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_ng_eNB_CU)&& 
       (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_gNB_CU)   ) {
2071
  int UE_id = find_UE_id(ctxt_pP->module_id, ctxt_pP->rnti);
2072 2073 2074 2075 2076 2077 2078 2079
  if(UE_id != -1){
    RC.mac[ctxt_pP->module_id]->UE_list.UE_sched_ctrl[UE_id].ue_reestablishment_reject_timer = 1;
    RC.mac[ctxt_pP->module_id]->UE_list.UE_sched_ctrl[UE_id].ue_reestablishment_reject_timer_thres = 20;
  }else{
    LOG_E(RRC,
            PROTOCOL_RRC_CTXT_UE_FMT" Generating RRCConnectionReestablishmentReject without UE_id(MAC) rnti %x\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ctxt_pP->rnti);
  }
2080
 }
2081 2082 2083
  T(T_ENB_RRC_CONNECTION_REESTABLISHMENT_REJECT, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

2084 2085 2086
  eNB_RRC_UE_t *ue_p = &ue_context_pP->ue_context; 

  ue_p->Srb0.Tx_buffer.payload_size =
2087
    do_RRCConnectionReestablishmentReject(ctxt_pP->module_id,
2088
                          (uint8_t*) ue_p->Srb0.Tx_buffer.Payload);
2089

2090
  LOG_DUMPMSG(RRC,DEBUG_RRC,
2091 2092
              (char *)(ue_p->Srb0.Tx_buffer.Payload),
              ue_p->Srb0.Tx_buffer.payload_size,
2093
              "[MSG] RRCConnectionReestablishmentReject\n");
2094 2095 2096 2097 2098


  MSC_LOG_TX_MESSAGE(
    MSC_RRC_ENB,
    MSC_RRC_UE,
2099 2100
    ue_p->Srb0.Tx_buffer.Header,
    ue_p->Srb0.Tx_buffer.payload_size,
2101 2102 2103
    MSC_AS_TIME_FMT" RRCConnectionReestablishmentReject UE %x size %u",
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP == NULL ? -1 : ue_context_pP->ue_context.rnti,
2104
    ue_p->Srb0.Tx_buffer.payload_size);
2105 2106 2107 2108

  LOG_I(RRC,
        PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel DL-CCCH, Generating RRCConnectionReestablishmentReject (bytes %d)\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
2109
        ue_p->Srb0.Tx_buffer.payload_size);
2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128
}

//-----------------------------------------------------------------------------
void
rrc_eNB_generate_RRCConnectionRelease(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t*          const ue_context_pP
)
//-----------------------------------------------------------------------------
{

  uint8_t                             buffer[RRC_BUF_SIZE];
  uint16_t                            size;

  T(T_ENB_RRC_CONNECTION_RELEASE, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

  memset(buffer, 0, RRC_BUF_SIZE);
  size = do_RRCConnectionRelease(ctxt_pP->module_id, buffer,rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id));
2129
  // set release timer
2130 2131 2132 2133
  //ue_context_pP->ue_context.ue_release_timer=1;
  // remove UE after 10 frames after RRCConnectionRelease is triggered
  //ue_context_pP->ue_context.ue_release_timer_thres=100;
    // set release timer
2134
//  ue_context_pP->ue_context.ue_release_timer_rrc = 1;
2135
  // remove UE after 10 frames after RRCConnectionRelease is triggered
2136
//  ue_context_pP->ue_context.ue_release_timer_thres_rrc = 100;
2137 2138
  ue_context_pP->ue_context.ue_reestablishment_timer = 0;
  ue_context_pP->ue_context.ue_release_timer = 0;
wujing's avatar
wujing committed
2139
  //ue_context_pP->ue_context.ue_release_timer_s1 = 0;
2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161
  LOG_I(RRC,
        PROTOCOL_RRC_CTXT_UE_FMT" Logical Channel DL-DCCH, Generate RRCConnectionRelease (bytes %d)\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
        size);

  LOG_D(RRC,
        PROTOCOL_RRC_CTXT_UE_FMT" --- PDCP_DATA_REQ/%d Bytes (rrcConnectionRelease MUI %d) --->[PDCP][RB %u]\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
        size,
        rrc_eNB_mui,
        DCCH);

  MSC_LOG_TX_MESSAGE(
    MSC_RRC_ENB,
    MSC_RRC_UE,
    buffer,
    size,
    MSC_AS_TIME_FMT" rrcConnectionRelease UE %x MUI %d size %u",
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP->ue_context.rnti,
    rrc_eNB_mui,
    size);
2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172
  pthread_mutex_lock(&rrc_release_freelist);
  for(uint16_t release_num = 0;release_num < NUMBER_OF_UE_MAX;release_num++){
    if(rrc_release_info.RRC_release_ctrl[release_num].flag == 0){
      if(ue_context_pP->ue_context.ue_release_timer_s1 > 0){
        rrc_release_info.RRC_release_ctrl[release_num].flag = 1;
      }else{
        rrc_release_info.RRC_release_ctrl[release_num].flag = 2;
      }
      rrc_release_info.RRC_release_ctrl[release_num].rnti = ctxt_pP->rnti;
      rrc_release_info.RRC_release_ctrl[release_num].rrc_eNB_mui = rrc_eNB_mui;
      rrc_release_info.num_UEs++;
wujing's avatar
wujing committed
2173 2174
      LOG_D(RRC,"Generate DLSCH Release send: index %d rnti %x mui %d flag %d \n",release_num,
             ctxt_pP->rnti, rrc_eNB_mui,rrc_release_info.RRC_release_ctrl[release_num].flag);
2175 2176 2177 2178
      break;
    }
  }
  pthread_mutex_unlock(&rrc_release_freelist);
2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313
  rrc_data_req(
	       ctxt_pP,
	       DCCH,
	       rrc_eNB_mui++,
	       SDU_CONFIRM_NO,
	       size,
	       buffer,
	       PDCP_TRANSMISSION_MODE_CONTROL);
}

uint8_t qci_to_priority[9]={2,4,3,5,1,6,7,8,9};

// TBD: this directive can be remived if we create a similar e_rab_param_t structure in RRC context
#if defined(ENABLE_ITTI) 
//-----------------------------------------------------------------------------
void
rrc_eNB_generate_dedicatedRRCConnectionReconfiguration(const protocol_ctxt_t* const ctxt_pP,
						     rrc_eNB_ue_context_t*          const ue_context_pP,
						     const uint8_t                ho_state
						     )
//-----------------------------------------------------------------------------
{
  
  uint8_t                             buffer[RRC_BUF_SIZE];
  uint16_t                            size;
  int i;
  
  struct DRB_ToAddMod                *DRB_config                       = NULL;
  struct RLC_Config                  *DRB_rlc_config                   = NULL;
  struct PDCP_Config                 *DRB_pdcp_config                  = NULL;
  struct PDCP_Config__rlc_AM         *PDCP_rlc_AM                      = NULL;
  struct PDCP_Config__rlc_UM         *PDCP_rlc_UM                      = NULL;
  struct LogicalChannelConfig        *DRB_lchan_config                 = NULL;
  struct LogicalChannelConfig__ul_SpecificParameters
    *DRB_ul_SpecificParameters        = NULL;
  //  DRB_ToAddModList_t**                DRB_configList=&ue_context_pP->ue_context.DRB_configList; 
  DRB_ToAddModList_t*                DRB_configList=ue_context_pP->ue_context.DRB_configList; 
  DRB_ToAddModList_t**                DRB_configList2=NULL;
  //DRB_ToAddModList_t**                RRC_DRB_configList=&ue_context_pP->ue_context.DRB_configList;

  struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList = NULL;
  DedicatedInfoNAS_t                 *dedicatedInfoNas                 = NULL;
  /* for no gcc warnings */
  (void)dedicatedInfoNas;

  long  *logicalchannelgroup_drb;
//  int drb_identity_index=0;

  uint8_t xid = rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id);   //Transaction_id,
  DRB_configList2=&ue_context_pP->ue_context.DRB_configList2[xid];
  if (*DRB_configList2) {
    free(*DRB_configList2);
  }
  //*DRB_configList = CALLOC(1, sizeof(*DRB_configList));
  *DRB_configList2 = CALLOC(1, sizeof(**DRB_configList2)); 
  /* Initialize NAS list */
  dedicatedInfoNASList = CALLOC(1, sizeof(struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList));

  int e_rab_done=0;
  
  for ( i = 0  ;
	i < ue_context_pP->ue_context.setup_e_rabs ;
	i++){

    if (e_rab_done >= ue_context_pP->ue_context.nb_of_e_rabs){
        break;
    }
    
    // bypass the new and already configured erabs
    if (ue_context_pP->ue_context.e_rab[i].status >= E_RAB_STATUS_DONE) {
//      drb_identity_index++;
      continue;
    }
        
    DRB_config = CALLOC(1, sizeof(*DRB_config));

    DRB_config->eps_BearerIdentity = CALLOC(1, sizeof(long));
    // allowed value 5..15, value : x+4
    *(DRB_config->eps_BearerIdentity) = ue_context_pP->ue_context.e_rab[i].param.e_rab_id;//+ 4; // especial case generation  

 //   DRB_config->drb_Identity =  1 + drb_identity_index + e_rab_done;// + i ;// (DRB_Identity_t) ue_context_pP->ue_context.e_rab[i].param.e_rab_id;
    // 1 + drb_identiy_index;  
    DRB_config->drb_Identity = i+1;

    DRB_config->logicalChannelIdentity = CALLOC(1, sizeof(long));
    *(DRB_config->logicalChannelIdentity) = DRB_config->drb_Identity + 2; //(long) (ue_context_pP->ue_context.e_rab[i].param.e_rab_id + 2); // value : x+2
    
    DRB_rlc_config = CALLOC(1, sizeof(*DRB_rlc_config));
    DRB_config->rlc_Config = DRB_rlc_config;

    DRB_pdcp_config = CALLOC(1, sizeof(*DRB_pdcp_config));
    DRB_config->pdcp_Config = DRB_pdcp_config;
    DRB_pdcp_config->discardTimer = CALLOC(1, sizeof(long));
    *DRB_pdcp_config->discardTimer = PDCP_Config__discardTimer_infinity;
    DRB_pdcp_config->rlc_AM = NULL;
    DRB_pdcp_config->rlc_UM = NULL;


    switch (ue_context_pP->ue_context.e_rab[i].param.qos.qci){
      /*
       * type: realtime data with medium packer error rate
       * action: swtich to RLC UM
       */
    case 1: // 100ms, 10^-2, p2, GBR
    case 2: // 150ms, 10^-3, p4, GBR
    case 3: // 50ms, 10^-3, p3, GBR
    case 4:  // 300ms, 10^-6, p5 
    case 7: // 100ms, 10^-3, p7, GBR
    case 9: // 300ms, 10^-6, p9
    case 65: // 75ms, 10^-2, p0.7, mission critical voice, GBR
    case 66: // 100ms, 10^-2, p2, non-mission critical  voice , GBR
      // RLC 
      DRB_rlc_config->present = RLC_Config_PR_um_Bi_Directional;
      DRB_rlc_config->choice.um_Bi_Directional.ul_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
      DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
      DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering = T_Reordering_ms35;
      // PDCP
      PDCP_rlc_UM = CALLOC(1, sizeof(*PDCP_rlc_UM));
      DRB_pdcp_config->rlc_UM = PDCP_rlc_UM;
      PDCP_rlc_UM->pdcp_SN_Size = PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits;
      break;
      
      /*
       * type: non-realtime data with low packer error rate
       * action: swtich to RLC AM
       */
    case 5:  // 100ms, 10^-6, p1 , IMS signaling 
    case 6:  // 300ms, 10^-6, p6 
    case 8: // 300ms, 10^-6, p8 
    case 69: // 60ms, 10^-6, p0.5, mission critical delay sensitive data, Lowest Priority 
    case 70: // 200ms, 10^-6, p5.5, mision critical data 
      // RLC
       DRB_rlc_config->present = RLC_Config_PR_am;
       DRB_rlc_config->choice.am.ul_AM_RLC.t_PollRetransmit = T_PollRetransmit_ms50;
       DRB_rlc_config->choice.am.ul_AM_RLC.pollPDU = PollPDU_p16;
2314 2315 2316 2317 2318 2319 2320 2321 2322 2323
       DRB_rlc_config->choice.am.ul_AM_RLC.pollByte = PollByte_kBinfinity;
       DRB_rlc_config->choice.am.ul_AM_RLC.maxRetxThreshold = UL_AM_RLC__maxRetxThreshold_t8;
       DRB_rlc_config->choice.am.dl_AM_RLC.t_Reordering = T_Reordering_ms35;
       DRB_rlc_config->choice.am.dl_AM_RLC.t_StatusProhibit = T_StatusProhibit_ms25;

       // PDCP
       PDCP_rlc_AM = CALLOC(1, sizeof(*PDCP_rlc_AM));
       DRB_pdcp_config->rlc_AM = PDCP_rlc_AM;
       PDCP_rlc_AM->statusReportRequired = FALSE;
       
2324 2325 2326 2327 2328
       break;
    default :
      LOG_E(RRC,"not supported qci %d\n", ue_context_pP->ue_context.e_rab[i].param.qos.qci);
      ue_context_pP->ue_context.e_rab[i].status = E_RAB_STATUS_FAILED; 
      ue_context_pP->ue_context.e_rab[i].xid = xid;
2329
      e_rab_done++;
2330
      continue;
2331 2332 2333 2334 2335 2336 2337 2338 2339
    }

    DRB_pdcp_config->headerCompression.present = PDCP_Config__headerCompression_PR_notUsed;
    
    DRB_lchan_config = CALLOC(1, sizeof(*DRB_lchan_config));
    DRB_config->logicalChannelConfig = DRB_lchan_config;
    DRB_ul_SpecificParameters = CALLOC(1, sizeof(*DRB_ul_SpecificParameters));
    DRB_lchan_config->ul_SpecificParameters = DRB_ul_SpecificParameters;

2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416
    if (ue_context_pP->ue_context.e_rab[i].param.qos.qci < 9 )
      DRB_ul_SpecificParameters->priority = qci_to_priority[ue_context_pP->ue_context.e_rab[i].param.qos.qci-1] + 3; 
    // ue_context_pP->ue_context.e_rab[i].param.qos.allocation_retention_priority.priority_level;
    else 
      DRB_ul_SpecificParameters->priority= 4;

    DRB_ul_SpecificParameters->prioritisedBitRate = LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_kBps8;
      //LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
    DRB_ul_SpecificParameters->bucketSizeDuration =
      LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
    
    logicalchannelgroup_drb = CALLOC(1, sizeof(long));
    *logicalchannelgroup_drb = 1;//(i+1) % 3;
    DRB_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup_drb;

    ASN_SEQUENCE_ADD(&DRB_configList->list, DRB_config);
    ASN_SEQUENCE_ADD(&(*DRB_configList2)->list, DRB_config);
    //ue_context_pP->ue_context.DRB_configList2[drb_identity_index] = &(*DRB_configList);
    
    LOG_I(RRC,"EPS ID %ld, DRB ID %ld (index %d), QCI %d, priority %ld, LCID %ld LCGID %ld \n",
	  *DRB_config->eps_BearerIdentity,
	  DRB_config->drb_Identity, i,
	  ue_context_pP->ue_context.e_rab[i].param.qos.qci,
	  DRB_ul_SpecificParameters->priority,
	  *(DRB_config->logicalChannelIdentity),
	  *DRB_ul_SpecificParameters->logicalChannelGroup	  
	  );

    e_rab_done++;
    ue_context_pP->ue_context.e_rab[i].status = E_RAB_STATUS_DONE; 
    ue_context_pP->ue_context.e_rab[i].xid = xid;
    
    {
      if (ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer != NULL) {
	dedicatedInfoNas = CALLOC(1, sizeof(DedicatedInfoNAS_t));
	memset(dedicatedInfoNas, 0, sizeof(OCTET_STRING_t));
	OCTET_STRING_fromBuf(dedicatedInfoNas, 
			     (char*)ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer,
			     ue_context_pP->ue_context.e_rab[i].param.nas_pdu.length);
	ASN_SEQUENCE_ADD(&dedicatedInfoNASList->list, dedicatedInfoNas);
	LOG_I(RRC,"add NAS info with size %d (rab id %d)\n",ue_context_pP->ue_context.e_rab[i].param.nas_pdu.length, i);
      } 
      else {
	LOG_W(RRC,"Not received activate dedicated EPS bearer context request\n");
      }
      /* TODO parameters yet to process ... */
      {
	//      ue_context_pP->ue_context.e_rab[i].param.qos;
	//      ue_context_pP->ue_context.e_rab[i].param.sgw_addr;
	//      ue_context_pP->ue_context.e_rab[i].param.gtp_teid;
      }
    }
    
  }

  /* If list is empty free the list and reset the address */
  if (dedicatedInfoNASList != NULL) {
    if (dedicatedInfoNASList->list.count == 0) {
      free(dedicatedInfoNASList);
      dedicatedInfoNASList = NULL;
      LOG_W(RRC,"dedlicated NAS list is empty, free the list and reset the address\n");
    }				
  } else {
    LOG_W(RRC,"dedlicated NAS list is empty\n");
  }

  memset(buffer, 0, RRC_BUF_SIZE);

   size = do_RRCConnectionReconfiguration(ctxt_pP,
					  buffer,
					  xid,
					  (SRB_ToAddModList_t*)NULL, 
					  (DRB_ToAddModList_t*)*DRB_configList2,
					  (DRB_ToReleaseList_t*)NULL,  // DRB2_list,
                                         (struct SPS_Config*)NULL,    // *sps_Config,
					  NULL, NULL, NULL, NULL,NULL,
					  NULL, NULL,  NULL, NULL, NULL, NULL, 
2417 2418 2419
					  (struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList*)dedicatedInfoNASList,
					  (SL_CommConfig_r12_t*)NULL,
					  (SL_DiscConfig_r12_t*)NULL
2420
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
2421 2422 2423 2424
                                         , (SCellToAddMod_r10_t*)NULL
#endif
                                        );
 
2425
  LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)buffer,size,"[MSG] RRC Connection Reconfiguration\n");
2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619


#if defined(ENABLE_ITTI)

  /* Free all NAS PDUs */
  for (i = 0; i < ue_context_pP->ue_context.nb_of_e_rabs; i++) {
    if (ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer != NULL) {
      /* Free the NAS PDU buffer and invalidate it */
      free(ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer);
      ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer = NULL;
    }
  }
#endif

 LOG_I(RRC,
        "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate RRCConnectionReconfiguration (bytes %d, UE RNTI %x)\n",
        ctxt_pP->module_id, ctxt_pP->frame, size, ue_context_pP->ue_context.rnti);

  LOG_D(RRC,
        "[FRAME %05d][RRC_eNB][MOD %u][][--- PDCP_DATA_REQ/%d Bytes (rrcConnectionReconfiguration to UE %x MUI %d) --->][PDCP][MOD %u][RB %u]\n",
        ctxt_pP->frame, ctxt_pP->module_id, size, ue_context_pP->ue_context.rnti, rrc_eNB_mui, ctxt_pP->module_id, DCCH);

  MSC_LOG_TX_MESSAGE(
    MSC_RRC_ENB,
    MSC_RRC_UE,
    buffer,
    size,
    MSC_AS_TIME_FMT" dedicated rrcConnectionReconfiguration UE %x MUI %d size %u",
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP->ue_context.rnti,
    rrc_eNB_mui,
    size);

  rrc_data_req(
    ctxt_pP,
    DCCH,
    rrc_eNB_mui++,
    SDU_CONFIRM_NO,
    size,
    buffer,
    PDCP_TRANSMISSION_MODE_CONTROL);


}
int
rrc_eNB_modify_dedicatedRRCConnectionReconfiguration(const protocol_ctxt_t* const ctxt_pP,
                             rrc_eNB_ue_context_t*          const ue_context_pP,
                             const uint8_t                ho_state
                             )
//-----------------------------------------------------------------------------
{
  uint8_t                             buffer[RRC_BUF_SIZE];
  uint16_t                            size;
  int i, j;

  struct DRB_ToAddMod                *DRB_config                       = NULL;
  struct RLC_Config                  *DRB_rlc_config                   = NULL;
  struct PDCP_Config                 *DRB_pdcp_config                  = NULL;
  struct PDCP_Config__rlc_AM         *PDCP_rlc_AM                      = NULL;
  struct PDCP_Config__rlc_UM         *PDCP_rlc_UM                      = NULL;
  struct LogicalChannelConfig        *DRB_lchan_config                 = NULL;
  struct LogicalChannelConfig__ul_SpecificParameters
  *DRB_ul_SpecificParameters        = NULL;
  DRB_ToAddModList_t*                 DRB_configList = ue_context_pP->ue_context.DRB_configList;
  DRB_ToAddModList_t*                DRB_configList2 = NULL;

  struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList = NULL;
  DedicatedInfoNAS_t                 *dedicatedInfoNas                 = NULL;
  /* for no gcc warnings */
  (void)dedicatedInfoNas;

  uint8_t xid = rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id);   // Transaction_id,
  DRB_configList2 = CALLOC(1, sizeof(*DRB_configList2));
  /* Initialize NAS list */
  dedicatedInfoNASList = CALLOC(1, sizeof(struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList));

  for (i = 0; i < ue_context_pP->ue_context.nb_of_modify_e_rabs; i++) {
    // bypass the new and already configured erabs
    if (ue_context_pP->ue_context.modify_e_rab[i].status >= E_RAB_STATUS_DONE) {
      ue_context_pP->ue_context.modify_e_rab[i].xid = xid;
      continue;
    }

    if (ue_context_pP->ue_context.modify_e_rab[i].cause != S1AP_CAUSE_NOTHING) {
      // set xid of failure RAB
      ue_context_pP->ue_context.modify_e_rab[i].xid = xid;
      ue_context_pP->ue_context.modify_e_rab[i].status = E_RAB_STATUS_FAILED;
      continue;
    }

    DRB_config = NULL;
    // search exist DRB_config
    for (j = 0; j < DRB_configList->list.count; j++) {
      if((uint8_t)*(DRB_configList->list.array[j]->eps_BearerIdentity) == ue_context_pP->ue_context.modify_e_rab[i].param.e_rab_id) {
        DRB_config = DRB_configList->list.array[j];
        break;
      }
    }
    if (NULL == DRB_config) {
      ue_context_pP->ue_context.modify_e_rab[i].xid = xid;
      ue_context_pP->ue_context.modify_e_rab[i].status = E_RAB_STATUS_FAILED;
      // TODO use which cause
      ue_context_pP->ue_context.modify_e_rab[i].cause = S1AP_CAUSE_RADIO_NETWORK;
      ue_context_pP->ue_context.modify_e_rab[i].cause_value = 0;//S1ap_CauseRadioNetwork_unspecified;
      ue_context_pP->ue_context.nb_of_failed_e_rabs++;
      continue;
    }

    DRB_rlc_config = DRB_config->rlc_Config;

    DRB_pdcp_config = DRB_config->pdcp_Config;
    *DRB_pdcp_config->discardTimer = PDCP_Config__discardTimer_infinity;
    switch (ue_context_pP->ue_context.modify_e_rab[i].param.qos.qci) {
    /*
     * type: realtime data with medium packer error rate
     * action: swtich to RLC UM
     */
    case 1: // 100ms, 10^-2, p2, GBR
    case 2: // 150ms, 10^-3, p4, GBR
    case 3: // 50ms, 10^-3, p3, GBR
    case 4:  // 300ms, 10^-6, p5
    case 7: // 100ms, 10^-3, p7, GBR
    case 9: // 300ms, 10^-6, p9
    case 65: // 75ms, 10^-2, p0.7, mission critical voice, GBR
    case 66: // 100ms, 10^-2, p2, non-mission critical  voice , GBR
      // RLC
      DRB_rlc_config->present = RLC_Config_PR_um_Bi_Directional;
      DRB_rlc_config->choice.um_Bi_Directional.ul_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
      DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
      DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering = T_Reordering_ms35;
      // PDCP
      if (DRB_pdcp_config->rlc_AM) {
        free(DRB_pdcp_config->rlc_AM);
        DRB_pdcp_config->rlc_AM = NULL;
      }
      if (DRB_pdcp_config->rlc_UM) {
        free(DRB_pdcp_config->rlc_UM);
        DRB_pdcp_config->rlc_UM = NULL;
      }
      PDCP_rlc_UM = CALLOC(1, sizeof(*PDCP_rlc_UM));
      DRB_pdcp_config->rlc_UM = PDCP_rlc_UM;
      PDCP_rlc_UM->pdcp_SN_Size = PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits;
      break;

    /*
     * type: non-realtime data with low packer error rate
     * action: swtich to RLC AM
     */
    case 5:  // 100ms, 10^-6, p1 , IMS signaling
    case 6:  // 300ms, 10^-6, p6
    case 8: // 300ms, 10^-6, p8
    case 69: // 60ms, 10^-6, p0.5, mission critical delay sensitive data, Lowest Priority
    case 70: // 200ms, 10^-6, p5.5, mision critical data
       // RLC
       DRB_rlc_config->present = RLC_Config_PR_am;
       DRB_rlc_config->choice.am.ul_AM_RLC.t_PollRetransmit = T_PollRetransmit_ms50;
       DRB_rlc_config->choice.am.ul_AM_RLC.pollPDU = PollPDU_p16;
       DRB_rlc_config->choice.am.ul_AM_RLC.pollByte = PollByte_kBinfinity;
       DRB_rlc_config->choice.am.ul_AM_RLC.maxRetxThreshold = UL_AM_RLC__maxRetxThreshold_t8;
       DRB_rlc_config->choice.am.dl_AM_RLC.t_Reordering = T_Reordering_ms35;
       DRB_rlc_config->choice.am.dl_AM_RLC.t_StatusProhibit = T_StatusProhibit_ms25;

       // PDCP
       if (DRB_pdcp_config->rlc_AM) {
         free(DRB_pdcp_config->rlc_AM);
         DRB_pdcp_config->rlc_AM = NULL;
       }
       if (DRB_pdcp_config->rlc_UM) {
         free(DRB_pdcp_config->rlc_UM);
         DRB_pdcp_config->rlc_UM = NULL;
       }
       PDCP_rlc_AM = CALLOC(1, sizeof(*PDCP_rlc_AM));
       DRB_pdcp_config->rlc_AM = PDCP_rlc_AM;
       PDCP_rlc_AM->statusReportRequired = FALSE;

       break;
    default :
      LOG_E(RRC, "not supported qci %d\n", ue_context_pP->ue_context.modify_e_rab[i].param.qos.qci);
      ue_context_pP->ue_context.modify_e_rab[i].status = E_RAB_STATUS_FAILED;
      ue_context_pP->ue_context.modify_e_rab[i].xid = xid;
      ue_context_pP->ue_context.modify_e_rab[i].cause = S1AP_CAUSE_RADIO_NETWORK;
      ue_context_pP->ue_context.modify_e_rab[i].cause_value = 37;//S1ap_CauseRadioNetwork_not_supported_QCI_value;
      ue_context_pP->ue_context.nb_of_failed_e_rabs++;
      continue;
    }

    DRB_pdcp_config->headerCompression.present = PDCP_Config__headerCompression_PR_notUsed;

    DRB_lchan_config = DRB_config->logicalChannelConfig;
    DRB_ul_SpecificParameters = DRB_lchan_config->ul_SpecificParameters;

    if (ue_context_pP->ue_context.modify_e_rab[i].param.qos.qci < 9 )
      DRB_ul_SpecificParameters->priority = qci_to_priority[ue_context_pP->ue_context.modify_e_rab[i].param.qos.qci-1] + 3;
    else
2620 2621 2622
      DRB_ul_SpecificParameters->priority= 4;

    DRB_ul_SpecificParameters->prioritisedBitRate = LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_kBps8;
2623

2624 2625
    DRB_ul_SpecificParameters->bucketSizeDuration =
      LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
2626

2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640
    ASN_SEQUENCE_ADD(&(DRB_configList2)->list, DRB_config);

    LOG_I(RRC, "EPS ID %ld, DRB ID %ld (index %d), QCI %d, priority %ld, LCID %ld LCGID %ld \n",
      *DRB_config->eps_BearerIdentity,
      DRB_config->drb_Identity, i,
      ue_context_pP->ue_context.modify_e_rab[i].param.qos.qci,
      DRB_ul_SpecificParameters->priority,
      *(DRB_config->logicalChannelIdentity),
      *DRB_ul_SpecificParameters->logicalChannelGroup
      );

    //e_rab_done++;
    ue_context_pP->ue_context.modify_e_rab[i].status = E_RAB_STATUS_DONE;
    ue_context_pP->ue_context.modify_e_rab[i].xid = xid;
2641

2642
    {
2643 2644 2645 2646 2647 2648 2649 2650
      if (ue_context_pP->ue_context.modify_e_rab[i].param.nas_pdu.buffer != NULL) {
        dedicatedInfoNas = CALLOC(1, sizeof(DedicatedInfoNAS_t));
        memset(dedicatedInfoNas, 0, sizeof(OCTET_STRING_t));
        OCTET_STRING_fromBuf(dedicatedInfoNas,
                 (char*)ue_context_pP->ue_context.modify_e_rab[i].param.nas_pdu.buffer,
                 ue_context_pP->ue_context.modify_e_rab[i].param.nas_pdu.length);
        ASN_SEQUENCE_ADD(&dedicatedInfoNASList->list, dedicatedInfoNas);
        LOG_I(RRC, "add NAS info with size %d (rab id %d)\n",ue_context_pP->ue_context.modify_e_rab[i].param.nas_pdu.length, i);
2651
      }
2652 2653
      else {
        LOG_W(RRC, "Not received activate dedicated EPS bearer context request\n");
2654
      }
2655 2656
    }
  }
2657 2658 2659 2660 2661 2662 2663

  /* If list is empty free the list and reset the address */
  if (dedicatedInfoNASList != NULL) {
    if (dedicatedInfoNASList->list.count == 0) {
      free(dedicatedInfoNASList);
      dedicatedInfoNASList = NULL;
      LOG_W(RRC,"dedlicated NAS list is empty, free the list and reset the address\n");
2664
    }
2665 2666 2667 2668
  } else {
    LOG_W(RRC,"dedlicated NAS list is empty\n");
  }

2669 2670
  memset(buffer, 0, RRC_BUF_SIZE);

2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682
   size = do_RRCConnectionReconfiguration(ctxt_pP,
					  buffer,
					  xid,
					  (SRB_ToAddModList_t*)NULL, 
					  (DRB_ToAddModList_t*)DRB_configList2,
					  (DRB_ToReleaseList_t*)NULL,  // DRB2_list,
                                         (struct SPS_Config*)NULL,    // *sps_Config,
					  NULL, NULL, NULL, NULL,NULL,
					  NULL, NULL,  NULL, NULL, NULL, NULL, 
					  (struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList*)dedicatedInfoNASList,
					  (SL_CommConfig_r12_t*)NULL,
					  (SL_DiscConfig_r12_t*)NULL
2683
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
2684
					  , (SCellToAddMod_r10_t*)NULL
2685
#endif
2686
   	   	   	   	   	  );
2687

2688 2689
  LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)buffer,size,
              "[MSG] RRC Connection Reconfiguration\n");
2690 2691 2692 2693

#if defined(ENABLE_ITTI)

  /* Free all NAS PDUs */
2694 2695
  for (i = 0; i < ue_context_pP->ue_context.nb_of_modify_e_rabs; i++) {
    if (ue_context_pP->ue_context.modify_e_rab[i].param.nas_pdu.buffer != NULL) {
2696
      /* Free the NAS PDU buffer and invalidate it */
2697 2698
      free(ue_context_pP->ue_context.modify_e_rab[i].param.nas_pdu.buffer);
      ue_context_pP->ue_context.modify_e_rab[i].param.nas_pdu.buffer = NULL;
2699 2700 2701 2702 2703
    }
  }
#endif

 LOG_I(RRC,
2704
        "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate RRCConnectionReconfiguration (bytes %d, UE RNTI %x)\n",
2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721
        ctxt_pP->module_id, ctxt_pP->frame, size, ue_context_pP->ue_context.rnti);

  LOG_D(RRC,
        "[FRAME %05d][RRC_eNB][MOD %u][][--- PDCP_DATA_REQ/%d Bytes (rrcConnectionReconfiguration to UE %x MUI %d) --->][PDCP][MOD %u][RB %u]\n",
        ctxt_pP->frame, ctxt_pP->module_id, size, ue_context_pP->ue_context.rnti, rrc_eNB_mui, ctxt_pP->module_id, DCCH);

  MSC_LOG_TX_MESSAGE(
    MSC_RRC_ENB,
    MSC_RRC_UE,
    buffer,
    size,
    MSC_AS_TIME_FMT" dedicated rrcConnectionReconfiguration UE %x MUI %d size %u",
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP->ue_context.rnti,
    rrc_eNB_mui,
    size);

2722
  rrc_data_req(
2723 2724 2725 2726 2727 2728 2729
    ctxt_pP,
    DCCH,
    rrc_eNB_mui++,
    SDU_CONFIRM_NO,
    size,
    buffer,
    PDCP_TRANSMISSION_MODE_CONTROL);
2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797
  return 0;
}

//-----------------------------------------------------------------------------
void
rrc_eNB_generate_dedicatedRRCConnectionReconfiguration_release(  const protocol_ctxt_t*   const ctxt_pP,
        rrc_eNB_ue_context_t*    const ue_context_pP,
        uint8_t                  xid,
        uint32_t                 nas_length,
        uint8_t*                 nas_buffer)
//-----------------------------------------------------------------------------
{
    uint8_t                             buffer[RRC_BUF_SIZE];
    int                                 i;
    uint16_t                            size  = 0;
    DRB_ToReleaseList_t**                DRB_Release_configList2=NULL;
    DRB_Identity_t* DRB_release;
    struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList = NULL;

    DRB_Release_configList2=&ue_context_pP->ue_context.DRB_Release_configList2[xid];
    if (*DRB_Release_configList2) {
      free(*DRB_Release_configList2);
    }
    *DRB_Release_configList2 = CALLOC(1, sizeof(**DRB_Release_configList2));

    for(i = 0; i < NB_RB_MAX; i++){
        if((ue_context_pP->ue_context.e_rab[i].status == E_RAB_STATUS_TORELEASE) && ue_context_pP->ue_context.e_rab[i].xid == xid){
            DRB_release = CALLOC(1, sizeof(DRB_Identity_t));
            *DRB_release = i+1;
            ASN_SEQUENCE_ADD(&(*DRB_Release_configList2)->list, DRB_release);
            //free(DRB_release);
        }
    }

    /* If list is empty free the list and reset the address */
    if (nas_length > 0) {
        DedicatedInfoNAS_t                 *dedicatedInfoNas                 = NULL;
        dedicatedInfoNASList = CALLOC(1, sizeof(struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList));
        dedicatedInfoNas = CALLOC(1, sizeof(DedicatedInfoNAS_t));
        memset(dedicatedInfoNas, 0, sizeof(OCTET_STRING_t));
                       OCTET_STRING_fromBuf(dedicatedInfoNas,
                              (char*)nas_buffer,
                              nas_length);
        ASN_SEQUENCE_ADD(&dedicatedInfoNASList->list, dedicatedInfoNas);
        LOG_I(RRC,"add NAS info with size %d\n",nas_length);
    } else {
      LOG_W(RRC,"dedlicated NAS list is empty\n");
    }

    memset(buffer, 0, RRC_BUF_SIZE);
    size = do_RRCConnectionReconfiguration(ctxt_pP,
                                    buffer,
                                    xid,
                                    NULL,
                                    NULL,
                                    (DRB_ToReleaseList_t*)*DRB_Release_configList2,
                                    NULL,
                                    NULL,
                                    NULL,
                                    NULL,
                                    NULL,
                                    NULL,
                                    NULL,
                                    NULL,
                                    NULL,
                                    NULL,
                                    NULL,
                                    NULL,
2798 2799 2800
                                    (struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList*)dedicatedInfoNASList,
                                    (SL_CommConfig_r12_t*)NULL,
                                    (SL_DiscConfig_r12_t*)NULL
2801
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
2802 2803 2804 2805
                                    , (SCellToAddMod_r10_t*)NULL
#endif
                                   );
    ue_context_pP->ue_context.e_rab_release_command_flag = 1;
2806 2807
    LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)buffer,size,
                "[MSG] RRC Connection Reconfiguration\n");
2808

2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834
#if defined(ENABLE_ITTI)
  /* Free all NAS PDUs */
  if (nas_length > 0) {
      /* Free the NAS PDU buffer and invalidate it */
      free(nas_buffer);
  }
#endif

  LOG_I(RRC,
        "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate RRCConnectionReconfiguration (bytes %d, UE RNTI %x)\n",
        ctxt_pP->module_id, ctxt_pP->frame, size, ue_context_pP->ue_context.rnti);

  LOG_D(RRC,
        "[FRAME %05d][RRC_eNB][MOD %u][][--- PDCP_DATA_REQ/%d Bytes (rrcConnectionReconfiguration to UE %x MUI %d) --->][PDCP][MOD %u][RB %u]\n",
        ctxt_pP->frame, ctxt_pP->module_id, size, ue_context_pP->ue_context.rnti, rrc_eNB_mui, ctxt_pP->module_id, DCCH);

  MSC_LOG_TX_MESSAGE(
    MSC_RRC_ENB,
    MSC_RRC_UE,
    buffer,
    size,
    MSC_AS_TIME_FMT" dedicated rrcConnectionReconfiguration UE %x MUI %d size %u",
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP->ue_context.rnti,
    rrc_eNB_mui,
    size);
2835

2836 2837 2838 2839 2840 2841 2842 2843
  rrc_data_req(
    ctxt_pP,
    DCCH,
    rrc_eNB_mui++,
    SDU_CONFIRM_NO,
    size,
    buffer,
    PDCP_TRANSMISSION_MODE_CONTROL);
2844 2845 2846 2847 2848 2849 2850 2851 2852

}
#endif 
//-----------------------------------------------------------------------------
void
rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt_t* const ctxt_pP,
						     rrc_eNB_ue_context_t*          const ue_context_pP,
						     const uint8_t                ho_state
						     )
2853
//-----------------------------------------------------------------------------
2854 2855 2856 2857 2858 2859
{
  uint8_t                             buffer[RRC_BUF_SIZE];
  uint16_t                            size;
  int                                 i;

  // configure SRB1/SRB2, PhysicalConfigDedicated, MAC_MainConfig for UE
2860
  eNB_RRC_INST*                       rrc_inst = RC.rrc[ctxt_pP->module_id];
2861
  struct PhysicalConfigDedicated**    physicalConfigDedicated = &ue_context_pP->ue_context.physicalConfigDedicated;
2862 2863 2864 2865 2866 2867

  struct SRB_ToAddMod                *SRB2_config                      = NULL;
  struct SRB_ToAddMod__rlc_Config    *SRB2_rlc_config                  = NULL;
  struct SRB_ToAddMod__logicalChannelConfig *SRB2_lchan_config         = NULL;
  struct LogicalChannelConfig__ul_SpecificParameters
      *SRB2_ul_SpecificParameters       = NULL;
2868
  SRB_ToAddModList_t*                 SRB_configList = ue_context_pP->ue_context.SRB_configList;
2869
  SRB_ToAddModList_t                 **SRB_configList2                  = NULL;
2870 2871 2872 2873 2874 2875 2876 2877 2878

  struct DRB_ToAddMod                *DRB_config                       = NULL;
  struct RLC_Config                  *DRB_rlc_config                   = NULL;
  struct PDCP_Config                 *DRB_pdcp_config                  = NULL;
  struct PDCP_Config__rlc_AM         *PDCP_rlc_AM                      = NULL;
  struct PDCP_Config__rlc_UM         *PDCP_rlc_UM                      = NULL;
  struct LogicalChannelConfig        *DRB_lchan_config                 = NULL;
  struct LogicalChannelConfig__ul_SpecificParameters
      *DRB_ul_SpecificParameters        = NULL;
2879
  DRB_ToAddModList_t**                DRB_configList = &ue_context_pP->ue_context.DRB_configList;
2880 2881
  DRB_ToAddModList_t**                DRB_configList2 = NULL;
   MAC_MainConfig_t                   *mac_MainConfig                   = NULL;
2882 2883 2884 2885 2886 2887 2888
  MeasObjectToAddModList_t           *MeasObj_list                     = NULL;
  MeasObjectToAddMod_t               *MeasObj                          = NULL;
  ReportConfigToAddModList_t         *ReportConfig_list                = NULL;
  ReportConfigToAddMod_t             *ReportConfig_per, *ReportConfig_A1,
                                     *ReportConfig_A2, *ReportConfig_A3, *ReportConfig_A4, *ReportConfig_A5;
  MeasIdToAddModList_t               *MeasId_list                      = NULL;
  MeasIdToAddMod_t                   *MeasId0, *MeasId1, *MeasId2, *MeasId3, *MeasId4, *MeasId5;
2889
#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
2890 2891
  long                               *sr_ProhibitTimer_r9              = NULL;
  //     uint8_t sCellIndexToAdd = rrc_find_free_SCell_index(enb_mod_idP, ue_mod_idP, 1);
2892
  //uint8_t                            sCellIndexToAdd = 0;
winckel's avatar
winckel committed
2893
#endif
2894

2895 2896
  long                               *logicalchannelgroup, *logicalchannelgroup_drb;
  long                               *maxHARQ_Tx, *periodicBSR_Timer;
2897

2898 2899 2900 2901 2902 2903 2904
  RSRP_Range_t                       *rsrp                             = NULL;
  struct MeasConfig__speedStatePars  *Sparams                          = NULL;
  QuantityConfig_t                   *quantityConfig                   = NULL;
  CellsToAddMod_t                    *CellToAdd                        = NULL;
  CellsToAddModList_t                *CellsToAddModList                = NULL;
  struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList = NULL;
  DedicatedInfoNAS_t                 *dedicatedInfoNas                 = NULL;
Cedric Roux's avatar
Cedric Roux committed
2905 2906
  /* for no gcc warnings */
  (void)dedicatedInfoNas;
2907

2908
  C_RNTI_t                           *cba_RNTI                         = NULL;
2909 2910 2911

  uint8_t xid = rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id);   //Transaction_id,

2912
#ifdef CBA
2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934
  //struct PUSCH_CBAConfigDedicated_vlola  *pusch_CBAConfigDedicated_vlola;
  uint8_t                            *cba_RNTI_buf;
  cba_RNTI = CALLOC(1, sizeof(C_RNTI_t));
  cba_RNTI_buf = CALLOC(1, 2 * sizeof(uint8_t));
  cba_RNTI->buf = cba_RNTI_buf;
  cba_RNTI->size = 2;
  cba_RNTI->bits_unused = 0;

  // associate UEs to the CBa groups as a function of their UE id
  if (rrc_inst->num_active_cba_groups) {
    cba_RNTI->buf[0] = rrc_inst->cba_rnti[ue_mod_idP % rrc_inst->num_active_cba_groups] & 0xff;
    cba_RNTI->buf[1] = 0xff;
    LOG_D(RRC,
          "[eNB %d] Frame %d: cba_RNTI = %x in group %d is attribued to UE %d\n",
          enb_mod_idP, frameP,
          rrc_inst->cba_rnti[ue_mod_idP % rrc_inst->num_active_cba_groups],
          ue_mod_idP % rrc_inst->num_active_cba_groups, ue_mod_idP);
  } else {
    cba_RNTI->buf[0] = 0x0;
    cba_RNTI->buf[1] = 0x0;
    LOG_D(RRC, "[eNB %d] Frame %d: no cba_RNTI is configured for UE %d\n", enb_mod_idP, frameP, ue_mod_idP);
  }
2935

2936
#endif
2937 2938 2939 2940

  T(T_ENB_RRC_CONNECTION_RECONFIGURATION, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

2941 2942
  // Configure SRB2
  /// SRB2
2943 2944 2945 2946 2947 2948
  SRB_configList2=&ue_context_pP->ue_context.SRB_configList2[xid];
  if (*SRB_configList2) {
    free(*SRB_configList2);
  }
  *SRB_configList2 = CALLOC(1, sizeof(**SRB_configList2));
  memset(*SRB_configList2, 0, sizeof(**SRB_configList2));
2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970
  SRB2_config = CALLOC(1, sizeof(*SRB2_config));

  SRB2_config->srb_Identity = 2;
  SRB2_rlc_config = CALLOC(1, sizeof(*SRB2_rlc_config));
  SRB2_config->rlc_Config = SRB2_rlc_config;

  SRB2_rlc_config->present = SRB_ToAddMod__rlc_Config_PR_explicitValue;
  SRB2_rlc_config->choice.explicitValue.present = RLC_Config_PR_am;
  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.t_PollRetransmit = T_PollRetransmit_ms15;
  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollPDU = PollPDU_p8;
  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollByte = PollByte_kB1000;
  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.maxRetxThreshold = UL_AM_RLC__maxRetxThreshold_t32;
  SRB2_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_Reordering = T_Reordering_ms35;
  SRB2_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_StatusProhibit = T_StatusProhibit_ms10;

  SRB2_lchan_config = CALLOC(1, sizeof(*SRB2_lchan_config));
  SRB2_config->logicalChannelConfig = SRB2_lchan_config;

  SRB2_lchan_config->present = SRB_ToAddMod__logicalChannelConfig_PR_explicitValue;

  SRB2_ul_SpecificParameters = CALLOC(1, sizeof(*SRB2_ul_SpecificParameters));

2971
  SRB2_ul_SpecificParameters->priority = 3; // let some priority for SRB1 and dedicated DRBs
2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983
  SRB2_ul_SpecificParameters->prioritisedBitRate =
    LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
  SRB2_ul_SpecificParameters->bucketSizeDuration =
    LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;

  // LCG for CCCH and DCCH is 0 as defined in 36331
  logicalchannelgroup = CALLOC(1, sizeof(long));
  *logicalchannelgroup = 0;

  SRB2_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup;

  SRB2_lchan_config->choice.explicitValue.ul_SpecificParameters = SRB2_ul_SpecificParameters;
Navid Nikaein's avatar
Navid Nikaein committed
2984
  // this list has the configuration for SRB1 and SRB2
2985
  ASN_SEQUENCE_ADD(&SRB_configList->list, SRB2_config);
Navid Nikaein's avatar
Navid Nikaein committed
2986
  // this list has only the configuration for SRB2
2987
  ASN_SEQUENCE_ADD(&(*SRB_configList2)->list, SRB2_config);
2988 2989 2990

  // Configure DRB
  //*DRB_configList = CALLOC(1, sizeof(*DRB_configList));
2991
  // list for all the configured DRB
2992 2993 2994
  if (*DRB_configList) {
    free(*DRB_configList);
  }
2995
  *DRB_configList = CALLOC(1, sizeof(**DRB_configList));
2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006
  memset(*DRB_configList, 0, sizeof(**DRB_configList));

  // list for the configured DRB for a this xid
  DRB_configList2=&ue_context_pP->ue_context.DRB_configList2[xid];
  if (*DRB_configList2) {
    free(*DRB_configList2);
  }
  *DRB_configList2 = CALLOC(1, sizeof(**DRB_configList2));
  memset(*DRB_configList2, 0, sizeof(**DRB_configList2));


3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018
  /// DRB
  DRB_config = CALLOC(1, sizeof(*DRB_config));

  DRB_config->eps_BearerIdentity = CALLOC(1, sizeof(long));
  *(DRB_config->eps_BearerIdentity) = 5L; // LW set to first value, allowed value 5..15, value : x+4
  // DRB_config->drb_Identity = (DRB_Identity_t) 1; //allowed values 1..32
  // NN: this is the 1st DRB for this ue, so set it to 1
  DRB_config->drb_Identity = (DRB_Identity_t) 1;  // (ue_mod_idP+1); //allowed values 1..32, value: x
  DRB_config->logicalChannelIdentity = CALLOC(1, sizeof(long));
  *(DRB_config->logicalChannelIdentity) = (long)3; // value : x+2
  DRB_rlc_config = CALLOC(1, sizeof(*DRB_rlc_config));
  DRB_config->rlc_Config = DRB_rlc_config;
winckel's avatar
winckel committed
3019

3020
#ifdef RRC_DEFAULT_RAB_IS_AM
3021 3022 3023 3024 3025 3026 3027
  DRB_rlc_config->present = RLC_Config_PR_am;
  DRB_rlc_config->choice.am.ul_AM_RLC.t_PollRetransmit = T_PollRetransmit_ms50;
  DRB_rlc_config->choice.am.ul_AM_RLC.pollPDU = PollPDU_p16;
  DRB_rlc_config->choice.am.ul_AM_RLC.pollByte = PollByte_kBinfinity;
  DRB_rlc_config->choice.am.ul_AM_RLC.maxRetxThreshold = UL_AM_RLC__maxRetxThreshold_t8;
  DRB_rlc_config->choice.am.dl_AM_RLC.t_Reordering = T_Reordering_ms35;
  DRB_rlc_config->choice.am.dl_AM_RLC.t_StatusProhibit = T_StatusProhibit_ms25;
3028
#else
3029 3030 3031
  DRB_rlc_config->present = RLC_Config_PR_um_Bi_Directional;
  DRB_rlc_config->choice.um_Bi_Directional.ul_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
3032
#ifdef CBA
3033
  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering   = T_Reordering_ms5;//T_Reordering_ms25;
3034 3035 3036
#else
  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering = T_Reordering_ms35;
#endif
3037
#endif
3038

3039 3040 3041 3042 3043 3044
  DRB_pdcp_config = CALLOC(1, sizeof(*DRB_pdcp_config));
  DRB_config->pdcp_Config = DRB_pdcp_config;
  DRB_pdcp_config->discardTimer = CALLOC(1, sizeof(long));
  *DRB_pdcp_config->discardTimer = PDCP_Config__discardTimer_infinity;
  DRB_pdcp_config->rlc_AM = NULL;
  DRB_pdcp_config->rlc_UM = NULL;
3045

Cedric Roux's avatar
Cedric Roux committed
3046 3047
  /* avoid gcc warnings */
  (void)PDCP_rlc_AM;
Cedric Roux's avatar
Cedric Roux committed
3048
  (void)PDCP_rlc_UM;
Cedric Roux's avatar
Cedric Roux committed
3049

3050
#ifdef RRC_DEFAULT_RAB_IS_AM // EXMIMO_IOT
3051 3052 3053
  PDCP_rlc_AM = CALLOC(1, sizeof(*PDCP_rlc_AM));
  DRB_pdcp_config->rlc_AM = PDCP_rlc_AM;
  PDCP_rlc_AM->statusReportRequired = FALSE;
3054
#else
3055 3056 3057
  PDCP_rlc_UM = CALLOC(1, sizeof(*PDCP_rlc_UM));
  DRB_pdcp_config->rlc_UM = PDCP_rlc_UM;
  PDCP_rlc_UM->pdcp_SN_Size = PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits;
3058
#endif
3059
  DRB_pdcp_config->headerCompression.present = PDCP_Config__headerCompression_PR_notUsed;
3060

3061 3062 3063 3064
  DRB_lchan_config = CALLOC(1, sizeof(*DRB_lchan_config));
  DRB_config->logicalChannelConfig = DRB_lchan_config;
  DRB_ul_SpecificParameters = CALLOC(1, sizeof(*DRB_ul_SpecificParameters));
  DRB_lchan_config->ul_SpecificParameters = DRB_ul_SpecificParameters;
3065

3066 3067 3068
  DRB_ul_SpecificParameters->priority = 12;    // lower priority than srb1, srb2 and other dedicated bearer
  DRB_ul_SpecificParameters->prioritisedBitRate =LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_kBps8 ;
    //LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
3069 3070
  DRB_ul_SpecificParameters->bucketSizeDuration =
    LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
3071

3072 3073 3074 3075
  // LCG for DTCH can take the value from 1 to 3 as defined in 36331: normally controlled by upper layers (like RRM)
  logicalchannelgroup_drb = CALLOC(1, sizeof(long));
  *logicalchannelgroup_drb = 1;
  DRB_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup_drb;
winckel's avatar
RRC:  
winckel committed
3076

3077
  ASN_SEQUENCE_ADD(&(*DRB_configList)->list, DRB_config);
3078 3079
  ASN_SEQUENCE_ADD(&(*DRB_configList2)->list, DRB_config);

3080
  //ue_context_pP->ue_context.DRB_configList2[0] = &(*DRB_configList);
winckel's avatar
RRC:  
winckel committed
3081

3082
  mac_MainConfig = CALLOC(1, sizeof(*mac_MainConfig));
3083
  ue_context_pP->ue_context.mac_MainConfig = mac_MainConfig;
winckel's avatar
RRC:  
winckel committed
3084

3085
  mac_MainConfig->ul_SCH_Config = CALLOC(1, sizeof(*mac_MainConfig->ul_SCH_Config));
3086

3087 3088 3089 3090
  maxHARQ_Tx = CALLOC(1, sizeof(long));
  *maxHARQ_Tx = MAC_MainConfig__ul_SCH_Config__maxHARQ_Tx_n5;
  mac_MainConfig->ul_SCH_Config->maxHARQ_Tx = maxHARQ_Tx;
  periodicBSR_Timer = CALLOC(1, sizeof(long));
Cedric Roux's avatar
Cedric Roux committed
3091
  *periodicBSR_Timer = PeriodicBSR_Timer_r12_sf64;
3092
  mac_MainConfig->ul_SCH_Config->periodicBSR_Timer = periodicBSR_Timer;
Cedric Roux's avatar
Cedric Roux committed
3093
  mac_MainConfig->ul_SCH_Config->retxBSR_Timer = RetxBSR_Timer_r12_sf320;
3094
  mac_MainConfig->ul_SCH_Config->ttiBundling = 0; // FALSE
3095

3096
  mac_MainConfig->timeAlignmentTimerDedicated = TimeAlignmentTimer_infinity;
3097

3098
  mac_MainConfig->drx_Config = NULL;
winckel's avatar
winckel committed
3099

3100
  mac_MainConfig->phr_Config = CALLOC(1, sizeof(*mac_MainConfig->phr_Config));
winckel's avatar
RRC:  
winckel committed
3101

3102 3103
  mac_MainConfig->phr_Config->present = MAC_MainConfig__phr_Config_PR_setup;
  mac_MainConfig->phr_Config->choice.setup.periodicPHR_Timer = MAC_MainConfig__phr_Config__setup__periodicPHR_Timer_sf20; // sf20 = 20 subframes
winckel's avatar
RRC:  
winckel committed
3104

3105
  mac_MainConfig->phr_Config->choice.setup.prohibitPHR_Timer = MAC_MainConfig__phr_Config__setup__prohibitPHR_Timer_sf20; // sf20 = 20 subframes
3106

3107
  mac_MainConfig->phr_Config->choice.setup.dl_PathlossChange = MAC_MainConfig__phr_Config__setup__dl_PathlossChange_dB1;  // Value dB1 =1 dB, dB3 = 3 dB
winckel's avatar
RRC:  
winckel committed
3108

3109
#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
3110 3111
  sr_ProhibitTimer_r9 = CALLOC(1, sizeof(long));
  *sr_ProhibitTimer_r9 = 0;   // SR tx on PUCCH, Value in number of SR period(s). Value 0 = no timer for SR, Value 2= 2*SR
3112 3113
  mac_MainConfig->ext1 = CALLOC(1, sizeof(struct MAC_MainConfig__ext1));
  mac_MainConfig->ext1->sr_ProhibitTimer_r9 = sr_ProhibitTimer_r9;
3114 3115 3116
  //sps_RA_ConfigList_rlola = NULL;
#endif

3117
  //change the transmission mode for the primary component carrier
3118
  //TODO: add codebook subset restriction here
3119
  //TODO: change TM for secondary CC in SCelltoaddmodlist
3120
  if (*physicalConfigDedicated) {
3121
    if ((*physicalConfigDedicated)->antennaInfo) {
3122
      (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.transmissionMode = rrc_inst->configuration.ue_TransmissionMode[0];
Cedric Roux's avatar
Cedric Roux committed
3123
      LOG_D(RRC,"Setting transmission mode to %ld+1\n",rrc_inst->configuration.ue_TransmissionMode[0]);
3124
      if (rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm3) {
3125 3126 3127 3128 3129 3130 3131 3132 3133
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=     
	  CALLOC(1,sizeof(AntennaInfoDedicated__codebookSubsetRestriction_PR));
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
	  AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm3;
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.buf= MALLOC(1);
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.buf[0] = 0xc0;
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.size=1;
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.bits_unused=6;
      }
3134
      else if (rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm4) {
3135 3136 3137 3138 3139 3140 3141 3142
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=     
	  CALLOC(1,sizeof(AntennaInfoDedicated__codebookSubsetRestriction_PR));
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
	  AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm4;
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm4.buf= MALLOC(1);
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm4.buf[0] = 0xfc;
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm4.size=1;
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm4.bits_unused=2;
3143

3144
      }
3145
      else if (rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm5) {
3146 3147 3148 3149 3150 3151 3152 3153 3154
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=     
	  CALLOC(1,sizeof(AntennaInfoDedicated__codebookSubsetRestriction_PR));
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
	  AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm5;
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm5.buf= MALLOC(1);
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm5.buf[0] = 0xf0;
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm5.size=1;
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm5.bits_unused=4;
      }
3155
      else if (rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm6) {
3156 3157 3158 3159 3160 3161 3162 3163 3164
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=     
	  CALLOC(1,sizeof(AntennaInfoDedicated__codebookSubsetRestriction_PR));
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
	  AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm6;
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm6.buf= MALLOC(1);
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm6.buf[0] = 0xf0;
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm6.size=1;
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm6.bits_unused=4;
      }
3165
    }
3166 3167 3168 3169 3170 3171 3172 3173 3174 3175
    else {
      LOG_E(RRC,"antenna_info not present in physical_config_dedicated. Not reconfiguring!\n");
    }
    if ((*physicalConfigDedicated)->cqi_ReportConfig) {
      if ((rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm4) ||
	  (rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm5) ||
	  (rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm6)) {
	//feedback mode needs to be set as well
	//TODO: I think this is taken into account in the PHY automatically based on the transmission mode variable
	printf("setting cqi reporting mode to rm31\n");
3176
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189
	*((*physicalConfigDedicated)->cqi_ReportConfig->cqi_ReportModeAperiodic)=CQI_ReportModeAperiodic_rm31;
#else
	*((*physicalConfigDedicated)->cqi_ReportConfig->cqi_ReportModeAperiodic)=CQI_ReportConfig__cqi_ReportModeAperiodic_rm31; // HLC CQI, no PMI
#endif
      }
    }
    else {
      LOG_E(RRC,"cqi_ReportConfig not present in physical_config_dedicated. Not reconfiguring!\n");
    }
  }
  else {
    LOG_E(RRC,"physical_config_dedicated not present in RRCConnectionReconfiguration. Not reconfiguring!\n");
  }
3190

3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262
  // Measurement ID list
  MeasId_list = CALLOC(1, sizeof(*MeasId_list));
  memset((void *)MeasId_list, 0, sizeof(*MeasId_list));

  MeasId0 = CALLOC(1, sizeof(*MeasId0));
  MeasId0->measId = 1;
  MeasId0->measObjectId = 1;
  MeasId0->reportConfigId = 1;
  ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId0);

  MeasId1 = CALLOC(1, sizeof(*MeasId1));
  MeasId1->measId = 2;
  MeasId1->measObjectId = 1;
  MeasId1->reportConfigId = 2;
  ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId1);

  MeasId2 = CALLOC(1, sizeof(*MeasId2));
  MeasId2->measId = 3;
  MeasId2->measObjectId = 1;
  MeasId2->reportConfigId = 3;
  ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId2);

  MeasId3 = CALLOC(1, sizeof(*MeasId3));
  MeasId3->measId = 4;
  MeasId3->measObjectId = 1;
  MeasId3->reportConfigId = 4;
  ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId3);

  MeasId4 = CALLOC(1, sizeof(*MeasId4));
  MeasId4->measId = 5;
  MeasId4->measObjectId = 1;
  MeasId4->reportConfigId = 5;
  ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId4);

  MeasId5 = CALLOC(1, sizeof(*MeasId5));
  MeasId5->measId = 6;
  MeasId5->measObjectId = 1;
  MeasId5->reportConfigId = 6;
  ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId5);

  //  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->measIdToAddModList = MeasId_list;

  // Add one EUTRA Measurement Object
  MeasObj_list = CALLOC(1, sizeof(*MeasObj_list));
  memset((void *)MeasObj_list, 0, sizeof(*MeasObj_list));

  // Configure MeasObject

  MeasObj = CALLOC(1, sizeof(*MeasObj));
  memset((void *)MeasObj, 0, sizeof(*MeasObj));

  MeasObj->measObjectId = 1;
  MeasObj->measObject.present = MeasObjectToAddMod__measObject_PR_measObjectEUTRA;
  MeasObj->measObject.choice.measObjectEUTRA.carrierFreq = 3350; //band 7, 2.68GHz
  //MeasObj->measObject.choice.measObjectEUTRA.carrierFreq = 36090; //band 33, 1.909GHz
  MeasObj->measObject.choice.measObjectEUTRA.allowedMeasBandwidth = AllowedMeasBandwidth_mbw25;
  MeasObj->measObject.choice.measObjectEUTRA.presenceAntennaPort1 = 1;
  MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.buf = CALLOC(1, sizeof(uint8_t));
  MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.buf[0] = 0;
  MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.size = 1;
  MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.bits_unused = 6;
  MeasObj->measObject.choice.measObjectEUTRA.offsetFreq = NULL;   // Default is 15 or 0dB

  MeasObj->measObject.choice.measObjectEUTRA.cellsToAddModList =
    (CellsToAddModList_t *) CALLOC(1, sizeof(*CellsToAddModList));

  CellsToAddModList = MeasObj->measObject.choice.measObjectEUTRA.cellsToAddModList;

  // Add adjacent cell lists (6 per eNB)
  for (i = 0; i < 6; i++) {
    CellToAdd = (CellsToAddMod_t *) CALLOC(1, sizeof(*CellToAdd));
    CellToAdd->cellIndex = i + 1;
3263
    CellToAdd->physCellId = get_adjacent_cell_id(ctxt_pP->module_id, i);
3264 3265 3266 3267
    CellToAdd->cellIndividualOffset = Q_OffsetRange_dB0;

    ASN_SEQUENCE_ADD(&CellsToAddModList->list, CellToAdd);
  }
3268

3269 3270
  ASN_SEQUENCE_ADD(&MeasObj_list->list, MeasObj);
  //  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->measObjectToAddModList = MeasObj_list;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3271

3272 3273
  // Report Configurations for periodical, A1-A5 events
  ReportConfig_list = CALLOC(1, sizeof(*ReportConfig_list));
3274

3275
  ReportConfig_per = CALLOC(1, sizeof(*ReportConfig_per));
3276

3277
  ReportConfig_A1 = CALLOC(1, sizeof(*ReportConfig_A1));
3278

3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318
  ReportConfig_A2 = CALLOC(1, sizeof(*ReportConfig_A2));

  ReportConfig_A3 = CALLOC(1, sizeof(*ReportConfig_A3));

  ReportConfig_A4 = CALLOC(1, sizeof(*ReportConfig_A4));

  ReportConfig_A5 = CALLOC(1, sizeof(*ReportConfig_A5));

  ReportConfig_per->reportConfigId = 1;
  ReportConfig_per->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerType.present =
    ReportConfigEUTRA__triggerType_PR_periodical;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerType.choice.periodical.purpose =
    ReportConfigEUTRA__triggerType__periodical__purpose_reportStrongestCells;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerQuantity = ReportConfigEUTRA__triggerQuantity_rsrp;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportInterval = ReportInterval_ms120;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;

  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_per);

  ReportConfig_A1->reportConfigId = 2;
  ReportConfig_A1->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.present =
    ReportConfigEUTRA__triggerType_PR_event;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
    ReportConfigEUTRA__triggerType__event__eventId_PR_eventA1;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA1.
  a1_Threshold.present = ThresholdEUTRA_PR_threshold_RSRP;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA1.
  a1_Threshold.choice.threshold_RSRP = 10;

  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerQuantity = ReportConfigEUTRA__triggerQuantity_rsrp;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportInterval = ReportInterval_ms120;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;

  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A1);
3319
  
3320
  if (ho_state == 1 /*HO_MEASURMENT */ ) {
3321 3322
    LOG_I(RRC, "[eNB %d] frame %d: requesting A2, A3, A4, A5, and A6 event reporting\n",
          ctxt_pP->module_id, ctxt_pP->frame);
3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438
    ReportConfig_A2->reportConfigId = 3;
    ReportConfig_A2->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.present =
      ReportConfigEUTRA__triggerType_PR_event;
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
      ReportConfigEUTRA__triggerType__event__eventId_PR_eventA2;
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
    eventA2.a2_Threshold.present = ThresholdEUTRA_PR_threshold_RSRP;
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
    eventA2.a2_Threshold.choice.threshold_RSRP = 10;

    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerQuantity =
      ReportConfigEUTRA__triggerQuantity_rsrp;
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportInterval = ReportInterval_ms120;
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;

    ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A2);

    ReportConfig_A3->reportConfigId = 4;
    ReportConfig_A3->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.present =
      ReportConfigEUTRA__triggerType_PR_event;
    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
      ReportConfigEUTRA__triggerType__event__eventId_PR_eventA3;

    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA3.a3_Offset = 1;   //10;
    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
    eventA3.reportOnLeave = 1;

    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerQuantity =
      ReportConfigEUTRA__triggerQuantity_rsrp;
    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportInterval = ReportInterval_ms120;
    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;

    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.hysteresis = 0.5; // FIXME ...hysteresis is of type long!
    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.timeToTrigger =
      TimeToTrigger_ms40;
    ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A3);

    ReportConfig_A4->reportConfigId = 5;
    ReportConfig_A4->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.present =
      ReportConfigEUTRA__triggerType_PR_event;
    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
      ReportConfigEUTRA__triggerType__event__eventId_PR_eventA4;
    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
    eventA4.a4_Threshold.present = ThresholdEUTRA_PR_threshold_RSRP;
    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
    eventA4.a4_Threshold.choice.threshold_RSRP = 10;

    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerQuantity =
      ReportConfigEUTRA__triggerQuantity_rsrp;
    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportInterval = ReportInterval_ms120;
    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;

    ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A4);

    ReportConfig_A5->reportConfigId = 6;
    ReportConfig_A5->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.present =
      ReportConfigEUTRA__triggerType_PR_event;
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
      ReportConfigEUTRA__triggerType__event__eventId_PR_eventA5;
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
    eventA5.a5_Threshold1.present = ThresholdEUTRA_PR_threshold_RSRP;
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
    eventA5.a5_Threshold2.present = ThresholdEUTRA_PR_threshold_RSRP;
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
    eventA5.a5_Threshold1.choice.threshold_RSRP = 10;
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
    eventA5.a5_Threshold2.choice.threshold_RSRP = 10;

    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerQuantity =
      ReportConfigEUTRA__triggerQuantity_rsrp;
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportInterval = ReportInterval_ms120;
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;

    ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A5);
    //  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->reportConfigToAddModList = ReportConfig_list;

    rsrp = CALLOC(1, sizeof(RSRP_Range_t));
    *rsrp = 20;

    Sparams = CALLOC(1, sizeof(*Sparams));
    Sparams->present = MeasConfig__speedStatePars_PR_setup;
    Sparams->choice.setup.timeToTrigger_SF.sf_High = SpeedStateScaleFactors__sf_Medium_oDot75;
    Sparams->choice.setup.timeToTrigger_SF.sf_Medium = SpeedStateScaleFactors__sf_High_oDot5;
    Sparams->choice.setup.mobilityStateParameters.n_CellChangeHigh = 10;
    Sparams->choice.setup.mobilityStateParameters.n_CellChangeMedium = 5;
    Sparams->choice.setup.mobilityStateParameters.t_Evaluation = MobilityStateParameters__t_Evaluation_s60;
    Sparams->choice.setup.mobilityStateParameters.t_HystNormal = MobilityStateParameters__t_HystNormal_s120;

    quantityConfig = CALLOC(1, sizeof(*quantityConfig));
    memset((void *)quantityConfig, 0, sizeof(*quantityConfig));
    quantityConfig->quantityConfigEUTRA = CALLOC(1, sizeof(struct QuantityConfigEUTRA));
    memset((void *)quantityConfig->quantityConfigEUTRA, 0, sizeof(*quantityConfig->quantityConfigEUTRA));
    quantityConfig->quantityConfigCDMA2000 = NULL;
    quantityConfig->quantityConfigGERAN = NULL;
    quantityConfig->quantityConfigUTRA = NULL;
    quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP =
      CALLOC(1, sizeof(*(quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP)));
    quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ =
      CALLOC(1, sizeof(*(quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ)));
    *quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP = FilterCoefficient_fc4;
    *quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ = FilterCoefficient_fc4;

    LOG_I(RRC,
          "[eNB %d] Frame %d: potential handover preparation: store the information in an intermediate structure in case of failure\n",
3439
          ctxt_pP->module_id, ctxt_pP->frame);
3440 3441
    // store the information in an intermediate structure for Hanodver management
    //rrc_inst->handover_info.as_config.sourceRadioResourceConfig.srb_ToAddModList = CALLOC(1,sizeof());
3442
    ue_context_pP->ue_context.handover_info = CALLOC(1, sizeof(*(ue_context_pP->ue_context.handover_info)));
3443
    //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.srb_ToAddModList,(void *)SRB_list,sizeof(SRB_ToAddModList_t));
3444
    ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.srb_ToAddModList = *SRB_configList2;
3445
    //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.drb_ToAddModList,(void *)DRB_list,sizeof(DRB_ToAddModList_t));
3446 3447 3448 3449 3450
    ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.drb_ToAddModList = *DRB_configList;
    ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.drb_ToReleaseList = NULL;
    ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig =
      CALLOC(1, sizeof(*ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig));
    memcpy((void*)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig,
3451
           (void *)mac_MainConfig, sizeof(MAC_MainConfig_t));
3452
    ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.physicalConfigDedicated =
3453
      CALLOC(1, sizeof(PhysicalConfigDedicated_t));
3454 3455 3456
    memcpy((void*)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.physicalConfigDedicated,
           (void*)ue_context_pP->ue_context.physicalConfigDedicated, sizeof(PhysicalConfigDedicated_t));
    ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.sps_Config = NULL;
3457 3458 3459 3460 3461 3462 3463 3464 3465
    //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.sps_Config,(void *)rrc_inst->sps_Config[ue_mod_idP],sizeof(SPS_Config_t));

  }

#if defined(ENABLE_ITTI)
  /* Initialize NAS list */
  dedicatedInfoNASList = CALLOC(1, sizeof(struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList));

  /* Add all NAS PDUs to the list */
3466 3467
  for (i = 0; i < ue_context_pP->ue_context.nb_of_e_rabs; i++) {
    if (ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer != NULL) {
3468 3469
      dedicatedInfoNas = CALLOC(1, sizeof(DedicatedInfoNAS_t));
      memset(dedicatedInfoNas, 0, sizeof(OCTET_STRING_t));
3470 3471
      OCTET_STRING_fromBuf(dedicatedInfoNas, 
			   (char*)ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer,
3472
                           ue_context_pP->ue_context.e_rab[i].param.nas_pdu.length);
3473
      ASN_SEQUENCE_ADD(&dedicatedInfoNASList->list, dedicatedInfoNas);
3474
    }
3475

3476 3477
    /* TODO parameters yet to process ... */
    {
3478 3479 3480
      //      ue_context_pP->ue_context.e_rab[i].param.qos;
      //      ue_context_pP->ue_context.e_rab[i].param.sgw_addr;
      //      ue_context_pP->ue_context.e_rab[i].param.gtp_teid;
3481
    }
3482 3483

    /* TODO should test if e RAB are Ok before! */
3484
    ue_context_pP->ue_context.e_rab[i].status = E_RAB_STATUS_DONE;
3485 3486
    LOG_D(RRC, "setting the status for the default DRB (index %d) to (%d,%s)\n", 
	  i, ue_context_pP->ue_context.e_rab[i].status, "E_RAB_STATUS_DONE");
3487 3488 3489 3490 3491 3492 3493 3494
  }

  /* If list is empty free the list and reset the address */
  if (dedicatedInfoNASList->list.count == 0) {
    free(dedicatedInfoNASList);
    dedicatedInfoNASList = NULL;
  }

3495 3496
#endif

3497
  memset(buffer, 0, RRC_BUF_SIZE);
3498

3499 3500
  size = do_RRCConnectionReconfiguration(ctxt_pP,
                                         buffer,
3501 3502
                                         xid,   //Transaction_id,
                                         (SRB_ToAddModList_t*)*SRB_configList2, // SRB_configList
3503 3504 3505
                                         (DRB_ToAddModList_t*)*DRB_configList,
                                         (DRB_ToReleaseList_t*)NULL,  // DRB2_list,
                                         (struct SPS_Config*)NULL,    // *sps_Config,
3506
                                         (struct PhysicalConfigDedicated*)*physicalConfigDedicated,
3507
#ifdef EXMIMO_IOT
3508
                                         NULL, NULL, NULL,NULL,
3509
#else
3510 3511 3512 3513
                                         (MeasObjectToAddModList_t*)MeasObj_list,
                                         (ReportConfigToAddModList_t*)ReportConfig_list,
                                         (QuantityConfig_t*)quantityConfig,
                                         (MeasIdToAddModList_t*)MeasId_list,
3514
#endif
3515 3516 3517 3518 3519 3520
                                         (MAC_MainConfig_t*)mac_MainConfig,
                                         (MeasGapConfig_t*)NULL,
                                         (MobilityControlInfo_t*)NULL,
                                         (struct MeasConfig__speedStatePars*)Sparams,
                                         (RSRP_Range_t*)rsrp,
                                         (C_RNTI_t*)cba_RNTI,
3521 3522 3523
                                         (struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList*)dedicatedInfoNASList,
                                         (SL_CommConfig_r12_t*)NULL,
                                         (SL_DiscConfig_r12_t*)NULL
3524
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
3525
                                         , (SCellToAddMod_r10_t*)NULL
3526
#endif
3527
                                        );
3528 3529
  LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)buffer,size,
              "[MSG] RRC Connection Reconfiguration\n");
3530

3531
#if defined(ENABLE_ITTI)
3532 3533

  /* Free all NAS PDUs */
3534 3535
  for (i = 0; i < ue_context_pP->ue_context.nb_of_e_rabs; i++) {
    if (ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer != NULL) {
3536
      /* Free the NAS PDU buffer and invalidate it */
3537 3538
      free(ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer);
      ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer = NULL;
3539
    }
3540 3541
  }

3542
#endif
3543

3544
  LOG_I(RRC,
3545 3546
        "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate RRCConnectionReconfiguration (bytes %d, UE id %x)\n",
        ctxt_pP->module_id, ctxt_pP->frame, size, ue_context_pP->ue_context.rnti);
3547

3548
  LOG_D(RRC,
3549 3550
        "[FRAME %05d][RRC_eNB][MOD %u][][--- PDCP_DATA_REQ/%d Bytes (rrcConnectionReconfiguration to UE %x MUI %d) --->][PDCP][MOD %u][RB %u]\n",
        ctxt_pP->frame, ctxt_pP->module_id, size, ue_context_pP->ue_context.rnti, rrc_eNB_mui, ctxt_pP->module_id, DCCH);
3551 3552

  MSC_LOG_TX_MESSAGE(
3553 3554 3555 3556 3557 3558 3559 3560 3561
    MSC_RRC_ENB,
    MSC_RRC_UE,
    buffer,
    size,
    MSC_AS_TIME_FMT" rrcConnectionReconfiguration UE %x MUI %d size %u",
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP->ue_context.rnti,
    rrc_eNB_mui,
    size);
3562

3563 3564 3565 3566 3567 3568 3569 3570
  rrc_data_req(
	       ctxt_pP,
	       DCCH,
	       rrc_eNB_mui++,
	       SDU_CONFIRM_NO,
	       size,
	       buffer,
	       PDCP_TRANSMISSION_MODE_CONTROL);
winckel's avatar
winckel committed
3571
}
3572

3573
//-----------------------------------------------------------------------------
3574 3575 3576 3577 3578 3579
void
flexran_rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt_t* const ctxt_pP,
                 rrc_eNB_ue_context_t*          const ue_context_pP,
                 const uint8_t                ho_state,
                 agent_reconf_rrc * trig_param
                 )
3580
//-----------------------------------------------------------------------------
3581
{
3582 3583 3584 3585 3586
  uint8_t                             buffer[RRC_BUF_SIZE];
  uint16_t                            size;
  int                                 i;
 
  // configure SRB1/SRB2, PhysicalConfigDedicated, MAC_MainConfig for UE
3587
  eNB_RRC_INST*                       rrc_inst = RC.rrc[ctxt_pP->module_id];
3588
  struct PhysicalConfigDedicated**    physicalConfigDedicated = &ue_context_pP->ue_context.physicalConfigDedicated;
3589

3590 3591 3592 3593 3594 3595 3596
  struct SRB_ToAddMod                *SRB2_config                      = NULL;
  struct SRB_ToAddMod__rlc_Config    *SRB2_rlc_config                  = NULL;
  struct SRB_ToAddMod__logicalChannelConfig *SRB2_lchan_config         = NULL;
  struct LogicalChannelConfig__ul_SpecificParameters
      *SRB2_ul_SpecificParameters       = NULL;
  SRB_ToAddModList_t*                 SRB_configList = ue_context_pP->ue_context.SRB_configList;
  SRB_ToAddModList_t                 **SRB_configList2                  = NULL;
3597

3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611
  struct DRB_ToAddMod                *DRB_config                       = NULL;
  struct RLC_Config                  *DRB_rlc_config                   = NULL;
  struct PDCP_Config                 *DRB_pdcp_config                  = NULL;
  struct PDCP_Config__rlc_AM         *PDCP_rlc_AM                      = NULL;
  struct PDCP_Config__rlc_UM         *PDCP_rlc_UM                      = NULL;
  struct LogicalChannelConfig        *DRB_lchan_config                 = NULL;
  struct LogicalChannelConfig__ul_SpecificParameters
      *DRB_ul_SpecificParameters        = NULL;
  DRB_ToAddModList_t**                DRB_configList = &ue_context_pP->ue_context.DRB_configList;
  DRB_ToAddModList_t**                DRB_configList2 = NULL;
   MAC_MainConfig_t                   *mac_MainConfig                   = NULL;
  MeasObjectToAddModList_t           *MeasObj_list                     = NULL;
  MeasObjectToAddMod_t               *MeasObj                          = NULL;
  ReportConfigToAddModList_t         *ReportConfig_list                = NULL;
shahab SHARIATBAGHERI's avatar
shahab SHARIATBAGHERI committed
3612 3613
  ReportConfigToAddMod_t             *ReportConfig_per;//, *ReportConfig_A1,
                                     // *ReportConfig_A2, *ReportConfig_A3, *ReportConfig_A4, *ReportConfig_A5;
3614
  MeasIdToAddModList_t               *MeasId_list                      = NULL;
shahab SHARIATBAGHERI's avatar
shahab SHARIATBAGHERI committed
3615
  MeasIdToAddMod_t                   *MeasId0; //, *MeasId1, *MeasId2, *MeasId3, *MeasId4, *MeasId5;
3616 3617 3618 3619
#if Rel10
  long                               *sr_ProhibitTimer_r9              = NULL;
  //     uint8_t sCellIndexToAdd = rrc_find_free_SCell_index(enb_mod_idP, ue_mod_idP, 1);
  //uint8_t                            sCellIndexToAdd = 0;
3620
#endif
3621

3622 3623
  long                               *logicalchannelgroup, *logicalchannelgroup_drb;
  long                               *maxHARQ_Tx, *periodicBSR_Timer;
3624

3625 3626 3627 3628 3629 3630 3631 3632 3633
  RSRP_Range_t                       *rsrp                             = NULL;
  struct MeasConfig__speedStatePars  *Sparams                          = NULL;
  QuantityConfig_t                   *quantityConfig                   = NULL;
  CellsToAddMod_t                    *CellToAdd                        = NULL;
  CellsToAddModList_t                *CellsToAddModList                = NULL;
  struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList = NULL;
  DedicatedInfoNAS_t                 *dedicatedInfoNas                 = NULL;
  /* for no gcc warnings */
  (void)dedicatedInfoNas;
3634

3635
  C_RNTI_t                           *cba_RNTI                         = NULL;
Cedric Roux's avatar
Cedric Roux committed
3636

3637
  uint8_t xid = rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id);   //Transaction_id,
3638

3639 3640 3641 3642 3643 3644 3645 3646
#ifdef CBA
  //struct PUSCH_CBAConfigDedicated_vlola  *pusch_CBAConfigDedicated_vlola;
  uint8_t                            *cba_RNTI_buf;
  cba_RNTI = CALLOC(1, sizeof(C_RNTI_t));
  cba_RNTI_buf = CALLOC(1, 2 * sizeof(uint8_t));
  cba_RNTI->buf = cba_RNTI_buf;
  cba_RNTI->size = 2;
  cba_RNTI->bits_unused = 0;
3647

3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660
  // associate UEs to the CBa groups as a function of their UE id
  if (rrc_inst->num_active_cba_groups) {
    cba_RNTI->buf[0] = rrc_inst->cba_rnti[ue_mod_idP % rrc_inst->num_active_cba_groups] & 0xff;
    cba_RNTI->buf[1] = 0xff;
    LOG_D(RRC,
          "[eNB %d] Frame %d: cba_RNTI = %x in group %d is attribued to UE %d\n",
          enb_mod_idP, frameP,
          rrc_inst->cba_rnti[ue_mod_idP % rrc_inst->num_active_cba_groups],
          ue_mod_idP % rrc_inst->num_active_cba_groups, ue_mod_idP);
  } else {
    cba_RNTI->buf[0] = 0x0;
    cba_RNTI->buf[1] = 0x0;
    LOG_D(RRC, "[eNB %d] Frame %d: no cba_RNTI is configured for UE %d\n", enb_mod_idP, frameP, ue_mod_idP);
3661 3662 3663 3664
  }

#endif

3665 3666 3667 3668 3669 3670 3671 3672
  T(T_ENB_RRC_CONNECTION_RECONFIGURATION, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

  // Configure SRB2
  /// SRB2
  SRB_configList2=&ue_context_pP->ue_context.SRB_configList2[xid];
  if (*SRB_configList2) {
    free(*SRB_configList2);
3673
  }
3674 3675 3676
  *SRB_configList2 = CALLOC(1, sizeof(**SRB_configList2));
  memset(*SRB_configList2, 0, sizeof(**SRB_configList2));
  SRB2_config = CALLOC(1, sizeof(*SRB2_config));
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3677

3678 3679 3680
  SRB2_config->srb_Identity = 2;
  SRB2_rlc_config = CALLOC(1, sizeof(*SRB2_rlc_config));
  SRB2_config->rlc_Config = SRB2_rlc_config;
3681

3682 3683 3684 3685 3686 3687 3688 3689
  SRB2_rlc_config->present = SRB_ToAddMod__rlc_Config_PR_explicitValue;
  SRB2_rlc_config->choice.explicitValue.present = RLC_Config_PR_am;
  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.t_PollRetransmit = T_PollRetransmit_ms15;
  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollPDU = PollPDU_p8;
  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollByte = PollByte_kB1000;
  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.maxRetxThreshold = UL_AM_RLC__maxRetxThreshold_t32;
  SRB2_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_Reordering = T_Reordering_ms35;
  SRB2_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_StatusProhibit = T_StatusProhibit_ms10;
3690

3691 3692
  SRB2_lchan_config = CALLOC(1, sizeof(*SRB2_lchan_config));
  SRB2_config->logicalChannelConfig = SRB2_lchan_config;
3693

3694
  SRB2_lchan_config->present = SRB_ToAddMod__logicalChannelConfig_PR_explicitValue;
3695

3696
  SRB2_ul_SpecificParameters = CALLOC(1, sizeof(*SRB2_ul_SpecificParameters));
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3697

3698 3699 3700 3701 3702
  SRB2_ul_SpecificParameters->priority = 3; // let some priority for SRB1 and dedicated DRBs
  SRB2_ul_SpecificParameters->prioritisedBitRate =
    LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
  SRB2_ul_SpecificParameters->bucketSizeDuration =
    LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
Cedric Roux's avatar
Cedric Roux committed
3703

3704 3705 3706
  // LCG for CCCH and DCCH is 0 as defined in 36331
  logicalchannelgroup = CALLOC(1, sizeof(long));
  *logicalchannelgroup = 0;
3707

3708
  SRB2_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup;
3709

3710 3711 3712 3713 3714
  SRB2_lchan_config->choice.explicitValue.ul_SpecificParameters = SRB2_ul_SpecificParameters;
  // this list has the configuration for SRB1 and SRB2
  ASN_SEQUENCE_ADD(&SRB_configList->list, SRB2_config);
  // this list has only the configuration for SRB2
  ASN_SEQUENCE_ADD(&(*SRB_configList2)->list, SRB2_config);
3715

3716 3717 3718 3719 3720 3721 3722 3723
  // Configure DRB
  //*DRB_configList = CALLOC(1, sizeof(*DRB_configList));
  // list for all the configured DRB
  if (*DRB_configList) {
    free(*DRB_configList);
  }
  *DRB_configList = CALLOC(1, sizeof(**DRB_configList));
  memset(*DRB_configList, 0, sizeof(**DRB_configList));
3724

3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842
  // list for the configured DRB for a this xid
  DRB_configList2=&ue_context_pP->ue_context.DRB_configList2[xid];
  if (*DRB_configList2) {
    free(*DRB_configList2);
  }
  *DRB_configList2 = CALLOC(1, sizeof(**DRB_configList2));
  memset(*DRB_configList2, 0, sizeof(**DRB_configList2));


  /// DRB
  DRB_config = CALLOC(1, sizeof(*DRB_config));

  DRB_config->eps_BearerIdentity = CALLOC(1, sizeof(long));
  *(DRB_config->eps_BearerIdentity) = 5L; // LW set to first value, allowed value 5..15, value : x+4
  // DRB_config->drb_Identity = (DRB_Identity_t) 1; //allowed values 1..32
  // NN: this is the 1st DRB for this ue, so set it to 1
  DRB_config->drb_Identity = (DRB_Identity_t) 1;  // (ue_mod_idP+1); //allowed values 1..32, value: x
  DRB_config->logicalChannelIdentity = CALLOC(1, sizeof(long));
  *(DRB_config->logicalChannelIdentity) = (long)3; // value : x+2
  DRB_rlc_config = CALLOC(1, sizeof(*DRB_rlc_config));
  DRB_config->rlc_Config = DRB_rlc_config;

#ifdef RRC_DEFAULT_RAB_IS_AM
  DRB_rlc_config->present = RLC_Config_PR_am;
  DRB_rlc_config->choice.am.ul_AM_RLC.t_PollRetransmit = T_PollRetransmit_ms50;
  DRB_rlc_config->choice.am.ul_AM_RLC.pollPDU = PollPDU_p16;
  DRB_rlc_config->choice.am.ul_AM_RLC.pollByte = PollByte_kBinfinity;
  DRB_rlc_config->choice.am.ul_AM_RLC.maxRetxThreshold = UL_AM_RLC__maxRetxThreshold_t8;
  DRB_rlc_config->choice.am.dl_AM_RLC.t_Reordering = T_Reordering_ms35;
  DRB_rlc_config->choice.am.dl_AM_RLC.t_StatusProhibit = T_StatusProhibit_ms25;
#else
  DRB_rlc_config->present = RLC_Config_PR_um_Bi_Directional;
  DRB_rlc_config->choice.um_Bi_Directional.ul_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
#ifdef CBA
  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering   = T_Reordering_ms5;//T_Reordering_ms25;
#else
  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering = T_Reordering_ms35;
#endif
#endif

  DRB_pdcp_config = CALLOC(1, sizeof(*DRB_pdcp_config));
  DRB_config->pdcp_Config = DRB_pdcp_config;
  DRB_pdcp_config->discardTimer = CALLOC(1, sizeof(long));
  *DRB_pdcp_config->discardTimer = PDCP_Config__discardTimer_infinity;
  DRB_pdcp_config->rlc_AM = NULL;
  DRB_pdcp_config->rlc_UM = NULL;

  /* avoid gcc warnings */
  (void)PDCP_rlc_AM;
  (void)PDCP_rlc_UM;

#ifdef RRC_DEFAULT_RAB_IS_AM // EXMIMO_IOT
  PDCP_rlc_AM = CALLOC(1, sizeof(*PDCP_rlc_AM));
  DRB_pdcp_config->rlc_AM = PDCP_rlc_AM;
  PDCP_rlc_AM->statusReportRequired = FALSE;
#else
  PDCP_rlc_UM = CALLOC(1, sizeof(*PDCP_rlc_UM));
  DRB_pdcp_config->rlc_UM = PDCP_rlc_UM;
  PDCP_rlc_UM->pdcp_SN_Size = PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits;
#endif
  DRB_pdcp_config->headerCompression.present = PDCP_Config__headerCompression_PR_notUsed;

  DRB_lchan_config = CALLOC(1, sizeof(*DRB_lchan_config));
  DRB_config->logicalChannelConfig = DRB_lchan_config;
  DRB_ul_SpecificParameters = CALLOC(1, sizeof(*DRB_ul_SpecificParameters));
  DRB_lchan_config->ul_SpecificParameters = DRB_ul_SpecificParameters;

  DRB_ul_SpecificParameters->priority = 12;    // lower priority than srb1, srb2 and other dedicated bearer
  DRB_ul_SpecificParameters->prioritisedBitRate =LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_kBps8 ;
    //LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
  DRB_ul_SpecificParameters->bucketSizeDuration =
    LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;

  // LCG for DTCH can take the value from 1 to 3 as defined in 36331: normally controlled by upper layers (like RRM)
  logicalchannelgroup_drb = CALLOC(1, sizeof(long));
  *logicalchannelgroup_drb = 1;
  DRB_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup_drb;

  ASN_SEQUENCE_ADD(&(*DRB_configList)->list, DRB_config);
  ASN_SEQUENCE_ADD(&(*DRB_configList2)->list, DRB_config);

  //ue_context_pP->ue_context.DRB_configList2[0] = &(*DRB_configList);

  mac_MainConfig = CALLOC(1, sizeof(*mac_MainConfig));
  // ue_context_pP->ue_context.mac_MainConfig = mac_MainConfig;

  mac_MainConfig->ul_SCH_Config = CALLOC(1, sizeof(*mac_MainConfig->ul_SCH_Config));

  maxHARQ_Tx = CALLOC(1, sizeof(long));
  *maxHARQ_Tx = MAC_MainConfig__ul_SCH_Config__maxHARQ_Tx_n5;
  mac_MainConfig->ul_SCH_Config->maxHARQ_Tx = maxHARQ_Tx;
  periodicBSR_Timer = CALLOC(1, sizeof(long));
  *periodicBSR_Timer = PeriodicBSR_Timer_r12_sf64;
  mac_MainConfig->ul_SCH_Config->periodicBSR_Timer = periodicBSR_Timer;
  mac_MainConfig->ul_SCH_Config->retxBSR_Timer = RetxBSR_Timer_r12_sf320;
  mac_MainConfig->ul_SCH_Config->ttiBundling = 0; // FALSE

  mac_MainConfig->timeAlignmentTimerDedicated = TimeAlignmentTimer_infinity;

  mac_MainConfig->drx_Config = NULL;

  mac_MainConfig->phr_Config = CALLOC(1, sizeof(*mac_MainConfig->phr_Config));

  mac_MainConfig->phr_Config->present = MAC_MainConfig__phr_Config_PR_setup;
  mac_MainConfig->phr_Config->choice.setup.periodicPHR_Timer = MAC_MainConfig__phr_Config__setup__periodicPHR_Timer_sf20; // sf20 = 20 subframes

  mac_MainConfig->phr_Config->choice.setup.prohibitPHR_Timer = MAC_MainConfig__phr_Config__setup__prohibitPHR_Timer_sf20; // sf20 = 20 subframes

  mac_MainConfig->phr_Config->choice.setup.dl_PathlossChange = MAC_MainConfig__phr_Config__setup__dl_PathlossChange_dB1;  // Value dB1 =1 dB, dB3 = 3 dB

#ifdef Rel10
  sr_ProhibitTimer_r9 = CALLOC(1, sizeof(long));
  *sr_ProhibitTimer_r9 = 0;   // SR tx on PUCCH, Value in number of SR period(s). Value 0 = no timer for SR, Value 2= 2*SR
  mac_MainConfig->ext1 = CALLOC(1, sizeof(struct MAC_MainConfig__ext1));
  mac_MainConfig->ext1->sr_ProhibitTimer_r9 = sr_ProhibitTimer_r9;
  //sps_RA_ConfigList_rlola = NULL;
#endif
3843

3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869
  //change the transmission mode for the primary component carrier
  //TODO: add codebook subset restriction here
  //TODO: change TM for secondary CC in SCelltoaddmodlist
  if (*physicalConfigDedicated) {
    if ((*physicalConfigDedicated)->antennaInfo) {
      (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.transmissionMode = rrc_inst->configuration.ue_TransmissionMode[0];
      LOG_D(RRC,"Setting transmission mode to %ld+1\n",rrc_inst->configuration.ue_TransmissionMode[0]);
      if (rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm3) {
  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=     
    CALLOC(1,sizeof(AntennaInfoDedicated__codebookSubsetRestriction_PR));
  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
    AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm3;
  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.buf= MALLOC(1);
  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.buf[0] = 0xc0;
  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.size=1;
  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.bits_unused=6;
      }
      else if (rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm4) {
  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=     
    CALLOC(1,sizeof(AntennaInfoDedicated__codebookSubsetRestriction_PR));
  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
    AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm4;
  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm4.buf= MALLOC(1);
  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm4.buf[0] = 0xfc;
  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm4.size=1;
  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm4.bits_unused=2;
3870

3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890
      }
      else if (rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm5) {
  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=     
    CALLOC(1,sizeof(AntennaInfoDedicated__codebookSubsetRestriction_PR));
  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
    AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm5;
  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm5.buf= MALLOC(1);
  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm5.buf[0] = 0xf0;
  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm5.size=1;
  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm5.bits_unused=4;
      }
      else if (rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm6) {
  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=     
    CALLOC(1,sizeof(AntennaInfoDedicated__codebookSubsetRestriction_PR));
  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
    AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm6;
  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm6.buf= MALLOC(1);
  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm6.buf[0] = 0xf0;
  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm6.size=1;
  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm6.bits_unused=4;
3891
      }
3892
    }
3893 3894 3895 3896 3897
    else {
      LOG_E(RRC,"antenna_info not present in physical_config_dedicated. Not reconfiguring!\n");
    }
    if ((*physicalConfigDedicated)->cqi_ReportConfig) {
      if ((rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm4) ||
3898 3899 3900 3901 3902
    (rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm5) ||
    (rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm6)) {
  //feedback mode needs to be set as well
  //TODO: I think this is taken into account in the PHY automatically based on the transmission mode variable
  printf("setting cqi reporting mode to rm31\n");
3903
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
3904
  *((*physicalConfigDedicated)->cqi_ReportConfig->cqi_ReportModeAperiodic)=CQI_ReportModeAperiodic_rm31;
3905
#else
3906
  *((*physicalConfigDedicated)->cqi_ReportConfig->cqi_ReportModeAperiodic)=CQI_ReportConfig__cqi_ReportModeAperiodic_rm31; // HLC CQI, no PMI
3907 3908 3909 3910 3911 3912 3913 3914 3915 3916
#endif
      }
    }
    else {
      LOG_E(RRC,"cqi_ReportConfig not present in physical_config_dedicated. Not reconfiguring!\n");
    }
  }
  else {
    LOG_E(RRC,"physical_config_dedicated not present in RRCConnectionReconfiguration. Not reconfiguring!\n");
  }
3917

3918 3919 3920 3921 3922 3923 3924 3925 3926 3927
  // Measurement ID list
  MeasId_list = CALLOC(1, sizeof(*MeasId_list));
  memset((void *)MeasId_list, 0, sizeof(*MeasId_list));

  MeasId0 = CALLOC(1, sizeof(*MeasId0));
  MeasId0->measId = 1;
  MeasId0->measObjectId = 1;
  MeasId0->reportConfigId = 1;
  ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId0);

3928 3929 3930
  /*
   * Add one EUTRA Measurement Object
  */
3931 3932 3933 3934

  MeasObj_list = CALLOC(1, sizeof(*MeasObj_list));
  memset((void *)MeasObj_list, 0, sizeof(*MeasObj_list));

3935
  // Configure MeasObject 
3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960

  MeasObj = CALLOC(1, sizeof(*MeasObj));
  memset((void *)MeasObj, 0, sizeof(*MeasObj));

  MeasObj->measObjectId = 1;
  MeasObj->measObject.present = MeasObjectToAddMod__measObject_PR_measObjectEUTRA;
  MeasObj->measObject.choice.measObjectEUTRA.carrierFreq = 3350; //band 7, 2.68GHz
  //MeasObj->measObject.choice.measObjectEUTRA.carrierFreq = 36090; //band 33, 1.909GHz
  MeasObj->measObject.choice.measObjectEUTRA.allowedMeasBandwidth = AllowedMeasBandwidth_mbw25;
  MeasObj->measObject.choice.measObjectEUTRA.presenceAntennaPort1 = 1;
  MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.buf = CALLOC(1, sizeof(uint8_t));
  MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.buf[0] = 0;
  MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.size = 1;
  MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.bits_unused = 6;
  MeasObj->measObject.choice.measObjectEUTRA.offsetFreq = NULL;   // Default is 15 or 0dB

  MeasObj->measObject.choice.measObjectEUTRA.cellsToAddModList =
    (CellsToAddModList_t *) CALLOC(1, sizeof(*CellsToAddModList));

  CellsToAddModList = MeasObj->measObject.choice.measObjectEUTRA.cellsToAddModList;

  // Add adjacent cell lists (6 per eNB)
  for (i = 0; i < 6; i++) {
    CellToAdd = (CellsToAddMod_t *) CALLOC(1, sizeof(*CellToAdd));
    CellToAdd->cellIndex = i + 1;
3961
    CellToAdd->physCellId = get_adjacent_cell_id(ctxt_pP->module_id, i);
3962 3963 3964 3965
    CellToAdd->cellIndividualOffset = Q_OffsetRange_dB0;

    ASN_SEQUENCE_ADD(&CellsToAddModList->list, CellToAdd);
  }
3966

3967 3968
  ASN_SEQUENCE_ADD(&MeasObj_list->list, MeasObj);
  //  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->measObjectToAddModList = MeasObj_list;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3969

3970
  // Report Configurations for periodical, A1-A5 events
3971

3972
  /* RRC Strategy Measurement */
3973 3974


3975
  if (strcmp("one_shot", trig_param->trigger_policy) == 0){
3976

3977 3978
      trig_param->report_interval = 0;
      trig_param->report_amount = 0;
3979

3980
  }
3981

3982
  else if (strcmp("event_driven", trig_param->trigger_policy) == 0){
3983

3984 3985
      trig_param->report_interval = 6;
      trig_param->report_amount = 2;
3986

3987
  }
3988

3989
  else if (strcmp("periodical", trig_param->trigger_policy) == 0){
3990

3991 3992
      trig_param->report_interval = 1;
      trig_param->report_amount = 7;
3993

3994
  }
3995

3996
  else {
3997

3998 3999
     LOG_E(FLEXRAN_AGENT, "There is something wrong on RRC agent!");
  }
4000 4001 4002



4003
  ReportConfig_list = CALLOC(1, sizeof(*ReportConfig_list));
4004

4005
  ReportConfig_per = CALLOC(1, sizeof(*ReportConfig_per));
4006

4007
    // Periodical Measurement Report
4008

4009 4010
  ReportConfig_per->reportConfigId = 1;
  ReportConfig_per->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
4011

4012 4013
    ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerType.present =
      ReportConfigEUTRA__triggerType_PR_periodical;
4014

4015 4016
    ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerType.choice.periodical.purpose =
      ReportConfigEUTRA__triggerType__periodical__purpose_reportStrongestCells;
4017

4018 4019 4020 4021 4022
    // ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.timeToTrigger = TimeToTrigger_ms40;  
    ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerQuantity = ReportConfigEUTRA__triggerQuantity_rsrp;
   ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
   ReportConfig_per->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
   ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportInterval = trig_param->report_interval ;//ReportInterval_ms2048; // RRC counter frame- ms1024 is 1ms   
4023

4024
   ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportAmount = trig_param->report_amount; //ReportConfigEUTRA__reportAmount_r2; // put r1 to see once, r2 for 2 times and ...
4025 4026


4027
  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_per);
4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044



    quantityConfig = CALLOC(1, sizeof(*quantityConfig));
    memset((void *)quantityConfig, 0, sizeof(*quantityConfig));
    quantityConfig->quantityConfigEUTRA = CALLOC(1, sizeof(struct QuantityConfigEUTRA));
    memset((void *)quantityConfig->quantityConfigEUTRA, 0, sizeof(*quantityConfig->quantityConfigEUTRA));
    quantityConfig->quantityConfigCDMA2000 = NULL;
    quantityConfig->quantityConfigGERAN = NULL;
    quantityConfig->quantityConfigUTRA = NULL;
    quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP =
      CALLOC(1, sizeof(*(quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP)));
    quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ =
      CALLOC(1, sizeof(*(quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ)));
    *quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP = FilterCoefficient_fc4;
    *quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ = FilterCoefficient_fc4;

4045
  
4046 4047 4048 4049 4050
#if defined(ENABLE_ITTI)
  /* Initialize NAS list */
  dedicatedInfoNASList = CALLOC(1, sizeof(struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList));

  /* Add all NAS PDUs to the list */
4051 4052
  for (i = 0; i < ue_context_pP->ue_context.nb_of_e_rabs; i++) {
    if (ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer != NULL) {
4053 4054
      dedicatedInfoNas = CALLOC(1, sizeof(DedicatedInfoNAS_t));
      memset(dedicatedInfoNas, 0, sizeof(OCTET_STRING_t));
4055
      OCTET_STRING_fromBuf(dedicatedInfoNas, 
4056
         (char*)ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer,
4057
                           ue_context_pP->ue_context.e_rab[i].param.nas_pdu.length);
4058
      ASN_SEQUENCE_ADD(&dedicatedInfoNASList->list, dedicatedInfoNas);
4059
    }
4060

4061
    /* TODO parameters yet to process ... */
4062
    // {
4063 4064 4065
      //      ue_context_pP->ue_context.e_rab[i].param.qos;
      //      ue_context_pP->ue_context.e_rab[i].param.sgw_addr;
      //      ue_context_pP->ue_context.e_rab[i].param.gtp_teid;
4066
    // }
4067 4068

    /* TODO should test if e RAB are Ok before! */
4069
    ue_context_pP->ue_context.e_rab[i].status = E_RAB_STATUS_DONE;
4070
    LOG_D(RRC, "setting the status for the default DRB (index %d) to (%d,%s)\n", 
4071
    i, ue_context_pP->ue_context.e_rab[i].status, "E_RAB_STATUS_DONE");
4072 4073 4074 4075 4076 4077 4078 4079
  }

  /* If list is empty free the list and reset the address */
  if (dedicatedInfoNASList->list.count == 0) {
    free(dedicatedInfoNASList);
    dedicatedInfoNASList = NULL;
  }

4080 4081
#endif

4082
  memset(buffer, 0, RRC_BUF_SIZE);
4083
  
4084 4085
  size = do_RRCConnectionReconfiguration(ctxt_pP,
                                         buffer,
4086
                                         xid,   //Transaction_id,
4087 4088
                                         (SRB_ToAddModList_t*)NULL, // SRB_configList
                                         (DRB_ToAddModList_t*)NULL,
4089 4090
                                         (DRB_ToReleaseList_t*)NULL,  // DRB2_list,
                                         (struct SPS_Config*)NULL,    // *sps_Config,
4091
                                         (struct PhysicalConfigDedicated*)*physicalConfigDedicated,
4092 4093 4094
// #ifdef EXMIMO_IOT
//                                          NULL, NULL, NULL,NULL,
// #else
4095 4096 4097 4098
                                         (MeasObjectToAddModList_t*)MeasObj_list,
                                         (ReportConfigToAddModList_t*)ReportConfig_list,
                                         (QuantityConfig_t*)quantityConfig,
                                         (MeasIdToAddModList_t*)MeasId_list,
4099
// #endif
4100 4101 4102 4103 4104 4105
                                         (MAC_MainConfig_t*)mac_MainConfig,
                                         (MeasGapConfig_t*)NULL,
                                         (MobilityControlInfo_t*)NULL,
                                         (struct MeasConfig__speedStatePars*)Sparams,
                                         (RSRP_Range_t*)rsrp,
                                         (C_RNTI_t*)cba_RNTI,
4106 4107 4108
                                         (struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList*)dedicatedInfoNASList,
                                         (SL_CommConfig_r12_t*)NULL,
                                         (SL_DiscConfig_r12_t*)NULL
4109
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
4110
                                         , (SCellToAddMod_r10_t*)NULL
4111
#endif
4112
                                        );
4113 4114
  LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)buffer,size,
              "[MSG] RRC Connection Reconfiguration\n");
4115

4116
#if defined(ENABLE_ITTI)
4117 4118

  /* Free all NAS PDUs */
4119 4120
  for (i = 0; i < ue_context_pP->ue_context.nb_of_e_rabs; i++) {
    if (ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer != NULL) {
4121
      /* Free the NAS PDU buffer and invalidate it */
4122 4123
      free(ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer);
      ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer = NULL;
4124
    }
4125 4126
  }

4127
#endif
4128

4129
  LOG_I(RRC,
4130 4131
        "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate RRCConnectionReconfiguration (bytes %d, UE id %x)\n",
        ctxt_pP->module_id, ctxt_pP->frame, size, ue_context_pP->ue_context.rnti);
4132

4133
  LOG_D(RRC,
4134 4135
        "[FRAME %05d][RRC_eNB][MOD %u][][--- PDCP_DATA_REQ/%d Bytes (rrcConnectionReconfiguration to UE %x MUI %d) --->][PDCP][MOD %u][RB %u]\n",
        ctxt_pP->frame, ctxt_pP->module_id, size, ue_context_pP->ue_context.rnti, rrc_eNB_mui, ctxt_pP->module_id, DCCH);
4136 4137

  MSC_LOG_TX_MESSAGE(
4138 4139 4140 4141 4142 4143 4144 4145 4146
    MSC_RRC_ENB,
    MSC_RRC_UE,
    buffer,
    size,
    MSC_AS_TIME_FMT" rrcConnectionReconfiguration UE %x MUI %d size %u",
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP->ue_context.rnti,
    rrc_eNB_mui,
    size);
4147

4148
  rrc_data_req(
4149 4150 4151 4152 4153 4154 4155
         ctxt_pP,
         DCCH,
         rrc_eNB_mui++,
         SDU_CONFIRM_NO,
         size,
         buffer,
         PDCP_TRANSMISSION_MODE_CONTROL);
winckel's avatar
winckel committed
4156
}
4157

4158

4159 4160 4161 4162 4163 4164 4165 4166
//-----------------------------------------------------------------------------
int
rrc_eNB_generate_RRCConnectionReconfiguration_SCell(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t* const ue_context_pP,
  uint32_t dl_CarrierFreq_r10
)
//-----------------------------------------------------------------------------
4167
{
4168 4169 4170

  uint8_t size;
  uint8_t buffer[100];
4171

4172
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
4173
  uint8_t sCellIndexToAdd = 0; //one SCell so far
4174 4175 4176

  //   uint8_t sCellIndexToAdd;
  //   sCellIndexToAdd = rrc_find_free_SCell_index(enb_mod_idP, ue_mod_idP, 1);
4177
  //  if (RC.rrc[enb_mod_idP]->sCell_config[ue_mod_idP][sCellIndexToAdd] ) {
4178 4179
  if (ue_context_pP->ue_context.sCell_config != NULL) {
    ue_context_pP->ue_context.sCell_config[sCellIndexToAdd].cellIdentification_r10->dl_CarrierFreq_r10 = dl_CarrierFreq_r10;
4180
  } else {
4181 4182
    LOG_E(RRC,"Scell not configured!\n");
    return(-1);
4183 4184
  }

4185
#endif
4186
  size = do_RRCConnectionReconfiguration(ctxt_pP,
4187
                                         buffer,
4188
                                         rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),//Transaction_id,
4189 4190 4191 4192 4193 4194 4195
                                         (SRB_ToAddModList_t*)NULL,
                                         (DRB_ToAddModList_t*)NULL,
                                         (DRB_ToReleaseList_t*)NULL,
                                         (struct SPS_Config*)NULL,
                                         (struct PhysicalConfigDedicated*)NULL,
                                         (MeasObjectToAddModList_t*)NULL,
                                         (ReportConfigToAddModList_t*)NULL,
4196
                                         (QuantityConfig_t*)NULL,
4197 4198 4199 4200 4201 4202 4203
                                         (MeasIdToAddModList_t*)NULL,
                                         (MAC_MainConfig_t*)NULL,
                                         (MeasGapConfig_t*)NULL,
                                         (MobilityControlInfo_t*)NULL,
                                         (struct MeasConfig__speedStatePars*)NULL,
                                         (RSRP_Range_t*)NULL,
                                         (C_RNTI_t*)NULL,
4204 4205 4206
                                         (struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList*)NULL,
                                         (SL_CommConfig_r12_t*)NULL,
                                         (SL_DiscConfig_r12_t*)NULL
4207

4208
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
4209
                                         , ue_context_pP->ue_context.sCell_config
4210
#endif
4211
                                        );
4212 4213 4214
  LOG_I(RRC,"[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate RRCConnectionReconfiguration (bytes %d, UE id %x)\n",
        ctxt_pP->module_id,ctxt_pP->frame, size, ue_context_pP->ue_context.rnti);

4215
  MSC_LOG_TX_MESSAGE(
4216 4217 4218 4219 4220 4221 4222 4223 4224
    MSC_RRC_ENB,
    MSC_RRC_UE,
    buffer,
    size,
    MSC_AS_TIME_FMT" rrcConnectionReconfiguration UE %x MUI %d size %u",
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP->ue_context.rnti,
    rrc_eNB_mui,
    size);
4225

4226 4227 4228 4229 4230 4231 4232 4233
  rrc_data_req(
	       ctxt_pP,
	       DCCH,
	       rrc_eNB_mui++,
	       SDU_CONFIRM_NO,
	       size,
	       buffer,
	       PDCP_TRANSMISSION_MODE_CONTROL);
4234 4235 4236 4237
  return(0);
}


4238 4239 4240 4241
//-----------------------------------------------------------------------------
void
rrc_eNB_process_MeasurementReport(
  const protocol_ctxt_t* const ctxt_pP,
4242
  rrc_eNB_ue_context_t*         ue_context_pP,
4243 4244 4245
  const MeasResults_t*   const measResults2
)
//-----------------------------------------------------------------------------
4246
{
4247 4248 4249
  int i=0;
  int neighboring_cells=-1;
  
Cedric Roux's avatar
Cedric Roux committed
4250 4251 4252
  T(T_ENB_RRC_MEASUREMENT_REPORT, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267
  if (measResults2 == NULL )
    return;
  
  if (measResults2->measId > 0 ){
     if (ue_context_pP->ue_context.measResults == NULL) {
       ue_context_pP->ue_context.measResults = CALLOC(1, sizeof(MeasResults_t));
     }
     ue_context_pP->ue_context.measResults->measId=measResults2->measId; 
     ue_context_pP->ue_context.measResults->measResultPCell.rsrpResult=measResults2->measResultPCell.rsrpResult;
     ue_context_pP->ue_context.measResults->measResultPCell.rsrqResult=measResults2->measResultPCell.rsrqResult;
     LOG_D(RRC, "[eNB %d]Frame %d: UE %x (Measurement Id %d): RSRP of Source %ld\n", ctxt_pP->module_id, ctxt_pP->frame, ctxt_pP->rnti, (int)measResults2->measId, ue_context_pP->ue_context.measResults->measResultPCell.rsrpResult-140);
     LOG_D(RRC, "[eNB %d]Frame %d: UE %x (Measurement Id %d): RSRQ of Source %ld\n", ctxt_pP->module_id, ctxt_pP->frame, ctxt_pP->rnti, (int)measResults2->measId, ue_context_pP->ue_context.measResults->measResultPCell.rsrqResult/2 - 20);
   }
   if (measResults2->measResultNeighCells == NULL)
     return;
4268

4269
   if (measResults2->measResultNeighCells->choice.measResultListEUTRA.list.count > 0) {
4270
     neighboring_cells = measResults2->measResultNeighCells->choice.measResultListEUTRA.list.count;
4271 4272 4273 4274 4275
     
     if (ue_context_pP->ue_context.measResults->measResultNeighCells == NULL) {
       
       ue_context_pP->ue_context.measResults->measResultNeighCells = CALLOC(1, sizeof(*measResults2->measResultNeighCells)*neighboring_cells);
     }
4276
     ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.count = neighboring_cells;
4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289
     for (i=0; i < neighboring_cells; i++){
       memcpy (ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[i],
	       measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[i],
	       sizeof(MeasResultListEUTRA_t));
       
       LOG_D(RRC, "Physical Cell Id %d\n",
	     (int)ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->physCellId);
       LOG_D(RRC, "RSRP of Target %d\n",
	     (int)*(ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->measResult.rsrpResult));
       LOG_D(RRC, "RSRQ of Target %d\n",
	     (int)*(ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->measResult.rsrqResult));
     }
   }
4290

4291
// #if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
4292

4293
  
4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307
// #else
  // LOG_I(RRC, "RSRP of Source %d\n", measResults2->measResultServCell.rsrpResult);
  // LOG_I(RRC, "RSRQ of Source %d\n", measResults2->measResultServCell.rsrqResult);
// #endif

  // if (ue_context_pP->ue_context.handover_info->ho_prepare != 0xF0) {
  //   rrc_eNB_generate_HandoverPreparationInformation(ctxt_pP,
  //       ue_context_pP,
  //       measResults2->measResultNeighCells->choice.
  //       measResultListEUTRA.list.array[0]->physCellId);
  // } else {
  //   LOG_D(RRC, "[eNB %d] Frame %d: Ignoring MeasReport from UE %x as Handover is in progress... \n", ctxt_pP->module_id, ctxt_pP->frame,
  //         ctxt_pP->rnti);
  // }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4308

4309 4310 4311 4312
  //Look for IP address of the target eNB
  //Send Handover Request -> target eNB
  //Wait for Handover Acknowledgement <- target eNB
  //Send Handover Command
4313

4314 4315
  //x2delay();
  //    handover_request_x2(ue_mod_idP,enb_mod_idP,measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[0]->physCellId);
4316

4317 4318 4319 4320 4321
  //    uint8_t buffer[100];
  //    int size=rrc_eNB_generate_Handover_Command_TeNB(0,0,buffer);
  //
  //      send_check_message((char*)buffer,size);
  //send_handover_command();
4322

4323 4324
}

4325 4326 4327 4328 4329 4330 4331 4332
//-----------------------------------------------------------------------------
void
rrc_eNB_generate_HandoverPreparationInformation(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t* const ue_context_pP,
  PhysCellId_t                 targetPhyId
)
//-----------------------------------------------------------------------------
4333
{
4334 4335
  struct rrc_eNB_ue_context_s*        ue_context_target_p = NULL;
  //uint8_t                             UE_id_target        = -1;
4336 4337 4338 4339 4340
  uint8_t                             mod_id_target = get_adjacent_cell_mod_id(targetPhyId);
  HANDOVER_INFO                      *handoverInfo = CALLOC(1, sizeof(*handoverInfo));
  /*
     uint8_t buffer[100];
     uint8_t size;
4341
     struct PhysicalConfigDedicated  **physicalConfigDedicated = &RC.rrc[enb_mod_idP]->physicalConfigDedicated[ue_mod_idP];
4342 4343
     RadioResourceConfigDedicated_t *radioResourceConfigDedicated = CALLOC(1,sizeof(RadioResourceConfigDedicated_t));
   */
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4344

Cedric Roux's avatar
Cedric Roux committed
4345 4346 4347
  T(T_ENB_RRC_HANDOVER_PREPARATION_INFORMATION, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

4348 4349 4350 4351
  handoverInfo->as_config.antennaInfoCommon.antennaPortsCount = 0;    //Not used 0- but check value
  handoverInfo->as_config.sourceDl_CarrierFreq = 36090;   //Verify!

  memcpy((void *)&handoverInfo->as_config.sourceMasterInformationBlock,
4352
         (void*)&RC.rrc[ctxt_pP->module_id]->carrier[0] /* CROUX TBC */.mib, sizeof(MasterInformationBlock_t));
4353
  memcpy((void *)&handoverInfo->as_config.sourceMeasConfig,
4354
         (void*)ue_context_pP->ue_context.measConfig, sizeof(MeasConfig_t));
4355 4356 4357 4358 4359 4360

  // FIXME handoverInfo not used...
  free( handoverInfo );
  handoverInfo = 0;

  //to be configured
4361
  memset((void*)&ue_context_pP->ue_context.handover_info->as_config.sourceSecurityAlgorithmConfig,
4362 4363
         0, sizeof(SecurityAlgorithmConfig_t));

4364
  memcpy((void*)&ue_context_pP->ue_context.handover_info->as_config.sourceSystemInformationBlockType1,
4365
         (void*)&RC.rrc[ctxt_pP->module_id]->carrier[0] /* CROUX TBC */.SIB1, sizeof(SystemInformationBlockType1_t));
4366
  memcpy((void*)&ue_context_pP->ue_context.handover_info->as_config.sourceSystemInformationBlockType2,
4367
         (void*)&RC.rrc[ctxt_pP->module_id]->carrier[0] /* CROUX TBC */.SIB23, sizeof(SystemInformationBlockType2_t));
4368
  ue_context_pP->ue_context.handover_info->as_context.reestablishmentInfo =
4369
    CALLOC(1, sizeof(ReestablishmentInfo_t));
4370
  ue_context_pP->ue_context.handover_info->as_context.reestablishmentInfo->sourcePhysCellId =
4371
    RC.rrc[ctxt_pP->module_id]->carrier[0] /* CROUX TBC */.physCellId;
4372 4373 4374 4375 4376 4377
  ue_context_pP->ue_context.handover_info->as_context.reestablishmentInfo->targetCellShortMAC_I.buf = NULL;  // Check values later
  ue_context_pP->ue_context.handover_info->as_context.reestablishmentInfo->targetCellShortMAC_I.size = 0;
  ue_context_pP->ue_context.handover_info->as_context.reestablishmentInfo->targetCellShortMAC_I.bits_unused = 0;
  ue_context_pP->ue_context.handover_info->as_context.reestablishmentInfo->additionalReestabInfoList = NULL;
  ue_context_pP->ue_context.handover_info->ho_prepare = 0xFF;    //0xF0;
  ue_context_pP->ue_context.handover_info->ho_complete = 0;
4378 4379 4380

  if (mod_id_target != 0xFF) {
    //UE_id_target = rrc_find_free_ue_index(modid_target);
4381 4382
    ue_context_target_p =
      rrc_eNB_get_ue_context(
4383
        RC.rrc[mod_id_target],
4384 4385 4386 4387
        ue_context_pP->ue_context.rnti);

    /*UE_id_target = rrc_eNB_get_next_free_UE_index(
                    mod_id_target,
4388
                    RC.rrc[ctxt_pP->module_id]->Info.UE_list[ue_mod_idP]);  //this should return a new index*/
4389 4390

    if (ue_context_target_p == NULL) { // if not already in target cell
4391
      ue_context_target_p = rrc_eNB_allocate_new_UE_context(RC.rrc[ctxt_pP->module_id]);
4392 4393
      ue_context_target_p->ue_id_rnti      = ue_context_pP->ue_context.rnti;             // LG: should not be the same
      ue_context_target_p->ue_context.rnti = ue_context_target_p->ue_id_rnti; // idem
4394
      LOG_I(RRC,
Cedric Roux's avatar
Cedric Roux committed
4395
            "[eNB %d] Frame %d : Emulate sending HandoverPreparationInformation msg from eNB source %d to eNB target %ld: source UE_id %x target UE_id %x source_modId: %d target_modId: %d\n",
4396 4397
            ctxt_pP->module_id,
            ctxt_pP->frame,
4398
            RC.rrc[ctxt_pP->module_id]->carrier[0] /* CROUX TBC */.physCellId,
4399 4400 4401 4402
            targetPhyId,
            ue_context_pP->ue_context.rnti,
            ue_context_target_p->ue_id_rnti,
            ctxt_pP->module_id,
4403
            mod_id_target);
4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421
      ue_context_target_p->ue_context.handover_info =
        CALLOC(1, sizeof(*(ue_context_target_p->ue_context.handover_info)));
      memcpy((void*)&ue_context_target_p->ue_context.handover_info->as_context,
             (void*)&ue_context_pP->ue_context.handover_info->as_context,
             sizeof(AS_Context_t));
      memcpy((void*)&ue_context_target_p->ue_context.handover_info->as_config,
             (void*)&ue_context_pP->ue_context.handover_info->as_config,
             sizeof(AS_Config_t));
      ue_context_target_p->ue_context.handover_info->ho_prepare = 0x00;// 0xFF;
      ue_context_target_p->ue_context.handover_info->ho_complete = 0;
      ue_context_pP->ue_context.handover_info->modid_t = mod_id_target;
      ue_context_pP->ue_context.handover_info->ueid_s  = ue_context_pP->ue_context.rnti;
      ue_context_pP->ue_context.handover_info->modid_s = ctxt_pP->module_id;
      ue_context_target_p->ue_context.handover_info->modid_t = mod_id_target;
      ue_context_target_p->ue_context.handover_info->modid_s = ctxt_pP->module_id;
      ue_context_target_p->ue_context.handover_info->ueid_t  = ue_context_target_p->ue_context.rnti;

    } else {
Cedric Roux's avatar
Cedric Roux committed
4422
      LOG_E(RRC, "\nError in obtaining free UE id in target eNB %ld for handover \n", targetPhyId);
4423 4424 4425
    }

  } else {
4426
    LOG_E(RRC, "\nError in obtaining Module ID of target eNB for handover \n");
4427
  }
4428 4429
}

4430 4431 4432 4433 4434 4435 4436
//-----------------------------------------------------------------------------
void
rrc_eNB_process_handoverPreparationInformation(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t*           const ue_context_pP
)
//-----------------------------------------------------------------------------
4437
{
Cedric Roux's avatar
Cedric Roux committed
4438 4439 4440
  T(T_ENB_RRC_HANDOVER_PREPARATION_INFORMATION, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

4441

4442 4443
  LOG_I(RRC,
        "[eNB %d] Frame %d : Logical Channel UL-DCCH, processing RRCHandoverPreparationInformation, sending RRCConnectionReconfiguration to UE %d \n",
4444 4445 4446 4447 4448 4449
        ctxt_pP->module_id, ctxt_pP->frame, ue_context_pP->ue_context.rnti);
  rrc_eNB_generate_RRCConnectionReconfiguration_handover(
    ctxt_pP,
    ue_context_pP,
    NULL,
    0);
winckel's avatar
winckel committed
4450
}
4451

4452 4453 4454 4455 4456

//-----------------------------------------------------------------------------
void
check_handovers(
  protocol_ctxt_t* const ctxt_pP
4457
)
4458
//-----------------------------------------------------------------------------
4459
{
4460
  int                                 result;
4461
  struct rrc_eNB_ue_context_s*        ue_context_p;
4462
  RB_FOREACH(ue_context_p, rrc_ue_tree_s, &RC.rrc[ctxt_pP->module_id]->rrc_ue_head) {
4463
    ctxt_pP->rnti  = ue_context_p->ue_id_rnti;
4464

4465 4466
    if (ue_context_p->ue_context.handover_info != NULL) {
      if (ue_context_p->ue_context.handover_info->ho_prepare == 0xFF) {
4467 4468
        LOG_D(RRC,
              "[eNB %d] Frame %d: Incoming handover detected for new UE_idx %d (source eNB %d->target eNB %d) \n",
4469 4470 4471 4472 4473
              ctxt_pP->module_id,
              ctxt_pP->frame,
              ctxt_pP->rnti,
              ctxt_pP->module_id,
              ue_context_p->ue_context.handover_info->modid_t);
4474
        // source eNB generates rrcconnectionreconfiguration to prepare the HO
4475 4476 4477 4478
        rrc_eNB_process_handoverPreparationInformation(
          ctxt_pP,
          ue_context_p);
        ue_context_p->ue_context.handover_info->ho_prepare = 0xF1;
4479 4480
      }

4481
      if (ue_context_p->ue_context.handover_info->ho_complete == 0xF1) {
4482
        LOG_D(RRC,
4483 4484 4485 4486 4487 4488
              "[eNB %d] Frame %d: handover Command received for new UE_id  %x current eNB %d target eNB: %d \n",
              ctxt_pP->module_id,
              ctxt_pP->frame,
              ctxt_pP->rnti,
              ctxt_pP->module_id,
              ue_context_p->ue_context.handover_info->modid_t);
4489
        //rrc_eNB_process_handoverPreparationInformation(enb_mod_idP,frameP,i);
4490
        result = pdcp_data_req(ctxt_pP,
4491 4492 4493
                               SRB_FLAG_YES,
                               DCCH,
                               rrc_eNB_mui++,
4494 4495 4496
                               SDU_CONFIRM_NO,
                               ue_context_p->ue_context.handover_info->size,
                               ue_context_p->ue_context.handover_info->buf,
4497
                               PDCP_TRANSMISSION_MODE_CONTROL
4498
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
4499 4500 4501
                               ,NULL, NULL
#endif
                               );
4502
        //AssertFatal(result == TRUE, "PDCP data request failed!\n");
4503 4504 4505 4506 4507
        if(result != TRUE)
        {
          LOG_I(RRC, "PDCP data request failed!\n");
          return;
        }
4508
        ue_context_p->ue_context.handover_info->ho_complete = 0xF2;
4509
      }
winckel's avatar
winckel committed
4510
    }
4511
  }
4512
}
winckel's avatar
RRC:  
winckel committed
4513

winckel's avatar
winckel committed
4514
// 5.3.5.4 RRCConnectionReconfiguration including the mobilityControlInfo to prepare the UE handover
4515 4516 4517 4518 4519 4520 4521 4522 4523
//-----------------------------------------------------------------------------
void
rrc_eNB_generate_RRCConnectionReconfiguration_handover(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t*           const ue_context_pP,
  uint8_t*                const nas_pdu,
  const uint32_t                nas_length
)
//-----------------------------------------------------------------------------
4524
{
Cedric Roux's avatar
Cedric Roux committed
4525 4526 4527
  T(T_ENB_RRC_CONNECTION_RECONFIGURATION, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

Lionel Gauthier's avatar
 
Lionel Gauthier committed
4528

4529 4530 4531 4532 4533
  uint8_t                             buffer[RRC_BUF_SIZE];
  int                                 i;
  uint8_t                             rv[2];
  uint16_t                            Idx;
  // configure SRB1/SRB2, PhysicalConfigDedicated, MAC_MainConfig for UE
4534
  eNB_RRC_INST*                       rrc_inst = RC.rrc[ctxt_pP->module_id];
4535
  struct PhysicalConfigDedicated**    physicalConfigDedicated = &ue_context_pP->ue_context.physicalConfigDedicated;
4536 4537 4538 4539 4540 4541

  struct SRB_ToAddMod                *SRB2_config;
  struct SRB_ToAddMod__rlc_Config    *SRB2_rlc_config;
  struct SRB_ToAddMod__logicalChannelConfig *SRB2_lchan_config;
  struct LogicalChannelConfig__ul_SpecificParameters *SRB2_ul_SpecificParameters;
  LogicalChannelConfig_t             *SRB1_logicalChannelConfig = NULL;
4542
  SRB_ToAddModList_t*                 SRB_configList = ue_context_pP->ue_context.SRB_configList;    // not used in this context: may be removed
4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563
  SRB_ToAddModList_t                 *SRB_configList2;

  struct DRB_ToAddMod                *DRB_config;
  struct RLC_Config                  *DRB_rlc_config;
  struct PDCP_Config                 *DRB_pdcp_config;
  struct PDCP_Config__rlc_UM         *PDCP_rlc_UM;
  struct LogicalChannelConfig        *DRB_lchan_config;
  struct LogicalChannelConfig__ul_SpecificParameters *DRB_ul_SpecificParameters;
  DRB_ToAddModList_t                 *DRB_configList2;

  MAC_MainConfig_t                   *mac_MainConfig;
  MeasObjectToAddModList_t           *MeasObj_list;
  MeasObjectToAddMod_t               *MeasObj;
  ReportConfigToAddModList_t         *ReportConfig_list;
  ReportConfigToAddMod_t             *ReportConfig_per, *ReportConfig_A1,
                                     *ReportConfig_A2, *ReportConfig_A3, *ReportConfig_A4, *ReportConfig_A5;
  MeasIdToAddModList_t               *MeasId_list;
  MeasIdToAddMod_t                   *MeasId0, *MeasId1, *MeasId2, *MeasId3, *MeasId4, *MeasId5;
  QuantityConfig_t                   *quantityConfig;
  MobilityControlInfo_t              *mobilityInfo;
  // HandoverCommand_t handoverCommand;
4564 4565
  //uint8_t                             sourceModId =
  //  get_adjacent_cell_mod_id(ue_context_pP->ue_context.handover_info->as_context.reestablishmentInfo->sourcePhysCellId);
4566
#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585
  long                               *sr_ProhibitTimer_r9;
#endif

  long                               *logicalchannelgroup, *logicalchannelgroup_drb;
  long                               *maxHARQ_Tx, *periodicBSR_Timer;

  // RSRP_Range_t *rsrp;
  struct MeasConfig__speedStatePars  *Sparams;
  CellsToAddMod_t                    *CellToAdd;
  CellsToAddModList_t                *CellsToAddModList;
  // srb 1: for HO
  struct SRB_ToAddMod                *SRB1_config;
  struct SRB_ToAddMod__rlc_Config    *SRB1_rlc_config;
  struct SRB_ToAddMod__logicalChannelConfig *SRB1_lchan_config;
  struct LogicalChannelConfig__ul_SpecificParameters *SRB1_ul_SpecificParameters;
  // phy config dedicated
  PhysicalConfigDedicated_t          *physicalConfigDedicated2;
  struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList;
  protocol_ctxt_t                     ctxt;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4586

4587 4588
  LOG_D(RRC, "[eNB %d] Frame %d: handover preparation: get the newSourceUEIdentity (C-RNTI): ",
        ctxt_pP->module_id, ctxt_pP->frame);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4589

4590 4591 4592 4593
  for (i = 0; i < 2; i++) {
    rv[i] = taus() & 0xff;
    LOG_D(RRC, " %x.", rv[i]);
  }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4594

4595
  LOG_D(RRC, "[eNB %d] Frame %d : handover reparation: add target eNB SRB1 and PHYConfigDedicated reconfiguration\n",
4596
        ctxt_pP->module_id, ctxt_pP->frame);
4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653
  // 1st: reconfigure SRB
  SRB_configList2 = CALLOC(1, sizeof(*SRB_configList));
  SRB1_config = CALLOC(1, sizeof(*SRB1_config));
  SRB1_config->srb_Identity = 1;
  SRB1_rlc_config = CALLOC(1, sizeof(*SRB1_rlc_config));
  SRB1_config->rlc_Config = SRB1_rlc_config;

  SRB1_rlc_config->present = SRB_ToAddMod__rlc_Config_PR_explicitValue;
  SRB1_rlc_config->choice.explicitValue.present = RLC_Config_PR_am;
  SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.t_PollRetransmit = T_PollRetransmit_ms15;
  SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollPDU = PollPDU_p8;
  SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollByte = PollByte_kB1000;
  SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.maxRetxThreshold = UL_AM_RLC__maxRetxThreshold_t16;
  SRB1_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_Reordering = T_Reordering_ms35;
  SRB1_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_StatusProhibit = T_StatusProhibit_ms10;

  SRB1_lchan_config = CALLOC(1, sizeof(*SRB1_lchan_config));
  SRB1_config->logicalChannelConfig = SRB1_lchan_config;

  SRB1_lchan_config->present = SRB_ToAddMod__logicalChannelConfig_PR_explicitValue;
  SRB1_ul_SpecificParameters = CALLOC(1, sizeof(*SRB1_ul_SpecificParameters));

  SRB1_lchan_config->choice.explicitValue.ul_SpecificParameters = SRB1_ul_SpecificParameters;

  SRB1_ul_SpecificParameters->priority = 1;

  //assign_enum(&SRB1_ul_SpecificParameters->prioritisedBitRate,LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity);
  SRB1_ul_SpecificParameters->prioritisedBitRate =
    LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;

  //assign_enum(&SRB1_ul_SpecificParameters->bucketSizeDuration,LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50);
  SRB1_ul_SpecificParameters->bucketSizeDuration =
    LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;

  logicalchannelgroup = CALLOC(1, sizeof(long));
  *logicalchannelgroup = 0;
  SRB1_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup;

  ASN_SEQUENCE_ADD(&SRB_configList2->list, SRB1_config);

  //2nd: now reconfigure phy config dedicated
  physicalConfigDedicated2 = CALLOC(1, sizeof(*physicalConfigDedicated2));
  *physicalConfigDedicated = physicalConfigDedicated2;

  physicalConfigDedicated2->pdsch_ConfigDedicated =
    CALLOC(1, sizeof(*physicalConfigDedicated2->pdsch_ConfigDedicated));
  physicalConfigDedicated2->pucch_ConfigDedicated =
    CALLOC(1, sizeof(*physicalConfigDedicated2->pucch_ConfigDedicated));
  physicalConfigDedicated2->pusch_ConfigDedicated =
    CALLOC(1, sizeof(*physicalConfigDedicated2->pusch_ConfigDedicated));
  physicalConfigDedicated2->uplinkPowerControlDedicated =
    CALLOC(1, sizeof(*physicalConfigDedicated2->uplinkPowerControlDedicated));
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH =
    CALLOC(1, sizeof(*physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH));
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH =
    CALLOC(1, sizeof(*physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH));
  physicalConfigDedicated2->cqi_ReportConfig = NULL;  //CALLOC(1,sizeof(*physicalConfigDedicated2->cqi_ReportConfig));
hbilel's avatar
hbilel committed
4654
  physicalConfigDedicated2->soundingRS_UL_ConfigDedicated = CALLOC(1,sizeof(*physicalConfigDedicated2->soundingRS_UL_ConfigDedicated));
4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694
  physicalConfigDedicated2->antennaInfo = CALLOC(1, sizeof(*physicalConfigDedicated2->antennaInfo));
  physicalConfigDedicated2->schedulingRequestConfig =
    CALLOC(1, sizeof(*physicalConfigDedicated2->schedulingRequestConfig));
  // PDSCH
  //assign_enum(&physicalConfigDedicated2->pdsch_ConfigDedicated->p_a,
  //          PDSCH_ConfigDedicated__p_a_dB0);
  physicalConfigDedicated2->pdsch_ConfigDedicated->p_a = PDSCH_ConfigDedicated__p_a_dB0;

  // PUCCH
  physicalConfigDedicated2->pucch_ConfigDedicated->ackNackRepetition.present =
    PUCCH_ConfigDedicated__ackNackRepetition_PR_release;
  physicalConfigDedicated2->pucch_ConfigDedicated->ackNackRepetition.choice.release = 0;
  physicalConfigDedicated2->pucch_ConfigDedicated->tdd_AckNackFeedbackMode = NULL;    //PUCCH_ConfigDedicated__tdd_AckNackFeedbackMode_multiplexing;

  // Pusch_config_dedicated
  physicalConfigDedicated2->pusch_ConfigDedicated->betaOffset_ACK_Index = 0;  // 2.00
  physicalConfigDedicated2->pusch_ConfigDedicated->betaOffset_RI_Index = 0;   // 1.25
  physicalConfigDedicated2->pusch_ConfigDedicated->betaOffset_CQI_Index = 8;  // 2.25

  // UplinkPowerControlDedicated
  physicalConfigDedicated2->uplinkPowerControlDedicated->p0_UE_PUSCH = 0; // 0 dB
  //assign_enum(&physicalConfigDedicated2->uplinkPowerControlDedicated->deltaMCS_Enabled,
  // UplinkPowerControlDedicated__deltaMCS_Enabled_en1);
  physicalConfigDedicated2->uplinkPowerControlDedicated->deltaMCS_Enabled =
    UplinkPowerControlDedicated__deltaMCS_Enabled_en1;
  physicalConfigDedicated2->uplinkPowerControlDedicated->accumulationEnabled = 1; // should be TRUE in order to have 0dB power offset
  physicalConfigDedicated2->uplinkPowerControlDedicated->p0_UE_PUCCH = 0; // 0 dB
  physicalConfigDedicated2->uplinkPowerControlDedicated->pSRS_Offset = 0; // 0 dB
  physicalConfigDedicated2->uplinkPowerControlDedicated->filterCoefficient =
    CALLOC(1, sizeof(*physicalConfigDedicated2->uplinkPowerControlDedicated->filterCoefficient));
  //  assign_enum(physicalConfigDedicated2->uplinkPowerControlDedicated->filterCoefficient,FilterCoefficient_fc4); // fc4 dB
  *physicalConfigDedicated2->uplinkPowerControlDedicated->filterCoefficient = FilterCoefficient_fc4;  // fc4 dB

  // TPC-PDCCH-Config
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->present = TPC_PDCCH_Config_PR_setup;
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_Index.present = TPC_Index_PR_indexOfFormat3;
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_Index.choice.indexOfFormat3 = 1;
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_RNTI.buf = CALLOC(1, 2);
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_RNTI.size = 2;
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_RNTI.buf[0] = 0x12;
4695
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_RNTI.buf[1] = 0x34 + ue_context_pP->local_uid;
4696 4697 4698 4699 4700 4701 4702 4703
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_RNTI.bits_unused = 0;

  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->present = TPC_PDCCH_Config_PR_setup;
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_Index.present = TPC_Index_PR_indexOfFormat3;
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_Index.choice.indexOfFormat3 = 1;
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_RNTI.buf = CALLOC(1, 2);
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_RNTI.size = 2;
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_RNTI.buf[0] = 0x22;
4704
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_RNTI.buf[1] = 0x34 + ue_context_pP->local_uid;
4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_RNTI.bits_unused = 0;

  // CQI ReportConfig
  /*
     physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportModeAperiodic=CALLOC(1,sizeof(*physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportModeAperiodic));
     assign_enum(physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportModeAperiodic,
     CQI_ReportConfig__cqi_ReportModeAperiodic_rm30); // HLC CQI, no PMI
     physicalConfigDedicated2->cqi_ReportConfig->nomPDSCH_RS_EPRE_Offset = 0; // 0 dB
     physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic=CALLOC(1,sizeof(*physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic));
     physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->present =  CQI_ReportPeriodic_PR_setup;
     physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->choice.setup.cqi_PUCCH_ResourceIndex = 0;  // n2_pucch
     physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->choice.setup.cqi_pmi_ConfigIndex = 0;  // Icqi/pmi
     physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present = CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_subbandCQI;  // subband CQI
     physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.choice.subbandCQI.k=4;

     physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->choice.setup.ri_ConfigIndex=NULL;
     physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->choice.setup.simultaneousAckNackAndCQI=0;
   */
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4723

4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737
  //soundingRS-UL-ConfigDedicated
  /*
     physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->present = SoundingRS_UL_ConfigDedicated_PR_setup;
     assign_enum(&physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.srs_Bandwidth,
     SoundingRS_UL_ConfigDedicated__setup__srs_Bandwidth_bw0);
     assign_enum(&physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.srs_HoppingBandwidth,
     SoundingRS_UL_ConfigDedicated__setup__srs_HoppingBandwidth_hbw0);
     physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.freqDomainPosition=0;
     physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.duration=1;
     physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.srs_ConfigIndex=1;
     physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.transmissionComb=0;
     assign_enum(&physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.cyclicShift,
     SoundingRS_UL_ConfigDedicated__setup__cyclicShift_cs0);
   */
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4738

4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768
  //AntennaInfoDedicated
  physicalConfigDedicated2->antennaInfo = CALLOC(1, sizeof(*physicalConfigDedicated2->antennaInfo));
  physicalConfigDedicated2->antennaInfo->present = PhysicalConfigDedicated__antennaInfo_PR_explicitValue;
  //assign_enum(&physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode,
  //     AntennaInfoDedicated__transmissionMode_tm2);
  /*
     switch (transmission_mode){
     case 1:
     physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm1;
     break;
     case 2:
     physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm2;
     break;
     case 4:
     physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm4;
     break;
     case 5:
     physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm5;
     break;
     case 6:
     physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm6;
     break;
     }
   */
  physicalConfigDedicated2->antennaInfo->choice.explicitValue.ue_TransmitAntennaSelection.present =
    AntennaInfoDedicated__ue_TransmitAntennaSelection_PR_release;
  physicalConfigDedicated2->antennaInfo->choice.explicitValue.ue_TransmitAntennaSelection.choice.release = 0;

  // SchedulingRequestConfig
  physicalConfigDedicated2->schedulingRequestConfig->present = SchedulingRequestConfig_PR_setup;
4769
  physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_PUCCH_ResourceIndex = ue_context_pP->local_uid;
4770

4771
  if (rrc_inst->carrier[0].sib1->tdd_Config==NULL) {  // FD
4772 4773
    physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_ConfigIndex = 5 + (ue_context_pP->local_uid %
        10);   // Isr = 5 (every 10 subframes, offset=2+UE_id mod3)
4774
  } else {
4775
    switch (rrc_inst->carrier[0].sib1->tdd_Config->subframeAssignment) {
4776
    case 1:
4777 4778
      physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_ConfigIndex = 7 + (ue_context_pP->local_uid & 1) + ((
            ue_context_pP->local_uid & 3) >> 1) * 5;    // Isr = 5 (every 10 subframes, offset=2 for UE0, 3 for UE1, 7 for UE2, 8 for UE3 , 2 for UE4 etc..)
4779 4780 4781
      break;

    case 3:
4782 4783
      physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_ConfigIndex = 7 + (ue_context_pP->local_uid %
          3);    // Isr = 5 (every 10 subframes, offset=2 for UE0, 3 for UE1, 3 for UE2, 2 for UE3 , etc..)
4784 4785 4786
      break;

    case 4:
4787 4788
      physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_ConfigIndex = 7 + (ue_context_pP->local_uid &
          1);    // Isr = 5 (every 10 subframes, offset=2 for UE0, 3 for UE1, 3 for UE2, 2 for UE3 , etc..)
4789 4790 4791 4792 4793
      break;

    default:
      physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_ConfigIndex = 7; // Isr = 5 (every 10 subframes, offset=2 for all UE0 etc..)
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4794
    }
4795
  }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4796

4797 4798 4799 4800 4801 4802 4803
  //  assign_enum(&physicalConfigDedicated2->schedulingRequestConfig->choice.setup.dsr_TransMax,
  //SchedulingRequestConfig__setup__dsr_TransMax_n4);
  //  assign_enum(&physicalConfigDedicated2->schedulingRequestConfig->choice.setup.dsr_TransMax = SchedulingRequestConfig__setup__dsr_TransMax_n4;
  physicalConfigDedicated2->schedulingRequestConfig->choice.setup.dsr_TransMax =
    SchedulingRequestConfig__setup__dsr_TransMax_n4;

  LOG_D(RRC,
4804 4805
        "handover_config [FRAME %05d][RRC_eNB][MOD %02d][][--- MAC_CONFIG_REQ  (SRB1 UE %x) --->][MAC_eNB][MOD %02d][]\n",
        ctxt_pP->frame, ctxt_pP->module_id, ue_context_pP->ue_context.rnti, ctxt_pP->module_id);
4806
  if (RC.rrc[ctxt_pP->module_id]->node_type == ngran_eNB) {
4807 4808 4809 4810
    rrc_mac_config_req_eNB(
			   ctxt_pP->module_id,
			   ue_context_pP->ue_context.primaryCC_id,
			   0,0,0,0,0,
4811
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
4812
			   0,
4813
#endif 
4814 4815 4816
			   ue_context_pP->ue_context.rnti,
			   (BCCH_BCH_Message_t *) NULL,
			   (RadioResourceConfigCommonSIB_t*) NULL,
4817
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
4818
			   (RadioResourceConfigCommonSIB_t*) NULL,
4819
#endif
4820
			   ue_context_pP->ue_context.physicalConfigDedicated,
4821
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
4822 4823
			   (SCellToAddMod_r10_t *)NULL,
			   //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
4824
#endif
4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836
			   (MeasObjectToAddMod_t **) NULL,
			   ue_context_pP->ue_context.mac_MainConfig,
			   1,
			   SRB1_logicalChannelConfig,
			   ue_context_pP->ue_context.measGapConfig,
			   (TDD_Config_t*) NULL,
			   (MobilityControlInfo_t*) NULL,
			   (SchedulingInfoList_t*) NULL,
			   0,
			   NULL,
			   NULL,
			   (MBSFN_SubframeConfigList_t *) NULL
4837
#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
4838
			   , 0, (MBSFN_AreaInfoList_r9_t *) NULL, (PMCH_InfoList_r9_t *) NULL
4839
#endif
4840
#if (RRC_VERSION >= MAKE_VERSION(13, 0, 0))
4841 4842
			   ,
			   (SystemInformationBlockType1_v1310_IEs_t *)NULL
4843
#endif
4844 4845
			   );
  }
4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863
  // Configure target eNB SRB2
  /// SRB2
  SRB2_config = CALLOC(1, sizeof(*SRB2_config));
  SRB_configList2 = CALLOC(1, sizeof(*SRB_configList2));
  memset(SRB_configList2, 0, sizeof(*SRB_configList2));

  SRB2_config->srb_Identity = 2;
  SRB2_rlc_config = CALLOC(1, sizeof(*SRB2_rlc_config));
  SRB2_config->rlc_Config = SRB2_rlc_config;

  SRB2_rlc_config->present = SRB_ToAddMod__rlc_Config_PR_explicitValue;
  SRB2_rlc_config->choice.explicitValue.present = RLC_Config_PR_am;
  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.t_PollRetransmit = T_PollRetransmit_ms15;
  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollPDU = PollPDU_p8;
  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollByte = PollByte_kB1000;
  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.maxRetxThreshold = UL_AM_RLC__maxRetxThreshold_t32;
  SRB2_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_Reordering = T_Reordering_ms35;
  SRB2_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_StatusProhibit = T_StatusProhibit_ms10;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4864

4865 4866
  SRB2_lchan_config = CALLOC(1, sizeof(*SRB2_lchan_config));
  SRB2_config->logicalChannelConfig = SRB2_lchan_config;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4867

4868
  SRB2_lchan_config->present = SRB_ToAddMod__logicalChannelConfig_PR_explicitValue;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4869

4870
  SRB2_ul_SpecificParameters = CALLOC(1, sizeof(*SRB2_ul_SpecificParameters));
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4871

4872 4873 4874 4875 4876
  SRB2_ul_SpecificParameters->priority = 1;
  SRB2_ul_SpecificParameters->prioritisedBitRate =
    LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
  SRB2_ul_SpecificParameters->bucketSizeDuration =
    LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4877

4878 4879 4880
  // LCG for CCCH and DCCH is 0 as defined in 36331
  logicalchannelgroup = CALLOC(1, sizeof(long));
  *logicalchannelgroup = 0;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4881

4882 4883 4884 4885
  SRB2_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup;
  SRB2_lchan_config->choice.explicitValue.ul_SpecificParameters = SRB2_ul_SpecificParameters;
  ASN_SEQUENCE_ADD(&SRB_configList->list, SRB2_config);
  ASN_SEQUENCE_ADD(&SRB_configList2->list, SRB2_config);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4886

4887 4888 4889 4890
  // Configure target eNB DRB
  DRB_configList2 = CALLOC(1, sizeof(*DRB_configList2));
  /// DRB
  DRB_config = CALLOC(1, sizeof(*DRB_config));
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4891

4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902
  //DRB_config->drb_Identity = (DRB_Identity_t) 1; //allowed values 1..32
  // NN: this is the 1st DRB for this ue, so set it to 1
  DRB_config->drb_Identity = (DRB_Identity_t) 1;  // (ue_mod_idP+1); //allowed values 1..32
  DRB_config->logicalChannelIdentity = CALLOC(1, sizeof(long));
  *(DRB_config->logicalChannelIdentity) = (long)3;
  DRB_rlc_config = CALLOC(1, sizeof(*DRB_rlc_config));
  DRB_config->rlc_Config = DRB_rlc_config;
  DRB_rlc_config->present = RLC_Config_PR_um_Bi_Directional;
  DRB_rlc_config->choice.um_Bi_Directional.ul_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering = T_Reordering_ms35;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4903

4904 4905 4906 4907 4908 4909 4910 4911
  DRB_pdcp_config = CALLOC(1, sizeof(*DRB_pdcp_config));
  DRB_config->pdcp_Config = DRB_pdcp_config;
  DRB_pdcp_config->discardTimer = NULL;
  DRB_pdcp_config->rlc_AM = NULL;
  PDCP_rlc_UM = CALLOC(1, sizeof(*PDCP_rlc_UM));
  DRB_pdcp_config->rlc_UM = PDCP_rlc_UM;
  PDCP_rlc_UM->pdcp_SN_Size = PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits;
  DRB_pdcp_config->headerCompression.present = PDCP_Config__headerCompression_PR_notUsed;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4912

4913 4914 4915 4916
  DRB_lchan_config = CALLOC(1, sizeof(*DRB_lchan_config));
  DRB_config->logicalChannelConfig = DRB_lchan_config;
  DRB_ul_SpecificParameters = CALLOC(1, sizeof(*DRB_ul_SpecificParameters));
  DRB_lchan_config->ul_SpecificParameters = DRB_ul_SpecificParameters;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4917

4918 4919 4920 4921 4922
  DRB_ul_SpecificParameters->priority = 2;    // lower priority than srb1, srb2
  DRB_ul_SpecificParameters->prioritisedBitRate =
    LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
  DRB_ul_SpecificParameters->bucketSizeDuration =
    LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4923

4924 4925 4926 4927
  // LCG for DTCH can take the value from 1 to 3 as defined in 36331: normally controlled by upper layers (like RRM)
  logicalchannelgroup_drb = CALLOC(1, sizeof(long));
  *logicalchannelgroup_drb = 1;
  DRB_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup_drb;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4928

4929
  ASN_SEQUENCE_ADD(&DRB_configList2->list, DRB_config);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4930

4931
  mac_MainConfig = CALLOC(1, sizeof(*mac_MainConfig));
4932
  ue_context_pP->ue_context.mac_MainConfig = mac_MainConfig;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4933

4934
  mac_MainConfig->ul_SCH_Config = CALLOC(1, sizeof(*mac_MainConfig->ul_SCH_Config));
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4935

4936 4937 4938
  maxHARQ_Tx = CALLOC(1, sizeof(long));
  *maxHARQ_Tx = MAC_MainConfig__ul_SCH_Config__maxHARQ_Tx_n5;
  mac_MainConfig->ul_SCH_Config->maxHARQ_Tx = maxHARQ_Tx;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4939

4940
  periodicBSR_Timer = CALLOC(1, sizeof(long));
Cedric Roux's avatar
Cedric Roux committed
4941
  *periodicBSR_Timer = PeriodicBSR_Timer_r12_sf64;
4942
  mac_MainConfig->ul_SCH_Config->periodicBSR_Timer = periodicBSR_Timer;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4943

Cedric Roux's avatar
Cedric Roux committed
4944
  mac_MainConfig->ul_SCH_Config->retxBSR_Timer = RetxBSR_Timer_r12_sf320;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4945

4946 4947 4948
  mac_MainConfig->ul_SCH_Config->ttiBundling = 0; // FALSE

  mac_MainConfig->drx_Config = NULL;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4949

4950
  mac_MainConfig->phr_Config = CALLOC(1, sizeof(*mac_MainConfig->phr_Config));
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4951

4952 4953
  mac_MainConfig->phr_Config->present = MAC_MainConfig__phr_Config_PR_setup;
  mac_MainConfig->phr_Config->choice.setup.periodicPHR_Timer = MAC_MainConfig__phr_Config__setup__periodicPHR_Timer_sf20; // sf20 = 20 subframes
4954

4955
  mac_MainConfig->phr_Config->choice.setup.prohibitPHR_Timer = MAC_MainConfig__phr_Config__setup__prohibitPHR_Timer_sf20; // sf20 = 20 subframes
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4956

4957 4958
  mac_MainConfig->phr_Config->choice.setup.dl_PathlossChange = MAC_MainConfig__phr_Config__setup__dl_PathlossChange_dB1;  // Value dB1 =1 dB, dB3 = 3 dB

4959
#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
4960 4961
  sr_ProhibitTimer_r9 = CALLOC(1, sizeof(long));
  *sr_ProhibitTimer_r9 = 0;   // SR tx on PUCCH, Value in number of SR period(s). Value 0 = no timer for SR, Value 2= 2*SR
4962 4963
  mac_MainConfig->ext1 = CALLOC(1, sizeof(struct MAC_MainConfig__ext1));
  mac_MainConfig->ext1->sr_ProhibitTimer_r9 = sr_ProhibitTimer_r9;
4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035
  //sps_RA_ConfigList_rlola = NULL;
#endif
  // Measurement ID list
  MeasId_list = CALLOC(1, sizeof(*MeasId_list));
  memset((void *)MeasId_list, 0, sizeof(*MeasId_list));

  MeasId0 = CALLOC(1, sizeof(*MeasId0));
  MeasId0->measId = 1;
  MeasId0->measObjectId = 1;
  MeasId0->reportConfigId = 1;
  ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId0);

  MeasId1 = CALLOC(1, sizeof(*MeasId1));
  MeasId1->measId = 2;
  MeasId1->measObjectId = 1;
  MeasId1->reportConfigId = 2;
  ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId1);

  MeasId2 = CALLOC(1, sizeof(*MeasId2));
  MeasId2->measId = 3;
  MeasId2->measObjectId = 1;
  MeasId2->reportConfigId = 3;
  ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId2);

  MeasId3 = CALLOC(1, sizeof(*MeasId3));
  MeasId3->measId = 4;
  MeasId3->measObjectId = 1;
  MeasId3->reportConfigId = 4;
  ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId3);

  MeasId4 = CALLOC(1, sizeof(*MeasId4));
  MeasId4->measId = 5;
  MeasId4->measObjectId = 1;
  MeasId4->reportConfigId = 5;
  ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId4);

  MeasId5 = CALLOC(1, sizeof(*MeasId5));
  MeasId5->measId = 6;
  MeasId5->measObjectId = 1;
  MeasId5->reportConfigId = 6;
  ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId5);

  //  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->measIdToAddModList = MeasId_list;

  // Add one EUTRA Measurement Object
  MeasObj_list = CALLOC(1, sizeof(*MeasObj_list));
  memset((void *)MeasObj_list, 0, sizeof(*MeasObj_list));

  // Configure MeasObject

  MeasObj = CALLOC(1, sizeof(*MeasObj));
  memset((void *)MeasObj, 0, sizeof(*MeasObj));

  MeasObj->measObjectId = 1;
  MeasObj->measObject.present = MeasObjectToAddMod__measObject_PR_measObjectEUTRA;
  MeasObj->measObject.choice.measObjectEUTRA.carrierFreq = 36090;
  MeasObj->measObject.choice.measObjectEUTRA.allowedMeasBandwidth = AllowedMeasBandwidth_mbw25;
  MeasObj->measObject.choice.measObjectEUTRA.presenceAntennaPort1 = 1;
  MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.buf = CALLOC(1, sizeof(uint8_t));
  MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.buf[0] = 0;
  MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.size = 1;
  MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.bits_unused = 6;
  MeasObj->measObject.choice.measObjectEUTRA.offsetFreq = NULL;   // Default is 15 or 0dB

  MeasObj->measObject.choice.measObjectEUTRA.cellsToAddModList =
    (CellsToAddModList_t *) CALLOC(1, sizeof(*CellsToAddModList));
  CellsToAddModList = MeasObj->measObject.choice.measObjectEUTRA.cellsToAddModList;

  // Add adjacent cell lists (6 per eNB)
  for (i = 0; i < 6; i++) {
    CellToAdd = (CellsToAddMod_t *) CALLOC(1, sizeof(*CellToAdd));
    CellToAdd->cellIndex = i + 1;
5036
    CellToAdd->physCellId = get_adjacent_cell_id(ctxt_pP->module_id, i);
5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200
    CellToAdd->cellIndividualOffset = Q_OffsetRange_dB0;

    ASN_SEQUENCE_ADD(&CellsToAddModList->list, CellToAdd);
  }

  ASN_SEQUENCE_ADD(&MeasObj_list->list, MeasObj);
  //  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->measObjectToAddModList = MeasObj_list;

  // Report Configurations for periodical, A1-A5 events
  ReportConfig_list = CALLOC(1, sizeof(*ReportConfig_list));

  ReportConfig_per = CALLOC(1, sizeof(*ReportConfig_per));

  ReportConfig_A1 = CALLOC(1, sizeof(*ReportConfig_A1));

  ReportConfig_A2 = CALLOC(1, sizeof(*ReportConfig_A2));

  ReportConfig_A3 = CALLOC(1, sizeof(*ReportConfig_A3));

  ReportConfig_A4 = CALLOC(1, sizeof(*ReportConfig_A4));

  ReportConfig_A5 = CALLOC(1, sizeof(*ReportConfig_A5));

  ReportConfig_per->reportConfigId = 1;
  ReportConfig_per->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerType.present =
    ReportConfigEUTRA__triggerType_PR_periodical;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerType.choice.periodical.purpose =
    ReportConfigEUTRA__triggerType__periodical__purpose_reportStrongestCells;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerQuantity = ReportConfigEUTRA__triggerQuantity_rsrp;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportInterval = ReportInterval_ms120;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;

  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_per);

  ReportConfig_A1->reportConfigId = 2;
  ReportConfig_A1->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.present =
    ReportConfigEUTRA__triggerType_PR_event;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
    ReportConfigEUTRA__triggerType__event__eventId_PR_eventA1;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA1.
  a1_Threshold.present = ThresholdEUTRA_PR_threshold_RSRP;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA1.
  a1_Threshold.choice.threshold_RSRP = 10;

  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerQuantity = ReportConfigEUTRA__triggerQuantity_rsrp;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportInterval = ReportInterval_ms120;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;

  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A1);

  ReportConfig_A2->reportConfigId = 3;
  ReportConfig_A2->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.present =
    ReportConfigEUTRA__triggerType_PR_event;
  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
    ReportConfigEUTRA__triggerType__event__eventId_PR_eventA2;
  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA2.
  a2_Threshold.present = ThresholdEUTRA_PR_threshold_RSRP;
  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA2.
  a2_Threshold.choice.threshold_RSRP = 10;

  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerQuantity = ReportConfigEUTRA__triggerQuantity_rsrp;
  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportInterval = ReportInterval_ms120;
  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;

  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A2);

  ReportConfig_A3->reportConfigId = 4;
  ReportConfig_A3->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.present =
    ReportConfigEUTRA__triggerType_PR_event;
  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
    ReportConfigEUTRA__triggerType__event__eventId_PR_eventA3;
  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA3.a3_Offset =
    10;
  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
  eventA3.reportOnLeave = 1;

  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerQuantity = ReportConfigEUTRA__triggerQuantity_rsrp;
  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportInterval = ReportInterval_ms120;
  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;

  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A3);

  ReportConfig_A4->reportConfigId = 5;
  ReportConfig_A4->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.present =
    ReportConfigEUTRA__triggerType_PR_event;
  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
    ReportConfigEUTRA__triggerType__event__eventId_PR_eventA4;
  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA4.
  a4_Threshold.present = ThresholdEUTRA_PR_threshold_RSRP;
  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA4.
  a4_Threshold.choice.threshold_RSRP = 10;

  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerQuantity = ReportConfigEUTRA__triggerQuantity_rsrp;
  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportInterval = ReportInterval_ms120;
  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;

  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A4);

  ReportConfig_A5->reportConfigId = 6;
  ReportConfig_A5->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.present =
    ReportConfigEUTRA__triggerType_PR_event;
  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
    ReportConfigEUTRA__triggerType__event__eventId_PR_eventA5;
  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
  eventA5.a5_Threshold1.present = ThresholdEUTRA_PR_threshold_RSRP;
  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
  eventA5.a5_Threshold2.present = ThresholdEUTRA_PR_threshold_RSRP;
  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
  eventA5.a5_Threshold1.choice.threshold_RSRP = 10;
  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
  eventA5.a5_Threshold2.choice.threshold_RSRP = 10;

  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerQuantity = ReportConfigEUTRA__triggerQuantity_rsrp;
  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportInterval = ReportInterval_ms120;
  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;

  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A5);

  Sparams = CALLOC(1, sizeof(*Sparams));
  Sparams->present = MeasConfig__speedStatePars_PR_setup;
  Sparams->choice.setup.timeToTrigger_SF.sf_High = SpeedStateScaleFactors__sf_Medium_oDot75;
  Sparams->choice.setup.timeToTrigger_SF.sf_Medium = SpeedStateScaleFactors__sf_High_oDot5;
  Sparams->choice.setup.mobilityStateParameters.n_CellChangeHigh = 10;
  Sparams->choice.setup.mobilityStateParameters.n_CellChangeMedium = 5;
  Sparams->choice.setup.mobilityStateParameters.t_Evaluation = MobilityStateParameters__t_Evaluation_s60;
  Sparams->choice.setup.mobilityStateParameters.t_HystNormal = MobilityStateParameters__t_HystNormal_s120;

  quantityConfig = CALLOC(1, sizeof(*quantityConfig));
  memset((void *)quantityConfig, 0, sizeof(*quantityConfig));
  quantityConfig->quantityConfigEUTRA = CALLOC(1, sizeof(*quantityConfig->quantityConfigEUTRA));
  memset((void *)quantityConfig->quantityConfigEUTRA, 0, sizeof(*quantityConfig->quantityConfigEUTRA));
  quantityConfig->quantityConfigCDMA2000 = NULL;
  quantityConfig->quantityConfigGERAN = NULL;
  quantityConfig->quantityConfigUTRA = NULL;
  quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP =
    CALLOC(1, sizeof(*quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP));
  quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ =
    CALLOC(1, sizeof(*quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ));
  *quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP = FilterCoefficient_fc4;
  *quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ = FilterCoefficient_fc4;

  /* mobilityinfo  */

  mobilityInfo = CALLOC(1, sizeof(*mobilityInfo));
  memset((void *)mobilityInfo, 0, sizeof(*mobilityInfo));
  mobilityInfo->targetPhysCellId =
5201
    (PhysCellId_t) two_tier_hexagonal_cellIds[ue_context_pP->ue_context.handover_info->modid_t];
Cedric Roux's avatar
Cedric Roux committed
5202
  LOG_D(RRC, "[eNB %d] Frame %d: handover preparation: targetPhysCellId: %ld mod_id: %d ue: %x \n",
5203 5204 5205 5206 5207
        ctxt_pP->module_id,
        ctxt_pP->frame,
        mobilityInfo->targetPhysCellId,
        ctxt_pP->module_id,
        ue_context_pP->ue_context.rnti);
5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227

  mobilityInfo->additionalSpectrumEmission = CALLOC(1, sizeof(*mobilityInfo->additionalSpectrumEmission));
  *mobilityInfo->additionalSpectrumEmission = 1;  //Check this value!

  mobilityInfo->t304 = MobilityControlInfo__t304_ms50;    // need to configure an appropriate value here

  // New UE Identity (C-RNTI) to identify an UE uniquely in a cell
  mobilityInfo->newUE_Identity.size = 2;
  mobilityInfo->newUE_Identity.bits_unused = 0;
  mobilityInfo->newUE_Identity.buf = rv;
  mobilityInfo->newUE_Identity.buf[0] = rv[0];
  mobilityInfo->newUE_Identity.buf[1] = rv[1];

  //memset((void *)&mobilityInfo->radioResourceConfigCommon,(void *)&rrc_inst->sib2->radioResourceConfigCommon,sizeof(RadioResourceConfigCommon_t));
  //memset((void *)&mobilityInfo->radioResourceConfigCommon,0,sizeof(RadioResourceConfigCommon_t));

  // Configuring radioResourceConfigCommon
  mobilityInfo->radioResourceConfigCommon.rach_ConfigCommon =
    CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.rach_ConfigCommon));
  memcpy((void *)mobilityInfo->radioResourceConfigCommon.rach_ConfigCommon,
5228
         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.rach_ConfigCommon, sizeof(RACH_ConfigCommon_t));
5229 5230 5231
  mobilityInfo->radioResourceConfigCommon.prach_Config.prach_ConfigInfo =
    CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.prach_Config.prach_ConfigInfo));
  memcpy((void *)mobilityInfo->radioResourceConfigCommon.prach_Config.prach_ConfigInfo,
5232
         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.prach_Config.prach_ConfigInfo,
5233 5234 5235
         sizeof(PRACH_ConfigInfo_t));

  mobilityInfo->radioResourceConfigCommon.prach_Config.rootSequenceIndex =
5236
    rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.prach_Config.rootSequenceIndex;
5237 5238 5239
  mobilityInfo->radioResourceConfigCommon.pdsch_ConfigCommon =
    CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.pdsch_ConfigCommon));
  memcpy((void *)mobilityInfo->radioResourceConfigCommon.pdsch_ConfigCommon,
5240
         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.pdsch_ConfigCommon, sizeof(PDSCH_ConfigCommon_t));
5241
  memcpy((void *)&mobilityInfo->radioResourceConfigCommon.pusch_ConfigCommon,
5242
         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.pusch_ConfigCommon, sizeof(PUSCH_ConfigCommon_t));
5243 5244 5245 5246
  mobilityInfo->radioResourceConfigCommon.phich_Config = NULL;
  mobilityInfo->radioResourceConfigCommon.pucch_ConfigCommon =
    CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.pucch_ConfigCommon));
  memcpy((void *)mobilityInfo->radioResourceConfigCommon.pucch_ConfigCommon,
5247
         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.pucch_ConfigCommon, sizeof(PUCCH_ConfigCommon_t));
5248 5249 5250
  mobilityInfo->radioResourceConfigCommon.soundingRS_UL_ConfigCommon =
    CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.soundingRS_UL_ConfigCommon));
  memcpy((void *)mobilityInfo->radioResourceConfigCommon.soundingRS_UL_ConfigCommon,
5251
         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon,
5252 5253 5254 5255
         sizeof(SoundingRS_UL_ConfigCommon_t));
  mobilityInfo->radioResourceConfigCommon.uplinkPowerControlCommon =
    CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.uplinkPowerControlCommon));
  memcpy((void *)mobilityInfo->radioResourceConfigCommon.uplinkPowerControlCommon,
5256
         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.uplinkPowerControlCommon,
5257 5258 5259 5260 5261 5262 5263
         sizeof(UplinkPowerControlCommon_t));
  mobilityInfo->radioResourceConfigCommon.antennaInfoCommon = NULL;
  mobilityInfo->radioResourceConfigCommon.p_Max = NULL;   // CALLOC(1,sizeof(*mobilityInfo->radioResourceConfigCommon.p_Max));
  //memcpy((void *)mobilityInfo->radioResourceConfigCommon.p_Max,(void *)rrc_inst->sib1->p_Max,sizeof(P_Max_t));
  mobilityInfo->radioResourceConfigCommon.tdd_Config = NULL;  //CALLOC(1,sizeof(TDD_Config_t));
  //memcpy((void *)mobilityInfo->radioResourceConfigCommon.tdd_Config,(void *)rrc_inst->sib1->tdd_Config,sizeof(TDD_Config_t));
  mobilityInfo->radioResourceConfigCommon.ul_CyclicPrefixLength =
5264
    rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.ul_CyclicPrefixLength;
5265 5266 5267 5268 5269 5270
  //End of configuration of radioResourceConfigCommon

  mobilityInfo->carrierFreq = CALLOC(1, sizeof(*mobilityInfo->carrierFreq));  //CALLOC(1,sizeof(CarrierFreqEUTRA_t)); 36090
  mobilityInfo->carrierFreq->dl_CarrierFreq = 36090;
  mobilityInfo->carrierFreq->ul_CarrierFreq = NULL;

5271 5272
  mobilityInfo->carrierBandwidth = CALLOC(1, sizeof(
      *mobilityInfo->carrierBandwidth));    //CALLOC(1,sizeof(struct CarrierBandwidthEUTRA));  AllowedMeasBandwidth_mbw25
5273 5274 5275 5276 5277 5278
  mobilityInfo->carrierBandwidth->dl_Bandwidth = CarrierBandwidthEUTRA__dl_Bandwidth_n25;
  mobilityInfo->carrierBandwidth->ul_Bandwidth = NULL;
  mobilityInfo->rach_ConfigDedicated = NULL;

  // store the srb and drb list for ho management, mainly in case of failure

5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291
  memcpy(ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.srb_ToAddModList,
         (void*)SRB_configList2,
         sizeof(SRB_ToAddModList_t));
  memcpy((void*)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.drb_ToAddModList,
         (void*)DRB_configList2,
         sizeof(DRB_ToAddModList_t));
  ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.drb_ToReleaseList = NULL;
  memcpy((void*)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig,
         (void*)mac_MainConfig,
         sizeof(MAC_MainConfig_t));
  memcpy((void*)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.physicalConfigDedicated,
         (void*)ue_context_pP->ue_context.physicalConfigDedicated,
         sizeof(PhysicalConfigDedicated_t));
5292 5293 5294 5295
  /*    memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.sps_Config,
     (void *)rrc_inst->sps_Config[ue_mod_idP],
     sizeof(SPS_Config_t));
   */
Cedric Roux's avatar
Cedric Roux committed
5296 5297
  LOG_I(RRC, "[eNB %d] Frame %d: adding new UE\n",
        ctxt_pP->module_id, ctxt_pP->frame);
5298 5299 5300
  //Idx = (ue_mod_idP * NB_RB_MAX) + DCCH;
  Idx = DCCH;
  // SRB1
5301 5302 5303 5304
  ue_context_pP->ue_context.Srb1.Active = 1;
  ue_context_pP->ue_context.Srb1.Srb_info.Srb_id = Idx;
  memcpy(&ue_context_pP->ue_context.Srb1.Srb_info.Lchan_desc[0], &DCCH_LCHAN_DESC, LCHAN_DESC_SIZE);
  memcpy(&ue_context_pP->ue_context.Srb1.Srb_info.Lchan_desc[1], &DCCH_LCHAN_DESC, LCHAN_DESC_SIZE);
5305

5306
  // SRB2 
5307 5308 5309 5310
  ue_context_pP->ue_context.Srb2.Active = 1;
  ue_context_pP->ue_context.Srb2.Srb_info.Srb_id = Idx;
  memcpy(&ue_context_pP->ue_context.Srb2.Srb_info.Lchan_desc[0], &DCCH_LCHAN_DESC, LCHAN_DESC_SIZE);
  memcpy(&ue_context_pP->ue_context.Srb2.Srb_info.Lchan_desc[1], &DCCH_LCHAN_DESC, LCHAN_DESC_SIZE);
5311

5312 5313
  LOG_I(RRC, "[eNB %d] CALLING RLC CONFIG SRB1 (rbid %d) for UE %x\n",
        ctxt_pP->module_id, Idx, ue_context_pP->ue_context.rnti);
5314 5315 5316 5317 5318

  //      rrc_pdcp_config_req (enb_mod_idP, frameP, 1, CONFIG_ACTION_ADD, idx, UNDEF_SECURITY_MODE);
  //      rrc_rlc_config_req(enb_mod_idP,frameP,1,CONFIG_ACTION_ADD,Idx,SIGNALLING_RADIO_BEARER,Rlc_info_am_config);

  rrc_pdcp_config_asn1_req(&ctxt,
5319
                           ue_context_pP->ue_context.SRB_configList,
5320
                           (DRB_ToAddModList_t *) NULL, (DRB_ToReleaseList_t *) NULL, 0xff, NULL, NULL, NULL
5321
#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
5322
                           , (PMCH_InfoList_r9_t *) NULL
winckel's avatar
winckel committed
5323
#endif
5324
                           ,NULL);
5325 5326
  if ( (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_eNB_CU) &&
       (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_ng_eNB_CU)&& 
5327 5328 5329 5330
       (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_gNB_CU)   ) {
    rrc_rlc_config_asn1_req(&ctxt,
			    ue_context_pP->ue_context.SRB_configList,
			    (DRB_ToAddModList_t *) NULL, (DRB_ToReleaseList_t *) NULL
5331
#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
5332 5333
			    , (PMCH_InfoList_r9_t *) NULL
			    , 0, 0
Lionel Gauthier's avatar
 
Lionel Gauthier committed
5334
#endif
5335 5336
			    );
  }
5337 5338
  /* Initialize NAS list */
  dedicatedInfoNASList = NULL;
5339

5340 5341 5342
  //  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->reportConfigToAddModList = ReportConfig_list;
  memset(buffer, 0, RRC_BUF_SIZE);

5343
 int size=do_RRCConnectionReconfiguration(
5344 5345 5346 5347 5348 5349
           ctxt_pP,
           buffer,
           rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),   //Transaction_id,
           SRB_configList2,
           DRB_configList2,
           NULL,  // DRB2_list,
5350
           NULL,    //*sps_Config,
5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361
           ue_context_pP->ue_context.physicalConfigDedicated,
           MeasObj_list,
           ReportConfig_list,
           NULL,    //quantityConfig,
           MeasId_list,
           mac_MainConfig,
           NULL,
           mobilityInfo,
           Sparams,
           NULL,
           NULL,
5362 5363 5364
           dedicatedInfoNASList,
           (SL_CommConfig_r12_t*)NULL,
           (SL_DiscConfig_r12_t*)NULL
5365
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
5366
           , NULL   // SCellToAddMod_r10_t
5367
#endif
5368
         );
5369 5370 5371 5372 5373
 if (size <= 0)
  LOG_E(RRC,
        "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate RRCConnectionReconfiguration for handover (bytes %d, UE rnti %x) failed\n",
        ctxt_pP->module_id, ctxt_pP->frame, size, ue_context_pP->ue_context.rnti);
 else
5374
  LOG_I(RRC,
5375 5376
        "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate RRCConnectionReconfiguration for handover (bytes %d, UE rnti %x)\n",
        ctxt_pP->module_id, ctxt_pP->frame, size, ue_context_pP->ue_context.rnti);
5377
  // to be updated if needed
5378 5379 5380
  /*if (RC.rrc[ctxt_pP->module_id]->SRB1_config[ue_mod_idP]->logicalChannelConfig) {
     if (RC.rrc[ctxt_pP->module_id]->SRB1_config[ue_mod_idP]->logicalChannelConfig->present == SRB_ToAddMod__logicalChannelConfig_PR_explicitValue) {
     SRB1_logicalChannelConfig = &RC.rrc[ctxt_pP->module_id]->SRB1_config[ue_mod_idP]->logicalChannelConfig->choice.explicitValue;
5381 5382 5383 5384 5385 5386 5387 5388 5389
     }
     else {
     SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
     }
     }
     else {
     SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
     }
   */
Lionel Gauthier's avatar
 
Lionel Gauthier committed
5390

5391
  LOG_D(RRC,
5392 5393 5394 5395
        "[FRAME %05d][RRC_eNB][MOD %02d][][--- PDCP_DATA_REQ/%d Bytes (rrcConnectionReconfiguration_handover to UE %x MUI %d) --->][PDCP][MOD %02d][RB %02d]\n",
        ctxt_pP->frame, ctxt_pP->module_id, size, ue_context_pP->ue_context.rnti, rrc_eNB_mui, ctxt_pP->module_id, DCCH);
  //rrc_rlc_data_req(ctxt_pP->module_id,frameP, 1,(ue_mod_idP*NB_RB_MAX)+DCCH,rrc_eNB_mui++,0,size,(char*)buffer);
  //pdcp_data_req (ctxt_pP->module_id, frameP, 1, (ue_mod_idP * NB_RB_MAX) + DCCH,rrc_eNB_mui++, 0, size, (char *) buffer, 1);
5396

5397
  if (RC.rrc[ctxt_pP->module_id]->node_type == ngran_eNB) {
5398 5399 5400 5401
    rrc_mac_config_req_eNB(
			   ctxt_pP->module_id,
			   ue_context_pP->ue_context.primaryCC_id,
			   0,0,0,0,0,
5402
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
5403
			   0,
5404
#endif
5405 5406 5407
			   ue_context_pP->ue_context.rnti,
			   (BCCH_BCH_Message_t *) NULL,
			   (RadioResourceConfigCommonSIB_t *) NULL,
5408
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
5409
			   (RadioResourceConfigCommonSIB_t *) NULL,
5410
#endif
5411
			   ue_context_pP->ue_context.physicalConfigDedicated,
5412
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
5413 5414
			   (SCellToAddMod_r10_t *)NULL,
			   //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
5415
#endif
5416 5417 5418 5419 5420 5421 5422 5423
			   (MeasObjectToAddMod_t **) NULL,
			   ue_context_pP->ue_context.mac_MainConfig,
			   1,
			   SRB1_logicalChannelConfig,
			   ue_context_pP->ue_context.measGapConfig,
			   (TDD_Config_t *) NULL,
			   (MobilityControlInfo_t *) mobilityInfo,
			   (SchedulingInfoList_t *) NULL, 0, NULL, NULL, (MBSFN_SubframeConfigList_t *) NULL
5424
#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
5425
			   , 0, (MBSFN_AreaInfoList_r9_t *) NULL, (PMCH_InfoList_r9_t *) NULL
5426
#endif
5427
#if (RRC_VERSION >= MAKE_VERSION(13, 0, 0))
5428 5429
			   ,
			   (SystemInformationBlockType1_v1310_IEs_t *)NULL
5430
#endif
5431 5432
			   );
  }
5433 5434 5435 5436 5437 5438
  /*
     handoverCommand.criticalExtensions.present = HandoverCommand__criticalExtensions_PR_c1;
     handoverCommand.criticalExtensions.choice.c1.present = HandoverCommand__criticalExtensions__c1_PR_handoverCommand_r8;
     handoverCommand.criticalExtensions.choice.c1.choice.handoverCommand_r8.handoverCommandMessage.buf = buffer;
     handoverCommand.criticalExtensions.choice.c1.choice.handoverCommand_r8.handoverCommandMessage.size = size;
   */
5439
//#warning "COMPILATION PROBLEM"
5440
#ifdef PROBLEM_COMPILATION_RESOLVED
Lionel Gauthier's avatar
 
Lionel Gauthier committed
5441

5442
  if (sourceModId != 0xFF) {
5443
    memcpy(RC.rrc[sourceModId].handover_info[RC.rrc[ctxt_pP->module_id]->handover_info[ue_mod_idP]->ueid_s]->buf,
5444
           (void *)buffer, size);
5445 5446
    RC.rrc[sourceModId].handover_info[RC.rrc[ctxt_pP->module_id]->handover_info[ue_mod_idP]->ueid_s]->size = size;
    RC.rrc[sourceModId].handover_info[RC.rrc[ctxt_pP->module_id]->handover_info[ue_mod_idP]->ueid_s]->ho_complete =
5447
      0xF1;
5448
    //RC.rrc[ctxt_pP->module_id]->handover_info[ue_mod_idP]->ho_complete = 0xFF;
5449
    LOG_D(RRC, "[eNB %d] Frame %d: setting handover complete to 0xF1 for (%d,%d) and to 0xFF for (%d,%d)\n",
5450 5451 5452
          ctxt_pP->module_id,
          ctxt_pP->frame,
          sourceModId,
5453
          RC.rrc[ctxt_pP->module_id]->handover_info[ue_mod_idP]->ueid_s,
5454 5455
          ctxt_pP->module_id,
          ue_mod_idP);
5456 5457 5458
  } else
    LOG_W(RRC,
          "[eNB %d] Frame %d: rrc_eNB_generate_RRCConnectionReconfiguration_handover: Could not find source eNB mod_id.\n",
5459
          ctxt_pP->module_id, ctxt_pP->frame);
5460

5461
#endif
winckel's avatar
winckel committed
5462
}
5463

winckel's avatar
winckel committed
5464
/*
Lionel Gauthier's avatar
 
Lionel Gauthier committed
5465
  void ue_rrc_process_rrcConnectionReconfiguration(uint8_t enb_mod_idP,frame_t frameP,
winckel's avatar
winckel committed
5466
  RRCConnectionReconfiguration_t *rrcConnectionReconfiguration,
5467
  uint8_t CH_index) {
5468

winckel's avatar
winckel committed
5469 5470
  if (rrcConnectionReconfiguration->criticalExtensions.present == RRCConnectionReconfiguration__criticalExtensions_PR_c1)
  if (rrcConnectionReconfiguration->criticalExtensions.choice.c1.present == RRCConnectionReconfiguration__criticalExtensions__c1_PR_rrcConnectionReconfiguration_r8) {
5471

winckel's avatar
winckel committed
5472
  if (rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated) {
Lionel Gauthier's avatar
 
Lionel Gauthier committed
5473
  rrc_ue_process_radioResourceConfigDedicated(enb_mod_idP,frameP,CH_index,
winckel's avatar
winckel committed
5474
  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated);
5475

winckel's avatar
winckel committed
5476 5477 5478 5479 5480 5481 5482
  }

  // check other fields for
  }
  }
*/

5483 5484 5485 5486
//-----------------------------------------------------------------------------
void
rrc_eNB_process_RRCConnectionReconfigurationComplete(
  const protocol_ctxt_t* const ctxt_pP,
5487 5488
  rrc_eNB_ue_context_t*        ue_context_pP,
  const uint8_t xid
5489 5490
)
//-----------------------------------------------------------------------------
5491
{
5492
  int                                 i, drb_id;
5493
#ifdef PDCP_USE_NETLINK
5494 5495
  int                                 oip_ifup = 0;
  int                                 dest_ip_offset = 0;
Cedric Roux's avatar
Cedric Roux committed
5496 5497 5498
  /* avoid gcc warnings */
  (void)oip_ifup;
  (void)dest_ip_offset;
winckel's avatar
winckel committed
5499 5500
#endif

5501 5502 5503
  uint8_t                            *kRRCenc = NULL;
  uint8_t                            *kRRCint = NULL;
  uint8_t                            *kUPenc = NULL;
5504
  ue_context_pP->ue_context.ue_reestablishment_timer = 0;
winckel's avatar
winckel committed
5505

5506 5507
  DRB_ToAddModList_t*                 DRB_configList = ue_context_pP->ue_context.DRB_configList2[xid];
  SRB_ToAddModList_t*                 SRB_configList = ue_context_pP->ue_context.SRB_configList2[xid];
5508 5509
  DRB_ToReleaseList_t*                DRB_Release_configList2 = ue_context_pP->ue_context.DRB_Release_configList2[xid];
  DRB_Identity_t*                     drb_id_p      = NULL;
winckel's avatar
winckel committed
5510

Cedric Roux's avatar
Cedric Roux committed
5511 5512 5513
  T(T_ENB_RRC_CONNECTION_RECONFIGURATION_COMPLETE, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

winckel's avatar
winckel committed
5514 5515
#if defined(ENABLE_SECURITY)

5516 5517
  /* Derive the keys from kenb */
  if (DRB_configList != NULL) {
5518 5519
    derive_key_up_enc(ue_context_pP->ue_context.ciphering_algorithm,
                      ue_context_pP->ue_context.kenb, &kUPenc);
5520 5521
  }

5522
  LOG_I(RRC,"Deriving keys for UE RNTI %x\n",ctxt_pP->rnti);
5523 5524 5525 5526
  derive_key_rrc_enc(ue_context_pP->ue_context.ciphering_algorithm,
                     ue_context_pP->ue_context.kenb, &kRRCenc);
  derive_key_rrc_int(ue_context_pP->ue_context.integrity_algorithm,
                     ue_context_pP->ue_context.kenb, &kRRCint);
5527

winckel's avatar
winckel committed
5528
#endif
5529 5530

  // Refresh SRBs/DRBs
Lionel Gauthier's avatar
Lionel Gauthier committed
5531 5532 5533 5534 5535 5536 5537 5538 5539
  MSC_LOG_TX_MESSAGE(
    MSC_RRC_ENB,
    MSC_PDCP_ENB,
    NULL,
    0,
    MSC_AS_TIME_FMT" CONFIG_REQ UE %x DRB (security unchanged)",
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP->ue_context.rnti);

5540
  rrc_pdcp_config_asn1_req(
5541
    ctxt_pP,
Navid Nikaein's avatar
Navid Nikaein committed
5542
    SRB_configList, //NULL,  //LG-RK 14/05/2014 SRB_configList,
5543
    DRB_configList, 
5544 5545
//    (DRB_ToReleaseList_t *) NULL,
    DRB_Release_configList2,
5546 5547
    /*RC.rrc[ctxt_pP->module_id]->ciphering_algorithm[ue_mod_idP] |
             (RC.rrc[ctxt_pP->module_id]->integrity_algorithm[ue_mod_idP] << 4),
5548 5549 5550 5551 5552
     */
    0xff, // already configured during the securitymodecommand
    kRRCenc,
    kRRCint,
    kUPenc
5553
#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
5554 5555
    , (PMCH_InfoList_r9_t *) NULL
#endif
5556
    ,NULL);
5557 5558
  if ( (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_eNB_CU) && 
       (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_ng_eNB_CU)&& 
5559 5560 5561 5562 5563 5564 5565 5566
       (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_gNB_CU)   ) {
    // Refresh SRBs/DRBs
    rrc_rlc_config_asn1_req(
			    ctxt_pP,
			    SRB_configList, // NULL,  //LG-RK 14/05/2014 SRB_configList,
			    DRB_configList,
			    //    (DRB_ToReleaseList_t *) NULL
			    DRB_Release_configList2
5567
#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
5568 5569
			    , (PMCH_InfoList_r9_t *) NULL
			    , 0, 0
winckel's avatar
winckel committed
5570
#endif
5571 5572
			    );
  }
5573

5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587
  // set the SRB active in Ue context
  if (SRB_configList != NULL) {
    for (i = 0; (i < SRB_configList->list.count) && (i < 3); i++) {
      if (SRB_configList->list.array[i]->srb_Identity == 1 ){
	ue_context_pP->ue_context.Srb1.Active=1;
      }
      else if (SRB_configList->list.array[i]->srb_Identity == 2 )  {
	  ue_context_pP->ue_context.Srb2.Active=1;
	  ue_context_pP->ue_context.Srb2.Srb_info.Srb_id=2;
	     LOG_I(RRC,"[eNB %d] Frame  %d CC %d : SRB2 is now active\n",
		ctxt_pP->module_id,
		ctxt_pP->frame,
		ue_context_pP->ue_context.primaryCC_id);
      } else {
Cedric Roux's avatar
Cedric Roux committed
5588
	LOG_W(RRC,"[eNB %d] Frame  %d CC %d : invalide SRB identity %ld\n",
5589 5590
	      ctxt_pP->module_id,
	      ctxt_pP->frame,
Cedric Roux's avatar
Cedric Roux committed
5591
              ue_context_pP->ue_context.primaryCC_id,
5592 5593 5594
	      SRB_configList->list.array[i]->srb_Identity);
      }
    }
5595 5596
    free(SRB_configList);
    ue_context_pP->ue_context.SRB_configList2[xid] = NULL;
5597 5598
  }
  
5599
  // Loop through DRBs and establish if necessary
Lionel Gauthier's avatar
 
Lionel Gauthier committed
5600

5601 5602 5603
  if (DRB_configList != NULL) {
    for (i = 0; i < DRB_configList->list.count; i++) {  // num max DRB (11-3-8)
      if (DRB_configList->list.array[i]) {
5604
	drb_id = (int)DRB_configList->list.array[i]->drb_Identity;
5605
        LOG_I(RRC,
5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617
              "[eNB %d] Frame  %d : Logical Channel UL-DCCH, Received RRCConnectionReconfigurationComplete from UE rnti %x, reconfiguring DRB %d/LCID %d\n",
              ctxt_pP->module_id,
              ctxt_pP->frame,
              ctxt_pP->rnti,
              (int)DRB_configList->list.array[i]->drb_Identity,
              (int)*DRB_configList->list.array[i]->logicalChannelIdentity);
        // for pre-ci tests
        LOG_I(RRC,
              "[eNB %d] Frame  %d : Logical Channel UL-DCCH, Received RRCConnectionReconfigurationComplete from UE %u, reconfiguring DRB %d/LCID %d\n",
              ctxt_pP->module_id,
              ctxt_pP->frame,
              oai_emulation.info.eNB_ue_local_uid_to_ue_module_id[ctxt_pP->module_id][ue_context_pP->local_uid],
5618
              (int)DRB_configList->list.array[i]->drb_Identity,
5619
              (int)*DRB_configList->list.array[i]->logicalChannelIdentity);
5620

5621
        if (ue_context_pP->ue_context.DRB_active[drb_id] == 0) {
5622
          /*
5623
             rrc_pdcp_config_req (ctxt_pP->module_id, frameP, 1, CONFIG_ACTION_ADD,
5624
             (ue_mod_idP * NB_RB_MAX) + *DRB_configList->list.array[i]->logicalChannelIdentity,UNDEF_SECURITY_MODE);
5625
             rrc_rlc_config_req(ctxt_pP->module_id,frameP,1,CONFIG_ACTION_ADD,
5626
             (ue_mod_idP * NB_RB_MAX) + (int)*RC.rrc[ctxt_pP->module_id]->DRB_config[ue_mod_idP][i]->logicalChannelIdentity,
5627 5628
             RADIO_ACCESS_BEARER,Rlc_info_um);
           */
5629
          ue_context_pP->ue_context.DRB_active[drb_id] = 1;
5630 5631
          LOG_D(RRC,
                "[eNB %d] Frame %d: Establish RLC UM Bidirectional, DRB %d Active\n",
5632 5633
                ctxt_pP->module_id, ctxt_pP->frame, (int)DRB_configList->list.array[i]->drb_Identity);
#if  defined(PDCP_USE_NETLINK) && !defined(LINK_ENB_PDCP_TO_GTPV1U)
5634
          // can mean also IPV6 since ether -> ipv6 autoconf
5635
#   if !defined(OAI_NW_DRIVER_TYPE_ETHERNET) && !defined(EXMIMO) && !defined(OAI_USRP) && !defined(OAI_BLADERF) && !defined(ETHERNET)
5636 5637 5638
          LOG_I(OIP, "[eNB %d] trying to bring up the OAI interface oai%d\n",
                ctxt_pP->module_id,
                ctxt_pP->module_id);
5639
          oip_ifup = nas_config(
5640 5641 5642
                       ctxt_pP->module_id,   // interface index
                       ctxt_pP->module_id + 1,   // thrid octet
                       ctxt_pP->module_id + 1);  // fourth octet
Lionel Gauthier's avatar
 
Lionel Gauthier committed
5643

5644
          if (oip_ifup == 0) {    // interface is up --> send a config the DRB
5645
            module_id_t ue_module_id; 
5646 5647
            dest_ip_offset = 8;
            LOG_I(OIP,
5648
                  "[eNB %d] Config the oai%d to send/receive pkt on DRB %ld to/from the protocol stack\n",
5649
                  ctxt_pP->module_id, ctxt_pP->module_id,
5650
                  (long int)((ue_context_pP->local_uid * maxDRB) + DRB_configList->list.array[i]->drb_Identity));
5651
            ue_module_id = oai_emulation.info.eNB_ue_local_uid_to_ue_module_id[ctxt_pP->module_id][ue_context_pP->local_uid];
5652
            rb_conf_ipv4(0, //add
5653 5654 5655
                         ue_module_id,  //cx
                         ctxt_pP->module_id,    //inst
                         (ue_module_id * maxDRB) + DRB_configList->list.array[i]->drb_Identity, // RB
5656
                         0,    //dscp
5657 5658 5659 5660
                         ipv4_address(ctxt_pP->module_id + 1, ctxt_pP->module_id + 1),  //saddr
                         ipv4_address(ctxt_pP->module_id + 1, dest_ip_offset + ue_module_id + 1));  //daddr
            LOG_D(RRC, "[eNB %d] State = Attached (UE rnti %x module id %u)\n",
                  ctxt_pP->module_id, ue_context_pP->ue_context.rnti, ue_module_id);
5661 5662
          }

Lionel Gauthier's avatar
 
Lionel Gauthier committed
5663 5664 5665
#   endif
#endif

5666
          LOG_D(RRC,
5667 5668
                PROTOCOL_RRC_CTXT_UE_FMT" RRC_eNB --- MAC_CONFIG_REQ  (DRB) ---> MAC_eNB\n",
                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
5669

5670
          if (DRB_configList->list.array[i]->logicalChannelIdentity) {
5671
            DRB2LCHAN[i] = (uint8_t) * DRB_configList->list.array[i]->logicalChannelIdentity;
5672
          }
5673

5674
	  if (RC.rrc[ctxt_pP->module_id]->node_type == ngran_eNB) {
5675 5676 5677 5678
	    rrc_mac_config_req_eNB(
				   ctxt_pP->module_id,
				   ue_context_pP->ue_context.primaryCC_id,
				   0,0,0,0,0,
5679
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
5680
				   0,
5681
#endif
5682 5683 5684
				   ue_context_pP->ue_context.rnti,
				   (BCCH_BCH_Message_t *) NULL,
				   (RadioResourceConfigCommonSIB_t *) NULL,
5685
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
5686
				   (RadioResourceConfigCommonSIB_t *) NULL,
5687
#endif
5688
				   ue_context_pP->ue_context.physicalConfigDedicated,
5689
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
5690 5691
				   (SCellToAddMod_r10_t *)NULL,
				   //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
5692
#endif
5693 5694 5695 5696 5697 5698 5699 5700 5701
				   (MeasObjectToAddMod_t **) NULL,
				   ue_context_pP->ue_context.mac_MainConfig,
				   DRB2LCHAN[i],
				   DRB_configList->list.array[i]->logicalChannelConfig,
				   ue_context_pP->ue_context.measGapConfig,
				   (TDD_Config_t *) NULL,
				   NULL,
				   (SchedulingInfoList_t *) NULL,
				   0, NULL, NULL, (MBSFN_SubframeConfigList_t *) NULL
5702
#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
5703
				   , 0, (MBSFN_AreaInfoList_r9_t *) NULL, (PMCH_InfoList_r9_t *) NULL
winckel's avatar
winckel committed
5704
#endif
5705
#if (RRC_VERSION >= MAKE_VERSION(13, 0, 0))
5706 5707
				   ,
				   (SystemInformationBlockType1_v1310_IEs_t *)NULL
5708
#endif
5709 5710 5711
				   );
	  }
	} else {        // remove LCHAN from MAC/PHY
5712

5713
        if (ue_context_pP->ue_context.DRB_active[drb_id] == 1) {
5714
            // DRB has just been removed so remove RLC + PDCP for DRB
5715
            /*      rrc_pdcp_config_req (ctxt_pP->module_id, frameP, 1, CONFIG_ACTION_REMOVE,
5716 5717
               (ue_mod_idP * NB_RB_MAX) + DRB2LCHAN[i],UNDEF_SECURITY_MODE);
             */
5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728
	    if ( (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_eNB_CU) ||
		 (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_ng_eNB_CU) ||
		 (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_gNB_CU)   ) {
	      rrc_rlc_config_req(
				 ctxt_pP,
				 SRB_FLAG_NO,
				 MBMS_FLAG_NO,
				 CONFIG_ACTION_REMOVE,
				 DRB2LCHAN[i],
				 Rlc_info_um);
	    }
5729 5730
          }

5731
          ue_context_pP->ue_context.DRB_active[drb_id] = 0;
5732
          LOG_D(RRC,
5733 5734
                PROTOCOL_RRC_CTXT_UE_FMT" RRC_eNB --- MAC_CONFIG_REQ  (DRB) ---> MAC_eNB\n",
                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
5735
	  if (RC.rrc[ctxt_pP->module_id]->node_type == ngran_eNB) {
5736 5737 5738
	    rrc_mac_config_req_eNB(ctxt_pP->module_id,
				   ue_context_pP->ue_context.primaryCC_id,
				   0,0,0,0,0,
5739
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
5740
				   0,
5741
#endif
5742 5743 5744
				   ue_context_pP->ue_context.rnti,
				   (BCCH_BCH_Message_t *) NULL,
				   (RadioResourceConfigCommonSIB_t *) NULL,
5745
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
5746
				   (RadioResourceConfigCommonSIB_t *) NULL,
5747
#endif
5748
				   ue_context_pP->ue_context.physicalConfigDedicated,
5749
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
5750 5751
				   (SCellToAddMod_r10_t *)NULL,
				   //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
5752
#endif
5753 5754 5755 5756 5757 5758 5759 5760 5761
				   (MeasObjectToAddMod_t **) NULL,
				   ue_context_pP->ue_context.mac_MainConfig,
				   DRB2LCHAN[i],
				   (LogicalChannelConfig_t *) NULL,
				   (MeasGapConfig_t *) NULL,
				   (TDD_Config_t *) NULL,
				   NULL, 
				   (SchedulingInfoList_t *) NULL,
				   0, NULL, NULL, NULL
5762
#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
5763
				   , 0, (MBSFN_AreaInfoList_r9_t *) NULL, (PMCH_InfoList_r9_t *) NULL
winckel's avatar
winckel committed
5764
#endif
5765
#if (RRC_VERSION >= MAKE_VERSION(13, 0, 0))
5766 5767
				   ,
				   (SystemInformationBlockType1_v1310_IEs_t *)NULL
5768
#endif
5769 5770
				   );
	  }
winckel's avatar
winckel committed
5771
        }
5772
      }
winckel's avatar
winckel committed
5773
    }
5774
    free(DRB_configList);
5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789
    ue_context_pP->ue_context.DRB_configList2[xid] = NULL;
  }

  if(DRB_Release_configList2 != NULL){
      for (i = 0; i < DRB_Release_configList2->list.count; i++) {
          if (DRB_Release_configList2->list.array[i]) {
              drb_id_p = DRB_Release_configList2->list.array[i];
              drb_id = *drb_id_p;
              if (ue_context_pP->ue_context.DRB_active[drb_id] == 1) {
                  ue_context_pP->ue_context.DRB_active[drb_id] = 0;
              }
          }
      }
      free(DRB_Release_configList2);
      ue_context_pP->ue_context.DRB_Release_configList2[xid] = NULL;
5790
  }
winckel's avatar
winckel committed
5791
}
5792

5793 5794 5795 5796
//-----------------------------------------------------------------------------
void
rrc_eNB_generate_RRCConnectionSetup(
  const protocol_ctxt_t* const ctxt_pP,
5797 5798
  rrc_eNB_ue_context_t*          const ue_context_pP,
  const int                    CC_id
5799 5800
)
//-----------------------------------------------------------------------------
5801
{
Lionel Gauthier's avatar
 
Lionel Gauthier committed
5802

5803 5804 5805 5806
  LogicalChannelConfig_t             *SRB1_logicalChannelConfig;  //,*SRB2_logicalChannelConfig;
  SRB_ToAddModList_t                **SRB_configList;
  SRB_ToAddMod_t                     *SRB1_config;
  int                                 cnt;
5807 5808
  MessageDef                            *message_p;
     
Cedric Roux's avatar
Cedric Roux committed
5809 5810 5811
  T(T_ENB_RRC_CONNECTION_SETUP, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

5812 5813 5814 5815
  eNB_RRC_UE_t *ue_p = &ue_context_pP->ue_context; 

  SRB_configList = &ue_p->SRB_configList;
  ue_p->Srb0.Tx_buffer.payload_size =
5816 5817
    do_RRCConnectionSetup(ctxt_pP,
                          ue_context_pP,
5818
                          CC_id,
5819
                          (uint8_t*) ue_p->Srb0.Tx_buffer.Payload,
5820
			  (uint8_t) RC.rrc[ctxt_pP->module_id]->carrier[CC_id].p_eNB, //at this point we do not have the UE capability information, so it can only be TM1 or TM2
5821 5822 5823
                          rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),
                          SRB_configList,
                          &ue_context_pP->ue_context.physicalConfigDedicated);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
5824

5825
  LOG_DUMPMSG(RRC,DEBUG_RRC,
5826 5827
              (char *)(ue_p->Srb0.Tx_buffer.Payload),
              ue_p->Srb0.Tx_buffer.payload_size,
5828
              "[MSG] RRC Connection Setup\n");
5829

5830
  // configure SRB1/SRB2, PhysicalConfigDedicated, MAC_MainConfig for UE
5831 5832 5833 5834 5835
   switch (RC.rrc[ctxt_pP->module_id]->node_type){
    case ngran_eNB_CU    :
    case ngran_ng_eNB_CU :
    case ngran_gNB_CU    :
      // create an ITTI message
5836 5837
      /* TODO: F1 IDs ar missing in RRC */
      message_p = itti_alloc_new_message (TASK_RRC_ENB, F1AP_DL_RRC_MESSAGE);
5838
      F1AP_DL_RRC_MESSAGE (message_p).rrc_container =  (uint8_t*)ue_p->Srb0.Tx_buffer.Payload;
5839

5840
      F1AP_DL_RRC_MESSAGE (message_p).rrc_container_length = ue_p->Srb0.Tx_buffer.payload_size;
5841
      F1AP_DL_RRC_MESSAGE (message_p).gNB_CU_ue_id     = 0;  
5842 5843
      F1AP_DL_RRC_MESSAGE (message_p).gNB_DU_ue_id = 0;
      F1AP_DL_RRC_MESSAGE (message_p).old_gNB_DU_ue_id  = 0xFFFFFFFF; // unknown 
5844
      F1AP_DL_RRC_MESSAGE (message_p).rnti = ue_p->rnti; 
5845 5846 5847
      F1AP_DL_RRC_MESSAGE (message_p).srb_id = CCCH;  
      F1AP_DL_RRC_MESSAGE (message_p).execute_duplication      = 1;
      F1AP_DL_RRC_MESSAGE (message_p).RAT_frequency_priority_information.en_dc      = 0; 
5848
      itti_send_msg_to_task (TASK_CU_F1, ctxt_pP->module_id, message_p);
Bing-Kai Hong's avatar
Bing-Kai Hong committed
5849
      LOG_D(RRC, "Send F1AP_DL_RRC_MESSAGE with ITTI\n");
5850 5851 5852 5853
      break;
    case ngran_eNB_DU    :
    case ngran_gNB_DU  :
      // nothing to do for DU 
5854
      AssertFatal(1==0,"nothing to do for DU\n");
5855
      break;
5856 5857 5858 5859 5860
    case ngran_eNB:   
    case ngran_ng_eNB :
    case ngran_gNB  :  
  
    if (*SRB_configList != NULL) {
5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876
    for (cnt = 0; cnt < (*SRB_configList)->list.count; cnt++) {
      if ((*SRB_configList)->list.array[cnt]->srb_Identity == 1) {
        SRB1_config = (*SRB_configList)->list.array[cnt];

        if (SRB1_config->logicalChannelConfig) {
          if (SRB1_config->logicalChannelConfig->present ==
              SRB_ToAddMod__logicalChannelConfig_PR_explicitValue) {
            SRB1_logicalChannelConfig = &SRB1_config->logicalChannelConfig->choice.explicitValue;
          } else {
            SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
          }
        } else {
          SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
        }

        LOG_D(RRC,
5877 5878
              PROTOCOL_RRC_CTXT_UE_FMT" RRC_eNB --- MAC_CONFIG_REQ  (SRB1) ---> MAC_eNB\n",
              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
5879
	if (RC.rrc[ctxt_pP->module_id]->node_type == ngran_eNB) {
5880 5881 5882 5883
	  rrc_mac_config_req_eNB(
				 ctxt_pP->module_id,
				 ue_context_pP->ue_context.primaryCC_id,
				 0,0,0,0,0,
5884
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
5885
				 0,
5886
#endif
5887 5888 5889
				 ue_context_pP->ue_context.rnti,
				 (BCCH_BCH_Message_t *) NULL,
				 (RadioResourceConfigCommonSIB_t *) NULL,
5890
#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
5891
				 (RadioResourceConfigCommonSIB_t *) NULL,
5892
#endif
5893
				 ue_context_pP->ue_context.physicalConfigDedicated,
5894
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
5895 5896
				 (SCellToAddMod_r10_t *)NULL,
				 //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
5897
#endif
5898 5899 5900 5901 5902 5903 5904 5905 5906
				 (MeasObjectToAddMod_t **) NULL,
				 ue_context_pP->ue_context.mac_MainConfig,
				 1,
				 SRB1_logicalChannelConfig,
				 ue_context_pP->ue_context.measGapConfig,
				 (TDD_Config_t *) NULL,
				 NULL,
				 (SchedulingInfoList_t *) NULL,
				 0, NULL, NULL, (MBSFN_SubframeConfigList_t *) NULL
5907
#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
5908
				 , 0, (MBSFN_AreaInfoList_r9_t *) NULL, (PMCH_InfoList_r9_t *) NULL
winckel's avatar
winckel committed
5909
#endif
5910
#if (RRC_VERSION >= MAKE_VERSION(13, 0, 0))
5911 5912
				 ,
				 (SystemInformationBlockType1_v1310_IEs_t *)NULL
5913
#endif
5914 5915
				 );
	}
5916
      }
winckel's avatar
winckel committed
5917
    }
5918
  }
5919 5920 5921 5922 5923
  break;
 default : 
    LOG_W(RRC, "Unknown node type %d\n", RC.rrc[ctxt_pP->module_id]->node_type);		
  }
  
5924
  MSC_LOG_TX_MESSAGE(
5925 5926
    MSC_RRC_ENB,
    MSC_RRC_UE,
5927 5928
    ue_p->Srb0.Tx_buffer.Header, // LG WARNING
    ue_p->Srb0.Tx_buffer.payload_size,
5929 5930 5931
    MSC_AS_TIME_FMT" RRCConnectionSetup UE %x size %u",
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP->ue_context.rnti,
5932
    ue_p->Srb0.Tx_buffer.payload_size);
5933

5934 5935

  LOG_I(RRC,
5936 5937
        PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel DL-CCCH, Generating RRCConnectionSetup (bytes %d)\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
5938
        ue_p->Srb0.Tx_buffer.payload_size);
5939

5940 5941
  //ue_context_pP->ue_context.ue_release_timer_thres=100;
     // activate release timer, if RRCSetupComplete not received after 100 frames, remove UE
5942 5943 5944
   ue_context_pP->ue_context.ue_release_timer=1;
   // remove UE after 10 frames after RRCConnectionRelease is triggered
   ue_context_pP->ue_context.ue_release_timer_thres=1000;
winckel's avatar
winckel committed
5945
}
5946

5947 5948 5949 5950
void setup_ngran_CU(eNB_RRC_INST *rrc) {

  
}
Lionel Gauthier's avatar
 
Lionel Gauthier committed
5951 5952

#if defined(ENABLE_ITTI)
5953 5954
//-----------------------------------------------------------------------------
char
5955
openair_rrc_eNB_configuration(
5956
  const module_id_t enb_mod_idP, RrcConfigurationReq *rrc_configuration_req
5957
)
winckel's avatar
winckel committed
5958
#else
5959
char
5960
openair_rrc_eNB_init(
5961 5962
  const module_id_t enb_mod_idP
)
winckel's avatar
winckel committed
5963
#endif
5964
//-----------------------------------------------------------------------------
winckel's avatar
winckel committed
5965
{
5966
  protocol_ctxt_t ctxt;
5967 5968
  int             CC_id;

5969
  PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, enb_mod_idP, ENB_FLAG_YES, NOT_A_RNTI, 0, 0,enb_mod_idP);
5970 5971 5972
  LOG_I(RRC,
        PROTOCOL_RRC_CTXT_FMT" Init...\n",
        PROTOCOL_RRC_CTXT_ARGS(&ctxt));
5973

laurent's avatar
laurent committed
5974
#if OCP_FRAMEWORK
5975 5976 5977 5978
  while ( RC.rrc[enb_mod_idP] == NULL ) {
    LOG_E(RRC, "RC.rrc not yet initialized, waiting 1 second\n");
    sleep(1);
  }
laurent's avatar
laurent committed
5979
#endif 
5980
  AssertFatal(RC.rrc[enb_mod_idP] != NULL, "RC.rrc not initialized!");
5981 5982
  AssertFatal(MAX_MOBILES_PER_ENB < (module_id_t)0xFFFFFFFFFFFFFFFF, " variable overflow");
  //    for (j = 0; j < MAX_MOBILES_PER_ENB; j++)
5983
  //        RC.rrc[ctxt.module_id].Info.UE[j].Status = RRC_IDLE;  //CH_READY;
5984 5985 5986 5987 5988 5989 5990
  //
  //#if defined(ENABLE_USE_MME)
  //    // Connect eNB to MME
  //    if (EPC_MODE_ENABLED <= 0)
  //#endif
  //    {
  //        /* Init security parameters */
5991
  //        for (j = 0; j < MAX_MOBILES_PER_ENB; j++) {
5992 5993
  //            RC.rrc[ctxt.module_id].ciphering_algorithm[j] = SecurityAlgorithmConfig__cipheringAlgorithm_eea0;
  //            RC.rrc[ctxt.module_id].integrity_algorithm[j] = SecurityAlgorithmConfig__integrityProtAlgorithm_eia2;
5994
  //            rrc_eNB_init_security(enb_mod_idP, j);
5995 5996
  //        }
  //    }
5997
  RC.rrc[ctxt.module_id]->Nb_ue = 0;
5998

5999 6000 6001
  pthread_mutex_init(&RC.rrc[ctxt.module_id]->cell_info_mutex,NULL);
  RC.rrc[ctxt.module_id]->cell_info_configured = 0;

6002 6003
  uid_linear_allocator_init(&RC.rrc[ctxt.module_id]->uid_allocator);
  RB_INIT(&RC.rrc[ctxt.module_id]->rrc_ue_head);
6004
  //    for (j = 0; j < (MAX_MOBILES_PER_ENB + 1); j++) {
6005
  //        RC.rrc[enb_mod_idP]->Srb2[j].Active = 0;
6006
  //    }
6007

6008

6009 6010
  RC.rrc[ctxt.module_id]->initial_id2_s1ap_ids = hashtable_create (MAX_MOBILES_PER_ENB * 2, NULL, NULL);
  RC.rrc[ctxt.module_id]->s1ap_id2_s1ap_ids    = hashtable_create (MAX_MOBILES_PER_ENB * 2, NULL, NULL);
6011

6012
  /// System Information INIT
6013

6014 6015
  LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Checking release \n",
        PROTOCOL_RRC_CTXT_ARGS(&ctxt));
6016
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
6017

6018 6019 6020
  // can clear it at runtime
  RC.rrc[ctxt.module_id]->carrier[0].MBMS_flag = 0;

6021
  // This has to come from some top-level configuration
6022
  // only CC_id 0 is logged
6023
#if (RRC_VERSION < MAKE_VERSION(10, 0, 0))
6024
  LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Rel10 RRC detected, MBMS flag %d\n",
Cedric Roux's avatar
Cedric Roux committed
6025 6026 6027
#else
  LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Rel14 RRC detected, MBMS flag %d\n",
#endif
6028
        PROTOCOL_RRC_CTXT_ARGS(&ctxt),
6029
        RC.rrc[ctxt.module_id]->carrier[0].MBMS_flag);
6030

winckel's avatar
winckel committed
6031
#else
6032
  LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Rel8 RRC\n", PROTOCOL_RRC_CTXT_ARGS(&ctxt));
winckel's avatar
winckel committed
6033 6034
#endif
#ifdef CBA
6035

6036 6037
  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
    for (j = 0; j < NUM_MAX_CBA_GROUP; j++) {
6038
      RC.rrc[ctxt.module_id]->carrier[CC_id].cba_rnti[j] = CBA_OFFSET + j;
6039
    }
6040

6041 6042
    if (RC.rrc[ctxt.module_id]->carrier[CC_id].num_active_cba_groups > NUM_MAX_CBA_GROUP) {
      RC.rrc[ctxt.module_id]->carrier[CC_id].num_active_cba_groups = NUM_MAX_CBA_GROUP;
6043
    }
6044

6045 6046 6047
    LOG_D(RRC,
          PROTOCOL_RRC_CTXT_FMT" Initialization of 4 cba_RNTI values (%x %x %x %x) num active groups %d\n",
          PROTOCOL_RRC_CTXT_ARGS(&ctxt),
6048 6049 6050 6051 6052
          enb_mod_idP, RC.rrc[ctxt.module_id]->carrier[CC_id].cba_rnti[0],
          RC.rrc[ctxt.module_id]->carrier[CC_id].cba_rnti[1],
          RC.rrc[ctxt.module_id]->carrier[CC_id].cba_rnti[2],
          RC.rrc[ctxt.module_id]->carrier[CC_id].cba_rnti[3],
          RC.rrc[ctxt.module_id]->carrier[CC_id].num_active_cba_groups);
6053
  }
6054

winckel's avatar
winckel committed
6055
#endif
6056

6057 6058 6059
  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
    init_SI(&ctxt,
            CC_id
winckel's avatar
winckel committed
6060
#if defined(ENABLE_ITTI)
6061
            , &RC.rrc[enb_mod_idP]->configuration
winckel's avatar
winckel committed
6062
#endif
6063
           );
6064
    for (int ue_id = 0; ue_id < MAX_MOBILES_PER_ENB; ue_id++) {
6065 6066 6067
        RC.rrc[ctxt.module_id]->carrier[CC_id].sizeof_paging[ue_id] = 0;
        RC.rrc[ctxt.module_id]->carrier[CC_id].paging[ue_id] = (uint8_t*) malloc16(256);
    }
6068
  }
6069

6070
  rrc_init_global_param();
6071
  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
6072

6073
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
6074
    switch (RC.rrc[ctxt.module_id]->carrier[CC_id].MBMS_flag) {
6075 6076 6077 6078
    case 1:
    case 2:
    case 3:
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Configuring 1 MBSFN sync area\n", PROTOCOL_RRC_CTXT_ARGS(&ctxt));
6079
      RC.rrc[ctxt.module_id]->carrier[CC_id].num_mbsfn_sync_area = 1;
6080
      break;
6081

6082 6083
    case 4:
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Configuring 2 MBSFN sync area\n", PROTOCOL_RRC_CTXT_ARGS(&ctxt));
6084
      RC.rrc[ctxt.module_id]->carrier[CC_id].num_mbsfn_sync_area = 2;
6085 6086 6087
      break;

    default:
6088
      RC.rrc[ctxt.module_id]->carrier[CC_id].num_mbsfn_sync_area = 0;
6089 6090 6091
      break;
    }

6092
    // if we are here the RC.rrc[enb_mod_idP]->MBMS_flag > 0,
6093
    /// MCCH INIT
6094
    if (RC.rrc[ctxt.module_id]->carrier[CC_id].MBMS_flag > 0) {
6095 6096 6097 6098
      init_MCCH(ctxt.module_id, CC_id);
      /// MTCH data bearer init
      init_MBMS(ctxt.module_id, CC_id, 0);
    }
winckel's avatar
winckel committed
6099
#endif
6100

6101 6102
    openair_rrc_top_init_eNB(RC.rrc[ctxt.module_id]->carrier[CC_id].MBMS_flag,0);
  }
6103
	
6104
  openair_rrc_on(&ctxt);
6105 6106 6107 6108 6109 6110 6111 6112 6113

/*
  RC.rrc[ctxt.module_id]->mcc= rrc_configuration_req->mcc;
  RC.rrc[ctxt.module_id]->mnc= rrc_configuration_req->mnc;
  RC.rrc[ctxt.module_id]->mnc_digit_length= rrc_configuration_req->mnc_digit_length;
  RC.rrc[ctxt.module_id]->tac= rrc_configuration_req->tac;

  LOG_W(RRC, "[inst %d] RRC->MCC/MSG->MCC %d/%d \n", ctxt.module_id, RC.rrc[ctxt.module_id]->mcc, rrc_configuration_req->mcc);
  */
6114
  if (RC.rrc[ctxt.module_id]->node_type == ngran_eNB_CU || RC.rrc[ctxt.module_id]->node_type == ngran_ng_eNB_CU) 
6115 6116
  	// msg_p = itti_alloc_new_message (TASK_ENB_APP, F1AP_SCTP_REQ);
    // RCconfig_CU_F1(msg_p, enb_id);
6117 6118
    setup_ngran_CU(RC.rrc[ctxt.module_id]);
	
6119
  return 0;
6120

winckel's avatar
winckel committed
6121
}
6122

winckel's avatar
winckel committed
6123
/*------------------------------------------------------------------------------*/
6124 6125 6126
int
rrc_eNB_decode_ccch(
  protocol_ctxt_t* const ctxt_pP,
6127 6128
  uint8_t                *buffer,
  int                    buffer_length,
6129
  const int              CC_id
6130 6131
)
//-----------------------------------------------------------------------------
6132
{
6133
  module_id_t                                   Idx;
6134 6135
  asn_dec_rval_t                      dec_rval;
  UL_CCCH_Message_t                  *ul_ccch_msg = NULL;
6136 6137
  RRCConnectionRequest_r8_IEs_t*                rrcConnectionRequest = NULL;
  RRCConnectionReestablishmentRequest_r8_IEs_t* rrcConnectionReestablishmentRequest = NULL;
6138
  int                                 i, rval;
6139 6140
  struct rrc_eNB_ue_context_s*                  ue_context_p = NULL;
  uint64_t                                      random_value = 0;
6141
  int                                           stmsi_received = 0;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
6142

Cedric Roux's avatar
Cedric Roux committed
6143 6144 6145
  T(T_ENB_RRC_UL_CCCH_DATA_IN, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

6146
  //memset(ul_ccch_msg,0,sizeof(UL_CCCH_Message_t));
Lionel Gauthier's avatar
 
Lionel Gauthier committed
6147

6148
  LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Decoding UL CCCH %x.%x.%x.%x.%x.%x (%p)\n",
6149
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
6150 6151 6152 6153 6154 6155
        ((uint8_t*) buffer)[0],
        ((uint8_t *) buffer)[1],
        ((uint8_t *) buffer)[2],
        ((uint8_t *) buffer)[3],
        ((uint8_t *) buffer)[4],
        ((uint8_t *) buffer)[5], (uint8_t *) buffer);
6156 6157 6158 6159
  dec_rval = uper_decode(
               NULL,
               &asn_DEF_UL_CCCH_Message,
               (void**)&ul_ccch_msg,
6160
               (uint8_t*) buffer,
6161 6162 6163
               100,
               0,
               0);
6164 6165


6166
  for (i = 0; i < 8; i++) {
6167
    LOG_T(RRC, "%x.", ((uint8_t *) & ul_ccch_msg)[i]);
6168
  }
6169 6170

  if (dec_rval.consumed == 0) {
6171 6172 6173
    LOG_E(RRC,
          PROTOCOL_RRC_CTXT_UE_FMT" FATAL Error in receiving CCCH\n",
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
6174 6175 6176 6177
    return -1;
  }

  if (ul_ccch_msg->message.present == UL_CCCH_MessageType_PR_c1) {
Lionel Gauthier's avatar
 
Lionel Gauthier committed
6178

6179
    switch (ul_ccch_msg->message.choice.c1.present) {
Lionel Gauthier's avatar
 
Lionel Gauthier committed
6180

6181
    case UL_CCCH_MessageType__c1_PR_NOTHING:
6182 6183 6184
      LOG_I(RRC,
            PROTOCOL_RRC_CTXT_FMT" Received PR_NOTHING on UL-CCCH-Message\n",
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
6185
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
6186

6187
    case UL_CCCH_MessageType__c1_PR_rrcConnectionReestablishmentRequest:
Cedric Roux's avatar
Cedric Roux committed
6188 6189 6190
      T(T_ENB_RRC_CONNECTION_REESTABLISHMENT_REQUEST, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

6191 6192
      LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)(buffer),
                  buffer_length,
6193
                  "[MSG] RRC Connection Reestablishment Request\n");
6194 6195

      LOG_D(RRC,
6196 6197 6198 6199 6200 6201 6202
            PROTOCOL_RRC_CTXT_UE_FMT"MAC_eNB--- MAC_DATA_IND (rrcConnectionReestablishmentRequest on SRB0) --> RRC_eNB\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
      rrcConnectionReestablishmentRequest =
        &ul_ccch_msg->message.choice.c1.choice.rrcConnectionReestablishmentRequest.criticalExtensions.choice.rrcConnectionReestablishmentRequest_r8;
      LOG_I(RRC,
            PROTOCOL_RRC_CTXT_UE_FMT" RRCConnectionReestablishmentRequest cause %s\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213
            ((rrcConnectionReestablishmentRequest->reestablishmentCause == ReestablishmentCause_otherFailure) ?    "Other Failure" :
             (rrcConnectionReestablishmentRequest->reestablishmentCause == ReestablishmentCause_handoverFailure) ? "Handover Failure" :
             "reconfigurationFailure"));
      /*{
      uint64_t                            c_rnti = 0;

      memcpy(((uint8_t *) & c_rnti) + 3, rrcConnectionReestablishmentRequest.UE_identity.c_RNTI.buf,
      rrcConnectionReestablishmentRequest.UE_identity.c_RNTI.size);
      ue_mod_id = rrc_eNB_get_UE_index(enb_mod_idP, c_rnti);
      }

6214
      if ((RC.rrc[enb_mod_idP]->phyCellId == rrcConnectionReestablishmentRequest.UE_identity.physCellId) &&
6215
      (ue_mod_id != UE_INDEX_INVALID)){
6216
      rrc_eNB_generate_RRCConnectionReestablishment(enb_mod_idP, frameP, ue_mod_id);
6217
      }else {
6218
      rrc_eNB_generate_RRCConnectionReestablishmentReject(enb_mod_idP, frameP, ue_mod_id);
6219 6220
      }
      */
6221
      /* reject all reestablishment attempts for the moment */
6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264
//      rrc_eNB_generate_RRCConnectionReestablishmentReject(ctxt_pP,
//                       rrc_eNB_get_ue_context(RC.rrc[ctxt_pP->module_id], ctxt_pP->rnti),
//                       CC_id);
{
      uint16_t                          c_rnti = 0;

      if (rrcConnectionReestablishmentRequest->ue_Identity.physCellId != RC.rrc[ctxt_pP->module_id]->carrier[CC_id].physCellId) {
        LOG_E(RRC,
              PROTOCOL_RRC_CTXT_UE_FMT" RRCConnectionReestablishmentRequest ue_Identity.physCellId(%ld) is not equal to current physCellId(%d), let's reject the UE\n",
              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
              rrcConnectionReestablishmentRequest->ue_Identity.physCellId,
              RC.rrc[ctxt_pP->module_id]->carrier[CC_id].physCellId);
        rrc_eNB_generate_RRCConnectionReestablishmentReject(ctxt_pP, ue_context_p, CC_id);
        break;
      }
      LOG_D(RRC, "physCellId is %ld\n", rrcConnectionReestablishmentRequest->ue_Identity.physCellId);

      for (i = 0; i < rrcConnectionReestablishmentRequest->ue_Identity.shortMAC_I.size; i++) {
        LOG_D(RRC, "rrcConnectionReestablishmentRequest->ue_Identity.shortMAC_I.buf[%d] = %x\n",
            i, rrcConnectionReestablishmentRequest->ue_Identity.shortMAC_I.buf[i]);
      }

      if (rrcConnectionReestablishmentRequest->ue_Identity.c_RNTI.size == 0 ||
          rrcConnectionReestablishmentRequest->ue_Identity.c_RNTI.size > 2) {
        LOG_E(RRC,
              PROTOCOL_RRC_CTXT_UE_FMT" RRCConnectionReestablishmentRequest c_RNTI range error, let's reject the UE\n",
              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
        rrc_eNB_generate_RRCConnectionReestablishmentReject(ctxt_pP, ue_context_p, CC_id);
        break;

      }

      c_rnti = BIT_STRING_to_uint16(&rrcConnectionReestablishmentRequest->ue_Identity.c_RNTI);
      LOG_D(RRC, "c_rnti is %x\n", c_rnti);

      ue_context_p = rrc_eNB_get_ue_context(RC.rrc[ctxt_pP->module_id], c_rnti);
      if (ue_context_p == NULL) {
        LOG_E(RRC,
              PROTOCOL_RRC_CTXT_UE_FMT" RRCConnectionReestablishmentRequest without UE context, let's reject the UE\n",
              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
        rrc_eNB_generate_RRCConnectionReestablishmentReject(ctxt_pP, ue_context_p, CC_id);
        break;
      }
6265 6266 6267 6268 6269
      if ( (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_eNB_CU) &&
       (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_ng_eNB_CU)&& 
       (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_gNB_CU)   ) {
  		int UE_id = find_UE_id(ctxt_pP->module_id, c_rnti);
      	if(UE_id == -1){
6270 6271 6272
          LOG_E(RRC,
                PROTOCOL_RRC_CTXT_UE_FMT" RRCConnectionReestablishmentRequest without UE_id(MAC) rnti %x, let's reject the UE\n",
                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),c_rnti);
6273 6274
          rrc_eNB_generate_RRCConnectionReestablishmentReject(ctxt_pP, ue_context_p, CC_id);
          break;
6275 6276 6277 6278 6279 6280 6281 6282 6283 6284
      	}
	    if((RC.mac[ctxt_pP->module_id]->UE_list.UE_sched_ctrl[UE_id].ue_reestablishment_reject_timer > 0) &&
	         (RC.mac[ctxt_pP->module_id]->UE_list.UE_sched_ctrl[UE_id].ue_reestablishment_reject_timer_thres > 20)){
	      LOG_E(RRC,
	             PROTOCOL_RRC_CTXT_UE_FMT" RCConnectionReestablishmentComplete(Previous) don't receive, delete the Previous UE\n",
	             PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
	      RC.mac[ctxt_pP->module_id]->UE_list.UE_sched_ctrl[UE_id].ue_reestablishment_reject_timer = 1000;
	      ue_context_p->ue_context.ue_reestablishment_timer = 0;
	    }
  	 }	
6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299
      if(ue_context_p->ue_context.ue_reestablishment_timer > 0){
    	  LOG_E(RRC,
                PROTOCOL_RRC_CTXT_UE_FMT" RRRCConnectionReconfigurationComplete(Previous) don't receive, delete the Previous UE\n",
                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
          ue_context_p->ue_context.Status = RRC_RECONFIGURED;
          protocol_ctxt_t  ctxt_old_p;
          PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt_old_p,
                                        ctxt_pP->instance,
                                        ENB_FLAG_YES,
                                        c_rnti,
                                        ctxt_pP->frame,
                                        ctxt_pP->subframe);
          rrc_eNB_process_RRCConnectionReconfigurationComplete(&ctxt_old_p,
                                                                ue_context_p,
                                                                ue_context_p->ue_context.reestablishment_xid);
6300
          LOG_E(RRC, "RRRCConnectionReconfigurationComplete: ue_context_p->ue_context.nb_of_e_rabs = %d \n", ue_context_p->ue_context.nb_of_e_rabs);
6301
          for (uint8_t e_rab = 0; e_rab < ue_context_p->ue_context.nb_of_e_rabs; e_rab++) {
6302
            LOG_E(RRC, "RRRCConnectionReconfigurationComplete: ue_context_p->ue_context.e_rab[e_rab].status = %d \n", ue_context_p->ue_context.e_rab[e_rab].status);
6303 6304 6305 6306 6307 6308 6309
            if (ue_context_p->ue_context.e_rab[e_rab].status == E_RAB_STATUS_DONE) {
              ue_context_p->ue_context.e_rab[e_rab].status = E_RAB_STATUS_ESTABLISHED;
            } else {
              ue_context_p->ue_context.e_rab[e_rab].status = E_RAB_STATUS_FAILED;
            }
          }
      }
6310 6311 6312 6313
      LOG_D(RRC,
            PROTOCOL_RRC_CTXT_UE_FMT" UE context: %p\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            ue_context_p);
6314
      /* reset timers */
6315 6316
      ue_context_p->ue_context.ul_failure_timer = 0;
      ue_context_p->ue_context.ue_release_timer = 0;
6317 6318 6319
      ue_context_p->ue_context.ue_reestablishment_timer = 0;
      ue_context_p->ue_context.ue_release_timer_s1 = 0;
      ue_context_p->ue_context.ue_release_timer_rrc = 0;
6320
      ue_context_p->ue_context.reestablishment_xid = -1;
6321

6322
      // insert C-RNTI to map
6323
      for (i = 0; i < MAX_MOBILES_PER_ENB; i++) {
6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392
        if (reestablish_rnti_map[i][0] == 0) {
          reestablish_rnti_map[i][0] = ctxt_pP->rnti;
          reestablish_rnti_map[i][1] = c_rnti;
          break;
        }
      }
      LOG_D(RRC, "reestablish_rnti_map[%d] [0] %x, [1] %x\n",
            i, reestablish_rnti_map[i][0], reestablish_rnti_map[i][1]);

#if defined(ENABLE_ITTI)
      ue_context_p->ue_context.reestablishment_cause = rrcConnectionReestablishmentRequest->reestablishmentCause;
      LOG_D(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Accept connection reestablishment request from UE physCellId %ld cause %ld\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            rrcConnectionReestablishmentRequest->ue_Identity.physCellId,
            ue_context_p->ue_context.reestablishment_cause);
#else
        LOG_D(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Accept connection restablishment request for UE\n",
              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
#endif

#ifndef NO_RRM
      send_msg(&S_rrc, msg_rrc_MR_attach_ind(ctxt_pP->module_id, Mac_id));
#else

      ue_context_p->ue_context.primaryCC_id = CC_id;

      //LG COMMENT Idx = (ue_mod_idP * NB_RB_MAX) + DCCH;
      Idx = DCCH;
      // SRB1
      ue_context_p->ue_context.Srb1.Active = 1;
      ue_context_p->ue_context.Srb1.Srb_info.Srb_id = Idx;
      memcpy(&ue_context_p->ue_context.Srb1.Srb_info.Lchan_desc[0],
             &DCCH_LCHAN_DESC,
             LCHAN_DESC_SIZE);
      memcpy(&ue_context_p->ue_context.Srb1.Srb_info.Lchan_desc[1],
             &DCCH_LCHAN_DESC,
             LCHAN_DESC_SIZE);

      // SRB2: set  it to go through SRB1 with id 1 (DCCH)
      ue_context_p->ue_context.Srb2.Active = 1;
      ue_context_p->ue_context.Srb2.Srb_info.Srb_id = Idx;
      memcpy(&ue_context_p->ue_context.Srb2.Srb_info.Lchan_desc[0],
             &DCCH_LCHAN_DESC,
             LCHAN_DESC_SIZE);
      memcpy(&ue_context_p->ue_context.Srb2.Srb_info.Lchan_desc[1],
             &DCCH_LCHAN_DESC,
             LCHAN_DESC_SIZE);

      rrc_eNB_generate_RRCConnectionReestablishment(ctxt_pP, ue_context_p, CC_id);
      LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT"CALLING RLC CONFIG SRB1 (rbid %d)\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            Idx);

      MSC_LOG_TX_MESSAGE(MSC_RRC_ENB,
                         MSC_PDCP_ENB,
                         NULL,
                         0,
                         MSC_AS_TIME_FMT" CONFIG_REQ UE %x SRB",
                         MSC_AS_TIME_ARGS(ctxt_pP),
                         ue_context_p->ue_context.rnti);

      rrc_pdcp_config_asn1_req(ctxt_pP,
                               ue_context_p->ue_context.SRB_configList,
                               (DRB_ToAddModList_t *) NULL,
                               (DRB_ToReleaseList_t*) NULL,
                               0xff,
                               NULL,
                               NULL,
                               NULL
6393
#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
6394
                               , (PMCH_InfoList_r9_t *) NULL
6395
#endif
6396 6397
                               ,NULL);

6398 6399
      if ( (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_eNB_CU) &&
	   (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_ng_eNB_CU)&& 
6400 6401 6402 6403 6404
	   (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_gNB_CU)   ) {
	rrc_rlc_config_asn1_req(ctxt_pP,
				ue_context_p->ue_context.SRB_configList,
				(DRB_ToAddModList_t*) NULL,
				(DRB_ToReleaseList_t*) NULL
6405
#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
6406 6407
				, (PMCH_InfoList_r9_t *) NULL,
				0,0
6408
#   endif
6409 6410 6411
				);
      }

6412
#endif //NO_RRM
6413 6414
	}
    break;
6415 6416

    case UL_CCCH_MessageType__c1_PR_rrcConnectionRequest:
Cedric Roux's avatar
Cedric Roux committed
6417 6418 6419
      T(T_ENB_RRC_CONNECTION_REQUEST, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

6420 6421
      LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)buffer,
                  buffer_length,
6422
                  "[MSG] RRC Connection Request\n");
6423 6424

      LOG_D(RRC,
6425 6426 6427
            PROTOCOL_RRC_CTXT_UE_FMT"MAC_eNB --- MAC_DATA_IND  (rrcConnectionRequest on SRB0) --> RRC_eNB\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
      ue_context_p = rrc_eNB_get_ue_context(
6428
                       RC.rrc[ctxt_pP->module_id],
6429 6430 6431
                       ctxt_pP->rnti);

      if (ue_context_p != NULL) {
6432
      	LOG_D(RRC,"ue_context_p already exist %p %d %x \n", ue_context_p, ctxt_pP->module_id, ctxt_pP->rnti);
6433 6434
        // erase content
        rrc_eNB_free_mem_UE_context(ctxt_pP, ue_context_p);
6435 6436

        MSC_LOG_RX_DISCARDED_MESSAGE(
6437 6438
          MSC_RRC_ENB,
          MSC_RRC_UE,
6439
          buffer,
6440 6441 6442 6443 6444 6445
          dec_rval.consumed,
          MSC_AS_TIME_FMT" RRCConnectionRequest UE %x size %u (UE already in context)",
          MSC_AS_TIME_ARGS(ctxt_pP),
          ue_context_p->ue_context.rnti,
          dec_rval.consumed);
      } else {
6446 6447
        rrcConnectionRequest = &ul_ccch_msg->message.choice.c1.choice.rrcConnectionRequest.criticalExtensions.choice.rrcConnectionRequest_r8;
        {
gauthier's avatar
gauthier committed
6448
          if (InitialUE_Identity_PR_randomValue == rrcConnectionRequest->ue_Identity.present) {
6449 6450 6451 6452 6453 6454
	    if(rrcConnectionRequest->ue_Identity.choice.randomValue.size != 5)
	      {
		LOG_I(RRC, "wrong InitialUE-Identity randomValue size, expected 5, provided %lu",
		      (long unsigned int)rrcConnectionRequest->ue_Identity.choice.randomValue.size);
		return -1;
	      }
gauthier's avatar
gauthier committed
6455 6456 6457 6458 6459 6460
            memcpy(((uint8_t*) & random_value) + 3,
                   rrcConnectionRequest->ue_Identity.choice.randomValue.buf,
                   rrcConnectionRequest->ue_Identity.choice.randomValue.size);
            /* if there is already a registered UE (with another RNTI) with this random_value,
             * the current one must be removed from MAC/PHY (zombie UE)
             */
6461 6462 6463 6464 6465 6466
            if ((ue_context_p = rrc_eNB_ue_context_random_exist(ctxt_pP, random_value))) {
              LOG_W(RRC, "new UE rnti %x (coming with random value) is already there as UE %x, removing %x from MAC/PHY\n",
                    ctxt_pP->rnti, ue_context_p->ue_context.rnti, ue_context_p->ue_context.rnti);
              ue_context_p->ue_context.ul_failure_timer = 20000;
            }
            ue_context_p = rrc_eNB_get_next_free_ue_context(ctxt_pP, random_value);
6467 6468 6469 6470 6471 6472 6473 6474
	    	ue_context_p->ue_context.Srb0.Srb_id=0;
	    	ue_context_p->ue_context.Srb0.Active=1;
	    	memcpy(ue_context_p->ue_context.Srb0.Rx_buffer.Payload,
	    		   buffer,
	    		   buffer_length);

	    	ue_context_p->ue_context.Srb0.Rx_buffer.payload_size=buffer_length;

gauthier's avatar
gauthier committed
6475 6476 6477 6478 6479 6480 6481
          } else if (InitialUE_Identity_PR_s_TMSI == rrcConnectionRequest->ue_Identity.present) {
            /* Save s-TMSI */
            S_TMSI_t   s_TMSI = rrcConnectionRequest->ue_Identity.choice.s_TMSI;
            mme_code_t mme_code = BIT_STRING_to_uint8(&s_TMSI.mmec);
            m_tmsi_t   m_tmsi   = BIT_STRING_to_uint32(&s_TMSI.m_TMSI);
            random_value = (((uint64_t)mme_code) << 32) | m_tmsi;
            if ((ue_context_p = rrc_eNB_ue_context_stmsi_exist(ctxt_pP, mme_code, m_tmsi))) {
6482
	      LOG_I(RRC," S-TMSI exists, ue_context_p %p, old rnti %x => %x\n",ue_context_p,ue_context_p->ue_context.rnti,ctxt_pP->rnti);
6483 6484 6485 6486 6487 6488 6489 6490 6491 6492

	      if ( (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_eNB_CU) ||
		   (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_ng_eNB_CU) ||
		   (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_gNB_CU)   ) {
		rrc_mac_remove_ue(ctxt_pP->module_id, ue_context_p->ue_context.rnti);
	      }
	      else {
		// send message to DU to remove context
		AssertFatal(1==0,"Need to added context removal\n");
	      }
6493
	      stmsi_received=1;
6494 6495
              /* replace rnti in the context */
              /* for that, remove the context from the RB tree */
6496
              RB_REMOVE(rrc_ue_tree_s, &RC.rrc[ctxt_pP->module_id]->rrc_ue_head, ue_context_p);
6497 6498
              /* and insert again, after changing rnti everywhere it has to be changed */
              ue_context_p->ue_id_rnti = ctxt_pP->rnti;
Raymond Knopp's avatar
Raymond Knopp committed
6499
	      ue_context_p->ue_context.rnti = ctxt_pP->rnti;
6500
              RB_INSERT(rrc_ue_tree_s, &RC.rrc[ctxt_pP->module_id]->rrc_ue_head, ue_context_p);
6501 6502 6503
              /* reset timers */
              ue_context_p->ue_context.ul_failure_timer = 0;
              ue_context_p->ue_context.ue_release_timer = 0;
6504 6505 6506
              ue_context_p->ue_context.ue_reestablishment_timer = 0;
              ue_context_p->ue_context.ue_release_timer_s1 = 0;
              ue_context_p->ue_context.ue_release_timer_rrc = 0;
6507
              ue_context_p->ue_context.reestablishment_xid = -1;
gauthier's avatar
gauthier committed
6508
            } else {
Cedric Roux's avatar
Cedric Roux committed
6509
	      LOG_I(RRC," S-TMSI doesn't exist, setting Initialue_identity_s_TMSI.m_tmsi to %p => %x\n",ue_context_p,m_tmsi);
6510 6511
//              ue_context_p = rrc_eNB_get_next_free_ue_context(ctxt_pP, NOT_A_RANDOM_UE_IDENTITY);
              ue_context_p = rrc_eNB_get_next_free_ue_context(ctxt_pP,random_value);
6512 6513 6514 6515 6516 6517 6518
              if (ue_context_p == NULL)
                LOG_E(RRC, "%s:%d:%s: rrc_eNB_get_next_free_ue_context returned NULL\n", __FILE__, __LINE__, __FUNCTION__);
              if (ue_context_p != NULL) {
	        ue_context_p->ue_context.Initialue_identity_s_TMSI.presence = TRUE;
	        ue_context_p->ue_context.Initialue_identity_s_TMSI.mme_code = mme_code;
	        ue_context_p->ue_context.Initialue_identity_s_TMSI.m_tmsi = m_tmsi;
              } else {
Cedric Roux's avatar
Cedric Roux committed
6519 6520
                /* TODO: do we have to break here? */
                //break;
6521
              }
gauthier's avatar
gauthier committed
6522 6523 6524 6525 6526
            }

            MSC_LOG_RX_MESSAGE(
              MSC_RRC_ENB,
              MSC_RRC_UE,
6527
              buffer,
gauthier's avatar
gauthier committed
6528 6529 6530 6531 6532 6533 6534 6535 6536
              dec_rval.consumed,
              MSC_AS_TIME_FMT" RRCConnectionRequest UE %x size %u (s-TMSI mmec %u m_TMSI %u random UE id (0x%" PRIx64 ")",
              MSC_AS_TIME_ARGS(ctxt_pP),
              ue_context_p->ue_context.rnti,
              dec_rval.consumed,
              ue_context_p->ue_context.Initialue_identity_s_TMSI.mme_code,
              ue_context_p->ue_context.Initialue_identity_s_TMSI.m_tmsi,
              ue_context_p->ue_context.random_ue_identity);
          } else {
6537
            LOG_E(RRC,
gauthier's avatar
gauthier committed
6538
                  PROTOCOL_RRC_CTXT_UE_FMT" RRCConnectionRequest without random UE identity or S-TMSI not supported, let's reject the UE\n",
6539 6540
                  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
            rrc_eNB_generate_RRCConnectionReject(ctxt_pP,
6541 6542
						 rrc_eNB_get_ue_context(RC.rrc[ctxt_pP->module_id], ctxt_pP->rnti),
						 CC_id);
Bing-Kai Hong's avatar
Bing-Kai Hong committed
6543
            // navid:
6544 6545
            break;
          }
gauthier's avatar
gauthier committed
6546

6547
        }
6548
        LOG_D(RRC,
Cedric Roux's avatar
Cedric Roux committed
6549
              PROTOCOL_RRC_CTXT_UE_FMT" UE context: %p\n",
6550 6551
              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
              ue_context_p);
6552

6553
        if (ue_context_p != NULL) {
6554

winckel's avatar
winckel committed
6555
#if defined(ENABLE_ITTI)
gauthier's avatar
gauthier committed
6556
          ue_context_p->ue_context.establishment_cause = rrcConnectionRequest->establishmentCause;
6557
          ue_context_p->ue_context.reestablishment_cause = ReestablishmentCause_spare1;
Raymond Knopp's avatar
Raymond Knopp committed
6558
	  if (stmsi_received==0)
Cedric Roux's avatar
Cedric Roux committed
6559
	    LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Accept new connection from UE random UE identity (0x%" PRIx64 ") MME code %u TMSI %u cause %ld\n",
Raymond Knopp's avatar
Raymond Knopp committed
6560 6561 6562 6563 6564 6565
		  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
		  ue_context_p->ue_context.random_ue_identity,
		  ue_context_p->ue_context.Initialue_identity_s_TMSI.mme_code,
		  ue_context_p->ue_context.Initialue_identity_s_TMSI.m_tmsi,
		  ue_context_p->ue_context.establishment_cause);
	  else
Cedric Roux's avatar
Cedric Roux committed
6566
	    LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Accept new connection from UE  MME code %u TMSI %u cause %ld\n",
Raymond Knopp's avatar
Raymond Knopp committed
6567 6568 6569 6570
		  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
		  ue_context_p->ue_context.Initialue_identity_s_TMSI.mme_code,
		  ue_context_p->ue_context.Initialue_identity_s_TMSI.m_tmsi,
		  ue_context_p->ue_context.establishment_cause);
6571 6572 6573 6574
#else
          LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Accept new connection for UE random UE identity (0x%" PRIx64 ")\n",
                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
                ue_context_p->ue_context.random_ue_identity);
6575
#endif
6576
          if (stmsi_received == 0)
6577
	    RC.rrc[ctxt_pP->module_id]->Nb_ue++;
6578

6579 6580
        } else {
          // no context available
6581 6582 6583 6584 6585
	  if (rrc_agent_registered[ctxt_pP->module_id]) {
	    agent_rrc_xface[ctxt_pP->module_id]->flexran_agent_notify_ue_state_change(ctxt_pP->module_id,
										      ctxt_pP->rnti,
										      PROTOCOL__FLEX_UE_STATE_CHANGE_TYPE__FLUESC_DEACTIVATED);
	  }
6586 6587
          LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Can't create new context for UE random UE identity (0x%" PRIx64 ")\n",
                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
6588
                random_value);
Raymond Knopp's avatar
Raymond Knopp committed
6589 6590 6591 6592 6593 6594 6595

          if (RC.rrc[ctxt_pP->module_id] == ngran_eNB)
	     rrc_mac_remove_ue(ctxt_pP->module_id,ctxt_pP->rnti);
          else if (RC.rrc[ctxt_pP->module_id]->node_type == ngran_eNB_CU || 
                   RC.rrc[ctxt_pP->module_id]->node_type == ngran_ng_eNB_CU)
             AssertFatal(1==0,"Need to added context removal\n");

6596 6597 6598
          return -1;
        }
      }
6599

winckel's avatar
winckel committed
6600
#ifndef NO_RRM
6601
      send_msg(&S_rrc, msg_rrc_MR_attach_ind(ctxt_pP->module_id, Mac_id));
winckel's avatar
winckel committed
6602
#else
6603

6604 6605
      ue_context_p->ue_context.primaryCC_id = CC_id;

6606 6607 6608
      //LG COMMENT Idx = (ue_mod_idP * NB_RB_MAX) + DCCH;
      Idx = DCCH;
      // SRB1
6609 6610 6611 6612
      ue_context_p->ue_context.Srb1.Active = 1;
      ue_context_p->ue_context.Srb1.Srb_info.Srb_id = Idx;
      memcpy(&ue_context_p->ue_context.Srb1.Srb_info.Lchan_desc[0],
             &DCCH_LCHAN_DESC,
6613
             LCHAN_DESC_SIZE);
6614 6615
      memcpy(&ue_context_p->ue_context.Srb1.Srb_info.Lchan_desc[1],
             &DCCH_LCHAN_DESC,
6616
             LCHAN_DESC_SIZE);
6617

6618
      // SRB2: set  it to go through SRB1 with id 1 (DCCH)
6619 6620 6621 6622
      ue_context_p->ue_context.Srb2.Active = 1;
      ue_context_p->ue_context.Srb2.Srb_info.Srb_id = Idx;
      memcpy(&ue_context_p->ue_context.Srb2.Srb_info.Lchan_desc[0],
             &DCCH_LCHAN_DESC,
6623
             LCHAN_DESC_SIZE);
6624 6625
      memcpy(&ue_context_p->ue_context.Srb2.Srb_info.Lchan_desc[1],
             &DCCH_LCHAN_DESC,
6626
             LCHAN_DESC_SIZE);
6627
      
6628
      rrc_eNB_generate_RRCConnectionSetup(ctxt_pP, ue_context_p, CC_id);
6629 6630 6631
      LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT"CALLING RLC CONFIG SRB1 (rbid %d)\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            Idx);
Lionel Gauthier's avatar
Lionel Gauthier committed
6632 6633 6634 6635 6636 6637 6638 6639 6640 6641

      MSC_LOG_TX_MESSAGE(
        MSC_RRC_ENB,
        MSC_PDCP_ENB,
        NULL,
        0,
        MSC_AS_TIME_FMT" CONFIG_REQ UE %x SRB",
        MSC_AS_TIME_ARGS(ctxt_pP),
        ue_context_p->ue_context.rnti);

6642 6643
      rrc_pdcp_config_asn1_req(ctxt_pP,
                               ue_context_p->ue_context.SRB_configList,
6644
                               (DRB_ToAddModList_t *) NULL,
6645 6646 6647 6648 6649
                               (DRB_ToReleaseList_t*) NULL,
                               0xff,
                               NULL,
                               NULL,
                               NULL
6650
#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
6651
                               , (PMCH_InfoList_r9_t *) NULL
6652
#endif
6653
                               ,NULL);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
6654

6655 6656
	if ( (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_eNB_CU) &&
	     (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_ng_eNB_CU) &&
6657 6658 6659 6660 6661 6662
	     (RC.rrc[ctxt_pP->module_id]->node_type  != ngran_gNB_CU)   ) {
	 
	 	 rrc_rlc_config_asn1_req(ctxt_pP,
	 	 	ue_context_p->ue_context.SRB_configList,
	 	 	(DRB_ToAddModList_t*) NULL,
	 	 	(DRB_ToReleaseList_t*) NULL
6663
#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
6664 6665
            , (PMCH_InfoList_r9_t *) NULL
            , 0, 0
6666
#endif
6667
            );
winckel's avatar
winckel committed
6668
#endif //NO_RRM
6669
	}
6670 6671 6672
      break;

    default:
6673 6674
      LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Unknown message\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
6675 6676
      rval = -1;
      break;
winckel's avatar
winckel committed
6677
    }
6678 6679 6680

    rval = 0;
  } else {
6681 6682
    LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT"  Unknown error \n",
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
6683 6684 6685 6686
    rval = -1;
  }

  return rval;
6687 6688
}

6689 6690 6691 6692 6693 6694 6695 6696 6697
//-----------------------------------------------------------------------------
int
rrc_eNB_decode_dcch(
  const protocol_ctxt_t* const ctxt_pP,
  const rb_id_t                Srb_id,
  const uint8_t*    const      Rx_sdu,
  const sdu_size_t             sdu_sizeP
)
//-----------------------------------------------------------------------------
6698
{
winckel's avatar
winckel committed
6699

6700 6701 6702 6703
  asn_dec_rval_t                      dec_rval;
  //UL_DCCH_Message_t uldcchmsg;
  UL_DCCH_Message_t                  *ul_dcch_msg = NULL; //&uldcchmsg;
  int i;
6704
  struct rrc_eNB_ue_context_s*        ue_context_p = NULL;
6705 6706 6707 6708 6709 6710
#if defined(ENABLE_ITTI)
#   if defined(ENABLE_USE_MME)
  MessageDef *                        msg_delete_tunnels_p = NULL;
  uint8_t                             xid;
#endif
#endif
6711

6712
  int dedicated_DRB=0; 
nikaeinn's avatar
nikaeinn committed
6713

Cedric Roux's avatar
Cedric Roux committed
6714 6715 6716
  T(T_ENB_RRC_UL_DCCH_DATA_IN, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

6717
  if ((Srb_id != 1) && (Srb_id != 2)) {
6718 6719 6720
    LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Received message on SRB%d, should not have ...\n",
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
          Srb_id);
6721 6722 6723 6724
  } else {
    LOG_D(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Received message on SRB%d\n",
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
          Srb_id);
6725 6726
  }
  //memset(ul_dcch_msg,0,sizeof(UL_DCCH_Message_t));
6727

6728 6729 6730 6731 6732 6733 6734 6735 6736 6737
  LOG_D(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Decoding UL-DCCH Message\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
  dec_rval = uper_decode(
               NULL,
               &asn_DEF_UL_DCCH_Message,
               (void**)&ul_dcch_msg,
               Rx_sdu,
               sdu_sizeP,
               0,
               0);
6738

6739
  {
6740
    for (i = 0; i < sdu_sizeP; i++) {
6741
      LOG_T(RRC, "%x.", Rx_sdu[i]);
6742
    }
winckel's avatar
winckel committed
6743

6744 6745 6746 6747
    LOG_T(RRC, "\n");
  }

  if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0)) {
Cedric Roux's avatar
Cedric Roux committed
6748
    LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Failed to decode UL-DCCH (%zu bytes)\n",
6749 6750
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
          dec_rval.consumed);
6751 6752
    return -1;
  }
6753

6754
  ue_context_p = rrc_eNB_get_ue_context(
6755
                   RC.rrc[ctxt_pP->module_id],
6756
                   ctxt_pP->rnti);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
6757

6758
  if (ul_dcch_msg->message.present == UL_DCCH_MessageType_PR_c1) {
Lionel Gauthier's avatar
 
Lionel Gauthier committed
6759

6760 6761 6762
    switch (ul_dcch_msg->message.choice.c1.present) {
    case UL_DCCH_MessageType__c1_PR_NOTHING:   /* No components present */
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
6763

6764 6765
    case UL_DCCH_MessageType__c1_PR_csfbParametersRequestCDMA2000:
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
6766

6767
    case UL_DCCH_MessageType__c1_PR_measurementReport:
6768 6769 6770 6771 6772
      // to avoid segmentation fault
      if(!ue_context_p){
        LOG_I(RRC, "Processing measurementReport UE %x, ue_context_p is NULL\n", ctxt_pP->rnti);
        break;
      }
6773
      LOG_D(RRC,
6774 6775 6776 6777 6778 6779 6780 6781
            PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND "
            "%d bytes (measurementReport) ---> RRC_eNB\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            DCCH,
            sdu_sizeP);
      rrc_eNB_process_MeasurementReport(
        ctxt_pP,
        ue_context_p,
6782 6783
        &ul_dcch_msg->message.choice.c1.choice.measurementReport.
        criticalExtensions.choice.c1.choice.measurementReport_r8.measResults);
6784
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
6785

6786
    case UL_DCCH_MessageType__c1_PR_rrcConnectionReconfigurationComplete:
6787 6788 6789 6790 6791
      // to avoid segmentation fault
      if(!ue_context_p){
        LOG_I(RRC, "Processing RRCConnectionReconfigurationComplete UE %x, ue_context_p is NULL\n", ctxt_pP->rnti);
        break;
      }
6792 6793
      LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)(Rx_sdu),sdu_sizeP,
                  "[MSG] RRC Connection Reconfiguration Complete\n");
6794

6795
      MSC_LOG_RX_MESSAGE(
6796 6797 6798 6799 6800 6801 6802 6803
        MSC_RRC_ENB,
        MSC_RRC_UE,
        Rx_sdu,
        sdu_sizeP,
        MSC_AS_TIME_FMT" RRCConnectionReconfigurationComplete UE %x size %u",
        MSC_AS_TIME_ARGS(ctxt_pP),
        ue_context_p->ue_context.rnti,
        sdu_sizeP);
6804

6805
      LOG_D(RRC,
6806 6807 6808 6809 6810
            PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
            "(RRCConnectionReconfigurationComplete) ---> RRC_eNB]\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            DCCH,
            sdu_sizeP);
6811 6812 6813 6814

      if (ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.criticalExtensions.
          present ==
          RRCConnectionReconfigurationComplete__criticalExtensions_PR_rrcConnectionReconfigurationComplete_r8) {
6815
	/*NN: revise the condition */
6816
	/*FK: left the condition as is for the case MME is used (S1 mode) but setting  dedicated_DRB = 1 otherwise (noS1 mode) so that no second RRCReconfiguration message activationg more DRB is sent as this causes problems with the nasmesh driver.*/
6817 6818
        if (EPC_MODE_ENABLED) {
  	  if (ue_context_p->ue_context.Status == RRC_RECONFIGURED){
6819
  	    dedicated_DRB = 1;
6820
  	    LOG_I(RRC,
6821
  		  PROTOCOL_RRC_CTXT_UE_FMT" UE State = RRC_RECONFIGURED (reconfigure default DRB /dedicated DRB, xid %ld)\n",
6822 6823
  		  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);
  	    //clear
6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857
  	    // FIX ME: MAC context does not exist in CU
  	    if ((RC.rrc[ctxt_pP->module_id]->node_type  != ngran_eNB_CU) &&
       		(RC.rrc[ctxt_pP->module_id]->node_type  != ngran_ng_eNB_CU)&& 
       		(RC.rrc[ctxt_pP->module_id]->node_type  != ngran_gNB_CU)   ) {
  		    int16_t UE_id = find_UE_id(ctxt_pP->module_id, ctxt_pP->rnti);
	  	    if(UE_id == -1){
	  	      LOG_E(RRC,
	  		    PROTOCOL_RRC_CTXT_UE_FMT" RRCConnectionReconfigurationComplete without rnti %x, fault\n",
	  		    PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ctxt_pP->rnti);
	  	      break;
	  	    }
  		
	  	    if(RC.mac[ctxt_pP->module_id]->UE_list.UE_sched_ctrl[UE_id].crnti_reconfigurationcomplete_flag == 1){
	  	      LOG_I(RRC,
	  		    PROTOCOL_RRC_CTXT_UE_FMT" UE State = RRC_RECONFIGURED (dedicated DRB, xid %ld) C-RNTI Complete\n",
	  		    PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);
	  	      dedicated_DRB = 2;
	  	      RC.mac[ctxt_pP->module_id]->UE_list.UE_sched_ctrl[UE_id].crnti_reconfigurationcomplete_flag = 0;
	  	    }
	  	  	else {
	  	    dedicated_DRB = 0;
	  	    ue_context_p->ue_context.Status = RRC_RECONFIGURED;
	  	    LOG_I(RRC,
	  		  PROTOCOL_RRC_CTXT_UE_FMT" UE State = RRC_RECONFIGURED (default DRB, xid %ld)\n",
	  		  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);
	  	  	}
	  	} else{
			dedicated_DRB = 0;
	  	    ue_context_p->ue_context.Status = RRC_RECONFIGURED;
	  	    LOG_I(RRC,
	  		  PROTOCOL_RRC_CTXT_UE_FMT" UE State = RRC_RECONFIGURED (default DRB, xid %ld)\n",
	  		  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);
	  		}
  	  		ue_context_p->ue_context.reestablishment_xid = -1;
6858 6859 6860
        } else {
  	  ue_context_p->ue_context.Status = RRC_RECONFIGURED;
  	  LOG_I(RRC,
6861
  	      PROTOCOL_RRC_CTXT_UE_FMT" UE State = RRC_RECONFIGURED (default DRB, xid %ld)\n",
6862 6863
  	      PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);
  	}
6864
  }
6865
	
6866
	rrc_eNB_process_RRCConnectionReconfigurationComplete(
6867 6868
          ctxt_pP,
          ue_context_p,
6869 6870
	  ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);

6871
	//WARNING:Inform the controller about the UE activation. Should be moved to RRC agent in the future
6872 6873
	if (rrc_agent_registered[ctxt_pP->module_id]) {
	  agent_rrc_xface[ctxt_pP->eNB_index]->flexran_agent_notify_ue_state_change(ctxt_pP->module_id,
6874
										ue_context_p->ue_id_rnti,
6875
										PROTOCOL__FLEX_UE_STATE_CHANGE_TYPE__FLUESC_UPDATED);
6876
	}
6877
      }
6878
#if defined(ENABLE_ITTI)
frtabu's avatar
frtabu committed
6879
#if defined(ENABLE_USE_MME)
6880
	if (dedicated_DRB == 1){
6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920
//	  rrc_eNB_send_S1AP_E_RAB_SETUP_RESP(ctxt_pP,
//					     ue_context_p,
//					     ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);
if (ue_context_p->ue_context.nb_of_modify_e_rabs > 0) {
            rrc_eNB_send_S1AP_E_RAB_MODIFY_RESP(ctxt_pP,
                             ue_context_p,
                             ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);

            ue_context_p->ue_context.nb_of_modify_e_rabs = 0;
            ue_context_p->ue_context.nb_of_failed_e_rabs = 0;
            memset(ue_context_p->ue_context.modify_e_rab, 0, sizeof(ue_context_p->ue_context.modify_e_rab));
            for(int i = 0; i < NB_RB_MAX; i++) {
              ue_context_p->ue_context.modify_e_rab[i].xid = -1;
            }

          } else if(ue_context_p->ue_context.e_rab_release_command_flag == 1){
            xid = ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier;
            ue_context_p->ue_context.e_rab_release_command_flag = 0;
            //gtp tunnel delete
            msg_delete_tunnels_p = itti_alloc_new_message(TASK_RRC_ENB, GTPV1U_ENB_DELETE_TUNNEL_REQ);
            memset(&GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p), 0, sizeof(GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p)));
            GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p).rnti = ue_context_p->ue_context.rnti;
            for(i = 0; i < NB_RB_MAX; i++){
               if(xid == ue_context_p->ue_context.e_rab[i].xid){
                 GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p).eps_bearer_id[GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p).num_erab++] = ue_context_p->ue_context.enb_gtp_ebi[i];
                 ue_context_p->ue_context.enb_gtp_teid[i] = 0;
                 memset(&ue_context_p->ue_context.enb_gtp_addrs[i], 0, sizeof(ue_context_p->ue_context.enb_gtp_addrs[i]));
                 ue_context_p->ue_context.enb_gtp_ebi[i]  = 0;
               }
            }
            itti_send_msg_to_task(TASK_GTPV1_U, ctxt_pP->instance, msg_delete_tunnels_p);
            //S1AP_E_RAB_RELEASE_RESPONSE
            rrc_eNB_send_S1AP_E_RAB_RELEASE_RESPONSE(ctxt_pP,
                    ue_context_p,
                    xid);
          } else {
              rrc_eNB_send_S1AP_E_RAB_SETUP_RESP(ctxt_pP,
                             ue_context_p,
                             ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);
          }
6921
  }else if(dedicated_DRB == 0){
6922
                LOG_D(RRC, "Sending rrc_eNB_send_S1AP_INITIAL_CONTEXT_SETUP_RESP, establishment cause %ld\n",
6923 6924 6925 6926
  		ue_context_p->ue_context.reestablishment_cause );
  		// NN: not sure what we need to send S1AP_INITIAL_CONTEXT_SETUP_RESP only with this cause?
        //if(ue_context_p->ue_context.reestablishment_cause == ReestablishmentCause_spare1){
	    	rrc_eNB_send_S1AP_INITIAL_CONTEXT_SETUP_RESP(ctxt_pP,
6927
						       ue_context_p);
6928 6929
        // } else 
           {
6930
            ue_context_p->ue_context.reestablishment_cause = ReestablishmentCause_spare1;
6931 6932 6933 6934 6935 6936 6937
            for (uint8_t e_rab = 0; e_rab < ue_context_p->ue_context.nb_of_e_rabs; e_rab++) {
              if (ue_context_p->ue_context.e_rab[e_rab].status == E_RAB_STATUS_DONE) {
                ue_context_p->ue_context.e_rab[e_rab].status = E_RAB_STATUS_ESTABLISHED;
              } else {
                ue_context_p->ue_context.e_rab[e_rab].status = E_RAB_STATUS_FAILED;
              }
            }
6938
          }
6939 6940 6941 6942 6943 6944 6945 6946 6947
  }else if(dedicated_DRB == 2){
             for (uint8_t e_rab = 0; e_rab < ue_context_p->ue_context.nb_of_e_rabs; e_rab++) {
               if (ue_context_p->ue_context.e_rab[e_rab].status == E_RAB_STATUS_DONE) {
                 ue_context_p->ue_context.e_rab[e_rab].status = E_RAB_STATUS_ESTABLISHED;
               } else {
                 ue_context_p->ue_context.e_rab[e_rab].status = E_RAB_STATUS_FAILED;
               }
             }
         }
frtabu's avatar
frtabu committed
6948
#endif   
6949 6950
#else  // establish a dedicated bearer 
      if (dedicated_DRB == 0 ) {
6951
	//	ue_context_p->ue_context.e_rab[0].status = E_RAB_STATUS_ESTABLISHED;
6952
	rrc_eNB_reconfigure_DRBs(ctxt_pP,ue_context_p);
6953
      }
6954
#endif 
6955
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
6956

6957
    case UL_DCCH_MessageType__c1_PR_rrcConnectionReestablishmentComplete:
Cedric Roux's avatar
Cedric Roux committed
6958 6959 6960
      T(T_ENB_RRC_CONNECTION_REESTABLISHMENT_COMPLETE, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

6961 6962
      LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)Rx_sdu,sdu_sizeP,
                  "[MSG] RRC Connection Reestablishment Complete\n");
6963 6964

      MSC_LOG_RX_MESSAGE(
6965 6966 6967 6968 6969 6970 6971 6972
        MSC_RRC_ENB,
        MSC_RRC_UE,
        Rx_sdu,
        sdu_sizeP,
        MSC_AS_TIME_FMT" rrcConnectionReestablishmentComplete UE %x size %u",
        MSC_AS_TIME_ARGS(ctxt_pP),
        ue_context_p->ue_context.rnti,
        sdu_sizeP);
6973

6974
      LOG_I(RRC,
6975 6976 6977 6978 6979
            PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
            "(rrcConnectionReestablishmentComplete) ---> RRC_eNB\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            DCCH,
            sdu_sizeP);
6980 6981 6982
       {
        rnti_t reestablish_rnti = 0;
        // select C-RNTI from map
6983
        for (i = 0; i < MAX_MOBILES_PER_ENB; i++) {
6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003
          if (reestablish_rnti_map[i][0] == ctxt_pP->rnti) {
            reestablish_rnti = reestablish_rnti_map[i][1];
            ue_context_p = rrc_eNB_get_ue_context(
                              RC.rrc[ctxt_pP->module_id],
                              reestablish_rnti);
            // clear currentC-RNTI from map
            reestablish_rnti_map[i][0] = 0;
            reestablish_rnti_map[i][1] = 0;
            break;
          }
        }
        LOG_D(RRC, "reestablish_rnti_map[%d] [0] %x, [1] %x\n",
              i, reestablish_rnti_map[i][0], reestablish_rnti_map[i][1]);

        if (!ue_context_p) {
          LOG_E(RRC,
                PROTOCOL_RRC_CTXT_UE_FMT" RRCConnectionReestablishmentComplete without UE context, falt\n",
                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
          break;
        }
7004
        //clear
7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018
        if ((RC.rrc[ctxt_pP->module_id]->node_type  != ngran_eNB_CU) &&
       		(RC.rrc[ctxt_pP->module_id]->node_type  != ngran_ng_eNB_CU)&& 
       		(RC.rrc[ctxt_pP->module_id]->node_type  != ngran_gNB_CU)   ) {
    		int UE_id = find_UE_id(ctxt_pP->module_id, ctxt_pP->rnti);
	        if(UE_id == -1){
	          LOG_E(RRC,
	                PROTOCOL_RRC_CTXT_UE_FMT" RRCConnectionReestablishmentComplete without UE_id(MAC) rnti %x, fault\n",
	                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ctxt_pP->rnti);
	          break;
	        }
	    
       		 RC.mac[ctxt_pP->module_id]->UE_list.UE_sched_ctrl[UE_id].ue_reestablishment_reject_timer = 0;
       		 ue_context_p->ue_context.ue_reestablishment_timer = 0;
		}
7019 7020 7021 7022 7023 7024 7025 7026
        if (ul_dcch_msg->message.choice.c1.choice.rrcConnectionReestablishmentComplete.criticalExtensions.present ==
            RRCConnectionReestablishmentComplete__criticalExtensions_PR_rrcConnectionReestablishmentComplete_r8) {
          rrc_eNB_process_RRCConnectionReestablishmentComplete(ctxt_pP, reestablish_rnti, ue_context_p,
              ul_dcch_msg->message.choice.c1.choice.rrcConnectionReestablishmentComplete.rrc_TransactionIdentifier,
              &ul_dcch_msg->message.choice.c1.choice.rrcConnectionReestablishmentComplete.criticalExtensions.choice.rrcConnectionReestablishmentComplete_r8);

          //WARNING:Inform the controller about the UE activation. Should be moved to RRC agent in the future
          if (mac_agent_registered[ctxt_pP->module_id]) {
Robert Schmidt's avatar
Robert Schmidt committed
7027
            agent_rrc_xface[ctxt_pP->eNB_index]->flexran_agent_notify_ue_state_change(ctxt_pP->module_id,
7028 7029 7030 7031
                                                                                      ue_context_p->ue_id_rnti,
                                                                                      PROTOCOL__FLEX_UE_STATE_CHANGE_TYPE__FLUESC_ACTIVATED);
          }
        }
7032
        //ue_context_p->ue_context.ue_release_timer = 0;
7033
        ue_context_p->ue_context.ue_reestablishment_timer = 1;
7034 7035
        // remove UE after 100 frames after RRCConnectionReestablishmentRelease is triggered
        ue_context_p->ue_context.ue_reestablishment_timer_thres = 1000;
7036
      }
7037 7038 7039
      break;

    case UL_DCCH_MessageType__c1_PR_rrcConnectionSetupComplete:
7040 7041 7042 7043 7044
      // to avoid segmentation fault
      if(!ue_context_p){
        LOG_I(RRC, "Processing RRCConnectionSetupComplete UE %x, ue_context_p is NULL\n", ctxt_pP->rnti);
        break;
      }
7045 7046
      LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)Rx_sdu,sdu_sizeP,
                  "[MSG] RRC Connection SetupComplete\n");
7047 7048

      MSC_LOG_RX_MESSAGE(
7049 7050 7051 7052 7053 7054 7055 7056
        MSC_RRC_ENB,
        MSC_RRC_UE,
        Rx_sdu,
        sdu_sizeP,
        MSC_AS_TIME_FMT" RRCConnectionSetupComplete UE %x size %u",
        MSC_AS_TIME_ARGS(ctxt_pP),
        ue_context_p->ue_context.rnti,
        sdu_sizeP);
7057

7058
      LOG_D(RRC,
7059 7060 7061 7062 7063
            PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
            "(RRCConnectionSetupComplete) ---> RRC_eNB\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            DCCH,
            sdu_sizeP);
7064 7065 7066 7067 7068 7069

      if (ul_dcch_msg->message.choice.c1.choice.rrcConnectionSetupComplete.criticalExtensions.present ==
          RRCConnectionSetupComplete__criticalExtensions_PR_c1) {
        if (ul_dcch_msg->message.choice.c1.choice.rrcConnectionSetupComplete.criticalExtensions.choice.c1.
            present ==
            RRCConnectionSetupComplete__criticalExtensions__c1_PR_rrcConnectionSetupComplete_r8) {
7070 7071 7072
          
          if ((RC.rrc[ctxt_pP->module_id]->node_type  == ngran_eNB_DU) ||
	          (RC.rrc[ctxt_pP->module_id]->node_type  == ngran_gNB_DU)  ) {
7073
/*
7074 7075
            MessageDef                            *message_p;
          	message_p = itti_alloc_new_message (TASK_RRC_ENB, F1AP_UL_RRC_MESSAGE);
7076
      		F1AP_UL_RRC_MESSAGE (message_p).rrc_container =  (uint8_t*)&ul_dcch_msg->message.choice.c1.choice.rrcConnectionSetupComplete.criticalExtensions.choice.c1.choice.rrcConnectionSetupComplete_r8;
7077 7078 7079 7080 7081 7082
            F1AP_UL_RRC_MESSAGE (message_p).rrc_container_length = strlen(&ul_dcch_msg->message.choice.c1.choice.rrcConnectionSetupComplete.criticalExtensions.choice.c1.choice.rrcConnectionSetupComplete_r8);
      	    F1AP_UL_RRC_MESSAGE (message_p).gNB_CU_ue_id     = 0;  
      		F1AP_UL_RRC_MESSAGE (message_p).gNB_DU_ue_id = 0;
      		F1AP_UL_RRC_MESSAGE (message_p).rnti = ue_context_p->ue_context.rnti; 
      		F1AP_UL_RRC_MESSAGE (message_p).srb_id = DCCH;  
      		itti_send_msg_to_task (TASK_DU_F1, ctxt_pP->module_id, message_p);
7083
      		LOG_D(RRC, "Send F1AP_UL_RRC_MESSAGE with ITTI\n");*/
7084
		  } else { // eNB or CU node type 
7085 7086 7087 7088 7089 7090
          		rrc_eNB_process_RRCConnectionSetupComplete(
           		  ctxt_pP,
                  ue_context_p,
                  &ul_dcch_msg->message.choice.c1.choice.rrcConnectionSetupComplete.criticalExtensions.choice.c1.choice.rrcConnectionSetupComplete_r8);
                ue_context_p->ue_context.Status = RRC_CONNECTED;
                LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" UE State = RRC_CONNECTED \n",
7091
                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
7092
	     }
7093
	  //WARNING:Inform the controller about the UE activation. Should be moved to RRC agent in the future
7094 7095
	  if (rrc_agent_registered[ctxt_pP->module_id]) {
	    agent_rrc_xface[ctxt_pP->eNB_index]->flexran_agent_notify_ue_state_change(ctxt_pP->module_id,
7096
										  ue_context_p->ue_id_rnti,
7097
										  PROTOCOL__FLEX_UE_STATE_CHANGE_TYPE__FLUESC_ACTIVATED);
7098
	  }
7099 7100 7101
        }
      }

7102
      ue_context_p->ue_context.ue_release_timer=0;
7103 7104 7105
      break;

    case UL_DCCH_MessageType__c1_PR_securityModeComplete:
Cedric Roux's avatar
Cedric Roux committed
7106 7107
      T(T_ENB_RRC_SECURITY_MODE_COMPLETE, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
7108 7109 7110 7111 7112
      // to avoid segmentation fault
      if(!ue_context_p){
        LOG_I(RRC, "Processing securityModeComplete UE %x, ue_context_p is NULL\n", ctxt_pP->rnti);
        break;
      }
7113 7114
      LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)Rx_sdu,sdu_sizeP,
                  "[MSG] RRC Security Mode Complete\n");
7115

7116 7117

      MSC_LOG_RX_MESSAGE(
7118 7119 7120 7121 7122 7123 7124 7125
        MSC_RRC_ENB,
        MSC_RRC_UE,
        Rx_sdu,
        sdu_sizeP,
        MSC_AS_TIME_FMT" securityModeComplete UE %x size %u",
        MSC_AS_TIME_ARGS(ctxt_pP),
        ue_context_p->ue_context.rnti,
        sdu_sizeP);
7126

7127
      LOG_I(RRC,
7128 7129 7130
            PROTOCOL_RRC_CTXT_UE_FMT" received securityModeComplete on UL-DCCH %d from UE\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            DCCH);
7131
      LOG_D(RRC,
7132 7133 7134 7135 7136
            PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
            "(securityModeComplete) ---> RRC_eNB\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            DCCH,
            sdu_sizeP);
7137 7138 7139
      if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
         xer_fprint(stdout, &asn_DEF_UL_DCCH_Message, (void *)ul_dcch_msg);
      }
7140 7141 7142
      // confirm with PDCP about the security mode for DCCH
      //rrc_pdcp_config_req (enb_mod_idP, frameP, 1,CONFIG_ACTION_SET_SECURITY_MODE, (ue_mod_idP * NB_RB_MAX) + DCCH, 0x77);
      // continue the procedure
7143 7144 7145
      rrc_eNB_generate_UECapabilityEnquiry(
        ctxt_pP,
        ue_context_p);
7146
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
7147

7148
    case UL_DCCH_MessageType__c1_PR_securityModeFailure:
Cedric Roux's avatar
Cedric Roux committed
7149 7150 7151
      T(T_ENB_RRC_SECURITY_MODE_FAILURE, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

7152 7153
      LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)Rx_sdu,sdu_sizeP,
                  "[MSG] RRC Security Mode Failure\n");
7154 7155

      MSC_LOG_RX_MESSAGE(
7156 7157 7158 7159 7160 7161 7162 7163
        MSC_RRC_ENB,
        MSC_RRC_UE,
        Rx_sdu,
        sdu_sizeP,
        MSC_AS_TIME_FMT" securityModeFailure UE %x size %u",
        MSC_AS_TIME_ARGS(ctxt_pP),
        ue_context_p->ue_context.rnti,
        sdu_sizeP);
7164

7165 7166 7167 7168 7169 7170
      LOG_W(RRC,
            PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
            "(securityModeFailure) ---> RRC_eNB\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            DCCH,
            sdu_sizeP);
7171 7172 7173
      if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
         xer_fprint(stdout, &asn_DEF_UL_DCCH_Message, (void *)ul_dcch_msg);
      }
7174
      // cancel the security mode in PDCP
Lionel Gauthier's avatar
 
Lionel Gauthier committed
7175

7176
      // followup with the remaining procedure
7177
//#warning "LG Removed rrc_eNB_generate_UECapabilityEnquiry after receiving securityModeFailure"
Raymond Knopp's avatar
Raymond Knopp committed
7178
      rrc_eNB_generate_UECapabilityEnquiry(ctxt_pP, ue_context_p);
7179
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
7180

7181
    case UL_DCCH_MessageType__c1_PR_ueCapabilityInformation:
Cedric Roux's avatar
Cedric Roux committed
7182 7183
      T(T_ENB_RRC_UE_CAPABILITY_INFORMATION, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
7184 7185 7186 7187 7188
      // to avoid segmentation fault
      if(!ue_context_p){
          LOG_I(RRC, "Processing ueCapabilityInformation UE %x, ue_context_p is NULL\n", ctxt_pP->rnti);
          break;
      }
7189

7190 7191
      LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)Rx_sdu,sdu_sizeP,
                  "[MSG] RRC UECapablility Information\n");
7192 7193

      MSC_LOG_RX_MESSAGE(
7194 7195 7196 7197 7198 7199 7200 7201
        MSC_RRC_ENB,
        MSC_RRC_UE,
        Rx_sdu,
        sdu_sizeP,
        MSC_AS_TIME_FMT" ueCapabilityInformation UE %x size %u",
        MSC_AS_TIME_ARGS(ctxt_pP),
        ue_context_p->ue_context.rnti,
        sdu_sizeP);
7202

7203
      LOG_I(RRC,
7204 7205 7206
            PROTOCOL_RRC_CTXT_UE_FMT" received ueCapabilityInformation on UL-DCCH %d from UE\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            DCCH);
7207
      LOG_D(RRC,
7208 7209 7210 7211 7212
            PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
            "(UECapabilityInformation) ---> RRC_eNB\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            DCCH,
            sdu_sizeP);
7213 7214 7215
      if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
          xer_fprint(stdout, &asn_DEF_UL_DCCH_Message, (void *)ul_dcch_msg);
      }
7216
      LOG_I(RRC, "got UE capabilities for UE %x\n", ctxt_pP->rnti);
7217 7218
      if (ue_context_p->ue_context.UE_Capability) {
        LOG_I(RRC, "freeing old UE capabilities for UE %x\n", ctxt_pP->rnti);
7219 7220
        ASN_STRUCT_FREE(asn_DEF_UE_EUTRA_Capability,
                        ue_context_p->ue_context.UE_Capability);
7221 7222
        ue_context_p->ue_context.UE_Capability = 0;
      }
7223 7224
      dec_rval = uper_decode(NULL,
                             &asn_DEF_UE_EUTRA_Capability,
7225
                             (void **)&ue_context_p->ue_context.UE_Capability,
7226 7227 7228 7229 7230 7231
                             ul_dcch_msg->message.choice.c1.choice.ueCapabilityInformation.criticalExtensions.
                             choice.c1.choice.ueCapabilityInformation_r8.ue_CapabilityRAT_ContainerList.list.
                             array[0]->ueCapabilityRAT_Container.buf,
                             ul_dcch_msg->message.choice.c1.choice.ueCapabilityInformation.criticalExtensions.
                             choice.c1.choice.ueCapabilityInformation_r8.ue_CapabilityRAT_ContainerList.list.
                             array[0]->ueCapabilityRAT_Container.size, 0, 0);
7232 7233 7234
      if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
         xer_fprint(stdout, &asn_DEF_UE_EUTRA_Capability, ue_context_p->ue_context.UE_Capability);
      }
7235 7236 7237 7238 7239

      if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0)) {
        LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Failed to decode UE capabilities (%zu bytes)\n",
              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
              dec_rval.consumed);
7240 7241
        ASN_STRUCT_FREE(asn_DEF_UE_EUTRA_Capability,
                        ue_context_p->ue_context.UE_Capability);
7242 7243
        ue_context_p->ue_context.UE_Capability = 0;
      }
7244

7245
      if (EPC_MODE_ENABLED) {
7246

7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259
        if (EPC_MODE_ENABLED == 1) {
  	  rrc_eNB_send_S1AP_UE_CAPABILITIES_IND(ctxt_pP,
  						ue_context_p,
  						ul_dcch_msg);
  	}
      } else {
  	ue_context_p->ue_context.nb_of_e_rabs = 1;
  	for (i = 0; i < ue_context_p->ue_context.nb_of_e_rabs; i++){
  	  ue_context_p->ue_context.e_rab[i].status = E_RAB_STATUS_NEW;
  	  ue_context_p->ue_context.e_rab[i].param.e_rab_id = 1+i;
  	  ue_context_p->ue_context.e_rab[i].param.qos.qci=9;
  	}
  	ue_context_p->ue_context.setup_e_rabs =ue_context_p->ue_context.nb_of_e_rabs;
7260
      }
7261

7262 7263
      rrc_eNB_generate_defaultRRCConnectionReconfiguration(ctxt_pP,
          ue_context_p,
7264
          RC.rrc[ctxt_pP->module_id]->HO_flag);
7265
      break;
7266

7267
    case UL_DCCH_MessageType__c1_PR_ulHandoverPreparationTransfer:
Cedric Roux's avatar
Cedric Roux committed
7268 7269 7270
      T(T_ENB_RRC_UL_HANDOVER_PREPARATION_TRANSFER, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

7271
      break;
7272

7273
    case UL_DCCH_MessageType__c1_PR_ulInformationTransfer:
Cedric Roux's avatar
Cedric Roux committed
7274 7275
      T(T_ENB_RRC_UL_INFORMATION_TRANSFER, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
7276 7277 7278 7279 7280
      // to avoid segmentation fault
      if(!ue_context_p){
          LOG_I(RRC, "Processing ulInformationTransfer UE %x, ue_context_p is NULL\n", ctxt_pP->rnti);
          break;
      }
Cedric Roux's avatar
Cedric Roux committed
7281

7282
      LOG_D(RRC,"[MSG] RRC UL Information Transfer \n");
7283 7284
      LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)Rx_sdu,sdu_sizeP,
                  "[MSG] RRC UL Information Transfer \n");
7285 7286

      MSC_LOG_RX_MESSAGE(
7287 7288 7289 7290 7291 7292 7293 7294
        MSC_RRC_ENB,
        MSC_RRC_UE,
        Rx_sdu,
        sdu_sizeP,
        MSC_AS_TIME_FMT" ulInformationTransfer UE %x size %u",
        MSC_AS_TIME_ARGS(ctxt_pP),
        ue_context_p->ue_context.rnti,
        sdu_sizeP);
7295

7296
      if (EPC_MODE_ENABLED == 1) {
7297 7298 7299
        rrc_eNB_send_S1AP_UPLINK_NAS(ctxt_pP,
                                     ue_context_p,
                                     ul_dcch_msg);
7300 7301
      }
      break;
7302

7303
    case UL_DCCH_MessageType__c1_PR_counterCheckResponse:
Cedric Roux's avatar
Cedric Roux committed
7304 7305 7306
      T(T_ENB_RRC_COUNTER_CHECK_RESPONSE, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

7307
      break;
7308

7309
#if (RRC_VERSION >= MAKE_VERSION(9, 0, 0))
7310

7311
    case UL_DCCH_MessageType__c1_PR_ueInformationResponse_r9:
Cedric Roux's avatar
Cedric Roux committed
7312 7313 7314
      T(T_ENB_RRC_UE_INFORMATION_RESPONSE_R9, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

7315 7316 7317
      break;

    case UL_DCCH_MessageType__c1_PR_proximityIndication_r9:
Cedric Roux's avatar
Cedric Roux committed
7318 7319 7320
      T(T_ENB_RRC_PROXIMITY_INDICATION_R9, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

7321
      break;
7322
#endif
7323

7324
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
7325
    case UL_DCCH_MessageType__c1_PR_rnReconfigurationComplete_r10:
Cedric Roux's avatar
Cedric Roux committed
7326 7327 7328
      T(T_ENB_RRC_RECONFIGURATION_COMPLETE_R10, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

7329
      break;
7330

7331
    case UL_DCCH_MessageType__c1_PR_mbmsCountingResponse_r10:
Cedric Roux's avatar
Cedric Roux committed
7332 7333 7334
      T(T_ENB_RRC_MBMS_COUNTING_RESPONSE_R10, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

7335
      break;
winckel's avatar
winckel committed
7336

7337
    case UL_DCCH_MessageType__c1_PR_interFreqRSTDMeasurementIndication_r10:
Cedric Roux's avatar
Cedric Roux committed
7338 7339 7340
      T(T_ENB_RRC_INTER_FREQ_RSTD_MEASUREMENT_INDICATION, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

7341
      break;
7342
#endif
7343

7344
    default:
Cedric Roux's avatar
Cedric Roux committed
7345 7346 7347
      T(T_ENB_RRC_UNKNOW_MESSAGE, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

7348 7349 7350
      LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Unknown message %s:%u\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            __FILE__, __LINE__);
7351
      return -1;
winckel's avatar
winckel committed
7352 7353
    }

7354
    return 0;
7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365
    //TTN for D2D
  } else if (ul_dcch_msg->message.present == UL_DCCH_MessageType_PR_messageClassExtension){
     LOG_I(RRC, "THINH [UL_DCCH_MessageType_PR_messageClassExtension]\n");

     switch (ul_dcch_msg->message.choice.messageClassExtension.present) {
     case UL_DCCH_MessageType__messageClassExtension_PR_NOTHING: /* No components present */
        break;
     case UL_DCCH_MessageType__messageClassExtension_PR_c2: //SidelinkUEInformation
     //case UL_DCCH_MessageType__messageClassExtension__c2_PR_sidelinkUEInformation_r12: //SidelinkUEInformation
        LOG_I(RRC,"THINH [UL_DCCH_MessageType__messageClassExtension_PR_c2]\n");

7366 7367
        LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)Rx_sdu,sdu_sizeP,
                    "[MSG] RRC SidelinkUEInformation \n");
7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394

        MSC_LOG_RX_MESSAGE(
              MSC_RRC_ENB,
              MSC_RRC_UE,
              Rx_sdu,
              sdu_sizeP,
              MSC_AS_TIME_FMT" SidelinkUEInformation UE %x size %u",
              MSC_AS_TIME_ARGS(ctxt_pP),
              ue_context_p->ue_context.rnti,
              sdu_sizeP);

        LOG_I(RRC,
              PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
              "(SidelinkUEInformation) ---> RRC_eNB\n",
              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
              DCCH,
              sdu_sizeP);

        rrc_eNB_process_SidelinkUEInformation(
              ctxt_pP,
              ue_context_p,
              &ul_dcch_msg->message.choice.messageClassExtension.choice.c2.choice.sidelinkUEInformation_r12);
        break;
     default:
        break;
     }
     //end TTN
7395
  } else {
7396 7397 7398
    LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Unknown error %s:%u\n",
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
          __FILE__, __LINE__);
7399 7400 7401
    return -1;
  }

7402
  return 0;
winckel's avatar
winckel committed
7403 7404
}

7405
#if defined(ENABLE_ITTI)
7406 7407 7408 7409
void rrc_eNB_reconfigure_DRBs (const protocol_ctxt_t* const ctxt_pP,
			       rrc_eNB_ue_context_t*  ue_context_pP){

  int i;
Navid Nikaein's avatar
Navid Nikaein committed
7410
  int e_rab_done=0;
7411
  for (i = 0; 
Navid Nikaein's avatar
Navid Nikaein committed
7412
       i < 3;//NB_RB_MAX - 3;  // S1AP_MAX_E_RAB
7413 7414
       i++) {
    
7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428
    if ( ue_context_pP->ue_context.e_rab[i].status < E_RAB_STATUS_DONE){ 
      ue_context_pP->ue_context.e_rab[i].status = E_RAB_STATUS_NEW;
      ue_context_pP->ue_context.e_rab[i].param.e_rab_id = i + 1;
      ue_context_pP->ue_context.e_rab[i].param.qos.qci = i % 9;
      ue_context_pP->ue_context.e_rab[i].param.qos.allocation_retention_priority.priority_level= i % PRIORITY_LEVEL_LOWEST;
      ue_context_pP->ue_context.e_rab[i].param.qos.allocation_retention_priority.pre_emp_capability= PRE_EMPTION_CAPABILITY_DISABLED;
      ue_context_pP->ue_context.e_rab[i].param.qos.allocation_retention_priority.pre_emp_vulnerability= PRE_EMPTION_VULNERABILITY_DISABLED;
      ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer = NULL;
      ue_context_pP->ue_context.e_rab[i].param.nas_pdu.length = 0;
      //	memset (ue_context_pP->ue_context.e_rab[i].param.sgw_addr.buffer,0,20);
      ue_context_pP->ue_context.e_rab[i].param.sgw_addr.length = 0;
      ue_context_pP->ue_context.e_rab[i].param.gtp_teid=0;
      
      ue_context_pP->ue_context.nb_of_e_rabs++;
Navid Nikaein's avatar
Navid Nikaein committed
7429
      e_rab_done++;
7430 7431 7432
      LOG_I(RRC,"setting up the dedicated DRBs %d (index %d) status %d \n", 
	    ue_context_pP->ue_context.e_rab[i].param.e_rab_id, i, ue_context_pP->ue_context.e_rab[i].status);
    }
7433
  }
Navid Nikaein's avatar
Navid Nikaein committed
7434 7435
  ue_context_pP->ue_context.setup_e_rabs+=e_rab_done;
 
7436 7437 7438
  rrc_eNB_generate_dedicatedRRCConnectionReconfiguration(ctxt_pP, ue_context_pP, 0);
}

Raymond Knopp's avatar
Raymond Knopp committed
7439
void handle_f1_setup_req(f1ap_setup_req_t *f1_setup_req) { 
7440

7441
  
7442
  LOG_I(RRC,"Received F1 Setup Request from gNB_DU %llu (%s)\n",(unsigned long long int)f1_setup_req->gNB_DU_id,f1_setup_req->gNB_DU_name);
7443
  
7444
  //uint16_t num_cells_to_activate = 0;
7445 7446
  
  int cu_cell_ind=0;
Raymond Knopp's avatar
Raymond Knopp committed
7447

7448 7449 7450
  MessageDef                         *msg_p = NULL;

  //LOG_W(RRC,"num_cells_available %d \n", f1_setup_req->num_cells_available);
7451 7452 7453 7454 7455
  for (int i=0;i<f1_setup_req->num_cells_available;i++) {
    // check that mcc/mnc match and grab MIB/SIB1
    int found_cell=0;
    for (int j=0;j<RC.nb_inst;j++) {
      eNB_RRC_INST *rrc = RC.rrc[j];
7456 7457 7458 7459 7460
      if (rrc->mcc == f1_setup_req->mcc[i] && 
	  rrc->mnc == f1_setup_req->mnc[i] && 
	  rrc->nr_cellid == f1_setup_req->nr_cellid[i]) {
        // check that CU rrc instance corresponds to mcc/mnc/cgi (normally cgi should be enough, but just in case)

7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507
        rrc->carrier[0].MIB = malloc(f1_setup_req->mib_length[i]);
        rrc->carrier[0].sizeof_MIB = f1_setup_req->mib_length[i];
        LOG_W(RRC, "instance %d mib length %d\n", i, f1_setup_req->mib_length[i]);
        LOG_W(RRC, "instance %d sib1 length %d\n", i, f1_setup_req->sib1_length[i]);
       
        memcpy((void*)rrc->carrier[0].MIB,f1_setup_req->mib[i],f1_setup_req->mib_length[i]);
        asn_dec_rval_t dec_rval = uper_decode_complete(NULL,
        					       &asn_DEF_BCCH_BCH_Message,
        					       (void **)&rrc->carrier[0].mib_DU,
        					       f1_setup_req->mib[i],
        					       f1_setup_req->mib_length[i]);
        AssertFatal(dec_rval.code == RC_OK,
        	    "[eNB_DU %"PRIu8"] Failed to decode BCCH_BCH_MESSAGE (%zu bits)\n",
        	    j,
        	    dec_rval.consumed );	
        BCCH_BCH_Message_t *mib = &rrc->carrier[0].mib;
        BCCH_BCH_Message_t *mib_DU = rrc->carrier[0].mib_DU;
        mib->message.dl_Bandwidth = mib_DU->message.dl_Bandwidth;
        mib->message.phich_Config.phich_Resource = mib_DU->message.phich_Config.phich_Resource;
        mib->message.phich_Config.phich_Duration = mib_DU->message.phich_Config.phich_Duration;

        rrc->carrier[0].SIB1 = malloc(f1_setup_req->sib1_length[i]);
        rrc->carrier[0].sizeof_SIB1 = f1_setup_req->sib1_length[i];
        memcpy((void*)rrc->carrier[0].SIB1,f1_setup_req->sib1[i],f1_setup_req->sib1_length[i]); 
        dec_rval = uper_decode_complete(NULL,
        				&asn_DEF_BCCH_DL_SCH_Message,
        				(void **)&rrc->carrier[0].siblock1_DU,
        				f1_setup_req->sib1[i],
        				f1_setup_req->sib1_length[i]);
        AssertFatal(dec_rval.code == RC_OK,
        	    "[eNB_DU %"PRIu8"] Failed to decode BCCH_DLSCH_MESSAGE (%zu bits)\n",
        	    j,
        	    dec_rval.consumed );	
        // Parse message and extract SystemInformationBlockType1 field
        BCCH_DL_SCH_Message_t *bcch_message = rrc->carrier[0].siblock1_DU;
        AssertFatal(bcch_message->message.present == BCCH_DL_SCH_MessageType_PR_c1,
        	    "bcch_message->message.present != BCCH_DL_SCH_MessageType_PR_c1\n");
        AssertFatal(bcch_message->message.choice.c1.present == BCCH_DL_SCH_MessageType__c1_PR_systemInformationBlockType1,
        	    "bcch_message->message.choice.c1.present != BCCH_DL_SCH_MessageType__c1_PR_systemInformationBlockType1\n");
        rrc->carrier[0].sib1 = &bcch_message->message.choice.c1.choice.systemInformationBlockType1;
        rrc->carrier[0].physCellId = f1_setup_req->nr_pci[i];
        // prepare F1_SETUP_RESPONSE

        if (msg_p == NULL) {
          msg_p = itti_alloc_new_message (TASK_CU_F1,F1AP_SETUP_RESP); 						 
        }
        F1AP_SETUP_RESP (msg_p).gNB_CU_name                                = rrc->node_name;
7508
        F1AP_SETUP_RESP (msg_p).mcc[cu_cell_ind]                           = rrc->mcc;
7509 7510
        F1AP_SETUP_RESP (msg_p).mnc[cu_cell_ind]                           = rrc->mnc;
        F1AP_SETUP_RESP (msg_p).mnc_digit_length[cu_cell_ind]              = rrc->mnc_digit_length;
7511
	F1AP_SETUP_RESP (msg_p).nr_cellid[cu_cell_ind]                     = rrc->nr_cellid;
7512 7513 7514 7515 7516
        F1AP_SETUP_RESP (msg_p).nrpci[cu_cell_ind]                         = f1_setup_req->nr_pci[i];
        int num_SI= 0;
        if (rrc->carrier[0].SIB23) {
          F1AP_SETUP_RESP (msg_p).SI_container[cu_cell_ind][num_SI]        = rrc->carrier[0].SIB23;
          F1AP_SETUP_RESP (msg_p).SI_container_length[cu_cell_ind][num_SI] = rrc->carrier[0].sizeof_SIB23;
7517 7518 7519
	  printf("SI %d: ",0);
	  for (int n=0;n<F1AP_SETUP_RESP (msg_p).SI_container_length[j][num_SI];n++) printf("%2x ",F1AP_SETUP_RESP (msg_p).SI_container[0][num_SI][n]);
	  printf("\n");
7520 7521 7522
          num_SI++;
        }
        F1AP_SETUP_RESP (msg_p).num_SI[cu_cell_ind] = num_SI;
7523

7524 7525
        cu_cell_ind++;
        found_cell=1;
7526 7527 7528 7529

        F1AP_SETUP_RESP (msg_p).num_cells_to_activate = cu_cell_ind;
        // send ITTI message to F1AP-CU task
        itti_send_msg_to_task (TASK_CU_F1, ENB_MODULE_ID_TO_INSTANCE(j), msg_p);
7530 7531 7532 7533 7534 7535 7536
        break;
      } else {// setup_req mcc/mnc match rrc internal list element
        
        LOG_W(RRC,"[Inst %d] No matching MCC/MNC: rrc->mcc/f1_setup_req->mcc %d/%d rrc->mnc/f1_setup_req->mnc %d/%d \n", 
            j, rrc->mcc, f1_setup_req->mcc[i],rrc->mnc, f1_setup_req->mnc[i]);

      }
7537 7538 7539
    }// for (int j=0;j<RC.nb_inst;j++)
    if (found_cell==0) {
      AssertFatal(1==0,"No cell found\n");
Raymond Knopp's avatar
Raymond Knopp committed
7540
      /*msg_p = itti_alloc_new_message (TASK_CU_F1,F1AP_SETUP_FAILURE); 						 
7541 7542 7543 7544 7545 7546 7547 7548 7549 7550
      F1AP_SETUP_RESP (msg_p).cause                             = rrc->node_name;
      F1AP_SETUP_RESP (msg_p).time_to_wait                      = rrc->node_id;
      F1AP_SETUP_RESP (msg_p).criticality_diagnostics           = rrc->node_name;*/
    }
    // handle other failure cases
  }//for (int i=0;i<f1_setup_req->num_cells_available;i++)
}
 

  // ignore 5GNR fields for now, just take MIB and SIB1
7551 7552 7553 7554 7555 7556
//-----------------------------------------------------------------------------
void*
rrc_enb_task(
  void* args_p
)
//-----------------------------------------------------------------------------
7557 7558 7559 7560
{
  MessageDef                         *msg_p;
  const char                         *msg_name_p;
  instance_t                          instance;
7561
  int                                rrc_inst;
7562 7563
  int                                 result;

7564
  protocol_ctxt_t                     ctxt;
7565

7566
  pthread_mutex_init(&lock_ue_freelist, NULL);
7567 7568
  pthread_mutex_init(&rrc_release_freelist, NULL);
  memset(&rrc_release_info,0,sizeof(RRC_release_list_t));
7569
  itti_mark_task_ready(TASK_RRC_ENB);
7570
  LOG_I(RRC,"Entering main loop of RRC message task\n");
7571 7572 7573 7574 7575 7576
  while (1) {
    // Wait for a message
    itti_receive_msg(TASK_RRC_ENB, &msg_p);

    msg_name_p = ITTI_MSG_NAME(msg_p);
    instance = ITTI_MSG_INSTANCE(msg_p);
7577
    
7578
    LOG_I(RRC,"Received message %s\n",msg_name_p);
7579 7580 7581

    switch (ITTI_MSG_ID(msg_p)) {
    case TERMINATE_MESSAGE:
7582
      LOG_W(RRC, " *** Exiting RRC thread\n");
7583 7584 7585 7586 7587 7588 7589 7590 7591
      itti_exit_task();
      break;

    case MESSAGE_TEST:
      LOG_I(RRC, "[eNB %d] Received %s\n", instance, msg_name_p);
      break;

      /* Messages from MAC */
    case RRC_MAC_CCCH_DATA_IND:
7592 7593 7594

      rrc_inst = RRC_MAC_CCCH_DATA_IND(msg_p).enb_index;

7595
      PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt,
7596
                                    rrc_inst,
7597 7598 7599 7600 7601 7602 7603
                                    ENB_FLAG_YES,
                                    RRC_MAC_CCCH_DATA_IND(msg_p).rnti,
                                    msg_p->ittiMsgHeader.lte_time.frame,
                                    msg_p->ittiMsgHeader.lte_time.slot);
      LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Received %s\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(&ctxt),
            msg_name_p);
7604

7605 7606
      // this part will be done in rrc_eNB_decode_ccch
      /*
7607
      struct rrc_eNB_ue_context_s *ue_context_p = rrc_eNB_get_ue_context(RC.rrc[rrc_inst],
7608 7609
									 RRC_MAC_CCCH_DATA_IND(msg_p).rnti);

7610 7611 7612 7613 7614 7615 7616 7617
      if (ue_context_p == NULL) {

	// create a ue_context with rnti as random value, will be updated when Attach Request is received
	ue_context_p = rrc_eNB_get_next_free_ue_context(&ctxt,
							RRC_MAC_CCCH_DATA_IND(msg_p).rnti
							);
      }

7618 7619
      eNB_RRC_UE_t *ue_p = &ue_context_p->ue_context; 
      srb_info_p = &ue_p->Srb0;
7620

7621 7622
      LOG_I(RRC,"Decoding CCCH : inst %d, CC_id %d, ue_context %p (rnti %x), sib_info_p->Rx_buffer.payload_size %d\n",
	    rrc_inst,CC_id,ue_p, ue_p->rnti,RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size);
7623 7624
       
      CC_id = RRC_MAC_CCCH_DATA_IND(msg_p).CC_id;
7625 7626
      memcpy(srb_info_p->Rx_buffer.Payload,
             RRC_MAC_CCCH_DATA_IND(msg_p).sdu,
7627 7628
             RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size);
      srb_info_p->Rx_buffer.payload_size = RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size;
7629
      srb_info_p->Active = 1;
7630

7631
      rrc_eNB_decode_ccch(&ctxt, (uint8_t*)srb_info_p->Rx_buffer.Payload,srb_info_p->Rx_buffer.payload_size, CC_id);
7632 7633 7634 7635 7636 7637 7638 7639
      */
      if (RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size >= RRC_BUFFER_SIZE_MAX) {
          LOG_W(RRC, "CCCH message has size %d > %d\n",RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size,RRC_BUFFER_SIZE_MAX);
      }
      rrc_eNB_decode_ccch(&ctxt, 
      					  (uint8_t*)RRC_MAC_CCCH_DATA_IND(msg_p).sdu,
             			  RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size,
             			  RRC_MAC_CCCH_DATA_IND(msg_p).CC_id);
7640
      break;
7641
	    
7642 7643
      /* Messages from PDCP */
    case RRC_DCCH_DATA_IND:
7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656
      PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt,
                                    instance,
                                    ENB_FLAG_YES,
                                    RRC_DCCH_DATA_IND(msg_p).rnti,
                                    msg_p->ittiMsgHeader.lte_time.frame,
                                    msg_p->ittiMsgHeader.lte_time.slot);
      LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Received on DCCH %d %s\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(&ctxt),
            RRC_DCCH_DATA_IND(msg_p).dcch_index,
            msg_name_p);
      rrc_eNB_decode_dcch(&ctxt,
                          RRC_DCCH_DATA_IND(msg_p).dcch_index,
                          RRC_DCCH_DATA_IND(msg_p).sdu_p,
7657 7658 7659 7660
                          RRC_DCCH_DATA_IND(msg_p).sdu_size);

      // Message buffer has been processed, free it now.
      result = itti_free(ITTI_MSG_ORIGIN_ID(msg_p), RRC_DCCH_DATA_IND(msg_p).sdu_p);
7661 7662 7663 7664
      if (result != EXIT_SUCCESS) {
          LOG_I(RRC, "Failed to free memory (%d)!\n",result);
          break;
      }
7665
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
7666 7667 7668

#   if defined(ENABLE_USE_MME)

7669 7670 7671 7672
      /* Messages from S1AP */
    case S1AP_DOWNLINK_NAS:
      rrc_eNB_process_S1AP_DOWNLINK_NAS(msg_p, msg_name_p, instance, &rrc_eNB_mui);
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
7673

7674 7675 7676
    case S1AP_INITIAL_CONTEXT_SETUP_REQ:
      rrc_eNB_process_S1AP_INITIAL_CONTEXT_SETUP_REQ(msg_p, msg_name_p, instance);
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
7677

7678 7679 7680
    case S1AP_UE_CTXT_MODIFICATION_REQ:
      rrc_eNB_process_S1AP_UE_CTXT_MODIFICATION_REQ(msg_p, msg_name_p, instance);
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
7681

7682
    case S1AP_PAGING_IND:
7683 7684
      LOG_D(RRC, "[eNB %d] Received Paging message from S1AP: %s\n", instance, msg_name_p);
      rrc_eNB_process_PAGING_IND(msg_p, msg_name_p, instance);
7685
      break;
7686 7687 7688 7689 7690
  
    case S1AP_E_RAB_SETUP_REQ: 
      rrc_eNB_process_S1AP_E_RAB_SETUP_REQ(msg_p, msg_name_p, instance);
      LOG_D(RRC, "[eNB %d] Received the message %s\n", instance, msg_name_p);
      break;
7691 7692 7693 7694 7695 7696 7697 7698

    case S1AP_E_RAB_MODIFY_REQ:
      rrc_eNB_process_S1AP_E_RAB_MODIFY_REQ(msg_p, msg_name_p, instance);
      break;

    case S1AP_E_RAB_RELEASE_COMMAND:
      rrc_eNB_process_S1AP_E_RAB_RELEASE_COMMAND(msg_p, msg_name_p, instance);
      break;
7699
    
7700 7701 7702
    case S1AP_UE_CONTEXT_RELEASE_REQ:
      rrc_eNB_process_S1AP_UE_CONTEXT_RELEASE_REQ(msg_p, msg_name_p, instance);
      break;
7703

7704 7705 7706
    case S1AP_UE_CONTEXT_RELEASE_COMMAND:
      rrc_eNB_process_S1AP_UE_CONTEXT_RELEASE_COMMAND(msg_p, msg_name_p, instance);
      break;
7707

7708 7709 7710 7711
    case GTPV1U_ENB_DELETE_TUNNEL_RESP:
      /* Nothing to do. Apparently everything is done in S1AP processing */
      //LOG_I(RRC, "[eNB %d] Received message %s, not processed because procedure not synched\n",
      //instance, msg_name_p);
7712 7713 7714 7715 7716
     if (rrc_eNB_get_ue_context(RC.rrc[instance], GTPV1U_ENB_DELETE_TUNNEL_RESP(msg_p).rnti)
         && rrc_eNB_get_ue_context(RC.rrc[instance], GTPV1U_ENB_DELETE_TUNNEL_RESP(msg_p).rnti)->ue_context.ue_release_timer_rrc > 0) {
        rrc_eNB_get_ue_context(RC.rrc[instance], GTPV1U_ENB_DELETE_TUNNEL_RESP(msg_p).rnti)->ue_context.ue_release_timer_rrc =
        rrc_eNB_get_ue_context(RC.rrc[instance], GTPV1U_ENB_DELETE_TUNNEL_RESP(msg_p).rnti)->ue_context.ue_release_timer_thres_rrc;
      }
7717
      break;
Lionel Gauthier's avatar
Lionel Gauthier committed
7718

Lionel Gauthier's avatar
 
Lionel Gauthier committed
7719 7720
#   endif

7721 7722
      /* Messages from eNB app */
    case RRC_CONFIGURATION_REQ:
7723
      LOG_I(RRC, "[eNB %d] Received %s : %p\n", instance, msg_name_p, &RRC_CONFIGURATION_REQ(msg_p));
7724
      openair_rrc_eNB_configuration(ENB_INSTANCE_TO_MODULE_ID(instance), &RRC_CONFIGURATION_REQ(msg_p));
7725
      break;
Raymond Knopp's avatar
Raymond Knopp committed
7726 7727
      /* Messages from F1AP task */
    case F1AP_SETUP_REQ:
7728
      AssertFatal(RC.rrc[0]->node_type == ngran_eNB_CU || RC.rrc[0]->node_type == ngran_ng_eNB_CU,
7729
		  "should not receive F1AP_SETUP_REQUEST, need call by CU!\n");
Raymond Knopp's avatar
Raymond Knopp committed
7730
      LOG_I(RRC,"[eNB %d] Received %s : %p\n", instance, msg_name_p, &F1AP_SETUP_REQ(msg_p));
7731 7732 7733
      
      
      handle_f1_setup_req(&F1AP_SETUP_REQ(msg_p));
Lionel Gauthier's avatar
 
Lionel Gauthier committed
7734

7735
      break;
7736 7737 7738
    default:
      LOG_E(RRC, "[eNB %d] Received unexpected message %s\n", instance, msg_name_p);
      break;
7739
    }
7740 7741

    result = itti_free(ITTI_MSG_ORIGIN_ID(msg_p), msg_p);
7742 7743 7744 7745
    if (result != EXIT_SUCCESS) {
        LOG_I(RRC, "Failed to free memory (%d)!\n",result);
        continue;
    }
7746 7747
    msg_p = NULL;
  }
7748 7749
}
#endif
winckel's avatar
winckel committed
7750

7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771
/*------------------------------------------------------------------------------*/
void
openair_rrc_top_init_eNB(int eMBMS_active,uint8_t HO_active)
//-----------------------------------------------------------------------------
{

  module_id_t         module_id;
  int                 CC_id;

  /* for no gcc warnings */
  (void)CC_id;

  LOG_D(RRC, "[OPENAIR][INIT] Init function start: NB_eNB_INST=%d\n", RC.nb_inst);

  if (RC.nb_inst > 0) {
    LOG_I(RRC,"[eNB] handover active state is %d \n", HO_active);

    for (module_id=0; module_id<NB_eNB_INST; module_id++) {
      RC.rrc[module_id]->HO_flag   = (uint8_t)HO_active;
    }

7772
#if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789
    LOG_I(RRC,"[eNB] eMBMS active state is %d \n", eMBMS_active);

    for (module_id=0; module_id<NB_eNB_INST; module_id++) {
      for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
        RC.rrc[module_id]->carrier[CC_id].MBMS_flag = (uint8_t)eMBMS_active;
      }
    }

#endif
#ifdef CBA

    for (module_id=0; module_id<RC.nb_inst; module_id++) {
      for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
        RC.rrc[module_id]->carrier[CC_id].num_active_cba_groups = cba_group_active;
      }
    }

winckel's avatar
winckel committed
7790
#endif
7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807
  } 


}

//-----------------------------------------------------------------------------
void
rrc_top_cleanup_eNB(
  void
)
//-----------------------------------------------------------------------------
{

  for (int i=0;i<RC.nb_inst;i++) free (RC.rrc[i]);
  free(RC.rrc);
}

7808 7809

//-----------------------------------------------------------------------------
7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928
//TTN - for D2D
uint8_t
rrc_eNB_process_SidelinkUEInformation(
      const protocol_ctxt_t* const ctxt_pP,
      rrc_eNB_ue_context_t*         ue_context_pP,
      SidelinkUEInformation_r12_t * sidelinkUEInformation
)
//-----------------------------------------------------------------------------
{
   SL_DestinationInfoList_r12_t  *destinationInfoList;
   int n_destinations = 0;
   int n_discoveryMessages = 0;

   LOG_I(RRC,
         PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel UL-DCCH, " "processing SidelinkUEInformation from UE (SRB1 Active)\n",
         PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));

   //For SL Communication
   if (sidelinkUEInformation->criticalExtensions.present ==  SidelinkUEInformation_r12__criticalExtensions_PR_c1){
      if (sidelinkUEInformation->criticalExtensions.choice.c1.present == SidelinkUEInformation_r12__criticalExtensions__c1_PR_sidelinkUEInformation_r12){
         // express its interest to receive SL communication
         if (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commRxInterestedFreq_r12 !=  NULL){

         }

         // express its interest to transmit  non-relay one-to-many SL communication
         if ((sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commTxResourceReq_r12 != NULL) && (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commTxResourceReq_r12->carrierFreq_r12 != NULL)){
            n_destinations = sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commTxResourceReq_r12->destinationInfoList_r12.list.count;
            destinationInfoList = CALLOC(1, sizeof(SL_DestinationInfoList_r12_t));
            for (int i=0; i< n_destinations; i++ ){
               //sl_DestinationIdentityList[i] = *(sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commTxResourceReq_r12->destinationInfoList_r12.list.array[i]);
               ASN_SEQUENCE_ADD(&destinationInfoList->list, sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commTxResourceReq_r12->destinationInfoList_r12.list.array[i]);
            }
            //generate RRC Reconfiguration
            rrc_eNB_generate_RRCConnectionReconfiguration_Sidelink(ctxt_pP, ue_context_pP, destinationInfoList, 0);
            return 0;

         }

         // express its interest to transmit  non-relay one-to-one SL communication
         if ((sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension != NULL) && (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceReqUC_r13 != NULL)) {
            if (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceReqUC_r13->carrierFreq_r12 != NULL){
               n_destinations = sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceReqUC_r13->destinationInfoList_r12.list.count;
               destinationInfoList = CALLOC(1, sizeof(SL_DestinationInfoList_r12_t));
               for (int i=0; i< n_destinations; i++ ){
                  //sl_DestinationIdentityList[i] = *(sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceReqUC_r13->destinationInfoList_r12.list.array[i]);
                  ASN_SEQUENCE_ADD(&destinationInfoList->list,sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceReqUC_r13->destinationInfoList_r12.list.array[i]);
               }
               //generate RRC Reconfiguration
               rrc_eNB_generate_RRCConnectionReconfiguration_Sidelink(ctxt_pP, ue_context_pP, destinationInfoList, 0);
               return 0;
            }
         }

         // express its interest to transmit relay related one-to-one SL communication
         if ((sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension != NULL) &&(sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelayUC_r13 != NULL)) {
            if (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelayUC_r13->destinationInfoList_r12.list.count > 0) {
               n_destinations = sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelayUC_r13->destinationInfoList_r12.list.count;
               destinationInfoList = CALLOC(1, sizeof(SL_DestinationInfoList_r12_t));
               for (int i=0; i< n_destinations; i++ ){
                  //sl_DestinationIdentityList[i] = *(sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelayUC_r13->destinationInfoList_r12.list.array[i]);
                  ASN_SEQUENCE_ADD(&destinationInfoList->list, sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelayUC_r13->destinationInfoList_r12.list.array[i]);
               }
               //generate RRC Reconfiguration
               rrc_eNB_generate_RRCConnectionReconfiguration_Sidelink(ctxt_pP, ue_context_pP, destinationInfoList, 0);
               return 0;
            }
         }

         //express its interest to transmit relay related one-to-many SL communication
         if ((sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension != NULL) && (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13 != NULL)) {
            if (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelay_r13->destinationInfoList_r12.list.count > 0){
               n_destinations = sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelay_r13->destinationInfoList_r12.list.count;
               destinationInfoList = CALLOC(1, sizeof(SL_DestinationInfoList_r12_t));
               for (int i=0; i< n_destinations; i++ ){
                  //sl_DestinationIdentityList[i] = *(sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelay_r13->destinationInfoList_r12.list.array[i]);
                  ASN_SEQUENCE_ADD(&destinationInfoList->list,sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelay_r13->destinationInfoList_r12.list.array[i]);
               }
               //generate RRC Reconfiguration
               rrc_eNB_generate_RRCConnectionReconfiguration_Sidelink(ctxt_pP, ue_context_pP, destinationInfoList, 0);
               return 0;
            }
         }

         //For SL Discovery
         //express its interest to receive SL discovery announcements
         //express its interest to transmit non-PS related discovery announcements
         if (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.discTxResourceReq_r12 != NULL){
            n_discoveryMessages = *(sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.discTxResourceReq_r12);
            //generate RRC Reconfiguration
            rrc_eNB_generate_RRCConnectionReconfiguration_Sidelink(ctxt_pP, ue_context_pP, NULL, n_discoveryMessages);
            return 0;
         }
         //express its interest to transmit PS related discovery announcements
         if ((sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension != NULL) && (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->discTxResourceReqPS_r13 !=NULL)) {
            if (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->discTxResourceReqPS_r13->discTxResourceReq_r13 > 0){
               n_discoveryMessages = sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->discTxResourceReqPS_r13->discTxResourceReq_r13;
               //generate RRC Reconfiguration
               rrc_eNB_generate_RRCConnectionReconfiguration_Sidelink(ctxt_pP, ue_context_pP, NULL, n_discoveryMessages);
               return 0;
            }
         }
      }
   }
   return 0;
}

//-----------------------------------------------------------------------------
int
rrc_eNB_generate_RRCConnectionReconfiguration_Sidelink(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t* const ue_context_pP,
  SL_DestinationInfoList_r12_t  *destinationInfoList,
  int n_discoveryMessages
)
//-----------------------------------------------------------------------------
{

  uint8_t                             buffer[RRC_BUF_SIZE];
7929
  uint16_t                            size = -1;
7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954
  memset(buffer, 0, RRC_BUF_SIZE);

  // allocate dedicated pools for UE -sl-CommConfig/sl-DiscConfig (sl-V2X-ConfigDedicated)
  //populate dedicated resources for SL communication (sl-CommConfig)
  if ((destinationInfoList != NULL) && (destinationInfoList->list.count > 0)) {

     LOG_I(RRC,"[eNB %d] Frame %d, Generate RRCConnectionReconfiguration_Sidelink (bytes %d, UE id %x), number of destinations %d\n",
            ctxt_pP->module_id,ctxt_pP->frame, size, ue_context_pP->ue_context.rnti,destinationInfoList->list.count );
     //get dedicated resources from available pool and assign to the UE
     SL_CommConfig_r12_t  sl_CommConfig[destinationInfoList->list.count];
     //get a RP from the available RPs
     sl_CommConfig[0] = rrc_eNB_get_sidelink_commTXPool(ctxt_pP, ue_context_pP, destinationInfoList);

     size = do_RRCConnectionReconfiguration(ctxt_pP,
                   buffer,
                   rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),   //Transaction_id
                   (SRB_ToAddModList_t*)NULL,
                   (DRB_ToAddModList_t*)NULL,
                   (DRB_ToReleaseList_t*)NULL,  // DRB2_list,
                   (struct SPS_Config*)NULL,    // *sps_Config,
                   NULL, NULL, NULL, NULL,NULL,
                   NULL, NULL,  NULL, NULL, NULL, NULL,
                   (struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList*)NULL,
                   (SL_CommConfig_r12_t*)&sl_CommConfig,
                   (SL_DiscConfig_r12_t*)NULL
7955
  #if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977
                                           , (SCellToAddMod_r10_t*)NULL
  #endif
                                           );
     //
  }
  //populate dedicated resources for SL discovery (sl-DiscConfig)
  if (n_discoveryMessages > 0) {
     SL_DiscConfig_r12_t sl_DiscConfig[n_discoveryMessages];
     //get a RP from the available RPs
     sl_DiscConfig[0] = rrc_eNB_get_sidelink_discTXPool(ctxt_pP, ue_context_pP, n_discoveryMessages );
     size = do_RRCConnectionReconfiguration(ctxt_pP,
                   buffer,
                   rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),   //Transaction_id
                   (SRB_ToAddModList_t*)NULL,
                   (DRB_ToAddModList_t*)NULL,
                   (DRB_ToReleaseList_t*)NULL,  // DRB2_list,
                   (struct SPS_Config*)NULL,    // *sps_Config,
                   NULL, NULL, NULL, NULL,NULL,
                   NULL, NULL,  NULL, NULL, NULL, NULL,
                   (struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList*)NULL,
                   (SL_CommConfig_r12_t*)NULL,
                   (SL_DiscConfig_r12_t*)&sl_DiscConfig
7978
  #if (RRC_VERSION >= MAKE_VERSION(10, 0, 0))
7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 8020 8021 8022 8023 8024 8025 8026 8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039 8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 8056 8057 8058 8059 8060 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083
                                           , (SCellToAddMod_r10_t*)NULL
  #endif
                                           );
  }

  LOG_I(RRC,"[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate RRCConnectionReconfiguration_Sidelink (bytes %d, UE id %x)\n",
        ctxt_pP->module_id,ctxt_pP->frame, size, ue_context_pP->ue_context.rnti);

  rrc_data_req(
    ctxt_pP,
    DCCH,
    rrc_eNB_mui++,
    SDU_CONFIRM_NO,
    size,
    buffer,
    PDCP_TRANSMISSION_MODE_CONTROL);

  // rrc_data_req();

  return size;
}

SL_CommConfig_r12_t rrc_eNB_get_sidelink_commTXPool( const protocol_ctxt_t* const ctxt_pP, rrc_eNB_ue_context_t* const ue_context_pP,  SL_DestinationInfoList_r12_t  *destinationInfoList ){
   // for the moment, use scheduled resource allocation
   SL_CommConfig_r12_t  *sl_CommConfig;
   SL_CommResourcePool_r12_t    *sc_CommTxConfig;

   sl_CommConfig = CALLOC(1, sizeof(struct SL_CommConfig_r12));
   sl_CommConfig->commTxResources_r12 = CALLOC(1, sizeof(*sl_CommConfig->commTxResources_r12));
   sl_CommConfig->commTxResources_r12->present = SL_CommConfig_r12__commTxResources_r12_PR_setup;

   sl_CommConfig->commTxResources_r12->choice.setup.present = SL_CommConfig_r12__commTxResources_r12__setup_PR_scheduled_r12;
   sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.sl_RNTI_r12.size = 2;
   sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.sl_RNTI_r12.buf = CALLOC(1,2);
   sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.sl_RNTI_r12.buf[0] = 0x00;
   sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.sl_RNTI_r12.buf[1] = 0x01;//ctxt_pP->rnti;//rnti
   sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.sl_RNTI_r12.bits_unused = 0;
   sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.mcs_r12 = CALLOC(1,sizeof(*sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.mcs_r12));
   //*sl_CommConfig_test->commTxResources_r12->choice.setup.choice.scheduled_r12.mcs_r12 = 12; //Msc
   sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.mac_MainConfig_r12.retx_BSR_TimerSL = RetxBSR_Timer_r12_sf320; //MacConfig, for testing only
   //sl_CommConfig_test->commTxResources_r12->choice.setup.choice.scheduled_r12.sc_CommTxConfig_r12;

   sc_CommTxConfig = & sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.sc_CommTxConfig_r12;

   sc_CommTxConfig->sc_CP_Len_r12 = SL_CP_Len_r12_normal;
   sc_CommTxConfig->sc_Period_r12 = SL_PeriodComm_r12_sf40;
   sc_CommTxConfig->data_CP_Len_r12  = SL_CP_Len_r12_normal;
   //sc_TF_ResourceConfig_r12
   sc_CommTxConfig->sc_TF_ResourceConfig_r12.prb_Num_r12 = 20;
   sc_CommTxConfig->sc_TF_ResourceConfig_r12.prb_Start_r12 = 5;
   sc_CommTxConfig->sc_TF_ResourceConfig_r12.prb_End_r12 = 44;
   sc_CommTxConfig->sc_TF_ResourceConfig_r12.offsetIndicator_r12.present = SL_OffsetIndicator_r12_PR_small_r12;
   sc_CommTxConfig->sc_TF_ResourceConfig_r12.offsetIndicator_r12.choice.small_r12 = 0;

   sc_CommTxConfig->sc_TF_ResourceConfig_r12.subframeBitmap_r12.present = SubframeBitmapSL_r12_PR_bs40_r12;
   sc_CommTxConfig->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.size = 5;
   sc_CommTxConfig->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.buf  = CALLOC(1,5);
   sc_CommTxConfig->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.bits_unused = 0;
   //dataHoppingConfig_r12
   sc_CommTxConfig->dataHoppingConfig_r12.hoppingParameter_r12 = 0;
   sc_CommTxConfig->dataHoppingConfig_r12.numSubbands_r12  =  SL_HoppingConfigComm_r12__numSubbands_r12_ns1;
   sc_CommTxConfig->dataHoppingConfig_r12.rb_Offset_r12 = 0;
   //ue_SelectedResourceConfig_r12
   sc_CommTxConfig->ue_SelectedResourceConfig_r12 = CALLOC (1, sizeof (*sc_CommTxConfig->ue_SelectedResourceConfig_r12));
   sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.prb_Num_r12 = 20;
   sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.prb_Start_r12 = 5;
   sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.prb_End_r12 = 44;
   sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.offsetIndicator_r12.present = SL_OffsetIndicator_r12_PR_small_r12;
   sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.offsetIndicator_r12.choice.small_r12 = 0 ;
   sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.present = SubframeBitmapSL_r12_PR_bs40_r12;
   sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.size = 5;
   sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf  = CALLOC(1,5);
   sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.bits_unused = 0;
   sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf[0] = 0xF0;
   sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf[1] = 0xFF;
   sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf[2] = 0xFF;
   sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf[3] = 0xFF;
   sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf[4] = 0xFF;
   //rxParametersNCell_r12
   sc_CommTxConfig->rxParametersNCell_r12 = CALLOC (1, sizeof (*sc_CommTxConfig->rxParametersNCell_r12));
   sc_CommTxConfig->rxParametersNCell_r12->tdd_Config_r12 = CALLOC (1, sizeof (*sc_CommTxConfig->rxParametersNCell_r12->tdd_Config_r12 ));
   sc_CommTxConfig->rxParametersNCell_r12->tdd_Config_r12->subframeAssignment = 0 ;
   sc_CommTxConfig->rxParametersNCell_r12->tdd_Config_r12->specialSubframePatterns = 0;
   sc_CommTxConfig->rxParametersNCell_r12->syncConfigIndex_r12 = 0;
   //txParameters_r12
   sc_CommTxConfig->txParameters_r12 = CALLOC (1, sizeof (*sc_CommTxConfig->txParameters_r12));
   sc_CommTxConfig->txParameters_r12->sc_TxParameters_r12.alpha_r12 = Alpha_r12_al0;
   sc_CommTxConfig->txParameters_r12->sc_TxParameters_r12.p0_r12 = 0;
   sc_CommTxConfig->ext1 = NULL ;

   return *sl_CommConfig;
}


SL_DiscConfig_r12_t rrc_eNB_get_sidelink_discTXPool( const protocol_ctxt_t* const ctxt_pP, rrc_eNB_ue_context_t* const ue_context_pP,  int n_discoveryMessages ){
   //TODO
   SL_DiscConfig_r12_t  sl_DiscConfig;
   sl_DiscConfig.discTxResources_r12 = CALLOC(1,sizeof(*sl_DiscConfig.discTxResources_r12));
   sl_DiscConfig.discTxResources_r12->present = SL_DiscConfig_r12__discTxResources_r12_PR_setup;
   sl_DiscConfig.discTxResources_r12->choice.setup.present = SL_DiscConfig_r12__discTxResources_r12__setup_PR_scheduled_r12;
   //sl_DiscConfig.discTxResources_r12->choice.setup.choice.scheduled_r12.discHoppingConfig_r12;
   //sl_DiscConfig.discTxResources_r12->choice.setup.choice.scheduled_r12.discTF_IndexList_r12;
   //sl_DiscConfig.discTxResources_r12->choice.setup.choice.scheduled_r12.discTxConfig_r12;
   return sl_DiscConfig;
}
8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 8094 8095 8096 8097 8098 8099 8100 8101 8102 8103 8104 8105 8106
RRC_status_t
rrc_rx_tx(
  protocol_ctxt_t* const ctxt_pP,
  const int          CC_id
)
//-----------------------------------------------------------------------------
{
  //uint8_t        UE_id;
  int32_t        current_timestamp_ms, ref_timestamp_ms;
  struct timeval ts;
  struct rrc_eNB_ue_context_s   *ue_context_p = NULL,*ue_to_be_removed = NULL;

#ifdef LOCALIZATION
  double                         estimated_distance;
  protocol_ctxt_t                ctxt;
#endif
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_RX_TX,VCD_FUNCTION_IN);

    check_handovers(ctxt_pP);
    // counetr, and get the value and aggregate

    // check for UL failure
    RB_FOREACH(ue_context_p, rrc_ue_tree_s, &(RC.rrc[ctxt_pP->module_id]->rrc_ue_head)) {
8107
      ctxt_pP->rnti = ue_context_p->ue_id_rnti;
8108 8109
      if ((ctxt_pP->frame == 0) && (ctxt_pP->subframe==0)) {
	if (ue_context_p->ue_context.Initialue_identity_s_TMSI.presence == TRUE) {
8110
	  LOG_I(RRC,"UE rnti %x:S-TMSI %x failure timer %d/8\n",
8111 8112 8113 8114 8115
		ue_context_p->ue_context.rnti,
		ue_context_p->ue_context.Initialue_identity_s_TMSI.m_tmsi,
		ue_context_p->ue_context.ul_failure_timer);
	}
	else {
8116
	  LOG_I(RRC,"UE rnti %x failure timer %d/8\n",
8117 8118 8119 8120 8121 8122
		ue_context_p->ue_context.rnti,
		ue_context_p->ue_context.ul_failure_timer);
	}
      }
      if (ue_context_p->ue_context.ul_failure_timer>0) {
	ue_context_p->ue_context.ul_failure_timer++;
8123
	if (ue_context_p->ue_context.ul_failure_timer >= 20000) {
8124 8125 8126 8127 8128 8129
	  // remove UE after 20 seconds after MAC has indicated UL failure
	  LOG_I(RRC,"Removing UE %x instance\n",ue_context_p->ue_context.rnti);
	  ue_to_be_removed = ue_context_p;
	  break;
	}
      }
8130 8131 8132 8133 8134 8135
      if (ue_context_p->ue_context.ue_release_timer_s1>0) {
        ue_context_p->ue_context.ue_release_timer_s1++;
        if (ue_context_p->ue_context.ue_release_timer_s1 >=
            ue_context_p->ue_context.ue_release_timer_thres_s1) {
          LOG_I(RRC,"Removing UE %x instance Because of UE_CONTEXT_RELEASE_COMMAND not received after %d ms from sending request\n",
                         ue_context_p->ue_context.rnti, ue_context_p->ue_context.ue_release_timer_thres_s1);
8136 8137 8138
//          ue_context_p->ue_context.ue_release_timer_s1 = 0;
#if defined(ENABLE_USE_MME)
#if defined(ENABLE_ITTI)
Raymond Knopp's avatar
Raymond Knopp committed
8139 8140
          if (RC.rrc[ctxt_pP->module_id]->node_type != ngran_eNB_DU)
            rrc_eNB_generate_RRCConnectionRelease(ctxt_pP, ue_context_p);
8141 8142
#endif
#else
8143
          ue_to_be_removed = ue_context_p;
8144 8145
#endif
          ue_context_p->ue_context.ue_release_timer_s1 = 0;
8146 8147 8148 8149 8150 8151 8152 8153 8154
          break;
        }
      }

      if (ue_context_p->ue_context.ue_release_timer_rrc>0) {
        ue_context_p->ue_context.ue_release_timer_rrc++;
        if (ue_context_p->ue_context.ue_release_timer_rrc >=
          ue_context_p->ue_context.ue_release_timer_thres_rrc) {
          LOG_I(RRC,"Removing UE %x instance After UE_CONTEXT_RELEASE_Complete\n", ue_context_p->ue_context.rnti);
8155
          ue_context_p->ue_context.ue_release_timer_rrc = 0;
8156
          ue_to_be_removed = ue_context_p;
8157
          ue_context_p->ue_context.ue_release_timer_rrc = 0;
8158 8159 8160
          break;
        }
      }
8161 8162 8163 8164 8165 8166 8167 8168 8169 8170 8171 8172 8173
       pthread_mutex_lock(&rrc_release_freelist);
      if(rrc_release_info.num_UEs > 0){
        uint16_t release_total = 0;
        for(uint16_t release_num = 0;release_num < NUMBER_OF_UE_MAX;release_num++){
          if(rrc_release_info.RRC_release_ctrl[release_num].flag > 0){
            release_total++;
          }
          if( (rrc_release_info.RRC_release_ctrl[release_num].flag > 2) &&
            (rrc_release_info.RRC_release_ctrl[release_num].rnti == ue_context_p->ue_context.rnti)){
           ue_context_p->ue_context.ue_release_timer_rrc = 1;
           ue_context_p->ue_context.ue_release_timer_thres_rrc = 100;
#if defined(ENABLE_USE_MME)
#if defined(ENABLE_ITTI)
Raymond Knopp's avatar
Raymond Knopp committed
8174 8175 8176 8177 8178 8179 8180 8181 8182 8183 8184 8185 8186 8187 8188 8189 8190 8191 8192
           if (RC.rrc[ctxt_pP->module_id]->node_type != ngran_eNB_DU) {
              int      e_rab;
              MessageDef *msg_complete_p = NULL;
              MessageDef *msg_delete_tunnels_p = NULL;
              uint32_t eNB_ue_s1ap_id = ue_context_p->ue_context.eNB_ue_s1ap_id;
              if(rrc_release_info.RRC_release_ctrl[release_num].flag == 4){
                MSC_LOG_TX_MESSAGE(
                       MSC_RRC_ENB,
                       MSC_S1AP_ENB,
                       NULL,0,
                       "0 S1AP_UE_CONTEXT_RELEASE_COMPLETE eNB_ue_s1ap_id 0x%06"PRIX32" ",
                       eNB_ue_s1ap_id);
                msg_complete_p = itti_alloc_new_message(TASK_RRC_ENB, S1AP_UE_CONTEXT_RELEASE_COMPLETE);
                S1AP_UE_CONTEXT_RELEASE_COMPLETE(msg_complete_p).eNB_ue_s1ap_id = eNB_ue_s1ap_id;
                itti_send_msg_to_task(TASK_S1AP, ctxt_pP->module_id, msg_complete_p);
              }
              MSC_LOG_TX_MESSAGE(MSC_RRC_ENB, MSC_GTPU_ENB, NULL,0, "0 GTPV1U_ENB_DELETE_TUNNEL_REQ rnti %x ", eNB_ue_s1ap_id);
              msg_delete_tunnels_p = itti_alloc_new_message(TASK_RRC_ENB, GTPV1U_ENB_DELETE_TUNNEL_REQ);
              memset(&GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p), 0, sizeof(GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p)));
8193
           // do not wait response
Raymond Knopp's avatar
Raymond Knopp committed
8194 8195 8196 8197 8198 8199 8200 8201 8202 8203 8204 8205 8206 8207 8208 8209 8210 8211 8212 8213
              GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p).rnti = ue_context_p->ue_context.rnti;
              for (e_rab = 0; e_rab < ue_context_p->ue_context.nb_of_e_rabs; e_rab++) {
                GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p).eps_bearer_id[GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p).num_erab++] =
                  ue_context_p->ue_context.enb_gtp_ebi[e_rab];
                // erase data
                ue_context_p->ue_context.enb_gtp_teid[e_rab] = 0;
                memset(&ue_context_p->ue_context.enb_gtp_addrs[e_rab], 0, sizeof(ue_context_p->ue_context.enb_gtp_addrs[e_rab]));
                ue_context_p->ue_context.enb_gtp_ebi[e_rab]  = 0;
              }
              itti_send_msg_to_task(TASK_GTPV1_U, ctxt_pP->module_id, msg_delete_tunnels_p);
              struct rrc_ue_s1ap_ids_s    *rrc_ue_s1ap_ids = NULL;
              rrc_ue_s1ap_ids = rrc_eNB_S1AP_get_ue_ids(
                     RC.rrc[ctxt_pP->module_id],
                     0,
                     eNB_ue_s1ap_id);
              if (NULL != rrc_ue_s1ap_ids) {
                rrc_eNB_S1AP_remove_ue_ids(
                           RC.rrc[ctxt_pP->module_id],
                           rrc_ue_s1ap_ids);
              }
8214 8215 8216 8217 8218 8219 8220 8221 8222 8223 8224 8225
           }
#endif
#endif
           rrc_release_info.RRC_release_ctrl[release_num].flag = 0;
           rrc_release_info.num_UEs--;
           break;
         }
         if(release_total >= rrc_release_info.num_UEs)
           break;
         }
       }
       pthread_mutex_unlock(&rrc_release_freelist);
8226 8227 8228 8229 8230 8231 8232 8233 8234 8235 8236 8237

      if (ue_context_p->ue_context.ue_reestablishment_timer>0) {
        ue_context_p->ue_context.ue_reestablishment_timer++;
        if (ue_context_p->ue_context.ue_reestablishment_timer >=
            ue_context_p->ue_context.ue_reestablishment_timer_thres) {
          LOG_I(RRC,"UE %d reestablishment_timer max\n",ue_context_p->ue_context.rnti);
          ue_context_p->ue_context.ul_failure_timer = 20000;
          ue_to_be_removed = ue_context_p;
          ue_context_p->ue_context.ue_reestablishment_timer = 0;
          break;
        }
      }
8238

8239 8240 8241 8242
      if (ue_context_p->ue_context.ue_release_timer>0) {
	ue_context_p->ue_context.ue_release_timer++;
	if (ue_context_p->ue_context.ue_release_timer >= 
	    ue_context_p->ue_context.ue_release_timer_thres) {
8243
          LOG_I(RRC,"Removing UE %x instance\n",ue_context_p->ue_context.rnti);
8244
	  ue_to_be_removed = ue_context_p;
8245
          ue_context_p->ue_context.ue_release_timer = 0;
8246 8247 8248 8249
	  break;
	}
      }
    }
8250
    if (ue_to_be_removed) {
8251
      if(ue_to_be_removed->ue_context.ul_failure_timer >= 20000) {
8252 8253 8254 8255 8256
          ue_to_be_removed->ue_context.ue_release_timer_s1 = 1;
          ue_to_be_removed->ue_context.ue_release_timer_thres_s1 = 100;
          ue_to_be_removed->ue_context.ue_release_timer = 0;
          ue_to_be_removed->ue_context.ue_reestablishment_timer = 0;
      }
8257
      rrc_eNB_free_UE(ctxt_pP->module_id,ue_to_be_removed);
8258
      if(ue_to_be_removed->ue_context.ul_failure_timer >= 20000){
8259 8260 8261
        ue_to_be_removed->ue_context.ul_failure_timer = 0;
      }
    }
8262 8263 8264 8265 8266 8267 8268 8269 8270 8271 8272 8273 8274 8275 8276 8277 8278 8279 8280 8281 8282 8283 8284 8285 8286 8287 8288 8289 8290 8291 8292 8293 8294 8295 8296 8297 8298 8299 8300

#ifdef RRC_LOCALIZATION

    /* for the localization, only primary CC_id might be relevant*/
    gettimeofday(&ts, NULL);
    current_timestamp_ms = ts.tv_sec * 1000 + ts.tv_usec / 1000;
    ref_timestamp_ms = RC.rrc[ctxt_pP->module_id]->reference_timestamp_ms;
    RB_FOREACH(ue_context_p, rrc_ue_tree_s, &(RC.rrc[ctxt_pP->module_id]->rrc_ue_head)) {
      ctxt = *ctxt_pP;
      ctxt.rnti = ue_context_p->ue_context.rnti;
      estimated_distance = rrc_get_estimated_ue_distance(
                             &ctxt,
                             CC_id,
                             RC.rrc[ctxt_pP->module_id]->loc_type);

      if ((current_timestamp_ms - ref_timestamp_ms > RC.rrc[ctxt_pP->module_id]->aggregation_period_ms) &&
          estimated_distance != -1) {
        LOG_D(LOCALIZE, " RRC [UE/id %d -> eNB/id %d] timestamp %d frame %d estimated r = %f\n",
              ctxt.rnti,
              ctxt_pP->module_id,
              current_timestamp_ms,
              ctxt_pP->frame,
              estimated_distance);
        LOG_D(LOCALIZE, " RRC status %d\n", ue_context_p->ue_context.Status);
        push_front(&RC.rrc[ctxt_pP->module_id]->loc_list,
                   estimated_distance);
        RC.rrc[ctxt_pP->module_id]->reference_timestamp_ms = current_timestamp_ms;
      }
    }

#endif
    (void)ts; /* remove gcc warning "unused variable" */
    (void)ref_timestamp_ms; /* remove gcc warning "unused variable" */
    (void)current_timestamp_ms; /* remove gcc warning "unused variable" */

  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_RX_TX,VCD_FUNCTION_OUT);
  return (RRC_OK);
}