rrc_eNB.c 419 KB
Newer Older
1 2 3 4 5
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
6
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
7 8 9 10 11 12 13 14 15 16 17 18 19 20
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */
21 22 23

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

68 69
#include "T.h"

70 71
//#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
#include "LTE_MeasResults.h"
72 73
//#endif

74 75 76 77
#include "RRC/NAS/nas_config.h"
#include "RRC/NAS/rb_config.h"
#include "OCG.h"
#include "OCG_extern.h"
78

79
#include "UTIL/OSA/osa_defs.h"
80

81 82
#include "rrc_eNB_S1AP.h"
#include "rrc_eNB_GTPV1U.h"
83

84
#include "pdcp.h"
85
#include "gtpv1u_eNB_task.h"
86

87
#include "intertask_interface.h"
88

89
#if ENABLE_RAL
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
90
  #include "rrc_eNB_ral.h"
Lionel Gauthier's avatar
Lionel Gauthier committed
91 92
#endif

93
#include "SIMULATION/TOOLS/sim.h" // for taus
94

95

96 97
extern RAN_CONTEXT_t RC;

98
#ifdef PHY_EMUL
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
99
  extern EMULATION_VARS              *Emul_vars;
100
#endif
Lionel Gauthier's avatar
 
Lionel Gauthier committed
101 102
extern eNB_MAC_INST                *eNB_mac_inst;
extern UE_MAC_INST                 *UE_mac_inst;
103

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

Lionel Gauthier's avatar
 
Lionel Gauthier committed
106
mui_t                               rrc_eNB_mui = 0;
winckel's avatar
RRC:  
winckel committed
107

108
extern uint32_t to_earfcn_DL(int eutra_bandP, uint32_t dl_CarrierFreq, uint32_t bw);
109 110 111
extern int rrc_eNB_process_security(const protocol_ctxt_t *const ctxt_pP, rrc_eNB_ue_context_t *const ue_context_pP, security_capabilities_t *security_capabilities_pP);
extern void process_eNB_security_key (const protocol_ctxt_t *const ctxt_pP, rrc_eNB_ue_context_t *const ue_context_pP, uint8_t *security_key_pP);
extern int derive_keNB_star(const uint8_t *kenb_32, const uint16_t pci, const uint32_t earfcn_dl, const bool is_rel8_only, uint8_t * kenb_star);
112

113 114
void
openair_rrc_on(
Cedric Roux's avatar
Cedric Roux committed
115
  const protocol_ctxt_t *const ctxt_pP
116 117 118 119
)
//-----------------------------------------------------------------------------
{
  int            CC_id;
Cedric Roux's avatar
Cedric Roux committed
120 121
  LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" ENB:OPENAIR RRC IN....\n",
        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
122

Cedric Roux's avatar
Cedric Roux committed
123 124 125 126
  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
    rrc_config_buffer (&RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SI, BCCH, 1);
    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SI.Active = 1;
  }
127 128
}

129 130 131
//-----------------------------------------------------------------------------
static void
init_SI(
132
  const protocol_ctxt_t *const ctxt_pP,
133
  const int              CC_id,
134
  RrcConfigurationReq *configuration
135
)
136
//-----------------------------------------------------------------------------
137
{
138
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
139 140
  int                                 i;
#endif
141 142
#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 1, 0))
  LTE_SystemInformationBlockType1_v1310_IEs_t *sib1_v13ext=(LTE_SystemInformationBlockType1_v1310_IEs_t *)NULL;
143
#endif
Cedric Roux's avatar
Cedric Roux committed
144
  LOG_D(RRC,"%s()\n\n\n\n",__FUNCTION__);
145 146
  eNB_RRC_INST *rrc = RC.rrc[ctxt_pP->module_id];
  rrc_eNB_carrier_data_t *carrier=&rrc->carrier[CC_id];
147

148 149 150 151 152 153 154 155
  carrier->MIB = (uint8_t*) malloc16(4);
  carrier->sizeof_SIB1 = 0;
  carrier->sizeof_SIB23 = 0;
  carrier->SIB1 = (uint8_t*) malloc16(32);
  
  AssertFatal(carrier->SIB1!=NULL,PROTOCOL_RRC_CTXT_FMT" init_SI: FATAL, no memory for SIB1 allocated\n",
	      PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));

156
  LOG_I(RRC,"[eNB %d] Node type %d \n ", ctxt_pP->module_id, rrc->node_type);
157
  if (NODE_IS_DU(rrc->node_type) || NODE_IS_MONOLITHIC(rrc->node_type)) {
158 159 160 161 162 163
    // copy basic Cell parameters
    carrier->physCellId      = configuration->Nid_cell[CC_id];
    carrier->p_eNB           = configuration->nb_antenna_ports[CC_id];
    carrier->Ncp             = configuration->prefix_type[CC_id];
    carrier->dl_CarrierFreq  = configuration->downlink_frequency[CC_id];
    carrier->ul_CarrierFreq  = configuration->downlink_frequency[CC_id]+ configuration->uplink_frequency_offset[CC_id];
164 165
    carrier->eutra_band      = configuration->eutra_band[CC_id];
    carrier->N_RB_DL         = configuration->N_RB_DL[CC_id];
166
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
167
    carrier->pbch_repetition = configuration->pbch_repetition[CC_id];
168
    LOG_I(RRC, "configuration->schedulingInfoSIB1_BR_r13[CC_id] %d\n",(int)configuration->schedulingInfoSIB1_BR_r13[CC_id]);
169
#endif
170 171 172

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

176 177 178 179 180
    carrier->sizeof_MIB = do_MIB(&rrc->carrier[CC_id],
                                 configuration->N_RB_DL[CC_id],
                                 configuration->radioresourceconfig[CC_id].phich_resource,
                                 configuration->radioresourceconfig[CC_id].phich_duration,
                                 0
181
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
182
                                 ,configuration->schedulingInfoSIB1_BR_r13[CC_id]
183
#endif
184
   );
185 186
    
    
187 188 189
    carrier->sizeof_SIB1 = do_SIB1(&rrc->carrier[CC_id],
                                   ctxt_pP->module_id,
                                   CC_id
190
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
191
                                   ,FALSE
winckel's avatar
winckel committed
192
#endif
193
                                   , configuration
194 195 196
				   );
    
    AssertFatal(carrier->sizeof_SIB1 != 255,"FATAL, RC.rrc[enb_mod_idP].carrier[CC_id].sizeof_SIB1 == 255");
197

198
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
199 200 201 202 203 204 205 206
    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB1_BR = 0;

    if (configuration->schedulingInfoSIB1_BR_r13[CC_id] > 0) {
      RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SIB1_BR = (uint8_t *) malloc16(32);
      RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB1_BR = do_SIB1(&RC.rrc[ctxt_pP->module_id]->carrier[CC_id],
                                                                          ctxt_pP->module_id,
                                                                          CC_id, TRUE, configuration);
    }
winckel's avatar
winckel committed
207
#endif
208

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

373
  // LTE-M stuff here (take out CU-DU for now)
374
  if (NODE_IS_MONOLITHIC(rrc->node_type)) {
375
    if ((carrier->mib.message.schedulingInfoSIB1_BR_r13>0) && 
376
        (carrier->sib1_BR!=NULL)) {
377
      AssertFatal(carrier->sib1_BR->nonCriticalExtension!=NULL,
378
                  "sib2_br->nonCriticalExtension is null (v8.9)\n");
379
      AssertFatal(carrier->sib1_BR->nonCriticalExtension->nonCriticalExtension!=NULL,
380
                  "sib2_br->nonCriticalExtension is null (v9.2)\n");
381
      AssertFatal(carrier->sib1_BR->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension!=NULL,
382
                  "sib2_br->nonCriticalExtension is null (v11.3)\n");
383
      AssertFatal(carrier->sib1_BR->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension!=NULL,
384
                  "sib2_br->nonCriticalExtension is null (v12.5)\n");
385
      AssertFatal(carrier->sib1_BR->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension!=NULL,
386
                  "sib2_br->nonCriticalExtension is null (v13.10)\n");
387

388
      sib1_v13ext = carrier->sib1_BR->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension;
389

islam.galal's avatar
islam.galal committed
390
      // Basic Asserts for CE_level0 PRACH configuration
391 392
      LTE_RadioResourceConfigCommonSIB_t *radioResourceConfigCommon_BR = &carrier[CC_id].sib2_BR->radioResourceConfigCommon;
      struct LTE_PRACH_ConfigSIB_v1310 *ext4_prach=radioResourceConfigCommon_BR->ext4->prach_ConfigCommon_v1310;
393
      LTE_PRACH_ParametersListCE_r13_t	 *prach_ParametersListCE_r13 = &ext4_prach->prach_ParametersListCE_r13;
islam.galal's avatar
islam.galal committed
394
      AssertFatal(prach_ParametersListCE_r13->list.count>0,"prach_ParametersListCE_r13 is empty\n");
395
                  LTE_PRACH_ParametersCE_r13_t *p = prach_ParametersListCE_r13->list.array[0];
islam.galal's avatar
islam.galal committed
396 397
      AssertFatal(p->prach_StartingSubframe_r13 != NULL, "prach_StartingSubframe_r13 celevel0 is null\n");
      AssertFatal((1<<p->numRepetitionPerPreambleAttempt_r13)<=(2<<*p->prach_StartingSubframe_r13),
398 399 400
                  "prachce0->numReptitionPerPreambleAttempt_r13 %d > prach_StartingSubframe_r13 %d\n",
                  1<<p->numRepetitionPerPreambleAttempt_r13,
                  2<<*p->prach_StartingSubframe_r13);
401 402 403
    }
  
  }
Cedric Roux's avatar
Cedric Roux committed
404
#endif
405
  /*
406 407 408 409 410 411 412 413 414
  if (rrc->node_type == ngran_eNB_DU) {
    LOG_D(RRC, "About to call rrc_mac_config_req_eNB for ngran_eNB_DU\n");
    
    rrc_mac_config_req_eNB(ctxt_pP->module_id, CC_id,
			   carrier->physCellId,
			   carrier->p_eNB,
			   carrier->Ncp,
			   carrier->sib1->freqBandIndicator,
			   carrier->dl_CarrierFreq,
415
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
416
			   carrier->pbch_repetition,
417
#endif
418 419 420 421
			   0, // rnti
			   (BCCH_BCH_Message_t *)
			   &carrier->mib,
			   (RadioResourceConfigCommonSIB_t *) NULL,
422
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
423
			   (RadioResourceConfigCommonSIB_t *) NULL,
424
#endif
425
			   (struct PhysicalConfigDedicated *)NULL,
426
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
427 428 429 430 431 432 433 434 435 436 437 438 439 440
			   (SCellToAddMod_r10_t *)NULL,
			   //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
#endif
			   (MeasObjectToAddMod_t **) NULL,
			   (MAC_MainConfig_t *) NULL, 0,
			   (struct LogicalChannelConfig *)NULL,
			   (MeasGapConfig_t *) NULL,
			   carrier->sib1->tdd_Config,
			   NULL,
			   &carrier->sib1->schedulingInfoList,
			   carrier->ul_CarrierFreq,
			   NULL,
			   NULL,
			   NULL
441
#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
442 443 444 445
			   ,
			   carrier->MBMS_flag,
			   NULL,
			   (PMCH_InfoList_r9_t *) NULL
446
#endif
447
#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
448 449 450 451 452
			   , 
			   NULL
#endif
			   );
  }
453 454
  else 
  */
455
  if (NODE_IS_MONOLITHIC(rrc->node_type)) {
456 457 458
    LOG_D(RRC, "About to call rrc_mac_config_req_eNB for ngran_eNB\n");
    
    rrc_mac_config_req_eNB(ctxt_pP->module_id, CC_id,
459 460 461 462 463 464 465 466 467 468 469 470 471
                           carrier->physCellId,
                           carrier->p_eNB,
                           carrier->Ncp,
                           carrier->sib1->freqBandIndicator,
                           carrier->dl_CarrierFreq,
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                           carrier->pbch_repetition,
#endif
                           0, // rnti
                           (LTE_BCCH_BCH_Message_t *) &carrier->mib,
                           (LTE_RadioResourceConfigCommonSIB_t *) &carrier->sib2->radioResourceConfigCommon,
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
                           (LTE_RadioResourceConfigCommonSIB_t *) &carrier->sib2_BR->radioResourceConfigCommon,
Cedric Roux's avatar
Cedric Roux committed
472
#endif
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
                           (struct LTE_PhysicalConfigDedicated *)NULL,
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
                           (LTE_SCellToAddMod_r10_t *)NULL,
                           //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
#endif
                           (LTE_MeasObjectToAddMod_t **) NULL,
                           (LTE_MAC_MainConfig_t *) NULL, 0,
                           (struct LTE_LogicalChannelConfig *)NULL,
                           (LTE_MeasGapConfig_t *) NULL,
                           carrier->sib1->tdd_Config,
                           NULL,
                           &carrier->sib1->schedulingInfoList,
                           carrier->ul_CarrierFreq,
                           carrier->sib2->freqInfo.ul_Bandwidth,
                           &carrier->sib2->freqInfo.additionalSpectrumEmission,
                           (LTE_MBSFN_SubframeConfigList_t*) carrier->sib2->mbsfn_SubframeConfigList
489
#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
490 491 492 493
                           ,
                           carrier->MBMS_flag,
                           (LTE_MBSFN_AreaInfoList_r9_t*) & carrier->sib13->mbsfn_AreaInfoList_r9,
                           (LTE_PMCH_InfoList_r9_t *) NULL
494
#endif
495
#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
496 497
                           ,
                           sib1_v13ext
498
#endif
499
                           );
500
  }
501 502 503

	/* set flag to indicate that cell information is configured. This is required
	 * in DU to trigger F1AP_SETUP procedure */
504 505 506
  pthread_mutex_lock(&rrc->cell_info_mutex);
  rrc->cell_info_configured=1;
  pthread_mutex_unlock(&rrc->cell_info_mutex);
507 508
}

509
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
winckel's avatar
winckel committed
510
/*------------------------------------------------------------------------------*/
511 512
static void
init_MCCH(
513 514
  module_id_t enb_mod_idP,
  int CC_id
515 516
)
//-----------------------------------------------------------------------------
517 518 519
{
  int                                 sync_area = 0;
  // initialize RRC_eNB_INST MCCH entry
520 521
  eNB_RRC_INST *rrc = RC.rrc[enb_mod_idP];

522
  RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESSAGE =
Cedric Roux's avatar
Cedric Roux committed
523
    malloc(RC.rrc[enb_mod_idP]->carrier[CC_id].num_mbsfn_sync_area * sizeof(uint8_t *));
Lionel Gauthier's avatar
 
Lionel Gauthier committed
524

525 526 527
  for (sync_area = 0; sync_area < RC.rrc[enb_mod_idP]->carrier[CC_id].num_mbsfn_sync_area; sync_area++) {
    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);
528
    AssertFatal(RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESSAGE[sync_area] != NULL,
Cedric Roux's avatar
Cedric Roux committed
529
                "[eNB %d]init_MCCH: FATAL, no memory for MCCH MESSAGE allocated \n", enb_mod_idP);
530
    RC.rrc[enb_mod_idP]->carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] = do_MBSFNAreaConfig(enb_mod_idP,
Cedric Roux's avatar
Cedric Roux committed
531 532 533 534
        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);
535
    LOG_I(RRC, "mcch message pointer %p for sync area %d \n",
Cedric Roux's avatar
Cedric Roux committed
536 537
          RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESSAGE[sync_area],
          sync_area);
538 539
    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,
Cedric Roux's avatar
Cedric Roux committed
540
          RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->commonSF_AllocPeriod_r9);
541
    LOG_D(RRC,
Cedric Roux's avatar
Cedric Roux committed
542 543
          "[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);
544
    LOG_D(RRC, "[eNB %d] MBSFN Subframe Pattern: %02x (in hex)\n",
Cedric Roux's avatar
Cedric Roux committed
545 546 547
          enb_mod_idP,
          RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->commonSF_Alloc_r9.list.array[0]->subframeAllocation.
          choice.oneFrame.buf[0]);
548
    AssertFatal(RC.rrc[enb_mod_idP]->carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] != 255,
Cedric Roux's avatar
Cedric Roux committed
549
                "RC.rrc[enb_mod_idP]->carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] == 255");
550
    RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESS[sync_area].Active = 1;
551
  }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
552

553
  //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)
554 555
  // ??Configure MCCH logical channel
  // call mac_config_req with appropriate structure from ASN.1 description
556 557
  //  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]);
558
  if (NODE_IS_MONOLITHIC(rrc->node_type)) {
559
    rrc_mac_config_req_eNB(enb_mod_idP, CC_id,
560
                           0,0,0,0,0,
561
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
562
                           0,
563
#endif
564 565 566
                           0,//rnti
                           (LTE_BCCH_BCH_Message_t *)NULL,
                           (LTE_RadioResourceConfigCommonSIB_t *) NULL,
567
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
568
                           (LTE_RadioResourceConfigCommonSIB_t *) NULL,
569
#endif
570 571
                           (struct LTE_PhysicalConfigDedicated *)NULL,
                           (LTE_SCellToAddMod_r10_t *)NULL,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
572
                         //(struct LTE_PhysicalConfigDedicatedSCell_r10 *)NULL,
573 574 575 576 577 578 579 580 581 582 583 584 585
                           (LTE_MeasObjectToAddMod_t **) NULL,
                           (LTE_MAC_MainConfig_t *) NULL,
                           0,
                           (struct LTE_LogicalChannelConfig *)NULL,
                           (LTE_MeasGapConfig_t *) NULL,
                           (LTE_TDD_Config_t *) NULL,
                           (LTE_MobilityControlInfo_t *)NULL,
                           (LTE_SchedulingInfoList_t *) NULL,
                           0, NULL, NULL, (LTE_MBSFN_SubframeConfigList_t *) NULL
                           ,
                           0,
                           (LTE_MBSFN_AreaInfoList_r9_t *) NULL,
                           (LTE_PMCH_InfoList_r9_t *) & (RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->pmch_InfoList_r9)
586
#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
587 588
                           ,
                           (LTE_SystemInformationBlockType1_v1310_IEs_t *)NULL
589
#endif
590
                           );
591
  }
592
  //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);
593 594
}

595
//-----------------------------------------------------------------------------
Lionel Gauthier's avatar
 
Lionel Gauthier committed
596
static void init_MBMS(
597
  module_id_t enb_mod_idP,
598
  int         CC_id,
599 600 601
  frame_t frameP
)
//-----------------------------------------------------------------------------
602 603 604
{
  // init the configuration for MTCH
  protocol_ctxt_t               ctxt;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
605

606
  if (RC.rrc[enb_mod_idP]->carrier[CC_id].MBMS_flag > 0) {
607
    PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, enb_mod_idP, ENB_FLAG_YES, NOT_A_RNTI, frameP, 0,enb_mod_idP);
608 609 610
    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
    rrc_pdcp_config_asn1_req(&ctxt,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
611 612
                             (LTE_SRB_ToAddModList_t *)NULL,   // LTE_SRB_ToAddModList
                             (LTE_DRB_ToAddModList_t *)NULL,   // LTE_DRB_ToAddModList
613
                             (LTE_DRB_ToReleaseList_t *)NULL,
614 615 616 617
                             0,     // security mode
                             NULL,  // key rrc encryption
                             NULL,  // key rrc integrity
                             NULL   // key encryption
618
                             , &(RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->pmch_InfoList_r9)
619
                             ,NULL);
620
    
621
    if (!NODE_IS_CU(RC.rrc[enb_mod_idP]->node_type)) {
622
      rrc_rlc_config_asn1_req(&ctxt,
623 624 625 626
                              NULL, // LTE_SRB_ToAddModList
                              NULL,   // LTE_DRB_ToAddModList
                              NULL,   // DRB_ToReleaseList
                              &(RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->pmch_InfoList_r9)
627
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
628
			      ,0, 0
629
#endif
630 631
			      );
    }
632
	    //rrc_mac_config_req();
633
  }
634 635 636
}
#endif

637 638 639 640 641 642
//-----------------------------------------------------------------------------
uint8_t
rrc_eNB_get_next_transaction_identifier(
  module_id_t enb_mod_idP
)
//-----------------------------------------------------------------------------
643
{
644 645
  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;
646
  LOG_T(RRC,"generated xid is %d\n",rrc_transaction_identifier[enb_mod_idP]);
647 648 649 650 651
  return rrc_transaction_identifier[enb_mod_idP];
}
/*------------------------------------------------------------------------------*/
/* Functions to handle UE index in eNB UE list */

winckel's avatar
winckel committed
652

653 654 655 656 657 658 659 660 661 662 663 664 665 666
////-----------------------------------------------------------------------------
//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);
//
667
//    for (i = 0; i < MAX_MOBILES_PER_ENB; i++) {
668
//        if (RC.rrc[enb_mod_idP]->Info.UE_list[i] == UE_identity) {
669 670 671 672 673 674 675 676 677 678 679 680 681
//            // UE_identity already registered
//            reg = TRUE;
//            break;
//        }
//    }
//
//    if (reg == FALSE) {
//        return (UE_MODULE_INVALID);
//    } else
//        return (i);
//}


682
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
683
// return the ue context if there is already an UE with ue_identityP, NULL otherwise
Cedric Roux's avatar
Cedric Roux committed
684
static struct rrc_eNB_ue_context_s *
685
rrc_eNB_ue_context_random_exist(
Cedric Roux's avatar
Cedric Roux committed
686
  const protocol_ctxt_t *const ctxt_pP,
687 688 689 690
  const uint64_t               ue_identityP
)
//-----------------------------------------------------------------------------
{
Cedric Roux's avatar
Cedric Roux committed
691
  struct rrc_eNB_ue_context_s        *ue_context_p = NULL;
692
  RB_FOREACH(ue_context_p, rrc_ue_tree_s, &(RC.rrc[ctxt_pP->module_id]->rrc_ue_head)) {
693
    if (ue_context_p->ue_context.random_ue_identity == ue_identityP)
gauthier's avatar
gauthier committed
694
      return ue_context_p;
695
  }
gauthier's avatar
gauthier committed
696 697 698 699
  return NULL;
}
//-----------------------------------------------------------------------------
// return the ue context if there is already an UE with the same S-TMSI(MMEC+M-TMSI), NULL otherwise
Cedric Roux's avatar
Cedric Roux committed
700
static struct rrc_eNB_ue_context_s *
gauthier's avatar
gauthier committed
701
rrc_eNB_ue_context_stmsi_exist(
Cedric Roux's avatar
Cedric Roux committed
702
  const protocol_ctxt_t *const ctxt_pP,
gauthier's avatar
gauthier committed
703 704 705 706 707
  const mme_code_t             mme_codeP,
  const m_tmsi_t               m_tmsiP
)
//-----------------------------------------------------------------------------
{
Cedric Roux's avatar
Cedric Roux committed
708
  struct rrc_eNB_ue_context_s        *ue_context_p = NULL;
709
  RB_FOREACH(ue_context_p, rrc_ue_tree_s, &(RC.rrc[ctxt_pP->module_id]->rrc_ue_head)) {
kaltenbe's avatar
kaltenbe committed
710
    LOG_I(RRC,"checking for UE S-TMSI %x, mme %x (%p): rnti %x",
Cedric Roux's avatar
Cedric Roux committed
711 712 713
          m_tmsiP, mme_codeP, ue_context_p,
          ue_context_p->ue_context.rnti);

kaltenbe's avatar
kaltenbe committed
714
    if (ue_context_p->ue_context.Initialue_identity_s_TMSI.presence == TRUE) {
715
      printf("=> S-TMSI %x, MME %x\n",
Cedric Roux's avatar
Cedric Roux committed
716 717 718
             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
719 720 721
      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;
Cedric Roux's avatar
Cedric Roux committed
722
    } else
kaltenbe's avatar
kaltenbe committed
723
      printf("\n");
gauthier's avatar
gauthier committed
724 725
  }
  return NULL;
726 727
}

728 729
//-----------------------------------------------------------------------------
// return a new ue context structure if ue_identityP, ctxt_pP->rnti not found in collection
Cedric Roux's avatar
Cedric Roux committed
730
static struct rrc_eNB_ue_context_s *
731
rrc_eNB_get_next_free_ue_context(
Cedric Roux's avatar
Cedric Roux committed
732
  const protocol_ctxt_t *const ctxt_pP,
733 734 735 736
  const uint64_t               ue_identityP
)
//-----------------------------------------------------------------------------
{
Cedric Roux's avatar
Cedric Roux committed
737
  struct rrc_eNB_ue_context_s        *ue_context_p = NULL;
738
  ue_context_p = rrc_eNB_get_ue_context(
Cedric Roux's avatar
Cedric Roux committed
739 740
                   RC.rrc[ctxt_pP->module_id],
                   ctxt_pP->rnti);
741 742

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

745 746 747 748 749
    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;
750
    }
751

752 753 754
    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;
755
    RB_INSERT(rrc_ue_tree_s, &RC.rrc[ctxt_pP->module_id]->rrc_ue_head, ue_context_p);
756 757 758 759 760 761 762 763 764 765 766
    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;
  } 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;
  }
767
  return(ue_context_p);
winckel's avatar
winckel committed
768 769
}

770 771 772
//-----------------------------------------------------------------------------
void
rrc_eNB_free_mem_UE_context(
Cedric Roux's avatar
Cedric Roux committed
773 774
  const protocol_ctxt_t               *const ctxt_pP,
  struct rrc_eNB_ue_context_s         *const ue_context_pP
775
)
776
//-----------------------------------------------------------------------------
Lionel Gauthier's avatar
Lionel Gauthier committed
777
{
778 779
  int i;
  LOG_T(RRC,
Cedric Roux's avatar
Cedric Roux committed
780
        PROTOCOL_RRC_CTXT_UE_FMT" Clearing UE context 0x%p (free internal structs)\n",
781 782
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
        ue_context_pP);
783 784 785
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
  ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_LTE_SCellToAddMod_r10, &ue_context_pP->ue_context.sCell_config[0]);
  ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_LTE_SCellToAddMod_r10, &ue_context_pP->ue_context.sCell_config[1]);
786 787 788
#endif

  if (ue_context_pP->ue_context.SRB_configList) {
789
    ASN_STRUCT_FREE(asn_DEF_LTE_SRB_ToAddModList, ue_context_pP->ue_context.SRB_configList);
790 791
    ue_context_pP->ue_context.SRB_configList = NULL;
  }
792

Cedric Roux's avatar
Cedric Roux committed
793 794 795 796 797
  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;
    }
798 799
  }

800
  if (ue_context_pP->ue_context.DRB_configList) {
801
    ASN_STRUCT_FREE(asn_DEF_LTE_DRB_ToAddModList, ue_context_pP->ue_context.DRB_configList);
802 803
    ue_context_pP->ue_context.DRB_configList = NULL;
  }
804

Cedric Roux's avatar
Cedric Roux committed
805 806 807 808 809 810 811 812 813 814
  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;
    }
815 816
  }

817
  memset(ue_context_pP->ue_context.DRB_active, 0, sizeof(ue_context_pP->ue_context.DRB_active));
818

819
  if (ue_context_pP->ue_context.physicalConfigDedicated) {
820
    ASN_STRUCT_FREE(asn_DEF_LTE_PhysicalConfigDedicated, ue_context_pP->ue_context.physicalConfigDedicated);
821
    ue_context_pP->ue_context.physicalConfigDedicated = NULL;
822 823
  }

824
  if (ue_context_pP->ue_context.sps_Config) {
825
    ASN_STRUCT_FREE(asn_DEF_LTE_SPS_Config, ue_context_pP->ue_context.sps_Config);
826
    ue_context_pP->ue_context.sps_Config = NULL;
827 828
  }

829 830
  for (i=0; i < MAX_MEAS_OBJ; i++) {
    if (ue_context_pP->ue_context.MeasObj[i] != NULL) {
831
      ASN_STRUCT_FREE(asn_DEF_LTE_MeasObjectToAddMod, ue_context_pP->ue_context.MeasObj[i]);
832 833
      ue_context_pP->ue_context.MeasObj[i] = NULL;
    }
834
  }
835

836 837
  for (i=0; i < MAX_MEAS_CONFIG; i++) {
    if (ue_context_pP->ue_context.ReportConfig[i] != NULL) {
838
      ASN_STRUCT_FREE(asn_DEF_LTE_ReportConfigToAddMod, ue_context_pP->ue_context.ReportConfig[i]);
839 840 841
      ue_context_pP->ue_context.ReportConfig[i] = NULL;
    }
  }
842

843
  if (ue_context_pP->ue_context.QuantityConfig) {
844
    ASN_STRUCT_FREE(asn_DEF_LTE_QuantityConfig, ue_context_pP->ue_context.QuantityConfig);
845 846
    ue_context_pP->ue_context.QuantityConfig = NULL;
  }
847

848
  if (ue_context_pP->ue_context.mac_MainConfig) {
849
    ASN_STRUCT_FREE(asn_DEF_LTE_MAC_MainConfig, ue_context_pP->ue_context.mac_MainConfig);
850 851
    ue_context_pP->ue_context.mac_MainConfig = NULL;
  }
852

Cedric Roux's avatar
Cedric Roux committed
853
  /*  if (ue_context_pP->ue_context.measGapConfig) {
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
854
      ASN_STRUCT_FREE(asn_DEF_LTE_MeasGapConfig, ue_context_pP->ue_context.measGapConfig);
Cedric Roux's avatar
Cedric Roux committed
855 856 857
      ue_context_pP->ue_context.measGapConfig = NULL;
    }*/
  if (ue_context_pP->ue_context.handover_info) {
Konstantinos Alexandris's avatar
Konstantinos Alexandris committed
858 859
    /* TODO: be sure free is enough here (check memory leaks) */
    free(ue_context_pP->ue_context.handover_info);
Cedric Roux's avatar
Cedric Roux committed
860 861
    ue_context_pP->ue_context.handover_info = NULL;
  }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
862

863 864 865 866 867
  //SRB_INFO                           SI;
  //SRB_INFO                           Srb0;
  //SRB_INFO_TABLE_ENTRY               Srb1;
  //SRB_INFO_TABLE_ENTRY               Srb2;
  if (ue_context_pP->ue_context.measConfig) {
868
    ASN_STRUCT_FREE(asn_DEF_LTE_MeasConfig, ue_context_pP->ue_context.measConfig);
869
    ue_context_pP->ue_context.measConfig = NULL;
870
  }
871

872
  if (ue_context_pP->ue_context.measConfig) {
873
    ASN_STRUCT_FREE(asn_DEF_LTE_MeasConfig, ue_context_pP->ue_context.measConfig);
874
    ue_context_pP->ue_context.measConfig = NULL;
875
  }
876

877
#if 0
878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897
  //HANDOVER_INFO                     *handover_info;
  //uint8_t kenb[32];
  //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
898
#endif
899 900
}

901
//-----------------------------------------------------------------------------
902
/*
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
903
* Should be called when UE context in eNB should be released
904
* or when S1 command UE_CONTEXT_RELEASE_REQ should be sent
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
905
*/
906
void
907 908 909
rrc_eNB_free_UE(
  const module_id_t enb_mod_idP,
  const struct rrc_eNB_ue_context_s *const ue_context_pP)
910
//-----------------------------------------------------------------------------
Lionel Gauthier's avatar
Lionel Gauthier committed
911
{
912
  rnti_t rnti = ue_context_pP->ue_context.rnti;
Cedric Roux's avatar
Cedric Roux committed
913

914
  if (enb_mod_idP >= NB_eNB_INST) {
915
    LOG_E(RRC, "eNB instance invalid (%d/%d) for UE %x!\n",
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
916 917 918
          enb_mod_idP,
          NB_eNB_INST,
          rnti);
Cedric Roux's avatar
Cedric Roux committed
919
    return;
920
  }
Lionel Gauthier's avatar
Lionel Gauthier committed
921

922
   if(EPC_MODE_ENABLED) {
923
     if (!NODE_IS_DU(RC.rrc[enb_mod_idP]->node_type)) {
924 925 926 927 928 929 930 931 932 933 934 935 936 937
       if((ue_context_pP->ue_context.ul_failure_timer >= 20000) && (mac_eNB_get_rrc_status(enb_mod_idP, rnti) >= RRC_CONNECTED)) {
         LOG_I(RRC, "[eNB %d] S1AP_UE_CONTEXT_RELEASE_REQ sent for RNTI %x, cause 21, radio connection with ue lost\n",
               enb_mod_idP,
               rnti);
         rrc_eNB_send_S1AP_UE_CONTEXT_RELEASE_REQ(enb_mod_idP,
                                                  ue_context_pP,
                                                  S1AP_CAUSE_RADIO_NETWORK,
                                                  21); // send cause 21: radio connection with ue lost
        /* From 3GPP 36300v10 p129 : 19.2.2.2.2 S1 UE Context Release Request (eNB triggered)
         * If the E-UTRAN internal reason is a radio link failure detected in the eNB, the eNB shall wait a sufficient time before
         *  triggering the S1 UE Context Release Request procedure in order to allow the UE to perform the NAS recovery
         *  procedure, see TS 23.401 [17].
         */
        return;
938
      }
Cedric Roux's avatar
Cedric Roux committed
939

940 941 942 943 944 945 946 947 948 949 950 951
      if((ue_context_pP->ue_context.ue_rrc_inactivity_timer >= RC.rrc[enb_mod_idP]->configuration.rrc_inactivity_timer_thres) &&
          (mac_eNB_get_rrc_status(enb_mod_idP, rnti) >= RRC_CONNECTED) &&
          (RC.rrc[enb_mod_idP]->configuration.rrc_inactivity_timer_thres > 0)) {
        LOG_I(RRC, "[eNB %d] S1AP_UE_CONTEXT_RELEASE_REQ sent for RNTI %x, cause 20, user inactivity\n",
              enb_mod_idP,
              rnti);
        rrc_eNB_send_S1AP_UE_CONTEXT_RELEASE_REQ(enb_mod_idP,
                                                 ue_context_pP,
                                                 S1AP_CAUSE_RADIO_NETWORK,
                                                 20); // send cause 20: user inactivity
        return;
      }
952
    }
953
  }
954

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
955 956 957
  LOG_W(RRC, "[eNB %d] Removing UE RNTI %x\n",
        enb_mod_idP,
        rnti);
958 959
  // add UE info to freeList
  LOG_I(RRC, "Put UE %x into freeList\n",
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
960
        rnti);
961
  put_UE_in_freelist(enb_mod_idP, rnti, 1);
962
}
963

Cedric Roux's avatar
Cedric Roux committed
964 965 966 967 968 969 970 971
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);
972 973
}

Cedric Roux's avatar
Cedric Roux committed
974 975 976 977 978 979 980 981 982 983
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);
984 985
}

Cedric Roux's avatar
Cedric Roux committed
986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002
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;
  LTE_eNB_DLSCH_t                          *dlsch = 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) {
1003
    pthread_mutex_unlock(&lock_ue_freelist);
Cedric Roux's avatar
Cedric Roux committed
1004 1005
    return;
  }
1006

Cedric Roux's avatar
Cedric Roux committed
1007 1008 1009
  if(tail < head) {
    tail = head + eNB_MAC->UE_free_list.num_UEs;
  }
1010

Cedric Roux's avatar
Cedric Roux committed
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040
  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<MAX_MOBILES_PER_ENB; i++) {
          ulsch = eNB_PHY->ulsch[i];

          if((ulsch != NULL) && (ulsch->rnti == rnti)) {
            void clean_eNb_ulsch(LTE_eNB_ULSCH_t *ulsch);
            LOG_I(RRC, "clean_eNb_ulsch ulsch[%d] UE %x\n", i, rnti);
            clean_eNb_ulsch(ulsch);
          }

          if(eNB_PHY->uci_vars[i].rnti == rnti) {
            LOG_I(MAC, "clean eNb uci_vars[%d] UE %x \n",i, rnti);
            memset(&eNB_PHY->uci_vars[i],0,sizeof(LTE_eNB_UCI));
          }
        }

        for (i=0; i<MAX_MOBILES_PER_ENB; i++) {
          dlsch = eNB_PHY->dlsch[i][0];
1041

Cedric Roux's avatar
Cedric Roux committed
1042 1043 1044 1045 1046 1047
          if((dlsch != NULL) && (dlsch->rnti == rnti)) {
            void clean_eNb_dlsch(LTE_eNB_DLSCH_t *dlsch);
            LOG_I(RRC, "clean_eNb_dlsch dlsch[%d] UE %x \n", i, rnti);
            clean_eNb_dlsch(dlsch);
          }
        }
1048

1049 1050 1051
        if (flexran_agent_get_rrc_xface(mod_id)) {
          flexran_agent_get_rrc_xface(mod_id)->flexran_agent_notify_ue_state_change(
              mod_id, rnti, PROTOCOL__FLEX_UE_STATE_CHANGE_TYPE__FLUESC_DEACTIVATED);
Cedric Roux's avatar
Cedric Roux committed
1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069
        }

        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) ||
                  (ul_req_tmp->ul_config_pdu_list[pdu_index].uci_harq_pdu.ue_information.ue_information_rel8.rnti == rnti) ||
                  (ul_req_tmp->ul_config_pdu_list[pdu_index].uci_cqi_pdu.ue_information.ue_information_rel8.rnti == rnti) ||
                  (ul_req_tmp->ul_config_pdu_list[pdu_index].uci_sr_pdu.ue_information.ue_information_rel8.rnti == rnti) ||
                  (ul_req_tmp->ul_config_pdu_list[pdu_index].srs_pdu.srs_pdu_rel8.rnti == rnti)) {
                LOG_I(RRC, "remove UE %x from ul_config_pdu_list %d/%d\n", rnti, pdu_index, pdu_number);

                if(pdu_index < pdu_number -1) {
                  memcpy(&ul_req_tmp->ul_config_pdu_list[pdu_index], &ul_req_tmp->ul_config_pdu_list[pdu_index+1], (pdu_number-1-pdu_index) * sizeof(nfapi_ul_config_request_pdu_t));
1070
                }
Cedric Roux's avatar
Cedric Roux committed
1071 1072

                ul_req_tmp->number_of_pdus--;
1073 1074
              }
            }
Cedric Roux's avatar
Cedric Roux committed
1075
          }
1076
        }
Cedric Roux's avatar
Cedric Roux committed
1077 1078
      }

1079
      if (!NODE_IS_CU(RC.rrc[mod_id]->node_type)) {
1080 1081 1082 1083
        rrc_mac_remove_ue(mod_id,rnti);
        rrc_rlc_remove_ue(&ctxt);
        pdcp_remove_UE(&ctxt);
      }
1084
      else {
1085 1086 1087 1088 1089 1090 1091 1092
        MessageDef *m = itti_alloc_new_message(TASK_RRC_ENB, F1AP_UE_CONTEXT_RELEASE_CMD);
        F1AP_UE_CONTEXT_RELEASE_CMD(m).rnti = rnti;
        F1AP_UE_CONTEXT_RELEASE_CMD(m).cause = F1AP_CAUSE_RADIO_NETWORK;
        F1AP_UE_CONTEXT_RELEASE_CMD(m).cause_value = 10; // 10 = F1AP_CauseRadioNetwork_normal_release
        F1AP_UE_CONTEXT_RELEASE_CMD(m).rrc_container = NULL;
        F1AP_UE_CONTEXT_RELEASE_CMD(m).rrc_container_length = 0;
        itti_send_msg_to_task(TASK_CU_F1, mod_id, m);
      }
Cedric Roux's avatar
Cedric Roux committed
1093 1094

      if(remove_UEContext) {
1095
        ue_context_pP = rrc_eNB_get_ue_context(RC.rrc[mod_id],rnti);
Cedric Roux's avatar
Cedric Roux committed
1096 1097 1098 1099

        if(ue_context_pP) {
          rrc_eNB_remove_ue_context(&ctxt,RC.rrc[mod_id],
                                    (struct rrc_eNB_ue_context_s *) ue_context_pP);
1100
        }
Cedric Roux's avatar
Cedric Roux committed
1101 1102 1103 1104
      }

      LOG_I(RRC, "[release_UE_in_freeList] remove UE %x from freeList\n", rnti);
      remove_UE_from_freelist(mod_id, rnti);
1105
    }
Cedric Roux's avatar
Cedric Roux committed
1106
  }
1107
}
1108

1109
//-----------------------------------------------------------------------------
1110 1111 1112
/*
* Process the rrc connection setup complete message from UE (SRB1 Active)
*/
1113 1114
void
rrc_eNB_process_RRCConnectionSetupComplete(
Cedric Roux's avatar
Cedric Roux committed
1115
  const protocol_ctxt_t *const ctxt_pP,
1116
  rrc_eNB_ue_context_t *ue_context_pP,
1117
  LTE_RRCConnectionSetupComplete_r8_IEs_t *rrcConnectionSetupComplete
1118
)
1119
//-----------------------------------------------------------------------------
Lionel Gauthier's avatar
Lionel Gauthier committed
1120
{
1121
  LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel UL-DCCH, " "processing LTE_RRCConnectionSetupComplete from UE (SRB1 Active)\n",
1122
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
1123

1124 1125
  ue_context_pP->ue_context.Srb1.Active = 1;
  ue_context_pP->ue_context.Status = RRC_CONNECTED;
1126 1127 1128 1129 1130 1131 1132
  ue_context_pP->ue_context.ue_rrc_inactivity_timer = 1; // set rrc inactivity timer when UE goes into RRC_CONNECTED

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

1134 1135
  if (EPC_MODE_ENABLED == 1) {
    // Forward message to S1AP layer
1136
    rrc_eNB_send_S1AP_NAS_FIRST_REQ(ctxt_pP, ue_context_pP, rrcConnectionSetupComplete);
1137
  } else {
1138
    // RRC loop back (no S1AP), send SecurityModeCommand to UE
1139
    rrc_eNB_generate_SecurityModeCommand(ctxt_pP, ue_context_pP);
1140
  }
winckel's avatar
winckel committed
1141 1142
}

1143 1144 1145
//-----------------------------------------------------------------------------
void
rrc_eNB_generate_SecurityModeCommand(
Cedric Roux's avatar
Cedric Roux committed
1146 1147
  const protocol_ctxt_t *const ctxt_pP,
  rrc_eNB_ue_context_t          *const ue_context_pP
1148
)
1149
//-----------------------------------------------------------------------------
Lionel Gauthier's avatar
Lionel Gauthier committed
1150
{
1151 1152
  uint8_t                             buffer[100];
  uint8_t                             size;
Cedric Roux's avatar
Cedric Roux committed
1153 1154
  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));
1155 1156 1157 1158 1159 1160
  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);
1161
  LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)buffer,size,"[MSG] RRC Security Mode Command\n");
1162
  LOG_I(RRC,
1163 1164 1165
        PROTOCOL_RRC_CTXT_UE_FMT" Logical Channel DL-DCCH, Generate SecurityModeCommand (bytes %d)\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
        size);
1166
  LOG_D(RRC,
1167 1168 1169 1170 1171
        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);
1172
  MSC_LOG_TX_MESSAGE(
1173 1174 1175 1176 1177 1178 1179 1180 1181
    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);
1182

1183
  if (!NODE_IS_DU(RC.rrc[ctxt_pP->module_id]->node_type)) {
1184
    LOG_I(RRC,"calling rrc_data_req :securityModeCommand\n");
1185

1186 1187 1188 1189 1190 1191 1192 1193
    rrc_data_req(ctxt_pP,
                 DCCH,
                 rrc_eNB_mui++,
                 SDU_CONFIRM_NO,
                 size,
                 buffer,
                 PDCP_TRANSMISSION_MODE_CONTROL);
  }
1194 1195
}

1196 1197 1198
//-----------------------------------------------------------------------------
void
rrc_eNB_generate_UECapabilityEnquiry(
Cedric Roux's avatar
Cedric Roux committed
1199 1200
  const protocol_ctxt_t *const ctxt_pP,
  rrc_eNB_ue_context_t          *const ue_context_pP
1201 1202
)
//-----------------------------------------------------------------------------
1203 1204 1205
{
  uint8_t                             buffer[100];
  uint8_t                             size;
Cedric Roux's avatar
Cedric Roux committed
1206 1207
  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));
1208 1209 1210 1211
  size = do_UECapabilityEnquiry(
           ctxt_pP,
           buffer,
           rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id));
1212
  LOG_I(RRC,
1213 1214 1215
        PROTOCOL_RRC_CTXT_UE_FMT" Logical Channel DL-DCCH, Generate UECapabilityEnquiry (bytes %d)\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
        size);
1216
  LOG_D(RRC,
1217 1218 1219 1220 1221
        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);
1222
  MSC_LOG_TX_MESSAGE(
1223 1224 1225 1226 1227 1228 1229 1230 1231
    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);
1232
  rrc_data_req(
Cedric Roux's avatar
Cedric Roux committed
1233 1234 1235 1236 1237 1238 1239
    ctxt_pP,
    DCCH,
    rrc_eNB_mui++,
    SDU_CONFIRM_NO,
    size,
    buffer,
    PDCP_TRANSMISSION_MODE_CONTROL);
1240 1241
}

1242 1243 1244
//-----------------------------------------------------------------------------
void
rrc_eNB_generate_RRCConnectionReject(
Cedric Roux's avatar
Cedric Roux committed
1245 1246
  const protocol_ctxt_t *const ctxt_pP,
  rrc_eNB_ue_context_t          *const ue_context_pP,
1247 1248 1249 1250
  const int                    CC_id
)
//-----------------------------------------------------------------------------
{
Cedric Roux's avatar
Cedric Roux committed
1251 1252 1253
  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));

1254
  eNB_RRC_UE_t *ue_p = &ue_context_pP->ue_context;
1255
  ue_p->Srb0.Tx_buffer.payload_size =
1256
    do_RRCConnectionReject(ctxt_pP->module_id,
1257
                          (uint8_t*) ue_p->Srb0.Tx_buffer.Payload);
1258

1259
  LOG_DUMPMSG(RRC,DEBUG_RRC,
1260
              (char *)(ue_p->Srb0.Tx_buffer.Payload),
1261
              ue_p->Srb0.Tx_buffer.payload_size,
1262
              "[MSG] RRCConnectionReject\n");
1263 1264 1265
  MSC_LOG_TX_MESSAGE(
    MSC_RRC_ENB,
    MSC_RRC_UE,
1266 1267
    ue_p->Srb0.Tx_buffer.Header,
    ue_p->Srb0.Tx_buffer.payload_size,
1268
    MSC_AS_TIME_FMT" LTE_RRCConnectionReject UE %x size %u",
1269 1270
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP == NULL ? -1 : ue_context_pP->ue_context.rnti,
1271
    ue_p->Srb0.Tx_buffer.payload_size);
1272
  LOG_I(RRC,
1273
        PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel DL-CCCH, Generating LTE_RRCConnectionReject (bytes %d)\n",
1274
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
1275
        ue_p->Srb0.Tx_buffer.payload_size);
1276 1277
}

1278
//-----------------------------------------------------------------------------
1279 1280 1281
/*
 * Generate a RCC Connection Reestablishment after requested
 */
1282
void
1283
rrc_eNB_generate_RRCConnectionReestablishment(
1284 1285 1286
  const protocol_ctxt_t *const ctxt_pP,
  rrc_eNB_ue_context_t  *const ue_context_pP,
  const int             CC_id)
1287 1288
//-----------------------------------------------------------------------------
{
1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308
  int UE_id = -1;
  LTE_LogicalChannelConfig_t *SRB1_logicalChannelConfig = NULL;
  LTE_SRB_ToAddModList_t     **SRB_configList;
  LTE_SRB_ToAddMod_t         *SRB1_config = NULL;
  rrc_eNB_carrier_data_t     *carrier = NULL;
  eNB_RRC_UE_t               *ue_context = NULL;

  module_id_t module_id = ctxt_pP->module_id;
  uint16_t rnti = ctxt_pP->rnti;

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

  SRB_configList = &(ue_context_pP->ue_context.SRB_configList);
  carrier = &(RC.rrc[ctxt_pP->module_id]->carrier[CC_id]);
  ue_context = &(ue_context_pP->ue_context);

OAI-admin's avatar
OAI-admin committed
1309
  ue_context->Srb0.Tx_buffer.payload_size = do_RRCConnectionReestablishment(ctxt_pP,
1310 1311
                                                                         ue_context_pP,
                                                                         CC_id,
OAI-admin's avatar
OAI-admin committed
1312
                                                                         (uint8_t *) ue_context->Srb0.Tx_buffer.Payload,
1313 1314 1315 1316 1317 1318
                                                                         (uint8_t) carrier->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(module_id),
                                                                         SRB_configList,
                                                                         &(ue_context->physicalConfigDedicated));

  LOG_DUMPMSG(RRC, DEBUG_RRC,
OAI-admin's avatar
OAI-admin committed
1319 1320
              (char *)(ue_context->Srb0.Tx_buffer.Payload),
              ue_context->Srb0.Tx_buffer.payload_size,
1321 1322 1323
              "[MSG] RRCConnectionReestablishment \n");

  /* Configure SRB1 for UE */
1324
  if (*SRB_configList != NULL) {
1325
    for (int cnt = 0; cnt < (*SRB_configList)->list.count; cnt++) {
1326 1327
      if ((*SRB_configList)->list.array[cnt]->srb_Identity == 1) {
        SRB1_config = (*SRB_configList)->list.array[cnt];
1328

1329
        if (SRB1_config->logicalChannelConfig) {
1330 1331
          if (SRB1_config->logicalChannelConfig->present == LTE_SRB_ToAddMod__logicalChannelConfig_PR_explicitValue) {
            SRB1_logicalChannelConfig = &(SRB1_config->logicalChannelConfig->choice.explicitValue);
1332
          } else {
1333
            SRB1_logicalChannelConfig = &(SRB1_logicalChannelConfig_defaultValue);
1334 1335
          }
        } else {
1336
          SRB1_logicalChannelConfig = &(SRB1_logicalChannelConfig_defaultValue);
1337
        }
Raymond Knopp's avatar
 
Raymond Knopp committed
1338

1339
        LOG_D(RRC, PROTOCOL_RRC_CTXT_UE_FMT" RRC_eNB --- MAC_CONFIG_REQ  (SRB1) ---> MAC_eNB\n",
1340
              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
1341
        if (NODE_IS_MONOLITHIC(RC.rrc[ctxt_pP->module_id]->node_type)) {
1342 1343 1344 1345 1346 1347 1348
          rrc_mac_config_req_eNB(module_id,
                                 ue_context->primaryCC_id,
                                 0,
                                 0,
                                 0,
                                 0,
                                 0,
1349
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
1350
                                 0,
1351
#endif
1352
                                 rnti,
1353 1354
                                 (LTE_BCCH_BCH_Message_t *) NULL,
                                 (LTE_RadioResourceConfigCommonSIB_t *) NULL,
1355
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
1356
                                 (LTE_RadioResourceConfigCommonSIB_t *) NULL,
1357
#endif
1358
                                 (struct LTE_PhysicalConfigDedicated * ) ue_context->physicalConfigDedicated,
1359
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
1360 1361 1362
                                 (LTE_SCellToAddMod_r10_t *)NULL,
#endif
                                 (LTE_MeasObjectToAddMod_t **) NULL,
1363
                                 ue_context->mac_MainConfig,
1364 1365
                                 1,
                                 SRB1_logicalChannelConfig,
1366
                                 ue_context->measGapConfig,
1367 1368 1369
                                 (LTE_TDD_Config_t *) NULL,
                                 NULL,
                                 (LTE_SchedulingInfoList_t *) NULL,
1370 1371 1372 1373
                                 0,
                                 NULL,
                                 NULL,
                                 (LTE_MBSFN_SubframeConfigList_t *) NULL
1374
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
1375 1376 1377
                                 , 0,
                                 (LTE_MBSFN_AreaInfoList_r9_t *) NULL,
                                 (LTE_PMCH_InfoList_r9_t *) NULL
1378
#endif
1379
#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
1380
                                 ,(LTE_SystemInformationBlockType1_v1310_IEs_t *) NULL
1381
#endif
1382
                                 );
1383 1384
          break;
        }
1385 1386 1387
      }  // if ((*SRB_configList)->list.array[cnt]->srb_Identity == 1)
    }  // for (int cnt = 0; cnt < (*SRB_configList)->list.count; cnt++)
  }  // if (*SRB_configList != NULL)
Raymond Knopp's avatar
 
Raymond Knopp committed
1388

1389 1390
  MSC_LOG_TX_MESSAGE(MSC_RRC_ENB,
                     MSC_RRC_UE,
OAI-admin's avatar
OAI-admin committed
1391 1392
                     ue_context->Srb0.Tx_buffer.Header,
                     ue_context->Srb0.Tx_buffer.payload_size,
1393
                     MSC_AS_TIME_FMT" LTE_RRCConnectionReestablishment UE %x size %u",
1394
                     MSC_AS_TIME_ARGS(ctxt_pP),
1395
                     ue_context->rnti,
OAI-admin's avatar
OAI-admin committed
1396
                     ue_context->Srb0.Tx_buffer.payload_size);
Cedric Roux's avatar
Cedric Roux committed
1397

1398
  LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel DL-CCCH, Generating LTE_RRCConnectionReestablishment (bytes %d)\n",
1399
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
OAI-admin's avatar
OAI-admin committed
1400
        ue_context->Srb0.Tx_buffer.payload_size);
1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412

  UE_id = find_UE_id(module_id, rnti);

  if (UE_id != -1) {
    /* Activate reject timer, if RRCComplete not received after 10 frames, reject UE */
    RC.mac[module_id]->UE_list.UE_sched_ctrl[UE_id].ue_reestablishment_reject_timer = 1;
    /* Reject UE after 10 frames, LTE_RRCConnectionReestablishmentReject is triggered */
    RC.mac[module_id]->UE_list.UE_sched_ctrl[UE_id].ue_reestablishment_reject_timer_thres = 100;
  } else {
    LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Generating LTE_RRCConnectionReestablishment without UE_id(MAC) rnti %x\n",
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
          rnti);
1413
  }
1414 1415

  /* Activate release timer, if RRCComplete not received after 100 frames, remove UE */
1416
  ue_context_pP->ue_context.ue_reestablishment_timer = 1;
1417
  /* Remove UE after 100 frames after LTE_RRCConnectionReestablishmentReject is triggered */
1418
  ue_context_pP->ue_context.ue_reestablishment_timer_thres = 1000;
Raymond Knopp's avatar
 
Raymond Knopp committed
1419
}
1420

1421 1422
//-----------------------------------------------------------------------------
void
1423
rrc_eNB_process_RRCConnectionReestablishmentComplete(
Cedric Roux's avatar
Cedric Roux committed
1424
  const protocol_ctxt_t *const ctxt_pP,
Cedric Roux's avatar
Cedric Roux committed
1425
  const rnti_t reestablish_rnti,
Cedric Roux's avatar
Cedric Roux committed
1426
  rrc_eNB_ue_context_t         *ue_context_pP,
1427
  const uint8_t xid,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
1428
  LTE_RRCConnectionReestablishmentComplete_r8_IEs_t *LTE_RRCConnectionReestablishmentComplete
1429
)
1430 1431
//-----------------------------------------------------------------------------
{
1432
  LOG_I(RRC,
1433
        PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel UL-DCCH, processing LTE_RRCConnectionReestablishmentComplete from UE (SRB1 Active)\n",
1434 1435 1436
        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));
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
1437 1438 1439 1440
  LTE_DRB_ToAddModList_t                 *DRB_configList = ue_context_pP->ue_context.DRB_configList;
  LTE_SRB_ToAddModList_t                 *SRB_configList = ue_context_pP->ue_context.SRB_configList;
  LTE_SRB_ToAddModList_t                **SRB_configList2 = NULL;
  LTE_DRB_ToAddModList_t                **DRB_configList2 = NULL;
1441 1442
  struct LTE_SRB_ToAddMod                *SRB2_config = NULL;
  struct LTE_DRB_ToAddMod                *DRB_config = NULL;
1443
  int i = 0;
1444 1445
  uint8_t                             buffer[RRC_BUF_SIZE];
  uint16_t                            size;
1446 1447 1448 1449
  LTE_MeasObjectToAddModList_t       *MeasObj_list                     = NULL;
  LTE_MeasObjectToAddMod_t           *MeasObj                          = NULL;
  LTE_ReportConfigToAddModList_t     *ReportConfig_list                = NULL;
  LTE_ReportConfigToAddMod_t         *ReportConfig_per, *ReportConfig_A1,
1450
                                     *ReportConfig_A2, *ReportConfig_A3, *ReportConfig_A4, *ReportConfig_A5;
1451 1452 1453 1454 1455 1456 1457 1458 1459
  LTE_MeasIdToAddModList_t           *MeasId_list                      = NULL;
  LTE_MeasIdToAddMod_t               *MeasId0, *MeasId1, *MeasId2, *MeasId3, *MeasId4, *MeasId5;
  LTE_RSRP_Range_t                   *rsrp                             = NULL;
  struct LTE_MeasConfig__speedStatePars  *Sparams                          = NULL;
  LTE_QuantityConfig_t                   *quantityConfig                   = NULL;
  LTE_CellsToAddMod_t                    *CellToAdd                        = NULL;
  LTE_CellsToAddModList_t                *CellsToAddModList                = NULL;
  struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList = NULL;
  LTE_DedicatedInfoNAS_t                 *dedicatedInfoNas                 = NULL;
1460 1461
  /* for no gcc warnings */
  (void)dedicatedInfoNas;
1462
  LTE_C_RNTI_t                           *cba_RNTI                         = NULL;
1463
  int                                    measurements_enabled;
1464 1465
  uint8_t next_xid = rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id);
  ue_context_pP->ue_context.Status = RRC_CONNECTED;
1466
  ue_context_pP->ue_context.ue_rrc_inactivity_timer = 1; // set rrc inactivity when UE goes into RRC_CONNECTED
1467
  ue_context_pP->ue_context.reestablishment_xid = next_xid;
1468
  SRB_configList2 = &ue_context_pP->ue_context.SRB_configList2[xid];
Cedric Roux's avatar
Cedric Roux committed
1469

1470 1471
  // get old configuration of SRB2
  if (*SRB_configList2 != NULL) {
Cedric Roux's avatar
Cedric Roux committed
1472
    if((*SRB_configList2)->list.count!=0) {
1473
      LOG_D(RRC, "SRB_configList2(%p) count is %d\n           SRB_configList2->list.array[0] addr is %p",
Cedric Roux's avatar
Cedric Roux committed
1474
            SRB_configList2, (*SRB_configList2)->list.count,  (*SRB_configList2)->list.array[0]);
1475
    }
Cedric Roux's avatar
Cedric Roux committed
1476

1477
    for (i = 0; (i < (*SRB_configList2)->list.count) && (i < 3); i++) {
Cedric Roux's avatar
Cedric Roux committed
1478
      if ((*SRB_configList2)->list.array[i]->srb_Identity == 2 ) {
1479 1480 1481 1482 1483 1484 1485
        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;
      }
    }
  }

frtabu's avatar
frtabu committed
1486 1487
  SRB_configList2 = &(ue_context_pP->ue_context.SRB_configList2[next_xid]);
  DRB_configList2 = &(ue_context_pP->ue_context.DRB_configList2[next_xid]);
1488

frtabu's avatar
frtabu committed
1489 1490 1491
  if (*SRB_configList2) {
    free(*SRB_configList2);
    LOG_D(RRC, "free(ue_context_pP->ue_context.SRB_configList2[%d])\n", next_xid);
1492
  }
Cedric Roux's avatar
Cedric Roux committed
1493

1494
  *SRB_configList2 = CALLOC(1, sizeof(**SRB_configList2));
Cedric Roux's avatar
Cedric Roux committed
1495

1496 1497 1498 1499 1500
  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",
Cedric Roux's avatar
Cedric Roux committed
1501
          SRB2_config->srb_Identity);
1502
    LOG_D(RRC, "Add SRB2_config (srb_Identity:%ld) to ue_context_pP->ue_context.SRB_configList2[%d]\n",
Cedric Roux's avatar
Cedric Roux committed
1503
          SRB2_config->srb_Identity, next_xid);
1504 1505 1506 1507 1508
  } else {
    // SRB configuration list only contains SRB1.
    LOG_W(RRC,"SRB2 configuration does not exist in SRB configuration list\n");
  }

frtabu's avatar
frtabu committed
1509 1510 1511
  if (*DRB_configList2) {
    free(*DRB_configList2);
    LOG_D(RRC, "free(ue_context_pP->ue_context.DRB_configList2[%d])\n", next_xid);
1512
  }
Cedric Roux's avatar
Cedric Roux committed
1513

1514
  *DRB_configList2 = CALLOC(1, sizeof(**DRB_configList2));
Navid Nikaein's avatar
Navid Nikaein committed
1515

1516 1517
  if (DRB_configList != NULL) {
    LOG_D(RRC, "get DRB_config from (ue_context_pP->ue_context.DRB_configList)\n");
Cedric Roux's avatar
Cedric Roux committed
1518

1519 1520
    for (i = 0; (i < DRB_configList->list.count) && (i < 3); i++) {
      DRB_config = DRB_configList->list.array[i];
1521
      // Add DRB to DRB configuration list, for LTE_RRCConnectionReconfigurationComplete
1522
      ASN_SEQUENCE_ADD(&(*DRB_configList2)->list, DRB_config);
1523
    }
1524
  }
Cedric Roux's avatar
Cedric Roux committed
1525

1526 1527
  ue_context_pP->ue_context.Srb1.Active = 1;
  //ue_context_pP->ue_context.Srb2.Srb_info.Srb_id = 2;
1528 1529

  if (EPC_MODE_ENABLED) {
Cedric Roux's avatar
Cedric Roux committed
1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541
  hashtable_rc_t    h_rc;
  int               j;
  rrc_ue_s1ap_ids_t *rrc_ue_s1ap_ids_p = NULL;
  uint16_t ue_initial_id = ue_context_pP->ue_context.ue_initial_id;
  uint32_t eNB_ue_s1ap_id = ue_context_pP->ue_context.eNB_ue_s1ap_id;
  eNB_RRC_INST *rrc_instance_p = RC.rrc[ENB_INSTANCE_TO_MODULE_ID(ctxt_pP->instance)];

  if (eNB_ue_s1ap_id > 0) {
    h_rc = hashtable_get(rrc_instance_p->s1ap_id2_s1ap_ids, (hash_key_t)eNB_ue_s1ap_id, (void **)&rrc_ue_s1ap_ids_p);

    if  (h_rc == HASH_TABLE_OK) {
      rrc_ue_s1ap_ids_p->ue_rnti = ctxt_pP->rnti;
1542
    }
Cedric Roux's avatar
Cedric Roux committed
1543
  }
1544

Cedric Roux's avatar
Cedric Roux committed
1545 1546
  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);
1547

Cedric Roux's avatar
Cedric Roux committed
1548 1549
    if  (h_rc == HASH_TABLE_OK) {
      rrc_ue_s1ap_ids_p->ue_rnti = ctxt_pP->rnti;
1550
    }
Cedric Roux's avatar
Cedric Roux committed
1551
  }
1552

Cedric Roux's avatar
Cedric Roux committed
1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566
  gtpv1u_enb_create_tunnel_req_t  create_tunnel_req;
  /* Save e RAB information for later */
  memset(&create_tunnel_req, 0, sizeof(create_tunnel_req));

  for ( j = 0, i = 0; i < NB_RB_MAX; i++) {
    if (ue_context_pP->ue_context.e_rab[i].status == E_RAB_STATUS_ESTABLISHED || ue_context_pP->ue_context.e_rab[i].status == E_RAB_STATUS_DONE) {
      create_tunnel_req.eps_bearer_id[j]   = ue_context_pP->ue_context.e_rab[i].param.e_rab_id;
      create_tunnel_req.sgw_S1u_teid[j]  = ue_context_pP->ue_context.e_rab[i].param.gtp_teid;
      memcpy(&create_tunnel_req.sgw_addr[j],
             &ue_context_pP->ue_context.e_rab[i].param.sgw_addr,
             sizeof(transport_layer_addr_t));
      j++;
    }
  }
1567

Cedric Roux's avatar
Cedric Roux committed
1568 1569 1570 1571 1572 1573
  create_tunnel_req.rnti       = ctxt_pP->rnti; // warning put zero above
  create_tunnel_req.num_tunnels    = j;
  gtpv1u_update_s1u_tunnel(
    ctxt_pP->instance,
    &create_tunnel_req,
    reestablish_rnti);
1574 1575
  } /* EPC_MODE_ENABLED */

1576 1577 1578
  /* 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;
1579 1580

  if (EPC_MODE_ENABLED) {
Cedric Roux's avatar
Cedric Roux committed
1581 1582 1583 1584 1585 1586
  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");
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
  // 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);
1622
  //  LTE_RRCConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->measIdToAddModList = MeasId_list;
1623 1624 1625 1626 1627 1628 1629
  // 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;
1630
  MeasObj->measObject.present = LTE_MeasObjectToAddMod__measObject_PR_measObjectEUTRA;
1631 1632
  MeasObj->measObject.choice.measObjectEUTRA.carrierFreq = 3350; //band 7, 2.68GHz
  //MeasObj->measObject.choice.measObjectEUTRA.carrierFreq = 36090; //band 33, 1.909GHz
1633
  MeasObj->measObject.choice.measObjectEUTRA.allowedMeasBandwidth = LTE_AllowedMeasBandwidth_mbw25;
1634 1635 1636 1637 1638 1639 1640
  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 =
1641
    (LTE_CellsToAddModList_t *) CALLOC(1, sizeof(*CellsToAddModList));
1642 1643 1644 1645
  CellsToAddModList = MeasObj->measObject.choice.measObjectEUTRA.cellsToAddModList;

  // Add adjacent cell lists (6 per eNB)
  for (i = 0; i < 6; i++) {
1646
    CellToAdd = (LTE_CellsToAddMod_t *) CALLOC(1, sizeof(*CellToAdd));
1647 1648
    CellToAdd->cellIndex = i + 1;
    CellToAdd->physCellId = get_adjacent_cell_id(ctxt_pP->module_id, i);
1649
    CellToAdd->cellIndividualOffset = LTE_Q_OffsetRange_dB0;
1650 1651 1652 1653
    ASN_SEQUENCE_ADD(&CellsToAddModList->list, CellToAdd);
  }

  ASN_SEQUENCE_ADD(&MeasObj_list->list, MeasObj);
1654
  //  LTE_RRCConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->measObjectToAddModList = MeasObj_list;
1655 1656 1657 1658 1659 1660 1661 1662 1663
  // 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;
1664
  ReportConfig_per->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
1665
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerType.present =
1666
    LTE_ReportConfigEUTRA__triggerType_PR_periodical;
1667
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerType.choice.periodical.purpose =
1668 1669 1670
    LTE_ReportConfigEUTRA__triggerType__periodical__purpose_reportStrongestCells;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerQuantity = LTE_ReportConfigEUTRA__triggerQuantity_rsrp;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both;
1671
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
1672 1673
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity;
1674 1675
  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_per);
  ReportConfig_A1->reportConfigId = 2;
1676
  ReportConfig_A1->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
1677
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.present =
1678
    LTE_ReportConfigEUTRA__triggerType_PR_event;
1679
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
1680
    LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA1;
1681
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA1.
1682
  a1_Threshold.present = LTE_ThresholdEUTRA_PR_threshold_RSRP;
1683 1684
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA1.
  a1_Threshold.choice.threshold_RSRP = 10;
1685 1686
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerQuantity = LTE_ReportConfigEUTRA__triggerQuantity_rsrp;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both;
1687
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
1688 1689
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity;
1690 1691
  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A1);

1692
  if (RC.rrc[ctxt_pP->module_id]->HO_flag == 1 /*HO_MEASUREMENT */ ) {
1693 1694 1695
    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;
1696
    ReportConfig_A2->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
1697
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.present =
1698
      LTE_ReportConfigEUTRA__triggerType_PR_event;
1699
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
1700
      LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA2;
1701
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
1702
    eventA2.a2_Threshold.present = LTE_ThresholdEUTRA_PR_threshold_RSRP;
1703 1704 1705
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
    eventA2.a2_Threshold.choice.threshold_RSRP = 10;
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerQuantity =
1706 1707
      LTE_ReportConfigEUTRA__triggerQuantity_rsrp;
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both;
1708
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
1709 1710
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120;
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity;
1711 1712
    ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A2);
    ReportConfig_A3->reportConfigId = 4;
1713
    ReportConfig_A3->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
1714
    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.present =
1715
      LTE_ReportConfigEUTRA__triggerType_PR_event;
1716
    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
1717
      LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA3;
1718 1719 1720 1721
    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 =
1722 1723
      LTE_ReportConfigEUTRA__triggerQuantity_rsrp;
    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both;
1724
    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
1725 1726
    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120;
    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity;
1727 1728
    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 =
1729
      LTE_TimeToTrigger_ms40;
1730 1731
    ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A3);
    ReportConfig_A4->reportConfigId = 5;
1732
    ReportConfig_A4->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
1733
    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.present =
1734
      LTE_ReportConfigEUTRA__triggerType_PR_event;
1735
    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
1736
      LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA4;
1737
    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
1738
    eventA4.a4_Threshold.present = LTE_ThresholdEUTRA_PR_threshold_RSRP;
1739 1740 1741
    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
    eventA4.a4_Threshold.choice.threshold_RSRP = 10;
    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerQuantity =
1742 1743
      LTE_ReportConfigEUTRA__triggerQuantity_rsrp;
    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both;
1744
    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
1745 1746
    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120;
    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity;
1747 1748
    ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A4);
    ReportConfig_A5->reportConfigId = 6;
1749
    ReportConfig_A5->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
1750
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.present =
1751
      LTE_ReportConfigEUTRA__triggerType_PR_event;
1752
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
1753
      LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA5;
1754
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
1755
    eventA5.a5_Threshold1.present = LTE_ThresholdEUTRA_PR_threshold_RSRP;
1756
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
1757
    eventA5.a5_Threshold2.present = LTE_ThresholdEUTRA_PR_threshold_RSRP;
1758 1759 1760 1761 1762
    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 =
1763 1764
      LTE_ReportConfigEUTRA__triggerQuantity_rsrp;
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both;
1765
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
1766 1767
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120;
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity;
1768
    ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A5);
1769 1770
    //  LTE_RRCConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->reportConfigToAddModList = ReportConfig_list;
    rsrp = CALLOC(1, sizeof(LTE_RSRP_Range_t));
1771 1772
    *rsrp = 20;
    Sparams = CALLOC(1, sizeof(*Sparams));
1773 1774 1775
    Sparams->present = LTE_MeasConfig__speedStatePars_PR_setup;
    Sparams->choice.setup.timeToTrigger_SF.sf_High = LTE_SpeedStateScaleFactors__sf_Medium_oDot75;
    Sparams->choice.setup.timeToTrigger_SF.sf_Medium = LTE_SpeedStateScaleFactors__sf_High_oDot5;
1776 1777
    Sparams->choice.setup.mobilityStateParameters.n_CellChangeHigh = 10;
    Sparams->choice.setup.mobilityStateParameters.n_CellChangeMedium = 5;
1778 1779
    Sparams->choice.setup.mobilityStateParameters.t_Evaluation = LTE_MobilityStateParameters__t_Evaluation_s60;
    Sparams->choice.setup.mobilityStateParameters.t_HystNormal = LTE_MobilityStateParameters__t_HystNormal_s120;
1780 1781
    quantityConfig = CALLOC(1, sizeof(*quantityConfig));
    memset((void *)quantityConfig, 0, sizeof(*quantityConfig));
1782
    quantityConfig->quantityConfigEUTRA = CALLOC(1, sizeof(struct LTE_QuantityConfigEUTRA));
1783 1784 1785 1786 1787 1788 1789 1790
    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)));
1791 1792
    *quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP = LTE_FilterCoefficient_fc4;
    *quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ = LTE_FilterCoefficient_fc4;
1793 1794 1795 1796 1797 1798
    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)));
1799
    //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.srb_ToAddModList,(void *)SRB_list,sizeof(LTE_SRB_ToAddModList_t));
1800
    ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.srb_ToAddModList = *SRB_configList2;
1801
    //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.drb_ToAddModList,(void *)DRB_list,sizeof(LTE_DRB_ToAddModList_t));
1802 1803 1804 1805
    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));
Cedric Roux's avatar
Cedric Roux committed
1806
    memcpy((void *)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig,
1807
           (void *)ue_context_pP->ue_context.mac_MainConfig, sizeof(LTE_MAC_MainConfig_t));
1808
    ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.physicalConfigDedicated =
1809
      CALLOC(1, sizeof(LTE_PhysicalConfigDedicated_t));
Cedric Roux's avatar
Cedric Roux committed
1810
    memcpy((void *)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.physicalConfigDedicated,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
1811
           (void *)ue_context_pP->ue_context.physicalConfigDedicated, sizeof(LTE_PhysicalConfigDedicated_t));
1812 1813 1814 1815 1816 1817 1818
    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;
1819
  cba_RNTI = CALLOC(1, sizeof(LTE_C_RNTI_t));
1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841
  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
  /* Initialize NAS list */
1842
  dedicatedInfoNASList = CALLOC(1, sizeof(struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList));
1843 1844 1845 1846

  /* 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) {
1847
      dedicatedInfoNas = CALLOC(1, sizeof(LTE_DedicatedInfoNAS_t));
1848 1849
      memset(dedicatedInfoNas, 0, sizeof(OCTET_STRING_t));
      OCTET_STRING_fromBuf(dedicatedInfoNas,
Cedric Roux's avatar
Cedric Roux committed
1850
                           (char *)ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer,
1851
                           ue_context_pP->ue_context.e_rab[i].param.nas_pdu.length);
1852
      LOG_D(RRC, "Add LTE_DedicatedInfoNAS(%d) to LTE_DedicatedInfoNASList\n", i);
1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863
      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;
1864
    ue_context_pP->ue_context.e_rab[i].xid    = xid;
1865
    LOG_D(RRC, "setting the status for the default DRB (index %d) to (%d,%s)\n",
Cedric Roux's avatar
Cedric Roux committed
1866
          i, ue_context_pP->ue_context.e_rab[i].status, "E_RAB_STATUS_DONE");
1867 1868 1869 1870 1871 1872 1873 1874
  }

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

1875 1876
  measurements_enabled = RC.rrc[ENB_INSTANCE_TO_MODULE_ID(ctxt_pP->instance)]->configuration.enable_x2 ||
                         RC.rrc[ENB_INSTANCE_TO_MODULE_ID(ctxt_pP->instance)]->configuration.enable_measurement_reports;
Cedric Roux's avatar
Cedric Roux committed
1877

1878
  // send LTE_RRCConnectionReconfiguration
1879 1880 1881 1882
  memset(buffer, 0, RRC_BUF_SIZE);
  size = do_RRCConnectionReconfiguration(ctxt_pP,
                                         buffer,
                                         next_xid,   //Transaction_id,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
1883 1884 1885 1886 1887
                                         (LTE_SRB_ToAddModList_t *)*SRB_configList2, // SRB_configList
                                         (LTE_DRB_ToAddModList_t *)DRB_configList,
                                         (LTE_DRB_ToReleaseList_t *)NULL, // DRB2_list,
                                         (struct LTE_SPS_Config *)NULL,   // maybe ue_context_pP->ue_context.sps_Config,
                                         (struct LTE_PhysicalConfigDedicated *)ue_context_pP->ue_context.physicalConfigDedicated,
Cedric Roux's avatar
Cedric Roux committed
1888 1889 1890
//#ifdef EXMIMO_IOT
//                                         NULL, NULL, NULL,NULL,
//#else
1891 1892 1893
                                         measurements_enabled ? (LTE_MeasObjectToAddModList_t *)MeasObj_list : NULL, // MeasObj_list,
                                         measurements_enabled ? (LTE_ReportConfigToAddModList_t *)ReportConfig_list : NULL, // ReportConfig_list,
                                         measurements_enabled ? (LTE_QuantityConfig_t *)quantityConfig : NULL, //quantityConfig,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
1894
                                         (LTE_MeasIdToAddModList_t *)NULL,
Cedric Roux's avatar
Cedric Roux committed
1895
//#endif
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
1896 1897 1898
                                         (LTE_MAC_MainConfig_t *)ue_context_pP->ue_context.mac_MainConfig,
                                         (LTE_MeasGapConfig_t *)NULL,
                                         (LTE_MobilityControlInfo_t *)NULL,
1899
                                         (LTE_SecurityConfigHO_t *)NULL,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
1900 1901 1902 1903 1904 1905
                                         (struct LTE_MeasConfig__speedStatePars *)Sparams, // Sparams,
                                         (LTE_RSRP_Range_t *)rsrp, // rsrp,
                                         (LTE_C_RNTI_t *)cba_RNTI, // cba_RNTI
                                         (struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *)dedicatedInfoNASList, //dedicatedInfoNASList
                                         (LTE_SL_CommConfig_r12_t *)NULL,
                                         (LTE_SL_DiscConfig_r12_t *)NULL
1906
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
1907
                                         , (LTE_SCellToAddMod_r10_t *)NULL
1908 1909
#endif
                                        );
1910 1911
  LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)buffer,size,
              "[MSG] RRC Connection Reconfiguration\n");
1912 1913 1914 1915 1916 1917 1918 1919 1920 1921

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

Cedric Roux's avatar
Cedric Roux committed
1922
  if(size==65535) {
1923 1924 1925
    LOG_E(RRC,"RRC decode err!!! do_RRCConnectionReconfiguration\n");
    put_UE_in_freelist(ctxt_pP->module_id, reestablish_rnti, 0);
    return;
Cedric Roux's avatar
Cedric Roux committed
1926
  } else {
1927
    LOG_I(RRC,
1928
          "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate LTE_RRCConnectionReconfiguration (bytes %d, UE id %x)\n",
1929 1930 1931 1932 1933 1934 1935 1936 1937
          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,
1938
      MSC_AS_TIME_FMT" LTE_RRCConnectionReconfiguration UE %x MUI %d size %u",
1939 1940 1941 1942 1943
      MSC_AS_TIME_ARGS(ctxt_pP),
      ue_context_pP->ue_context.rnti,
      rrc_eNB_mui,
      size);
    rrc_data_req(
Cedric Roux's avatar
Cedric Roux committed
1944 1945 1946 1947 1948 1949 1950
      ctxt_pP,
      DCCH,
      rrc_eNB_mui++,
      SDU_CONFIRM_NO,
      size,
      buffer,
      PDCP_TRANSMISSION_MODE_CONTROL);
1951
  }
Cedric Roux's avatar
Cedric Roux committed
1952

1953
  // delete UE data of prior RNTI.  UE use current RNTI.
Cedric Roux's avatar
Cedric Roux committed
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
  //  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<MAX_MOBILES_PER_ENB; i++) {
  //      ulsch = eNB_PHY->ulsch[i];
  //      if((ulsch != NULL) && (ulsch->rnti == ctxt_prior.rnti)){
  //        void clean_eNb_ulsch(LTE_eNB_ULSCH_t *ulsch);
  //        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);
1992 1993 1994
  // 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);
1995 1996 1997 1998 1999
}

//-----------------------------------------------------------------------------
void
rrc_eNB_generate_RRCConnectionReestablishmentReject(
Cedric Roux's avatar
Cedric Roux committed
2000 2001
  const protocol_ctxt_t *const ctxt_pP,
  rrc_eNB_ue_context_t          *const ue_context_pP,
2002 2003 2004 2005
  const int                    CC_id
)
//-----------------------------------------------------------------------------
{
2006
 if (!NODE_IS_CU(RC.rrc[ctxt_pP->module_id]->node_type)) {
2007
  int UE_id = find_UE_id(ctxt_pP->module_id, ctxt_pP->rnti);
Cedric Roux's avatar
Cedric Roux committed
2008 2009

  if(UE_id != -1) {
2010 2011
    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;
Cedric Roux's avatar
Cedric Roux committed
2012
  } else {
2013
    LOG_E(RRC,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
2014
          PROTOCOL_RRC_CTXT_UE_FMT" Generating LTE_RRCConnectionReestablishmentReject without UE_id(MAC) rnti %x\n",
Cedric Roux's avatar
Cedric Roux committed
2015
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ctxt_pP->rnti);
2016
  }
2017
 }
2018 2019 2020
  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));

2021 2022 2023
  eNB_RRC_UE_t *ue_p = &ue_context_pP->ue_context; 

  ue_p->Srb0.Tx_buffer.payload_size =
2024
    do_RRCConnectionReestablishmentReject(ctxt_pP->module_id,
2025
                          (uint8_t*) ue_p->Srb0.Tx_buffer.Payload);
2026

2027
  LOG_DUMPMSG(RRC,DEBUG_RRC,
2028 2029
              (char *)(ue_p->Srb0.Tx_buffer.Payload),
              ue_p->Srb0.Tx_buffer.payload_size,
2030
              "[MSG] RRCConnectionReestablishmentReject\n");
2031 2032 2033
  MSC_LOG_TX_MESSAGE(
    MSC_RRC_ENB,
    MSC_RRC_UE,
2034 2035
    ue_p->Srb0.Tx_buffer.Header,
    ue_p->Srb0.Tx_buffer.payload_size,
2036
    MSC_AS_TIME_FMT" LTE_RRCConnectionReestablishmentReject UE %x size %u",
2037 2038
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP == NULL ? -1 : ue_context_pP->ue_context.rnti,
2039
    ue_p->Srb0.Tx_buffer.payload_size);
2040 2041

  LOG_I(RRC,
2042
        PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel DL-CCCH, Generating LTE_RRCConnectionReestablishmentReject (bytes %d)\n",
2043
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
2044
        ue_p->Srb0.Tx_buffer.payload_size);
2045 2046 2047
}

//-----------------------------------------------------------------------------
2048 2049 2050 2051
/*
* Generate the RRC Connection Release to UE.
* If received, UE should switch to RRC_IDLE mode.
*/
2052 2053
void
rrc_eNB_generate_RRCConnectionRelease(
Cedric Roux's avatar
Cedric Roux committed
2054
  const protocol_ctxt_t *const ctxt_pP,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
2055
  rrc_eNB_ue_context_t *const ue_context_pP
2056 2057 2058
)
//-----------------------------------------------------------------------------
{
root's avatar
root committed
2059
  uint8_t buffer[RRC_BUF_SIZE];
2060
  uint16_t size = 0;
root's avatar
root committed
2061
  memset(buffer, 0, RRC_BUF_SIZE);
2062 2063 2064
  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));
  size = do_RRCConnectionRelease(ctxt_pP->module_id, buffer,rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id));
2065 2066
  ue_context_pP->ue_context.ue_reestablishment_timer = 0;
  ue_context_pP->ue_context.ue_release_timer = 0;
2067
  ue_context_pP->ue_context.ue_rrc_inactivity_timer = 0;
2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082
  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,
2083
    MSC_AS_TIME_FMT" LTE_RRCConnectionRelease UE %x MUI %d size %u",
2084 2085 2086 2087
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP->ue_context.rnti,
    rrc_eNB_mui,
    size);
2088
  pthread_mutex_lock(&rrc_release_freelist);
Cedric Roux's avatar
Cedric Roux committed
2089

2090 2091 2092
  for (uint16_t release_num = 0; release_num < NUMBER_OF_UE_MAX; release_num++) {
    if (rrc_release_info.RRC_release_ctrl[release_num].flag == 0) {
      if (ue_context_pP->ue_context.ue_release_timer_s1 > 0) {
2093
        rrc_release_info.RRC_release_ctrl[release_num].flag = 1;
Cedric Roux's avatar
Cedric Roux committed
2094
      } else {
2095 2096
        rrc_release_info.RRC_release_ctrl[release_num].flag = 2;
      }
Cedric Roux's avatar
Cedric Roux committed
2097

2098 2099 2100
      rrc_release_info.RRC_release_ctrl[release_num].rnti = ctxt_pP->rnti;
      rrc_release_info.RRC_release_ctrl[release_num].rrc_eNB_mui = rrc_eNB_mui;
      rrc_release_info.num_UEs++;
2101
      LOG_D(RRC, "Generate DLSCH Release send: index %d rnti %x mui %d flag %d \n",
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
2102 2103 2104 2105
            release_num,
            ctxt_pP->rnti,
            rrc_eNB_mui,
            rrc_release_info.RRC_release_ctrl[release_num].flag);
2106 2107 2108
      break;
    }
  }
Cedric Roux's avatar
Cedric Roux committed
2109

2110
  pthread_mutex_unlock(&rrc_release_freelist);
2111
  if (NODE_IS_CU(RC.rrc[ctxt_pP->module_id]->node_type)) {
2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127
    MessageDef *m = itti_alloc_new_message(TASK_RRC_ENB, F1AP_UE_CONTEXT_RELEASE_CMD);
    F1AP_UE_CONTEXT_RELEASE_CMD(m).rnti = ctxt_pP->rnti;
    F1AP_UE_CONTEXT_RELEASE_CMD(m).cause = F1AP_CAUSE_RADIO_NETWORK;
    F1AP_UE_CONTEXT_RELEASE_CMD(m).cause_value = 10; // 10 = F1AP_CauseRadioNetwork_normal_release
    F1AP_UE_CONTEXT_RELEASE_CMD(m).rrc_container = buffer;
    F1AP_UE_CONTEXT_RELEASE_CMD(m).rrc_container_length = size;
    itti_send_msg_to_task(TASK_CU_F1, ctxt_pP->module_id, m);
  } else {
    rrc_data_req(ctxt_pP,
                 DCCH,
                 rrc_eNB_mui++,
                 SDU_CONFIRM_NO,
                 size,
                 buffer,
                 PDCP_TRANSMISSION_MODE_CONTROL);
  }
2128 2129
}

Cedric Roux's avatar
Cedric Roux committed
2130
uint8_t qci_to_priority[9]= {2,4,3,5,1,6,7,8,9};
2131 2132 2133 2134

// TBD: this directive can be remived if we create a similar e_rab_param_t structure in RRC context
//-----------------------------------------------------------------------------
void
Cedric Roux's avatar
Cedric Roux committed
2135 2136 2137 2138
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
                                                      )
2139 2140 2141 2142 2143
//-----------------------------------------------------------------------------
{
  uint8_t                             buffer[RRC_BUF_SIZE];
  uint16_t                            size;
  int i;
2144 2145 2146 2147 2148 2149 2150
  struct LTE_DRB_ToAddMod                *DRB_config                       = NULL;
  struct LTE_RLC_Config                  *DRB_rlc_config                   = NULL;
  struct LTE_PDCP_Config                 *DRB_pdcp_config                  = NULL;
  struct LTE_PDCP_Config__rlc_AM         *PDCP_rlc_AM                      = NULL;
  struct LTE_PDCP_Config__rlc_UM         *PDCP_rlc_UM                      = NULL;
  struct LTE_LogicalChannelConfig        *DRB_lchan_config                 = NULL;
  struct LTE_LogicalChannelConfig__ul_SpecificParameters
2151
    *DRB_ul_SpecificParameters        = NULL;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
2152 2153 2154
  //  LTE_DRB_ToAddModList_t**                DRB_configList=&ue_context_pP->ue_context.DRB_configList;
  LTE_DRB_ToAddModList_t                *DRB_configList=ue_context_pP->ue_context.DRB_configList;
  LTE_DRB_ToAddModList_t                **DRB_configList2=NULL;
2155
  //DRB_ToAddModList_t**                RRC_DRB_configList=&ue_context_pP->ue_context.DRB_configList;
2156 2157
  struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList = NULL;
  LTE_DedicatedInfoNAS_t                 *dedicatedInfoNas                 = NULL;
2158 2159 2160
  /* for no gcc warnings */
  (void)dedicatedInfoNas;
  long  *logicalchannelgroup_drb;
Cedric Roux's avatar
Cedric Roux committed
2161
  //  int drb_identity_index=0;
2162 2163
  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];
Cedric Roux's avatar
Cedric Roux committed
2164

2165 2166 2167
  if (*DRB_configList2) {
    free(*DRB_configList2);
  }
Cedric Roux's avatar
Cedric Roux committed
2168

2169
  //*DRB_configList = CALLOC(1, sizeof(*DRB_configList));
Cedric Roux's avatar
Cedric Roux committed
2170
  *DRB_configList2 = CALLOC(1, sizeof(**DRB_configList2));
2171
  /* Initialize NAS list */
2172
  dedicatedInfoNASList = CALLOC(1, sizeof(struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList));
2173 2174
  int e_rab_done=0;

Cedric Roux's avatar
Cedric Roux committed
2175 2176 2177 2178 2179
  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;
2180
    }
Cedric Roux's avatar
Cedric Roux committed
2181

2182 2183
    // bypass the new and already configured erabs
    if (ue_context_pP->ue_context.e_rab[i].status >= E_RAB_STATUS_DONE) {
Cedric Roux's avatar
Cedric Roux committed
2184
      //      drb_identity_index++;
2185 2186 2187
      continue;
    }

Cedric Roux's avatar
Cedric Roux committed
2188
    DRB_config = CALLOC(1, sizeof(*DRB_config));
2189 2190
    DRB_config->eps_BearerIdentity = CALLOC(1, sizeof(long));
    // allowed value 5..15, value : x+4
Cedric Roux's avatar
Cedric Roux committed
2191
    *(DRB_config->eps_BearerIdentity) = ue_context_pP->ue_context.e_rab[i].param.e_rab_id;//+ 4; // especial case generation
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
2192
    //   DRB_config->drb_Identity =  1 + drb_identity_index + e_rab_done;// + i ;// (LTE_DRB_Identity_t) ue_context_pP->ue_context.e_rab[i].param.e_rab_id;
Cedric Roux's avatar
Cedric Roux committed
2193
    // 1 + drb_identiy_index;
2194 2195 2196 2197 2198 2199 2200 2201
    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));
2202
    *DRB_pdcp_config->discardTimer = LTE_PDCP_Config__discardTimer_infinity;
2203 2204 2205
    DRB_pdcp_config->rlc_AM = NULL;
    DRB_pdcp_config->rlc_UM = NULL;

Cedric Roux's avatar
Cedric Roux committed
2206
    switch (ue_context_pP->ue_context.e_rab[i].param.qos.qci) {
2207 2208 2209 2210
      /*
       * type: realtime data with medium packer error rate
       * action: swtich to RLC UM
       */
Cedric Roux's avatar
Cedric Roux committed
2211 2212 2213 2214 2215 2216 2217 2218 2219
      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
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
2220 2221 2222 2223
        DRB_rlc_config->present = LTE_RLC_Config_PR_um_Bi_Directional;
        DRB_rlc_config->choice.um_Bi_Directional.ul_UM_RLC.sn_FieldLength = LTE_SN_FieldLength_size10;
        DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.sn_FieldLength = LTE_SN_FieldLength_size10;
        DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering = LTE_T_Reordering_ms35;
Cedric Roux's avatar
Cedric Roux committed
2224 2225 2226
        // PDCP
        PDCP_rlc_UM = CALLOC(1, sizeof(*PDCP_rlc_UM));
        DRB_pdcp_config->rlc_UM = PDCP_rlc_UM;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
2227
        PDCP_rlc_UM->pdcp_SN_Size = LTE_PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits;
Cedric Roux's avatar
Cedric Roux committed
2228 2229
        break;

2230 2231 2232 2233
      /*
       * type: non-realtime data with low packer error rate
       * action: swtich to RLC AM
       */
Cedric Roux's avatar
Cedric Roux committed
2234 2235 2236 2237 2238 2239
      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
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
2240 2241 2242 2243 2244 2245 2246
        DRB_rlc_config->present = LTE_RLC_Config_PR_am;
        DRB_rlc_config->choice.am.ul_AM_RLC.t_PollRetransmit = LTE_T_PollRetransmit_ms50;
        DRB_rlc_config->choice.am.ul_AM_RLC.pollPDU = LTE_PollPDU_p16;
        DRB_rlc_config->choice.am.ul_AM_RLC.pollByte = LTE_PollByte_kBinfinity;
        DRB_rlc_config->choice.am.ul_AM_RLC.maxRetxThreshold = LTE_UL_AM_RLC__maxRetxThreshold_t8;
        DRB_rlc_config->choice.am.dl_AM_RLC.t_Reordering = LTE_T_Reordering_ms35;
        DRB_rlc_config->choice.am.dl_AM_RLC.t_StatusProhibit = LTE_T_StatusProhibit_ms25;
Cedric Roux's avatar
Cedric Roux committed
2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258
        // PDCP
        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.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;
        e_rab_done++;
        continue;
2259 2260
    }

2261
    DRB_pdcp_config->headerCompression.present = LTE_PDCP_Config__headerCompression_PR_notUsed;
2262 2263 2264 2265 2266
    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;

2267
    if (ue_context_pP->ue_context.e_rab[i].param.qos.qci < 9 )
Cedric Roux's avatar
Cedric Roux committed
2268
      DRB_ul_SpecificParameters->priority = qci_to_priority[ue_context_pP->ue_context.e_rab[i].param.qos.qci-1] + 3;
2269
    // ue_context_pP->ue_context.e_rab[i].param.qos.allocation_retention_priority.priority_level;
Cedric Roux's avatar
Cedric Roux committed
2270
    else
2271 2272
      DRB_ul_SpecificParameters->priority= 4;

2273
    DRB_ul_SpecificParameters->prioritisedBitRate = LTE_LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_kBps8;
Cedric Roux's avatar
Cedric Roux committed
2274
    //LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
2275
    DRB_ul_SpecificParameters->bucketSizeDuration =
2276
      LTE_LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
2277 2278 2279 2280 2281 2282 2283
    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",
Cedric Roux's avatar
Cedric Roux committed
2284 2285 2286 2287 2288 2289 2290
          *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
         );
2291
    e_rab_done++;
Cedric Roux's avatar
Cedric Roux committed
2292
    ue_context_pP->ue_context.e_rab[i].status = E_RAB_STATUS_DONE;
2293 2294 2295
    ue_context_pP->ue_context.e_rab[i].xid = xid;
    {
      if (ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer != NULL) {
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
2296
        dedicatedInfoNas = CALLOC(1, sizeof(LTE_DedicatedInfoNAS_t));
Cedric Roux's avatar
Cedric Roux committed
2297 2298 2299 2300 2301 2302 2303 2304
        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");
2305
      }
Cedric Roux's avatar
Cedric Roux committed
2306

2307 2308
      /* TODO parameters yet to process ... */
      {
Cedric Roux's avatar
Cedric Roux committed
2309 2310 2311
        //      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;
2312 2313 2314 2315 2316 2317 2318 2319 2320 2321
      }
    }
  }

  /* 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");
Cedric Roux's avatar
Cedric Roux committed
2322
    }
2323 2324 2325 2326 2327
  } else {
    LOG_W(RRC,"dedlicated NAS list is empty\n");
  }

  memset(buffer, 0, RRC_BUF_SIZE);
Cedric Roux's avatar
Cedric Roux committed
2328 2329 2330
  size = do_RRCConnectionReconfiguration(ctxt_pP,
                                         buffer,
                                         xid,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
2331 2332 2333 2334
                                         (LTE_SRB_ToAddModList_t *)NULL,
                                         (LTE_DRB_ToAddModList_t *)*DRB_configList2,
                                         (LTE_DRB_ToReleaseList_t *)NULL, // DRB2_list,
                                         (struct LTE_SPS_Config *)NULL,   // *sps_Config,
Cedric Roux's avatar
Cedric Roux committed
2335 2336
                                         NULL, NULL, NULL, NULL,NULL,
                                         NULL, NULL,  NULL, NULL, NULL, NULL, NULL,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
2337 2338 2339
                                         (struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *)dedicatedInfoNASList,
                                         (LTE_SL_CommConfig_r12_t *)NULL,
                                         (LTE_SL_DiscConfig_r12_t *)NULL
2340
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
2341
                                         , (LTE_SCellToAddMod_r10_t *)NULL
2342 2343
#endif
                                        );
2344
  LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)buffer,size,"[MSG] RRC Connection Reconfiguration\n");
2345 2346 2347 2348 2349 2350 2351 2352 2353 2354

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

Cedric Roux's avatar
Cedric Roux committed
2355
  LOG_I(RRC,
2356
        "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate LTE_RRCConnectionReconfiguration (bytes %d, UE RNTI %x)\n",
2357 2358 2359 2360 2361 2362 2363 2364 2365
        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,
2366
    MSC_AS_TIME_FMT" dedicated LTE_RRCConnectionReconfiguration UE %x MUI %d size %u",
2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380
    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
Cedric Roux's avatar
Cedric Roux committed
2381 2382 2383 2384
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
                                                    )
2385 2386 2387 2388 2389
//-----------------------------------------------------------------------------
{
  uint8_t                             buffer[RRC_BUF_SIZE];
  uint16_t                            size;
  int i, j;
2390 2391 2392 2393 2394 2395 2396
  struct LTE_DRB_ToAddMod                *DRB_config                       = NULL;
  struct LTE_RLC_Config                  *DRB_rlc_config                   = NULL;
  struct LTE_PDCP_Config                 *DRB_pdcp_config                  = NULL;
  struct LTE_PDCP_Config__rlc_AM         *PDCP_rlc_AM                      = NULL;
  struct LTE_PDCP_Config__rlc_UM         *PDCP_rlc_UM                      = NULL;
  struct LTE_LogicalChannelConfig        *DRB_lchan_config                 = NULL;
  struct LTE_LogicalChannelConfig__ul_SpecificParameters
Cedric Roux's avatar
Cedric Roux committed
2397
    *DRB_ul_SpecificParameters        = NULL;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
2398 2399
  LTE_DRB_ToAddModList_t                 *DRB_configList = ue_context_pP->ue_context.DRB_configList;
  LTE_DRB_ToAddModList_t                *DRB_configList2 = NULL;
2400 2401
  struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList = NULL;
  LTE_DedicatedInfoNAS_t                 *dedicatedInfoNas                 = NULL;
2402 2403 2404 2405 2406
  /* 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 */
2407
  dedicatedInfoNASList = CALLOC(1, sizeof(struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList));
2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423

  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;
Cedric Roux's avatar
Cedric Roux committed
2424

2425 2426 2427 2428 2429 2430 2431
    // 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;
      }
    }
Cedric Roux's avatar
Cedric Roux committed
2432

2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444
    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;
2445
    *DRB_pdcp_config->discardTimer = LTE_PDCP_Config__discardTimer_infinity;
Cedric Roux's avatar
Cedric Roux committed
2446

2447
    switch (ue_context_pP->ue_context.modify_e_rab[i].param.qos.qci) {
Cedric Roux's avatar
Cedric Roux committed
2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460
      /*
       * 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
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
2461 2462 2463 2464
        DRB_rlc_config->present = LTE_RLC_Config_PR_um_Bi_Directional;
        DRB_rlc_config->choice.um_Bi_Directional.ul_UM_RLC.sn_FieldLength = LTE_SN_FieldLength_size10;
        DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.sn_FieldLength = LTE_SN_FieldLength_size10;
        DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering = LTE_T_Reordering_ms35;
Cedric Roux's avatar
Cedric Roux committed
2465 2466 2467 2468 2469 2470

        // PDCP
        if (DRB_pdcp_config->rlc_AM) {
          free(DRB_pdcp_config->rlc_AM);
          DRB_pdcp_config->rlc_AM = NULL;
        }
2471

Cedric Roux's avatar
Cedric Roux committed
2472 2473 2474 2475 2476 2477 2478
        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;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
2479
        PDCP_rlc_UM->pdcp_SN_Size = LTE_PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits;
Cedric Roux's avatar
Cedric Roux committed
2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491
        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
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
2492 2493 2494 2495 2496 2497 2498
        DRB_rlc_config->present = LTE_RLC_Config_PR_am;
        DRB_rlc_config->choice.am.ul_AM_RLC.t_PollRetransmit = LTE_T_PollRetransmit_ms50;
        DRB_rlc_config->choice.am.ul_AM_RLC.pollPDU = LTE_PollPDU_p16;
        DRB_rlc_config->choice.am.ul_AM_RLC.pollByte = LTE_PollByte_kBinfinity;
        DRB_rlc_config->choice.am.ul_AM_RLC.maxRetxThreshold = LTE_UL_AM_RLC__maxRetxThreshold_t8;
        DRB_rlc_config->choice.am.dl_AM_RLC.t_Reordering = LTE_T_Reordering_ms35;
        DRB_rlc_config->choice.am.dl_AM_RLC.t_StatusProhibit = LTE_T_StatusProhibit_ms25;
Cedric Roux's avatar
Cedric Roux committed
2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514

        // 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;
2515

Cedric Roux's avatar
Cedric Roux committed
2516 2517 2518 2519 2520 2521 2522 2523
      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;
2524 2525
    }

2526
    DRB_pdcp_config->headerCompression.present = LTE_PDCP_Config__headerCompression_PR_notUsed;
2527 2528 2529 2530 2531 2532
    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
2533 2534
      DRB_ul_SpecificParameters->priority= 4;

2535
    DRB_ul_SpecificParameters->prioritisedBitRate = LTE_LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_kBps8;
2536
    DRB_ul_SpecificParameters->bucketSizeDuration =
2537
      LTE_LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
2538 2539
    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",
Cedric Roux's avatar
Cedric Roux committed
2540 2541 2542 2543 2544 2545 2546
          *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
         );
2547 2548 2549
    //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;
2550
    {
2551
      if (ue_context_pP->ue_context.modify_e_rab[i].param.nas_pdu.buffer != NULL) {
2552
        dedicatedInfoNas = CALLOC(1, sizeof(LTE_DedicatedInfoNAS_t));
2553 2554
        memset(dedicatedInfoNas, 0, sizeof(OCTET_STRING_t));
        OCTET_STRING_fromBuf(dedicatedInfoNas,
Cedric Roux's avatar
Cedric Roux committed
2555 2556
                             (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);
2557 2558
        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);
Cedric Roux's avatar
Cedric Roux committed
2559
      } else {
2560
        LOG_W(RRC, "Not received activate dedicated EPS bearer context request\n");
2561
      }
2562 2563
    }
  }
2564 2565 2566 2567 2568 2569 2570

  /* 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");
2571
    }
2572 2573 2574 2575
  } else {
    LOG_W(RRC,"dedlicated NAS list is empty\n");
  }

2576
  memset(buffer, 0, RRC_BUF_SIZE);
Cedric Roux's avatar
Cedric Roux committed
2577 2578 2579
  size = do_RRCConnectionReconfiguration(ctxt_pP,
                                         buffer,
                                         xid,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
2580 2581 2582 2583
                                         (LTE_SRB_ToAddModList_t *)NULL,
                                         (LTE_DRB_ToAddModList_t *)DRB_configList2,
                                         (LTE_DRB_ToReleaseList_t *)NULL, // DRB2_list,
                                         (struct LTE_SPS_Config *)NULL,   // *sps_Config,
Cedric Roux's avatar
Cedric Roux committed
2584 2585
                                         NULL, NULL, NULL, NULL,NULL,
                                         NULL, NULL,  NULL, NULL, NULL, NULL, NULL,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
2586 2587 2588
                                         (struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *)dedicatedInfoNASList,
                                         (LTE_SL_CommConfig_r12_t *)NULL,
                                         (LTE_SL_DiscConfig_r12_t *)NULL
2589
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
2590
                                         , (LTE_SCellToAddMod_r10_t *)NULL
2591
#endif
Cedric Roux's avatar
Cedric Roux committed
2592
                                        );
2593 2594
  LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)buffer,size,
              "[MSG] RRC Connection Reconfiguration\n");
2595 2596

  /* Free all NAS PDUs */
2597 2598
  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) {
2599
      /* Free the NAS PDU buffer and invalidate it */
2600 2601
      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;
2602 2603 2604
    }
  }

Cedric Roux's avatar
Cedric Roux committed
2605
  LOG_I(RRC,
2606
        "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate LTE_RRCConnectionReconfiguration (bytes %d, UE RNTI %x)\n",
2607 2608 2609 2610 2611 2612 2613 2614 2615
        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,
2616
    MSC_AS_TIME_FMT" dedicated LTE_RRCConnectionReconfiguration UE %x MUI %d size %u",
2617 2618 2619 2620
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP->ue_context.rnti,
    rrc_eNB_mui,
    size);
2621
  rrc_data_req(
2622 2623 2624 2625 2626 2627 2628
    ctxt_pP,
    DCCH,
    rrc_eNB_mui++,
    SDU_CONFIRM_NO,
    size,
    buffer,
    PDCP_TRANSMISSION_MODE_CONTROL);
2629 2630 2631 2632 2633
  return 0;
}

//-----------------------------------------------------------------------------
void
Cedric Roux's avatar
Cedric Roux committed
2634 2635 2636 2637 2638
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)
2639 2640
//-----------------------------------------------------------------------------
{
Cedric Roux's avatar
Cedric Roux committed
2641 2642 2643
  uint8_t                             buffer[RRC_BUF_SIZE];
  int                                 i;
  uint16_t                            size  = 0;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
2644 2645 2646
  LTE_DRB_ToReleaseList_t                **DRB_Release_configList2=NULL;
  LTE_DRB_Identity_t *DRB_release;
  struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList = NULL;
Cedric Roux's avatar
Cedric Roux committed
2647
  DRB_Release_configList2=&ue_context_pP->ue_context.DRB_Release_configList2[xid];
2648

Cedric Roux's avatar
Cedric Roux committed
2649 2650 2651 2652 2653 2654 2655 2656
  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) {
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
2657
      DRB_release = CALLOC(1, sizeof(LTE_DRB_Identity_t));
Cedric Roux's avatar
Cedric Roux committed
2658 2659 2660
      *DRB_release = i+1;
      ASN_SEQUENCE_ADD(&(*DRB_Release_configList2)->list, DRB_release);
      //free(DRB_release);
2661
    }
Cedric Roux's avatar
Cedric Roux committed
2662
  }
2663

Cedric Roux's avatar
Cedric Roux committed
2664 2665
  /* If list is empty free the list and reset the address */
  if (nas_length > 0) {
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
2666 2667 2668
    LTE_DedicatedInfoNAS_t                 *dedicatedInfoNas                 = NULL;
    dedicatedInfoNASList = CALLOC(1, sizeof(struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList));
    dedicatedInfoNas = CALLOC(1, sizeof(LTE_DedicatedInfoNAS_t));
Cedric Roux's avatar
Cedric Roux committed
2669 2670 2671 2672 2673 2674 2675 2676 2677
    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");
  }
2678

Cedric Roux's avatar
Cedric Roux committed
2679 2680 2681 2682 2683 2684
  memset(buffer, 0, RRC_BUF_SIZE);
  size = do_RRCConnectionReconfiguration(ctxt_pP,
                                         buffer,
                                         xid,
                                         NULL,
                                         NULL,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
2685
                                         (LTE_DRB_ToReleaseList_t *)*DRB_Release_configList2,
Cedric Roux's avatar
Cedric Roux committed
2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698
                                         NULL,
                                         NULL,
                                         NULL,
                                         NULL,
                                         NULL,
                                         NULL,
                                         NULL,
                                         NULL,
                                         NULL,
                                         NULL,
                                         NULL,
                                         NULL,
                                         NULL,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
2699 2700 2701
                                         (struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *)dedicatedInfoNASList,
                                         (LTE_SL_CommConfig_r12_t *)NULL,
                                         (LTE_SL_DiscConfig_r12_t *)NULL
2702
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
2703
                                         , (LTE_SCellToAddMod_r10_t *)NULL
2704
#endif
Cedric Roux's avatar
Cedric Roux committed
2705 2706 2707 2708 2709
                                        );
  ue_context_pP->ue_context.e_rab_release_command_flag = 1;
  LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)buffer,size,
              "[MSG] RRC Connection Reconfiguration\n");

2710 2711
  /* Free all NAS PDUs */
  if (nas_length > 0) {
Cedric Roux's avatar
Cedric Roux committed
2712 2713
    /* Free the NAS PDU buffer and invalidate it */
    free(nas_buffer);
2714 2715 2716
  }

  LOG_I(RRC,
2717
        "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate LTE_RRCConnectionReconfiguration (bytes %d, UE RNTI %x)\n",
2718 2719 2720 2721 2722 2723 2724 2725 2726
        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,
2727
    MSC_AS_TIME_FMT" dedicated LTE_RRCConnectionReconfiguration UE %x MUI %d size %u",
2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739
    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);
2740
}
2741

2742
//-----------------------------------------------------------------------------
2743 2744 2745 2746 2747 2748
/*
 * Generate the basic (first) RRC Connection Reconfiguration (non BR UE)
 */
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)
2749
//-----------------------------------------------------------------------------
2750
{
2751 2752 2753 2754 2755 2756
  uint8_t   buffer[RRC_BUF_SIZE];
  uint16_t  size;
  int       i;
  
  /* Configure SRB1/SRB2, PhysicalConfigDedicated, LTE_MAC_MainConfig for UE */
  eNB_RRC_INST                           *rrc_inst = RC.rrc[ctxt_pP->module_id];
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
2757
  struct LTE_PhysicalConfigDedicated    **physicalConfigDedicated = &ue_context_pP->ue_context.physicalConfigDedicated;
2758 2759 2760 2761
  struct LTE_SRB_ToAddMod                *SRB2_config                      = NULL;
  struct LTE_SRB_ToAddMod__rlc_Config    *SRB2_rlc_config                  = NULL;
  struct LTE_SRB_ToAddMod__logicalChannelConfig *SRB2_lchan_config         = NULL;
  struct LTE_LogicalChannelConfig__ul_SpecificParameters
Cedric Roux's avatar
Cedric Roux committed
2762
    *SRB2_ul_SpecificParameters       = NULL;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
2763
  LTE_SRB_ToAddModList_t                 *SRB_configList = ue_context_pP->ue_context.SRB_configList;
2764
  LTE_SRB_ToAddModList_t                 **SRB_configList2                 = NULL;
2765 2766 2767 2768 2769 2770 2771
  struct LTE_DRB_ToAddMod                *DRB_config                       = NULL;
  struct LTE_RLC_Config                  *DRB_rlc_config                   = NULL;
  struct LTE_PDCP_Config                 *DRB_pdcp_config                  = NULL;
  struct LTE_PDCP_Config__rlc_AM         *PDCP_rlc_AM                      = NULL;
  struct LTE_PDCP_Config__rlc_UM         *PDCP_rlc_UM                      = NULL;
  struct LTE_LogicalChannelConfig        *DRB_lchan_config                 = NULL;
  struct LTE_LogicalChannelConfig__ul_SpecificParameters
Cedric Roux's avatar
Cedric Roux committed
2772
    *DRB_ul_SpecificParameters        = NULL;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
2773
  LTE_DRB_ToAddModList_t                **DRB_configList = &ue_context_pP->ue_context.DRB_configList;
2774
  LTE_DRB_ToAddModList_t                **DRB_configList2                  = NULL;
2775 2776 2777 2778 2779
  LTE_MAC_MainConfig_t                   *mac_MainConfig                   = NULL;
  LTE_MeasObjectToAddModList_t           *MeasObj_list                     = NULL;
  LTE_MeasObjectToAddMod_t               *MeasObj                          = NULL;
  LTE_ReportConfigToAddModList_t         *ReportConfig_list                = NULL;
  LTE_ReportConfigToAddMod_t             *ReportConfig_per, *ReportConfig_A1,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
2780
                                         *ReportConfig_A2, *ReportConfig_A3, *ReportConfig_A4, *ReportConfig_A5;
2781 2782
  LTE_MeasIdToAddModList_t               *MeasId_list                      = NULL;
  LTE_MeasIdToAddMod_t                   *MeasId0, *MeasId1, *MeasId2, *MeasId3, *MeasId4, *MeasId5;
2783

2784
#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
2785
  long                                   *sr_ProhibitTimer_r9              = NULL;
winckel's avatar
winckel committed
2786
#endif
2787 2788 2789 2790 2791

  long                                   *logicalchannelgroup              = NULL;
  long                                   *logicalchannelgroup_drb          = NULL;
  long                                   *maxHARQ_Tx                       = NULL; 
  long                                   *periodicBSR_Timer                = NULL;
2792 2793 2794
  LTE_RSRP_Range_t                       *rsrp                             = NULL;
  struct LTE_MeasConfig__speedStatePars  *Sparams                          = NULL;
  LTE_QuantityConfig_t                   *quantityConfig                   = NULL;
2795 2796
  struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList 
    *dedicatedInfoNASList = NULL;
2797
  LTE_DedicatedInfoNAS_t                 *dedicatedInfoNas                 = NULL;
2798 2799 2800
  
  /* For no gcc warnings */
  (void) dedicatedInfoNas;
2801
  LTE_C_RNTI_t                           *cba_RNTI                         = NULL;
2802
  int                                    measurements_enabled;
2803
  uint8_t xid = rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id);   //Transaction_id,
2804 2805
  uint8_t cc_id = ue_context_pP->ue_context.primaryCC_id;
  LTE_UE_EUTRA_Capability_t *UEcap = ue_context_pP->ue_context.UE_Capability;
2806 2807

#ifdef CBA // Contention Based Access
2808
  uint8_t                            *cba_RNTI_buf;
2809
  cba_RNTI = CALLOC(1, sizeof(LTE_C_RNTI_t));
2810 2811 2812 2813 2814
  cba_RNTI_buf = CALLOC(1, 2 * sizeof(uint8_t));
  cba_RNTI->buf = cba_RNTI_buf;
  cba_RNTI->size = 2;
  cba_RNTI->bits_unused = 0;

2815
  /* Associate UEs to the CBA groups as a function of their UE id */
2816 2817 2818
  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;
2819 2820 2821
    LOG_D(RRC, "[eNB %d] Frame %d: cba_RNTI = %x in group %d is attribued to UE %d\n",
          enb_mod_idP, 
          frameP,
2822 2823 2824 2825 2826
          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;
2827 2828 2829 2830
    LOG_D(RRC, "[eNB %d] Frame %d: no cba_RNTI is configured for UE %d\n", 
          enb_mod_idP, 
          frameP, 
          ue_mod_idP);
2831
  }
2832
#endif
2833 2834 2835 2836 2837 2838 2839 2840 2841

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

  /* Configure SRB2 */
  SRB_configList2 = &(ue_context_pP->ue_context.SRB_configList2[xid]);
Cedric Roux's avatar
Cedric Roux committed
2842

2843 2844 2845
  if (*SRB_configList2) {
    free(*SRB_configList2);
  }
Cedric Roux's avatar
Cedric Roux committed
2846

2847 2848
  *SRB_configList2 = CALLOC(1, sizeof(**SRB_configList2));
  memset(*SRB_configList2, 0, sizeof(**SRB_configList2));
2849 2850 2851 2852
  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;
2853 2854 2855 2856 2857 2858 2859 2860
  SRB2_rlc_config->present = LTE_SRB_ToAddMod__rlc_Config_PR_explicitValue;
  SRB2_rlc_config->choice.explicitValue.present = LTE_RLC_Config_PR_am;
  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.t_PollRetransmit = LTE_T_PollRetransmit_ms15;
  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollPDU = LTE_PollPDU_p8;
  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollByte = LTE_PollByte_kB1000;
  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.maxRetxThreshold = LTE_UL_AM_RLC__maxRetxThreshold_t32;
  SRB2_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_Reordering = LTE_T_Reordering_ms35;
  SRB2_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_StatusProhibit = LTE_T_StatusProhibit_ms10;
2861 2862
  SRB2_lchan_config = CALLOC(1, sizeof(*SRB2_lchan_config));
  SRB2_config->logicalChannelConfig = SRB2_lchan_config;
2863
  SRB2_lchan_config->present = LTE_SRB_ToAddMod__logicalChannelConfig_PR_explicitValue;
2864
  SRB2_ul_SpecificParameters = CALLOC(1, sizeof(*SRB2_ul_SpecificParameters));
2865
  SRB2_ul_SpecificParameters->priority = 3; // let some priority for SRB1 and dedicated DRBs
2866 2867 2868 2869
  SRB2_ul_SpecificParameters->prioritisedBitRate = LTE_LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
  SRB2_ul_SpecificParameters->bucketSizeDuration = LTE_LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
  
  /* LCG for CCCH and DCCH is 0 as defined in 36331 */
2870 2871 2872 2873
  logicalchannelgroup = CALLOC(1, sizeof(long));
  *logicalchannelgroup = 0;
  SRB2_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup;
  SRB2_lchan_config->choice.explicitValue.ul_SpecificParameters = SRB2_ul_SpecificParameters;
2874 2875 2876
  
  ASN_SEQUENCE_ADD(&SRB_configList->list, SRB2_config); // this list has the configuration for SRB1 and SRB2
  ASN_SEQUENCE_ADD(&(*SRB_configList2)->list, SRB2_config); // this list has only the configuration for SRB2
2877

2878
  /* Configure DRB */
2879
  // list for all the configured DRB
2880 2881 2882
  if (*DRB_configList) {
    free(*DRB_configList);
  }
Cedric Roux's avatar
Cedric Roux committed
2883

2884
  *DRB_configList = CALLOC(1, sizeof(**DRB_configList));
2885
  memset(*DRB_configList, 0, sizeof(**DRB_configList));
2886 2887
  
  DRB_configList2=&ue_context_pP->ue_context.DRB_configList2[xid]; // list for the configured DRB for a this xid
Cedric Roux's avatar
Cedric Roux committed
2888

2889 2890 2891
  if (*DRB_configList2) {
    free(*DRB_configList2);
  }
Cedric Roux's avatar
Cedric Roux committed
2892

2893 2894
  *DRB_configList2 = CALLOC(1, sizeof(**DRB_configList2));
  memset(*DRB_configList2, 0, sizeof(**DRB_configList2));
2895
  
2896 2897 2898 2899
  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
  // NN: this is the 1st DRB for this ue, so set it to 1
2900
  DRB_config->drb_Identity = (LTE_DRB_Identity_t) 1;  // (ue_mod_idP+1); //allowed values 1..32, value: x
2901 2902 2903 2904
  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;
2905

2906
#ifdef RRC_DEFAULT_RAB_IS_AM
2907 2908 2909 2910 2911 2912 2913
  DRB_rlc_config->present = LTE_RLC_Config_PR_am;
  DRB_rlc_config->choice.am.ul_AM_RLC.t_PollRetransmit = LTE_T_PollRetransmit_ms50;
  DRB_rlc_config->choice.am.ul_AM_RLC.pollPDU = LTE_PollPDU_p16;
  DRB_rlc_config->choice.am.ul_AM_RLC.pollByte = LTE_PollByte_kBinfinity;
  DRB_rlc_config->choice.am.ul_AM_RLC.maxRetxThreshold = LTE_UL_AM_RLC__maxRetxThreshold_t8;
  DRB_rlc_config->choice.am.dl_AM_RLC.t_Reordering = LTE_T_Reordering_ms35;
  DRB_rlc_config->choice.am.dl_AM_RLC.t_StatusProhibit = LTE_T_StatusProhibit_ms25;
2914
#else
2915 2916 2917
  DRB_rlc_config->present = LTE_RLC_Config_PR_um_Bi_Directional;
  DRB_rlc_config->choice.um_Bi_Directional.ul_UM_RLC.sn_FieldLength = LTE_SN_FieldLength_size10;
  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.sn_FieldLength = LTE_SN_FieldLength_size10;
2918

2919
#ifdef CBA
2920
  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering   = LTE_T_Reordering_ms5; //T_Reordering_ms25;
2921
#else
2922
  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering = LTE_T_Reordering_ms35;
2923
#endif
2924

2925
#endif
2926

2927 2928 2929
  DRB_pdcp_config = CALLOC(1, sizeof(*DRB_pdcp_config));
  DRB_config->pdcp_Config = DRB_pdcp_config;
  DRB_pdcp_config->discardTimer = CALLOC(1, sizeof(long));
2930
  *DRB_pdcp_config->discardTimer = LTE_PDCP_Config__discardTimer_infinity;
2931 2932
  DRB_pdcp_config->rlc_AM = NULL;
  DRB_pdcp_config->rlc_UM = NULL;
2933
  /* Avoid gcc warnings */
Cedric Roux's avatar
Cedric Roux committed
2934
  (void)PDCP_rlc_AM;
Cedric Roux's avatar
Cedric Roux committed
2935
  (void)PDCP_rlc_UM;
2936

2937
#ifdef RRC_DEFAULT_RAB_IS_AM // EXMIMO_IOT
2938 2939 2940
  PDCP_rlc_AM = CALLOC(1, sizeof(*PDCP_rlc_AM));
  DRB_pdcp_config->rlc_AM = PDCP_rlc_AM;
  PDCP_rlc_AM->statusReportRequired = FALSE;
2941
#else
2942 2943
  PDCP_rlc_UM = CALLOC(1, sizeof(*PDCP_rlc_UM));
  DRB_pdcp_config->rlc_UM = PDCP_rlc_UM;
2944
  PDCP_rlc_UM->pdcp_SN_Size = LTE_PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits;
2945
#endif
2946

2947
  DRB_pdcp_config->headerCompression.present = LTE_PDCP_Config__headerCompression_PR_notUsed;
2948 2949 2950 2951
  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;
2952 2953 2954
  DRB_ul_SpecificParameters->priority = 12; // lower priority than srb1, srb2 and other dedicated bearer
  DRB_ul_SpecificParameters->prioritisedBitRate = LTE_LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_kBps8; // LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
  DRB_ul_SpecificParameters->bucketSizeDuration = LTE_LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
2955 2956 2957 2958
  // 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;
2959
  
2960
  ASN_SEQUENCE_ADD(&(*DRB_configList)->list, DRB_config);
2961
  ASN_SEQUENCE_ADD(&(*DRB_configList2)->list, DRB_config);
2962 2963 2964
  
  /* MAC Main Config */
  // The different parts of MAC main config are set below
2965
  mac_MainConfig = CALLOC(1, sizeof(*mac_MainConfig));
2966
  ue_context_pP->ue_context.mac_MainConfig = mac_MainConfig;
2967 2968
  mac_MainConfig->ul_SCH_Config = CALLOC(1, sizeof(*mac_MainConfig->ul_SCH_Config));
  maxHARQ_Tx = CALLOC(1, sizeof(long));
2969
  *maxHARQ_Tx = LTE_MAC_MainConfig__ul_SCH_Config__maxHARQ_Tx_n5;
2970
  mac_MainConfig->ul_SCH_Config->maxHARQ_Tx = maxHARQ_Tx;
2971 2972

  /* BSR reconfiguration */
2973
  periodicBSR_Timer = CALLOC(1, sizeof(long));
2974
  *periodicBSR_Timer = LTE_PeriodicBSR_Timer_r12_sf64; //LTE_PeriodicBSR_Timer_r12_infinity; // LTE_PeriodicBSR_Timer_r12_sf64; // LTE_PeriodicBSR_Timer_r12_sf20
2975
  mac_MainConfig->ul_SCH_Config->periodicBSR_Timer = periodicBSR_Timer;
2976
  mac_MainConfig->ul_SCH_Config->retxBSR_Timer = LTE_RetxBSR_Timer_r12_sf320; // LTE_RetxBSR_Timer_r12_sf320; // LTE_RetxBSR_Timer_r12_sf5120
2977
  mac_MainConfig->ul_SCH_Config->ttiBundling = 0; // FALSE
2978
  mac_MainConfig->timeAlignmentTimerDedicated = LTE_TimeAlignmentTimer_infinity;
2979 2980

  /* PHR reconfiguration */
2981
  mac_MainConfig->phr_Config = CALLOC(1, sizeof(*mac_MainConfig->phr_Config));
2982
  mac_MainConfig->phr_Config->present = LTE_MAC_MainConfig__phr_Config_PR_setup;
2983 2984 2985 2986
  mac_MainConfig->phr_Config->choice.setup.periodicPHR_Timer = LTE_MAC_MainConfig__phr_Config__setup__periodicPHR_Timer_sf500; // sf20 = 20 subframes // LTE_MAC_MainConfig__phr_Config__setup__periodicPHR_Timer_infinity
  mac_MainConfig->phr_Config->choice.setup.prohibitPHR_Timer = LTE_MAC_MainConfig__phr_Config__setup__prohibitPHR_Timer_sf200; // sf20 = 20 subframes // LTE_MAC_MainConfig__phr_Config__setup__prohibitPHR_Timer_sf1000
  mac_MainConfig->phr_Config->choice.setup.dl_PathlossChange = LTE_MAC_MainConfig__phr_Config__setup__dl_PathlossChange_dB3;  // Value dB1 =1 dB, dB3 = 3 dB

2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001
  if (!NODE_IS_CU(RC.rrc[ctxt_pP->module_id]->node_type)) {
    /* CDRX Configuration */
    // Need to check if UE is a BR UE
    rnti_t rnti = ue_context_pP->ue_id_rnti;
    module_id_t module_id = ctxt_pP->module_id;
    int UE_id = find_UE_id(module_id, rnti);
    eNB_MAC_INST *mac = RC.mac[module_id];
    UE_list_t *UE_list = &(mac->UE_list);

    if (UE_id != -1) {
      if ((rrc_inst->carrier[cc_id].sib1->tdd_Config == NULL) && 
        (UE_list->UE_template[ue_context_pP->ue_context.primaryCC_id][UE_id].rach_resource_type == 0)) {
      // CDRX can be only configured in case of FDD and non BR UE (09/04/19)
      
      LOG_D(RRC, "Processing the DRX configuration in RRC Connection Reconfiguration\n");
3002

3003 3004 3005 3006 3007 3008
      /* Process the IE drx_Config */
      if (cc_id < MAX_NUM_CCs) {
        mac_MainConfig->drx_Config = do_DrxConfig(module_id, cc_id, &rrc_inst->configuration, UEcap); // drx_Config IE
      } else {
        LOG_E(RRC, "Invalid CC_id for DRX configuration\n");
      }
3009

3010 3011
      /* Set timers and thresholds values in local MAC context of UE */
      eNB_Config_Local_DRX(module_id, ue_context_pP->ue_id_rnti, mac_MainConfig->drx_Config);
3012

3013
      LOG_D(RRC, "DRX configured in mac main config for RRC Connection Reconfiguration\n");
3014

3015 3016 3017 3018 3019
      } else { // CDRX not implemented for TDD and LTE-M (09/04/19)
        mac_MainConfig->drx_Config = NULL;
      }
    } else { // UE_id invalid
      LOG_E(RRC, "Invalid UE_id found!\n");
3020 3021
      mac_MainConfig->drx_Config = NULL;
    }
3022 3023
  } else { // No CDRX with the CU/DU split in this version
    LOG_E(RRC, "CU/DU split activated\n");
3024 3025 3026
    mac_MainConfig->drx_Config = NULL;
  }

3027
#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
3028
  sr_ProhibitTimer_r9 = CALLOC(1, sizeof(long));
3029
  *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
3030
  mac_MainConfig->ext1 = CALLOC(1, sizeof(struct LTE_MAC_MainConfig__ext1));
3031
  mac_MainConfig->ext1->sr_ProhibitTimer_r9 = sr_ProhibitTimer_r9;
3032 3033
#endif

3034 3035 3036
  // change the transmission mode for the primary component carrier
  // TODO: add codebook subset restriction here
  // TODO: change TM for secondary CC in SCelltoaddmodlist
3037
  if (*physicalConfigDedicated) {
3038
    if ((*physicalConfigDedicated)->antennaInfo) {
3039 3040
      (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.transmissionMode = rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode;
      LOG_D(RRC,"Setting transmission mode to %ld+1\n",rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode);
3041

3042
      if (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm3) {
3043
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=     
3044
	  CALLOC(1,sizeof(LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR));
3045
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
3046
	  LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm3;
3047 3048 3049 3050
	(*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;
3051
      } else if (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm4) {
3052
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=     
3053
	  CALLOC(1,sizeof(LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR));
3054
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
3055
	  LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm4;
3056 3057 3058 3059
	(*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;
3060
      } else if (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm5) {
3061
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=     
3062
	  CALLOC(1,sizeof(LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR));
3063
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
3064
	  LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm5;
3065 3066 3067 3068
	(*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;
3069
      } else if (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm6) {
3070
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=     
3071
	  CALLOC(1,sizeof(LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR));
3072
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
3073
	  LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm6;
3074 3075 3076 3077 3078
	(*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;
      }
3079
    } else {
3080 3081
      LOG_E(RRC,"antenna_info not present in physical_config_dedicated. Not reconfiguring!\n");
    }
Cedric Roux's avatar
Cedric Roux committed
3082

3083 3084 3085 3086 3087 3088 3089 3090 3091 3092
    /* CSI RRC Reconfiguration */
    if ((*physicalConfigDedicated)->cqi_ReportConfig != NULL) {
      if ((rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode == LTE_AntennaInfoDedicated__transmissionMode_tm4) ||
          (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode == LTE_AntennaInfoDedicated__transmissionMode_tm5) ||
          (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode == LTE_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
        LOG_I(RRC, "Setting cqi reporting mode to rm31 (hardcoded)\n");

3093
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
3094
        *((*physicalConfigDedicated)->cqi_ReportConfig->cqi_ReportModeAperiodic) = LTE_CQI_ReportModeAperiodic_rm31; // HLC CQI, single PMI
3095
#else
3096
        *((*physicalConfigDedicated)->cqi_ReportConfig->cqi_ReportModeAperiodic) = LTE_CQI_ReportConfig__cqi_ReportModeAperiodic_rm31; // HLC CQI, single PMI
3097 3098
#endif
      }
Cedric Roux's avatar
Cedric Roux committed
3099
    } else {
3100 3101
      LOG_E(RRC,"cqi_ReportConfig not present in physical_config_dedicated. Not reconfiguring!\n");
    }
Cedric Roux's avatar
Cedric Roux committed
3102
  } else {
3103
    LOG_E(RRC,"physical_config_dedicated not present in LTE_RRCConnectionReconfiguration. Not reconfiguring!\n");
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 3136 3137 3138
  // 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);
3139
  //  LTE_RRCConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->measIdToAddModList = MeasId_list;
3140 3141 3142 3143 3144 3145 3146
  // 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;
3147
  MeasObj->measObject.present = LTE_MeasObjectToAddMod__measObject_PR_measObjectEUTRA;
3148 3149 3150 3151
  MeasObj->measObject.choice.measObjectEUTRA.carrierFreq =
      to_earfcn_DL(RC.rrc[ctxt_pP->module_id]->configuration.eutra_band[0],
                   RC.rrc[ctxt_pP->module_id]->configuration.downlink_frequency[0],
                   RC.rrc[ctxt_pP->module_id]->configuration.N_RB_DL[0]);
3152
  MeasObj->measObject.choice.measObjectEUTRA.allowedMeasBandwidth = LTE_AllowedMeasBandwidth_mbw25;
3153 3154 3155 3156 3157 3158
  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
3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170
  //  MeasObj->measObject.choice.measObjectEUTRA.cellsToAddModList =
  //    (LTE_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 = (LTE_CellsToAddMod_t *) CALLOC(1, sizeof(*CellToAdd));
  //    CellToAdd->cellIndex = i + 1;
  //    CellToAdd->physCellId = get_adjacent_cell_id(ctxt_pP->module_id, i);
  //    CellToAdd->cellIndividualOffset = LTE_Q_OffsetRange_dB0;
  //    ASN_SEQUENCE_ADD(&CellsToAddModList->list, CellToAdd);
  //  }
3171
  ASN_SEQUENCE_ADD(&MeasObj_list->list, MeasObj);
3172
  //  LTE_RRCConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->measObjectToAddModList = MeasObj_list;
3173 3174 3175 3176 3177 3178 3179 3180 3181
  // 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;
3182
  ReportConfig_per->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
3183
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerType.present =
3184
    LTE_ReportConfigEUTRA__triggerType_PR_periodical;
3185
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerType.choice.periodical.purpose =
3186 3187 3188
    LTE_ReportConfigEUTRA__triggerType__periodical__purpose_reportStrongestCells;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerQuantity = LTE_ReportConfigEUTRA__triggerQuantity_rsrp;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both;
3189
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
3190 3191
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity;
3192 3193
  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_per);
  ReportConfig_A1->reportConfigId = 2;
3194
  ReportConfig_A1->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
3195
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.present =
3196
    LTE_ReportConfigEUTRA__triggerType_PR_event;
3197
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
3198
    LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA1;
3199
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA1.
3200
  a1_Threshold.present = LTE_ThresholdEUTRA_PR_threshold_RSRP;
3201 3202
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA1.
  a1_Threshold.choice.threshold_RSRP = 10;
3203 3204
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerQuantity = LTE_ReportConfigEUTRA__triggerQuantity_rsrp;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both;
3205
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
3206 3207
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity;
3208
  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A1);
3209
  //if (ho_state == 1 /*HO_MEASURMENT */ ) {
Cedric Roux's avatar
Cedric Roux committed
3210 3211 3212
  LOG_I(RRC, "[eNB %d] frame %d: requesting A2, A3, A4, and A5 event reporting\n",
        ctxt_pP->module_id, ctxt_pP->frame);
  ReportConfig_A2->reportConfigId = 3;
3213
  ReportConfig_A2->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
Cedric Roux's avatar
Cedric Roux committed
3214
  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.present =
3215
    LTE_ReportConfigEUTRA__triggerType_PR_event;
Cedric Roux's avatar
Cedric Roux committed
3216
  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
3217
    LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA2;
Cedric Roux's avatar
Cedric Roux committed
3218
  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
3219
  eventA2.a2_Threshold.present = LTE_ThresholdEUTRA_PR_threshold_RSRP;
Cedric Roux's avatar
Cedric Roux committed
3220 3221 3222
  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
  eventA2.a2_Threshold.choice.threshold_RSRP = 10;
  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerQuantity =
3223 3224
    LTE_ReportConfigEUTRA__triggerQuantity_rsrp;
  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both;
Cedric Roux's avatar
Cedric Roux committed
3225
  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
3226 3227
  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120;
  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity;
Cedric Roux's avatar
Cedric Roux committed
3228 3229
  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A2);
  ReportConfig_A3->reportConfigId = 4;
3230
  ReportConfig_A3->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
Cedric Roux's avatar
Cedric Roux committed
3231
  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.present =
3232
    LTE_ReportConfigEUTRA__triggerType_PR_event;
Cedric Roux's avatar
Cedric Roux committed
3233
  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
3234
    LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA3;
Cedric Roux's avatar
Cedric Roux committed
3235 3236 3237 3238
  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA3.a3_Offset = 0;   //10;
  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
  eventA3.reportOnLeave = 1;
  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerQuantity =
3239 3240
    LTE_ReportConfigEUTRA__triggerQuantity_rsrp;
  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both;
Cedric Roux's avatar
Cedric Roux committed
3241
  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
3242 3243
  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120;
  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity;
Cedric Roux's avatar
Cedric Roux committed
3244 3245
  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.hysteresis = 0; // FIXME ...hysteresis is of type long!
  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.timeToTrigger =
3246
    LTE_TimeToTrigger_ms40;
Cedric Roux's avatar
Cedric Roux committed
3247 3248
  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A3);
  ReportConfig_A4->reportConfigId = 5;
3249
  ReportConfig_A4->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
Cedric Roux's avatar
Cedric Roux committed
3250
  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.present =
3251
    LTE_ReportConfigEUTRA__triggerType_PR_event;
Cedric Roux's avatar
Cedric Roux committed
3252
  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
3253
    LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA4;
Cedric Roux's avatar
Cedric Roux committed
3254
  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
3255
  eventA4.a4_Threshold.present = LTE_ThresholdEUTRA_PR_threshold_RSRP;
Cedric Roux's avatar
Cedric Roux committed
3256 3257 3258
  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
  eventA4.a4_Threshold.choice.threshold_RSRP = 10;
  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerQuantity =
3259 3260
    LTE_ReportConfigEUTRA__triggerQuantity_rsrp;
  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both;
Cedric Roux's avatar
Cedric Roux committed
3261
  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
3262 3263
  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120;
  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity;
Cedric Roux's avatar
Cedric Roux committed
3264 3265
  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A4);
  ReportConfig_A5->reportConfigId = 6;
3266
  ReportConfig_A5->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
Cedric Roux's avatar
Cedric Roux committed
3267
  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.present =
3268
    LTE_ReportConfigEUTRA__triggerType_PR_event;
Cedric Roux's avatar
Cedric Roux committed
3269
  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
3270
    LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA5;
Cedric Roux's avatar
Cedric Roux committed
3271
  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
3272
  eventA5.a5_Threshold1.present = LTE_ThresholdEUTRA_PR_threshold_RSRP;
Cedric Roux's avatar
Cedric Roux committed
3273
  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
3274
  eventA5.a5_Threshold2.present = LTE_ThresholdEUTRA_PR_threshold_RSRP;
Cedric Roux's avatar
Cedric Roux committed
3275 3276 3277 3278 3279
  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 =
3280 3281
    LTE_ReportConfigEUTRA__triggerQuantity_rsrp;
  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both;
Cedric Roux's avatar
Cedric Roux committed
3282
  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
3283 3284
  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120;
  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity;
Cedric Roux's avatar
Cedric Roux committed
3285
  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A5);
3286 3287
  //  LTE_RRCConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->reportConfigToAddModList = ReportConfig_list;
  rsrp = CALLOC(1, sizeof(LTE_RSRP_Range_t));
Cedric Roux's avatar
Cedric Roux committed
3288 3289
  *rsrp = 20;
  Sparams = CALLOC(1, sizeof(*Sparams));
3290 3291 3292
  Sparams->present = LTE_MeasConfig__speedStatePars_PR_setup;
  Sparams->choice.setup.timeToTrigger_SF.sf_High = LTE_SpeedStateScaleFactors__sf_Medium_oDot75;
  Sparams->choice.setup.timeToTrigger_SF.sf_Medium = LTE_SpeedStateScaleFactors__sf_High_oDot5;
Cedric Roux's avatar
Cedric Roux committed
3293 3294
  Sparams->choice.setup.mobilityStateParameters.n_CellChangeHigh = 10;
  Sparams->choice.setup.mobilityStateParameters.n_CellChangeMedium = 5;
3295 3296
  Sparams->choice.setup.mobilityStateParameters.t_Evaluation = LTE_MobilityStateParameters__t_Evaluation_s60;
  Sparams->choice.setup.mobilityStateParameters.t_HystNormal = LTE_MobilityStateParameters__t_HystNormal_s120;
Cedric Roux's avatar
Cedric Roux committed
3297 3298
  quantityConfig = CALLOC(1, sizeof(*quantityConfig));
  memset((void *)quantityConfig, 0, sizeof(*quantityConfig));
3299
  quantityConfig->quantityConfigEUTRA = CALLOC(1, sizeof(struct LTE_QuantityConfigEUTRA));
Cedric Roux's avatar
Cedric Roux committed
3300 3301 3302 3303 3304 3305 3306 3307
  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)));
3308 3309
  *quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP = LTE_FilterCoefficient_fc4;
  *quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ = LTE_FilterCoefficient_fc4;
3310

3311
  /* Initialize NAS list */
3312
  dedicatedInfoNASList = CALLOC(1, sizeof(struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList));
3313 3314

  /* Add all NAS PDUs to the list */
3315 3316
  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) {
3317
      dedicatedInfoNas = CALLOC(1, sizeof(LTE_DedicatedInfoNAS_t));
3318
      memset(dedicatedInfoNas, 0, sizeof(OCTET_STRING_t));
Cedric Roux's avatar
Cedric Roux committed
3319 3320
      OCTET_STRING_fromBuf(dedicatedInfoNas,
                           (char *)ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer,
3321
                           ue_context_pP->ue_context.e_rab[i].param.nas_pdu.length);
3322
      ASN_SEQUENCE_ADD(&dedicatedInfoNASList->list, dedicatedInfoNas);
3323
    }
3324

3325 3326
    /* TODO parameters yet to process ... */
    {
3327 3328 3329
      //      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;
3330
    }
3331 3332

    /* TODO should test if e RAB are OK before! */
3333
    ue_context_pP->ue_context.e_rab[i].status = E_RAB_STATUS_DONE;
Cedric Roux's avatar
Cedric Roux committed
3334 3335
    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");
3336 3337 3338 3339 3340 3341 3342 3343
  }

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

3344 3345
  measurements_enabled = RC.rrc[ENB_INSTANCE_TO_MODULE_ID(ctxt_pP->instance)]->configuration.enable_x2 ||
                         RC.rrc[ENB_INSTANCE_TO_MODULE_ID(ctxt_pP->instance)]->configuration.enable_measurement_reports;
Cedric Roux's avatar
Cedric Roux committed
3346

3347
  memset(buffer, 0, RRC_BUF_SIZE);
3348

3349 3350
  size = do_RRCConnectionReconfiguration(ctxt_pP,
                                         buffer,
3351 3352 3353 3354 3355 3356
                                         xid, // Transaction_id,
                                         (LTE_SRB_ToAddModList_t *) *SRB_configList2, // SRB_configList
                                         (LTE_DRB_ToAddModList_t *) *DRB_configList,
                                         (LTE_DRB_ToReleaseList_t *) NULL, // DRB2_list,
                                         (struct LTE_SPS_Config *) NULL,   // *sps_Config,
                                         (struct LTE_PhysicalConfigDedicated *) *physicalConfigDedicated,
3357 3358 3359 3360
                                         measurements_enabled ? (LTE_MeasObjectToAddModList_t *) MeasObj_list : NULL,
                                         measurements_enabled ? (LTE_ReportConfigToAddModList_t *) ReportConfig_list : NULL,
                                         measurements_enabled ? (LTE_QuantityConfig_t *) quantityConfig : NULL,
                                         measurements_enabled ? (LTE_MeasIdToAddModList_t *) MeasId_list : NULL,
3361 3362 3363 3364 3365 3366 3367 3368 3369 3370
                                         (LTE_MAC_MainConfig_t *) mac_MainConfig,
                                         (LTE_MeasGapConfig_t *) NULL,
                                         (LTE_MobilityControlInfo_t *) NULL,
                                         (LTE_SecurityConfigHO_t *) NULL,
                                         (struct LTE_MeasConfig__speedStatePars *) Sparams,
                                         (LTE_RSRP_Range_t *) rsrp,
                                         (LTE_C_RNTI_t *) cba_RNTI,
                                         (struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *) dedicatedInfoNASList,
                                         (LTE_SL_CommConfig_r12_t *) NULL,
                                         (LTE_SL_DiscConfig_r12_t *) NULL
3371
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
3372
                                         , (LTE_SCellToAddMod_r10_t *) NULL
3373
#endif
3374
                                        );
3375 3376

  LOG_DUMPMSG(RRC, DEBUG_RRC,(char *)buffer, size, "[MSG] RRC Connection Reconfiguration\n");
3377 3378

  /* Free all NAS PDUs */
3379 3380
  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) {
3381
      /* Free the NAS PDU buffer and invalidate it */
3382 3383
      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;
3384
    }
3385 3386
  }

3387
  LOG_I(RRC, "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate LTE_RRCConnectionReconfiguration (bytes %d, UE id %x)\n",
3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418
        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" LTE_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);
winckel's avatar
winckel committed
3419
}
3420

3421
//-----------------------------------------------------------------------------
3422
void
Cedric Roux's avatar
Cedric Roux committed
3423 3424 3425 3426 3427
flexran_rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt_t *const ctxt_pP,
    rrc_eNB_ue_context_t          *const ue_context_pP,
    const uint8_t                ho_state,
    agent_reconf_rrc *trig_param
                                                            )
3428
//-----------------------------------------------------------------------------
3429
{
3430 3431 3432
  uint8_t                             buffer[RRC_BUF_SIZE];
  uint16_t                            size;
  int                                 i;
3433
  // configure SRB1/SRB2, PhysicalConfigDedicated, LTE_MAC_MainConfig for UE
Cedric Roux's avatar
Cedric Roux committed
3434
  eNB_RRC_INST                       *rrc_inst = RC.rrc[ctxt_pP->module_id];
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
3435
  struct LTE_PhysicalConfigDedicated    **physicalConfigDedicated = &ue_context_pP->ue_context.physicalConfigDedicated;
3436 3437 3438 3439
  struct LTE_SRB_ToAddMod                *SRB2_config                      = NULL;
  struct LTE_SRB_ToAddMod__rlc_Config    *SRB2_rlc_config                  = NULL;
  struct LTE_SRB_ToAddMod__logicalChannelConfig *SRB2_lchan_config         = NULL;
  struct LTE_LogicalChannelConfig__ul_SpecificParameters
Cedric Roux's avatar
Cedric Roux committed
3440
    *SRB2_ul_SpecificParameters       = NULL;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
3441
  LTE_SRB_ToAddModList_t                 *SRB_configList = ue_context_pP->ue_context.SRB_configList;
3442 3443 3444 3445 3446 3447 3448 3449
  LTE_SRB_ToAddModList_t                 **SRB_configList2                  = NULL;
  struct LTE_DRB_ToAddMod                *DRB_config                       = NULL;
  struct LTE_RLC_Config                  *DRB_rlc_config                   = NULL;
  struct LTE_PDCP_Config                 *DRB_pdcp_config                  = NULL;
  struct LTE_PDCP_Config__rlc_AM         *PDCP_rlc_AM                      = NULL;
  struct LTE_PDCP_Config__rlc_UM         *PDCP_rlc_UM                      = NULL;
  struct LTE_LogicalChannelConfig        *DRB_lchan_config                 = NULL;
  struct LTE_LogicalChannelConfig__ul_SpecificParameters
Cedric Roux's avatar
Cedric Roux committed
3450
    *DRB_ul_SpecificParameters        = NULL;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
3451 3452
  LTE_DRB_ToAddModList_t                **DRB_configList = &ue_context_pP->ue_context.DRB_configList;
  LTE_DRB_ToAddModList_t                **DRB_configList2 = NULL;
3453 3454 3455 3456 3457
  LTE_MAC_MainConfig_t                   *mac_MainConfig                   = NULL;
  LTE_MeasObjectToAddModList_t           *MeasObj_list                     = NULL;
  LTE_MeasObjectToAddMod_t               *MeasObj                          = NULL;
  LTE_ReportConfigToAddModList_t         *ReportConfig_list                = NULL;
  LTE_ReportConfigToAddMod_t             *ReportConfig_per;//, *ReportConfig_A1,
Cedric Roux's avatar
Cedric Roux committed
3458
  // *ReportConfig_A2, *ReportConfig_A3, *ReportConfig_A4, *ReportConfig_A5;
3459 3460 3461
  LTE_MeasIdToAddModList_t               *MeasId_list                      = NULL;
  LTE_MeasIdToAddMod_t                   *MeasId0; //, *MeasId1, *MeasId2, *MeasId3, *MeasId4, *MeasId5;
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
3462 3463 3464
  long                               *sr_ProhibitTimer_r9              = NULL;
  //     uint8_t sCellIndexToAdd = rrc_find_free_SCell_index(enb_mod_idP, ue_mod_idP, 1);
  //uint8_t                            sCellIndexToAdd = 0;
3465
#endif
3466 3467
  long                               *logicalchannelgroup, *logicalchannelgroup_drb;
  long                               *maxHARQ_Tx, *periodicBSR_Timer;
3468 3469 3470 3471 3472 3473 3474
  LTE_RSRP_Range_t                       *rsrp                             = NULL;
  struct LTE_MeasConfig__speedStatePars  *Sparams                          = NULL;
  LTE_QuantityConfig_t                   *quantityConfig                   = NULL;
  LTE_CellsToAddMod_t                    *CellToAdd                        = NULL;
  LTE_CellsToAddModList_t                *CellsToAddModList                = NULL;
  struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList = NULL;
  LTE_DedicatedInfoNAS_t                 *dedicatedInfoNas                 = NULL;
3475 3476
  /* for no gcc warnings */
  (void)dedicatedInfoNas;
3477
  LTE_C_RNTI_t                           *cba_RNTI                         = NULL;
3478
  int                                    measurements_enabled;
3479 3480 3481 3482
  uint8_t xid = rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id);   //Transaction_id,
#ifdef CBA
  //struct PUSCH_CBAConfigDedicated_vlola  *pusch_CBAConfigDedicated_vlola;
  uint8_t                            *cba_RNTI_buf;
3483
  cba_RNTI = CALLOC(1, sizeof(LTE_C_RNTI_t));
3484 3485 3486 3487
  cba_RNTI_buf = CALLOC(1, 2 * sizeof(uint8_t));
  cba_RNTI->buf = cba_RNTI_buf;
  cba_RNTI->size = 2;
  cba_RNTI->bits_unused = 0;
3488

3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501
  // 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);
3502 3503 3504
  }

#endif
3505 3506 3507 3508 3509
  T(T_ENB_RRC_CONNECTION_RECONFIGURATION, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
  // Configure SRB2
  /// SRB2
  SRB_configList2=&ue_context_pP->ue_context.SRB_configList2[xid];
Cedric Roux's avatar
Cedric Roux committed
3510

3511 3512
  if (*SRB_configList2) {
    free(*SRB_configList2);
3513
  }
Cedric Roux's avatar
Cedric Roux committed
3514

3515 3516 3517 3518 3519 3520
  *SRB_configList2 = CALLOC(1, sizeof(**SRB_configList2));
  memset(*SRB_configList2, 0, sizeof(**SRB_configList2));
  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;
3521 3522 3523 3524 3525 3526 3527 3528
  SRB2_rlc_config->present = LTE_SRB_ToAddMod__rlc_Config_PR_explicitValue;
  SRB2_rlc_config->choice.explicitValue.present = LTE_RLC_Config_PR_am;
  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.t_PollRetransmit = LTE_T_PollRetransmit_ms15;
  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollPDU = LTE_PollPDU_p8;
  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollByte = LTE_PollByte_kB1000;
  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.maxRetxThreshold = LTE_UL_AM_RLC__maxRetxThreshold_t32;
  SRB2_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_Reordering = LTE_T_Reordering_ms35;
  SRB2_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_StatusProhibit = LTE_T_StatusProhibit_ms10;
3529 3530
  SRB2_lchan_config = CALLOC(1, sizeof(*SRB2_lchan_config));
  SRB2_config->logicalChannelConfig = SRB2_lchan_config;
3531
  SRB2_lchan_config->present = LTE_SRB_ToAddMod__logicalChannelConfig_PR_explicitValue;
3532 3533 3534
  SRB2_ul_SpecificParameters = CALLOC(1, sizeof(*SRB2_ul_SpecificParameters));
  SRB2_ul_SpecificParameters->priority = 3; // let some priority for SRB1 and dedicated DRBs
  SRB2_ul_SpecificParameters->prioritisedBitRate =
3535
    LTE_LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
3536
  SRB2_ul_SpecificParameters->bucketSizeDuration =
3537
    LTE_LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
3538 3539 3540 3541 3542 3543 3544 3545 3546
  // 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;
  // this list has the configuration for SRB1 and SRB2
  ASN_SEQUENCE_ADD(&SRB_configList->list, SRB2_config);
  // this list has only the configuration for SRB2
  ASN_SEQUENCE_ADD(&(*SRB_configList2)->list, SRB2_config);
3547

3548 3549 3550 3551 3552 3553
  // Configure DRB
  //*DRB_configList = CALLOC(1, sizeof(*DRB_configList));
  // list for all the configured DRB
  if (*DRB_configList) {
    free(*DRB_configList);
  }
Cedric Roux's avatar
Cedric Roux committed
3554

3555 3556 3557 3558
  *DRB_configList = CALLOC(1, sizeof(**DRB_configList));
  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];
Cedric Roux's avatar
Cedric Roux committed
3559

3560 3561 3562
  if (*DRB_configList2) {
    free(*DRB_configList2);
  }
Cedric Roux's avatar
Cedric Roux committed
3563

3564 3565 3566 3567 3568 3569
  *DRB_configList2 = CALLOC(1, sizeof(**DRB_configList2));
  memset(*DRB_configList2, 0, sizeof(**DRB_configList2));
  /// DRB
  DRB_config = CALLOC(1, sizeof(*DRB_config));
  DRB_config->eps_BearerIdentity = CALLOC(1, sizeof(long));
  *(DRB_config->eps_BearerIdentity) = 5L; // LW set to first value, allowed value 5..15, value : x+4
3570
  // DRB_config->drb_Identity = (LTE_DRB_Identity_t) 1; //allowed values 1..32
3571
  // NN: this is the 1st DRB for this ue, so set it to 1
3572
  DRB_config->drb_Identity = (LTE_DRB_Identity_t) 1;  // (ue_mod_idP+1); //allowed values 1..32, value: x
3573 3574 3575 3576 3577
  DRB_config->logicalChannelIdentity = CALLOC(1, sizeof(long));
  *(DRB_config->logicalChannelIdentity) = (long)3; // value : x+2
  DRB_rlc_config = CALLOC(1, sizeof(*DRB_rlc_config));
  DRB_config->rlc_Config = DRB_rlc_config;
#ifdef RRC_DEFAULT_RAB_IS_AM
3578 3579 3580 3581 3582 3583 3584
  DRB_rlc_config->present = LTE_RLC_Config_PR_am;
  DRB_rlc_config->choice.am.ul_AM_RLC.t_PollRetransmit = LTE_T_PollRetransmit_ms50;
  DRB_rlc_config->choice.am.ul_AM_RLC.pollPDU = LTE_PollPDU_p16;
  DRB_rlc_config->choice.am.ul_AM_RLC.pollByte = LTE_PollByte_kBinfinity;
  DRB_rlc_config->choice.am.ul_AM_RLC.maxRetxThreshold = LTE_UL_AM_RLC__maxRetxThreshold_t8;
  DRB_rlc_config->choice.am.dl_AM_RLC.t_Reordering = LTE_T_Reordering_ms35;
  DRB_rlc_config->choice.am.dl_AM_RLC.t_StatusProhibit = LTE_T_StatusProhibit_ms25;
3585
#else
3586 3587 3588
  DRB_rlc_config->present = LTE_RLC_Config_PR_um_Bi_Directional;
  DRB_rlc_config->choice.um_Bi_Directional.ul_UM_RLC.sn_FieldLength = LTE_SN_FieldLength_size10;
  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.sn_FieldLength = LTE_SN_FieldLength_size10;
3589
#ifdef CBA
3590
  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering   = LTE_T_Reordering_ms5;//T_Reordering_ms25;
3591
#else
3592
  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering = LTE_T_Reordering_ms35;
3593 3594 3595 3596 3597
#endif
#endif
  DRB_pdcp_config = CALLOC(1, sizeof(*DRB_pdcp_config));
  DRB_config->pdcp_Config = DRB_pdcp_config;
  DRB_pdcp_config->discardTimer = CALLOC(1, sizeof(long));
3598
  *DRB_pdcp_config->discardTimer = LTE_PDCP_Config__discardTimer_infinity;
3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610
  DRB_pdcp_config->rlc_AM = NULL;
  DRB_pdcp_config->rlc_UM = NULL;
  /* avoid gcc warnings */
  (void)PDCP_rlc_AM;
  (void)PDCP_rlc_UM;
#ifdef RRC_DEFAULT_RAB_IS_AM // EXMIMO_IOT
  PDCP_rlc_AM = CALLOC(1, sizeof(*PDCP_rlc_AM));
  DRB_pdcp_config->rlc_AM = PDCP_rlc_AM;
  PDCP_rlc_AM->statusReportRequired = FALSE;
#else
  PDCP_rlc_UM = CALLOC(1, sizeof(*PDCP_rlc_UM));
  DRB_pdcp_config->rlc_UM = PDCP_rlc_UM;
3611
  PDCP_rlc_UM->pdcp_SN_Size = LTE_PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits;
3612
#endif
3613
  DRB_pdcp_config->headerCompression.present = LTE_PDCP_Config__headerCompression_PR_notUsed;
3614 3615 3616 3617 3618
  DRB_lchan_config = CALLOC(1, sizeof(*DRB_lchan_config));
  DRB_config->logicalChannelConfig = DRB_lchan_config;
  DRB_ul_SpecificParameters = CALLOC(1, sizeof(*DRB_ul_SpecificParameters));
  DRB_lchan_config->ul_SpecificParameters = DRB_ul_SpecificParameters;
  DRB_ul_SpecificParameters->priority = 12;    // lower priority than srb1, srb2 and other dedicated bearer
3619
  DRB_ul_SpecificParameters->prioritisedBitRate = LTE_LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_kBps8 ;
Cedric Roux's avatar
Cedric Roux committed
3620
  //LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
3621
  DRB_ul_SpecificParameters->bucketSizeDuration =
3622
    LTE_LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
3623 3624 3625 3626 3627 3628 3629 3630
  // LCG for DTCH can take the value from 1 to 3 as defined in 36331: normally controlled by upper layers (like RRM)
  logicalchannelgroup_drb = CALLOC(1, sizeof(long));
  *logicalchannelgroup_drb = 1;
  DRB_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup_drb;
  ASN_SEQUENCE_ADD(&(*DRB_configList)->list, DRB_config);
  ASN_SEQUENCE_ADD(&(*DRB_configList2)->list, DRB_config);
  //ue_context_pP->ue_context.DRB_configList2[0] = &(*DRB_configList);
  mac_MainConfig = CALLOC(1, sizeof(*mac_MainConfig));
3631
  // ue_context_pP->ue_context.mac_MainConfig = LTE_MAC_MainConfig;
3632 3633
  mac_MainConfig->ul_SCH_Config = CALLOC(1, sizeof(*mac_MainConfig->ul_SCH_Config));
  maxHARQ_Tx = CALLOC(1, sizeof(long));
3634
  *maxHARQ_Tx = LTE_MAC_MainConfig__ul_SCH_Config__maxHARQ_Tx_n5;
3635 3636
  mac_MainConfig->ul_SCH_Config->maxHARQ_Tx = maxHARQ_Tx;
  periodicBSR_Timer = CALLOC(1, sizeof(long));
3637
  *periodicBSR_Timer = LTE_PeriodicBSR_Timer_r12_sf64;
3638
  mac_MainConfig->ul_SCH_Config->periodicBSR_Timer = periodicBSR_Timer;
3639
  mac_MainConfig->ul_SCH_Config->retxBSR_Timer = LTE_RetxBSR_Timer_r12_sf320;
3640
  mac_MainConfig->ul_SCH_Config->ttiBundling = 0; // FALSE
3641
  mac_MainConfig->timeAlignmentTimerDedicated = LTE_TimeAlignmentTimer_infinity;
3642 3643
  mac_MainConfig->drx_Config = NULL;
  mac_MainConfig->phr_Config = CALLOC(1, sizeof(*mac_MainConfig->phr_Config));
3644 3645 3646 3647 3648
  mac_MainConfig->phr_Config->present = LTE_MAC_MainConfig__phr_Config_PR_setup;
  mac_MainConfig->phr_Config->choice.setup.periodicPHR_Timer = LTE_MAC_MainConfig__phr_Config__setup__periodicPHR_Timer_sf20; // sf20 = 20 subframes
  mac_MainConfig->phr_Config->choice.setup.prohibitPHR_Timer = LTE_MAC_MainConfig__phr_Config__setup__prohibitPHR_Timer_sf20; // sf20 = 20 subframes
  mac_MainConfig->phr_Config->choice.setup.dl_PathlossChange = LTE_MAC_MainConfig__phr_Config__setup__dl_PathlossChange_dB1;  // Value dB1 =1 dB, dB3 = 3 dB
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
3649 3650
  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
3651
  mac_MainConfig->ext1 = CALLOC(1, sizeof(struct LTE_MAC_MainConfig__ext1));
3652 3653 3654
  mac_MainConfig->ext1->sr_ProhibitTimer_r9 = sr_ProhibitTimer_r9;
  //sps_RA_ConfigList_rlola = NULL;
#endif
3655

3656 3657 3658 3659 3660
  //change the transmission mode for the primary component carrier
  //TODO: add codebook subset restriction here
  //TODO: change TM for secondary CC in SCelltoaddmodlist
  if (*physicalConfigDedicated) {
    if ((*physicalConfigDedicated)->antennaInfo) {
3661 3662
      (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.transmissionMode = rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode;
      LOG_D(RRC,"Setting transmission mode to %ld+1\n",rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode);
3663

3664
      if (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm3) {
3665
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=
3666 3667 3668 3669 3670 3671 3672 3673
	  CALLOC(1,sizeof(LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR));
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
	  LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm3;
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.buf= MALLOC(1);
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.buf[0] = 0xc0;
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.size=1;
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.bits_unused=6;
      } else if (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm4) {
3674
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=
3675 3676 3677 3678 3679 3680 3681
	  CALLOC(1,sizeof(LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR));
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
	  LTE_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;
3682
      } else if (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm5) {
3683
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=
3684 3685 3686 3687 3688 3689 3690
	  CALLOC(1,sizeof(LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR));
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
	  LTE_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;
3691
      } else if (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm6) {
3692
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=
3693 3694 3695 3696 3697 3698 3699
	  CALLOC(1,sizeof(LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR));
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
	  LTE_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;
3700
      }
3701
    } else {
3702 3703
      LOG_E(RRC,"antenna_info not present in physical_config_dedicated. Not reconfiguring!\n");
    }
Cedric Roux's avatar
Cedric Roux committed
3704

3705 3706 3707 3708 3709 3710 3711 3712 3713
    /* CSI Configuration through RRC */
    if ((*physicalConfigDedicated)->cqi_ReportConfig != NULL) {
      if ((rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode == LTE_AntennaInfoDedicated__transmissionMode_tm4) ||
          (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode == LTE_AntennaInfoDedicated__transmissionMode_tm5) ||
          (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode == LTE_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
        LOG_I(RRC, "Setting cqi aperiodic reporting mode to rm31 (hardcoded)\n");

3714
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
3715
        *((*physicalConfigDedicated)->cqi_ReportConfig->cqi_ReportModeAperiodic)=LTE_CQI_ReportModeAperiodic_rm31;
3716
#else
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
3717
        *((*physicalConfigDedicated)->cqi_ReportConfig->cqi_ReportModeAperiodic)=LTE_CQI_ReportConfig__cqi_ReportModeAperiodic_rm31; // HLC CQI, no PMI
3718 3719
#endif
      }
Cedric Roux's avatar
Cedric Roux committed
3720
    } else {
3721 3722
      LOG_E(RRC,"cqi_ReportConfig not present in physical_config_dedicated. Not reconfiguring!\n");
    }
Cedric Roux's avatar
Cedric Roux committed
3723
  } else {
3724
    LOG_E(RRC,"physical_config_dedicated not present in LTE_RRCConnectionReconfiguration. Not reconfiguring!\n");
3725
  }
3726

3727 3728 3729 3730 3731 3732 3733 3734
  // 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);
3735 3736 3737
  /*
   * Add one EUTRA Measurement Object
  */
3738 3739
  MeasObj_list = CALLOC(1, sizeof(*MeasObj_list));
  memset((void *)MeasObj_list, 0, sizeof(*MeasObj_list));
Cedric Roux's avatar
Cedric Roux committed
3740
  // Configure MeasObject
3741 3742 3743
  MeasObj = CALLOC(1, sizeof(*MeasObj));
  memset((void *)MeasObj, 0, sizeof(*MeasObj));
  MeasObj->measObjectId = 1;
3744
  MeasObj->measObject.present = LTE_MeasObjectToAddMod__measObject_PR_measObjectEUTRA;
3745 3746
  MeasObj->measObject.choice.measObjectEUTRA.carrierFreq = 3350; //band 7, 2.68GHz
  //MeasObj->measObject.choice.measObjectEUTRA.carrierFreq = 36090; //band 33, 1.909GHz
3747
  MeasObj->measObject.choice.measObjectEUTRA.allowedMeasBandwidth = LTE_AllowedMeasBandwidth_mbw25;
3748 3749 3750 3751 3752 3753 3754
  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 =
3755
    (LTE_CellsToAddModList_t *) CALLOC(1, sizeof(*CellsToAddModList));
3756 3757 3758 3759
  CellsToAddModList = MeasObj->measObject.choice.measObjectEUTRA.cellsToAddModList;

  // Add adjacent cell lists (6 per eNB)
  for (i = 0; i < 6; i++) {
3760
    CellToAdd = (LTE_CellsToAddMod_t *) CALLOC(1, sizeof(*CellToAdd));
3761
    CellToAdd->cellIndex = i + 1;
3762
    CellToAdd->physCellId = get_adjacent_cell_id(ctxt_pP->module_id, i);
3763
    CellToAdd->cellIndividualOffset = LTE_Q_OffsetRange_dB0;
3764 3765
    ASN_SEQUENCE_ADD(&CellsToAddModList->list, CellToAdd);
  }
3766

3767
  ASN_SEQUENCE_ADD(&MeasObj_list->list, MeasObj);
3768
  //  LTE_RRCConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->measObjectToAddModList = MeasObj_list;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3769

3770
  // Report Configurations for periodical, A1-A5 events
3771

3772
  /* RRC Strategy Measurement */
3773

Cedric Roux's avatar
Cedric Roux committed
3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784
  if (strcmp("one_shot", trig_param->trigger_policy) == 0) {
    trig_param->report_interval = 0;
    trig_param->report_amount = 0;
  } else if (strcmp("event_driven", trig_param->trigger_policy) == 0) {
    trig_param->report_interval = 6;
    trig_param->report_amount = 2;
  } else if (strcmp("periodical", trig_param->trigger_policy) == 0) {
    trig_param->report_interval = 1;
    trig_param->report_amount = 7;
  } else {
    LOG_E(FLEXRAN_AGENT, "There is something wrong on RRC agent!");
3785
  }
3786

3787 3788
  ReportConfig_list = CALLOC(1, sizeof(*ReportConfig_list));
  ReportConfig_per = CALLOC(1, sizeof(*ReportConfig_per));
Cedric Roux's avatar
Cedric Roux committed
3789
  // Periodical Measurement Report
3790
  ReportConfig_per->reportConfigId = 1;
3791
  ReportConfig_per->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
Cedric Roux's avatar
Cedric Roux committed
3792
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerType.present =
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
3793
    LTE_ReportConfigEUTRA__triggerType_PR_periodical;
Cedric Roux's avatar
Cedric Roux committed
3794
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerType.choice.periodical.purpose =
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
3795
    LTE_ReportConfigEUTRA__triggerType__periodical__purpose_reportStrongestCells;
Cedric Roux's avatar
Cedric Roux committed
3796
  // ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.timeToTrigger = TimeToTrigger_ms40;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
3797 3798
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerQuantity = LTE_ReportConfigEUTRA__triggerQuantity_rsrp;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both;
Cedric Roux's avatar
Cedric Roux committed
3799 3800 3801
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportInterval = trig_param->report_interval ;//ReportInterval_ms2048; // RRC counter frame- ms1024 is 1ms
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportAmount = trig_param->report_amount; //ReportConfigEUTRA__reportAmount_r2; // put r1 to see once, r2 for 2 times and ...
3802
  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_per);
Cedric Roux's avatar
Cedric Roux committed
3803 3804
  quantityConfig = CALLOC(1, sizeof(*quantityConfig));
  memset((void *)quantityConfig, 0, sizeof(*quantityConfig));
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
3805
  quantityConfig->quantityConfigEUTRA = CALLOC(1, sizeof(struct LTE_QuantityConfigEUTRA));
Cedric Roux's avatar
Cedric Roux committed
3806 3807 3808 3809 3810 3811 3812 3813
  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)));
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
3814 3815
  *quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP = LTE_FilterCoefficient_fc4;
  *quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ = LTE_FilterCoefficient_fc4;
3816
  /* Initialize NAS list */
3817
  dedicatedInfoNASList = CALLOC(1, sizeof(struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList));
3818 3819

  /* Add all NAS PDUs to the list */
3820 3821
  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) {
3822
      dedicatedInfoNas = CALLOC(1, sizeof(LTE_DedicatedInfoNAS_t));
3823
      memset(dedicatedInfoNas, 0, sizeof(OCTET_STRING_t));
Cedric Roux's avatar
Cedric Roux committed
3824 3825
      OCTET_STRING_fromBuf(dedicatedInfoNas,
                           (char *)ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer,
3826
                           ue_context_pP->ue_context.e_rab[i].param.nas_pdu.length);
3827
      ASN_SEQUENCE_ADD(&dedicatedInfoNASList->list, dedicatedInfoNas);
3828
    }
3829

3830
    /* TODO parameters yet to process ... */
3831
    // {
Cedric Roux's avatar
Cedric Roux committed
3832 3833 3834
    //      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;
3835
    // }
3836
    /* TODO should test if e RAB are Ok before! */
3837
    ue_context_pP->ue_context.e_rab[i].status = E_RAB_STATUS_DONE;
Cedric Roux's avatar
Cedric Roux committed
3838 3839
    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");
3840
  }
3841 3842 3843 3844 3845

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

3848 3849
  measurements_enabled = RC.rrc[ENB_INSTANCE_TO_MODULE_ID(ctxt_pP->instance)]->configuration.enable_x2 ||
                         RC.rrc[ENB_INSTANCE_TO_MODULE_ID(ctxt_pP->instance)]->configuration.enable_measurement_reports;
Cedric Roux's avatar
Cedric Roux committed
3850

3851
  memset(buffer, 0, RRC_BUF_SIZE);
3852 3853
  size = do_RRCConnectionReconfiguration(ctxt_pP,
                                         buffer,
3854
                                         xid,   //Transaction_id,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
3855 3856 3857 3858 3859
                                         (LTE_SRB_ToAddModList_t *)NULL, // SRB_configList
                                         (LTE_DRB_ToAddModList_t *)NULL,
                                         (LTE_DRB_ToReleaseList_t *)NULL, // DRB2_list,
                                         (struct LTE_SPS_Config *)NULL,   // *sps_Config,
                                         (struct LTE_PhysicalConfigDedicated *)*physicalConfigDedicated,
Cedric Roux's avatar
Cedric Roux committed
3860 3861 3862
                                         // #ifdef EXMIMO_IOT
                                         //                                          NULL, NULL, NULL,NULL,
                                         // #else
3863 3864 3865 3866
                                         measurements_enabled ? (LTE_MeasObjectToAddModList_t *)MeasObj_list : NULL,
                                         measurements_enabled ? (LTE_ReportConfigToAddModList_t *)ReportConfig_list : NULL,
                                         measurements_enabled ? (LTE_QuantityConfig_t *)quantityConfig : NULL,
                                         measurements_enabled ? (LTE_MeasIdToAddModList_t *)MeasId_list : NULL,
Cedric Roux's avatar
Cedric Roux committed
3867
                                         // #endif
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
3868 3869 3870
                                         (LTE_MAC_MainConfig_t *)mac_MainConfig,
                                         (LTE_MeasGapConfig_t *)NULL,
                                         (LTE_MobilityControlInfo_t *)NULL,
3871
                                         (LTE_SecurityConfigHO_t *)NULL,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
3872 3873 3874 3875 3876 3877
                                         (struct LTE_MeasConfig__speedStatePars *)Sparams,
                                         (LTE_RSRP_Range_t *)rsrp,
                                         (LTE_C_RNTI_t *)cba_RNTI,
                                         (struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *)dedicatedInfoNASList,
                                         (LTE_SL_CommConfig_r12_t *)NULL,
                                         (LTE_SL_DiscConfig_r12_t *)NULL
3878
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
3879
                                         , (LTE_SCellToAddMod_r10_t *)NULL
3880
#endif
3881
                                        );
3882 3883
  LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)buffer,size,
              "[MSG] RRC Connection Reconfiguration\n");
3884 3885

  /* Free all NAS PDUs */
3886 3887
  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) {
3888
      /* Free the NAS PDU buffer and invalidate it */
3889 3890
      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;
3891
    }
3892 3893 3894
  }

  LOG_I(RRC,
3895
        "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate LTE_RRCConnectionReconfiguration (bytes %d, UE id %x)\n",
3896
        ctxt_pP->module_id, ctxt_pP->frame, size, ue_context_pP->ue_context.rnti);
3897
  LOG_D(RRC,
3898 3899
        "[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);
3900
  MSC_LOG_TX_MESSAGE(
3901 3902 3903 3904
    MSC_RRC_ENB,
    MSC_RRC_UE,
    buffer,
    size,
3905
    MSC_AS_TIME_FMT" LTE_RRCConnectionReconfiguration UE %x MUI %d size %u",
3906 3907 3908 3909
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP->ue_context.rnti,
    rrc_eNB_mui,
    size);
3910
  rrc_data_req(
Cedric Roux's avatar
Cedric Roux committed
3911 3912 3913 3914 3915 3916 3917
    ctxt_pP,
    DCCH,
    rrc_eNB_mui++,
    SDU_CONFIRM_NO,
    size,
    buffer,
    PDCP_TRANSMISSION_MODE_CONTROL);
3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929
  if (quantityConfig){
    if (quantityConfig->quantityConfigEUTRA){
      if (quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ){
        free(quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ);
      }
      if (quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP){
        free(quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP);
      }
      free(quantityConfig->quantityConfigEUTRA);
    }
    free(quantityConfig);
  }
winckel's avatar
winckel committed
3930
}
3931

3932

3933 3934 3935
//-----------------------------------------------------------------------------
int
rrc_eNB_generate_RRCConnectionReconfiguration_SCell(
Cedric Roux's avatar
Cedric Roux committed
3936 3937
  const protocol_ctxt_t *const ctxt_pP,
  rrc_eNB_ue_context_t *const ue_context_pP,
3938 3939 3940
  uint32_t dl_CarrierFreq_r10
)
//-----------------------------------------------------------------------------
3941
{
3942 3943
  uint8_t size;
  uint8_t buffer[100];
3944
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
3945
  uint8_t sCellIndexToAdd = 0; //one SCell so far
3946 3947 3948

  //   uint8_t sCellIndexToAdd;
  //   sCellIndexToAdd = rrc_find_free_SCell_index(enb_mod_idP, ue_mod_idP, 1);
3949
  //  if (RC.rrc[enb_mod_idP]->sCell_config[ue_mod_idP][sCellIndexToAdd] ) {
3950 3951
  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;
3952
  } else {
3953 3954
    LOG_E(RRC,"Scell not configured!\n");
    return(-1);
3955 3956
  }

3957
#endif
3958
  size = do_RRCConnectionReconfiguration(ctxt_pP,
3959
                                         buffer,
3960
                                         rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),//Transaction_id,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972
                                         (LTE_SRB_ToAddModList_t *)NULL,
                                         (LTE_DRB_ToAddModList_t *)NULL,
                                         (LTE_DRB_ToReleaseList_t *)NULL,
                                         (struct LTE_SPS_Config *)NULL,
                                         (struct LTE_PhysicalConfigDedicated *)NULL,
                                         (LTE_MeasObjectToAddModList_t *)NULL,
                                         (LTE_ReportConfigToAddModList_t *)NULL,
                                         (LTE_QuantityConfig_t *)NULL,
                                         (LTE_MeasIdToAddModList_t *)NULL,
                                         (LTE_MAC_MainConfig_t *)NULL,
                                         (LTE_MeasGapConfig_t *)NULL,
                                         (LTE_MobilityControlInfo_t *)NULL,
3973
                                         (LTE_SecurityConfigHO_t *)NULL,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
3974 3975 3976 3977 3978 3979
                                         (struct LTE_MeasConfig__speedStatePars *)NULL,
                                         (LTE_RSRP_Range_t *)NULL,
                                         (LTE_C_RNTI_t *)NULL,
                                         (struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *)NULL,
                                         (LTE_SL_CommConfig_r12_t *)NULL,
                                         (LTE_SL_DiscConfig_r12_t *)NULL
3980
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
3981
                                         , ue_context_pP->ue_context.sCell_config
3982
#endif
3983
                                        );
3984
  LOG_I(RRC,"[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate LTE_RRCConnectionReconfiguration (bytes %d, UE id %x)\n",
3985
        ctxt_pP->module_id,ctxt_pP->frame, size, ue_context_pP->ue_context.rnti);
3986
  MSC_LOG_TX_MESSAGE(
3987 3988 3989 3990
    MSC_RRC_ENB,
    MSC_RRC_UE,
    buffer,
    size,
3991
    MSC_AS_TIME_FMT" LTE_RRCConnectionReconfiguration UE %x MUI %d size %u",
3992 3993 3994 3995
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP->ue_context.rnti,
    rrc_eNB_mui,
    size);
3996
  rrc_data_req(
Cedric Roux's avatar
Cedric Roux committed
3997 3998 3999 4000 4001 4002 4003
    ctxt_pP,
    DCCH,
    rrc_eNB_mui++,
    SDU_CONFIRM_NO,
    size,
    buffer,
    PDCP_TRANSMISSION_MODE_CONTROL);
4004 4005 4006 4007
  return(0);
}


4008 4009 4010
//-----------------------------------------------------------------------------
void
rrc_eNB_process_MeasurementReport(
Cedric Roux's avatar
Cedric Roux committed
4011 4012
  const protocol_ctxt_t *const ctxt_pP,
  rrc_eNB_ue_context_t         *ue_context_pP,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
4013
  const LTE_MeasResults_t   *const measResults2
4014 4015
)
//-----------------------------------------------------------------------------
4016
{
4017 4018
  int i=0;
  int neighboring_cells=-1;
4019 4020
  int ncell_index = 0;
  long ncell_max = -150;
4021 4022 4023
  uint32_t earfcn_dl;
  uint8_t KeNB_star[32] = { 0 };

Cedric Roux's avatar
Cedric Roux committed
4024 4025 4026
  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));

4027 4028
  if (measResults2 == NULL )
    return;
4029

Cedric Roux's avatar
Cedric Roux committed
4030 4031
  if (measResults2->measId > 0 ) {
    if (ue_context_pP->ue_context.measResults == NULL) {
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
4032
      ue_context_pP->ue_context.measResults = CALLOC(1, sizeof(LTE_MeasResults_t));
Cedric Roux's avatar
Cedric Roux committed
4033
    }
4034

Cedric Roux's avatar
Cedric Roux committed
4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077
    ue_context_pP->ue_context.measResults->measId=measResults2->measId;

    switch (measResults2->measId) {
      case 1:
        LOG_D(RRC,"Periodic report at frame %d and subframe %d \n", ctxt_pP->frame, ctxt_pP->subframe);
        break;

      case 2:
        LOG_D(RRC,"A1 event report (Serving becomes better than absolute threshold) at frame %d and subframe %d \n", ctxt_pP->frame, ctxt_pP->subframe);
        break;

      case 3:
        LOG_D(RRC,"A2 event report (Serving becomes worse than absolute threshold) at frame %d and subframe %d \n", ctxt_pP->frame, ctxt_pP->subframe);
        break;

      case 4:
        LOG_D(RRC,"A3 event report (Neighbour becomes amount of offset better than PCell) at frame %d and subframe %d \n", ctxt_pP->frame, ctxt_pP->subframe);
        break;

      case 5:
        LOG_D(RRC,"A4 event report (Neighbour becomes better than absolute threshold) at frame %d and subframe %d \n", ctxt_pP->frame, ctxt_pP->subframe);
        break;

      case 6:
        LOG_D(RRC,"A5 event report (PCell becomes worse than absolute threshold1 AND Neighbour becomes better than another absolute threshold2) at frame %d and subframe %d \n", ctxt_pP->frame,
              ctxt_pP->subframe);
        break;

      default:
        LOG_D(RRC,"Other event report frame %d and subframe %d \n", ctxt_pP->frame, ctxt_pP->subframe);
        break;
    }

    ue_context_pP->ue_context.measResults->measResultPCell.rsrpResult=measResults2->measResultPCell.rsrpResult;
    ue_context_pP->ue_context.measResults->measResultPCell.rsrqResult=measResults2->measResultPCell.rsrqResult;
    LOG_D(RRC, "[eNB %d]Frame %d: UE %x (Measurement Id %d): RSRP of Source %ld\n", ctxt_pP->module_id, ctxt_pP->frame, ctxt_pP->rnti, (int)measResults2->measId,
          ue_context_pP->ue_context.measResults->measResultPCell.rsrpResult-140);
    LOG_D(RRC, "[eNB %d]Frame %d: UE %x (Measurement Id %d): RSRQ of Source %ld\n", ctxt_pP->module_id, ctxt_pP->frame, ctxt_pP->rnti, (int)measResults2->measId,
          ue_context_pP->ue_context.measResults->measResultPCell.rsrqResult/2 - 20);
  }

  if (measResults2->measResultNeighCells == NULL)
    return;
4078

Cedric Roux's avatar
Cedric Roux committed
4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119
  if (measResults2->measResultNeighCells->choice.measResultListEUTRA.list.count > 0) {
    neighboring_cells = measResults2->measResultNeighCells->choice.measResultListEUTRA.list.count;

    if (ue_context_pP->ue_context.measResults->measResultNeighCells == NULL) {
      ue_context_pP->ue_context.measResults->measResultNeighCells = CALLOC(1, sizeof(*ue_context_pP->ue_context.measResults->measResultNeighCells));
    }

    for (i=0; i < neighboring_cells; i++) {
      if (i>=ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.count) {
        //printf("NeighCells number: %d \n", ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.count);
        ASN_SEQUENCE_ADD(&ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list,measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[i]);
      }

      ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->physCellId =
        measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->physCellId;
      ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->measResult.rsrpResult =
        measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->measResult.rsrpResult;
      ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->measResult.rsrqResult =
        measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->measResult.rsrqResult;
      LOG_D(RRC, "Physical Cell Id %d\n",
            (int)ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->physCellId);
      LOG_D(RRC, "RSRP of Target %ld\n",
            (*ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->measResult.rsrpResult)-140);
      LOG_D(RRC, "RSRQ of Target %ld\n",
            (*ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->measResult.rsrqResult)/2 - 20);

      if ( *measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->measResult.rsrpResult >= ncell_max ) {
        ncell_max = *measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->measResult.rsrpResult;
        ncell_index = i;
      }

      //LOG_D(RRC, "Physical Cell Id2 %d\n",
      //(int)measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->physCellId);
      //LOG_D(RRC, "RSRP of Target2 %ld\n",
      //(*(measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->
      //measResult.rsrpResult))-140);
      //LOG_D(RRC, "RSRQ of Target2 %ld\n",
      //(*(measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->
      //measResult.rsrqResult))/2 - 20);
    }
  }
4120

4121 4122 4123
  /* Decide whether to trigger HO or not */
  if (!(measResults2->measId == 4))
    return;
Cedric Roux's avatar
Cedric Roux committed
4124

Cedric Roux's avatar
Cedric Roux committed
4125
  /* if X2AP is disabled, do nothing */
4126
  if (!RC.rrc[ENB_INSTANCE_TO_MODULE_ID(ctxt_pP->instance)]->configuration.enable_x2)
Cedric Roux's avatar
Cedric Roux committed
4127 4128
    return;

4129
  LOG_D(RRC, "A3 event is triggered...\n");
4130

4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141
  /* if the UE is not in handover mode, start handover procedure */
  if (ue_context_pP->ue_context.Status != RRC_HO_EXECUTION) {
    MessageDef      *msg;
    LOG_I(RRC, "Send HO preparation message at frame %d and subframe %d \n", ctxt_pP->frame, ctxt_pP->subframe);
    /* HO info struct may not be needed anymore */
    ue_context_pP->ue_context.handover_info = CALLOC(1, sizeof(*(ue_context_pP->ue_context.handover_info)));
    ue_context_pP->ue_context.Status = RRC_HO_EXECUTION;
    ue_context_pP->ue_context.handover_info->state = HO_REQUEST;
    /* HO Preparation message */
    msg = itti_alloc_new_message(TASK_RRC_ENB, X2AP_HANDOVER_REQ);
    rrc_eNB_generate_HandoverPreparationInformation(
Cedric Roux's avatar
Cedric Roux committed
4142 4143 4144
      ue_context_pP,
      X2AP_HANDOVER_REQ(msg).rrc_buffer,
      &X2AP_HANDOVER_REQ(msg).rrc_buffer_size);
4145
    X2AP_HANDOVER_REQ(msg).rnti = ctxt_pP->rnti;
4146
    X2AP_HANDOVER_REQ(msg).target_physCellId = measResults2->measResultNeighCells->choice.
Cedric Roux's avatar
Cedric Roux committed
4147
        measResultListEUTRA.list.array[ncell_index]->physCellId;
4148 4149 4150 4151 4152 4153 4154 4155
    X2AP_HANDOVER_REQ(msg).ue_gummei.mcc = ue_context_pP->ue_context.ue_gummei.mcc;
    X2AP_HANDOVER_REQ(msg).ue_gummei.mnc = ue_context_pP->ue_context.ue_gummei.mnc;
    X2AP_HANDOVER_REQ(msg).ue_gummei.mnc_len = ue_context_pP->ue_context.ue_gummei.mnc_len;
    X2AP_HANDOVER_REQ(msg).ue_gummei.mme_code = ue_context_pP->ue_context.ue_gummei.mme_code;
    X2AP_HANDOVER_REQ(msg).ue_gummei.mme_group_id = ue_context_pP->ue_context.ue_gummei.mme_group_id;
    // Don't know how to get this ID?
    X2AP_HANDOVER_REQ(msg).mme_ue_s1ap_id = ue_context_pP->ue_context.mme_ue_s1ap_id;
    X2AP_HANDOVER_REQ(msg).security_capabilities = ue_context_pP->ue_context.security_capabilities;
4156 4157 4158 4159 4160
    // compute keNB*
    earfcn_dl = (uint32_t)to_earfcn_DL(RC.rrc[ctxt_pP->module_id]->carrier[0].eutra_band, RC.rrc[ctxt_pP->module_id]->carrier[0].dl_CarrierFreq,
    RC.rrc[ctxt_pP->module_id]->carrier[0].N_RB_DL);
    derive_keNB_star(ue_context_pP->ue_context.kenb, X2AP_HANDOVER_REQ(msg).target_physCellId, earfcn_dl, true, KeNB_star);
    memcpy(X2AP_HANDOVER_REQ(msg).kenb, KeNB_star, 32);
4161 4162 4163 4164
    X2AP_HANDOVER_REQ(msg).kenb_ncc = ue_context_pP->ue_context.kenb_ncc;
    //X2AP_HANDOVER_REQ(msg).ue_ambr=ue_context_pP->ue_context.ue_ambr;
    X2AP_HANDOVER_REQ(msg).nb_e_rabs_tobesetup = ue_context_pP->ue_context.setup_e_rabs;

Cedric Roux's avatar
Cedric Roux committed
4165 4166 4167 4168 4169 4170 4171 4172
    for (int i=0; i<ue_context_pP->ue_context.setup_e_rabs; i++) {
      X2AP_HANDOVER_REQ(msg).e_rabs_tobesetup[i].e_rab_id = ue_context_pP->ue_context.e_rab[i].param.e_rab_id;
      X2AP_HANDOVER_REQ(msg).e_rabs_tobesetup[i].eNB_addr = ue_context_pP->ue_context.e_rab[i].param.sgw_addr;
      X2AP_HANDOVER_REQ(msg).e_rabs_tobesetup[i].gtp_teid = ue_context_pP->ue_context.e_rab[i].param.gtp_teid;
      X2AP_HANDOVER_REQ(msg).e_rab_param[i].qos.qci = ue_context_pP->ue_context.e_rab[i].param.qos.qci;
      X2AP_HANDOVER_REQ(msg).e_rab_param[i].qos.allocation_retention_priority.priority_level = ue_context_pP->ue_context.e_rab[i].param.qos.allocation_retention_priority.priority_level;
      X2AP_HANDOVER_REQ(msg).e_rab_param[i].qos.allocation_retention_priority.pre_emp_capability = ue_context_pP->ue_context.e_rab[i].param.qos.allocation_retention_priority.pre_emp_capability;
      X2AP_HANDOVER_REQ(msg).e_rab_param[i].qos.allocation_retention_priority.pre_emp_vulnerability = ue_context_pP->ue_context.e_rab[i].param.qos.allocation_retention_priority.pre_emp_vulnerability;
4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184
    }

    /* TODO: don't do that, X2AP should find the target by itself */
    //X2AP_HANDOVER_REQ(msg).target_mod_id = 0;
    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);
    itti_send_msg_to_task(TASK_X2AP, ENB_MODULE_ID_TO_INSTANCE(ctxt_pP->module_id), msg);
  } else {
    LOG_D(RRC, "[eNB %d] Frame %d: Ignoring MeasReport from UE %x as Handover is in progress... \n", ctxt_pP->module_id, ctxt_pP->frame,
          ctxt_pP->rnti);
  }
4185 4186
}

4187 4188 4189
//-----------------------------------------------------------------------------
void
rrc_eNB_generate_HandoverPreparationInformation(
4190
  //const protocol_ctxt_t* const ctxt_pP,
Cedric Roux's avatar
Cedric Roux committed
4191 4192
  rrc_eNB_ue_context_t *const ue_context_pP,
  uint8_t                     *buffer,
4193
  int                          *_size
Cedric Roux's avatar
Cedric Roux committed
4194
) {
4195
  memset(buffer, 0, RRC_BUF_SIZE);
Cedric Roux's avatar
Cedric Roux committed
4196
  char *ho_buf = (char *) buffer;
4197 4198 4199
  int ho_size;
  ho_size = do_HandoverPreparation(ho_buf, 1024, ue_context_pP->ue_context.UE_Capability, ue_context_pP->ue_context.UE_Capability_size);
  *_size = ho_size;
4200 4201
}

Cedric Roux's avatar
Cedric Roux committed
4202 4203
void rrc_eNB_process_handoverPreparationInformation(int mod_id, x2ap_handover_req_t *m) {
  struct rrc_eNB_ue_context_s        *ue_context_target_p = NULL;
4204 4205 4206 4207
  /* TODO: get proper UE rnti */
  int rnti = taus() & 0xffff;
  int i;
  //global_rnti = rnti;
4208 4209 4210
  LTE_HandoverPreparationInformation_t *ho = NULL;
  LTE_HandoverPreparationInformation_r8_IEs_t *ho_info;
  asn_dec_rval_t                      dec_rval;
4211
  ue_context_target_p = rrc_eNB_get_ue_context(RC.rrc[mod_id], rnti);
Cedric Roux's avatar
Cedric Roux committed
4212

4213 4214 4215 4216 4217 4218
  if (ue_context_target_p != NULL) {
    LOG_E(RRC, "\nError in obtaining free UE id in target eNB for handover \n");
    return;
  }

  ue_context_target_p = rrc_eNB_allocate_new_UE_context(RC.rrc[mod_id]);
Cedric Roux's avatar
Cedric Roux committed
4219

4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231
  if (ue_context_target_p == NULL) {
    LOG_E(RRC, "Cannot create new UE context\n");
    return;
  }

  ue_context_target_p->ue_id_rnti = rnti;
  ue_context_target_p->ue_context.rnti = rnti;
  RB_INSERT(rrc_ue_tree_s, &RC.rrc[mod_id]->rrc_ue_head, ue_context_target_p);
  LOG_D(RRC, "eNB %d: Created new UE context uid %u\n", mod_id, ue_context_target_p->local_uid);
  ue_context_target_p->ue_context.handover_info = CALLOC(1, sizeof(*(ue_context_target_p->ue_context.handover_info)));
  ue_context_target_p->ue_context.Status = RRC_HO_EXECUTION;
  ue_context_target_p->ue_context.handover_info->state = HO_ACK;
4232 4233
  ue_context_target_p->ue_context.handover_info->x2_id = m->x2_id;
  ue_context_target_p->ue_context.handover_info->assoc_id = m->target_assoc_id;
4234 4235 4236 4237 4238 4239
  memset (ue_context_target_p->ue_context.nh, 0, 32);
  ue_context_target_p->ue_context.nh_ncc = -1;
  memcpy (ue_context_target_p->ue_context.kenb, m->kenb, 32);
  ue_context_target_p->ue_context.kenb_ncc = m->kenb_ncc;
  ue_context_target_p->ue_context.security_capabilities.encryption_algorithms = m->security_capabilities.encryption_algorithms;
  ue_context_target_p->ue_context.security_capabilities.integrity_algorithms = m->security_capabilities.integrity_algorithms;
4240

4241
  dec_rval = uper_decode(NULL,
4242
                         &asn_DEF_LTE_HandoverPreparationInformation,
4243 4244 4245 4246
                         (void **)&ho,
                         m->rrc_buffer,
                         m->rrc_buffer_size, 0, 0);

4247 4248 4249 4250
 if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
     xer_fprint(stdout, &asn_DEF_LTE_HandoverPreparationInformation, ho);
 }

4251
  if (dec_rval.code != RC_OK ||
4252 4253
      ho->criticalExtensions.present != LTE_HandoverPreparationInformation__criticalExtensions_PR_c1 ||
      ho->criticalExtensions.choice.c1.present != LTE_HandoverPreparationInformation__criticalExtensions__c1_PR_handoverPreparationInformation_r8) {
4254 4255 4256 4257 4258 4259 4260 4261
    LOG_E(RRC, "could not decode Handover Preparation\n");
    abort();
  }

  ho_info = &ho->criticalExtensions.choice.c1.choice.handoverPreparationInformation_r8;

  if (ue_context_target_p->ue_context.UE_Capability) {
    LOG_I(RRC, "freeing old UE capabilities for UE %x\n", rnti);
4262
    ASN_STRUCT_FREE(asn_DEF_LTE_UE_EUTRA_Capability,
4263 4264 4265 4266 4267
                    ue_context_target_p->ue_context.UE_Capability);
    ue_context_target_p->ue_context.UE_Capability = 0;
  }

  dec_rval = uper_decode(NULL,
4268
                         &asn_DEF_LTE_UE_EUTRA_Capability,
4269 4270 4271 4272 4273 4274 4275
                         (void **)&ue_context_target_p->ue_context.UE_Capability,
                         ho_info->ue_RadioAccessCapabilityInfo.list.array[0]->ueCapabilityRAT_Container.buf,
                         ho_info->ue_RadioAccessCapabilityInfo.list.array[0]->ueCapabilityRAT_Container.size, 0, 0);

  ue_context_target_p->ue_context.UE_Capability_size = ho_info->ue_RadioAccessCapabilityInfo.list.array[0]->ueCapabilityRAT_Container.size;

  if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
4276
     xer_fprint(stdout, &asn_DEF_LTE_UE_EUTRA_Capability, ue_context_target_p->ue_context.UE_Capability);
4277 4278 4279 4280
  }

  if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0)) {
      LOG_E(RRC, "Failed to decode UE capabilities (%zu bytes)\n", dec_rval.consumed);
4281
      ASN_STRUCT_FREE(asn_DEF_LTE_UE_EUTRA_Capability,
4282 4283 4284
                      ue_context_target_p->ue_context.UE_Capability);
      ue_context_target_p->ue_context.UE_Capability = 0;
  }
4285

4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296
  ue_context_target_p->ue_context.nb_of_e_rabs = m->nb_e_rabs_tobesetup;
  ue_context_target_p->ue_context.setup_e_rabs = m->nb_e_rabs_tobesetup;
  ue_context_target_p->ue_context.mme_ue_s1ap_id = m->mme_ue_s1ap_id;
  ue_context_target_p->ue_context.ue_gummei.mcc = m->ue_gummei.mcc;
  ue_context_target_p->ue_context.ue_gummei.mnc = m->ue_gummei.mnc;
  ue_context_target_p->ue_context.ue_gummei.mnc_len = m->ue_gummei.mnc_len;
  ue_context_target_p->ue_context.ue_gummei.mme_code = m->ue_gummei.mme_code;
  ue_context_target_p->ue_context.ue_gummei.mme_group_id = m->ue_gummei.mme_group_id;
  LOG_I(RRC, "eNB %d: Update the E-RABS %u\n", mod_id, ue_context_target_p->ue_context.nb_of_e_rabs);

  for (i = 0; i < ue_context_target_p->ue_context.nb_of_e_rabs; i++) {
Cedric Roux's avatar
Cedric Roux committed
4297 4298 4299 4300 4301 4302 4303
    ue_context_target_p->ue_context.e_rab[i].status = E_RAB_STATUS_NEW;
    ue_context_target_p->ue_context.e_rab[i].param.e_rab_id = m->e_rabs_tobesetup[i].e_rab_id;
    ue_context_target_p->ue_context.e_rab[i].param.sgw_addr = m->e_rabs_tobesetup[i].eNB_addr;
    ue_context_target_p->ue_context.e_rab[i].param.gtp_teid= m->e_rabs_tobesetup[i].gtp_teid;
    LOG_I(RRC, "eNB %d: Update the UE context after HO, e_rab_id %u gtp_teid %u\n", mod_id,
          ue_context_target_p->ue_context.e_rab[i].param.e_rab_id,
          ue_context_target_p->ue_context.e_rab[i].param.gtp_teid);
4304 4305 4306 4307
  }
}

void rrc_eNB_process_handoverCommand(
Cedric Roux's avatar
Cedric Roux committed
4308 4309 4310
  int                         mod_id,
  struct rrc_eNB_ue_context_s *ue_context,
  x2ap_handover_req_ack_t     *m) {
4311
  asn_dec_rval_t dec_rval;
4312
  LTE_HandoverCommand_t *ho = NULL;
4313 4314
  dec_rval = uper_decode(
               NULL,
4315
               &asn_DEF_LTE_HandoverCommand,
Cedric Roux's avatar
Cedric Roux committed
4316
               (void **)&ho,
4317 4318 4319 4320 4321 4322
               m->rrc_buffer,
               m->rrc_buffer_size,
               0,
               0);

  if (dec_rval.code != RC_OK ||
4323 4324
      ho->criticalExtensions.present != LTE_HandoverCommand__criticalExtensions_PR_c1 ||
      ho->criticalExtensions.choice.c1.present != LTE_HandoverCommand__criticalExtensions__c1_PR_handoverCommand_r8) {
4325 4326 4327 4328 4329 4330 4331
    LOG_E(RRC, "could not decode Handover Command\n");
    abort();
  }

  unsigned char *buf = ho->criticalExtensions.choice.c1.choice.handoverCommand_r8.handoverCommandMessage.buf;
  int size = ho->criticalExtensions.choice.c1.choice.handoverCommand_r8.handoverCommandMessage.size;

Cedric Roux's avatar
Cedric Roux committed
4332 4333 4334 4335
  if (size > RRC_BUF_SIZE) {
    printf("%s:%d: fatal\n", __FILE__, __LINE__);
    abort();
  }
4336 4337 4338 4339

  memcpy(ue_context->ue_context.handover_info->buf, buf, size);
  ue_context->ue_context.handover_info->size = size;
}
4340

4341
void rrc_eNB_handover_ue_context_release(
Cedric Roux's avatar
Cedric Roux committed
4342 4343
        protocol_ctxt_t *const ctxt_pP,
        struct rrc_eNB_ue_context_s *ue_context_p) {
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
  int e_rab = 0;
  //MessageDef *msg_release_p = NULL;
  MessageDef *msg_delete_tunnels_p = NULL;
  uint32_t eNB_ue_s1ap_id = ue_context_p->ue_context.eNB_ue_s1ap_id;

  //msg_release_p = itti_alloc_new_message(TASK_RRC_ENB, S1AP_UE_CONTEXT_RELEASE);
  //itti_send_msg_to_task(TASK_S1AP, ctxt_pP->module_id, msg_release_p);
  s1ap_ue_context_release(ctxt_pP->instance, ue_context_p->ue_context.eNB_ue_s1ap_id);

  //MSC_LOG_TX_MESSAGE(MSC_RRC_ENB, MSC_GTPU_ENB, NULL,0, "0 GTPV1U_ENB_DELETE_TUNNEL_REQ rnti %x ", eNB_ue_s1ap_id);
  msg_delete_tunnels_p = itti_alloc_new_message(TASK_RRC_ENB, GTPV1U_ENB_DELETE_TUNNEL_REQ);
  memset(&GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p), 0, sizeof(GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p)));

  GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p).rnti = ue_context_p->ue_context.rnti;

  for (e_rab = 0; e_rab < ue_context_p->ue_context.nb_of_e_rabs; e_rab++) {
    GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p).eps_bearer_id[GTPV1U_ENB_DELETE_TUNNEL_REQ(msg_delete_tunnels_p).num_erab++] =
      ue_context_p->ue_context.enb_gtp_ebi[e_rab];
    // erase data
    ue_context_p->ue_context.enb_gtp_teid[e_rab] = 0;
    memset(&ue_context_p->ue_context.enb_gtp_addrs[e_rab], 0, sizeof(ue_context_p->ue_context.enb_gtp_addrs[e_rab]));
    ue_context_p->ue_context.enb_gtp_ebi[e_rab] = 0;
  }

  itti_send_msg_to_task(TASK_GTPV1_U, ctxt_pP->module_id, msg_delete_tunnels_p);
  struct rrc_ue_s1ap_ids_s *rrc_ue_s1ap_ids = NULL;
  rrc_ue_s1ap_ids = rrc_eNB_S1AP_get_ue_ids(RC.rrc[ctxt_pP->module_id], 0, eNB_ue_s1ap_id);

  if (rrc_ue_s1ap_ids != NULL) {
    rrc_eNB_S1AP_remove_ue_ids(RC.rrc[ctxt_pP->module_id], rrc_ue_s1ap_ids);
  }
winckel's avatar
winckel committed
4375
}
Cedric Roux's avatar
Cedric Roux committed
4376 4377 4378 4379 4380 4381 4382 4383 4384 4385

/* This function may be incorrect. */
void rrc_eNB_handover_cancel(
        protocol_ctxt_t              *const ctxt_pP,
        struct rrc_eNB_ue_context_s  *ue_context_p) {
  int s1_cause = 1;                        /* 1 = tx2relocoverall-expiry */

  rrc_eNB_send_S1AP_UE_CONTEXT_RELEASE_REQ(ctxt_pP->module_id, ue_context_p,
      S1AP_CAUSE_RADIO_NETWORK, s1_cause);
}
4386 4387 4388

void
check_handovers(
Cedric Roux's avatar
Cedric Roux committed
4389
  protocol_ctxt_t *const ctxt_pP
4390 4391 4392
)
//-----------------------------------------------------------------------------
{
Cedric Roux's avatar
Cedric Roux committed
4393
  struct rrc_eNB_ue_context_s        *ue_context_p;
4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406
  RB_FOREACH(ue_context_p, rrc_ue_tree_s, &(RC.rrc[ctxt_pP->module_id]->rrc_ue_head)) {
    ctxt_pP->rnti  = ue_context_p->ue_id_rnti;

    if (ue_context_p->ue_context.Status == RRC_HO_EXECUTION && ue_context_p->ue_context.handover_info != NULL) {
      /* in the source, UE in HO_PREPARE mode */
      if (ue_context_p->ue_context.handover_info->state == HO_PREPARE) {
        LOG_D(RRC,
              "[eNB %d] Frame %d: Incoming handover detected for new UE_id %x) \n",
              ctxt_pP->module_id,
              ctxt_pP->frame,
              ctxt_pP->rnti);
        // source eNB generates rrcconnectionreconfiguration to prepare the HO
        LOG_I(RRC,
Cedric Roux's avatar
Cedric Roux committed
4407 4408
              "[eNB %d] Frame %d : Logical Channel UL-DCCH, processing RRCHandoverPreparationInformation, sending RRCConnectionReconfiguration to UE %d \n",
              ctxt_pP->module_id, ctxt_pP->frame, ue_context_p->ue_context.rnti);
4409 4410
        rrc_data_req(
          ctxt_pP,
4411 4412 4413 4414 4415
                               DCCH,
                               rrc_eNB_mui++,
                               SDU_CONFIRM_NO,
                               ue_context_p->ue_context.handover_info->size,
                               ue_context_p->ue_context.handover_info->buf,
4416 4417
          PDCP_TRANSMISSION_MODE_CONTROL);

4418
        ue_context_p->ue_context.handover_info->state = HO_COMPLETE;
Cedric Roux's avatar
Cedric Roux committed
4419
        LOG_I(RRC, "RRC Sends RRCConnectionReconfiguration to UE %d  at frame %d and subframe %d \n", ue_context_p->ue_context.rnti, ctxt_pP->frame,ctxt_pP->subframe);
4420
      }
4421

4422 4423 4424 4425 4426 4427 4428
      /* in the target, UE in HO_ACK mode */
      if (ue_context_p->ue_context.handover_info->state == HO_ACK) {
        MessageDef *msg;
        // Configure target
        ue_context_p->ue_context.handover_info->state = HO_CONFIGURED;
        msg = itti_alloc_new_message(TASK_RRC_ENB, X2AP_HANDOVER_REQ_ACK);
        rrc_eNB_generate_HO_RRCConnectionReconfiguration(ctxt_pP, ue_context_p, X2AP_HANDOVER_REQ_ACK(msg).rrc_buffer,
Cedric Roux's avatar
Cedric Roux committed
4429
            &X2AP_HANDOVER_REQ_ACK(msg).rrc_buffer_size);
4430
        rrc_eNB_configure_rbs_handover(ue_context_p,ctxt_pP);
4431

4432 4433 4434
        X2AP_HANDOVER_REQ_ACK(msg).rnti = ue_context_p->ue_context.rnti;
        X2AP_HANDOVER_REQ_ACK(msg).x2_id_target = ue_context_p->ue_context.handover_info->x2_id;
        X2AP_HANDOVER_REQ_ACK(msg).source_assoc_id = ue_context_p->ue_context.handover_info->assoc_id;
4435 4436 4437
        /* Call admission control not implemented yet */
        X2AP_HANDOVER_REQ_ACK(msg).nb_e_rabs_tobesetup = ue_context_p->ue_context.setup_e_rabs;

Cedric Roux's avatar
Cedric Roux committed
4438
        for (int i=0; i<ue_context_p->ue_context.setup_e_rabs; i++) {
4439 4440
          X2AP_HANDOVER_REQ_ACK(msg).e_rabs_tobesetup[i].e_rab_id = ue_context_p->ue_context.e_rab[i].param.e_rab_id;
        }
4441

4442
        itti_send_msg_to_task(TASK_X2AP, ENB_MODULE_ID_TO_INSTANCE(ctxt_pP->module_id), msg);
Cedric Roux's avatar
Cedric Roux committed
4443
        LOG_I(RRC, "RRC Sends X2 HO ACK to the source eNB at frame %d and subframe %d \n", ctxt_pP->frame,ctxt_pP->subframe);
4444 4445 4446 4447
      }
    }
  }
}
4448 4449

void
Cedric Roux's avatar
Cedric Roux committed
4450 4451 4452 4453 4454 4455
rrc_eNB_generate_HO_RRCConnectionReconfiguration(const protocol_ctxt_t *const ctxt_pP,
    rrc_eNB_ue_context_t  *const ue_context_pP,
    uint8_t               *buffer,
    int                    *_size
    //const uint8_t        ho_state
                                                )
4456
//-----------------------------------------------------------------------------
4457
{
4458
  uint16_t                            size;
4459 4460 4461
  int                                 i;
  uint8_t                             rv[2];
  // configure SRB1/SRB2, PhysicalConfigDedicated, MAC_MainConfig for UE
Cedric Roux's avatar
Cedric Roux committed
4462
  eNB_RRC_INST                       *rrc_inst = RC.rrc[ctxt_pP->module_id];
4463
  struct LTE_PhysicalConfigDedicated **physicalConfigDedicated = &ue_context_pP->ue_context.physicalConfigDedicated;
4464
  // phy config dedicated
4465
  LTE_PhysicalConfigDedicated_t      *physicalConfigDedicated2;
4466
  // srb 1: for HO
4467 4468 4469 4470
  struct LTE_SRB_ToAddMod            *SRB1_config                      = NULL;
  struct LTE_SRB_ToAddMod__rlc_Config *SRB1_rlc_config                 = NULL;
  struct LTE_SRB_ToAddMod__logicalChannelConfig *SRB1_lchan_config     = NULL;
  struct LTE_LogicalChannelConfig__ul_SpecificParameters
Cedric Roux's avatar
Cedric Roux committed
4471
    *SRB1_ul_SpecificParameters       = NULL;
4472 4473 4474 4475
  struct LTE_SRB_ToAddMod            *SRB2_config                      = NULL;
  struct LTE_SRB_ToAddMod__rlc_Config *SRB2_rlc_config                 = NULL;
  struct LTE_SRB_ToAddMod__logicalChannelConfig *SRB2_lchan_config     = NULL;
  struct LTE_LogicalChannelConfig__ul_SpecificParameters
Cedric Roux's avatar
Cedric Roux committed
4476
    *SRB2_ul_SpecificParameters       = NULL;
4477 4478 4479 4480 4481 4482 4483 4484 4485
  LTE_SRB_ToAddModList_t             *SRB_configList = ue_context_pP->ue_context.SRB_configList;
  LTE_SRB_ToAddModList_t             **SRB_configList2                 = NULL;
  struct LTE_DRB_ToAddMod            *DRB_config                       = NULL;
  struct LTE_RLC_Config              *DRB_rlc_config                   = NULL;
  struct LTE_PDCP_Config             *DRB_pdcp_config                  = NULL;
  struct LTE_PDCP_Config__rlc_AM     *PDCP_rlc_AM                      = NULL;
  struct LTE_PDCP_Config__rlc_UM     *PDCP_rlc_UM                      = NULL;
  struct LTE_LogicalChannelConfig    *DRB_lchan_config                 = NULL;
  struct LTE_LogicalChannelConfig__ul_SpecificParameters
Cedric Roux's avatar
Cedric Roux committed
4486
    *DRB_ul_SpecificParameters        = NULL;
4487 4488 4489 4490 4491 4492 4493
  LTE_DRB_ToAddModList_t            **DRB_configList = &ue_context_pP->ue_context.DRB_configList;
  LTE_DRB_ToAddModList_t            **DRB_configList2 = NULL;
  LTE_MAC_MainConfig_t               *mac_MainConfig                   = NULL;
  LTE_MeasObjectToAddModList_t       *MeasObj_list                     = NULL;
  LTE_MeasObjectToAddMod_t           *MeasObj                          = NULL;
  LTE_ReportConfigToAddModList_t     *ReportConfig_list                = NULL;
  LTE_ReportConfigToAddMod_t         *ReportConfig_per, *ReportConfig_A1,
4494
                                     *ReportConfig_A2, *ReportConfig_A3, *ReportConfig_A4, *ReportConfig_A5;
4495 4496 4497
  LTE_MeasIdToAddModList_t           *MeasId_list                      = NULL;
  LTE_MeasIdToAddMod_t               *MeasId0, *MeasId1, *MeasId2, *MeasId3, *MeasId4, *MeasId5;
#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
4498 4499 4500
  long                               *sr_ProhibitTimer_r9              = NULL;
  //     uint8_t sCellIndexToAdd = rrc_find_free_SCell_index(enb_mod_idP, ue_mod_idP, 1);
  //uint8_t                            sCellIndexToAdd = 0;
4501 4502 4503
#endif
  long                               *logicalchannelgroup, *logicalchannelgroup_drb;
  long                               *maxHARQ_Tx, *periodicBSR_Timer;
4504 4505 4506 4507 4508
  LTE_RSRP_Range_t                   *rsrp                             = NULL;
  struct LTE_MeasConfig__speedStatePars *Sparams                       = NULL;
  LTE_QuantityConfig_t               *quantityConfig                   = NULL;
  LTE_MobilityControlInfo_t          *mobilityInfo                     = NULL;
  LTE_SecurityConfigHO_t             *securityConfigHO                 = NULL;
4509 4510
  //CellsToAddMod_t                    *CellToAdd                        = NULL;
  //CellsToAddModList_t                *CellsToAddModList                = NULL;
4511 4512
  struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList = NULL;
  LTE_DedicatedInfoNAS_t             *dedicatedInfoNas                 = NULL;
4513 4514
  /* for no gcc warnings */
  (void)dedicatedInfoNas;
4515
  LTE_C_RNTI_t                       *cba_RNTI                         = NULL;
4516
  int                                measurements_enabled;
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
  uint8_t xid = rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id);   //Transaction_id,
#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
  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));
  rv[0] = (ue_context_pP->ue_context.rnti >> 8) & 255;
  rv[1] = ue_context_pP->ue_context.rnti & 255;
  LOG_I(RRC, "target UE rnti = %x (decimal: %d)\n", ue_context_pP->ue_context.rnti, ue_context_pP->ue_context.rnti);
  LOG_D(RRC, "[eNB %d] Frame %d : handover preparation: add target eNB SRB1 and PHYConfigDedicated reconfiguration\n",
        ctxt_pP->module_id, ctxt_pP->frame);

  if (SRB_configList) {
    free(SRB_configList);
  }
Cedric Roux's avatar
Cedric Roux committed
4554

4555 4556 4557 4558 4559 4560
  SRB_configList = CALLOC(1, sizeof(*SRB_configList));
  memset(SRB_configList, 0, 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;
4561 4562 4563 4564 4565 4566 4567 4568
  SRB1_rlc_config->present = LTE_SRB_ToAddMod__rlc_Config_PR_explicitValue;
  SRB1_rlc_config->choice.explicitValue.present = LTE_RLC_Config_PR_am;
  SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.t_PollRetransmit = LTE_T_PollRetransmit_ms15;
  SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollPDU = LTE_PollPDU_p8;
  SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollByte = LTE_PollByte_kB1000;
  SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.maxRetxThreshold = LTE_UL_AM_RLC__maxRetxThreshold_t16;
  SRB1_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_Reordering = LTE_T_Reordering_ms35;
  SRB1_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_StatusProhibit = LTE_T_StatusProhibit_ms10;
4569 4570
  SRB1_lchan_config = CALLOC(1, sizeof(*SRB1_lchan_config));
  SRB1_config->logicalChannelConfig = SRB1_lchan_config;
4571
  SRB1_lchan_config->present = LTE_SRB_ToAddMod__logicalChannelConfig_PR_explicitValue;
4572 4573 4574 4575 4576
  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 =
4577
    LTE_LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
4578 4579
  //assign_enum(&SRB1_ul_SpecificParameters->bucketSizeDuration,LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50);
  SRB1_ul_SpecificParameters->bucketSizeDuration =
4580
    LTE_LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
4581 4582 4583 4584 4585 4586 4587 4588
  logicalchannelgroup = CALLOC(1, sizeof(long));
  *logicalchannelgroup = 0;
  SRB1_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup;
  ASN_SEQUENCE_ADD(&SRB_configList->list, SRB1_config);
  ue_context_pP->ue_context.SRB_configList = SRB_configList;
  // Configure SRB2
  /// SRB2
  SRB_configList2=&ue_context_pP->ue_context.SRB_configList2[xid];
Cedric Roux's avatar
Cedric Roux committed
4589

4590 4591 4592
  if (*SRB_configList2) {
    free(*SRB_configList2);
  }
Cedric Roux's avatar
Cedric Roux committed
4593

4594 4595 4596 4597 4598 4599
  *SRB_configList2 = CALLOC(1, sizeof(**SRB_configList2));
  memset(*SRB_configList2, 0, sizeof(**SRB_configList2));
  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;
4600 4601 4602 4603 4604 4605 4606 4607
  SRB2_rlc_config->present = LTE_SRB_ToAddMod__rlc_Config_PR_explicitValue;
  SRB2_rlc_config->choice.explicitValue.present = LTE_RLC_Config_PR_am;
  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.t_PollRetransmit = LTE_T_PollRetransmit_ms15;
  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollPDU = LTE_PollPDU_p8;
  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollByte = LTE_PollByte_kB1000;
  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.maxRetxThreshold = LTE_UL_AM_RLC__maxRetxThreshold_t32;
  SRB2_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_Reordering = LTE_T_Reordering_ms35;
  SRB2_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_StatusProhibit = LTE_T_StatusProhibit_ms10;
4608 4609
  SRB2_lchan_config = CALLOC(1, sizeof(*SRB2_lchan_config));
  SRB2_config->logicalChannelConfig = SRB2_lchan_config;
4610
  SRB2_lchan_config->present = LTE_SRB_ToAddMod__logicalChannelConfig_PR_explicitValue;
4611 4612 4613
  SRB2_ul_SpecificParameters = CALLOC(1, sizeof(*SRB2_ul_SpecificParameters));
  SRB2_ul_SpecificParameters->priority = 3; // let some priority for SRB1 and dedicated DRBs
  SRB2_ul_SpecificParameters->prioritisedBitRate =
4614
    LTE_LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
4615
  SRB2_ul_SpecificParameters->bucketSizeDuration =
4616
    LTE_LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632
  // 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;
  // this list has the configuration for SRB1 and SRB2
  ASN_SEQUENCE_ADD(&SRB_configList->list, SRB2_config);
  // this list has only the configuration for SRB2
  ASN_SEQUENCE_ADD(&(*SRB_configList2)->list, SRB2_config);

  // Configure DRB
  //*DRB_configList = CALLOC(1, sizeof(*DRB_configList));
  // list for all the configured DRB
  if (*DRB_configList) {
    free(*DRB_configList);
  }
Cedric Roux's avatar
Cedric Roux committed
4633

4634 4635 4636 4637
  *DRB_configList = CALLOC(1, sizeof(**DRB_configList));
  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];
Cedric Roux's avatar
Cedric Roux committed
4638

4639 4640 4641
  if (*DRB_configList2) {
    free(*DRB_configList2);
  }
Cedric Roux's avatar
Cedric Roux committed
4642

4643 4644 4645 4646 4647 4648 4649 4650
  *DRB_configList2 = CALLOC(1, sizeof(**DRB_configList2));
  memset(*DRB_configList2, 0, sizeof(**DRB_configList2));
  /// DRB
  DRB_config = CALLOC(1, sizeof(*DRB_config));
  DRB_config->eps_BearerIdentity = CALLOC(1, sizeof(long));
  *(DRB_config->eps_BearerIdentity) = 5L; // LW set to first value, allowed value 5..15, value : x+4
  // DRB_config->drb_Identity = (DRB_Identity_t) 1; //allowed values 1..32
  // NN: this is the 1st DRB for this ue, so set it to 1
4651
  DRB_config->drb_Identity = (LTE_DRB_Identity_t) 1;  // (ue_mod_idP+1); //allowed values 1..32, value: x
4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664
  DRB_config->logicalChannelIdentity = CALLOC(1, sizeof(long));
  *(DRB_config->logicalChannelIdentity) = (long)3; // value : x+2
  DRB_rlc_config = CALLOC(1, sizeof(*DRB_rlc_config));
  DRB_config->rlc_Config = DRB_rlc_config;
#ifdef RRC_DEFAULT_RAB_IS_AM
  DRB_rlc_config->present = RLC_Config_PR_am;
  DRB_rlc_config->choice.am.ul_AM_RLC.t_PollRetransmit = T_PollRetransmit_ms50;
  DRB_rlc_config->choice.am.ul_AM_RLC.pollPDU = PollPDU_p16;
  DRB_rlc_config->choice.am.ul_AM_RLC.pollByte = PollByte_kBinfinity;
  DRB_rlc_config->choice.am.ul_AM_RLC.maxRetxThreshold = UL_AM_RLC__maxRetxThreshold_t8;
  DRB_rlc_config->choice.am.dl_AM_RLC.t_Reordering = T_Reordering_ms35;
  DRB_rlc_config->choice.am.dl_AM_RLC.t_StatusProhibit = T_StatusProhibit_ms25;
#else
4665 4666 4667
  DRB_rlc_config->present = LTE_RLC_Config_PR_um_Bi_Directional;
  DRB_rlc_config->choice.um_Bi_Directional.ul_UM_RLC.sn_FieldLength = LTE_SN_FieldLength_size10;
  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.sn_FieldLength = LTE_SN_FieldLength_size10;
4668
#ifdef CBA
4669
  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering   = LTE_T_Reordering_ms5;//T_Reordering_ms25;
4670
#else
4671
  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering = LTE_T_Reordering_ms35;
4672 4673 4674 4675 4676
#endif
#endif
  DRB_pdcp_config = CALLOC(1, sizeof(*DRB_pdcp_config));
  DRB_config->pdcp_Config = DRB_pdcp_config;
  DRB_pdcp_config->discardTimer = CALLOC(1, sizeof(long));
4677
  *DRB_pdcp_config->discardTimer = LTE_PDCP_Config__discardTimer_infinity;
4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689
  DRB_pdcp_config->rlc_AM = NULL;
  DRB_pdcp_config->rlc_UM = NULL;
  /* avoid gcc warnings */
  (void)PDCP_rlc_AM;
  (void)PDCP_rlc_UM;
#ifdef RRC_DEFAULT_RAB_IS_AM // EXMIMO_IOT
  PDCP_rlc_AM = CALLOC(1, sizeof(*PDCP_rlc_AM));
  DRB_pdcp_config->rlc_AM = PDCP_rlc_AM;
  PDCP_rlc_AM->statusReportRequired = FALSE;
#else
  PDCP_rlc_UM = CALLOC(1, sizeof(*PDCP_rlc_UM));
  DRB_pdcp_config->rlc_UM = PDCP_rlc_UM;
4690
  PDCP_rlc_UM->pdcp_SN_Size = LTE_PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits;
4691
#endif
4692
  DRB_pdcp_config->headerCompression.present = LTE_PDCP_Config__headerCompression_PR_notUsed;
4693 4694 4695 4696 4697
  DRB_lchan_config = CALLOC(1, sizeof(*DRB_lchan_config));
  DRB_config->logicalChannelConfig = DRB_lchan_config;
  DRB_ul_SpecificParameters = CALLOC(1, sizeof(*DRB_ul_SpecificParameters));
  DRB_lchan_config->ul_SpecificParameters = DRB_ul_SpecificParameters;
  DRB_ul_SpecificParameters->priority = 12;    // lower priority than srb1, srb2 and other dedicated bearer
4698
  DRB_ul_SpecificParameters->prioritisedBitRate =LTE_LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_kBps8 ;
Cedric Roux's avatar
Cedric Roux committed
4699
  //LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
4700
  DRB_ul_SpecificParameters->bucketSizeDuration =
4701
    LTE_LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712
  // LCG for DTCH can take the value from 1 to 3 as defined in 36331: normally controlled by upper layers (like RRM)
  logicalchannelgroup_drb = CALLOC(1, sizeof(long));
  *logicalchannelgroup_drb = 1;
  DRB_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup_drb;
  ASN_SEQUENCE_ADD(&(*DRB_configList)->list, DRB_config);
  ASN_SEQUENCE_ADD(&(*DRB_configList2)->list, DRB_config);
  //ue_context_pP->ue_context.DRB_configList2[0] = &(*DRB_configList);
  mac_MainConfig = CALLOC(1, sizeof(*mac_MainConfig));
  ue_context_pP->ue_context.mac_MainConfig = mac_MainConfig;
  mac_MainConfig->ul_SCH_Config = CALLOC(1, sizeof(*mac_MainConfig->ul_SCH_Config));
  maxHARQ_Tx = CALLOC(1, sizeof(long));
4713
  *maxHARQ_Tx = LTE_MAC_MainConfig__ul_SCH_Config__maxHARQ_Tx_n5;
4714 4715
  mac_MainConfig->ul_SCH_Config->maxHARQ_Tx = maxHARQ_Tx;
  periodicBSR_Timer = CALLOC(1, sizeof(long));
4716
  *periodicBSR_Timer = LTE_PeriodicBSR_Timer_r12_sf64;
4717
  mac_MainConfig->ul_SCH_Config->periodicBSR_Timer = periodicBSR_Timer;
4718
  mac_MainConfig->ul_SCH_Config->retxBSR_Timer = LTE_RetxBSR_Timer_r12_sf320;
4719
  mac_MainConfig->ul_SCH_Config->ttiBundling = 0; // FALSE
4720
  mac_MainConfig->timeAlignmentTimerDedicated = LTE_TimeAlignmentTimer_infinity;
4721 4722
  mac_MainConfig->drx_Config = NULL;
  mac_MainConfig->phr_Config = CALLOC(1, sizeof(*mac_MainConfig->phr_Config));
4723 4724 4725 4726 4727
  mac_MainConfig->phr_Config->present = LTE_MAC_MainConfig__phr_Config_PR_setup;
  mac_MainConfig->phr_Config->choice.setup.periodicPHR_Timer = LTE_MAC_MainConfig__phr_Config__setup__periodicPHR_Timer_sf20; // sf20 = 20 subframes
  mac_MainConfig->phr_Config->choice.setup.prohibitPHR_Timer = LTE_MAC_MainConfig__phr_Config__setup__prohibitPHR_Timer_sf20; // sf20 = 20 subframes
  mac_MainConfig->phr_Config->choice.setup.dl_PathlossChange = LTE_MAC_MainConfig__phr_Config__setup__dl_PathlossChange_dB1;  // Value dB1 =1 dB, dB3 = 3 dB
#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
4728 4729
  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
4730
  mac_MainConfig->ext1 = CALLOC(1, sizeof(struct LTE_MAC_MainConfig__ext1));
4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765
  mac_MainConfig->ext1->sr_ProhibitTimer_r9 = sr_ProhibitTimer_r9;
  //sps_RA_ConfigList_rlola = NULL;
#endif

  //change the transmission mode for the primary component carrier
  //TODO: add codebook subset restriction here
  //TODO: change TM for secondary CC in SCelltoaddmodlist
  /// now reconfigure phy config dedicated
  if (*physicalConfigDedicated) {
    free(*physicalConfigDedicated);
  }

  //if (*physicalConfigDedicated) {
  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));
  physicalConfigDedicated2->soundingRS_UL_ConfigDedicated = NULL; //CALLOC(1,sizeof(*physicalConfigDedicated2->soundingRS_UL_ConfigDedicated));
  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);
4766
  physicalConfigDedicated2->pdsch_ConfigDedicated->p_a = LTE_PDSCH_ConfigDedicated__p_a_dB0;
4767 4768
  // PUCCH
  physicalConfigDedicated2->pucch_ConfigDedicated->ackNackRepetition.present =
4769
    LTE_PUCCH_ConfigDedicated__ackNackRepetition_PR_release;
4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780
  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 =
4781
    LTE_UplinkPowerControlDedicated__deltaMCS_Enabled_en1;
4782 4783 4784 4785 4786 4787
  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
4788
  *physicalConfigDedicated2->uplinkPowerControlDedicated->filterCoefficient = LTE_FilterCoefficient_fc4;  // fc4 dB
4789
  // TPC-PDCCH-Config
4790 4791
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->present = LTE_TPC_PDCCH_Config_PR_setup;
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_Index.present = LTE_TPC_Index_PR_indexOfFormat3;
4792 4793 4794 4795 4796 4797
  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;
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_RNTI.buf[1] = 0x34 + ue_context_pP->local_uid;
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_RNTI.bits_unused = 0;
4798 4799
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->present = LTE_TPC_PDCCH_Config_PR_setup;
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_Index.present = LTE_TPC_Index_PR_indexOfFormat3;
4800 4801 4802 4803 4804 4805 4806 4807
  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;
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_RNTI.buf[1] = 0x34 + ue_context_pP->local_uid;
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_RNTI.bits_unused = 0;
  //AntennaInfoDedicated
  physicalConfigDedicated2->antennaInfo = CALLOC(1, sizeof(*physicalConfigDedicated2->antennaInfo));
4808
  physicalConfigDedicated2->antennaInfo->present = LTE_PhysicalConfigDedicated__antennaInfo_PR_explicitValue;
4809
  //if ((*physicalConfigDedicated)->antennaInfo) {
Cedric Roux's avatar
Cedric Roux committed
4810 4811
  (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.transmissionMode = rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode;
  LOG_D(RRC,"Setting transmission mode to %ld+1\n",rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode);
Cedric Roux's avatar
Cedric Roux committed
4812

Cedric Roux's avatar
Cedric Roux committed
4813
  if (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm3) {
Cedric Roux's avatar
Cedric Roux committed
4814
    (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=
4815
      CALLOC(1,sizeof(LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR));
Cedric Roux's avatar
Cedric Roux committed
4816
    (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
4817
      LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm3;
Cedric Roux's avatar
Cedric Roux committed
4818 4819 4820 4821
    (*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;
Cedric Roux's avatar
Cedric Roux committed
4822
  } else if (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm4) {
Cedric Roux's avatar
Cedric Roux committed
4823
    (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=
4824
      CALLOC(1,sizeof(LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR));
Cedric Roux's avatar
Cedric Roux committed
4825
    (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
4826
      LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm4;
Cedric Roux's avatar
Cedric Roux committed
4827 4828 4829 4830
    (*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;
Cedric Roux's avatar
Cedric Roux committed
4831
  } else if (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm5) {
Cedric Roux's avatar
Cedric Roux committed
4832
    (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=
4833
      CALLOC(1,sizeof(LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR));
Cedric Roux's avatar
Cedric Roux committed
4834
    (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
4835
      LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm5;
Cedric Roux's avatar
Cedric Roux committed
4836 4837 4838 4839
    (*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;
Cedric Roux's avatar
Cedric Roux committed
4840
  } else if (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm6) {
Cedric Roux's avatar
Cedric Roux committed
4841
    (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=
4842
      CALLOC(1,sizeof(LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR));
Cedric Roux's avatar
Cedric Roux committed
4843
    (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
4844
      LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm6;
Cedric Roux's avatar
Cedric Roux committed
4845 4846 4847 4848 4849
    (*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;
  }
4850 4851

  physicalConfigDedicated2->antennaInfo->choice.explicitValue.ue_TransmitAntennaSelection.present =
4852
    LTE_AntennaInfoDedicated__ue_TransmitAntennaSelection_PR_release;
4853 4854 4855
  physicalConfigDedicated2->antennaInfo->choice.explicitValue.ue_TransmitAntennaSelection.choice.release = 0;
  //}
  //else {
Cedric Roux's avatar
Cedric Roux committed
4856
  //LOG_E(RRC,"antenna_info not present in physical_config_dedicated. Not reconfiguring!\n");
4857 4858
  //}
  // CQI ReportConfig
Cedric Roux's avatar
Cedric Roux committed
4859 4860 4861 4862 4863
  physicalConfigDedicated2->cqi_ReportConfig = CALLOC(1,sizeof(*physicalConfigDedicated2->cqi_ReportConfig));
  physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportModeAperiodic = CALLOC(1,sizeof(*physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportModeAperiodic));
  physicalConfigDedicated2->cqi_ReportConfig->nomPDSCH_RS_EPRE_Offset = 0; // 0 dB
  //physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic=NULL;
  physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic=CALLOC(1,sizeof(*physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic));
4864
  physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->present =  LTE_CQI_ReportPeriodic_PR_release;
4865 4866

  //if ((*physicalConfigDedicated)->cqi_ReportConfig) {
Cedric Roux's avatar
Cedric Roux committed
4867 4868 4869
  if ((rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm4) ||
      (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm5) ||
      (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm6)) {
Cedric Roux's avatar
Cedric Roux committed
4870 4871 4872
    //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");
4873 4874
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
    *((*physicalConfigDedicated)->cqi_ReportConfig->cqi_ReportModeAperiodic)=LTE_CQI_ReportModeAperiodic_rm31;
4875
#else
Cedric Roux's avatar
Cedric Roux committed
4876
    *((*physicalConfigDedicated)->cqi_ReportConfig->cqi_ReportModeAperiodic)=CQI_ReportConfig__cqi_ReportModeAperiodic_rm31; // HLC CQI, no PMI
4877
#endif
Cedric Roux's avatar
Cedric Roux committed
4878
  } else {
4879 4880
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
    *physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportModeAperiodic= LTE_CQI_ReportModeAperiodic_rm30;
4881
#else
Cedric Roux's avatar
Cedric Roux committed
4882
    *physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportModeAperiodic=CQI_ReportConfig__cqi_ReportModeAperiodic_rm30; // HLC CQI, no PMI
4883
#endif
Cedric Roux's avatar
Cedric Roux committed
4884 4885
  }

4886 4887
  //}
  //else {
Cedric Roux's avatar
Cedric Roux committed
4888
  //LOG_E(RRC,"cqi_ReportConfig not present in physical_config_dedicated. Not reconfiguring!\n");
4889 4890
  //}
  // SchedulingRequestConfig
4891
  physicalConfigDedicated2->schedulingRequestConfig->present = LTE_SchedulingRequestConfig_PR_setup;
4892 4893 4894 4895 4896 4897 4898
  physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_PUCCH_ResourceIndex = ue_context_pP->local_uid;

  if (rrc_inst->carrier[0].sib1->tdd_Config==NULL) {  // FDD
    physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_ConfigIndex = 5 + (ue_context_pP->local_uid %
        10);   // Isr = 5 (every 10 subframes, offset=2+UE_id mod3)
  } else {
    switch (rrc_inst->carrier[0].sib1->tdd_Config->subframeAssignment) {
Cedric Roux's avatar
Cedric Roux committed
4899 4900 4901 4902
      case 1:
        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..)
        break;
4903

Cedric Roux's avatar
Cedric Roux committed
4904 4905 4906 4907
      case 3:
        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..)
        break;
4908

Cedric Roux's avatar
Cedric Roux committed
4909 4910 4911 4912
      case 4:
        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..)
        break;
4913

Cedric Roux's avatar
Cedric Roux committed
4914 4915 4916
      default:
        physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_ConfigIndex = 7; // Isr = 5 (every 10 subframes, offset=2 for all UE0 etc..)
        break;
4917 4918 4919 4920 4921 4922 4923
    }
  }

  //  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 =
4924
    LTE_SchedulingRequestConfig__setup__dsr_TransMax_n4;
4925 4926
  //}
  //else {
Cedric Roux's avatar
Cedric Roux committed
4927
  //LOG_E(RRC,"physical_config_dedicated not present in RRCConnectionReconfiguration. Not reconfiguring!\n");
4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969
  //}
  // 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;
4970
  MeasObj->measObject.present = LTE_MeasObjectToAddMod__measObject_PR_measObjectEUTRA;
4971 4972 4973 4974
  MeasObj->measObject.choice.measObjectEUTRA.carrierFreq =
      to_earfcn_DL(RC.rrc[ctxt_pP->module_id]->configuration.eutra_band[0],
                   RC.rrc[ctxt_pP->module_id]->configuration.downlink_frequency[0],
                   RC.rrc[ctxt_pP->module_id]->configuration.N_RB_DL[0]);
4975
  MeasObj->measObject.choice.measObjectEUTRA.allowedMeasBandwidth = LTE_AllowedMeasBandwidth_mbw25;
4976 4977 4978 4979 4980 4981 4982
  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 =
Cedric Roux's avatar
Cedric Roux committed
4983
  //(CellsToAddModList_t *) CALLOC(1, sizeof(*CellsToAddModList));
4984 4985 4986
  //CellsToAddModList = MeasObj->measObject.choice.measObjectEUTRA.cellsToAddModList;
  // Add adjacent cell lists (6 per eNB)
  //for (i = 0; i < 6; i++) {
Cedric Roux's avatar
Cedric Roux committed
4987 4988 4989 4990 4991
  //CellToAdd = (CellsToAddMod_t *) CALLOC(1, sizeof(*CellToAdd));
  //CellToAdd->cellIndex = 1;//i + 1;
  //CellToAdd->physCellId = 1;//get_adjacent_cell_id(ctxt_pP->module_id, i);
  //CellToAdd->cellIndividualOffset = Q_OffsetRange_dB0;
  //ASN_SEQUENCE_ADD(&CellsToAddModList->list, CellToAdd);
4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003
  //}
  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;
5004
  ReportConfig_per->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
5005
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerType.present =
5006
    LTE_ReportConfigEUTRA__triggerType_PR_periodical;
5007
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerType.choice.periodical.purpose =
5008 5009 5010
    LTE_ReportConfigEUTRA__triggerType__periodical__purpose_reportStrongestCells;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerQuantity = LTE_ReportConfigEUTRA__triggerQuantity_rsrp;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both;
5011
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
5012 5013
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity;
5014 5015
  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_per);
  ReportConfig_A1->reportConfigId = 2;
5016
  ReportConfig_A1->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
5017
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.present =
5018
    LTE_ReportConfigEUTRA__triggerType_PR_event;
5019
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
5020
    LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA1;
5021
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA1.
5022
  a1_Threshold.present = LTE_ThresholdEUTRA_PR_threshold_RSRP;
5023 5024
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA1.
  a1_Threshold.choice.threshold_RSRP = 10;
5025 5026
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerQuantity = LTE_ReportConfigEUTRA__triggerQuantity_rsrp;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both;
5027
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
5028 5029
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity;
5030
  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A1);
Cedric Roux's avatar
Cedric Roux committed
5031 5032 5033 5034
  //  if (ho_state == 1 /*HO_MEASUREMENT */ ) {
  LOG_I(RRC, "[eNB %d] frame %d: requesting A2, A3, A4, and A5 event reporting\n",
        ctxt_pP->module_id, ctxt_pP->frame);
  ReportConfig_A2->reportConfigId = 3;
5035
  ReportConfig_A2->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
Cedric Roux's avatar
Cedric Roux committed
5036
  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.present =
5037
    LTE_ReportConfigEUTRA__triggerType_PR_event;
Cedric Roux's avatar
Cedric Roux committed
5038
  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
5039
    LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA2;
Cedric Roux's avatar
Cedric Roux committed
5040
  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
5041
  eventA2.a2_Threshold.present = LTE_ThresholdEUTRA_PR_threshold_RSRP;
Cedric Roux's avatar
Cedric Roux committed
5042 5043 5044
  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
  eventA2.a2_Threshold.choice.threshold_RSRP = 10;
  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerQuantity =
5045 5046
    LTE_ReportConfigEUTRA__triggerQuantity_rsrp;
  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both;
Cedric Roux's avatar
Cedric Roux committed
5047
  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
5048 5049
  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120;
  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity;
Cedric Roux's avatar
Cedric Roux committed
5050 5051
  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A2);
  ReportConfig_A3->reportConfigId = 4;
5052
  ReportConfig_A3->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
Cedric Roux's avatar
Cedric Roux committed
5053
  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.present =
5054
    LTE_ReportConfigEUTRA__triggerType_PR_event;
Cedric Roux's avatar
Cedric Roux committed
5055
  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
5056
    LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA3;
Cedric Roux's avatar
Cedric Roux committed
5057 5058 5059 5060
  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA3.a3_Offset = 0;   //10;
  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
  eventA3.reportOnLeave = 1;
  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerQuantity =
5061 5062
    LTE_ReportConfigEUTRA__triggerQuantity_rsrp;
  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both;
Cedric Roux's avatar
Cedric Roux committed
5063
  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
5064 5065
  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120;
  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity;
Cedric Roux's avatar
Cedric Roux committed
5066 5067
  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.hysteresis = 0; // FIXME ...hysteresis is of type long!
  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.timeToTrigger =
5068
    LTE_TimeToTrigger_ms40;
Cedric Roux's avatar
Cedric Roux committed
5069 5070
  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A3);
  ReportConfig_A4->reportConfigId = 5;
5071
  ReportConfig_A4->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
Cedric Roux's avatar
Cedric Roux committed
5072
  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.present =
5073
    LTE_ReportConfigEUTRA__triggerType_PR_event;
Cedric Roux's avatar
Cedric Roux committed
5074
  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
5075
    LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA4;
Cedric Roux's avatar
Cedric Roux committed
5076
  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
5077
  eventA4.a4_Threshold.present = LTE_ThresholdEUTRA_PR_threshold_RSRP;
Cedric Roux's avatar
Cedric Roux committed
5078 5079 5080
  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
  eventA4.a4_Threshold.choice.threshold_RSRP = 10;
  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerQuantity =
5081 5082
    LTE_ReportConfigEUTRA__triggerQuantity_rsrp;
  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both;
Cedric Roux's avatar
Cedric Roux committed
5083
  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
5084 5085
  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120;
  ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity;
Cedric Roux's avatar
Cedric Roux committed
5086 5087
  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A4);
  ReportConfig_A5->reportConfigId = 6;
5088
  ReportConfig_A5->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
Cedric Roux's avatar
Cedric Roux committed
5089
  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.present =
5090
    LTE_ReportConfigEUTRA__triggerType_PR_event;
Cedric Roux's avatar
Cedric Roux committed
5091
  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
5092
    LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA5;
Cedric Roux's avatar
Cedric Roux committed
5093
  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
5094
  eventA5.a5_Threshold1.present = LTE_ThresholdEUTRA_PR_threshold_RSRP;
Cedric Roux's avatar
Cedric Roux committed
5095
  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
5096
  eventA5.a5_Threshold2.present = LTE_ThresholdEUTRA_PR_threshold_RSRP;
Cedric Roux's avatar
Cedric Roux committed
5097 5098 5099 5100 5101
  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 =
5102 5103
    LTE_ReportConfigEUTRA__triggerQuantity_rsrp;
  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both;
Cedric Roux's avatar
Cedric Roux committed
5104
  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
5105 5106
  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120;
  ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity;
Cedric Roux's avatar
Cedric Roux committed
5107 5108 5109 5110 5111
  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));
5112 5113 5114
  Sparams->present = LTE_MeasConfig__speedStatePars_PR_setup;
  Sparams->choice.setup.timeToTrigger_SF.sf_High = LTE_SpeedStateScaleFactors__sf_Medium_oDot75;
  Sparams->choice.setup.timeToTrigger_SF.sf_Medium = LTE_SpeedStateScaleFactors__sf_High_oDot5;
Cedric Roux's avatar
Cedric Roux committed
5115 5116
  Sparams->choice.setup.mobilityStateParameters.n_CellChangeHigh = 10;
  Sparams->choice.setup.mobilityStateParameters.n_CellChangeMedium = 5;
5117 5118
  Sparams->choice.setup.mobilityStateParameters.t_Evaluation = LTE_MobilityStateParameters__t_Evaluation_s60;
  Sparams->choice.setup.mobilityStateParameters.t_HystNormal = LTE_MobilityStateParameters__t_HystNormal_s120;
Cedric Roux's avatar
Cedric Roux committed
5119 5120
  quantityConfig = CALLOC(1, sizeof(*quantityConfig));
  memset((void *)quantityConfig, 0, sizeof(*quantityConfig));
5121
  quantityConfig->quantityConfigEUTRA = CALLOC(1, sizeof(struct LTE_QuantityConfigEUTRA));
Cedric Roux's avatar
Cedric Roux committed
5122 5123 5124 5125 5126 5127 5128 5129
  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)));
5130 5131
  *quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP = LTE_FilterCoefficient_fc4;
  *quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ = LTE_FilterCoefficient_fc4;
Cedric Roux's avatar
Cedric Roux committed
5132 5133
  /* mobilityinfo  */
  mobilityInfo = ue_context_pP->ue_context.mobilityInfo;
5134

Cedric Roux's avatar
Cedric Roux committed
5135 5136 5137
  if (mobilityInfo) {
    free(mobilityInfo);
  }
5138

Cedric Roux's avatar
Cedric Roux committed
5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149
  mobilityInfo = CALLOC(1, sizeof(*mobilityInfo));
  memset((void *)mobilityInfo, 0, sizeof(*mobilityInfo));
  mobilityInfo->targetPhysCellId = RC.rrc[ctxt_pP->module_id]->carrier[0].physCellId;
  //(PhysCellId_t) two_tier_hexagonal_cellIds[ue_context_pP->ue_context.handover_info->modid_t];
  LOG_D(RRC, "[eNB %d] Frame %d: handover preparation: targetPhysCellId: %ld mod_id: %d ue: %x \n",
        ctxt_pP->module_id,
        ctxt_pP->frame,
        mobilityInfo->targetPhysCellId,
        ctxt_pP->module_id, // get_adjacent_cell_mod_id(mobilityInfo->targetPhysCellId),
        ue_context_pP->ue_context.rnti);
  mobilityInfo->additionalSpectrumEmission = CALLOC(1, sizeof(*mobilityInfo->additionalSpectrumEmission));
5150
  *mobilityInfo->additionalSpectrumEmission = (LTE_AdditionalSpectrumEmission_t) 1;  //Check this value!
5151
  mobilityInfo->t304 = LTE_MobilityControlInfo__t304_ms200;    // need to configure an appropriate value here
Cedric Roux's avatar
Cedric Roux committed
5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163
  // 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,
5164
         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.rach_ConfigCommon, sizeof(LTE_RACH_ConfigCommon_t));
Cedric Roux's avatar
Cedric Roux committed
5165 5166 5167 5168
  mobilityInfo->radioResourceConfigCommon.prach_Config.prach_ConfigInfo =
    CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.prach_Config.prach_ConfigInfo));
  memcpy((void *)mobilityInfo->radioResourceConfigCommon.prach_Config.prach_ConfigInfo,
         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.prach_Config.prach_ConfigInfo,
5169
         sizeof(LTE_PRACH_ConfigInfo_t));
Cedric Roux's avatar
Cedric Roux committed
5170 5171 5172 5173 5174
  mobilityInfo->radioResourceConfigCommon.prach_Config.rootSequenceIndex =
    rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.prach_Config.rootSequenceIndex;
  mobilityInfo->radioResourceConfigCommon.pdsch_ConfigCommon =
    CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.pdsch_ConfigCommon));
  memcpy((void *)mobilityInfo->radioResourceConfigCommon.pdsch_ConfigCommon,
5175
         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.pdsch_ConfigCommon, sizeof(LTE_PDSCH_ConfigCommon_t));
Cedric Roux's avatar
Cedric Roux committed
5176
  memcpy((void *)&mobilityInfo->radioResourceConfigCommon.pusch_ConfigCommon,
5177
         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.pusch_ConfigCommon, sizeof(LTE_PUSCH_ConfigCommon_t));
Cedric Roux's avatar
Cedric Roux committed
5178 5179 5180 5181
  mobilityInfo->radioResourceConfigCommon.phich_Config = NULL;
  mobilityInfo->radioResourceConfigCommon.pucch_ConfigCommon =
    CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.pucch_ConfigCommon));
  memcpy((void *)mobilityInfo->radioResourceConfigCommon.pucch_ConfigCommon,
5182
         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.pucch_ConfigCommon, sizeof(LTE_PUCCH_ConfigCommon_t));
Cedric Roux's avatar
Cedric Roux committed
5183 5184 5185 5186
  mobilityInfo->radioResourceConfigCommon.soundingRS_UL_ConfigCommon =
    CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.soundingRS_UL_ConfigCommon));
  memcpy((void *)mobilityInfo->radioResourceConfigCommon.soundingRS_UL_ConfigCommon,
         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon,
5187
         sizeof(LTE_SoundingRS_UL_ConfigCommon_t));
Cedric Roux's avatar
Cedric Roux committed
5188 5189 5190 5191
  mobilityInfo->radioResourceConfigCommon.uplinkPowerControlCommon =
    CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.uplinkPowerControlCommon));
  memcpy((void *)mobilityInfo->radioResourceConfigCommon.uplinkPowerControlCommon,
         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.uplinkPowerControlCommon,
5192
         sizeof(LTE_UplinkPowerControlCommon_t));
Cedric Roux's avatar
Cedric Roux committed
5193 5194 5195 5196 5197 5198 5199 5200 5201
  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 =
    rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.ul_CyclicPrefixLength;
  //End of configuration of radioResourceConfigCommon
  mobilityInfo->carrierFreq = CALLOC(1, sizeof(*mobilityInfo->carrierFreq));  //CALLOC(1,sizeof(CarrierFreqEUTRA_t)); 36090
5202 5203 5204 5205
  mobilityInfo->carrierFreq->dl_CarrierFreq =
      to_earfcn_DL(RC.rrc[ctxt_pP->module_id]->configuration.eutra_band[0],
                   RC.rrc[ctxt_pP->module_id]->configuration.downlink_frequency[0],
                   RC.rrc[ctxt_pP->module_id]->configuration.N_RB_DL[0]);
Cedric Roux's avatar
Cedric Roux committed
5206 5207 5208
  mobilityInfo->carrierFreq->ul_CarrierFreq = NULL;
  mobilityInfo->carrierBandwidth = CALLOC(1, sizeof(
      *mobilityInfo->carrierBandwidth));    //CALLOC(1,sizeof(struct CarrierBandwidthEUTRA));  AllowedMeasBandwidth_mbw25
5209
  mobilityInfo->carrierBandwidth->dl_Bandwidth = LTE_CarrierBandwidthEUTRA__dl_Bandwidth_n25;
Cedric Roux's avatar
Cedric Roux committed
5210 5211 5212
  mobilityInfo->carrierBandwidth->ul_Bandwidth = NULL;
  mobilityInfo->rach_ConfigDedicated = NULL;
  ue_context_pP->ue_context.mobilityInfo = mobilityInfo;
5213
#if 0
Cedric Roux's avatar
Cedric Roux committed
5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236
  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 *)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));
#endif
  //  }
5237 5238
  securityConfigHO = CALLOC(1, sizeof(*securityConfigHO));
  memset((void *)securityConfigHO, 0, sizeof(*securityConfigHO));
5239
  securityConfigHO->handoverType.present = LTE_SecurityConfigHO__handoverType_PR_intraLTE;
5240 5241 5242 5243 5244
  securityConfigHO->handoverType.choice.intraLTE.securityAlgorithmConfig = NULL; /* TODO: to be checked */
  securityConfigHO->handoverType.choice.intraLTE.keyChangeIndicator = 0;
  securityConfigHO->handoverType.choice.intraLTE.nextHopChainingCount = 0;
#if defined(ENABLE_ITTI)
  /* Initialize NAS list */
5245
  dedicatedInfoNASList = CALLOC(1, sizeof(struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList));
5246 5247 5248 5249

  /* 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) {
5250
      dedicatedInfoNas = CALLOC(1, sizeof(LTE_DedicatedInfoNAS_t));
5251 5252
      memset(dedicatedInfoNas, 0, sizeof(OCTET_STRING_t));
      OCTET_STRING_fromBuf(dedicatedInfoNas,
Cedric Roux's avatar
Cedric Roux committed
5253
                           (char *)ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer,
5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266
                           ue_context_pP->ue_context.e_rab[i].param.nas_pdu.length);
      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",
Cedric Roux's avatar
Cedric Roux committed
5267
          i, ue_context_pP->ue_context.e_rab[i].status, "E_RAB_STATUS_DONE");
5268 5269 5270 5271 5272 5273 5274 5275 5276
  }

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

#endif
Cedric Roux's avatar
Cedric Roux committed
5277

5278 5279
  measurements_enabled = RC.rrc[ENB_INSTANCE_TO_MODULE_ID(ctxt_pP->instance)]->configuration.enable_x2 ||
                         RC.rrc[ENB_INSTANCE_TO_MODULE_ID(ctxt_pP->instance)]->configuration.enable_measurement_reports;
Cedric Roux's avatar
Cedric Roux committed
5280

5281 5282 5283 5284
  memset(buffer, 0, RRC_BUF_SIZE);
  char rrc_buf[1000 /* arbitrary, should be big enough, has to be less than size of return buf by a few bits/bytes */];
  int rrc_size;
  rrc_size = do_RRCConnectionReconfiguration(ctxt_pP,
Cedric Roux's avatar
Cedric Roux committed
5285 5286 5287 5288 5289
             (unsigned char *)rrc_buf,
             xid,   //Transaction_id,
             NULL, // SRB_configList
             NULL,
             NULL,  // DRB2_list,
5290 5291
             (struct LTE_SPS_Config *)NULL,   // *sps_Config,
             (struct LTE_PhysicalConfigDedicated *)*physicalConfigDedicated,
Cedric Roux's avatar
Cedric Roux committed
5292 5293 5294
             //#ifdef EXMIMO_IOT
             //                                         NULL, NULL, NULL,NULL,
             //#else
5295 5296 5297 5298
             measurements_enabled ? (LTE_MeasObjectToAddModList_t *)MeasObj_list : NULL,
             measurements_enabled ? (LTE_ReportConfigToAddModList_t *)ReportConfig_list : NULL,
             measurements_enabled ? (LTE_QuantityConfig_t *)quantityConfig : NULL,
             measurements_enabled ? (LTE_MeasIdToAddModList_t *)MeasId_list : NULL,
Cedric Roux's avatar
Cedric Roux committed
5299
             //#endif
5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311
             (LTE_MAC_MainConfig_t *)mac_MainConfig,
             (LTE_MeasGapConfig_t *)NULL,
             (LTE_MobilityControlInfo_t *)mobilityInfo,
             (LTE_SecurityConfigHO_t *)securityConfigHO,
             (struct LTE_MeasConfig__speedStatePars *)Sparams,
             (LTE_RSRP_Range_t *)rsrp,
             (LTE_C_RNTI_t *)cba_RNTI,
             (struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *)dedicatedInfoNASList,
             (LTE_SL_CommConfig_r12_t *)NULL,
             (LTE_SL_DiscConfig_r12_t *)NULL
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
             , (LTE_SCellToAddMod_r10_t *)NULL
5312
#endif
Cedric Roux's avatar
Cedric Roux committed
5313
                                            );
5314

Cedric Roux's avatar
Cedric Roux committed
5315 5316 5317 5318
  if (rrc_size <= 0) {
    printf("%s:%d: fatal\n", __FILE__, __LINE__);
    abort();
  }
5319

Cedric Roux's avatar
Cedric Roux committed
5320
  char *ho_buf = (char *)buffer;
5321 5322
  int ho_size;
  ho_size = do_HandoverCommand(
Cedric Roux's avatar
Cedric Roux committed
5323 5324 5325
              ho_buf, 1024 /* TODO: this is the value found in struct x2ap_handover_req_ack_s for array rrc_buffer */,
              rrc_buf,
              rrc_size);
5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359
  *_size = size = ho_size;
  LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)buffer,size,
              "[MSG] RRC Connection Reconfiguration handover\n");
#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 handover (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 handover 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 handover UE %x MUI %d size %u",
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP->ue_context.rnti,
    rrc_eNB_mui,
    size);
}

void
Cedric Roux's avatar
Cedric Roux committed
5360
rrc_eNB_configure_rbs_handover(struct rrc_eNB_ue_context_s *ue_context_p, protocol_ctxt_t *const ctxt_pP) {
5361 5362 5363
  uint16_t                            Idx;
  Idx = DCCH;
#if 1
Cedric Roux's avatar
Cedric Roux committed
5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380
  // Activate the radio bearers
  // 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
  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);
#endif
  LOG_I(RRC, "[eNB %d] CALLING RLC CONFIG SRB1 (rbid %d) for UE %x\n",
        ctxt_pP->module_id, Idx, ue_context_p->ue_context.rnti);
  // Configure PDCP/RLC for the target
  rrc_pdcp_config_asn1_req(ctxt_pP,
                           ue_context_p->ue_context.SRB_configList,
5381 5382
                           (LTE_DRB_ToAddModList_t *) NULL,
                           (LTE_DRB_ToReleaseList_t *) NULL,
Cedric Roux's avatar
Cedric Roux committed
5383 5384 5385 5386
                           0xff,
                           NULL,
                           NULL,
                           NULL
nepes's avatar
nepes committed
5387
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
5388
                           , (LTE_PMCH_InfoList_r9_t *) NULL
5389
#endif
Cedric Roux's avatar
Cedric Roux committed
5390 5391 5392
                           , NULL);
  rrc_rlc_config_asn1_req(ctxt_pP,
                          ue_context_p->ue_context.SRB_configList,
5393 5394
                          (LTE_DRB_ToAddModList_t *) NULL,
                          (LTE_DRB_ToReleaseList_t *) NULL
nepes's avatar
nepes committed
5395
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
5396
                          , (LTE_PMCH_InfoList_r9_t *) NULL
Cedric Roux's avatar
Cedric Roux committed
5397
                          , 0, 0
5398
#endif
Cedric Roux's avatar
Cedric Roux committed
5399
                         );
Cedric Roux's avatar
Cedric Roux committed
5400 5401

  if (EPC_MODE_ENABLED) {
5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413
  rrc_eNB_process_security (
    ctxt_pP,
    ue_context_p,
    &ue_context_p->ue_context.security_capabilities);
  process_eNB_security_key (
    ctxt_pP,
    ue_context_p,
    ue_context_p->ue_context.kenb);
  rrc_pdcp_config_security(
    ctxt_pP,
    ue_context_p,
    FALSE);
Cedric Roux's avatar
Cedric Roux committed
5414
  }
5415

5416 5417
  // Add a new user (called during the HO procedure)
  LOG_I(RRC, "rrc_eNB_target_add_ue_handover module_id %d rnti %d\n", ctxt_pP->module_id, ctxt_pP->rnti);
Cedric Roux's avatar
Cedric Roux committed
5418
  // Configure MAC for the target
5419
  rrc_mac_config_req_eNB(
Cedric Roux's avatar
Cedric Roux committed
5420 5421 5422
    ctxt_pP->module_id,
    ue_context_p->ue_context.primaryCC_id,
    0,0,0,0,0,
5423
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
Cedric Roux's avatar
Cedric Roux committed
5424
    0,
5425
#endif
Cedric Roux's avatar
Cedric Roux committed
5426
    ue_context_p->ue_context.rnti,
5427 5428 5429 5430
    (LTE_BCCH_BCH_Message_t *) NULL,
    (LTE_RadioResourceConfigCommonSIB_t *) NULL,
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
    (LTE_RadioResourceConfigCommonSIB_t *) NULL,
5431
#endif
Cedric Roux's avatar
Cedric Roux committed
5432
    ue_context_p->ue_context.physicalConfigDedicated,
5433 5434
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
    (LTE_SCellToAddMod_r10_t *)NULL,
Cedric Roux's avatar
Cedric Roux committed
5435 5436
    //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
#endif
5437
    (LTE_MeasObjectToAddMod_t **) NULL,
Cedric Roux's avatar
Cedric Roux committed
5438 5439 5440 5441
    ue_context_p->ue_context.mac_MainConfig,
    1,
    NULL,//SRB1_logicalChannelConfig,
    ue_context_p->ue_context.measGapConfig,
5442 5443 5444
    (LTE_TDD_Config_t *) NULL,
    (LTE_MobilityControlInfo_t *) ue_context_p->ue_context.mobilityInfo,
    (LTE_SchedulingInfoList_t *) NULL,
Cedric Roux's avatar
Cedric Roux committed
5445 5446 5447
    0,
    NULL,
    NULL,
5448 5449 5450
    (LTE_MBSFN_SubframeConfigList_t *) NULL
#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
    , 0, (LTE_MBSFN_AreaInfoList_r9_t *) NULL, (LTE_PMCH_InfoList_r9_t *) NULL
5451
#endif
5452
#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
Cedric Roux's avatar
Cedric Roux committed
5453
    ,
5454
    (LTE_SystemInformationBlockType1_v1310_IEs_t *)NULL
5455
#endif
Cedric Roux's avatar
Cedric Roux committed
5456
  );
5457 5458 5459
//#if 0
//}
//#endif
5460 5461 5462
}

//-----------------------------------------------------------------------------
Cedric Roux's avatar
Cedric Roux committed
5463
/*
5464
* Process the RRC Connection Reconfiguration Complete from the UE
Cedric Roux's avatar
Cedric Roux committed
5465
*/
5466
void
Cedric Roux's avatar
Cedric Roux committed
5467
rrc_eNB_process_RRCConnectionReconfigurationComplete(
Cedric Roux's avatar
Cedric Roux committed
5468
  const protocol_ctxt_t *const ctxt_pP,
5469
  rrc_eNB_ue_context_t  *ue_context_pP,
Cedric Roux's avatar
Cedric Roux committed
5470
  const uint8_t xid
5471 5472 5473
)
//-----------------------------------------------------------------------------
{
OAI-admin's avatar
OAI-admin committed
5474
  int                                 drb_id;
Cedric Roux's avatar
Cedric Roux committed
5475 5476 5477 5478 5479
  int                                 oip_ifup = 0;
  int                                 dest_ip_offset = 0;
  uint8_t                            *kRRCenc = NULL;
  uint8_t                            *kRRCint = NULL;
  uint8_t                            *kUPenc = NULL;
5480 5481 5482 5483 5484
  LTE_DRB_ToAddModList_t             *DRB_configList = ue_context_pP->ue_context.DRB_configList2[xid];
  LTE_SRB_ToAddModList_t             *SRB_configList = ue_context_pP->ue_context.SRB_configList2[xid];
  LTE_DRB_ToReleaseList_t            *DRB_Release_configList2 = ue_context_pP->ue_context.DRB_Release_configList2[xid];
  LTE_DRB_Identity_t                 *drb_id_p      = NULL;

Cedric Roux's avatar
Cedric Roux committed
5485
  ue_context_pP->ue_context.ue_reestablishment_timer = 0;
5486 5487
  ue_context_pP->ue_context.ue_rrc_inactivity_timer = 1; // reset rrc inactivity timer

5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498
  if (!NODE_IS_CU(RC.rrc[ctxt_pP->module_id]->node_type)) {
    /* CDRX: activated if ack was expected */
    int UE_id_mac = find_UE_id(ctxt_pP->module_id, ue_context_pP->ue_context.rnti);
    UE_sched_ctrl *UE_scheduling_control = &(RC.mac[ctxt_pP->module_id]->UE_list.UE_sched_ctrl[UE_id_mac]);
    
    if (UE_scheduling_control->cdrx_waiting_ack == TRUE) {
      UE_scheduling_control->cdrx_waiting_ack = FALSE;
      UE_scheduling_control->cdrx_configured = TRUE;
      LOG_I(RRC, "CDRX configuration activated after RRC Connection Reconfiguration Complete reception\n");
    }
  } // No CDRX with the CU/DU split in this version of the code
5499 5500 5501 5502 5503 5504

  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));
Lionel Gauthier's avatar
 
Lionel Gauthier committed
5505

Cedric Roux's avatar
Cedric Roux committed
5506 5507 5508
  /* Derive the keys from kenb */
  if (DRB_configList != NULL) {
    derive_key_up_enc(ue_context_pP->ue_context.ciphering_algorithm,
5509 5510
                      ue_context_pP->ue_context.kenb,
                      &kUPenc);
5511
  }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
5512

Cedric Roux's avatar
Cedric Roux committed
5513
  derive_key_rrc_enc(ue_context_pP->ue_context.ciphering_algorithm,
5514 5515 5516
                     ue_context_pP->ue_context.kenb,
                     &kRRCenc);

Cedric Roux's avatar
Cedric Roux committed
5517
  derive_key_rrc_int(ue_context_pP->ue_context.integrity_algorithm,
5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533
                     ue_context_pP->ue_context.kenb,
                     &kRRCint);

  /* Refresh SRBs/DRBs */
  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);

  rrc_pdcp_config_asn1_req(ctxt_pP,
                          SRB_configList, // NULL,
                          DRB_configList,
                          DRB_Release_configList2,
                          0xff, // already configured during the securitymodecommand
                          kRRCenc,
                          kRRCint,
                          kUPenc
Cedric Roux's avatar
Cedric Roux committed
5534
#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
5535
                          , (LTE_PMCH_InfoList_r9_t *) NULL
Cedric Roux's avatar
Cedric Roux committed
5536
#endif
5537 5538 5539 5540 5541 5542 5543
                          , NULL);

  /* Refresh SRBs/DRBs */
  rrc_rlc_config_asn1_req(ctxt_pP,
                          SRB_configList, // NULL,
                          DRB_configList,
                          DRB_Release_configList2
Cedric Roux's avatar
Cedric Roux committed
5544
#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
5545 5546 5547
                          , (LTE_PMCH_InfoList_r9_t *) NULL,
                          0,
                          0
Cedric Roux's avatar
Cedric Roux committed
5548
#endif
5549
                          );
5550

5551
  /* Set the SRB active in UE context */
Cedric Roux's avatar
Cedric Roux committed
5552
  if (SRB_configList != NULL) {
5553 5554 5555 5556 5557 5558
    for (int 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;
Cedric Roux's avatar
Cedric Roux committed
5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569
        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 {
        LOG_W(RRC,"[eNB %d] Frame  %d CC %d : invalide SRB identity %ld\n",
              ctxt_pP->module_id,
              ctxt_pP->frame,
              ue_context_pP->ue_context.primaryCC_id,
              SRB_configList->list.array[i]->srb_Identity);
      }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
5570
    }
Cedric Roux's avatar
Cedric Roux committed
5571 5572 5573

    free(SRB_configList);
    ue_context_pP->ue_context.SRB_configList2[xid] = NULL;
5574
  }
Cedric Roux's avatar
Cedric Roux committed
5575

5576
  /* Loop through DRBs and establish if necessary */
5577
  if (DRB_configList != NULL) {
5578
    for (int i = 0; i < DRB_configList->list.count; i++) {  // num max DRB (11-3-8)
5579
      if (DRB_configList->list.array[i]) {
Cedric Roux's avatar
Cedric Roux committed
5580
        drb_id = (int)DRB_configList->list.array[i]->drb_Identity;
5581 5582

        LOG_I(RRC, "[eNB %d] Frame  %d : Logical Channel UL-DCCH, Received LTE_RRCConnectionReconfigurationComplete from UE rnti %x, reconfiguring DRB %d/LCID %d\n",
5583 5584 5585 5586 5587
              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);
5588 5589 5590

        /* For pre-ci tests */
        LOG_I(RRC, "[eNB %d] Frame  %d : Logical Channel UL-DCCH, Received LTE_RRCConnectionReconfigurationComplete from UE %u, reconfiguring DRB %d/LCID %d\n",
5591 5592 5593
              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],
5594
              (int)DRB_configList->list.array[i]->drb_Identity,
5595
              (int)*DRB_configList->list.array[i]->logicalChannelIdentity);
5596

5597 5598
        if (ue_context_pP->ue_context.DRB_active[drb_id] == 0) {
          ue_context_pP->ue_context.DRB_active[drb_id] = 1;
5599
          LOG_D(RRC, "[eNB %d] Frame %d: Establish RLC UM Bidirectional, DRB %d Active\n",
5600
                ctxt_pP->module_id, ctxt_pP->frame, (int)DRB_configList->list.array[i]->drb_Identity);
5601

5602
          if (!EPC_MODE_ENABLED && !ENB_NAS_USE_TUN) {
5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628
            LOG_I(OIP, "[eNB %d] trying to bring up the OAI interface oai%d\n",
                  ctxt_pP->module_id,
                  ctxt_pP->module_id);

            oip_ifup = nas_config(ctxt_pP->module_id,   // interface index
                                  ctxt_pP->module_id + 1,   // third octet
                                  ctxt_pP->module_id + 1,   // fourth octet
                                  "oai");

            if (oip_ifup == 0) { // interface is up --> send a config the DRB
              module_id_t ue_module_id;
              dest_ip_offset = 8;
              LOG_I(OIP,
                    "[eNB %d] Config the oai%d to send/receive pkt on DRB %ld to/from the protocol stack\n",
                    ctxt_pP->module_id, ctxt_pP->module_id,
                      (long int)((ue_context_pP->local_uid * LTE_maxDRB) + DRB_configList->list.array[i]->drb_Identity));
              ue_module_id = oai_emulation.info.eNB_ue_local_uid_to_ue_module_id[ctxt_pP->module_id][ue_context_pP->local_uid];
              rb_conf_ipv4(0, //add
                          ue_module_id,  //cx
                          ctxt_pP->module_id,    //inst
                            (ue_module_id * LTE_maxDRB) + DRB_configList->list.array[i]->drb_Identity, // RB
                          0,    //dscp
                          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);
5629 5630
            } /* oip_ifup */
          } /* !EPC_MODE_ENABLED && ENB_NAS_USE_TUN*/
5631

5632
          LOG_D(RRC,
5633 5634
                PROTOCOL_RRC_CTXT_UE_FMT" RRC_eNB --- MAC_CONFIG_REQ  (DRB) ---> MAC_eNB\n",
                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
5635

5636
          if (DRB_configList->list.array[i]->logicalChannelIdentity) {
5637
            DRB2LCHAN[i] = (uint8_t) * DRB_configList->list.array[i]->logicalChannelIdentity;
5638
          }
5639

5640 5641 5642 5643 5644 5645 5646 5647
	        if (NODE_IS_MONOLITHIC(RC.rrc[ctxt_pP->module_id]->node_type)) {
            rrc_mac_config_req_eNB(ctxt_pP->module_id,
                                   ue_context_pP->ue_context.primaryCC_id,
                                   0,
                                   0,
                                   0,
                                   0,
                                   0,
5648
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
5649
                                   0,
5650
#endif
5651 5652 5653
                                   ue_context_pP->ue_context.rnti,
                                   (LTE_BCCH_BCH_Message_t *) NULL,
                                   (LTE_RadioResourceConfigCommonSIB_t *) NULL,
5654
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
5655
                                   (LTE_RadioResourceConfigCommonSIB_t *) NULL,
5656
#endif
5657
                                   ue_context_pP->ue_context.physicalConfigDedicated,
5658
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
5659
                                   (LTE_SCellToAddMod_r10_t *)NULL,
5660
#endif
5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672
                                   (LTE_MeasObjectToAddMod_t **) NULL,
                                   ue_context_pP->ue_context.mac_MainConfig,
                                   DRB2LCHAN[i],
                                   DRB_configList->list.array[i]->logicalChannelConfig,
                                   ue_context_pP->ue_context.measGapConfig,
                                   (LTE_TDD_Config_t *) NULL,
                                   NULL,
                                   (LTE_SchedulingInfoList_t *) NULL,
                                   0,
                                   NULL,
                                   NULL,
                                   (LTE_MBSFN_SubframeConfigList_t *) NULL
5673
#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
5674 5675 5676
                                   , 0,
                                   (LTE_MBSFN_AreaInfoList_r9_t *) NULL,
                                   (LTE_PMCH_InfoList_r9_t *) NULL
winckel's avatar
winckel committed
5677
#endif
5678
#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
5679 5680
                                   ,
                                   (LTE_SystemInformationBlockType1_v1310_IEs_t *) NULL
5681
#endif
5682 5683 5684 5685
                                   );
          }
        } else { // end if (ue_context_pP->ue_context.DRB_active[drb_id] == 0) // remove LCHAN from MAC/PHY
          if (ue_context_pP->ue_context.DRB_active[drb_id] == 1) {
5686
            // DRB has just been removed so remove RLC + PDCP for DRB
5687
            /*      rrc_pdcp_config_req (ctxt_pP->module_id, frameP, 1, CONFIG_ACTION_REMOVE,
5688 5689
               (ue_mod_idP * NB_RB_MAX) + DRB2LCHAN[i],UNDEF_SECURITY_MODE);
             */
5690 5691 5692 5693 5694 5695 5696 5697
            if (!NODE_IS_CU(RC.rrc[ctxt_pP->module_id]->node_type)) {
              rrc_rlc_config_req(ctxt_pP,
                                SRB_FLAG_NO,
                                MBMS_FLAG_NO,
                                CONFIG_ACTION_REMOVE,
                                DRB2LCHAN[i],
                                Rlc_info_um);
            }
5698 5699
          }

5700
          ue_context_pP->ue_context.DRB_active[drb_id] = 0;
5701 5702

          LOG_D(RRC, PROTOCOL_RRC_CTXT_UE_FMT" RRC_eNB --- MAC_CONFIG_REQ  (DRB) ---> MAC_eNB\n",
5703
                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
5704
          if (NODE_IS_MONOLITHIC(RC.rrc[ctxt_pP->module_id]->node_type)) {
5705 5706
            rrc_mac_config_req_eNB(ctxt_pP->module_id,
                                   ue_context_pP->ue_context.primaryCC_id,
5707 5708 5709 5710 5711
                                   0,
                                   0,
                                   0,
                                   0,
                                   0,
5712
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
5713
                                   0,
5714
#endif
5715 5716 5717
                                   ue_context_pP->ue_context.rnti,
                                   (LTE_BCCH_BCH_Message_t *) NULL,
                                   (LTE_RadioResourceConfigCommonSIB_t *) NULL,
5718
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
5719
                                   (LTE_RadioResourceConfigCommonSIB_t *) NULL,
5720
#endif
5721
                                   ue_context_pP->ue_context.physicalConfigDedicated,
5722
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
5723
                                   (LTE_SCellToAddMod_r10_t *) NULL,
5724 5725 5726 5727 5728 5729 5730 5731 5732
#endif
                                   (LTE_MeasObjectToAddMod_t **) NULL,
                                   ue_context_pP->ue_context.mac_MainConfig,
                                   DRB2LCHAN[i],
                                   (LTE_LogicalChannelConfig_t *) NULL,
                                   (LTE_MeasGapConfig_t *) NULL,
                                   (LTE_TDD_Config_t *) NULL,
                                   NULL,
                                   (LTE_SchedulingInfoList_t *) NULL,
5733 5734 5735 5736
                                   0,
                                   NULL,
                                   NULL,
                                   NULL
5737
#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
5738 5739 5740 5741
                                   ,
                                   0,
                                   (LTE_MBSFN_AreaInfoList_r9_t *) NULL,
                                   (LTE_PMCH_InfoList_r9_t *) NULL
winckel's avatar
winckel committed
5742
#endif
5743
#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
5744
                                   ,
5745
                                   (LTE_SystemInformationBlockType1_v1310_IEs_t *) NULL
5746
#endif
5747
                                   );
5748
          }
5749 5750 5751 5752
        } // end else of if (ue_context_pP->ue_context.DRB_active[drb_id] == 0)
      } // end if (DRB_configList->list.array[i])
    } // end for (int i = 0; i < DRB_configList->list.count; i++)

5753
    free(DRB_configList);
5754
    ue_context_pP->ue_context.DRB_configList2[xid] = NULL;
5755
  } // end if DRB_configList != NULL
5756

Cedric Roux's avatar
Cedric Roux committed
5757
  if(DRB_Release_configList2 != NULL) {
5758
    for (int i = 0; i < DRB_Release_configList2->list.count; i++) {
Cedric Roux's avatar
Cedric Roux committed
5759 5760 5761 5762 5763 5764 5765
      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;
        }
5766
      }
Cedric Roux's avatar
Cedric Roux committed
5767 5768 5769 5770
    }

    free(DRB_Release_configList2);
    ue_context_pP->ue_context.DRB_Release_configList2[xid] = NULL;
5771
  }
winckel's avatar
winckel committed
5772
}
5773

5774
//-----------------------------------------------------------------------------
5775 5776 5777 5778 5779 5780
void
rrc_eNB_generate_RRCConnectionSetup(
  const protocol_ctxt_t *const ctxt_pP,
  rrc_eNB_ue_context_t  *const ue_context_pP,
  const int                    CC_id
)
5781
//-----------------------------------------------------------------------------
5782
{
5783
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
Ahmed.Elias's avatar
Ahmed.Elias committed
5784 5785
  boolean_t is_mtc = ctxt_pP->brOption;
#endif
5786 5787 5788
  LTE_LogicalChannelConfig_t             *SRB1_logicalChannelConfig;  //,*SRB2_logicalChannelConfig;
  LTE_SRB_ToAddModList_t                **SRB_configList;
  LTE_SRB_ToAddMod_t                     *SRB1_config;
5789 5790

  MessageDef                             *message_p;
5791
     
5792 5793 5794 5795 5796
  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));
Cedric Roux's avatar
Cedric Roux committed
5797

5798 5799
  eNB_RRC_UE_t *ue_p = &ue_context_pP->ue_context; 
  SRB_configList = &ue_p->SRB_configList;
5800

5801
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
5802

5803
  if (is_mtc) {
5804
    ue_p->Srb0.Tx_buffer.payload_size =
5805
      do_RRCConnectionSetup_BR(ctxt_pP,
5806 5807 5808 5809 5810 5811 5812
                                ue_context_pP,
                                CC_id,
                                (uint8_t *) ue_p->Srb0.Tx_buffer.Payload,
                                (const 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);
5813
  } else
Ahmed.Elias's avatar
Ahmed.Elias committed
5814 5815
#endif
  {
5816
    ue_p->Srb0.Tx_buffer.payload_size =
5817
      do_RRCConnectionSetup(ctxt_pP,
5818 5819 5820 5821 5822 5823 5824
                            ue_context_pP,
                            CC_id,
                            (uint8_t*) ue_p->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);
5825
  }
5826 5827 5828 5829
  LOG_DUMPMSG(RRC,DEBUG_RRC,
              (char *)(ue_p->Srb0.Tx_buffer.Payload),
              ue_p->Srb0.Tx_buffer.payload_size,
              "[MSG] RRC Connection Setup\n");
5830

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

5841
      F1AP_DL_RRC_MESSAGE (message_p).rrc_container_length = ue_p->Srb0.Tx_buffer.payload_size;
5842
      F1AP_DL_RRC_MESSAGE (message_p).gNB_CU_ue_id     = 0;  
5843 5844
      F1AP_DL_RRC_MESSAGE (message_p).gNB_DU_ue_id = 0;
      F1AP_DL_RRC_MESSAGE (message_p).old_gNB_DU_ue_id  = 0xFFFFFFFF; // unknown 
5845
      F1AP_DL_RRC_MESSAGE (message_p).rnti = ue_p->rnti; 
5846 5847 5848
      F1AP_DL_RRC_MESSAGE (message_p).srb_id = CCCH;  
      F1AP_DL_RRC_MESSAGE (message_p).execute_duplication      = 1;
      F1AP_DL_RRC_MESSAGE (message_p).RAT_frequency_priority_information.en_dc      = 0; 
5849
      itti_send_msg_to_task (TASK_CU_F1, ctxt_pP->module_id, message_p);
Bing-Kai Hong's avatar
Bing-Kai Hong committed
5850
      LOG_D(RRC, "Send F1AP_DL_RRC_MESSAGE with ITTI\n");
5851 5852 5853 5854
      break;
    case ngran_eNB_DU    :
    case ngran_gNB_DU  :
      // nothing to do for DU 
5855
      AssertFatal(1==0,"nothing to do for DU\n");
5856
      break;
5857 5858 5859 5860
    case ngran_eNB:   
    case ngran_ng_eNB :
    case ngran_gNB  :  
  
5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883
      if (*SRB_configList != NULL) {
        for (int 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 ==
                  LTE_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,
                PROTOCOL_RRC_CTXT_UE_FMT" RRC_eNB --- MAC_CONFIG_REQ  (SRB1) ---> MAC_eNB\n",
                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
            if (RC.rrc[ctxt_pP->module_id]->node_type == ngran_eNB) {
             rrc_mac_config_req_eNB(ctxt_pP->module_id,
                                  ue_context_pP->ue_context.primaryCC_id,
                                  0,0,0,0,0,
5884
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
5885
                                   0,
5886
#endif
5887 5888 5889
                                  ue_context_pP->ue_context.rnti,
                                  (LTE_BCCH_BCH_Message_t *) NULL,
                                  (LTE_RadioResourceConfigCommonSIB_t *) NULL,
5890
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
5891
                                  (LTE_RadioResourceConfigCommonSIB_t *) NULL,
5892
#endif
5893
                                  ue_context_pP->ue_context.physicalConfigDedicated,
5894
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
5895 5896
                                   (LTE_SCellToAddMod_r10_t *)NULL,
                                  //(struct LTE_PhysicalConfigDedicatedSCell_r10 *)NULL,
5897
#endif
5898 5899 5900 5901 5902 5903 5904 5905 5906
                                  (LTE_MeasObjectToAddMod_t **) NULL,
                                  ue_context_pP->ue_context.mac_MainConfig,
                                  1,
                                  SRB1_logicalChannelConfig,
                                  ue_context_pP->ue_context.measGapConfig,
                                  (LTE_TDD_Config_t *) NULL,
                                  NULL,
                                  (LTE_SchedulingInfoList_t *) NULL,
                                  0, NULL, NULL, (LTE_MBSFN_SubframeConfigList_t *) NULL
5907
#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
5908
                                  , 0, (LTE_MBSFN_AreaInfoList_r9_t *) NULL, (LTE_PMCH_InfoList_r9_t *) NULL
winckel's avatar
winckel committed
5909
#endif
5910
#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
5911 5912
                                   ,
                                  (LTE_SystemInformationBlockType1_v1310_IEs_t *)NULL
5913
#endif
5914 5915
          );
        }
5916
      }
winckel's avatar
winckel committed
5917
    }
5918

5919 5920
    break;
  default :
5921 5922 5923
    LOG_W(RRC, "Unknown node type %d\n", RC.rrc[ctxt_pP->module_id]->node_type);		
  }
  
5924
  MSC_LOG_TX_MESSAGE(
5925 5926
    MSC_RRC_ENB,
    MSC_RRC_UE,
5927 5928
    ue_p->Srb0.Tx_buffer.Header, // LG WARNING
    ue_p->Srb0.Tx_buffer.payload_size,
5929 5930 5931
    MSC_AS_TIME_FMT" RRCConnectionSetup UE %x size %u",
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP->ue_context.rnti,
5932
    ue_p->Srb0.Tx_buffer.payload_size);
5933

5934 5935

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

5940
     // activate release timer, if RRCSetupComplete not received after 100 frames, remove UE
5941 5942 5943 5944 5945 5946
    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;

  /* init timers */
  ue_context_pP->ue_context.ue_rrc_inactivity_timer = 0;
5947
  }
winckel's avatar
winckel committed
5948
}
5949

5950 5951 5952 5953
void setup_ngran_CU(eNB_RRC_INST *rrc) {

  
}
Lionel Gauthier's avatar
 
Lionel Gauthier committed
5954

5955
//-----------------------------------------------------------------------------
5956
char openair_rrc_eNB_configuration(
5957 5958
  const module_id_t enb_mod_idP,
  RrcConfigurationReq *configuration
5959 5960
)
//-----------------------------------------------------------------------------
winckel's avatar
winckel committed
5961
{
5962
  protocol_ctxt_t ctxt;
5963
  int             CC_id;
5964
  PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, enb_mod_idP, ENB_FLAG_YES, NOT_A_RNTI, 0, 0,enb_mod_idP);
5965 5966 5967
  LOG_I(RRC,
        PROTOCOL_RRC_CTXT_FMT" Init...\n",
        PROTOCOL_RRC_CTXT_ARGS(&ctxt));
laurent's avatar
laurent committed
5968
#if OCP_FRAMEWORK
Cedric Roux's avatar
Cedric Roux committed
5969

5970 5971 5972 5973
  while ( RC.rrc[enb_mod_idP] == NULL ) {
    LOG_E(RRC, "RC.rrc not yet initialized, waiting 1 second\n");
    sleep(1);
  }
Cedric Roux's avatar
Cedric Roux committed
5974 5975

#endif
5976
  AssertFatal(RC.rrc[enb_mod_idP] != NULL, "RC.rrc not initialized!");
5977
  AssertFatal(MAX_MOBILES_PER_ENB < (module_id_t)0xFFFFFFFFFFFFFFFF, " variable overflow");
5978
  AssertFatal(configuration!=NULL,"configuration input is null\n");
5979
  RC.rrc[ctxt.module_id]->Nb_ue = 0;
5980

5981 5982 5983
  pthread_mutex_init(&RC.rrc[ctxt.module_id]->cell_info_mutex,NULL);
  RC.rrc[ctxt.module_id]->cell_info_configured = 0;

5984 5985
  uid_linear_allocator_init(&RC.rrc[ctxt.module_id]->uid_allocator);
  RB_INIT(&RC.rrc[ctxt.module_id]->rrc_ue_head);
5986
  //    for (j = 0; j < (MAX_MOBILES_PER_ENB + 1); j++) {
5987
  //        RC.rrc[enb_mod_idP]->Srb2[j].Active = 0;
5988
  //    }
5989 5990
  RC.rrc[ctxt.module_id]->initial_id2_s1ap_ids = hashtable_create (MAX_MOBILES_PER_ENB * 2, NULL, NULL);
  RC.rrc[ctxt.module_id]->s1ap_id2_s1ap_ids    = hashtable_create (MAX_MOBILES_PER_ENB * 2, NULL, NULL);
5991

5992
  /// System Information INIT
5993 5994
  LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Checking release \n",
        PROTOCOL_RRC_CTXT_ARGS(&ctxt));
5995
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
5996 5997
  // can clear it at runtime
  RC.rrc[ctxt.module_id]->carrier[0].MBMS_flag = 0;
5998
  // This has to come from some top-level configuration
5999
  // only CC_id 0 is logged
6000
#if (LTE_RRC_VERSION < MAKE_VERSION(10, 0, 0))
6001
  LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Rel10 RRC detected, MBMS flag %d\n",
Cedric Roux's avatar
Cedric Roux committed
6002 6003 6004
#else
  LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Rel14 RRC detected, MBMS flag %d\n",
#endif
6005
        PROTOCOL_RRC_CTXT_ARGS(&ctxt),
6006
        RC.rrc[ctxt.module_id]->carrier[0].MBMS_flag);
winckel's avatar
winckel committed
6007
#else
6008
  LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Rel8 RRC\n", PROTOCOL_RRC_CTXT_ARGS(&ctxt));
winckel's avatar
winckel committed
6009 6010
#endif
#ifdef CBA
6011

6012 6013
  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
    for (j = 0; j < NUM_MAX_CBA_GROUP; j++) {
6014
      RC.rrc[ctxt.module_id]->carrier[CC_id].cba_rnti[j] = CBA_OFFSET + j;
6015
    }
6016

6017 6018
    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;
6019
    }
6020

6021 6022 6023
    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),
6024 6025 6026 6027 6028
          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);
6029
  }
winckel's avatar
winckel committed
6030
#endif
6031

6032
  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
6033
    init_SI(&ctxt, CC_id, configuration);
Cedric Roux's avatar
Cedric Roux committed
6034

6035
    for (int ue_id = 0; ue_id < MAX_MOBILES_PER_ENB; ue_id++) {
Cedric Roux's avatar
Cedric Roux committed
6036 6037
      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);
6038
    }
6039
  }
6040 6041
  rrc_init_global_param();

6042
  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
6043
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
6044 6045

    switch (RC.rrc[ctxt.module_id]->carrier[CC_id].MBMS_flag) {
Cedric Roux's avatar
Cedric Roux committed
6046 6047 6048 6049 6050 6051
      case 1:
      case 2:
      case 3:
        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Configuring 1 MBSFN sync area\n", PROTOCOL_RRC_CTXT_ARGS(&ctxt));
        RC.rrc[ctxt.module_id]->carrier[CC_id].num_mbsfn_sync_area = 1;
        break;
6052

Cedric Roux's avatar
Cedric Roux committed
6053 6054 6055 6056
      case 4:
        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Configuring 2 MBSFN sync area\n", PROTOCOL_RRC_CTXT_ARGS(&ctxt));
        RC.rrc[ctxt.module_id]->carrier[CC_id].num_mbsfn_sync_area = 2;
        break;
6057

Cedric Roux's avatar
Cedric Roux committed
6058 6059 6060
      default:
        RC.rrc[ctxt.module_id]->carrier[CC_id].num_mbsfn_sync_area = 0;
        break;
6061 6062
    }

6063
    // if we are here the RC.rrc[enb_mod_idP]->MBMS_flag > 0,
6064
    /// MCCH INIT
6065
    if (RC.rrc[ctxt.module_id]->carrier[CC_id].MBMS_flag > 0) {
6066 6067 6068 6069
      init_MCCH(ctxt.module_id, CC_id);
      /// MTCH data bearer init
      init_MBMS(ctxt.module_id, CC_id, 0);
    }
6070

Cedric Roux's avatar
Cedric Roux committed
6071
#endif
6072 6073
    openair_rrc_top_init_eNB(RC.rrc[ctxt.module_id]->carrier[CC_id].MBMS_flag,0);
  }
6074
	
6075
  openair_rrc_on(&ctxt);
6076 6077 6078 6079 6080 6081 6082 6083 6084

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

  LOG_W(RRC, "[inst %d] RRC->MCC/MSG->MCC %d/%d \n", ctxt.module_id, RC.rrc[ctxt.module_id]->mcc, rrc_configuration_req->mcc);
  */
6085
  if (NODE_IS_CU(RC.rrc[ctxt.module_id]->node_type))
6086 6087
  	// msg_p = itti_alloc_new_message (TASK_ENB_APP, F1AP_SCTP_REQ);
    // RCconfig_CU_F1(msg_p, enb_id);
6088 6089
    setup_ngran_CU(RC.rrc[ctxt.module_id]);
	
6090
  return 0;
winckel's avatar
winckel committed
6091
}
6092

winckel's avatar
winckel committed
6093
/*------------------------------------------------------------------------------*/
6094 6095 6096
int
rrc_eNB_decode_ccch(
  protocol_ctxt_t* const ctxt_pP,
Robert Schmidt's avatar
Robert Schmidt committed
6097
  const uint8_t          *buffer,
6098
  int                    buffer_length,
6099
  const int              CC_id
6100 6101
)
//-----------------------------------------------------------------------------
6102
{
6103 6104 6105
  module_id_t                                       Idx;
  asn_dec_rval_t                                    dec_rval;
  LTE_UL_CCCH_Message_t                             *ul_ccch_msg = NULL;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6106 6107
  LTE_RRCConnectionRequest_r8_IEs_t                *rrcConnectionRequest = NULL;
  LTE_RRCConnectionReestablishmentRequest_r8_IEs_t *rrcConnectionReestablishmentRequest = NULL;
6108
  int                                 i, rval;
Cedric Roux's avatar
Cedric Roux committed
6109
  struct rrc_eNB_ue_context_s                  *ue_context_p = NULL;
6110
  uint64_t                                      random_value = 0;
6111
  int                                           stmsi_received = 0;
Cedric Roux's avatar
Cedric Roux committed
6112 6113
  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));
6114
  //memset(ul_ccch_msg,0,sizeof(UL_CCCH_Message_t));
6115
  LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Decoding UL CCCH %x.%x.%x.%x.%x.%x (%p)\n",
6116
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
6117 6118 6119 6120 6121 6122
        ((uint8_t*) buffer)[0],
        ((uint8_t *) buffer)[1],
        ((uint8_t *) buffer)[2],
        ((uint8_t *) buffer)[3],
        ((uint8_t *) buffer)[4],
        ((uint8_t *) buffer)[5], (uint8_t *) buffer);
6123 6124
  dec_rval = uper_decode(
               NULL,
6125
               &asn_DEF_LTE_UL_CCCH_Message,
Cedric Roux's avatar
Cedric Roux committed
6126
               (void **)&ul_ccch_msg,
6127
               (uint8_t *) buffer,
6128 6129 6130
               100,
               0,
               0);
6131

6132
  for (i = 0; i < 8; i++) {
6133
    LOG_T(RRC, "%x.", ((uint8_t *) & ul_ccch_msg)[i]);
6134
  }
6135 6136

  if (dec_rval.consumed == 0) {
6137 6138 6139
    LOG_E(RRC,
          PROTOCOL_RRC_CTXT_UE_FMT" FATAL Error in receiving CCCH\n",
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
6140 6141 6142
    return -1;
  }

6143
  if (ul_ccch_msg->message.present == LTE_UL_CCCH_MessageType_PR_c1) {
6144
    switch (ul_ccch_msg->message.choice.c1.present) {
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6145
      case LTE_UL_CCCH_MessageType__c1_PR_NOTHING:
Cedric Roux's avatar
Cedric Roux committed
6146 6147 6148 6149
        LOG_I(RRC,
              PROTOCOL_RRC_CTXT_FMT" Received PR_NOTHING on UL-CCCH-Message\n",
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
        break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
6150

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6151
      case LTE_UL_CCCH_MessageType__c1_PR_rrcConnectionReestablishmentRequest:
Cedric Roux's avatar
Cedric Roux committed
6152 6153
        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));
6154
        LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)(buffer), buffer_length,
Cedric Roux's avatar
Cedric Roux committed
6155 6156 6157 6158 6159 6160 6161
                    "[MSG] RRC Connection Reestablishment Request\n");
        LOG_D(RRC,
              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,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6162
              PROTOCOL_RRC_CTXT_UE_FMT" LTE_RRCConnectionReestablishmentRequest cause %s\n",
Cedric Roux's avatar
Cedric Roux committed
6163
              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6164 6165
              ((rrcConnectionReestablishmentRequest->reestablishmentCause == LTE_ReestablishmentCause_otherFailure) ?    "Other Failure" :
               (rrcConnectionReestablishmentRequest->reestablishmentCause == LTE_ReestablishmentCause_handoverFailure) ? "Handover Failure" :
Cedric Roux's avatar
Cedric Roux committed
6166 6167 6168
               "reconfigurationFailure"));
        {
          uint16_t                          c_rnti = 0;
Cedric Roux's avatar
Cedric Roux committed
6169

Cedric Roux's avatar
Cedric Roux committed
6170 6171
          if (rrcConnectionReestablishmentRequest->ue_Identity.physCellId != RC.rrc[ctxt_pP->module_id]->carrier[CC_id].physCellId) {
            LOG_E(RRC,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6172
                  PROTOCOL_RRC_CTXT_UE_FMT" LTE_RRCConnectionReestablishmentRequest ue_Identity.physCellId(%ld) is not equal to current physCellId(%d), let's reject the UE\n",
Cedric Roux's avatar
Cedric Roux committed
6173 6174 6175 6176 6177 6178
                  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;
          }
6179

Cedric Roux's avatar
Cedric Roux committed
6180
          LOG_D(RRC, "physCellId is %ld\n", rrcConnectionReestablishmentRequest->ue_Identity.physCellId);
6181

Cedric Roux's avatar
Cedric Roux committed
6182 6183 6184 6185
          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]);
          }
6186

Cedric Roux's avatar
Cedric Roux committed
6187 6188 6189
          if (rrcConnectionReestablishmentRequest->ue_Identity.c_RNTI.size == 0 ||
              rrcConnectionReestablishmentRequest->ue_Identity.c_RNTI.size > 2) {
            LOG_E(RRC,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6190
                  PROTOCOL_RRC_CTXT_UE_FMT" LTE_RRCConnectionReestablishmentRequest c_RNTI range error, let's reject the UE\n",
Cedric Roux's avatar
Cedric Roux committed
6191 6192 6193 6194
                  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
            rrc_eNB_generate_RRCConnectionReestablishmentReject(ctxt_pP, ue_context_p, CC_id);
            break;
          }
6195

Cedric Roux's avatar
Cedric Roux committed
6196 6197 6198
          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);
6199

Cedric Roux's avatar
Cedric Roux committed
6200 6201
          if (ue_context_p == NULL) {
            LOG_E(RRC,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6202
                  PROTOCOL_RRC_CTXT_UE_FMT" LTE_RRCConnectionReestablishmentRequest without UE context, let's reject the UE\n",
Cedric Roux's avatar
Cedric Roux committed
6203 6204 6205 6206
                  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
            rrc_eNB_generate_RRCConnectionReestablishmentReject(ctxt_pP, ue_context_p, CC_id);
            break;
          }
6207

Cedric Roux's avatar
Cedric Roux committed
6208
          int UE_id = find_UE_id(ctxt_pP->module_id, c_rnti);
6209

Cedric Roux's avatar
Cedric Roux committed
6210 6211
          if(UE_id == -1) {
            LOG_E(RRC,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6212
                  PROTOCOL_RRC_CTXT_UE_FMT" LTE_RRCConnectionReestablishmentRequest without UE_id(MAC) rnti %x, let's reject the UE\n",
Cedric Roux's avatar
Cedric Roux committed
6213 6214 6215 6216
                  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),c_rnti);
            rrc_eNB_generate_RRCConnectionReestablishmentReject(ctxt_pP, ue_context_p, CC_id);
            break;
          }
6217

Cedric Roux's avatar
Cedric Roux committed
6218 6219 6220 6221 6222 6223 6224 6225
          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;
          }
6226

Cedric Roux's avatar
Cedric Roux committed
6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241
          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);
6242

Cedric Roux's avatar
Cedric Roux committed
6243 6244 6245 6246 6247 6248 6249 6250
            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;
              }
            }
          }
6251

Cedric Roux's avatar
Cedric Roux committed
6252 6253 6254 6255 6256 6257 6258
          LOG_D(RRC,
                PROTOCOL_RRC_CTXT_UE_FMT" UE context: %p\n",
                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
                ue_context_p);
          /* reset timers */
          ue_context_p->ue_context.ul_failure_timer = 0;
          ue_context_p->ue_context.ue_release_timer = 0;
6259
          ue_context_p->ue_context.ue_reestablishment_timer = 0;
Cedric Roux's avatar
Cedric Roux committed
6260 6261 6262
          ue_context_p->ue_context.ue_release_timer_s1 = 0;
          ue_context_p->ue_context.ue_release_timer_rrc = 0;
          ue_context_p->ue_context.reestablishment_xid = -1;
6263

Cedric Roux's avatar
Cedric Roux committed
6264 6265 6266 6267 6268 6269
          // insert C-RNTI to map
          for (i = 0; i < MAX_MOBILES_PER_ENB; i++) {
            if (reestablish_rnti_map[i][0] == 0) {
              reestablish_rnti_map[i][0] = ctxt_pP->rnti;
              reestablish_rnti_map[i][1] = c_rnti;
              break;
6270 6271
            }
          }
6272

Cedric Roux's avatar
Cedric Roux committed
6273 6274 6275 6276 6277 6278 6279
          LOG_D(RRC, "reestablish_rnti_map[%d] [0] %x, [1] %x\n",
                i, reestablish_rnti_map[i][0], reestablish_rnti_map[i][1]);
          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);
6280
#ifndef NO_RRM
Cedric Roux's avatar
Cedric Roux committed
6281
          send_msg(&S_rrc, msg_rrc_MR_attach_ind(ctxt_pP->module_id, Mac_id));
6282
#else
Cedric Roux's avatar
Cedric Roux committed
6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316
          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,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6317 6318
                                   (LTE_DRB_ToAddModList_t *) NULL,
                                   (LTE_DRB_ToReleaseList_t *) NULL,
Cedric Roux's avatar
Cedric Roux committed
6319 6320 6321 6322
                                   0xff,
                                   NULL,
                                   NULL,
                                   NULL
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6323
                                   , (LTE_PMCH_InfoList_r9_t *) NULL
Cedric Roux's avatar
Cedric Roux committed
6324
                                   ,NULL);
6325
          if (!NODE_IS_CU(RC.rrc[ctxt_pP->module_id]->node_type)) {
6326 6327 6328 6329 6330 6331 6332 6333
            rrc_rlc_config_asn1_req(ctxt_pP,
                                    ue_context_p->ue_context.SRB_configList,
                                    (LTE_DRB_ToAddModList_t *) NULL,
                                    (LTE_DRB_ToReleaseList_t *) NULL
                                    , (LTE_PMCH_InfoList_r9_t *) NULL,
                                    0,0
                                   );
        }
6334
#endif //NO_RRM
Cedric Roux's avatar
Cedric Roux committed
6335 6336
        }
        break;
6337

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6338
      case LTE_UL_CCCH_MessageType__c1_PR_rrcConnectionRequest:
Cedric Roux's avatar
Cedric Roux committed
6339 6340
        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));
Cedric Roux's avatar
Cedric Roux committed
6341

6342 6343
      LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)buffer,
                  buffer_length,
Cedric Roux's avatar
Cedric Roux committed
6344 6345 6346 6347 6348 6349 6350
                    "[MSG] RRC Connection Request\n");
        LOG_D(RRC,
              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(
                         RC.rrc[ctxt_pP->module_id],
                         ctxt_pP->rnti);
6351

Cedric Roux's avatar
Cedric Roux committed
6352 6353 6354 6355 6356 6357
        if (ue_context_p != NULL) {
          // erase content
          rrc_eNB_free_mem_UE_context(ctxt_pP, ue_context_p);
          MSC_LOG_RX_DISCARDED_MESSAGE(
            MSC_RRC_ENB,
            MSC_RRC_UE,
6358
            buffer,
Cedric Roux's avatar
Cedric Roux committed
6359
            dec_rval.consumed,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6360
            MSC_AS_TIME_FMT" LTE_RRCConnectionRequest UE %x size %u (UE already in context)",
Cedric Roux's avatar
Cedric Roux committed
6361 6362 6363 6364 6365 6366
            MSC_AS_TIME_ARGS(ctxt_pP),
            ue_context_p->ue_context.rnti,
            dec_rval.consumed);
        } else {
          rrcConnectionRequest = &ul_ccch_msg->message.choice.c1.choice.rrcConnectionRequest.criticalExtensions.choice.rrcConnectionRequest_r8;
          {
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6367
            if (LTE_InitialUE_Identity_PR_randomValue == rrcConnectionRequest->ue_Identity.present) {
Cedric Roux's avatar
Cedric Roux committed
6368 6369 6370 6371
              if(rrcConnectionRequest->ue_Identity.choice.randomValue.size != 5) {
                LOG_I(RRC, "wrong InitialUE-Identity randomValue size, expected 5, provided %lu",
                      (long unsigned int)rrcConnectionRequest->ue_Identity.choice.randomValue.size);
                return -1;
6372
              }
gauthier's avatar
gauthier committed
6373

Cedric Roux's avatar
Cedric Roux committed
6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385
              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)
               */
              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;
              }
gauthier's avatar
gauthier committed
6386

Cedric Roux's avatar
Cedric Roux committed
6387
              ue_context_p = rrc_eNB_get_next_free_ue_context(ctxt_pP, random_value);
6388

6389 6390 6391 6392 6393 6394
              ue_context_p->ue_context.Srb0.Srb_id = 0;
              ue_context_p->ue_context.Srb0.Active = 1;
              memcpy(ue_context_p->ue_context.Srb0.Rx_buffer.Payload,
                     buffer,
                     buffer_length);
              ue_context_p->ue_context.Srb0.Rx_buffer.payload_size = buffer_length;
6395

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6396
            } else if (LTE_InitialUE_Identity_PR_s_TMSI == rrcConnectionRequest->ue_Identity.present) {
Cedric Roux's avatar
Cedric Roux committed
6397
              /* Save s-TMSI */
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6398
              LTE_S_TMSI_t   s_TMSI = rrcConnectionRequest->ue_Identity.choice.s_TMSI;
Cedric Roux's avatar
Cedric Roux committed
6399 6400 6401 6402 6403 6404
              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))) {
                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);
6405

6406
                if (!NODE_IS_CU(RC.rrc[ctxt_pP->module_id]->node_type)) {
6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417
                  rrc_mac_remove_ue(ctxt_pP->module_id, ue_context_p->ue_context.rnti);
                }
                else {
                  MessageDef *m = itti_alloc_new_message(TASK_RRC_ENB, F1AP_UE_CONTEXT_RELEASE_CMD);
                  F1AP_UE_CONTEXT_RELEASE_CMD(m).rnti = ctxt_pP->rnti;
                  F1AP_UE_CONTEXT_RELEASE_CMD(m).cause = F1AP_CAUSE_RADIO_NETWORK;
                  F1AP_UE_CONTEXT_RELEASE_CMD(m).cause_value = 10; // 10 = F1AP_CauseRadioNetwork_normal_release
                  F1AP_UE_CONTEXT_RELEASE_CMD(m).rrc_container = NULL;
                  F1AP_UE_CONTEXT_RELEASE_CMD(m).rrc_container_length = 0;
                  itti_send_msg_to_task(TASK_CU_F1, ctxt_pP->module_id, m);
                }
6418

Cedric Roux's avatar
Cedric Roux committed
6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433
                stmsi_received=1;
                /* replace rnti in the context */
                /* for that, remove the context from the RB tree */
                RB_REMOVE(rrc_ue_tree_s, &RC.rrc[ctxt_pP->module_id]->rrc_ue_head, ue_context_p);
                /* and insert again, after changing rnti everywhere it has to be changed */
                ue_context_p->ue_id_rnti = ctxt_pP->rnti;
                ue_context_p->ue_context.rnti = ctxt_pP->rnti;
                RB_INSERT(rrc_ue_tree_s, &RC.rrc[ctxt_pP->module_id]->rrc_ue_head, ue_context_p);
                /* reset timers */
                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;
                ue_context_p->ue_context.reestablishment_xid = -1;
6434
              } else {
Cedric Roux's avatar
Cedric Roux committed
6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449
                LOG_I(RRC," S-TMSI doesn't exist, setting Initialue_identity_s_TMSI.m_tmsi to %p => %x\n",ue_context_p,m_tmsi);
                //              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);

                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 {
                  /* TODO: do we have to break here? */
                  //break;
                }
6450
              }
gauthier's avatar
gauthier committed
6451

Cedric Roux's avatar
Cedric Roux committed
6452 6453 6454
              MSC_LOG_RX_MESSAGE(
                MSC_RRC_ENB,
                MSC_RRC_UE,
6455
                buffer,
Cedric Roux's avatar
Cedric Roux committed
6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472
                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 {
              LOG_E(RRC,
                    PROTOCOL_RRC_CTXT_UE_FMT" RRCConnectionRequest without random UE identity or S-TMSI not supported, let's reject the UE\n",
                    PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
              rrc_eNB_generate_RRCConnectionReject(ctxt_pP,
                                                   rrc_eNB_get_ue_context(RC.rrc[ctxt_pP->module_id], ctxt_pP->rnti),
                                                   CC_id);
              break;
            }
6473
          }
Cedric Roux's avatar
Cedric Roux committed
6474 6475 6476 6477
          LOG_D(RRC,
                PROTOCOL_RRC_CTXT_UE_FMT" UE context: %p\n",
                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
                ue_context_p);
6478

Cedric Roux's avatar
Cedric Roux committed
6479 6480
          if (ue_context_p != NULL) {
            ue_context_p->ue_context.establishment_cause = rrcConnectionRequest->establishmentCause;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6481
            ue_context_p->ue_context.reestablishment_cause = LTE_ReestablishmentCause_spare1;
6482

Cedric Roux's avatar
Cedric Roux committed
6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495
            if (stmsi_received==0)
              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",
                    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
              LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Accept new connection from UE  MME code %u TMSI %u cause %ld\n",
                    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);
6496

Cedric Roux's avatar
Cedric Roux committed
6497 6498 6499 6500
            if (stmsi_received == 0)
              RC.rrc[ctxt_pP->module_id]->Nb_ue++;
          } else {
            // no context available
6501 6502
            if (flexran_agent_get_rrc_xface(ctxt_pP->module_id)) {
              flexran_agent_get_rrc_xface(ctxt_pP->module_id)->flexran_agent_notify_ue_state_change(ctxt_pP->module_id,
Cedric Roux's avatar
Cedric Roux committed
6503 6504 6505
                  ctxt_pP->rnti,
                  PROTOCOL__FLEX_UE_STATE_CHANGE_TYPE__FLUESC_DEACTIVATED);
            }
Raymond Knopp's avatar
Raymond Knopp committed
6506

Cedric Roux's avatar
Cedric Roux committed
6507 6508 6509
            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),
                  random_value);
6510
            if (NODE_IS_MONOLITHIC(RC.rrc[ctxt_pP->module_id]->node_type))
6511
              rrc_mac_remove_ue(ctxt_pP->module_id,ctxt_pP->rnti);
6512
            else if (NODE_IS_CU(RC.rrc[ctxt_pP->module_id]->node_type)) {
6513 6514 6515 6516 6517 6518 6519 6520
              MessageDef *m = itti_alloc_new_message(TASK_RRC_ENB, F1AP_UE_CONTEXT_RELEASE_CMD);
              F1AP_UE_CONTEXT_RELEASE_CMD(m).rnti = ctxt_pP->rnti;
              F1AP_UE_CONTEXT_RELEASE_CMD(m).cause = F1AP_CAUSE_RADIO_NETWORK;
              F1AP_UE_CONTEXT_RELEASE_CMD(m).cause_value = 10; // 10 = F1AP_CauseRadioNetwork_normal_release
              F1AP_UE_CONTEXT_RELEASE_CMD(m).rrc_container = NULL;
              F1AP_UE_CONTEXT_RELEASE_CMD(m).rrc_container_length = 0;
              itti_send_msg_to_task(TASK_CU_F1, ctxt_pP->module_id, m);
            }
Cedric Roux's avatar
Cedric Roux committed
6521 6522
            return -1;
          }
6523
        }
6524

winckel's avatar
winckel committed
6525
#ifndef NO_RRM
Cedric Roux's avatar
Cedric Roux committed
6526
        send_msg(&S_rrc, msg_rrc_MR_attach_ind(ctxt_pP->module_id, Mac_id));
winckel's avatar
winckel committed
6527
#else
Cedric Roux's avatar
Cedric Roux committed
6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562
        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_RRCConnectionSetup(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,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6563 6564
                                 (LTE_DRB_ToAddModList_t *) NULL,
                                 (LTE_DRB_ToReleaseList_t *) NULL,
Cedric Roux's avatar
Cedric Roux committed
6565 6566 6567 6568
                                 0xff,
                                 NULL,
                                 NULL,
                                 NULL
6569
#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6570
                                 , (LTE_PMCH_InfoList_r9_t *) NULL
6571
#endif
Cedric Roux's avatar
Cedric Roux committed
6572
                                 ,NULL);
6573

6574
        if (!NODE_IS_CU(RC.rrc[ctxt_pP->module_id]->node_type)) {
6575 6576 6577 6578
          rrc_rlc_config_asn1_req(ctxt_pP,
                                  ue_context_p->ue_context.SRB_configList,
                                  (LTE_DRB_ToAddModList_t *) NULL,
                                  (LTE_DRB_ToReleaseList_t *) NULL
6579
#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
6580 6581
                                  , (LTE_PMCH_InfoList_r9_t *) NULL
                                  , 0, 0
6582
#endif
6583 6584
                                 );
        }
winckel's avatar
winckel committed
6585
#endif //NO_RRM
Cedric Roux's avatar
Cedric Roux committed
6586
        break;
6587

Cedric Roux's avatar
Cedric Roux committed
6588 6589 6590 6591 6592
      default:
        LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Unknown message\n",
              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
        rval = -1;
        break;
winckel's avatar
winckel committed
6593
    }
6594 6595 6596

    rval = 0;
  } else {
6597 6598
    LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT"  Unknown error \n",
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
6599 6600 6601 6602
    rval = -1;
  }

  return rval;
6603 6604
}

6605 6606 6607
//-----------------------------------------------------------------------------
int
rrc_eNB_decode_dcch(
Cedric Roux's avatar
Cedric Roux committed
6608
  const protocol_ctxt_t *const ctxt_pP,
6609
  const rb_id_t                Srb_id,
Cedric Roux's avatar
Cedric Roux committed
6610
  const uint8_t    *const      Rx_sdu,
6611 6612 6613
  const sdu_size_t             sdu_sizeP
)
//-----------------------------------------------------------------------------
6614 6615 6616
{
  asn_dec_rval_t                      dec_rval;
  //UL_DCCH_Message_t uldcchmsg;
6617
  LTE_UL_DCCH_Message_t               *ul_dcch_msg = NULL; //&uldcchmsg;
6618
  int i;
Cedric Roux's avatar
Cedric Roux committed
6619 6620
  struct rrc_eNB_ue_context_s        *ue_context_p = NULL;
  MessageDef                         *msg_delete_tunnels_p = NULL;
6621
  uint8_t                             xid;
Cedric Roux's avatar
Cedric Roux committed
6622
  int dedicated_DRB=0;
Cedric Roux's avatar
Cedric Roux committed
6623 6624 6625
  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));

6626
  if ((Srb_id != 1) && (Srb_id != 2)) {
6627 6628 6629
    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);
6630 6631 6632 6633
  } else {
    LOG_D(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Received message on SRB%d\n",
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
          Srb_id);
6634
  }
6635

Cedric Roux's avatar
Cedric Roux committed
6636
  //memset(ul_dcch_msg,0,sizeof(UL_DCCH_Message_t));
6637 6638 6639 6640
  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,
6641
               &asn_DEF_LTE_UL_DCCH_Message,
Cedric Roux's avatar
Cedric Roux committed
6642
               (void **)&ul_dcch_msg,
6643 6644 6645 6646
               Rx_sdu,
               sdu_sizeP,
               0,
               0);
6647
  {
6648
    for (i = 0; i < sdu_sizeP; i++) {
6649
      LOG_T(RRC, "%x.", Rx_sdu[i]);
6650
    }
winckel's avatar
winckel committed
6651

6652 6653 6654 6655
    LOG_T(RRC, "\n");
  }

  if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0)) {
Cedric Roux's avatar
Cedric Roux committed
6656
    LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Failed to decode UL-DCCH (%zu bytes)\n",
6657 6658
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
          dec_rval.consumed);
6659 6660
    return -1;
  }
6661

6662
  ue_context_p = rrc_eNB_get_ue_context(
6663
                   RC.rrc[ctxt_pP->module_id],
6664
                   ctxt_pP->rnti);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
6665

6666
  if (ul_dcch_msg->message.present == LTE_UL_DCCH_MessageType_PR_c1) {
6667
    switch (ul_dcch_msg->message.choice.c1.present) {
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6668
      case LTE_UL_DCCH_MessageType__c1_PR_NOTHING:   /* No components present */
6669
        break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
6670

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6671
      case LTE_UL_DCCH_MessageType__c1_PR_csfbParametersRequestCDMA2000:
6672
        break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
6673

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6674
      case LTE_UL_DCCH_MessageType__c1_PR_measurementReport:
Cedric Roux's avatar
Cedric Roux committed
6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688

        // to avoid segmentation fault
        if(!ue_context_p) {
          LOG_I(RRC, "Processing measurementReport UE %x, ue_context_p is NULL\n", ctxt_pP->rnti);
          break;
        }

        LOG_D(RRC,
              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(
6689 6690
          ctxt_pP,
          ue_context_p,
Cedric Roux's avatar
Cedric Roux committed
6691 6692
          &ul_dcch_msg->message.choice.c1.choice.measurementReport.
          criticalExtensions.choice.c1.choice.measurementReport_r8.measResults);
6693
        break;
Cedric Roux's avatar
Cedric Roux committed
6694

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6695
      case LTE_UL_DCCH_MessageType__c1_PR_rrcConnectionReconfigurationComplete:
Cedric Roux's avatar
Cedric Roux committed
6696 6697 6698

        // to avoid segmentation fault
        if(!ue_context_p) {
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6699
          LOG_I(RRC, "Processing LTE_RRCConnectionReconfigurationComplete UE %x, ue_context_p is NULL\n", ctxt_pP->rnti);
Cedric Roux's avatar
Cedric Roux committed
6700 6701 6702 6703 6704 6705 6706 6707 6708 6709
          break;
        }

        LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)(Rx_sdu),sdu_sizeP,
                    "[MSG] RRC Connection Reconfiguration Complete\n");
        MSC_LOG_RX_MESSAGE(
          MSC_RRC_ENB,
          MSC_RRC_UE,
          Rx_sdu,
          sdu_sizeP,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6710
          MSC_AS_TIME_FMT" LTE_RRCConnectionReconfigurationComplete UE %x size %u",
Cedric Roux's avatar
Cedric Roux committed
6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722
          MSC_AS_TIME_ARGS(ctxt_pP),
          ue_context_p->ue_context.rnti,
          sdu_sizeP);
        LOG_D(RRC,
              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);

        if (ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.criticalExtensions.
            present ==
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6723
            LTE_RRCConnectionReconfigurationComplete__criticalExtensions_PR_rrcConnectionReconfigurationComplete_r8) {
Cedric Roux's avatar
Cedric Roux committed
6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741
          /*NN: revise the condition */
          /*FK: left the condition as is for the case MME is used (S1 mode) but setting  dedicated_DRB = 1 otherwise (noS1 mode) so that no second RRCReconfiguration message activationg more DRB is sent as this causes problems with the nasmesh driver.*/
          if (EPC_MODE_ENABLED) {
            if (ue_context_p->ue_context.Status == RRC_RECONFIGURED) {
              dedicated_DRB = 1;
              LOG_I(RRC,
                    PROTOCOL_RRC_CTXT_UE_FMT" UE State = RRC_RECONFIGURED (dedicated DRB, xid %ld)\n",
                    PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);
              //clear
              int16_t UE_id = find_UE_id(ctxt_pP->module_id, ctxt_pP->rnti);

              if(UE_id == -1) {
                LOG_E(RRC,
                      PROTOCOL_RRC_CTXT_UE_FMT" RRCConnectionReconfigurationComplete without rnti %x, fault\n",
                      PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ctxt_pP->rnti);
                break;
              }

6742
              AssertFatal(!NODE_IS_CU(RC.rrc[ctxt_pP->module_id]->node_type),
6743 6744
                          "CU cannot decode DCCH: no access to RC.mac[]\n");

Cedric Roux's avatar
Cedric Roux committed
6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773
              if(RC.mac[ctxt_pP->module_id]->UE_list.UE_sched_ctrl[UE_id].crnti_reconfigurationcomplete_flag == 1) {
                LOG_I(RRC,
                      PROTOCOL_RRC_CTXT_UE_FMT" UE State = RRC_RECONFIGURED (dedicated DRB, xid %ld) C-RNTI Complete\n",
                      PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);
                dedicated_DRB = 2;
                RC.mac[ctxt_pP->module_id]->UE_list.UE_sched_ctrl[UE_id].crnti_reconfigurationcomplete_flag = 0;
              }
            } else if (ue_context_p->ue_context.Status == RRC_HO_EXECUTION) {
              int16_t UE_id = find_UE_id(ctxt_pP->module_id, ctxt_pP->rnti);

              if(UE_id == -1) {
                LOG_E(RRC,
                      PROTOCOL_RRC_CTXT_UE_FMT" RRCConnectionReconfigurationComplete without rnti %x, fault\n",
                      PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ctxt_pP->rnti);
                break;
              }

              dedicated_DRB = 3;
              RC.mac[ctxt_pP->module_id]->UE_list.UE_sched_ctrl[UE_id].crnti_reconfigurationcomplete_flag = 0;
              ue_context_p->ue_context.Status = RRC_RECONFIGURED;
              LOG_I(RRC,
                    PROTOCOL_RRC_CTXT_UE_FMT" UE State = RRC_HO_EXECUTION (xid %ld)\n",
                    PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);
            } else {
              dedicated_DRB = 0;
              ue_context_p->ue_context.Status = RRC_RECONFIGURED;
              LOG_I(RRC,
                    PROTOCOL_RRC_CTXT_UE_FMT" UE State = RRC_RECONFIGURED (default DRB, xid %ld)\n",
                    PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);
6774
            }
Cedric Roux's avatar
Cedric Roux committed
6775 6776 6777 6778

            ue_context_p->ue_context.reestablishment_xid = -1;
          } else {
            dedicated_DRB = 1;
6779 6780
            ue_context_p->ue_context.Status = RRC_RECONFIGURED;
            LOG_I(RRC,
Cedric Roux's avatar
Cedric Roux committed
6781
                  PROTOCOL_RRC_CTXT_UE_FMT" UE State = RRC_RECONFIGURED (dedicated DRB, xid %ld)\n",
6782 6783
                  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);
          }
Cedric Roux's avatar
Cedric Roux committed
6784 6785 6786 6787 6788 6789 6790

          rrc_eNB_process_RRCConnectionReconfigurationComplete(
            ctxt_pP,
            ue_context_p,
            ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);

          //WARNING:Inform the controller about the UE activation. Should be moved to RRC agent in the future
6791 6792
          if (flexran_agent_get_rrc_xface(ctxt_pP->module_id)) {
            flexran_agent_get_rrc_xface(ctxt_pP->module_id)->flexran_agent_notify_ue_state_change(ctxt_pP->module_id,
Cedric Roux's avatar
Cedric Roux committed
6793 6794 6795 6796 6797
                ue_context_p->ue_id_rnti,
                PROTOCOL__FLEX_UE_STATE_CHANGE_TYPE__FLUESC_UPDATED);
          }
        }

6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828
        if (EPC_MODE_ENABLED) {
          if (dedicated_DRB == 1) {
            //    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;
                }
Cedric Roux's avatar
Cedric Roux committed
6829 6830
              }

6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846
              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);
            }
          } else if(dedicated_DRB == 0) {
            if(ue_context_p->ue_context.reestablishment_cause == LTE_ReestablishmentCause_spare1) {
              rrc_eNB_send_S1AP_INITIAL_CONTEXT_SETUP_RESP(ctxt_pP,
                  ue_context_p);
            } else {
              ue_context_p->ue_context.reestablishment_cause = LTE_ReestablishmentCause_spare1;
Cedric Roux's avatar
Cedric Roux committed
6847

6848 6849 6850 6851 6852 6853 6854 6855 6856
              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;
                }
              }
            }
          } else if(dedicated_DRB == 2) {
6857 6858 6859 6860 6861 6862 6863
            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;
              }
            }
6864 6865 6866 6867 6868 6869 6870
          } else if(dedicated_DRB == 3) { //x2 path switch
            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;
              }
Cedric Roux's avatar
Cedric Roux committed
6871
            }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
6872

6873 6874 6875 6876
            LOG_I(RRC,"issue rrc_eNB_send_PATH_SWITCH_REQ \n");
            rrc_eNB_send_PATH_SWITCH_REQ(ctxt_pP,ue_context_p);
          }
        } /* EPC_MODE_ENABLED */
Cedric Roux's avatar
Cedric Roux committed
6877 6878

        break;
Cedric Roux's avatar
Cedric Roux committed
6879

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6880
      case LTE_UL_DCCH_MessageType__c1_PR_rrcConnectionReestablishmentComplete:
Cedric Roux's avatar
Cedric Roux committed
6881 6882 6883 6884 6885 6886 6887 6888 6889
        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));
        LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)Rx_sdu,sdu_sizeP,
                    "[MSG] RRC Connection Reestablishment Complete\n");
        MSC_LOG_RX_MESSAGE(
          MSC_RRC_ENB,
          MSC_RRC_UE,
          Rx_sdu,
          sdu_sizeP,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6890
          MSC_AS_TIME_FMT" LTE_RRCConnectionReestablishmentComplete UE %x size %u",
Cedric Roux's avatar
Cedric Roux committed
6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915
          MSC_AS_TIME_ARGS(ctxt_pP),
          ue_context_p->ue_context.rnti,
          sdu_sizeP);
        LOG_I(RRC,
              PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
              "(rrcConnectionReestablishmentComplete) ---> RRC_eNB\n",
              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
              DCCH,
              sdu_sizeP);
        {
          rnti_t reestablish_rnti = 0;

          // select C-RNTI from map
          for (i = 0; i < MAX_MOBILES_PER_ENB; 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;
            }
          }
6916

Cedric Roux's avatar
Cedric Roux committed
6917 6918
          LOG_D(RRC, "reestablish_rnti_map[%d] [0] %x, [1] %x\n",
                i, reestablish_rnti_map[i][0], reestablish_rnti_map[i][1]);
6919

Cedric Roux's avatar
Cedric Roux committed
6920 6921
          if (!ue_context_p) {
            LOG_E(RRC,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6922
                  PROTOCOL_RRC_CTXT_UE_FMT" LTE_RRCConnectionReestablishmentComplete without UE context, falt\n",
Cedric Roux's avatar
Cedric Roux committed
6923
                  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
6924 6925
            break;
          }
6926

Cedric Roux's avatar
Cedric Roux committed
6927 6928
          //clear
          int UE_id = find_UE_id(ctxt_pP->module_id, ctxt_pP->rnti);
6929

Cedric Roux's avatar
Cedric Roux committed
6930 6931
          if(UE_id == -1) {
            LOG_E(RRC,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6932
                  PROTOCOL_RRC_CTXT_UE_FMT" LTE_RRCConnectionReestablishmentComplete without UE_id(MAC) rnti %x, fault\n",
Cedric Roux's avatar
Cedric Roux committed
6933
                  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ctxt_pP->rnti);
6934 6935 6936
            break;
          }

Cedric Roux's avatar
Cedric Roux committed
6937 6938 6939 6940
          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;

          if (ul_dcch_msg->message.choice.c1.choice.rrcConnectionReestablishmentComplete.criticalExtensions.present ==
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6941
              LTE_RRCConnectionReestablishmentComplete__criticalExtensions_PR_rrcConnectionReestablishmentComplete_r8) {
Cedric Roux's avatar
Cedric Roux committed
6942 6943 6944 6945 6946
            rrc_eNB_process_RRCConnectionReestablishmentComplete(ctxt_pP, reestablish_rnti, ue_context_p,
                ul_dcch_msg->message.choice.c1.choice.rrcConnectionReestablishmentComplete.rrc_TransactionIdentifier,
                &ul_dcch_msg->message.choice.c1.choice.rrcConnectionReestablishmentComplete.criticalExtensions.choice.rrcConnectionReestablishmentComplete_r8);

            //WARNING:Inform the controller about the UE activation. Should be moved to RRC agent in the future
6947 6948
            if (flexran_agent_get_rrc_xface(ctxt_pP->module_id)) {
              flexran_agent_get_rrc_xface(ctxt_pP->module_id)->flexran_agent_notify_ue_state_change(ctxt_pP->module_id,
Cedric Roux's avatar
Cedric Roux committed
6949 6950 6951 6952 6953 6954 6955
                  ue_context_p->ue_id_rnti,
                  PROTOCOL__FLEX_UE_STATE_CHANGE_TYPE__FLUESC_ACTIVATED);
            }
          }

          //ue_context_p->ue_context.ue_release_timer = 0;
          ue_context_p->ue_context.ue_reestablishment_timer = 1;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6956
          // remove UE after 100 frames after LTE_RRCConnectionReestablishmentRelease is triggered
Cedric Roux's avatar
Cedric Roux committed
6957
          ue_context_p->ue_context.ue_reestablishment_timer_thres = 1000;
6958
        }
Cedric Roux's avatar
Cedric Roux committed
6959
        break;
6960

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6961
      case LTE_UL_DCCH_MessageType__c1_PR_rrcConnectionSetupComplete:
Cedric Roux's avatar
Cedric Roux committed
6962 6963 6964

        // to avoid segmentation fault
        if(!ue_context_p) {
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6965
          LOG_I(RRC, "Processing LTE_RRCConnectionSetupComplete UE %x, ue_context_p is NULL\n", ctxt_pP->rnti);
6966 6967 6968
          break;
        }

Cedric Roux's avatar
Cedric Roux committed
6969 6970 6971 6972 6973 6974 6975
        LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)Rx_sdu,sdu_sizeP,
                    "[MSG] RRC Connection SetupComplete\n");
        MSC_LOG_RX_MESSAGE(
          MSC_RRC_ENB,
          MSC_RRC_UE,
          Rx_sdu,
          sdu_sizeP,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6976
          MSC_AS_TIME_FMT" LTE_RRCConnectionSetupComplete UE %x size %u",
Cedric Roux's avatar
Cedric Roux committed
6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987
          MSC_AS_TIME_ARGS(ctxt_pP),
          ue_context_p->ue_context.rnti,
          sdu_sizeP);
        LOG_D(RRC,
              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);

        if (ul_dcch_msg->message.choice.c1.choice.rrcConnectionSetupComplete.criticalExtensions.present ==
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6988
            LTE_RRCConnectionSetupComplete__criticalExtensions_PR_c1) {
Cedric Roux's avatar
Cedric Roux committed
6989 6990
          if (ul_dcch_msg->message.choice.c1.choice.rrcConnectionSetupComplete.criticalExtensions.choice.c1.
              present ==
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
6991
              LTE_RRCConnectionSetupComplete__criticalExtensions__c1_PR_rrcConnectionSetupComplete_r8) {
6992
            AssertFatal(!NODE_IS_DU(RC.rrc[ctxt_pP->module_id]->node_type),
6993
                        "should not be reached in DU\n");
Cedric Roux's avatar
Cedric Roux committed
6994 6995 6996 6997 6998 6999
            rrc_eNB_process_RRCConnectionSetupComplete(
              ctxt_pP,
              ue_context_p,
              &ul_dcch_msg->message.choice.c1.choice.rrcConnectionSetupComplete.criticalExtensions.choice.c1.choice.rrcConnectionSetupComplete_r8);
            LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" UE State = RRC_CONNECTED \n",
                  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
7000

Cedric Roux's avatar
Cedric Roux committed
7001
            //WARNING:Inform the controller about the UE activation. Should be moved to RRC agent in the future
7002 7003
            if (flexran_agent_get_rrc_xface(ctxt_pP->module_id)) {
              flexran_agent_get_rrc_xface(ctxt_pP->module_id)->flexran_agent_notify_ue_state_change(ctxt_pP->module_id,
Cedric Roux's avatar
Cedric Roux committed
7004 7005 7006
                  ue_context_p->ue_id_rnti,
                  PROTOCOL__FLEX_UE_STATE_CHANGE_TYPE__FLUESC_ACTIVATED);
            }
7007 7008
          }
        }
7009

Cedric Roux's avatar
Cedric Roux committed
7010
        ue_context_p->ue_context.ue_release_timer=0;
7011
        break;
Cedric Roux's avatar
Cedric Roux committed
7012

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7013
      case LTE_UL_DCCH_MessageType__c1_PR_securityModeComplete:
Cedric Roux's avatar
Cedric Roux committed
7014 7015 7016 7017 7018 7019 7020
        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));

        // to avoid segmentation fault
        if(!ue_context_p) {
          LOG_I(RRC, "Processing securityModeComplete UE %x, ue_context_p is NULL\n", ctxt_pP->rnti);
          break;
7021 7022
        }

Cedric Roux's avatar
Cedric Roux committed
7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043
        LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)Rx_sdu,sdu_sizeP,
                    "[MSG] RRC Security Mode Complete\n");
        MSC_LOG_RX_MESSAGE(
          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);
        LOG_I(RRC,
              PROTOCOL_RRC_CTXT_UE_FMT" received securityModeComplete on UL-DCCH %d from UE\n",
              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
              DCCH);
        LOG_D(RRC,
              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);
7044

Cedric Roux's avatar
Cedric Roux committed
7045
        if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7046
          xer_fprint(stdout, &asn_DEF_LTE_UL_DCCH_Message, (void *)ul_dcch_msg);
Cedric Roux's avatar
Cedric Roux committed
7047
        }
7048

Cedric Roux's avatar
Cedric Roux committed
7049 7050 7051 7052 7053 7054
        // 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
        rrc_eNB_generate_UECapabilityEnquiry(
          ctxt_pP,
          ue_context_p);
7055
        break;
7056

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7057
      case LTE_UL_DCCH_MessageType__c1_PR_securityModeFailure:
Cedric Roux's avatar
Cedric Roux committed
7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076
        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));
        LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)Rx_sdu,sdu_sizeP,
                    "[MSG] RRC Security Mode Failure\n");
        MSC_LOG_RX_MESSAGE(
          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);
        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);
7077

Cedric Roux's avatar
Cedric Roux committed
7078
        if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7079
          xer_fprint(stdout, &asn_DEF_LTE_UL_DCCH_Message, (void *)ul_dcch_msg);
Cedric Roux's avatar
Cedric Roux committed
7080
        }
7081

Cedric Roux's avatar
Cedric Roux committed
7082 7083 7084 7085 7086
        // cancel the security mode in PDCP
        // followup with the remaining procedure
        //#warning "LG Removed rrc_eNB_generate_UECapabilityEnquiry after receiving securityModeFailure"
        rrc_eNB_generate_UECapabilityEnquiry(ctxt_pP, ue_context_p);
        break;
7087

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7088
      case LTE_UL_DCCH_MessageType__c1_PR_ueCapabilityInformation:
Cedric Roux's avatar
Cedric Roux committed
7089 7090
        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));
Lionel Gauthier's avatar
 
Lionel Gauthier committed
7091

Cedric Roux's avatar
Cedric Roux committed
7092 7093
        // to avoid segmentation fault
        if(!ue_context_p) {
7094 7095
          LOG_I(RRC, "Processing ueCapabilityInformation UE %x, ue_context_p is NULL\n", ctxt_pP->rnti);
          break;
Cedric Roux's avatar
Cedric Roux committed
7096
        }
7097

Cedric Roux's avatar
Cedric Roux committed
7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118
        LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)Rx_sdu,sdu_sizeP,
                    "[MSG] RRC UECapablility Information\n");
        MSC_LOG_RX_MESSAGE(
          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);
        LOG_I(RRC,
              PROTOCOL_RRC_CTXT_UE_FMT" received ueCapabilityInformation on UL-DCCH %d from UE\n",
              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
              DCCH);
        LOG_D(RRC,
              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);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
7119

Cedric Roux's avatar
Cedric Roux committed
7120
        if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7121
          xer_fprint(stdout, &asn_DEF_LTE_UL_DCCH_Message, (void *)ul_dcch_msg);
Cedric Roux's avatar
Cedric Roux committed
7122
        }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
7123

Cedric Roux's avatar
Cedric Roux committed
7124
        LOG_I(RRC, "got UE capabilities for UE %x\n", ctxt_pP->rnti);
7125

Cedric Roux's avatar
Cedric Roux committed
7126 7127
        if (ue_context_p->ue_context.UE_Capability) {
          LOG_I(RRC, "freeing old UE capabilities for UE %x\n", ctxt_pP->rnti);
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7128
          ASN_STRUCT_FREE(asn_DEF_LTE_UE_EUTRA_Capability,
Cedric Roux's avatar
Cedric Roux committed
7129 7130 7131
                          ue_context_p->ue_context.UE_Capability);
          ue_context_p->ue_context.UE_Capability = 0;
        }
7132

Cedric Roux's avatar
Cedric Roux committed
7133
        dec_rval = uper_decode(NULL,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7134
                               &asn_DEF_LTE_UE_EUTRA_Capability,
Cedric Roux's avatar
Cedric Roux committed
7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146
                               (void **)&ue_context_p->ue_context.UE_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);
        ue_context_p->ue_context.UE_Capability_size = ul_dcch_msg->message.choice.c1.choice.ueCapabilityInformation.criticalExtensions.
            choice.c1.choice.ueCapabilityInformation_r8.ue_CapabilityRAT_ContainerList.list.
            array[0]->ueCapabilityRAT_Container.size;

        if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7147
          xer_fprint(stdout, &asn_DEF_LTE_UE_EUTRA_Capability, ue_context_p->ue_context.UE_Capability);
Cedric Roux's avatar
Cedric Roux committed
7148
        }
7149

Cedric Roux's avatar
Cedric Roux committed
7150 7151 7152 7153
        if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0)) {
          LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Failed to decode UE capabilities (%zu bytes)\n",
                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
                dec_rval.consumed);
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7154
          ASN_STRUCT_FREE(asn_DEF_LTE_UE_EUTRA_Capability,
Cedric Roux's avatar
Cedric Roux committed
7155 7156 7157
                          ue_context_p->ue_context.UE_Capability);
          ue_context_p->ue_context.UE_Capability = 0;
        }
7158

Cedric Roux's avatar
Cedric Roux committed
7159 7160 7161 7162 7163 7164
        if (EPC_MODE_ENABLED) {
            rrc_eNB_send_S1AP_UE_CAPABILITIES_IND(ctxt_pP,
                                                  ue_context_p,
                                                  ul_dcch_msg);
        } else {
          ue_context_p->ue_context.nb_of_e_rabs = 1;
7165

Cedric Roux's avatar
Cedric Roux committed
7166 7167 7168 7169 7170
          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;
          }
7171

Cedric Roux's avatar
Cedric Roux committed
7172 7173
          ue_context_p->ue_context.setup_e_rabs =ue_context_p->ue_context.nb_of_e_rabs;
        }
7174

Cedric Roux's avatar
Cedric Roux committed
7175 7176 7177 7178
        rrc_eNB_generate_defaultRRCConnectionReconfiguration(ctxt_pP,
            ue_context_p,
            RC.rrc[ctxt_pP->module_id]->HO_flag);
        break;
7179

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7180
      case LTE_UL_DCCH_MessageType__c1_PR_ulHandoverPreparationTransfer:
Cedric Roux's avatar
Cedric Roux committed
7181 7182 7183
        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));
        break;
Cedric Roux's avatar
Cedric Roux committed
7184

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7185
      case LTE_UL_DCCH_MessageType__c1_PR_ulInformationTransfer:
Cedric Roux's avatar
Cedric Roux committed
7186 7187
        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));
7188

Cedric Roux's avatar
Cedric Roux committed
7189 7190
        // to avoid segmentation fault
        if(!ue_context_p) {
7191 7192
          LOG_I(RRC, "Processing ulInformationTransfer UE %x, ue_context_p is NULL\n", ctxt_pP->rnti);
          break;
Cedric Roux's avatar
Cedric Roux committed
7193
        }
Cedric Roux's avatar
Cedric Roux committed
7194

Cedric Roux's avatar
Cedric Roux committed
7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206
        LOG_D(RRC,"[MSG] RRC UL Information Transfer \n");
        LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)Rx_sdu,sdu_sizeP,
                    "[MSG] RRC UL Information Transfer \n");
        MSC_LOG_RX_MESSAGE(
          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);
7207

Cedric Roux's avatar
Cedric Roux committed
7208 7209 7210 7211 7212
        if (EPC_MODE_ENABLED == 1) {
          rrc_eNB_send_S1AP_UPLINK_NAS(ctxt_pP,
                                       ue_context_p,
                                       ul_dcch_msg);
        }
7213

Cedric Roux's avatar
Cedric Roux committed
7214
        break;
Cedric Roux's avatar
Cedric Roux committed
7215

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7216
      case LTE_UL_DCCH_MessageType__c1_PR_counterCheckResponse:
Cedric Roux's avatar
Cedric Roux committed
7217 7218 7219
        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));
        break;
7220
#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
7221

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7222
      case LTE_UL_DCCH_MessageType__c1_PR_ueInformationResponse_r9:
Cedric Roux's avatar
Cedric Roux committed
7223 7224 7225
        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));
        break;
Cedric Roux's avatar
Cedric Roux committed
7226

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7227
      case LTE_UL_DCCH_MessageType__c1_PR_proximityIndication_r9:
Cedric Roux's avatar
Cedric Roux committed
7228 7229 7230
        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));
        break;
7231
#endif
7232
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
7233

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7234
      case LTE_UL_DCCH_MessageType__c1_PR_rnReconfigurationComplete_r10:
Cedric Roux's avatar
Cedric Roux committed
7235 7236 7237
        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));
        break;
winckel's avatar
winckel committed
7238

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7239
      case LTE_UL_DCCH_MessageType__c1_PR_mbmsCountingResponse_r10:
Cedric Roux's avatar
Cedric Roux committed
7240 7241 7242
        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));
        break;
Cedric Roux's avatar
Cedric Roux committed
7243

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7244
      case LTE_UL_DCCH_MessageType__c1_PR_interFreqRSTDMeasurementIndication_r10:
Cedric Roux's avatar
Cedric Roux committed
7245 7246 7247
        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));
        break;
7248
#endif
7249

Cedric Roux's avatar
Cedric Roux committed
7250 7251 7252 7253 7254 7255 7256
      default:
        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));
        LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Unknown message %s:%u\n",
              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
              __FILE__, __LINE__);
        return -1;
winckel's avatar
winckel committed
7257 7258
    }

7259
    return 0;
7260
    //TTN for D2D
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7261
  } else if (ul_dcch_msg->message.present == LTE_UL_DCCH_MessageType_PR_messageClassExtension) {
7262
    LOG_I(RRC, "THINH [LTE_UL_DCCH_MessageType_PR_messageClassExtension]\n");
7263

Cedric Roux's avatar
Cedric Roux committed
7264
    switch (ul_dcch_msg->message.choice.messageClassExtension.present) {
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7265
      case LTE_UL_DCCH_MessageType__messageClassExtension_PR_NOTHING: /* No components present */
7266 7267
        break;

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7268
      case LTE_UL_DCCH_MessageType__messageClassExtension_PR_c2: //SidelinkUEInformation
Cedric Roux's avatar
Cedric Roux committed
7269
        //case UL_DCCH_MessageType__messageClassExtension__c2_PR_sidelinkUEInformation_r12: //SidelinkUEInformation
7270
        LOG_I(RRC,"THINH [LTE_UL_DCCH_MessageType__messageClassExtension_PR_c2]\n");
7271 7272
        LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)Rx_sdu,sdu_sizeP,
                    "[MSG] RRC SidelinkUEInformation \n");
7273
        MSC_LOG_RX_MESSAGE(
Cedric Roux's avatar
Cedric Roux committed
7274 7275 7276 7277 7278 7279 7280 7281
          MSC_RRC_ENB,
          MSC_RRC_UE,
          Rx_sdu,
          sdu_sizeP,
          MSC_AS_TIME_FMT" SidelinkUEInformation UE %x size %u",
          MSC_AS_TIME_ARGS(ctxt_pP),
          ue_context_p->ue_context.rnti,
          sdu_sizeP);
7282 7283 7284 7285 7286 7287 7288
        LOG_I(RRC,
              PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
              "(SidelinkUEInformation) ---> RRC_eNB\n",
              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
              DCCH,
              sdu_sizeP);
        rrc_eNB_process_SidelinkUEInformation(
Cedric Roux's avatar
Cedric Roux committed
7289 7290 7291
          ctxt_pP,
          ue_context_p,
          &ul_dcch_msg->message.choice.messageClassExtension.choice.c2.choice.sidelinkUEInformation_r12);
7292
        break;
Cedric Roux's avatar
Cedric Roux committed
7293 7294

      default:
7295
        break;
Cedric Roux's avatar
Cedric Roux committed
7296 7297 7298
    }

    //end TTN
7299
  } else {
7300 7301 7302
    LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Unknown error %s:%u\n",
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
          __FILE__, __LINE__);
7303 7304 7305
    return -1;
  }

7306
  return 0;
winckel's avatar
winckel committed
7307 7308
}

Cedric Roux's avatar
Cedric Roux committed
7309 7310
void rrc_eNB_reconfigure_DRBs (const protocol_ctxt_t *const ctxt_pP,
                               rrc_eNB_ue_context_t  *ue_context_pP) {
7311
  int i;
Navid Nikaein's avatar
Navid Nikaein committed
7312
  int e_rab_done=0;
Cedric Roux's avatar
Cedric Roux committed
7313 7314

  for (i = 0;
Navid Nikaein's avatar
Navid Nikaein committed
7315
       i < 3;//NB_RB_MAX - 3;  // S1AP_MAX_E_RAB
7316
       i++) {
Cedric Roux's avatar
Cedric Roux committed
7317
    if ( ue_context_pP->ue_context.e_rab[i].status < E_RAB_STATUS_DONE) {
7318 7319 7320 7321 7322 7323 7324 7325
      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;
Cedric Roux's avatar
Cedric Roux committed
7326
      //  memset (ue_context_pP->ue_context.e_rab[i].param.sgw_addr.buffer,0,20);
7327 7328 7329
      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
7330
      e_rab_done++;
Cedric Roux's avatar
Cedric Roux committed
7331 7332
      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);
7333
    }
7334
  }
Cedric Roux's avatar
Cedric Roux committed
7335

Navid Nikaein's avatar
Navid Nikaein committed
7336
  ue_context_pP->ue_context.setup_e_rabs+=e_rab_done;
7337 7338 7339
  rrc_eNB_generate_dedicatedRRCConnectionReconfiguration(ctxt_pP, ue_context_pP, 0);
}

Raymond Knopp's avatar
Raymond Knopp committed
7340
void handle_f1_setup_req(f1ap_setup_req_t *f1_setup_req) { 
7341

7342
  
7343
  LOG_I(RRC,"Received F1 Setup Request from gNB_DU %llu (%s)\n",(unsigned long long int)f1_setup_req->gNB_DU_id,f1_setup_req->gNB_DU_name);
7344
  
7345
  //uint16_t num_cells_to_activate = 0;
7346 7347
  
  int cu_cell_ind=0;
Raymond Knopp's avatar
Raymond Knopp committed
7348

7349 7350 7351
  MessageDef                         *msg_p = NULL;

  //LOG_W(RRC,"num_cells_available %d \n", f1_setup_req->num_cells_available);
7352 7353 7354 7355 7356
  for (int i=0;i<f1_setup_req->num_cells_available;i++) {
    // check that mcc/mnc match and grab MIB/SIB1
    int found_cell=0;
    for (int j=0;j<RC.nb_inst;j++) {
      eNB_RRC_INST *rrc = RC.rrc[j];
Robert Schmidt's avatar
Robert Schmidt committed
7357 7358
      if (rrc->configuration.mcc[0] == f1_setup_req->mcc[i] &&
	  rrc->configuration.mnc[0] == f1_setup_req->mnc[i] &&
7359 7360 7361
	  rrc->nr_cellid == f1_setup_req->nr_cellid[i]) {
        // check that CU rrc instance corresponds to mcc/mnc/cgi (normally cgi should be enough, but just in case)

7362 7363 7364 7365 7366 7367 7368
        rrc->carrier[0].MIB = malloc(f1_setup_req->mib_length[i]);
        rrc->carrier[0].sizeof_MIB = f1_setup_req->mib_length[i];
        LOG_W(RRC, "instance %d mib length %d\n", i, f1_setup_req->mib_length[i]);
        LOG_W(RRC, "instance %d sib1 length %d\n", i, f1_setup_req->sib1_length[i]);
       
        memcpy((void*)rrc->carrier[0].MIB,f1_setup_req->mib[i],f1_setup_req->mib_length[i]);
        asn_dec_rval_t dec_rval = uper_decode_complete(NULL,
7369
                         &asn_DEF_LTE_BCCH_BCH_Message,
7370 7371 7372 7373
        					       (void **)&rrc->carrier[0].mib_DU,
        					       f1_setup_req->mib[i],
        					       f1_setup_req->mib_length[i]);
        AssertFatal(dec_rval.code == RC_OK,
7374
              "[eNB_DU %"PRIu8"] Failed to decode LTE_BCCH_BCH_MESSAGE (%zu bits)\n",
7375 7376
        	    j,
        	    dec_rval.consumed );	
7377 7378
        LTE_BCCH_BCH_Message_t *mib = &rrc->carrier[0].mib;
        LTE_BCCH_BCH_Message_t *mib_DU = rrc->carrier[0].mib_DU;
7379 7380 7381 7382 7383 7384 7385 7386
        mib->message.dl_Bandwidth = mib_DU->message.dl_Bandwidth;
        mib->message.phich_Config.phich_Resource = mib_DU->message.phich_Config.phich_Resource;
        mib->message.phich_Config.phich_Duration = mib_DU->message.phich_Config.phich_Duration;

        rrc->carrier[0].SIB1 = malloc(f1_setup_req->sib1_length[i]);
        rrc->carrier[0].sizeof_SIB1 = f1_setup_req->sib1_length[i];
        memcpy((void*)rrc->carrier[0].SIB1,f1_setup_req->sib1[i],f1_setup_req->sib1_length[i]); 
        dec_rval = uper_decode_complete(NULL,
7387
                &asn_DEF_LTE_BCCH_DL_SCH_Message,
7388 7389 7390 7391
        				(void **)&rrc->carrier[0].siblock1_DU,
        				f1_setup_req->sib1[i],
        				f1_setup_req->sib1_length[i]);
        AssertFatal(dec_rval.code == RC_OK,
7392
              "[eNB_DU %"PRIu8"] Failed to decode LTE_BCCH_DLSCH_MESSAGE (%zu bits)\n",
7393 7394 7395
        	    j,
        	    dec_rval.consumed );	
        // Parse message and extract SystemInformationBlockType1 field
7396 7397 7398 7399 7400
        LTE_BCCH_DL_SCH_Message_t *bcch_message = rrc->carrier[0].siblock1_DU;
        AssertFatal(bcch_message->message.present == LTE_BCCH_DL_SCH_MessageType_PR_c1,
              "bcch_message->message.present != LTE_BCCH_DL_SCH_MessageType_PR_c1\n");
        AssertFatal(bcch_message->message.choice.c1.present == LTE_BCCH_DL_SCH_MessageType__c1_PR_systemInformationBlockType1,
              "bcch_message->message.choice.c1.present != LTE_BCCH_DL_SCH_MessageType__c1_PR_systemInformationBlockType1\n");
7401 7402 7403 7404 7405 7406 7407 7408
        rrc->carrier[0].sib1 = &bcch_message->message.choice.c1.choice.systemInformationBlockType1;
        rrc->carrier[0].physCellId = f1_setup_req->nr_pci[i];
        // prepare F1_SETUP_RESPONSE

        if (msg_p == NULL) {
          msg_p = itti_alloc_new_message (TASK_CU_F1,F1AP_SETUP_RESP); 						 
        }
        F1AP_SETUP_RESP (msg_p).gNB_CU_name                                = rrc->node_name;
Robert Schmidt's avatar
Robert Schmidt committed
7409 7410 7411
        F1AP_SETUP_RESP (msg_p).mcc[cu_cell_ind]                           = rrc->configuration.mcc[0];
        F1AP_SETUP_RESP (msg_p).mnc[cu_cell_ind]                           = rrc->configuration.mnc[0];
        F1AP_SETUP_RESP (msg_p).mnc_digit_length[cu_cell_ind]              = rrc->configuration.mnc_digit_length[0];
7412
	F1AP_SETUP_RESP (msg_p).nr_cellid[cu_cell_ind]                     = rrc->nr_cellid;
7413 7414 7415 7416 7417
        F1AP_SETUP_RESP (msg_p).nrpci[cu_cell_ind]                         = f1_setup_req->nr_pci[i];
        int num_SI= 0;
        if (rrc->carrier[0].SIB23) {
          F1AP_SETUP_RESP (msg_p).SI_container[cu_cell_ind][num_SI]        = rrc->carrier[0].SIB23;
          F1AP_SETUP_RESP (msg_p).SI_container_length[cu_cell_ind][num_SI] = rrc->carrier[0].sizeof_SIB23;
7418 7419 7420 7421
          //printf("SI %d size %d: ", 0, F1AP_SETUP_RESP(msg_p).SI_container_length[j][num_SI]);
          //for (int n = 0; n < F1AP_SETUP_RESP(msg_p).SI_container_length[j][num_SI]; n++)
          //  printf("%02x ", F1AP_SETUP_RESP(msg_p).SI_container[0][num_SI][n]);
          //printf("\n");
7422 7423 7424
          num_SI++;
        }
        F1AP_SETUP_RESP (msg_p).num_SI[cu_cell_ind] = num_SI;
7425

7426 7427
        cu_cell_ind++;
        found_cell=1;
7428 7429 7430 7431

        F1AP_SETUP_RESP (msg_p).num_cells_to_activate = cu_cell_ind;
        // send ITTI message to F1AP-CU task
        itti_send_msg_to_task (TASK_CU_F1, ENB_MODULE_ID_TO_INSTANCE(j), msg_p);
7432 7433 7434 7435
        break;
      } else {// setup_req mcc/mnc match rrc internal list element
        
        LOG_W(RRC,"[Inst %d] No matching MCC/MNC: rrc->mcc/f1_setup_req->mcc %d/%d rrc->mnc/f1_setup_req->mnc %d/%d \n", 
Robert Schmidt's avatar
Robert Schmidt committed
7436
            j, rrc->configuration.mcc[0], f1_setup_req->mcc[i],rrc->configuration.mnc[0], f1_setup_req->mnc[i]);
7437 7438

      }
7439 7440 7441
    }// for (int j=0;j<RC.nb_inst;j++)
    if (found_cell==0) {
      AssertFatal(1==0,"No cell found\n");
Raymond Knopp's avatar
Raymond Knopp committed
7442
      /*msg_p = itti_alloc_new_message (TASK_CU_F1,F1AP_SETUP_FAILURE); 						 
7443 7444 7445 7446 7447 7448 7449 7450 7451 7452
      F1AP_SETUP_RESP (msg_p).cause                             = rrc->node_name;
      F1AP_SETUP_RESP (msg_p).time_to_wait                      = rrc->node_id;
      F1AP_SETUP_RESP (msg_p).criticality_diagnostics           = rrc->node_name;*/
    }
    // handle other failure cases
  }//for (int i=0;i<f1_setup_req->num_cells_available;i++)
}
 

  // ignore 5GNR fields for now, just take MIB and SIB1
7453 7454
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
laurent's avatar
laurent committed
7455
void rrc_enb_init(void) {
7456
  pthread_mutex_init(&lock_ue_freelist, NULL);
7457 7458
  pthread_mutex_init(&rrc_release_freelist, NULL);
  memset(&rrc_release_info,0,sizeof(RRC_release_list_t));
laurent's avatar
laurent committed
7459 7460 7461
}

//-----------------------------------------------------------------------------
7462 7463 7464 7465 7466 7467 7468 7469 7470
void rrc_subframe_process(protocol_ctxt_t *const ctxt_pP, const int CC_id)
{
  int32_t current_timestamp_ms = 0;
  int32_t ref_timestamp_ms = 0;
  struct timeval ts;
  struct rrc_eNB_ue_context_s *ue_context_p = NULL;
  struct rrc_eNB_ue_context_s *ue_to_be_removed = NULL;
#ifdef LOCALIZATION
  double estimated_distance = 0;
7471
  protocol_ctxt_t                     ctxt;
7472
#endif
Cedric Roux's avatar
Cedric Roux committed
7473 7474
  MessageDef *msg;

7475
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_RX_TX, VCD_FUNCTION_IN);
Cedric Roux's avatar
Cedric Roux committed
7476

7477
  if (RC.rrc[ENB_INSTANCE_TO_MODULE_ID(ctxt_pP->instance)]->configuration.enable_x2) {
Cedric Roux's avatar
Cedric Roux committed
7478 7479 7480 7481
    /* send a tick to x2ap */
    msg = itti_alloc_new_message(TASK_RRC_ENB, X2AP_SUBFRAME_PROCESS);
    itti_send_msg_to_task(TASK_X2AP, ctxt_pP->module_id, msg);

7482
  check_handovers(ctxt_pP); // counter, get the value and aggregate
Cedric Roux's avatar
Cedric Roux committed
7483 7484
  }

7485 7486 7487
  // check for UL failure or for UE to be released
  RB_FOREACH(ue_context_p, rrc_ue_tree_s, &(RC.rrc[ctxt_pP->module_id]->rrc_ue_head)) {
    ctxt_pP->rnti = ue_context_p->ue_id_rnti;
7488

7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500
    if ((ctxt_pP->frame == 0) && (ctxt_pP->subframe == 0)) {
      if (ue_context_p->ue_context.Initialue_identity_s_TMSI.presence == TRUE) {
        LOG_I(RRC, "UE rnti %x: S-TMSI %x failure timer %d/8\n",
              ue_context_p->ue_context.rnti,
              ue_context_p->ue_context.Initialue_identity_s_TMSI.m_tmsi,
              ue_context_p->ue_context.ul_failure_timer);
      } else {
        LOG_I(RRC, "UE rnti %x failure timer %d/8\n",
              ue_context_p->ue_context.rnti,
              ue_context_p->ue_context.ul_failure_timer);
      }
    }
7501

7502 7503
    if (ue_context_p->ue_context.ul_failure_timer > 0) {
      ue_context_p->ue_context.ul_failure_timer++;
7504

7505 7506 7507 7508 7509 7510 7511 7512
      if (ue_context_p->ue_context.ul_failure_timer >= 20000) {
        // remove UE after 20 seconds after MAC (or else) has indicated UL failure
        LOG_I(RRC, "Removing UE %x instance, because of uplink failure timer timeout\n",
              ue_context_p->ue_context.rnti);
        ue_to_be_removed = ue_context_p;
        break; // break RB_FOREACH
      }
    }
7513

7514 7515
    if (ue_context_p->ue_context.ue_release_timer_s1 > 0) {
      ue_context_p->ue_context.ue_release_timer_s1++;
7516

7517 7518 7519 7520
      if (ue_context_p->ue_context.ue_release_timer_s1 >= ue_context_p->ue_context.ue_release_timer_thres_s1) {
        LOG_I(RRC, "Removing UE %x instance, because of UE_CONTEXT_RELEASE_COMMAND not received after %d ms from sending request\n",
              ue_context_p->ue_context.rnti,
              ue_context_p->ue_context.ue_release_timer_thres_s1);
7521

7522
        if (EPC_MODE_ENABLED && !NODE_IS_DU(RC.rrc[ctxt_pP->module_id]->node_type))
7523 7524 7525
          rrc_eNB_generate_RRCConnectionRelease(ctxt_pP, ue_context_p);
        else
          ue_to_be_removed = ue_context_p;
7526

7527 7528 7529 7530
        ue_context_p->ue_context.ue_release_timer_s1 = 0;
        break; // break RB_FOREACH
      } // end if timer_s1 timeout
    } // end if timer_s1 > 0 (S1 UE_CONTEXT_RELEASE_REQ ongoing)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
7531

7532 7533
    if (ue_context_p->ue_context.ue_release_timer_rrc > 0) {
      ue_context_p->ue_context.ue_release_timer_rrc++;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7534

7535 7536 7537 7538 7539 7540
      if (ue_context_p->ue_context.ue_release_timer_rrc >= ue_context_p->ue_context.ue_release_timer_thres_rrc) {
        LOG_I(RRC, "Removing UE %x instance after UE_CONTEXT_RELEASE_Complete (ue_release_timer_rrc timeout)\n",
              ue_context_p->ue_context.rnti);
        ue_context_p->ue_context.ue_release_timer_rrc = 0;
        ue_to_be_removed = ue_context_p;
        break; // break RB_FOREACH
7541
      }
7542
    }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
7543

7544 7545 7546 7547 7548 7549
    if (ue_context_p->ue_context.handover_info != NULL) {
      if (ue_context_p->ue_context.handover_info->state == HO_RELEASE) {
        ue_to_be_removed = ue_context_p;
        rrc_eNB_handover_ue_context_release(ctxt_pP, ue_context_p);
        break; //break RB_FOREACH (why to break ?)
      }
Cedric Roux's avatar
Cedric Roux committed
7550 7551 7552 7553 7554 7555 7556 7557
      if (ue_context_p->ue_context.handover_info->state == HO_CANCEL) {
        rrc_eNB_handover_cancel(ctxt_pP, ue_context_p);
        /* freeing handover_info and setting it to NULL to let
         * RRC wait for MME to later on release the UE
         */
        free(ue_context_p->ue_context.handover_info);
        ue_context_p->ue_context.handover_info = NULL;
      }
7558
    }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
7559

7560
    pthread_mutex_lock(&rrc_release_freelist);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
7561

7562 7563
    if (rrc_release_info.num_UEs > 0) {
      uint16_t release_total = 0;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
7564

7565 7566 7567 7568 7569 7570 7571 7572 7573 7574
      for (uint16_t release_num = 0; release_num < NUMBER_OF_UE_MAX; release_num++) {
        if (rrc_release_info.RRC_release_ctrl[release_num].flag > 0) {
          release_total++;
        }

        if ((rrc_release_info.RRC_release_ctrl[release_num].flag > 2) &&
            (rrc_release_info.RRC_release_ctrl[release_num].rnti == ue_context_p->ue_context.rnti)) {
          ue_context_p->ue_context.ue_release_timer_rrc = 1;
          ue_context_p->ue_context.ue_release_timer_thres_rrc = 100;

7575
          if (EPC_MODE_ENABLED && !NODE_IS_DU(RC.rrc[ctxt_pP->module_id]->node_type)) {
7576
            if (rrc_release_info.RRC_release_ctrl[release_num].flag == 4) { // if timer_s1 == 0
7577 7578
              rrc_eNB_send_S1AP_UE_CONTEXT_RELEASE_CPLT(ctxt_pP->module_id,
                  ue_context_p->ue_context.eNB_ue_s1ap_id);
7579 7580
            }

7581 7582 7583 7584
            rrc_eNB_send_GTPV1U_ENB_DELETE_TUNNEL_REQ(ctxt_pP->module_id,
                  ue_context_p);
            // erase data of GTP tunnels in UE context
            for (int e_rab = 0; e_rab < ue_context_p->ue_context.nb_of_e_rabs; e_rab++) {
7585
              ue_context_p->ue_context.enb_gtp_teid[e_rab] = 0;
7586 7587 7588
              memset(&ue_context_p->ue_context.enb_gtp_addrs[e_rab],
                  0, sizeof(ue_context_p->ue_context.enb_gtp_addrs[e_rab]));
              ue_context_p->ue_context.enb_gtp_ebi[e_rab]  = 0;
7589 7590 7591
            }

            struct rrc_ue_s1ap_ids_s *rrc_ue_s1ap_ids = NULL;
7592 7593
            rrc_ue_s1ap_ids = rrc_eNB_S1AP_get_ue_ids(RC.rrc[ctxt_pP->module_id], 0,
                                                      ue_context_p->ue_context.eNB_ue_s1ap_id);
7594 7595 7596 7597

            if (rrc_ue_s1ap_ids != NULL) {
              rrc_eNB_S1AP_remove_ue_ids(RC.rrc[ctxt_pP->module_id], rrc_ue_s1ap_ids);
            }
7598
          } /* EPC_MODE_ENABLED && !NODE_IS_DU */
7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613

          rrc_release_info.RRC_release_ctrl[release_num].flag = 0;
          rrc_release_info.num_UEs--;
          break; // break for (release_num)
        } // end if ((rrc_release_info.RRC_release_ctrl[release_num].flag > 2) && ...

        if (release_total >= rrc_release_info.num_UEs) {
          break; // break for (release_num)
        }
      } // end for (release_num)
    } // end if (rrc_release_info.num_UEs > 0)

    pthread_mutex_unlock(&rrc_release_freelist);

    if ((ue_context_p->ue_context.ue_rrc_inactivity_timer > 0) && (RC.rrc[ctxt_pP->module_id]->configuration.rrc_inactivity_timer_thres > 0)) {
7614
      ue_context_p->ue_context.ue_rrc_inactivity_timer++;
7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707

      if (ue_context_p->ue_context.ue_rrc_inactivity_timer >= RC.rrc[ctxt_pP->module_id]->configuration.rrc_inactivity_timer_thres) {
        LOG_I(RRC, "Removing UE %x instance because of rrc_inactivity_timer timeout\n",
              ue_context_p->ue_context.rnti);
        ue_to_be_removed = ue_context_p;
        break; // break RB_FOREACH
      }
    }

    if (ue_context_p->ue_context.ue_reestablishment_timer > 0) {
      ue_context_p->ue_context.ue_reestablishment_timer++;

      if (ue_context_p->ue_context.ue_reestablishment_timer >= ue_context_p->ue_context.ue_reestablishment_timer_thres) {
        LOG_I(RRC, "Removing UE %x instance because of reestablishment_timer timeout\n",
              ue_context_p->ue_context.rnti);
        ue_context_p->ue_context.ul_failure_timer = 20000; // lead to send S1 UE_CONTEXT_RELEASE_REQ
        ue_to_be_removed = ue_context_p;
        ue_context_p->ue_context.ue_reestablishment_timer = 0;
        break; // break RB_FOREACH
      }
    }

    if (ue_context_p->ue_context.ue_release_timer > 0) {
      ue_context_p->ue_context.ue_release_timer++;

      if (ue_context_p->ue_context.ue_release_timer >= ue_context_p->ue_context.ue_release_timer_thres) {
        LOG_I(RRC, "Removing UE %x instance because of RRC Connection Setup timer timeout\n",
              ue_context_p->ue_context.rnti);
        /*
        * TODO: Naming problem here: ue_release_timer seems to have been used when RRC Connection Release was sent.
        * It is no more the case.
        * The timer should be renamed.
        */
        ue_to_be_removed = ue_context_p;
        ue_context_p->ue_context.ue_release_timer = 0;
        break; // break RB_FOREACH
      }
    }
  } // end RB_FOREACH

  if (ue_to_be_removed) {
    if ((ue_to_be_removed->ue_context.ul_failure_timer >= 20000) ||
        ((ue_to_be_removed->ue_context.ue_rrc_inactivity_timer >= RC.rrc[ctxt_pP->module_id]->configuration.rrc_inactivity_timer_thres) &&
         (RC.rrc[ctxt_pP->module_id]->configuration.rrc_inactivity_timer_thres > 0))) {
      ue_to_be_removed->ue_context.ue_release_timer_s1 = 1;
      ue_to_be_removed->ue_context.ue_release_timer_thres_s1 = 100;
      ue_to_be_removed->ue_context.ue_release_timer = 0;
      ue_to_be_removed->ue_context.ue_reestablishment_timer = 0;
    }

    rrc_eNB_free_UE(ctxt_pP->module_id, ue_to_be_removed);

    if (ue_to_be_removed->ue_context.ul_failure_timer >= 20000) {
      ue_to_be_removed->ue_context.ul_failure_timer = 0;
    }

    if ((ue_to_be_removed->ue_context.ue_rrc_inactivity_timer >= RC.rrc[ctxt_pP->module_id]->configuration.rrc_inactivity_timer_thres) &&
        (RC.rrc[ctxt_pP->module_id]->configuration.rrc_inactivity_timer_thres > 0)) {
      ue_to_be_removed->ue_context.ue_rrc_inactivity_timer = 0; //reset timer after S1 command UE context release request is sent
    }
  }

#ifdef RRC_LOCALIZATION
  /* for the localization, only primary CC_id might be relevant*/
  gettimeofday(&ts, NULL);
  current_timestamp_ms = ts.tv_sec * 1000 + ts.tv_usec / 1000;
  ref_timestamp_ms = RC.rrc[ctxt_pP->module_id]->reference_timestamp_ms;
  RB_FOREACH(ue_context_p, rrc_ue_tree_s, &(RC.rrc[ctxt_pP->module_id]->rrc_ue_head)) {
    ctxt = *ctxt_pP;
    ctxt.rnti = ue_context_p->ue_context.rnti;
    estimated_distance = rrc_get_estimated_ue_distance(&ctxt, CC_id, RC.rrc[ctxt_pP->module_id]->loc_type);

    if ((current_timestamp_ms - ref_timestamp_ms > RC.rrc[ctxt_pP->module_id]->aggregation_period_ms) &&
        estimated_distance != -1) {
      LOG_D(LOCALIZE, "RRC [UE/id %d -> eNB/id %d] timestamp %d frame %d estimated r = %f\n",
            ctxt.rnti,
            ctxt_pP->module_id,
            current_timestamp_ms,
            ctxt_pP->frame,
            estimated_distance);
      LOG_D(LOCALIZE, "RRC status %d\n",
            ue_context_p->ue_context.Status);
      push_front(&RC.rrc[ctxt_pP->module_id]->loc_list, estimated_distance);
      RC.rrc[ctxt_pP->module_id]->reference_timestamp_ms = current_timestamp_ms;
    } // end if
  } // end RB_FOREACH
#endif
  (void)ts; /* remove gcc warning "unused variable" */
  (void)ref_timestamp_ms; /* remove gcc warning "unused variable" */
  (void)current_timestamp_ms; /* remove gcc warning "unused variable" */
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_RX_TX, VCD_FUNCTION_OUT);
}

7708
//-----------------------------------------------------------------------------
laurent's avatar
laurent committed
7709
void *rrc_enb_process_itti_msg(void *notUsed) {
7710 7711 7712 7713
  MessageDef                         *msg_p;
  const char                         *msg_name_p;
  instance_t                          instance;
  int                                 result;
7714
  protocol_ctxt_t                     ctxt;
7715

7716
  memset(&ctxt, 0, sizeof(ctxt));
7717

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7718 7719 7720 7721
  // 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);
7722 7723 7724
  /* RRC_SUBFRAME_PROCESS is sent every subframe, do not log it */
  if (ITTI_MSG_ID(msg_p) != RRC_SUBFRAME_PROCESS)
    LOG_I(RRC,"Received message %s\n",msg_name_p);
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7725 7726

  switch (ITTI_MSG_ID(msg_p)) {
7727
    case TERMINATE_MESSAGE:
7728
      LOG_W(RRC, " *** Exiting RRC thread\n");
7729 7730 7731
      itti_exit_task();
      break;

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

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7736
    /* Messages from MAC */
7737
    case RRC_MAC_CCCH_DATA_IND:
7738
      PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt,
7739
                                    RRC_MAC_CCCH_DATA_IND(msg_p).enb_index,
7740 7741 7742 7743
                                    ENB_FLAG_YES,
                                    RRC_MAC_CCCH_DATA_IND(msg_p).rnti,
                                    msg_p->ittiMsgHeader.lte_time.frame,
                                    msg_p->ittiMsgHeader.lte_time.slot);
7744

7745
      LOG_I(RRC,"Decoding CCCH : inst %d, CC_id %d, ctxt %p, sib_info_p->Rx_buffer.payload_size %d\n",
Robert Schmidt's avatar
Robert Schmidt committed
7746 7747 7748 7749
            instance,
            RRC_MAC_CCCH_DATA_IND(msg_p).CC_id,
            &ctxt,
            RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size);
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7750

7751
      if (RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size >= CCCH_SDU_SIZE) {
7752
        LOG_I(RRC, "CCCH message has size %d > %d\n",
7753
              RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size,CCCH_SDU_SIZE);
Cedric Roux's avatar
Cedric Roux committed
7754
        break;
7755
      }
7756

7757 7758 7759 7760
      rrc_eNB_decode_ccch(&ctxt,
                          (uint8_t*)RRC_MAC_CCCH_DATA_IND(msg_p).sdu,
                          RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size,
                          RRC_MAC_CCCH_DATA_IND(msg_p).CC_id);
7761
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
7762

7763

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7764
    /* Messages from PDCP */
7765
    case RRC_DCCH_DATA_IND:
7766 7767 7768 7769 7770 7771
      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);
7772
      LOG_D(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Received on DCCH %d %s\n",
7773 7774 7775 7776 7777 7778
            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,
7779 7780 7781
                          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);
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7782

7783
      if (result != EXIT_SUCCESS) {
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7784
        LOG_I(RRC, "Failed to free memory (%d)!\n",result);
Cedric Roux's avatar
Cedric Roux committed
7785
        break;
7786
      }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
7787

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7788
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
7789

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7790
    /* Messages from S1AP */
7791 7792 7793
    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
7794

7795 7796 7797
    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
7798

7799 7800 7801
    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
7802

7803
    case S1AP_PAGING_IND:
7804 7805
      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);
7806
      break;
7807

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7808
    case S1AP_E_RAB_SETUP_REQ:
7809 7810 7811
      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;
7812 7813 7814 7815 7816 7817 7818 7819

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

7821 7822 7823
    case S1AP_UE_CONTEXT_RELEASE_REQ:
      rrc_eNB_process_S1AP_UE_CONTEXT_RELEASE_REQ(msg_p, msg_name_p, instance);
      break;
7824

7825 7826 7827
    case S1AP_UE_CONTEXT_RELEASE_COMMAND:
      rrc_eNB_process_S1AP_UE_CONTEXT_RELEASE_COMMAND(msg_p, msg_name_p, instance);
      break;
7828

Konstantinos Alexandris's avatar
Konstantinos Alexandris committed
7829 7830
    case GTPV1U_ENB_DELETE_TUNNEL_RESP: {
      rrc_eNB_ue_context_t *ue = rrc_eNB_get_ue_context(RC.rrc[instance], GTPV1U_ENB_DELETE_TUNNEL_RESP(msg_p).rnti);
Lionel Gauthier's avatar
Lionel Gauthier committed
7831

Konstantinos Alexandris's avatar
Konstantinos Alexandris committed
7832 7833
      if (ue != NULL
          && ue->ue_context.ue_release_timer_rrc > 0
Cedric Roux's avatar
Cedric Roux committed
7834 7835 7836
          && (ue->ue_context.handover_info == NULL ||
              (ue->ue_context.handover_info->state != HO_RELEASE &&
               ue->ue_context.handover_info->state != HO_CANCEL))) {
Konstantinos Alexandris's avatar
Konstantinos Alexandris committed
7837
        ue->ue_context.ue_release_timer_rrc = ue->ue_context.ue_release_timer_thres_rrc;
7838
      }
Cedric Roux's avatar
Cedric Roux committed
7839

7840
      break;
Konstantinos Alexandris's avatar
Konstantinos Alexandris committed
7841
    }
Lionel Gauthier's avatar
Lionel Gauthier committed
7842

7843 7844 7845 7846
    case S1AP_PATH_SWITCH_REQ_ACK:
      LOG_I(RRC, "[eNB %d] received path switch ack %s\n", instance, msg_name_p);
      rrc_eNB_process_S1AP_PATH_SWITCH_REQ_ACK(msg_p, msg_name_p, instance);
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
7847

7848
    case X2AP_HANDOVER_REQ:
7849
      LOG_I(RRC, "[eNB %d] target eNB Receives X2 HO Req %s\n", instance, msg_name_p);
7850 7851
      rrc_eNB_process_handoverPreparationInformation(instance, &X2AP_HANDOVER_REQ(msg_p));
      break;
7852

7853 7854
    case X2AP_HANDOVER_REQ_ACK: {
      struct rrc_eNB_ue_context_s        *ue_context_p = NULL;
7855 7856 7857 7858 7859 7860 7861 7862
      ue_context_p = rrc_eNB_get_ue_context(RC.rrc[instance], X2AP_HANDOVER_REQ_ACK(msg_p).rnti);
      if (ue_context_p == NULL) {
        /* is it possible? */
        LOG_E(RRC, "could not find UE (rnti %x) while processing X2AP_HANDOVER_REQ_ACK\n",
              X2AP_HANDOVER_REQ_ACK(msg_p).rnti);
        exit(1);
      }
      LOG_I(RRC, "[eNB %d] source eNB receives the X2 HO ACK %s\n", instance, msg_name_p);
7863
      DevAssert(ue_context_p != NULL);
7864

7865
      if (ue_context_p->ue_context.handover_info->state != HO_REQUEST) abort();
Cedric Roux's avatar
Cedric Roux committed
7866

7867 7868 7869 7870
      rrc_eNB_process_handoverCommand(instance, ue_context_p, &X2AP_HANDOVER_REQ_ACK(msg_p));
      ue_context_p->ue_context.handover_info->state = HO_PREPARE;
      break;
    }
7871

7872 7873
   case X2AP_UE_CONTEXT_RELEASE: {
      struct rrc_eNB_ue_context_s        *ue_context_p = NULL;
7874 7875
      ue_context_p = rrc_eNB_get_ue_context(RC.rrc[instance], X2AP_UE_CONTEXT_RELEASE(msg_p).rnti);
      LOG_I(RRC, "[eNB %d] source eNB receives the X2 UE CONTEXT RELEASE %s\n", instance, msg_name_p);
7876 7877 7878 7879 7880 7881 7882 7883
      DevAssert(ue_context_p != NULL);

      if (ue_context_p->ue_context.handover_info->state != HO_COMPLETE) abort();

      ue_context_p->ue_context.handover_info->state = HO_RELEASE;
      break;
    }

Cedric Roux's avatar
Cedric Roux committed
7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928
   case X2AP_HANDOVER_CANCEL: {
      struct rrc_eNB_ue_context_s        *ue_context_p = NULL;
      char *cause;
      switch (X2AP_HANDOVER_CANCEL(msg_p).cause) {
      case X2AP_T_RELOC_PREP_TIMEOUT:
        cause = "T_RelocPrep timeout";
        break;
      case X2AP_TX2_RELOC_OVERALL_TIMEOUT:
        cause = "Tx2_RelocOverall timeout";
        break;
      default:
        /* cannot come here */
        exit(1);
      }
      ue_context_p = rrc_eNB_get_ue_context(RC.rrc[instance], X2AP_HANDOVER_CANCEL(msg_p).rnti);
      if (ue_context_p != NULL &&
          ue_context_p->ue_context.handover_info != NULL) {
        LOG_I(RRC, "[eNB %d] eNB receives X2 HANDOVER CANCEL for rnti %x, cause %s [%s]\n",
              instance,
              X2AP_HANDOVER_CANCEL(msg_p).rnti,
              cause,
              msg_name_p);
        if (X2AP_HANDOVER_CANCEL(msg_p).cause == X2AP_T_RELOC_PREP_TIMEOUT) {
          /* for prep timeout, simply return to normal state */
          /* TODO: be sure that it's correct to set Status to RRC_RECONFIGURED */
          ue_context_p->ue_context.Status = RRC_RECONFIGURED;
          /* TODO: be sure free is enough here (check memory leaks) */
          free(ue_context_p->ue_context.handover_info);
          ue_context_p->ue_context.handover_info = NULL;
        } else {
          /* for overall timeout, remove UE entirely */
          ue_context_p->ue_context.handover_info->state = HO_CANCEL;
        }
      } else {
        char *failure_cause;
        if (ue_context_p == NULL)
          failure_cause = "no UE found";
        else
          failure_cause = "UE not in handover";
        LOG_W(RRC, "[eNB %d] cannot process (%s) X2 HANDOVER CANCEL for rnti %x, cause %s, ignoring\n",
              instance, failure_cause, X2AP_HANDOVER_CANCEL(msg_p).rnti, cause);
      }
      break;
    }

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7929
    /* Messages from eNB app */
7930
    case RRC_CONFIGURATION_REQ:
7931
      LOG_I(RRC, "[eNB %d] Received %s : %p\n", instance, msg_name_p, &RRC_CONFIGURATION_REQ(msg_p));
7932
      openair_rrc_eNB_configuration(ENB_INSTANCE_TO_MODULE_ID(instance), &RRC_CONFIGURATION_REQ(msg_p));
7933
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
7934

7935
    /* Messages from F1AP task */
Raymond Knopp's avatar
Raymond Knopp committed
7936
    case F1AP_SETUP_REQ:
7937
      AssertFatal(NODE_IS_CU(RC.rrc[instance]->node_type),
7938
		  "should not receive F1AP_SETUP_REQUEST, need call by CU!\n");
Raymond Knopp's avatar
Raymond Knopp committed
7939
      LOG_I(RRC,"[eNB %d] Received %s : %p\n", instance, msg_name_p, &F1AP_SETUP_REQ(msg_p));
7940
      handle_f1_setup_req(&F1AP_SETUP_REQ(msg_p));
7941
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
7942

7943 7944
    case RRC_SUBFRAME_PROCESS:
      rrc_subframe_process(&RRC_SUBFRAME_PROCESS(msg_p).ctxt, RRC_SUBFRAME_PROCESS(msg_p).CC_id);
7945
      break;
7946

7947 7948 7949
    default:
      LOG_E(RRC, "[eNB %d] Received unexpected message %s\n", instance, msg_name_p);
      break;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7950
  }
7951

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7952
  result = itti_free(ITTI_MSG_ORIGIN_ID(msg_p), msg_p);
Cedric Roux's avatar
Cedric Roux committed
7953

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7954 7955 7956
  if (result != EXIT_SUCCESS) {
    LOG_I(RRC, "Failed to free memory (%d)!\n",result);
  }
Cedric Roux's avatar
Cedric Roux committed
7957

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7958 7959
  msg_p = NULL;
  return NULL;
laurent's avatar
laurent committed
7960 7961 7962
}

//-----------------------------------------------------------------------------
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7963
void *
laurent's avatar
laurent committed
7964
rrc_enb_task(
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
7965
  void *args_p
laurent's avatar
laurent committed
7966 7967 7968 7969 7970 7971 7972 7973 7974
)
//-----------------------------------------------------------------------------
{
  rrc_enb_init();
  itti_mark_task_ready(TASK_RRC_ENB);
  LOG_I(RRC,"Entering main loop of RRC message task\n");

  while (1) {
    (void) rrc_enb_process_itti_msg(NULL);
7975
  }
7976
}
winckel's avatar
winckel committed
7977

7978 7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995
/*------------------------------------------------------------------------------*/
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;
    }

7996
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
7997 7998 7999 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013
    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
8014
#endif
Cedric Roux's avatar
Cedric Roux committed
8015
  }
8016 8017 8018 8019 8020 8021 8022 8023 8024
}

//-----------------------------------------------------------------------------
void
rrc_top_cleanup_eNB(
  void
)
//-----------------------------------------------------------------------------
{
Cedric Roux's avatar
Cedric Roux committed
8025
  for (int i=0; i<RC.nb_inst; i++) free (RC.rrc[i]);
8026 8027 8028 8029

  free(RC.rrc);
}

8030 8031

//-----------------------------------------------------------------------------
8032 8033 8034
//TTN - for D2D
uint8_t
rrc_eNB_process_SidelinkUEInformation(
Cedric Roux's avatar
Cedric Roux committed
8035 8036
  const protocol_ctxt_t *const ctxt_pP,
  rrc_eNB_ue_context_t         *ue_context_pP,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
8037
  LTE_SidelinkUEInformation_r12_t *sidelinkUEInformation
8038 8039 8040
)
//-----------------------------------------------------------------------------
{
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
8041
  LTE_SL_DestinationInfoList_r12_t  *destinationInfoList;
Cedric Roux's avatar
Cedric Roux committed
8042 8043 8044 8045 8046 8047 8048
  int n_destinations = 0;
  int n_discoveryMessages = 0;
  LOG_I(RRC,
        PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel UL-DCCH, " "processing SidelinkUEInformation from UE (SRB1 Active)\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));

  //For SL Communication
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
8049 8050
  if (sidelinkUEInformation->criticalExtensions.present == LTE_SidelinkUEInformation_r12__criticalExtensions_PR_c1) {
    if (sidelinkUEInformation->criticalExtensions.choice.c1.present == LTE_SidelinkUEInformation_r12__criticalExtensions__c1_PR_sidelinkUEInformation_r12) {
Cedric Roux's avatar
Cedric Roux committed
8051 8052 8053 8054 8055 8056 8057 8058
      // express its interest to receive SL communication
      if (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commRxInterestedFreq_r12 !=  NULL) {
      }

      // express its interest to transmit  non-relay one-to-many SL communication
      if ((sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commTxResourceReq_r12 != NULL) &&
          (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commTxResourceReq_r12->carrierFreq_r12 != NULL)) {
        n_destinations = sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commTxResourceReq_r12->destinationInfoList_r12.list.count;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
8059
        destinationInfoList = CALLOC(1, sizeof(LTE_SL_DestinationInfoList_r12_t));
Cedric Roux's avatar
Cedric Roux committed
8060 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075

        for (int i=0; i< n_destinations; i++ ) {
          //sl_DestinationIdentityList[i] = *(sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commTxResourceReq_r12->destinationInfoList_r12.list.array[i]);
          ASN_SEQUENCE_ADD(&destinationInfoList->list, sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.commTxResourceReq_r12->destinationInfoList_r12.list.array[i]);
        }

        //generate RRC Reconfiguration
        rrc_eNB_generate_RRCConnectionReconfiguration_Sidelink(ctxt_pP, ue_context_pP, destinationInfoList, 0);
        return 0;
      }

      // express its interest to transmit  non-relay one-to-one SL communication
      if ((sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension != NULL) &&
          (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceReqUC_r13 != NULL)) {
        if (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceReqUC_r13->carrierFreq_r12 != NULL) {
          n_destinations = sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceReqUC_r13->destinationInfoList_r12.list.count;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
8076
          destinationInfoList = CALLOC(1, sizeof(LTE_SL_DestinationInfoList_r12_t));
Cedric Roux's avatar
Cedric Roux committed
8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 8094 8095 8096

          for (int i=0; i< n_destinations; i++ ) {
            //sl_DestinationIdentityList[i] = *(sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceReqUC_r13->destinationInfoList_r12.list.array[i]);
            ASN_SEQUENCE_ADD(&destinationInfoList->list,
                             sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceReqUC_r13->destinationInfoList_r12.list.array[i]);
          }

          //generate RRC Reconfiguration
          rrc_eNB_generate_RRCConnectionReconfiguration_Sidelink(ctxt_pP, ue_context_pP, destinationInfoList, 0);
          return 0;
        }
      }

      // express its interest to transmit relay related one-to-one SL communication
      if ((sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension != NULL) &&
          (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelayUC_r13 != NULL)) {
        if (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelayUC_r13->destinationInfoList_r12.list.count
            > 0) {
          n_destinations =
            sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelayUC_r13->destinationInfoList_r12.list.count;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
8097
          destinationInfoList = CALLOC(1, sizeof(LTE_SL_DestinationInfoList_r12_t));
Cedric Roux's avatar
Cedric Roux committed
8098 8099 8100 8101 8102 8103 8104 8105 8106 8107 8108 8109 8110 8111 8112 8113 8114 8115 8116 8117

          for (int i=0; i< n_destinations; i++ ) {
            //sl_DestinationIdentityList[i] = *(sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelayUC_r13->destinationInfoList_r12.list.array[i]);
            ASN_SEQUENCE_ADD(&destinationInfoList->list,
                             sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelayUC_r13->destinationInfoList_r12.list.array[i]);
          }

          //generate RRC Reconfiguration
          rrc_eNB_generate_RRCConnectionReconfiguration_Sidelink(ctxt_pP, ue_context_pP, destinationInfoList, 0);
          return 0;
        }
      }

      //express its interest to transmit relay related one-to-many SL communication
      if ((sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension != NULL) &&
          (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13 != NULL)) {
        if (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelay_r13->destinationInfoList_r12.list.count
            > 0) {
          n_destinations =
            sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelay_r13->destinationInfoList_r12.list.count;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
8118
          destinationInfoList = CALLOC(1, sizeof(LTE_SL_DestinationInfoList_r12_t));
Cedric Roux's avatar
Cedric Roux committed
8119 8120 8121 8122 8123 8124 8125 8126 8127 8128 8129 8130 8131 8132 8133 8134 8135 8136 8137 8138 8139

          for (int i=0; i< n_destinations; i++ ) {
            //sl_DestinationIdentityList[i] = *(sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelay_r13->destinationInfoList_r12.list.array[i]);
            ASN_SEQUENCE_ADD(&destinationInfoList->list,
                             sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->commTxResourceInfoReqRelay_r13->commTxResourceReqRelay_r13->destinationInfoList_r12.list.array[i]);
          }

          //generate RRC Reconfiguration
          rrc_eNB_generate_RRCConnectionReconfiguration_Sidelink(ctxt_pP, ue_context_pP, destinationInfoList, 0);
          return 0;
        }
      }

      //For SL Discovery
      //express its interest to receive SL discovery announcements
      //express its interest to transmit non-PS related discovery announcements
      if (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.discTxResourceReq_r12 != NULL) {
        n_discoveryMessages = *(sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.discTxResourceReq_r12);
        //generate RRC Reconfiguration
        rrc_eNB_generate_RRCConnectionReconfiguration_Sidelink(ctxt_pP, ue_context_pP, NULL, n_discoveryMessages);
        return 0;
8140
      }
Cedric Roux's avatar
Cedric Roux committed
8141 8142 8143 8144 8145 8146 8147 8148 8149 8150

      //express its interest to transmit PS related discovery announcements
      if ((sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension != NULL) &&
          (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->discTxResourceReqPS_r13 !=NULL)) {
        if (sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->discTxResourceReqPS_r13->discTxResourceReq_r13 > 0) {
          n_discoveryMessages = sidelinkUEInformation->criticalExtensions.choice.c1.choice.sidelinkUEInformation_r12.nonCriticalExtension->discTxResourceReqPS_r13->discTxResourceReq_r13;
          //generate RRC Reconfiguration
          rrc_eNB_generate_RRCConnectionReconfiguration_Sidelink(ctxt_pP, ue_context_pP, NULL, n_discoveryMessages);
          return 0;
        }
8151
      }
Cedric Roux's avatar
Cedric Roux committed
8152 8153 8154 8155
    }
  }

  return 0;
8156 8157 8158 8159 8160
}

//-----------------------------------------------------------------------------
int
rrc_eNB_generate_RRCConnectionReconfiguration_Sidelink(
Cedric Roux's avatar
Cedric Roux committed
8161 8162
  const protocol_ctxt_t *const ctxt_pP,
  rrc_eNB_ue_context_t *const ue_context_pP,
8163
  LTE_SL_DestinationInfoList_r12_t  *destinationInfoList,
8164 8165 8166 8167 8168
  int n_discoveryMessages
)
//-----------------------------------------------------------------------------
{
  uint8_t                             buffer[RRC_BUF_SIZE];
8169
  uint16_t                            size = 0;
8170 8171 8172 8173 8174
  memset(buffer, 0, RRC_BUF_SIZE);

  // allocate dedicated pools for UE -sl-CommConfig/sl-DiscConfig (sl-V2X-ConfigDedicated)
  //populate dedicated resources for SL communication (sl-CommConfig)
  if ((destinationInfoList != NULL) && (destinationInfoList->list.count > 0)) {
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
8175
    LOG_I(RRC,"[eNB %d] Frame %d, Generate LTE_RRCConnectionReconfiguration_Sidelink (bytes %d, UE id %x), number of destinations %d\n",
Cedric Roux's avatar
Cedric Roux committed
8176 8177
          ctxt_pP->module_id,ctxt_pP->frame, size, ue_context_pP->ue_context.rnti,destinationInfoList->list.count );
    //get dedicated resources from available pool and assign to the UE
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
8178
    LTE_SL_CommConfig_r12_t  sl_CommConfig[destinationInfoList->list.count];
Cedric Roux's avatar
Cedric Roux committed
8179 8180 8181 8182 8183
    //get a RP from the available RPs
    sl_CommConfig[0] = rrc_eNB_get_sidelink_commTXPool(ctxt_pP, ue_context_pP, destinationInfoList);
    size = do_RRCConnectionReconfiguration(ctxt_pP,
                                           buffer,
                                           rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),   //Transaction_id
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
8184 8185 8186 8187
                                           (LTE_SRB_ToAddModList_t *)NULL,
                                           (LTE_DRB_ToAddModList_t *)NULL,
                                           (LTE_DRB_ToReleaseList_t *)NULL, // DRB2_list,
                                           (struct LTE_SPS_Config *)NULL,   // *sps_Config,
Cedric Roux's avatar
Cedric Roux committed
8188 8189
                                           NULL, NULL, NULL, NULL,NULL,
                                           NULL, NULL,  NULL, NULL, NULL, NULL, NULL,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
8190 8191 8192 8193 8194
                                           (struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *)NULL,
                                           (LTE_SL_CommConfig_r12_t *)&sl_CommConfig,
                                           (LTE_SL_DiscConfig_r12_t *)NULL
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
                                           , (LTE_SCellToAddMod_r10_t *)NULL
Cedric Roux's avatar
Cedric Roux committed
8195 8196 8197
#endif
                                          );
    //
8198
  }
Cedric Roux's avatar
Cedric Roux committed
8199

8200 8201
  //populate dedicated resources for SL discovery (sl-DiscConfig)
  if (n_discoveryMessages > 0) {
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
8202
    LTE_SL_DiscConfig_r12_t sl_DiscConfig[n_discoveryMessages];
Cedric Roux's avatar
Cedric Roux committed
8203 8204 8205 8206 8207
    //get a RP from the available RPs
    sl_DiscConfig[0] = rrc_eNB_get_sidelink_discTXPool(ctxt_pP, ue_context_pP, n_discoveryMessages );
    size = do_RRCConnectionReconfiguration(ctxt_pP,
                                           buffer,
                                           rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),   //Transaction_id
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
8208 8209 8210 8211
                                           (LTE_SRB_ToAddModList_t *)NULL,
                                           (LTE_DRB_ToAddModList_t *)NULL,
                                           (LTE_DRB_ToReleaseList_t *)NULL, // DRB2_list,
                                           (struct LTE_SPS_Config *)NULL,   // *sps_Config,
Cedric Roux's avatar
Cedric Roux committed
8212 8213
                                           NULL, NULL, NULL, NULL,NULL,
                                           NULL, NULL,  NULL, NULL, NULL, NULL, NULL,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
8214 8215 8216 8217 8218
                                           (struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *)NULL,
                                           (LTE_SL_CommConfig_r12_t *)NULL,
                                           (LTE_SL_DiscConfig_r12_t *)&sl_DiscConfig
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
                                           , (LTE_SCellToAddMod_r10_t *)NULL
Cedric Roux's avatar
Cedric Roux committed
8219 8220
#endif
                                          );
8221 8222
  }

8223
  LOG_I(RRC,"[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate LTE_RRCConnectionReconfiguration_Sidelink (bytes %d, UE id %x)\n",
8224 8225 8226 8227 8228 8229 8230 8231 8232 8233 8234 8235 8236
        ctxt_pP->module_id,ctxt_pP->frame, size, ue_context_pP->ue_context.rnti);
  rrc_data_req(
    ctxt_pP,
    DCCH,
    rrc_eNB_mui++,
    SDU_CONFIRM_NO,
    size,
    buffer,
    PDCP_TRANSMISSION_MODE_CONTROL);
  // rrc_data_req();
  return size;
}

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
8237
LTE_SL_CommConfig_r12_t rrc_eNB_get_sidelink_commTXPool( const protocol_ctxt_t *const ctxt_pP, rrc_eNB_ue_context_t *const ue_context_pP, LTE_SL_DestinationInfoList_r12_t  *destinationInfoList ) {
Cedric Roux's avatar
Cedric Roux committed
8238
  // for the moment, use scheduled resource allocation
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
8239 8240 8241
  LTE_SL_CommConfig_r12_t  *sl_CommConfig;
  LTE_SL_CommResourcePool_r12_t    *sc_CommTxConfig;
  sl_CommConfig = CALLOC(1, sizeof(struct LTE_SL_CommConfig_r12));
Cedric Roux's avatar
Cedric Roux committed
8242
  sl_CommConfig->commTxResources_r12 = CALLOC(1, sizeof(*sl_CommConfig->commTxResources_r12));
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
8243 8244
  sl_CommConfig->commTxResources_r12->present = LTE_SL_CommConfig_r12__commTxResources_r12_PR_setup;
  sl_CommConfig->commTxResources_r12->choice.setup.present = LTE_SL_CommConfig_r12__commTxResources_r12__setup_PR_scheduled_r12;
Cedric Roux's avatar
Cedric Roux committed
8245 8246 8247 8248 8249 8250 8251
  sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.sl_RNTI_r12.size = 2;
  sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.sl_RNTI_r12.buf = CALLOC(1,2);
  sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.sl_RNTI_r12.buf[0] = 0x00;
  sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.sl_RNTI_r12.buf[1] = 0x01;//ctxt_pP->rnti;//rnti
  sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.sl_RNTI_r12.bits_unused = 0;
  sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.mcs_r12 = CALLOC(1,sizeof(*sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.mcs_r12));
  //*sl_CommConfig_test->commTxResources_r12->choice.setup.choice.scheduled_r12.mcs_r12 = 12; //Msc
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
8252
  sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.mac_MainConfig_r12.retx_BSR_TimerSL = LTE_RetxBSR_Timer_r12_sf320; //MacConfig, for testing only
Cedric Roux's avatar
Cedric Roux committed
8253 8254
  //sl_CommConfig_test->commTxResources_r12->choice.setup.choice.scheduled_r12.sc_CommTxConfig_r12;
  sc_CommTxConfig = & sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.sc_CommTxConfig_r12;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
8255 8256 8257
  sc_CommTxConfig->sc_CP_Len_r12 = LTE_SL_CP_Len_r12_normal;
  sc_CommTxConfig->sc_Period_r12 = LTE_SL_PeriodComm_r12_sf40;
  sc_CommTxConfig->data_CP_Len_r12 = LTE_SL_CP_Len_r12_normal;
Cedric Roux's avatar
Cedric Roux committed
8258 8259 8260 8261
  //sc_TF_ResourceConfig_r12
  sc_CommTxConfig->sc_TF_ResourceConfig_r12.prb_Num_r12 = 20;
  sc_CommTxConfig->sc_TF_ResourceConfig_r12.prb_Start_r12 = 5;
  sc_CommTxConfig->sc_TF_ResourceConfig_r12.prb_End_r12 = 44;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
8262
  sc_CommTxConfig->sc_TF_ResourceConfig_r12.offsetIndicator_r12.present = LTE_SL_OffsetIndicator_r12_PR_small_r12;
Cedric Roux's avatar
Cedric Roux committed
8263
  sc_CommTxConfig->sc_TF_ResourceConfig_r12.offsetIndicator_r12.choice.small_r12 = 0;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
8264
  sc_CommTxConfig->sc_TF_ResourceConfig_r12.subframeBitmap_r12.present = LTE_SubframeBitmapSL_r12_PR_bs40_r12;
Cedric Roux's avatar
Cedric Roux committed
8265 8266 8267 8268 8269
  sc_CommTxConfig->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.size = 5;
  sc_CommTxConfig->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.buf  = CALLOC(1,5);
  sc_CommTxConfig->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.bits_unused = 0;
  //dataHoppingConfig_r12
  sc_CommTxConfig->dataHoppingConfig_r12.hoppingParameter_r12 = 0;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
8270
  sc_CommTxConfig->dataHoppingConfig_r12.numSubbands_r12  = LTE_SL_HoppingConfigComm_r12__numSubbands_r12_ns1;
Cedric Roux's avatar
Cedric Roux committed
8271 8272 8273 8274 8275 8276
  sc_CommTxConfig->dataHoppingConfig_r12.rb_Offset_r12 = 0;
  //ue_SelectedResourceConfig_r12
  sc_CommTxConfig->ue_SelectedResourceConfig_r12 = CALLOC (1, sizeof (*sc_CommTxConfig->ue_SelectedResourceConfig_r12));
  sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.prb_Num_r12 = 20;
  sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.prb_Start_r12 = 5;
  sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.prb_End_r12 = 44;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
8277
  sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.offsetIndicator_r12.present = LTE_SL_OffsetIndicator_r12_PR_small_r12;
Cedric Roux's avatar
Cedric Roux committed
8278
  sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.offsetIndicator_r12.choice.small_r12 = 0 ;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
8279
  sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.present = LTE_SubframeBitmapSL_r12_PR_bs40_r12;
Cedric Roux's avatar
Cedric Roux committed
8280 8281 8282 8283 8284 8285 8286 8287 8288 8289 8290 8291 8292 8293 8294 8295
  sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.size = 5;
  sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf  = CALLOC(1,5);
  sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.bits_unused = 0;
  sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf[0] = 0xF0;
  sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf[1] = 0xFF;
  sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf[2] = 0xFF;
  sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf[3] = 0xFF;
  sc_CommTxConfig->ue_SelectedResourceConfig_r12->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs4_r12.buf[4] = 0xFF;
  //rxParametersNCell_r12
  sc_CommTxConfig->rxParametersNCell_r12 = CALLOC (1, sizeof (*sc_CommTxConfig->rxParametersNCell_r12));
  sc_CommTxConfig->rxParametersNCell_r12->tdd_Config_r12 = CALLOC (1, sizeof (*sc_CommTxConfig->rxParametersNCell_r12->tdd_Config_r12 ));
  sc_CommTxConfig->rxParametersNCell_r12->tdd_Config_r12->subframeAssignment = 0 ;
  sc_CommTxConfig->rxParametersNCell_r12->tdd_Config_r12->specialSubframePatterns = 0;
  sc_CommTxConfig->rxParametersNCell_r12->syncConfigIndex_r12 = 0;
  //txParameters_r12
  sc_CommTxConfig->txParameters_r12 = CALLOC (1, sizeof (*sc_CommTxConfig->txParameters_r12));
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
8296
  sc_CommTxConfig->txParameters_r12->sc_TxParameters_r12.alpha_r12 = LTE_Alpha_r12_al0;
Cedric Roux's avatar
Cedric Roux committed
8297 8298 8299
  sc_CommTxConfig->txParameters_r12->sc_TxParameters_r12.p0_r12 = 0;
  sc_CommTxConfig->ext1 = NULL ;
  return *sl_CommConfig;
8300 8301 8302
}


Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
8303
LTE_SL_DiscConfig_r12_t rrc_eNB_get_sidelink_discTXPool( const protocol_ctxt_t *const ctxt_pP, rrc_eNB_ue_context_t *const ue_context_pP,  int n_discoveryMessages ) {
Cedric Roux's avatar
Cedric Roux committed
8304
  //TODO
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
8305
  LTE_SL_DiscConfig_r12_t  sl_DiscConfig;
8306
  memset(&sl_DiscConfig,0,sizeof(LTE_SL_DiscConfig_r12_t));
Cedric Roux's avatar
Cedric Roux committed
8307
  sl_DiscConfig.discTxResources_r12 = CALLOC(1,sizeof(*sl_DiscConfig.discTxResources_r12));
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
8308 8309
  sl_DiscConfig.discTxResources_r12->present = LTE_SL_DiscConfig_r12__discTxResources_r12_PR_setup;
  sl_DiscConfig.discTxResources_r12->choice.setup.present = LTE_SL_DiscConfig_r12__discTxResources_r12__setup_PR_scheduled_r12;
Cedric Roux's avatar
Cedric Roux committed
8310 8311 8312 8313
  //sl_DiscConfig.discTxResources_r12->choice.setup.choice.scheduled_r12.discHoppingConfig_r12;
  //sl_DiscConfig.discTxResources_r12->choice.setup.choice.scheduled_r12.discTF_IndexList_r12;
  //sl_DiscConfig.discTxResources_r12->choice.setup.choice.scheduled_r12.discTxConfig_r12;
  return sl_DiscConfig;
8314
}
8315

8316 8317
RRC_status_t
rrc_rx_tx(
Cedric Roux's avatar
Cedric Roux committed
8318
  protocol_ctxt_t *const ctxt_pP,
8319
  const int        CC_id
8320 8321 8322
)
//-----------------------------------------------------------------------------
{
8323 8324 8325 8326 8327
  MessageDef *message_p;
  message_p = itti_alloc_new_message(TASK_RRC_ENB, RRC_SUBFRAME_PROCESS);
  RRC_SUBFRAME_PROCESS(message_p).ctxt  = *ctxt_pP;
  RRC_SUBFRAME_PROCESS(message_p).CC_id = CC_id;
  itti_send_msg_to_task(TASK_RRC_ENB, ctxt_pP->module_id, message_p);
8328
  return RRC_OK;
8329
}