rrc_UE.c 188 KB
Newer Older
1
/*******************************************************************************
2 3
    OpenAirInterface
    Copyright(c) 1999 - 2014 Eurecom
4

5 6 7 8
    OpenAirInterface is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
9 10


11 12 13 14
    OpenAirInterface is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
15

16 17 18 19
    You should have received a copy of the GNU General Public License
    along with OpenAirInterface.The full GNU General Public License is
    included in this distribution in the file called "COPYING". If not,
    see <http://www.gnu.org/licenses/>.
20 21

  Contact Information
22 23
  OpenAirInterface Admin: openair_admin@eurecom.fr
  OpenAirInterface Tech : openair_tech@eurecom.fr
24
  OpenAirInterface Dev  : openair4g-devel@lists.eurecom.fr
25

ghaddab's avatar
ghaddab committed
26
  Address      : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE
27

28
*******************************************************************************/
29
/*! \file rrc_UE.c
30
 * \brief rrc procedures for UE
31 32
 * \author Navid Nikaein and Raymond Knopp
 * \date 2011 - 2014
33 34
 * \version 1.0
 * \company Eurecom
35
 * \email: navid.nikaein@eurecom.fr and raymond.knopp@eurecom.fr
36
 */
37

Lionel Gauthier's avatar
Lionel Gauthier committed
38 39
#define RRC_UE
#define RRC_UE_C
40

41
#include "assertions.h"
42
#include "asn1_conversions.h"
43
#include "defs.h"
44
#include "PHY/TOOLS/dB_routines.h"
45 46
#include "extern.h"
#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"
47
#include "RRC/LITE/rrc_eNB_primitives.h"
48 49 50 51
#include "LAYER2/RLC/rlc.h"
#include "COMMON/mac_rrc_primitives.h"
#include "UTIL/LOG/log.h"
#include "UTIL/LOG/vcd_signal_dumper.h"
52 53 54
#ifndef CELLULAR
#include "RRC/LITE/MESSAGES/asn1_msg.h"
#endif
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
#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"
#ifdef Rel10
#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
79
#if ENABLE_RAL
Lionel Gauthier's avatar
Lionel Gauthier committed
80 81
#include "rrc_UE_ral.h"
#endif
82 83 84 85 86

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

87
#include "pdcp.h"
88
#include "plmn_data.h"
Lionel Gauthier's avatar
Lionel Gauthier committed
89
#include "msc.h"
90

91 92 93 94
#if defined(ENABLE_ITTI)
# include "intertask_interface.h"
#endif

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


98 99 100 101 102 103 104 105 106 107 108
#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

//#define XER_PRINT

109
extern int8_t dB_fixed2(uint32_t x,uint32_t y);
110

111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153

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

static void rrc_ue_generate_MeasurementReport( const protocol_ctxt_t* const ctxt_pP, uint8_t eNB_index );

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

static void decode_MBSFNAreaConfiguration(module_id_t module_idP, uint8_t eNB_index, frame_t frameP,uint8_t mbsfn_sync_area);








winckel's avatar
winckel committed
154
/*------------------------------------------------------------------------------*/
155 156
static Rrc_State_t rrc_get_state (module_id_t ue_mod_idP)
{
Lionel Gauthier's avatar
 
Lionel Gauthier committed
157
  return UE_rrc_inst[ue_mod_idP].RrcState;
winckel's avatar
winckel committed
158 159
}

160 161
static Rrc_Sub_State_t rrc_get_sub_state (module_id_t ue_mod_idP)
{
Lionel Gauthier's avatar
 
Lionel Gauthier committed
162
  return UE_rrc_inst[ue_mod_idP].RrcSubState;
winckel's avatar
winckel committed
163 164
}

165 166
static int rrc_set_state (module_id_t ue_mod_idP, Rrc_State_t state)
{
winckel's avatar
winckel committed
167
  AssertFatal ((RRC_STATE_FIRST <= state) && (state <= RRC_STATE_LAST),
168
               "Invalid state %d!\n", state);
winckel's avatar
winckel committed
169

Lionel Gauthier's avatar
 
Lionel Gauthier committed
170
  if (UE_rrc_inst[ue_mod_idP].RrcState != state) {
171
    UE_rrc_inst[ue_mod_idP].RrcState = state;
winckel's avatar
winckel committed
172

173
#if defined(ENABLE_ITTI)
174 175
    {
      MessageDef *msg_p;
176

177 178 179
      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
180

181
      itti_send_msg_to_task(TASK_UNKNOWN, UE_MODULE_ID_TO_INSTANCE(ue_mod_idP), msg_p);
182
    }
183
#endif
184
    return (1);
winckel's avatar
winckel committed
185 186 187 188 189
  }

  return (0);
}

190
//-----------------------------------------------------------------------------
191
static int rrc_set_sub_state( module_id_t ue_mod_idP, Rrc_Sub_State_t subState )
192
{
193
#if (defined(ENABLE_ITTI) && (defined(ENABLE_USE_MME) || ENABLE_RAL))
194

Lionel Gauthier's avatar
 
Lionel Gauthier committed
195
  switch (UE_rrc_inst[ue_mod_idP].RrcState) {
196 197
  case RRC_STATE_INACTIVE:
    AssertFatal ((RRC_SUB_STATE_INACTIVE_FIRST <= subState) && (subState <= RRC_SUB_STATE_INACTIVE_LAST),
198
                 "Invalid sub state %d for state %d!\n", subState, UE_rrc_inst[ue_mod_idP].RrcState);
199 200 201 202
    break;

  case RRC_STATE_IDLE:
    AssertFatal ((RRC_SUB_STATE_IDLE_FIRST <= subState) && (subState <= RRC_SUB_STATE_IDLE_LAST),
203
                 "Invalid sub state %d for state %d!\n", subState, UE_rrc_inst[ue_mod_idP].RrcState);
204 205 206 207
    break;

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

212
#endif
winckel's avatar
winckel committed
213

Lionel Gauthier's avatar
 
Lionel Gauthier committed
214
  if (UE_rrc_inst[ue_mod_idP].RrcSubState != subState) {
215
    UE_rrc_inst[ue_mod_idP].RrcSubState = subState;
winckel's avatar
winckel committed
216

217
#if defined(ENABLE_ITTI)
218 219
    {
      MessageDef *msg_p;
winckel's avatar
winckel committed
220

221 222 223
      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;
224

225
      itti_send_msg_to_task(TASK_UNKNOWN, UE_MODULE_ID_TO_INSTANCE(ue_mod_idP), msg_p);
226
    }
227
#endif
228
    return (1);
winckel's avatar
winckel committed
229 230 231 232 233
  }

  return (0);
}

234
//-----------------------------------------------------------------------------
235
static void init_SI_UE( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index )
236
{
237 238
  UE_rrc_inst[ctxt_pP->module_id].sizeof_SIB1[eNB_index] = 0;
  UE_rrc_inst[ctxt_pP->module_id].sizeof_SI[eNB_index] = 0;
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
  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) );
#ifdef Rel10
  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 );
256

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

259
  UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus = 0;
260
  UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIcnt    = 0;
261 262 263
}

#ifdef Rel10
264 265
//-----------------------------------------------------------------------------
static void init_MCCH_UE(module_id_t ue_mod_idP, uint8_t eNB_index)
266
{
267
  int i;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
268 269 270
  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));
271

272
  for (i=0; i<8; i++) { // MAX MBSFN Area
Lionel Gauthier's avatar
 
Lionel Gauthier committed
273
    UE_rrc_inst[ue_mod_idP].Info[eNB_index].MCCHStatus[i] = 0;
274

275
  }
276 277 278
}
#endif

279 280
//-----------------------------------------------------------------------------
static void openair_rrc_lite_ue_init_security( const protocol_ctxt_t* const ctxt_pP )
281 282
{
#if defined(ENABLE_SECURITY)
283 284 285 286
  //    uint8_t *kRRCenc;
  //    uint8_t *kRRCint;
  char ascii_buffer[65];
  uint8_t i;
287

288
  memset(UE_rrc_inst[ctxt_pP->module_id].kenb, ctxt_pP->module_id, 32);
289

290
  for (i = 0; i < 32; i++) {
291
    sprintf(&ascii_buffer[2 * i], "%02X", UE_rrc_inst[ctxt_pP->module_id].kenb[i]);
292
  }
293

294 295 296
  LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT"[OSA] kenb    = %s\n",
        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
        ascii_buffer);
297
#endif
298
}
299

300
//-----------------------------------------------------------------------------
301
char openair_rrc_lite_ue_init( const module_id_t ue_mod_idP, const unsigned char eNB_index )
302
{
303
  protocol_ctxt_t ctxt;
304
  PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_idP, ENB_FLAG_NO, NOT_A_RNTI, 0, 0,eNB_index);
305 306 307
  LOG_I(RRC,
        PROTOCOL_RRC_CTXT_FMT" Init...\n",
        PROTOCOL_RRC_CTXT_ARGS(&ctxt));
Lionel Gauthier's avatar
 
Lionel Gauthier committed
308 309 310
  rrc_set_state (ue_mod_idP, RRC_STATE_INACTIVE);
  rrc_set_sub_state (ue_mod_idP, RRC_SUB_STATE_INACTIVE);

311 312 313 314 315 316 317 318 319 320 321
  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;
  UE_rrc_inst[ctxt.module_id].ciphering_algorithm = SecurityAlgorithmConfig__cipheringAlgorithm_eea0;
322
#ifdef Rel10
323
  UE_rrc_inst[ctxt.module_id].integrity_algorithm = SecurityAlgorithmConfig__integrityProtAlgorithm_eia0_v920;
324
#else
325
  UE_rrc_inst[ctxt.module_id].integrity_algorithm = SecurityAlgorithmConfig__integrityProtAlgorithm_reserved;
326 327
#endif

328 329 330 331
  openair_rrc_lite_ue_init_security(&ctxt);
  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));
332 333

#ifndef NO_RRM
334
  send_msg(&S_rrc,msg_rrc_phy_synch_to_CH_ind(ctxt.module_id,eNB_index,UE_rrc_inst[ctxt.module_id].Mac_id));
335 336 337
#endif

#ifdef NO_RRM //init ch SRB0, SRB1 & BDTCH
338
  openair_rrc_on(&ctxt);
339
#endif
340
#ifdef CBA
341
  int j;
342

343
  for(j=0; j<NUM_MAX_CBA_GROUP; j++) {
Lionel Gauthier's avatar
 
Lionel Gauthier committed
344
    UE_rrc_inst[ue_mod_idP].cba_rnti[j] = 0x0000;
345
  }
346

Lionel Gauthier's avatar
 
Lionel Gauthier committed
347
  UE_rrc_inst[ue_mod_idP].num_active_cba_groups = 0;
348 349 350 351 352
#endif

  return 0;
}

353
//-----------------------------------------------------------------------------
354
void rrc_ue_generate_RRCConnectionRequest( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index )
355
{
356

357
  uint8_t i=0,rv[6];
358

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

361 362 363 364 365 366
    // 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;
367
#else
368
      rv[i]=taus()&0xff;
369
#endif
370 371
      LOG_T(RRC,"%x.",rv[i]);
    }
372

373
    LOG_T(RRC,"\n");
374 375 376 377 378
    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);
379 380

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

383 384
    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]);
385 386 387
    }

    LOG_T(RRC,"\n");
388 389
    /*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; */
390 391 392 393 394 395 396

  }
}


mui_t rrc_mui=0;

397
/* NAS Attach request with IMSI */
398
static const char const nas_attach_req_imsi[] = {
399 400 401 402 403 404 405 406 407 408 409
  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,
};
410 411

/* NAS Attach request with GUTI */
412
static const char const nas_attach_req_guti[] = {
413 414 415 416 417 418 419 420 421 422 423
  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,
};
424

425
//-----------------------------------------------------------------------------
426
static void rrc_ue_generate_RRCConnectionSetupComplete( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index, const uint8_t Transaction_id )
427
{
428

429 430
  uint8_t    buffer[100];
  uint8_t    size;
431
  const char * nas_msg;
winckel's avatar
winckel committed
432
  int   nas_msg_length;
433

winckel's avatar
winckel committed
434
#if defined(ENABLE_ITTI) && defined(ENABLE_USE_MME)
435 436
  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
437 438 439 440 441
#else
  nas_msg         = nas_attach_req_imsi;
  nas_msg_length  = sizeof(nas_attach_req_imsi);
#endif

442
  size = do_RRCConnectionSetupComplete(ctxt_pP->module_id, buffer, Transaction_id, nas_msg_length, nas_msg);
443 444

  LOG_I(RRC,"[UE %d][RAPROC] Frame %d : Logical Channel UL-DCCH (SRB1), Generating RRCConnectionSetupComplete (bytes%d, eNB %d)\n",
445 446
        ctxt_pP->module_id,ctxt_pP->frame, size, eNB_index);
  LOG_D(RLC,
Lionel Gauthier's avatar
Lionel Gauthier committed
447
        "[FRAME %05d][RRC_UE][MOD %02d][][--- PDCP_DATA_REQ/%d Bytes (RRCConnectionSetupComplete to eNB %d MUI %d) --->][PDCP][MOD %02d][RB %02d]\n",
448 449 450 451 452 453 454 455 456
        ctxt_pP->frame, ctxt_pP->module_id+NB_eNB_INST, size, eNB_index, rrc_mui, ctxt_pP->module_id+NB_eNB_INST, DCCH);
  pdcp_rrc_data_req (
    ctxt_pP,
    DCCH,
    rrc_mui++,
    SDU_CONFIRM_NO,
    size,
    buffer,
    PDCP_TRANSMISSION_MODE_CONTROL);
457 458
}

459
//-----------------------------------------------------------------------------
460
static void rrc_ue_generate_RRCConnectionReconfigurationComplete( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index, const uint8_t Transaction_id )
461
{
462

463
  uint8_t buffer[32], size;
464 465 466
  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);
467
  LOG_D(RRC,
Lionel Gauthier's avatar
Lionel Gauthier committed
468
        "[FRAME %05d][RRC_UE][INST %02d][][--- PDCP_DATA_REQ/%d Bytes (RRCConnectionReconfigurationComplete to eNB %d MUI %d) --->][PDCP][INST %02d][RB %02d]\n",
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
        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);
  pdcp_rrc_data_req (
    ctxt_pP,
    DCCH,
    rrc_mui++,
    SDU_CONFIRM_NO,
    size,
    buffer,
    PDCP_TRANSMISSION_MODE_CONTROL);
484 485 486
}


487 488
//-----------------------------------------------------------------------------
// Called by L2 interface (MAC)
489
int rrc_ue_decode_ccch( const protocol_ctxt_t* const ctxt_pP, const SRB_INFO* const Srb_info, const uint8_t eNB_index )
490 491
{
  DL_CCCH_Message_t* dl_ccch_msg=NULL;
492
  asn_dec_rval_t dec_rval;
493
  int rval=0;
494

495
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_CCCH, VCD_FUNCTION_IN);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
496 497
  //  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);
498 499

  dec_rval = uper_decode(NULL,
500 501 502 503
                         &asn_DEF_DL_CCCH_Message,
                         (void**)&dl_ccch_msg,
                         (uint8_t*)Srb_info->Rx_buffer.Payload,
                         100,0,0);
504 505 506 507 508

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

509
#if defined(ENABLE_ITTI)
510
# if defined(DISABLE_ITTI_XER_PRINT)
511
  {
winckel's avatar
winckel committed
512
    MessageDef *msg_p;
513

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

517
    itti_send_msg_to_task (TASK_UNKNOWN, ctxt_pP->instance, msg_p);
518
  }
519 520
# else
  {
521 522
    char        message_string[10000];
    size_t      message_string_size;
523

524 525
    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_DL_CCCH_Message, (void *)dl_ccch_msg)) > 0) {
      MessageDef *msg_p;
526

527 528 529
      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);
530

531
      itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
532
    }
533 534
  }
# endif
535 536
#endif

537
  if ((dec_rval.code != RC_OK) && (dec_rval.consumed==0)) {
538
    LOG_E(RRC,"[UE %d] Frame %d : Failed to decode DL-CCCH-Message (%d bytes)\n",ctxt_pP->module_id,dec_rval.consumed);
539
    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_CCCH, VCD_FUNCTION_OUT);
540
    return -1;
541 542 543 544
  }

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

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

547
      switch (dl_ccch_msg->message.choice.c1.present) {
548

549
      case DL_CCCH_MessageType__c1_PR_NOTHING:
550 551 552
        LOG_I(RRC, "[UE%d] Frame %d : Received PR_NOTHING on DL-CCCH-Message\n",
              ctxt_pP->module_id,
              ctxt_pP->frame);
553 554
        rval = 0;
        break;
555

556 557
      case DL_CCCH_MessageType__c1_PR_rrcConnectionReestablishment:
        LOG_I(RRC,
558 559 560
              "[UE%d] Frame %d : Logical Channel DL-CCCH (SRB0), Received RRCConnectionReestablishment\n",
              ctxt_pP->module_id,
              ctxt_pP->frame);
561 562
        rval = 0;
        break;
563

564 565
      case DL_CCCH_MessageType__c1_PR_rrcConnectionReestablishmentReject:
        LOG_I(RRC,
566 567 568
              "[UE%d] Frame %d : Logical Channel DL-CCCH (SRB0), Received RRCConnectionReestablishmentReject\n",
              ctxt_pP->module_id,
              ctxt_pP->frame);
569 570
        rval = 0;
        break;
571

572 573
      case DL_CCCH_MessageType__c1_PR_rrcConnectionReject:
        LOG_I(RRC,
574 575 576
              "[UE%d] Frame %d : Logical Channel DL-CCCH (SRB0), Received RRCConnectionReject \n",
              ctxt_pP->module_id,
              ctxt_pP->frame);
577 578
        rval = 0;
        break;
579

580 581
      case DL_CCCH_MessageType__c1_PR_rrcConnectionSetup:
        LOG_I(RRC,
582 583 584 585
              "[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);
586
        // Get configuration
587

588
        // Release T300 timer
589 590 591 592
        UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].T300_active = 0;
        rrc_ue_process_radioResourceConfigDedicated(
          ctxt_pP,
          eNB_index,
593
          &dl_ccch_msg->message.choice.c1.choice.rrcConnectionSetup.criticalExtensions.choice.c1.choice.rrcConnectionSetup_r8.radioResourceConfigDedicated);
594

595 596 597 598 599 600 601
        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);
602

603 604
        rval = 0;
        break;
605

606
      default:
607 608 609
        LOG_E(RRC, "[UE%d] Frame %d : Unknown message\n",
              ctxt_pP->module_id,
              ctxt_pP->frame);
610 611
        rval = -1;
        break;
612
      }
613
    }
614 615
  }

616
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_CCCH, VCD_FUNCTION_OUT);
617 618 619
  return rval;
}

620 621 622 623 624 625 626 627 628
//-----------------------------------------------------------------------------
int32_t
rrc_ue_establish_srb1(
  module_id_t ue_mod_idP,
  frame_t frameP,
  uint8_t eNB_index,
  struct SRB_ToAddMod* SRB_config
)
//-----------------------------------------------------------------------------
629
{
630
  // add descriptor from RRC PDU
631

632
  uint8_t lchan_id = DCCH;
633

Lionel Gauthier's avatar
 
Lionel Gauthier committed
634 635 636
  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;
637

638
  // copy default configuration for now
Lionel Gauthier's avatar
 
Lionel Gauthier committed
639 640
  //  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);
641 642


Lionel Gauthier's avatar
 
Lionel Gauthier committed
643
  LOG_I(RRC,"[UE %d], CONFIG_SRB1 %d corresponding to eNB_index %d\n", ue_mod_idP,lchan_id,eNB_index);
644

Lionel Gauthier's avatar
 
Lionel Gauthier committed
645 646
  //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);
647

Lionel Gauthier's avatar
 
Lionel Gauthier committed
648
  //  UE_rrc_inst[ue_mod_idP].Srb1[eNB_index].Srb_info.Tx_buffer.payload_size=DEFAULT_MEAS_IND_SIZE+1;
649 650 651 652 653


  return(0);
}

654 655 656 657 658 659 660 661 662
//-----------------------------------------------------------------------------
int32_t
rrc_ue_establish_srb2(
  module_id_t ue_mod_idP,
  frame_t frameP,
  uint8_t eNB_index,
  struct SRB_ToAddMod* SRB_config
)
//-----------------------------------------------------------------------------
663
{
664
  // add descriptor from RRC PDU
665

666
  uint8_t lchan_id = DCCH1;
667

Lionel Gauthier's avatar
 
Lionel Gauthier committed
668 669 670
  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;
671

672
  // copy default configuration for now
Lionel Gauthier's avatar
 
Lionel Gauthier committed
673 674
  //  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);
675 676


Lionel Gauthier's avatar
 
Lionel Gauthier committed
677
  LOG_I(RRC,"[UE %d], CONFIG_SRB2 %d corresponding to eNB_index %d\n",ue_mod_idP,lchan_id,eNB_index);
678

Lionel Gauthier's avatar
 
Lionel Gauthier committed
679 680
  //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);
681

Lionel Gauthier's avatar
 
Lionel Gauthier committed
682
  //  UE_rrc_inst[ue_mod_idP].Srb1[eNB_index].Srb_info.Tx_buffer.payload_size=DEFAULT_MEAS_IND_SIZE+1;
683 684 685 686 687


  return(0);
}

688 689 690 691 692 693 694 695 696
//-----------------------------------------------------------------------------
int32_t
rrc_ue_establish_drb(
  module_id_t ue_mod_idP,
  frame_t frameP,
  uint8_t eNB_index,
  struct DRB_ToAddMod* DRB_config
)
//-----------------------------------------------------------------------------
697
{
698 699
  // add descriptor from RRC PDU
#ifdef PDCP_USE_NETLINK
700
  int oip_ifup=0,ip_addr_offset3=0,ip_addr_offset4=0;
701
#endif
702

703
  LOG_I(RRC,"[UE %d] Frame %d: processing RRCConnectionReconfiguration: reconfiguring DRB %ld/LCID %d\n",
704
        ue_mod_idP, frameP, DRB_config->drb_Identity, (int)*DRB_config->logicalChannelIdentity);
705
  /*
Lionel Gauthier's avatar
 
Lionel Gauthier committed
706
  rrc_pdcp_config_req (ue_mod_idP+NB_eNB_INST, frameP, 0, CONFIG_ACTION_ADD,
707
                             (eNB_index * NB_RB_MAX) + *DRB_config->logicalChannelIdentity, UNDEF_SECURITY_MODE);
708

709
  rrc_rlc_config_req(ue_mod_idP+NB_eNB_INST,frameP,0,CONFIG_ACTION_ADD,
710 711
                    (eNB_index * NB_RB_MAX) + *DRB_config->logicalChannelIdentity,
                    RADIO_ACCESS_BEARER,Rlc_info_um);
712
   */
713
#ifdef PDCP_USE_NETLINK
714
#   if !defined(OAI_NW_DRIVER_TYPE_ETHERNET) && !defined(EXMIMO) && !defined(OAI_USRP) && !defined(OAI_BLADERF) && !defined(ETHERNET) && !defined(LINK_ENB_PDCP_TO_GTPV1U)
715
#    ifdef OAI_EMU
716 717
  ip_addr_offset3 = oai_emulation.info.nb_enb_local;
  ip_addr_offset4 = NB_eNB_INST;
718
#    else
719 720
  ip_addr_offset3 = 0;
  ip_addr_offset4 = 8;
721
#    endif
Lionel Gauthier's avatar
 
Lionel Gauthier committed
722
  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,
723
        ip_addr_offset3+ue_mod_idP+1,ip_addr_offset4+ue_mod_idP+1);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
724
  oip_ifup=nas_config(ip_addr_offset3+ue_mod_idP,   // interface_id
725 726 727 728
                      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
729
#        ifdef OAI_EMU
730
    oai_emulation.info.oai_ifup[ue_mod_idP]=1;
731
#        endif
732
    LOG_I(OIP,"[UE %d] Config the oai%d to send/receive pkt on DRB %d to/from the protocol stack\n",
Lionel Gauthier's avatar
 
Lionel Gauthier committed
733 734
          ue_mod_idP,
          ip_addr_offset3+ue_mod_idP,
735
          (eNB_index * maxDRB) + DRB_config->drb_Identity);
736

737 738 739 740 741 742 743 744
    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);
745
  }
746

747 748
#    else
#        ifdef OAI_EMU
Lionel Gauthier's avatar
 
Lionel Gauthier committed
749
  oai_emulation.info.oai_ifup[ue_mod_idP]=1;
750 751 752 753 754 755 756 757
#        endif
#    endif
#endif

  return(0);
}


758 759 760 761 762 763 764 765
//-----------------------------------------------------------------------------
void
rrc_ue_process_measConfig(
  const protocol_ctxt_t* const       ctxt_pP,
  const uint8_t                      eNB_index,
  MeasConfig_t* const               measConfig
)
//-----------------------------------------------------------------------------
766
{
767 768 769 770 771 772 773

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

  if (measConfig->measObjectToRemoveList != NULL) {
774 775
    for (i=0; i<measConfig->measObjectToRemoveList->list.count; i++) {
      ind   = *measConfig->measObjectToRemoveList->list.array[i];
776
      free(UE_rrc_inst[ctxt_pP->module_id].MeasObj[eNB_index][ind-1]);
777
    }
778
  }
779

780
  if (measConfig->measObjectToAddModList != NULL) {
781 782 783 784 785 786
    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;

787
      if (UE_rrc_inst[ctxt_pP->module_id].MeasObj[eNB_index][ind-1]) {
788
        LOG_D(RRC,"Modifying measurement object %d\n",ind);
789
        memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].MeasObj[eNB_index][ind-1],
790 791 792 793 794 795 796 797 798 799 800
               (char*)measObj,
               sizeof(MeasObjectToAddMod_t));
      } else {
        LOG_I(RRC,"Adding measurement object %d\n",ind);

        if (measObj->measObject.present == MeasObjectToAddMod__measObject_PR_measObjectEUTRA) {
          LOG_I(RRC,"EUTRA Measurement : carrierFreq %d, allowedMeasBandwidth %d,presenceAntennaPort1 %d, neighCellConfig %d\n",
                measObj->measObject.choice.measObjectEUTRA.carrierFreq,
                measObj->measObject.choice.measObjectEUTRA.allowedMeasBandwidth,
                measObj->measObject.choice.measObjectEUTRA.presenceAntennaPort1,
                measObj->measObject.choice.measObjectEUTRA.neighCellConfig.buf[0]);
801
          UE_rrc_inst[ctxt_pP->module_id].MeasObj[eNB_index][ind-1]=measObj;
802
        }
803
      }
804 805
    }

806
    rrc_mac_config_req(ctxt_pP->module_id,0,ENB_FLAG_NO,0,eNB_index,
807 808
                       (RadioResourceConfigCommonSIB_t *)NULL,
                       (struct PhysicalConfigDedicated *)NULL,
809
#ifdef Rel10
810 811 812
                       (SCellToAddMod_r10_t *)NULL,
                       //struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
#endif
813
                       UE_rrc_inst[ctxt_pP->module_id].MeasObj[eNB_index],
814 815 816 817 818 819 820 821 822 823 824 825
                       (MAC_MainConfig_t *)NULL,
                       0,
                       (struct LogicalChannelConfig *)NULL,
                       (MeasGapConfig_t *)NULL,
                       (TDD_Config_t *)NULL,
                       (MobilityControlInfo_t *)NULL,
                       NULL,
                       NULL,
                       NULL,
                       NULL,
                       NULL,
                       NULL
826
#ifdef Rel10
827 828 829 830
                       ,
                       0,
                       (MBSFN_AreaInfoList_r9_t *)NULL,
                       (PMCH_InfoList_r9_t *)NULL
831 832
#endif
#ifdef CBA
833 834 835
                       ,
                       0,
                       0
836
#endif
837
                      );
838
  }
839

840
  if (measConfig->reportConfigToRemoveList != NULL) {
841 842
    for (i=0; i<measConfig->reportConfigToRemoveList->list.count; i++) {
      ind   = *measConfig->reportConfigToRemoveList->list.array[i];
843
      free(UE_rrc_inst[ctxt_pP->module_id].ReportConfig[eNB_index][ind-1]);
844
    }
845
  }
846

847
  if (measConfig->reportConfigToAddModList != NULL) {
848 849 850 851 852
    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;

853
      if (UE_rrc_inst[ctxt_pP->module_id].ReportConfig[eNB_index][ind-1]) {
854
        LOG_I(RRC,"Modifying Report Configuration %d\n",ind-1);
855
        memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].ReportConfig[eNB_index][ind-1],
856 857 858 859
               (char*)measConfig->reportConfigToAddModList->list.array[i],
               sizeof(ReportConfigToAddMod_t));
      } else {
        LOG_D(RRC,"Adding Report Configuration %d %p \n",ind-1,measConfig->reportConfigToAddModList->list.array[i]);
860
        UE_rrc_inst[ctxt_pP->module_id].ReportConfig[eNB_index][ind-1] = measConfig->reportConfigToAddModList->list.array[i];
861
      }
862
    }
863 864 865
  }

  if (measConfig->quantityConfig != NULL) {
866
    if (UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index]) {
867
      LOG_D(RRC,"Modifying Quantity Configuration \n");
868
      memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index],
869 870 871 872
             (char*)measConfig->quantityConfig,
             sizeof(QuantityConfig_t));
    } else {
      LOG_D(RRC,"Adding Quantity configuration\n");
873
      UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index] = measConfig->quantityConfig;
874
    }
875 876 877
  }

  if (measConfig->measIdToRemoveList != NULL) {
878 879
    for (i=0; i<measConfig->measIdToRemoveList->list.count; i++) {
      ind   = *measConfig->measIdToRemoveList->list.array[i];
880
      free(UE_rrc_inst[ctxt_pP->module_id].MeasId[eNB_index][ind-1]);
881
    }
882 883 884
  }

  if (measConfig->measIdToAddModList != NULL) {
885 886 887
    for (i=0; i<measConfig->measIdToAddModList->list.count; i++) {
      ind   = measConfig->measIdToAddModList->list.array[i]->measId;

888
      if (UE_rrc_inst[ctxt_pP->module_id].MeasId[eNB_index][ind-1]) {
889
        LOG_D(RRC,"Modifying Measurement ID %d\n",ind-1);
890
        memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].MeasId[eNB_index][ind-1],
891 892 893 894
               (char*)measConfig->measIdToAddModList->list.array[i],
               sizeof(MeasIdToAddMod_t));
      } else {
        LOG_D(RRC,"Adding Measurement ID %d %p\n",ind-1,measConfig->measIdToAddModList->list.array[i]);
895
        UE_rrc_inst[ctxt_pP->module_id].MeasId[eNB_index][ind-1] = measConfig->measIdToAddModList->list.array[i];
896
      }
897
    }
898 899 900
  }

  if (measConfig->measGapConfig !=NULL) {
901 902
    if (UE_rrc_inst[ctxt_pP->module_id].measGapConfig[eNB_index]) {
      memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].measGapConfig[eNB_index],
903 904 905
             (char*)measConfig->measGapConfig,
             sizeof(MeasGapConfig_t));
    } else {
906
      UE_rrc_inst[ctxt_pP->module_id].measGapConfig[eNB_index] = measConfig->measGapConfig;
907
    }
908 909
  }

910
  if (measConfig->quantityConfig != NULL) {
911
    if (UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index]) {
912
      LOG_I(RRC,"Modifying Quantity Configuration \n");
913
      memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index],
914 915 916 917
             (char*)measConfig->quantityConfig,
             sizeof(QuantityConfig_t));
    } else {
      LOG_I(RRC,"Adding Quantity configuration\n");
918
      UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index] = measConfig->quantityConfig;
919
    }
920

921 922 923 924
    UE_rrc_inst[ctxt_pP->module_id].filter_coeff_rsrp = 1./pow(2,
        (*UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index]->quantityConfigEUTRA->filterCoefficientRSRP)/4);
    UE_rrc_inst[ctxt_pP->module_id].filter_coeff_rsrq = 1./pow(2,
        (*UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index]->quantityConfigEUTRA->filterCoefficientRSRQ)/4);
925

926
    LOG_I(RRC,"[UE %d] set rsrp-coeff for eNB %d: %d rsrq-coeff: %d rsrp_factor: %f rsrq_factor: %f \n",
927 928 929 930 931 932 933
          ctxt_pP->module_id, eNB_index, // UE_rrc_inst[ue_mod_idP].Info[eNB_index].UE_index,
          *UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index]->quantityConfigEUTRA->filterCoefficientRSRP,
          *UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index]->quantityConfigEUTRA->filterCoefficientRSRQ,
          UE_rrc_inst[ctxt_pP->module_id].filter_coeff_rsrp,
          UE_rrc_inst[ctxt_pP->module_id].filter_coeff_rsrp,
          UE_rrc_inst[ctxt_pP->module_id].filter_coeff_rsrp,
          UE_rrc_inst[ctxt_pP->module_id].filter_coeff_rsrq);
934 935
  }

936
  if (measConfig->s_Measure != NULL) {
937
    UE_rrc_inst[ctxt_pP->module_id].s_measure = *measConfig->s_Measure;
938
  }
939

940
  if (measConfig->speedStatePars != NULL) {
941 942 943 944 945
    if (UE_rrc_inst[ctxt_pP->module_id].speedStatePars) {
      memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].speedStatePars,(char*)measConfig->speedStatePars,sizeof(struct MeasConfig__speedStatePars));
    } else {
      UE_rrc_inst[ctxt_pP->module_id].speedStatePars = measConfig->speedStatePars;
    }
946 947

    LOG_I(RRC,"[UE %d] Configuring mobility optimization params for UE %d \n",
948
          ctxt_pP->module_id,UE_rrc_inst[ctxt_pP->module_id].Info[0].UE_index);
949
  }
950 951
}

952
//-----------------------------------------------------------------------------
953
void
954 955 956 957 958 959
rrc_ue_process_radioResourceConfigDedicated(
  const protocol_ctxt_t* const ctxt_pP,
  uint8_t eNB_index,
  RadioResourceConfigDedicated_t* radioResourceConfigDedicated
)
//-----------------------------------------------------------------------------
960
{
961 962 963 964

  long SRB_id,DRB_id;
  int i,cnt;
  LogicalChannelConfig_t *SRB1_logicalChannelConfig,*SRB2_logicalChannelConfig;
965
#ifdef CBA
966 967
  uint8_t cba_found = 0;
  uint16_t cba_RNTI;
968
#endif
969 970 971

  // Save physicalConfigDedicated if present
  if (radioResourceConfigDedicated->physicalConfigDedicated) {
972 973
    if (UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]) {
      memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index],(char*)radioResourceConfigDedicated->physicalConfigDedicated,
974
             sizeof(struct PhysicalConfigDedicated));
975

976
    } else {
977
      UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index] = radioResourceConfigDedicated->physicalConfigDedicated;
978
    }
979
  }
980

981 982
  // Apply macMainConfig if present
  if (radioResourceConfigDedicated->mac_MainConfig) {
983
    if (radioResourceConfigDedicated->mac_MainConfig->present == RadioResourceConfigDedicated__mac_MainConfig_PR_explicitValue) {
984 985
      if (UE_rrc_inst[ctxt_pP->module_id].mac_MainConfig[eNB_index]) {
        memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].mac_MainConfig[eNB_index],(char*)&radioResourceConfigDedicated->mac_MainConfig->choice.explicitValue,
986
               sizeof(MAC_MainConfig_t));
987 988 989
      } else {
        UE_rrc_inst[ctxt_pP->module_id].mac_MainConfig[eNB_index] = &radioResourceConfigDedicated->mac_MainConfig->choice.explicitValue;
      }
990
    }
991 992 993 994
  }

  // Apply spsConfig if present
  if (radioResourceConfigDedicated->sps_Config) {
995 996
    if (UE_rrc_inst[ctxt_pP->module_id].sps_Config[eNB_index]) {
      memcpy(UE_rrc_inst[ctxt_pP->module_id].sps_Config[eNB_index],radioResourceConfigDedicated->sps_Config,
997 998
             sizeof(struct SPS_Config));
    } else {
999
      UE_rrc_inst[ctxt_pP->module_id].sps_Config[eNB_index] = radioResourceConfigDedicated->sps_Config;
1000
    }
1001
  }
1002

1003
#ifdef CBA
1004

1005
  if (radioResourceConfigDedicated->cba_RNTI_vlola) {
1006 1007 1008 1009
    cba_RNTI = (uint16_t) (((radioResourceConfigDedicated->cba_RNTI_vlola->buf[1]&0xff) << 8) |
                           (radioResourceConfigDedicated->cba_RNTI_vlola->buf[0]&0xff));

    for (i=0 ; i< NUM_MAX_CBA_GROUP; i++) {
1010
      if (UE_rrc_inst[ctxt_pP->module_id].cba_rnti[i] == cba_RNTI ) {
1011 1012
        cba_found=1;
        break;
1013
      } else if (UE_rrc_inst[ctxt_pP->module_id].cba_rnti[i] == 0 ) {
1014
        break;
1015
      }
1016 1017 1018
    }

    if (cba_found==0) {
1019 1020
      UE_rrc_inst[ctxt_pP->module_id].num_active_cba_groups++;
      UE_rrc_inst[ctxt_pP->module_id].cba_rnti[i]=cba_RNTI;
1021
      LOG_D(RRC, "[UE %d] Frame %d: radioResourceConfigDedicated reveived CBA_RNTI = %x for group %d from eNB %d \n",
1022
            ctxt_pP->module_id,frameP, UE_rrc_inst[ctxt_pP->module_id].cba_rnti[i], i, eNB_index);
1023
    }
1024
  }
1025 1026 1027

#endif

1028 1029 1030
  // Establish SRBs if present
  // loop through SRBToAddModList
  if (radioResourceConfigDedicated->srb_ToAddModList) {
1031 1032
    uint8_t *kRRCenc = NULL;
    uint8_t *kRRCint = NULL;
1033 1034

#if defined(ENABLE_SECURITY)
1035 1036 1037 1038
    derive_key_rrc_enc(UE_rrc_inst[ctxt_pP->module_id].ciphering_algorithm,
                       UE_rrc_inst[ctxt_pP->module_id].kenb, &kRRCenc);
    derive_key_rrc_int(UE_rrc_inst[ctxt_pP->module_id].integrity_algorithm,
                       UE_rrc_inst[ctxt_pP->module_id].kenb, &kRRCint);
1039 1040
#endif
    // Refresh SRBs
1041
    rrc_pdcp_config_asn1_req(ctxt_pP,
1042 1043 1044
                             radioResourceConfigDedicated->srb_ToAddModList,
                             (DRB_ToAddModList_t*)NULL,
                             (DRB_ToReleaseList_t*)NULL,
1045 1046
                             UE_rrc_inst[ctxt_pP->module_id].ciphering_algorithm |
                             (UE_rrc_inst[ctxt_pP->module_id].integrity_algorithm << 4),
1047 1048 1049
                             kRRCenc,
                             kRRCint,
                             NULL
1050
#ifdef Rel10
1051
                             ,(PMCH_InfoList_r9_t *)NULL
1052
#endif
1053
                            );
1054

1055
    // Refresh SRBs
1056
    rrc_rlc_config_asn1_req(ctxt_pP,
1057 1058 1059
                            radioResourceConfigDedicated->srb_ToAddModList,
                            (DRB_ToAddModList_t*)NULL,
                            (DRB_ToReleaseList_t*)NULL
1060
#ifdef Rel10
1061
                            ,(PMCH_InfoList_r9_t *)NULL
1062
#endif
1063
                           );
1064

1065
#if ENABLE_RAL
1066
    // first msg that includes srb config
1067
    UE_rrc_inst[ctxt_pP->module_id].num_srb=radioResourceConfigDedicated->srb_ToAddModList->list.count;
1068
#endif
1069

1070 1071 1072
    for (cnt=0; cnt<radioResourceConfigDedicated->srb_ToAddModList->list.count; cnt++) {
      //  connection_reestablishment_ind.num_srb+=1;
      SRB_id = radioResourceConfigDedicated->srb_ToAddModList->list.array[cnt]->srb_Identity;
1073
      LOG_D(RRC,"[UE %d]: Frame %d SRB config cnt %d (SRB%ld)\n",ctxt_pP->module_id,ctxt_pP->frame,cnt,SRB_id);
1074 1075

      if (SRB_id == 1) {
1076 1077
        if (UE_rrc_inst[ctxt_pP->module_id].SRB1_config[eNB_index]) {
          memcpy(UE_rrc_inst[ctxt_pP->module_id].SRB1_config[eNB_index],radioResourceConfigDedicated->srb_ToAddModList->list.array[cnt],
1078 1079
                 sizeof(struct SRB_ToAddMod));
        } else {
1080 1081
          UE_rrc_inst[ctxt_pP->module_id].SRB1_config[eNB_index] = radioResourceConfigDedicated->srb_ToAddModList->list.array[cnt];
          rrc_ue_establish_srb1(ctxt_pP->module_id,ctxt_pP->frame,eNB_index,radioResourceConfigDedicated->srb_ToAddModList->list.array[cnt]);
1082

1083 1084 1085
          if (UE_rrc_inst[ctxt_pP->module_id].SRB1_config[eNB_index]->logicalChannelConfig) {
            if (UE_rrc_inst[ctxt_pP->module_id].SRB1_config[eNB_index]->logicalChannelConfig->present == SRB_ToAddMod__logicalChannelConfig_PR_explicitValue) {
              SRB1_logicalChannelConfig = &UE_rrc_inst[ctxt_pP->module_id].SRB1_config[eNB_index]->logicalChannelConfig->choice.explicitValue;
1086 1087 1088 1089 1090 1091 1092 1093

            } else {
              SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
            }
          } else {
            SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
          }

Lionel Gauthier's avatar
Lionel Gauthier committed
1094
          LOG_D(RRC, "[FRAME %05d][RRC_UE][MOD %02d][][--- MAC_CONFIG_REQ  (SRB1 eNB %d) --->][MAC_UE][MOD %02d][]\n",
1095
                ctxt_pP->frame, ctxt_pP->module_id, eNB_index, ctxt_pP->module_id);
1096
          rrc_mac_config_req(ctxt_pP->module_id,0,ENB_FLAG_NO,0,eNB_index,
1097
                             (RadioResourceConfigCommonSIB_t *)NULL,
1098
                             UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index],
1099 1100 1101 1102 1103
#ifdef Rel10
                             (SCellToAddMod_r10_t *)NULL,
                             //struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
#endif
                             (MeasObjectToAddMod_t **)NULL,
1104
                             UE_rrc_inst[ctxt_pP->module_id].mac_MainConfig[eNB_index],
1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115
                             1,
                             SRB1_logicalChannelConfig,
                             (MeasGapConfig_t *)NULL,
                             NULL,
                             NULL,
                             NULL,
                             NULL,
                             NULL,
                             NULL,
                             NULL,
                             NULL
1116
#ifdef Rel10
1117 1118 1119 1120
                             ,
                             0,
                             (MBSFN_AreaInfoList_r9_t *)NULL,
                             (PMCH_InfoList_r9_t *)NULL
1121 1122
#endif
#ifdef CBA
1123 1124 1125
                             ,
                             0,
                             0
1126
#endif
1127 1128 1129
                            );
        }
      } else {
1130 1131
        if (UE_rrc_inst[ctxt_pP->module_id].SRB2_config[eNB_index]) {
          memcpy(UE_rrc_inst[ctxt_pP->module_id].SRB2_config[eNB_index],radioResourceConfigDedicated->srb_ToAddModList->list.array[cnt],
1132 1133
                 sizeof(struct SRB_ToAddMod));
        } else {
1134 1135
          UE_rrc_inst[ctxt_pP->module_id].SRB2_config[eNB_index] = radioResourceConfigDedicated->srb_ToAddModList->list.array[cnt];
          rrc_ue_establish_srb2(ctxt_pP->module_id,ctxt_pP->frame,eNB_index,radioResourceConfigDedicated->srb_ToAddModList->list.array[cnt]);
1136

1137 1138
          if (UE_rrc_inst[ctxt_pP->module_id].SRB2_config[eNB_index]->logicalChannelConfig) {
            if (UE_rrc_inst[ctxt_pP->module_id].SRB2_config[eNB_index]->logicalChannelConfig->present == SRB_ToAddMod__logicalChannelConfig_PR_explicitValue) {
1139
              LOG_I(RRC,"Applying Explicit SRB2 logicalChannelConfig\n");
1140
              SRB2_logicalChannelConfig = &UE_rrc_inst[ctxt_pP->module_id].SRB2_config[eNB_index]->logicalChannelConfig->choice.explicitValue;
1141 1142 1143 1144 1145 1146
            } else {
              LOG_I(RRC,"Applying default SRB2 logicalChannelConfig\n");
              SRB2_logicalChannelConfig = &SRB2_logicalChannelConfig_defaultValue;
            }
          } else {
            SRB2_logicalChannelConfig = &SRB2_logicalChannelConfig_defaultValue;
1147
          }
1148

Lionel Gauthier's avatar
Lionel Gauthier committed
1149
          LOG_D(RRC, "[FRAME %05d][RRC_UE][MOD %02d][][--- MAC_CONFIG_REQ  (SRB2 eNB %d) --->][MAC_UE][MOD %02d][]\n",
1150 1151 1152 1153
                ctxt_pP->frame,
                ctxt_pP->module_id,
                eNB_index,
                ctxt_pP->module_id);
1154
          rrc_mac_config_req(ctxt_pP->module_id,0,ENB_FLAG_NO,0,eNB_index,
1155
                             (RadioResourceConfigCommonSIB_t *)NULL,
1156
                             UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index],
1157
#ifdef Rel10
1158 1159 1160 1161
                             (SCellToAddMod_r10_t *)NULL,
                             //struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
#endif
                             (MeasObjectToAddMod_t **)NULL,
1162
                             UE_rrc_inst[ctxt_pP->module_id].mac_MainConfig[eNB_index],
1163 1164
                             2,
                             SRB2_logicalChannelConfig,
1165
                             UE_rrc_inst[ctxt_pP->module_id].measGapConfig[eNB_index],
1166 1167 1168 1169 1170 1171 1172 1173
                             (TDD_Config_t *)NULL,
                             (MobilityControlInfo_t *)NULL,
                             NULL,
                             NULL,
                             NULL,
                             NULL,
                             NULL,
                             NULL
1174
#ifdef Rel10
1175 1176 1177 1178
                             ,
                             0,
                             (MBSFN_AreaInfoList_r9_t *)NULL,
                             (PMCH_InfoList_r9_t *)NULL
1179 1180
#endif
#ifdef CBA
1181 1182 1183
                             ,
                             0,
                             0
1184
#endif
1185 1186
                            );
        }
1187
      }
1188
    }
1189 1190 1191 1192
  }

  // Establish DRBs if present
  if (radioResourceConfigDedicated->drb_ToAddModList) {
1193
    uint8_t *kUPenc = NULL;
1194 1195

#if defined(ENABLE_SECURITY)
1196 1197
    derive_key_up_enc(UE_rrc_inst[ctxt_pP->module_id].integrity_algorithm,
                      UE_rrc_inst[ctxt_pP->module_id].kenb, &kUPenc);
1198 1199
#endif

Lionel Gauthier's avatar
Lionel Gauthier committed
1200 1201 1202 1203 1204 1205 1206 1207 1208
    MSC_LOG_TX_MESSAGE(
      MSC_RRC_UE,
      MSC_PDCP_UE,
      NULL,
      0,
      MSC_AS_TIME_FMT" CONFIG_REQ UE %x DRB (security %X)",
      MSC_AS_TIME_ARGS(ctxt_pP),
      ctxt_pP->rnti,
      UE_rrc_inst[ctxt_pP->module_id].ciphering_algorithm |
1209
      (UE_rrc_inst[ctxt_pP->module_id].integrity_algorithm << 4));
Lionel Gauthier's avatar
Lionel Gauthier committed
1210

1211
    // Refresh DRBs
1212
    rrc_pdcp_config_asn1_req(ctxt_pP,
1213 1214 1215
                             (SRB_ToAddModList_t*)NULL,
                             radioResourceConfigDedicated->drb_ToAddModList,
                             (DRB_ToReleaseList_t*)NULL,
1216 1217
                             UE_rrc_inst[ctxt_pP->module_id].ciphering_algorithm |
                             (UE_rrc_inst[ctxt_pP->module_id].integrity_algorithm << 4),
1218 1219 1220
                             NULL,
                             NULL,
                             kUPenc
1221
#ifdef Rel10
1222
                             ,(PMCH_InfoList_r9_t *)NULL
1223
#endif
1224
                            );
1225

1226
    // Refresh DRBs
1227
    rrc_rlc_config_asn1_req(ctxt_pP,
1228 1229 1230
                            (SRB_ToAddModList_t*)NULL,
                            radioResourceConfigDedicated->drb_ToAddModList,
                            (DRB_ToReleaseList_t*)NULL
1231
#ifdef Rel10
1232 1233 1234 1235 1236 1237 1238
                            ,(PMCH_InfoList_r9_t *)NULL
#endif
                           );

    for (i=0; i<radioResourceConfigDedicated->drb_ToAddModList->list.count; i++) {
      DRB_id   = radioResourceConfigDedicated->drb_ToAddModList->list.array[i]->drb_Identity-1;

1239 1240 1241
      if (UE_rrc_inst[ctxt_pP->module_id].DRB_config[eNB_index][DRB_id]) {
        memcpy(UE_rrc_inst[ctxt_pP->module_id].DRB_config[eNB_index][DRB_id],
               radioResourceConfigDedicated->drb_ToAddModList->list.array[i],
1242 1243
               sizeof(struct DRB_ToAddMod));
      } else {
1244 1245
        UE_rrc_inst[ctxt_pP->module_id].DRB_config[eNB_index][DRB_id] = radioResourceConfigDedicated->drb_ToAddModList->list.array[i];
        rrc_ue_establish_drb(ctxt_pP->module_id,ctxt_pP->frame,eNB_index,radioResourceConfigDedicated->drb_ToAddModList->list.array[i]);
1246
        // MAC/PHY Configuration
Lionel Gauthier's avatar
Lionel Gauthier committed
1247
        LOG_D(RRC, "[FRAME %05d][RRC_UE][MOD %02d][][--- MAC_CONFIG_REQ (DRB %d eNB %d) --->][MAC_UE][MOD %02d][]\n",
1248 1249 1250 1251
              ctxt_pP->frame, ctxt_pP->module_id,
              radioResourceConfigDedicated->drb_ToAddModList->list.array[i]->drb_Identity,
              eNB_index,
              ctxt_pP->module_id);
1252
        rrc_mac_config_req(ctxt_pP->module_id,0,ENB_FLAG_NO,0,eNB_index,
1253
                           (RadioResourceConfigCommonSIB_t *)NULL,
1254
                           UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index],
1255
#ifdef Rel10
1256 1257 1258 1259
                           (SCellToAddMod_r10_t *)NULL,
                           //struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
#endif
                           (MeasObjectToAddMod_t **)NULL,
1260 1261 1262 1263
                           UE_rrc_inst[ctxt_pP->module_id].mac_MainConfig[eNB_index],
                           *UE_rrc_inst[ctxt_pP->module_id].DRB_config[eNB_index][DRB_id]->logicalChannelIdentity,
                           UE_rrc_inst[ctxt_pP->module_id].DRB_config[eNB_index][DRB_id]->logicalChannelConfig,
                           UE_rrc_inst[ctxt_pP->module_id].measGapConfig[eNB_index],
1264 1265 1266 1267 1268 1269 1270 1271
                           (TDD_Config_t*)NULL,
                           (MobilityControlInfo_t *)NULL,
                           NULL,
                           NULL,
                           NULL,
                           NULL,
                           NULL,
                           NULL
1272
#ifdef Rel10
1273 1274 1275 1276
                           ,
                           0,
                           (MBSFN_AreaInfoList_r9_t *)NULL,
                           (PMCH_InfoList_r9_t *)NULL
1277 1278
#endif
#ifdef CBA
1279 1280 1281
                           ,
                           UE_rrc_inst[ue_mod_idP].num_active_cba_groups, //
                           UE_rrc_inst[ue_mod_idP].cba_rnti[0]
1282
#endif
1283
                          );
1284 1285

      }
1286
    }
1287 1288
  }

1289 1290
  UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].State = RRC_CONNECTED;
  LOG_I(RRC,"[UE %d] State = RRC_CONNECTED (eNB %d)\n",ctxt_pP->module_id,eNB_index);
1291
#if !defined(ENABLE_USE_MME) && defined(OAI_EMU)
Raymond Knopp's avatar
 
Raymond Knopp committed
1292
#    ifdef OAI_EMU
1293 1294 1295 1296 1297 1298 1299
  rrc_eNB_emulation_notify_ue_module_id(
    ctxt_pP->module_id,
    ctxt_pP->rnti,
    UE_rrc_inst[ctxt_pP->module_id].sib1[eNB_index]->cellAccessRelatedInfo.cellIdentity.buf[0],
    UE_rrc_inst[ctxt_pP->module_id].sib1[eNB_index]->cellAccessRelatedInfo.cellIdentity.buf[1],
    UE_rrc_inst[ctxt_pP->module_id].sib1[eNB_index]->cellAccessRelatedInfo.cellIdentity.buf[2],
    UE_rrc_inst[ctxt_pP->module_id].sib1[eNB_index]->cellAccessRelatedInfo.cellIdentity.buf[3]);
Raymond Knopp's avatar
 
Raymond Knopp committed
1300
#    endif OAI_EMU
1301
#endif
1302 1303
}

1304 1305 1306 1307 1308 1309 1310 1311 1312

//-----------------------------------------------------------------------------
void
rrc_ue_process_securityModeCommand(
  const protocol_ctxt_t* const ctxt_pP,
  SecurityModeCommand_t* const securityModeCommand,
  const uint8_t                eNB_index
)
//-----------------------------------------------------------------------------
1313
{
1314 1315 1316 1317 1318 1319 1320

  asn_enc_rval_t enc_rval;

  UL_DCCH_Message_t ul_dcch_msg;
  // SecurityModeCommand_t SecurityModeCommand;
  uint8_t buffer[200];
  int i, securityMode;
1321

1322
  LOG_I(RRC,"[UE %d] Frame %d: Receiving from SRB1 (DL-DCCH), Processing securityModeCommand (eNB %d)\n",
1323
        ctxt_pP->module_id,ctxt_pP->frame,eNB_index);
1324

1325
  switch (securityModeCommand->criticalExtensions.choice.c1.choice.securityModeCommand_r8.securityConfigSMC.securityAlgorithmConfig.cipheringAlgorithm) {
1326
  case SecurityAlgorithmConfig__cipheringAlgorithm_eea0:
1327 1328
    LOG_I(RRC,"[UE %d] Security algorithm is set to eea0\n",
          ctxt_pP->module_id);
1329 1330
    securityMode= SecurityAlgorithmConfig__cipheringAlgorithm_eea0;
    break;
1331

1332
  case SecurityAlgorithmConfig__cipheringAlgorithm_eea1:
1333
    LOG_I(RRC,"[UE %d] Security algorithm is set to eea1\n",ctxt_pP->module_id);
1334 1335
    securityMode= SecurityAlgorithmConfig__cipheringAlgorithm_eea1;
    break;
1336

1337
  case SecurityAlgorithmConfig__cipheringAlgorithm_eea2:
1338 1339
    LOG_I(RRC,"[UE %d] Security algorithm is set to eea2\n",
          ctxt_pP->module_id);
1340 1341
    securityMode = SecurityAlgorithmConfig__cipheringAlgorithm_eea2;
    break;
1342

1343
  default:
1344
    LOG_I(RRC,"[UE %d] Security algorithm is set to none\n",ctxt_pP->module_id);
1345 1346 1347
    securityMode = SecurityAlgorithmConfig__cipheringAlgorithm_spare1;
    break;
  }
1348 1349

  switch (securityModeCommand->criticalExtensions.choice.c1.choice.securityModeCommand_r8.securityConfigSMC.securityAlgorithmConfig.integrityProtAlgorithm) {
1350
  case SecurityAlgorithmConfig__integrityProtAlgorithm_eia1:
1351
    LOG_I(RRC,"[UE %d] Integrity protection algorithm is set to eia1\n",ctxt_pP->module_id);
1352 1353
    securityMode |= 1 << 5;
    break;
1354

1355
  case SecurityAlgorithmConfig__integrityProtAlgorithm_eia2:
1356
    LOG_I(RRC,"[UE %d] Integrity protection algorithm is set to eia2\n",ctxt_pP->module_id);
1357 1358
    securityMode |= 1 << 6;
    break;
1359

1360
  default:
1361
    LOG_I(RRC,"[UE %d] Integrity protection algorithm is set to none\n",ctxt_pP->module_id);
1362 1363 1364
    securityMode |= 0x70 ;
    break;
  }
1365

1366
  LOG_D(RRC,"[UE %d] security mode is %x \n",ctxt_pP->module_id, securityMode);
1367 1368

  /* Store the parameters received */
1369 1370 1371 1372
  UE_rrc_inst[ctxt_pP->module_id].ciphering_algorithm =
    securityModeCommand->criticalExtensions.choice.c1.choice.securityModeCommand_r8.securityConfigSMC.securityAlgorithmConfig.cipheringAlgorithm;
  UE_rrc_inst[ctxt_pP->module_id].integrity_algorithm =
    securityModeCommand->criticalExtensions.choice.c1.choice.securityModeCommand_r8.securityConfigSMC.securityAlgorithmConfig.integrityProtAlgorithm;
1373

1374 1375 1376 1377
  memset((void *)&ul_dcch_msg,0,sizeof(UL_DCCH_Message_t));
  //memset((void *)&SecurityModeCommand,0,sizeof(SecurityModeCommand_t));

  ul_dcch_msg.message.present           = UL_DCCH_MessageType_PR_c1;
1378

1379
  if (securityMode >= NO_SECURITY_MODE) {
1380
    ul_dcch_msg.message.choice.c1.present = UL_DCCH_MessageType__c1_PR_securityModeComplete;
1381
  } else {
1382
    ul_dcch_msg.message.choice.c1.present = UL_DCCH_MessageType__c1_PR_securityModeFailure;
1383
  }
1384

1385
  if (securityModeCommand->criticalExtensions.present == SecurityModeCommand__criticalExtensions_PR_c1) {
1386
    if (securityModeCommand->criticalExtensions.choice.c1.present == SecurityModeCommand__criticalExtensions__c1_PR_securityModeCommand_r8) {
1387

1388
      ul_dcch_msg.message.choice.c1.choice.securityModeComplete.rrc_TransactionIdentifier = securityModeCommand->rrc_TransactionIdentifier;
1389
      ul_dcch_msg.message.choice.c1.choice.securityModeComplete.criticalExtensions.present = SecurityModeCommand__criticalExtensions_PR_c1;
1390
      ul_dcch_msg.message.choice.c1.choice.securityModeComplete.criticalExtensions.choice.securityModeComplete_r8.nonCriticalExtension =NULL;
1391

1392
      LOG_I(RRC,"[UE %d] Frame %d: Receiving from SRB1 (DL-DCCH), encoding securityModeComplete (eNB %d)\n",
1393
            ctxt_pP->module_id,ctxt_pP->frame,eNB_index);
1394

1395 1396 1397 1398 1399 1400
      enc_rval = uper_encode_to_buffer(&asn_DEF_UL_DCCH_Message,
                                       (void*)&ul_dcch_msg,
                                       buffer,
                                       100);
      AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %jd)!\n",
                   enc_rval.failed_type->name, enc_rval.encoded);
1401 1402

#ifdef XER_PRINT
1403 1404
      xer_fprint(stdout, &asn_DEF_UL_DCCH_Message, (void*)&ul_dcch_msg);
#endif
1405

1406 1407
#if defined(ENABLE_ITTI)
# if !defined(DISABLE_XER_SPRINT)
1408 1409 1410
      {
        char        message_string[20000];
        size_t      message_string_size;
1411

1412 1413
        if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_UL_DCCH_Message, (void *) &ul_dcch_msg)) > 0) {
          MessageDef *msg_p;
1414

1415 1416 1417
          msg_p = itti_alloc_new_message_sized (TASK_RRC_UE, RRC_UL_DCCH, message_string_size + sizeof (IttiMsgText));
          msg_p->ittiMsg.rrc_ul_dcch.size = message_string_size;
          memcpy(&msg_p->ittiMsg.rrc_ul_dcch.text, message_string, message_string_size);
1418

1419
          itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
1420 1421
        }
      }
1422 1423 1424
# endif
#endif

1425
#ifdef USER_MODE
1426
      LOG_D(RRC, "securityModeComplete Encoded %d bits (%d bytes)\n", enc_rval.encoded, (enc_rval.encoded+7)/8);
1427
#endif
1428

1429
      for (i = 0; i < (enc_rval.encoded + 7) / 8; i++) {
1430
        LOG_T(RRC, "%02x.", buffer[i]);
1431
      }
1432 1433

      LOG_T(RRC, "\n");
1434 1435 1436 1437 1438 1439 1440 1441 1442
      pdcp_rrc_data_req (
        ctxt_pP,
        DCCH,
        rrc_mui++,
        SDU_CONFIRM_NO,
        (enc_rval.encoded + 7) / 8,
        buffer,
        PDCP_TRANSMISSION_MODE_CONTROL);
    }
1443
  }
1444
}
1445

1446 1447 1448 1449 1450 1451 1452 1453
//-----------------------------------------------------------------------------
void
rrc_ue_process_ueCapabilityEnquiry(
  const protocol_ctxt_t* const ctxt_pP,
  UECapabilityEnquiry_t* UECapabilityEnquiry,
  uint8_t eNB_index
)
//-----------------------------------------------------------------------------
1454
{
1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466

  asn_enc_rval_t enc_rval;

  UL_DCCH_Message_t ul_dcch_msg;


  UE_CapabilityRAT_Container_t ue_CapabilityRAT_Container;

  uint8_t buffer[200];
  int i;

  LOG_I(RRC,"[UE %d] Frame %d: Receiving from SRB1 (DL-DCCH), Processing UECapabilityEnquiry (eNB %d)\n",
1467 1468 1469
        ctxt_pP->module_id,
        ctxt_pP->frame,
        eNB_index);
1470 1471 1472 1473 1474 1475 1476


  memset((void *)&ul_dcch_msg,0,sizeof(UL_DCCH_Message_t));
  memset((void *)&ue_CapabilityRAT_Container,0,sizeof(UE_CapabilityRAT_Container_t));

  ul_dcch_msg.message.present           = UL_DCCH_MessageType_PR_c1;
  ul_dcch_msg.message.choice.c1.present = UL_DCCH_MessageType__c1_PR_ueCapabilityInformation;
1477
  ul_dcch_msg.message.choice.c1.choice.ueCapabilityInformation.rrc_TransactionIdentifier = UECapabilityEnquiry->rrc_TransactionIdentifier;
1478 1479 1480

  ue_CapabilityRAT_Container.rat_Type = RAT_Type_eutra;
  OCTET_STRING_fromBuf(&ue_CapabilityRAT_Container.ueCapabilityRAT_Container,
1481 1482
                       (const char*)UE_rrc_inst[ctxt_pP->module_id].UECapability,
                       UE_rrc_inst[ctxt_pP->module_id].UECapability_size);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1483 1484
  //  ue_CapabilityRAT_Container.ueCapabilityRAT_Container.buf  = UE_rrc_inst[ue_mod_idP].UECapability;
  // ue_CapabilityRAT_Container.ueCapabilityRAT_Container.size = UE_rrc_inst[ue_mod_idP].UECapability_size;
1485

1486 1487

  if (UECapabilityEnquiry->criticalExtensions.present == UECapabilityEnquiry__criticalExtensions_PR_c1) {
1488 1489
    if (UECapabilityEnquiry->criticalExtensions.choice.c1.present == UECapabilityEnquiry__criticalExtensions__c1_PR_ueCapabilityEnquiry_r8) {
      ul_dcch_msg.message.choice.c1.choice.ueCapabilityInformation.criticalExtensions.present           = UECapabilityInformation__criticalExtensions_PR_c1;
1490 1491 1492 1493
      ul_dcch_msg.message.choice.c1.choice.ueCapabilityInformation.criticalExtensions.choice.c1.present =
        UECapabilityInformation__criticalExtensions__c1_PR_ueCapabilityInformation_r8;
      ul_dcch_msg.message.choice.c1.choice.ueCapabilityInformation.criticalExtensions.choice.c1.choice.ueCapabilityInformation_r8.ue_CapabilityRAT_ContainerList.list.count
        =0;
1494

1495
      for (i=0; i<UECapabilityEnquiry->criticalExtensions.choice.c1.choice.ueCapabilityEnquiry_r8.ue_CapabilityRequest.list.count; i++) {
1496

1497 1498 1499 1500 1501
        if (*UECapabilityEnquiry->criticalExtensions.choice.c1.choice.ueCapabilityEnquiry_r8.ue_CapabilityRequest.list.array[i]
            == RAT_Type_eutra) {
          ASN_SEQUENCE_ADD(
            &ul_dcch_msg.message.choice.c1.choice.ueCapabilityInformation.criticalExtensions.choice.c1.choice.ueCapabilityInformation_r8.ue_CapabilityRAT_ContainerList.list,
            &ue_CapabilityRAT_Container);
1502

1503 1504 1505
          enc_rval = uper_encode_to_buffer(&asn_DEF_UL_DCCH_Message, (void*) &ul_dcch_msg, buffer, 100);
          AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %jd)!\n",
                       enc_rval.failed_type->name, enc_rval.encoded);
1506 1507

#ifdef XER_PRINT
1508
          xer_fprint(stdout, &asn_DEF_UL_DCCH_Message, (void*)&ul_dcch_msg);
1509
#endif
1510

1511 1512
#if defined(ENABLE_ITTI)
# if !defined(DISABLE_XER_SPRINT)
1513 1514 1515
          {
            char        message_string[20000];
            size_t      message_string_size;
1516

1517 1518
            if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_UL_DCCH_Message, (void *) &ul_dcch_msg)) > 0) {
              MessageDef *msg_p;
1519

1520 1521 1522
              msg_p = itti_alloc_new_message_sized (TASK_RRC_UE, RRC_UL_DCCH, message_string_size + sizeof (IttiMsgText));
              msg_p->ittiMsg.rrc_ul_dcch.size = message_string_size;
              memcpy(&msg_p->ittiMsg.rrc_ul_dcch.text, message_string, message_string_size);
1523

1524
              itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
1525 1526
            }
          }
1527 1528 1529
# endif
#endif

1530
#ifdef USER_MODE
1531
          LOG_D(RRC,"UECapabilityInformation Encoded %d bits (%d bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);
1532
#endif
1533

1534
          for (i = 0; i < (enc_rval.encoded + 7) / 8; i++) {
1535
            LOG_T(RRC, "%02x.", buffer[i]);
1536
          }
1537 1538

          LOG_T(RRC, "\n");
1539 1540 1541 1542 1543 1544 1545 1546
          pdcp_rrc_data_req (
            ctxt_pP,
            DCCH,
            rrc_mui++,
            SDU_CONFIRM_NO,
            (enc_rval.encoded + 7) / 8,
            buffer,
            PDCP_TRANSMISSION_MODE_CONTROL);
1547
        }
1548
      }
1549
    }
1550 1551 1552
  }
}

1553

1554 1555 1556 1557
//-----------------------------------------------------------------------------
void
rrc_ue_process_rrcConnectionReconfiguration(
  const protocol_ctxt_t* const       ctxt_pP,
1558
  RRCConnectionReconfiguration_t *rrcConnectionReconfiguration,
1559 1560 1561
  uint8_t eNB_index
)
//-----------------------------------------------------------------------------
1562
{
1563

1564
  LOG_I(RRC,"[UE %d] Frame %d: Receiving from SRB1 (DL-DCCH), Processing RRCConnectionReconfiguration (eNB %d)\n",
1565
        ctxt_pP->module_id,ctxt_pP->frame,eNB_index);
1566

1567
  if (rrcConnectionReconfiguration->criticalExtensions.present == RRCConnectionReconfiguration__criticalExtensions_PR_c1) {
1568 1569
    if (rrcConnectionReconfiguration->criticalExtensions.choice.c1.present ==
        RRCConnectionReconfiguration__criticalExtensions__c1_PR_rrcConnectionReconfiguration_r8) {
1570 1571
      RRCConnectionReconfiguration_r8_IEs_t* rrcConnectionReconfiguration_r8 =
        &rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8;
Lionel Gauthier's avatar
Lionel Gauthier committed
1572

1573 1574
      if (rrcConnectionReconfiguration_r8->mobilityControlInfo) {
        LOG_I(RRC,"Mobility Control Information is present\n");
1575 1576 1577 1578
        rrc_ue_process_mobilityControlInfo(
          ctxt_pP,
          eNB_index,
          rrcConnectionReconfiguration_r8->mobilityControlInfo);
1579 1580 1581 1582
      }

      if (rrcConnectionReconfiguration_r8->measConfig != NULL) {
        LOG_I(RRC,"Measurement Configuration is present\n");
1583 1584
        rrc_ue_process_measConfig(ctxt_pP,
                                  eNB_index,
1585 1586 1587 1588 1589
                                  rrcConnectionReconfiguration_r8->measConfig);
      }

      if (rrcConnectionReconfiguration_r8->radioResourceConfigDedicated) {
        LOG_I(RRC,"Radio Resource Configuration is present\n");
1590
        rrc_ue_process_radioResourceConfigDedicated(ctxt_pP,eNB_index, rrcConnectionReconfiguration_r8->radioResourceConfigDedicated);
1591
      }
1592 1593 1594

#if defined(ENABLE_ITTI)

1595 1596 1597 1598 1599 1600
      /* Check if there is dedicated NAS information to forward to NAS */
      if (rrcConnectionReconfiguration_r8->dedicatedInfoNASList != NULL) {
        int list_count;
        uint32_t pdu_length;
        uint8_t *pdu_buffer;
        MessageDef *msg_p;
1601

1602 1603 1604
        for (list_count = 0; list_count < rrcConnectionReconfiguration_r8->dedicatedInfoNASList->list.count; list_count++) {
          pdu_length = rrcConnectionReconfiguration_r8->dedicatedInfoNASList->list.array[list_count]->size;
          pdu_buffer = rrcConnectionReconfiguration_r8->dedicatedInfoNASList->list.array[list_count]->buf;
1605

1606 1607 1608 1609
          msg_p = itti_alloc_new_message(TASK_RRC_UE, NAS_CONN_ESTABLI_CNF);
          NAS_CONN_ESTABLI_CNF(msg_p).errCode = AS_SUCCESS;
          NAS_CONN_ESTABLI_CNF(msg_p).nasMsg.length = pdu_length;
          NAS_CONN_ESTABLI_CNF(msg_p).nasMsg.data = pdu_buffer;
1610

1611
          itti_send_msg_to_task(TASK_NAS_UE, ctxt_pP->instance, msg_p);
1612
        }
1613

1614 1615
        free (rrcConnectionReconfiguration_r8->dedicatedInfoNASList);
      }
1616

1617
#if ENABLE_RAL
1618 1619 1620 1621 1622 1623 1624 1625
      {
        MessageDef                                 *message_ral_p = NULL;
        rrc_ral_connection_reestablishment_ind_t    connection_reestablishment_ind;
        int                                         i;

        message_ral_p = itti_alloc_new_message (TASK_RRC_UE, RRC_RAL_CONNECTION_REESTABLISHMENT_IND);
        memset(&connection_reestablishment_ind, 0, sizeof(rrc_ral_connection_reestablishment_ind_t));
        // TO DO ral_si_ind.plmn_id        = 0;
1626
        connection_reestablishment_ind.ue_id            = ctxt_pP->rnti;
1627 1628 1629 1630 1631

        if (rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList != NULL) {
          connection_reestablishment_ind.num_drb      =
            rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList->list.count;

1632 1633 1634
          for (i=0; (
                 i<rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList->list.count)
               && (i < maxDRB); i++) {
1635 1636 1637
            // why minus 1 in RRC code for drb_identity ?
            connection_reestablishment_ind.drb_id[i]   =
              rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList->list.array[i]->drb_Identity;
1638
          }
1639 1640 1641 1642 1643 1644
        } else {
          connection_reestablishment_ind.num_drb      = 0;
        }

        if (rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->srb_ToAddModList != NULL) {
          connection_reestablishment_ind.num_srb      =
1645 1646
            rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->srb_ToAddModList->list.count +
            UE_rrc_inst[ctxt_pP->module_id].num_srb;
1647 1648

        } else {
1649
          connection_reestablishment_ind.num_srb      += UE_rrc_inst[ctxt_pP->module_id].num_srb;
1650 1651
        }

1652
        if (connection_reestablishment_ind.num_srb > 2) { // fixme: only 2 srbs can exist, adjust the value
1653
          connection_reestablishment_ind.num_srb =2;
1654
        }
1655 1656 1657 1658

        memcpy (&message_ral_p->ittiMsg, (void *) &connection_reestablishment_ind, sizeof(rrc_ral_connection_reestablishment_ind_t));
        //#warning "ue_mod_idP ? for instance ? => YES"
        LOG_I(RRC, "Sending RRC_RAL_CONNECTION_REESTABLISHMENT_IND to mRAL\n");
1659
        itti_send_msg_to_task (TASK_RAL_UE, ctxt_pP->instance, message_ral_p);
1660
      }
Lionel Gauthier's avatar
Lionel Gauthier committed
1661
#endif
1662
#endif
1663
    } // c1 present
1664
  } // critical extensions present
1665 1666
}

1667
/* 36.331, 5.3.5.4      Reception of an RRCConnectionReconfiguration including the mobilityControlInfo by the UE (handover) */
1668 1669 1670 1671 1672 1673 1674 1675
//-----------------------------------------------------------------------------
void
rrc_ue_process_mobilityControlInfo(
  const protocol_ctxt_t* const       ctxt_pP,
  const uint8_t                      eNB_index,
  struct MobilityControlInfo* const mobilityControlInfo
)
//-----------------------------------------------------------------------------
1676
{
1677
  /*
1678 1679
  DRB_ToReleaseList_t*  drb2release_list;
  DRB_Identity_t *lcid;
1680
   */
1681
  LOG_N(RRC,"Note: This function needs some updates\n");
1682

1683 1684 1685
  if(UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].T310_active == 1) {
    UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].T310_active = 0;
  }
1686

1687 1688
  UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].T304_active = 1;
  UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].T304_cnt = T304[mobilityControlInfo->t304];
1689

1690
  /*
1691 1692 1693
  drb2release_list = CALLOC (1, sizeof (*drb2release_list));
  lcid= CALLOC (1, sizeof (DRB_Identity_t)); // long
  for (*lcid=0;*lcid<NB_RB_MAX;*lcid++)
1694
  {
1695
    ASN_SEQUENCE_ADD (&(drb2release_list)->list,lcid);
1696
  }
1697
   */
1698
  //Removing SRB1 and SRB2 and DRB0
1699 1700 1701 1702 1703 1704 1705
  //LOG_N(RRC,"[UE %d] : Update needed for rrc_pdcp_config_req (deprecated) and rrc_rlc_config_req commands(deprecated)\n", ctxt_pP->module_id);
  //rrc_pdcp_config_req (ctxt_pP, SRB_FLAG_YES, CONFIG_ACTION_REMOVE, DCCH,UNDEF_SECURITY_MODE);
  //rrc_rlc_config_req(ctxt_pP, SRB_FLAG_YES, MBMS_FLAG_NO, CONFIG_ACTION_REMOVE,ctxt_pP->module_id+DCCH,Rlc_info_am_config);
  //rrc_pdcp_config_req (ctxt_pP, SRB_FLAG_YES, CONFIG_ACTION_REMOVE, DCCH1,UNDEF_SECURITY_MODE);
  //rrc_rlc_config_req(ctxt_pP, SRB_FLAG_YES,CONFIG_ACTION_REMOVE, MBMS_FLAG_NO,ctxt_pP->module_id+DCCH1,Rlc_info_am_config);
  //rrc_pdcp_config_req (ctxt_pP, SRB_FLAG_NO, CONFIG_ACTION_REMOVE, DTCH,UNDEF_SECURITY_MODE);
  //rrc_rlc_config_req(ctxt_pP, SRB_FLAG_NO,CONFIG_ACTION_REMOVE, MBMS_FLAG_NO,ctxt_pP->module_id+DTCH,Rlc_info_um);
1706
  /*
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1707
  rrc_pdcp_config_asn1_req(NB_eNB_INST+ue_mod_idP,frameP, 0,eNB_index,
1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718
         NULL, // SRB_ToAddModList
         NULL, // DRB_ToAddModList
         drb2release_list,
         0, // security mode
         NULL, // key rrc encryption
         NULL, // key rrc integrity
         NULL // key encryption
  #ifdef Rel10
         ,NULL
  #endif
         );
1719

Lionel Gauthier's avatar
 
Lionel Gauthier committed
1720
  rrc_rlc_config_asn1_req(NB_eNB_INST+ue_mod_idP, frameP,0,eNB_index,
1721 1722 1723 1724 1725 1726 1727
        NULL,// SRB_ToAddModList
        NULL,// DRB_ToAddModList
        drb2release_list // DRB_ToReleaseList
  #ifdef Rel10
        ,NULL
  #endif
        );
1728
   */
1729

1730 1731 1732 1733

  //A little cleanup at RRC...
  //Copying current queue config to free RRC index
  /*
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1734 1735 1736
    memcpy((void *)UE_rrc_inst[ue_mod_idP].SRB1_config[~(7<<eNB_index)],(void *)UE_rrc_inst[ue_mod_idP].SRB1_config[7<<eNB_index],sizeof(SRB_ToAddMod_t));
    memcpy((void *)UE_rrc_inst[ue_mod_idP].SRB2_config[~(7<<eNB_index)],(void *)UE_rrc_inst[ue_mod_idP].SRB2_config[7<<eNB_index],sizeof(SRB_ToAddMod_t));
    memcpy((void *)UE_rrc_inst[ue_mod_idP].DRB_config[~(7<<eNB_index)][0],(void *)UE_rrc_inst[ue_mod_idP].DRB_config[7<<eNB_index][0],sizeof(DRB_ToAddMod_t));
1737
   */
1738 1739
  /*
  LOG_N(RRC,"Not sure if Freeing the current queue config works properly: Fix me\n");
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1740 1741 1742
  free((void *)&UE_rrc_inst[ue_mod_idP].SRB1_config[eNB_index]);
  free((void *)&UE_rrc_inst[ue_mod_idP].SRB2_config[eNB_index]);
  free((void *)&UE_rrc_inst[ue_mod_idP].DRB_config[eNB_index][0]);
1743

Lionel Gauthier's avatar
 
Lionel Gauthier committed
1744 1745 1746
  UE_rrc_inst[ue_mod_idP].SRB1_config[eNB_index] = NULL;
  UE_rrc_inst[ue_mod_idP].SRB2_config[eNB_index] = NULL;
  UE_rrc_inst[ue_mod_idP].DRB_config[eNB_index][0] = NULL;
1747
   */
1748
  //Synchronisation to DL of target cell
1749
  LOG_D(RRC,
Lionel Gauthier's avatar
Lionel Gauthier committed
1750
        "HO: Reset PDCP and RLC for configured RBs.. \n[FRAME %05d][RRC_UE][MOD %02d][][--- MAC_CONFIG_REQ  (SRB2 eNB %d) --->][MAC_UE][MOD %02d][]\n",
1751
        ctxt_pP->frame, ctxt_pP->module_id, eNB_index, ctxt_pP->module_id);
1752 1753

  // Reset MAC and configure PHY
1754
  rrc_mac_config_req(ctxt_pP->module_id,
1755
                     0,
1756 1757 1758
                     ENB_FLAG_NO,
                     0,
                     eNB_index,
1759 1760
                     (RadioResourceConfigCommonSIB_t *)NULL,
                     (struct PhysicalConfigDedicated *)NULL,
1761
#ifdef Rel10
1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777
                     (SCellToAddMod_r10_t *)NULL,
                     //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
#endif
                     (MeasObjectToAddMod_t **)NULL,
                     (MAC_MainConfig_t *)NULL,
                     0,
                     (struct LogicalChannelConfig *)NULL,
                     (MeasGapConfig_t *)NULL,
                     (TDD_Config_t *)NULL,
                     mobilityControlInfo,
                     (uint8_t *)NULL,
                     (uint16_t *)NULL,
                     NULL,
                     NULL,
                     NULL,
                     NULL
1778
#ifdef Rel10
1779 1780 1781
                     ,0,
                     (MBSFN_AreaInfoList_r9_t *)NULL,
                     (PMCH_InfoList_r9_t *)NULL
1782 1783
#endif
#ifdef CBA
1784 1785
                     ,0,
                     0
1786
#endif
1787
                    );
1788

1789
  // Re-establish PDCP for all RBs that are established
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1790 1791 1792
  // rrc_pdcp_config_req (ue_mod_idP+NB_eNB_INST, frameP, 0, CONFIG_ACTION_ADD, ue_mod_idP+DCCH);
  // rrc_pdcp_config_req (ue_mod_idP+NB_eNB_INST, frameP, 0, CONFIG_ACTION_ADD, ue_mod_idP+DCCH1);
  // rrc_pdcp_config_req (ue_mod_idP+NB_eNB_INST, frameP, 0, CONFIG_ACTION_ADD, ue_mod_idP+DTCH);
1793 1794


1795
  // Re-establish RLC for all RBs that are established
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1796 1797 1798
  // rrc_rlc_config_req(ue_mod_idP+NB_eNB_INST,frameP,0,CONFIG_ACTION_ADD,ue_mod_idP+DCCH,SIGNALLING_RADIO_BEARER,Rlc_info_am_config);
  // rrc_rlc_config_req(ue_mod_idP+NB_eNB_INST,frameP,0,CONFIG_ACTION_ADD,ue_mod_idP+DCCH1,SIGNALLING_RADIO_BEARER,Rlc_info_am_config);
  // rrc_rlc_config_req(ue_mod_idP+NB_eNB_INST,frameP,0,CONFIG_ACTION_ADD,ue_mod_idP+DTCH,RADIO_ACCESS_BEARER,Rlc_info_um);
1799
  rrc_mac_get_new_crnti(ctxt_pP,eNB_index);
1800
  UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].State = RRC_SI_RECEIVED;
1801
}
1802 1803 1804 1805 1806 1807 1808 1809

//-----------------------------------------------------------------------------
void
rrc_detach_from_eNB(
  module_id_t ue_mod_idP,
  uint8_t eNB_index
)
//-----------------------------------------------------------------------------
1810
{
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1811
  //UE_rrc_inst[ue_mod_idP].DRB_config[eNB_index]
1812 1813
}

1814 1815 1816 1817 1818 1819 1820 1821 1822
//-----------------------------------------------------------------------------
void
rrc_ue_decode_dcch(
  const protocol_ctxt_t* const ctxt_pP,
  const rb_id_t                Srb_id,
  const uint8_t*         const Buffer,
  const uint8_t                eNB_indexP
)
//-----------------------------------------------------------------------------
1823
{
1824 1825 1826 1827

  //DL_DCCH_Message_t dldcchmsg;
  DL_DCCH_Message_t *dl_dcch_msg=NULL;//&dldcchmsg;
  //  asn_dec_rval_t dec_rval;
1828
  // int i;
1829
  uint8_t target_eNB_index=0xFF;
winckel's avatar
winckel committed
1830 1831 1832 1833
#if defined(ENABLE_ITTI)
  MessageDef *msg_p;
#endif

1834
  if (Srb_id != 1) {
1835
    LOG_E(RRC,"[UE %d] Frame %d: Received message on DL-DCCH (SRB%d), should not have ...\n",
1836
          ctxt_pP->module_id, ctxt_pP->frame, Srb_id);
1837
    return;
1838 1839 1840 1841 1842
  }

  //memset(dl_dcch_msg,0,sizeof(DL_DCCH_Message_t));

  // decode messages
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1843
  //  LOG_D(RRC,"[UE %d] Decoding DL-DCCH message\n",ue_mod_idP);
1844 1845 1846 1847
  /*
  for (i=0;i<30;i++)
    LOG_T(RRC,"%x.",Buffer[i]);
  LOG_T(RRC, "\n");
1848
   */
1849
  uper_decode(NULL,
1850 1851 1852 1853
              &asn_DEF_DL_DCCH_Message,
              (void**)&dl_dcch_msg,
              (uint8_t*)Buffer,
              RRC_BUF_SIZE,0,0);
1854 1855 1856 1857 1858

#ifdef XER_PRINT
  xer_fprint(stdout,&asn_DEF_DL_DCCH_Message,(void*)dl_dcch_msg);
#endif

1859
#if defined(ENABLE_ITTI)
1860
# if defined(DISABLE_ITTI_XER_PRINT)
1861
  {
winckel's avatar
winckel committed
1862 1863
    msg_p = itti_alloc_new_message (TASK_RRC_UE, RRC_DL_DCCH_MESSAGE);
    memcpy (&msg_p->ittiMsg, (void *) dl_dcch_msg, sizeof(RrcDlDcchMessage));
1864

1865
    itti_send_msg_to_task (TASK_UNKNOWN, ctxt_pP->instance, msg_p);
1866
  }
1867 1868
# else
  {
1869
    char        message_string[30000];
1870
    size_t      message_string_size;
1871

1872 1873 1874 1875
    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_DL_DCCH_Message, (void *)dl_dcch_msg)) > 0) {
      msg_p = itti_alloc_new_message_sized (TASK_RRC_UE, RRC_DL_DCCH, message_string_size + sizeof (IttiMsgText));
      msg_p->ittiMsg.rrc_dl_dcch.size = message_string_size;
      memcpy(&msg_p->ittiMsg.rrc_dl_dcch.text, message_string, message_string_size);
1876

1877
      itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
1878
    }
1879 1880
  }
# endif
1881 1882
#endif

1883 1884
  if (dl_dcch_msg->message.present == DL_DCCH_MessageType_PR_c1) {

1885
    if (UE_rrc_inst[ctxt_pP->module_id].Info[eNB_indexP].State >= RRC_CONNECTED) {
1886

1887
      switch (dl_dcch_msg->message.choice.c1.present) {
1888

1889
      case DL_DCCH_MessageType__c1_PR_NOTHING:
1890 1891
        LOG_I(RRC, "[UE %d] Frame %d : Received PR_NOTHING on DL-DCCH-Message\n",
              ctxt_pP->module_id, ctxt_pP->frame);
1892
        return;
winckel's avatar
RRC:  
winckel committed
1893

1894 1895
      case DL_DCCH_MessageType__c1_PR_csfbParametersResponseCDMA2000:
        break;
1896

1897
      case DL_DCCH_MessageType__c1_PR_dlInformationTransfer: {
winckel's avatar
RRC:  
winckel committed
1898
#if defined(ENABLE_ITTI)
1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916
        DLInformationTransfer_t *dlInformationTransfer = &dl_dcch_msg->message.choice.c1.choice.dlInformationTransfer;

        if ((dlInformationTransfer->criticalExtensions.present == DLInformationTransfer__criticalExtensions_PR_c1)
            && (dlInformationTransfer->criticalExtensions.choice.c1.present
                == DLInformationTransfer__criticalExtensions__c1_PR_dlInformationTransfer_r8)
            && (dlInformationTransfer->criticalExtensions.choice.c1.choice.dlInformationTransfer_r8.dedicatedInfoType.present
                == DLInformationTransfer_r8_IEs__dedicatedInfoType_PR_dedicatedInfoNAS)) {
          /* This message hold a dedicated info NAS payload, forward it to NAS */
          struct DLInformationTransfer_r8_IEs__dedicatedInfoType *dedicatedInfoType =
                &dlInformationTransfer->criticalExtensions.choice.c1.choice.dlInformationTransfer_r8.dedicatedInfoType;
          uint32_t pdu_length;
          uint8_t *pdu_buffer;
          MessageDef *msg_p;

          pdu_length = dedicatedInfoType->choice.dedicatedInfoNAS.size;
          pdu_buffer = dedicatedInfoType->choice.dedicatedInfoNAS.buf;

          msg_p = itti_alloc_new_message(TASK_RRC_UE, NAS_DOWNLINK_DATA_IND);
1917
          NAS_DOWNLINK_DATA_IND(msg_p).UEid = ctxt_pP->module_id; // TODO set the UEid to something else ?
1918 1919 1920
          NAS_DOWNLINK_DATA_IND(msg_p).nasMsg.length = pdu_length;
          NAS_DOWNLINK_DATA_IND(msg_p).nasMsg.data = pdu_buffer;

1921
          itti_send_msg_to_task(TASK_NAS_UE, ctxt_pP->instance, msg_p);
1922 1923
        }

winckel's avatar
RRC:  
winckel committed
1924
#endif
1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939
        break;
      }

      case DL_DCCH_MessageType__c1_PR_handoverFromEUTRAPreparationRequest:
        break;

      case DL_DCCH_MessageType__c1_PR_mobilityFromEUTRACommand:
        break;

      case DL_DCCH_MessageType__c1_PR_rrcConnectionReconfiguration:

        // first check if mobilityControlInfo  is present
        if (dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.mobilityControlInfo
            != NULL) {
          /* 36.331, 5.3.5.4 Reception of an RRCConnectionReconfiguration including the mobilityControlInfo by the UE (handover)*/
1940
          if (UE_rrc_inst[ctxt_pP->module_id].HandoverInfoUe.targetCellId
1941 1942
              != dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.mobilityControlInfo->targetPhysCellId) {
            LOG_W(RRC,
1943 1944 1945
                  "[UE %d] Frame %d: Handover target (%d) is different from RSRP measured target (%d)..\n",
                  ctxt_pP->module_id,
                  ctxt_pP->frame,
1946
                  dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.mobilityControlInfo->targetPhysCellId,
1947
                  UE_rrc_inst[ctxt_pP->module_id].HandoverInfoUe.targetCellId);
1948
            return;
1949
          } else if ((target_eNB_index = get_adjacent_cell_mod_id(UE_rrc_inst[ctxt_pP->module_id].HandoverInfoUe.targetCellId))
1950 1951
                     == 0xFF) {
            LOG_W(RRC,
1952 1953 1954
                  "[UE %d] Frame %d: ue_mod_idP of the target eNB not found, check the network topology\n",
                  ctxt_pP->module_id,
                  ctxt_pP->frame);
1955 1956 1957
            return;
          } else {
            LOG_I(RRC,
1958 1959 1960 1961
                  "[UE% d] Frame %d: Received rrcConnectionReconfiguration with mobilityControlInfo \n",
                  ctxt_pP->module_id,
                  ctxt_pP->frame);
            UE_rrc_inst[ctxt_pP->module_id].HandoverInfoUe.measFlag = 1; // Ready to send more MeasReports if required
1962
          }
1963
        }
1964

1965 1966 1967 1968
        rrc_ue_process_rrcConnectionReconfiguration(
          ctxt_pP,
          &dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration,
          eNB_indexP);
1969 1970

        if (target_eNB_index != 0xFF) {
1971 1972 1973
          rrc_ue_generate_RRCConnectionReconfigurationComplete(
            ctxt_pP,
            target_eNB_index,
1974
            dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.rrc_TransactionIdentifier);
1975 1976 1977 1978
          UE_rrc_inst[ctxt_pP->module_id].Info[eNB_indexP].State = RRC_HO_EXECUTION;
          UE_rrc_inst[ctxt_pP->module_id].Info[target_eNB_index].State = RRC_RECONFIGURED;
          LOG_I(RRC, "[UE %d] State = RRC_RECONFIGURED during HO (eNB %d)\n",
                ctxt_pP->module_id, target_eNB_index);
Lionel Gauthier's avatar
Lionel Gauthier committed
1979
#if defined(ENABLE_ITTI)
1980
#if ENABLE_RAL
1981 1982 1983 1984 1985 1986 1987
          {
            MessageDef                                 *message_ral_p = NULL;
            rrc_ral_connection_reconfiguration_ho_ind_t connection_reconfiguration_ho_ind;
            int                                         i;

            message_ral_p = itti_alloc_new_message (TASK_RRC_UE, RRC_RAL_CONNECTION_RECONFIGURATION_HO_IND);
            memset(&connection_reconfiguration_ho_ind, 0, sizeof(rrc_ral_connection_reconfiguration_ho_ind_t));
1988
            connection_reconfiguration_ho_ind.ue_id = ctxt_pP->module_id;
1989

1990 1991
            if (dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList
                != NULL) {
1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005
              connection_reconfiguration_ho_ind.num_drb      =
                dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList->list.count;

              for (i=0; (
                     i<dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList->list.count)
                   && (i < maxDRB); i++) {
                // why minus 1 in RRC code for drb_identity ?
                connection_reconfiguration_ho_ind.drb_id[i]   =
                  dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList->list.array[i]->drb_Identity;
              }
            } else {
              connection_reconfiguration_ho_ind.num_drb      = 0;
            }

2006 2007
            if (dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->srb_ToAddModList
                != NULL) {
2008
              connection_reconfiguration_ho_ind.num_srb      =
2009 2010 2011
                dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->srb_ToAddModList->list.count
                +
                UE_rrc_inst[ctxt_pP->module_id].num_srb;
2012
            } else {
2013
              connection_reconfiguration_ho_ind.num_srb      += UE_rrc_inst[ctxt_pP->module_id].num_srb;
2014 2015
            }

2016
            if (connection_reconfiguration_ho_ind.num_srb > 2 ) {
2017
              connection_reconfiguration_ho_ind.num_srb =2;
2018
            }
2019 2020 2021 2022

            memcpy (&message_ral_p->ittiMsg, (void *) &connection_reconfiguration_ho_ind, sizeof(rrc_ral_connection_reconfiguration_ho_ind_t));
            //#warning "ue_mod_idP ? for instance ? => YES"
            LOG_I(RRC, "Sending RRC_RAL_CONNECTION_RECONFIGURATION_HO_IND to mRAL\n");
2023
            itti_send_msg_to_task (TASK_RAL_UE, ctxt_pP->instance, message_ral_p);
2024
          }
Lionel Gauthier's avatar
Lionel Gauthier committed
2025 2026
#endif
#endif
2027
        } else {
2028 2029 2030
          rrc_ue_generate_RRCConnectionReconfigurationComplete(
            ctxt_pP,
            eNB_indexP,
2031
            dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.rrc_TransactionIdentifier);
2032 2033 2034 2035
          UE_rrc_inst[ctxt_pP->module_id].Info[eNB_indexP].State = RRC_RECONFIGURED;
          LOG_I(RRC, "[UE %d] State = RRC_RECONFIGURED (eNB %d)\n",
                ctxt_pP->module_id,
                eNB_indexP);
Lionel Gauthier's avatar
Lionel Gauthier committed
2036
#if defined(ENABLE_ITTI)
2037
#if ENABLE_RAL
2038 2039 2040 2041 2042 2043 2044
          {
            MessageDef                                 *message_ral_p = NULL;
            rrc_ral_connection_reconfiguration_ind_t    connection_reconfiguration_ind;
            int                                         i;

            message_ral_p = itti_alloc_new_message (TASK_RRC_UE, RRC_RAL_CONNECTION_RECONFIGURATION_IND);
            memset(&connection_reconfiguration_ind, 0, sizeof(rrc_ral_connection_reconfiguration_ind_t));
2045
            connection_reconfiguration_ind.ue_id = ctxt_pP->module_id;
2046

2047 2048
            if (dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList
                != NULL) {
2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062
              connection_reconfiguration_ind.num_drb      =
                dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList->list.count;

              for (i=0; (
                     i<dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList->list.count)
                   && (i < maxDRB); i++) {
                // why minus 1 in RRC code for drb_identity ?
                connection_reconfiguration_ind.drb_id[i]   =
                  dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList->list.array[i]->drb_Identity;
              }
            } else {
              connection_reconfiguration_ind.num_drb      = 0;
            }

2063 2064
            if (dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->srb_ToAddModList
                != NULL) {
2065
              connection_reconfiguration_ind.num_srb      =
2066 2067 2068
                dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->srb_ToAddModList->list.count
                +
                UE_rrc_inst[ctxt_pP->module_id].num_srb;
2069
            } else {
2070
              connection_reconfiguration_ind.num_srb      +=UE_rrc_inst[ctxt_pP->module_id].num_srb;
2071 2072
            }

2073
            if (connection_reconfiguration_ind.num_srb > 2 ) {
2074
              connection_reconfiguration_ind.num_srb =2;
2075
            }
2076 2077 2078 2079

            memcpy (&message_ral_p->ittiMsg, (void *) &connection_reconfiguration_ind, sizeof(rrc_ral_connection_reconfiguration_ind_t));
            //#warning "ue_mod_idP ? for instance ? => YES"
            LOG_I(RRC, "Sending RRC_RAL_CONNECTION_RECONFIGURATION_IND to mRAL\n");
2080
            itti_send_msg_to_task (TASK_RAL_UE, ctxt_pP->instance, message_ral_p);
2081
          }
Lionel Gauthier's avatar
Lionel Gauthier committed
2082 2083 2084
#endif
#endif

2085 2086 2087
        }

        break;
2088

2089
      case DL_DCCH_MessageType__c1_PR_rrcConnectionRelease:
2090
#if defined(ENABLE_ITTI)
2091 2092 2093 2094 2095 2096 2097 2098 2099
        msg_p = itti_alloc_new_message(TASK_RRC_UE, NAS_CONN_RELEASE_IND);

        if ((dl_dcch_msg->message.choice.c1.choice.rrcConnectionRelease.criticalExtensions.present
             == RRCConnectionRelease__criticalExtensions_PR_c1)
            && (dl_dcch_msg->message.choice.c1.choice.rrcConnectionRelease.criticalExtensions.choice.c1.present
                == RRCConnectionRelease__criticalExtensions__c1_PR_rrcConnectionRelease_r8)) {
          NAS_CONN_RELEASE_IND(msg_p).cause =
            dl_dcch_msg->message.choice.c1.choice.rrcConnectionRelease.criticalExtensions.choice.c1.choice.rrcConnectionRelease_r8.releaseCause;
        }
winckel's avatar
winckel committed
2100

2101
        itti_send_msg_to_task(TASK_NAS_UE, ctxt_pP->instance, msg_p);
2102
#if ENABLE_RAL
2103
        msg_p = itti_alloc_new_message(TASK_RRC_UE, RRC_RAL_CONNECTION_RELEASE_IND);
2104 2105
        RRC_RAL_CONNECTION_RELEASE_IND(msg_p).ue_id = ctxt_pP->module_id;
        itti_send_msg_to_task(TASK_RAL_UE, ctxt_pP->instance, msg_p);
Lionel Gauthier's avatar
Lionel Gauthier committed
2106
#endif
2107
#endif
2108
        break;
2109

2110
      case DL_DCCH_MessageType__c1_PR_securityModeCommand:
2111 2112 2113 2114 2115 2116
        LOG_I(RRC, "[UE %d] Received securityModeCommand (eNB %d)\n",
              ctxt_pP->module_id, eNB_indexP);
        rrc_ue_process_securityModeCommand(
          ctxt_pP,
          &dl_dcch_msg->message.choice.c1.choice.securityModeCommand,
          eNB_indexP);
2117
        break;
2118

2119
      case DL_DCCH_MessageType__c1_PR_ueCapabilityEnquiry:
2120 2121 2122 2123 2124 2125 2126
        LOG_I(RRC, "[UE %d] Received Capability Enquiry (eNB %d)\n",
              ctxt_pP->module_id,
              eNB_indexP);
        rrc_ue_process_ueCapabilityEnquiry(
          ctxt_pP,
          &dl_dcch_msg->message.choice.c1.choice.ueCapabilityEnquiry,
          eNB_indexP);
2127
        break;
2128

2129 2130
      case DL_DCCH_MessageType__c1_PR_counterCheck:
        break;
winckel's avatar
RRC:  
winckel committed
2131

2132
#ifdef Rel10
2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151

      case DL_DCCH_MessageType__c1_PR_ueInformationRequest_r9:
        break;

      case DL_DCCH_MessageType__c1_PR_loggedMeasurementConfiguration_r10:
        break;

      case DL_DCCH_MessageType__c1_PR_rnReconfiguration_r10:
        break;
#endif

      case DL_DCCH_MessageType__c1_PR_spare1:
      case DL_DCCH_MessageType__c1_PR_spare2:
      case DL_DCCH_MessageType__c1_PR_spare3:
      case DL_DCCH_MessageType__c1_PR_spare4:
        break;

      default:
        break;
2152
      }
2153
    }
2154
  }
2155

2156
#ifndef NO_RRM
2157
  send_msg(&S_rrc,msg_rrc_end_scan_req(ctxt_pP->module_id,eNB_indexP));
2158 2159 2160
#endif
}

2161
const char siWindowLength[8][5] = {"1ms","2ms","5ms","10ms","15ms","20ms","40ms","ERR"};
2162 2163
const char siWindowLength_int[7] = {1,2,5,10,15,20,40};

2164 2165
const char SIBType[12][6] = {"SIB3","SIB4","SIB5","SIB6","SIB7","SIB8","SIB9","SIB10","SIB11","SIB12","SIB13","Spare"};
const char SIBPeriod[8][6]= {"rf8","rf16","rf32","rf64","rf128","rf256","rf512","ERR"};
2166 2167
int siPeriod_int[7] = {80,160,320,640,1280,2560,5120};

2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219
static const char* SIBreserved( long value )
{
  if (value < 0 || value > 1)
    return "ERR";

  if (value)
    return "notReserved";

  return "reserved";
}
static const char* SIBbarred( long value )
{
  if (value < 0 || value > 1)
    return "ERR";

  if (value)
    return "notBarred";

  return "barred";
}
static const char* SIBallowed( long value )
{
  if (value < 0 || value > 1)
    return "ERR";

  if (value)
    return "notAllowed";

  return "allowed";
}
static const char* SIB2SoundingPresent( int value )
{
  switch (value) {
  case SoundingRS_UL_ConfigCommon_PR_NOTHING:
    return "NOTHING";

  case SoundingRS_UL_ConfigCommon_PR_release:
    return "release";

  case SoundingRS_UL_ConfigCommon_PR_setup:
    return "setup";
  }

  return "ERR";
}
static const char* SIB2numberOfRA_Preambles( long value )
{
  static char temp[4] = {0};

  if (value < 0 || value > 15)
    return "ERR";

2220
  snprintf( temp, sizeof(temp), "n%ld", value*4 + 4 );
2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238
  temp[3] = 0; // terminate string
  return temp;
}
static const char* SIB2powerRampingStep( long value )
{
  if (value < 0 || value > 3)
    return "ERR";

  static const char str[4][4] = {"dB0","dB2","dB4","dB6"};
  return str[value];
}
static const char* SIB2preambleInitialReceivedTargetPower( long value )
{
  static char temp[8] = {0};

  if (value < 0 || value > 15)
    return "ERR";

2239
  snprintf( temp, sizeof(temp), "dBm-%ld", 120 - value*2 );
2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250
  temp[7] = 0; // terminate string
  return temp;
}
static const char* SIB2preambleTransMax( long value )
{
  static char temp[5] = {0};

  if (value < 0 || value > 10)
    return "ERR";

  if (value <= 5) {
2251
    snprintf( temp, sizeof(temp), "n%ld", value+3 );
2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281
    return temp;
  }

  switch (value) {
  case 6:
    return "n10";

  case 7:
    return "n20";

  case 8:
    return "n50";

  case 9:
    return "n100";

  case 10:
    return "n200";
  }
}
static const char* SIB2ra_ResponseWindowSize( long value )
{
  static char temp[4] = {0};

  if (value < 0 || value > 7)
    return "ERR";

  if (value == 7)
    return "sf10";

2282
  snprintf( temp, sizeof(temp), "sf%ld", value+2 );
2283 2284 2285 2286 2287 2288 2289 2290 2291
  return temp;
}
static const char* SIB2mac_ContentionResolutionTimer( long value )
{
  static char temp[5] = {0};

  if (value < 0 || value > 7)
    return "ERR";

2292
  snprintf( temp, sizeof(temp), "sf%ld", 8 + value*8 );
2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326
  return temp;
}
static const char* SIB2modificationPeriodCoeff( long value )
{
  static char temp[4] = {0};

  if (value < 0 || value > 3)
    return "ERR";

  snprintf( temp, sizeof(temp), "n%d", (int)pow(2,value+1) );
  return temp;
}
static const char* SIB2defaultPagingCycle( long value )
{
  static char temp[6] = {0};

  if (value < 0 || value > 3)
    return "ERR";

  snprintf( temp, sizeof(temp), "rf%d", (int)pow(2,value+4) );
  return temp;
}
static const char* SIB2nB( long value )
{
  if (value < 0 || value > 7)
    return "ERR";

  static const char str[8][17] = {"fourT","twoT","oneT","halfT","quarterT","oneEigthT","oneSixteenthT","oneThirtySecondT"};
  return str[value];
}




2327
//-----------------------------------------------------------------------------
2328
int decode_BCCH_DLSCH_Message(
2329 2330 2331 2332 2333
  const protocol_ctxt_t* const ctxt_pP,
  const uint8_t                eNB_index,
  uint8_t*               const Sdu,
  const uint8_t                Sdu_len,
  const uint8_t                rsrq,
2334
  const uint8_t                rsrp )
Lionel Gauthier's avatar
Lionel Gauthier committed
2335
{
2336
  BCCH_DL_SCH_Message_t *bcch_message = NULL;
2337 2338
  SystemInformationBlockType1_t* sib1 = UE_rrc_inst[ctxt_pP->module_id].sib1[eNB_index];
  int i;
2339

2340
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_BCCH, VCD_FUNCTION_IN );
2341

2342 2343 2344 2345
  if (((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&1) == 1) &&  // SIB1 received
      (UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIcnt == sib1->schedulingInfoList.list.count)) {
    // Avoid decoding  SystemInformationBlockType1_t* sib1 = UE_rrc_inst[ctxt_pP->module_id].sib1[eNB_index];
    // to prevent memory bloating
2346
    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_BCCH, VCD_FUNCTION_OUT );
2347
    return 0;
2348
  }
2349

2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361
  rrc_set_sub_state( ctxt_pP->module_id, RRC_SUB_STATE_IDLE_RECEIVING_SIB );

  asn_dec_rval_t dec_rval = uper_decode_complete( NULL,
                            &asn_DEF_BCCH_DL_SCH_Message,
                            (void **)&bcch_message,
                            (const void *)Sdu,
                            Sdu_len );

  if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0)) {
    LOG_E( RRC, "[UE %"PRIu8"] Failed to decode BCCH_DLSCH_MESSAGE (%zu bits)\n",
           ctxt_pP->module_id,
           dec_rval.consumed );
2362 2363 2364
    for (i=0;i<Sdu_len;i++)
      printf("%02x ",Sdu[i]);
    printf("\n");
2365 2366 2367 2368 2369
    // free the memory
    SEQUENCE_free( &asn_DEF_BCCH_DL_SCH_Message, (void*)bcch_message, 1 );
    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_BCCH, VCD_FUNCTION_OUT );
    return -1;
  }
2370 2371

#if defined(ENABLE_ITTI)
2372
# if defined(DISABLE_ITTI_XER_PRINT)
2373 2374
  {
    MessageDef *msg_p;
2375

2376 2377
    msg_p = itti_alloc_new_message (TASK_RRC_UE, RRC_DL_BCCH_MESSAGE);
    memcpy (&msg_p->ittiMsg, (void *) bcch_message, sizeof(RrcDlBcchMessage));
2378

2379 2380
    itti_send_msg_to_task (TASK_UNKNOWN, ctxt_pP->instance, msg_p);
  }
2381
# else
2382 2383 2384
  {
    char        message_string[15000];
    size_t      message_string_size;
2385

2386 2387
    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_BCCH_DL_SCH_Message, (void *)bcch_message)) > 0) {
      MessageDef *msg_p;
2388

2389 2390 2391
      msg_p = itti_alloc_new_message_sized (TASK_RRC_UE, RRC_DL_BCCH, message_string_size + sizeof (IttiMsgText));
      msg_p->ittiMsg.rrc_dl_bcch.size = message_string_size;
      memcpy(&msg_p->ittiMsg.rrc_dl_bcch.text, message_string, message_string_size);
winckel's avatar
winckel committed
2392

2393
      itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
2394
    }
2395
  }
2396
# endif
2397 2398
#endif

2399 2400 2401 2402 2403
  if (bcch_message->message.present == BCCH_DL_SCH_MessageType_PR_c1) {
    switch (bcch_message->message.choice.c1.present) {
    case BCCH_DL_SCH_MessageType__c1_PR_systemInformationBlockType1:
      if ((ctxt_pP->frame % 2) == 0) {
        // even frame
2404
        if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&1) == 0) {
2405 2406 2407 2408 2409 2410
          SystemInformationBlockType1_t* sib1 = UE_rrc_inst[ctxt_pP->module_id].sib1[eNB_index];
          memcpy( (void*)sib1,
                  (void*)&bcch_message->message.choice.c1.choice.systemInformationBlockType1,
                  sizeof(SystemInformationBlockType1_t) );
          LOG_D( RRC, "[UE %"PRIu8"] Decoding First SIB1\n", ctxt_pP->module_id );
          decode_SIB1( ctxt_pP, eNB_index, rsrq, rsrp );
2411
        }
2412
      }
2413

2414
      break;
2415

2416
    case BCCH_DL_SCH_MessageType__c1_PR_systemInformation:
2417
      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&1) == 1) {
2418
        // SIB1 with schedulingInfoList is available
2419

2420 2421 2422 2423
        SystemInformation_t* si = UE_rrc_inst[ctxt_pP->module_id].si[eNB_index];
        memcpy( si,
                &bcch_message->message.choice.c1.choice.systemInformation,
                sizeof(SystemInformation_t) );
2424

2425 2426 2427
        LOG_D( RRC, "[UE %"PRIu8"] Decoding SI for frameP %"PRIu32"\n",
               ctxt_pP->module_id,
               ctxt_pP->frame );
2428

2429
        decode_SI( ctxt_pP, eNB_index );
2430
      }
2431 2432 2433 2434 2435 2436

      break;

    case BCCH_DL_SCH_MessageType__c1_PR_NOTHING:
    default:
      break;
2437
    }
2438
  }
winckel's avatar
winckel committed
2439

2440
  if ((rrc_get_sub_state(ctxt_pP->module_id) == RRC_SUB_STATE_IDLE_SIB_COMPLETE)
2441
#if defined(ENABLE_USE_MME)
2442
      && (UE_rrc_inst[ctxt_pP->module_id].initialNasMsg.data != NULL)
2443
#endif
2444
     ) {
2445
    rrc_ue_generate_RRCConnectionRequest(ctxt_pP, 0);
2446
    rrc_set_sub_state( ctxt_pP->module_id, RRC_SUB_STATE_IDLE_CONNECTING );
winckel's avatar
winckel committed
2447 2448
  }

2449
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_BCCH, VCD_FUNCTION_OUT );
2450 2451

  return 0;
2452 2453 2454
}


2455
//-----------------------------------------------------------------------------
2456
static int decode_SIB1( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index, const uint8_t rsrq, const uint8_t rsrp )
Lionel Gauthier's avatar
Lionel Gauthier committed
2457
{
2458
  SystemInformationBlockType1_t* sib1 = UE_rrc_inst[ctxt_pP->module_id].sib1[eNB_index];
2459

2460
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_UE_DECODE_SIB1, VCD_FUNCTION_IN );
2461

2462
  LOG_I( RRC, "[UE %d] : Dumping SIB 1\n", ctxt_pP->module_id );
2463

2464
  PLMN_Identity_t *PLMN_identity = &sib1->cellAccessRelatedInfo.plmn_IdentityList.list.array[0]->plmn_Identity;
2465

2466 2467 2468 2469
  int mccdigits = PLMN_identity->mcc->list.count;
  int mncdigits = PLMN_identity->mnc.list.count;

  int mcc;
2470

2471
  if (mccdigits == 2) {
2472 2473
    mcc = *PLMN_identity->mcc->list.array[0]*10 + *PLMN_identity->mcc->list.array[1];
  } else {
2474 2475
    mcc = *PLMN_identity->mcc->list.array[0]*100 + *PLMN_identity->mcc->list.array[1]*10 + *PLMN_identity->mcc->list.array[2];
  }
2476

2477 2478
  int mnc;

2479
  if (mncdigits == 2) {
2480
    mnc = *PLMN_identity->mnc.list.array[0]*10 + *PLMN_identity->mnc.list.array[1];
2481
  } else {
2482 2483
    mnc = *PLMN_identity->mnc.list.array[0]*100 + *PLMN_identity->mnc.list.array[1]*10 + *PLMN_identity->mnc.list.array[2];
  }
2484

2485 2486 2487 2488
  int tac = 0;

  if (sib1->cellAccessRelatedInfo.trackingAreaCode.size == 2) {
    tac = (sib1->cellAccessRelatedInfo.trackingAreaCode.buf[0]<<8) + sib1->cellAccessRelatedInfo.trackingAreaCode.buf[1];
2489
  }
2490

2491 2492 2493 2494 2495 2496
  LOG_I( RRC, "PLMN MCC %0*d, MNC %0*d, TAC 0x%04x\n", mccdigits, mcc, mncdigits, mnc, tac );
  long cellReservedForOperatorUse = sib1->cellAccessRelatedInfo.plmn_IdentityList.list.array[0]->cellReservedForOperatorUse;
  LOG_I( RRC, "cellReservedForOperatorUse                 : raw:%ld decoded:%s\n", cellReservedForOperatorUse, SIBreserved(cellReservedForOperatorUse) );

  // search internal table for provider name
  int plmn_ind = 0;
2497

2498 2499 2500
  while (plmn_data[plmn_ind].mcc > 0) {
    if ((plmn_data[plmn_ind].mcc == mcc) && (plmn_data[plmn_ind].mnc == mnc)) {
      LOG_I( RRC, "Found %s (name from internal table)\n", plmn_data[plmn_ind].oper_short );
2501 2502
      break;
    }
2503

2504 2505
    plmn_ind++;
  }
2506

2507 2508
  if (plmn_data[plmn_ind].mcc < 0) {
    LOG_I( RRC, "Found Unknown operator (no entry in internal table)\n" );
2509
  }
2510

2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529
  LOG_I( RRC, "cellAccessRelatedInfo.cellIdentity         : raw:%"PRIu32" decoded:%02x.%02x.%02x.%02x\n",
         BIT_STRING_to_uint32( &sib1->cellAccessRelatedInfo.cellIdentity ),
         sib1->cellAccessRelatedInfo.cellIdentity.buf[0],
         sib1->cellAccessRelatedInfo.cellIdentity.buf[1],
         sib1->cellAccessRelatedInfo.cellIdentity.buf[2],
         sib1->cellAccessRelatedInfo.cellIdentity.buf[3] >> sib1->cellAccessRelatedInfo.cellIdentity.bits_unused);

  long cellBarred = sib1->cellAccessRelatedInfo.cellBarred;
  LOG_I( RRC, "cellAccessRelatedInfo.cellBarred           : raw:%ld decoded:%s\n", cellBarred, SIBbarred(cellBarred) );
  long intraFreqReselection = sib1->cellAccessRelatedInfo.intraFreqReselection;
  LOG_I( RRC, "cellAccessRelatedInfo.intraFreqReselection : raw:%ld decoded:%s\n", intraFreqReselection, SIBallowed(intraFreqReselection) );
  LOG_I( RRC, "cellAccessRelatedInfo.csg_Indication       : %d\n", sib1->cellAccessRelatedInfo.csg_Indication );

  if (sib1->cellAccessRelatedInfo.csg_Identity)
    LOG_I( RRC, "cellAccessRelatedInfo.csg_Identity         : %"PRIu32"\n", BIT_STRING_to_uint32(sib1->cellAccessRelatedInfo.csg_Identity) );
  else
    LOG_I( RRC, "cellAccessRelatedInfo.csg_Identity         : not defined\n" );

  LOG_I( RRC, "cellSelectionInfo.q_RxLevMin               : %ld\n", sib1->cellSelectionInfo.q_RxLevMin );
2530

2531 2532 2533 2534
  if (sib1->cellSelectionInfo.q_RxLevMinOffset)
    LOG_I( RRC, "cellSelectionInfo.q_RxLevMinOffset         : %ld\n", *sib1->cellSelectionInfo.q_RxLevMinOffset );
  else
    LOG_I( RRC, "cellSelectionInfo.q_RxLevMinOffset         : not defined\n" );
2535

2536 2537 2538 2539
  if (sib1->p_Max)
    LOG_I( RRC, "p_Max                                      : %ld\n", *sib1->p_Max );
  else
    LOG_I( RRC, "p_Max                                      : not defined\n" );
2540

2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554
  LOG_I( RRC, "freqBandIndicator                          : %ld\n", sib1->freqBandIndicator );

  if (sib1->schedulingInfoList.list.count > 0) {
    for (int i=0; i<sib1->schedulingInfoList.list.count; i++) {
      LOG_I( RRC, "si_Periodicity[%d]                          : %s\n", i, SIBPeriod[min(sib1->schedulingInfoList.list.array[i]->si_Periodicity,7)]);

      if (sib1->schedulingInfoList.list.array[i]->sib_MappingInfo.list.count > 0) {
        char temp[32 * sizeof(SIBType[0])] = {0}; // maxSIB==32

        for (int j=0; j<sib1->schedulingInfoList.list.array[i]->sib_MappingInfo.list.count; j++) {
          sprintf( temp + j*sizeof(SIBType[0]), "%*s ", (int)sizeof(SIBType[0])-1, SIBType[min(*sib1->schedulingInfoList.list.array[i]->sib_MappingInfo.list.array[0],11)] );
        }

        LOG_I( RRC, "siSchedulingInfoSIBType[%d]                 : %s\n", i, temp );
2555
      } else {
2556
        LOG_I( RRC, "mapping list %d is null\n", i );
2557
      }
2558 2559
    }
  } else {
2560
    LOG_E( RRC, "siSchedulingInfoPeriod[0]                  : PROBLEM!!!\n" );
2561
    return -1;
2562 2563
  }

2564 2565 2566
  if (sib1->tdd_Config) {
    LOG_I( RRC, "TDD subframeAssignment                     : %ld\n", sib1->tdd_Config->subframeAssignment );
    LOG_I( RRC, "TDD specialSubframePatterns                : %ld\n", sib1->tdd_Config->specialSubframePatterns );
2567 2568
  }

2569 2570 2571 2572 2573 2574 2575 2576
  LOG_I( RRC, "siWindowLength                             : %s\n", siWindowLength[min(sib1->si_WindowLength,7)] );
  LOG_I( RRC, "systemInfoValueTag                         : %ld\n", sib1->systemInfoValueTag );

  UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIperiod     = siPeriod_int[sib1->schedulingInfoList.list.array[0]->si_Periodicity];
  UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIwindowsize = siWindowLength_int[sib1->si_WindowLength];
  LOG_D( RRC, "[FRAME unknown][RRC_UE][MOD %02"PRIu8"][][--- MAC_CONFIG_REQ (SIB1 params eNB %"PRIu8") --->][MAC_UE][MOD %02"PRIu8"][]\n",
         ctxt_pP->module_id, eNB_index, ctxt_pP->module_id );

2577
  rrc_mac_config_req(ctxt_pP->module_id, 0, ENB_FLAG_NO, 0, eNB_index,
2578 2579
                      (RadioResourceConfigCommonSIB_t *)NULL,
                      (struct PhysicalConfigDedicated *)NULL,
2580
#ifdef Rel10
2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596
                      (SCellToAddMod_r10_t *)NULL,
                      //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
#endif
                      (MeasObjectToAddMod_t **)NULL,
                      (MAC_MainConfig_t *)NULL,
                      0,
                      (struct LogicalChannelConfig *)NULL,
                      (MeasGapConfig_t *)NULL,
                      UE_rrc_inst[ctxt_pP->module_id].sib1[eNB_index]->tdd_Config,
                      (MobilityControlInfo_t *) NULL,
                      &UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIwindowsize,
                      &UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIperiod,
                      NULL,
                      NULL,
                      NULL,
                      (MBSFN_SubframeConfigList_t *)NULL
2597
#ifdef Rel10
2598 2599 2600
                      ,0,
                      (MBSFN_AreaInfoList_r9_t *)NULL,
                      (PMCH_InfoList_r9_t *)NULL
2601 2602
#endif
#ifdef CBA
2603 2604 2605
                      ,
                      0,
                      0
2606
#endif
2607
                    );
2608

2609
  UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus = 1;
2610
  UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIB1systemInfoValueTag = sib1->systemInfoValueTag;
2611 2612 2613 2614 2615

#if defined(ENABLE_ITTI) && defined(ENABLE_USE_MME)
  {
    int cell_valid = 0;

2616
    if (sib1->cellAccessRelatedInfo.cellBarred == SystemInformationBlockType1__cellAccessRelatedInfo__cellBarred_notBarred) {
2617 2618 2619 2620
      /* Cell is not barred */
      int plmn;
      int plmn_number;

2621
      plmn_number = sib1->cellAccessRelatedInfo.plmn_IdentityList.list.count;
2622 2623 2624 2625 2626

      /* Compare requested PLMN and PLMNs from SIB1*/
      for (plmn = 0; plmn < plmn_number; plmn++) {
        PLMN_Identity_t *plmn_Identity;

2627
        plmn_Identity = &sib1->cellAccessRelatedInfo.plmn_IdentityList.list.array[plmn]->plmn_Identity;
2628

2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649
        if (
          (
            (plmn_Identity->mcc == NULL)
            ||
            (
              (UE_rrc_inst[ctxt_pP->module_id].plmnID.MCCdigit1 == *(plmn_Identity->mcc->list.array[0])) &&
              (UE_rrc_inst[ctxt_pP->module_id].plmnID.MCCdigit2 == *(plmn_Identity->mcc->list.array[1])) &&
              (UE_rrc_inst[ctxt_pP->module_id].plmnID.MCCdigit3 == *(plmn_Identity->mcc->list.array[2]))
            )
          )
          &&
          (UE_rrc_inst[ctxt_pP->module_id].plmnID.MNCdigit1 == *(plmn_Identity->mnc.list.array[0]))
          &&
          (UE_rrc_inst[ctxt_pP->module_id].plmnID.MNCdigit2 == *(plmn_Identity->mnc.list.array[1]))
          &&
          (
            ((UE_rrc_inst[ctxt_pP->module_id].plmnID.MNCdigit3 == 0xf) && (plmn_Identity->mnc.list.count == 2))
            ||
            (UE_rrc_inst[ctxt_pP->module_id].plmnID.MNCdigit3 == *(plmn_Identity->mnc.list.array[2]))
          )
        ) {
2650 2651 2652 2653 2654
          /* PLMN match, send a confirmation to NAS */
          MessageDef  *msg_p;

          msg_p = itti_alloc_new_message(TASK_RRC_UE, NAS_CELL_SELECTION_CNF);
          NAS_CELL_SELECTION_CNF (msg_p).errCode = AS_SUCCESS;
2655 2656
          NAS_CELL_SELECTION_CNF (msg_p).cellID = BIT_STRING_to_uint32(&sib1->cellAccessRelatedInfo.cellIdentity);
          NAS_CELL_SELECTION_CNF (msg_p).tac = BIT_STRING_to_uint16(&sib1->cellAccessRelatedInfo.trackingAreaCode);
2657 2658 2659 2660
          NAS_CELL_SELECTION_CNF (msg_p).rat = 0xFF;
          NAS_CELL_SELECTION_CNF (msg_p).rsrq = rsrq;
          NAS_CELL_SELECTION_CNF (msg_p).rsrp = rsrp;

2661
          itti_send_msg_to_task(TASK_NAS_UE, ctxt_pP->instance, msg_p);
2662 2663
          cell_valid = 1;
          break;
2664
        }
2665
      }
2666 2667
    }

2668 2669 2670
    if (cell_valid == 0) {
      /* Cell can not be used, ask PHY to try the next one */
      MessageDef  *msg_p;
2671

2672
      msg_p = itti_alloc_new_message(TASK_RRC_UE, PHY_FIND_NEXT_CELL_REQ);
2673

2674
      itti_send_msg_to_task(TASK_PHY_UE, ctxt_pP->instance, msg_p);
2675
    }
2676 2677 2678
  }
#endif

2679
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_UE_DECODE_SIB1, VCD_FUNCTION_OUT );
2680

2681
  return 0;
2682 2683 2684
}


2685
//-----------------------------------------------------------------------------
2686
static void dump_sib2( SystemInformationBlockType2_t *sib2 )
Lionel Gauthier's avatar
Lionel Gauthier committed
2687
{
2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729
  // ac_BarringInfo
  if (sib2->ac_BarringInfo) {
    LOG_I( RRC, "ac_BarringInfo->ac_BarringForEmergency : %d\n",
           sib2->ac_BarringInfo->ac_BarringForEmergency );

    if (sib2->ac_BarringInfo->ac_BarringForMO_Signalling) {
      LOG_I( RRC, "ac_BarringInfo->ac_BarringForMO_Signalling->ac_BarringFactor       : %ld\n",
             sib2->ac_BarringInfo->ac_BarringForMO_Signalling->ac_BarringFactor );
      LOG_I( RRC, "ac_BarringInfo->ac_BarringForMO_Signalling->ac_BarringTime         : %ld\n",
             sib2->ac_BarringInfo->ac_BarringForMO_Signalling->ac_BarringTime );
      LOG_I( RRC, "ac_BarringInfo->ac_BarringForMO_Signalling->ac_BarringForSpecialAC : %"PRIu32"\n",
             BIT_STRING_to_uint32(&sib2->ac_BarringInfo->ac_BarringForMO_Signalling->ac_BarringForSpecialAC) );
    } else
      LOG_I( RRC, "ac_BarringInfo->ac_BarringForMO_Signalling : not defined\n" );

    if (sib2->ac_BarringInfo->ac_BarringForMO_Data) {
      LOG_I( RRC, "ac_BarringInfo->ac_BarringForMO_Data->ac_BarringFactor       : %ld\n",
             sib2->ac_BarringInfo->ac_BarringForMO_Data->ac_BarringFactor );
      LOG_I( RRC, "ac_BarringInfo->ac_BarringForMO_Data->ac_BarringTime         : %ld\n",
             sib2->ac_BarringInfo->ac_BarringForMO_Data->ac_BarringTime );
      LOG_I( RRC, "ac_BarringInfo->ac_BarringForMO_Data->ac_BarringForSpecialAC : %"PRIu32"\n",
             BIT_STRING_to_uint32(&sib2->ac_BarringInfo->ac_BarringForMO_Data->ac_BarringForSpecialAC) );
    } else
      LOG_I( RRC, "ac_BarringInfo->ac_BarringForMO_Data : not defined\n" );
  } else
    LOG_I( RRC, "ac_BarringInfo : not defined\n" );

  // RACH
  LOG_I( RRC, "radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.numberOfRA_Preambles  : raw:%ld decoded:%s\n",
         sib2->radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.numberOfRA_Preambles,
         SIB2numberOfRA_Preambles(sib2->radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.numberOfRA_Preambles) );

  if (sib2->radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.preamblesGroupAConfig) {
    LOG_I( RRC, "radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.preamblesGroupAConfig->sizeOfRA_PreamblesGroupA : %ld\n",
           sib2->radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.preamblesGroupAConfig->sizeOfRA_PreamblesGroupA );
    LOG_I( RRC, "radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.preamblesGroupAConfig->messageSizeGroupA        : %ld\n",
           sib2->radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.preamblesGroupAConfig->messageSizeGroupA );
    LOG_I( RRC, "radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.preamblesGroupAConfig->messagePowerOffsetGroupB : %ld\n",
           sib2->radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.preamblesGroupAConfig->messagePowerOffsetGroupB );
  } else {
    LOG_I( RRC, "radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.preamblesGroupAConfig : not defined\n" );
  }
2730

2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774
  LOG_I( RRC, "radioResourceConfigCommon.rach_ConfigCommon.powerRampingParameters.powerRampingStep                   : raw:%ld decoded:%s\n",
         sib2->radioResourceConfigCommon.rach_ConfigCommon.powerRampingParameters.powerRampingStep,
         SIB2powerRampingStep(sib2->radioResourceConfigCommon.rach_ConfigCommon.powerRampingParameters.powerRampingStep) );
  LOG_I( RRC, "radioResourceConfigCommon.rach_ConfigCommon.powerRampingParameters.preambleInitialReceivedTargetPower : raw:%ld decoded:%s\n",
         sib2->radioResourceConfigCommon.rach_ConfigCommon.powerRampingParameters.preambleInitialReceivedTargetPower,
         SIB2preambleInitialReceivedTargetPower(sib2->radioResourceConfigCommon.rach_ConfigCommon.powerRampingParameters.preambleInitialReceivedTargetPower) );

  LOG_I( RRC, "radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.preambleTransMax              : raw:%ld decoded:%s\n",
         sib2->radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.preambleTransMax,
         SIB2preambleTransMax(sib2->radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.preambleTransMax) );
  LOG_I( RRC, "radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.ra_ResponseWindowSize         : raw:%ld decoded:%s\n",
         sib2->radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.ra_ResponseWindowSize,
         SIB2ra_ResponseWindowSize(sib2->radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.ra_ResponseWindowSize) );
  LOG_I( RRC, "radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.mac_ContentionResolutionTimer : raw:%ld decoded:%s\n",
         sib2->radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.mac_ContentionResolutionTimer,
         SIB2mac_ContentionResolutionTimer(sib2->radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.mac_ContentionResolutionTimer) );

  LOG_I( RRC, "radioResourceConfigCommon.rach_ConfigCommon.maxHARQ_Msg3Tx : %ld\n",
         sib2->radioResourceConfigCommon.rach_ConfigCommon.maxHARQ_Msg3Tx );

  // BCCH
  LOG_I( RRC, "radioResourceConfigCommon.bcch_Config.modificationPeriodCoeff : raw:%ld decoded:%s\n",
         sib2->radioResourceConfigCommon.bcch_Config.modificationPeriodCoeff,
         SIB2modificationPeriodCoeff(sib2->radioResourceConfigCommon.bcch_Config.modificationPeriodCoeff) );

  // PCCH
  LOG_I( RRC, "radioResourceConfigCommon.pcch_Config.defaultPagingCycle : raw:%ld decoded:%s\n",
         sib2->radioResourceConfigCommon.pcch_Config.defaultPagingCycle,
         SIB2defaultPagingCycle(sib2->radioResourceConfigCommon.pcch_Config.defaultPagingCycle) );
  LOG_I( RRC, "radioResourceConfigCommon.pcch_Config.nB                 : raw:%ld decoded:%s\n",
         sib2->radioResourceConfigCommon.pcch_Config.nB,
         SIB2nB(sib2->radioResourceConfigCommon.pcch_Config.nB) );

  // PRACH
  LOG_I( RRC, "radioResourceConfigCommon.prach_Config.rootSequenceIndex                          : %ld\n",
         sib2->radioResourceConfigCommon.prach_Config.rootSequenceIndex );
  LOG_I( RRC, "radioResourceConfigCommon.prach_Config.prach_ConfigInfo.prach_ConfigIndex         : %ld\n",
         sib2->radioResourceConfigCommon.prach_Config.prach_ConfigInfo.prach_ConfigIndex );
  LOG_I( RRC, "radioResourceConfigCommon.prach_Config.prach_ConfigInfo.highSpeedFlag             : %d\n",
         sib2->radioResourceConfigCommon.prach_Config.prach_ConfigInfo.highSpeedFlag );
  LOG_I( RRC, "radioResourceConfigCommon.prach_Config.prach_ConfigInfo.zeroCorrelationZoneConfig : %ld\n",
         sib2->radioResourceConfigCommon.prach_Config.prach_ConfigInfo.zeroCorrelationZoneConfig );
  LOG_I( RRC, "radioResourceConfigCommon.prach_Config.prach_ConfigInfo.prach_FreqOffset          : %ld\n",
         sib2->radioResourceConfigCommon.prach_Config.prach_ConfigInfo.prach_FreqOffset );
2775

2776 2777 2778 2779 2780
  // PDSCH-Config
  LOG_I( RRC, "radioResourceConfigCommon.pdsch_ConfigCommon.referenceSignalPower : %ld\n",
         sib2->radioResourceConfigCommon.pdsch_ConfigCommon.referenceSignalPower );
  LOG_I( RRC, "radioResourceConfigCommon.pdsch_ConfigCommon.p_b                  : %ld\n",
         sib2->radioResourceConfigCommon.pdsch_ConfigCommon.p_b );
2781

2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798
  // PUSCH-Config
  LOG_I( RRC, "radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.n_SB                : %ld\n",
         sib2->radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.n_SB );
  LOG_I( RRC, "radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.hoppingMode         : %ld\n",
         sib2->radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.hoppingMode );
  LOG_I( RRC, "radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.pusch_HoppingOffset : %ld\n",
         sib2->radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.pusch_HoppingOffset );
  LOG_I( RRC, "radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.enable64QAM         : %d\n",
         sib2->radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.enable64QAM );
  LOG_I( RRC, "radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.groupHoppingEnabled    : %d\n",
         sib2->radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.groupHoppingEnabled );
  LOG_I( RRC, "radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH   : %ld\n",
         sib2->radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH );
  LOG_I( RRC, "radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled : %d\n",
         sib2->radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled );
  LOG_I( RRC, "radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.cyclicShift            : %ld\n",
         sib2->radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.cyclicShift );
2799

2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824
  // PUCCH-Config
  LOG_I( RRC, "radioResourceConfigCommon.pucch_ConfigCommon.deltaPUCCH_Shift : %ld\n",
         sib2->radioResourceConfigCommon.pucch_ConfigCommon.deltaPUCCH_Shift );
  LOG_I( RRC, "radioResourceConfigCommon.pucch_ConfigCommon.nRB_CQI          : %ld\n",
         sib2->radioResourceConfigCommon.pucch_ConfigCommon.nRB_CQI );
  LOG_I( RRC, "radioResourceConfigCommon.pucch_ConfigCommon.nCS_AN           : %ld\n",
         sib2->radioResourceConfigCommon.pucch_ConfigCommon.nCS_AN );
  LOG_I( RRC, "radioResourceConfigCommon.pucch_ConfigCommon.n1PUCCH_AN       : %ld\n",
         sib2->radioResourceConfigCommon.pucch_ConfigCommon.n1PUCCH_AN );

  // SoundingRS_UL_Config
  LOG_I( RRC, "radioResourceConfigCommon.soundingRS_UL_ConfigCommon.present : raw:%d decoded:%s\n",
         sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.present,
         SIB2SoundingPresent(sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.present) );

  if (sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.present == SoundingRS_UL_ConfigCommon_PR_setup) {
    LOG_I( RRC, "radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_BandwidthConfig                 : %ld\n",
           sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_BandwidthConfig );
    LOG_I( RRC, "radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_SubframeConfig                  : %ld\n",
           sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_SubframeConfig );
    LOG_I( RRC, "radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.ackNackSRS_SimultaneousTransmission : %d\n",
           sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.ackNackSRS_SimultaneousTransmission );
    LOG_I( RRC, "radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_MaxUpPts                        : %ld\n",
           sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_MaxUpPts );
  }
2825

2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847
  // uplinkPowerControlCommon
  LOG_I( RRC, "radioResourceConfigCommon.uplinkPowerControlCommon.p0_NominalPUSCH   : %ld\n",
         sib2->radioResourceConfigCommon.uplinkPowerControlCommon.p0_NominalPUSCH );
  LOG_I( RRC, "radioResourceConfigCommon.uplinkPowerControlCommon.alpha             : %ld\n",
         sib2->radioResourceConfigCommon.uplinkPowerControlCommon.alpha );
  LOG_I( RRC, "radioResourceConfigCommon.uplinkPowerControlCommon.p0_NominalPUCCH   : %ld\n",
         sib2->radioResourceConfigCommon.uplinkPowerControlCommon.p0_NominalPUCCH );
  LOG_I( RRC, "radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format1  : %ld\n",
         sib2->radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format1 );
  LOG_I( RRC, "radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format1b : %ld\n",
         sib2->radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format1b );
  LOG_I( RRC, "radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format2  : %ld\n",
         sib2->radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format2 );
  LOG_I( RRC, "radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format2a : %ld\n",
         sib2->radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format2a );
  LOG_I( RRC, "radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format2b : %ld\n",
         sib2->radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format2b );
  LOG_I( RRC, "radioResourceConfigCommon.uplinkPowerControlCommon.deltaPreambleMsg3 : %ld\n",
         sib2->radioResourceConfigCommon.uplinkPowerControlCommon.deltaPreambleMsg3 );

  LOG_I( RRC, "radioResourceConfigCommon.ul_CyclicPrefixLength : %ld\n",
         sib2->radioResourceConfigCommon.ul_CyclicPrefixLength );
2848

2849 2850 2851 2852
#ifdef Rel10
  // UplinkPowerControlCommon_v1020
  // ...
#endif
2853

2854 2855 2856 2857 2858 2859
  LOG_I( RRC, "ue_TimersAndConstants.t300 : %ld\n", sib2->ue_TimersAndConstants.t300 );
  LOG_I( RRC, "ue_TimersAndConstants.t301 : %ld\n", sib2->ue_TimersAndConstants.t301 );
  LOG_I( RRC, "ue_TimersAndConstants.t310 : %ld\n", sib2->ue_TimersAndConstants.t310 );
  LOG_I( RRC, "ue_TimersAndConstants.n310 : %ld\n", sib2->ue_TimersAndConstants.n310 );
  LOG_I( RRC, "ue_TimersAndConstants.t311 : %ld\n", sib2->ue_TimersAndConstants.t311 );
  LOG_I( RRC, "ue_TimersAndConstants.n311 : %ld\n", sib2->ue_TimersAndConstants.n311 );
2860

2861 2862 2863 2864
  if (sib2->freqInfo.ul_CarrierFreq)
    LOG_I( RRC, "freqInfo.ul_CarrierFreq             : %ld\n", *sib2->freqInfo.ul_CarrierFreq );
  else
    LOG_I( RRC, "freqInfo.ul_CarrierFreq             : not defined\n" );
2865

2866 2867 2868 2869
  if (sib2->freqInfo.ul_Bandwidth)
    LOG_I( RRC, "freqInfo.ul_Bandwidth               : %ld\n", *sib2->freqInfo.ul_Bandwidth );
  else
    LOG_I( RRC, "freqInfo.ul_Bandwidth               : not defined\n" );
2870

2871
  LOG_I( RRC, "freqInfo.additionalSpectrumEmission : %ld\n", sib2->freqInfo.additionalSpectrumEmission );
2872

2873 2874 2875 2876 2877
  if (sib2->mbsfn_SubframeConfigList) {
    LOG_I( RRC, "mbsfn_SubframeConfigList : %p\n", sib2->mbsfn_SubframeConfigList );
    // FIXME
  } else
    LOG_I( RRC, "mbsfn_SubframeConfigList : not defined\n" );
2878

2879
  LOG_I( RRC, "timeAlignmentTimerCommon : %ld\n", sib2->timeAlignmentTimerCommon );
2880

2881
#ifdef Rel10
2882

2883 2884 2885 2886 2887
  if (sib2->lateNonCriticalExtension) {
    LOG_I( RRC, "lateNonCriticalExtension : %p\n", sib2->lateNonCriticalExtension );
  } else
    LOG_I( RRC, "lateNonCriticalExtension : not defined\n" );

2888
  if (sib2->ext1 && sib2->ext1->ssac_BarringForMMTEL_Voice_r9) {
2889
    LOG_I( RRC, "ssac_BarringForMMTEL_Voice_r9->ac_BarringFactor       : %ld\n",
2890
           sib2->ext1->ssac_BarringForMMTEL_Voice_r9->ac_BarringFactor );
2891
    LOG_I( RRC, "ssac_BarringForMMTEL_Voice_r9->ac_BarringTime         : %ld\n",
2892
           sib2->ext1->ssac_BarringForMMTEL_Voice_r9->ac_BarringTime );
2893
    LOG_I( RRC, "ssac_BarringForMMTEL_Voice_r9->ac_BarringForSpecialAC : %"PRIu32"\n",
2894
           BIT_STRING_to_uint32(&sib2->ext1->ssac_BarringForMMTEL_Voice_r9->ac_BarringForSpecialAC) );
2895 2896 2897
  } else
    LOG_I( RRC, "ssac_BarringForMMTEL_Voice_r9 : not defined\n" );

2898
  if (sib2->ext1 && sib2->ext1->ssac_BarringForMMTEL_Video_r9) {
2899
    LOG_I( RRC, "ssac_BarringForMMTEL_Video_r9->ac_BarringFactor       : %ld\n",
2900
           sib2->ext1->ssac_BarringForMMTEL_Video_r9->ac_BarringFactor );
2901
    LOG_I( RRC, "ssac_BarringForMMTEL_Video_r9->ac_BarringTime         : %ld\n",
2902
           sib2->ext1->ssac_BarringForMMTEL_Video_r9->ac_BarringTime );
2903
    LOG_I( RRC, "ssac_BarringForMMTEL_Video_r9->ac_BarringForSpecialAC : %"PRIu32"\n",
2904
           BIT_STRING_to_uint32(&sib2->ext1->ssac_BarringForMMTEL_Video_r9->ac_BarringForSpecialAC) );
2905 2906 2907
  } else
    LOG_I( RRC, "ssac_BarringForMMTEL_Video_r9 : not defined\n" );

2908
  if (sib2->ext2 && sib2->ext2->ac_BarringForCSFB_r10) {
2909
    LOG_I( RRC, "ac_BarringForCSFB_r10->ac_BarringFactor       : %ld\n",
2910
           sib2->ext2->ac_BarringForCSFB_r10->ac_BarringFactor );
2911
    LOG_I( RRC, "ac_BarringForCSFB_r10->ac_BarringTime         : %ld\n",
2912
           sib2->ext2->ac_BarringForCSFB_r10->ac_BarringTime );
2913
    LOG_I( RRC, "ac_BarringForCSFB_r10->ac_BarringForSpecialAC : %"PRIu32"\n",
2914
           BIT_STRING_to_uint32(&sib2->ext2->ac_BarringForCSFB_r10->ac_BarringForSpecialAC) );
2915 2916
  } else
    LOG_I( RRC, "ac_BarringForCSFB_r10 : not defined\n" );
2917

2918
#endif
2919 2920
}

2921
//-----------------------------------------------------------------------------
2922
static void dump_sib3( SystemInformationBlockType3_t *sib3 )
2923
{
2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967
  LOG_I( RRC, "Dumping SIB3 (see TS36.331 V8.21.0)\n" );

  int q_Hyst_dB = sib3->cellReselectionInfoCommon.q_Hyst; // sib3->cellReselectionInfoCommon.q_Hyst is a enumerated value

  if (q_Hyst_dB > 6)
    q_Hyst_dB = (q_Hyst_dB-6) * 2 + 6;

  LOG_I( RRC, "cellReselectionInfoCommon.q_Hyst : raw:%ld  decoded:%d dB\n", sib3->cellReselectionInfoCommon.q_Hyst, q_Hyst_dB );

  if (sib3->cellReselectionInfoCommon.speedStateReselectionPars) {
    LOG_I( RRC, "cellReselectionInfoCommon.speedStateReselectionPars->mobilityStateParameters.t_Evaluation : %ld\n",
           sib3->cellReselectionInfoCommon.speedStateReselectionPars->mobilityStateParameters.t_Evaluation );
    LOG_I( RRC, "cellReselectionInfoCommon.speedStateReselectionPars->mobilityStateParameters.t_HystNormal : %ld\n",
           sib3->cellReselectionInfoCommon.speedStateReselectionPars->mobilityStateParameters.t_HystNormal );
    LOG_I( RRC, "cellReselectionInfoCommon.speedStateReselectionPars->mobilityStateParameters.n_CellChangeMedium : %ld\n",
           sib3->cellReselectionInfoCommon.speedStateReselectionPars->mobilityStateParameters.n_CellChangeMedium );
    LOG_I( RRC, "cellReselectionInfoCommon.speedStateReselectionPars->mobilityStateParameters.n_CellChangeHigh : %ld\n",
           sib3->cellReselectionInfoCommon.speedStateReselectionPars->mobilityStateParameters.n_CellChangeHigh );
    int q_HystSF_Medium = 6 - 2 * sib3->cellReselectionInfoCommon.speedStateReselectionPars->q_HystSF.sf_Medium;
    int q_HystSF_High = 6 - 2 * sib3->cellReselectionInfoCommon.speedStateReselectionPars->q_HystSF.sf_High;
    LOG_I( RRC, "cellReselectionInfoCommon.speedStateReselectionPars->q_HystSF.sf_Medium : raw:%ld decoded:%d dB\n", sib3->cellReselectionInfoCommon.speedStateReselectionPars->q_HystSF.sf_Medium,
           q_HystSF_Medium );
    LOG_I( RRC, "cellReselectionInfoCommon.speedStateReselectionPars->q_HystSF.sf_High : raw:%ld decoded:%d dB\n", sib3->cellReselectionInfoCommon.speedStateReselectionPars->q_HystSF.sf_High,
           q_HystSF_High );
  } else {
    LOG_I( RRC, "cellReselectionInfoCommon.speedStateReselectionPars : not defined\n" );
  }

  if (sib3->cellReselectionServingFreqInfo.s_NonIntraSearch) {
    LOG_I( RRC, "cellReselectionServingFreqInfo.s_NonIntraSearch : %ld\n", *(sib3->cellReselectionServingFreqInfo.s_NonIntraSearch) );
  } else {
    LOG_I( RRC, "cellReselectionServingFreqInfo.s_NonIntraSearch : not defined\n" );
  }

  LOG_I( RRC, "cellReselectionServingFreqInfo.threshServingLow : %ld\n", sib3->cellReselectionServingFreqInfo.threshServingLow );
  LOG_I( RRC, "cellReselectionServingFreqInfo.cellReselectionPriority : %ld\n", sib3->cellReselectionServingFreqInfo.cellReselectionPriority );

  LOG_I( RRC, "intraFreqCellReselectionInfo.q_RxLevMin : %ld\n", sib3->intraFreqCellReselectionInfo.q_RxLevMin );

  if (sib3->intraFreqCellReselectionInfo.p_Max) {
    LOG_I( RRC, "intraFreqCellReselectionInfo.p_Max : %ld\n", *(sib3->intraFreqCellReselectionInfo.p_Max) );
  } else {
    LOG_I( RRC, "intraFreqCellReselectionInfo.p_Max : not defined\n" );
  }
2968

2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990
  if (sib3->intraFreqCellReselectionInfo.s_IntraSearch) {
    LOG_I( RRC, "intraFreqCellReselectionInfo.s_IntraSearch : %ld\n", *(sib3->intraFreqCellReselectionInfo.s_IntraSearch) );
  } else {
    LOG_I( RRC, "intraFreqCellReselectionInfo.s_IntraSearch : not defined\n" );
  }

  if (sib3->intraFreqCellReselectionInfo.allowedMeasBandwidth) {
    LOG_I( RRC, "intraFreqCellReselectionInfo.allowedMeasBandwidth : %ld\n", *(sib3->intraFreqCellReselectionInfo.allowedMeasBandwidth) );
  } else {
    LOG_I( RRC, "intraFreqCellReselectionInfo.allowedMeasBandwidth : not defined\n" );
  }

  LOG_I( RRC, "intraFreqCellReselectionInfo.presenceAntennaPort1 : %d\n", sib3->intraFreqCellReselectionInfo.presenceAntennaPort1 );
  LOG_I( RRC, "intraFreqCellReselectionInfo.neighCellConfig : %"PRIu8"\n", BIT_STRING_to_uint8( &(sib3->intraFreqCellReselectionInfo.neighCellConfig) ) );
  LOG_I( RRC, "intraFreqCellReselectionInfo.t_ReselectionEUTRA : %ld\n", sib3->intraFreqCellReselectionInfo.t_ReselectionEUTRA );

  if (sib3->intraFreqCellReselectionInfo.t_ReselectionEUTRA_SF) {
    LOG_I( RRC, "intraFreqCellReselectionInfo.t_ReselectionEUTRA_SF->sf_Medium : %ld\n", sib3->intraFreqCellReselectionInfo.t_ReselectionEUTRA_SF->sf_Medium );
    LOG_I( RRC, "intraFreqCellReselectionInfo.t_ReselectionEUTRA_SF->sf_High : %ld\n", sib3->intraFreqCellReselectionInfo.t_ReselectionEUTRA_SF->sf_High );
  } else {
    LOG_I( RRC, "intraFreqCellReselectionInfo.t_ReselectionEUTRA_SF : not defined\n" );
  }
2991 2992
}

2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030
int Qoffsettab[31] = {-24,-22,-20,-18,-16,-14,-12,-10,-8,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,8,10,12,14,16,18,20,22,24};
int PhysCellIdRange[16] = {4,8,12,16,24,32,48,64,84,96,128,168,252,504,0,0};

uint64_t arfcn_to_freq(long arfcn) {
  
  if (arfcn < 600)  // Band 1
    return((uint64_t)2110000000 + (arfcn*100000));
  else if (arfcn <1200) // Band 2
    return((uint64_t)1930000000 + ((arfcn-600)*100000));
  else if (arfcn <1950) // Band 3
    return((uint64_t)1805000000 + ((arfcn-1200)*100000));
  else if (arfcn <2400) // Band 4
    return((uint64_t)2110000000 + ((arfcn-1950)*100000));
  else if (arfcn <2650) // Band 5
    return((uint64_t)869000000 + ((arfcn-2400)*100000));
  else if (arfcn <2750) // Band 6
    return((uint64_t)875000000 + ((arfcn-2650)*100000));
  else if (arfcn <3450) // Band 7
    return((uint64_t)2620000000 + ((arfcn-2750)*100000));
  else if (arfcn <3800) // Band 8
    return((uint64_t)925000000 + ((arfcn-3450)*100000));
  else if (arfcn <4150) // Band 9
    return((uint64_t)1844900000 + ((arfcn-3800)*100000));
  else if (arfcn <4650) // Band 10
    return((uint64_t)2110000000 + ((arfcn-4150)*100000));
  else if (arfcn <5010) // Band 11
    return((uint64_t)1475900000 + ((arfcn-4750)*100000));
  else if (arfcn <5180) // Band 12
    return((uint64_t)729000000 + ((arfcn-5010)*100000));
  else if (arfcn <5280) // Band 13
    return((uint64_t)746000000 + ((arfcn-5180)*100000));
  else if (arfcn <5730) // Band 14
    return((uint64_t)758000000 + ((arfcn-5280)*100000));
  else if (arfcn <5850) // Band 17
    return((uint64_t)734000000 + ((arfcn-5730)*100000));
  else if (arfcn <6000) // Band 18
    return((uint64_t)860000000 + ((arfcn-5850)*100000));
  else if (arfcn <6150) // Band 19
3031
    return((uint64_t)875000000 + ((arfcn-6000)*100000));
3032
  else if (arfcn <6450) // Band 20
3033
    return((uint64_t)791000000 + ((arfcn-6150)*100000));
3034
  else if (arfcn <6600) // Band 21
3035
    return((uint64_t)1495900000 + ((arfcn-6450)*100000));
3036
  else if (arfcn <7500) // Band 22
3037
    return((uint64_t)351000000 + ((arfcn-6600)*100000));
3038
  else if (arfcn <7700) // Band 23
3039
    return((uint64_t)2180000000 + ((arfcn-7500)*100000));
3040
  else if (arfcn <8040) // Band 24
3041
    return((uint64_t)1525000000 + ((arfcn-7700)*100000));
3042
  else if (arfcn <8690) // Band 25
3043
    return((uint64_t)1930000000 + ((arfcn-8040)*100000));
3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072
  else if (arfcn <36200) // Band 33
    return((uint64_t)1900000000 + ((arfcn-36000)*100000));
  else if (arfcn <36350) // Band 34
    return((uint64_t)2010000000 + ((arfcn-36200)*100000));
  else if (arfcn <36950) // Band 35
    return((uint64_t)1850000000 + ((arfcn-36350)*100000));
  else if (arfcn <37550) // Band 36
    return((uint64_t)1930000000 + ((arfcn-36950)*100000));
  else if (arfcn <37750) // Band 37
    return((uint64_t)1910000000 + ((arfcn-37550)*100000));
  else if (arfcn <38250) // Band 38
    return((uint64_t)2570000000 + ((arfcn-37750)*100000));
  else if (arfcn <38650) // Band 39
    return((uint64_t)1880000000 + ((arfcn-38250)*100000));
  else if (arfcn <39650) // Band 40
    return((uint64_t)2300000000 + ((arfcn-38650)*100000));
  else if (arfcn <41590) // Band 41
    return((uint64_t)2496000000 + ((arfcn-39650)*100000));
  else if (arfcn <43590) // Band 42
    return((uint64_t)3400000000 + ((arfcn-41590)*100000));
  else if (arfcn <45590) // Band 43
    return((uint64_t)3600000000 + ((arfcn-43950)*100000));
  else
    LOG_E(RRC,"Unknown EARFCN %d\n",arfcn);

}
static void dump_sib5( SystemInformationBlockType5_t *sib5 )
{
  InterFreqCarrierFreqList_t interFreqCarrierFreqList = sib5->interFreqCarrierFreqList;
3073
  int i,j;
3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122
  InterFreqCarrierFreqInfo_t *ifcfInfo;

  LOG_I( RRC, "Dumping SIB5 (see TS36.331 V8.21.0)\n" );
  
  for (i=0;i<interFreqCarrierFreqList.list.count;i++) {
    LOG_I(RRC, "SIB5 InterFreqCarrierFreq element %d/%d\n",i,interFreqCarrierFreqList.list.count);
    ifcfInfo = interFreqCarrierFreqList.list.array[i];
    LOG_I(RRC, "   DL Carrier Frequency/ARFCN : %ld/%d\n",
	  arfcn_to_freq(ifcfInfo->dl_CarrierFreq),
	  ifcfInfo->dl_CarrierFreq);
    LOG_I(RRC,"   Q_RXLevMin : %d\n", ifcfInfo->q_RxLevMin);
    LOG_I(RRC,"   P_max : %d\n",ifcfInfo->p_Max);
    LOG_I(RRC,"   T_ReselectionEUTRA : %d\n",ifcfInfo->t_ReselectionEUTRA);
    if (ifcfInfo->t_ReselectionEUTRA_SF) {
      LOG_I(RRC,"   t_ReselectionEUTRA_SF.sf_Medium %d, t_ReselectionEUTRA_SF.sf_High %d",
	    ifcfInfo->t_ReselectionEUTRA_SF->sf_Medium,
	    ifcfInfo->t_ReselectionEUTRA_SF->sf_High);
    }
    LOG_I(RRC,"   threshX_High : %d\n",ifcfInfo->threshX_High);
    LOG_I(RRC,"   threshX_Low : %d\n",ifcfInfo->threshX_Low);
    switch(ifcfInfo->allowedMeasBandwidth) {
    case AllowedMeasBandwidth_mbw6:
      LOG_I(RRC,"   AllowedMeasBandwidth : 6\n");
      break;
    case AllowedMeasBandwidth_mbw15:
      LOG_I(RRC,"   AllowedMeasBandwidth : 15\n");
      break;
    case AllowedMeasBandwidth_mbw25:
      LOG_I(RRC,"   AllowedMeasBandwidth : 25\n");
      break;
    case AllowedMeasBandwidth_mbw50:
      LOG_I(RRC,"   AllowedMeasBandwidth : 50\n");
      break;
    case AllowedMeasBandwidth_mbw75:
      LOG_I(RRC,"   AllowedMeasBandwidth : 75\n");
      break;
    case AllowedMeasBandwidth_mbw100:
      LOG_I(RRC,"   AllowedMeasBandwidth : 100\n");
      break;
    }
    if (ifcfInfo->presenceAntennaPort1)
      LOG_I(RRC,"   PresenceAntennaPort1 : True\n");
    else
      LOG_I(RRC,"   PresenceAntennaPort1 : False\n");
    if (ifcfInfo->cellReselectionPriority) {
      LOG_I(RRC,"   CellReselectionPriority : %d\n",
	    *ifcfInfo->cellReselectionPriority);
    }
    LOG_I(RRC,"   NeighCellConfig  : ");
3123 3124
    for (j=0;j<ifcfInfo->neighCellConfig.size;j++) {
      printf("%2x ",ifcfInfo->neighCellConfig.buf[j]);
3125
    }
3126
    printf("\n");
3127
    if (ifcfInfo->q_OffsetFreq)
3128
      LOG_I(RRC,"   Q_OffsetFreq : %d\n",Qoffsettab[*ifcfInfo->q_OffsetFreq]);
3129 3130
    if (ifcfInfo->interFreqNeighCellList) {
      
3131
      for (j=0;j<ifcfInfo->interFreqNeighCellList->list.count;j++) {
3132
	LOG_I(RRC,"   Cell %d\n");
3133 3134
	LOG_I(RRC,"      PhysCellId : %d\n",ifcfInfo->interFreqNeighCellList->list.array[j]->physCellId);
	LOG_I(RRC,"      Q_OffsetRange : %d\n",ifcfInfo->interFreqNeighCellList->list.array[j]->q_OffsetCell);
3135 3136 3137 3138 3139
	
      }
    }
    if (ifcfInfo->interFreqBlackCellList) {
      
3140
      for (j=0;j<ifcfInfo->interFreqBlackCellList->list.count;j++) {
3141
	LOG_I(RRC,"   Cell %d\n");
3142
	LOG_I(RRC,"      PhysCellId start: %d\n",ifcfInfo->interFreqBlackCellList->list.array[j]->start);
3143
	if (ifcfInfo->interFreqBlackCellList->list.array[i]->range) {
3144
	  LOG_I(RRC,"      PhysCellId Range : %d\n",ifcfInfo->interFreqBlackCellList->list.array[j]->range);
3145 3146 3147
	}
      }
    }
roux's avatar
roux committed
3148
#ifdef Rel10
3149 3150
    if (ifcfInfo->ext1 && ifcfInfo->ext1->q_QualMin_r9)
      LOG_I(RRC,"   Q_QualMin_r9 : %d\n",*ifcfInfo->ext1->q_QualMin_r9);
3151
    
3152 3153 3154
    if (ifcfInfo->ext1 && ifcfInfo->ext1->threshX_Q_r9) {
      LOG_I(RRC,"   threshX_HighQ_r9 : %d\n",ifcfInfo->ext1->threshX_Q_r9->threshX_HighQ_r9);
      LOG_I(RRC,"   threshX_LowQ_r9: %d\n",ifcfInfo->ext1->threshX_Q_r9->threshX_LowQ_r9);
3155
    }
roux's avatar
roux committed
3156
#endif
3157 3158 3159 3160
  }
  
}
  
3161
#ifdef Rel10
3162
static void dump_sib13( SystemInformationBlockType13_r9_t *sib13 )
3163
{
3164 3165 3166 3167 3168
  LOG_I( RRC, "[UE] Dumping SIB13\n" );
  LOG_I( RRC, "[UE] dumping sib13 second time\n" );
  LOG_I( RRC, "[UE] NotificationRepetitionCoeff-r9 : %ld\n", sib13->notificationConfig_r9.notificationRepetitionCoeff_r9 );
  LOG_I( RRC, "[UE] NotificationOffset-r9 : %d\n", (int)sib13->notificationConfig_r9.notificationOffset_r9 );
  LOG_I( RRC, "[UE] NotificationSF-Index-r9 : %d\n", (int)sib13->notificationConfig_r9.notificationSF_Index_r9 );
3169 3170
}
#endif
winckel's avatar
winckel committed
3171

3172
//-----------------------------------------------------------------------------
3173
static int decode_SI( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index )
3174
{
3175

3176
  SystemInformation_t** si = &UE_rrc_inst[ctxt_pP->module_id].si[eNB_index];
3177 3178
  int new_sib = 0;
  SystemInformationBlockType1_t* sib1 = UE_rrc_inst[ctxt_pP->module_id].sib1[eNB_index];
3179

3180
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_UE_DECODE_SI, VCD_FUNCTION_IN );
3181 3182

  // Dump contents
3183 3184 3185
  if ((*si)->criticalExtensions.present == SystemInformation__criticalExtensions_PR_systemInformation_r8) {
    LOG_D( RRC, "[UE] (*si)->criticalExtensions.choice.systemInformation_r8.sib_TypeAndInfo.list.count %d\n",
           (*si)->criticalExtensions.choice.systemInformation_r8.sib_TypeAndInfo.list.count );
3186
  } else {
3187
    LOG_D( RRC, "[UE] Unknown criticalExtension version (not Rel8)\n" );
3188
    return -1;
3189 3190
  }

3191 3192 3193 3194
  for (int i=0; i<(*si)->criticalExtensions.choice.systemInformation_r8.sib_TypeAndInfo.list.count; i++) {
    LOG_D( RRC, "SI count %d\n", i );
    struct SystemInformation_r8_IEs__sib_TypeAndInfo__Member *typeandinfo;
    typeandinfo = (*si)->criticalExtensions.choice.systemInformation_r8.sib_TypeAndInfo.list.array[i];
3195

3196 3197
    switch(typeandinfo->present) {
    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib2:
3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208
      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&2) == 0) {
	UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=2;
	new_sib=1;
	memcpy( UE_rrc_inst[ctxt_pP->module_id].sib2[eNB_index], &typeandinfo->choice.sib2, sizeof(SystemInformationBlockType2_t) );
	LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB2 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
	dump_sib2( UE_rrc_inst[ctxt_pP->module_id].sib2[eNB_index] );
	LOG_I( RRC, "[FRAME %05"PRIu32"][RRC_UE][MOD %02"PRIu8"][][--- MAC_CONFIG_REQ (SIB2 params  eNB %"PRIu8") --->][MAC_UE][MOD %02"PRIu8"][]\n",
	       ctxt_pP->frame, ctxt_pP->module_id, eNB_index, ctxt_pP->module_id );
	rrc_mac_config_req(ctxt_pP->module_id, 0, ENB_FLAG_NO, 0, eNB_index,
			   &UE_rrc_inst[ctxt_pP->module_id].sib2[eNB_index]->radioResourceConfigCommon,
			   (struct PhysicalConfigDedicated *)NULL,
3209
#ifdef Rel10
3210
			   (SCellToAddMod_r10_t *)NULL,
3211
#endif
3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224
			   (MeasObjectToAddMod_t **)NULL,
			   (MAC_MainConfig_t *)NULL,
			   0,
			   (struct LogicalChannelConfig *)NULL,
			   (MeasGapConfig_t *)NULL,
			   (TDD_Config_t *)NULL,
			   (MobilityControlInfo_t *)NULL,
			   NULL,
			   NULL,
			   UE_rrc_inst[ctxt_pP->module_id].sib2[eNB_index]->freqInfo.ul_CarrierFreq,
			   UE_rrc_inst[ctxt_pP->module_id].sib2[eNB_index]->freqInfo.ul_Bandwidth,
			   &UE_rrc_inst[ctxt_pP->module_id].sib2[eNB_index]->freqInfo.additionalSpectrumEmission,
			   UE_rrc_inst[ctxt_pP->module_id].sib2[eNB_index]->mbsfn_SubframeConfigList
winckel's avatar
winckel committed
3225
#ifdef Rel10
3226 3227 3228
			   ,0,
			   (MBSFN_AreaInfoList_r9_t *)NULL,
			   (PMCH_InfoList_r9_t *)NULL
3229 3230
#endif
#ifdef CBA
3231 3232
			   ,0,
			   0
3233
#endif
3234 3235
			   );
	// After SI is received, prepare RRCConnectionRequest
3236
#ifdef Rel10
3237

3238
	if (UE_rrc_inst[ctxt_pP->module_id].MBMS_flag < 3) // see -Q option
3239
#endif
winckel's avatar
winckel committed
3240
#if !(defined(ENABLE_ITTI) && defined(ENABLE_USE_MME))
3241 3242
	  rrc_ue_generate_RRCConnectionRequest( ctxt_pP, eNB_index );
	
winckel's avatar
winckel committed
3243
#endif
3244 3245 3246 3247
	
	if (UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].State == RRC_IDLE) {
	  LOG_I( RRC, "[UE %d] Received SIB1/SIB2/SIB3 Switching to RRC_SI_RECEIVED\n", ctxt_pP->module_id );
	  UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].State = RRC_SI_RECEIVED;
3248
#if ENABLE_RAL
3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269
	  {
	    MessageDef                            *message_ral_p = NULL;
	    rrc_ral_system_information_ind_t       ral_si_ind;
	    
	    message_ral_p = itti_alloc_new_message (TASK_RRC_UE, RRC_RAL_SYSTEM_INFORMATION_IND);
	    memset(&ral_si_ind, 0, sizeof(rrc_ral_system_information_ind_t));
	    ral_si_ind.plmn_id.MCCdigit2 = '0';
	    ral_si_ind.plmn_id.MCCdigit1 = '2';
	    ral_si_ind.plmn_id.MNCdigit3 = '0';
	    ral_si_ind.plmn_id.MCCdigit3 = '8';
	    ral_si_ind.plmn_id.MNCdigit2 = '9';
	    ral_si_ind.plmn_id.MNCdigit1 = '9';
	    ral_si_ind.cell_id        = 1;
	    ral_si_ind.dbm            = 0;
	    //ral_si_ind.dbm            = fifo_dump_emos_UE.PHY_measurements->rx_rssi_dBm[eNB_index];
	    // TO DO
	    ral_si_ind.sinr           = 0;
	    //ral_si_ind.sinr           = fifo_dump_emos_UE.PHY_measurements->subband_cqi_dB[eNB_index][phy_vars_ue->lte_frame_parms.nb_antennas_rx][0];
	    // TO DO
	    ral_si_ind.link_data_rate = 0;
	    memcpy (&message_ral_p->ittiMsg, (void *) &ral_si_ind, sizeof(rrc_ral_system_information_ind_t));
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3270
#warning "ue_mod_idP ? for instance ?"
3271 3272
	    itti_send_msg_to_task (TASK_RAL_UE, UE_MODULE_ID_TO_INSTANCE(ctxt_pP->module_id), message_ral_p);
	  }
3273
#endif
3274
	}
3275
      }
3276
      break; // case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib2
3277 3278

    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib3:
3279 3280 3281 3282 3283 3284 3285 3286
      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&4) == 0) {
	UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=4;
	new_sib=1;
	memcpy( UE_rrc_inst[ctxt_pP->module_id].sib3[eNB_index], &typeandinfo->choice.sib3, sizeof(SystemInformationBlockType3_t) );
	LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB3 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
	dump_sib3( UE_rrc_inst[ctxt_pP->module_id].sib3[eNB_index] );

      }
3287 3288 3289
      break;

    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib4:
3290 3291 3292 3293 3294 3295 3296
      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&8) == 0) {
	UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=8;
	new_sib=1;
	memcpy( UE_rrc_inst[ctxt_pP->module_id].sib4[eNB_index], &typeandinfo->choice.sib4, sizeof(SystemInformationBlockType4_t) );
	LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB4 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
      }

3297 3298 3299
      break;

    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib5:
3300 3301 3302 3303 3304 3305
      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&16) == 0) {
	UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=16;
	new_sib=1;
     
	memcpy( UE_rrc_inst[ctxt_pP->module_id].sib5[eNB_index], &typeandinfo->choice.sib5, sizeof(SystemInformationBlockType5_t) );
	LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB5 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
3306
	dump_sib5(UE_rrc_inst[ctxt_pP->module_id].sib5[eNB_index]);
3307
      }
3308 3309 3310
      break;

    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib6:
3311 3312 3313 3314 3315 3316 3317
      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&32) == 0) {
	UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=32;
	new_sib=1;
     
	memcpy( UE_rrc_inst[ctxt_pP->module_id].sib6[eNB_index], &typeandinfo->choice.sib6, sizeof(SystemInformationBlockType6_t) );
	LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB6 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
      }
3318 3319 3320
      break;

    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib7:
3321 3322 3323 3324 3325 3326
      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&64) == 0) {
	UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=64;
	new_sib=1;
	memcpy( UE_rrc_inst[ctxt_pP->module_id].sib7[eNB_index], &typeandinfo->choice.sib7, sizeof(SystemInformationBlockType7_t) );
	LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB7 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
      }
3327 3328 3329
      break;

    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib8:
3330 3331 3332 3333 3334 3335
      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&128) == 0) {
	UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=128;
	new_sib=1;
	memcpy( UE_rrc_inst[ctxt_pP->module_id].sib8[eNB_index], &typeandinfo->choice.sib8, sizeof(SystemInformationBlockType8_t) );
	LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB8 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
      }
3336 3337 3338
      break;

    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib9:
3339 3340 3341 3342 3343 3344 3345
      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&256) == 0) {
	UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=256;
	new_sib=1;
      
	memcpy( UE_rrc_inst[ctxt_pP->module_id].sib9[eNB_index], &typeandinfo->choice.sib9, sizeof(SystemInformationBlockType9_t) );
	LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB9 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
      }
3346 3347 3348
      break;

    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib10:
3349 3350 3351 3352 3353 3354
      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&512) == 0) {
	UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=512;
	new_sib=1;
	memcpy( UE_rrc_inst[ctxt_pP->module_id].sib10[eNB_index], &typeandinfo->choice.sib10, sizeof(SystemInformationBlockType10_t) );
	LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB10 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
      }
3355 3356 3357
      break;

    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib11:
3358 3359 3360 3361 3362 3363 3364
      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&1024) == 0) {
	UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=1024;
	new_sib=1;

	memcpy( UE_rrc_inst[ctxt_pP->module_id].sib11[eNB_index], &typeandinfo->choice.sib11, sizeof(SystemInformationBlockType11_t) );
	LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB11 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
      }
3365
      break;
3366

3367
#ifdef Rel10
3368 3369

    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib12_v920:
3370 3371 3372 3373 3374 3375
      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&2048) == 0) {
	UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=2048;
	new_sib=1;
	memcpy( UE_rrc_inst[ctxt_pP->module_id].sib12[eNB_index], &typeandinfo->choice.sib12_v920, sizeof(SystemInformationBlockType12_r9_t) );
	LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB12 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
      }
3376
      break;
3377
	
3378
    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib13_v920:
3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408
      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&4096) == 0) {
	UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=4096;
	new_sib=1;
	
	memcpy( UE_rrc_inst[ctxt_pP->module_id].sib13[eNB_index], &typeandinfo->choice.sib13_v920, sizeof(SystemInformationBlockType13_r9_t) );
	LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB13 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
	dump_sib13( UE_rrc_inst[ctxt_pP->module_id].sib13[eNB_index] );
	// adding here function to store necessary parameters for using in decode_MCCH_Message + maybe transfer to PHY layer
	LOG_D( RRC, "[FRAME %05"PRIu32"][RRC_UE][MOD %02"PRIu8"][][--- MAC_CONFIG_REQ (SIB13 params eNB %"PRIu8") --->][MAC_UE][MOD %02"PRIu8"][]\n",
	       ctxt_pP->frame, ctxt_pP->module_id, eNB_index, ctxt_pP->module_id);
	rrc_mac_config_req(ctxt_pP->module_id,0,ENB_FLAG_NO,0,eNB_index,
			   (RadioResourceConfigCommonSIB_t *)NULL,
			   (struct PhysicalConfigDedicated *)NULL,
			   (SCellToAddMod_r10_t *)NULL,
			   (MeasObjectToAddMod_t **)NULL,
			   (MAC_MainConfig_t *)NULL,
			   0,
			   (struct LogicalChannelConfig *)NULL,
			   (MeasGapConfig_t *)NULL,
			   (TDD_Config_t *)NULL,
			   (MobilityControlInfo_t *)NULL,
			   NULL,
			   NULL,
			   NULL,
			   NULL,
			   NULL,
			   (MBSFN_SubframeConfigList_t *)NULL,
			   0,
			   &UE_rrc_inst[ctxt_pP->module_id].sib13[eNB_index]->mbsfn_AreaInfoList_r9,
			   (PMCH_InfoList_r9_t *)NULL
3409
#ifdef CBA
3410 3411
			   ,0,
			   0
3412
#endif
3413 3414 3415
			   );
	break;
      }
3416
#endif
3417 3418 3419
    default:
      break;
    }
3420 3421

  }
3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432
  if (new_sib == 1) {
    UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIcnt++;

    if (UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIcnt == sib1->schedulingInfoList.list.count)
      rrc_set_sub_state( ctxt_pP->module_id, RRC_SUB_STATE_IDLE_SIB_COMPLETE );

    LOG_I(RRC,"SIStatus %x, SIcnt %d/%d\n", 
	  UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus,
	  UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIcnt,
	  sib1->schedulingInfoList.list.count);
  }
3433

3434
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_UE_DECODE_SI  , VCD_FUNCTION_OUT);
3435 3436 3437
  return 0;
}

3438
// layer 3 filtering of RSRP (EUTRA) measurements: 36.331, Sec. 5.5.3.2
3439
//-----------------------------------------------------------------------------
3440
void ue_meas_filtering( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index )
3441
{
3442 3443
  float a;
  float a1;
3444
  //float rsrp_db, rsrq_db;
3445
  uint8_t    eNB_offset;
3446

3447 3448 3449 3450 3451 3452
  if(!((a=get_rsrp_filter_coeff(ctxt_pP->module_id))>=0))
	  a  = UE_rrc_inst[ctxt_pP->module_id].filter_coeff_rsrp; // 'a' in 36.331 Sec. 5.5.3.2

  if(!((a1=get_rsrq_filter_coeff(ctxt_pP->module_id))>=0))
	  a1 = UE_rrc_inst[ctxt_pP->module_id].filter_coeff_rsrq;

3453 3454 3455 3456
  if(UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[0] != NULL) { // Only consider 1 serving cell (index: 0)
    if (UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[0]->quantityConfigEUTRA != NULL) {
      if(UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[0]->quantityConfigEUTRA->filterCoefficientRSRP != NULL) {
        for (eNB_offset = 0; eNB_offset<1+mac_xface->get_n_adj_cells(ctxt_pP->module_id,0); eNB_offset++) {
3457 3458 3459
          //filter_factor = 1/power(2,*UE_rrc_inst[ue_mod_idP].QuantityConfig[0]->quantityConfigEUTRA->filterCoefficientRSRP/4);
          // LOG_N(RRC,"[UE %d] Frame %d : check proper operation in abstraction mode rsrp (%d), rx gain (%d) N_RB_DL (%d)\n",
          //  ue_mod_idP,frameP,mac_xface->get_RSRP(ue_mod_idP,0,eNB_offset),mac_xface->get_rx_total_gain_dB(ue_mod_idP,0),mac_xface->lte_frame_parms->N_RB_DL);
3460 3461 3462 3463 3464 3465 3466
          UE_rrc_inst[ctxt_pP->module_id].rsrp_db[eNB_offset] =
            (dB_fixed_times10(mac_xface->get_RSRP(ctxt_pP->module_id,0,eNB_offset))/10.0) -
            mac_xface->get_rx_total_gain_dB(ctxt_pP->module_id,0) -
            dB_fixed(mac_xface->lte_frame_parms->N_RB_DL*12);
          UE_rrc_inst[ctxt_pP->module_id].rsrp_db_filtered[eNB_offset] =
            (1.0-a)*UE_rrc_inst[ctxt_pP->module_id].rsrp_db_filtered[eNB_offset] +
            a*UE_rrc_inst[ctxt_pP->module_id].rsrp_db[eNB_offset];
3467 3468 3469 3470 3471
          //mac_xface->set_RSRP_filtered(ue_mod_idP,eNB_offset,UE_rrc_inst[ue_mod_idP].rsrp_db_filtered[eNB_offset]);


          //LOG_D(RRC,"RSRP_total_dB: %3.2f \n",(dB_fixed_times10(mac_xface->get_RSRP(ue_mod_idP,0,eNB_offset))/10.0)-mac_xface->get_rx_total_gain_dB(ue_mod_idP,0)-dB_fixed(mac_xface->lte_frame_parms->N_RB_DL*12));

3472 3473
          LOG_D(RRC,"RSRP_dBm: %3.2f \n",(dB_fixed_times10(mac_xface->get_RSRP(ctxt_pP->module_id,0,eNB_offset))/10.0));
          LOG_D(RRC,"gain_loss_dB: %d \n",mac_xface->get_rx_total_gain_dB(ctxt_pP->module_id,0));
3474 3475
          LOG_D(RRC,"gain_fixed_dB: %d \n",dB_fixed(mac_xface->lte_frame_parms->N_RB_DL*12));
          LOG_D(PHY,"[UE %d] Frame %d, RRC Measurements => rssi %3.1f dBm (digital: %3.1f dB)\n",
3476 3477 3478 3479
                ctxt_pP->module_id,
                ctxt_pP->frame,
                10*log10(mac_xface->get_RSSI(ctxt_pP->module_id,0))-mac_xface->get_rx_total_gain_dB(ctxt_pP->module_id,0),
                10*log10(mac_xface->get_RSSI(ctxt_pP->module_id,0)));
3480
          LOG_D(RRC,"[UE %d] Frame %d: Meas RSRP: eNB_offset: %d rsrp_coef: %3.1f filter_coef: %d before L3 filtering: rsrp: %3.1f after L3 filtering: rsrp: %3.1f \n ",
3481 3482
                ctxt_pP->module_id,
                ctxt_pP->frame, eNB_offset,a,
3483
                *UE_rrc_inst->QuantityConfig[0]->quantityConfigEUTRA->filterCoefficientRSRP,
3484 3485
                UE_rrc_inst[ctxt_pP->module_id].rsrp_db[eNB_offset],
                UE_rrc_inst[ctxt_pP->module_id].rsrp_db_filtered[eNB_offset]);
3486
        }
3487
      }
3488
    } else {
3489 3490
      for (eNB_offset = 0; eNB_offset<1+mac_xface->get_n_adj_cells(ctxt_pP->module_id,0); eNB_offset++) {
        UE_rrc_inst[ctxt_pP->module_id].rsrp_db_filtered[eNB_offset]= mac_xface->get_RSRP(ctxt_pP->module_id,0,eNB_offset);
3491 3492
        // phy_vars_ue->PHY_measurements.rsrp_filtered[eNB_offset]=UE_rrc_inst[ue_mod_idP].rsrp_db_filtered[eNB_offset];
        //mac_xface->set_RSRP_filtered(ue_mod_idP,eNB_offset,UE_rrc_inst[ue_mod_idP].rsrp_db_filtered[eNB_offset]);
3493
      }
3494 3495
    }

3496 3497 3498
    if (UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[0]->quantityConfigEUTRA != NULL) {
      if(UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[0]->quantityConfigEUTRA->filterCoefficientRSRQ != NULL) {
        for (eNB_offset = 0; eNB_offset<1+mac_xface->get_n_adj_cells(ctxt_pP->module_id,0); eNB_offset++) {
3499
          // LOG_N(RRC,"[UE %d] Frame %d : check if this operation workes properly in abstraction mode\n",ue_mod_idP,frameP);
3500 3501 3502
          UE_rrc_inst[ctxt_pP->module_id].rsrq_db[eNB_offset] = (10*log10(mac_xface->get_RSRQ(ctxt_pP->module_id,0,eNB_offset)))-20;
          UE_rrc_inst[ctxt_pP->module_id].rsrq_db_filtered[eNB_offset]=(1-a1)*UE_rrc_inst[ctxt_pP->module_id].rsrq_db_filtered[eNB_offset] +
              a1 *UE_rrc_inst[ctxt_pP->module_id].rsrq_db[eNB_offset];
3503 3504
          //mac_xface->set_RSRP_filtered(ue_mod_idP,eNB_offset,UE_rrc_inst[ue_mod_idP].rsrp_db_filtered[eNB_offset]);
          /*
3505
          LOG_D(RRC,"[UE %d] Frame %d: Meas RSRQ: eNB_offset: %d rsrq_coef: %3.2f filter_coef: %d before L3 filtering: rsrq: %3.1f after L3 filtering: rsrq: %3.1f \n ",
3506 3507 3508 3509 3510 3511 3512
          ue_mod_idP,frameP,eNB_offset,a1,
           *UE_rrc_inst->QuantityConfig[0]->quantityConfigEUTRA->filterCoefficientRSRQ,
          mac_xface->get_RSRQ(ue_mod_idP,0,eNB_offset),
          UE_rrc_inst[ue_mod_idP].rsrq_db[eNB_offset],
          UE_rrc_inst[ue_mod_idP].rsrq_db_filtered[eNB_offset]);
           */
        }
3513
      }
3514
    } else {
3515 3516
      for (eNB_offset = 0; eNB_offset<1+mac_xface->get_n_adj_cells(ctxt_pP->module_id,0); eNB_offset++) {
        UE_rrc_inst[ctxt_pP->module_id].rsrq_db_filtered[eNB_offset]= mac_xface->get_RSRQ(ctxt_pP->module_id,0,eNB_offset);
3517
      }
3518
    }
3519 3520 3521
  }
}

3522
//Below routine implements Measurement Reporting procedure from 36.331 Section 5.5.5
3523
//-----------------------------------------------------------------------------
3524
static void rrc_ue_generate_MeasurementReport( const protocol_ctxt_t* const ctxt_pP, uint8_t eNB_index )
3525
{
3526 3527 3528 3529 3530 3531

  uint8_t             buffer[32], size;
  uint8_t             i;
  uint8_t             target_eNB_offset;
  MeasId_t         measId;
  PhysCellId_t     cellId, targetCellId;
3532 3533 3534
  long             rsrp_t,rsrq_t;
  long             rsrp_s,rsrq_s;
  long             nElem, nElem1;
3535 3536 3537
  float            rsrp_filtered, rsrq_filtered;
  static frame_t   pframe=0;
  int              result;
3538 3539 3540

  nElem = 98;
  nElem1 = 35;
3541
  target_eNB_offset = UE_rrc_inst[ctxt_pP->module_id].Info[0].handoverTarget; // eNB_offset of target eNB: used to obtain the mod_id of target eNB
3542

3543
  for (i=0; i<MAX_MEAS_ID; i++) {
3544 3545
    if (UE_rrc_inst[ctxt_pP->module_id].measReportList[0][i] != NULL) {
      measId = UE_rrc_inst[ctxt_pP->module_id].measReportList[0][i]->measId;
3546 3547

      // Note: Values in the meas report have to be the mapped values...to implement binary search for LUT
3548
      rsrp_filtered = UE_rrc_inst[ctxt_pP->module_id].rsrp_db_filtered[eNB_index];//nid_cell];
3549 3550
      rsrp_s = binary_search_float(RSRP_meas_mapping,nElem, rsrp_filtered);

3551
      rsrq_filtered = UE_rrc_inst[ctxt_pP->module_id].rsrq_db_filtered[eNB_index];//nid_cell]; //RSRQ of serving cell
3552 3553 3554
      rsrq_s = binary_search_float(RSRQ_meas_mapping,nElem1,rsrq_filtered);//mapped RSRQ of serving cell

      LOG_D(RRC,"[UE %d] Frame %d: source eNB %d :rsrp_s: %ld rsrq_s: %ld rsrp_filtered: %f rsrq_filtered: %f \n",
3555 3556 3557 3558 3559 3560 3561 3562 3563
            ctxt_pP->module_id,
            ctxt_pP->frame,
            eNB_index,
            rsrp_s,
            rsrq_s,
            rsrp_filtered,
            rsrq_filtered);
      rsrp_t = binary_search_float(RSRP_meas_mapping,nElem,UE_rrc_inst[ctxt_pP->module_id].rsrp_db_filtered[target_eNB_offset]); //RSRP of target cell
      rsrq_t = binary_search_float(RSRQ_meas_mapping,nElem1,UE_rrc_inst[ctxt_pP->module_id].rsrq_db_filtered[target_eNB_offset]); //RSRQ of target cell
3564 3565

      LOG_D(RRC,"[UE %d] Frame %d: target eNB %d :rsrp_t: %ld rsrq_t: %ld rsrp_filtered: %f rsrq_filtered: %f \n",
3566 3567 3568 3569 3570 3571 3572
            ctxt_pP->module_id,
            ctxt_pP->frame,
            target_eNB_offset,
            rsrp_t,
            rsrq_t,
            UE_rrc_inst[ctxt_pP->module_id].rsrp_db_filtered[target_eNB_offset],
            UE_rrc_inst[ctxt_pP->module_id].rsrq_db_filtered[target_eNB_offset]);
3573 3574

      //  if (measFlag == 1) {
Navid Nikaein's avatar
Navid Nikaein committed
3575
      cellId = eNB_index; //get_adjacent_cell_id(ctxt_pP->module_id, eNB_index); //PhycellId of serving cell
3576
      targetCellId = UE_rrc_inst[ctxt_pP->module_id].HandoverInfoUe.targetCellId ;//get_adjacent_cell_id(ue_mod_idP,target_eNB_offset); //PhycellId of target cell
3577

3578 3579
      if (pframe!=ctxt_pP->frame) {
        pframe=ctxt_pP->frame;
3580
        LOG_D(RRC, "[UE %d] Frame %d: doing MeasReport: servingCell(%d) targetCell(%d) rsrp_s(%ld) rsrq_s(%ld) rsrp_t(%ld) rsrq_t(%ld) \n",
3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592
              ctxt_pP->module_id,
              ctxt_pP->frame,
              cellId,
              targetCellId,
              rsrp_s,
              rsrq_s,
              rsrp_t,
              rsrq_t);
        size = do_MeasurementReport(ctxt_pP->module_id, buffer,measId,targetCellId,rsrp_s,rsrq_s,rsrp_t,rsrq_t);
        LOG_I(RRC, "[UE %d] Frame %d : Generating Measurement Report for eNB %d\n",
              ctxt_pP->module_id, ctxt_pP->frame, eNB_index);
        result = pdcp_data_req(ctxt_pP,  SRB_FLAG_YES, DCCH, rrc_mui++, 0, size, buffer, PDCP_TRANSMISSION_MODE_DATA);
3593 3594
        AssertFatal (result == TRUE, "PDCP data request failed!\n");
        //LOG_D(RRC, "[UE %d] Frame %d Sending MeasReport (%d bytes) through DCCH%d to PDCP \n",ue_mod_idP,frameP, size, DCCH);
3595
      }
3596 3597 3598 3599

      //          measFlag = 0; //re-setting measFlag so that no more MeasReports are sent in this frameP
      //          }
    }
3600 3601 3602
  }
}

3603
// Measurement report triggering, described in 36.331 Section 5.5.4.1: called periodically
3604
//-----------------------------------------------------------------------------
3605
void ue_measurement_report_triggering( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index )
3606
{
3607
  uint8_t               i,j;
3608 3609 3610 3611
  Hysteresis_t     hys;
  TimeToTrigger_t  ttt_ms;
  Q_OffsetRange_t  ofn;
  Q_OffsetRange_t  ocn;
3612 3613
  Q_OffsetRange_t  ofs;
  Q_OffsetRange_t  ocs;
3614 3615
  long             a3_offset;
  MeasObjectId_t   measObjId;
3616
  ReportConfigId_t reportConfigId;
3617

3618
  for(i=0 ; i<NB_CNX_UE ; i++) {
3619
    for(j=0 ; j<MAX_MEAS_ID ; j++) {
3620 3621 3622
      if(UE_rrc_inst[ctxt_pP->module_id].MeasId[i][j] != NULL) {
        measObjId = UE_rrc_inst[ctxt_pP->module_id].MeasId[i][j]->measObjectId;
        reportConfigId = UE_rrc_inst[ctxt_pP->module_id].MeasId[i][j]->reportConfigId;
3623

3624 3625
        if( /*UE_rrc_inst[ctxt_pP->module_id].MeasId[i][j] != NULL && */ UE_rrc_inst[ctxt_pP->module_id].MeasObj[i][measObjId-1] != NULL) {
          if(UE_rrc_inst[ctxt_pP->module_id].MeasObj[i][measObjId-1]->measObject.present == MeasObjectToAddMod__measObject_PR_measObjectEUTRA) {
3626 3627 3628
            /* consider any neighboring cell detected on the associated frequency to be
             * applicable when the concerned cell is not included in the blackCellsToAddModList
             * defined within the VarMeasConfig for this measId */
3629 3630 3631 3632 3633
            //    LOG_I(RRC,"event %d %d %p \n", measObjId,reportConfigId, UE_rrc_inst[ctxt_pP->module_id].ReportConfig[i][reportConfigId-1]);
            if((UE_rrc_inst[ctxt_pP->module_id].ReportConfig[i][reportConfigId-1] != NULL) &&
                (UE_rrc_inst[ctxt_pP->module_id].ReportConfig[i][reportConfigId-1]->reportConfig.present==ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA) &&
                (UE_rrc_inst[ctxt_pP->module_id].ReportConfig[i][reportConfigId-1]->reportConfig.choice.reportConfigEUTRA.triggerType.present ==
                 ReportConfigEUTRA__triggerType_PR_event)) {
alexandr's avatar
alexandr committed
3634 3635 3636
              if(!((hys=get_hys(ctxt_pP->module_id))>=0))
            	  hys = UE_rrc_inst[ctxt_pP->module_id].ReportConfig[i][reportConfigId-1]->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.hysteresis;
              //LOG_D(RRC,"Hysteresis for eNB %d is set to %ld\n",ctxt_pP->module_id,hys);
3637
              //LOG_N(RRC,"[UE%d] Frame %d Check below lines for segfault :), Fix me \n",ctxt_pP->module_id, frameP);
alexandr's avatar
alexandr committed
3638 3639 3640
              if(!((ttt_ms=get_ttt_ms(ctxt_pP->module_id))>=0))
            	  ttt_ms = timeToTrigger_ms[UE_rrc_inst[ctxt_pP->module_id].ReportConfig[i][reportConfigId-1]->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.timeToTrigger];
              //LOG_D(RRC,"Time to trigger for eNB %d is set to %d\n",ctxt_pP->module_id,ttt_ms);
3641
              // Freq specific offset of neighbor cell freq
alexandr's avatar
alexandr committed
3642 3643 3644 3645 3646
              if(!((ofn=get_ofn(ctxt_pP->module_id))>=0))
            	  ofn=5;
              //LOG_D(RRC,"OFN for eNB %d is set to %d\n",ctxt_pP->module_id,ofn);
              //((UE_rrc_inst[ctxt_pP->module_id].MeasObj[i][measObjId-1]->measObject.choice.measObjectEUTRA.offsetFreq != NULL) ?

3647
              // *UE_rrc_inst[ctxt_pP->module_id].MeasObj[i][measObjId-1]->measObject.choice.measObjectEUTRA.offsetFreq : 15); //  /* 15 is the Default */
3648
              // cellIndividualOffset of neighbor cell - not defined yet
3649 3650 3651 3652 3653 3654 3655 3656
              if(!((ocn=get_ocn(ctxt_pP->module_id))>=0))
            	  ocn = 0;
              if(!((ofs=get_ofs(ctxt_pP->module_id))>=0))
            	  ofs = 0;
              if(!((ocs=get_ocs(ctxt_pP->module_id))>=0))
            	  ocs = 0;
              if(!((a3_offset=get_off(ctxt_pP->module_id))>=0))
            	  a3_offset = UE_rrc_inst[ctxt_pP->module_id].ReportConfig[i][reportConfigId-1]->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA3.a3_Offset;
3657

3658
              switch (UE_rrc_inst[ctxt_pP->module_id].ReportConfig[i][reportConfigId-1]->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present) {
3659
              case ReportConfigEUTRA__triggerType__event__eventId_PR_eventA1:
3660 3661
                LOG_D(RRC,"[UE %d] Frame %d : A1 event: check if serving becomes better than threshold\n",
                      ctxt_pP->module_id, ctxt_pP->frame);
3662 3663 3664
                break;

              case ReportConfigEUTRA__triggerType__event__eventId_PR_eventA2:
3665 3666
                LOG_D(RRC,"[UE %d] Frame %d : A2 event, check if serving becomes worse than a threshold\n",
                      ctxt_pP->module_id, ctxt_pP->frame);
3667 3668 3669
                break;

              case ReportConfigEUTRA__triggerType__event__eventId_PR_eventA3:
3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680
                LOG_D(RRC,"[UE %d] Frame %d : A3 event: check if a neighboring cell becomes offset better than serving to trigger a measurement event \n",
                      ctxt_pP->module_id, ctxt_pP->frame);

                if ((check_trigger_meas_event(
                       ctxt_pP->module_id,
                       ctxt_pP->frame,
                       eNB_index,
                       i,j,ofn,ocn,hys,ofs,ocs,a3_offset,ttt_ms)) &&
                    (UE_rrc_inst[ctxt_pP->module_id].Info[0].State >= RRC_CONNECTED) &&
                    (UE_rrc_inst[ctxt_pP->module_id].Info[0].T304_active == 0 )      &&
                    (UE_rrc_inst[ctxt_pP->module_id].HandoverInfoUe.measFlag == 1)) {
3681
                  //trigger measurement reporting procedure (36.331, section 5.5.5)
3682 3683
                  if (UE_rrc_inst[ctxt_pP->module_id].measReportList[i][j] == NULL) {
                    UE_rrc_inst[ctxt_pP->module_id].measReportList[i][j] = malloc(sizeof(MEAS_REPORT_LIST));
3684 3685
                  }

3686 3687 3688 3689 3690 3691 3692 3693
                  UE_rrc_inst[ctxt_pP->module_id].measReportList[i][j]->measId = UE_rrc_inst[ctxt_pP->module_id].MeasId[i][j]->measId;
                  UE_rrc_inst[ctxt_pP->module_id].measReportList[i][j]->numberOfReportsSent = 0;
                  rrc_ue_generate_MeasurementReport(
                    ctxt_pP,
                    eNB_index);
                  UE_rrc_inst[ctxt_pP->module_id].HandoverInfoUe.measFlag = 1;
                  LOG_I(RRC,"[UE %d] Frame %d: A3 event detected, state: %d \n",
                        ctxt_pP->module_id, ctxt_pP->frame, UE_rrc_inst[ctxt_pP->module_id].Info[0].State);
3694
                } else {
3695 3696
                  if(UE_rrc_inst[ctxt_pP->module_id].measReportList[i][j] != NULL) {
                    free(UE_rrc_inst[ctxt_pP->module_id].measReportList[i][j]);
3697
                  }
3698

3699
                  UE_rrc_inst[ctxt_pP->module_id].measReportList[i][j] = NULL;
3700 3701 3702 3703 3704
                }

                break;

              case ReportConfigEUTRA__triggerType__event__eventId_PR_eventA4:
3705 3706
                LOG_D(RRC,"[UE %d] Frame %d : received an A4 event, neighbor becomes offset better than a threshold\n",
                      ctxt_pP->module_id, ctxt_pP->frame);
3707 3708 3709
                break;

              case ReportConfigEUTRA__triggerType__event__eventId_PR_eventA5:
3710 3711
                LOG_D(RRC,"[UE %d] Frame %d: received an A5 event, serving becomes worse than threshold 1 and neighbor becomes better than threshold 2\n",
                      ctxt_pP->module_id, ctxt_pP->frame);
3712 3713 3714 3715
                break;

              default:
                LOG_D(RRC,"Invalid ReportConfigEUTRA__triggerType__event__eventId: %d",
3716
                      UE_rrc_inst[ctxt_pP->module_id].ReportConfig[i][j]->reportConfig.choice.reportConfigEUTRA.triggerType.present);
3717
                break;
winckel's avatar
winckel committed
3718
              }
3719
            }
winckel's avatar
winckel committed
3720
          }
3721
        }
3722
      }
3723
    }
3724 3725 3726
  }
}

Lionel Gauthier's avatar
 
Lionel Gauthier committed
3727
//check_trigger_meas_event(ue_mod_idP, frameP, eNB_index, i,j,ofn,ocn,hys,ofs,ocs,a3_offset,ttt_ms)
3728
//-----------------------------------------------------------------------------
3729
static uint8_t check_trigger_meas_event(
3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740
  module_id_t     ue_mod_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,
3741
  TimeToTrigger_t ttt )
Lionel Gauthier's avatar
Lionel Gauthier committed
3742
{
3743 3744
  uint8_t eNB_offset;
  uint8_t currentCellIndex = mac_xface->lte_frame_parms->Nid_cell;
3745
  uint8_t tmp_offset;
Lionel Gauthier's avatar
Lionel Gauthier committed
3746

3747
  LOG_I(RRC,"[UE %d] ofn(%d) ocn(%d) hys(%d) ofs(%d) ocs(%d) a3_offset(%d) ttt(%d) rssi %3.1f\n",
3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777
        ue_mod_idP,
        ofn,ocn,hys,ofs,ocs,a3_offset,ttt,
        10*log10(mac_xface->get_RSSI(ue_mod_idP,0))-mac_xface->get_rx_total_gain_dB(ue_mod_idP,0));

  for (eNB_offset = 0; eNB_offset<1+mac_xface->get_n_adj_cells(ue_mod_idP,0); eNB_offset++) {
    //for (eNB_offset = 1;(eNB_offset<1+mac_xface->get_n_adj_cells(ue_mod_idP,0));eNB_offset++) {
    /* RHS: Verify that idx 0 corresponds to currentCellIndex in rsrp array */
    if((eNB_offset!=eNB_index)&&(eNB_offset<NB_eNB_INST)) {
      if(eNB_offset<eNB_index) {
        tmp_offset = eNB_offset;
      } else {
        tmp_offset = eNB_offset-1;
      }

      if(UE_rrc_inst[ue_mod_idP].rsrp_db_filtered[eNB_offset]+ofn+ocn-hys > UE_rrc_inst[ue_mod_idP].rsrp_db_filtered[eNB_index]+ofs+ocs-1/*+a3_offset*/) {
        UE_rrc_inst->measTimer[ue_cnx_index][meas_index][tmp_offset] += 2; //Called every subframe = 2ms
        LOG_D(RRC,"[UE %d] Frame %d: Entry measTimer[%d][%d][%d]: %d currentCell: %d betterCell: %d \n",
              ue_mod_idP, frameP, ue_cnx_index,meas_index,tmp_offset,UE_rrc_inst->measTimer[ue_cnx_index][meas_index][tmp_offset],currentCellIndex,eNB_offset);
      } else {
        UE_rrc_inst->measTimer[ue_cnx_index][meas_index][tmp_offset] = 0; //Exit condition: Resetting the measurement timer
        LOG_D(RRC,"[UE %d] Frame %d: Exit measTimer[%d][%d][%d]: %d currentCell: %d betterCell: %d \n",
              ue_mod_idP, frameP, ue_cnx_index,meas_index,tmp_offset,UE_rrc_inst->measTimer[ue_cnx_index][meas_index][tmp_offset],currentCellIndex,eNB_offset);
      }

      if (UE_rrc_inst->measTimer[ue_cnx_index][meas_index][tmp_offset] >= ttt) {
        UE_rrc_inst->HandoverInfoUe.targetCellId = get_adjacent_cell_id(ue_mod_idP,tmp_offset); //WARNING!!!...check this!
        LOG_D(RRC,"[UE %d] Frame %d eNB %d: Handover triggered: targetCellId: %d currentCellId: %d eNB_offset: %d rsrp source: %3.1f rsrp target: %3.1f\n", \
              ue_mod_idP, frameP, eNB_index,
              UE_rrc_inst->HandoverInfoUe.targetCellId,ue_cnx_index,eNB_offset,
              (dB_fixed_times10(UE_rrc_inst[ue_mod_idP].rsrp_db[0])/10.0)-mac_xface->get_rx_total_gain_dB(ue_mod_idP,0)-dB_fixed(mac_xface->lte_frame_parms->N_RB_DL*12),
3778 3779
              (dB_fixed_times10(UE_rrc_inst[ue_mod_idP].rsrp_db[eNB_offset])/10.0)-mac_xface->get_rx_total_gain_dB(ue_mod_idP,
                  0)-dB_fixed(mac_xface->lte_frame_parms->N_RB_DL*12));
3780 3781 3782 3783 3784 3785 3786 3787 3788
        UE_rrc_inst->Info[0].handoverTarget = eNB_offset;
        //LOG_D(RRC,"PHY_ID: %d \n",UE_rrc_inst->HandoverInfoUe.targetCellId);
        return 1;
      }

      // else{
      //  LOG_D(RRC,"Condition does not hold\n");
      // }
    }
3789
  }
3790

3791 3792 3793
  return 0;
}

3794
#ifdef Rel10
3795
//-----------------------------------------------------------------------------
3796
int decode_MCCH_Message( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index, const uint8_t* const Sdu, const uint8_t Sdu_len, const uint8_t mbsfn_sync_area )
Lionel Gauthier's avatar
Lionel Gauthier committed
3797
{
3798

Lionel Gauthier's avatar
Lionel Gauthier committed
3799
  MCCH_Message_t               *mcch=NULL;
3800
  MBSFNAreaConfiguration_r9_t** mcch_message=&UE_rrc_inst[ctxt_pP->module_id].mcch_message[eNB_index];
3801

Lionel Gauthier's avatar
Lionel Gauthier committed
3802
  asn_dec_rval_t                dec_rval;
3803

3804
  if (UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].MCCHStatus[mbsfn_sync_area] == 1) {
3805
    LOG_D(RRC,"[UE %d] Frame %d: MCCH MESSAGE for MBSFN sync area %d has been already received!\n",
3806 3807 3808
          ctxt_pP->module_id,
          ctxt_pP->frame,
          mbsfn_sync_area);
3809 3810 3811 3812 3813 3814 3815 3816 3817
    return 0; // avoid decoding to prevent memory bloating
  } else {
    dec_rval = uper_decode_complete(NULL,
                                    &asn_DEF_MCCH_Message,
                                    (void **)&mcch,
                                    (const void *)Sdu,
                                    Sdu_len);

    if ((dec_rval.code != RC_OK) && (dec_rval.consumed==0)) {
3818 3819 3820
      LOG_E(RRC,"[UE %d] Failed to decode MCCH__MESSAGE (%d bits)\n",
            ctxt_pP->module_id,
            dec_rval.consumed);
3821 3822 3823 3824 3825
      //free the memory
      SEQUENCE_free(&asn_DEF_MCCH_Message, (void*)mcch, 1);
      return -1;
    }

3826
#ifdef XER_PRINT
3827
    xer_fprint(stdout, &asn_DEF_MCCH_Message, (void*)mcch);
3828 3829
#endif

3830
    if (mcch->message.present == MCCH_MessageType_PR_c1) {
3831 3832
      LOG_D(RRC,"[UE %d] Found mcch message \n",
            ctxt_pP->module_id);
3833 3834 3835

      if(mcch->message.choice.c1.present == MCCH_MessageType__c1_PR_mbsfnAreaConfiguration_r9) {
        /*
winckel's avatar
winckel committed
3836
        memcpy((void*)*mcch_message,
3837 3838 3839
         (void*)&mcch->message.choice.c1.choice.mbsfnAreaConfiguration_r9,
         sizeof(MBSFNAreaConfiguration_r9_t)); */
        *mcch_message = &mcch->message.choice.c1.choice.mbsfnAreaConfiguration_r9;
3840 3841 3842 3843 3844 3845 3846 3847 3848
        LOG_I(RRC,"[UE %d] Frame %d : Found MBSFNAreaConfiguration from eNB %d \n",
              ctxt_pP->module_id,
              ctxt_pP->frame,
              eNB_index);
        decode_MBSFNAreaConfiguration(
          ctxt_pP->module_id,
          eNB_index,
          ctxt_pP->frame,
          mbsfn_sync_area);
3849 3850

      }
3851
    }
3852
  }
3853

3854 3855 3856
  return 0;
}

3857
//-----------------------------------------------------------------------------
3858
static void decode_MBSFNAreaConfiguration( module_id_t ue_mod_idP, uint8_t eNB_index, frame_t frameP, uint8_t mbsfn_sync_area )
Lionel Gauthier's avatar
Lionel Gauthier committed
3859
{
3860
  protocol_ctxt_t               ctxt;
Lionel Gauthier's avatar
Lionel Gauthier committed
3861

3862 3863
  LOG_D(RRC,"[UE %d] Frame %d : Number of MCH(s) in the MBSFN Sync Area %d  is %d\n",
        ue_mod_idP, frameP, mbsfn_sync_area, UE_rrc_inst[ue_mod_idP].mcch_message[eNB_index]->pmch_InfoList_r9.list.count);
3864
  //  store to MAC/PHY necessary parameters for receiving MTCHs
3865
  rrc_mac_config_req(ue_mod_idP,0,ENB_FLAG_NO,0,eNB_index,
3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884
                     (RadioResourceConfigCommonSIB_t *)NULL,
                     (struct PhysicalConfigDedicated *)NULL,
#ifdef Rel10
                     (SCellToAddMod_r10_t *)NULL,
                     //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
#endif
                     (MeasObjectToAddMod_t **)NULL,
                     (MAC_MainConfig_t *)NULL,
                     0,
                     (struct LogicalChannelConfig *)NULL,
                     (MeasGapConfig_t *)NULL,
                     (TDD_Config_t *)NULL,
                     (MobilityControlInfo_t *)NULL,
                     NULL,
                     NULL,
                     NULL,
                     NULL,
                     NULL,
                     (MBSFN_SubframeConfigList_t *)NULL
3885
#ifdef Rel10
3886 3887 3888 3889
                     ,
                     0,
                     (MBSFN_AreaInfoList_r9_t *)NULL,
                     &UE_rrc_inst[ue_mod_idP].mcch_message[eNB_index]->pmch_InfoList_r9
3890 3891
#endif
#ifdef CBA
3892 3893 3894
                     ,
                     0,
                     0
3895
#endif
3896
                    );
3897

Lionel Gauthier's avatar
 
Lionel Gauthier committed
3898
  UE_rrc_inst[ue_mod_idP].Info[eNB_index].MCCHStatus[mbsfn_sync_area] = 1;
3899

3900
  PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_idP, ENB_FLAG_NO, UE_rrc_inst[ue_mod_idP].Info[eNB_index].rnti, frameP, 0,eNB_index);
Lionel Gauthier's avatar
Lionel Gauthier committed
3901

3902
  // Config Radio Bearer for MBMS user data (similar way to configure for eNB side in init_MBMS function)
Lionel Gauthier's avatar
Lionel Gauthier committed
3903
  rrc_pdcp_config_asn1_req(&ctxt,
3904 3905 3906 3907 3908 3909 3910
                           NULL, // SRB_ToAddModList
                           NULL, // DRB_ToAddModList
                           (DRB_ToReleaseList_t*)NULL,
                           0, // security mode
                           NULL, // key rrc encryption
                           NULL, // key rrc integrity
                           NULL // key encryption
3911
#ifdef Rel10
3912
                           ,&(UE_rrc_inst[ue_mod_idP].mcch_message[eNB_index]->pmch_InfoList_r9)
3913
#endif
3914
                          );
winckel's avatar
winckel committed
3915

Lionel Gauthier's avatar
Lionel Gauthier committed
3916
  rrc_rlc_config_asn1_req(&ctxt,
3917 3918 3919
                          NULL,// SRB_ToAddModList
                          NULL,// DRB_ToAddModList
                          NULL,// DRB_ToReleaseList
3920
#ifdef Rel10
3921 3922 3923
                          &(UE_rrc_inst[ue_mod_idP].mcch_message[eNB_index]->pmch_InfoList_r9)
#endif
                         );
3924
  // */
3925

3926 3927 3928 3929 3930 3931 3932
}

#endif // rel10

#ifndef USER_MODE
EXPORT_SYMBOL(Rlc_info_am_config);
#endif
3933 3934

#if defined(ENABLE_ITTI)
3935
//-----------------------------------------------------------------------------
3936
void *rrc_ue_task( void *args_p )
Lionel Gauthier's avatar
Lionel Gauthier committed
3937
{
3938 3939 3940
  MessageDef   *msg_p;
  const char   *msg_name;
  instance_t    instance;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3941
  unsigned int  ue_mod_id;
3942 3943
  int           result;
  SRB_INFO     *srb_info_p;
3944

3945
  protocol_ctxt_t  ctxt;
3946 3947 3948
  itti_mark_task_ready (TASK_RRC_UE);

  while(1) {
3949 3950
    // Wait for a message
    itti_receive_msg (TASK_RRC_UE, &msg_p);
3951

3952 3953
    msg_name = ITTI_MSG_NAME (msg_p);
    instance = ITTI_MSG_INSTANCE (msg_p);
3954
    ue_mod_id = UE_INSTANCE_TO_MODULE_ID(instance);
3955

3956 3957 3958 3959
    switch (ITTI_MSG_ID(msg_p)) {
    case TERMINATE_MESSAGE:
      itti_exit_task ();
      break;
3960

3961
    case MESSAGE_TEST:
3962
      LOG_D(RRC, "[UE %d] Received %s\n", ue_mod_id, msg_name);
3963
      break;
3964

3965 3966 3967
      /* MAC messages */
    case RRC_MAC_IN_SYNC_IND:
      LOG_D(RRC, "[UE %d] Received %s: frameP %d, eNB %d\n", ue_mod_id, msg_name,
3968
            RRC_MAC_IN_SYNC_IND (msg_p).frame, RRC_MAC_IN_SYNC_IND (msg_p).enb_index);
3969

3970
      UE_rrc_inst[ue_mod_id].Info[RRC_MAC_IN_SYNC_IND (msg_p).enb_index].N310_cnt = 0;
3971

3972
      if (UE_rrc_inst[ue_mod_id].Info[RRC_MAC_IN_SYNC_IND (msg_p).enb_index].T310_active == 1) {
3973
        UE_rrc_inst[ue_mod_id].Info[RRC_MAC_IN_SYNC_IND (msg_p).enb_index].N311_cnt++;
3974
      }
3975 3976 3977 3978

      break;

    case RRC_MAC_OUT_OF_SYNC_IND:
3979
      LOG_D(RRC, "[UE %d] Received %s: frameP %d, eNB %d\n", ue_mod_id, msg_name,
3980
            RRC_MAC_OUT_OF_SYNC_IND (msg_p).frame, RRC_MAC_OUT_OF_SYNC_IND (msg_p).enb_index);
3981

3982 3983
      UE_rrc_inst[ue_mod_id].Info[RRC_MAC_OUT_OF_SYNC_IND (msg_p).enb_index].N310_cnt ++;
      break;
3984

3985 3986
    case RRC_MAC_BCCH_DATA_IND:
      LOG_D(RRC, "[UE %d] Received %s: frameP %d, eNB %d\n", ue_mod_id, msg_name,
3987
            RRC_MAC_BCCH_DATA_IND (msg_p).frame, RRC_MAC_BCCH_DATA_IND (msg_p).enb_index);
3988

3989 3990
      //      PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, ENB_FLAG_NO, NOT_A_RNTI, RRC_MAC_BCCH_DATA_IND (msg_p).frame, 0);
      PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_id, ENB_FLAG_NO, NOT_A_RNTI, RRC_MAC_BCCH_DATA_IND (msg_p).frame, 0,RRC_MAC_BCCH_DATA_IND (msg_p).enb_index);
3991 3992 3993
      decode_BCCH_DLSCH_Message (&ctxt,
                                 RRC_MAC_BCCH_DATA_IND (msg_p).enb_index,
                                 RRC_MAC_BCCH_DATA_IND (msg_p).sdu,
3994
                                 RRC_MAC_BCCH_DATA_IND (msg_p).sdu_size,
3995 3996
                                 RRC_MAC_BCCH_DATA_IND (msg_p).rsrq,
                                 RRC_MAC_BCCH_DATA_IND (msg_p).rsrp);
3997
      break;
3998

3999
    case RRC_MAC_CCCH_DATA_CNF:
4000
      LOG_D(RRC, "[UE %d] Received %s: eNB %d\n", ue_mod_id, msg_name,
4001
            RRC_MAC_CCCH_DATA_CNF (msg_p).enb_index);
4002

4003 4004 4005
      // reset the tx buffer to indicate RRC that ccch was successfully transmitted (for example if contention resolution succeeds)
      UE_rrc_inst[ue_mod_id].Srb0[RRC_MAC_CCCH_DATA_CNF (msg_p).enb_index].Tx_buffer.payload_size = 0;
      break;
4006

4007
    case RRC_MAC_CCCH_DATA_IND:
4008
      LOG_D(RRC, "[UE %d] RNTI %x Received %s: frameP %d, eNB %d\n",
4009 4010 4011 4012 4013
            ue_mod_id,
            RRC_MAC_CCCH_DATA_IND (msg_p).rnti,
            msg_name,
            RRC_MAC_CCCH_DATA_IND (msg_p).frame,
            RRC_MAC_CCCH_DATA_IND (msg_p).enb_index);
4014

4015
      srb_info_p = &UE_rrc_inst[ue_mod_id].Srb0[RRC_MAC_CCCH_DATA_IND (msg_p).enb_index];
4016

4017 4018 4019
      memcpy (srb_info_p->Rx_buffer.Payload, RRC_MAC_CCCH_DATA_IND (msg_p).sdu,
              RRC_MAC_CCCH_DATA_IND (msg_p).sdu_size);
      srb_info_p->Rx_buffer.payload_size = RRC_MAC_CCCH_DATA_IND (msg_p).sdu_size;
4020 4021
      //      PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, ENB_FLAG_NO, RRC_MAC_CCCH_DATA_IND (msg_p).rnti, RRC_MAC_CCCH_DATA_IND (msg_p).frame, 0);
      PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_id, ENB_FLAG_NO, RRC_MAC_CCCH_DATA_IND (msg_p).rnti, RRC_MAC_CCCH_DATA_IND (msg_p).frame, 0, RRC_MAC_CCCH_DATA_IND (msg_p).enb_index);
4022 4023
      rrc_ue_decode_ccch (&ctxt,
                          srb_info_p,
4024 4025
                          RRC_MAC_CCCH_DATA_IND (msg_p).enb_index);
      break;
4026

4027
# ifdef Rel10
4028 4029

    case RRC_MAC_MCCH_DATA_IND:
4030
      LOG_D(RRC, "[UE %d] Received %s: frameP %d, eNB %d, mbsfn SA %d\n", ue_mod_id, msg_name,
4031
            RRC_MAC_MCCH_DATA_IND (msg_p).frame, RRC_MAC_MCCH_DATA_IND (msg_p).enb_index, RRC_MAC_MCCH_DATA_IND (msg_p).mbsfn_sync_area);
4032

4033 4034
      //PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, ENB_FLAG_NO, M_RNTI, RRC_MAC_MCCH_DATA_IND (msg_p).frame, 0);
      PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_id, ENB_FLAG_NO, M_RNTI, RRC_MAC_MCCH_DATA_IND (msg_p).frame, 0,RRC_MAC_MCCH_DATA_IND (msg_p).enb_index);
4035 4036 4037 4038 4039
      decode_MCCH_Message (
        &ctxt,
        RRC_MAC_MCCH_DATA_IND (msg_p).enb_index,
        RRC_MAC_MCCH_DATA_IND (msg_p).sdu,
        RRC_MAC_MCCH_DATA_IND (msg_p).sdu_size,
4040
        RRC_MAC_MCCH_DATA_IND (msg_p).mbsfn_sync_area);
4041
      break;
4042
# endif
4043

4044 4045
      /* PDCP messages */
    case RRC_DCCH_DATA_IND:
4046
      PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, RRC_DCCH_DATA_IND (msg_p).module_id, ENB_FLAG_NO, RRC_DCCH_DATA_IND (msg_p).rnti, RRC_DCCH_DATA_IND (msg_p).frame, 0,RRC_DCCH_DATA_IND (msg_p).eNB_index);
4047
      LOG_D(RRC, "[UE %d] Received %s: frameP %d, DCCH %d, eNB %d\n",
4048 4049 4050 4051
            RRC_DCCH_DATA_IND (msg_p).module_id,
            msg_name,
            RRC_DCCH_DATA_IND (msg_p).frame,
            RRC_DCCH_DATA_IND (msg_p).dcch_index,
4052
            RRC_DCCH_DATA_IND (msg_p).eNB_index);
4053

4054
      LOG_D(RRC, PROTOCOL_RRC_CTXT_UE_FMT"Received %s DCCH %d, eNB %d\n",
4055 4056 4057 4058 4059 4060 4061 4062 4063
            PROTOCOL_RRC_CTXT_UE_ARGS(&ctxt),
            msg_name,
            RRC_DCCH_DATA_IND (msg_p).dcch_index,
            RRC_DCCH_DATA_IND (msg_p).eNB_index);
      rrc_ue_decode_dcch (
        &ctxt,
        RRC_DCCH_DATA_IND (msg_p).dcch_index,
        RRC_DCCH_DATA_IND (msg_p).sdu_p,
        RRC_DCCH_DATA_IND (msg_p).eNB_index);
4064 4065 4066 4067
      // Message buffer has been processed, free it now.
      result = itti_free (ITTI_MSG_ORIGIN_ID(msg_p), RRC_DCCH_DATA_IND (msg_p).sdu_p);
      AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
      break;
4068

4069 4070
# if defined(ENABLE_USE_MME)

4071 4072 4073 4074
      /* NAS messages */
    case NAS_CELL_SELECTION_REQ:
      ue_mod_id = 0; /* TODO force ue_mod_id to first UE, NAS UE not virtualized yet */

4075
      LOG_D(RRC, "[UE %d] Received %s: state %d, plmnID %d, rat %x\n", ue_mod_id, msg_name, rrc_get_state(ue_mod_id),
4076
            NAS_CELL_SELECTION_REQ (msg_p).plmnID, NAS_CELL_SELECTION_REQ (msg_p).rat);
4077

4078 4079 4080 4081
      if (rrc_get_state(ue_mod_id) == RRC_STATE_INACTIVE) {
        // have a look at MAC/main.c void dl_phy_sync_success(...)
        openair_rrc_ue_init(ue_mod_id,0);
      }
4082

4083 4084 4085 4086
      /* Save cell selection criterion */
      {
        UE_rrc_inst[ue_mod_id].plmnID = NAS_CELL_SELECTION_REQ (msg_p).plmnID;
        UE_rrc_inst[ue_mod_id].rat = NAS_CELL_SELECTION_REQ (msg_p).rat;
4087
        LOG_D(RRC, "[UE %d] Save cell selection criterion MCC %X%X%X MNC %X%X%X\n",
4088 4089 4090 4091 4092 4093 4094
              ue_mod_id,
              UE_rrc_inst[ue_mod_id].plmnID.MCCdigit1,
              UE_rrc_inst[ue_mod_id].plmnID.MCCdigit2,
              UE_rrc_inst[ue_mod_id].plmnID.MCCdigit3,
              UE_rrc_inst[ue_mod_id].plmnID.MNCdigit1,
              UE_rrc_inst[ue_mod_id].plmnID.MNCdigit2,
              UE_rrc_inst[ue_mod_id].plmnID.MNCdigit3);
Lionel Gauthier's avatar
Lionel Gauthier committed
4095

4096
      }
4097

4098 4099 4100 4101
      switch (rrc_get_state(ue_mod_id)) {
      case RRC_STATE_INACTIVE: {
        /* Need to first activate lower layers */
        MessageDef *message_p;
4102

4103
        message_p = itti_alloc_new_message(TASK_RRC_UE, ACTIVATE_MESSAGE);
4104

4105
        itti_send_msg_to_task(TASK_L2L1, UE_MODULE_ID_TO_INSTANCE(ue_mod_id), message_p);
4106

4107 4108 4109
        rrc_set_state (ue_mod_id, RRC_STATE_IDLE);
        /* Fall through to next case */
      }
winckel's avatar
winckel committed
4110

4111 4112 4113
      case RRC_STATE_IDLE: {
        /* Ask to layer 1 to find a cell matching the criterion */
        MessageDef *message_p;
winckel's avatar
winckel committed
4114

4115
        message_p = itti_alloc_new_message(TASK_RRC_UE, PHY_FIND_CELL_REQ);
winckel's avatar
winckel committed
4116

4117 4118
        PHY_FIND_CELL_REQ (message_p).earfcn_start = 1;
        PHY_FIND_CELL_REQ (message_p).earfcn_end = 1;
winckel's avatar
winckel committed
4119

4120
        itti_send_msg_to_task(TASK_PHY_UE, UE_MODULE_ID_TO_INSTANCE(ue_mod_id), message_p);
4121
        rrc_set_sub_state (ue_mod_id, RRC_SUB_STATE_IDLE_SEARCHING);
winckel's avatar
winckel committed
4122

4123 4124
        break;
      }
4125

4126 4127 4128 4129
      case RRC_STATE_CONNECTED:
        /* should not happen */
        LOG_E(RRC, "[UE %d] request %s in RRC state %d\n", ue_mod_id, msg_name, rrc_get_state(ue_mod_id));
        break;
4130

4131 4132
      default:
        LOG_C(RRC, "[UE %d] Invalid RRC state %d\n", ue_mod_id, rrc_get_state(ue_mod_id));
4133
        break;
4134
      }
winckel's avatar
winckel committed
4135

4136
      break;
winckel's avatar
winckel committed
4137

4138
    case NAS_CONN_ESTABLI_REQ:
4139
      LOG_D(RRC, "[UE %d] Received %s: cause %d, type %d, s_tmsi %d, plmnID %d\n", ue_mod_id, msg_name, NAS_CONN_ESTABLI_REQ (msg_p).cause,
4140
            NAS_CONN_ESTABLI_REQ (msg_p).type, NAS_CONN_ESTABLI_REQ (msg_p).s_tmsi, NAS_CONN_ESTABLI_REQ (msg_p).plmnID);
winckel's avatar
winckel committed
4141

4142 4143 4144
      //PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, ENB_FLAG_NO, NOT_A_RNTI, 0, 0);
      PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_id, ENB_FLAG_NO, NOT_A_RNTI, 0, 0, 0);

4145
      UE_rrc_inst[ue_mod_id].initialNasMsg = NAS_CONN_ESTABLI_REQ (msg_p).initialNasMsg;
winckel's avatar
winckel committed
4146

4147 4148 4149
      switch (rrc_get_state(ue_mod_id)) {
      case RRC_STATE_IDLE: {
        if (rrc_get_sub_state(ue_mod_id) == RRC_SUB_STATE_IDLE_SIB_COMPLETE) {
4150
          rrc_ue_generate_RRCConnectionRequest(&ctxt, 0);
4151
          LOG_D(RRC, "not sending connection request\n");
winckel's avatar
winckel committed
4152

4153 4154
          rrc_set_sub_state (ue_mod_id, RRC_SUB_STATE_IDLE_CONNECTING);
        }
winckel's avatar
winckel committed
4155

4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168
        break;
      }

      case RRC_STATE_INACTIVE:
      case RRC_STATE_CONNECTED:
        /* should not happen */
        LOG_E(RRC, "[UE %d] request %s in RRC state %d\n", ue_mod_id, msg_name, rrc_get_state(ue_mod_id));
        break;

      default:
        LOG_C(RRC, "[UE %d] Invalid RRC state %d\n", ue_mod_id, rrc_get_state(ue_mod_id));
        break;
      }
winckel's avatar
winckel committed
4169

4170
      break;
winckel's avatar
RRC:  
winckel committed
4171

4172 4173 4174
    case NAS_UPLINK_DATA_REQ: {
      uint32_t length;
      uint8_t *buffer;
winckel's avatar
RRC:  
winckel committed
4175

4176
      LOG_D(RRC, "[UE %d] Received %s: UEid %d\n", ue_mod_id, msg_name, NAS_UPLINK_DATA_REQ (msg_p).UEid);
4177 4178 4179 4180 4181

      /* Create message for PDCP (ULInformationTransfer_t) */
      length = do_ULInformationTransfer(&buffer, NAS_UPLINK_DATA_REQ (msg_p).nasMsg.length, NAS_UPLINK_DATA_REQ (msg_p).nasMsg.data);

      /* Transfer data to PDCP */
4182
      PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_id, ENB_FLAG_NO, UE_rrc_inst[ue_mod_id].Info[0].rnti, 0, 0,0);
4183 4184 4185 4186 4187 4188
      pdcp_rrc_data_req (&ctxt,
                         DCCH,
                         rrc_mui++,
                         SDU_CONFIRM_NO,
                         length, buffer,
                         PDCP_TRANSMISSION_MODE_CONTROL);
4189 4190
      break;
    }
winckel's avatar
RRC:  
winckel committed
4191

4192
# endif
winckel's avatar
RRC:  
winckel committed
4193

4194
# if ENABLE_RAL
4195

4196
    case RRC_RAL_SCAN_REQ:
4197
      LOG_D(RRC, "[UE %d] Received %s: state %d\n", ue_mod_id, msg_name);
4198

4199 4200 4201 4202
      switch (rrc_get_state(ue_mod_id)) {
      case RRC_STATE_INACTIVE: {
        /* Need to first activate lower layers */
        MessageDef *message_p;
4203

4204
        message_p = itti_alloc_new_message(TASK_RRC_UE, ACTIVATE_MESSAGE);
4205

4206
        itti_send_msg_to_task(TASK_L2L1, instance, message_p);
4207

4208 4209 4210
        rrc_set_state (ue_mod_id, RRC_STATE_IDLE);
        /* Fall through to next case */
      }
4211

4212 4213 4214 4215
      case RRC_STATE_IDLE: {
        if (rrc_get_sub_state(ue_mod_id) != RRC_SUB_STATE_IDLE_SEARCHING) {
          /* Ask to layer 1 to find a cell matching the criterion */
          MessageDef *message_p;
4216

4217
          message_p = itti_alloc_new_message(TASK_RRC_UE, PHY_FIND_CELL_REQ);
4218

4219
          rrc_set_sub_state (ue_mod_id, RRC_SUB_STATE_IDLE_SEARCHING);
4220

4221 4222 4223
          PHY_FIND_CELL_REQ (message_p).transaction_id = RRC_RAL_SCAN_REQ (msg_p).transaction_id;
          PHY_FIND_CELL_REQ (message_p).earfcn_start   = 1;
          PHY_FIND_CELL_REQ (message_p).earfcn_end     = 1; //44
4224

4225 4226
          itti_send_msg_to_task(TASK_PHY_UE, instance, message_p);
        }
4227

4228 4229
        break;
      }
4230

4231 4232 4233 4234
      case RRC_STATE_CONNECTED:
        /* should not happen */
        LOG_E(RRC, "[UE %d] request %s in RRC state %d\n", ue_mod_id, msg_name, rrc_get_state(ue_mod_id));
        break;
4235

4236 4237 4238 4239
      default:
        LOG_C(RRC, "[UE %d] Invalid RRC state %d\n", ue_mod_id, rrc_get_state(ue_mod_id));
        break;
      }
4240

4241
      break;
4242

4243
    case PHY_FIND_CELL_IND:
4244
      LOG_D(RRC, "[UE %d] Received %s: state %d\n", ue_mod_id, msg_name, rrc_get_state(ue_mod_id));
4245

4246 4247 4248 4249 4250 4251
      switch (rrc_get_state(ue_mod_id)) {
      case RRC_STATE_IDLE:
        switch (rrc_get_sub_state(ue_mod_id)) {
        case RRC_SUB_STATE_IDLE_SEARCHING: {
          MessageDef *message_p;
          int         i;
4252

4253
          message_p = itti_alloc_new_message(TASK_RRC_UE, RRC_RAL_SCAN_CONF);
4254

4255 4256
          RRC_RAL_SCAN_CONF (message_p).transaction_id = PHY_FIND_CELL_IND(msg_p).transaction_id;
          RRC_RAL_SCAN_CONF (message_p).num_scan_resp  = PHY_FIND_CELL_IND(msg_p).cell_nb;
4257

4258 4259 4260 4261 4262
          for (i = 0 ; i < PHY_FIND_CELL_IND(msg_p).cell_nb; i++) {
            // TO DO
            memset(&RRC_RAL_SCAN_CONF (message_p).link_scan_resp[i].link_addr,  0, sizeof(ral_link_addr_t));
            // TO DO
            memset(&RRC_RAL_SCAN_CONF (message_p).link_scan_resp[i].network_id, 0, sizeof(ral_network_id_t));
4263

4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291
            RRC_RAL_SCAN_CONF (message_p).link_scan_resp[i].sig_strength.choice     = RAL_SIG_STRENGTH_CHOICE_DBM;
            RRC_RAL_SCAN_CONF (message_p).link_scan_resp[i].sig_strength._union.dbm = PHY_FIND_CELL_IND(msg_p).cells[i].rsrp;
          }

          rrc_set_sub_state (ue_mod_id, RRC_SUB_STATE_IDLE);

          itti_send_msg_to_task(TASK_RAL_UE, instance, message_p);
          break;
        }

        default:
          LOG_C(RRC, "[UE %d] Invalid RRC state %d substate %d\n",
                ue_mod_id,
                rrc_get_state(ue_mod_id),
                rrc_get_sub_state(ue_mod_id));
        }

        break;

      case RRC_STATE_INACTIVE:
      case RRC_STATE_CONNECTED:
        /* should not happen */
        LOG_E(RRC, "[UE %d] indication %s in RRC state %d\n", ue_mod_id, msg_name, rrc_get_state(ue_mod_id));
        break;

      default:
        LOG_C(RRC, "[UE %d] Invalid RRC state %d\n", ue_mod_id, rrc_get_state(ue_mod_id));
        break;
4292
      }
4293

4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307
      break; // PHY_FIND_CELL_IND

    case PHY_MEAS_REPORT_IND: {
      MessageDef *message_p;
      message_p = itti_alloc_new_message(TASK_RRC_UE, RRC_RAL_MEASUREMENT_REPORT_IND);

      memcpy(&RRC_RAL_MEASUREMENT_REPORT_IND (message_p).threshold,
             &PHY_MEAS_REPORT_IND(msg_p).threshold,
             sizeof(RRC_RAL_MEASUREMENT_REPORT_IND (message_p).threshold));

      memcpy(&RRC_RAL_MEASUREMENT_REPORT_IND (message_p).link_param,
             &PHY_MEAS_REPORT_IND(msg_p).link_param,
             sizeof(RRC_RAL_MEASUREMENT_REPORT_IND (message_p).link_param));

4308
      LOG_D(RRC, "[UE %d] PHY_MEAS_REPORT_IN: sending msg %s to %s \n", ue_mod_id, "RRC_RAL_MEASUREMENT_REPORT_IND", "TASK_RAL_UE");
4309 4310 4311 4312 4313 4314 4315 4316 4317
      itti_send_msg_to_task(TASK_RAL_UE, instance, message_p);
      break;
    }

    case RRC_RAL_CONFIGURE_THRESHOLD_REQ:
      rrc_ue_ral_handle_configure_threshold_request(ue_mod_id, msg_p);
      break;

    case RRC_RAL_CONNECTION_ESTABLISHMENT_REQ:
4318
      LOG_D(RRC, "[UE %d] Received %s\n", ue_mod_id, msg_name);
4319 4320 4321 4322

      switch (rrc_get_state(ue_mod_id)) {
      case RRC_STATE_IDLE: {
        if (rrc_get_sub_state(ue_mod_id) == RRC_SUB_STATE_IDLE_SIB_COMPLETE) {
4323
          PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_id, ENB_FLAG_NO, UE_rrc_inst[ue_mod_id].Info[0].rnti, 0, 0, 0);
4324
          rrc_ue_generate_RRCConnectionRequest(&ctxt, 0);
4325
          LOG_D(RRC, "not sending connection request\n");
4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346
          rrc_set_sub_state (ue_mod_id, RRC_SUB_STATE_IDLE_CONNECTING);
        }

        break;
      }

      case RRC_STATE_INACTIVE:
      case RRC_STATE_CONNECTED:
        /* should not happen */
        LOG_E(RRC, "[UE %d] request %s in RRC state %d\n", ue_mod_id, msg_name, rrc_get_state(ue_mod_id));
        break;

      default:
        LOG_C(RRC, "[UE %d] Invalid RRC state %d\n", ue_mod_id, rrc_get_state(ue_mod_id));
        break;
      }

      break;

    case RRC_RAL_CONNECTION_RELEASE_REQ:
      ue_mod_id = 0; /* TODO force ue_mod_id to first UE, NAS UE not virtualized yet */
4347
      LOG_D(RRC, "[UE %d] Received %s\n", ue_mod_id, msg_name);
4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359
      break;
#endif

    default:
      LOG_E(RRC, "[UE %d] Received unexpected message %s\n", ue_mod_id, msg_name);
      break;
    }

    result = itti_free (ITTI_MSG_ORIGIN_ID(msg_p), msg_p);
    AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
    AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
    msg_p = NULL;
4360 4361 4362
  }
}
#endif