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

  Eurecom OpenAirInterface 2
  Copyright(c) 1999 - 2010 Eurecom

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

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

  You should have received a copy of the GNU General Public License along with
  this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.

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

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

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


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

#include "defs.h"
#include "extern.h"
42
#include "assertions.h"
43
#include "asn1_conversions.h"
44
45
46
47
48
49
50
51
52
53
54
#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"
#include "LAYER2/RLC/rlc.h"
#include "UTIL/LOG/log.h"
#include "COMMON/mac_rrc_primitives.h"
#include "RRC/LITE/MESSAGES/asn1_msg.h"
#include "RRCConnectionRequest.h"
#include "UL-CCCH-Message.h"
#include "DL-CCCH-Message.h"
#include "UL-DCCH-Message.h"
#include "DL-DCCH-Message.h"
#include "TDD-Config.h"
55
#include "HandoverCommand.h"
56
57
58
59
#include "rlc.h"
#include "SIMULATION/ETH_TRANSPORT/extern.h"

//#ifdef Rel10
60
#include "MeasResults.h"
61
62
63
//#endif

#ifdef USER_MODE
64
65
66
67
# include "RRC/NAS/nas_config.h"
# include "RRC/NAS/rb_config.h"
# include "OCG.h"
# include "OCG_extern.h"
68
69
#endif

70
71
72
73
#if defined(ENABLE_SECURITY)
# include "UTIL/OSA/osa_defs.h"
#endif

74
#if defined(ENABLE_USE_MME)
75
# include "rrc_eNB_S1AP.h"
76
77
# if defined(ENABLE_ITTI)
# else
78
79
#   include "../../S1AP/s1ap_eNB.h"
# endif
80
81
#endif

82
83
84
85
86
87
#include "pdcp.h"

#if defined(ENABLE_ITTI)
# include "intertask_interface.h"
#endif

88
89
90
91
92
93
94
95
//#define XER_PRINT

#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
96
extern void *bigphys_malloc (int);
97
98
#endif

99
extern uint16_t two_tier_hexagonal_cellIds[7];
100
extern inline unsigned int taus (void);
winckel's avatar
RRC:    
winckel committed
101

102
103
104
/* TS 36.331: RRC-TransactionIdentifier ::= INTEGER (0..3) */
static const uint8_t RRC_TRANSACTION_IDENTIFIER_NUMBER = 4;

winckel's avatar
winckel committed
105
mui_t rrc_eNB_mui = 0;
winckel's avatar
RRC:    
winckel committed
106

winckel's avatar
winckel committed
107
108
/*------------------------------------------------------------------------------*/
static void init_SI (u8 Mod_id) {
109

110
111
  u8 SIwindowsize = 1;
  u16 SIperiod = 8;
112
#ifdef Rel10
113
  int i;
114
#endif
115
  /*
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
     uint32_t mib=0;
     int i;
     int N_RB_DL,phich_resource;


     do_MIB(mac_xface->lte_frame_parms,0x321,&mib);

     for (i=0;i<1024;i+=4)
     do_MIB(mac_xface->lte_frame_parms,i,&mib);

     N_RB_DL=6;
     while (N_RB_DL != 0) {
     phich_resource = 1;
     while (phich_resource != 0) {
     for (i=0;i<2;i++) {
     mac_xface->lte_frame_parms->N_RB_DL = N_RB_DL;
     mac_xface->lte_frame_parms->phich_config_common.phich_duration=i;
     mac_xface->lte_frame_parms->phich_config_common.phich_resource = phich_resource;
     do_MIB(mac_xface->lte_frame_parms,0,&mib);
     }
     if (phich_resource == 1)
     phich_resource = 3;
     else if (phich_resource == 3)
     phich_resource = 6;
     else if (phich_resource == 6)
     phich_resource = 12;
     else if (phich_resource == 12)
     phich_resource = 0;
     }
     if (N_RB_DL == 6)
     N_RB_DL = 15;
     else if (N_RB_DL == 15)
     N_RB_DL = 25;
     else if (N_RB_DL == 25)
     N_RB_DL = 50;
     else if (N_RB_DL == 50)
     N_RB_DL = 75;
     else if (N_RB_DL == 75)
     N_RB_DL = 100;
     else if (N_RB_DL == 100)
     N_RB_DL = 0;
     }
     exit(-1);
   */
160
161
162
163

  eNB_rrc_inst[Mod_id].sizeof_SIB1 = 0;
  eNB_rrc_inst[Mod_id].sizeof_SIB23 = 0;

164
  eNB_rrc_inst[Mod_id].SIB1 = (u8 *) malloc16 (32);
165
166

  /*
167
168
169
170
171
     printf ("before SIB1 init : Nid_cell %d\n", mac_xface->lte_frame_parms->Nid_cell);
     printf ("before SIB1 init : frame_type %d,tdd_config %d\n",
     mac_xface->lte_frame_parms->frame_type,
     mac_xface->lte_frame_parms->tdd_config);
   */
172
173

  if (eNB_rrc_inst[Mod_id].SIB1)
174
175
176
177
178
179
180
181
182
183
184
    eNB_rrc_inst[Mod_id].sizeof_SIB1 = do_SIB1 (mac_xface->lte_frame_parms,
                                                (uint8_t *)
                                                eNB_rrc_inst[Mod_id].SIB1,
                                                &eNB_rrc_inst[Mod_id].
                                                siblock1,
                                                &eNB_rrc_inst[Mod_id].sib1);
  else
    {
      LOG_E (RRC, "[eNB] init_SI: FATAL, no memory for SIB1 allocated\n");
      mac_xface->macphy_exit ("");
    }
185
  /*
186
187
188
189
190
     printf ("after SIB1 init : Nid_cell %d\n", mac_xface->lte_frame_parms->Nid_cell);
     printf ("after SIB1 init : frame_type %d,tdd_config %d\n",
     mac_xface->lte_frame_parms->frame_type,
     mac_xface->lte_frame_parms->tdd_config);
   */
191
  if (eNB_rrc_inst[Mod_id].sizeof_SIB1 == 255)
192
193
194
    mac_xface->macphy_exit ("");

  eNB_rrc_inst[Mod_id].SIB23 = (u8 *) malloc16 (64);
195
  if (eNB_rrc_inst[Mod_id].SIB23)    {
196
197
198
199
200
201
202
203
204
205
206

      eNB_rrc_inst[Mod_id].sizeof_SIB23 = do_SIB23 (Mod_id,
                                                    mac_xface->
                                                    lte_frame_parms,
                                                    eNB_rrc_inst[Mod_id].
                                                    SIB23,
                                                    &eNB_rrc_inst[Mod_id].
                                                    systemInformation,
                                                    &eNB_rrc_inst[Mod_id].
                                                    sib2,
                                                    &eNB_rrc_inst[Mod_id].sib3
207
#ifdef Rel10
208
                                                    ,
209
210
                                                    &eNB_rrc_inst[Mod_id].sib13,
                                                    eNB_rrc_inst[Mod_id].MBMS_flag
211
#endif
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
        );
      /*
         eNB_rrc_inst[Mod_id].sizeof_SIB23 = do_SIB2_AT4(Mod_id,
         eNB_rrc_inst[Mod_id].SIB23,
         &eNB_rrc_inst[Mod_id].systemInformation,
         &eNB_rrc_inst[Mod_id].sib2);
       */
      if (eNB_rrc_inst[Mod_id].sizeof_SIB23 == 255)
        mac_xface->macphy_exit ("eNB_rrc_inst[Mod_id].sizeof_SIB23 == 255");

      LOG_T (RRC, "[eNB %d] SIB2/3 Contents (partial)\n", Mod_id);
      LOG_T (RRC, "[eNB %d] pusch_config_common.n_SB = %ld\n", Mod_id,
             eNB_rrc_inst[Mod_id].sib2->radioResourceConfigCommon.
             pusch_ConfigCommon.pusch_ConfigBasic.n_SB);
      LOG_T (RRC, "[eNB %d] pusch_config_common.hoppingMode = %ld\n", Mod_id,
             eNB_rrc_inst[Mod_id].sib2->radioResourceConfigCommon.
             pusch_ConfigCommon.pusch_ConfigBasic.hoppingMode);
      LOG_T (RRC, "[eNB %d] pusch_config_common.pusch_HoppingOffset = %ld\n",
             Mod_id,
             eNB_rrc_inst[Mod_id].sib2->radioResourceConfigCommon.
             pusch_ConfigCommon.pusch_ConfigBasic.pusch_HoppingOffset);
      LOG_T (RRC, "[eNB %d] pusch_config_common.enable64QAM = %d\n", Mod_id,
             (int) eNB_rrc_inst[Mod_id].sib2->radioResourceConfigCommon.
             pusch_ConfigCommon.pusch_ConfigBasic.enable64QAM);
      LOG_T (RRC, "[eNB %d] pusch_config_common.groupHoppingEnabled = %d\n",
             Mod_id,
             (int) eNB_rrc_inst[Mod_id].sib2->radioResourceConfigCommon.
             pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.groupHoppingEnabled);
      LOG_T (RRC, "[eNB %d] pusch_config_common.groupAssignmentPUSCH = %ld\n",
             Mod_id,
             eNB_rrc_inst[Mod_id].sib2->radioResourceConfigCommon.
             pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.
             groupAssignmentPUSCH);
      LOG_T (RRC,
             "[eNB %d] pusch_config_common.sequenceHoppingEnabled = %d\n",
             Mod_id,
             (int) eNB_rrc_inst[Mod_id].sib2->radioResourceConfigCommon.
             pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.
             sequenceHoppingEnabled);
      LOG_T (RRC, "[eNB %d] pusch_config_common.cyclicShift  = %ld\n", Mod_id,
             eNB_rrc_inst[Mod_id].sib2->radioResourceConfigCommon.
             pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.cyclicShift);
254
255
256


#ifdef Rel10
257
258
259
260
261
262
      if (eNB_rrc_inst[Mod_id].MBMS_flag > 0) {
	
        for (i=0; 
	     i< eNB_rrc_inst[Mod_id].sib2->mbsfn_SubframeConfigList->list.count;
	     i++){
	  // SIB 2
263
          //   LOG_D(RRC, "[eNB %d] mbsfn_SubframeConfigList.list.count = %ld\n", Mod_id, eNB_rrc_inst[Mod_id].sib2->mbsfn_SubframeConfigList->list.count);
264
265
266
267
268
           LOG_D (RRC, "[eNB %d] SIB13 contents for MBSFN subframe allocation %d/%d(partial)\n", 
		  Mod_id,i,eNB_rrc_inst[Mod_id].sib2->mbsfn_SubframeConfigList->list.count);
	   LOG_D (RRC, "[eNB %d] mbsfn_Subframe_pattern is  = %x\n", Mod_id,
                 eNB_rrc_inst[Mod_id].sib2->mbsfn_SubframeConfigList->list.array[i]->subframeAllocation.choice.oneFrame.buf[0]>>0);
          LOG_D (RRC, "[eNB %d] radioframe_allocation_period  = %ld (just index number, not the real value)\n", Mod_id, eNB_rrc_inst[Mod_id].sib2->mbsfn_SubframeConfigList->list.array[i]->radioframeAllocationPeriod);        // need to display the real value, using array of char (like in dumping SIB2)
269
270
          LOG_D (RRC, "[eNB %d] radioframe_allocation_offset  = %ld\n",
                 Mod_id,
271
272
                 eNB_rrc_inst[Mod_id].sib2->mbsfn_SubframeConfigList->list.array[i]->radioframeAllocationOffset);
	}
273
          //   SIB13
274
275
276
277
278
279
280
        for (i=0; 
	     i<  eNB_rrc_inst[Mod_id].sib13->mbsfn_AreaInfoList_r9.list.count;
	     i++){
	  LOG_D (RRC,"[eNB %d] SIB13 contents for MBSFN sync area %d/2 (partial)\n", 
		 Mod_id, i,
                 eNB_rrc_inst[Mod_id].sib13->mbsfn_AreaInfoList_r9.list.count);
	  LOG_D (RRC,"[eNB %d] MCCH Repetition Period: %d (just index number, not real value)\n",
281
                 Mod_id,
282
                 eNB_rrc_inst[Mod_id].sib13->mbsfn_AreaInfoList_r9.list.array[i]->mcch_Config_r9.mcch_RepetitionPeriod_r9);
283
          LOG_D (RRC, "[eNB %d] MCCH Offset: %d\n", Mod_id,
284
285
286
287
                 eNB_rrc_inst[Mod_id].sib13->mbsfn_AreaInfoList_r9.list.array[i]->mcch_Config_r9.mcch_Offset_r9);
       
	}
      }
288
289
#endif

290
291
292
293
294
295
296
297
298
299
300
301
302
303
      LOG_D (RRC,
             "[MSC_MSG][FRAME unknown][RRC_UE][MOD %02d][][--- MAC_CONFIG_REQ (SIB1.tdd & SIB2 params) --->][MAC_UE][MOD %02d][]\n",
             Mod_id, Mod_id);

      rrc_mac_config_req (Mod_id, 1, 0, 0,
                          (RadioResourceConfigCommonSIB_t *) &
                          eNB_rrc_inst[Mod_id].sib2->
                          radioResourceConfigCommon,
                          (struct PhysicalConfigDedicated *) NULL,
                          (MeasObjectToAddMod_t **) NULL,
                          (MAC_MainConfig_t *) NULL, 0,
                          (struct LogicalChannelConfig *) NULL,
                          (MeasGapConfig_t *) NULL,
                          eNB_rrc_inst[Mod_id].sib1->tdd_Config,
304
			  NULL,
305
306
307
308
309
310
311
                          &SIwindowsize, &SIperiod,
                          eNB_rrc_inst[Mod_id].sib2->freqInfo.ul_CarrierFreq,
                          eNB_rrc_inst[Mod_id].sib2->freqInfo.ul_Bandwidth,
                          &eNB_rrc_inst[Mod_id].sib2->freqInfo.
                          additionalSpectrumEmission,
                          (MBSFN_SubframeConfigList_t *) eNB_rrc_inst[Mod_id].
                          sib2->mbsfn_SubframeConfigList
312
#ifdef Rel10
313
314
315
316
317
                          ,
                          eNB_rrc_inst[Mod_id].MBMS_flag,
                          (MBSFN_AreaInfoList_r9_t *) & eNB_rrc_inst[Mod_id].
                          sib13->mbsfn_AreaInfoList_r9,
                          (PMCH_InfoList_r9_t *) NULL
318
319
#endif
#ifdef CBA
320
                          ,0,  //eNB_rrc_inst[Mod_id].num_active_cba_groups,
321
322
323
324
325
326
327
328
329
                          0     //eNB_rrc_inst[Mod_id].cba_rnti[0]
#endif
        );
    }
  else
    {
      LOG_E (RRC, "[eNB] init_SI: FATAL, no memory for SIB2/3 allocated\n");
      mac_xface->macphy_exit ("");
    }
330
331
332
}

#ifdef Rel10
winckel's avatar
winckel committed
333
334
/*------------------------------------------------------------------------------*/
static void init_MCCH (u8 Mod_id) {
335

336
  int sync_area=0;
337
  // initialize RRC_eNB_INST MCCH entry
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
  eNB_rrc_inst[Mod_id].MCCH_MESSAGE=malloc(eNB_rrc_inst[Mod_id].num_mbsfn_sync_area*sizeof(uint32_t*));
  for (sync_area = 0;
       sync_area < eNB_rrc_inst[Mod_id].num_mbsfn_sync_area;
       sync_area++){ 
  
    eNB_rrc_inst[Mod_id].sizeof_MCCH_MESSAGE[sync_area] = 0;
    eNB_rrc_inst[Mod_id].MCCH_MESSAGE[sync_area] = (u8 *) malloc16 (32);
    
    if (eNB_rrc_inst[Mod_id].MCCH_MESSAGE[sync_area] == NULL) {
      LOG_E(RRC,"[eNB %d][MAIN] init_MCCH: FATAL, no memory for MCCH MESSAGE allocated \n", Mod_id);
      mac_xface->macphy_exit("[RRC][init_MCCH] not enough memory\n");
    } else {
      eNB_rrc_inst[Mod_id].sizeof_MCCH_MESSAGE[sync_area] = do_MBSFNAreaConfig (mac_xface->lte_frame_parms,
										sync_area,
										(uint8_t *) eNB_rrc_inst[Mod_id].MCCH_MESSAGE[sync_area],
										&eNB_rrc_inst[Mod_id].mcch,
										&eNB_rrc_inst[Mod_id].mcch_message);

      LOG_I(RRC,"mcch message pointer %p for sync area %d \n", eNB_rrc_inst[Mod_id].MCCH_MESSAGE[sync_area],sync_area);
      LOG_D (RRC, "[eNB %d] MCCH_MESSAGE  contents for Sync Area %d (partial)\n", Mod_id,sync_area);
358
359
360
361
362
363
      LOG_D (RRC, "[eNB %d] CommonSF_AllocPeriod_r9 %d\n", Mod_id,
             eNB_rrc_inst[Mod_id].mcch_message->commonSF_AllocPeriod_r9);
      LOG_D (RRC,
             "[eNB %d] CommonSF_Alloc_r9.list.count (number of MBSFN Subframe Pattern) %d\n",
             Mod_id,
             eNB_rrc_inst[Mod_id].mcch_message->commonSF_Alloc_r9.list.count);
364
      LOG_D (RRC, "[eNB %d] MBSFN Subframe Pattern: %02x (in hex)\n",
365
366
367
368
369
             Mod_id,
             eNB_rrc_inst[Mod_id].mcch_message->commonSF_Alloc_r9.list.
             array[0]->subframeAllocation.choice.oneFrame.buf[0]);


370
371
372
373
      if (eNB_rrc_inst[Mod_id].sizeof_MCCH_MESSAGE[sync_area] == 255)
	mac_xface->macphy_exit ("");
      else 
	eNB_rrc_inst[Mod_id].MCCH_MESS[sync_area].Active = 1;
374
    }
375
  }
376
  //Set the eNB_rrc_inst[Mod_id].MCCH_MESS.Active to 1 (allow to  transfer MCCH message RRC->MAC in function mac_rrc_data_req)
377
 
378
379
380
381
382

  // ??Configure MCCH logical channel
  // call mac_config_req with appropriate structure from ASN.1 description

  //  LOG_I(RRC, "DUY: serviceID is %d\n",eNB_rrc_inst[Mod_id].mcch_message->pmch_InfoList_r9.list.array[0]->mbms_SessionInfoList_r9.list.array[0]->tmgi_r9.serviceId_r9.buf[2]);
383
  //  LOG_I(RRC, "DUY: session ID is %d\n",eNB_rrc_inst[Mod_id].mcch_message->pmch_InfoList_r9.list.array[0]->mbms_SessionInfoList_r9.list.array[0]->sessionId_r9->buf[0]);
384
385
386
387
388
389
390
391
392
  rrc_mac_config_req (Mod_id, 1, 0, 0,
                      (RadioResourceConfigCommonSIB_t *) NULL,
                      (struct PhysicalConfigDedicated *) NULL,
                      (MeasObjectToAddMod_t **) NULL,
                      (MAC_MainConfig_t *) NULL,
                      0,
                      (struct LogicalChannelConfig *) NULL,
                      (MeasGapConfig_t *) NULL,
                      (TDD_Config_t *) NULL,
393
		      NULL,
394
395
396
                      (u8 *) NULL,
                      (u16 *) NULL,
                      NULL, NULL, NULL, (MBSFN_SubframeConfigList_t *) NULL
397
#ifdef Rel10
398
399
400
                      ,
                      0,
                      (MBSFN_AreaInfoList_r9_t *) NULL,
401
                      (PMCH_InfoList_r9_t *) & (eNB_rrc_inst[Mod_id].mcch_message->pmch_InfoList_r9)
402
#endif
403
#ifdef CBA
404
                      , 0, 0
405
#endif
406
    );
407
408

  //LOG_I(RRC,"DUY: lcid after rrc_mac_config_req is %02d\n",eNB_rrc_inst[Mod_id].mcch_message->pmch_InfoList_r9.list.array[0]->mbms_SessionInfoList_r9.list.array[0]->logicalChannelIdentity_r9);
409

410
411
}

winckel's avatar
winckel committed
412
413
/*------------------------------------------------------------------------------*/
static void init_MBMS (u8 Mod_id, u32 frame) {
414
  // init the configuration for MTCH 
415

416
  if (eNB_rrc_inst[Mod_id].MBMS_flag > 0) {
417

418
    LOG_D(RRC,"[eNB %d] Frame %d : Radio Bearer config request for MBMS\n", Mod_id, frame); //check the lcid
419
420
      // Configuring PDCP and RLC for MBMS Radio Bearer

421
422
      rrc_pdcp_config_asn1_req (Mod_id, frame, 1, 0, 
				NULL,      // SRB_ToAddModList
423
                                NULL,   // DRB_ToAddModList
424
425
426
427
428
                                (DRB_ToReleaseList_t *) NULL,
				0, // security mode
				NULL, // key rrc encryption
				NULL, // key rrc integrity
				NULL // key encryption
429
#ifdef Rel10
430
                                ,
431
                                &(eNB_rrc_inst[Mod_id].mcch_message->pmch_InfoList_r9)
432
#endif
433
434
435
436
437
438
439
440
441
442
443
444
			     );
    
    rrc_rlc_config_asn1_req(Mod_id, frame, 1, 0,
			    NULL,// SRB_ToAddModList
			    NULL,// DRB_ToAddModList
			    NULL,// DRB_ToReleaseList
			    &(eNB_rrc_inst[Mod_id].mcch_message->pmch_InfoList_r9));
    
    //rrc_mac_config_req();
    
  }  
  
445
446
447
}
#endif

winckel's avatar
winckel committed
448
449
450
451
452
453
454
455
456
457
458
459
/*------------------------------------------------------------------------------*/
static void rrc_lite_eNB_init_security(u8 Mod_id, u8 UE_index)
{
#if defined(ENABLE_SECURITY)
    char ascii_buffer[65];
    uint8_t i;

    memset(eNB_rrc_inst[Mod_id].kenb[UE_index], UE_index, 32);

    for (i = 0; i < 32; i++) {
        sprintf(&ascii_buffer[2 * i], "%02X", eNB_rrc_inst[Mod_id].kenb[UE_index][i]);
    }
460
    ascii_buffer[2 * i] = '\0';
winckel's avatar
winckel committed
461
462
463
464
465

    LOG_T(RRC, "[OSA][MOD %02d][UE %02d] kenb    = %s\n", Mod_id, UE_index, ascii_buffer);
#endif
}

466
/*------------------------------------------------------------------------------*/
winckel's avatar
winckel committed
467
uint8_t rrc_eNB_get_next_transaction_identifier(uint8_t Mod_id)
winckel's avatar
RRC:    
winckel committed
468
469
470
{
    static uint8_t rrc_transaction_identifier[NUMBER_OF_eNB_MAX];

471
    rrc_transaction_identifier[Mod_id] = (rrc_transaction_identifier[Mod_id] + 1) % RRC_TRANSACTION_IDENTIFIER_NUMBER;
winckel's avatar
RRC:    
winckel committed
472
473
474
475

    return rrc_transaction_identifier[Mod_id];
}

476
477
/*------------------------------------------------------------------------------*/
/* Functions to handle UE index in eNB UE list */
winckel's avatar
winckel committed
478
479

static uint8_t rrc_eNB_get_next_free_UE_index (uint8_t Mod_id, uint8_t *UE_identity)
480
{
481
  uint8_t i, first_index = UE_INDEX_INVALID, reg = 0;
482
483
484
485

  DevCheck(Mod_id < NB_eNB_INST, Mod_id, NB_eNB_INST, 0);

  for (i = 0; i < NUMBER_OF_UE_MAX; i++) {
winckel's avatar
winckel committed
486
    if ((first_index == UE_INDEX_INVALID) && (eNB_rrc_inst[Mod_id].Info.UE_list[i] == 0)) {
487
488
489
      first_index = i; // save first free position
    }

winckel's avatar
winckel committed
490
    if (memcmp (&eNB_rrc_inst[Mod_id].Info.UE_list[i], UE_identity, sizeof(eNB_rrc_inst[0].Info.UE_list[i])) == 0) {
491
492
493
494
495
496
497
498
499
500
      // UE_identity already registered
      reg = 1;
    }
  }

  if (reg == 0) {
    LOG_I(RRC, "Adding UE %d\n", first_index);
    return (first_index);
  }
  else {
501
    return (UE_INDEX_INVALID);
502
503
504
  }
}

winckel's avatar
winckel committed
505
void rrc_eNB_free_UE_index (uint8_t Mod_id, uint8_t UE_id)
506
507
508
509
{
  DevCheck(Mod_id < NB_eNB_INST, Mod_id, UE_id, NB_eNB_INST);
  DevCheck(UE_id < NUMBER_OF_UE_MAX, Mod_id, UE_id, NUMBER_OF_UE_MAX);

winckel's avatar
winckel committed
510
  LOG_I (RRC, "Removing UE %d 0x%" PRIx64 "\n", UE_id, eNB_rrc_inst[Mod_id].Info.UE_list[UE_id]);
511
  eNB_rrc_inst[Mod_id].Info.UE[UE_id].Status = RRC_IDLE;
winckel's avatar
winckel committed
512
  eNB_rrc_inst[Mod_id].Info.UE_list[UE_id] = 0;
513
514
}

winckel's avatar
winckel committed
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
/*------------------------------------------------------------------------------*/
void rrc_eNB_process_RRCConnectionSetupComplete (u8 Mod_id,
                                                 u32 frame,
                                                 u8 UE_index,
                                                 RRCConnectionSetupComplete_r8_IEs_t *rrcConnectionSetupComplete)
{
  LOG_I (RRC, "[eNB %d][RAPROC] Frame %d : Logical Channel UL-DCCH, ""processing RRCConnectionSetupComplete from UE %d\n",
         Mod_id, frame, UE_index);

#if defined(ENABLE_USE_MME)
  if (EPC_MODE_ENABLED == 1)
  {
    // Forward message to S1AP layer
    rrc_eNB_send_S1AP_NAS_FIRST_REQ(Mod_id, UE_index, rrcConnectionSetupComplete);
  }
  else
#endif
  {
    // RRC loop back (no S1AP), send SecurityModeCommand to UE
    rrc_eNB_generate_SecurityModeCommand (Mod_id, frame, UE_index);
    // rrc_eNB_generate_UECapabilityEnquiry(Mod_id,frame,UE_index);
  }
}

539
/*------------------------------------------------------------------------------*/
winckel's avatar
winckel committed
540
void rrc_eNB_generate_SecurityModeCommand (u8 Mod_id, u32 frame, u16 UE_index)
541
{
winckel's avatar
winckel committed
542
543
  uint8_t buffer[100];
  uint8_t size;
winckel's avatar
winckel committed
544

545
546
  size = do_SecurityModeCommand(Mod_id, buffer, UE_index, rrc_eNB_get_next_transaction_identifier(Mod_id),
      eNB_rrc_inst[Mod_id].ciphering_algorithm[UE_index], eNB_rrc_inst[Mod_id].integrity_algorithm[UE_index]);
winckel's avatar
winckel committed
547

winckel's avatar
winckel committed
548
549
550
  LOG_I (RRC,
         "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate SecurityModeCommand (bytes %d, UE id %d)\n",
         Mod_id, frame, size, UE_index);
winckel's avatar
winckel committed
551

552

winckel's avatar
winckel committed
553
554
555
556
557
558
559
  LOG_D (RRC,
         "[MSC_MSG][FRAME %05d][RRC_eNB][MOD %02d][][--- PDCP_DATA_REQ/%d Bytes (securityModeCommand to UE %d MUI %d) --->][PDCP][MOD %02d][RB %02d]\n",
         frame, Mod_id, size, UE_index, rrc_eNB_mui, Mod_id,
         (UE_index * NB_RB_MAX) + DCCH);
  //rrc_rlc_data_req(Mod_id,frame, 1,(UE_index*NB_RB_MAX)+DCCH,rrc_eNB_mui++,0,size,(char*)buffer);
  pdcp_rrc_data_req (Mod_id, frame, 1, (UE_index * NB_RB_MAX) + DCCH,
                     rrc_eNB_mui++, 0, size, buffer, 1);
560
561
562

}

563
/*------------------------------------------------------------------------------*/
winckel's avatar
winckel committed
564
void rrc_eNB_generate_UECapabilityEnquiry (u8 Mod_id, u32 frame, u16 UE_index)
565
566
{

winckel's avatar
winckel committed
567
568
  uint8_t buffer[100];
  uint8_t size;
569

winckel's avatar
winckel committed
570
571
572
573
574
575
576
577
578
579
580
581
582
583
  size = do_UECapabilityEnquiry (Mod_id, buffer, UE_index, rrc_eNB_get_next_transaction_identifier(Mod_id));

  LOG_I (RRC,
         "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate UECapabilityEnquiry (bytes %d, UE id %d)\n",
         Mod_id, frame, size, UE_index);


  LOG_D (RRC,
         "[MSC_MSG][FRAME %05d][RRC_eNB][MOD %02d][][--- PDCP_DATA_REQ/%d Bytes (UECapabilityEnquiry to UE %d MUI %d) --->][PDCP][MOD %02d][RB %02d]\n",
         frame, Mod_id, size, UE_index, rrc_eNB_mui, Mod_id,
         (UE_index * NB_RB_MAX) + DCCH);
  //rrc_rlc_data_req(Mod_id,frame, 1,(UE_index*NB_RB_MAX)+DCCH,rrc_eNB_mui++,0,size,(char*)buffer);
  pdcp_rrc_data_req (Mod_id, frame, 1, (UE_index * NB_RB_MAX) + DCCH,
                     rrc_eNB_mui++, 0, size, buffer, 1);
584
585
586

}

587
/*------------------------------------------------------------------------------*/
588
589
590
static void rrc_eNB_generate_defaultRRCConnectionReconfiguration (u8 Mod_id, u32 frame,
                                                                  u16 UE_index,
                                                                  u8 ho_state)
591
{
winckel's avatar
winckel committed
592
#if defined(ENABLE_ITTI)
593
  eNB_RRC_UE_INFO *UE_info = &eNB_rrc_inst[Mod_id].Info.UE[UE_index];
winckel's avatar
winckel committed
594
#endif
winckel's avatar
winckel committed
595
596
597
  u8 buffer[RRC_BUF_SIZE];
  u8 size;
  int i;
598

winckel's avatar
winckel committed
599
600
  // configure SRB1/SRB2, PhysicalConfigDedicated, MAC_MainConfig for UE
  eNB_RRC_INST *rrc_inst = &eNB_rrc_inst[Mod_id];
601

winckel's avatar
winckel committed
602
  struct PhysicalConfigDedicated **physicalConfigDedicated = &rrc_inst->physicalConfigDedicated[UE_index];
603
604


winckel's avatar
winckel committed
605
606
607
608
609
610
611
  struct SRB_ToAddMod *SRB2_config;
  struct SRB_ToAddMod__rlc_Config *SRB2_rlc_config;
  struct SRB_ToAddMod__logicalChannelConfig *SRB2_lchan_config;
  struct LogicalChannelConfig__ul_SpecificParameters
    *SRB2_ul_SpecificParameters;
  SRB_ToAddModList_t *SRB_configList = rrc_inst->SRB_configList[UE_index];
  SRB_ToAddModList_t *SRB_configList2;
612

winckel's avatar
winckel committed
613
614
615
616
617
618
619
620
  struct DRB_ToAddMod *DRB_config;
  struct RLC_Config *DRB_rlc_config;
  struct PDCP_Config *DRB_pdcp_config;
  struct PDCP_Config__rlc_UM *PDCP_rlc_UM;
  struct LogicalChannelConfig *DRB_lchan_config;
  struct LogicalChannelConfig__ul_SpecificParameters
    *DRB_ul_SpecificParameters;
  DRB_ToAddModList_t **DRB_configList = &rrc_inst->DRB_configList[UE_index];
621

winckel's avatar
winckel committed
622
623
624
625
626
627
628
629
630
631
632
  MAC_MainConfig_t *mac_MainConfig;
  MeasObjectToAddModList_t *MeasObj_list;
  MeasObjectToAddMod_t *MeasObj;
  ReportConfigToAddModList_t *ReportConfig_list;
  ReportConfigToAddMod_t *ReportConfig_per, *ReportConfig_A1,
    *ReportConfig_A2, *ReportConfig_A3, *ReportConfig_A4, *ReportConfig_A5;
  MeasIdToAddModList_t *MeasId_list;
  MeasIdToAddMod_t *MeasId0, *MeasId1, *MeasId2, *MeasId3, *MeasId4, *MeasId5;
#if Rel10
  long *sr_ProhibitTimer_r9;
#endif
633

winckel's avatar
winckel committed
634
635
  long *logicalchannelgroup, *logicalchannelgroup_drb;
  long *maxHARQ_Tx, *periodicBSR_Timer;
636

winckel's avatar
winckel committed
637
638
639
640
641
  RSRP_Range_t *rsrp=NULL;
  struct MeasConfig__speedStatePars *Sparams=NULL;
  QuantityConfig_t *quantityConfig=NULL;
  CellsToAddMod_t *CellToAdd;
  CellsToAddModList_t *CellsToAddModList;
winckel's avatar
winckel committed
642
  struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList = NULL;
643
  DedicatedInfoNAS_t *dedicatedInfoNas;
644

winckel's avatar
winckel committed
645
  C_RNTI_t *cba_RNTI = NULL;
646
#ifdef CBA
winckel's avatar
winckel committed
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
  //struct PUSCH_CBAConfigDedicated_vlola  *pusch_CBAConfigDedicated_vlola;
  uint8_t *cba_RNTI_buf;
  cba_RNTI = CALLOC (1, sizeof (C_RNTI_t));
  cba_RNTI_buf = CALLOC (1, 2 * sizeof (uint8_t));
  cba_RNTI->buf = cba_RNTI_buf;
  cba_RNTI->size = 2;
  cba_RNTI->bits_unused = 0;
  // associate UEs to the CBa groups as a function of their UE id
  if (rrc_inst->num_active_cba_groups)
    {
      cba_RNTI->buf[0] =
        rrc_inst->cba_rnti[UE_index % rrc_inst->num_active_cba_groups] & 0xff;
      cba_RNTI->buf[1] = 0xff;
      LOG_D (RRC,
             "[eNB %d] Frame %d: cba_RNTI = %x in group %d is attribued to UE %d\n",
             Mod_id, frame,
             rrc_inst->cba_rnti[UE_index % rrc_inst->num_active_cba_groups],
             UE_index % rrc_inst->num_active_cba_groups, UE_index);
    }
  else
    {
      cba_RNTI->buf[0] = 0x0;
      cba_RNTI->buf[1] = 0x0;
      LOG_D (RRC, "[eNB %d] Frame %d: no cba_RNTI is configured for UE %d\n",
             Mod_id, frame, UE_index);
    }
673
674


675
#endif
winckel's avatar
winckel committed
676
677
678
679
680
  // Configure SRB2
  /// SRB2
  SRB2_config = CALLOC (1, sizeof (*SRB2_config));
  SRB_configList2 = CALLOC (1, sizeof (*SRB_configList2));
  memset (SRB_configList2, 0, sizeof (*SRB_configList2));
681

winckel's avatar
winckel committed
682
683
684
  SRB2_config->srb_Identity = 2;
  SRB2_rlc_config = CALLOC (1, sizeof (*SRB2_rlc_config));
  SRB2_config->rlc_Config = SRB2_rlc_config;
685

winckel's avatar
winckel committed
686
687
688
689
690
691
692
693
  SRB2_rlc_config->present = SRB_ToAddMod__rlc_Config_PR_explicitValue;
  SRB2_rlc_config->choice.explicitValue.present = RLC_Config_PR_am;
  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.t_PollRetransmit = T_PollRetransmit_ms15;
  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollPDU = PollPDU_p8;
  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollByte = PollByte_kB1000;
  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.maxRetxThreshold = UL_AM_RLC__maxRetxThreshold_t32;
  SRB2_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_Reordering = T_Reordering_ms50;
  SRB2_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_StatusProhibit =  T_StatusProhibit_ms10;
694

winckel's avatar
winckel committed
695
696
  SRB2_lchan_config = CALLOC (1, sizeof (*SRB2_lchan_config));
  SRB2_config->logicalChannelConfig = SRB2_lchan_config;
697

winckel's avatar
winckel committed
698
  SRB2_lchan_config->present =  SRB_ToAddMod__logicalChannelConfig_PR_explicitValue;
699

winckel's avatar
winckel committed
700
  SRB2_ul_SpecificParameters = CALLOC (1, sizeof (*SRB2_ul_SpecificParameters));
701

winckel's avatar
winckel committed
702
703
704
  SRB2_ul_SpecificParameters->priority = 1;
  SRB2_ul_SpecificParameters->prioritisedBitRate = LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
  SRB2_ul_SpecificParameters->bucketSizeDuration = LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
705

winckel's avatar
winckel committed
706
707
708
  // LCG for CCCH and DCCH is 0 as defined in 36331
  logicalchannelgroup = CALLOC (1, sizeof (long));
  *logicalchannelgroup = 0;
709

winckel's avatar
winckel committed
710
  SRB2_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup;
711

winckel's avatar
winckel committed
712
713
714
  SRB2_lchan_config->choice.explicitValue.ul_SpecificParameters =  SRB2_ul_SpecificParameters;
  ASN_SEQUENCE_ADD (&SRB_configList->list, SRB2_config);
  ASN_SEQUENCE_ADD (&SRB_configList2->list, SRB2_config);
715

winckel's avatar
winckel committed
716
717
718
719
  // Configure DRB
  *DRB_configList = CALLOC (1, sizeof (*DRB_configList));
  /// DRB
  DRB_config = CALLOC (1, sizeof (*DRB_config));
720

winckel's avatar
winckel committed
721
722
723
724
725
726
727
728
729
730
731
  //DRB_config->drb_Identity = (DRB_Identity_t) 1; //allowed values 1..32
  // NN: this is the 1st DRB for this ue, so set it to 1
  DRB_config->drb_Identity = (DRB_Identity_t) 1;        // (UE_index+1); //allowed values 1..32
  DRB_config->logicalChannelIdentity = CALLOC (1, sizeof (long));
  *(DRB_config->logicalChannelIdentity) = (long) 3;
  DRB_rlc_config = CALLOC (1, sizeof (*DRB_rlc_config));
  DRB_config->rlc_Config = DRB_rlc_config;
  DRB_rlc_config->present = RLC_Config_PR_um_Bi_Directional;
  DRB_rlc_config->choice.um_Bi_Directional.ul_UM_RLC.sn_FieldLength =  SN_FieldLength_size10;
  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.sn_FieldLength =  SN_FieldLength_size10;
  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering =   T_Reordering_ms5;
732

winckel's avatar
winckel committed
733
734
735
736
737
738
739
740
  DRB_pdcp_config = CALLOC (1, sizeof (*DRB_pdcp_config));
  DRB_config->pdcp_Config = DRB_pdcp_config;
  DRB_pdcp_config->discardTimer = NULL;
  DRB_pdcp_config->rlc_AM = NULL;
  PDCP_rlc_UM = CALLOC (1, sizeof (*PDCP_rlc_UM));
  DRB_pdcp_config->rlc_UM = PDCP_rlc_UM;
  PDCP_rlc_UM->pdcp_SN_Size = PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits;
  DRB_pdcp_config->headerCompression.present = PDCP_Config__headerCompression_PR_notUsed;
741

winckel's avatar
winckel committed
742
743
744
745
  DRB_lchan_config = CALLOC (1, sizeof (*DRB_lchan_config));
  DRB_config->logicalChannelConfig = DRB_lchan_config;
  DRB_ul_SpecificParameters = CALLOC (1, sizeof (*DRB_ul_SpecificParameters));
  DRB_lchan_config->ul_SpecificParameters = DRB_ul_SpecificParameters;
746

747

winckel's avatar
winckel committed
748
749
750
  DRB_ul_SpecificParameters->priority = 2;      // lower priority than srb1, srb2
  DRB_ul_SpecificParameters->prioritisedBitRate = LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
  DRB_ul_SpecificParameters->bucketSizeDuration = LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
751

winckel's avatar
winckel committed
752
753
754
755
  // LCG for DTCH can take the value from 1 to 3 as defined in 36331: normally controlled by upper layers (like RRM)
  logicalchannelgroup_drb = CALLOC (1, sizeof (long));
  *logicalchannelgroup_drb = 1;
  DRB_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup_drb;
winckel's avatar
RRC:    
winckel committed
756

winckel's avatar
winckel committed
757
  ASN_SEQUENCE_ADD (&(*DRB_configList)->list, DRB_config);
winckel's avatar
RRC:    
winckel committed
758

winckel's avatar
winckel committed
759
760
  mac_MainConfig = CALLOC (1, sizeof (*mac_MainConfig));
  eNB_rrc_inst[Mod_id].mac_MainConfig[UE_index] = mac_MainConfig;
winckel's avatar
RRC:    
winckel committed
761

winckel's avatar
winckel committed
762
  mac_MainConfig->ul_SCH_Config = CALLOC (1, sizeof (*mac_MainConfig->ul_SCH_Config));
763

winckel's avatar
winckel committed
764
765
766
767
768
769
770
771
  maxHARQ_Tx = CALLOC (1, sizeof (long));
  *maxHARQ_Tx = MAC_MainConfig__ul_SCH_Config__maxHARQ_Tx_n5;
  mac_MainConfig->ul_SCH_Config->maxHARQ_Tx = maxHARQ_Tx;
  periodicBSR_Timer = CALLOC (1, sizeof (long));
  *periodicBSR_Timer = MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_sf64;
  mac_MainConfig->ul_SCH_Config->periodicBSR_Timer = periodicBSR_Timer;
  mac_MainConfig->ul_SCH_Config->retxBSR_Timer =  MAC_MainConfig__ul_SCH_Config__retxBSR_Timer_sf320;
  mac_MainConfig->ul_SCH_Config->ttiBundling = 0;       // FALSE
772

winckel's avatar
winckel committed
773
  mac_MainConfig->drx_Config = NULL;
winckel's avatar
winckel committed
774

winckel's avatar
winckel committed
775
  mac_MainConfig->phr_Config =  CALLOC (1, sizeof (*mac_MainConfig->phr_Config));
winckel's avatar
RRC:    
winckel committed
776

winckel's avatar
winckel committed
777
778
  mac_MainConfig->phr_Config->present = MAC_MainConfig__phr_Config_PR_setup;
  mac_MainConfig->phr_Config->choice.setup.periodicPHR_Timer = MAC_MainConfig__phr_Config__setup__periodicPHR_Timer_sf20;       // sf20 = 20 subframes
winckel's avatar
RRC:    
winckel committed
779

winckel's avatar
winckel committed
780
  mac_MainConfig->phr_Config->choice.setup.prohibitPHR_Timer = MAC_MainConfig__phr_Config__setup__prohibitPHR_Timer_sf20;       // sf20 = 20 subframes
781

winckel's avatar
winckel committed
782
  mac_MainConfig->phr_Config->choice.setup.dl_PathlossChange = MAC_MainConfig__phr_Config__setup__dl_PathlossChange_dB1;        // Value dB1 =1 dB, dB3 = 3 dB
winckel's avatar
RRC:    
winckel committed
783

winckel's avatar
winckel committed
784
785
786
787
788
#ifdef Rel10
  sr_ProhibitTimer_r9 = CALLOC (1, sizeof (long));
  *sr_ProhibitTimer_r9 = 0;     // SR tx on PUCCH, Value in number of SR period(s). Value 0 = no timer for SR, Value 2= 2*SR
  mac_MainConfig->sr_ProhibitTimer_r9 = sr_ProhibitTimer_r9;
  //sps_RA_ConfigList_rlola = NULL;
789
#endif
790

791

winckel's avatar
winckel committed
792
793
794
  // Measurement ID list
  MeasId_list = CALLOC (1, sizeof (*MeasId_list));
  memset ((void *) MeasId_list, 0, sizeof (*MeasId_list));
winckel's avatar
RRC:    
winckel committed
795

winckel's avatar
winckel committed
796
797
798
799
800
  MeasId0 = CALLOC (1, sizeof (*MeasId0));
  MeasId0->measId = 1;
  MeasId0->measObjectId = 1;
  MeasId0->reportConfigId = 1;
  ASN_SEQUENCE_ADD (&MeasId_list->list, MeasId0);
801

winckel's avatar
winckel committed
802
803
804
805
806
  MeasId1 = CALLOC (1, sizeof (*MeasId1));
  MeasId1->measId = 2;
  MeasId1->measObjectId = 1;
  MeasId1->reportConfigId = 2;
  ASN_SEQUENCE_ADD (&MeasId_list->list, MeasId1);
winckel's avatar
RRC:    
winckel committed
807

winckel's avatar
winckel committed
808
809
810
811
812
  MeasId2 = CALLOC (1, sizeof (*MeasId2));
  MeasId2->measId = 3;
  MeasId2->measObjectId = 1;
  MeasId2->reportConfigId = 3;
  ASN_SEQUENCE_ADD (&MeasId_list->list, MeasId2);
winckel's avatar
RRC:    
winckel committed
813

winckel's avatar
winckel committed
814
815
816
817
818
  MeasId3 = CALLOC (1, sizeof (*MeasId3));
  MeasId3->measId = 4;
  MeasId3->measObjectId = 1;
  MeasId3->reportConfigId = 4;
  ASN_SEQUENCE_ADD (&MeasId_list->list, MeasId3);
winckel's avatar
RRC:    
winckel committed
819

winckel's avatar
winckel committed
820
821
822
823
824
  MeasId4 = CALLOC (1, sizeof (*MeasId4));
  MeasId4->measId = 5;
  MeasId4->measObjectId = 1;
  MeasId4->reportConfigId = 5;
  ASN_SEQUENCE_ADD (&MeasId_list->list, MeasId4);
winckel's avatar
RRC:    
winckel committed
825

winckel's avatar
winckel committed
826
827
828
829
830
  MeasId5 = CALLOC (1, sizeof (*MeasId5));
  MeasId5->measId = 6;
  MeasId5->measObjectId = 1;
  MeasId5->reportConfigId = 6;
  ASN_SEQUENCE_ADD (&MeasId_list->list, MeasId5);
winckel's avatar
RRC:    
winckel committed
831

winckel's avatar
winckel committed
832
  //  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->measIdToAddModList = MeasId_list;
winckel's avatar
RRC:    
winckel committed
833

winckel's avatar
winckel committed
834
835
836
  // Add one EUTRA Measurement Object
  MeasObj_list = CALLOC (1, sizeof (*MeasObj_list));
  memset ((void *) MeasObj_list, 0, sizeof (*MeasObj_list));
winckel's avatar
RRC:    
winckel committed
837

winckel's avatar
winckel committed
838
  // Configure MeasObject
winckel's avatar
RRC:    
winckel committed
839

winckel's avatar
winckel committed
840
841
  MeasObj = CALLOC (1, sizeof (*MeasObj));
  memset ((void *) MeasObj, 0, sizeof (*MeasObj));
winckel's avatar
RRC:    
winckel committed
842

winckel's avatar
winckel committed
843
844
845
846
847
848
849
850
851
852
  MeasObj->measObjectId = 1;
  MeasObj->measObject.present =  MeasObjectToAddMod__measObject_PR_measObjectEUTRA;
  MeasObj->measObject.choice.measObjectEUTRA.carrierFreq = 36090;
  MeasObj->measObject.choice.measObjectEUTRA.allowedMeasBandwidth = AllowedMeasBandwidth_mbw25;
  MeasObj->measObject.choice.measObjectEUTRA.presenceAntennaPort1 = 1;
  MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.buf = CALLOC (1, sizeof (uint8_t));
  MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.buf[0] = 0;
  MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.size = 1;
  MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.bits_unused = 6;
  MeasObj->measObject.choice.measObjectEUTRA.offsetFreq = NULL; // Default is 15 or 0dB
853

winckel's avatar
winckel committed
854
  MeasObj->measObject.choice.measObjectEUTRA.cellsToAddModList = (CellsToAddModList_t *) CALLOC (1, sizeof (*CellsToAddModList));
855

winckel's avatar
winckel committed
856
  CellsToAddModList = MeasObj->measObject.choice.measObjectEUTRA.cellsToAddModList;
857

winckel's avatar
winckel committed
858
859
860
861
862
863
  // Add adjacent cell lists (6 per eNB)
  for (i = 0; i < 6; i++)   {
      CellToAdd = (CellsToAddMod_t *) CALLOC (1, sizeof (*CellToAdd));
      CellToAdd->cellIndex = i + 1;
      CellToAdd->physCellId = get_adjacent_cell_id (Mod_id, i);
      CellToAdd->cellIndividualOffset = Q_OffsetRange_dB0;
864

winckel's avatar
winckel committed
865
866
      ASN_SEQUENCE_ADD (&CellsToAddModList->list, CellToAdd);
  }
867

winckel's avatar
winckel committed
868
869
  ASN_SEQUENCE_ADD (&MeasObj_list->list, MeasObj);
  //  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->measObjectToAddModList = MeasObj_list;
870

winckel's avatar
winckel committed
871
872
  // Report Configurations for periodical, A1-A5 events
  ReportConfig_list = CALLOC (1, sizeof (*ReportConfig_list));
873

winckel's avatar
winckel committed
874
  ReportConfig_per = CALLOC (1, sizeof (*ReportConfig_per));
875

winckel's avatar
winckel committed
876
  ReportConfig_A1 = CALLOC (1, sizeof (*ReportConfig_A1));
877

winckel's avatar
winckel committed
878
  ReportConfig_A2 = CALLOC (1, sizeof (*ReportConfig_A2));
879

winckel's avatar
winckel committed
880
  ReportConfig_A3 = CALLOC (1, sizeof (*ReportConfig_A3));
881

winckel's avatar
winckel committed
882
  ReportConfig_A4 = CALLOC (1, sizeof (*ReportConfig_A4));
883

winckel's avatar
winckel committed
884
  ReportConfig_A5 = CALLOC (1, sizeof (*ReportConfig_A5));
885

winckel's avatar
winckel committed
886
887
888
889
890
891
892
893
894
  ReportConfig_per->reportConfigId = 1;
  ReportConfig_per->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerType.present = ReportConfigEUTRA__triggerType_PR_periodical;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerType.choice.periodical.purpose = ReportConfigEUTRA__triggerType__periodical__purpose_reportStrongestCells;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerQuantity = ReportConfigEUTRA__triggerQuantity_rsrp;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportInterval = ReportInterval_ms120;
  ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;
895

winckel's avatar
winckel committed
896
897
898
899
900
901
902
903
904
  ASN_SEQUENCE_ADD (&ReportConfig_list->list, ReportConfig_per);
 
  ReportConfig_A1->reportConfigId = 2;
  ReportConfig_A1->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.present = ReportConfigEUTRA__triggerType_PR_event;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present = ReportConfigEUTRA__triggerType__event__eventId_PR_eventA1;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA1.a1_Threshold.present =
    ThresholdEUTRA_PR_threshold_RSRP;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA1.a1_Threshold.choice.threshold_RSRP = 10;
905

winckel's avatar
winckel committed
906
907
908
909
910
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerQuantity = ReportConfigEUTRA__triggerQuantity_rsrp;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportInterval = ReportInterval_ms120;
  ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;
911

winckel's avatar
winckel committed
912
  ASN_SEQUENCE_ADD (&ReportConfig_list->list, ReportConfig_A1);
913

winckel's avatar
winckel committed
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
  if (ho_state == 1 /*HO_MEASURMENT*/ ){
    LOG_I(RRC,"[eNB %d] frame %d: requesting A2, A3, A4, A5, and A6 event reporting\n", Mod_id, frame);
    ReportConfig_A2->reportConfigId                                                              = 3;
    ReportConfig_A2->reportConfig.present                                                        = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.present                  = ReportConfigEUTRA__triggerType_PR_event;
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present= ReportConfigEUTRA__triggerType__event__eventId_PR_eventA2;
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA2.a2_Threshold.present = ThresholdEUTRA_PR_threshold_RSRP;
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA2.a2_Threshold.choice.threshold_RSRP = 10;
    
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerQuantity                       = ReportConfigEUTRA__triggerQuantity_rsrp;
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportQuantity                        = ReportConfigEUTRA__reportQuantity_both;
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.maxReportCells                        = 2;
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportInterval                        = ReportInterval_ms120;
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportAmount                          = ReportConfigEUTRA__reportAmount_infinity;
    
    ASN_SEQUENCE_ADD(&ReportConfig_list->list,ReportConfig_A2);
930

winckel's avatar
winckel committed
931
932
933
934
    ReportConfig_A3->reportConfigId                                                              = 4;
    ReportConfig_A3->reportConfig.present                                                        = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.present                   = ReportConfigEUTRA__triggerType_PR_event;
    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present = ReportConfigEUTRA__triggerType__event__eventId_PR_eventA3;
935

winckel's avatar
winckel committed
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA3.a3_Offset = 1;//10;
    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA3.reportOnLeave = 1;
    
    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerQuantity                       = ReportConfigEUTRA__triggerQuantity_rsrp;
    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportQuantity                        = ReportConfigEUTRA__reportQuantity_both;
    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.maxReportCells                        = 2;
    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportInterval                        = ReportInterval_ms120;
    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportAmount                          = ReportConfigEUTRA__reportAmount_infinity;
    
    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.hysteresis   = 0.5;
    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.timeToTrigger = TimeToTrigger_ms40;
    ASN_SEQUENCE_ADD(&ReportConfig_list->list,ReportConfig_A3);
    
    ReportConfig_A4->reportConfigId                                                              = 5;
    ReportConfig_A4->reportConfig.present                                                        = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.present                   = ReportConfigEUTRA__triggerType_PR_event;
    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present = ReportConfigEUTRA__triggerType__event__eventId_PR_eventA4;
    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA4.a4_Threshold.present = ThresholdEUTRA_PR_threshold_RSRP;
    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA4.a4_Threshold.choice.threshold_RSRP = 10;
    
    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerQuantity                       = ReportConfigEUTRA__triggerQuantity_rsrp;
    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportQuantity                        = ReportConfigEUTRA__reportQuantity_both;
    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.maxReportCells                        = 2;
    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportInterval                        = ReportInterval_ms120;
    ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportAmount                          = ReportConfigEUTRA__reportAmount_infinity;
    
    ASN_SEQUENCE_ADD(&ReportConfig_list->list,ReportConfig_A4);
    
    ReportConfig_A5->reportConfigId                                                              = 6;
    ReportConfig_A5->reportConfig.present                                                        = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.present                                    = ReportConfigEUTRA__triggerType_PR_event;
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present              = ReportConfigEUTRA__triggerType__event__eventId_PR_eventA5;
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA5.a5_Threshold1.present = ThresholdEUTRA_PR_threshold_RSRP;
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA5.a5_Threshold2.present = ThresholdEUTRA_PR_threshold_RSRP;
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA5.a5_Threshold1.choice.threshold_RSRP = 10;
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA5.a5_Threshold2.choice.threshold_RSRP = 10;
    
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerQuantity                       = ReportConfigEUTRA__triggerQuantity_rsrp;
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportQuantity                        = ReportConfigEUTRA__reportQuantity_both;
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.maxReportCells                        = 2;
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportInterval                        = ReportInterval_ms120;
    ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportAmount                          = ReportConfigEUTRA__reportAmount_infinity;
    
    ASN_SEQUENCE_ADD(&ReportConfig_list->list,ReportConfig_A5);
    //  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->reportConfigToAddModList = ReportConfig_list;
981

winckel's avatar
winckel committed
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
    rsrp=CALLOC(1,sizeof(RSRP_Range_t));
    *rsrp=20;
    
    Sparams = CALLOC(1,sizeof(*Sparams));
    Sparams->present=MeasConfig__speedStatePars_PR_setup;
    Sparams->choice.setup.timeToTrigger_SF.sf_High=SpeedStateScaleFactors__sf_Medium_oDot75;
    Sparams->choice.setup.timeToTrigger_SF.sf_Medium=SpeedStateScaleFactors__sf_High_oDot5;
    Sparams->choice.setup.mobilityStateParameters.n_CellChangeHigh=10;
    Sparams->choice.setup.mobilityStateParameters.n_CellChangeMedium=5;
    Sparams->choice.setup.mobilityStateParameters.t_Evaluation=MobilityStateParameters__t_Evaluation_s60;
    Sparams->choice.setup.mobilityStateParameters.t_HystNormal=MobilityStateParameters__t_HystNormal_s120;
    
    quantityConfig = CALLOC(1,sizeof(*quantityConfig));
    memset((void *)quantityConfig,0,sizeof(*quantityConfig));
    quantityConfig->quantityConfigEUTRA = CALLOC(1,sizeof(struct QuantityConfigEUTRA));
    memset((void *)quantityConfig->quantityConfigEUTRA,0,sizeof(*quantityConfig->quantityConfigEUTRA));
    quantityConfig->quantityConfigCDMA2000 = NULL;
    quantityConfig->quantityConfigGERAN = NULL;
    quantityConfig->quantityConfigUTRA = NULL;
    quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP = CALLOC(1,sizeof(*(quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP)));
    quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ = CALLOC(1,sizeof(*(quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ)));
    *quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP = FilterCoefficient_fc4;
    *quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ = FilterCoefficient_fc4;
  
    LOG_I(RRC,"[eNB %d] Frame %d: potential handover preparation: store the information in an intermediate structure in case of failure\n",Mod_id, frame);
    // store the information in an intermediate structure for Hanodver management
    //rrc_inst->handover_info.as_config.sourceRadioResourceConfig.srb_ToAddModList = CALLOC(1,sizeof());
    rrc_inst->handover_info[UE_index] = CALLOC(1,sizeof(*(rrc_inst->handover_info[UE_index])));
    //memcpy((void *)rrc_inst->handover_info[UE_index]->as_config.sourceRadioResourceConfig.srb_ToAddModList,(void *)SRB_list,sizeof(SRB_ToAddModList_t));
    rrc_inst->handover_info[UE_index]->as_config.sourceRadioResourceConfig.srb_ToAddModList = SRB_configList2;
    //memcpy((void *)rrc_inst->handover_info[UE_index]->as_config.sourceRadioResourceConfig.drb_ToAddModList,(void *)DRB_list,sizeof(DRB_ToAddModList_t));
    rrc_inst->handover_info[UE_index]->as_config.sourceRadioResourceConfig.drb_ToAddModList = *DRB_configList;
    rrc_inst->handover_info[UE_index]->as_config.sourceRadioResourceConfig.drb_ToReleaseList = NULL;
    rrc_inst->handover_info[UE_index]->as_config.sourceRadioResourceConfig.mac_MainConfig = CALLOC(1, sizeof(*rrc_inst->handover_info[UE_index]->as_config.sourceRadioResourceConfig.mac_MainConfig));
    memcpy((void *)rrc_inst->handover_info[UE_index]->as_config.sourceRadioResourceConfig.mac_MainConfig,
           (void *)mac_MainConfig,
           sizeof(MAC_MainConfig_t));
    rrc_inst->handover_info[UE_index]->as_config.sourceRadioResourceConfig.physicalConfigDedicated = CALLOC(1,sizeof(PhysicalConfigDedicated_t));
    memcpy((void *)rrc_inst->handover_info[UE_index]->as_config.sourceRadioResourceConfig.physicalConfigDedicated,
           (void *)rrc_inst->physicalConfigDedicated[UE_index],
           sizeof(PhysicalConfigDedicated_t));
    rrc_inst->handover_info[UE_index]->as_config.sourceRadioResourceConfig.sps_Config = NULL;
    //memcpy((void *)rrc_inst->handover_info[UE_index]->as_config.sourceRadioResourceConfig.sps_Config,(void *)rrc_inst->sps_Config[UE_index],sizeof(SPS_Config_t));
1025

winckel's avatar
winckel committed
1026
1027
  }
   
winckel's avatar
winckel committed
1028
#if defined(ENABLE_ITTI)
1029
1030
1031
1032
1033
1034
1035
  /* Initialize NAS list */
  dedicatedInfoNASList = CALLOC (1, sizeof (struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList));
  /* Add all NAS PDUs to the list */
  for (i = 0; i < UE_info->nb_of_e_rabs; i++)
  {
    if (UE_info->e_rab[i].param.nas_pdu.buffer != NULL)
    {
1036
      dedicatedInfoNas = CALLOC (1, sizeof(DedicatedInfoNAS_t));
1037
1038
1039
1040
1041

      OCTET_STRING_fromBuf (dedicatedInfoNas, (char *) UE_info->e_rab[i].param.nas_pdu.buffer, UE_info->e_rab[i].param.nas_pdu.length);
      ASN_SEQUENCE_ADD (&dedicatedInfoNASList->list, dedicatedInfoNas);
    }

1042
1043
1044
1045
1046
1047
1048
    /* TODO parameters yet to process ... */
    {
      UE_info->e_rab[i].param.qos;
      UE_info->e_rab[i].param.sgw_addr;
      UE_info->e_rab[i].param.gtp_teid;
    }

1049
1050
1051
1052
1053
1054
1055
1056
1057
    /* TODO should test if e RAB are Ok before! */
    eNB_rrc_inst[Mod_id].Info.UE[UE_index].e_rab[i].status = E_RAB_STATUS_DONE;
  }
  /* If list is empty free the list and reset the address */
  if(dedicatedInfoNASList->list.count == 0)
  {
    free (dedicatedInfoNASList);
    dedicatedInfoNASList = NULL;
  }
winckel's avatar
winckel committed
1058
1059
#endif

winckel's avatar
winckel committed
1060
  memset (buffer, 0, RRC_BUF_SIZE);
1061

winckel's avatar
winckel committed
1062
1063
1064
1065
1066
1067
  size = do_RRCConnectionReconfiguration (Mod_id, buffer, UE_index, rrc_eNB_get_next_transaction_identifier(Mod_id),  //Transaction_id,
                                          SRB_configList2, *DRB_configList, NULL,       // DRB2_list,
                                          NULL, //*sps_Config,
                                          physicalConfigDedicated[UE_index], MeasObj_list, ReportConfig_list, 
                                          quantityConfig,
                                          MeasId_list, mac_MainConfig, NULL,NULL,Sparams,rsrp,
1068
1069
                                          cba_RNTI, dedicatedInfoNASList);

winckel's avatar
winckel committed
1070
#if defined(ENABLE_ITTI)
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
  /* Free all NAS PDUs */
  for (i = 0; i < UE_info->nb_of_e_rabs; i++)
  {
    if (UE_info->e_rab[i].param.nas_pdu.buffer != NULL)
    {
      /* Free the NAS PDU buffer and invalidate it */
      free (UE_info->e_rab[i].param.nas_pdu.buffer);
      UE_info->e_rab[i].param.nas_pdu.buffer = NULL;
    }
  }
winckel's avatar
winckel committed
1081
#endif
1082

winckel's avatar
winckel committed
1083
1084
  LOG_I (RRC,"[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate RRCConnectionReconfiguration (bytes %d, UE id %d)\n",
         Mod_id, frame, size, UE_index);
1085

winckel's avatar
winckel committed
1086
1087
1088
1089
1090
1091
  LOG_D (RRC,"[MSC_MSG][FRAME %05d][RRC_eNB][MOD %02d][][--- PDCP_DATA_REQ/%d Bytes (rrcConnectionReconfiguration to UE %d MUI %d) --->][PDCP][MOD %02d][RB %02d]\n",
         frame, Mod_id, size, UE_index, rrc_eNB_mui, Mod_id,
         (UE_index * NB_RB_MAX) + DCCH);
  //rrc_rlc_data_req(Mod_id,frame, 1,(UE_index*NB_RB_MAX)+DCCH,rrc_eNB_mui++,0,size,(char*)buffer);
  pdcp_rrc_data_req (Mod_id, frame, 1, (UE_index * NB_RB_MAX) + DCCH,
                     rrc_eNB_mui++, 0, size, buffer, 1);
1092

winckel's avatar
winckel committed
1093
}
1094

winckel's avatar
winckel committed
1095
1096
1097
1098
/*------------------------------------------------------------------------------*/
void rrc_eNB_process_MeasurementReport (u8 Mod_id, u32 frame, u16 UE_index,
                                   MeasResults_t * measResults2)
{
1099

winckel's avatar
winckel committed
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
  LOG_I (RRC,"[eNB %d] Frame %d: Process Measurement Report From UE %d (Measurement Id %d)\n",
         Mod_id, frame, UE_index, (int) measResults2->measId);
  if (measResults2->measResultNeighCells->choice.measResultListEUTRA.list.count > 0) {
      LOG_I (RRC, "Physical Cell Id %d\n",
             (int) measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[0]->physCellId);
      LOG_I (RRC, "RSRP of Target %d\n",
             (int) *(measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[0]->measResult.rsrpResult));
      LOG_I (RRC, "RSRQ of Target %d\n",
             (int) *(measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[0]->measResult.rsrqResult));
  }
1110
#ifdef Rel10
winckel's avatar
winckel committed
1111
1112
1113
1114
1115
1116
1117
1118
1119
  LOG_I (RRC, "RSRP of Source %d\n",
         measResults2->measResultPCell.rsrpResult);
  LOG_I (RRC, "RSRQ of Source %d\n",
         measResults2->measResultPCell.rsrqResult);
#else
  LOG_I (RRC, "RSRP of Source %d\n",
         measResults2->measResultServCell.rsrpResult);
  LOG_I (RRC, "RSRQ of Source %d\n",
         measResults2->measResultServCell.rsrqResult);
1120
#endif
1121

winckel's avatar
winckel committed
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
  if(eNB_rrc_inst[Mod_id].handover_info[UE_index]->ho_prepare != 0xF0){
    rrc_eNB_generate_HandoverPreparationInformation(Mod_id,
                                                    frame,
                                                    UE_index,
                                                    measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[0]->physCellId);
  }else{
    LOG_D(RRC,"[eNB %d] Frame %d: Ignoring MeasReport from UE %d as Handover is in progress... \n",Mod_id,frame, UE_index);
  }
  //Look for IP address of the target eNB
  //Send Handover Request -> target eNB
  //Wait for Handover Acknowledgement <- target eNB
  //Send Handover Command
1134

winckel's avatar
winckel committed
1135
1136
  //x2delay();
  //    handover_request_x2(UE_index,Mod_id,measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[0]->physCellId);
1137

winckel's avatar
winckel committed
1138
1139
1140
1141
1142
  //    u8 buffer[100];
  //    int size=rrc_eNB_generate_Handover_Command_TeNB(0,0,buffer);
  //
  //      send_check_message((char*)buffer,size);
  //send_handover_command();
1143

1144
1145
}

winckel's avatar
winckel committed
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
/*------------------------------------------------------------------------------*/
void rrc_eNB_generate_HandoverPreparationInformation (u8 Mod_id, u32 frame, u8 UE_index, PhysCellId_t targetPhyId) {
  u8 UE_id_target;
  u8 mod_id_target = get_adjacent_cell_mod_id(targetPhyId);
  HANDOVER_INFO *handoverInfo = CALLOC(1,sizeof(*handoverInfo));
  /*
  u8 buffer[100];
  u8 size;
  struct PhysicalConfigDedicated  **physicalConfigDedicated = &eNB_rrc_inst[Mod_id].physicalConfigDedicated[UE_index];
  RadioResourceConfigDedicated_t *radioResourceConfigDedicated = CALLOC(1,sizeof(RadioResourceConfigDedicated_t));
  */
winckel's avatar
winckel committed
1157

winckel's avatar
winckel committed
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
  handoverInfo->as_config.antennaInfoCommon.antennaPortsCount =  0; //Not used 0- but check value
  handoverInfo->as_config.sourceDl_CarrierFreq = 36090; //Verify!
  memcpy((void*) &handoverInfo->as_config.sourceMasterInformationBlock, 
         (void*) &eNB_rrc_inst[Mod_id].mib,
         sizeof(MasterInformationBlock_t));
  memcpy((void*) &handoverInfo->as_config.sourceMeasConfig, 
         (void*) &eNB_rrc_inst[Mod_id].measConfig[UE_index],
         sizeof(MeasConfig_t));
  //to be configured
  memset((void *)&eNB_rrc_inst[Mod_id].handover_info[UE_index]->as_config.sourceSecurityAlgorithmConfig,
         0,
         sizeof(SecurityAlgorithmConfig_t));
1170

winckel's avatar
winckel committed
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
  memcpy((void *)&eNB_rrc_inst[Mod_id].handover_info[UE_index]->as_config.sourceSystemInformationBlockType1,
         (void *)&eNB_rrc_inst[Mod_id].SIB1,
         sizeof(SystemInformationBlockType1_t));
  memcpy((void *)&eNB_rrc_inst[Mod_id].handover_info[UE_index]->as_config.sourceSystemInformationBlockType2,
         (void *)&eNB_rrc_inst[Mod_id].SIB23,
         sizeof(SystemInformationBlockType2_t));

  eNB_rrc_inst[Mod_id].handover_info[UE_index]->as_context.reestablishmentInfo = CALLOC(1,sizeof(ReestablishmentInfo_t));
  eNB_rrc_inst[Mod_id].handover_info[UE_index]->as_context.reestablishmentInfo->sourcePhysCellId = eNB_rrc_inst[Mod_id].physCellId;
  eNB_rrc_inst[Mod_id].handover_info[UE_index]->as_context.reestablishmentInfo->targetCellShortMAC_I.buf = NULL; // Check values later
  eNB_rrc_inst[Mod_id].handover_info[UE_index]->as_context.reestablishmentInfo->targetCellShortMAC_I.size = 0;
  eNB_rrc_inst[Mod_id].handover_info[UE_index]->as_context.reestablishmentInfo->targetCellShortMAC_I.bits_unused = 0;
  eNB_rrc_inst[Mod_id].handover_info[UE_index]->as_context.reestablishmentInfo->additionalReestabInfoList = NULL;

  eNB_rrc_inst[Mod_id].handover_info[UE_index]->ho_prepare = 0xFF;//0xF0;
  eNB_rrc_inst[Mod_id].handover_info[UE_index]->ho_complete = 0;

  if (mod_id_target != 0xFF) {
    //UE_id_target = rrc_find_free_ue_index(modid_target);
winckel's avatar
winckel committed
1190
    UE_id_target = rrc_eNB_get_next_free_UE_index(mod_id_target,(u8 *) &eNB_rrc_inst[Mod_id].Info.UE_list[UE_index]); //this should return a new index
winckel's avatar
winckel committed
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213

    if (UE_id_target!=0xFF) {
      LOG_N(RRC,"[eNB %d] Frame %d : Emulate sending HandoverPreparationInformation msg from eNB source %d to eNB target %d: source UE_id %d target UE_id %d source_modId: %d target_modId: %d\n",Mod_id,frame,eNB_rrc_inst[Mod_id].physCellId,targetPhyId,UE_index,UE_id_target,Mod_id,mod_id_target);
      eNB_rrc_inst[mod_id_target].handover_info[UE_id_target] = CALLOC(1,sizeof(*(eNB_rrc_inst[mod_id_target].handover_info[UE_id_target])));
      memcpy((void *)&eNB_rrc_inst[mod_id_target].handover_info[UE_id_target]->as_context, 
             (void *)&eNB_rrc_inst[Mod_id].handover_info[UE_index]->as_context,
             sizeof(AS_Context_t));
      memcpy((void *)&eNB_rrc_inst[mod_id_target].handover_info[UE_id_target]->as_config, 
             (void *)&eNB_rrc_inst[Mod_id].handover_info[UE_index]->as_config,
             sizeof(AS_Config_t));
      
      eNB_rrc_inst[mod_id_target].handover_info[UE_id_target]->ho_prepare = 0xFF;
      eNB_rrc_inst[mod_id_target].handover_info[UE_id_target]->ho_complete = 0;

      eNB_rrc_inst[Mod_id].handover_info[UE_index]->modid_t = mod_id_target;
      eNB_rrc_inst[Mod_id].handover_info[UE_index]->ueid_s = UE_index;
      eNB_rrc_inst[Mod_id].handover_info[UE_index]->modid_s = Mod_id;
      eNB_rrc_inst[mod_id_target].handover_info[UE_id_target]->modid_t = mod_id_target;
      eNB_rrc_inst[mod_id_target].handover_info[UE_id_target]->modid_s = Mod_id;
      eNB_rrc_inst[mod_id_target].handover_info[UE_id_target]->ueid_t = UE_id_target;
    }
    else
      LOG_E(RRC,"\nError in obtaining free UE id in target eNB %l for handover \n", targetPhyId);
1214
  }
winckel's avatar