rrc_UE.c 151 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
#include "pdcp.h"
87
#include "plmn_data.h"
88

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

93
94
95
96
97
98
99
100
101
102
103
104
#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);
gauthier's avatar
gauthier committed
105
extern int8_t dB_fixed2(uint32_t x,uint32_t y);
106

winckel's avatar
winckel committed
107
/*------------------------------------------------------------------------------*/
gauthier's avatar
   
gauthier committed
108
109
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
110
111
}

gauthier's avatar
   
gauthier committed
112
113
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
114
115
}

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

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

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

gauthier's avatar
gauthier committed
127
        msg_p = itti_alloc_new_message(TASK_RRC_UE, RRC_STATE_IND);
gauthier's avatar
   
gauthier committed
128
129
        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
130

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

  return (0);
}

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

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

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

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

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

gauthier's avatar
gauthier committed
167
        msg_p = itti_alloc_new_message(TASK_RRC_UE, RRC_STATE_IND);
gauthier's avatar
   
gauthier committed
168
169
        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;
170

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

  return (0);
}

/*------------------------------------------------------------------------------*/
gauthier's avatar
   
gauthier committed
181
void init_SI_UE(module_id_t ue_mod_idP,uint8_t eNB_index) {
182
183
184
185

  int i;


gauthier's avatar
   
gauthier committed
186
187
  UE_rrc_inst[ue_mod_idP].sizeof_SIB1[eNB_index] = 0;
  UE_rrc_inst[ue_mod_idP].sizeof_SI[eNB_index] = 0;
188

gauthier's avatar
   
gauthier committed
189
190
191
  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);
192
193

  for (i=0;i<NB_CNX_UE;i++) {
gauthier's avatar
   
gauthier committed
194
      UE_rrc_inst[ue_mod_idP].si[eNB_index][i] = (SystemInformation_t *)malloc16(sizeof(SystemInformation_t));
195
196
  }

gauthier's avatar
   
gauthier committed
197
198
  UE_rrc_inst[ue_mod_idP].Info[eNB_index].SIB1Status = 0;
  UE_rrc_inst[ue_mod_idP].Info[eNB_index].SIStatus = 0;
199
200
201
}

#ifdef Rel10
gauthier's avatar
   
gauthier committed
202
void init_MCCH_UE(module_id_t ue_mod_idP, uint8_t eNB_index) {
203
  int i;
gauthier's avatar
   
gauthier committed
204
205
206
  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));
207
  for (i=0; i<8;i++) // MAX MBSFN Area
gauthier's avatar
   
gauthier committed
208
    UE_rrc_inst[ue_mod_idP].Info[eNB_index].MCCHStatus[i] = 0;
209
210
211
212
213

}
#endif

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

gauthier's avatar
   
gauthier committed
222
  memset(UE_rrc_inst[ue_mod_idP].kenb, ue_mod_idP, 32);
223

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

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

/*------------------------------------------------------------------------------*/
gauthier's avatar
   
gauthier committed
233
char openair_rrc_lite_ue_init(module_id_t ue_mod_idP, unsigned char eNB_index){
234
  /*-----------------------------------------------------------------------------*/
gauthier's avatar
   
gauthier committed
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
  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;
253
#ifdef Rel10
gauthier's avatar
   
gauthier committed
254
  UE_rrc_inst[ue_mod_idP].integrity_algorithm = SecurityAlgorithmConfig__integrityProtAlgorithm_eia0_v920;
255
#else
gauthier's avatar
   
gauthier committed
256
  UE_rrc_inst[ue_mod_idP].integrity_algorithm = SecurityAlgorithmConfig__integrityProtAlgorithm_reserved;
257
258
#endif

gauthier's avatar
   
gauthier committed
259
  openair_rrc_lite_ue_init_security(ue_mod_idP);
260

gauthier's avatar
   
gauthier committed
261
262
  init_SI_UE(ue_mod_idP,eNB_index);
  LOG_D(RRC,"[UE %d] INIT: phy_sync_2_ch_ind\n", ue_mod_idP);
263
264

#ifndef NO_RRM
gauthier's avatar
   
gauthier committed
265
  send_msg(&S_rrc,msg_rrc_phy_synch_to_CH_ind(ue_mod_idP,eNB_index,UE_rrc_inst[ue_mod_idP].Mac_id));
266
267
268
#endif

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

  return 0;
}

/*------------------------------------------------------------------------------*/
gauthier's avatar
   
gauthier committed
282
void rrc_ue_generate_RRCConnectionRequest(module_id_t ue_mod_idP, frame_t frameP, uint8_t eNB_index){
283
284
  /*------------------------------------------------------------------------------*/

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

gauthier's avatar
   
gauthier committed
287
  if(UE_rrc_inst[ue_mod_idP].Srb0[eNB_index].Tx_buffer.payload_size ==0){
288

gauthier's avatar
gauthier committed
289
290
      // Get RRCConnectionRequest, fill random for now
      // Generate random byte stream for contention resolution
291
292
      for (i=0;i<6;i++) {
#ifdef SMBV   
gauthier's avatar
gauthier committed
293
294
          // if SMBV is configured the contention resolution needs to be fix for the connection procedure to succeed
          rv[i]=i;
295
#else
gauthier's avatar
gauthier committed
296
          rv[i]=taus()&0xff;
297
#endif
gauthier's avatar
gauthier committed
298
299
300
          LOG_T(RRC,"%x.",rv[i]);
      }
      LOG_T(RRC,"\n");
gauthier's avatar
   
gauthier committed
301
      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);
302

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

gauthier's avatar
   
gauthier committed
306
307
      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
308
309
310
      }
      LOG_T(RRC,"\n");
      /*
gauthier's avatar
   
gauthier committed
311
      UE_rrc_inst[ue_mod_idP].Srb0[Idx].Tx_buffer.Payload[i] = taus()&0xff;
312

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

  }
}


mui_t rrc_mui=0;

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

/* NAS Attach request with GUTI */
338
static const char const nas_attach_req_guti[] =
gauthier's avatar
gauthier committed
339
340
341
342
343
344
345
346
347
348
349
350
    {
        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,
    };
351

352
/*------------------------------------------------------------------------------*/
gauthier's avatar
   
gauthier committed
353
void rrc_ue_generate_RRCConnectionSetupComplete(module_id_t ue_mod_idP, frame_t frameP, uint8_t eNB_index, uint8_t Transaction_id){
354
355
  /*------------------------------------------------------------------------------*/

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

winckel's avatar
winckel committed
361
#if defined(ENABLE_ITTI) && defined(ENABLE_USE_MME)
gauthier's avatar
   
gauthier committed
362
363
  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
364
365
366
367
368
#else
  nas_msg         = nas_attach_req_imsi;
  nas_msg_length  = sizeof(nas_attach_req_imsi);
#endif

gauthier's avatar
   
gauthier committed
369
  size = do_RRCConnectionSetupComplete(ue_mod_idP, buffer, Transaction_id, nas_msg_length, nas_msg);
370
371

  LOG_I(RRC,"[UE %d][RAPROC] Frame %d : Logical Channel UL-DCCH (SRB1), Generating RRCConnectionSetupComplete (bytes%d, eNB %d)\n",
gauthier's avatar
   
gauthier committed
372
      ue_mod_idP,frameP, size, eNB_index);
373

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

gauthier's avatar
   
gauthier committed
377
378
  //  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);
379
380
}

gauthier's avatar
   
gauthier committed
381
void rrc_ue_generate_RRCConnectionReconfigurationComplete(module_id_t ue_mod_idP, frame_t frameP, uint8_t eNB_index, uint8_t Transaction_id) {
382

gauthier's avatar
gauthier committed
383
  uint8_t buffer[32], size;
384

gauthier's avatar
   
gauthier committed
385
  size = do_RRCConnectionReconfigurationComplete(ue_mod_idP, buffer, Transaction_id);
386
387

  LOG_I(RRC,"[UE %d] Frame %d : Logical Channel UL-DCCH (SRB1), Generating RRCConnectionReconfigurationComplete (bytes %d, eNB_index %d)\n",
gauthier's avatar
   
gauthier committed
388
      ue_mod_idP,frameP, size, eNB_index);
389
  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",
gauthier's avatar
   
gauthier committed
390
      frameP, ue_mod_idP+NB_eNB_INST, size, eNB_index, rrc_mui, ue_mod_idP+NB_eNB_INST, DCCH);
391

gauthier's avatar
   
gauthier committed
392
393
  //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);
394
395
396
}

/*------------------------------------------------------------------------------*/
gauthier's avatar
   
gauthier committed
397
int rrc_ue_decode_ccch(module_id_t ue_mod_idP, frame_t frameP, SRB_INFO *Srb_info, uint8_t eNB_index){
398
399
400
401
402
  /*------------------------------------------------------------------------------*/

  //DL_CCCH_Message_t dlccchmsg;
  DL_CCCH_Message_t *dl_ccch_msg=NULL;//&dlccchmsg;
  asn_dec_rval_t dec_rval;
403
  int rval=0;
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));

gauthier's avatar
   
gauthier committed
409
410
  //  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);
411
412

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

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

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

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

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

437
    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
438
439
      {
        MessageDef *msg_p;
440

gauthier's avatar
gauthier committed
441
442
443
        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);
444

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

451
  if ((dec_rval.code != RC_OK) && (dec_rval.consumed==0)) {
gauthier's avatar
   
gauthier committed
452
      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
453
454
      vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_CCCH, VCD_FUNCTION_OUT);
      return -1;
455
456
457
458
  }

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

gauthier's avatar
   
gauthier committed
459
      if (UE_rrc_inst[ue_mod_idP].Info[eNB_index].State == RRC_SI_RECEIVED) {
460

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

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

gauthier's avatar
gauthier committed
468
469
          case DL_CCCH_MessageType__c1_PR_rrcConnectionReestablishment:
            LOG_D(RRC,
gauthier's avatar
   
gauthier committed
470
                "[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);
471

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

gauthier's avatar
gauthier committed
477
478
          case DL_CCCH_MessageType__c1_PR_rrcConnectionReestablishmentReject:
            LOG_D(RRC,
gauthier's avatar
   
gauthier committed
479
                "[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
480
            LOG_I(RRC,
gauthier's avatar
   
gauthier committed
481
                "[UE%d] Frame %d : Logical Channel DL-CCCH (SRB0), Received RRCConnectionReestablishmentReject\n", ue_mod_idP, frameP);
gauthier's avatar
gauthier committed
482
483
            rval = 0;
            break;
484

gauthier's avatar
gauthier committed
485
486
          case DL_CCCH_MessageType__c1_PR_rrcConnectionReject:
            LOG_D(RRC,
gauthier's avatar
   
gauthier committed
487
                "[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);
488

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

gauthier's avatar
gauthier committed
494
495
          case DL_CCCH_MessageType__c1_PR_rrcConnectionSetup:
            LOG_D(RRC,
gauthier's avatar
   
gauthier committed
496
                "[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);
497

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

gauthier's avatar
gauthier committed
502
            // Release T300 timer
gauthier's avatar
   
gauthier committed
503
504
            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
505
                &dl_ccch_msg->message.choice.c1.choice.rrcConnectionSetup.criticalExtensions.choice.c1.choice.rrcConnectionSetup_r8.radioResourceConfigDedicated);
506

gauthier's avatar
   
gauthier committed
507
508
509
            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);
510

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

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

  vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_CCCH, VCD_FUNCTION_OUT);
  return rval;
}

gauthier's avatar
   
gauthier committed
526
int32_t rrc_ue_establish_srb1(module_id_t ue_mod_idP, frame_t frameP,uint8_t eNB_index, struct SRB_ToAddMod *SRB_config) {
527
  // add descriptor from RRC PDU
528

gauthier's avatar
gauthier committed
529
  uint8_t lchan_id = DCCH;
530

gauthier's avatar
   
gauthier committed
531
532
533
  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;
534

gauthier's avatar
gauthier committed
535
  // copy default configuration for now
gauthier's avatar
   
gauthier committed
536
537
  //  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);
538
539


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

gauthier's avatar
   
gauthier committed
542
543
  //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);
544

gauthier's avatar
   
gauthier committed
545
  //  UE_rrc_inst[ue_mod_idP].Srb1[eNB_index].Srb_info.Tx_buffer.payload_size=DEFAULT_MEAS_IND_SIZE+1;
546
547
548
549
550


  return(0);
}

gauthier's avatar
   
gauthier committed
551
int32_t rrc_ue_establish_srb2(module_id_t ue_mod_idP, frame_t frameP,uint8_t eNB_index, struct SRB_ToAddMod *SRB_config) {
552
  // add descriptor from RRC PDU
553

gauthier's avatar
gauthier committed
554
  uint8_t lchan_id = DCCH1;
555

gauthier's avatar
   
gauthier committed
556
557
558
  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;
559

gauthier's avatar
gauthier committed
560
  // copy default configuration for now
gauthier's avatar
   
gauthier committed
561
562
  //  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);
563
564


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

gauthier's avatar
   
gauthier committed
567
568
  //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);
569

gauthier's avatar
   
gauthier committed
570
  //  UE_rrc_inst[ue_mod_idP].Srb1[eNB_index].Srb_info.Tx_buffer.payload_size=DEFAULT_MEAS_IND_SIZE+1;
571
572
573
574
575


  return(0);
}

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

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

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

      rb_conf_ipv4(0,//add
gauthier's avatar
   
gauthier committed
616
617
          ue_mod_idP,//cx align with the UE index
          ip_addr_offset3+ue_mod_idP,//inst num_enb+ue_index
618
          (eNB_index * maxDRB) + DRB_config->drb_Identity,//rb
gauthier's avatar
gauthier committed
619
          0,//dscp
gauthier's avatar
   
gauthier committed
620
621
622
          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
623
  }
624
625
#    else
#        ifdef OAI_EMU
gauthier's avatar
   
gauthier committed
626
  oai_emulation.info.oai_ifup[ue_mod_idP]=1;
627
628
629
630
631
632
633
634
#        endif
#    endif
#endif

  return(0);
}


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

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

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

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

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

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

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

gauthier's avatar
   
gauthier committed
787
788
      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
789
790

      LOG_I(RRC,"[UE %d] set rsrp-coeff for eNB %d: %d rsrq-coeff: %d rsrp_factor: %f rsrq_factor: %f \n",
gauthier's avatar
   
gauthier committed
791
792
793
794
795
          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);
796
797
  }

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

802
  if (measConfig->speedStatePars != NULL) {
gauthier's avatar
   
gauthier committed
803
804
      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
805
      else
gauthier's avatar
   
gauthier committed
806
        UE_rrc_inst[ue_mod_idP].speedStatePars = measConfig->speedStatePars;
gauthier's avatar
gauthier committed
807
      LOG_I(RRC,"[UE %d] Configuring mobility optimization params for UE %d \n",
gauthier's avatar
   
gauthier committed
808
          ue_mod_idP,UE_rrc_inst[ue_mod_idP].Info[0].UE_index);
809
  }
810
811
}

812
void    
gauthier's avatar
   
gauthier committed
813
rrc_ue_process_radioResourceConfigDedicated(module_id_t ue_mod_idP, frame_t frameP, uint8_t eNB_index,
gauthier's avatar
gauthier committed
814
    RadioResourceConfigDedicated_t *radioResourceConfigDedicated) {
815
816
817
818

  long SRB_id,DRB_id;
  int i,cnt;
  LogicalChannelConfig_t *SRB1_logicalChannelConfig,*SRB2_logicalChannelConfig;
819
  protocol_ctxt_t   ctxt;
820
821
822
823
824
825
826
#ifdef CBA  
  uint8_t cba_found = 0;
  uint16_t cba_RNTI;
#endif 

  // Save physicalConfigDedicated if present
  if (radioResourceConfigDedicated->physicalConfigDedicated) {
gauthier's avatar
   
gauthier committed
827
828
      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
829
              sizeof(struct PhysicalConfigDedicated));
830

gauthier's avatar
gauthier committed
831
832
      }
      else {
gauthier's avatar
   
gauthier committed
833
          UE_rrc_inst[ue_mod_idP].physicalConfigDedicated[eNB_index] = radioResourceConfigDedicated->physicalConfigDedicated;
gauthier's avatar
gauthier committed
834
      }
835
836
837
  }
  // Apply macMainConfig if present
  if (radioResourceConfigDedicated->mac_MainConfig) {
gauthier's avatar
gauthier committed
838
      if (radioResourceConfigDedicated->mac_MainConfig->present == RadioResourceConfigDedicated__mac_MainConfig_PR_explicitValue) {
gauthier's avatar
   
gauthier committed
839
840
          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
841
842
843
                  sizeof(MAC_MainConfig_t));
          }
          else
gauthier's avatar
   
gauthier committed
844
            UE_rrc_inst[ue_mod_idP].mac_MainConfig[eNB_index] = &radioResourceConfigDedicated->mac_MainConfig->choice.explicitValue;
845
846
847
848
849
      }
  }

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

#if defined(ENABLE_SECURITY)
gauthier's avatar
   
gauthier committed
884
885
886
887
      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);
888
#endif
889

890
891
892
893
894
895
      ctxt.enb_module_id = eNB_index;
      ctxt.ue_module_id  = ue_mod_idP;
      ctxt.frame         = frameP;
      ctxt.enb_flag      = ENB_FLAG_NO;
      // Refresh SRBs
      rrc_pdcp_config_asn1_req(&ctxt,
gauthier's avatar
gauthier committed
896
897
898
          radioResourceConfigDedicated->srb_ToAddModList,
          (DRB_ToAddModList_t*)NULL,
          (DRB_ToReleaseList_t*)NULL,
gauthier's avatar
   
gauthier committed
899
900
          UE_rrc_inst[ue_mod_idP].ciphering_algorithm |
          (UE_rrc_inst[ue_mod_idP].integrity_algorithm << 4),
gauthier's avatar
gauthier committed
901
902
903
          kRRCenc,
          kRRCint,
          NULL
904
#ifdef Rel10
gauthier's avatar
gauthier committed
905
,(PMCH_InfoList_r9_t *)NULL
906
#endif
gauthier's avatar
gauthier committed
907
      );
908

gauthier's avatar
gauthier committed
909
      // Refresh SRBs
910
      rrc_rlc_config_asn1_req(&ctxt,
gauthier's avatar
gauthier committed
911
912
913
          radioResourceConfigDedicated->srb_ToAddModList,
          (DRB_ToAddModList_t*)NULL,
          (DRB_ToReleaseList_t*)NULL
914
#ifdef Rel10
gauthier's avatar
gauthier committed
915
          ,(PMCH_InfoList_r9_t *)NULL
916
#endif
gauthier's avatar
gauthier committed
917
      );
918

919
920
921
922
923
#ifdef ENABLE_RAL
	// first msg that includes srb config	
	UE_rrc_inst[ue_mod_idP].num_srb=radioResourceConfigDedicated->srb_ToAddModList->list.count;
#endif