rrc_UE.c 233 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
Cedric Roux's avatar
Cedric Roux committed
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

/*! \file rrc_UE.c
gauthier's avatar
gauthier committed
23
 * \brief rrc procedures for UE
nikaeinn's avatar
nikaeinn committed
24
25
 * \author Navid Nikaein and Raymond Knopp
 * \date 2011 - 2014
gauthier's avatar
gauthier committed
26
27
 * \version 1.0
 * \company Eurecom
nikaeinn's avatar
nikaeinn committed
28
 * \email: navid.nikaein@eurecom.fr and raymond.knopp@eurecom.fr
gauthier's avatar
gauthier committed
29
 */
30

gauthier's avatar
gauthier committed
31
32
#define RRC_UE
#define RRC_UE_C
33

34
#include "assertions.h"
35
#include "hashtable.h"
36
#include "asn1_conversions.h"
37
#include "defs.h"
38
#include "PHY/TOOLS/dB_routines.h"
39
40
41
42
43
44
#include "extern.h"
#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"
#include "LAYER2/RLC/rlc.h"
#include "COMMON/mac_rrc_primitives.h"
#include "UTIL/LOG/log.h"
#include "UTIL/LOG/vcd_signal_dumper.h"
45
46
47
#ifndef CELLULAR
#include "RRC/LITE/MESSAGES/asn1_msg.h"
#endif
48
49
50
51
52
53
54
#include "RRCConnectionRequest.h"
#include "RRCConnectionReconfiguration.h"
#include "UL-CCCH-Message.h"
#include "DL-CCCH-Message.h"
#include "UL-DCCH-Message.h"
#include "DL-DCCH-Message.h"
#include "BCCH-DL-SCH-Message.h"
55
#include "PCCH-Message.h"
Cedric Roux's avatar
Cedric Roux committed
56
#if defined(Rel10) || defined(Rel14)
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "MCCH-Message.h"
#endif
#include "MeasConfig.h"
#include "MeasGapConfig.h"
#include "MeasObjectEUTRA.h"
#include "TDD-Config.h"
#include "UECapabilityEnquiry.h"
#include "UE-CapabilityRequest.h"
#ifdef PHY_ABSTRACTION
#include "OCG.h"
#include "OCG_extern.h"
#endif
#ifdef USER_MODE
#include "RRC/NAS/nas_config.h"
#include "RRC/NAS/rb_config.h"
#endif
73
#if ENABLE_RAL
gauthier's avatar
gauthier committed
74
75
#include "rrc_UE_ral.h"
#endif
76
77
78
79
80

#if defined(ENABLE_SECURITY)
# include "UTIL/OSA/osa_defs.h"
#endif

81
#include "pdcp.h"
82
#include "plmn_data.h"
gauthier's avatar
gauthier committed
83
#include "msc.h"
84

85
86
87
88
#if defined(ENABLE_ITTI)
# include "intertask_interface.h"
#endif

89
90
#include "SIMULATION/TOOLS/defs.h" // for taus

91
92
93
94
95
96
97
98
99
//TTN - for D2D
#define D2D_MODE //enable d2d
int ctrl_sock_fd;
#define BUFSIZE 1024
struct sockaddr_in prose_app_addr;
int slrb_id;
pthread_mutex_t slrb_mutex;
static void *rrc_control_socket_thread_fct(void *arg);
//end TTN
100

101
102
103
104
105
106
107
108
109
#ifdef PHY_EMUL
extern EMULATION_VARS *Emul_vars;
#endif
extern eNB_MAC_INST *eNB_mac_inst;
extern UE_MAC_INST *UE_mac_inst;
#ifdef BIGPHYSAREA
extern void *bigphys_malloc(int);
#endif

110
//#define XER_PRINT
111

112
//extern int8_t dB_fixed2(uint32_t x,uint32_t y);
113

114
115
116
117
118
119
120
121
122
extern void pdcp_config_set_security(
  const protocol_ctxt_t* const  ctxt_pP,
  pdcp_t         * const pdcp_pP,
  const rb_id_t         rb_idP,
  const uint16_t        lc_idP,
  const uint8_t         security_modeP,
  uint8_t        * const kRRCenc,
  uint8_t        * const kRRCint,
  uint8_t        * const  kUPenc);
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145

// internal prototypes

void rrc_ue_process_securityModeCommand( const protocol_ctxt_t* const ctxt_pP, SecurityModeCommand_t* const securityModeCommand, const uint8_t eNB_index );

static int decode_SI( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index );

static int decode_SIB1( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index, const uint8_t rsrq, const uint8_t rsrp );

/** \brief Generates/Encodes RRCConnnectionSetupComplete message at UE
 *  \param ctxt_pP Running context
 *  \param eNB_index Index of corresponding eNB/CH
 *  \param Transaction_id Transaction identifier
 */
static void rrc_ue_generate_RRCConnectionSetupComplete( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index, const uint8_t Transaction_id );

/** \brief Generates/Encodes RRCConnectionReconfigurationComplete message at UE
 *  \param ctxt_pP Running context
 *  \param eNB_index Index of corresponding eNB/CH
 *  \param Transaction_id RRC transaction identifier
 */
static void rrc_ue_generate_RRCConnectionReconfigurationComplete( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index, const uint8_t Transaction_id );

146
static void rrc_ue_generate_MeasurementReport(protocol_ctxt_t* const ctxt_pP, uint8_t eNB_index );
147
148
149
150
151
152
153
154
155
156

static uint8_t check_trigger_meas_event(
  uint8_t module_idP,
  frame_t frameP,
  uint8_t eNB_index,
  uint8_t ue_cnx_index,
  uint8_t meas_index,
  Q_OffsetRange_t ofn, Q_OffsetRange_t ocn, Hysteresis_t hys,
  Q_OffsetRange_t ofs, Q_OffsetRange_t ocs, long a3_offset, TimeToTrigger_t ttt);

Cedric Roux's avatar
Cedric Roux committed
157
#if defined(Rel10) || defined(Rel14)
158
static void decode_MBSFNAreaConfiguration(module_id_t module_idP, uint8_t eNB_index, frame_t frameP,uint8_t mbsfn_sync_area);
Cedric Roux's avatar
Cedric Roux committed
159
#endif
160
161
162
163
164
165
166
167








winckel's avatar
winckel committed
168
/*------------------------------------------------------------------------------*/
Cedric Roux's avatar
Cedric Roux committed
169
170
/* to avoid gcc warnings when compiling with certain options */
#if defined(ENABLE_USE_MME) || ENABLE_RAL
171
172
static Rrc_State_t rrc_get_state (module_id_t ue_mod_idP)
{
gauthier's avatar
   
gauthier committed
173
  return UE_rrc_inst[ue_mod_idP].RrcState;
winckel's avatar
winckel committed
174
}
Cedric Roux's avatar
Cedric Roux committed
175
#endif
winckel's avatar
winckel committed
176

177
178
static Rrc_Sub_State_t rrc_get_sub_state (module_id_t ue_mod_idP)
{
gauthier's avatar
   
gauthier committed
179
  return UE_rrc_inst[ue_mod_idP].RrcSubState;
winckel's avatar
winckel committed
180
181
}

182
183
static int rrc_set_state (module_id_t ue_mod_idP, Rrc_State_t state)
{
winckel's avatar
winckel committed
184
  AssertFatal ((RRC_STATE_FIRST <= state) && (state <= RRC_STATE_LAST),
185
               "Invalid state %d!\n", state);
winckel's avatar
winckel committed
186

gauthier's avatar
   
gauthier committed
187
  if (UE_rrc_inst[ue_mod_idP].RrcState != state) {
188
    UE_rrc_inst[ue_mod_idP].RrcState = state;
winckel's avatar
winckel committed
189

190
#if defined(ENABLE_ITTI)
191
192
    {
      MessageDef *msg_p;
193

194
195
196
      msg_p = itti_alloc_new_message(TASK_RRC_UE, RRC_STATE_IND);
      RRC_STATE_IND(msg_p).state = UE_rrc_inst[ue_mod_idP].RrcState;
      RRC_STATE_IND(msg_p).sub_state = UE_rrc_inst[ue_mod_idP].RrcSubState;
winckel's avatar
winckel committed
197

198
      itti_send_msg_to_task(TASK_UNKNOWN, UE_MODULE_ID_TO_INSTANCE(ue_mod_idP), msg_p);
199
    }
200
#endif
201
    return (1);
winckel's avatar
winckel committed
202
203
204
205
206
  }

  return (0);
}

207
//-----------------------------------------------------------------------------
208
static int rrc_set_sub_state( module_id_t ue_mod_idP, Rrc_Sub_State_t subState )
209
{
210
#if (defined(ENABLE_ITTI) && (defined(ENABLE_USE_MME) || ENABLE_RAL))
211

gauthier's avatar
   
gauthier committed
212
  switch (UE_rrc_inst[ue_mod_idP].RrcState) {
gauthier's avatar
gauthier committed
213
214
  case RRC_STATE_INACTIVE:
    AssertFatal ((RRC_SUB_STATE_INACTIVE_FIRST <= subState) && (subState <= RRC_SUB_STATE_INACTIVE_LAST),
215
                 "Invalid sub state %d for state %d!\n", subState, UE_rrc_inst[ue_mod_idP].RrcState);
gauthier's avatar
gauthier committed
216
217
218
219
    break;

  case RRC_STATE_IDLE:
    AssertFatal ((RRC_SUB_STATE_IDLE_FIRST <= subState) && (subState <= RRC_SUB_STATE_IDLE_LAST),
220
                 "Invalid sub state %d for state %d!\n", subState, UE_rrc_inst[ue_mod_idP].RrcState);
gauthier's avatar
gauthier committed
221
222
223
224
    break;

  case RRC_STATE_CONNECTED:
    AssertFatal ((RRC_SUB_STATE_CONNECTED_FIRST <= subState) && (subState <= RRC_SUB_STATE_CONNECTED_LAST),
225
                 "Invalid sub state %d for state %d!\n", subState, UE_rrc_inst[ue_mod_idP].RrcState);
gauthier's avatar
gauthier committed
226
    break;
winckel's avatar
winckel committed
227
  }
228

229
#endif
winckel's avatar
winckel committed
230

gauthier's avatar
   
gauthier committed
231
  if (UE_rrc_inst[ue_mod_idP].RrcSubState != subState) {
232
    UE_rrc_inst[ue_mod_idP].RrcSubState = subState;
winckel's avatar
winckel committed
233

234
#if defined(ENABLE_ITTI)
235
236
    {
      MessageDef *msg_p;
winckel's avatar
winckel committed
237

238
239
240
      msg_p = itti_alloc_new_message(TASK_RRC_UE, RRC_STATE_IND);
      RRC_STATE_IND(msg_p).state = UE_rrc_inst[ue_mod_idP].RrcState;
      RRC_STATE_IND(msg_p).sub_state = UE_rrc_inst[ue_mod_idP].RrcSubState;
241

242
      itti_send_msg_to_task(TASK_UNKNOWN, UE_MODULE_ID_TO_INSTANCE(ue_mod_idP), msg_p);
243
    }
244
#endif
245
    return (1);
winckel's avatar
winckel committed
246
247
248
249
250
  }

  return (0);
}

251
//-----------------------------------------------------------------------------
252
static void init_SI_UE( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index )
253
{
254
255
  UE_rrc_inst[ctxt_pP->module_id].sizeof_SIB1[eNB_index] = 0;
  UE_rrc_inst[ctxt_pP->module_id].sizeof_SI[eNB_index] = 0;
256
257
258
259
260
261
262
263
264
265
266
267
  UE_rrc_inst[ctxt_pP->module_id].SIB1[eNB_index] = (uint8_t*)malloc16_clear( 32 );
  UE_rrc_inst[ctxt_pP->module_id].sib1[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType1_t) );
  UE_rrc_inst[ctxt_pP->module_id].sib2[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType2_t) );
  UE_rrc_inst[ctxt_pP->module_id].sib3[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType3_t) );
  UE_rrc_inst[ctxt_pP->module_id].sib4[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType4_t) );
  UE_rrc_inst[ctxt_pP->module_id].sib5[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType5_t) );
  UE_rrc_inst[ctxt_pP->module_id].sib6[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType6_t) );
  UE_rrc_inst[ctxt_pP->module_id].sib7[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType7_t) );
  UE_rrc_inst[ctxt_pP->module_id].sib8[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType8_t) );
  UE_rrc_inst[ctxt_pP->module_id].sib9[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType9_t) );
  UE_rrc_inst[ctxt_pP->module_id].sib10[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType10_t) );
  UE_rrc_inst[ctxt_pP->module_id].sib11[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType11_t) );
Cedric Roux's avatar
Cedric Roux committed
268
#if defined(Rel10) || defined(Rel14)
269
270
271
272
  UE_rrc_inst[ctxt_pP->module_id].sib12[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType12_r9_t) );
  UE_rrc_inst[ctxt_pP->module_id].sib13[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType13_r9_t) );
#endif
  UE_rrc_inst[ctxt_pP->module_id].SI[eNB_index] = (uint8_t*)malloc16_clear( 64 );
273

274
  UE_rrc_inst[ctxt_pP->module_id].si[eNB_index] = (SystemInformation_t*)malloc16_clear( sizeof(SystemInformation_t) );
275

276
  UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus = 0;
277
  UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIcnt    = 0;
278
279
}

Cedric Roux's avatar
Cedric Roux committed
280
#if defined(Rel10) || defined(Rel14)
281
//-----------------------------------------------------------------------------
282
#if 0
283
static void init_MCCH_UE(module_id_t ue_mod_idP, uint8_t eNB_index)
284
{
285
  int i;
gauthier's avatar
   
gauthier committed
286
287
288
  UE_rrc_inst[ue_mod_idP].sizeof_MCCH_MESSAGE[eNB_index] = 0;
  UE_rrc_inst[ue_mod_idP].MCCH_MESSAGE[eNB_index] = (uint8_t *)malloc16(32);
  UE_rrc_inst[ue_mod_idP].mcch_message[eNB_index] = (MBSFNAreaConfiguration_r9_t *)malloc16(sizeof(MBSFNAreaConfiguration_r9_t));
289

290
  for (i=0; i<8; i++) { // MAX MBSFN Area
gauthier's avatar
   
gauthier committed
291
    UE_rrc_inst[ue_mod_idP].Info[eNB_index].MCCHStatus[i] = 0;
292

293
  }
294
295
}
#endif
296
#endif
297

298
//-----------------------------------------------------------------------------
299
static void openair_rrc_ue_init_security( const protocol_ctxt_t* const ctxt_pP )
300
301
{
#if defined(ENABLE_SECURITY)
gauthier's avatar
gauthier committed
302
303
304
305
  //    uint8_t *kRRCenc;
  //    uint8_t *kRRCint;
  char ascii_buffer[65];
  uint8_t i;
306

307
  memset(UE_rrc_inst[ctxt_pP->module_id].kenb, ctxt_pP->module_id, 32);
308

gauthier's avatar
gauthier committed
309
  for (i = 0; i < 32; i++) {
310
    sprintf(&ascii_buffer[2 * i], "%02X", UE_rrc_inst[ctxt_pP->module_id].kenb[i]);
gauthier's avatar
gauthier committed
311
  }
312

313
314
315
  LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT"[OSA] kenb    = %s\n",
        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
        ascii_buffer);
316
#endif
317
}
318

319
//-----------------------------------------------------------------------------
320
char openair_rrc_ue_init( const module_id_t ue_mod_idP, const unsigned char eNB_index )
321
{
322
  protocol_ctxt_t ctxt;
323
  PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_idP, ENB_FLAG_NO, NOT_A_RNTI, 0, 0,eNB_index);
324
325
326
  LOG_I(RRC,
        PROTOCOL_RRC_CTXT_FMT" Init...\n",
        PROTOCOL_RRC_CTXT_ARGS(&ctxt));
gauthier's avatar
   
gauthier committed
327
328
329
  rrc_set_state (ue_mod_idP, RRC_STATE_INACTIVE);
  rrc_set_sub_state (ue_mod_idP, RRC_SUB_STATE_INACTIVE);

330
331
332
333
334
335
336
337
338
339
  LOG_D(RRC,"[UE %d] INIT State = RRC_IDLE (eNB %d)\n",ctxt.module_id,eNB_index);
  UE_rrc_inst[ctxt.module_id].Info[eNB_index].State=RRC_IDLE;
  UE_rrc_inst[ctxt.module_id].Info[eNB_index].T300_active = 0;
  UE_rrc_inst[ctxt.module_id].Info[eNB_index].T304_active = 0;
  UE_rrc_inst[ctxt.module_id].Info[eNB_index].T310_active = 0;
  UE_rrc_inst[ctxt.module_id].Info[eNB_index].UE_index=0xffff;
  UE_rrc_inst[ctxt.module_id].Srb0[eNB_index].Active=0;
  UE_rrc_inst[ctxt.module_id].Srb1[eNB_index].Active=0;
  UE_rrc_inst[ctxt.module_id].Srb2[eNB_index].Active=0;
  UE_rrc_inst[ctxt.module_id].HandoverInfoUe.measFlag=1;
Cedric Roux's avatar
Cedric Roux committed
340
341
  UE_rrc_inst[ctxt.module_id].ciphering_algorithm = CipheringAlgorithm_r12_eea0;
#if defined(Rel10) || defined(Rel14)
342
  UE_rrc_inst[ctxt.module_id].integrity_algorithm = SecurityAlgorithmConfig__integrityProtAlgorithm_eia0_v920;
343
#else
344
  UE_rrc_inst[ctxt.module_id].integrity_algorithm = SecurityAlgorithmConfig__integrityProtAlgorithm_reserved;
345
346
#endif

347
  openair_rrc_ue_init_security(&ctxt);
348
349
350
  init_SI_UE(&ctxt,eNB_index);
  LOG_D(RRC,PROTOCOL_RRC_CTXT_FMT"  INIT: phy_sync_2_ch_ind\n",
        PROTOCOL_RRC_CTXT_ARGS(&ctxt));
351
352

#ifndef NO_RRM
353
  send_msg(&S_rrc,msg_rrc_phy_synch_to_CH_ind(ctxt.module_id,eNB_index,UE_rrc_inst[ctxt.module_id].Mac_id));
354
355
356
#endif

#ifdef NO_RRM //init ch SRB0, SRB1 & BDTCH
357
  openair_rrc_on(&ctxt);
358
#endif
359
#ifdef CBA
360
  int j;
361

362
  for(j=0; j<NUM_MAX_CBA_GROUP; j++) {
gauthier's avatar
   
gauthier committed
363
    UE_rrc_inst[ue_mod_idP].cba_rnti[j] = 0x0000;
364
  }
365

gauthier's avatar
   
gauthier committed
366
  UE_rrc_inst[ue_mod_idP].num_active_cba_groups = 0;
367
368
369
370
371
#endif

  return 0;
}

372
//-----------------------------------------------------------------------------
373
void rrc_ue_generate_RRCConnectionRequest( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index )
374
{
375

gauthier's avatar
gauthier committed
376
  uint8_t i=0,rv[6];
gauthier's avatar
gauthier committed
377

378
  if(UE_rrc_inst[ctxt_pP->module_id].Srb0[eNB_index].Tx_buffer.payload_size ==0) {
379

380
381
382
383
384
385
    // Get RRCConnectionRequest, fill random for now
    // Generate random byte stream for contention resolution
    for (i=0; i<6; i++) {
#ifdef SMBV
      // if SMBV is configured the contention resolution needs to be fix for the connection procedure to succeed
      rv[i]=i;
386
#else
387
      rv[i]=taus()&0xff;
388
#endif
389
390
      LOG_T(RRC,"%x.",rv[i]);
    }
391

392
    LOG_T(RRC,"\n");
393
394
395
396
397
    UE_rrc_inst[ctxt_pP->module_id].Srb0[eNB_index].Tx_buffer.payload_size =
      do_RRCConnectionRequest(
        ctxt_pP->module_id,
        (uint8_t*)UE_rrc_inst[ctxt_pP->module_id].Srb0[eNB_index].Tx_buffer.Payload,
        rv);
398
399

    LOG_I(RRC,"[UE %d] : Frame %d, Logical Channel UL-CCCH (SRB0), Generating RRCConnectionRequest (bytes %d, eNB %d)\n",
400
          ctxt_pP->module_id, ctxt_pP->frame, UE_rrc_inst[ctxt_pP->module_id].Srb0[eNB_index].Tx_buffer.payload_size, eNB_index);
401

402
403
    for (i=0; i<UE_rrc_inst[ctxt_pP->module_id].Srb0[eNB_index].Tx_buffer.payload_size; i++) {
      LOG_T(RRC,"%x.",UE_rrc_inst[ctxt_pP->module_id].Srb0[eNB_index].Tx_buffer.Payload[i]);
404
405
406
    }

    LOG_T(RRC,"\n");
407
408
    /*UE_rrc_inst[ue_mod_idP].Srb0[Idx].Tx_buffer.Payload[i] = taus()&0xff;
    UE_rrc_inst[ue_mod_idP].Srb0[Idx].Tx_buffer.payload_size =i; */
409
410
411
412
413
414
415

  }
}


mui_t rrc_mui=0;

416
#if !(defined(ENABLE_ITTI) && defined(ENABLE_USE_MME))
417
/* NAS Attach request with IMSI */
418
static const char const nas_attach_req_imsi[] = {
419
420
421
422
423
424
425
426
427
428
429
  0x07, 0x41,
  /* EPS Mobile identity = IMSI */
  0x71, 0x08, 0x29, 0x80, 0x43, 0x21, 0x43, 0x65, 0x87,
  0xF9,
  /* End of EPS Mobile Identity */
  0x02, 0xE0, 0xE0, 0x00, 0x20, 0x02, 0x03,
  0xD0, 0x11, 0x27, 0x1A, 0x80, 0x80, 0x21, 0x10, 0x01, 0x00, 0x00,
  0x10, 0x81, 0x06, 0x00, 0x00, 0x00, 0x00, 0x83, 0x06, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x0A, 0x00, 0x52, 0x12, 0xF2,
  0x01, 0x27, 0x11,
};
430
#endif /* !(defined(ENABLE_ITTI) && defined(ENABLE_USE_MME)) */
431

432
#if 0
433
/* NAS Attach request with GUTI */
434
static const char const nas_attach_req_guti[] = {
435
436
437
438
439
440
441
442
443
444
445
  0x07, 0x41,
  /* EPS Mobile identity = GUTI */
  0x71, 0x0B, 0xF6, 0x12, 0xF2, 0x01, 0x80, 0x00, 0x01, 0xE0, 0x00,
  0xDA, 0x1F,
  /* End of EPS Mobile Identity */
  0x02, 0xE0, 0xE0, 0x00, 0x20, 0x02, 0x03,
  0xD0, 0x11, 0x27, 0x1A, 0x80, 0x80, 0x21, 0x10, 0x01, 0x00, 0x00,
  0x10, 0x81, 0x06, 0x00, 0x00, 0x00, 0x00, 0x83, 0x06, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x0A, 0x00, 0x52, 0x12, 0xF2,
  0x01, 0x27, 0x11,
};
446
#endif
447

448
//-----------------------------------------------------------------------------
449
static void rrc_ue_generate_RRCConnectionSetupComplete( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index, const uint8_t Transaction_id )
450
{
451

gauthier's avatar
gauthier committed
452
453
  uint8_t    buffer[100];
  uint8_t    size;
454
  const char * nas_msg;
winckel's avatar
winckel committed
455
  int   nas_msg_length;
456

winckel's avatar
winckel committed
457
#if defined(ENABLE_ITTI) && defined(ENABLE_USE_MME)
458
459
  nas_msg         = (char*) UE_rrc_inst[ctxt_pP->module_id].initialNasMsg.data;
  nas_msg_length  = UE_rrc_inst[ctxt_pP->module_id].initialNasMsg.length;
winckel's avatar
winckel committed
460
461
462
463
464
#else
  nas_msg         = nas_attach_req_imsi;
  nas_msg_length  = sizeof(nas_attach_req_imsi);
#endif

465
  size = do_RRCConnectionSetupComplete(ctxt_pP->module_id, buffer, Transaction_id, nas_msg_length, nas_msg);
466
467

  LOG_I(RRC,"[UE %d][RAPROC] Frame %d : Logical Channel UL-DCCH (SRB1), Generating RRCConnectionSetupComplete (bytes%d, eNB %d)\n",
468
469
        ctxt_pP->module_id,ctxt_pP->frame, size, eNB_index);
  LOG_D(RLC,
gauthier's avatar
gauthier committed
470
        "[FRAME %05d][RRC_UE][MOD %02d][][--- PDCP_DATA_REQ/%d Bytes (RRCConnectionSetupComplete to eNB %d MUI %d) --->][PDCP][MOD %02d][RB %02d]\n",
471
        ctxt_pP->frame, ctxt_pP->module_id+NB_eNB_INST, size, eNB_index, rrc_mui, ctxt_pP->module_id+NB_eNB_INST, DCCH);
472
473
474
475
476
477
478
479
  rrc_data_req (
		ctxt_pP,
		DCCH,
		rrc_mui++,
		SDU_CONFIRM_NO,
		size,
		buffer,
		PDCP_TRANSMISSION_MODE_CONTROL);
480
481
}

482
//-----------------------------------------------------------------------------
483
static void rrc_ue_generate_RRCConnectionReconfigurationComplete( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index, const uint8_t Transaction_id )
484
{
485

gauthier's avatar
gauthier committed
486
  uint8_t buffer[32], size;
487
488
489
490
  size = do_RRCConnectionReconfigurationComplete(ctxt_pP, buffer, Transaction_id);
  LOG_I(RRC,PROTOCOL_RRC_CTXT_UE_FMT" Logical Channel UL-DCCH (SRB1), Generating RRCConnectionReconfigurationComplete (bytes %d, eNB_index %d)\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP), size, eNB_index);
  LOG_D(RLC,
gauthier's avatar
gauthier committed
491
        "[FRAME %05d][RRC_UE][INST %02d][][--- PDCP_DATA_REQ/%d Bytes (RRCConnectionReconfigurationComplete to eNB %d MUI %d) --->][PDCP][INST %02d][RB %02d]\n",
492
493
494
495
496
497
498
        ctxt_pP->frame,
        UE_MODULE_ID_TO_INSTANCE(ctxt_pP->module_id),
        size,
        eNB_index,
        rrc_mui,
        UE_MODULE_ID_TO_INSTANCE(ctxt_pP->module_id),
        DCCH);
499
500
501
502
503
504
505
506
  rrc_data_req (
		ctxt_pP,
		DCCH,
		rrc_mui++,
		SDU_CONFIRM_NO,
		size,
		buffer,
		PDCP_TRANSMISSION_MODE_CONTROL);
507
508
509
}


510
511
//-----------------------------------------------------------------------------
// Called by L2 interface (MAC)
512
int rrc_ue_decode_ccch( const protocol_ctxt_t* const ctxt_pP, const SRB_INFO* const Srb_info, const uint8_t eNB_index )
513
514
{
  DL_CCCH_Message_t* dl_ccch_msg=NULL;
515
  asn_dec_rval_t dec_rval;
516
  int rval=0;
517

gauthier's avatar
gauthier committed
518
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_CCCH, VCD_FUNCTION_IN);
gauthier's avatar
   
gauthier committed
519
520
  //  LOG_D(RRC,"[UE %d] Decoding DL-CCCH message (%d bytes), State %d\n",ue_mod_idP,Srb_info->Rx_buffer.payload_size,
  //  UE_rrc_inst[ue_mod_idP].Info[eNB_index].State);
521
522

  dec_rval = uper_decode(NULL,
523
524
525
526
                         &asn_DEF_DL_CCCH_Message,
                         (void**)&dl_ccch_msg,
                         (uint8_t*)Srb_info->Rx_buffer.Payload,
                         100,0,0);
527
528
529
530
531

#ifdef XER_PRINT
  xer_fprint(stdout,&asn_DEF_DL_CCCH_Message,(void*)dl_ccch_msg);
#endif

532
#if defined(ENABLE_ITTI)
533
# if defined(DISABLE_ITTI_XER_PRINT)
534
  {
winckel's avatar
winckel committed
535
    MessageDef *msg_p;
536

winckel's avatar
winckel committed
537
538
    msg_p = itti_alloc_new_message (TASK_RRC_UE, RRC_DL_CCCH_MESSAGE);
    memcpy (&msg_p->ittiMsg, (void *) dl_ccch_msg, sizeof(RrcDlCcchMessage));
539

540
    itti_send_msg_to_task (TASK_UNKNOWN, ctxt_pP->instance, msg_p);
541
  }
542
543
# else
  {
544
545
    char        message_string[10000];
    size_t      message_string_size;
546

547
548
    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_DL_CCCH_Message, (void *)dl_ccch_msg)) > 0) {
      MessageDef *msg_p;
549

550
551
552
      msg_p = itti_alloc_new_message_sized (TASK_RRC_UE, RRC_DL_CCCH, message_string_size + sizeof (IttiMsgText));
      msg_p->ittiMsg.rrc_dl_ccch.size = message_string_size;
      memcpy(&msg_p->ittiMsg.rrc_dl_ccch.text, message_string, message_string_size);
553

554
      itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
555
    }
556
557
  }
# endif
558
559
#endif

560
  if ((dec_rval.code != RC_OK) && (dec_rval.consumed==0)) {
Cedric Roux's avatar
Cedric Roux committed
561
    LOG_E(RRC,"[UE %d] Frame %d : Failed to decode DL-CCCH-Message (%zu bytes)\n",ctxt_pP->module_id,ctxt_pP->frame,dec_rval.consumed);
gauthier's avatar
gauthier committed
562
    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_CCCH, VCD_FUNCTION_OUT);
563
    return -1;
564
565
566
567
  }

  if (dl_ccch_msg->message.present == DL_CCCH_MessageType_PR_c1) {

568
    if (UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].State == RRC_SI_RECEIVED) {
569

570
      switch (dl_ccch_msg->message.choice.c1.present) {
571

572
      case DL_CCCH_MessageType__c1_PR_NOTHING:
573
574
575
        LOG_I(RRC, "[UE%d] Frame %d : Received PR_NOTHING on DL-CCCH-Message\n",
              ctxt_pP->module_id,
              ctxt_pP->frame);
576
577
        rval = 0;
        break;
578

579
580
      case DL_CCCH_MessageType__c1_PR_rrcConnectionReestablishment:
        LOG_I(RRC,
581
582
583
              "[UE%d] Frame %d : Logical Channel DL-CCCH (SRB0), Received RRCConnectionReestablishment\n",
              ctxt_pP->module_id,
              ctxt_pP->frame);
584
585
        rval = 0;
        break;
586

587
588
      case DL_CCCH_MessageType__c1_PR_rrcConnectionReestablishmentReject:
        LOG_I(RRC,
589
590
591
              "[UE%d] Frame %d : Logical Channel DL-CCCH (SRB0), Received RRCConnectionReestablishmentReject\n",
              ctxt_pP->module_id,
              ctxt_pP->frame);
592
593
        rval = 0;
        break;
594

595
596
      case DL_CCCH_MessageType__c1_PR_rrcConnectionReject:
        LOG_I(RRC,
597
598
599
              "[UE%d] Frame %d : Logical Channel DL-CCCH (SRB0), Received RRCConnectionReject \n",
              ctxt_pP->module_id,
              ctxt_pP->frame);
600
601
        rval = 0;
        break;
602

603
604
      case DL_CCCH_MessageType__c1_PR_rrcConnectionSetup:
        LOG_I(RRC,
605
606
607
608
              "[UE%d][RAPROC] Frame %d : Logical Channel DL-CCCH (SRB0), Received RRCConnectionSetup RNTI %x\n",
              ctxt_pP->module_id,
              ctxt_pP->frame,
              ctxt_pP->rnti);
609
        // Get configuration
610

611
        // Release T300 timer
612
613
614
615
        UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].T300_active = 0;
        rrc_ue_process_radioResourceConfigDedicated(
          ctxt_pP,
          eNB_index,
616
          &dl_ccch_msg->message.choice.c1.choice.rrcConnectionSetup.criticalExtensions.choice.c1.choice.rrcConnectionSetup_r8.radioResourceConfigDedicated);
617

618
619
620
621
622
623
624
        rrc_set_state (ctxt_pP->module_id, RRC_STATE_CONNECTED);
        rrc_set_sub_state (ctxt_pP->module_id, RRC_SUB_STATE_CONNECTED);
        UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].rnti = ctxt_pP->rnti;
        rrc_ue_generate_RRCConnectionSetupComplete(
          ctxt_pP,
          eNB_index,
          dl_ccch_msg->message.choice.c1.choice.rrcConnectionSetup.rrc_TransactionIdentifier);
625

626
627
        rval = 0;
        break;
628

629
      default:
630
631
632
        LOG_E(RRC, "[UE%d] Frame %d : Unknown message\n",
              ctxt_pP->module_id,
              ctxt_pP->frame);
633
634
        rval = -1;
        break;
635
      }
636
    }
637
638
  }

gauthier's avatar
gauthier committed
639
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_CCCH, VCD_FUNCTION_OUT);
640
641
642
  return rval;
}

643
644
645
646
647
648
649
650
651
//-----------------------------------------------------------------------------
int32_t
rrc_ue_establish_srb1(
  module_id_t ue_mod_idP,
  frame_t frameP,
  uint8_t eNB_index,
  struct SRB_ToAddMod* SRB_config
)
//-----------------------------------------------------------------------------
652
{
653
  // add descriptor from RRC PDU
654

gauthier's avatar
gauthier committed
655
  uint8_t lchan_id = DCCH;
656

gauthier's avatar
   
gauthier committed
657
658
659
  UE_rrc_inst[ue_mod_idP].Srb1[eNB_index].Active = 1;
  UE_rrc_inst[ue_mod_idP].Srb1[eNB_index].Status = RADIO_CONFIG_OK;//RADIO CFG
  UE_rrc_inst[ue_mod_idP].Srb1[eNB_index].Srb_info.Srb_id = 1;
660

gauthier's avatar
gauthier committed
661
  // copy default configuration for now
gauthier's avatar
   
gauthier committed
662
663
  //  memcpy(&UE_rrc_inst[ue_mod_idP].Srb1[eNB_index].Srb_info.Lchan_desc[0],&DCCH_LCHAN_DESC,LCHAN_DESC_SIZE);
  //  memcpy(&UE_rrc_inst[ue_mod_idP].Srb1[eNB_index].Srb_info.Lchan_desc[1],&DCCH_LCHAN_DESC,LCHAN_DESC_SIZE);
664
665


gauthier's avatar
   
gauthier committed
666
  LOG_I(RRC,"[UE %d], CONFIG_SRB1 %d corresponding to eNB_index %d\n", ue_mod_idP,lchan_id,eNB_index);
667

gauthier's avatar
   
gauthier committed
668
669
  //rrc_pdcp_config_req (ue_mod_idP+NB_eNB_INST, frameP, 0, CONFIG_ACTION_ADD, lchan_id,UNDEF_SECURITY_MODE);
  //  rrc_rlc_config_req(ue_mod_idP+NB_eNB_INST,frameP,0,CONFIG_ACTION_ADD,lchan_id,SIGNALLING_RADIO_BEARER,Rlc_info_am_config);
670

gauthier's avatar
   
gauthier committed
671
  //  UE_rrc_inst[ue_mod_idP].Srb1[eNB_index].Srb_info.Tx_buffer.payload_size=DEFAULT_MEAS_IND_SIZE+1;
672
673
674
675
676


  return(0);
}

677
678
679
680
681
682
683
684
685
//-----------------------------------------------------------------------------
int32_t
rrc_ue_establish_srb2(
  module_id_t ue_mod_idP,
  frame_t frameP,
  uint8_t eNB_index,
  struct SRB_ToAddMod* SRB_config
)
//-----------------------------------------------------------------------------
686
{
687
  // add descriptor from RRC PDU
688

gauthier's avatar
gauthier committed
689
  uint8_t lchan_id = DCCH1;
690

gauthier's avatar
   
gauthier committed
691
692
693
  UE_rrc_inst[ue_mod_idP].Srb2[eNB_index].Active = 1;
  UE_rrc_inst[ue_mod_idP].Srb2[eNB_index].Status = RADIO_CONFIG_OK;//RADIO CFG
  UE_rrc_inst[ue_mod_idP].Srb2[eNB_index].Srb_info.Srb_id = 2;
694

gauthier's avatar
gauthier committed
695
  // copy default configuration for now
gauthier's avatar
   
gauthier committed
696
697
  //  memcpy(&UE_rrc_inst[ue_mod_idP].Srb2[eNB_index].Srb_info.Lchan_desc[0],&DCCH_LCHAN_DESC,LCHAN_DESC_SIZE);
  //  memcpy(&UE_rrc_inst[ue_mod_idP].Srb2[eNB_index].Srb_info.Lchan_desc[1],&DCCH_LCHAN_DESC,LCHAN_DESC_SIZE);
698
699


gauthier's avatar
   
gauthier committed
700
  LOG_I(RRC,"[UE %d], CONFIG_SRB2 %d corresponding to eNB_index %d\n",ue_mod_idP,lchan_id,eNB_index);
701

gauthier's avatar
   
gauthier committed
702
703
  //rrc_pdcp_config_req (ue_mod_idP+NB_eNB_INST, frameP, 0, CONFIG_ACTION_ADD, lchan_id, UNDEF_SECURITY_MODE);
  //  rrc_rlc_config_req(ue_mod_idP+NB_eNB_INST,frameP,0,CONFIG_ACTION_ADD,lchan_id,SIGNALLING_RADIO_BEARER,Rlc_info_am_config);
704

gauthier's avatar
   
gauthier committed
705
  //  UE_rrc_inst[ue_mod_idP].Srb1[eNB_index].Srb_info.Tx_buffer.payload_size=DEFAULT_MEAS_IND_SIZE+1;
706
707
708
709
710


  return(0);
}

711
712
713
714
715
716
717
718
719
//-----------------------------------------------------------------------------
int32_t
rrc_ue_establish_drb(
  module_id_t ue_mod_idP,
  frame_t frameP,
  uint8_t eNB_index,
  struct DRB_ToAddMod* DRB_config
)
//-----------------------------------------------------------------------------
720
{
721
722
  // add descriptor from RRC PDU
#ifdef PDCP_USE_NETLINK
723
  int oip_ifup=0,ip_addr_offset3=0,ip_addr_offset4=0;
Cedric Roux's avatar
Cedric Roux committed
724
725
726
727
  /* avoid gcc warnings */
  (void)oip_ifup;
  (void)ip_addr_offset3;
  (void)ip_addr_offset4;
728
#endif
729

730
  LOG_I(RRC,"[UE %d] Frame %d: processing RRCConnectionReconfiguration: reconfiguring DRB %ld/LCID %d\n",
731
        ue_mod_idP, frameP, DRB_config->drb_Identity, (int)*DRB_config->logicalChannelIdentity);
732
  /*
gauthier's avatar
   
gauthier committed
733
  rrc_pdcp_config_req (ue_mod_idP+NB_eNB_INST, frameP, 0, CONFIG_ACTION_ADD,
734
                             (eNB_index * NB_RB_MAX) + *DRB_config->logicalChannelIdentity, UNDEF_SECURITY_MODE);
gauthier's avatar
gauthier committed
735

736
  rrc_rlc_config_req(ue_mod_idP+NB_eNB_INST,frameP,0,CONFIG_ACTION_ADD,
737
738
                    (eNB_index * NB_RB_MAX) + *DRB_config->logicalChannelIdentity,
                    RADIO_ACCESS_BEARER,Rlc_info_um);
gauthier's avatar
gauthier committed
739
   */
740
#ifdef PDCP_USE_NETLINK
741
#   if !defined(OAI_NW_DRIVER_TYPE_ETHERNET) && !defined(EXMIMO) && !defined(OAI_USRP) && !defined(OAI_BLADERF) && !defined(ETHERNET) && !defined(LINK_ENB_PDCP_TO_GTPV1U)
742
#    ifdef OAI_EMU
gauthier's avatar
gauthier committed
743
744
  ip_addr_offset3 = oai_emulation.info.nb_enb_local;
  ip_addr_offset4 = NB_eNB_INST;
745
#    else
gauthier's avatar
gauthier committed
746
747
  ip_addr_offset3 = 0;
  ip_addr_offset4 = 8;
748
#    endif
gauthier's avatar
   
gauthier committed
749
  LOG_I(OIP,"[UE %d] trying to bring up the OAI interface oai%d, IP 10.0.%d.%d\n", ue_mod_idP, ip_addr_offset3+ue_mod_idP,
750
        ip_addr_offset3+ue_mod_idP+1,ip_addr_offset4+ue_mod_idP+1);
gauthier's avatar
   
gauthier committed
751
  oip_ifup=nas_config(ip_addr_offset3+ue_mod_idP,   // interface_id
752
753
754
755
                      ip_addr_offset3+ue_mod_idP+1, // third_octet
                      ip_addr_offset4+ue_mod_idP+1); // fourth_octet

  if (oip_ifup == 0 ) { // interface is up --> send a config the DRB
756
#        ifdef OAI_EMU
757
    oai_emulation.info.oai_ifup[ue_mod_idP]=1;
758
#        endif
759
    LOG_I(OIP,"[UE %d] Config the oai%d to send/receive pkt on DRB %ld to/from the protocol stack\n",
gauthier's avatar
   
gauthier committed
760
761
          ue_mod_idP,
          ip_addr_offset3+ue_mod_idP,
762
          (long int)((eNB_index * maxDRB) + DRB_config->drb_Identity));
763

764
765
766
767
768
769
770
771
    rb_conf_ipv4(0,//add
                 ue_mod_idP,//cx align with the UE index
                 ip_addr_offset3+ue_mod_idP,//inst num_enb+ue_index
                 (eNB_index * maxDRB) + DRB_config->drb_Identity,//rb
                 0,//dscp
                 ipv4_address(ip_addr_offset3+ue_mod_idP+1,ip_addr_offset4+ue_mod_idP+1),//saddr
                 ipv4_address(ip_addr_offset3+ue_mod_idP+1,eNB_index+1));//daddr
    LOG_D(RRC,"[UE %d] State = Attached (eNB %d)\n",ue_mod_idP,eNB_index);
gauthier's avatar
gauthier committed
772
  }
773

774
775
#    else
#        ifdef OAI_EMU
gauthier's avatar
   
gauthier committed
776
  oai_emulation.info.oai_ifup[ue_mod_idP]=1;
777
778
779
780
781
782
783
784
#        endif
#    endif
#endif

  return(0);
}


785
786
787
788
789
790
791
792
//-----------------------------------------------------------------------------
void
rrc_ue_process_measConfig(
  const protocol_ctxt_t* const       ctxt_pP,
  const uint8_t                      eNB_index,
  MeasConfig_t* const               measConfig
)
//-----------------------------------------------------------------------------
793
{
794
795
796
797
798
799
800

  // This is the procedure described in 36.331 Section 5.5.2.1
  int i;
  long ind;
  MeasObjectToAddMod_t *measObj;

  if (measConfig->measObjectToRemoveList != NULL) {
801
802
    for (i=0; i<measConfig->measObjectToRemoveList->list.count; i++) {
      ind   = *measConfig->measObjectToRemoveList->list.array[i];
803
      free(UE_rrc_inst[ctxt_pP->module_id].MeasObj[eNB_index][ind-1]);
804
    }
805
  }
806

807
  if (measConfig->measObjectToAddModList != NULL) {
808
809
810
811
812
813
    LOG_D(RRC,"Measurement Object List is present\n");

    for (i=0; i<measConfig->measObjectToAddModList->list.count; i++) {
      measObj = measConfig->measObjectToAddModList->list.array[i];
      ind   = measConfig->measObjectToAddModList->list.array[i]->measObjectId;

814
      if (UE_rrc_inst[ctxt_pP->module_id].MeasObj[eNB_index][ind-1]) {
Cedric Roux's avatar
Cedric Roux committed
815
        LOG_D(RRC,"Modifying measurement object %ld\n",ind);
816
        memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].MeasObj[eNB_index][ind-1],
817
818
819
               (char*)measObj,
               sizeof(MeasObjectToAddMod_t));
      } else {
Cedric Roux's avatar
Cedric Roux committed
820
        LOG_I(RRC,"Adding measurement object %ld\n",ind);
821
822

        if (measObj->measObject.present == MeasObjectToAddMod__measObject_PR_measObjectEUTRA) {
Cedric Roux's avatar
Cedric Roux committed
823
          LOG_I(RRC,"EUTRA Measurement : carrierFreq %ld, allowedMeasBandwidth %ld,presenceAntennaPort1 %d, neighCellConfig %d\n",
824
825
826
827
                measObj->measObject.choice.measObjectEUTRA.carrierFreq,
                measObj->measObject.choice.measObjectEUTRA.allowedMeasBandwidth,
                measObj->measObject.choice.measObjectEUTRA.presenceAntennaPort1,
                measObj->measObject.choice.measObjectEUTRA.neighCellConfig.buf[0]);
828
          UE_rrc_inst[ctxt_pP->module_id].MeasObj[eNB_index][ind-1]=measObj;
829
        }
830
      }
831
832
    }

Bilel's avatar
Bilel committed
833
    LOG_I(RRC,"call rrc_mac_config_req \n");
834

835
836
837
    rrc_mac_config_req_ue(ctxt_pP->module_id,0,eNB_index,
			  (RadioResourceConfigCommonSIB_t *)NULL,
			  (struct PhysicalConfigDedicated *)NULL,
Cedric Roux's avatar
Cedric Roux committed
838
#if defined(Rel10) || defined(Rel14)
839
840
			  (SCellToAddMod_r10_t *)NULL,
			  //struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
841
#endif
842
843
844
845
846
847
848
849
850
851
852
853
854
			  UE_rrc_inst[ctxt_pP->module_id].MeasObj[eNB_index],
			  (MAC_MainConfig_t *)NULL,
			  0,
			  (struct LogicalChannelConfig *)NULL,
			  (MeasGapConfig_t *)NULL,
			  (TDD_Config_t *)NULL,
			  (MobilityControlInfo_t *)NULL,
			  NULL,
			  NULL,
			  NULL,
			  NULL,
			  NULL,
			  NULL
Cedric Roux's avatar
Cedric Roux committed
855
#if defined(Rel10) || defined(Rel14)
856
			  ,0,
857
858
			  (MBSFN_AreaInfoList_r9_t *)NULL,
			  (PMCH_InfoList_r9_t *)NULL
859

860
861
#endif
#ifdef CBA
862
863
864
			  ,
			  0,
			  0
865
#endif
866
			  );
867
  }
868

869
  if (measConfig->reportConfigToRemoveList != NULL) {
870
871
    for (i=0; i<measConfig->reportConfigToRemoveList->list.count; i++) {
      ind   = *measConfig->reportConfigToRemoveList->list.array[i];
872
      free(UE_rrc_inst[ctxt_pP->module_id].ReportConfig[eNB_index][ind-1]);
873
    }
874
  }
875

876
  if (measConfig->reportConfigToAddModList != NULL) {
877
878
879
880
881
    LOG_I(RRC,"Report Configuration List is present\n");

    for (i=0; i<measConfig->reportConfigToAddModList->list.count; i++) {
      ind   = measConfig->reportConfigToAddModList->list.array[i]->reportConfigId;

882
      if (UE_rrc_inst[ctxt_pP->module_id].ReportConfig[eNB_index][ind-1]) {
Cedric Roux's avatar
Cedric Roux committed
883
        LOG_I(RRC,"Modifying Report Configuration %ld\n",ind-1);
884
        memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].ReportConfig[eNB_index][ind-1],
885
886
887
               (char*)measConfig->reportConfigToAddModList->list.array[i],
               sizeof(ReportConfigToAddMod_t));
      } else {
Cedric Roux's avatar
Cedric Roux committed
888
        LOG_D(RRC,"Adding Report Configuration %ld %p \n",ind-1,measConfig->reportConfigToAddModList->list.array[i]);
889
        UE_rrc_inst[ctxt_pP->module_id].ReportConfig[eNB_index][ind-1] = measConfig->reportConfigToAddModList->list.array[i];
890
      }
891
    }
892
893
894
  }

  if (measConfig->quantityConfig != NULL) {
895
    if (UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index]) {
896
      LOG_D(RRC,"Modifying Quantity Configuration \n");
897
      memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index],
898
899
900
901
             (char*)measConfig->quantityConfig,
             sizeof(QuantityConfig_t));
    } else {
      LOG_D(RRC,"Adding Quantity configuration\n");
902
      UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index] = measConfig->quantityConfig;
903
    }
904
905
906
  }

  if (measConfig->measIdToRemoveList != NULL) {
907
908
    for (i=0; i<measConfig->measIdToRemoveList->list.count; i++) {
      ind   = *measConfig->measIdToRemoveList->list.array[i];
909
      free(UE_rrc_inst[ctxt_pP->module_id].MeasId[eNB_index][ind-1]);
910
    }
911
912
913
  }

  if (measConfig->measIdToAddModList != NULL) {
914
915