rrc_UE.c 139 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
/*******************************************************************************

  Eurecom OpenAirInterface 2
  Copyright(c) 1999 - 2010 Eurecom

  This program is free software; you can redistribute it and/or modify it
  under the terms and conditions of the GNU General Public License,
  version 2, as published by the Free Software Foundation.

  This program is distributed in the hope 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.
  You should have received a copy of the GNU General Public License along with
  this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.

  The full GNU General Public License is included in this distribution in
  the file called "COPYING".

  Contact Information
  Openair Admin: openair_admin@eurecom.fr
  Openair Tech : openair_tech@eurecom.fr
  Forums       : http://forums.eurecom.fsr/openairinterface
  Address      : Eurecom, 2229, route des crêtes, 06560 Valbonne Sophia Antipolis, France

*******************************************************************************/

/*! \file rrc_UE.c
* \brief rrc procedures for UE
* \author Raymond Knopp and Navid Nikaein
* \date 2011
* \version 1.0
* \company Eurecom
* \email: raymond.knopp@eurecom.fr and  navid.nikaein@eurecom.fr
*/

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

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

86 87
#include "pdcp.h"

88 89 90 91
#if defined(ENABLE_ITTI)
# include "intertask_interface.h"
#endif

92 93 94 95 96 97 98 99 100 101 102 103
#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

extern inline unsigned int taus(void);
104
extern s8 dB_fixed2(u32 x,u32 y);
105

winckel's avatar
winckel committed
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
/*------------------------------------------------------------------------------*/
static Rrc_State_t rrc_get_state (u8 Mod_id) {
  return UE_rrc_inst[Mod_id].RrcState;
}

static Rrc_Sub_State_t rrc_get_sub_state (u8 Mod_id) {
  return UE_rrc_inst[Mod_id].RrcSubState;
}

static int rrc_set_state (u8 Mod_id, Rrc_State_t state) {
  AssertFatal ((RRC_STATE_FIRST <= state) && (state <= RRC_STATE_LAST),
               "Invalid state %d!\n", state);

  if (UE_rrc_inst[Mod_id].RrcState != state) {
    UE_rrc_inst[Mod_id].RrcState = state;

122 123 124 125 126 127 128
#if defined(ENABLE_ITTI)
    {
      MessageDef *msg_p;

      msg_p = itti_alloc_new_message(TASK_RRC_UE, RRC_STATE_IND);
      RRC_STATE_IND(msg_p).state = UE_rrc_inst[Mod_id].RrcState;
      RRC_STATE_IND(msg_p).sub_state = UE_rrc_inst[Mod_id].RrcSubState;
winckel's avatar
winckel committed
129

130 131 132
      itti_send_msg_to_task(TASK_UNKNOWN, NB_eNB_INST + Mod_id, msg_p);
    }
#endif
winckel's avatar
winckel committed
133 134 135 136 137 138 139
    return (1);
  }

  return (0);
}

static int rrc_set_sub_state (u8 Mod_id, Rrc_Sub_State_t subState) {
140
#if (defined(ENABLE_ITTI) && defined(ENABLE_USE_MME))
winckel's avatar
winckel committed
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
  switch (UE_rrc_inst[Mod_id].RrcState) {
    case RRC_STATE_INACTIVE:
      AssertFatal ((RRC_SUB_STATE_INACTIVE_FIRST <= subState) && (subState <= RRC_SUB_STATE_INACTIVE_LAST),
                   "Invalid sub state %d for state %d!\n", subState, UE_rrc_inst[Mod_id].RrcState);
      break;

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

    case RRC_STATE_CONNECTED:
      AssertFatal ((RRC_SUB_STATE_CONNECTED_FIRST <= subState) && (subState <= RRC_SUB_STATE_CONNECTED_LAST),
                   "Invalid sub state %d for state %d!\n", subState, UE_rrc_inst[Mod_id].RrcState);
      break;
  }
157
#endif
winckel's avatar
winckel committed
158 159 160 161

  if (UE_rrc_inst[Mod_id].RrcSubState != subState) {
    UE_rrc_inst[Mod_id].RrcSubState = subState;

162 163 164
#if defined(ENABLE_ITTI)
    {
      MessageDef *msg_p;
winckel's avatar
winckel committed
165

166 167 168 169 170 171 172
      msg_p = itti_alloc_new_message(TASK_RRC_UE, RRC_STATE_IND);
      RRC_STATE_IND(msg_p).state = UE_rrc_inst[Mod_id].RrcState;
      RRC_STATE_IND(msg_p).sub_state = UE_rrc_inst[Mod_id].RrcSubState;

      itti_send_msg_to_task(TASK_UNKNOWN, NB_eNB_INST + Mod_id, msg_p);
    }
#endif
winckel's avatar
winckel committed
173 174 175 176 177 178 179
    return (1);
  }

  return (0);
}

/*------------------------------------------------------------------------------*/
180 181 182 183 184 185 186 187 188 189 190 191 192
void init_SI_UE(u8 Mod_id,u8 eNB_index) {

  int i;


  UE_rrc_inst[Mod_id].sizeof_SIB1[eNB_index] = 0;
  UE_rrc_inst[Mod_id].sizeof_SI[eNB_index] = 0;

  UE_rrc_inst[Mod_id].SIB1[eNB_index] = (u8 *)malloc16(32);
  UE_rrc_inst[Mod_id].sib1[eNB_index] = (SystemInformationBlockType1_t *)malloc16(sizeof(SystemInformationBlockType1_t));
  UE_rrc_inst[Mod_id].SI[eNB_index] = (u8 *)malloc16(64);

  for (i=0;i<NB_CNX_UE;i++) {
193
    UE_rrc_inst[Mod_id].si[eNB_index][i] = (SystemInformation_t *)malloc16(sizeof(SystemInformation_t));
194 195 196 197 198 199 200 201
  }

  UE_rrc_inst[Mod_id].Info[eNB_index].SIB1Status = 0;
  UE_rrc_inst[Mod_id].Info[eNB_index].SIStatus = 0;
}

#ifdef Rel10
void init_MCCH_UE(u8 Mod_id, u8 eNB_index) {
202
  int i;
203 204 205
  UE_rrc_inst[Mod_id].sizeof_MCCH_MESSAGE[eNB_index] = 0;
  UE_rrc_inst[Mod_id].MCCH_MESSAGE[eNB_index] = (u8 *)malloc16(32);
  UE_rrc_inst[Mod_id].mcch_message[eNB_index] = (MBSFNAreaConfiguration_r9_t *)malloc16(sizeof(MBSFNAreaConfiguration_r9_t));
206 207
  for (i=0; i<8;i++) // MAX MBSFN Area
    UE_rrc_inst[Mod_id].Info[eNB_index].MCCHStatus[i] = 0;
208 209 210 211 212 213 214 215

}
#endif

static
void openair_rrc_lite_ue_init_security(u8 Mod_id)
{
#if defined(ENABLE_SECURITY)
216 217
//    uint8_t *kRRCenc;
//    uint8_t *kRRCint;
218 219 220 221 222 223 224 225 226
    char ascii_buffer[65];
    uint8_t i;

    memset(UE_rrc_inst[Mod_id].kenb, Mod_id, 32);

    for (i = 0; i < 32; i++) {
        sprintf(&ascii_buffer[2 * i], "%02X", UE_rrc_inst[Mod_id].kenb[i]);
    }

227
    LOG_T(RRC, "[OSA][UE %02d] kenb    = %s\n", Mod_id, ascii_buffer);
228
#endif
229
}
230 231 232 233

/*------------------------------------------------------------------------------*/
char openair_rrc_lite_ue_init(u8 Mod_id, unsigned char eNB_index){
  /*-----------------------------------------------------------------------------*/
winckel's avatar
winckel committed
234 235 236
  rrc_set_state (Mod_id, RRC_STATE_INACTIVE);
  rrc_set_sub_state (Mod_id, RRC_SUB_STATE_INACTIVE);

237 238 239 240 241 242 243 244 245 246 247 248
  LOG_D(RRC,"[UE %d] INIT State = RRC_IDLE (eNB %d)\n",Mod_id,eNB_index);
  LOG_D(RRC,"[MSC_NEW][FRAME 00000][RRC_UE][MOD %02d][]\n", Mod_id+NB_eNB_INST);
  LOG_D(RRC, "[MSC_NEW][FRAME 00000][IP][MOD %02d][]\n", Mod_id+NB_eNB_INST);

  UE_rrc_inst[Mod_id].Info[eNB_index].State=RRC_IDLE;
  UE_rrc_inst[Mod_id].Info[eNB_index].T300_active = 0;
  UE_rrc_inst[Mod_id].Info[eNB_index].T304_active = 0;
  UE_rrc_inst[Mod_id].Info[eNB_index].T310_active = 0;
  UE_rrc_inst[Mod_id].Info[eNB_index].UE_index=0xffff;
  UE_rrc_inst[Mod_id].Srb0[eNB_index].Active=0;
  UE_rrc_inst[Mod_id].Srb1[eNB_index].Active=0;
  UE_rrc_inst[Mod_id].Srb2[eNB_index].Active=0;
249
  UE_rrc_inst[Mod_id].HandoverInfoUe.measFlag=1;
250

251 252 253 254 255 256 257 258 259
  UE_rrc_inst[Mod_id].ciphering_algorithm = SecurityAlgorithmConfig__cipheringAlgorithm_eea0;
#ifdef Rel10
  UE_rrc_inst[Mod_id].integrity_algorithm = SecurityAlgorithmConfig__integrityProtAlgorithm_eia0_v920;
#else
  UE_rrc_inst[Mod_id].integrity_algorithm = SecurityAlgorithmConfig__integrityProtAlgorithm_reserved;
#endif

  openair_rrc_lite_ue_init_security(Mod_id);

260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
  init_SI_UE(Mod_id,eNB_index);
  LOG_D(RRC,"[UE %d] INIT: phy_sync_2_ch_ind\n", Mod_id);

#ifndef NO_RRM
  send_msg(&S_rrc,msg_rrc_phy_synch_to_CH_ind(Mod_id,eNB_index,UE_rrc_inst[Mod_id].Mac_id));
#endif

#ifdef NO_RRM //init ch SRB0, SRB1 & BDTCH
  openair_rrc_on(Mod_id,0);
#endif
#ifdef CBA 
  int j;
  for(j=0; j<NUM_MAX_CBA_GROUP; j++)
    UE_rrc_inst[Mod_id].cba_rnti[j] = 0x0000;
  UE_rrc_inst[Mod_id].num_active_cba_groups = 0;
#endif

  return 0;
}

/*------------------------------------------------------------------------------*/
void rrc_ue_generate_RRCConnectionRequest(u8 Mod_id, u32 frame, u8 eNB_index){
  /*------------------------------------------------------------------------------*/

  u8 i=0,rv[6];
285
  
286 287 288 289 290 291
  if(UE_rrc_inst[Mod_id].Srb0[eNB_index].Tx_buffer.payload_size ==0){

    // Get RRCConnectionRequest, fill random for now
    // Generate random byte stream for contention resolution
      for (i=0;i<6;i++) {
#ifdef SMBV   
292 293
        // if SMBV is configured the contention resolution needs to be fix for the connection procedure to succeed
        rv[i]=i;
294
#else
295
        rv[i]=taus()&0xff;
296 297 298 299
#endif
      LOG_T(RRC,"%x.",rv[i]);
    }
    LOG_T(RRC,"\n");
300
    UE_rrc_inst[Mod_id].Srb0[eNB_index].Tx_buffer.payload_size = do_RRCConnectionRequest(Mod_id, (u8 *)UE_rrc_inst[Mod_id].Srb0[eNB_index].Tx_buffer.Payload,rv);
301 302

    LOG_I(RRC,"[UE %d] : Frame %d, Logical Channel UL-CCCH (SRB0), Generating RRCConnectionRequest (bytes %d, eNB %d)\n",
303
      Mod_id, frame, UE_rrc_inst[Mod_id].Srb0[eNB_index].Tx_buffer.payload_size, eNB_index);
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320

    for (i=0;i<UE_rrc_inst[Mod_id].Srb0[eNB_index].Tx_buffer.payload_size;i++) {
      LOG_T(RRC,"%x.",UE_rrc_inst[Mod_id].Srb0[eNB_index].Tx_buffer.Payload[i]);
    }
    LOG_T(RRC,"\n");
    /*
      UE_rrc_inst[Mod_id].Srb0[Idx].Tx_buffer.Payload[i] = taus()&0xff;

    UE_rrc_inst[Mod_id].Srb0[Idx].Tx_buffer.payload_size =i;
    */

  }
}


mui_t rrc_mui=0;

321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
/* NAS Attach request with IMSI */
static const char nas_attach_req_imsi[] =
{
    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,
};

/* NAS Attach request with GUTI */
static const char nas_attach_req_guti[] =
{
    0x07, 0x41,
340
    /* EPS Mobile identity = GUTI */
341 342 343 344 345 346 347 348 349 350
    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,
};

351
/*------------------------------------------------------------------------------*/
352
void rrc_ue_generate_RRCConnectionSetupComplete(u8 Mod_id, u32 frame, u8 eNB_index, uint8_t Transaction_id){
353 354
  /*------------------------------------------------------------------------------*/

winckel's avatar
winckel committed
355 356 357 358
  u8    buffer[100];
  u8    size;
  char *nas_msg;
  int   nas_msg_length;
359

winckel's avatar
winckel committed
360 361 362 363 364 365 366 367
#if defined(ENABLE_ITTI) && defined(ENABLE_USE_MME)
  nas_msg         = (char *) UE_rrc_inst[Mod_id].initialNasMsg.data;
  nas_msg_length  = UE_rrc_inst[Mod_id].initialNasMsg.length;
#else
  nas_msg         = nas_attach_req_imsi;
  nas_msg_length  = sizeof(nas_attach_req_imsi);
#endif

368
  size = do_RRCConnectionSetupComplete(Mod_id, buffer, Transaction_id, nas_msg_length, nas_msg);
369 370

  LOG_I(RRC,"[UE %d][RAPROC] Frame %d : Logical Channel UL-DCCH (SRB1), Generating RRCConnectionSetupComplete (bytes%d, eNB %d)\n",
371
    Mod_id,frame, size, eNB_index);
372 373 374 375 376

   LOG_D(RLC, "[MSC_MSG][FRAME %05d][RRC_UE][MOD %02d][][--- PDCP_DATA_REQ/%d Bytes (RRCConnectionSetupComplete to eNB %d MUI %d) --->][PDCP][MOD %02d][RB %02d]\n",
                                     frame, Mod_id+NB_eNB_INST, size, eNB_index, rrc_mui, Mod_id+NB_eNB_INST, DCCH);

   //  rrc_rlc_data_req(Mod_id+NB_eNB_INST,frame, 0 ,DCCH,rrc_mui++,0,size,(char*)buffer);
377
  pdcp_rrc_data_req (eNB_index, Mod_id, frame, 0, DCCH, rrc_mui++, 0, size, buffer, 1);
378 379
}

380
void rrc_ue_generate_RRCConnectionReconfigurationComplete(u8 Mod_id, u32 frame, u8 eNB_index, uint8_t Transaction_id) {
381 382 383

  u8 buffer[32], size;

384
  size = do_RRCConnectionReconfigurationComplete(Mod_id, buffer, Transaction_id);
385 386

  LOG_I(RRC,"[UE %d] Frame %d : Logical Channel UL-DCCH (SRB1), Generating RRCConnectionReconfigurationComplete (bytes %d, eNB_index %d)\n",
387
    Mod_id,frame, size, eNB_index);
388
  LOG_D(RLC, "[MSC_MSG][FRAME %05d][RRC_UE][MOD %02d][][--- PDCP_DATA_REQ/%d Bytes (RRCConnectionReconfigurationComplete to eNB %d MUI %d) --->][PDCP][MOD %02d][RB %02d]\n",
389
    frame, Mod_id+NB_eNB_INST, size, eNB_index, rrc_mui, Mod_id+NB_eNB_INST, DCCH);
390 391

  //rrc_rlc_data_req(Mod_id+NB_eNB_INST,frame, 0 ,DCCH,rrc_mui++,0,size,(char*)buffer);
392
  pdcp_rrc_data_req (eNB_index, Mod_id, frame, 0, DCCH, rrc_mui++, 0, size, buffer, 1);
393 394 395 396 397 398 399 400 401
}

/*------------------------------------------------------------------------------*/
int rrc_ue_decode_ccch(u8 Mod_id, u32 frame, SRB_INFO *Srb_info, u8 eNB_index){
  /*------------------------------------------------------------------------------*/

  //DL_CCCH_Message_t dlccchmsg;
  DL_CCCH_Message_t *dl_ccch_msg=NULL;//&dlccchmsg;
  asn_dec_rval_t dec_rval;
402
  int rval=0;
403 404 405 406 407 408

  vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_CCCH, VCD_FUNCTION_IN);

  //memset(dl_ccch_msg,0,sizeof(DL_CCCH_Message_t));

  //  LOG_D(RRC,"[UE %d] Decoding DL-CCCH message (%d bytes), State %d\n",Mod_id,Srb_info->Rx_buffer.payload_size,
409
  //  UE_rrc_inst[Mod_id].Info[eNB_index].State);
410 411

  dec_rval = uper_decode(NULL,
412 413 414 415
      &asn_DEF_DL_CCCH_Message,
      (void**)&dl_ccch_msg,
      (uint8_t*)Srb_info->Rx_buffer.Payload,
      100,0,0);
416 417 418 419 420

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

421
#if defined(ENABLE_ITTI)
422
# if defined(DISABLE_ITTI_XER_PRINT)
423
  {
winckel's avatar
winckel committed
424
    MessageDef *msg_p;
425

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

winckel's avatar
winckel committed
429
    itti_send_msg_to_task (TASK_UNKNOWN, Mod_id + NB_eNB_INST, msg_p);
430
  }
431 432
# else
  {
433 434
    char        message_string[10000];
    size_t      message_string_size;
435

436
    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_DL_CCCH_Message, (void *)dl_ccch_msg)) > 0)
437
    {
winckel's avatar
winckel committed
438
      MessageDef *msg_p;
439

winckel's avatar
winckel committed
440 441
      msg_p = itti_alloc_new_message_sized (TASK_RRC_UE, GENERIC_LOG, message_string_size);
      memcpy(&msg_p->ittiMsg.generic_log, message_string, message_string_size);
442

winckel's avatar
winckel committed
443
      itti_send_msg_to_task(TASK_UNKNOWN, Mod_id + NB_eNB_INST, msg_p);
444 445 446
    }
  }
# endif
447 448
#endif

449 450 451 452 453 454 455 456 457 458 459 460
  if ((dec_rval.code != RC_OK) && (dec_rval.consumed==0)) {
    LOG_E(RRC,"[UE %d] Frame %d : Failed to decode DL-CCCH-Message (%d bytes)\n",Mod_id,dec_rval.consumed);
    vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_CCCH, VCD_FUNCTION_OUT);
    return -1;
  }

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

    if (UE_rrc_inst[Mod_id].Info[eNB_index].State == RRC_SI_RECEIVED) {

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

461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504
        case DL_CCCH_MessageType__c1_PR_NOTHING:
          LOG_I(RRC, "[UE%d] Frame %d : Received PR_NOTHING on DL-CCCH-Message\n", Mod_id, frame);
          rval = 0;
          break;

        case DL_CCCH_MessageType__c1_PR_rrcConnectionReestablishment:
          LOG_D(RRC,
              "[MSC_MSG][FRAME %05d][MAC_UE][MOD %02d][][--- MAC_DATA_IND (rrcConnectionReestablishment ENB %d) --->][RRC_UE][MOD %02d][]\n", frame, Mod_id+NB_eNB_INST, eNB_index, Mod_id+NB_eNB_INST);

          LOG_I(RRC,
              "[UE%d] Frame %d : Logical Channel DL-CCCH (SRB0), Received RRCConnectionReestablishment\n", Mod_id, frame);
          rval = 0;
          break;

        case DL_CCCH_MessageType__c1_PR_rrcConnectionReestablishmentReject:
          LOG_D(RRC,
              "[MSC_MSG][FRAME %05d][MAC_UE][MOD %02d][][--- MAC_DATA_IND (RRCConnectionReestablishmentReject ENB %d) --->][RRC_UE][MOD %02d][]\n", frame, Mod_id+NB_eNB_INST, eNB_index, Mod_id+NB_eNB_INST);
          LOG_I(RRC,
              "[UE%d] Frame %d : Logical Channel DL-CCCH (SRB0), Received RRCConnectionReestablishmentReject\n", Mod_id, frame);
          rval = 0;
          break;

        case DL_CCCH_MessageType__c1_PR_rrcConnectionReject:
          LOG_D(RRC,
              "[MSC_MSG][FRAME %05d][MAC_UE][MOD %02d][][--- MAC_DATA_IND (rrcConnectionReject ENB %d) --->][RRC_UE][MOD %02d][]\n", frame, Mod_id+NB_eNB_INST, eNB_index, Mod_id+NB_eNB_INST);

          LOG_I(RRC,
              "[UE%d] Frame %d : Logical Channel DL-CCCH (SRB0), Received RRCConnectionReject \n", Mod_id, frame);
          rval = 0;
          break;

        case DL_CCCH_MessageType__c1_PR_rrcConnectionSetup:
          LOG_D(RRC,
              "[MSC_MSG][FRAME %05d][MAC_UE][MOD %02d][][--- MAC_DATA_IND (rrcConnectionSetup ENB %d) --->][RRC_UE][MOD %02d][]\n", frame, Mod_id+NB_eNB_INST, eNB_index, Mod_id+NB_eNB_INST);

          LOG_I(RRC,
              "[UE%d][RAPROC] Frame %d : Logical Channel DL-CCCH (SRB0), Received RRCConnectionSetup \n", Mod_id, frame);
          // Get configuration

          // Release T300 timer
          UE_rrc_inst[Mod_id].Info[eNB_index].T300_active = 0;
          rrc_ue_process_radioResourceConfigDedicated(Mod_id, frame, eNB_index,
              &dl_ccch_msg->message.choice.c1.choice.rrcConnectionSetup.criticalExtensions.choice.c1.choice.rrcConnectionSetup_r8.radioResourceConfigDedicated);

winckel's avatar
winckel committed
505 506
          rrc_set_state (Mod_id, RRC_STATE_CONNECTED);
          rrc_set_sub_state (Mod_id, RRC_SUB_STATE_CONNECTED);
507 508 509 510 511 512 513 514 515
          rrc_ue_generate_RRCConnectionSetupComplete(Mod_id, frame, eNB_index, dl_ccch_msg->message.choice.c1.choice.rrcConnectionSetup.rrc_TransactionIdentifier);

          rval = 0;
          break;

        default:
          LOG_E(RRC, "[UE%d] Frame %d : Unknown message\n", Mod_id, frame);
          rval = -1;
          break;
516 517 518 519 520 521 522 523
      }
    }
  }

  vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_CCCH, VCD_FUNCTION_OUT);
  return rval;
}

524 525
s32 rrc_ue_establish_srb1(u8 Mod_id,u32 frame,u8 eNB_index, struct SRB_ToAddMod *SRB_config) {
  // add descriptor from RRC PDU
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548

  u8 lchan_id = DCCH;

  UE_rrc_inst[Mod_id].Srb1[eNB_index].Active = 1;
  UE_rrc_inst[Mod_id].Srb1[eNB_index].Status = RADIO_CONFIG_OK;//RADIO CFG
  UE_rrc_inst[Mod_id].Srb1[eNB_index].Srb_info.Srb_id = 1;

    // copy default configuration for now
  //  memcpy(&UE_rrc_inst[Mod_id].Srb1[eNB_index].Srb_info.Lchan_desc[0],&DCCH_LCHAN_DESC,LCHAN_DESC_SIZE);
  //  memcpy(&UE_rrc_inst[Mod_id].Srb1[eNB_index].Srb_info.Lchan_desc[1],&DCCH_LCHAN_DESC,LCHAN_DESC_SIZE);


  LOG_I(RRC,"[UE %d], CONFIG_SRB1 %d corresponding to eNB_index %d\n", Mod_id,lchan_id,eNB_index);

  //rrc_pdcp_config_req (Mod_id+NB_eNB_INST, frame, 0, ACTION_ADD, lchan_id,UNDEF_SECURITY_MODE);
  //  rrc_rlc_config_req(Mod_id+NB_eNB_INST,frame,0,ACTION_ADD,lchan_id,SIGNALLING_RADIO_BEARER,Rlc_info_am_config);

  //  UE_rrc_inst[Mod_id].Srb1[eNB_index].Srb_info.Tx_buffer.payload_size=DEFAULT_MEAS_IND_SIZE+1;


  return(0);
}

549 550
s32 rrc_ue_establish_srb2(u8 Mod_id,u32 frame,u8 eNB_index, struct SRB_ToAddMod *SRB_config) {
  // add descriptor from RRC PDU
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574

  u8 lchan_id = DCCH1;

  UE_rrc_inst[Mod_id].Srb2[eNB_index].Active = 1;
  UE_rrc_inst[Mod_id].Srb2[eNB_index].Status = RADIO_CONFIG_OK;//RADIO CFG
  UE_rrc_inst[Mod_id].Srb2[eNB_index].Srb_info.Srb_id = 2;

    // copy default configuration for now
  //  memcpy(&UE_rrc_inst[Mod_id].Srb2[eNB_index].Srb_info.Lchan_desc[0],&DCCH_LCHAN_DESC,LCHAN_DESC_SIZE);
  //  memcpy(&UE_rrc_inst[Mod_id].Srb2[eNB_index].Srb_info.Lchan_desc[1],&DCCH_LCHAN_DESC,LCHAN_DESC_SIZE);


  LOG_I(RRC,"[UE %d], CONFIG_SRB2 %d corresponding to eNB_index %d\n",Mod_id,lchan_id,eNB_index);

  //rrc_pdcp_config_req (Mod_id+NB_eNB_INST, frame, 0, ACTION_ADD, lchan_id, UNDEF_SECURITY_MODE);
  //  rrc_rlc_config_req(Mod_id+NB_eNB_INST,frame,0,ACTION_ADD,lchan_id,SIGNALLING_RADIO_BEARER,Rlc_info_am_config);

  //  UE_rrc_inst[Mod_id].Srb1[eNB_index].Srb_info.Tx_buffer.payload_size=DEFAULT_MEAS_IND_SIZE+1;


  return(0);
}

s32 rrc_ue_establish_drb(u8 Mod_id,u32 frame,u8 eNB_index,
575
                                        struct DRB_ToAddMod *DRB_config) { // add descriptor from RRC PDU
576
#ifdef NAS_NETLINK
577
  int oip_ifup=0,ip_addr_offset3=0,ip_addr_offset4=0;
578
#endif
579

580 581
  LOG_I(RRC,"[UE %d] Frame %d: processing RRCConnectionReconfiguration: reconfiguring DRB %ld/LCID %d\n",
        Mod_id, frame, DRB_config->drb_Identity, (int)*DRB_config->logicalChannelIdentity);
582 583
  /*
  rrc_pdcp_config_req (Mod_id+NB_eNB_INST, frame, 0, ACTION_ADD,
584
                             (eNB_index * NB_RB_MAX) + *DRB_config->logicalChannelIdentity, UNDEF_SECURITY_MODE);
585 586
 
 rrc_rlc_config_req(Mod_id+NB_eNB_INST,frame,0,ACTION_ADD,
587 588
                    (eNB_index * NB_RB_MAX) + *DRB_config->logicalChannelIdentity,
                    RADIO_ACCESS_BEARER,Rlc_info_um);
589 590 591 592 593 594 595 596 597 598 599
  */
#ifdef NAS_NETLINK
#    ifdef OAI_EMU
    ip_addr_offset3 = oai_emulation.info.nb_enb_local;
    ip_addr_offset4 = NB_eNB_INST;
#    else
    ip_addr_offset3 = 0;
    ip_addr_offset4 = 8;
#    endif
#    if !defined(OAI_NW_DRIVER_TYPE_ETHERNET) && !defined(EXMIMO)
    LOG_I(OIP,"[UE %d] trying to bring up the OAI interface oai%d, IP 10.0.%d.%d\n", Mod_id, ip_addr_offset3+Mod_id,
600
          ip_addr_offset3+Mod_id+1,ip_addr_offset4+Mod_id+1);
601
    oip_ifup=nas_config(ip_addr_offset3+Mod_id,   // interface_id
602 603
                        ip_addr_offset3+Mod_id+1, // third_octet
                        ip_addr_offset4+Mod_id+1); // fourth_octet
604 605 606 607 608
    if (oip_ifup == 0 ){ // interface is up --> send a config the DRB
#        ifdef OAI_EMU
      oai_emulation.info.oai_ifup[Mod_id]=1;
#        endif
      LOG_I(OIP,"[UE %d] Config the oai%d to send/receive pkt on DRB %d to/from the protocol stack\n",
609 610 611 612 613 614 615 616 617 618 619 620
            Mod_id,
            ip_addr_offset3+Mod_id,
            (eNB_index * NB_RB_MAX) + *DRB_config->logicalChannelIdentity);

      rb_conf_ipv4(0,//add
                   Mod_id,//cx align with the UE index
                   ip_addr_offset3+Mod_id,//inst num_enb+ue_index
                   (eNB_index * NB_RB_MAX) + *DRB_config->logicalChannelIdentity,//rb
                   0,//dscp
                   ipv4_address(ip_addr_offset3+Mod_id+1,ip_addr_offset4+Mod_id+1),//saddr
                   ipv4_address(ip_addr_offset3+Mod_id+1,eNB_index+1));//daddr
      LOG_D(RRC,"[UE %d] State = Attached (eNB %d)\n",Mod_id,eNB_index);
621 622 623 624 625 626 627 628 629 630 631 632
    }
#    else
#        ifdef OAI_EMU
      oai_emulation.info.oai_ifup[Mod_id]=1;
#        endif
#    endif
#endif

  return(0);
}


633
void  rrc_ue_process_measConfig(u8 Mod_id,u32 frame, u8 eNB_index,MeasConfig_t *measConfig){
634 635 636 637 638 639 640 641 642

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

  if (measConfig->measObjectToRemoveList != NULL) {
    for (i=0;i<measConfig->measObjectToRemoveList->list.count;i++) {
      ind   = *measConfig->measObjectToRemoveList->list.array[i];
643
      free(UE_rrc_inst[Mod_id].MeasObj[eNB_index][ind-1]);
644 645 646 647 648 649 650 651 652
    }
  }
  if (measConfig->measObjectToAddModList != NULL) {
    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;

      if (UE_rrc_inst[Mod_id].MeasObj[eNB_index][ind-1]) {
653 654 655 656
        LOG_D(RRC,"Modifying measurement object %d\n",ind);
        memcpy((char*)UE_rrc_inst[Mod_id].MeasObj[eNB_index][ind-1],
            (char*)measObj,
            sizeof(MeasObjectToAddMod_t));
657 658
      }
      else {
659 660 661 662 663 664 665 666 667
        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]);
          UE_rrc_inst[Mod_id].MeasObj[eNB_index][ind-1]=measObj;
        }
668 669 670
      }
    }
    rrc_mac_config_req(Mod_id,0,0,eNB_index,
671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690
        (RadioResourceConfigCommonSIB_t *)NULL,
        (struct PhysicalConfigDedicated *)NULL,
        UE_rrc_inst[Mod_id].MeasObj[eNB_index],
        (MAC_MainConfig_t *)NULL,
        0,
        (struct LogicalChannelConfig *)NULL,
        (MeasGapConfig_t *)NULL,
        (TDD_Config_t *)NULL,
        (MobilityControlInfo_t *)NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL
#ifdef Rel10
        ,
        0,
        (MBSFN_AreaInfoList_r9_t *)NULL,
        (PMCH_InfoList_r9_t *)NULL
691 692
#endif
#ifdef CBA
693 694 695
        ,
        0,
        0
696
#endif
697
    );
698 699 700 701
  }
  if (measConfig->reportConfigToRemoveList != NULL) {
    for (i=0;i<measConfig->reportConfigToRemoveList->list.count;i++) {
      ind   = *measConfig->reportConfigToRemoveList->list.array[i];
702
      free(UE_rrc_inst[Mod_id].ReportConfig[eNB_index][ind-1]);
703 704 705 706 707 708
    }
  }
  if (measConfig->reportConfigToAddModList != NULL) {
    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;
709
      if (UE_rrc_inst[Mod_id].ReportConfig[eNB_index][ind-1]) {
710 711 712 713
        LOG_I(RRC,"Modifying Report Configuration %d\n",ind-1);
        memcpy((char*)UE_rrc_inst[Mod_id].ReportConfig[eNB_index][ind-1],
            (char*)measConfig->reportConfigToAddModList->list.array[i],
            sizeof(ReportConfigToAddMod_t));
714 715
      }
      else {
716 717
        LOG_D(RRC,"Adding Report Configuration %d %p \n",ind-1,measConfig->reportConfigToAddModList->list.array[i]);
        UE_rrc_inst[Mod_id].ReportConfig[eNB_index][ind-1] = measConfig->reportConfigToAddModList->list.array[i];
718 719 720 721 722 723 724
      }
    }
  }

  if (measConfig->quantityConfig != NULL) {
    if (UE_rrc_inst[Mod_id].QuantityConfig[eNB_index]) {
      LOG_D(RRC,"Modifying Quantity Configuration \n");
725
      memcpy((char*)UE_rrc_inst[Mod_id].QuantityConfig[eNB_index],
726 727
          (char*)measConfig->quantityConfig,
          sizeof(QuantityConfig_t));
728 729 730 731 732 733 734 735 736 737
    }
    else {
      LOG_D(RRC,"Adding Quantity configuration\n");
      UE_rrc_inst[Mod_id].QuantityConfig[eNB_index] = measConfig->quantityConfig;
    }
  }

  if (measConfig->measIdToRemoveList != NULL) {
    for (i=0;i<measConfig->measIdToRemoveList->list.count;i++) {
      ind   = *measConfig->measIdToRemoveList->list.array[i];
738
      free(UE_rrc_inst[Mod_id].MeasId[eNB_index][ind-1]);
739 740 741 742 743 744
    }
  }

  if (measConfig->measIdToAddModList != NULL) {
    for (i=0;i<measConfig->measIdToAddModList->list.count;i++) {
      ind   = measConfig->measIdToAddModList->list.array[i]->measId;
745
      if (UE_rrc_inst[Mod_id].MeasId[eNB_index][ind-1]) {
746 747 748 749
        LOG_D(RRC,"Modifying Measurement ID %d\n",ind-1);
        memcpy((char*)UE_rrc_inst[Mod_id].MeasId[eNB_index][ind-1],
            (char*)measConfig->measIdToAddModList->list.array[i],
            sizeof(MeasIdToAddMod_t));
750 751
      }
      else {
752 753
        LOG_D(RRC,"Adding Measurement ID %d %p\n",ind-1,measConfig->measIdToAddModList->list.array[i]);
        UE_rrc_inst[Mod_id].MeasId[eNB_index][ind-1] = measConfig->measIdToAddModList->list.array[i];
754 755 756 757 758 759
      }
    }
  }

  if (measConfig->measGapConfig !=NULL) {
    if (UE_rrc_inst[Mod_id].measGapConfig[eNB_index]) {
760
      memcpy((char*)UE_rrc_inst[Mod_id].measGapConfig[eNB_index],
761 762
           (char*)measConfig->measGapConfig,
                sizeof(MeasGapConfig_t));
763 764 765 766 767 768
    }
    else {
      UE_rrc_inst[Mod_id].measGapConfig[eNB_index] = measConfig->measGapConfig;
    }
  }

769 770 771 772
  if (measConfig->quantityConfig != NULL) {
    if (UE_rrc_inst[Mod_id].QuantityConfig[eNB_index]) {
      LOG_I(RRC,"Modifying Quantity Configuration \n");
      memcpy((char*)UE_rrc_inst[Mod_id].QuantityConfig[eNB_index],
773 774
          (char*)measConfig->quantityConfig,
          sizeof(QuantityConfig_t));
775 776 777 778 779 780 781 782 783 784
    }
    else {
      LOG_I(RRC,"Adding Quantity configuration\n");
      UE_rrc_inst[Mod_id].QuantityConfig[eNB_index] = measConfig->quantityConfig;
    }
    
    UE_rrc_inst[Mod_id].filter_coeff_rsrp = 1./pow(2,(*UE_rrc_inst[Mod_id].QuantityConfig[eNB_index]->quantityConfigEUTRA->filterCoefficientRSRP)/4);
    UE_rrc_inst[Mod_id].filter_coeff_rsrq = 1./pow(2,(*UE_rrc_inst[Mod_id].QuantityConfig[eNB_index]->quantityConfigEUTRA->filterCoefficientRSRQ)/4);

    LOG_I(RRC,"[UE %d] set rsrp-coeff for eNB %d: %d rsrq-coeff: %d rsrp_factor: %f rsrq_factor: %f \n",
785 786 787 788 789
        Mod_id, eNB_index, // UE_rrc_inst[Mod_id].Info[eNB_index].UE_index,
        *UE_rrc_inst[Mod_id].QuantityConfig[eNB_index]->quantityConfigEUTRA->filterCoefficientRSRP,
        *UE_rrc_inst[Mod_id].QuantityConfig[eNB_index]->quantityConfigEUTRA->filterCoefficientRSRQ,
        UE_rrc_inst[Mod_id].filter_coeff_rsrp, UE_rrc_inst[Mod_id].filter_coeff_rsrp,
        UE_rrc_inst[Mod_id].filter_coeff_rsrp, UE_rrc_inst[Mod_id].filter_coeff_rsrq);
790 791
  }

792 793 794
  if (measConfig->s_Measure != NULL) {
    UE_rrc_inst[Mod_id].s_measure = *measConfig->s_Measure;
  }
795 796 797 798 799 800 801
 
  if (measConfig->speedStatePars != NULL) {
    if (UE_rrc_inst[Mod_id].speedStatePars)
      memcpy((char*)UE_rrc_inst[Mod_id].speedStatePars,(char*)measConfig->speedStatePars,sizeof(struct MeasConfig__speedStatePars));
    else
      UE_rrc_inst[Mod_id].speedStatePars = measConfig->speedStatePars;
    LOG_I(RRC,"[UE %d] Configuring mobility optimization params for UE %d \n",
802
        Mod_id,UE_rrc_inst[Mod_id].Info[0].UE_index);
803
  }
804 805
}

806
void    
807
rrc_ue_process_radioResourceConfigDedicated(u8 Mod_id,u32 frame, u8 eNB_index,
808
                                            RadioResourceConfigDedicated_t *radioResourceConfigDedicated) {
809 810 811 812 813 814 815 816 817 818 819 820 821

  long SRB_id,DRB_id;
  int i,cnt;
  LogicalChannelConfig_t *SRB1_logicalChannelConfig,*SRB2_logicalChannelConfig;
#ifdef CBA  
  uint8_t cba_found = 0;
  uint16_t cba_RNTI;
#endif 

  // Save physicalConfigDedicated if present
  if (radioResourceConfigDedicated->physicalConfigDedicated) {
    if (UE_rrc_inst[Mod_id].physicalConfigDedicated[eNB_index]) {
      memcpy((char*)UE_rrc_inst[Mod_id].physicalConfigDedicated[eNB_index],(char*)radioResourceConfigDedicated->physicalConfigDedicated,
822
           sizeof(struct PhysicalConfigDedicated));
823 824 825 826 827 828 829 830 831 832

    }
    else {
      UE_rrc_inst[Mod_id].physicalConfigDedicated[eNB_index] = radioResourceConfigDedicated->physicalConfigDedicated;
    }
  }
  // Apply macMainConfig if present
  if (radioResourceConfigDedicated->mac_MainConfig) {
    if (radioResourceConfigDedicated->mac_MainConfig->present == RadioResourceConfigDedicated__mac_MainConfig_PR_explicitValue) {
      if (UE_rrc_inst[Mod_id].mac_MainConfig[eNB_index]) {
833 834
        memcpy((char*)UE_rrc_inst[Mod_id].mac_MainConfig[eNB_index],(char*)&radioResourceConfigDedicated->mac_MainConfig->choice.explicitValue,
             sizeof(MAC_MainConfig_t));
835 836
      }
      else
837
        UE_rrc_inst[Mod_id].mac_MainConfig[eNB_index] = &radioResourceConfigDedicated->mac_MainConfig->choice.explicitValue;
838 839 840 841 842 843 844
    }
  }

  // Apply spsConfig if present
  if (radioResourceConfigDedicated->sps_Config) {
    if (UE_rrc_inst[Mod_id].sps_Config[eNB_index]) {
      memcpy(UE_rrc_inst[Mod_id].sps_Config[eNB_index],radioResourceConfigDedicated->sps_Config,
845
           sizeof(struct SPS_Config));
846 847 848 849 850 851 852 853
    }
    else {
      UE_rrc_inst[Mod_id].sps_Config[eNB_index] = radioResourceConfigDedicated->sps_Config;
    }
  }
#ifdef CBA
  if (radioResourceConfigDedicated->cba_RNTI_vlola) {
    cba_RNTI = (uint16_t) (((radioResourceConfigDedicated->cba_RNTI_vlola->buf[1]&0xff) << 8) | 
854
                  (radioResourceConfigDedicated->cba_RNTI_vlola->buf[0]&0xff));
855 856
    for (i=0 ; i< NUM_MAX_CBA_GROUP; i++) {
      if (UE_rrc_inst[Mod_id].cba_rnti[i] == cba_RNTI ) {
857 858
        cba_found=1;
        break;
859
      } else if (UE_rrc_inst[Mod_id].cba_rnti[i] == 0 )
860
      break;
861 862 863 864 865
    }
    if (cba_found==0) {
      UE_rrc_inst[Mod_id].num_active_cba_groups++;
      UE_rrc_inst[Mod_id].cba_rnti[i]=cba_RNTI;
      LOG_D(RRC, "[UE %d] Frame %d: radioResourceConfigDedicated reveived CBA_RNTI = %x for group %d from eNB %d \n", 
866
          Mod_id,frame, UE_rrc_inst[Mod_id].cba_rnti[i], i, eNB_index);
867 868 869 870 871 872
    }
  }
#endif 
  // Establish SRBs if present
  // loop through SRBToAddModList
  if (radioResourceConfigDedicated->srb_ToAddModList) {
873 874 875 876 877 878 879 880 881
    uint8_t *kRRCenc = NULL;
    uint8_t *kRRCint = NULL;

#if defined(ENABLE_SECURITY)
    derive_key_rrc_enc(UE_rrc_inst[Mod_id].ciphering_algorithm,
                       UE_rrc_inst[Mod_id].kenb, &kRRCenc);
    derive_key_rrc_int(UE_rrc_inst[Mod_id].integrity_algorithm,
                       UE_rrc_inst[Mod_id].kenb, &kRRCint);
#endif
882 883

// Refresh SRBs
884
    rrc_pdcp_config_asn1_req(eNB_index,Mod_id,frame,0,
885 886 887 888 889 890 891 892
                             radioResourceConfigDedicated->srb_ToAddModList,
                             (DRB_ToAddModList_t*)NULL,
                             (DRB_ToReleaseList_t*)NULL,
                             UE_rrc_inst[Mod_id].ciphering_algorithm |
                             (UE_rrc_inst[Mod_id].integrity_algorithm << 4),
                             kRRCenc,
                             kRRCint,
                             NULL
893
#ifdef Rel10
894
                           ,(PMCH_InfoList_r9_t *)NULL
895
#endif
896
                            );
897 898

    // Refresh SRBs
899
    rrc_rlc_config_asn1_req(NB_eNB_INST+Mod_id,frame,0,eNB_index,
900 901 902
                            radioResourceConfigDedicated->srb_ToAddModList,
                            (DRB_ToAddModList_t*)NULL,
                            (DRB_ToReleaseList_t*)NULL
903
#ifdef Rel10
904
                            ,(PMCH_InfoList_r9_t *)NULL
905
#endif
906
    );
907 908 909 910 911 912

    for (cnt=0;cnt<radioResourceConfigDedicated->srb_ToAddModList->list.count;cnt++) {

      SRB_id = radioResourceConfigDedicated->srb_ToAddModList->list.array[cnt]->srb_Identity;
      LOG_D(RRC,"[UE %d]: Frame %d SRB config cnt %d (SRB%ld)\n",Mod_id,frame,cnt,SRB_id);
      if (SRB_id == 1) {
913 914 915 916 917 918
        if (UE_rrc_inst[Mod_id].SRB1_config[eNB_index]) {
          memcpy(UE_rrc_inst[Mod_id].SRB1_config[eNB_index],radioResourceConfigDedicated->srb_ToAddModList->list.array[cnt],
                 sizeof(struct SRB_ToAddMod));
        }
        else {
          UE_rrc_inst[Mod_id].SRB1_config[eNB_index] = radioResourceConfigDedicated->srb_ToAddModList->list.array[cnt];
919

920 921 922 923 924 925 926 927 928 929 930 931
          rrc_ue_establish_srb1(Mod_id,frame,eNB_index,radioResourceConfigDedicated->srb_ToAddModList->list.array[cnt]);
          if (UE_rrc_inst[Mod_id].SRB1_config[eNB_index]->logicalChannelConfig) {
            if (UE_rrc_inst[Mod_id].SRB1_config[eNB_index]->logicalChannelConfig->present == SRB_ToAddMod__logicalChannelConfig_PR_explicitValue) {
              SRB1_logicalChannelConfig = &UE_rrc_inst[Mod_id].SRB1_config[eNB_index]->logicalChannelConfig->choice.explicitValue;
            }
            else {
              SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
            }
          }
          else {
            SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
          }
932 933 934

      LOG_D(RRC, "[MSC_MSG][FRAME %05d][RRC_UE][MOD %02d][][--- MAC_CONFIG_REQ  (SRB1 eNB %d) --->][MAC_UE][MOD %02d][]\n",
            frame, Mod_id, eNB_index, Mod_id);
935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950
      rrc_mac_config_req(Mod_id,0,0,eNB_index,
                         (RadioResourceConfigCommonSIB_t *)NULL,
                         UE_rrc_inst[Mod_id].physicalConfigDedicated[eNB_index],
                         (MeasObjectToAddMod_t **)NULL,
                         UE_rrc_inst[Mod_id].mac_MainConfig[eNB_index],
                         1,
                         SRB1_logicalChannelConfig,
                         (MeasGapConfig_t *)NULL,
                         NULL,
                         NULL,
                         NULL,
                         NULL,
                         NULL,
                         NULL,
                         NULL,
                         NULL
951
#ifdef Rel10	       
952 953 954 955
                         ,
                         0,
                         (MBSFN_AreaInfoList_r9_t *)NULL,
                         (PMCH_InfoList_r9_t *)NULL
956 957
#endif
#ifdef CBA
958 959 960
                         ,
                         0,
                         0
961
#endif
962 963
                         );
        }
964 965
      }
      else {
966 967 968 969 970
        if (UE_rrc_inst[Mod_id].SRB2_config[eNB_index]) {
          memcpy(UE_rrc_inst[Mod_id].SRB2_config[eNB_index],radioResourceConfigDedicated->srb_ToAddModList->list.array[cnt],
                 sizeof(struct SRB_ToAddMod));
        }
        else {
971

972
          UE_rrc_inst[Mod_id].SRB2_config[eNB_index] = radioResourceConfigDedicated->srb_ToAddModList->list.array[cnt];
973

974 975 976 977 978 979 980 981 982 983 984 985 986 987
          rrc_ue_establish_srb2(Mod_id,frame,eNB_index,radioResourceConfigDedicated->srb_ToAddModList->list.array[cnt]);
          if (UE_rrc_inst[Mod_id].SRB2_config[eNB_index]->logicalChannelConfig) {
            if (UE_rrc_inst[Mod_id].SRB2_config[eNB_index]->logicalChannelConfig->present == SRB_ToAddMod__logicalChannelConfig_PR_explicitValue){
              LOG_I(RRC,"Applying Explicit SRB2 logicalChannelConfig\n");
              SRB2_logicalChannelConfig = &UE_rrc_inst[Mod_id].SRB2_config[eNB_index]->logicalChannelConfig->choice.explicitValue;
            }
            else {
              LOG_I(RRC,"Applying default SRB2 logicalChannelConfig\n");
              SRB2_logicalChannelConfig = &SRB2_logicalChannelConfig_defaultValue;
            }
          }
          else {
            SRB2_logicalChannelConfig = &SRB2_logicalChannelConfig_defaultValue;
          }
988 989 990 991

      LOG_D(RRC, "[MSC_MSG][FRAME %05d][RRC_UE][MOD %02d][][--- MAC_CONFIG_REQ  (SRB2 eNB %d) --->][MAC_UE][MOD %02d][]\n",
            frame, Mod_id, eNB_index, Mod_id);
      rrc_mac_config_req(Mod_id,0,0,eNB_index,
992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011
                         (RadioResourceConfigCommonSIB_t *)NULL,
                         UE_rrc_inst[Mod_id].physicalConfigDedicated[eNB_index],
                         (MeasObjectToAddMod_t **)NULL,
                         UE_rrc_inst[Mod_id].mac_MainConfig[eNB_index],
                         2,
                         SRB2_logicalChannelConfig,
                         UE_rrc_inst[Mod_id].measGapConfig[eNB_index],
                         (TDD_Config_t *)NULL,
                         (MobilityControlInfo_t *)NULL,
                         NULL,
                         NULL,
                         NULL,
                         NULL,
                         NULL,
                         NULL
#ifdef Rel10
                         ,
                         0,
                         (MBSFN_AreaInfoList_r9_t *)NULL,
                         (PMCH_InfoList_r9_t *)NULL
1012 1013
#endif
#ifdef CBA
1014 1015 1016
                         ,
                         0,
                         0
1017
#endif
1018 1019
                        );
        }
1020 1021 1022 1023 1024 1025
      }
    }
  }

  // Establish DRBs if present
  if (radioResourceConfigDedicated->drb_ToAddModList) {
1026
    uint8_t *kUPenc = NULL;
1027 1028 1029 1030 1031

#if defined(ENABLE_SECURITY)
    derive_key_up_enc(UE_rrc_inst[Mod_id].integrity_algorithm,
                      UE_rrc_inst[Mod_id].kenb, &kUPenc);
#endif
1032 1033

    // Refresh DRBs
1034
    rrc_pdcp_config_asn1_req(eNB_index, Mod_id,frame,0,
1035 1036 1037 1038 1039 1040 1041 1042
                             (SRB_ToAddModList_t*)NULL,
                             radioResourceConfigDedicated->drb_ToAddModList,
                             (DRB_ToReleaseList_t*)NULL,
                             UE_rrc_inst[Mod_id].ciphering_algorithm |
                             (UE_rrc_inst[Mod_id].integrity_algorithm << 4),
                             NULL,
                             NULL,
                             kUPenc
1043
#ifdef Rel10
1044
                             ,(PMCH_InfoList_r9_t *)NULL
1045
#endif
1046 1047
                            );

1048
  // Refresh DRBs
1049
    rrc_rlc_config_asn1_req(NB_eNB_INST+Mod_id,frame,0,eNB_index,
1050 1051 1052
                            (SRB_ToAddModList_t*)NULL,
                            radioResourceConfigDedicated->drb_ToAddModList,
                            (DRB_ToReleaseList_t*)NULL
1053
#ifdef Rel10
1054
                            ,(PMCH_InfoList_r9_t *)NULL
1055
#endif
1056
                            );
1057 1058 1059
    for (i=0;i<radioResourceConfigDedicated->drb_ToAddModList->list.count;i++) {
      DRB_id   = radioResourceConfigDedicated->drb_ToAddModList->list.array[i]->drb_Identity-1;
      if (UE_rrc_inst[Mod_id].DRB_config[eNB_index][DRB_id]) {
1060 1061
        memcpy(UE_rrc_inst[Mod_id].DRB_config[eNB_index][DRB_id],radioResourceConfigDedicated->drb_ToAddModList->list.array[i],
               sizeof(struct DRB_ToAddMod));
1062 1063
      }
      else {
1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090
        UE_rrc_inst[Mod_id].DRB_config[eNB_index][DRB_id] = radioResourceConfigDedicated->drb_ToAddModList->list.array[i];

        rrc_ue_establish_drb(Mod_id,frame,eNB_index,radioResourceConfigDedicated->drb_ToAddModList->list.array[i]);
        // MAC/PHY Configuration
        LOG_D(RRC, "[MSC_MSG][FRAME %05d][RRC_UE][MOD %02d][][--- MAC_CONFIG_REQ (DRB %d eNB %d) --->][MAC_UE][MOD %02d][]\n",
              frame, Mod_id, radioResourceConfigDedicated->drb_ToAddModList->list.array[i]->drb_Identity, eNB_index, Mod_id);
        rrc_mac_config_req(Mod_id,0,0,eNB_index,
                           (RadioResourceConfigCommonSIB_t *)NULL,
                           UE_rrc_inst[Mod_id].physicalConfigDedicated[eNB_index],
                           (MeasObjectToAddMod_t **)NULL,
                           UE_rrc_inst[Mod_id].mac_MainConfig[eNB_index],
                           *UE_rrc_inst[Mod_id].DRB_config[eNB_index][DRB_id]->logicalChannelIdentity,
                           UE_rrc_inst[Mod_id].DRB_config[eNB_index][DRB_id]->logicalChannelConfig,
                           UE_rrc_inst[Mod_id].measGapConfig[eNB_index],
                           (TDD_Config_t*)NULL,
                           (MobilityControlInfo_t *)NULL,
                           NULL,
                           NULL,
                           NULL,
                           NULL,
                           NULL,
                           NULL
#ifdef Rel10
                           ,
                           0,
                           (MBSFN_AreaInfoList_r9_t *)NULL,
                           (PMCH_InfoList_r9_t *)NULL
1091 1092
#endif
#ifdef CBA
1093 1094 1095
                           ,
                           UE_rrc_inst[Mod_id].num_active_cba_groups, //
                           UE_rrc_inst[Mod_id].cba_rnti[0]
1096
#endif
1097
                          );
1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153

      }
    }
  }

  UE_rrc_inst[Mod_id].Info[eNB_index].State = RRC_CONNECTED;
  LOG_I(RRC,"[UE %d] State = RRC_CONNECTED (eNB %d)\n",Mod_id,eNB_index);


}

void rrc_ue_process_securityModeCommand(uint8_t Mod_id,uint32_t frame,SecurityModeCommand_t *securityModeCommand,uint8_t eNB_index) {

  asn_enc_rval_t enc_rval;

  UL_DCCH_Message_t ul_dcch_msg;
  // SecurityModeCommand_t SecurityModeCommand;
  uint8_t buffer[200];
  int i, securityMode;
  
  LOG_I(RRC,"[UE %d] Frame %d: Receiving from SRB1 (DL-DCCH), Processing securityModeCommand (eNB %d)\n",
	Mod_id,frame,eNB_index);

  switch (securityModeCommand->criticalExtensions.choice.c1.choice.securityModeCommand_r8.securityConfigSMC.securityAlgorithmConfig.cipheringAlgorithm){
  case SecurityAlgorithmConfig__cipheringAlgorithm_eea0:
    LOG_I(RRC,"[UE %d] Security algorithm is set to eea0\n",Mod_id);
    securityMode= SecurityAlgorithmConfig__cipheringAlgorithm_eea0;
    break;
  case SecurityAlgorithmConfig__cipheringAlgorithm_eea1:
    LOG_I(RRC,"[UE %d] Security algorithm is set to eea1\n",Mod_id);
    securityMode= SecurityAlgorithmConfig__cipheringAlgorithm_eea1;
    break;
  case SecurityAlgorithmConfig__cipheringAlgorithm_eea2:
    LOG_I(RRC,"[UE %d] Security algorithm is set to eea2\n",Mod_id);
    securityMode = SecurityAlgorithmConfig__cipheringAlgorithm_eea2;
    break;
  default:
    LOG_I(RRC,"[UE %d] Security algorithm is set to none\n",Mod_id);
    securityMode = SecurityAlgorithmConfig__cipheringAlgorithm_spare1;
    break;
  }
  switch (securityModeCommand->criticalExtensions.choice.c1.choice.securityModeCommand_r8.securityConfigSMC.securityAlgorithmConfig.integrityProtAlgorithm){
  case SecurityAlgorithmConfig__integrityProtAlgorithm_eia1:
    LOG_I(RRC,"[UE %d] Integrity protection algorithm is set to eia1\n",Mod_id);
    securityMode |= 1 << 5;
    break;
  case SecurityAlgorithmConfig__integrityProtAlgorithm_eia2:
    LOG_I(RRC,"[UE %d] Integrity protection algorithm is set to eia2\n",Mod_id);
    securityMode |= 1 << 6;
    break;
  default:
    LOG_I(RRC,"[UE %d] Integrity protection algorithm is set to none\n",Mod_id);
    securityMode |= 0x70 ;
    break;
  }
  LOG_D(RRC,"[UE %d] security mode is %x \n",Mod_id, securityMode);
1154 1155 1156 1157 1158

  /* Store the parameters received */
  UE_rrc_inst[Mod_id].ciphering_algorithm = securityModeCommand->criticalExtensions.choice.c1.choice.securityModeCommand_r8.securityConfigSMC.securityAlgorithmConfig.cipheringAlgorithm;
  UE_rrc_inst[Mod_id].integrity_algorithm = securityModeCommand->criticalExtensions.choice.c1.choice.securityModeCommand_r8.securityConfigSMC.securityAlgorithmConfig.integrityProtAlgorithm;

1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175
  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;
  if (securityMode >= NO_SECURITY_MODE)
    ul_dcch_msg.message.choice.c1.present = UL_DCCH_MessageType__c1_PR_securityModeComplete;
  else 
    ul_dcch_msg.message.choice.c1.present = UL_DCCH_MessageType__c1_PR_securityModeFailure;
  
  if (securityModeCommand->criticalExtensions.present == SecurityModeCommand__criticalExtensions_PR_c1) {
    if (securityModeCommand->criticalExtensions.choice.c1.present == SecurityModeCommand__criticalExtensions__c1_PR_securityModeCommand_r8) {
    
      ul_dcch_msg.message.choice.c1.choice.securityModeComplete.rrc_TransactionIdentifier = securityModeCommand->rrc_TransactionIdentifier;
      ul_dcch_msg.message.choice.c1.choice.securityModeComplete.criticalExtensions.present = SecurityModeCommand__criticalExtensions_PR_c1;
      ul_dcch_msg.message.choice.c1.choice.securityModeComplete.criticalExtensions.choice.securityModeComplete_r8.nonCriticalExtension =NULL; 

      LOG_I(RRC,"[UE %d] Frame %d: Receiving from SRB1 (DL-DCCH), encoding securityModeComplete (eNB %d)\n",
1176
          Mod_id,frame,eNB_index);
1177 1178

      enc_rval = uper_encode_to_buffer(&asn_DEF_UL_DCCH_Message,
1179 1180 1181
          (void*)&ul_dcch_msg,
          buffer,
          100);
1182 1183 1184 1185 1186

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

1187 1188 1189 1190 1191 1192 1193 1194 1195 1196
#if defined(ENABLE_ITTI)
# if !defined(DISABLE_XER_SPRINT)
      {
        char        message_string[20000];
        size_t      message_string_size;

        if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_UL_DCCH_Message, (void *) &ul_dcch_msg)) > 0)
        {
          MessageDef *message_p;

winckel's avatar
winckel committed
1197
          message_p = itti_alloc_new_message_sized (TASK_RRC_UE, GENERIC_LOG, message_string_size);
1198 1199 1200 1201 1202 1203 1204 1205
          memcpy(&message_p->ittiMsg.generic_log, message_string, message_string_size);

          itti_send_msg_to_task(TASK_UNKNOWN, NB_eNB_INST + Mod_id, message_p);
        }
      }
# endif
#endif

1206
#ifdef USER_MODE
1207
      LOG_D(RRC, "securityModeComplete Encoded %d bits (%d bytes)\n", enc_rval.encoded, (enc_rval.encoded+7)/8);
1208
#endif
1209 1210 1211
      for (i = 0; i < (enc_rval.encoded + 7) / 8; i++)
        LOG_T(RRC, "%02x.", buffer[i]);
      LOG_T(RRC, "\n");
1212
      pdcp_rrc_data_req (eNB_index, Mod_id, frame, 0, DCCH, rrc_mui++, 0, (enc_rval.encoded + 7) / 8, buffer, 1);
1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229
    }
  }
  
}
void rrc_ue_process_ueCapabilityEnquiry(uint8_t Mod_id,uint32_t frame,UECapabilityEnquiry_t *UECapabilityEnquiry,uint8_t eNB_index) {

  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",
1230
    Mod_id,frame,eNB_index);
1231 1232 1233 1234 1235 1236 1237


  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;
1238
  ul_dcch_msg.message.choice.c1.choice.ueCapabilityInformation.rrc_TransactionIdentifier = UECapabilityEnquiry->rrc_TransactionIdentifier;
1239 1240 1241

  ue_CapabilityRAT_Container.rat_Type = RAT_Type_eutra;
  OCTET_STRING_fromBuf(&ue_CapabilityRAT_Container.ueCapabilityRAT_Container,
1242 1243
      (const char*)UE_rrc_inst[Mod_id].UECapability,
      UE_rrc_inst[Mod_id].UECapability_size);
1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255
  //  ue_CapabilityRAT_Container.ueCapabilityRAT_Container.buf  = UE_rrc_inst[Mod_id].UECapability;
  // ue_CapabilityRAT_Container.ueCapabilityRAT_Container.size = UE_rrc_inst[Mod_id].UECapability_size;
  

  if (UECapabilityEnquiry->criticalExtensions.present == UECapabilityEnquiry__criticalExtensions_PR_c1) {
    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;
      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;

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

1256 1257 1258 1259 1260
        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);
1261

1262
          enc_rval = uper_encode_to_buffer(&asn_DEF_UL_DCCH_Message, (void*) &ul_dcch_msg, buffer, 100);
1263 1264

#ifdef XER_PRINT
1265
          xer_fprint(stdout, &asn_DEF_UL_DCCH_Message, (void*)&ul_dcch_msg);
1266
#endif
1267

1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286
#if defined(ENABLE_ITTI)
# if !defined(DISABLE_XER_SPRINT)
          {
            char        message_string[20000];
            size_t      message_string_size;

            if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_UL_DCCH_Message, (void *) &ul_dcch_msg)) > 0)
            {
              MessageDef *message_p;

              message_p = itti_alloc_new_message_sized (TASK_RRC_UE, GENERIC_LOG, message_string_size);
              memcpy(&message_p->ittiMsg.generic_log, message_string, message_string_size);

              itti_send_msg_to_task(TASK_UNKNOWN, NB_eNB_INST + Mod_id, message_p);
            }
          }
# endif
#endif

1287
#ifdef USER_MODE
1288
          LOG_D(RRC,"UECapabilityInformation Encoded %d bits (%d bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);
1289
#endif
1290 1291 1292
          for (i = 0; i < (enc_rval.encoded + 7) / 8; i++)
            LOG_T(RRC, "%02x.", buffer[i]);
          LOG_T(RRC, "\n");
1293
          pdcp_rrc_data_req (eNB_index, Mod_id, frame, 0, DCCH, rrc_mui++, 0, (enc_rval.encoded + 7) / 8, buffer, 1);
1294
        }
1295 1296 1297 1298 1299
      }
    }
  }
}

1300

1301
void rrc_ue_process_rrcConnectionReconfiguration(u8 Mod_id, u32 frame,
1302 1303
                                                 RRCConnectionReconfiguration_t *rrcConnectionReconfiguration,
                                                 u8 eNB_index) {
1304

Lionel Gauthier's avatar
Lionel Gauthier committed
1305
    LOG_I(RRC,"[UE %d] Frame %d: Receiving from SRB1 (DL-DCCH), Processing RRCConnectionReconfiguration (eNB %d)\n",
1306
      Mod_id,frame,eNB_index);
Lionel Gauthier's avatar
Lionel Gauthier committed
1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324
    if (rrcConnectionReconfiguration->criticalExtensions.present == RRCConnectionReconfiguration__criticalExtensions_PR_c1) {
        if (rrcConnectionReconfiguration->criticalExtensions.choice.c1.present ==
                RRCConnectionReconfiguration__criticalExtensions__c1_PR_rrcConnectionReconfiguration_r8) {
            RRCConnectionReconfiguration_r8_IEs_t *rrcConnectionReconfiguration_r8 = &rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8;

            if (rrcConnectionReconfiguration_r8->mobilityControlInfo) {
                LOG_I(RRC,"Mobility Control Information is present\n");
                rrc_ue_process_mobilityControlInfo(Mod_id, eNB_index, frame, rrcConnectionReconfiguration_r8->mobilityControlInfo);
            }
            if (rrcConnectionReconfiguration_r8->measConfig != NULL) {
                LOG_I(RRC,"Measurement Configuration is present\n");
                rrc_ue_process_measConfig(Mod_id,frame, eNB_index,
                rrcConnectionReconfiguration_r8->measConfig);
            }
            if (rrcConnectionReconfiguration_r8->radioResourceConfigDedicated) {
                LOG_I(RRC,"Radio Resource Configuration is present\n");
                rrc_ue_process_radioResourceConfigDedicated(Mod_id,frame,eNB_index, rrcConnectionReconfiguration_r8->radioResourceConfigDedicated);
            }
1325 1326

#if defined(ENABLE_ITTI)
Lionel Gauthier's avatar
Lionel Gauthier committed
1327 1328 1329 1330 1331 1332
            /* 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;
1333

Lionel Gauthier's avatar
Lionel Gauthier committed
1334 1335 1336
                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;
1337

winckel's avatar
winckel committed
1338 1339 1340 1341
                    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;
1342

Lionel Gauthier's avatar
Lionel Gauthier committed
1343 1344
                    itti_send_msg_to_task(TASK_NAS_UE, Mod_id, msg_p);
                }
1345

Lionel Gauthier's avatar
Lionel Gauthier committed
1346 1347
                free (rrcConnectionReconfiguration_r8->dedicatedInfoNASList);
            }
1348
#ifdef ENABLE_RAL
Lionel Gauthier's avatar
Lionel Gauthier committed
1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375
            {
                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;
                connection_reestablishment_ind.ue_id            = Mod_id;
                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;

                    for (i=0;(i<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_reestablishment_ind.drb_id[i]   = rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList->list.array[i]->drb_Identity;
                    }
                } else {
                    connection_reestablishment_ind.num_drb      = 0;
                }
                if (rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->srb_ToAddModList != NULL) {
                    connection_reestablishment_ind.num_srb      = rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->srb_ToAddModList->list.count;
                } else {
                    connection_reestablishment_ind.num_srb      = 0;
                }
                memcpy (&message_ral_p->ittiMsg, (void *) &connection_reestablishment_ind, sizeof(rrc_ral_connection_reestablishment_ind_t));
                //#warning "Mod_id ? for instance ? => YES"
                LOG_I(RRC, "Sending RRC_RAL_CONNECTION_REESTABLISHMENT_IND to mRAL\n");
1376
                itti_send_msg_to_task (TASK_RAL_UE, Mod_id + NB_eNB_INST, message_ral_p);
Lionel Gauthier's avatar
Lionel Gauthier committed
1377 1378
            }
#endif
1379
#endif
Lionel Gauthier's avatar
Lionel Gauthier committed
1380 1381
        } // c1 present
    } // critical extensions present
1382 1383
}

1384
/* 36.331, 5.3.5.4      Reception of an RRCConnectionReconfiguration including the mobilityControlInfo by the UE (handover) */
1385 1386 1387
void rrc_ue_process_mobilityControlInfo(u8 eNB_index, u8 UE_id, u32 frame, struct MobilityControlInfo *mobilityControlInfo)
{
  u8 Mod_id = NB_eNB_INST + UE_id;
1388
  /*
1389 1390
  DRB_ToReleaseList_t*  drb2release_list;
  DRB_Identity_t *lcid;
1391
  */
1392
  LOG_N(RRC,"Note: This function needs some updates\n");
1393 1394 1395 1396
  if(UE_rrc_inst[UE_id].Info[eNB_index].T310_active == 1)
    UE_rrc_inst[UE_id].Info[eNB_index].T310_active = 0;
  UE_rrc_inst[UE_id].Info[eNB_index].T304_active = 1;
  UE_rrc_inst[UE_id].Info[eNB_index].T304_cnt = T304[mobilityControlInfo->t304];
1397

1398
  /*
1399 1400 1401
  drb2release_list = CALLOC (1, sizeof (*drb2release_list));
  lcid= CALLOC (1, sizeof (DRB_Identity_t)); // long
  for (*lcid=0;*lcid<NB_RB_MAX;*lcid++)
1402
  {
1403
    ASN_SEQUENCE_ADD (&(drb2release_list)->list,lcid);
1404 1405
  }
  */
1406 1407

  //Removing SRB1 and SRB2 and DRB0
1408 1409 1410
  LOG_N(RRC,"[UE %d] : Update needed for rrc_pdcp_config_req (deprecated) and rrc_rlc_config_req commands(deprecated)\n", UE_id);
  rrc_pdcp_config_req (eNB_index, UE_id, frame, 0, ACTION_REMOVE, DCCH,UNDEF_SECURITY_MODE);
  rrc_rlc_config_req(Mod_id,frame,0,ACTION_REMOVE,Mod_id+DCCH,SIGNALLING_RADIO_BEARER,Rlc_info_am_config);
1411

1412 1413
  rrc_pdcp_config_req (eNB_index, UE_id, frame, 0, ACTION_REMOVE, DCCH1,UNDEF_SECURITY_MODE);
  rrc_rlc_config_req(Mod_id,frame,0,ACTION_REMOVE,Mod_id+DCCH1,SIGNALLING_RADIO_BEARER,Rlc_info_am_config);
1414

1415 1416
  rrc_pdcp_config_req (eNB_index, UE_id, frame, 0, ACTION_REMOVE, DTCH,UNDEF_SECURITY_MODE);
  rrc_rlc_config_req(Mod_id,frame,0,ACTION_REMOVE,Mod_id+DTCH,RADIO_ACCESS_BEARER,Rlc_info_um);
1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460
  /*
  rrc_pdcp_config_asn1_req(NB_eNB_INST+Mod_id,frame, 0,eNB_index,
			   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
			   );
    
  rrc_rlc_config_asn1_req(NB_eNB_INST+Mod_id, frame,0,eNB_index,
			  NULL,// SRB_ToAddModList
			  NULL,// DRB_ToAddModList
			  drb2release_list // DRB_ToReleaseList
#ifdef Rel10
			  ,NULL
#endif 
			  );
   */
  

  //A little cleanup at RRC...
  //Copying current queue config to free RRC index
  /*
    memcpy((void *)UE_rrc_inst[Mod_id].SRB1_config[~(7<<eNB_index)],(void *)UE_rrc_inst[Mod_id].SRB1_config[7<<eNB_index],sizeof(SRB_ToAddMod_t));
    memcpy((void *)UE_rrc_inst[Mod_id].SRB2_config[~(7<<eNB_index)],(void *)UE_rrc_inst[Mod_id].SRB2_config[7<<eNB_index],sizeof(SRB_ToAddMod_t));
    memcpy((void *)UE_rrc_inst[Mod_id].DRB_config[~(7<<eNB_index)][0],(void *)UE_rrc_inst[Mod_id].DRB_config[7<<eNB_index][0],sizeof(DRB_ToAddMod_t));
  */
  /*
  LOG_N(RRC,"Not sure if Freeing the current queue config works properly: Fix me\n");
  free((void *)&UE_rrc_inst[Mod_id].SRB1_config[eNB_index]);
  free((void *)&UE_rrc_inst[Mod_id].SRB2_config[eNB_index]);
  free((void *)&UE_rrc_inst[Mod_id].DRB_config[eNB_index][0]);
 
  UE_rrc_inst[Mod_id].SRB1_config[eNB_index] = NULL;
  UE_rrc_inst[Mod_id].SRB2_config[eNB_index] = NULL;
  UE_rrc_inst[Mod_id].DRB_config[eNB_index][0] = NULL;
  */   
  //Synchronisation to DL of target cell
  LOG_D(RRC,"HO: Reset PDCP and RLC for configured RBs.. \n[MSC_MSG][FRAME %05d][RRC_UE][MOD %02d][][--- MAC_CONFIG_REQ  (SRB2 eNB %d) --->][MAC_UE][MOD %02d][]\n",
1461
      frame, Mod_id, eNB_index, Mod_id);
1462 1463 1464
  
    // Reset MAC and configure PHY
  rrc_mac_config_req(Mod_id,0,0,eNB_index,
1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483
      (RadioResourceConfigCommonSIB_t *)NULL,
      (struct PhysicalConfigDedicated *)NULL,
      (MeasObjectToAddMod_t **)NULL,
      (MAC_MainConfig_t *)NULL,
      0,
      (struct LogicalChannelConfig *)NULL,
      (MeasGapConfig_t *)NULL,
      (TDD_Config_t *)NULL,
      mobilityControlInfo,
      (u8 *)NULL,
      (u16 *)NULL,
      NULL,
      NULL,
      NULL,
      NULL
#ifdef Rel10
      ,0,
      (MBSFN_AreaInfoList_r9_t *)NULL,
      (PMCH_InfoList_r9_t *)NULL
1484 1485
#endif
#ifdef CBA
1486 1487
      ,0,
      0
1488 1489 1490 1491
#endif
		     );
  
  // Re-establish PDCP for all RBs that are established
1492 1493 1494
  // rrc_pdcp_config_req (Mod_id+NB_eNB_INST, frame, 0, ACTION_ADD, Mod_id+DCCH);
  // rrc_pdcp_config_req (Mod_id+NB_eNB_INST, frame, 0, ACTION_ADD, Mod_id+DCCH1);
  // rrc_pdcp_config_req (Mod_id+NB_eNB_INST, frame, 0, ACTION_ADD, Mod_id+DTCH);
1495 1496 1497
  
  
  // Re-establish RLC for all RBs that are established
1498 1499 1500
  // rrc_rlc_config_req(Mod_id+NB_eNB_INST,frame,0,ACTION_ADD,Mod_id+DCCH,SIGNALLING_RADIO_BEARER,Rlc_info_am_config);
  // rrc_rlc_config_req(Mod_id+NB_eNB_INST,frame,0,ACTION_ADD,Mod_id+DCCH1,SIGNALLING_RADIO_BEARER,Rlc_info_am_config);
  // rrc_rlc_config_req(Mod_id+NB_eNB_INST,frame,0,ACTION_ADD,Mod_id+DTCH,RADIO_ACCESS_BEARER,Rlc_info_um);
1501 1502 1503 1504 1505
  
  UE_rrc_inst[Mod_id].Info[eNB_index].State = RRC_SI_RECEIVED;

}
void rrc_detach_from_eNB(u8 Mod_id,u8 eNB_index) {
1506
     //UE_rrc_inst[Mod_id].DRB_config[eNB_index]
1507 1508
}

1509 1510 1511 1512 1513 1514 1515
/*------------------------------------------------------------------------------------------*/
void  rrc_ue_decode_dcch(u8 Mod_id,u32 frame,u8 Srb_id, u8 *Buffer,u8 eNB_index){
  /*------------------------------------------------------------------------------------------*/

  //DL_DCCH_Message_t dldcchmsg;
  DL_DCCH_Message_t *dl_dcch_msg=NULL;//&dldcchmsg;
  //  asn_dec_rval_t dec_rval;
1516
  // int i;
1517
  u8 target_eNB_index=0xFF;
winckel's avatar
winckel committed
1518 1519 1520 1521
#if defined(ENABLE_ITTI)
  MessageDef *msg_p;
#endif

1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536
  if (Srb_id != 1) {
    LOG_E(RRC,"[UE %d] Frame %d: Received message on DL-DCCH (SRB1), should not have ...\n",Mod_id,frame);
    return;
  }

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

  // decode messages
  //  LOG_D(RRC,"[UE %d] Decoding DL-DCCH message\n",Mod_id);
  /*
  for (i=0;i<30;i++)
    LOG_T(RRC,"%x.",Buffer[i]);
  LOG_T(RRC, "\n");
  */
  uper_decode(NULL,
1537 1538 1539 1540
      &asn_DEF_DL_DCCH_Message,
      (void**)&dl_dcch_msg,
      (uint8_t*)Buffer,
      RRC_BUF_SIZE,0,0);
1541 1542 1543 1544 1545

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

1546
#if defined(ENABLE_ITTI)
1547
# if defined(DISABLE_ITTI_XER_PRINT)
1548
  {
winckel's avatar
winckel committed
1549 1550
    msg_p = itti_alloc_new_message (TASK_RRC_UE, RRC_DL_DCCH_MESSAGE);
    memcpy (&msg_p->ittiMsg, (void *) dl_dcch_msg, sizeof(RrcDlDcchMessage));
1551

winckel's avatar
winckel committed
1552
    itti_send_msg_to_task (TASK_UNKNOWN, Mod_id + NB_eNB_INST, msg_p);
1553
  }
1554 1555
# else
  {
1556 1557
    char        message_string[20000];
    size_t      message_string_size;
1558

1559
    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_DL_DCCH_Message, (void *)dl_dcch_msg)) > 0)
1560
    {
winckel's avatar
winckel committed
1561 1562
      msg_p = itti_alloc_new_message_sized (TASK_RRC_UE, GENERIC_LOG, message_string_size);
      memcpy(&msg_p->ittiMsg.generic_log, message_string, message_string_size);
1563

winckel's avatar
winckel committed
1564
      itti_send_msg_to_task(TASK_UNKNOWN, Mod_id + NB_eNB_INST, msg_p);
1565 1566 1567
    }
  }
# endif
1568 1569
#endif

1570 1571
  if (dl_dcch_msg->message.present == DL_DCCH_MessageType_PR_c1) {

1572
    if (UE_rrc_inst[Mod_id].Info[eNB_index].State >= RRC_CONNECTED) {
1573 1574 1575

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

1576 1577 1578
        case DL_DCCH_MessageType__c1_PR_NOTHING:
          LOG_I(RRC, "[UE %d] Frame %d : Received PR_NOTHING on DL-DCCH-Message\n", Mod_id, frame);
          return;
winckel's avatar
RRC:  
winckel committed
1579

1580 1581 1582 1583
        case DL_DCCH_MessageType__c1_PR_csfbParametersResponseCDMA2000:
          break;

        case DL_DCCH_MessageType__c1_PR_dlInformationTransfer: {
winckel's avatar
RRC:  
winckel committed
1584
#if defined(ENABLE_ITTI)
1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608
          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);
            NAS_DOWNLINK_DATA_IND(msg_p).UEid = Mod_id; // TODO set the UEid to something else ?
            NAS_DOWNLINK_DATA_IND(msg_p).nasMsg.length = pdu_length;
            NAS_DOWNLINK_DATA_IND(msg_p).nasMsg.data = pdu_buffer;

            itti_send_msg_to_task(TASK_NAS_UE, Mod_id + NB_eNB_INST, msg_p);
          }
winckel's avatar
RRC:  
winckel committed
1609
#endif
1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650
          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)*/
            if (UE_rrc_inst[Mod_id].HandoverInfoUe.targetCellId
                != dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.mobilityControlInfo->targetPhysCellId) {
              LOG_W(RRC,
                  "[UE %d] Frame %d: Handover target (%d) is different from RSRP measured target (%d)..\n", Mod_id, frame, dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.mobilityControlInfo->targetPhysCellId, UE_rrc_inst[Mod_id].HandoverInfoUe.targetCellId);
              return;
            }
            else
              if ((target_eNB_index = get_adjacent_cell_mod_id(UE_rrc_inst[Mod_id].HandoverInfoUe.targetCellId))
                  == 0xFF) {
                LOG_W(RRC,
                    "[UE %d] Frame %d: Mod_id of the target eNB not found, check the network topology\n", Mod_id, frame);
                return;
              }
              else {
                LOG_I(RRC,
                    "[UE% d] Frame %d: Received rrcConnectionReconfiguration with mobilityControlInfo \n", Mod_id, frame);
                UE_rrc_inst[Mod_id].HandoverInfoUe.measFlag = 1; // Ready to send more MeasReports if required
              }
          }
          rrc_ue_process_rrcConnectionReconfiguration(Mod_id, frame,
              &dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration, eNB_index);
          if (target_eNB_index != 0xFF) {
            rrc_ue_generate_RRCConnectionReconfigurationComplete(Mod_id, frame, target_eNB_index,
                dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.rrc_TransactionIdentifier);
            UE_rrc_inst[Mod_id].Info[eNB_index].State = RRC_HO_EXECUTION;
            UE_rrc_inst[Mod_id].Info[target_eNB_index].State = RRC_RECONFIGURED;
            LOG_I(RRC, "[UE %d] State = RRC_RECONFIGURED during HO (eNB %d)\n", Mod_id, target_eNB_index);
Lionel Gauthier's avatar
Lionel Gauthier committed
1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678
#if defined(ENABLE_ITTI)
#ifdef ENABLE_RAL
            {
                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));
                connection_reconfiguration_ho_ind.ue_id = Mod_id;
                if (dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList != NULL) {
                    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;
                }
                if (dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->srb_ToAddModList != NULL) {
                    connection_reconfiguration_ho_ind.num_srb      = dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->srb_ToAddModList->list.count;
                } else {
                    connection_reconfiguration_ho_ind.num_srb      = 0;
                }
                memcpy (&message_ral_p->ittiMsg, (void *) &connection_reconfiguration_ho_ind, sizeof(rrc_ral_connection_reconfiguration_ho_ind_t));
                //#warning "Mod_id ? for instance ? => YES"
                LOG_I(RRC, "Sending RRC_RAL_CONNECTION_REESTABLISHMENT_HO_IND to mRAL\n");
1679
                itti_send_msg_to_task (TASK_RAL_UE, Mod_id + NB_eNB_INST, message_ral_p);
Lionel Gauthier's avatar
Lionel Gauthier committed
1680 1681 1682
            }
#endif
#endif
1683 1684 1685 1686 1687 1688
          }
          else {
            rrc_ue_generate_RRCConnectionReconfigurationComplete(Mod_id, frame, eNB_index,
                dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.rrc_TransactionIdentifier);
            UE_rrc_inst[Mod_id].Info[eNB_index].State = RRC_RECONFIGURED;
            LOG_I(RRC, "[UE %d] State = RRC_RECONFIGURED (eNB %d)\n", Mod_id, eNB_index);
Lionel Gauthier's avatar
Lionel Gauthier committed
1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716
#if defined(ENABLE_ITTI)
#ifdef ENABLE_RAL
            {
                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));
                connection_reconfiguration_ind.ue_id = Mod_id;
                if (dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList != NULL) {
                    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;
                }
                if (dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->srb_ToAddModList != NULL) {
                    connection_reconfiguration_ind.num_srb      = dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->srb_ToAddModList->list.count;
                } else {
                    connection_reconfiguration_ind.num_srb      = 0;
                }
                memcpy (&message_ral_p->ittiMsg, (void *) &connection_reconfiguration_ind, sizeof(rrc_ral_connection_reconfiguration_ind_t));
                //#warning "Mod_id ? for instance ? => YES"
                LOG_I(RRC, "Sending RRC_RAL_CONNECTION_REESTABLISHMENT_IND to mRAL\n");
1717
                itti_send_msg_to_task (TASK_RAL_UE, Mod_id + NB_eNB_INST, message_ral_p);
Lionel Gauthier's avatar
Lionel Gauthier committed
1718 1719 1720 1721
            }
#endif
#endif

1722 1723 1724 1725
          }
          break;

        case DL_DCCH_MessageType__c1_PR_rrcConnectionRelease:
1726 1727 1728 1729 1730 1731 1732 1733 1734
#if defined(ENABLE_ITTI)
          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
1735

1736 1737
          itti_send_msg_to_task(TASK_NAS_UE, Mod_id + NB_eNB_INST, msg_p);
#endif
1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753
          break;

        case DL_DCCH_MessageType__c1_PR_securityModeCommand:
          LOG_I(RRC, "[UE %d] Received securityModeCommand (eNB %d)\n", Mod_id, eNB_index);
          rrc_ue_process_securityModeCommand(Mod_id, frame, &dl_dcch_msg->message.choice.c1.choice.securityModeCommand,
              eNB_index);
          break;

        case DL_DCCH_MessageType__c1_PR_ueCapabilityEnquiry:
          LOG_I(RRC, "[UE %d] Received Capability Enquiry (eNB %d)\n", Mod_id, eNB_index);
          rrc_ue_process_ueCapabilityEnquiry(Mod_id, frame, &dl_dcch_msg->message.choice.c1.choice.ueCapabilityEnquiry,
              eNB_index);
          break;

        case DL_DCCH_MessageType__c1_PR_counterCheck:
          break;
winckel's avatar
RRC:  
winckel committed
1754

1755
#ifdef Rel10
winckel's avatar
winckel committed
1756
        case DL_DCCH_MessageType__c1_PR_ueInformationRequest_r9:
1757
          break;
winckel's avatar
winckel committed
1758
        case DL_DCCH_MessageType__c1_PR_loggedMeasurementConfiguration_r10:
1759
          break;
winckel's avatar
winckel committed
1760
        case DL_DCCH_MessageType__c1_PR_rnReconfiguration_r10:
1761
          break;
1762
#endif
1763 1764 1765 1766 1767 1768 1769 1770 1771

        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;
1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786
      }
    }
  }
#ifndef NO_RRM
    send_msg(&S_rrc,msg_rrc_end_scan_req(Mod_id,eNB_index));
#endif
}

const char siWindowLength[7][5] = {"1ms\0","2ms\0","5ms\0","10ms\0","15ms\0","20ms\0","40ms\0"};
const char siWindowLength_int[7] = {1,2,5,10,15,20,40};

const char SIBType[16][6] ={"SIB3\0","SIB4\0","SIB5\0","SIB6\0","SIB7\0","SIB8\0","SIB9\0","SIB10\0","SIB11\0","SIB12\0","SIB13\0","Sp2\0","Sp3\0","Sp4\0"};
const char SIBPeriod[7][7]= {"80ms\0","160ms\0","320ms\0","640ms\0","1280ms\0","2560ms\0","5120ms\0"};
int siPeriod_int[7] = {80,160,320,640,1280,2560,5120};

1787
int decode_BCCH_DLSCH_Message(u8 Mod_id,u32 frame,u8 eNB_index,u8 *Sdu,u8 Sdu_len, u8 rsrq, u8 rsrp) {
1788 1789 1790 1791 1792 1793 1794

  //BCCH_DL_SCH_Message_t bcch_message;
  BCCH_DL_SCH_Message_t *bcch_message=NULL;//_ptr=&bcch_message;
  SystemInformationBlockType1_t **sib1=&UE_rrc_inst[Mod_id].sib1[eNB_index];
  SystemInformation_t **si=UE_rrc_inst[Mod_id].si[eNB_index];
  asn_dec_rval_t dec_rval;
  uint32_t si_window;//, sib1_decoded=0, si_decoded=0;
1795
  // int i;
1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807

  vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_BCCH, VCD_FUNCTION_IN);


  if ((UE_rrc_inst[Mod_id].Info[eNB_index].SIB1Status == 1) &&
      (UE_rrc_inst[Mod_id].Info[eNB_index].SIStatus == 1)) {
    // Avoid decoding to prevent memory bloating
    vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_BCCH, VCD_FUNCTION_OUT);
    return 0;
  } 
  else {

winckel's avatar
winckel committed
1808 1809
    rrc_set_sub_state (Mod_id, RRC_SUB_STATE_IDLE_RECEIVING_SIB);

1810 1811 1812 1813 1814 1815 1816
    //memset(&bcch_message,0,sizeof(BCCH_DL_SCH_Message_t));
    //  LOG_D(RRC,"[UE %d] Decoding DL_BCCH_DLSCH_Message\n",Mod_id)
    /*
    for (i=0;i<Sdu_len;i++)
      printf("%x.",Sdu[i]);
      printf("\n");*/
    dec_rval = uper_decode_complete(NULL,
1817 1818 1819 1820
        &asn_DEF_BCCH_DL_SCH_Message,
        (void **)&bcch_message,
        (const void *)Sdu,
        Sdu_len);//,0,0);
1821 1822 1823 1824 1825 1826 1827 1828 1829
    
    if ((dec_rval.code != RC_OK) && (dec_rval.consumed==0)) {
      LOG_E(RRC,"[UE %d] Failed to decode BCCH_DLSCH_MESSAGE (%d bits)\n",Mod_id,dec_rval.consumed);
      //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;
    }
    //  xer_fprint(stdout,  &asn_DEF_BCCH_DL_SCH_Message, (void*)&bcch_message);
1830 1831

#if defined(ENABLE_ITTI)
1832
# if defined(DISABLE_ITTI_XER_PRINT)
winckel's avatar
winckel committed
1833 1834
    {
      MessageDef *msg_p;
1835

winckel's avatar
winckel committed
1836 1837
      msg_p = itti_alloc_new_message (TASK_RRC_UE, RRC_DL_BCCH_MESSAGE);
      memcpy (&msg_p->ittiMsg, (void *) bcch_message, sizeof(RrcDlBcchMessage));
1838

winckel's avatar
winckel committed
1839 1840
      itti_send_msg_to_task (TASK_UNKNOWN, Mod_id + NB_eNB_INST, msg_p);
    }
1841 1842
# else
    {
winckel's avatar
winckel committed
1843 1844
      char        message_string[15000];
      size_t      message_string_size;
1845

winckel's avatar
winckel committed
1846 1847 1848
      if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_BCCH_DL_SCH_Message, (void *)bcch_message)) > 0)
      {
        MessageDef *msg_p;
1849

winckel's avatar
winckel committed
1850 1851 1852 1853 1854
        msg_p = itti_alloc_new_message_sized (TASK_RRC_UE, GENERIC_LOG, message_string_size);
        memcpy(&msg_p->ittiMsg.generic_log, message_string, message_string_size);

        itti_send_msg_to_task(TASK_UNKNOWN, Mod_id + NB_eNB_INST, msg_p);
      }
1855 1856
    }
# endif
1857 1858
#endif

1859 1860
    if (bcch_message->message.present == BCCH_DL_SCH_MessageType_PR_c1) {
      switch (bcch_message->message.choice.c1.present) {
1861 1862 1863 1864 1865 1866 1867 1868 1869 1870
        case BCCH_DL_SCH_MessageType__c1_PR_systemInformationBlockType1:
          if ((frame %2) == 0) {
            if (UE_rrc_inst[Mod_id].Info[eNB_index].SIB1Status == 0) {
              memcpy((void*)*sib1,
                  (void*)&bcch_message->message.choice.c1.choice.systemInformationBlockType1,
                  sizeof(SystemInformationBlockType1_t));
              LOG_D(RRC,"[UE %d] Decoding First SIB1\n",Mod_id);
              decode_SIB1(Mod_id, eNB_index, rsrq, rsrp);
              //mac_xface->macphy_exit("after decode_SIB1");
            }
1871
          }
1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892
          break;

        case BCCH_DL_SCH_MessageType__c1_PR_systemInformation:
          if ((UE_rrc_inst[Mod_id].Info[eNB_index].SIB1Status == 1) &&
              (UE_rrc_inst[Mod_id].Info[eNB_index].SIStatus == 0)) {
            //                                                if ((frame %8) == 1) {  // check only in odd frames for SI
            si_window = (frame%(UE_rrc_inst[Mod_id].Info[eNB_index].SIperiod/10))/(UE_rrc_inst[Mod_id].Info[eNB_index].SIwindowsize/10);
            memcpy((void*)si[si_window],
                (void*)&bcch_message->message.choice.c1.choice.systemInformation,
                sizeof(SystemInformation_t));
            LOG_D(RRC,"[UE %d] Decoding SI for frame %d, si_window %d\n",Mod_id,frame,si_window);
            decode_SI(Mod_id,frame,eNB_index,si_window);
            //mac_xface->macphy_exit("after decode_SI");

            //                                }
          }
          break;

        case BCCH_DL_SCH_MessageType__c1_PR_NOTHING:
        default:
          break;
1893 1894 1895
      }
    }
  }
winckel's avatar
winckel committed
1896

1897 1898 1899 1900 1901
  if ((rrc_get_sub_state(Mod_id) == RRC_SUB_STATE_IDLE_SIB_COMPLETE)
# if defined(ENABLE_USE_MME)
&& (UE_rrc_inst[Mod_id].initialNasMsg.data != NULL)
#endif
  ) {
winckel's avatar
winckel committed
1902 1903 1904 1905 1906 1907
    rrc_ue_generate_RRCConnectionRequest(Mod_id, frame, 0);
    LOG_I(RRC, "not sending connection request\n");

    rrc_set_sub_state (Mod_id, RRC_SUB_STATE_IDLE_CONNECTING);
  }

1908 1909 1910 1911
  /*  if ((UE_rrc_inst[Mod_id].Info[eNB_index].SIB1Status == 1) &&
      (UE_rrc_inst[Mod_id].Info[eNB_index].SIStatus == 1) && (frame >= Mod_id * 20 + 10))
      SEQUENCE_free(&asn_DEF_BCCH_DL_SCH_Message, (void*)bcch_message, 0);*/
  vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_BCCH, VCD_FUNCTION_OUT);
1912 1913

  return 0;
1914 1915 1916
}


1917
int decode_SIB1(u8 Mod_id,u8 eNB_index, u8 rsrq, u8 rsrp) {
1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939
  SystemInformationBlockType1_t **sib1=&UE_rrc_inst[Mod_id].sib1[eNB_index];
  int i;

  vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_UE_DECODE_SIB1, VCD_FUNCTION_IN);

  LOG_D(RRC,"[UE %d] : Dumping SIB 1\n",Mod_id);

  //  xer_fprint(stdout,&asn_DEF_SystemInformationBlockType1, (void*)*sib1);

  LOG_D(RRC,"cellAccessRelatedInfo.cellIdentity : %x.%x.%x.%x\n",
      (*sib1)->cellAccessRelatedInfo.cellIdentity.buf[0],
      (*sib1)->cellAccessRelatedInfo.cellIdentity.buf[1],
      (*sib1)->cellAccessRelatedInfo.cellIdentity.buf[2],
      (*sib1)->cellAccessRelatedInfo.cellIdentity.buf[3]);

  LOG_D(RRC,"cellSelectionInfo.q_RxLevMin       : %d\n",(int)(*sib1)->cellSelectionInfo.q_RxLevMin);
  LOG_D(RRC,"freqBandIndicator                  : %d\n",(int)(*sib1)->freqBandIndicator);
  LOG_D(RRC,"siWindowLength                     : %s\n",siWindowLength[(*sib1)->si_WindowLength]);
  if ((*sib1)->schedulingInfoList.list.count>0) {
    for (i=0;i<(*sib1)->schedulingInfoList.list.count;i++) {
      LOG_D(RRC,"siSchedulingInfoPeriod[%d]          : %s\n",i,SIBPeriod[(int)(*sib1)->schedulingInfoList.list.array[i]->si_Periodicity]);
      if ((*sib1)->schedulingInfoList.list.array[i]->sib_MappingInfo.list.count>0)
1940
        LOG_D(RRC,"siSchedulingInfoSIBType[%d]         : %s\n",i,SIBType[(int)(*(*sib1)->schedulingInfoList.list.array[i]->sib_MappingInfo.list.array[0])]);
1941
      else {
1942
        LOG_W(RRC,"mapping list %d is null\n",i);
1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961
      }
    }
  }
  else {
   LOG_E(RRC,"siSchedulingInfoPeriod[0]          : PROBLEM!!!\n");
   return -1;
  }

  if ((*sib1)->tdd_Config) {
    LOG_D(RRC,"TDD subframe assignment            : %d\n",(int)(*sib1)->tdd_Config->subframeAssignment);
    LOG_D(RRC,"S-Subframe Config                  : %d\n",(int)(*sib1)->tdd_Config->specialSubframePatterns);
  }

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

  rrc_mac_config_req(Mod_id,0,0,eNB_index,
1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980
      (RadioResourceConfigCommonSIB_t *)NULL,
      (struct PhysicalConfigDedicated *)NULL,
      (MeasObjectToAddMod_t **)NULL,
      (MAC_MainConfig_t *)NULL,
      0,
      (struct LogicalChannelConfig *)NULL,
      (MeasGapConfig_t *)NULL,
      UE_rrc_inst[Mod_id].sib1[eNB_index]->tdd_Config,
      (MobilityControlInfo_t *) NULL,
      &UE_rrc_inst[Mod_id].Info[eNB_index].SIwindowsize,
      &UE_rrc_inst[Mod_id].Info[eNB_index].SIperiod,
      NULL,
      NULL,
      NULL,
      (MBSFN_SubframeConfigList_t *)NULL
#ifdef Rel10
      ,0,
      (MBSFN_AreaInfoList_r9_t *)NULL,
      (PMCH_InfoList_r9_t *)NULL
1981 1982
#endif
#ifdef CBA
1983 1984 1985
      ,
      0,
      0
1986
#endif
1987
  );
1988 1989

  UE_rrc_inst[Mod_id].Info[eNB_index].SIB1Status = 1;
1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048
  UE_rrc_inst[Mod_id].Info[eNB_index].SIB1systemInfoValueTag = (*sib1)->systemInfoValueTag;

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

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

      plmn_number = (*sib1)->cellAccessRelatedInfo.plmn_IdentityList.list.count;

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

        plmn_Identity = &(*sib1)->cellAccessRelatedInfo.plmn_IdentityList.list.array[plmn]->plmn_Identity;
        if (((plmn_Identity->mcc == NULL)
             ||
             ((UE_rrc_inst[Mod_id].plmnID.MCCdigit1 == *(plmn_Identity->mcc->list.array[0])) &&
              (UE_rrc_inst[Mod_id].plmnID.MCCdigit2 == *(plmn_Identity->mcc->list.array[1])) &&
              (UE_rrc_inst[Mod_id].plmnID.MCCdigit3 == *(plmn_Identity->mcc->list.array[2]))))
            &&
            (UE_rrc_inst[Mod_id].plmnID.MNCdigit1 == *(plmn_Identity->mnc.list.array[0])) &&
            (UE_rrc_inst[Mod_id].plmnID.MNCdigit2 == *(plmn_Identity->mnc.list.array[1])) &&
            (((UE_rrc_inst[Mod_id].plmnID.MNCdigit3 == 0xf) && (plmn_Identity->mnc.list.count == 2))
             ||
             (UE_rrc_inst[Mod_id].plmnID.MNCdigit3 == *(plmn_Identity->mnc.list.array[2])))) {
          /* 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;
          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);
          NAS_CELL_SELECTION_CNF (msg_p).rat = 0xFF;
          NAS_CELL_SELECTION_CNF (msg_p).rsrq = rsrq;
          NAS_CELL_SELECTION_CNF (msg_p).rsrp = rsrp;

          itti_send_msg_to_task(TASK_NAS_UE, Mod_id + NB_eNB_INST, msg_p);
          cell_valid = 1;
          break;
        }
      }
    }

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

      msg_p = itti_alloc_new_message(TASK_RRC_UE, PHY_FIND_NEXT_CELL_REQ);

      itti_send_msg_to_task(TASK_PHY_UE, Mod_id + NB_eNB_INST, msg_p);
    }
  }
#endif

2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129
  vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_UE_DECODE_SIB1, VCD_FUNCTION_OUT);
  return 0;

}


void dump_sib2(SystemInformationBlockType2_t *sib2) {

  LOG_D(RRC,"radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.numberOfRA_Preambles : %ld\n",
      sib2->radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.numberOfRA_Preambles);

  //  if (radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.preamblesGroupAConfig)
  //msg("radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.preamblesGroupAConfig ",sib2->radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.preamblesGroupAConfig = NULL;

  LOG_D(RRC,"[UE]radioResourceConfigCommon.rach_ConfigCommon.powerRampingParameters.powerRampingStep : %ld\n",sib2->radioResourceConfigCommon.rach_ConfigCommon.powerRampingParameters.powerRampingStep);

  LOG_D(RRC,"[UE]radioResourceConfigCommon.rach_ConfigCommon.powerRampingParameters.preambleInitialReceivedTargetPower : %ld\n",sib2->radioResourceConfigCommon.rach_ConfigCommon.powerRampingParameters.preambleInitialReceivedTargetPower);

  LOG_D(RRC,"radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.preambleTransMax  : %ld\n",sib2->radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.preambleTransMax);

  LOG_D(RRC,"radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.ra_ResponseWindowSize : %ld\n",sib2->radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.ra_ResponseWindowSize);

  LOG_D(RRC,"radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.mac_ContentionResolutionTimer : %ld\n",sib2->radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.mac_ContentionResolutionTimer);

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

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

  // PDSCH-Config
  LOG_D(RRC,"radioResourceConfigCommon.pdsch_ConfigCommon.referenceSignalPower  : %ld\n",sib2->radioResourceConfigCommon.pdsch_ConfigCommon.referenceSignalPower);
  LOG_D(RRC,"radioResourceConfigCommon.pdsch_ConfigCommon.p_b : %ld\n",sib2->radioResourceConfigCommon.pdsch_ConfigCommon.p_b);

  // PUSCH-Config
  LOG_D(RRC,"radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.n_SB  : %ld\n",sib2->radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.n_SB);
  LOG_D(RRC,"radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.hoppingMode  : %ld\n",sib2->radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.hoppingMode);
  LOG_D(RRC,"radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.pusch_HoppingOffset : %ld\n",sib2->radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.pusch_HoppingOffset);
  LOG_D(RRC,"radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.enable64QAM : %d\n",(int)sib2->radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.enable64QAM);
  LOG_D(RRC,"radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.groupHoppingEnabled : %d\n",(int)sib2->radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.groupHoppingEnabled);
  LOG_D(RRC,"radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH : %ld\n",sib2->radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH);
  LOG_D(RRC,"radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled : %d\n",(int)sib2->radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled);
  LOG_D(RRC,"radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.cyclicShift : %ld\n",sib2->radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.cyclicShift);

  // PUCCH-Config

  LOG_D(RRC,"radioResourceConfigCommon.pucch_ConfigCommon.deltaPUCCH_Shift : %ld\n",sib2->radioResourceConfigCommon.pucch_ConfigCommon.deltaPUCCH_Shift);
  LOG_D(RRC,"radioResourceConfigCommon.pucch_ConfigCommon.nRB_CQI : %ld\n",sib2->radioResourceConfigCommon.pucch_ConfigCommon.nRB_CQI);
  LOG_D(RRC,"radioResourceConfigCommon.pucch_ConfigCommon.nCS_AN : %ld\n",sib2->radioResourceConfigCommon.pucch_ConfigCommon.nCS_AN);
  LOG_D(RRC,"radioResourceConfigCommon.pucch_ConfigCommon.n1PUCCH_AN : %ld\n",sib2->radioResourceConfigCommon.pucch_ConfigCommon.n1PUCCH_AN);

  LOG_D(RRC,"radioResourceConfigCommon.soundingRS_UL_ConfigCommon.present : %d\n",sib2-> radioResourceConfigCommon.soundingRS_UL_ConfigCommon.present);


  // uplinkPowerControlCommon

  LOG_D(RRC,"radioResourceConfigCommon.uplinkPowerControlCommon.p0_NominalPUSCH : %ld\n",sib2->radioResourceConfigCommon.uplinkPowerControlCommon.p0_NominalPUSCH);
  LOG_D(RRC,"radioResourceConfigCommon.uplinkPowerControlCommon.alpha : %ld\n",sib2->radioResourceConfigCommon.uplinkPowerControlCommon.alpha);

  LOG_D(RRC,"radioResourceConfigCommon.uplinkPowerControlCommon.p0_NominalPUCCH : %ld\n",sib2->radioResourceConfigCommon.uplinkPowerControlCommon.p0_NominalPUCCH);
  LOG_D(RRC,"radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format1 : %ld\n",sib2->radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format1);
  LOG_D(RRC,"radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format1b :%ld\n",sib2->radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format1b);
  LOG_D(RRC,"radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format2  :%ld\n",sib2->radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format2);
  LOG_D(RRC,"radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format2a :%ld\n",sib2->radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format2a);
  LOG_D(RRC,"radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format2b :%ld\n",sib2->radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format2b);

  LOG_D(RRC,"radioResourceConfigCommon.uplinkPowerControlCommon.deltaPreambleMsg3 : %ld\n",sib2->radioResourceConfigCommon.uplinkPowerControlCommon.deltaPreambleMsg3);

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

  LOG_D(RRC,"ue_TimersAndConstants.t300 : %ld\n", sib2->ue_TimersAndConstants.t300);
  LOG_D(RRC,"ue_TimersAndConstants.t301 : %ld\n", sib2->ue_TimersAndConstants.t301);
  LOG_D(RRC,"ue_TimersAndConstants.t310 : %ld\n", sib2->ue_TimersAndConstants.t310);
  LOG_D(RRC,"ue_TimersAndConstants.n310 : %ld\n", sib2->ue_TimersAndConstants.n310);
  LOG_D(RRC,"ue_TimersAndConstants.t311 : %ld\n", sib2->ue_TimersAndConstants.t311);
  LOG_D(RRC,"ue_TimersAndConstants.n311 : %ld\n", sib2->ue_TimersAndConstants.n311);

  LOG_D(RRC,"freqInfo.additionalSpectrumEmission : %ld\n",sib2->freqInfo.additionalSpectrumEmission);
2130 2131 2132
  LOG_D(RRC,"freqInfo.ul_CarrierFreq : %p\n", sib2->freqInfo.ul_CarrierFreq);
  LOG_D(RRC,"freqInfo.ul_Bandwidth : %p\n", sib2->freqInfo.ul_Bandwidth);
  LOG_D(RRC,"mbsfn_SubframeConfigList : %p\n", sib2->mbsfn_SubframeConfigList);
2133
  LOG_D(RRC,"timeAlignmentTimerCommon : %ld\n", sib2->timeAlignmentTimerCommon);
2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150
}

void dump_sib3(SystemInformationBlockType3_t *sib3) {

}

#ifdef Rel10
void dump_sib13(SystemInformationBlockType13_r9_t *sib13) {

  LOG_D(RRC,"[RRC][UE] Dumping SIB13\n");
  LOG_D(RRC,"[RRC][UE] dumping sib13 second time\n");
  LOG_D(RRC,"[RRC][UE] NotificationRepetitionCoeff-r9 : %ld\n", sib13->notificationConfig_r9.notificationRepetitionCoeff_r9);
  LOG_D(RRC,"[RRC][UE] NotificationOffset-r9 : %d\n", (int)sib13->notificationConfig_r9.notificationOffset_r9);
  LOG_D(RRC,"[RRC][UE] NotificationSF-Index-r9 : %d\n", (int)sib13->notificationConfig_r9.notificationSF_Index_r9);

}
#endif
winckel's avatar
winckel committed
2151

2152 2153 2154 2155 2156
//const char SIBPeriod[7][7]= {"80ms\0","160ms\0","320ms\0","640ms\0","1280ms\0","2560ms\0","5120ms\0"};
int decode_SI(u8 Mod_id,u32 frame,u8 eNB_index,u8 si_window) {

  SystemInformation_t **si=&UE_rrc_inst[Mod_id].si[eNB_index][si_window];
  int i;
2157
  struct SystemInformation_r8_IEs_sib_TypeAndInfo_Member *typeandinfo;
2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175

  vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_UE_DECODE_SI  , VCD_FUNCTION_IN);

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

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

    switch(typeandinfo->present) {
2176
    case SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib2:
2177 2178 2179 2180 2181 2182
      UE_rrc_inst[Mod_id].sib2[eNB_index] = &typeandinfo->choice.sib2;
      LOG_D(RRC,"[UE %d] Frame %d Found SIB2 from eNB %d\n",Mod_id,frame,eNB_index);
      dump_sib2(UE_rrc_inst[Mod_id].sib2[eNB_index]);
      LOG_D(RRC, "[MSC_MSG][FRAME %05d][RRC_UE][MOD %02d][][--- MAC_CONFIG_REQ (SIB2 params  eNB %d) --->][MAC_UE][MOD %02d][]\n",
            frame, Mod_id, eNB_index, Mod_id);
      rrc_mac_config_req(Mod_id,0,0,eNB_index,
winckel's avatar
winckel committed
2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201
                         &UE_rrc_inst[Mod_id].sib2[eNB_index]->radioResourceConfigCommon,
                         (struct PhysicalConfigDedicated *)NULL,
                         (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[Mod_id].sib2[eNB_index]->freqInfo.ul_CarrierFreq,
                         UE_rrc_inst[Mod_id].sib2[eNB_index]->freqInfo.ul_Bandwidth,
                         &UE_rrc_inst[Mod_id].sib2[eNB_index]->freqInfo.additionalSpectrumEmission,
                         UE_rrc_inst[Mod_id].sib2[eNB_index]->mbsfn_SubframeConfigList
#ifdef Rel10
                         ,0,
                         (MBSFN_AreaInfoList_r9_t *)NULL,
                         (PMCH_InfoList_r9_t *)NULL
2202 2203
#endif
#ifdef CBA
winckel's avatar
winckel committed
2204 2205
                         ,0,
                         0
2206
#endif
winckel's avatar
winckel committed
2207
                         );
2208 2209
      UE_rrc_inst[Mod_id].Info[eNB_index].SIStatus = 1;
      // After SI is received, prepare RRCConnectionRequest
2210 2211 2212
#ifdef Rel10
      if (UE_rrc_inst[Mod_id].MBMS_flag < 3) // see -Q option
#endif
winckel's avatar
winckel committed
2213
#if !(defined(ENABLE_ITTI) && defined(ENABLE_USE_MME))
2214
      rrc_ue_generate_RRCConnectionRequest(Mod_id,frame,eNB_index);
2215
      LOG_I(RRC, "not sending connection request\n");
winckel's avatar
winckel committed
2216
#endif
2217 2218

      if (UE_rrc_inst[Mod_id].Info[eNB_index].State == RRC_IDLE) {
2219 2220 2221 2222 2223 2224 2225 2226 2227
          LOG_I(RRC,"[UE %d] Received SIB1/SIB2/SIB3 Switching to RRC_SI_RECEIVED\n",Mod_id);
          UE_rrc_inst[Mod_id].Info[eNB_index].State = RRC_SI_RECEIVED;
#ifdef ENABLE_RAL
          {
              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));
Lionel Gauthier's avatar
Lionel Gauthier committed
2228 2229 2230 2231 2232 2233 2234
              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;
2235
              ral_si_ind.dbm            = 0;
Lionel Gauthier's avatar
Lionel Gauthier committed
2236 2237
              //ral_si_ind.dbm            = fifo_dump_emos_UE.PHY_measurements->rx_rssi_dBm[eNB_index];
              // TO DO
2238
              ral_si_ind.sinr           = 0;
Lionel Gauthier's avatar
Lionel Gauthier committed
2239 2240
              //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
2241 2242 2243
              ral_si_ind.link_data_rate = 0;
              memcpy (&message_ral_p->ittiMsg, (void *) &ral_si_ind, sizeof(rrc_ral_system_information_ind_t));
#warning "Mod_id ? for instance ?"
2244
              itti_send_msg_to_task (TASK_RAL_UE, Mod_id + NB_eNB_INST, message_ral_p);
2245 2246
          }
#endif
2247 2248
      }
      break;
2249
    case SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib3:
2250 2251 2252 2253
      UE_rrc_inst[Mod_id].sib3[eNB_index] = &typeandinfo->choice.sib3;
      LOG_I(RRC,"[UE %d] Frame %d Found SIB3 from eNB %d\n",Mod_id,frame,eNB_index);
      dump_sib3(UE_rrc_inst[Mod_id].sib3[eNB_index]);
      UE_rrc_inst[Mod_id].Info[eNB_index].SIStatus = 1;
winckel's avatar
winckel committed
2254 2255

      rrc_set_sub_state (Mod_id, RRC_SUB_STATE_IDLE_SIB_COMPLETE);
2256
      break;
2257
    case SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib4:
2258 2259 2260
      UE_rrc_inst[Mod_id].sib4[eNB_index] = &typeandinfo->choice.sib4;
      LOG_I(RRC,"[UE %d] Frame %d Found SIB4 from eNB %d\n",Mod_id,frame,eNB_index);
      break;
2261
    case SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib5:
2262 2263 2264
      UE_rrc_inst[Mod_id].sib5[eNB_index] = &typeandinfo->choice.sib5;
      LOG_I(RRC,"[UE %d] Found SIB5 from eNB %d\n",Mod_id,eNB_index);
      break;
2265
    case SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib6:
2266 2267 2268
      UE_rrc_inst[Mod_id].sib6[eNB_index] = &typeandinfo->choice.sib6;
      LOG_I(RRC,"[UE %d] Found SIB6 from eNB %d\n",Mod_id,eNB_index);
      break;
2269
    case SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib7:
2270 2271 2272
      UE_rrc_inst[Mod_id].sib7[eNB_index] = &typeandinfo->choice.sib7;
      LOG_I(RRC,"[UE %d] Found SIB7 from eNB %d\n",Mod_id,eNB_index);
      break;
2273
    case SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib8:
2274 2275 2276
      UE_rrc_inst[Mod_id].sib8[eNB_index] = &typeandinfo->choice.sib8;
      LOG_I(RRC,"[UE %d] Found SIB8 from eNB %d\n",Mod_id,eNB_index);
      break;
2277
    case SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib9:
2278 2279 2280
      UE_rrc_inst[Mod_id].sib9[eNB_index] = &typeandinfo->choice.sib9;
      LOG_I(RRC,"[UE %d] Found SIB9 from eNB %d\n",Mod_id,eNB_index);
      break;
2281
    case SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib10:
2282 2283 2284
      UE_rrc_inst[Mod_id].sib10[eNB_index] = &typeandinfo->choice.sib10;
      LOG_I(RRC,"[UE %d] Found SIB10 from eNB %d\n",Mod_id,eNB_index);
      break;
2285
    case SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib11:
2286 2287 2288 2289
      UE_rrc_inst[Mod_id].sib11[eNB_index] = &typeandinfo->choice.sib11;
      LOG_I(RRC,"[UE %d] Found SIB11 from eNB %d\n",Mod_id,eNB_index);
      break;
#ifdef Rel10
2290
    case SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib12_v920:
2291 2292 2293
      UE_rrc_inst[Mod_id].sib12[eNB_index] = &typeandinfo->choice.sib12_v920;
      LOG_I(RRC,"[RRC][UE %d] Found SIB12 from eNB %d\n",Mod_id,eNB_index);
      break;
2294
    case SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib13_v920:
2295 2296 2297 2298 2299 2300 2301
      UE_rrc_inst[Mod_id].sib13[eNB_index] = &typeandinfo->choice.sib13_v920;
      LOG_I(RRC,"[RRC][UE %d] Found SIB13 from eNB %d\n",Mod_id,eNB_index);
      dump_sib13(UE_rrc_inst[Mod_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, "[MSC_MSG][FRAME %05d][RRC_UE][MOD %02d][][--- MAC_CONFIG_REQ (SIB13 params eNB %d) --->][MAC_UE][MOD %02d][]\n",
            frame, Mod_id, eNB_index, Mod_id);
      rrc_mac_config_req(Mod_id,0,0,eNB_index,
winckel's avatar
winckel committed
2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319
                         (RadioResourceConfigCommonSIB_t *)NULL,
                         (struct PhysicalConfigDedicated *)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[Mod_id].sib13[eNB_index]->mbsfn_AreaInfoList_r9,
                         (PMCH_InfoList_r9_t *)NULL
2320
#ifdef CBA
winckel's avatar
winckel committed
2321 2322
                         ,0,
                         0
2323
#endif
winckel's avatar
winckel committed
2324
                         );
2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337
      UE_rrc_inst[Mod_id].Info[eNB_index].SIStatus = 1;
      break;
#endif
    default:
      break;
    }

  }

  vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_UE_DECODE_SI  , VCD_FUNCTION_OUT);
  return 0;
}

2338 2339 2340 2341 2342 2343 2344 2345 2346 2347
// layer 3 filtering of RSRP (EUTRA) measurements: 36.331, Sec. 5.5.3.2
void ue_meas_filtering(u8 Mod_id,u32 frame,u8 eNB_index){
  float a = UE_rrc_inst[Mod_id].filter_coeff_rsrp; // 'a' in 36.331 Sec. 5.5.3.2
  float a1 = UE_rrc_inst[Mod_id].filter_coeff_rsrq;
  //float rsrp_db, rsrq_db;
  u8 eNB_offset;

  if(UE_rrc_inst[Mod_id].QuantityConfig[0] != NULL) { // Only consider 1 serving cell (index: 0)
    if (UE_rrc_inst[Mod_id].QuantityConfig[0]->quantityConfigEUTRA != NULL) {
      if(UE_rrc_inst[Mod_id].QuantityConfig[0]->quantityConfigEUTRA->filterCoefficientRSRP != NULL) {
winckel's avatar
winckel committed
2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361
        for (eNB_offset = 0;eNB_offset<1+mac_xface->get_n_adj_cells(Mod_id);eNB_offset++) {
          //filter_factor = 1/power(2,*UE_rrc_inst[Mod_id].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",
          //	Mod_id,frame,mac_xface->get_RSRP(Mod_id,eNB_offset),mac_xface->get_rx_total_gain_dB(Mod_id),mac_xface->lte_frame_parms->N_RB_DL);
          UE_rrc_inst[Mod_id].rsrp_db[eNB_offset] = (dB_fixed_times10(mac_xface->get_RSRP(Mod_id,eNB_offset))/10.0)-mac_xface->get_rx_total_gain_dB(Mod_id)-dB_fixed(mac_xface->lte_frame_parms->N_RB_DL*12);
          UE_rrc_inst[Mod_id].rsrp_db_filtered[eNB_offset] = (1.0-a)*UE_rrc_inst[Mod_id].rsrp_db_filtered[eNB_offset] +  a*UE_rrc_inst[Mod_id].rsrp_db[eNB_offset];
          //mac_xface->set_RSRP_filtered(Mod_id,eNB_offset,UE_rrc_inst[Mod_id].rsrp_db_filtered[eNB_offset]);

          LOG_D(RRC,"[UE %d] Frame %d: Meas RSRP: eNB_offset: %d rsrp_coef: %3.2f filter_coef: %d before L3 filtering: rsrp: %3.1f after L3 filtering: rsrp: %3.1f \n ",
            Mod_id, frame, eNB_offset,a,
            *UE_rrc_inst->QuantityConfig[0]->quantityConfigEUTRA->filterCoefficientRSRP,
            UE_rrc_inst[Mod_id].rsrp_db[eNB_offset],
            UE_rrc_inst[Mod_id].rsrp_db_filtered[eNB_offset]);
        }
2362 2363 2364 2365
      }
    }
    else {
      for (eNB_offset = 0;eNB_offset<1+mac_xface->get_n_adj_cells(Mod_id);eNB_offset++) {
2366 2367 2368
        UE_rrc_inst[Mod_id].rsrp_db_filtered[eNB_offset]= mac_xface->get_RSRP(Mod_id,eNB_offset);
        // phy_vars_ue->PHY_measurements.rsrp_filtered[eNB_offset]=UE_rrc_inst[Mod_id].rsrp_db_filtered[eNB_offset];
        //mac_xface->set_RSRP_filtered(Mod_id,eNB_offset,UE_rrc_inst[Mod_id].rsrp_db_filtered[eNB_offset]);
2369 2370 2371 2372
      }
    }
    if (UE_rrc_inst[Mod_id].QuantityConfig[0]->quantityConfigEUTRA != NULL) {
      if(UE_rrc_inst[Mod_id].QuantityConfig[0]->quantityConfigEUTRA->filterCoefficientRSRQ != NULL) {
winckel's avatar
winckel committed
2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387
        for (eNB_offset = 0;eNB_offset<1+mac_xface->get_n_adj_cells(Mod_id);eNB_offset++) {
          // LOG_N(RRC,"[UE %d] Frame %d : check if this operation workes properly in abstraction mode\n",Mod_id,frame);
          UE_rrc_inst[Mod_id].rsrq_db[eNB_offset] = (10*log10(mac_xface->get_RSRQ(Mod_id,eNB_offset)))-20;
          UE_rrc_inst[Mod_id].rsrq_db_filtered[eNB_offset]=(1-a1)*UE_rrc_inst[Mod_id].rsrq_db_filtered[eNB_offset] + a1 *UE_rrc_inst[Mod_id].rsrq_db[eNB_offset];
          //mac_xface->set_RSRP_filtered(Mod_id,eNB_offset,UE_rrc_inst[Mod_id].rsrp_db_filtered[eNB_offset]);
          /*
          LOG_D(RRC,"[UE %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 ",
            Mod_id, eNB_offset,
            a1,
            *UE_rrc_inst->QuantityConfig[0]->quantityConfigEUTRA->filterCoefficientRSRQ,
            mac_xface->get_RSRQ(Mod_id,eNB_offset),
            UE_rrc_inst[Mod_id].rsrq_db[eNB_offset],
            UE_rrc_inst[Mod_id].rsrq_db_filtered[eNB_offset]);
          */
        }
2388 2389 2390 2391
      }
    }
    else{
      for (eNB_offset = 0;eNB_offset<1+mac_xface->get_n_adj_cells(Mod_id);eNB_offset++) {
winckel's avatar
winckel committed
2392
          UE_rrc_inst[Mod_id].rsrq_db_filtered[eNB_offset]= mac_xface->get_RSRQ(Mod_id,eNB_offset);
2393 2394 2395 2396 2397
      }
    } 
  }
}

2398
//Below routine implements Measurement Reporting procedure from 36.331 Section 5.5.5
2399
void rrc_ue_generate_MeasurementReport(u8 eNB_id, u8 UE_id, u32 frame) {
2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411

  u8 buffer[32], size;
  u8 i;
  u8 target_eNB_offset;
  MeasId_t measId;
  PhysCellId_t cellId, targetCellId;
  long rsrq_s,rsrp_t,rsrq_t;
  long rsrp_s, nElem, nElem1;
  float rsrp_filtered, rsrq_filtered;
  nElem = 100;
  nElem1 = 33;
  static u32 pframe=0;
2412
  int result;
2413
  target_eNB_offset = UE_rrc_inst[UE_id].Info[0].handoverTarget; // eNB_offset of target eNB: used to obtain the mod_id of target eNB
2414 2415

  for (i=0;i<MAX_MEAS_ID;i++) {
2416 2417
    if (UE_rrc_inst[UE_id].measReportList[0][i] != NULL) {
      measId = UE_rrc_inst[UE_id].measReportList[0][i]->measId;
2418 2419

      // Note: Values in the meas report have to be the mapped values...to implement binary search for LUT
2420
      rsrp_filtered = UE_rrc_inst[UE_id].rsrp_db_filtered[eNB_id];//nid_cell];
2421 2422
      rsrp_s = binary_search_float(RSRP_meas_mapping,nElem, rsrp_filtered); //mapped RSRP of serving cell

2423
      rsrq_filtered = UE_rrc_inst[UE_id].rsrq_db_filtered[eNB_id];//nid_cell]; //RSRQ of serving cell
2424 2425 2426
      rsrq_s = binary_search_float(RSRQ_meas_mapping,nElem1,rsrp_filtered);//mapped RSRQ of serving cell

      LOG_D(RRC,"[UE %d] Frame %d: source eNB %d :rsrp_s: %d rsrq_s: %d tmp: %f tmp1: %f \n",
2427
          UE_id, frame, eNB_id, rsrp_s,rsrq_s,rsrp_filtered,rsrq_filtered);
2428

2429 2430
      rsrp_t = binary_search_float(RSRP_meas_mapping,nElem,UE_rrc_inst[UE_id].rsrp_db_filtered[target_eNB_offset]); //RSRP of target cell
      rsrq_t = binary_search_float(RSRQ_meas_mapping,nElem1,UE_rrc_inst[UE_id].rsrq_db_filtered[target_eNB_offset]); //RSRQ of target cell
2431 2432

      //  if (measFlag == 1) {
2433 2434
      cellId = get_adjacent_cell_id(UE_id, eNB_id); //PhycellId of serving cell
      targetCellId = UE_rrc_inst[UE_id].HandoverInfoUe.targetCellId ;//get_adjacent_cell_id(Mod_id,target_eNB_offset); //PhycellId of target cell
2435 2436 2437

      if (pframe!=frame){
        pframe=frame;
2438
        size = do_MeasurementReport(UE_id, buffer,measId,targetCellId,rsrp_s,rsrq_s,rsrp_t,rsrq_t);
2439 2440 2441 2442 2443
        LOG_D(RRC, "[UE %d] Frame %d: Sending MeasReport: servingCell(%d) targetCell(%d) rsrp_s(%d) rsrq_s(%d) rsrp_t(%d) rsrq_t(%d) \n",
              UE_id, frame, cellId,targetCellId,rsrp_s,rsrq_s,rsrp_t,rsrq_t);
        LOG_I(RRC, "[UE %d] Frame %d : Generating Measurement Report for eNB %d\n", UE_id, frame, eNB_id);
        LOG_D(RLC, "[MSC_MSG][FRAME %05d][RRC_UE][UE %02d][][--- PDCP_DATA_REQ/%d Bytes (MeasurementReport to eNB %d MUI %d) --->][PDCP][MOD %02d][RB %02d]\n",
              frame, UE_id, size, eNB_id, rrc_mui, eNB_id, DCCH);
2444 2445
        result = pdcp_data_req(eNB_id, UE_id, frame, 0, DCCH, rrc_mui++, 0, size, buffer, 1);
        AssertFatal (result == TRUE, "PDCP data request failed!\n");
2446 2447 2448 2449 2450 2451 2452 2453
        //LOG_D(RRC, "[UE %d] Frame %d Sending MeasReport (%d bytes) through DCCH%d to PDCP \n",Mod_id,frame, size, DCCH);
      }
      //          measFlag = 0; //re-setting measFlag so that no more MeasReports are sent in this frame
      //          }
    }
  }
}

2454 2455 2456
// Measurement report triggering, described in 36.331 Section 5.5.4.1: called periodically 
void ue_measurement_report_triggering(u8 Mod_id, u32 frame,u8 eNB_index) {
  u8 i,j;
2457 2458
  Hysteresis_t   hys;
  TimeToTrigger_t        ttt_ms;
2459 2460
  Q_OffsetRange_t ofn;
  Q_OffsetRange_t ocn;
2461 2462
  Q_OffsetRange_t ofs = 0;
  Q_OffsetRange_t ocs = 0;
2463 2464 2465
  long            a3_offset;
  MeasObjectId_t  measObjId;
  ReportConfigId_t reportConfigId;
2466 2467 2468 2469
  
  for(i=0 ; i<NB_CNX_UE ; i++) {
    for(j=0 ; j<MAX_MEAS_ID ; j++) {
      if(UE_rrc_inst[Mod_id].MeasId[i][j] != NULL) {
winckel's avatar
winckel committed
2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534
        measObjId = UE_rrc_inst[Mod_id].MeasId[i][j]->measObjectId;
        reportConfigId = UE_rrc_inst[Mod_id].MeasId[i][j]->reportConfigId;
        if( /*UE_rrc_inst[Mod_id].MeasId[i][j] != NULL && */ UE_rrc_inst[Mod_id].MeasObj[i][measObjId-1] != NULL) {
          if(UE_rrc_inst[Mod_id].MeasObj[i][measObjId-1]->measObject.present == MeasObjectToAddMod__measObject_PR_measObjectEUTRA) {
            /* 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 */
            //    LOG_I(RRC,"event %d %d %p \n", measObjId,reportConfigId, UE_rrc_inst[Mod_id].ReportConfig[i][reportConfigId-1]);
            if((UE_rrc_inst[Mod_id].ReportConfig[i][reportConfigId-1] != NULL) &&
               (UE_rrc_inst[Mod_id].ReportConfig[i][reportConfigId-1]->reportConfig.present==ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA) &&
               (UE_rrc_inst[Mod_id].ReportConfig[i][reportConfigId-1]->reportConfig.choice.reportConfigEUTRA.triggerType.present == ReportConfigEUTRA__triggerType_PR_event)) {
              hys = UE_rrc_inst[Mod_id].ReportConfig[i][reportConfigId-1]->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.hysteresis;
              //LOG_N(RRC,"[UE%d] Frame %d Check below lines for segfault :), Fix me \n",Mod_id, frame);
              ttt_ms = timeToTrigger_ms[UE_rrc_inst[Mod_id].ReportConfig[i][reportConfigId-1]->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.timeToTrigger];
              // Freq specific offset of neighbor cell freq
              ofn = ((UE_rrc_inst[Mod_id].MeasObj[i][measObjId-1]->measObject.choice.measObjectEUTRA.offsetFreq != NULL) ?
                 *UE_rrc_inst[Mod_id].MeasObj[i][measObjId-1]->measObject.choice.measObjectEUTRA.offsetFreq : 15); //  /* 15 is the Default */
              // cellIndividualOffset of neighbor cell - not defined yet
              ocn = 0;
              a3_offset = UE_rrc_inst[Mod_id].ReportConfig[i][reportConfigId-1]->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA3.a3_Offset;

              switch (UE_rrc_inst[Mod_id].ReportConfig[i][reportConfigId-1]->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present) {
              case ReportConfigEUTRA__triggerType__event__eventId_PR_eventA1:
            LOG_D(RRC,"[UE %d] Frame %d : A1 event: check if serving becomes better than threshold\n",Mod_id, frame);
            break;
              case ReportConfigEUTRA__triggerType__event__eventId_PR_eventA2:
            LOG_D(RRC,"[UE %d] Frame %d : A2 event, check if serving becomes worse than a threshold\n",Mod_id, frame);
            break;
              case ReportConfigEUTRA__triggerType__event__eventId_PR_eventA3:
            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",Mod_id, frame);
            if ((check_trigger_meas_event(Mod_id,frame,eNB_index,i,j,ofn,ocn,hys,ofs,ocs,a3_offset,ttt_ms)) &&
                (UE_rrc_inst[Mod_id].Info[0].State >= RRC_CONNECTED) &&
                (UE_rrc_inst[Mod_id].Info[0].T304_active == 0 )      &&
                (UE_rrc_inst[Mod_id].HandoverInfoUe.measFlag == 1)) {
              //trigger measurement reporting procedure (36.331, section 5.5.5)
              if (UE_rrc_inst[Mod_id].measReportList[i][j] == NULL) {
                UE_rrc_inst[Mod_id].measReportList[i][j] = malloc(sizeof(MEAS_REPORT_LIST));
              }
              UE_rrc_inst[Mod_id].measReportList[i][j]->measId = UE_rrc_inst[Mod_id].MeasId[i][j]->measId;
              UE_rrc_inst[Mod_id].measReportList[i][j]->numberOfReportsSent = 0;
              rrc_ue_generate_MeasurementReport(Mod_id,frame,eNB_index);
              UE_rrc_inst[Mod_id].HandoverInfoUe.measFlag = 1;
              LOG_I(RRC,"[UE %d] Frame %d: A3 event detected, state: %d \n", Mod_id, frame, UE_rrc_inst[Mod_id].Info[0].State);
            }
            else {
              if(UE_rrc_inst[Mod_id].measReportList[i][j] != NULL){
                free(UE_rrc_inst[Mod_id].measReportList[i][j]);
              }
              UE_rrc_inst[Mod_id].measReportList[i][j] = NULL;
            }
            break;
              case ReportConfigEUTRA__triggerType__event__eventId_PR_eventA4:
            LOG_D(RRC,"[UE %d] Frame %d : received an A4 event, neighbor becomes offset better than a threshold\n",Mod_id, frame);
            break;
              case ReportConfigEUTRA__triggerType__event__eventId_PR_eventA5:
            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",Mod_id, frame);
            break;
              default:
            LOG_D(RRC,"Invalid ReportConfigEUTRA__triggerType__event__eventId: %d",
                  UE_rrc_inst[Mod_id].ReportConfig[i][j]->reportConfig.choice.reportConfigEUTRA.triggerType.present);
            break;
              }
            }
          }
        }
2535 2536 2537 2538 2539 2540 2541
      }
    }
  }
}

//check_trigger_meas_event(Mod_id, frame, eNB_index, i,j,ofn,ocn,hys,ofs,ocs,a3_offset,ttt_ms)
u8 check_trigger_meas_event(u8 Mod_id,u32 frame, u8 eNB_index, u8 ue_cnx_index, u8 meas_index, 
winckel's avatar
winckel committed
2542 2543
                            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) {
2544 2545 2546 2547
  u8 eNB_offset;
  u8 currentCellIndex = mac_xface->lte_frame_parms->Nid_cell;
  
  LOG_I(RRC,"ofn(%d) ocn(%d) hys(%d) ofs(%d) ocs(%d) a3_offset(%d) ttt(%d) rssi %3.1f\n", \
winckel's avatar
winckel committed
2548
        ofn,ocn,hys,ofs,ocs,a3_offset,ttt,10*log10(mac_xface->get_RSSI(Mod_id))-mac_xface->get_rx_total_gain_dB(Mod_id));
2549 2550 2551 2552 2553 2554 2555
  
  //  for (eNB_offset = 0;(eNB_offset<1+mac_xface->get_n_adj_cells(Mod_id))&& (eNB_offset!=eNB_index);eNB_offset++) {
  for (eNB_offset = 1;(eNB_offset<1+mac_xface->get_n_adj_cells(Mod_id));eNB_offset++) {
    /* RHS: Verify that idx 0 corresponds to currentCellIndex in rsrp array */
    if(UE_rrc_inst[Mod_id].rsrp_db_filtered[eNB_offset]+ofn+ocn-hys > UE_rrc_inst[Mod_id].rsrp_db_filtered[0/*eNB_index*/]+ofs+ocs - 1 /*+a3_offset*/) {
      UE_rrc_inst->measTimer[ue_cnx_index][meas_index][eNB_offset-1] += 2; //Called every subframe = 2ms
      LOG_D(RRC,"[UE %d] Frame %d: Entry measTimer[%d][%d]: %d currentCell: %d betterCell: %d \n", 
2556
          Mod_id, frame, ue_cnx_index,meas_index,UE_rrc_inst->measTimer[ue_cnx_index][meas_index][eNB_offset-1],currentCellIndex,eNB_offset);
2557 2558 2559 2560
    }
    else {
      UE_rrc_inst->measTimer[ue_cnx_index][meas_index][eNB_offset-1] = 0; //Exit condition: Resetting the measurement timer
      LOG_D(RRC,"[UE %d] Frame %d: Exit measTimer[%d][%d]: %d currentCell: %d betterCell: %d \n", 
2561
          Mod_id, frame, ue_cnx_index,meas_index,UE_rrc_inst->measTimer[ue_cnx_index][meas_index][eNB_offset-1],currentCellIndex,eNB_offset);
2562 2563 2564 2565
    }
    if (UE_rrc_inst->measTimer[ue_cnx_index][meas_index][eNB_offset-1] >= ttt) {
      UE_rrc_inst->HandoverInfoUe.targetCellId = get_adjacent_cell_id(Mod_id,eNB_offset-1); //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", \
winckel's avatar
winckel committed
2566 2567 2568 2569
            Mod_id, frame, eNB_index,
            UE_rrc_inst->HandoverInfoUe.targetCellId,ue_cnx_index,eNB_offset,
            (dB_fixed_times10(UE_rrc_inst[Mod_id].rsrp_db[0])/10.0)-mac_xface->get_rx_total_gain_dB(Mod_id)-dB_fixed(mac_xface->lte_frame_parms->N_RB_DL*12),
            (dB_fixed_times10(UE_rrc_inst[Mod_id].rsrp_db[eNB_offset])/10.0)-mac_xface->get_rx_total_gain_dB(Mod_id)-dB_fixed(mac_xface->lte_frame_parms->N_RB_DL*12));
2570 2571 2572 2573 2574 2575 2576
      UE_rrc_inst->Info[0].handoverTarget = eNB_offset;
      return 1;
    }
  }
  return 0;
}

2577
#ifdef Rel10
2578
int decode_MCCH_Message(u8 Mod_id, u32 frame, u8 eNB_index, u8 *Sdu, u8 Sdu_len,u8 mbsfn_sync_area) {
2579 2580 2581 2582 2583
  
  MCCH_Message_t *mcch=NULL;
  MBSFNAreaConfiguration_r9_t **mcch_message=&UE_rrc_inst[Mod_id].mcch_message[eNB_index];
  asn_dec_rval_t dec_rval;
  
2584 2585
  if (UE_rrc_inst[Mod_id].Info[eNB_index].MCCHStatus[mbsfn_sync_area] == 1) {
    LOG_D(RRC,"[UE %d] Frame %d: MCCH MESSAGE for MBSFN sync area %d has been already received!\n",
2586
      Mod_id, frame, mbsfn_sync_area);
2587 2588 2589 2590
    return 0; // avoid decoding to prevent memory bloating
  }
  else {
    dec_rval = uper_decode_complete(NULL,
winckel's avatar
winckel committed
2591 2592 2593 2594
                                    &asn_DEF_MCCH_Message,
                                    (void **)&mcch,
                                    (const void *)Sdu,
                                    Sdu_len);
2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605
    if ((dec_rval.code != RC_OK) && (dec_rval.consumed==0)) {
      LOG_E(RRC,"[UE %d] Failed to decode MCCH__MESSAGE (%d bits)\n",Mod_id,dec_rval.consumed);
      //free the memory
      SEQUENCE_free(&asn_DEF_MCCH_Message, (void*)mcch, 1);
      return -1;
    }
#ifdef XER_PRINT
    xer_fprint(stdout, &asn_DEF_MCCH_Message, (void*)mcch);
#endif

    if (mcch->message.present == MCCH_MessageType_PR_c1) {
2606
      LOG_D(RRC,"[UE %d] Found mcch message \n",Mod_id);
2607
      if(mcch->message.choice.c1.present == MCCH_MessageType__c1_PR_mbsfnAreaConfiguration_r9) {
winckel's avatar
winckel committed
2608 2609 2610 2611 2612 2613 2614
        /*
        memcpy((void*)*mcch_message,
               (void*)&mcch->message.choice.c1.choice.mbsfnAreaConfiguration_r9,
               sizeof(MBSFNAreaConfiguration_r9_t)); */
        *mcch_message = &mcch->message.choice.c1.choice.mbsfnAreaConfiguration_r9;
        LOG_I(RRC,"[UE %d] Frame %d : Found MBSFNAreaConfiguration from eNB %d \n",Mod_id, frame, eNB_index);
        decode_MBSFNAreaConfiguration(Mod_id,eNB_index,frame, mbsfn_sync_area);
2615 2616 2617 2618 2619 2620 2621

      }
    }
  }
  return 0;
}

2622 2623 2624
void decode_MBSFNAreaConfiguration(u8 Mod_id, u8 eNB_index, u32 frame,u8 mbsfn_sync_area) {
  LOG_D(RRC,"[UE %d] Frame %d : Number of MCH(s) in the MBSFN Sync Area %d  is %d\n", 
	Mod_id, frame, mbsfn_sync_area, UE_rrc_inst[Mod_id].mcch_message[eNB_index]->pmch_InfoList_r9.list.count);
2625 2626
  //  store to MAC/PHY necessary parameters for receiving MTCHs
  rrc_mac_config_req(Mod_id,0,0,eNB_index,
winckel's avatar
winckel committed
2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641
                     (RadioResourceConfigCommonSIB_t *)NULL,
                     (struct PhysicalConfigDedicated *)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
2642
#ifdef Rel10	       
winckel's avatar
winckel committed
2643 2644 2645 2646
                     ,
                     0,
                     (MBSFN_AreaInfoList_r9_t *)NULL,
                     &UE_rrc_inst[Mod_id].mcch_message[eNB_index]->pmch_InfoList_r9
2647 2648
#endif
#ifdef CBA
winckel's avatar
winckel committed
2649 2650 2651
                     ,
                     0,
                     0
2652
#endif
winckel's avatar
winckel committed
2653
                     );
2654

2655 2656
  UE_rrc_inst[Mod_id].Info[eNB_index].MCCHStatus[mbsfn_sync_area] = 1;
  
2657
  // Config Radio Bearer for MBMS user data (similar way to configure for eNB side in init_MBMS function)
2658
  rrc_pdcp_config_asn1_req(eNB_index, Mod_id, frame, 0,
winckel's avatar
winckel committed
2659 2660 2661 2662 2663 2664 2665
                           NULL, // SRB_ToAddModList
                           NULL, // DRB_ToAddModList
                           (DRB_ToReleaseList_t*)NULL,
                           0, // security mode
                           NULL, // key rrc encryption
                           NULL, // key rrc integrity
                           NULL // key encryption
2666
#ifdef Rel10
winckel's avatar
winckel committed
2667
                           ,&(UE_rrc_inst[Mod_id].mcch_message[eNB_index]->pmch_InfoList_r9)
2668
#endif
winckel's avatar
winckel committed
2669 2670
                           );

2671
  rrc_rlc_config_asn1_req(NB_eNB_INST+Mod_id, frame,0,eNB_index,
winckel's avatar
winckel committed
2672 2673 2674
                          NULL,// SRB_ToAddModList
                          NULL,// DRB_ToAddModList
                          NULL,// DRB_ToReleaseList
2675
#ifdef Rel10
winckel's avatar
winckel committed
2676
                          &(UE_rrc_inst[Mod_id].mcch_message[eNB_index]->pmch_InfoList_r9)
2677
#endif 
winckel's avatar
winckel committed
2678
                          );
2679 2680
  // */
  
2681 2682 2683 2684 2685 2686 2687
}

#endif // rel10

#ifndef USER_MODE
EXPORT_SYMBOL(Rlc_info_am_config);
#endif
2688 2689 2690

#if defined(ENABLE_ITTI)
void *rrc_ue_task(void *args_p) {
2691 2692 2693
  MessageDef   *msg_p;
  const char   *msg_name;
  instance_t    instance;
2694
  unsigned int  Mod_id;
2695 2696
  int           result;
  SRB_INFO     *srb_info_p;
2697 2698 2699 2700 2701 2702 2703 2704 2705

  itti_mark_task_ready (TASK_RRC_UE);

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

    msg_name = ITTI_MSG_NAME (msg_p);
    instance = ITTI_MSG_INSTANCE (msg_p);
2706
    Mod_id = instance - NB_eNB_INST;
2707

Cedric Roux's avatar
Cedric Roux committed
2708
    switch (ITTI_MSG_ID(msg_p)) {
2709 2710 2711 2712 2713
      case TERMINATE_MESSAGE:
        itti_exit_task ();
        break;

      case MESSAGE_TEST:
2714
        LOG_I(RRC, "[UE %d] Received %s\n", Mod_id, msg_name);
2715 2716
        break;

winckel's avatar
RRC:  
winckel committed
2717
      /* MAC messages */
2718
      case RRC_MAC_IN_SYNC_IND:
winckel's avatar
winckel committed
2719
        LOG_D(RRC, "[UE %d] Received %s: frame %d, eNB %d\n", Mod_id, msg_name,
2720 2721
              RRC_MAC_IN_SYNC_IND (msg_p).frame, RRC_MAC_IN_SYNC_IND (msg_p).enb_index);

2722 2723 2724
        UE_rrc_inst[Mod_id].Info[RRC_MAC_IN_SYNC_IND (msg_p).enb_index].N310_cnt = 0;
        if (UE_rrc_inst[Mod_id].Info[RRC_MAC_IN_SYNC_IND (msg_p).enb_index].T310_active == 1)
          UE_rrc_inst[Mod_id].Info[RRC_MAC_IN_SYNC_IND (msg_p).enb_index].N311_cnt++;
2725 2726 2727
        break;

      case RRC_MAC_OUT_OF_SYNC_IND:
2728
        LOG_I(RRC, "[UE %d] Received %s: frame %d, eNB %d\n", Mod_id, msg_name,
2729 2730
              RRC_MAC_OUT_OF_SYNC_IND (msg_p).frame, RRC_MAC_OUT_OF_SYNC_IND (msg_p).enb_index);

2731
        UE_rrc_inst[Mod_id].Info[RRC_MAC_OUT_OF_SYNC_IND (msg_p).enb_index].N310_cnt ++;
2732 2733 2734
        break;

      case RRC_MAC_BCCH_DATA_IND:
winckel's avatar
winckel committed
2735
        LOG_D(RRC, "[UE %d] Received %s: frame %d, eNB %d\n", Mod_id, msg_name,
2736 2737
              RRC_MAC_BCCH_DATA_IND (msg_p).frame, RRC_MAC_BCCH_DATA_IND (msg_p).enb_index);

2738
        decode_BCCH_DLSCH_Message (Mod_id, RRC_MAC_BCCH_DATA_IND (msg_p).frame,
2739
                                   RRC_MAC_BCCH_DATA_IND (msg_p).enb_index, RRC_MAC_BCCH_DATA_IND (msg_p).sdu,
2740 2741
                                   RRC_MAC_BCCH_DATA_IND (msg_p).sdu_size,
                                   RRC_MAC_BCCH_DATA_IND (msg_p).rsrq, RRC_MAC_BCCH_DATA_IND (msg_p).rsrp);
2742
        break;
2743

2744
      case RRC_MAC_CCCH_DATA_CNF:
2745
        LOG_I(RRC, "[UE %d] Received %s: eNB %d\n", Mod_id, msg_name,
2746 2747 2748
              RRC_MAC_CCCH_DATA_CNF (msg_p).enb_index);

        // reset the tx buffer to indicate RRC that ccch was successfully transmitted (for example if contention resolution succeeds)
2749
        UE_rrc_inst[Mod_id].Srb0[RRC_MAC_CCCH_DATA_CNF (msg_p).enb_index].Tx_buffer.payload_size = 0;
2750 2751 2752
        break;

      case RRC_MAC_CCCH_DATA_IND:
2753
        LOG_I(RRC, "[UE %d] Received %s: frame %d, eNB %d\n", Mod_id, msg_name,
2754 2755
              RRC_MAC_CCCH_DATA_IND (msg_p).frame, RRC_MAC_CCCH_DATA_IND (msg_p).enb_index);

2756
        srb_info_p = &UE_rrc_inst[Mod_id].Srb0[RRC_MAC_CCCH_DATA_IND (msg_p).enb_index];
2757

2758
        memcpy (srb_info_p->Rx_buffer.Payload, RRC_MAC_CCCH_DATA_IND (msg_p).sdu,
2759 2760
                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;
2761
        rrc_ue_decode_ccch (Mod_id, RRC_MAC_CCCH_DATA_IND (msg_p).frame, srb_info_p,
2762 2763 2764
                            RRC_MAC_CCCH_DATA_IND (msg_p).enb_index);
        break;

2765
# ifdef Rel10
2766
      case RRC_MAC_MCCH_DATA_IND:
2767
        LOG_I(RRC, "[UE %d] Received %s: frame %d, eNB %d, mbsfn SA %d\n", Mod_id, msg_name,
2768
              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);
2769

2770
        decode_MCCH_Message (Mod_id, RRC_MAC_MCCH_DATA_IND (msg_p).frame, RRC_MAC_MCCH_DATA_IND (msg_p).enb_index,
2771
                             RRC_MAC_MCCH_DATA_IND (msg_p).sdu, RRC_MAC_MCCH_DATA_IND (msg_p).sdu_size,
2772 2773
                             RRC_MAC_MCCH_DATA_IND (msg_p).mbsfn_sync_area);
        break;
2774
# endif
2775

winckel's avatar
RRC:  
winckel committed
2776
        /* PDCP messages */
2777
      case RRC_DCCH_DATA_IND:
2778 2779
        LOG_I(RRC, "[UE %d] Received %s: frame %d, DCCH %d, eNB %d\n", Mod_id, msg_name,
              RRC_DCCH_DATA_IND (msg_p).frame, RRC_DCCH_DATA_IND (msg_p).dcch_index, RRC_DCCH_DATA_IND (msg_p).eNB_index);
2780

2781
        rrc_ue_decode_dcch (Mod_id, RRC_DCCH_DATA_IND (msg_p).frame,
2782
                            RRC_DCCH_DATA_IND (msg_p).dcch_index, RRC_DCCH_DATA_IND (msg_p).sdu_p,
2783
                            RRC_DCCH_DATA_IND (msg_p).eNB_index);
2784 2785

        // Message buffer has been processed, free it now.
2786 2787
        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);
2788 2789
        break;

2790
# if defined(ENABLE_USE_MME)
winckel's avatar
RRC:  
winckel committed
2791
      /* NAS messages */
winckel's avatar
winckel committed
2792
      case NAS_CELL_SELECTION_REQ:
2793 2794
          Mod_id = 0; /* TODO force Mod_id to first UE, NAS UE not virtualized yet */

winckel's avatar
winckel committed
2795
          LOG_I(RRC, "[UE %d] Received %s: state %d, plmnID %d, rat %x\n", Mod_id, msg_name, rrc_get_state(Mod_id),
2796 2797
                NAS_CELL_SELECTION_REQ (msg_p).plmnID, NAS_CELL_SELECTION_REQ (msg_p).rat);

2798 2799 2800 2801 2802 2803
          /* Save cell selection criterion */
          {
              UE_rrc_inst[Mod_id].plmnID = NAS_CELL_SELECTION_REQ (msg_p).plmnID;
              UE_rrc_inst[Mod_id].rat = NAS_CELL_SELECTION_REQ (msg_p).rat;
          }

winckel's avatar
winckel committed
2804
          switch (rrc_get_state(Mod_id)) {
2805
              case RRC_STATE_INACTIVE:
2806 2807 2808
              {
                  /* Need to first activate lower layers */
                  MessageDef *message_p;
2809

2810 2811 2812 2813
                  message_p = itti_alloc_new_message(TASK_RRC_UE, ACTIVATE_MESSAGE);

                  itti_send_msg_to_task(TASK_L2L1, NB_eNB_INST + Mod_id, message_p);

winckel's avatar
winckel committed
2814
                  rrc_set_state (Mod_id, RRC_STATE_IDLE);
winckel's avatar
winckel committed
2815
                  /* Fall through to next case */
2816
              }
winckel's avatar
winckel committed
2817

2818
              case RRC_STATE_IDLE:
winckel's avatar
winckel committed
2819 2820 2821 2822 2823 2824 2825 2826 2827 2828
              {
                  /* Ask to layer 1 to find a cell matching the criterion */
                  MessageDef *message_p;

                  message_p = itti_alloc_new_message(TASK_RRC_UE, PHY_FIND_CELL_REQ);

                  PHY_FIND_CELL_REQ (message_p).earfcn_start = 1;
                  PHY_FIND_CELL_REQ (message_p).earfcn_end = 1;

                  itti_send_msg_to_task(TASK_PHY_UE, NB_eNB_INST + Mod_id, message_p);
winckel's avatar
winckel committed
2829
                  rrc_set_sub_state (Mod_id, RRC_SUB_STATE_IDLE_SEARCHING);
winckel's avatar
winckel committed
2830 2831 2832

                  break;
              }
2833 2834

              case RRC_STATE_CONNECTED:
winckel's avatar
winckel committed
2835 2836 2837
                  /* should not happen */
                  LOG_E(RRC, "[UE %d] request %s in RRC state %d\n", Mod_id, msg_name, rrc_get_state(Mod_id));
                  break;
2838 2839

              default:
winckel's avatar
winckel committed
2840 2841
                  LOG_C(RRC, "[UE %d] Invalid RRC state %d\n", Mod_id, rrc_get_state(Mod_id));
                  break;
2842
          }
winckel's avatar
winckel committed
2843 2844 2845 2846 2847 2848
          break;

      case NAS_CONN_ESTABLI_REQ:
          LOG_I(RRC, "[UE %d] Received %s: cause %d, type %d, s_tmsi %d, plmnID %d\n", Mod_id, msg_name, NAS_CONN_ESTABLI_REQ (msg_p).cause,
                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
2849 2850 2851 2852 2853 2854 2855
          UE_rrc_inst[Mod_id].initialNasMsg = NAS_CONN_ESTABLI_REQ (msg_p).initialNasMsg;

          switch (rrc_get_state(Mod_id)) {
              case RRC_STATE_IDLE:
              {
                  if (rrc_get_sub_state(Mod_id) == RRC_SUB_STATE_IDLE_SIB_COMPLETE)
                  {
2856
                      rrc_ue_generate_RRCConnectionRequest(Mod_id, 0 /* TODO put frame number ! */, 0);
winckel's avatar
winckel committed
2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873
                      LOG_I(RRC, "not sending connection request\n");

                      rrc_set_sub_state (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", Mod_id, msg_name, rrc_get_state(Mod_id));
                  break;

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

winckel's avatar
RRC:  
winckel committed
2876 2877
      case NAS_UPLINK_DATA_REQ:
      {
2878 2879
          uint32_t length;
          uint8_t *buffer;
winckel's avatar
RRC:  
winckel committed
2880

2881
          LOG_I(RRC, "[UE %d] Received %s: UEid %d\n", Mod_id, msg_name, NAS_UPLINK_DATA_REQ (msg_p).UEid);
winckel's avatar
RRC:  
winckel committed
2882

2883 2884
          /* 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);
winckel's avatar
RRC:  
winckel committed
2885

2886
          /* Transfer data to PDCP */
2887
          pdcp_rrc_data_req (0, Mod_id, 0 /* TODO put frame number ! */, 0, DCCH, rrc_mui++, 0, length, buffer, 1);
2888
          break;
winckel's avatar
RRC:  
winckel committed
2889
      }
2890
# endif
winckel's avatar
RRC:  
winckel committed
2891

2892
# if defined(ENABLE_RAL)
2893
      case RRC_RAL_SCAN_REQ:
2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937
          LOG_I(RRC, "[UE %d] Received %s: state %d\n", Mod_id, msg_name);

          switch (rrc_get_state(Mod_id)) {
              case RRC_STATE_INACTIVE:
              {
                  /* Need to first activate lower layers */
                  MessageDef *message_p;

                  message_p = itti_alloc_new_message(TASK_RRC_UE, ACTIVATE_MESSAGE);

                  itti_send_msg_to_task(TASK_L2L1, instance, message_p);

                  rrc_set_state (Mod_id, RRC_STATE_IDLE);
                  /* Fall through to next case */
              }

              case RRC_STATE_IDLE:
              {
                  if (rrc_get_sub_state(Mod_id) != RRC_SUB_STATE_IDLE_SEARCHING) {
                      /* Ask to layer 1 to find a cell matching the criterion */
                      MessageDef *message_p;

                      message_p = itti_alloc_new_message(TASK_RRC_UE, PHY_FIND_CELL_REQ);

                      rrc_set_sub_state (Mod_id, RRC_SUB_STATE_IDLE_SEARCHING);

                      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

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

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

              default:
                  LOG_C(RRC, "[UE %d] Invalid RRC state %d\n", Mod_id, rrc_get_state(Mod_id));
                  break;
          }
2938
          break;
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 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006
      case PHY_FIND_CELL_IND:
          LOG_I(RRC, "[UE %d] Received %s: state %d\n", Mod_id, msg_name, rrc_get_state(Mod_id));
          switch (rrc_get_state(Mod_id)) {
              case RRC_STATE_IDLE:
                  switch (rrc_get_sub_state(Mod_id)) {
                      case RRC_SUB_STATE_IDLE_SEARCHING:
                      {
                          MessageDef *message_p;
                          int         i;

                          message_p = itti_alloc_new_message(TASK_RRC_UE, RRC_RAL_SCAN_CONF);

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

                              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 (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",
                                  Mod_id,
                                  rrc_get_state(Mod_id),
                                  rrc_get_sub_state(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", Mod_id, msg_name, rrc_get_state(Mod_id));
                  break;

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

      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_type,
                  &PHY_MEAS_REPORT_IND(msg_p).link_param_type,
                  sizeof(RRC_RAL_MEASUREMENT_REPORT_IND (message_p).link_param_type));

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

3007
      case RRC_RAL_CONFIGURE_THRESHOLD_REQ:
Lionel Gauthier's avatar
Lionel Gauthier committed
3008
          rrc_ue_ral_handle_configure_threshold_request(Mod_id, msg_p);
3009
          break;
3010 3011

      case RRC_RAL_CONNECTION_ESTABLISHMENT_REQ:
3012
          LOG_I(RRC, "[UE %d] Received %s\n", Mod_id, msg_name);
3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035
          switch (rrc_get_state(Mod_id)) {
              case RRC_STATE_IDLE:
              {
                  if (rrc_get_sub_state(Mod_id) == RRC_SUB_STATE_IDLE_SIB_COMPLETE)
                  {
                      rrc_ue_generate_RRCConnectionRequest(Mod_id, 0 /* TODO put frame number ! */, 0);
                      LOG_I(RRC, "not sending connection request\n");

                      rrc_set_sub_state (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", Mod_id, msg_name, rrc_get_state(Mod_id));
                  break;

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

      case RRC_RAL_CONNECTION_RELEASE_REQ:
3039
          Mod_id = 0; /* TODO force Mod_id to first UE, NAS UE not virtualized yet */
3040 3041
          LOG_I(RRC, "[UE %d] Received %s\n", Mod_id, msg_name);
          break;
Lionel Gauthier's avatar
Lionel Gauthier committed
3042
#endif
3043

3044
      default:
3045
        LOG_E(RRC, "[UE %d] Received unexpected message %s\n", Mod_id, msg_name);
3046 3047 3048
        break;
    }

Lionel Gauthier's avatar
Lionel Gauthier committed
3049 3050
    result = itti_free (ITTI_MSG_ORIGIN_ID(msg_p), msg_p);
    AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
3051
    AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
3052
    msg_p = NULL;
3053 3054 3055
  }
}
#endif