rrc_UE.c 147 KB
Newer Older
1
/*******************************************************************************
nikaeinn's avatar
nikaeinn committed
2 3
    OpenAirInterface
    Copyright(c) 1999 - 2014 Eurecom
4

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


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

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

  Contact Information
nikaeinn's avatar
nikaeinn committed
22 23 24
  OpenAirInterface Admin: openair_admin@eurecom.fr
  OpenAirInterface Tech : openair_tech@eurecom.fr
  OpenAirInterface Dev  : openair4g-devel@eurecom.fr
25

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

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

gauthier's avatar
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
gauthier's avatar
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 int8_t dB_fixed2(uint32_t x,uint32_t y);
105

winckel's avatar
winckel committed
106
/*------------------------------------------------------------------------------*/
107 108
static Rrc_State_t rrc_get_state (module_id_t ue_mod_idP) {
  return UE_rrc_inst[ue_mod_idP].RrcState;
winckel's avatar
winckel committed
109 110
}

111 112
static Rrc_Sub_State_t rrc_get_sub_state (module_id_t ue_mod_idP) {
  return UE_rrc_inst[ue_mod_idP].RrcSubState;
winckel's avatar
winckel committed
113 114
}

115
static int rrc_set_state (module_id_t ue_mod_idP, Rrc_State_t state) {
winckel's avatar
winckel committed
116
  AssertFatal ((RRC_STATE_FIRST <= state) && (state <= RRC_STATE_LAST),
gauthier's avatar
gauthier committed
117
      "Invalid state %d!\n", state);
winckel's avatar
winckel committed
118

119 120
  if (UE_rrc_inst[ue_mod_idP].RrcState != state) {
      UE_rrc_inst[ue_mod_idP].RrcState = state;
winckel's avatar
winckel committed
121

122
#if defined(ENABLE_ITTI)
gauthier's avatar
gauthier committed
123 124
      {
        MessageDef *msg_p;
125

gauthier's avatar
gauthier committed
126
        msg_p = itti_alloc_new_message(TASK_RRC_UE, RRC_STATE_IND);
127 128
        RRC_STATE_IND(msg_p).state = UE_rrc_inst[ue_mod_idP].RrcState;
        RRC_STATE_IND(msg_p).sub_state = UE_rrc_inst[ue_mod_idP].RrcSubState;
winckel's avatar
winckel committed
129

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

  return (0);
}

139
static int rrc_set_sub_state (module_id_t ue_mod_idP, Rrc_Sub_State_t subState) {
140
#if (defined(ENABLE_ITTI) && (defined(ENABLE_USE_MME) || defined(ENABLE_RAL)))
141
  switch (UE_rrc_inst[ue_mod_idP].RrcState) {
gauthier's avatar
gauthier committed
142 143
  case RRC_STATE_INACTIVE:
    AssertFatal ((RRC_SUB_STATE_INACTIVE_FIRST <= subState) && (subState <= RRC_SUB_STATE_INACTIVE_LAST),
144
        "Invalid sub state %d for state %d!\n", subState, UE_rrc_inst[ue_mod_idP].RrcState);
gauthier's avatar
gauthier committed
145 146 147 148
    break;

  case RRC_STATE_IDLE:
    AssertFatal ((RRC_SUB_STATE_IDLE_FIRST <= subState) && (subState <= RRC_SUB_STATE_IDLE_LAST),
149
        "Invalid sub state %d for state %d!\n", subState, UE_rrc_inst[ue_mod_idP].RrcState);
gauthier's avatar
gauthier committed
150 151 152 153
    break;

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

159 160
  if (UE_rrc_inst[ue_mod_idP].RrcSubState != subState) {
      UE_rrc_inst[ue_mod_idP].RrcSubState = subState;
winckel's avatar
winckel committed
161

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

gauthier's avatar
gauthier committed
166
        msg_p = itti_alloc_new_message(TASK_RRC_UE, RRC_STATE_IND);
167 168
        RRC_STATE_IND(msg_p).state = UE_rrc_inst[ue_mod_idP].RrcState;
        RRC_STATE_IND(msg_p).sub_state = UE_rrc_inst[ue_mod_idP].RrcSubState;
169

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

  return (0);
}

/*------------------------------------------------------------------------------*/
180
void init_SI_UE(module_id_t ue_mod_idP,uint8_t eNB_index) {
181 182 183 184

  int i;


185 186
  UE_rrc_inst[ue_mod_idP].sizeof_SIB1[eNB_index] = 0;
  UE_rrc_inst[ue_mod_idP].sizeof_SI[eNB_index] = 0;
187

188 189 190
  UE_rrc_inst[ue_mod_idP].SIB1[eNB_index] = (uint8_t *)malloc16(32);
  UE_rrc_inst[ue_mod_idP].sib1[eNB_index] = (SystemInformationBlockType1_t *)malloc16(sizeof(SystemInformationBlockType1_t));
  UE_rrc_inst[ue_mod_idP].SI[eNB_index] = (uint8_t *)malloc16(64);
191 192

  for (i=0;i<NB_CNX_UE;i++) {
193
      UE_rrc_inst[ue_mod_idP].si[eNB_index][i] = (SystemInformation_t *)malloc16(sizeof(SystemInformation_t));
194 195
  }

196 197
  UE_rrc_inst[ue_mod_idP].Info[eNB_index].SIB1Status = 0;
  UE_rrc_inst[ue_mod_idP].Info[eNB_index].SIStatus = 0;
198 199 200
}

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

}
#endif

static
213
void openair_rrc_lite_ue_init_security(module_id_t ue_mod_idP)
214 215
{
#if defined(ENABLE_SECURITY)
gauthier's avatar
gauthier committed
216 217 218 219
  //    uint8_t *kRRCenc;
  //    uint8_t *kRRCint;
  char ascii_buffer[65];
  uint8_t i;
220

221
  memset(UE_rrc_inst[ue_mod_idP].kenb, ue_mod_idP, 32);
222

gauthier's avatar
gauthier committed
223
  for (i = 0; i < 32; i++) {
224
      sprintf(&ascii_buffer[2 * i], "%02X", UE_rrc_inst[ue_mod_idP].kenb[i]);
gauthier's avatar
gauthier committed
225
  }
226

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

/*------------------------------------------------------------------------------*/
232
char openair_rrc_lite_ue_init(module_id_t ue_mod_idP, unsigned char eNB_index){
233
  /*-----------------------------------------------------------------------------*/
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
  rrc_set_state (ue_mod_idP, RRC_STATE_INACTIVE);
  rrc_set_sub_state (ue_mod_idP, RRC_SUB_STATE_INACTIVE);

  LOG_D(RRC,"[UE %d] INIT State = RRC_IDLE (eNB %d)\n",ue_mod_idP,eNB_index);
  LOG_D(RRC,"[MSC_NEW][FRAME 00000][RRC_UE][MOD %02d][]\n", ue_mod_idP+NB_eNB_INST);
  LOG_D(RRC, "[MSC_NEW][FRAME 00000][IP][MOD %02d][]\n", ue_mod_idP+NB_eNB_INST);

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

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

258
  openair_rrc_lite_ue_init_security(ue_mod_idP);
259

260 261
  init_SI_UE(ue_mod_idP,eNB_index);
  LOG_D(RRC,"[UE %d] INIT: phy_sync_2_ch_ind\n", ue_mod_idP);
262 263

#ifndef NO_RRM
264
  send_msg(&S_rrc,msg_rrc_phy_synch_to_CH_ind(ue_mod_idP,eNB_index,UE_rrc_inst[ue_mod_idP].Mac_id));
265 266 267
#endif

#ifdef NO_RRM //init ch SRB0, SRB1 & BDTCH
268
  openair_rrc_on(ue_mod_idP,0);
269 270 271 272
#endif
#ifdef CBA 
  int j;
  for(j=0; j<NUM_MAX_CBA_GROUP; j++)
273 274
    UE_rrc_inst[ue_mod_idP].cba_rnti[j] = 0x0000;
  UE_rrc_inst[ue_mod_idP].num_active_cba_groups = 0;
275 276 277 278 279 280
#endif

  return 0;
}

/*------------------------------------------------------------------------------*/
281
void rrc_ue_generate_RRCConnectionRequest(module_id_t ue_mod_idP, frame_t frameP, uint8_t eNB_index){
282 283
  /*------------------------------------------------------------------------------*/

284
  uint8_t i=0,rv[6];
gauthier's avatar
gauthier committed
285

286
  if(UE_rrc_inst[ue_mod_idP].Srb0[eNB_index].Tx_buffer.payload_size ==0){
287

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

gauthier's avatar
gauthier committed
302
      LOG_I(RRC,"[UE %d] : Frame %d, Logical Channel UL-CCCH (SRB0), Generating RRCConnectionRequest (bytes %d, eNB %d)\n",
303
          ue_mod_idP, frameP, UE_rrc_inst[ue_mod_idP].Srb0[eNB_index].Tx_buffer.payload_size, eNB_index);
304

305 306
      for (i=0;i<UE_rrc_inst[ue_mod_idP].Srb0[eNB_index].Tx_buffer.payload_size;i++) {
          LOG_T(RRC,"%x.",UE_rrc_inst[ue_mod_idP].Srb0[eNB_index].Tx_buffer.Payload[i]);
gauthier's avatar
gauthier committed
307 308 309
      }
      LOG_T(RRC,"\n");
      /*
310
      UE_rrc_inst[ue_mod_idP].Srb0[Idx].Tx_buffer.Payload[i] = taus()&0xff;
311

312
    UE_rrc_inst[ue_mod_idP].Srb0[Idx].Tx_buffer.payload_size =i;
gauthier's avatar
gauthier committed
313
       */
314 315 316 317 318 319 320

  }
}


mui_t rrc_mui=0;

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

/* NAS Attach request with GUTI */
337
static const char const nas_attach_req_guti[] =
gauthier's avatar
gauthier committed
338 339 340 341 342 343 344 345 346 347 348 349
    {
        0x07, 0x41,
        /* EPS Mobile identity = GUTI */
        0x71, 0x0B, 0xF6, 0x12, 0xF2, 0x01, 0x80, 0x00, 0x01, 0xE0, 0x00,
        0xDA, 0x1F,
        /* End of EPS Mobile Identity */
        0x02, 0xE0, 0xE0, 0x00, 0x20, 0x02, 0x03,
        0xD0, 0x11, 0x27, 0x1A, 0x80, 0x80, 0x21, 0x10, 0x01, 0x00, 0x00,
        0x10, 0x81, 0x06, 0x00, 0x00, 0x00, 0x00, 0x83, 0x06, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x0A, 0x00, 0x52, 0x12, 0xF2,
        0x01, 0x27, 0x11,
    };
350

351
/*------------------------------------------------------------------------------*/
352
void rrc_ue_generate_RRCConnectionSetupComplete(module_id_t ue_mod_idP, frame_t frameP, uint8_t eNB_index, uint8_t Transaction_id){
353 354
  /*------------------------------------------------------------------------------*/

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

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

368
  size = do_RRCConnectionSetupComplete(ue_mod_idP, 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
      ue_mod_idP,frameP, size, eNB_index);
372

gauthier's avatar
gauthier committed
373
  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",
374
      frameP, ue_mod_idP+NB_eNB_INST, size, eNB_index, rrc_mui, ue_mod_idP+NB_eNB_INST, DCCH);
375

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

380
void rrc_ue_generate_RRCConnectionReconfigurationComplete(module_id_t ue_mod_idP, frame_t frameP, uint8_t eNB_index, uint8_t Transaction_id) {
381

382
  uint8_t buffer[32], size;
383

384
  size = do_RRCConnectionReconfigurationComplete(ue_mod_idP, 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
      ue_mod_idP,frameP, 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
      frameP, ue_mod_idP+NB_eNB_INST, size, eNB_index, rrc_mui, ue_mod_idP+NB_eNB_INST, DCCH);
390

391 392
  //rrc_rlc_data_req(ue_mod_idP+NB_eNB_INST,frameP, 0 ,DCCH,rrc_mui++,0,size,(char*)buffer);
  pdcp_rrc_data_req (eNB_index, ue_mod_idP, frameP, 0, DCCH, rrc_mui++, 0, size, buffer, 1);
393 394 395
}

/*------------------------------------------------------------------------------*/
396
int rrc_ue_decode_ccch(module_id_t ue_mod_idP, frame_t frameP, SRB_INFO *Srb_info, uint8_t eNB_index){
397 398 399 400 401
  /*------------------------------------------------------------------------------*/

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

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

408 409
  //  LOG_D(RRC,"[UE %d] Decoding DL-CCCH message (%d bytes), State %d\n",ue_mod_idP,Srb_info->Rx_buffer.payload_size,
  //  UE_rrc_inst[ue_mod_idP].Info[eNB_index].State);
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

429
    itti_send_msg_to_task (TASK_UNKNOWN, ue_mod_idP + 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)
gauthier's avatar
gauthier committed
437 438
      {
        MessageDef *msg_p;
439

gauthier's avatar
gauthier committed
440 441 442
        msg_p = itti_alloc_new_message_sized (TASK_RRC_UE, RRC_DL_CCCH, message_string_size + sizeof (IttiMsgText));
        msg_p->ittiMsg.rrc_dl_ccch.size = message_string_size;
        memcpy(&msg_p->ittiMsg.rrc_dl_ccch.text, message_string, message_string_size);
443

444
        itti_send_msg_to_task(TASK_UNKNOWN, ue_mod_idP + NB_eNB_INST, msg_p);
gauthier's avatar
gauthier committed
445
      }
446 447
  }
# endif
448 449
#endif

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

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

458
      if (UE_rrc_inst[ue_mod_idP].Info[eNB_index].State == RRC_SI_RECEIVED) {
459

gauthier's avatar
gauthier committed
460
          switch (dl_ccch_msg->message.choice.c1.present) {
461

gauthier's avatar
gauthier committed
462
          case DL_CCCH_MessageType__c1_PR_NOTHING:
463
            LOG_I(RRC, "[UE%d] Frame %d : Received PR_NOTHING on DL-CCCH-Message\n", ue_mod_idP, frameP);
gauthier's avatar
gauthier committed
464 465
            rval = 0;
            break;
466

gauthier's avatar
gauthier committed
467 468
          case DL_CCCH_MessageType__c1_PR_rrcConnectionReestablishment:
            LOG_D(RRC,
469
                "[MSC_MSG][FRAME %05d][MAC_UE][MOD %02d][][--- MAC_DATA_IND (rrcConnectionReestablishment ENB %d) --->][RRC_UE][MOD %02d][]\n", frameP, ue_mod_idP+NB_eNB_INST, eNB_index, ue_mod_idP+NB_eNB_INST);
470

gauthier's avatar
gauthier committed
471
            LOG_I(RRC,
472
                "[UE%d] Frame %d : Logical Channel DL-CCCH (SRB0), Received RRCConnectionReestablishment\n", ue_mod_idP, frameP);
gauthier's avatar
gauthier committed
473 474
            rval = 0;
            break;
475

gauthier's avatar
gauthier committed
476 477
          case DL_CCCH_MessageType__c1_PR_rrcConnectionReestablishmentReject:
            LOG_D(RRC,
478
                "[MSC_MSG][FRAME %05d][MAC_UE][MOD %02d][][--- MAC_DATA_IND (RRCConnectionReestablishmentReject ENB %d) --->][RRC_UE][MOD %02d][]\n", frameP, ue_mod_idP+NB_eNB_INST, eNB_index, ue_mod_idP+NB_eNB_INST);
gauthier's avatar
gauthier committed
479
            LOG_I(RRC,
480
                "[UE%d] Frame %d : Logical Channel DL-CCCH (SRB0), Received RRCConnectionReestablishmentReject\n", ue_mod_idP, frameP);
gauthier's avatar
gauthier committed
481 482
            rval = 0;
            break;
483

gauthier's avatar
gauthier committed
484 485
          case DL_CCCH_MessageType__c1_PR_rrcConnectionReject:
            LOG_D(RRC,
486
                "[MSC_MSG][FRAME %05d][MAC_UE][MOD %02d][][--- MAC_DATA_IND (rrcConnectionReject ENB %d) --->][RRC_UE][MOD %02d][]\n", frameP, ue_mod_idP+NB_eNB_INST, eNB_index, ue_mod_idP+NB_eNB_INST);
487

gauthier's avatar
gauthier committed
488
            LOG_I(RRC,
489
                "[UE%d] Frame %d : Logical Channel DL-CCCH (SRB0), Received RRCConnectionReject \n", ue_mod_idP, frameP);
gauthier's avatar
gauthier committed
490 491
            rval = 0;
            break;
492

gauthier's avatar
gauthier committed
493 494
          case DL_CCCH_MessageType__c1_PR_rrcConnectionSetup:
            LOG_D(RRC,
495
                "[MSC_MSG][FRAME %05d][MAC_UE][MOD %02d][][--- MAC_DATA_IND (rrcConnectionSetup ENB %d) --->][RRC_UE][MOD %02d][]\n", frameP, ue_mod_idP+NB_eNB_INST, eNB_index, ue_mod_idP+NB_eNB_INST);
496

gauthier's avatar
gauthier committed
497
            LOG_I(RRC,
498
                "[UE%d][RAPROC] Frame %d : Logical Channel DL-CCCH (SRB0), Received RRCConnectionSetup \n", ue_mod_idP, frameP);
gauthier's avatar
gauthier committed
499
            // Get configuration
500

gauthier's avatar
gauthier committed
501
            // Release T300 timer
502 503
            UE_rrc_inst[ue_mod_idP].Info[eNB_index].T300_active = 0;
            rrc_ue_process_radioResourceConfigDedicated(ue_mod_idP, frameP, eNB_index,
gauthier's avatar
gauthier committed
504
                &dl_ccch_msg->message.choice.c1.choice.rrcConnectionSetup.criticalExtensions.choice.c1.choice.rrcConnectionSetup_r8.radioResourceConfigDedicated);
505

506 507 508
            rrc_set_state (ue_mod_idP, RRC_STATE_CONNECTED);
            rrc_set_sub_state (ue_mod_idP, RRC_SUB_STATE_CONNECTED);
            rrc_ue_generate_RRCConnectionSetupComplete(ue_mod_idP, frameP, eNB_index, dl_ccch_msg->message.choice.c1.choice.rrcConnectionSetup.rrc_TransactionIdentifier);
509

gauthier's avatar
gauthier committed
510 511
            rval = 0;
            break;
512

gauthier's avatar
gauthier committed
513
          default:
514
            LOG_E(RRC, "[UE%d] Frame %d : Unknown message\n", ue_mod_idP, frameP);
gauthier's avatar
gauthier committed
515 516 517
            rval = -1;
            break;
          }
518 519 520 521 522 523 524
      }
  }

  vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_CCCH, VCD_FUNCTION_OUT);
  return rval;
}

525
int32_t rrc_ue_establish_srb1(module_id_t ue_mod_idP, frame_t frameP,uint8_t eNB_index, struct SRB_ToAddMod *SRB_config) {
526
  // add descriptor from RRC PDU
527

528
  uint8_t lchan_id = DCCH;
529

530 531 532
  UE_rrc_inst[ue_mod_idP].Srb1[eNB_index].Active = 1;
  UE_rrc_inst[ue_mod_idP].Srb1[eNB_index].Status = RADIO_CONFIG_OK;//RADIO CFG
  UE_rrc_inst[ue_mod_idP].Srb1[eNB_index].Srb_info.Srb_id = 1;
533

gauthier's avatar
gauthier committed
534
  // copy default configuration for now
535 536
  //  memcpy(&UE_rrc_inst[ue_mod_idP].Srb1[eNB_index].Srb_info.Lchan_desc[0],&DCCH_LCHAN_DESC,LCHAN_DESC_SIZE);
  //  memcpy(&UE_rrc_inst[ue_mod_idP].Srb1[eNB_index].Srb_info.Lchan_desc[1],&DCCH_LCHAN_DESC,LCHAN_DESC_SIZE);
537 538


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

541 542
  //rrc_pdcp_config_req (ue_mod_idP+NB_eNB_INST, frameP, 0, CONFIG_ACTION_ADD, lchan_id,UNDEF_SECURITY_MODE);
  //  rrc_rlc_config_req(ue_mod_idP+NB_eNB_INST,frameP,0,CONFIG_ACTION_ADD,lchan_id,SIGNALLING_RADIO_BEARER,Rlc_info_am_config);
543

544
  //  UE_rrc_inst[ue_mod_idP].Srb1[eNB_index].Srb_info.Tx_buffer.payload_size=DEFAULT_MEAS_IND_SIZE+1;
545 546 547 548 549


  return(0);
}

550
int32_t rrc_ue_establish_srb2(module_id_t ue_mod_idP, frame_t frameP,uint8_t eNB_index, struct SRB_ToAddMod *SRB_config) {
551
  // add descriptor from RRC PDU
552

553
  uint8_t lchan_id = DCCH1;
554

555 556 557
  UE_rrc_inst[ue_mod_idP].Srb2[eNB_index].Active = 1;
  UE_rrc_inst[ue_mod_idP].Srb2[eNB_index].Status = RADIO_CONFIG_OK;//RADIO CFG
  UE_rrc_inst[ue_mod_idP].Srb2[eNB_index].Srb_info.Srb_id = 2;
558

gauthier's avatar
gauthier committed
559
  // copy default configuration for now
560 561
  //  memcpy(&UE_rrc_inst[ue_mod_idP].Srb2[eNB_index].Srb_info.Lchan_desc[0],&DCCH_LCHAN_DESC,LCHAN_DESC_SIZE);
  //  memcpy(&UE_rrc_inst[ue_mod_idP].Srb2[eNB_index].Srb_info.Lchan_desc[1],&DCCH_LCHAN_DESC,LCHAN_DESC_SIZE);
562 563


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

566 567
  //rrc_pdcp_config_req (ue_mod_idP+NB_eNB_INST, frameP, 0, CONFIG_ACTION_ADD, lchan_id, UNDEF_SECURITY_MODE);
  //  rrc_rlc_config_req(ue_mod_idP+NB_eNB_INST,frameP,0,CONFIG_ACTION_ADD,lchan_id,SIGNALLING_RADIO_BEARER,Rlc_info_am_config);
568

569
  //  UE_rrc_inst[ue_mod_idP].Srb1[eNB_index].Srb_info.Tx_buffer.payload_size=DEFAULT_MEAS_IND_SIZE+1;
570 571 572 573 574


  return(0);
}

575
int32_t rrc_ue_establish_drb(module_id_t ue_mod_idP, frame_t frameP,uint8_t eNB_index,
gauthier's avatar
gauthier committed
576
    struct DRB_ToAddMod *DRB_config) { // add descriptor from RRC PDU
577
#ifdef NAS_NETLINK
578
  int oip_ifup=0,ip_addr_offset3=0,ip_addr_offset4=0;
579
#endif
580

581
  LOG_I(RRC,"[UE %d] Frame %d: processing RRCConnectionReconfiguration: reconfiguring DRB %ld/LCID %d\n",
582
      ue_mod_idP, frameP, DRB_config->drb_Identity, (int)*DRB_config->logicalChannelIdentity);
583
  /*
584
  rrc_pdcp_config_req (ue_mod_idP+NB_eNB_INST, frameP, 0, CONFIG_ACTION_ADD,
585
                             (eNB_index * NB_RB_MAX) + *DRB_config->logicalChannelIdentity, UNDEF_SECURITY_MODE);
gauthier's avatar
gauthier committed
586

587
 rrc_rlc_config_req(ue_mod_idP+NB_eNB_INST,frameP,0,CONFIG_ACTION_ADD,
588 589
                    (eNB_index * NB_RB_MAX) + *DRB_config->logicalChannelIdentity,
                    RADIO_ACCESS_BEARER,Rlc_info_um);
gauthier's avatar
gauthier committed
590
   */
591 592
#ifdef NAS_NETLINK
#    ifdef OAI_EMU
gauthier's avatar
gauthier committed
593 594
  ip_addr_offset3 = oai_emulation.info.nb_enb_local;
  ip_addr_offset4 = NB_eNB_INST;
595
#    else
gauthier's avatar
gauthier committed
596 597
  ip_addr_offset3 = 0;
  ip_addr_offset4 = 8;
598 599
#    endif
#    if !defined(OAI_NW_DRIVER_TYPE_ETHERNET) && !defined(EXMIMO)
600 601 602 603 604
  LOG_I(OIP,"[UE %d] trying to bring up the OAI interface oai%d, IP 10.0.%d.%d\n", ue_mod_idP, ip_addr_offset3+ue_mod_idP,
      ip_addr_offset3+ue_mod_idP+1,ip_addr_offset4+ue_mod_idP+1);
  oip_ifup=nas_config(ip_addr_offset3+ue_mod_idP,   // interface_id
      ip_addr_offset3+ue_mod_idP+1, // third_octet
      ip_addr_offset4+ue_mod_idP+1); // fourth_octet
gauthier's avatar
gauthier committed
605
  if (oip_ifup == 0 ){ // interface is up --> send a config the DRB
606
#        ifdef OAI_EMU
607
      oai_emulation.info.oai_ifup[ue_mod_idP]=1;
608 609
#        endif
      LOG_I(OIP,"[UE %d] Config the oai%d to send/receive pkt on DRB %d to/from the protocol stack\n",
610 611
          ue_mod_idP,
          ip_addr_offset3+ue_mod_idP,
612
          (eNB_index * maxDRB) + DRB_config->drb_Identity);
613 614

      rb_conf_ipv4(0,//add
615 616
          ue_mod_idP,//cx align with the UE index
          ip_addr_offset3+ue_mod_idP,//inst num_enb+ue_index
617
          (eNB_index * maxDRB) + DRB_config->drb_Identity,//rb
gauthier's avatar
gauthier committed
618
          0,//dscp
619 620 621
          ipv4_address(ip_addr_offset3+ue_mod_idP+1,ip_addr_offset4+ue_mod_idP+1),//saddr
          ipv4_address(ip_addr_offset3+ue_mod_idP+1,eNB_index+1));//daddr
      LOG_D(RRC,"[UE %d] State = Attached (eNB %d)\n",ue_mod_idP,eNB_index);
gauthier's avatar
gauthier committed
622
  }
623 624
#    else
#        ifdef OAI_EMU
625
  oai_emulation.info.oai_ifup[ue_mod_idP]=1;
626 627 628 629 630 631 632 633
#        endif
#    endif
#endif

  return(0);
}


634
void  rrc_ue_process_measConfig(module_id_t ue_mod_idP, frame_t frameP, uint8_t eNB_index,MeasConfig_t *measConfig){
635 636 637 638 639 640 641

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

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

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

  if (measConfig->quantityConfig != NULL) {
728
      if (UE_rrc_inst[ue_mod_idP].QuantityConfig[eNB_index]) {
gauthier's avatar
gauthier committed
729
          LOG_D(RRC,"Modifying Quantity Configuration \n");
730
          memcpy((char*)UE_rrc_inst[ue_mod_idP].QuantityConfig[eNB_index],
gauthier's avatar
gauthier committed
731 732 733 734 735
              (char*)measConfig->quantityConfig,
              sizeof(QuantityConfig_t));
      }
      else {
          LOG_D(RRC,"Adding Quantity configuration\n");
736
          UE_rrc_inst[ue_mod_idP].QuantityConfig[eNB_index] = measConfig->quantityConfig;
gauthier's avatar
gauthier committed
737
      }
738 739 740
  }

  if (measConfig->measIdToRemoveList != NULL) {
gauthier's avatar
gauthier committed
741 742
      for (i=0;i<measConfig->measIdToRemoveList->list.count;i++) {
          ind   = *measConfig->measIdToRemoveList->list.array[i];
743
          free(UE_rrc_inst[ue_mod_idP].MeasId[eNB_index][ind-1]);
gauthier's avatar
gauthier committed
744
      }
745 746 747
  }

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

  if (measConfig->measGapConfig !=NULL) {
764 765
      if (UE_rrc_inst[ue_mod_idP].measGapConfig[eNB_index]) {
          memcpy((char*)UE_rrc_inst[ue_mod_idP].measGapConfig[eNB_index],
gauthier's avatar
gauthier committed
766 767 768 769
              (char*)measConfig->measGapConfig,
              sizeof(MeasGapConfig_t));
      }
      else {
770
          UE_rrc_inst[ue_mod_idP].measGapConfig[eNB_index] = measConfig->measGapConfig;
gauthier's avatar
gauthier committed
771
      }
772 773
  }

774
  if (measConfig->quantityConfig != NULL) {
775
      if (UE_rrc_inst[ue_mod_idP].QuantityConfig[eNB_index]) {
gauthier's avatar
gauthier committed
776
          LOG_I(RRC,"Modifying Quantity Configuration \n");
777
          memcpy((char*)UE_rrc_inst[ue_mod_idP].QuantityConfig[eNB_index],
gauthier's avatar
gauthier committed
778 779 780 781 782
              (char*)measConfig->quantityConfig,
              sizeof(QuantityConfig_t));
      }
      else {
          LOG_I(RRC,"Adding Quantity configuration\n");
783
          UE_rrc_inst[ue_mod_idP].QuantityConfig[eNB_index] = measConfig->quantityConfig;
gauthier's avatar
gauthier committed
784 785
      }

786 787
      UE_rrc_inst[ue_mod_idP].filter_coeff_rsrp = 1./pow(2,(*UE_rrc_inst[ue_mod_idP].QuantityConfig[eNB_index]->quantityConfigEUTRA->filterCoefficientRSRP)/4);
      UE_rrc_inst[ue_mod_idP].filter_coeff_rsrq = 1./pow(2,(*UE_rrc_inst[ue_mod_idP].QuantityConfig[eNB_index]->quantityConfigEUTRA->filterCoefficientRSRQ)/4);
gauthier's avatar
gauthier committed
788 789

      LOG_I(RRC,"[UE %d] set rsrp-coeff for eNB %d: %d rsrq-coeff: %d rsrp_factor: %f rsrq_factor: %f \n",
790 791 792 793 794
          ue_mod_idP, eNB_index, // UE_rrc_inst[ue_mod_idP].Info[eNB_index].UE_index,
          *UE_rrc_inst[ue_mod_idP].QuantityConfig[eNB_index]->quantityConfigEUTRA->filterCoefficientRSRP,
          *UE_rrc_inst[ue_mod_idP].QuantityConfig[eNB_index]->quantityConfigEUTRA->filterCoefficientRSRQ,
          UE_rrc_inst[ue_mod_idP].filter_coeff_rsrp, UE_rrc_inst[ue_mod_idP].filter_coeff_rsrp,
          UE_rrc_inst[ue_mod_idP].filter_coeff_rsrp, UE_rrc_inst[ue_mod_idP].filter_coeff_rsrq);
795 796
  }

797
  if (measConfig->s_Measure != NULL) {
798
      UE_rrc_inst[ue_mod_idP].s_measure = *measConfig->s_Measure;
799
  }
gauthier's avatar
gauthier committed
800

801
  if (measConfig->speedStatePars != NULL) {
802 803
      if (UE_rrc_inst[ue_mod_idP].speedStatePars)
        memcpy((char*)UE_rrc_inst[ue_mod_idP].speedStatePars,(char*)measConfig->speedStatePars,sizeof(struct MeasConfig__speedStatePars));
gauthier's avatar
gauthier committed
804
      else
805
        UE_rrc_inst[ue_mod_idP].speedStatePars = measConfig->speedStatePars;
gauthier's avatar
gauthier committed
806
      LOG_I(RRC,"[UE %d] Configuring mobility optimization params for UE %d \n",
807
          ue_mod_idP,UE_rrc_inst[ue_mod_idP].Info[0].UE_index);
808
  }
809 810
}

811
void    
812
rrc_ue_process_radioResourceConfigDedicated(module_id_t ue_mod_idP, frame_t frameP, uint8_t eNB_index,
gauthier's avatar
gauthier committed
813
    RadioResourceConfigDedicated_t *radioResourceConfigDedicated) {
814 815 816 817 818 819 820 821 822 823 824

  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) {
825 826
      if (UE_rrc_inst[ue_mod_idP].physicalConfigDedicated[eNB_index]) {
          memcpy((char*)UE_rrc_inst[ue_mod_idP].physicalConfigDedicated[eNB_index],(char*)radioResourceConfigDedicated->physicalConfigDedicated,
gauthier's avatar
gauthier committed
827
              sizeof(struct PhysicalConfigDedicated));
828

gauthier's avatar
gauthier committed
829 830
      }
      else {
831
          UE_rrc_inst[ue_mod_idP].physicalConfigDedicated[eNB_index] = radioResourceConfigDedicated->physicalConfigDedicated;
gauthier's avatar
gauthier committed
832
      }
833 834 835
  }
  // Apply macMainConfig if present
  if (radioResourceConfigDedicated->mac_MainConfig) {
gauthier's avatar
gauthier committed
836
      if (radioResourceConfigDedicated->mac_MainConfig->present == RadioResourceConfigDedicated__mac_MainConfig_PR_explicitValue) {
837 838
          if (UE_rrc_inst[ue_mod_idP].mac_MainConfig[eNB_index]) {
              memcpy((char*)UE_rrc_inst[ue_mod_idP].mac_MainConfig[eNB_index],(char*)&radioResourceConfigDedicated->mac_MainConfig->choice.explicitValue,
gauthier's avatar
gauthier committed
839 840 841
                  sizeof(MAC_MainConfig_t));
          }
          else
842
            UE_rrc_inst[ue_mod_idP].mac_MainConfig[eNB_index] = &radioResourceConfigDedicated->mac_MainConfig->choice.explicitValue;
843 844 845 846 847
      }
  }

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

#if defined(ENABLE_SECURITY)
882 883 884 885
      derive_key_rrc_enc(UE_rrc_inst[ue_mod_idP].ciphering_algorithm,
          UE_rrc_inst[ue_mod_idP].kenb, &kRRCenc);
      derive_key_rrc_int(UE_rrc_inst[ue_mod_idP].integrity_algorithm,
          UE_rrc_inst[ue_mod_idP].kenb, &kRRCint);
886
#endif
887 888

// Refresh SRBs
889
      rrc_pdcp_config_asn1_req(eNB_index,ue_mod_idP,frameP,0,
gauthier's avatar
gauthier committed
890 891 892
          radioResourceConfigDedicated->srb_ToAddModList,
          (DRB_ToAddModList_t*)NULL,
          (DRB_ToReleaseList_t*)NULL,
893 894
          UE_rrc_inst[ue_mod_idP].ciphering_algorithm |
          (UE_rrc_inst[ue_mod_idP].integrity_algorithm << 4),
gauthier's avatar
gauthier committed
895 896 897
          kRRCenc,
          kRRCint,
          NULL
898
#ifdef Rel10
gauthier's avatar
gauthier committed
899
,(PMCH_InfoList_r9_t *)NULL
900
#endif
gauthier's avatar
gauthier committed
901
      );
902

gauthier's avatar
gauthier committed
903
      // Refresh SRBs
904
      rrc_rlc_config_asn1_req(eNB_index,ue_mod_idP,frameP,0,
gauthier's avatar
gauthier committed
905 906 907
          radioResourceConfigDedicated->srb_ToAddModList,
          (DRB_ToAddModList_t*)NULL,
          (DRB_ToReleaseList_t*)NULL
908
#ifdef Rel10
gauthier's avatar
gauthier committed
909
          ,(PMCH_InfoList_r9_t *)NULL
910
#endif
gauthier's avatar
gauthier committed
911
      );
912

gauthier's avatar
gauthier committed
913
      for (cnt=0;cnt<radioResourceConfigDedicated->srb_ToAddModList->list.count;cnt++) {
nikaeinn's avatar
nikaeinn committed
914
	//	connection_reestablishment_ind.num_srb+=1;
gauthier's avatar
gauthier committed
915
          SRB_id = radioResourceConfigDedicated->srb_ToAddModList->list.array[cnt]->srb_Identity;
916
          LOG_D(RRC,"[UE %d]: Frame %d SRB config cnt %d (SRB%ld)\n",ue_mod_idP,frameP,cnt,SRB_id);
gauthier's avatar
gauthier committed
917
          if (SRB_id == 1) {
918 919
              if (UE_rrc_inst[ue_mod_idP].SRB1_config[eNB_index]) {
                  memcpy(UE_rrc_inst[ue_mod_idP].SRB1_config[eNB_index],radioResourceConfigDedicated->srb_ToAddModList->list.array[cnt],
gauthier's avatar
gauthier committed
920 921 922
                      sizeof(struct SRB_ToAddMod));
              }
              else {
923
                  UE_rrc_inst[ue_mod_idP].SRB1_config[eNB_index] = radioResourceConfigDedicated->srb_ToAddModList->list.array[cnt];
924

925 926 927 928
                  rrc_ue_establish_srb1(ue_mod_idP,frameP,eNB_index,radioResourceConfigDedicated->srb_ToAddModList->list.array[cnt]);
                  if (UE_rrc_inst[ue_mod_idP].SRB1_config[eNB_index]->logicalChannelConfig) {
                      if (UE_rrc_inst[ue_mod_idP].SRB1_config[eNB_index]->logicalChannelConfig->present == SRB_ToAddMod__logicalChannelConfig_PR_explicitValue) {
                          SRB1_logicalChannelConfig = &UE_rrc_inst[ue_mod_idP].SRB1_config[eNB_index]->logicalChannelConfig->choice.explicitValue;
gauthier's avatar
gauthier committed
929 930 931 932 933 934 935 936
                      }
                      else {
                          SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
                      }
                  }
                  else {
                      SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
                  }
937

gauthier's avatar
gauthier committed
938
                  LOG_D(RRC, "[MSC_MSG][FRAME %05d][RRC_UE][MOD %02d][][--- MAC_CONFIG_REQ  (SRB1 eNB %d) --->][MAC_UE][MOD %02d][]\n",
939 940
                      frameP, ue_mod_idP, eNB_index, ue_mod_idP);
                  rrc_mac_config_req(ue_mod_idP,ENB_FLAG_NO,0,eNB_index,
gauthier's avatar
gauthier committed
941
                      (RadioResourceConfigCommonSIB_t *)NULL,