rrc_eNB.c 306 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 "defs.h"
#include "extern.h"
35
#include "assertions.h"
36
#include "common/ran_context.h"
37
#include "asn1_conversions.h"
38 39
#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"
#include "LAYER2/RLC/rlc.h"
40
#include "LAYER2/MAC/proto.h"
41 42 43 44
#include "UTIL/LOG/log.h"
#include "COMMON/mac_rrc_primitives.h"
#include "RRC/LITE/MESSAGES/asn1_msg.h"
#include "RRCConnectionRequest.h"
45 46
#include "RRCConnectionReestablishmentRequest.h"
//#include "ReestablishmentCause.h"
47
#include "BCCH-BCH-Message.h"
48 49 50 51 52
#include "UL-CCCH-Message.h"
#include "DL-CCCH-Message.h"
#include "UL-DCCH-Message.h"
#include "DL-DCCH-Message.h"
#include "TDD-Config.h"
53
#include "HandoverCommand.h"
54 55
#include "rlc.h"
#include "SIMULATION/ETH_TRANSPORT/extern.h"
56 57 58
#include "rrc_eNB_UE_context.h"
#include "platform_types.h"
#include "msc.h"
59

60 61
#include "T.h"

Cedric Roux's avatar
Cedric Roux committed
62
//#if defined(Rel10) || defined(Rel14)
63
#include "MeasResults.h"
64 65 66
//#endif

#ifdef USER_MODE
Lionel Gauthier's avatar
 
Lionel Gauthier committed
67 68 69 70
#   include "RRC/NAS/nas_config.h"
#   include "RRC/NAS/rb_config.h"
#   include "OCG.h"
#   include "OCG_extern.h"
71 72
#endif

73
#if defined(ENABLE_SECURITY)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
74
#   include "UTIL/OSA/osa_defs.h"
75 76
#endif

77
#if defined(ENABLE_USE_MME)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
78
#   include "rrc_eNB_S1AP.h"
79
#   include "rrc_eNB_GTPV1U.h"
Lionel Gauthier's avatar
 
Lionel Gauthier committed
80 81 82 83
#   if defined(ENABLE_ITTI)
#   else
#      include "../../S1AP/s1ap_eNB.h"
#   endif
84 85
#endif

86
#include "pdcp.h"
87
#include "gtpv1u_eNB_task.h"
88 89

#if defined(ENABLE_ITTI)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
90
#   include "intertask_interface.h"
91 92
#endif

93
#if ENABLE_RAL
Lionel Gauthier's avatar
 
Lionel Gauthier committed
94
#   include "rrc_eNB_ral.h"
Lionel Gauthier's avatar
Lionel Gauthier committed
95 96
#endif

97 98
#include "SIMULATION/TOOLS/defs.h" // for taus

99
#if defined(FLEXRAN_AGENT_SB_IF)
100
#include "flexran_agent_extern.h"
101
#endif
102
//#define XER_PRINT
103

104 105
extern RAN_CONTEXT_t RC;

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

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

Lionel Gauthier's avatar
 
Lionel Gauthier committed
117
mui_t                               rrc_eNB_mui = 0;
winckel's avatar
RRC:  
winckel committed
118

119 120 121
//-----------------------------------------------------------------------------
static void
init_SI(
122 123
  const protocol_ctxt_t* const ctxt_pP,
  const int              CC_id
winckel's avatar
winckel committed
124
#if defined(ENABLE_ITTI)
125 126
  ,
  RrcConfigurationReq * configuration
winckel's avatar
winckel committed
127
#endif
128
)
129
//-----------------------------------------------------------------------------
130
{
Cedric Roux's avatar
Cedric Roux committed
131
#if defined(Rel10) || defined(Rel14)
132 133
  int                                 i;
#endif
134 135 136 137 138

#ifdef Rel14
  SystemInformationBlockType1_v1310_IEs_t *sib1_v13ext=(SystemInformationBlockType1_v1310_IEs_t *)NULL;
#endif

139
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].MIB = (uint8_t*) malloc16(4);
140 141 142 143 144 145
  // copy basic parameters
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].physCellId      = configuration->Nid_cell[CC_id];
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].p_eNB           = configuration->nb_antenna_ports[CC_id];
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Ncp             = configuration->prefix_type[CC_id];
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].dl_CarrierFreq  = configuration->downlink_frequency[CC_id];
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].ul_CarrierFreq  = configuration->downlink_frequency[CC_id]+ configuration->uplink_frequency_offset[CC_id];
146 147 148
#ifdef Rel14
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].pbch_repetition = configuration->pbch_repetition[CC_id];
#endif
149
  LOG_I(RRC, "Configuring MIB (N_RB_DL %d,phich_Resource %d,phich_Duration %d)\n", 
Raymond Knopp's avatar
Raymond Knopp committed
150 151 152
	(int)configuration->N_RB_DL[CC_id],
	(int)configuration->phich_resource[CC_id],
	(int)configuration->phich_duration[CC_id]);
153 154 155 156 157 158 159 160 161 162 163 164 165 166
  do_MIB(&RC.rrc[ctxt_pP->module_id]->carrier[CC_id],
#ifdef ENABLE_ITTI
	 configuration->N_RB_DL[CC_id],
	 configuration->phich_resource[CC_id],
	 configuration->phich_duration[CC_id]
#else
	 50,0,0
#endif
	 ,0);
  

  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB1 = 0;
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB23 = 0;
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SIB1 = (uint8_t*) malloc16(32);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
167

168 169 170
  AssertFatal(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SIB1!=NULL,PROTOCOL_RRC_CTXT_FMT" init_SI: FATAL, no memory for SIB1 allocated\n",
	      PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB1 = do_SIB1(&RC.rrc[ctxt_pP->module_id]->carrier[CC_id],ctxt_pP->module_id,CC_id
winckel's avatar
winckel committed
171
#if defined(ENABLE_ITTI)
172
								   , configuration
winckel's avatar
winckel committed
173
#endif
174
								   );
175

176
  AssertFatal(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB1 != 255,"FATAL, RC.rrc[enb_mod_idP].carrier[CC_id].sizeof_SIB1 == 255");
177

178
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SIB23 = (uint8_t*) malloc16(64);
179 180 181 182 183
  AssertFatal(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SIB23!=NULL,"cannot allocate memory for SIB");
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB23 = do_SIB23(
								     ctxt_pP->module_id,
								     
								     CC_id
184
#if defined(ENABLE_ITTI)
185
								     , configuration
Lionel Gauthier's avatar
 
Lionel Gauthier committed
186
#endif
187
								     );
188

189 190
  AssertFatal(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB23 != 255,"FATAL, RC.rrc[mod].carrier[CC_id].sizeof_SIB23 == 255");
  
191

192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
  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),
	RC.rrc[ctxt_pP->module_id]->carrier[CC_id].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),
	RC.rrc[ctxt_pP->module_id]->carrier[CC_id].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),
	RC.rrc[ctxt_pP->module_id]->carrier[CC_id].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)RC.rrc[ctxt_pP->module_id]->carrier[CC_id].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)RC.rrc[ctxt_pP->module_id]->carrier[CC_id].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),
	RC.rrc[ctxt_pP->module_id]->carrier[CC_id].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)RC.rrc[ctxt_pP->module_id]->carrier[CC_id].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),
	RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
	ul_ReferenceSignalsPUSCH.cyclicShift);
  
Cedric Roux's avatar
Cedric Roux committed
227
#if defined(Rel10) || defined(Rel14)
228

229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
  if (RC.rrc[ctxt_pP->module_id]->carrier[CC_id].MBMS_flag > 0) {
    for (i = 0; i < RC.rrc[ctxt_pP->module_id]->carrier[CC_id].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,
	    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->mbsfn_SubframeConfigList->list.count);
      LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" mbsfn_Subframe_pattern is  = %x\n",
	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
	    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].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),
	    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].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),
	    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->mbsfn_SubframeConfigList->list.array[i]->radioframeAllocationOffset);
246
    }
247 248 249 250 251 252 253 254 255 256 257 258 259 260
    
    //   SIB13
    for (i = 0; i < RC.rrc[ctxt_pP->module_id]->carrier[CC_id].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,
	    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].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),
	    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].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),
	    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib13->mbsfn_AreaInfoList_r9.list.array[i]->mcch_Config_r9.mcch_Offset_r9);
    }
261 262
  }
  else memset((void*)&RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib13,0,sizeof(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib13));
263 264
#endif

265 266 267
  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));
268 269 270 271 272

#ifdef Rel14
  if ((RC.rrc[ctxt_pP->module_id]->carrier[CC_id].mib.message.schedulingInfoSIB1_BR_r13>0) && 
      (RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1_BR!=NULL)) {
      AssertFatal(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1_BR->nonCriticalExtension!=NULL,
Raymond Knopp's avatar
Raymond Knopp committed
273
		  "sib2_br->nonCriticalExtension is null (v8.9)\n");
274
      AssertFatal(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1_BR->nonCriticalExtension->nonCriticalExtension!=NULL,
Raymond Knopp's avatar
Raymond Knopp committed
275
		  "sib2_br->nonCriticalExtension is null (v9.2)\n");
276
      AssertFatal(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1_BR->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension!=NULL,
Raymond Knopp's avatar
Raymond Knopp committed
277
		  "sib2_br->nonCriticalExtension is null (v11.3)\n");
278
      AssertFatal(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1_BR->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension!=NULL,
Raymond Knopp's avatar
Raymond Knopp committed
279 280
		  "sib2_br->nonCriticalExtension is null (v12.5)\n");
      AssertFatal(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1_BR->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension!=NULL,
281
		  "sib2_br->nonCriticalExtension is null (v13.10)\n");
Raymond Knopp's avatar
Raymond Knopp committed
282
      sib1_v13ext = RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1_BR->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension;
283 284 285
  }
#endif

286 287 288 289 290 291 292 293 294
  rrc_mac_config_req_eNB(ctxt_pP->module_id, CC_id,
			 RC.rrc[ctxt_pP->module_id]->carrier[CC_id].physCellId,
			 RC.rrc[ctxt_pP->module_id]->carrier[CC_id].p_eNB,
			 RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Ncp,
			 RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1->freqBandIndicator,
			 RC.rrc[ctxt_pP->module_id]->carrier[CC_id].dl_CarrierFreq,
#ifdef Rel14
			 RC.rrc[ctxt_pP->module_id]->carrier[CC_id].pbch_repetition,
#endif
295
			 0, // rnti
296 297 298 299 300 301 302 303 304
			 (BCCH_BCH_Message_t *)
			 &RC.rrc[ctxt_pP->module_id]->carrier[CC_id].mib,
			 (RadioResourceConfigCommonSIB_t *) &
			 RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon,
#if defined(Rel14)
			 (RadioResourceConfigCommonSIB_t *) &
			 RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2_BR->radioResourceConfigCommon,
#endif
			 (struct PhysicalConfigDedicated *)NULL,
Cedric Roux's avatar
Cedric Roux committed
305
#if defined(Rel10) || defined(Rel14)
306 307 308 309 310 311 312 313 314
			 (SCellToAddMod_r10_t *)NULL,
			 //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
#endif
			 (MeasObjectToAddMod_t **) NULL,
			 (MAC_MainConfig_t *) NULL, 0,
			 (struct LogicalChannelConfig *)NULL,
			 (MeasGapConfig_t *) NULL,
			 RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1->tdd_Config,
			 NULL,
315
			 &RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1->schedulingInfoList,
316 317 318 319
			 RC.rrc[ctxt_pP->module_id]->carrier[CC_id].ul_CarrierFreq,
			 RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->freqInfo.ul_Bandwidth,
			 &RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->freqInfo.additionalSpectrumEmission,
			 (MBSFN_SubframeConfigList_t*) RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->mbsfn_SubframeConfigList
Cedric Roux's avatar
Cedric Roux committed
320
#if defined(Rel10) || defined(Rel14)
321 322 323 324
			 ,
			 RC.rrc[ctxt_pP->module_id]->carrier[CC_id].MBMS_flag,
			 (MBSFN_AreaInfoList_r9_t*) & RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib13->mbsfn_AreaInfoList_r9,
			 (PMCH_InfoList_r9_t *) NULL
325
#endif
326 327 328
#ifdef Rel14
			 , 
			 sib1_v13ext
329
#endif
330
			 );
331 332
}

Cedric Roux's avatar
Cedric Roux committed
333
#if defined(Rel10) || defined(Rel14)
winckel's avatar
winckel committed
334
/*------------------------------------------------------------------------------*/
335 336
static void
init_MCCH(
337 338
  module_id_t enb_mod_idP,
  int CC_id
339 340
)
//-----------------------------------------------------------------------------
341
{
Lionel Gauthier's avatar
 
Lionel Gauthier committed
342

343 344
  int                                 sync_area = 0;
  // initialize RRC_eNB_INST MCCH entry
345 346
  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
347

348
  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
349

350 351
    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);
352

353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
    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;
378
  }
379
  
Lionel Gauthier's avatar
 
Lionel Gauthier committed
380

381
  //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
382

383 384 385
  // ??Configure MCCH logical channel
  // call mac_config_req with appropriate structure from ASN.1 description

386

387 388 389
  //  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]);
  rrc_mac_config_req_eNB(enb_mod_idP, CC_id,
390 391 392 393
			 0,0,0,0,0,
#ifdef Rel14 
			 0,
#endif
394
			 0,//rnti
395 396
			 (BCCH_BCH_Message_t *)NULL,
			 (RadioResourceConfigCommonSIB_t *) NULL,
397 398
			 (RadioResourceConfigCommonSIB_t *) NULL,
			 (struct PhysicalConfigDedicated *)NULL,
Cedric Roux's avatar
Cedric Roux committed
399
#if defined(Rel10) || defined(Rel14)
400 401
			 (SCellToAddMod_r10_t *)NULL,
			 //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
402
#endif
403 404 405 406 407 408
			 (MeasObjectToAddMod_t **) NULL,
			 (MAC_MainConfig_t *) NULL,
			 0,
			 (struct LogicalChannelConfig *)NULL,
			 (MeasGapConfig_t *) NULL,
			 (TDD_Config_t *) NULL,
409 410 411
			 (MobilityControlInfo_t *)NULL, 
			 (SchedulingInfoList_t *) NULL, 
			 0, NULL, NULL, (MBSFN_SubframeConfigList_t *) NULL
412
#if defined(Rel10) || defined(Rel14)
413 414 415 416
			 ,
			 0,
			 (MBSFN_AreaInfoList_r9_t *) NULL,
			 (PMCH_InfoList_r9_t *) & (RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->pmch_InfoList_r9)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
417
#   endif
418 419 420
#   ifdef Rel14
			 ,
			 (SystemInformationBlockType1_v1310_IEs_t *)NULL
Lionel Gauthier's avatar
 
Lionel Gauthier committed
421
#   endif
422 423 424
			 );
  
  //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);
425

426 427
}

428
//-----------------------------------------------------------------------------
Lionel Gauthier's avatar
 
Lionel Gauthier committed
429
static void init_MBMS(
430
  module_id_t enb_mod_idP,
431
  int         CC_id,
432 433 434
  frame_t frameP
)
//-----------------------------------------------------------------------------
435 436 437
{
  // init the configuration for MTCH
  protocol_ctxt_t               ctxt;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
438

439
  if (RC.rrc[enb_mod_idP]->carrier[CC_id].MBMS_flag > 0) {
440
    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
441

442 443
    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
444

445 446 447 448 449 450 451 452
    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
Cedric Roux's avatar
Cedric Roux committed
453
#   if defined(Rel10) || defined(Rel14)
454
                             , &(RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->pmch_InfoList_r9)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
455
#   endif
456
                             ,NULL);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
457

458 459 460 461
    rrc_rlc_config_asn1_req(&ctxt,
                            NULL, // SRB_ToAddModList
                            NULL,   // DRB_ToAddModList
                            NULL,   // DRB_ToReleaseList
462
                            &(RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->pmch_InfoList_r9));
Lionel Gauthier's avatar
 
Lionel Gauthier committed
463

464 465
    //rrc_mac_config_req();
  }
466 467 468
}
#endif

469 470 471 472 473 474
//-----------------------------------------------------------------------------
uint8_t
rrc_eNB_get_next_transaction_identifier(
  module_id_t enb_mod_idP
)
//-----------------------------------------------------------------------------
475
{
476 477
  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;
478
  LOG_T(RRC,"generated xid is %d\n",rrc_transaction_identifier[enb_mod_idP]);
479 480 481 482 483
  return rrc_transaction_identifier[enb_mod_idP];
}
/*------------------------------------------------------------------------------*/
/* Functions to handle UE index in eNB UE list */

winckel's avatar
winckel committed
484

485 486 487 488 489 490 491 492 493 494 495 496 497 498 499
////-----------------------------------------------------------------------------
//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);
//
//    for (i = 0; i < NUMBER_OF_UE_MAX; i++) {
500
//        if (RC.rrc[enb_mod_idP]->Info.UE_list[i] == UE_identity) {
501 502 503 504 505 506 507 508 509 510 511 512 513
//            // UE_identity already registered
//            reg = TRUE;
//            break;
//        }
//    }
//
//    if (reg == FALSE) {
//        return (UE_MODULE_INVALID);
//    } else
//        return (i);
//}


514
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
515 516
// return the ue context if there is already an UE with ue_identityP, NULL otherwise
static struct rrc_eNB_ue_context_s*
517 518 519 520 521 522 523
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;
524
  RB_FOREACH(ue_context_p, rrc_ue_tree_s, &(RC.rrc[ctxt_pP->module_id]->rrc_ue_head)) {
525
    if (ue_context_p->ue_context.random_ue_identity == ue_identityP)
gauthier's avatar
gauthier committed
526
      return ue_context_p;
527
  }
gauthier's avatar
gauthier committed
528 529 530 531 532 533 534 535 536 537 538 539 540
  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;
541
  RB_FOREACH(ue_context_p, rrc_ue_tree_s, &(RC.rrc[ctxt_pP->module_id]->rrc_ue_head)) {
kaltenbe's avatar
kaltenbe committed
542 543 544 545
    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) {
546
      printf("=> S-TMSI %x, MME %x\n",
kaltenbe's avatar
kaltenbe committed
547 548
	    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
549 550 551
      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
552 553 554 555
    }
    else
      printf("\n");

gauthier's avatar
gauthier committed
556 557
  }
  return NULL;
558 559
}

560 561 562 563 564 565 566 567 568 569 570
//-----------------------------------------------------------------------------
// return a new ue context structure if ue_identityP, ctxt_pP->rnti not found in collection
static struct rrc_eNB_ue_context_s*
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(
571 572
					RC.rrc[ctxt_pP->module_id],
					ctxt_pP->rnti);
573 574

  if (ue_context_p == NULL) {
575
#if 0
576
    RB_FOREACH(ue_context_p, rrc_ue_tree_s, &(RC.rrc[ctxt_pP->module_id]->rrc_ue_head)) {
577 578
      if (ue_context_p->ue_context.random_ue_identity == ue_identityP) {
        LOG_D(RRC,
Cedric Roux's avatar
Cedric Roux committed
579
              PROTOCOL_RRC_CTXT_UE_FMT" Cannot create new UE context, already exist rand UE id 0x%"PRIx64", uid %u\n",
580 581 582 583 584 585
              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
              ue_identityP,
              ue_context_p->local_uid);
        return NULL;
      }
    }
586
#endif
587
    ue_context_p = rrc_eNB_allocate_new_UE_context(RC.rrc[ctxt_pP->module_id]);
winckel's avatar
winckel committed
588

589 590 591 592 593
    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;
594
    }
595

596 597 598
    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;
599
    RB_INSERT(rrc_ue_tree_s, &RC.rrc[ctxt_pP->module_id]->rrc_ue_head, ue_context_p);
600 601 602 603 604
    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
605

606 607 608 609 610 611
  } 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;
  }
winckel's avatar
winckel committed
612 613
}

614 615 616 617 618 619 620 621
#if !defined(ENABLE_USE_MME)
void rrc_eNB_emulation_notify_ue_module_id(
  const module_id_t ue_module_idP,
  const rnti_t      rntiP,
  const uint8_t     cell_identity_byte0P,
  const uint8_t     cell_identity_byte1P,
  const uint8_t     cell_identity_byte2P,
  const uint8_t     cell_identity_byte3P)
622
{
623 624
  module_id_t                         enb_module_id;
  struct rrc_eNB_ue_context_s*        ue_context_p = NULL;
625
  int                                 CC_id;
626 627 628

  // find enb_module_id
  for (enb_module_id = 0; enb_module_id < NUMBER_OF_eNB_MAX; enb_module_id++) {
629 630 631
    if(enb_module_id>0){ /*FIX LATER*/
      return;
    }
632
    for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
633
      if (&RC.rrc[enb_module_id]->carrier[CC_id].sib1 != NULL) {
634
        if (
635 636 637 638
          (&RC.rrc[enb_module_id]->carrier[CC_id].sib1->cellAccessRelatedInfo.cellIdentity.buf[0] == cell_identity_byte0P) &&
          (&RC.rrc[enb_module_id]->carrier[CC_id].sib1->cellAccessRelatedInfo.cellIdentity.buf[1] == cell_identity_byte1P) &&
          (&RC.rrc[enb_module_id]->carrier[CC_id].sib1->cellAccessRelatedInfo.cellIdentity.buf[2] == cell_identity_byte2P) &&
          (&RC.rrc[enb_module_id]->carrier[CC_id].sib1->cellAccessRelatedInfo.cellIdentity.buf[3] == cell_identity_byte3P)
639 640
        ) {
          ue_context_p = rrc_eNB_get_ue_context(
641
                           RC.rrc[enb_module_id],
642 643 644 645 646 647
                           rntiP
                         );

          if (NULL != ue_context_p) {
            oai_emulation.info.eNB_ue_local_uid_to_ue_module_id[enb_module_id][ue_context_p->local_uid] = ue_module_idP;
          }
winckel's avatar
RRC:  
winckel committed
648

649
          //return;
650
        }
651 652
      }
    }
653
    oai_emulation.info.eNB_ue_module_id_to_rnti[enb_module_id][ue_module_idP] = rntiP;
654
  }
winckel's avatar
winckel committed
655

656 657 658 659 660
  AssertFatal(enb_module_id == NUMBER_OF_eNB_MAX,
              "Cell identity not found for ue module id %u rnti %x",
              ue_module_idP, rntiP);
}
#endif
661

662 663 664 665 666
//-----------------------------------------------------------------------------
void
rrc_eNB_free_mem_UE_context(
  const protocol_ctxt_t*               const ctxt_pP,
  struct rrc_eNB_ue_context_s*         const ue_context_pP
667
)
668
//-----------------------------------------------------------------------------
Lionel Gauthier's avatar
Lionel Gauthier committed
669
{
670 671
  int i;
  LOG_T(RRC,
Cedric Roux's avatar
Cedric Roux committed
672
        PROTOCOL_RRC_CTXT_UE_FMT" Clearing UE context 0x%p (free internal structs)\n",
673 674
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
        ue_context_pP);
Cedric Roux's avatar
Cedric Roux committed
675
#if defined(Rel10) || defined(Rel14)
676 677 678 679 680 681 682 683
  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;
  }
684

685 686 687 688 689 690 691
  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;
      }
  }

692 693 694 695
  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;
  }
696

697 698 699 700 701 702 703 704 705 706 707
  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;
      }
  }

708
  memset(ue_context_pP->ue_context.DRB_active, 0, sizeof(ue_context_pP->ue_context.DRB_active));
709

710 711 712
  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;
713 714
  }

715 716 717
  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;
718 719
  }

720 721 722 723 724
  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;
    }
725
  }
726

727 728 729 730 731 732
  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;
    }
  }
733

734 735 736 737
  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;
  }
738

739 740 741 742
  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;
  }
743

744
/*  if (ue_context_pP->ue_context.measGapConfig) {
745 746
    ASN_STRUCT_FREE(asn_DEF_MeasGapConfig, ue_context_pP->ue_context.measGapConfig);
    ue_context_pP->ue_context.measGapConfig = NULL;
747 748 749 750 751
  }*/
    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
752

753 754 755 756 757 758 759
  //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;
760
  }
761

762 763 764
  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;
765
  }
766

767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788
  //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
789 790
}

791
//-----------------------------------------------------------------------------
792
// should be called when UE is lost by eNB
793
void
794
rrc_eNB_free_UE(const module_id_t enb_mod_idP,const struct rrc_eNB_ue_context_s*        const ue_context_pP)
795
//-----------------------------------------------------------------------------
Lionel Gauthier's avatar
Lionel Gauthier committed
796
{
Raymond Knopp's avatar
 
Raymond Knopp committed
797

798

799
  protocol_ctxt_t                     ctxt;
800 801
#if !defined(ENABLE_USE_MME)
  module_id_t                         ue_module_id;
Cedric Roux's avatar
Cedric Roux committed
802 803
  /* avoid gcc warnings */
  (void)ue_module_id;
804
#endif
805
  rnti_t rnti = ue_context_pP->ue_context.rnti;
806 807 808 809 810
  int i, j , CC_id, pdu_number;
  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[enb_mod_idP];
811 812 813

  AssertFatal(enb_mod_idP < NB_eNB_INST, "eNB inst invalid (%d/%d) for UE %x!", enb_mod_idP, NB_eNB_INST, rnti);
  /*  ue_context_p = rrc_eNB_get_ue_context(
814
                   &RC.rrc[enb_mod_idP],
815 816
                   rntiP
                 );
817 818 819 820
  */
  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
821 822

#if defined(ENABLE_USE_MME)
823 824
   if( ue_context_pP->ue_context.ul_failure_timer >= 8 ) {
	LOG_I(RRC, "[eNB %d] S1AP_UE_CONTEXT_RELEASE_REQ RNTI %x\n", enb_mod_idP, rnti);
825
    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
826 827 828 829 830 831
    /* 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].
     */
832 833
     return;
    }
834
#else
835
#if defined(OAI_EMU)
836 837 838 839
    AssertFatal(ue_context_pP->local_uid < NUMBER_OF_UE_MAX, "local_uid invalid (%d<%d) for UE %x!", ue_context_pP->local_uid, NUMBER_OF_UE_MAX, rnti);
    ue_module_id = oai_emulation.info.eNB_ue_local_uid_to_ue_module_id[enb_mod_idP][ue_context_pP->local_uid];
    AssertFatal(ue_module_id < NUMBER_OF_UE_MAX, "ue_module_id invalid (%d<%d) for UE %x!", ue_module_id, NUMBER_OF_UE_MAX, rnti);
    oai_emulation.info.eNB_ue_local_uid_to_ue_module_id[enb_mod_idP][ue_context_pP->local_uid] = -1;
840
    oai_emulation.info.eNB_ue_module_id_to_rnti[enb_mod_idP][ue_module_id] = NOT_A_RNTI;
841
#endif
Lionel Gauthier's avatar
Lionel Gauthier committed
842
#endif
843 844 845 846 847 848 849 850 851 852
    for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
      eNB_PHY = RC.eNB[enb_mod_idP][CC_id];
      for (i=0; i<NUMBER_OF_UE_MAX; i++) {
        ulsch = eNB_PHY->ulsch[i];
        if((ulsch != NULL) && (ulsch->rnti == rnti)){
          LOG_I(RRC, "clean_eNb_ulsch UE %x \n", rnti);
          clean_eNb_ulsch(ulsch);
          break;
        }
      }
853

854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869
      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--){
            if(ul_req_tmp->ul_config_pdu_list[pdu_index].ulsch_pdu.ulsch_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--;
            }
          }
        }
      }
    }
870
    rrc_mac_remove_ue(enb_mod_idP,rnti);
871 872
    rrc_rlc_remove_ue(&ctxt);
    pdcp_remove_UE(&ctxt);
Raymond Knopp's avatar
 
Raymond Knopp committed
873

874 875
    rrc_eNB_remove_ue_context(
      &ctxt,
876
      RC.rrc[enb_mod_idP],
877
      (struct rrc_eNB_ue_context_s*) ue_context_pP);
878
  }
879 880
}

881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980
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;
    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];
              for (i=0; i<=NUMBER_OF_UE_MAX; i++) {
                ulsch = eNB_PHY->ulsch[i];
                if((ulsch != NULL) && (ulsch->rnti == rnti)){
                    LOG_I(RRC, "clean_eNb_ulsch ulsch[%d] UE %x\n", i, rnti);
                    clean_eNb_ulsch(ulsch);
                 }
              }

              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--){
                    if(ul_req_tmp->ul_config_pdu_list[pdu_index].ulsch_pdu.ulsch_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--;
                    }
                  }
                }
              }
            }
            rrc_mac_remove_ue(mod_id,rnti);
            rrc_rlc_remove_ue(&ctxt);
            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);
        }
    }
}

981 982 983 984
//-----------------------------------------------------------------------------
void
rrc_eNB_process_RRCConnectionSetupComplete(
  const protocol_ctxt_t* const ctxt_pP,
985
  rrc_eNB_ue_context_t*         ue_context_pP,
986 987
  RRCConnectionSetupComplete_r8_IEs_t * rrcConnectionSetupComplete
)
988
//-----------------------------------------------------------------------------
Lionel Gauthier's avatar
Lionel Gauthier committed
989
{
990
  LOG_I(RRC,
991
        PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel UL-DCCH, " "processing RRCConnectionSetupComplete from UE (SRB1 Active)\n",
992
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
winckel's avatar
winckel committed
993

nikaeinn's avatar
nikaeinn committed
994
  ue_context_pP->ue_context.Srb1.Active=1;  
Cedric Roux's avatar
Cedric Roux committed
995 996 997
  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));

winckel's avatar
winckel committed
998
#if defined(ENABLE_USE_MME)
999 1000 1001

  if (EPC_MODE_ENABLED == 1) {
    // Forward message to S1AP layer
1002 1003 1004 1005
    rrc_eNB_send_S1AP_NAS_FIRST_REQ(
      ctxt_pP,
      ue_context_pP,
      rrcConnectionSetupComplete);
1006
  } else
winckel's avatar
winckel committed
1007
#endif
1008 1009
  {
    // RRC loop back (no S1AP), send SecurityModeCommand to UE
1010 1011 1012
    rrc_eNB_generate_SecurityModeCommand(
      ctxt_pP,
      ue_context_pP);
1013 1014
    // rrc_eNB_generate_UECapabilityEnquiry(enb_mod_idP,frameP,ue_mod_idP);
  }
winckel's avatar
winckel committed
1015 1016
}

1017 1018 1019 1020 1021
//-----------------------------------------------------------------------------
void
rrc_eNB_generate_SecurityModeCommand(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t*          const ue_context_pP
1022
)
1023
//-----------------------------------------------------------------------------
Lionel Gauthier's avatar
Lionel Gauthier committed
1024
{
1025 1026
  uint8_t                             buffer[100];
  uint8_t                             size;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1027

Cedric Roux's avatar
Cedric Roux committed
1028 1029 1030
  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));

1031 1032 1033 1034 1035 1036
  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
1037

1038
#ifdef RRC_MSG_PRINT
1039 1040 1041
  uint16_t i=0;
  LOG_F(RRC,"[MSG] RRC Security Mode Command\n");

1042
  for (i = 0; i < size; i++) {
1043
    LOG_F(RRC,"%02x ", ((uint8_t*)buffer)[i]);
1044
  }
1045 1046

  LOG_F(RRC,"\n");
1047 1048
#endif

1049
  LOG_I(RRC,
1050 1051 1052
        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
1053

1054
  LOG_D(RRC,
1055 1056 1057 1058 1059
        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);
1060 1061

  MSC_LOG_TX_MESSAGE(
1062 1063 1064 1065 1066 1067 1068 1069 1070
    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);
1071

1072 1073 1074 1075 1076 1077 1078 1079
  rrc_data_req(
	       ctxt_pP,
	       DCCH,
	       rrc_eNB_mui++,
	       SDU_CONFIRM_NO,
	       size,
	       buffer,
	       PDCP_TRANSMISSION_MODE_CONTROL);
1080 1081 1082

}

1083 1084 1085 1086 1087 1088 1089
//-----------------------------------------------------------------------------
void
rrc_eNB_generate_UECapabilityEnquiry(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t*          const ue_context_pP
)
//-----------------------------------------------------------------------------
1090
{
1091

1092 1093
  uint8_t                             buffer[100];
  uint8_t                             size;
1094

Cedric Roux's avatar
Cedric Roux committed
1095 1096 1097
  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));

1098 1099 1100 1101
  size = do_UECapabilityEnquiry(
           ctxt_pP,
           buffer,
           rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id));
winckel's avatar
winckel committed
1102

1103
  LOG_I(RRC,
1104 1105 1106
        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
1107

1108
  LOG_D(RRC,
1109 1110 1111 1112 1113
        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);
1114 1115

  MSC_LOG_TX_MESSAGE(
1116 1117 1118 1119 1120 1121 1122 1123 1124
    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);
1125

1126 1127 1128 1129 1130 1131 1132 1133
  rrc_data_req(
	       ctxt_pP,
	       DCCH,
	       rrc_eNB_mui++,
	       SDU_CONFIRM_NO,
	       size,
	       buffer,
	       PDCP_TRANSMISSION_MODE_CONTROL);
1134 1135 1136

}

1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149
//-----------------------------------------------------------------------------
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
)
//-----------------------------------------------------------------------------
{
#ifdef RRC_MSG_PRINT
  int                                 cnt;
#endif

Cedric Roux's avatar
Cedric Roux committed
1150 1151 1152
  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));

1153
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size =
1154
    do_RRCConnectionReject(ctxt_pP->module_id,
1155
                          (uint8_t*) RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.Payload);
1156 1157 1158 1159

#ifdef RRC_MSG_PRINT
  LOG_F(RRC,"[MSG] RRCConnectionReject\n");

1160 1161
  for (cnt = 0; cnt < RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size; cnt++) {
    LOG_F(RRC,"%02x ", ((uint8_t*)RC.rrc[ctxt_pP->module_id]->Srb0.Tx_buffer.Payload)[cnt]);
1162 1163 1164 1165 1166 1167 1168 1169
  }

  LOG_F(RRC,"\n");
#endif

  MSC_LOG_TX_MESSAGE(
    MSC_RRC_ENB,
    MSC_RRC_UE,
1170 1171
    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.Header,
    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size,
1172 1173 1174
    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,
1175
    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size);
1176 1177 1178 1179

  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),
1180
        RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size);
1181 1182
}

1183 1184
//-----------------------------------------------------------------------------
void
1185 1186
rrc_eNB_generate_RRCConnectionReestablishment(
  const protocol_ctxt_t*         const ctxt_pP,
1187
  rrc_eNB_ue_context_t*          const ue_context_pP,
1188
  const int                            CC_id
1189 1190 1191
)
//-----------------------------------------------------------------------------
{
1192 1193 1194
  LogicalChannelConfig_t             *SRB1_logicalChannelConfig;
  SRB_ToAddModList_t                 **SRB_configList;
  SRB_ToAddMod_t                     *SRB1_config;
1195 1196
  int                                 cnt;

1197
  T(T_ENB_RRC_CONNECTION_REESTABLISHMENT, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
Cedric Roux's avatar
Cedric Roux committed
1198 1199
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

1200
  SRB_configList = &ue_context_pP->ue_context.SRB_configList;
1201
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size =
1202 1203 1204 1205 1206 1207 1208 1209
    do_RRCConnectionReestablishment(ctxt_pP,
                                    ue_context_pP,
                                    CC_id,
                                    (uint8_t*) RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.Payload,
                                    (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);
1210 1211

#ifdef RRC_MSG_PRINT
1212
  LOG_F(RRC,"[MSG] RRCConnectionReestablishment\n");
1213

1214
  for (cnt = 0; cnt < RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size; cnt++) {
1215
    LOG_F(RRC,"%02x ", ((uint8_t*)RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.Payload)[cnt]);
1216 1217 1218 1219 1220
  }

  LOG_F(RRC,"\n");
#endif

1221
  // configure SRB1 for UE
1222

1223 1224 1225 1226
  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];
1227

1228 1229 1230 1231 1232 1233 1234 1235 1236 1237
        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
1238

1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276
        LOG_D(RRC,
              PROTOCOL_RRC_CTXT_UE_FMT" RRC_eNB --- MAC_CONFIG_REQ  (SRB1) ---> MAC_eNB\n",
              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
        rrc_mac_config_req_eNB(ctxt_pP->module_id,
                           ue_context_pP->ue_context.primaryCC_id,
                           0,0,0,0,0,
#ifdef Rel14 
			 0,
#endif
                           ctxt_pP->rnti,
                           (BCCH_BCH_Message_t *) NULL, 
                           (RadioResourceConfigCommonSIB_t *) NULL,
                           (RadioResourceConfigCommonSIB_t *) NULL,
                           (struct PhysicalConfigDedicated* ) ue_context_pP->ue_context.physicalConfigDedicated,
#if defined(Rel10) || defined(Rel14)
                           (SCellToAddMod_r10_t *)NULL,
                           //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
#endif
                           (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
#if defined(Rel10) || defined(Rel14)
                           , 0, (MBSFN_AreaInfoList_r9_t *) NULL, (PMCH_InfoList_r9_t *) NULL
#endif
#ifdef Rel14
                           ,(SystemInformationBlockType1_v1310_IEs_t *)NULL 
#endif
        );
        break;
      }
    }
  }
Raymond Knopp's avatar
 
Raymond Knopp committed
1277

1278 1279 1280 1281 1282 1283 1284 1285
  MSC_LOG_TX_MESSAGE(MSC_RRC_ENB,
                     MSC_RRC_UE,
                     RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.Header,
                     RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size,
                     MSC_AS_TIME_FMT" RRCConnectionReestablishment UE %x size %u",
                     MSC_AS_TIME_ARGS(ctxt_pP),
                     ue_context_pP->ue_context.rnti,
                     RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size);
Cedric Roux's avatar
Cedric Roux committed
1286

Raymond Knopp's avatar
 
Raymond Knopp committed
1287

1288
  LOG_I(RRC,
1289
        PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel DL-CCCH, Generating RRCConnectionReestablishment (bytes %d)\n",
1290
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
1291
        RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size);
1292

1293
  int UE_id = find_UE_id(ctxt_pP->module_id, ctxt_pP->rnti);
1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305
  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);
  }
  // activate release timer, if RRCComplete not received after 100 frames, remove UE
  ue_context_pP->ue_context.ue_reestablishment_timer = 1;
1306
  // remove UE after 100 frames after RRCConnectionReestablishmentRelease is triggered
1307
  ue_context_pP->ue_context.ue_reestablishment_timer_thres = 1000;
Raymond Knopp's avatar
 
Raymond Knopp committed
1308
}
1309

1310 1311
//-----------------------------------------------------------------------------
void
1312 1313 1314 1315 1316 1317 1318
rrc_eNB_process_RRCConnectionReestablishmentComplete(
  const protocol_ctxt_t* const ctxt_pP,
  const rnti_t const reestablish_rnti,
  rrc_eNB_ue_context_t*         ue_context_pP,
  const uint8_t xid,
  RRCConnectionReestablishmentComplete_r8_IEs_t * rrcConnectionReestablishmentComplete
)
1319 1320
//-----------------------------------------------------------------------------
{
1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338
  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;
# if defined(ENABLE_USE_MME)
  int j = 0;
  hashtable_rc_t                      h_rc;
#endif
1339 1340
  uint8_t                             buffer[RRC_BUF_SIZE];
  uint16_t                            size;
1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352
  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;
1353 1354
  struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList = NULL;
  DedicatedInfoNAS_t                 *dedicatedInfoNas                 = NULL;
1355 1356
  /* for no gcc warnings */
  (void)dedicatedInfoNas;
1357 1358 1359 1360
  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;
1361
  ue_context_pP->ue_context.reestablishment_xid = next_xid;
1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398

  SRB_configList2 = &ue_context_pP->ue_context.SRB_configList2[xid];
  // get old configuration of SRB2
  if (*SRB_configList2 != NULL) {
    LOG_D(RRC, "SRB_configList2(%p) count is %d\n           SRB_configList2->list.array[0] addr is %p",
          SRB_configList2, (*SRB_configList2)->list.count,  (*SRB_configList2)->list.array[0]);
    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];

  if (*SRB_configList2) {
    free(*SRB_configList2);
    LOG_D(RRC, "free(ue_context_pP->ue_context.SRB_configList2[%d])\n", next_xid);
  }
  *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");
  }

1399

1400

1401 1402
  if (*DRB_configList2) {
    free(*DRB_configList2);
1403
    LOG_D(RRC, "free(ue_context_pP->ue_context.DRB_configList2[%d])\n", next_xid);
1404
  }
1405
  *DRB_configList2 = CALLOC(1, sizeof(**DRB_configList2));
Navid Nikaein's avatar
Navid Nikaein committed
1406

1407 1408 1409 1410 1411 1412 1413
  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);
1414
    }
1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435
  }
  ue_context_pP->ue_context.Srb1.Active = 1;
  //ue_context_pP->ue_context.Srb2.Srb_info.Srb_id = 2;

# if defined(ENABLE_USE_MME)
  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;
    }
  }
  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;
    }
  }
1436

1437
  gtpv1u_enb_create_tunnel_req_t  create_tunnel_req;
1438

1439 1440
  /* Save e RAB information for later */
  memset(&create_tunnel_req, 0 , sizeof(create_tunnel_req));
1441

1442 1443 1444 1445
  for (j = 0, i = 0; i < NB_RB_MAX; i++) {
    if (ue_context_pP->ue_context.e_rab[i].status == E_RAB_STATUS_ESTABLISHED) {
      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;
1446

1447 1448 1449 1450 1451 1452
      memcpy(&create_tunnel_req.sgw_addr[j],
             &ue_context_pP->ue_context.e_rab[i].param.sgw_addr,
             sizeof(transport_layer_addr_t));
      j++;
    }
  }
1453

1454 1455
  create_tunnel_req.rnti       = ctxt_pP->rnti; // warning put zero above
  create_tunnel_req.num_tunnels    = j;
1456

1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 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
  gtpv1u_update_s1u_tunnel(
            ctxt_pP->instance,
            &create_tunnel_req,
            reestablish_rnti);
#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;
# if defined(ENABLE_USE_MME)
  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");
#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;
    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
                                         (struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList*)dedicatedInfoNASList //dedicatedInfoNASList
#if defined(Rel10) || defined(Rel14)
                                         , (SCellToAddMod_r10_t*)NULL
#endif
                                        );

#ifdef RRC_MSG_PRINT
  LOG_F(RRC,"[MSG] RRC Connection Reconfiguration\n");
  for (i = 0; i < size; i++) {
    LOG_F(RRC,"%02x ", ((uint8_t*)buffer)[i]);
  }
  LOG_F(RRC,"\n");
  ////////////////////////////////////////
#endif

#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 id %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" 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);

  // delete UE data of prior RNTI.  UE use current RNTI.
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 1921 1922 1923 1924 1925 1926 1927
//  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];
//    for (int i=0; i<NUMBER_OF_UE_MAX; i++) {
//      ulsch = eNB_PHY->ulsch[i];
//      if((ulsch != NULL) && (ulsch->rnti == ctxt_prior.rnti)){
//        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);
1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941
}

//-----------------------------------------------------------------------------
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
)
//-----------------------------------------------------------------------------
{
#ifdef RRC_MSG_PRINT
  int                                 cnt;
#endif
1942
  int UE_id = find_UE_id(ctxt_pP->module_id, ctxt_pP->rnti);
1943 1944 1945 1946 1947 1948 1949 1950
  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);
  }
1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003

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

  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size =
    do_RRCConnectionReestablishmentReject(ctxt_pP->module_id,
                          (uint8_t*) RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.Payload);

#ifdef RRC_MSG_PRINT
  LOG_F(RRC,"[MSG] RRCConnectionReestablishmentReject\n");

  for (cnt = 0; cnt < RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size; cnt++) {
    LOG_F(RRC,"%02x ", ((uint8_t*)RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.Payload)[cnt]);
  }

  LOG_F(RRC,"\n");
#endif

  MSC_LOG_TX_MESSAGE(
    MSC_RRC_ENB,
    MSC_RRC_UE,
    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.Header,
    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size,
    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,
    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size);

  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),
        RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size);
}

//-----------------------------------------------------------------------------
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));
  // set release timer
2004
  //ue_context_pP->ue_context.ue_release_timer=1;
2005
  // remove UE after 10 frames after RRCConnectionRelease is triggered
2006 2007 2008 2009
  //ue_context_pP->ue_context.ue_release_timer_thres=100;
    // set release timer
  ue_context_pP->ue_context.ue_release_timer_rrc = 1;
  // remove UE after 10 frames after RRCConnectionRelease is triggered
2010
  ue_context_pP->ue_context.ue_release_timer_thres_rrc = 100;
2011 2012 2013
  ue_context_pP->ue_context.ue_reestablishment_timer = 0;
  ue_context_pP->ue_context.ue_release_timer = 0;
  ue_context_pP->ue_context.ue_release_timer_s1 = 0;
2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 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 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171
  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);

  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;
2172 2173 2174 2175 2176 2177 2178 2179 2180 2181
       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;
       
2182 2183 2184 2185 2186
       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;
2187
      e_rab_done++;
2188
      continue;
2189 2190 2191 2192 2193 2194 2195 2196 2197
    }

    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;

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 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 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 2417 2418 2419 2420 2421 2422 2423 2424 2425 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
    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, 
					  (struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList*)dedicatedInfoNASList
#if defined(Rel10) || defined(Rel14)
                                         , (SCellToAddMod_r10_t*)NULL
#endif
                                        );
 

#ifdef RRC_MSG_PRINT
  LOG_F(RRC,"[MSG] RRC Connection Reconfiguration\n");
  for (i = 0; i < size; i++) {
    LOG_F(RRC,"%02x ", ((uint8_t*)buffer)[i]);
  }
  LOG_F(RRC,"\n");
  ////////////////////////////////////////
#endif

#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
2483 2484 2485
      DRB_ul_SpecificParameters->priority= 4;

    DRB_ul_SpecificParameters->prioritisedBitRate = LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_kBps8;
2486

2487 2488
    DRB_ul_SpecificParameters->bucketSizeDuration =
      LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
2489

2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503
    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;
2504

2505
    {
2506 2507 2508 2509 2510 2511 2512 2513
      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);
2514
      }
2515 2516
      else {
        LOG_W(RRC, "Not received activate dedicated EPS bearer context request\n");
2517
      }
2518 2519
    }
  }
2520 2521 2522 2523 2524 2525 2526

  /* 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");
2527
    }
2528 2529 2530 2531
  } else {
    LOG_W(RRC,"dedlicated NAS list is empty\n");
  }

2532 2533
  memset(buffer, 0, RRC_BUF_SIZE);

2534 2535 2536 2537 2538 2539 2540 2541 2542 2543
  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
Cedric Roux's avatar
Cedric Roux committed
2544
#if defined(Rel10) || defined(Rel14)
2545
                                          , (SCellToAddMod_r10_t*)NULL
2546
#endif
2547 2548
                                          );

2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561

#ifdef RRC_MSG_PRINT
  LOG_F(RRC,"[MSG] RRC Connection Reconfiguration\n");
  for (i = 0; i < size; i++) {
    LOG_F(RRC,"%02x ", ((uint8_t*)buffer)[i]);
  }
  LOG_F(RRC,"\n");
  ////////////////////////////////////////
#endif

#if defined(ENABLE_ITTI)

  /* Free all NAS PDUs */
2562 2563
  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) {
2564
      /* Free the NAS PDU buffer and invalidate it */
2565 2566
      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;
2567 2568 2569 2570 2571
    }
  }
#endif

 LOG_I(RRC,
2572
        "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate RRCConnectionReconfiguration (bytes %d, UE RNTI %x)\n",
2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589
        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);

2590
  rrc_data_req(
2591 2592 2593 2594 2595 2596 2597
    ctxt_pP,
    DCCH,
    rrc_eNB_mui++,
    SDU_CONFIRM_NO,
    size,
    buffer,
    PDCP_TRANSMISSION_MODE_CONTROL);
2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680
  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,
                                    (struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList*)dedicatedInfoNASList
#if defined(Rel10) || defined(Rel14)
                                    , (SCellToAddMod_r10_t*)NULL
#endif
                                   );
    ue_context_pP->ue_context.e_rab_release_command_flag = 1;

#ifdef RRC_MSG_PRINT
  LOG_F(RRC,"[MSG] RRC Connection Reconfiguration\n");
  for (i = 0; i < size; i++) {
    LOG_F(RRC,"%02x ", ((uint8_t*)buffer)[i]);
  }
  LOG_F(RRC,"\n");
  ////////////////////////////////////////
#endif
2681

2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716
#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);

  rrc_data_req(
    ctxt_pP,
    DCCH,
    rrc_eNB_mui++,
    SDU_CONFIRM_NO,
    size,
    buffer,
    PDCP_TRANSMISSION_MODE_CONTROL);
2717 2718 2719 2720 2721 2722 2723 2724 2725

}
#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
						     )
2726
//-----------------------------------------------------------------------------
2727 2728 2729 2730 2731 2732
{
  uint8_t                             buffer[RRC_BUF_SIZE];
  uint16_t                            size;
  int                                 i;

  // configure SRB1/SRB2, PhysicalConfigDedicated, MAC_MainConfig for UE
2733
  eNB_RRC_INST*                       rrc_inst = RC.rrc[ctxt_pP->module_id];
2734
  struct PhysicalConfigDedicated**    physicalConfigDedicated = &ue_context_pP->ue_context.physicalConfigDedicated;
2735 2736 2737 2738 2739 2740

  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;
2741
  SRB_ToAddModList_t*                 SRB_configList = ue_context_pP->ue_context.SRB_configList;
2742
  SRB_ToAddModList_t                 **SRB_configList2                  = NULL;
2743 2744 2745 2746 2747 2748 2749 2750 2751

  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;
2752
  DRB_ToAddModList_t**                DRB_configList = &ue_context_pP->ue_context.DRB_configList;
2753 2754
  DRB_ToAddModList_t**                DRB_configList2 = NULL;
   MAC_MainConfig_t                   *mac_MainConfig                   = NULL;
2755 2756 2757 2758 2759 2760 2761
  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;
Cedric Roux's avatar
Cedric Roux committed
2762
#if defined(Rel10) || defined(Rel14)
2763 2764
  long                               *sr_ProhibitTimer_r9              = NULL;
  //     uint8_t sCellIndexToAdd = rrc_find_free_SCell_index(enb_mod_idP, ue_mod_idP, 1);
2765
  //uint8_t                            sCellIndexToAdd = 0;
winckel's avatar
winckel committed
2766
#endif
2767

2768 2769
  long                               *logicalchannelgroup, *logicalchannelgroup_drb;
  long                               *maxHARQ_Tx, *periodicBSR_Timer;
2770

2771 2772 2773 2774 2775 2776 2777
  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
2778 2779
  /* for no gcc warnings */
  (void)dedicatedInfoNas;
2780

2781
  C_RNTI_t                           *cba_RNTI                         = NULL;
2782 2783 2784

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

2785
#ifdef CBA
2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807
  //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);
  }
2808

2809
#endif
2810 2811 2812 2813

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

2814 2815
  // Configure SRB2
  /// SRB2
2816 2817 2818 2819 2820 2821
  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));
2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843
  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));

2844
  SRB2_ul_SpecificParameters->priority = 3; // let some priority for SRB1 and dedicated DRBs
2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856
  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
2857
  // this list has the configuration for SRB1 and SRB2
2858
  ASN_SEQUENCE_ADD(&SRB_configList->list, SRB2_config);
Navid Nikaein's avatar
Navid Nikaein committed
2859
  // this list has only the configuration for SRB2
2860
  ASN_SEQUENCE_ADD(&(*SRB_configList2)->list, SRB2_config);
2861 2862 2863

  // Configure DRB
  //*DRB_configList = CALLOC(1, sizeof(*DRB_configList));
2864
  // list for all the configured DRB
2865 2866 2867
  if (*DRB_configList) {
    free(*DRB_configList);
  }
2868
  *DRB_configList = CALLOC(1, sizeof(**DRB_configList));
2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879
  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));


2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891
  /// 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
2892

2893
#ifdef RRC_DEFAULT_RAB_IS_AM
2894 2895 2896 2897 2898 2899 2900
  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;
2901
#else
2902 2903 2904
  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;
2905
#ifdef CBA
2906
  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering   = T_Reordering_ms5;//T_Reordering_ms25;
2907 2908 2909
#else
  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering = T_Reordering_ms35;
#endif
2910
#endif
2911

2912 2913 2914 2915 2916 2917
  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;
2918

Cedric Roux's avatar
Cedric Roux committed
2919 2920
  /* avoid gcc warnings */
  (void)PDCP_rlc_AM;
Cedric Roux's avatar
Cedric Roux committed
2921
  (void)PDCP_rlc_UM;
Cedric Roux's avatar
Cedric Roux committed
2922

2923
#ifdef RRC_DEFAULT_RAB_IS_AM // EXMIMO_IOT
2924 2925 2926
  PDCP_rlc_AM = CALLOC(1, sizeof(*PDCP_rlc_AM));
  DRB_pdcp_config->rlc_AM = PDCP_rlc_AM;
  PDCP_rlc_AM->statusReportRequired = FALSE;
2927
#else
2928 2929 2930
  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;
2931
#endif
2932
  DRB_pdcp_config->headerCompression.present = PDCP_Config__headerCompression_PR_notUsed;
2933

2934 2935 2936 2937
  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;
2938

2939 2940 2941
  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;
2942 2943
  DRB_ul_SpecificParameters->bucketSizeDuration =
    LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
2944

2945 2946 2947 2948
  // 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
2949

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

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

2955
  mac_MainConfig = CALLOC(1, sizeof(*mac_MainConfig));
2956
  ue_context_pP->ue_context.mac_MainConfig = mac_MainConfig;
winckel's avatar
RRC:  
winckel committed
2957

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

2960 2961 2962 2963
  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
2964
  *periodicBSR_Timer = PeriodicBSR_Timer_r12_sf64;
2965
  mac_MainConfig->ul_SCH_Config->periodicBSR_Timer = periodicBSR_Timer;
Cedric Roux's avatar
Cedric Roux committed
2966
  mac_MainConfig->ul_SCH_Config->retxBSR_Timer = RetxBSR_Timer_r12_sf320;
2967
  mac_MainConfig->ul_SCH_Config->ttiBundling = 0; // FALSE
2968

2969
  mac_MainConfig->timeAlignmentTimerDedicated = TimeAlignmentTimer_infinity;
2970

2971
  mac_MainConfig->drx_Config = NULL;
winckel's avatar
winckel committed
2972

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

2975 2976
  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
2977

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

2980
  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
2981

Cedric Roux's avatar
Cedric Roux committed
2982
#if defined(Rel10) || defined(Rel14)
2983 2984
  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
2985 2986
  mac_MainConfig->ext1 = CALLOC(1, sizeof(struct MAC_MainConfig__ext1));
  mac_MainConfig->ext1->sr_ProhibitTimer_r9 = sr_ProhibitTimer_r9;
2987 2988 2989
  //sps_RA_ConfigList_rlola = NULL;
#endif

2990
  //change the transmission mode for the primary component carrier
2991
  //TODO: add codebook subset restriction here
2992
  //TODO: change TM for secondary CC in SCelltoaddmodlist
2993
  if (*physicalConfigDedicated) {
2994
    if ((*physicalConfigDedicated)->antennaInfo) {
2995
      (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.transmissionMode = rrc_inst->configuration.ue_TransmissionMode[0];
Cedric Roux's avatar
Cedric Roux committed
2996
      LOG_D(RRC,"Setting transmission mode to %ld+1\n",rrc_inst->configuration.ue_TransmissionMode[0]);
2997
      if (rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm3) {
2998 2999 3000 3001 3002 3003 3004 3005 3006
	(*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;
      }
3007
      else if (rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm4) {
3008 3009 3010 3011 3012 3013 3014 3015
	(*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;
3016

3017
      }
3018
      else if (rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm5) {
3019 3020 3021 3022 3023 3024 3025 3026 3027
	(*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;
      }
3028
      else if (rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm6) {
3029 3030 3031 3032 3033 3034 3035 3036 3037
	(*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;
      }
3038
    }
3039 3040 3041 3042 3043 3044 3045 3046 3047 3048
    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");
Cedric Roux's avatar
Cedric Roux committed
3049
#if defined(Rel10) || defined(Rel14)
3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062
	*((*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");
  }
3063

3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135
  // 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;
3136
    CellToAdd->physCellId = get_adjacent_cell_id(ctxt_pP->module_id, i);
3137 3138 3139 3140
    CellToAdd->cellIndividualOffset = Q_OffsetRange_dB0;

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

3142 3143
  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
3144

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

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

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

3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193
  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 (ho_state == 1 /*HO_MEASURMENT */ ) {
3194 3195
    LOG_I(RRC, "[eNB %d] frame %d: requesting A2, A3, A4, A5, and A6 event reporting\n",
          ctxt_pP->module_id, ctxt_pP->frame);
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 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 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
    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",
3312
          ctxt_pP->module_id, ctxt_pP->frame);
3313 3314
    // store the information in an intermediate structure for Hanodver management
    //rrc_inst->handover_info.as_config.sourceRadioResourceConfig.srb_ToAddModList = CALLOC(1,sizeof());
3315
    ue_context_pP->ue_context.handover_info = CALLOC(1, sizeof(*(ue_context_pP->ue_context.handover_info)));
3316
    //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.srb_ToAddModList,(void *)SRB_list,sizeof(SRB_ToAddModList_t));
3317
    ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.srb_ToAddModList = *SRB_configList2;
3318
    //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.drb_ToAddModList,(void *)DRB_list,sizeof(DRB_ToAddModList_t));
3319 3320 3321 3322 3323
    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,
3324
           (void *)mac_MainConfig, sizeof(MAC_MainConfig_t));
3325
    ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.physicalConfigDedicated =
3326
      CALLOC(1, sizeof(PhysicalConfigDedicated_t));
3327 3328 3329
    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;
3330 3331 3332 3333 3334 3335 3336 3337 3338
    //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 */
3339 3340
  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) {
3341 3342
      dedicatedInfoNas = CALLOC(1, sizeof(DedicatedInfoNAS_t));
      memset(dedicatedInfoNas, 0, sizeof(OCTET_STRING_t));
3343 3344
      OCTET_STRING_fromBuf(dedicatedInfoNas, 
			   (char*)ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer,
3345
                           ue_context_pP->ue_context.e_rab[i].param.nas_pdu.length);
3346
      ASN_SEQUENCE_ADD(&dedicatedInfoNASList->list, dedicatedInfoNas);
3347
    }
3348

3349 3350
    /* TODO parameters yet to process ... */
    {
3351 3352 3353
      //      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;
3354
    }
3355 3356

    /* TODO should test if e RAB are Ok before! */
3357
    ue_context_pP->ue_context.e_rab[i].status = E_RAB_STATUS_DONE;
3358 3359
    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");
3360 3361 3362 3363 3364 3365 3366 3367
  }

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

3368 3369
#endif

3370
  memset(buffer, 0, RRC_BUF_SIZE);
3371

3372 3373
  size = do_RRCConnectionReconfiguration(ctxt_pP,
                                         buffer,
3374 3375
                                         xid,   //Transaction_id,
                                         (SRB_ToAddModList_t*)*SRB_configList2, // SRB_configList
3376 3377 3378
                                         (DRB_ToAddModList_t*)*DRB_configList,
                                         (DRB_ToReleaseList_t*)NULL,  // DRB2_list,
                                         (struct SPS_Config*)NULL,    // *sps_Config,
3379
                                         (struct PhysicalConfigDedicated*)*physicalConfigDedicated,
3380
#ifdef EXMIMO_IOT
3381
                                         NULL, NULL, NULL,NULL,
3382
#else
3383 3384 3385 3386
                                         (MeasObjectToAddModList_t*)MeasObj_list,
                                         (ReportConfigToAddModList_t*)ReportConfig_list,
                                         (QuantityConfig_t*)quantityConfig,
                                         (MeasIdToAddModList_t*)MeasId_list,
3387
#endif
3388 3389 3390 3391 3392 3393 3394
                                         (MAC_MainConfig_t*)mac_MainConfig,
                                         (MeasGapConfig_t*)NULL,
                                         (MobilityControlInfo_t*)NULL,
                                         (struct MeasConfig__speedStatePars*)Sparams,
                                         (RSRP_Range_t*)rsrp,
                                         (C_RNTI_t*)cba_RNTI,
                                         (struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList*)dedicatedInfoNASList
Cedric Roux's avatar
Cedric Roux committed
3395
#if defined(Rel10) || defined(Rel14)
3396
                                         , (SCellToAddMod_r10_t*)NULL
3397
#endif
3398
                                        );
3399

3400
#ifdef RRC_MSG_PRINT
3401
  LOG_F(RRC,"[MSG] RRC Connection Reconfiguration\n");
3402
  for (i = 0; i < size; i++) {
3403
    LOG_F(RRC,"%02x ", ((uint8_t*)buffer)[i]);
3404
  }
3405 3406 3407 3408
  LOG_F(RRC,"\n");
  ////////////////////////////////////////
#endif

3409
#if defined(ENABLE_ITTI)
3410 3411

  /* Free all NAS PDUs */
3412 3413
  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) {
3414
      /* Free the NAS PDU buffer and invalidate it */
3415 3416
      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;
3417
    }
3418 3419
  }

3420
#endif
3421

3422
  LOG_I(RRC,
3423 3424
        "[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);
3425

3426
  LOG_D(RRC,
3427 3428
        "[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);
3429 3430

  MSC_LOG_TX_MESSAGE(
3431 3432 3433 3434 3435 3436 3437 3438 3439
    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);
3440

3441 3442 3443 3444 3445 3446 3447 3448
  rrc_data_req(
	       ctxt_pP,
	       DCCH,
	       rrc_eNB_mui++,
	       SDU_CONFIRM_NO,
	       size,
	       buffer,
	       PDCP_TRANSMISSION_MODE_CONTROL);
winckel's avatar
winckel committed
3449
}
3450

3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557
typedef enum { BAND_TYPE_FDD, BAND_TYPE_TDD } band_type;

typedef struct {
  band_type t;
  int band;
  unsigned long ul_minfreq, ul_maxfreq;
  unsigned long dl_minfreq, dl_maxfreq;
} band_freq;

static band_freq bands[] = {
  { BAND_TYPE_FDD, 1, 1920000000UL, 1980000000UL, 2110000000UL, 2170000000UL },
  { BAND_TYPE_FDD, 2, 1850000000UL, 1910000000UL, 1930000000UL, 1990000000UL },
  { BAND_TYPE_FDD, 3, 1710000000UL, 1785000000UL, 1805000000UL, 1880000000UL },
  { BAND_TYPE_FDD, 4, 1710000000UL, 1755000000UL, 2110000000UL, 2155000000UL },
  { BAND_TYPE_FDD, 5, 824000000UL, 849000000UL, 869000000UL, 894000000UL },
    /* to remove? */{ BAND_TYPE_FDD, 6, 830000000UL, 840000000UL, 875000000UL, 885000000UL },
  { BAND_TYPE_FDD, 7, 2500000000UL, 2570000000UL, 2620000000UL, 2690000000UL },
  { BAND_TYPE_FDD, 8, 880000000UL, 915000000UL, 925000000UL, 960000000UL },
  { BAND_TYPE_FDD, 9, 1749900000UL, 1784900000UL, 1844900000UL, 1879900000UL },
  { BAND_TYPE_FDD, 10, 1710000000UL, 1770000000UL, 2110000000UL, 2170000000UL },
  { BAND_TYPE_FDD, 11, 1427900000UL, 1447900000UL, 1475900000UL, 1495900000UL },
  { BAND_TYPE_FDD, 12, 699000000UL, 716000000UL, 729000000UL, 746000000UL },
  { BAND_TYPE_FDD, 13, 777000000UL, 787000000UL, 746000000UL, 756000000UL },
  { BAND_TYPE_FDD, 14, 788000000UL, 798000000UL, 758000000UL, 768000000UL },
  { BAND_TYPE_FDD, 17, 704000000UL, 716000000UL, 734000000UL, 746000000UL },
  { BAND_TYPE_FDD, 18, 815000000UL, 830000000UL, 860000000UL, 875000000UL },
  { BAND_TYPE_FDD, 19, 830000000UL, 845000000UL, 875000000UL, 890000000UL },
  { BAND_TYPE_FDD, 20, 832000000UL, 862000000UL, 791000000UL, 821000000UL },
  { BAND_TYPE_FDD, 21, 1447900000UL, 1462900000UL, 1495900000UL, 1510900000UL },
  { BAND_TYPE_FDD, 22, 3410000000UL, 3490000000UL, 3510000000UL, 3590000000UL },
  { BAND_TYPE_FDD, 23, 2000000000UL, 2020000000UL, 2180000000UL, 2200000000UL },
  { BAND_TYPE_FDD, 24, 1626500000UL, 1660500000UL, 1525000000UL, 1559000000UL },
  { BAND_TYPE_FDD, 25, 1850000000UL, 1915000000UL, 1930000000UL, 1995000000UL },

  { BAND_TYPE_TDD, 33, 1900000000UL, 1920000000UL, 1900000000UL, 1920000000UL },
  { BAND_TYPE_TDD, 34, 2010000000UL, 2025000000UL, 2010000000UL, 2025000000UL },
  { BAND_TYPE_TDD, 35, 1850000000UL, 1910000000UL, 1850000000UL, 1910000000UL },
  { BAND_TYPE_TDD, 36, 1930000000UL, 1990000000UL, 1930000000UL, 1990000000UL },
  { BAND_TYPE_TDD, 37, 1910000000UL, 1930000000UL, 1910000000UL, 1930000000UL },
  { BAND_TYPE_TDD, 38, 2570000000UL, 2620000000UL, 2570000000UL, 2620000000UL },
  { BAND_TYPE_TDD, 39, 1880000000UL, 1920000000UL, 1880000000UL, 1920000000UL },
  { BAND_TYPE_TDD, 40, 2300000000UL, 2400000000UL, 2300000000UL, 2400000000UL },
  { BAND_TYPE_TDD, 41, 2496000000UL, 2690000000UL, 2496000000UL, 2690000000UL },
  { BAND_TYPE_TDD, 42, 3400000000UL, 3600000000UL, 3400000000UL, 3600000000UL },
  { BAND_TYPE_TDD, 43, 3600000000UL, 3800000000UL, 3600000000UL, 3800000000UL },
};

typedef struct {
  int band;
  unsigned long dl_flow;
  int dl_off;
  int dl_offmin, dl_offmax;
  unsigned long ul_flow;
  int ul_off;
  int ul_offmin, ul_offmax;
} earfcn;

static earfcn earfcn_table[] = {
  { 1, 2110000000UL, 0, 0, 599, 1920000000UL, 18000, 18000, 18599 },
  { 2, 1930000000UL, 600, 600, 1199, 1850000000UL, 18600, 18600, 19199 },
  { 3, 1805000000UL, 1200, 1200, 1949, 1710000000UL, 19200, 19200, 19949 },
  { 4, 2110000000UL, 1950, 1950, 2399, 1710000000UL, 19950, 19950, 20399 },
  { 5, 869000000UL, 2400, 2400, 2649, 824000000UL, 20400, 20400, 20649 },
  { 6, 875000000UL, 2650, 2650, 2749, 830000000UL, 20650, 20650, 20749 },
  { 7, 2620000000UL, 2750, 2750, 3449, 2500000000UL, 20750, 20750, 21449 },
  { 8, 925000000UL, 3450, 3450, 3799, 880000000UL, 21450, 21450, 21799 },
  { 9, 1844900000UL, 3800, 3800, 4149, 1749900000UL, 21800, 21800, 22149 },
  { 10, 2110000000UL, 4150, 4150, 4749, 1710000000UL, 22150, 22150, 22749 },
  { 11, 1475900000UL, 4750, 4750, 4949, 1427900000UL, 22750, 22750, 22949 },
  { 12, 729000000UL, 5010, 5010, 5179, 699000000UL, 23010, 23010, 23179 },
  { 13, 746000000UL, 5180, 5180, 5279, 777000000UL, 23180, 23180, 23279 },
  { 14, 758000000UL, 5280, 5280, 5379, 788000000UL, 23280, 23280, 23379 },
  { 17, 734000000UL, 5730, 5730, 5849, 704000000UL, 23730, 23730, 23849 },
  { 18, 860000000UL, 5850, 5850, 5999, 815000000UL, 23850, 23850, 23999 },
  { 19, 875000000UL, 6000, 6000, 6149, 830000000UL, 24000, 24000, 24149 },
  { 20, 791000000UL, 6150, 6150, 6449, 832000000UL, 24150, 24150, 24449 },
  { 21, 1495900000UL, 6450, 6450, 6599, 1447900000UL, 24450, 24450, 24599 },
  { 22, 3510000000UL, 6600, 6600, 7399, 3410000000UL, 24600, 24600, 25399 },
  { 23, 2180000000UL, 7500, 7500, 7699, 2000000000UL, 25500, 25500, 25699 },
  { 24, 1525000000UL, 7700, 7700, 8039, 1626500000UL, 25700, 25700, 26039 },
  { 25, 1930000000UL, 8040, 8040, 8689, 1850000000UL, 26040, 26040, 26689 },
  { 33, 1900000000UL, 36000, 36000, 36199, 1900000000UL, 36000, 36000, 36199 },
  { 34, 2010000000UL, 36200, 36200, 36349, 2010000000UL, 36200, 36200, 36349 },
  { 35, 1850000000UL, 36350, 36350, 36949, 1850000000UL, 36350, 36350, 36949 },
  { 36, 1930000000UL, 36950, 36950, 37549, 1930000000UL, 36950, 36950, 37549 },
  { 37, 1910000000UL, 37550, 37550, 37749, 1910000000UL, 37550, 37550, 37749 },
  { 38, 2570000000UL, 37750, 37750, 38249, 2570000000UL, 37750, 37750, 38249 },
  { 39, 1880000000UL, 38250, 38250, 38649, 1880000000UL, 38250, 38250, 38649 },
  { 40, 2300000000UL, 38650, 38650, 39649, 2300000000UL, 38650, 38650, 39649 },
  { 41, 2496000000UL, 39650, 39650, 41589, 2496000000UL, 39650, 39650, 41589 },
  { 42, 3400000000UL, 41590, 41590, 43589, 3400000000UL, 41590, 41590, 43589 },
  { 43, 3600000000UL, 43590, 43590, 45589, 3600000000UL, 43590, 43590, 45589 },
};
  
int freq_to_arfcn10(int band, unsigned long freq)
{ 
  int N = sizeof(earfcn_table) / sizeof(earfcn_table[0]); 
  int i;
  
  for (i = 0; i < N; i++) if (bands[i].band == band) break; 
  if (i == N) return -1;
  
  if (!(bands[i].dl_minfreq < freq && freq < bands[i].dl_maxfreq))
    return -1;
  
  return (freq - earfcn_table[i].dl_flow) / 100000UL + earfcn_table[i].dl_off;
}
3558

3559 3560 3561 3562 3563 3564 3565 3566
//-----------------------------------------------------------------------------
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
)
//-----------------------------------------------------------------------------
3567
{
3568 3569 3570

  uint8_t size;
  uint8_t buffer[100];
3571

Cedric Roux's avatar
Cedric Roux committed
3572
#if defined(Rel10) || defined(Rel14)
3573
  uint8_t sCellIndexToAdd = 0; //one SCell so far
3574 3575 3576

  //   uint8_t sCellIndexToAdd;
  //   sCellIndexToAdd = rrc_find_free_SCell_index(enb_mod_idP, ue_mod_idP, 1);
3577
  //  if (RC.rrc[enb_mod_idP]->sCell_config[ue_mod_idP][sCellIndexToAdd] ) {
3578 3579
  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;
3580
  } else {
3581 3582
    LOG_E(RRC,"Scell not configured!\n");
    return(-1);
3583 3584
  }

3585
#endif
3586
  size = do_RRCConnectionReconfiguration(ctxt_pP,
3587
                                         buffer,
3588
                                         rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),//Transaction_id,
3589 3590 3591 3592 3593 3594 3595
                                         (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,
3596
                                         (QuantityConfig_t*)NULL,
3597 3598 3599 3600 3601 3602 3603
                                         (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,
3604 3605
                                         (struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList*)NULL

Cedric Roux's avatar
Cedric Roux committed
3606
#if defined(Rel10) || defined(Rel14)
3607
                                         , ue_context_pP->ue_context.sCell_config
3608
#endif
3609
                                        );
3610 3611 3612
  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);

3613
  MSC_LOG_TX_MESSAGE(
3614 3615 3616 3617 3618 3619 3620 3621 3622
    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);
3623

3624 3625 3626 3627 3628 3629 3630 3631
  rrc_data_req(
	       ctxt_pP,
	       DCCH,
	       rrc_eNB_mui++,
	       SDU_CONFIRM_NO,
	       size,
	       buffer,
	       PDCP_TRANSMISSION_MODE_CONTROL);
3632 3633 3634 3635
  return(0);
}


3636 3637 3638 3639 3640 3641 3642 3643
//-----------------------------------------------------------------------------
void
rrc_eNB_process_MeasurementReport(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t*          const ue_context_pP,
  const MeasResults_t*   const measResults2
)
//-----------------------------------------------------------------------------
3644
{
Cedric Roux's avatar
Cedric Roux committed
3645 3646 3647
  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));

3648

3649 3650
  LOG_I(RRC, "[eNB %d] Frame %d: Process Measurement Report From UE %x (Measurement Id %d)\n",
        ctxt_pP->module_id, ctxt_pP->frame, ctxt_pP->rnti, (int)measResults2->measId);
3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662

  if (measResults2->measResultNeighCells->choice.measResultListEUTRA.list.count > 0) {
    LOG_I(RRC, "Physical Cell Id %d\n",
          (int)measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[0]->physCellId);
    LOG_I(RRC, "RSRP of Target %d\n",
          (int)*(measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[0]->
                 measResult.rsrpResult));
    LOG_I(RRC, "RSRQ of Target %d\n",
          (int)*(measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[0]->
                 measResult.rsrqResult));
  }

Cedric Roux's avatar
Cedric Roux committed
3663
#if defined(Rel10) || defined(Rel14)
Cedric Roux's avatar
Cedric Roux committed
3664 3665
  LOG_I(RRC, "RSRP of Source %ld\n", measResults2->measResultPCell.rsrpResult);
  LOG_I(RRC, "RSRQ of Source %ld\n", measResults2->measResultPCell.rsrqResult);
winckel's avatar
winckel committed
3666
#else
3667 3668
  LOG_I(RRC, "RSRP of Source %ld\n", measResults2->measResultServCell.rsrpResult);
  LOG_I(RRC, "RSRQ of Source %ld\n", measResults2->measResultServCell.rsrqResult);
3669 3670
#endif

3671 3672 3673
  if (ue_context_pP->ue_context.handover_info->ho_prepare != 0xF0) {
    rrc_eNB_generate_HandoverPreparationInformation(ctxt_pP,
        ue_context_pP,
3674 3675 3676
        measResults2->measResultNeighCells->choice.
        measResultListEUTRA.list.array[0]->physCellId);
  } else {
3677 3678
    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);
3679
  }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3680

3681 3682 3683 3684
  //Look for IP address of the target eNB
  //Send Handover Request -> target eNB
  //Wait for Handover Acknowledgement <- target eNB
  //Send Handover Command
3685

3686 3687
  //x2delay();
  //    handover_request_x2(ue_mod_idP,enb_mod_idP,measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[0]->physCellId);
3688

3689 3690 3691 3692 3693
  //    uint8_t buffer[100];
  //    int size=rrc_eNB_generate_Handover_Command_TeNB(0,0,buffer);
  //
  //      send_check_message((char*)buffer,size);
  //send_handover_command();
3694

3695 3696
}

3697 3698 3699 3700 3701 3702 3703 3704
//-----------------------------------------------------------------------------
void
rrc_eNB_generate_HandoverPreparationInformation(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t* const ue_context_pP,
  PhysCellId_t                 targetPhyId
)
//-----------------------------------------------------------------------------
3705
{
3706 3707
  struct rrc_eNB_ue_context_s*        ue_context_target_p = NULL;
  //uint8_t                             UE_id_target        = -1;
3708 3709 3710 3711 3712
  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;
3713
     struct PhysicalConfigDedicated  **physicalConfigDedicated = &RC.rrc[enb_mod_idP]->physicalConfigDedicated[ue_mod_idP];
3714 3715
     RadioResourceConfigDedicated_t *radioResourceConfigDedicated = CALLOC(1,sizeof(RadioResourceConfigDedicated_t));
   */
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3716

Cedric Roux's avatar
Cedric Roux committed
3717 3718 3719
  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));

3720 3721 3722 3723
  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,
3724
         (void*)&RC.rrc[ctxt_pP->module_id]->carrier[0] /* CROUX TBC */.mib, sizeof(MasterInformationBlock_t));
3725
  memcpy((void *)&handoverInfo->as_config.sourceMeasConfig,
3726
         (void*)ue_context_pP->ue_context.measConfig, sizeof(MeasConfig_t));
3727 3728 3729 3730 3731 3732

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

  //to be configured
3733
  memset((void*)&ue_context_pP->ue_context.handover_info->as_config.sourceSecurityAlgorithmConfig,
3734 3735
         0, sizeof(SecurityAlgorithmConfig_t));

3736
  memcpy((void*)&ue_context_pP->ue_context.handover_info->as_config.sourceSystemInformationBlockType1,
3737
         (void*)&RC.rrc[ctxt_pP->module_id]->carrier[0] /* CROUX TBC */.SIB1, sizeof(SystemInformationBlockType1_t));
3738
  memcpy((void*)&ue_context_pP->ue_context.handover_info->as_config.sourceSystemInformationBlockType2,
3739
         (void*)&RC.rrc[ctxt_pP->module_id]->carrier[0] /* CROUX TBC */.SIB23, sizeof(SystemInformationBlockType2_t));
3740
  ue_context_pP->ue_context.handover_info->as_context.reestablishmentInfo =
3741
    CALLOC(1, sizeof(ReestablishmentInfo_t));
3742
  ue_context_pP->ue_context.handover_info->as_context.reestablishmentInfo->sourcePhysCellId =
3743
    RC.rrc[ctxt_pP->module_id]->carrier[0] /* CROUX TBC */.physCellId;
3744 3745 3746 3747 3748 3749
  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;
3750 3751 3752

  if (mod_id_target != 0xFF) {
    //UE_id_target = rrc_find_free_ue_index(modid_target);
3753 3754
    ue_context_target_p =
      rrc_eNB_get_ue_context(
3755
        RC.rrc[mod_id_target],
3756 3757 3758 3759
        ue_context_pP->ue_context.rnti);

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

    if (ue_context_target_p == NULL) { // if not already in target cell
3763
      ue_context_target_p = rrc_eNB_allocate_new_UE_context(RC.rrc[ctxt_pP->module_id]);
3764 3765
      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
3766
      LOG_N(RRC,
Cedric Roux's avatar
Cedric Roux committed
3767
            "[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",
3768 3769
            ctxt_pP->module_id,
            ctxt_pP->frame,
3770
            RC.rrc[ctxt_pP->module_id]->carrier[0] /* CROUX TBC */.physCellId,
3771 3772 3773 3774
            targetPhyId,
            ue_context_pP->ue_context.rnti,
            ue_context_target_p->ue_id_rnti,
            ctxt_pP->module_id,
3775
            mod_id_target);
3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793
      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
3794
      LOG_E(RRC, "\nError in obtaining free UE id in target eNB %ld for handover \n", targetPhyId);
3795 3796 3797
    }

  } else {
3798
    LOG_E(RRC, "\nError in obtaining Module ID of target eNB for handover \n");
3799
  }
3800 3801
}

3802 3803 3804 3805 3806 3807 3808
//-----------------------------------------------------------------------------
void
rrc_eNB_process_handoverPreparationInformation(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t*           const ue_context_pP
)
//-----------------------------------------------------------------------------
3809
{
Cedric Roux's avatar
Cedric Roux committed
3810 3811 3812
  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));

3813

3814 3815
  LOG_I(RRC,
        "[eNB %d] Frame %d : Logical Channel UL-DCCH, processing RRCHandoverPreparationInformation, sending RRCConnectionReconfiguration to UE %d \n",
3816 3817 3818 3819 3820 3821
        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
3822
}
3823

3824 3825 3826 3827 3828

//-----------------------------------------------------------------------------
void
check_handovers(
  protocol_ctxt_t* const ctxt_pP
3829
)
3830
//-----------------------------------------------------------------------------
3831
{
3832
  int                                 result;
3833
  struct rrc_eNB_ue_context_s*        ue_context_p;
3834
  RB_FOREACH(ue_context_p, rrc_ue_tree_s, &RC.rrc[ctxt_pP->module_id]->rrc_ue_head) {
3835
    ctxt_pP->rnti  = ue_context_p->ue_id_rnti;
3836

3837 3838
    if (ue_context_p->ue_context.handover_info != NULL) {
      if (ue_context_p->ue_context.handover_info->ho_prepare == 0xFF) {
3839 3840
        LOG_D(RRC,
              "[eNB %d] Frame %d: Incoming handover detected for new UE_idx %d (source eNB %d->target eNB %d) \n",
3841 3842 3843 3844 3845
              ctxt_pP->module_id,
              ctxt_pP->frame,
              ctxt_pP->rnti,
              ctxt_pP->module_id,
              ue_context_p->ue_context.handover_info->modid_t);
3846
        // source eNB generates rrcconnectionreconfiguration to prepare the HO
3847 3848 3849 3850
        rrc_eNB_process_handoverPreparationInformation(
          ctxt_pP,
          ue_context_p);
        ue_context_p->ue_context.handover_info->ho_prepare = 0xF1;
3851 3852
      }

3853
      if (ue_context_p->ue_context.handover_info->ho_complete == 0xF1) {
3854
        LOG_D(RRC,
3855 3856 3857 3858 3859 3860
              "[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);
3861
        //rrc_eNB_process_handoverPreparationInformation(enb_mod_idP,frameP,i);
3862
        result = pdcp_data_req(ctxt_pP,
3863 3864 3865
                               SRB_FLAG_YES,
                               DCCH,
                               rrc_eNB_mui++,
3866 3867 3868 3869
                               SDU_CONFIRM_NO,
                               ue_context_p->ue_context.handover_info->size,
                               ue_context_p->ue_context.handover_info->buf,
                               PDCP_TRANSMISSION_MODE_CONTROL);
3870
        AssertFatal(result == TRUE, "PDCP data request failed!\n");
3871
        ue_context_p->ue_context.handover_info->ho_complete = 0xF2;
3872
      }
winckel's avatar
winckel committed
3873
    }
3874
  }
3875
}
winckel's avatar
RRC:  
winckel committed
3876

winckel's avatar
winckel committed
3877
// 5.3.5.4 RRCConnectionReconfiguration including the mobilityControlInfo to prepare the UE handover
3878 3879 3880 3881 3882 3883 3884 3885 3886
//-----------------------------------------------------------------------------
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
)
//-----------------------------------------------------------------------------
3887
{
Cedric Roux's avatar
Cedric Roux committed
3888 3889 3890
  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
3891

3892 3893 3894 3895 3896 3897
  uint8_t                             buffer[RRC_BUF_SIZE];
  uint16_t                            size;
  int                                 i;
  uint8_t                             rv[2];
  uint16_t                            Idx;
  // configure SRB1/SRB2, PhysicalConfigDedicated, MAC_MainConfig for UE
3898
  eNB_RRC_INST*                       rrc_inst = RC.rrc[ctxt_pP->module_id];
3899
  struct PhysicalConfigDedicated**    physicalConfigDedicated = &ue_context_pP->ue_context.physicalConfigDedicated;
3900 3901 3902 3903 3904 3905

  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;
3906
  SRB_ToAddModList_t*                 SRB_configList = ue_context_pP->ue_context.SRB_configList;    // not used in this context: may be removed
3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927
  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;
3928 3929
  //uint8_t                             sourceModId =
  //  get_adjacent_cell_mod_id(ue_context_pP->ue_context.handover_info->as_context.reestablishmentInfo->sourcePhysCellId);
Cedric Roux's avatar
Cedric Roux committed
3930
#if defined(Rel10) || defined(Rel14)
3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949
  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
3950

3951 3952
  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
3953

3954 3955 3956 3957
  for (i = 0; i < 2; i++) {
    rv[i] = taus() & 0xff;
    LOG_D(RRC, " %x.", rv[i]);
  }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3958

3959
  LOG_D(RRC, "[eNB %d] Frame %d : handover reparation: add target eNB SRB1 and PHYConfigDedicated reconfiguration\n",
3960
        ctxt_pP->module_id, ctxt_pP->frame);
3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017
  // 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
4018
  physicalConfigDedicated2->soundingRS_UL_ConfigDedicated = CALLOC(1,sizeof(*physicalConfigDedicated2->soundingRS_UL_ConfigDedicated));
4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058
  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;
4059
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_RNTI.buf[1] = 0x34 + ue_context_pP->local_uid;
4060 4061 4062 4063 4064 4065 4066 4067
  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;
4068
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_RNTI.buf[1] = 0x34 + ue_context_pP->local_uid;
4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086
  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
4087

4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101
  //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
4102

4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132
  //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;
4133
  physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_PUCCH_ResourceIndex = ue_context_pP->local_uid;
4134

4135
  if (rrc_inst->carrier[0].sib1->tdd_Config==NULL) {  // FD
4136 4137
    physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_ConfigIndex = 5 + (ue_context_pP->local_uid %
        10);   // Isr = 5 (every 10 subframes, offset=2+UE_id mod3)
4138
  } else {
4139
    switch (rrc_inst->carrier[0].sib1->tdd_Config->subframeAssignment) {
4140
    case 1:
4141 4142
      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..)
4143 4144 4145
      break;

    case 3:
4146 4147
      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..)
4148 4149 4150
      break;

    case 4:
4151 4152
      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..)
4153 4154 4155 4156 4157
      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
4158
    }
4159
  }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4160

4161 4162 4163 4164 4165 4166 4167
  //  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,
4168 4169
        "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);
4170 4171 4172
  rrc_mac_config_req_eNB(
			 ctxt_pP->module_id,
			 ue_context_pP->ue_context.primaryCC_id,
4173 4174 4175 4176
			 0,0,0,0,0,
#ifdef Rel14 
0,
#endif 
4177
			 ue_context_pP->ue_context.rnti,
4178 4179
			 (BCCH_BCH_Message_t *) NULL,
			 (RadioResourceConfigCommonSIB_t*) NULL,
4180 4181
			 (RadioResourceConfigCommonSIB_t*) NULL,
			 ue_context_pP->ue_context.physicalConfigDedicated,
Cedric Roux's avatar
Cedric Roux committed
4182
#if defined(Rel10) || defined(Rel14)
4183 4184
			 (SCellToAddMod_r10_t *)NULL,
			 //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
4185
#endif
4186 4187 4188 4189 4190 4191 4192
			 (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,
4193
			 (SchedulingInfoList_t*) NULL,
4194 4195 4196 4197
			 0,
			 NULL,
			 NULL,
			 (MBSFN_SubframeConfigList_t *) NULL
Cedric Roux's avatar
Cedric Roux committed
4198
#if defined(Rel10) || defined(Rel14)
4199
			 , 0, (MBSFN_AreaInfoList_r9_t *) NULL, (PMCH_InfoList_r9_t *) NULL
4200
#endif
4201 4202 4203 4204
#   ifdef Rel14
			 ,
			 (SystemInformationBlockType1_v1310_IEs_t *)NULL
#   endif
4205 4206
			 );
  
4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224
  // 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
4225

4226 4227
  SRB2_lchan_config = CALLOC(1, sizeof(*SRB2_lchan_config));
  SRB2_config->logicalChannelConfig = SRB2_lchan_config;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4228

4229
  SRB2_lchan_config->present = SRB_ToAddMod__logicalChannelConfig_PR_explicitValue;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4230

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

4233 4234 4235 4236 4237
  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
4238

4239 4240 4241
  // 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
4242

4243 4244 4245 4246
  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
4247

4248 4249 4250 4251
  // 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
4252

4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263
  //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
4264

4265 4266 4267 4268 4269 4270 4271 4272
  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
4273

4274 4275 4276 4277
  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
4278

4279 4280 4281 4282 4283
  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
4284

4285 4286 4287 4288
  // 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
4289

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

4292
  mac_MainConfig = CALLOC(1, sizeof(*mac_MainConfig));
4293
  ue_context_pP->ue_context.mac_MainConfig = mac_MainConfig;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4294

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

4297 4298 4299
  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
4300

4301
  periodicBSR_Timer = CALLOC(1, sizeof(long));
Cedric Roux's avatar
Cedric Roux committed
4302
  *periodicBSR_Timer = PeriodicBSR_Timer_r12_sf64;
4303
  mac_MainConfig->ul_SCH_Config->periodicBSR_Timer = periodicBSR_Timer;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4304

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

4307 4308 4309
  mac_MainConfig->ul_SCH_Config->ttiBundling = 0; // FALSE

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

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

4313 4314
  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
4315

4316
  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
4317

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

Cedric Roux's avatar
Cedric Roux committed
4320
#if defined(Rel10) || defined(Rel14)
4321 4322
  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
4323 4324
  mac_MainConfig->ext1 = CALLOC(1, sizeof(struct MAC_MainConfig__ext1));
  mac_MainConfig->ext1->sr_ProhibitTimer_r9 = sr_ProhibitTimer_r9;
4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396
  //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;
4397
    CellToAdd->physCellId = get_adjacent_cell_id(ctxt_pP->module_id, i);
4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561
    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 =
4562
    (PhysCellId_t) two_tier_hexagonal_cellIds[ue_context_pP->ue_context.handover_info->modid_t];
Cedric Roux's avatar
Cedric Roux committed
4563
  LOG_D(RRC, "[eNB %d] Frame %d: handover preparation: targetPhysCellId: %ld mod_id: %d ue: %x \n",
4564 4565 4566 4567 4568
        ctxt_pP->module_id,
        ctxt_pP->frame,
        mobilityInfo->targetPhysCellId,
        ctxt_pP->module_id,
        ue_context_pP->ue_context.rnti);
4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588

  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,
4589
         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.rach_ConfigCommon, sizeof(RACH_ConfigCommon_t));
4590 4591 4592
  mobilityInfo->radioResourceConfigCommon.prach_Config.prach_ConfigInfo =
    CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.prach_Config.prach_ConfigInfo));
  memcpy((void *)mobilityInfo->radioResourceConfigCommon.prach_Config.prach_ConfigInfo,
4593
         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.prach_Config.prach_ConfigInfo,
4594 4595 4596
         sizeof(PRACH_ConfigInfo_t));

  mobilityInfo->radioResourceConfigCommon.prach_Config.rootSequenceIndex =
4597
    rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.prach_Config.rootSequenceIndex;
4598 4599 4600
  mobilityInfo->radioResourceConfigCommon.pdsch_ConfigCommon =
    CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.pdsch_ConfigCommon));
  memcpy((void *)mobilityInfo->radioResourceConfigCommon.pdsch_ConfigCommon,
4601
         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.pdsch_ConfigCommon, sizeof(PDSCH_ConfigCommon_t));
4602
  memcpy((void *)&mobilityInfo->radioResourceConfigCommon.pusch_ConfigCommon,
4603
         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.pusch_ConfigCommon, sizeof(PUSCH_ConfigCommon_t));
4604 4605 4606 4607
  mobilityInfo->radioResourceConfigCommon.phich_Config = NULL;
  mobilityInfo->radioResourceConfigCommon.pucch_ConfigCommon =
    CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.pucch_ConfigCommon));
  memcpy((void *)mobilityInfo->radioResourceConfigCommon.pucch_ConfigCommon,
4608
         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.pucch_ConfigCommon, sizeof(PUCCH_ConfigCommon_t));
4609 4610 4611
  mobilityInfo->radioResourceConfigCommon.soundingRS_UL_ConfigCommon =
    CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.soundingRS_UL_ConfigCommon));
  memcpy((void *)mobilityInfo->radioResourceConfigCommon.soundingRS_UL_ConfigCommon,
4612
         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon,
4613 4614 4615 4616
         sizeof(SoundingRS_UL_ConfigCommon_t));
  mobilityInfo->radioResourceConfigCommon.uplinkPowerControlCommon =
    CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.uplinkPowerControlCommon));
  memcpy((void *)mobilityInfo->radioResourceConfigCommon.uplinkPowerControlCommon,
4617
         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.uplinkPowerControlCommon,
4618 4619 4620 4621 4622 4623 4624
         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 =
4625
    rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.ul_CyclicPrefixLength;
4626 4627 4628 4629 4630 4631
  //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;

4632 4633
  mobilityInfo->carrierBandwidth = CALLOC(1, sizeof(
      *mobilityInfo->carrierBandwidth));    //CALLOC(1,sizeof(struct CarrierBandwidthEUTRA));  AllowedMeasBandwidth_mbw25
4634 4635 4636 4637 4638 4639
  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

4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652
  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));
4653 4654 4655 4656
  /*    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
4657 4658
  LOG_I(RRC, "[eNB %d] Frame %d: adding new UE\n",
        ctxt_pP->module_id, ctxt_pP->frame);
4659 4660 4661
  //Idx = (ue_mod_idP * NB_RB_MAX) + DCCH;
  Idx = DCCH;
  // SRB1
4662 4663 4664 4665
  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);
4666

4667
  // SRB2 
4668 4669 4670 4671
  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);
4672

4673 4674
  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);
4675 4676 4677 4678 4679

  //      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,
4680
                           ue_context_pP->ue_context.SRB_configList,
4681
                           (DRB_ToAddModList_t *) NULL, (DRB_ToReleaseList_t *) NULL, 0xff, NULL, NULL, NULL
Cedric Roux's avatar
Cedric Roux committed
4682
#if defined(Rel10) || defined(Rel14)
4683
                           , (PMCH_InfoList_r9_t *) NULL
winckel's avatar
winckel committed
4684
#endif
4685
                           ,NULL);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4686

4687
  rrc_rlc_config_asn1_req(&ctxt,
4688
                          ue_context_pP->ue_context.SRB_configList,
4689
                          (DRB_ToAddModList_t *) NULL, (DRB_ToReleaseList_t *) NULL
Cedric Roux's avatar
Cedric Roux committed
4690
#if defined(Rel10) || defined(Rel14)
4691
                          , (PMCH_InfoList_r9_t *) NULL
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4692
#endif
4693
                         );
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4694

4695 4696
  /* Initialize NAS list */
  dedicatedInfoNASList = NULL;
4697

4698 4699 4700
  //  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->reportConfigToAddModList = ReportConfig_list;
  memset(buffer, 0, RRC_BUF_SIZE);

4701 4702 4703 4704 4705 4706 4707
  size = do_RRCConnectionReconfiguration(
           ctxt_pP,
           buffer,
           rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),   //Transaction_id,
           SRB_configList2,
           DRB_configList2,
           NULL,  // DRB2_list,
4708
           NULL,    //*sps_Config,
4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720
           ue_context_pP->ue_context.physicalConfigDedicated,
           MeasObj_list,
           ReportConfig_list,
           NULL,    //quantityConfig,
           MeasId_list,
           mac_MainConfig,
           NULL,
           mobilityInfo,
           Sparams,
           NULL,
           NULL,
           dedicatedInfoNASList
Cedric Roux's avatar
Cedric Roux committed
4721
#if defined(Rel10) || defined(Rel14)
4722
           , NULL   // SCellToAddMod_r10_t
4723
#endif
4724
         );
4725 4726

  LOG_I(RRC,
4727 4728
        "[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);
4729
  // to be updated if needed
4730 4731 4732
  /*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;
4733 4734 4735 4736 4737 4738 4739 4740 4741
     }
     else {
     SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
     }
     }
     else {
     SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
     }
   */
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4742

4743
  LOG_D(RRC,
4744 4745 4746 4747
        "[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);
4748

4749 4750 4751
  rrc_mac_config_req_eNB(
			 ctxt_pP->module_id,
			 ue_context_pP->ue_context.primaryCC_id,
4752 4753 4754 4755
			 0,0,0,0,0,
#ifdef Rel14 
			 0,
#endif
4756
			 ue_context_pP->ue_context.rnti,
4757 4758
			 (BCCH_BCH_Message_t *) NULL,
			 (RadioResourceConfigCommonSIB_t *) NULL,
4759 4760
			 (RadioResourceConfigCommonSIB_t *) NULL,
			 ue_context_pP->ue_context.physicalConfigDedicated,
Cedric Roux's avatar
Cedric Roux committed
4761
#if defined(Rel10) || defined(Rel14)
4762 4763
			 (SCellToAddMod_r10_t *)NULL,
			 //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
4764
#endif
4765 4766 4767 4768 4769 4770 4771
			 (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,
4772
			 (SchedulingInfoList_t *) NULL, 0, NULL, NULL, (MBSFN_SubframeConfigList_t *) NULL
Cedric Roux's avatar
Cedric Roux committed
4773
#if defined(Rel10) || defined(Rel14)
4774
			 , 0, (MBSFN_AreaInfoList_r9_t *) NULL, (PMCH_InfoList_r9_t *) NULL
4775
#endif
4776 4777 4778 4779
#   ifdef Rel14
			 ,
			 (SystemInformationBlockType1_v1310_IEs_t *)NULL
#   endif
4780 4781
			 );
  
4782 4783 4784 4785 4786 4787
  /*
     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;
   */
4788
//#warning "COMPILATION PROBLEM"
4789
#ifdef PROBLEM_COMPILATION_RESOLVED
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4790

4791
  if (sourceModId != 0xFF) {
4792
    memcpy(RC.rrc[sourceModId].handover_info[RC.rrc[ctxt_pP->module_id]->handover_info[ue_mod_idP]->ueid_s]->buf,
4793
           (void *)buffer, size);
4794 4795
    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 =
4796
      0xF1;
4797
    //RC.rrc[ctxt_pP->module_id]->handover_info[ue_mod_idP]->ho_complete = 0xFF;
4798
    LOG_D(RRC, "[eNB %d] Frame %d: setting handover complete to 0xF1 for (%d,%d) and to 0xFF for (%d,%d)\n",
4799 4800 4801
          ctxt_pP->module_id,
          ctxt_pP->frame,
          sourceModId,
4802
          RC.rrc[ctxt_pP->module_id]->handover_info[ue_mod_idP]->ueid_s,
4803 4804
          ctxt_pP->module_id,
          ue_mod_idP);
4805 4806 4807
  } else
    LOG_W(RRC,
          "[eNB %d] Frame %d: rrc_eNB_generate_RRCConnectionReconfiguration_handover: Could not find source eNB mod_id.\n",
4808
          ctxt_pP->module_id, ctxt_pP->frame);
4809

4810
#endif
winckel's avatar
winckel committed
4811
}
4812

winckel's avatar
winckel committed
4813
/*
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4814
  void ue_rrc_process_rrcConnectionReconfiguration(uint8_t enb_mod_idP,frame_t frameP,
winckel's avatar
winckel committed
4815
  RRCConnectionReconfiguration_t *rrcConnectionReconfiguration,
4816
  uint8_t CH_index) {
4817

winckel's avatar
winckel committed
4818 4819
  if (rrcConnectionReconfiguration->criticalExtensions.present == RRCConnectionReconfiguration__criticalExtensions_PR_c1)
  if (rrcConnectionReconfiguration->criticalExtensions.choice.c1.present == RRCConnectionReconfiguration__criticalExtensions__c1_PR_rrcConnectionReconfiguration_r8) {
4820

winckel's avatar
winckel committed
4821
  if (rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated) {
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4822
  rrc_ue_process_radioResourceConfigDedicated(enb_mod_idP,frameP,CH_index,
winckel's avatar
winckel committed
4823
  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated);
4824

winckel's avatar
winckel committed
4825 4826 4827 4828 4829 4830 4831
  }

  // check other fields for
  }
  }
*/

4832 4833 4834 4835
//-----------------------------------------------------------------------------
void
rrc_eNB_process_RRCConnectionReconfigurationComplete(
  const protocol_ctxt_t* const ctxt_pP,
4836 4837
  rrc_eNB_ue_context_t*        ue_context_pP,
  const uint8_t xid
4838 4839
)
//-----------------------------------------------------------------------------
4840
{
4841
  int                                 i, drb_id;
4842
#ifdef PDCP_USE_NETLINK
4843 4844
  int                                 oip_ifup = 0;
  int                                 dest_ip_offset = 0;
4845
  module_id_t                         ue_module_id   = -1;
Cedric Roux's avatar
Cedric Roux committed
4846 4847 4848 4849
  /* avoid gcc warnings */
  (void)oip_ifup;
  (void)dest_ip_offset;
  (void)ue_module_id;
winckel's avatar
winckel committed
4850 4851
#endif

4852 4853 4854
  uint8_t                            *kRRCenc = NULL;
  uint8_t                            *kRRCint = NULL;
  uint8_t                            *kUPenc = NULL;
4855
  ue_context_pP->ue_context.ue_reestablishment_timer = 0;
winckel's avatar
winckel committed
4856

4857 4858
  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];
4859 4860
  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
4861

Cedric Roux's avatar
Cedric Roux committed
4862 4863 4864
  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
4865 4866
#if defined(ENABLE_SECURITY)

4867 4868
  /* Derive the keys from kenb */
  if (DRB_configList != NULL) {
4869 4870
    derive_key_up_enc(ue_context_pP->ue_context.ciphering_algorithm,
                      ue_context_pP->ue_context.kenb, &kUPenc);
4871 4872
  }

4873 4874 4875 4876
  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);
4877

winckel's avatar
winckel committed
4878
#endif
4879 4880

  // Refresh SRBs/DRBs
Lionel Gauthier's avatar
Lionel Gauthier committed
4881 4882 4883 4884 4885 4886 4887 4888 4889
  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);

4890
  rrc_pdcp_config_asn1_req(
4891
    ctxt_pP,
Navid Nikaein's avatar
Navid Nikaein committed
4892
    SRB_configList, //NULL,  //LG-RK 14/05/2014 SRB_configList,
4893
    DRB_configList, 
4894 4895
//    (DRB_ToReleaseList_t *) NULL,
    DRB_Release_configList2,
4896 4897
    /*RC.rrc[ctxt_pP->module_id]->ciphering_algorithm[ue_mod_idP] |
             (RC.rrc[ctxt_pP->module_id]->integrity_algorithm[ue_mod_idP] << 4),
4898 4899 4900 4901 4902
     */
    0xff, // already configured during the securitymodecommand
    kRRCenc,
    kRRCint,
    kUPenc
Cedric Roux's avatar
Cedric Roux committed
4903
#if defined(Rel10) || defined(Rel14)
4904 4905
    , (PMCH_InfoList_r9_t *) NULL
#endif
4906
    ,NULL);
4907 4908
  // Refresh SRBs/DRBs
  rrc_rlc_config_asn1_req(
4909
    ctxt_pP,
Navid Nikaein's avatar
Navid Nikaein committed
4910
    SRB_configList, // NULL,  //LG-RK 14/05/2014 SRB_configList,
4911
    DRB_configList,
4912 4913
//    (DRB_ToReleaseList_t *) NULL
    DRB_Release_configList2
Cedric Roux's avatar
Cedric Roux committed
4914
#if defined(Rel10) || defined(Rel14)
4915
    , (PMCH_InfoList_r9_t *) NULL
winckel's avatar
winckel committed
4916
#endif
4917
  );
4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932
  
  // 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
4933
	LOG_W(RRC,"[eNB %d] Frame  %d CC %d : invalide SRB identity %ld\n",
4934 4935
	      ctxt_pP->module_id,
	      ctxt_pP->frame,
Cedric Roux's avatar
Cedric Roux committed
4936
              ue_context_pP->ue_context.primaryCC_id,
4937 4938 4939
	      SRB_configList->list.array[i]->srb_Identity);
      }
    }
4940 4941
    free(SRB_configList);
    ue_context_pP->ue_context.SRB_configList2[xid] = NULL;
4942 4943
  }
  
4944
  // Loop through DRBs and establish if necessary
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4945

4946 4947 4948
  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]) {
4949
	drb_id = (int)DRB_configList->list.array[i]->drb_Identity;
4950
        LOG_I(RRC,
4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962
              "[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],
4963
              (int)DRB_configList->list.array[i]->drb_Identity,
4964
              (int)*DRB_configList->list.array[i]->logicalChannelIdentity);
4965

4966
        if (ue_context_pP->ue_context.DRB_active[drb_id] == 0) {
4967
          /*
4968
             rrc_pdcp_config_req (ctxt_pP->module_id, frameP, 1, CONFIG_ACTION_ADD,
4969
             (ue_mod_idP * NB_RB_MAX) + *DRB_configList->list.array[i]->logicalChannelIdentity,UNDEF_SECURITY_MODE);
4970
             rrc_rlc_config_req(ctxt_pP->module_id,frameP,1,CONFIG_ACTION_ADD,
4971
             (ue_mod_idP * NB_RB_MAX) + (int)*RC.rrc[ctxt_pP->module_id]->DRB_config[ue_mod_idP][i]->logicalChannelIdentity,
4972 4973
             RADIO_ACCESS_BEARER,Rlc_info_um);
           */
4974
          ue_context_pP->ue_context.DRB_active[drb_id] = 1;
4975 4976 4977

          LOG_D(RRC,
                "[eNB %d] Frame %d: Establish RLC UM Bidirectional, DRB %d Active\n",
4978 4979
                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)
4980
          // can mean also IPV6 since ether -> ipv6 autoconf
4981
#   if !defined(OAI_NW_DRIVER_TYPE_ETHERNET) && !defined(EXMIMO) && !defined(OAI_USRP) && !defined(OAI_BLADERF) && !defined(ETHERNET)
4982 4983 4984
          LOG_I(OIP, "[eNB %d] trying to bring up the OAI interface oai%d\n",
                ctxt_pP->module_id,
                ctxt_pP->module_id);
4985
          oip_ifup = nas_config(
4986 4987 4988
                       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
4989

4990
          if (oip_ifup == 0) {    // interface is up --> send a config the DRB
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4991
#      ifdef OAI_EMU
4992
            oai_emulation.info.oai_ifup[ctxt_pP->module_id] = 1;
4993
            dest_ip_offset = NB_eNB_INST;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4994
#      else
4995
            dest_ip_offset = 8;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4996
#      endif
4997
            LOG_I(OIP,
4998
                  "[eNB %d] Config the oai%d to send/receive pkt on DRB %ld to/from the protocol stack\n",
4999
                  ctxt_pP->module_id, ctxt_pP->module_id,
5000
                  (long int)((ue_context_pP->local_uid * maxDRB) + DRB_configList->list.array[i]->drb_Identity));
5001
            ue_module_id = oai_emulation.info.eNB_ue_local_uid_to_ue_module_id[ctxt_pP->module_id][ue_context_pP->local_uid];
5002
            rb_conf_ipv4(0, //add
5003 5004 5005
                         ue_module_id,  //cx
                         ctxt_pP->module_id,    //inst
                         (ue_module_id * maxDRB) + DRB_configList->list.array[i]->drb_Identity, // RB
5006
                         0,    //dscp
5007 5008 5009 5010
                         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);
5011 5012
          }

Lionel Gauthier's avatar
 
Lionel Gauthier committed
5013 5014
#   else
#      ifdef OAI_EMU
5015
          oai_emulation.info.oai_ifup[ctxt_pP->module_id] = 1;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
5016 5017 5018 5019
#      endif
#   endif
#endif

5020
          LOG_D(RRC,
5021 5022
                PROTOCOL_RRC_CTXT_UE_FMT" RRC_eNB --- MAC_CONFIG_REQ  (DRB) ---> MAC_eNB\n",
                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
5023

5024
          if (DRB_configList->list.array[i]->logicalChannelIdentity) {
5025
            DRB2LCHAN[i] = (uint8_t) * DRB_configList->list.array[i]->logicalChannelIdentity;
5026
          }
5027

5028 5029 5030
          rrc_mac_config_req_eNB(
				 ctxt_pP->module_id,
				 ue_context_pP->ue_context.primaryCC_id,
5031 5032 5033 5034
				 0,0,0,0,0,
#ifdef Rel14 
				 0,
#endif
5035
				 ue_context_pP->ue_context.rnti,
5036 5037
				 (BCCH_BCH_Message_t *) NULL,
				 (RadioResourceConfigCommonSIB_t *) NULL,
5038 5039
				 (RadioResourceConfigCommonSIB_t *) NULL,
				 ue_context_pP->ue_context.physicalConfigDedicated,
Cedric Roux's avatar
Cedric Roux committed
5040
#if defined(Rel10) || defined(Rel14)
5041 5042
				 (SCellToAddMod_r10_t *)NULL,
				 //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
5043
#endif
5044 5045 5046 5047 5048 5049 5050
				 (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,
5051 5052
				 (SchedulingInfoList_t *) NULL,
				 0, NULL, NULL, (MBSFN_SubframeConfigList_t *) NULL
Cedric Roux's avatar
Cedric Roux committed
5053
#if defined(Rel10) || defined(Rel14)
5054
				 , 0, (MBSFN_AreaInfoList_r9_t *) NULL, (PMCH_InfoList_r9_t *) NULL
winckel's avatar
winckel committed
5055
#endif
5056 5057 5058 5059
#   ifdef Rel14
				 ,
				 (SystemInformationBlockType1_v1310_IEs_t *)NULL
#   endif
5060 5061
				 );
	  
5062 5063
        } else {        // remove LCHAN from MAC/PHY

5064
          if (ue_context_pP->ue_context.DRB_active[drb_id] == 1) {
5065
            // DRB has just been removed so remove RLC + PDCP for DRB
5066
            /*      rrc_pdcp_config_req (ctxt_pP->module_id, frameP, 1, CONFIG_ACTION_REMOVE,
5067 5068 5069
               (ue_mod_idP * NB_RB_MAX) + DRB2LCHAN[i],UNDEF_SECURITY_MODE);
             */
            rrc_rlc_config_req(
5070
              ctxt_pP,
5071 5072 5073 5074 5075 5076 5077
              SRB_FLAG_NO,
              MBMS_FLAG_NO,
              CONFIG_ACTION_REMOVE,
              DRB2LCHAN[i],
              Rlc_info_um);
          }

5078
          ue_context_pP->ue_context.DRB_active[drb_id] = 0;
5079
          LOG_D(RRC,
5080 5081
                PROTOCOL_RRC_CTXT_UE_FMT" RRC_eNB --- MAC_CONFIG_REQ  (DRB) ---> MAC_eNB\n",
                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
5082 5083
          rrc_mac_config_req_eNB(ctxt_pP->module_id,
				 ue_context_pP->ue_context.primaryCC_id,
5084 5085 5086 5087
				 0,0,0,0,0,
#ifdef Rel14 
				 0,
#endif
5088
				 ue_context_pP->ue_context.rnti,
5089 5090
				 (BCCH_BCH_Message_t *) NULL,
				 (RadioResourceConfigCommonSIB_t *) NULL,
5091 5092
				 (RadioResourceConfigCommonSIB_t *) NULL,
				 ue_context_pP->ue_context.physicalConfigDedicated,
Cedric Roux's avatar
Cedric Roux committed
5093
#if defined(Rel10) || defined(Rel14)
5094 5095
				 (SCellToAddMod_r10_t *)NULL,
				 //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
5096
#endif
5097 5098 5099 5100 5101 5102
				 (MeasObjectToAddMod_t **) NULL,
				 ue_context_pP->ue_context.mac_MainConfig,
				 DRB2LCHAN[i],
				 (LogicalChannelConfig_t *) NULL,
				 (MeasGapConfig_t *) NULL,
				 (TDD_Config_t *) NULL,
5103 5104 5105
				 NULL, 
				 (SchedulingInfoList_t *) NULL,
				 0, NULL, NULL, NULL
Cedric Roux's avatar
Cedric Roux committed
5106
#if defined(Rel10) || defined(Rel14)
5107
				 , 0, (MBSFN_AreaInfoList_r9_t *) NULL, (PMCH_InfoList_r9_t *) NULL
winckel's avatar
winckel committed
5108
#endif
5109 5110 5111 5112
#   ifdef Rel14
				 ,
				 (SystemInformationBlockType1_v1310_IEs_t *)NULL
#   endif
5113
				 );
winckel's avatar
winckel committed
5114
        }
5115
      }
winckel's avatar
winckel committed
5116
    }
5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132
   free(DRB_configList);
    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;
5133
  }
winckel's avatar
winckel committed
5134
}
5135

5136 5137 5138 5139
//-----------------------------------------------------------------------------
void
rrc_eNB_generate_RRCConnectionSetup(
  const protocol_ctxt_t* const ctxt_pP,
5140 5141
  rrc_eNB_ue_context_t*          const ue_context_pP,
  const int                    CC_id
5142 5143
)
//-----------------------------------------------------------------------------
5144
{
Lionel Gauthier's avatar
 
Lionel Gauthier committed
5145

5146 5147 5148 5149
  LogicalChannelConfig_t             *SRB1_logicalChannelConfig;  //,*SRB2_logicalChannelConfig;
  SRB_ToAddModList_t                **SRB_configList;
  SRB_ToAddMod_t                     *SRB1_config;
  int                                 cnt;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
5150

Cedric Roux's avatar
Cedric Roux committed
5151 5152 5153
  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));

5154
  SRB_configList = &ue_context_pP->ue_context.SRB_configList;
5155
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size =
5156 5157
    do_RRCConnectionSetup(ctxt_pP,
                          ue_context_pP,
5158
                          CC_id,
5159
                          (uint8_t*) RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.Payload,
5160
			  (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
5161 5162 5163
                          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
5164

5165
#ifdef RRC_MSG_PRINT
5166 5167
  LOG_F(RRC,"[MSG] RRC Connection Setup\n");

5168 5169
  for (cnt = 0; cnt < RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size; cnt++) {
    LOG_F(RRC,"%02x ", ((uint8_t*)RC.rrc[ctxt_pP->module_id]->Srb0.Tx_buffer.Payload)[cnt]);
5170
  }
5171 5172

  LOG_F(RRC,"\n");
5173 5174 5175
  //////////////////////////////////
#endif

5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194
  // configure SRB1/SRB2, PhysicalConfigDedicated, MAC_MainConfig for UE

  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];

        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,
5195 5196
              PROTOCOL_RRC_CTXT_UE_FMT" RRC_eNB --- MAC_CONFIG_REQ  (SRB1) ---> MAC_eNB\n",
              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
5197 5198 5199
        rrc_mac_config_req_eNB(
			       ctxt_pP->module_id,
			       ue_context_pP->ue_context.primaryCC_id,
5200 5201 5202 5203
			       0,0,0,0,0,
#ifdef Rel14 
			       0,
#endif
5204
			       ue_context_pP->ue_context.rnti,
5205 5206
			       (BCCH_BCH_Message_t *) NULL,
			       (RadioResourceConfigCommonSIB_t *) NULL,
5207 5208
			       (RadioResourceConfigCommonSIB_t *) NULL,
			       ue_context_pP->ue_context.physicalConfigDedicated,
Cedric Roux's avatar
Cedric Roux committed
5209
#if defined(Rel10) || defined(Rel14)
5210 5211
			       (SCellToAddMod_r10_t *)NULL,
			       //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
5212
#endif
5213 5214 5215 5216 5217 5218 5219
			       (MeasObjectToAddMod_t **) NULL,
			       ue_context_pP->ue_context.mac_MainConfig,
			       1,
			       SRB1_logicalChannelConfig,
			       ue_context_pP->ue_context.measGapConfig,
			       (TDD_Config_t *) NULL,
			       NULL,
5220 5221
			       (SchedulingInfoList_t *) NULL,
			       0, NULL, NULL, (MBSFN_SubframeConfigList_t *) NULL
Cedric Roux's avatar
Cedric Roux committed
5222
#if defined(Rel10) || defined(Rel14)
5223
			       , 0, (MBSFN_AreaInfoList_r9_t *) NULL, (PMCH_InfoList_r9_t *) NULL
winckel's avatar
winckel committed
5224
#endif
5225 5226 5227 5228
#   ifdef Rel14
			       ,
			       (SystemInformationBlockType1_v1310_IEs_t *)NULL
#   endif
5229
			       );
5230 5231
        break;
      }
winckel's avatar
winckel committed
5232
    }
5233
  }
5234 5235

  MSC_LOG_TX_MESSAGE(
5236 5237
    MSC_RRC_ENB,
    MSC_RRC_UE,
5238 5239
    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.Header, // LG WARNING
    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size,
5240 5241 5242
    MSC_AS_TIME_FMT" RRCConnectionSetup UE %x size %u",
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP->ue_context.rnti,
5243
    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size);
5244

5245 5246

  LOG_I(RRC,
5247 5248
        PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel DL-CCCH, Generating RRCConnectionSetup (bytes %d)\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
5249
        RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size);
5250

5251
  // activate release timer, if RRCSetupComplete not received after 10 frames, remove UE
5252
  //ue_context_pP->ue_context.ue_release_timer=1;
5253
  // remove UE after 10 frames after RRCConnectionRelease is triggered
5254 5255 5256 5257 5258
  //ue_context_pP->ue_context.ue_release_timer_thres=100;
     // activate release timer, if RRCSetupComplete not received after 100 frames, remove UE
   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
5259
}
5260

Lionel Gauthier's avatar
 
Lionel Gauthier committed
5261 5262

#if defined(ENABLE_ITTI)
5263 5264
//-----------------------------------------------------------------------------
char
5265
openair_rrc_eNB_configuration(
5266 5267 5268
  const module_id_t enb_mod_idP,
  RrcConfigurationReq* configuration
)
winckel's avatar
winckel committed
5269
#else
5270
char
5271
openair_rrc_eNB_init(
5272 5273
  const module_id_t enb_mod_idP
)
winckel's avatar
winckel committed
5274
#endif
5275
//-----------------------------------------------------------------------------
winckel's avatar
winckel committed
5276
{
5277
  protocol_ctxt_t ctxt;
5278 5279
  int             CC_id;

5280
  PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, enb_mod_idP, ENB_FLAG_YES, NOT_A_RNTI, 0, 0,enb_mod_idP);
5281 5282 5283
  LOG_I(RRC,
        PROTOCOL_RRC_CTXT_FMT" Init...\n",
        PROTOCOL_RRC_CTXT_ARGS(&ctxt));
5284

laurent's avatar
laurent committed
5285
#if OCP_FRAMEWORK
5286 5287 5288 5289
  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
5290
#endif 
5291
  AssertFatal(RC.rrc[enb_mod_idP] != NULL, "RC.rrc not initialized!");
5292
  AssertFatal(NUMBER_OF_UE_MAX < (module_id_t)0xFFFFFFFFFFFFFFFF, " variable overflow");
5293 5294 5295
#ifdef ENABLE_ITTI
  AssertFatal(configuration!=NULL,"configuration input is null\n");
#endif
5296
  //    for (j = 0; j < NUMBER_OF_UE_MAX; j++)
5297
  //        RC.rrc[ctxt.module_id].Info.UE[j].Status = RRC_IDLE;  //CH_READY;
5298 5299 5300 5301 5302 5303 5304 5305
  //
  //#if defined(ENABLE_USE_MME)
  //    // Connect eNB to MME
  //    if (EPC_MODE_ENABLED <= 0)
  //#endif
  //    {
  //        /* Init security parameters */
  //        for (j = 0; j < NUMBER_OF_UE_MAX; j++) {
5306 5307
  //            RC.rrc[ctxt.module_id].ciphering_algorithm[j] = SecurityAlgorithmConfig__cipheringAlgorithm_eea0;
  //            RC.rrc[ctxt.module_id].integrity_algorithm[j] = SecurityAlgorithmConfig__integrityProtAlgorithm_eia2;
5308
  //            rrc_eNB_init_security(enb_mod_idP, j);
5309 5310
  //        }
  //    }
5311
  RC.rrc[ctxt.module_id]->Nb_ue = 0;
5312

5313
  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
5314
    RC.rrc[ctxt.module_id]->carrier[CC_id].Srb0.Active = 0;
5315
  }
5316

5317 5318
  uid_linear_allocator_init(&RC.rrc[ctxt.module_id]->uid_allocator);
  RB_INIT(&RC.rrc[ctxt.module_id]->rrc_ue_head);
5319
  //    for (j = 0; j < (NUMBER_OF_UE_MAX + 1); j++) {
5320
  //        RC.rrc[enb_mod_idP]->Srb2[j].Active = 0;
5321
  //    }
5322

5323

5324 5325
  RC.rrc[ctxt.module_id]->initial_id2_s1ap_ids = hashtable_create (NUMBER_OF_UE_MAX * 2, NULL, NULL);
  RC.rrc[ctxt.module_id]->s1ap_id2_s1ap_ids    = hashtable_create (NUMBER_OF_UE_MAX * 2, NULL, NULL);
5326

5327
  memcpy(&RC.rrc[ctxt.module_id]->configuration,configuration,sizeof(RrcConfigurationReq));
5328

5329
  /// System Information INIT
5330

5331 5332
  LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Checking release \n",
        PROTOCOL_RRC_CTXT_ARGS(&ctxt));
Cedric Roux's avatar
Cedric Roux committed
5333
#if defined(Rel10) || defined(Rel14)
5334

5335 5336 5337
  // can clear it at runtime
  RC.rrc[ctxt.module_id]->carrier[0].MBMS_flag = 0;

5338
  // This has to come from some top-level configuration
5339
  // only CC_id 0 is logged
Cedric Roux's avatar
Cedric Roux committed
5340
#if defined(Rel10)
5341
  LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Rel10 RRC detected, MBMS flag %d\n",
Cedric Roux's avatar
Cedric Roux committed
5342 5343 5344
#else
  LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Rel14 RRC detected, MBMS flag %d\n",
#endif
5345
        PROTOCOL_RRC_CTXT_ARGS(&ctxt),
5346
        RC.rrc[ctxt.module_id]->carrier[0].MBMS_flag);
5347

winckel's avatar
winckel committed
5348
#else
5349
  LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Rel8 RRC\n", PROTOCOL_RRC_CTXT_ARGS(&ctxt));
winckel's avatar
winckel committed
5350 5351
#endif
#ifdef CBA
5352

5353 5354
  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
    for (j = 0; j < NUM_MAX_CBA_GROUP; j++) {
5355
      RC.rrc[ctxt.module_id]->carrier[CC_id].cba_rnti[j] = CBA_OFFSET + j;
5356
    }
5357

5358 5359
    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;
5360
    }
5361

5362 5363 5364
    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),
5365 5366 5367 5368 5369
          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);
5370
  }
5371

winckel's avatar
winckel committed
5372
#endif
5373

5374 5375 5376
  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
    init_SI(&ctxt,
            CC_id
winckel's avatar
winckel committed
5377
#if defined(ENABLE_ITTI)
5378
            , configuration
winckel's avatar
winckel committed
5379
#endif
5380
           );
5381 5382 5383 5384
    for (int ue_id = 0; ue_id < NUMBER_OF_UE_MAX; ue_id++) {
        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);
    }
5385
  }
5386

5387
  rrc_init_global_param();
5388
  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
5389

5390
#if defined(Rel10) || defined(Rel14)
5391
    switch (RC.rrc[ctxt.module_id]->carrier[CC_id].MBMS_flag) {
5392 5393 5394 5395
    case 1:
    case 2:
    case 3:
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Configuring 1 MBSFN sync area\n", PROTOCOL_RRC_CTXT_ARGS(&ctxt));
5396
      RC.rrc[ctxt.module_id]->carrier[CC_id].num_mbsfn_sync_area = 1;
5397
      break;
5398

5399 5400
    case 4:
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Configuring 2 MBSFN sync area\n", PROTOCOL_RRC_CTXT_ARGS(&ctxt));
5401
      RC.rrc[ctxt.module_id]->carrier[CC_id].num_mbsfn_sync_area = 2;
5402 5403 5404
      break;

    default:
5405
      RC.rrc[ctxt.module_id]->carrier[CC_id].num_mbsfn_sync_area = 0;
5406 5407 5408
      break;
    }

5409
    // if we are here the RC.rrc[enb_mod_idP]->MBMS_flag > 0,
5410
    /// MCCH INIT
5411
    if (RC.rrc[ctxt.module_id]->carrier[CC_id].MBMS_flag > 0) {
5412 5413 5414 5415
      init_MCCH(ctxt.module_id, CC_id);
      /// MTCH data bearer init
      init_MBMS(ctxt.module_id, CC_id, 0);
    }
winckel's avatar
winckel committed
5416
#endif
5417

5418 5419
    openair_rrc_top_init_eNB(RC.rrc[ctxt.module_id]->carrier[CC_id].MBMS_flag,0);
  }
5420
  openair_rrc_on(&ctxt);
5421

5422
  return 0;
5423

winckel's avatar
winckel committed
5424
}
5425

winckel's avatar
winckel committed
5426
/*------------------------------------------------------------------------------*/
5427 5428 5429
int
rrc_eNB_decode_ccch(
  protocol_ctxt_t* const ctxt_pP,
5430 5431
  const SRB_INFO*        const Srb_info,
  const int              CC_id
5432 5433
)
//-----------------------------------------------------------------------------
5434
{
5435
  module_id_t                                   Idx;
5436 5437
  asn_dec_rval_t                      dec_rval;
  UL_CCCH_Message_t                  *ul_ccch_msg = NULL;
5438 5439
  RRCConnectionRequest_r8_IEs_t*                rrcConnectionRequest = NULL;
  RRCConnectionReestablishmentRequest_r8_IEs_t* rrcConnectionReestablishmentRequest = NULL;
5440
  int                                 i, rval;
5441 5442
  struct rrc_eNB_ue_context_s*                  ue_context_p = NULL;
  uint64_t                                      random_value = 0;
5443
  int                                           stmsi_received = 0;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
5444

Cedric Roux's avatar
Cedric Roux committed
5445 5446 5447
  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));

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

5450
  LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Decoding UL CCCH %x.%x.%x.%x.%x.%x (%p)\n",
5451 5452
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
        ((uint8_t*) Srb_info->Rx_buffer.Payload)[0],
5453 5454 5455 5456 5457
        ((uint8_t *) Srb_info->Rx_buffer.Payload)[1],
        ((uint8_t *) Srb_info->Rx_buffer.Payload)[2],
        ((uint8_t *) Srb_info->Rx_buffer.Payload)[3],
        ((uint8_t *) Srb_info->Rx_buffer.Payload)[4],
        ((uint8_t *) Srb_info->Rx_buffer.Payload)[5], (uint8_t *) Srb_info->Rx_buffer.Payload);
5458 5459 5460 5461 5462 5463 5464 5465
  dec_rval = uper_decode(
               NULL,
               &asn_DEF_UL_CCCH_Message,
               (void**)&ul_ccch_msg,
               (uint8_t*) Srb_info->Rx_buffer.Payload,
               100,
               0,
               0);
5466

5467
  /*
winckel's avatar
winckel committed
5468
#if defined(ENABLE_ITTI)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
5469
#   if defined(DISABLE_ITTI_XER_PRINT)
5470 5471
  {
    MessageDef                         *message_p;
5472

5473 5474
    message_p = itti_alloc_new_message(TASK_RRC_ENB, RRC_UL_CCCH_MESSAGE);
    memcpy(&message_p->ittiMsg, (void *)ul_ccch_msg, sizeof(RrcUlCcchMessage));
5475

5476
    itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, message_p);
5477
  }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
5478
#   else
5479 5480 5481
  {
    char                                message_string[10000];
    size_t                              message_string_size;
5482

5483 5484 5485
    if ((message_string_size =
           xer_sprint(message_string, sizeof(message_string), &asn_DEF_UL_CCCH_Message, (void *)ul_ccch_msg)) > 0) {
      MessageDef                         *msg_p;
5486

5487 5488 5489
      msg_p = itti_alloc_new_message_sized(TASK_RRC_ENB, RRC_UL_CCCH, message_string_size + sizeof(IttiMsgText));
      msg_p->ittiMsg.rrc_ul_ccch.size = message_string_size;
      memcpy(&msg_p->ittiMsg.rrc_ul_ccch.text, message_string, message_string_size);
5490

5491
      itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
5492
    }
5493
  }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
5494 5495
#   endif
#endif
5496
  */
5497

5498
  for (i = 0; i < 8; i++) {
5499
    LOG_T(RRC, "%x.", ((uint8_t *) & ul_ccch_msg)[i]);
5500
  }
5501 5502

  if (dec_rval.consumed == 0) {
5503 5504 5505
    LOG_E(RRC,
          PROTOCOL_RRC_CTXT_UE_FMT" FATAL Error in receiving CCCH\n",
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
5506 5507 5508 5509
    return -1;
  }

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

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

5513
    case UL_CCCH_MessageType__c1_PR_NOTHING:
5514 5515 5516
      LOG_I(RRC,
            PROTOCOL_RRC_CTXT_FMT" Received PR_NOTHING on UL-CCCH-Message\n",
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
5517
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
5518

5519
    case UL_CCCH_MessageType__c1_PR_rrcConnectionReestablishmentRequest:
Cedric Roux's avatar
Cedric Roux committed
5520 5521 5522
      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));

5523
#ifdef RRC_MSG_PRINT
5524
      LOG_F(RRC,"[MSG] RRC Connection Reestablishment Request\n");
5525

5526
      for (i = 0; i < Srb_info->Rx_buffer.payload_size; i++) {
5527
        LOG_F(RRC,"%02x ", ((uint8_t*)Srb_info->Rx_buffer.Payload)[i]);
5528
      }
5529 5530 5531 5532

      LOG_F(RRC,"\n");
#endif
      LOG_D(RRC,
5533 5534 5535 5536 5537 5538 5539
            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),
5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550
            ((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);
      }

5551
      if ((RC.rrc[enb_mod_idP]->phyCellId == rrcConnectionReestablishmentRequest.UE_identity.physCellId) &&
5552
      (ue_mod_id != UE_INDEX_INVALID)){
5553
      rrc_eNB_generate_RRCConnectionReestablishment(enb_mod_idP, frameP, ue_mod_id);
5554
      }else {
5555
      rrc_eNB_generate_RRCConnectionReestablishmentReject(enb_mod_idP, frameP, ue_mod_id);
5556 5557
      }
      */
5558
      /* reject all reestablishment attempts for the moment */
5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601
//      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;
      }
5602
      int UE_id = find_UE_id(ctxt_pP->module_id, c_rnti);
5603 5604 5605 5606
      if(UE_id == -1){
          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);
5607 5608 5609
          rrc_eNB_generate_RRCConnectionReestablishmentReject(ctxt_pP, ue_context_p, CC_id);
          break;
      }
5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642

      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;
      }

      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);
          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;
            }
          }
      }
5643 5644 5645 5646
      LOG_D(RRC,
            PROTOCOL_RRC_CTXT_UE_FMT" UE context: %p\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            ue_context_p);
5647
      /* reset timers */
5648 5649 5650 5651 5652
      ue_context_p->ue_context.ul_failure_timer = 0;
      ue_context_p->ue_context.ue_release_timer = 0;
      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;
5653
      ue_context_p->ue_context.reestablishment_xid = -1;
5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740

      // insert C-RNTI to map
      for (i = 0; i < NUMBER_OF_UE_MAX; i++) {
        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
#   if defined(Rel10) || defined(Rel14)
                               , (PMCH_InfoList_r9_t *) NULL
#   endif
                               ,NULL);

      rrc_rlc_config_asn1_req(ctxt_pP,
                              ue_context_p->ue_context.SRB_configList,
                              (DRB_ToAddModList_t*) NULL,
                              (DRB_ToReleaseList_t*) NULL
#   if defined(Rel10) || defined(Rel14)
                              , (PMCH_InfoList_r9_t *) NULL
#   endif
                             );
#endif //NO_RRM
      }
5741 5742 5743
      break;

    case UL_CCCH_MessageType__c1_PR_rrcConnectionRequest:
Cedric Roux's avatar
Cedric Roux committed
5744 5745 5746
      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));

5747
#ifdef RRC_MSG_PRINT
5748 5749
      LOG_F(RRC,"[MSG] RRC Connection Request\n");

5750
      for (i = 0; i < Srb_info->Rx_buffer.payload_size; i++) {
5751
        LOG_F(RRC,"%02x ", ((uint8_t*)Srb_info->Rx_buffer.Payload)[i]);
5752
      }
5753 5754

      LOG_F(RRC,"\n");
5755
#endif
5756
      LOG_D(RRC,
5757 5758 5759
            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(
5760
                       RC.rrc[ctxt_pP->module_id],
5761 5762 5763 5764 5765
                       ctxt_pP->rnti);

      if (ue_context_p != NULL) {
        // erase content
        rrc_eNB_free_mem_UE_context(ctxt_pP, ue_context_p);
5766 5767

        MSC_LOG_RX_DISCARDED_MESSAGE(
5768 5769 5770 5771 5772 5773 5774 5775 5776
          MSC_RRC_ENB,
          MSC_RRC_UE,
          Srb_info->Rx_buffer.Payload,
          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 {
5777 5778
        rrcConnectionRequest = &ul_ccch_msg->message.choice.c1.choice.rrcConnectionRequest.criticalExtensions.choice.rrcConnectionRequest_r8;
        {
gauthier's avatar
gauthier committed
5779 5780 5781 5782 5783 5784 5785 5786 5787 5788
          if (InitialUE_Identity_PR_randomValue == rrcConnectionRequest->ue_Identity.present) {
            AssertFatal(rrcConnectionRequest->ue_Identity.choice.randomValue.size == 5,
                        "wrong InitialUE-Identity randomValue size, expected 5, provided %d",
                        rrcConnectionRequest->ue_Identity.choice.randomValue.size);
            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)
             */
5789
#if 0
gauthier's avatar
gauthier committed
5790
            if ((ue_context_p = rrc_eNB_ue_context_random_exist(ctxt_pP, random_value))) {
Cedric Roux's avatar
Cedric Roux committed
5791 5792 5793
              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, ctxt_pP->rnti);
	      rrc_mac_remove_ue(ctxt_pP->module_id, ctxt_pP->rnti);
gauthier's avatar
gauthier committed
5794
              ue_context_p = NULL;
Cedric Roux's avatar
Cedric Roux committed
5795
              return 0;
gauthier's avatar
gauthier committed
5796 5797 5798
            } else {
              ue_context_p = rrc_eNB_get_next_free_ue_context(ctxt_pP, random_value);
            }
5799 5800 5801 5802 5803 5804 5805
#endif
            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);
gauthier's avatar
gauthier committed
5806 5807 5808 5809 5810 5811 5812
          } 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))) {
5813
	      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);
Cedric Roux's avatar
Cedric Roux committed
5814
	      rrc_mac_remove_ue(ctxt_pP->module_id, ue_context_p->ue_context.rnti);
5815
	      stmsi_received=1;
5816 5817
              /* replace rnti in the context */
              /* for that, remove the context from the RB tree */
5818
              RB_REMOVE(rrc_ue_tree_s, &RC.rrc[ctxt_pP->module_id]->rrc_ue_head, ue_context_p);
5819 5820
              /* 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
5821
	      ue_context_p->ue_context.rnti = ctxt_pP->rnti;
5822
              RB_INSERT(rrc_ue_tree_s, &RC.rrc[ctxt_pP->module_id]->rrc_ue_head, ue_context_p);
5823 5824 5825
              /* reset timers */
              ue_context_p->ue_context.ul_failure_timer = 0;
              ue_context_p->ue_context.ue_release_timer = 0;
5826 5827 5828
              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;
5829
              ue_context_p->ue_context.reestablishment_xid = -1;
gauthier's avatar
gauthier committed
5830
            } else {
Cedric Roux's avatar
Cedric Roux committed
5831
	      LOG_I(RRC," S-TMSI doesn't exist, setting Initialue_identity_s_TMSI.m_tmsi to %p => %x\n",ue_context_p,m_tmsi);
5832 5833
//              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);
5834 5835 5836 5837 5838 5839 5840
              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
5841 5842
                /* TODO: do we have to break here? */
                //break;
5843
              }
gauthier's avatar
gauthier committed
5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858
            }

            MSC_LOG_RX_MESSAGE(
              MSC_RRC_ENB,
              MSC_RRC_UE,
              Srb_info->Rx_buffer.Payload,
              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 {
5859
            LOG_E(RRC,
gauthier's avatar
gauthier committed
5860
                  PROTOCOL_RRC_CTXT_UE_FMT" RRCConnectionRequest without random UE identity or S-TMSI not supported, let's reject the UE\n",
5861 5862
                  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
            rrc_eNB_generate_RRCConnectionReject(ctxt_pP,
5863
                             rrc_eNB_get_ue_context(RC.rrc[ctxt_pP->module_id], ctxt_pP->rnti),
5864 5865 5866
                             CC_id);
            break;
          }
gauthier's avatar
gauthier committed
5867

5868
        }
5869
        LOG_D(RRC,
Cedric Roux's avatar
Cedric Roux committed
5870
              PROTOCOL_RRC_CTXT_UE_FMT" UE context: %p\n",
5871 5872
              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
              ue_context_p);
5873

5874
        if (ue_context_p != NULL) {
5875 5876


winckel's avatar
winckel committed
5877
#if defined(ENABLE_ITTI)
gauthier's avatar
gauthier committed
5878
          ue_context_p->ue_context.establishment_cause = rrcConnectionRequest->establishmentCause;
5879
          ue_context_p->ue_context.reestablishment_cause = ReestablishmentCause_spare1;
Raymond Knopp's avatar
Raymond Knopp committed
5880
	  if (stmsi_received==0)
Cedric Roux's avatar
Cedric Roux committed
5881
	    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
5882 5883 5884 5885 5886 5887
		  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
5888
	    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
5889 5890 5891 5892
		  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);
5893 5894 5895 5896
#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);
5897
#endif
5898
          if (stmsi_received == 0)
5899
	    RC.rrc[ctxt_pP->module_id]->Nb_ue++;
5900

5901 5902 5903 5904
        } else {
          // no context available
          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),
5905
                random_value);
5906
	  rrc_mac_remove_ue(ctxt_pP->module_id,ctxt_pP->rnti);
5907 5908 5909
          return -1;
        }
      }
5910

winckel's avatar
winckel committed
5911
#ifndef NO_RRM
5912
      send_msg(&S_rrc, msg_rrc_MR_attach_ind(ctxt_pP->module_id, Mac_id));
winckel's avatar
winckel committed
5913
#else
5914

5915 5916
      ue_context_p->ue_context.primaryCC_id = CC_id;

5917 5918 5919
      //LG COMMENT Idx = (ue_mod_idP * NB_RB_MAX) + DCCH;
      Idx = DCCH;
      // SRB1
5920 5921 5922 5923
      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,
5924
             LCHAN_DESC_SIZE);
5925 5926
      memcpy(&ue_context_p->ue_context.Srb1.Srb_info.Lchan_desc[1],
             &DCCH_LCHAN_DESC,
5927
             LCHAN_DESC_SIZE);
5928

5929
      // SRB2: set  it to go through SRB1 with id 1 (DCCH)
5930 5931 5932 5933
      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,
5934
             LCHAN_DESC_SIZE);
5935 5936
      memcpy(&ue_context_p->ue_context.Srb2.Srb_info.Lchan_desc[1],
             &DCCH_LCHAN_DESC,
5937
             LCHAN_DESC_SIZE);
5938
      
5939
      rrc_eNB_generate_RRCConnectionSetup(ctxt_pP, ue_context_p, CC_id);
5940 5941 5942
      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
5943 5944 5945 5946 5947 5948 5949 5950 5951 5952

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

5953 5954
      rrc_pdcp_config_asn1_req(ctxt_pP,
                               ue_context_p->ue_context.SRB_configList,
5955
                               (DRB_ToAddModList_t *) NULL,
5956 5957 5958 5959 5960
                               (DRB_ToReleaseList_t*) NULL,
                               0xff,
                               NULL,
                               NULL,
                               NULL
Cedric Roux's avatar
Cedric Roux committed
5961
#   if defined(Rel10) || defined(Rel14)
5962
                               , (PMCH_InfoList_r9_t *) NULL
Lionel Gauthier's avatar
 
Lionel Gauthier committed
5963
#   endif
5964
                               ,NULL);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
5965

5966 5967 5968 5969
      rrc_rlc_config_asn1_req(ctxt_pP,
                              ue_context_p->ue_context.SRB_configList,
                              (DRB_ToAddModList_t*) NULL,
                              (DRB_ToReleaseList_t*) NULL
Cedric Roux's avatar
Cedric Roux committed
5970
#   if defined(Rel10) || defined(Rel14)
5971
                              , (PMCH_InfoList_r9_t *) NULL
Lionel Gauthier's avatar
 
Lionel Gauthier committed
5972
#   endif
5973
                             );
winckel's avatar
winckel committed
5974
#endif //NO_RRM
5975 5976 5977 5978

      break;

    default:
5979 5980
      LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Unknown message\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
5981 5982
      rval = -1;
      break;
winckel's avatar
winckel committed
5983
    }
5984 5985 5986

    rval = 0;
  } else {
5987 5988
    LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT"  Unknown error \n",
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
5989 5990 5991 5992
    rval = -1;
  }

  return rval;
5993 5994
}

5995 5996 5997 5998 5999 6000 6001 6002 6003
//-----------------------------------------------------------------------------
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
)
//-----------------------------------------------------------------------------
6004
{
winckel's avatar
winckel committed
6005

6006 6007 6008 6009 6010
  asn_dec_rval_t                      dec_rval;
  //UL_DCCH_Message_t uldcchmsg;
  UL_DCCH_Message_t                  *ul_dcch_msg = NULL; //&uldcchmsg;
  UE_EUTRA_Capability_t              *UE_EUTRA_Capability = NULL;
  int i;
6011
  struct rrc_eNB_ue_context_s*        ue_context_p = NULL;
6012 6013 6014 6015 6016 6017
#if defined(ENABLE_ITTI)
#   if defined(ENABLE_USE_MME)
  MessageDef *                        msg_delete_tunnels_p = NULL;
  uint8_t                             xid;
#endif
#endif
6018

6019
  int dedicated_DRB=0; 
nikaeinn's avatar
nikaeinn committed
6020

Cedric Roux's avatar
Cedric Roux committed
6021 6022 6023
  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));

6024
  if ((Srb_id != 1) && (Srb_id != 2)) {
6025 6026 6027
    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);
6028 6029 6030 6031
  } else {
    LOG_D(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Received message on SRB%d\n",
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
          Srb_id);
6032 6033
  }
  //memset(ul_dcch_msg,0,sizeof(UL_DCCH_Message_t));
6034

6035 6036 6037 6038 6039 6040 6041 6042 6043 6044
  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);
6045
  /*
winckel's avatar
winckel committed
6046
#if defined(ENABLE_ITTI)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
6047
#   if defined(DISABLE_ITTI_XER_PRINT)
6048 6049
  {
    MessageDef                         *message_p;
6050

6051 6052
    message_p = itti_alloc_new_message(TASK_RRC_ENB, RRC_UL_DCCH_MESSAGE);
    memcpy(&message_p->ittiMsg, (void *)ul_dcch_msg, sizeof(RrcUlDcchMessage));
6053

6054
    itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, message_p);
6055
  }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
6056
#   else
6057 6058 6059
  {
    char                                message_string[10000];
    size_t                              message_string_size;
6060

6061 6062 6063
    if ((message_string_size =
           xer_sprint(message_string, sizeof(message_string), &asn_DEF_UL_DCCH_Message, (void *)ul_dcch_msg)) >= 0) {
      MessageDef                         *msg_p;
6064

6065 6066 6067
      msg_p = itti_alloc_new_message_sized(TASK_RRC_ENB, RRC_UL_DCCH, message_string_size + sizeof(IttiMsgText));
      msg_p->ittiMsg.rrc_ul_dcch.size = message_string_size;
      memcpy(&msg_p->ittiMsg.rrc_ul_dcch.text, message_string, message_string_size);
6068

6069
      itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
winckel's avatar
winckel committed
6070
    }
6071
  }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
6072 6073
#   endif
#endif
6074
  */
6075
  {
6076
    for (i = 0; i < sdu_sizeP; i++) {
6077
      LOG_T(RRC, "%x.", Rx_sdu[i]);
6078
    }
winckel's avatar
winckel committed
6079

6080 6081 6082 6083
    LOG_T(RRC, "\n");
  }

  if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0)) {
Cedric Roux's avatar
Cedric Roux committed
6084
    LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Failed to decode UL-DCCH (%zu bytes)\n",
6085 6086
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
          dec_rval.consumed);
6087 6088
    return -1;
  }
6089

6090
  ue_context_p = rrc_eNB_get_ue_context(
6091
                   RC.rrc[ctxt_pP->module_id],
6092
                   ctxt_pP->rnti);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
6093

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

6096 6097 6098
    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
6099

6100 6101
    case UL_DCCH_MessageType__c1_PR_csfbParametersRequestCDMA2000:
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
6102

6103 6104
    case UL_DCCH_MessageType__c1_PR_measurementReport:
      LOG_D(RRC,
6105 6106 6107 6108 6109 6110 6111 6112
            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,
6113 6114
        &ul_dcch_msg->message.choice.c1.choice.measurementReport.
        criticalExtensions.choice.c1.choice.measurementReport_r8.measResults);
6115
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
6116

6117
    case UL_DCCH_MessageType__c1_PR_rrcConnectionReconfigurationComplete:
6118
#ifdef RRC_MSG_PRINT
6119 6120
      LOG_F(RRC,"[MSG] RRC Connection Reconfiguration Complete\n");

6121
      for (i = 0; i < sdu_sizeP; i++) {
6122
        LOG_F(RRC,"%02x ", ((uint8_t*)Rx_sdu)[i]);
6123
      }
6124 6125

      LOG_F(RRC,"\n");
6126
#endif
6127
      MSC_LOG_RX_MESSAGE(
6128 6129 6130 6131 6132 6133 6134 6135
        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);
6136

6137
      LOG_D(RRC,
6138 6139 6140 6141 6142
            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);
6143 6144 6145 6146

      if (ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.criticalExtensions.
          present ==
          RRCConnectionReconfigurationComplete__criticalExtensions_PR_rrcConnectionReconfigurationComplete_r8) {
6147
	/*NN: revise the condition */
6148 6149 6150
        if (ue_context_p->ue_context.Status == RRC_RECONFIGURED){
	  dedicated_DRB = 1;
	  LOG_I(RRC,
Cedric Roux's avatar
Cedric Roux committed
6151
		PROTOCOL_RRC_CTXT_UE_FMT" UE State = RRC_RECONFIGURED (dedicated DRB, xid %ld)\n",
6152
		PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);
6153
	}else {
6154
	  dedicated_DRB = 0;
6155 6156
	  ue_context_p->ue_context.Status = RRC_RECONFIGURED;
	  LOG_I(RRC,
Cedric Roux's avatar
Cedric Roux committed
6157
		PROTOCOL_RRC_CTXT_UE_FMT" UE State = RRC_RECONFIGURED (default DRB, xid %ld)\n",
6158
		PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);
6159
	}
6160
        ue_context_p->ue_context.reestablishment_xid = -1;
6161
	rrc_eNB_process_RRCConnectionReconfigurationComplete(
6162 6163
          ctxt_pP,
          ue_context_p,
6164 6165
	  ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);

6166
#if defined(FLEXRAN_AGENT_SB_IF)
6167 6168
	//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]) {
6169
	  agent_mac_xface[ctxt_pP->eNB_index]->flexran_agent_notify_ue_state_change(ctxt_pP->module_id,
6170
										ue_context_p->ue_id_rnti,
6171
										PROTOCOL__FLEX_UE_STATE_CHANGE_TYPE__FLUESC_UPDATED);
6172
	}
6173
#endif
6174
      }
6175 6176
#if defined(ENABLE_ITTI)
#   if defined(ENABLE_USE_MME)
6177
      if (EPC_MODE_ENABLED == 1) {
6178
	if (dedicated_DRB == 1){
6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218
//	  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);
          }
6219
	}else {
6220 6221
          if(ue_context_p->ue_context.reestablishment_cause == ReestablishmentCause_spare1){
	    rrc_eNB_send_S1AP_INITIAL_CONTEXT_SETUP_RESP(ctxt_pP,
6222
						       ue_context_p);
6223 6224
          } else {
            ue_context_p->ue_context.reestablishment_cause = ReestablishmentCause_spare1;
6225 6226 6227 6228 6229 6230 6231
            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;
              }
            }
6232
          }
6233 6234 6235 6236
	}
      }    
#else  // establish a dedicated bearer 
      if (dedicated_DRB == 0 ) {
6237
	//	ue_context_p->ue_context.e_rab[0].status = E_RAB_STATUS_ESTABLISHED;
6238
	rrc_eNB_reconfigure_DRBs(ctxt_pP,ue_context_p);
6239
      }
6240
      
Lionel Gauthier's avatar
 
Lionel Gauthier committed
6241
#endif
6242
#endif 
6243
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
6244

6245
    case UL_DCCH_MessageType__c1_PR_rrcConnectionReestablishmentComplete:
Cedric Roux's avatar
Cedric Roux committed
6246 6247 6248
      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));

6249
#ifdef RRC_MSG_PRINT
6250 6251
      LOG_F(RRC,"[MSG] RRC Connection Reestablishment Complete\n");

6252
      for (i = 0; i < sdu_sizeP; i++) {
6253
        LOG_F(RRC,"%02x ", ((uint8_t*)Rx_sdu)[i]);
6254
      }
6255 6256

      LOG_F(RRC,"\n");
6257
#endif
6258 6259

      MSC_LOG_RX_MESSAGE(
6260 6261 6262 6263 6264 6265 6266 6267
        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);
6268

6269
      LOG_I(RRC,
6270 6271 6272 6273 6274
            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);
6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298
       {
        rnti_t reestablish_rnti = 0;
        // select C-RNTI from map
        for (i = 0; i < NUMBER_OF_UE_MAX; i++) {
          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;
        }
6299 6300 6301 6302 6303 6304 6305 6306 6307 6308
        //clear
        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;
6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324

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

#if defined(FLEXRAN_AGENT_SB_IF)
          //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]) {
            agent_mac_xface[ctxt_pP->eNB_index]->flexran_agent_notify_ue_state_change(ctxt_pP->module_id,
                                                                                      ue_context_p->ue_id_rnti,
                                                                                      PROTOCOL__FLEX_UE_STATE_CHANGE_TYPE__FLUESC_ACTIVATED);
          }
#endif
        }
6325
        //ue_context_p->ue_context.ue_release_timer = 0;
6326 6327 6328
        ue_context_p->ue_context.ue_reestablishment_timer = 1;
        // remove UE after 100 frames after RRCConnectionReestablishmentRelease is triggered
        ue_context_p->ue_context.ue_reestablishment_timer_thres = 1000;
6329
      }
6330 6331 6332
      break;

    case UL_DCCH_MessageType__c1_PR_rrcConnectionSetupComplete:
6333
#ifdef RRC_MSG_PRINT
6334 6335
      LOG_F(RRC,"[MSG] RRC Connection SetupComplete\n");

6336
      for (i = 0; i < sdu_sizeP; i++) {
6337
        LOG_F(RRC,"%02x ", ((uint8_t*)Rx_sdu)[i]);
6338
      }
6339 6340

      LOG_F(RRC,"\n");
6341
#endif
6342 6343

      MSC_LOG_RX_MESSAGE(
6344 6345 6346 6347 6348 6349 6350 6351
        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);
6352

6353
      LOG_D(RRC,
6354 6355 6356 6357 6358
            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);
6359 6360 6361 6362 6363 6364

      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) {
6365 6366 6367 6368 6369 6370 6371
          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",
                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
6372 6373
	  
#if defined(FLEXRAN_AGENT_SB_IF)
6374 6375
	  //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]) {
6376
	    agent_mac_xface[ctxt_pP->eNB_index]->flexran_agent_notify_ue_state_change(ctxt_pP->module_id,
6377
										  ue_context_p->ue_id_rnti,
6378
										  PROTOCOL__FLEX_UE_STATE_CHANGE_TYPE__FLUESC_ACTIVATED);
6379
	  }
6380
#endif
6381 6382 6383
        }
      }

6384
      ue_context_p->ue_context.ue_release_timer=0;
6385 6386 6387
      break;

    case UL_DCCH_MessageType__c1_PR_securityModeComplete:
Cedric Roux's avatar
Cedric Roux committed
6388 6389 6390
      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));

6391
#ifdef RRC_MSG_PRINT
6392 6393
      LOG_F(RRC,"[MSG] RRC Security Mode Complete\n");

6394
      for (i = 0; i < sdu_sizeP; i++) eNB->pusch_vars[UE_id]{
6395
        LOG_F(RRC,"%02x ", ((uint8_t*)Rx_sdu)[i]);
6396
      }
6397 6398

      LOG_F(RRC,"\n");
6399
#endif
6400 6401

      MSC_LOG_RX_MESSAGE(
6402 6403 6404 6405 6406 6407 6408 6409
        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);
6410

6411
      LOG_I(RRC,
6412 6413 6414
            PROTOCOL_RRC_CTXT_UE_FMT" received securityModeComplete on UL-DCCH %d from UE\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            DCCH);
6415
      LOG_D(RRC,
6416 6417 6418 6419 6420
            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);
winckel's avatar
winckel committed
6421
#ifdef XER_PRINT
6422
      xer_fprint(stdout, &asn_DEF_UL_DCCH_Message, (void *)ul_dcch_msg);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
6423
#endif
6424 6425 6426
      // 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
6427 6428 6429
      rrc_eNB_generate_UECapabilityEnquiry(
        ctxt_pP,
        ue_context_p);
6430
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
6431

6432
    case UL_DCCH_MessageType__c1_PR_securityModeFailure:
Cedric Roux's avatar
Cedric Roux committed
6433 6434 6435
      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));

6436
#ifdef RRC_MSG_PRINT
6437 6438
      LOG_F(RRC,"[MSG] RRC Security Mode Failure\n");

6439
      for (i = 0; i < sdu_sizeP; i++) {
6440
        LOG_F(RRC,"%02x ", ((uint8_t*)Rx_sdu)[i]);
6441
      }
6442 6443 6444

      LOG_F(RRC,"\n");
#endif
6445 6446

      MSC_LOG_RX_MESSAGE(
6447 6448 6449 6450 6451 6452 6453 6454
        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);
6455

6456 6457 6458 6459 6460 6461
      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);
winckel's avatar
winckel committed
6462
#ifdef XER_PRINT
6463
      xer_fprint(stdout, &asn_DEF_UL_DCCH_Message, (void *)ul_dcch_msg);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
6464
#endif
6465
      // cancel the security mode in PDCP
Lionel Gauthier's avatar
 
Lionel Gauthier committed
6466

6467
      // followup with the remaining procedure
6468
//#warning "LG Removed rrc_eNB_generate_UECapabilityEnquiry after receiving securityModeFailure"
Raymond Knopp's avatar
Raymond Knopp committed
6469
      rrc_eNB_generate_UECapabilityEnquiry(ctxt_pP, ue_context_p);
6470
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
6471

6472
    case UL_DCCH_MessageType__c1_PR_ueCapabilityInformation:
Cedric Roux's avatar
Cedric Roux committed
6473 6474 6475
      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));

6476
#ifdef RRC_MSG_PRINT
6477 6478
      LOG_F(RRC,"[MSG] RRC UECapablility Information \n");

6479
      for (i = 0; i < sdu_sizeP; i++) {
6480
        LOG_F(RRC,"%02x ", ((uint8_t*)Rx_sdu)[i]);
6481
      }
6482 6483

      LOG_F(RRC,"\n");
6484
#endif
6485 6486

      MSC_LOG_RX_MESSAGE(
6487 6488 6489 6490 6491 6492 6493 6494
        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);
6495

6496
      LOG_I(RRC,
6497 6498 6499
            PROTOCOL_RRC_CTXT_UE_FMT" received ueCapabilityInformation on UL-DCCH %d from UE\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            DCCH);
6500
      LOG_D(RRC,
6501 6502 6503 6504 6505
            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);
winckel's avatar
winckel committed
6506
#ifdef XER_PRINT
6507 6508
      xer_fprint(stdout, &asn_DEF_UL_DCCH_Message, (void *)ul_dcch_msg);
#endif
6509
      LOG_I(RRC, "got UE capabilities for UE %x\n", ctxt_pP->rnti);
6510 6511 6512 6513 6514 6515 6516 6517 6518 6519
      dec_rval = uper_decode(NULL,
                             &asn_DEF_UE_EUTRA_Capability,
                             (void **)&UE_EUTRA_Capability,
                             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);
      //#ifdef XER_PRINT
6520
      //xer_fprint(stdout, &asn_DEF_UE_EUTRA_Capability, (void *)UE_EUTRA_Capability);
6521
      //#endif
6522

6523
#if defined(ENABLE_USE_MME)
6524 6525

      if (EPC_MODE_ENABLED == 1) {
6526 6527 6528
        rrc_eNB_send_S1AP_UE_CAPABILITIES_IND(ctxt_pP,
                                              ue_context_p,
                                              ul_dcch_msg);
6529
      }
6530 6531 6532 6533 6534 6535 6536 6537
#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;
6538 6539
#endif

6540 6541
      rrc_eNB_generate_defaultRRCConnectionReconfiguration(ctxt_pP,
          ue_context_p,
6542
          RC.rrc[ctxt_pP->module_id]->HO_flag);
6543
      break;
6544

6545
    case UL_DCCH_MessageType__c1_PR_ulHandoverPreparationTransfer:
Cedric Roux's avatar
Cedric Roux committed
6546 6547 6548
      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));

6549
      break;
6550

6551
    case UL_DCCH_MessageType__c1_PR_ulInformationTransfer:
Cedric Roux's avatar
Cedric Roux committed
6552 6553 6554
      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));

6555
#ifdef RRC_MSG_PRINT
6556 6557
      LOG_F(RRC,"[MSG] RRC UL Information Transfer \n");

6558
      for (i = 0; i < sdu_sizeP; i++) {
6559
        LOG_F(RRC,"%02x ", ((uint8_t*)Rx_sdu)[i]);
6560
      }
6561 6562

      LOG_F(RRC,"\n");
6563 6564
#endif

6565 6566

      MSC_LOG_RX_MESSAGE(
6567 6568 6569 6570 6571 6572 6573 6574
        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);
6575

winckel's avatar
winckel committed
6576
#if defined(ENABLE_USE_MME)
6577 6578

      if (EPC_MODE_ENABLED == 1) {
6579 6580 6581
        rrc_eNB_send_S1AP_UPLINK_NAS(ctxt_pP,
                                     ue_context_p,
                                     ul_dcch_msg);
6582 6583
      }

winckel's avatar
winckel committed
6584
#endif
6585
      break;
6586

6587
    case UL_DCCH_MessageType__c1_PR_counterCheckResponse:
Cedric Roux's avatar
Cedric Roux committed
6588 6589 6590
      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));

6591
      break;
6592

Cedric Roux's avatar
Cedric Roux committed
6593
#if defined(Rel10) || defined(Rel14)
6594

6595
    case UL_DCCH_MessageType__c1_PR_ueInformationResponse_r9:
Cedric Roux's avatar
Cedric Roux committed
6596 6597 6598
      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));

6599 6600 6601
      break;

    case UL_DCCH_MessageType__c1_PR_proximityIndication_r9:
Cedric Roux's avatar
Cedric Roux committed
6602 6603 6604
      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));

6605
      break;
6606

6607
    case UL_DCCH_MessageType__c1_PR_rnReconfigurationComplete_r10:
Cedric Roux's avatar
Cedric Roux committed
6608 6609 6610
      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));

6611
      break;
6612

6613
    case UL_DCCH_MessageType__c1_PR_mbmsCountingResponse_r10:
Cedric Roux's avatar
Cedric Roux committed
6614 6615 6616
      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));

6617
      break;
winckel's avatar
winckel committed
6618

6619
    case UL_DCCH_MessageType__c1_PR_interFreqRSTDMeasurementIndication_r10:
Cedric Roux's avatar
Cedric Roux committed
6620 6621 6622
      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));

6623
      break;
6624
#endif
6625

6626
    default:
Cedric Roux's avatar
Cedric Roux committed
6627 6628 6629
      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));

6630 6631 6632
      LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Unknown message %s:%u\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            __FILE__, __LINE__);
6633
      return -1;
winckel's avatar
winckel committed
6634 6635
    }

6636 6637
    return 0;
  } else {
6638 6639 6640
    LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Unknown error %s:%u\n",
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
          __FILE__, __LINE__);
6641 6642 6643
    return -1;
  }

winckel's avatar
winckel committed
6644 6645
}

6646
#if defined(ENABLE_ITTI)
6647 6648 6649 6650
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
6651
  int e_rab_done=0;
6652
  for (i = 0; 
Navid Nikaein's avatar
Navid Nikaein committed
6653
       i < 3;//NB_RB_MAX - 3;  // S1AP_MAX_E_RAB
6654 6655
       i++) {
    
6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669
    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
6670
      e_rab_done++;
6671 6672 6673
      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);
    }
6674
  }
Navid Nikaein's avatar
Navid Nikaein committed
6675 6676
  ue_context_pP->ue_context.setup_e_rabs+=e_rab_done;
 
6677 6678 6679 6680
  rrc_eNB_generate_dedicatedRRCConnectionReconfiguration(ctxt_pP, ue_context_pP, 0);
}


6681 6682 6683 6684 6685 6686
//-----------------------------------------------------------------------------
void*
rrc_enb_task(
  void* args_p
)
//-----------------------------------------------------------------------------
6687 6688 6689 6690 6691 6692
{
  MessageDef                         *msg_p;
  const char                         *msg_name_p;
  instance_t                          instance;
  int                                 result;
  SRB_INFO                           *srb_info_p;
6693
  int                                 CC_id;
6694

6695
  protocol_ctxt_t                     ctxt;
6696 6697 6698

  pthread_mutex_init(&lock_ue_freelist, NULL);

6699
  itti_mark_task_ready(TASK_RRC_ENB);
6700
  LOG_I(RRC,"Entering main loop of RRC message task\n");
6701 6702 6703 6704 6705 6706
  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);
6707
    LOG_I(RRC,"Received message %s\n",msg_name_p);
6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719

    switch (ITTI_MSG_ID(msg_p)) {
    case TERMINATE_MESSAGE:
      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:
6720 6721 6722 6723 6724 6725 6726 6727 6728
      PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt,
                                    instance,
                                    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);
6729

6730
      CC_id = RRC_MAC_CCCH_DATA_IND(msg_p).CC_id;
6731
      srb_info_p = &RC.rrc[instance]->carrier[CC_id].Srb0;
6732

6733 6734 6735 6736 6737
      LOG_I(RRC,"Decoding CCCH : inst %d, CC_id %d, ctxt %p, sib_info_p->Rx_buffer.payload_size %d\n",
	    instance,CC_id,&ctxt, RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size);
      AssertFatal(RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size < RRC_BUFFER_SIZE_MAX,
		  "CCCH message has size %d > %d\n",
		  RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size,RRC_BUFFER_SIZE_MAX);
6738 6739
      memcpy(srb_info_p->Rx_buffer.Payload,
             RRC_MAC_CCCH_DATA_IND(msg_p).sdu,
6740 6741
             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;
6742

6743
      rrc_eNB_decode_ccch(&ctxt, srb_info_p, CC_id);
6744
      break;
6745
	    
6746 6747
      /* Messages from PDCP */
    case RRC_DCCH_DATA_IND:
6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760
      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,
6761 6762 6763 6764 6765 6766
                          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);
      AssertFatal(result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
6767 6768 6769

#   if defined(ENABLE_USE_MME)

6770 6771 6772 6773
      /* 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
6774

6775 6776 6777
    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
6778

6779 6780 6781
    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
6782

6783
    case S1AP_PAGING_IND:
6784 6785
      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);
6786
      break;
6787 6788 6789 6790 6791
  
    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;
6792 6793 6794 6795 6796 6797 6798 6799

    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;
6800
    
6801 6802 6803
    case S1AP_UE_CONTEXT_RELEASE_REQ:
      rrc_eNB_process_S1AP_UE_CONTEXT_RELEASE_REQ(msg_p, msg_name_p, instance);
      break;
6804

6805 6806 6807
    case S1AP_UE_CONTEXT_RELEASE_COMMAND:
      rrc_eNB_process_S1AP_UE_CONTEXT_RELEASE_COMMAND(msg_p, msg_name_p, instance);
      break;
6808

6809 6810 6811 6812
    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);
6813 6814 6815 6816 6817
     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;
      }
6818
      break;
Lionel Gauthier's avatar
Lionel Gauthier committed
6819

Lionel Gauthier's avatar
 
Lionel Gauthier committed
6820 6821
#   endif

6822 6823
      /* Messages from eNB app */
    case RRC_CONFIGURATION_REQ:
6824
      LOG_I(RRC, "[eNB %d] Received %s : %p\n", instance, msg_name_p,&RRC_CONFIGURATION_REQ(msg_p));
6825
      openair_rrc_eNB_configuration(ENB_INSTANCE_TO_MODULE_ID(instance), &RRC_CONFIGURATION_REQ(msg_p));
6826
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
6827

6828 6829 6830
    default:
      LOG_E(RRC, "[eNB %d] Received unexpected message %s\n", instance, msg_name_p);
      break;
6831
    }
6832 6833 6834 6835 6836

    result = itti_free(ITTI_MSG_ORIGIN_ID(msg_p), msg_p);
    AssertFatal(result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
    msg_p = NULL;
  }
6837 6838
}
#endif
winckel's avatar
winckel committed
6839

6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860
/*------------------------------------------------------------------------------*/
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;
    }

6861
#if defined(Rel10) || defined(Rel14)
6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878
    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
6879
#endif
6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896
  } 


}

//-----------------------------------------------------------------------------
void
rrc_top_cleanup_eNB(
  void
)
//-----------------------------------------------------------------------------
{

  for (int i=0;i<RC.nb_inst;i++) free (RC.rrc[i]);
  free(RC.rrc);
}