rrc_eNB.c 152 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 "UTIL/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
76
77
# if defined(ENABLE_ITTI)
#   include "s1ap_eNB.h"
# else
78
79
#   include "../../S1AP/s1ap_eNB.h"
# endif
80
81
#endif

82
#include "pdcp.h"
winckel's avatar
winckel committed
83
#include "rrc_eNB_S1AP.h"
84
85
86
87
88

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

89
90
91
92
93
94
95
96
//#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
97
extern void *bigphys_malloc (int);
98
99
#endif

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

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

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

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

111
112
  u8 SIwindowsize = 1;
  u16 SIperiod = 8;
113
#ifdef Rel10
114
  int i;
115
#endif
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
160
     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);
   */
161
162
163
164

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

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

  /*
168
169
170
171
172
     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);
   */
173
174

  if (eNB_rrc_inst[Mod_id].SIB1)
175
176
177
178
179
180
181
182
183
184
185
    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 ("");
    }
186
  /*
187
188
189
190
191
     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);
   */
192
  if (eNB_rrc_inst[Mod_id].sizeof_SIB1 == 255)
193
194
195
    mac_xface->macphy_exit ("");

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

      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
208
#ifdef Rel10
209
                                                    ,
210
211
                                                    &eNB_rrc_inst[Mod_id].sib13,
                                                    eNB_rrc_inst[Mod_id].MBMS_flag
212
#endif
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
254
        );
      /*
         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);
255
256
257


#ifdef Rel10
258
259
260
261
262
263
      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
264
          //   LOG_D(RRC, "[eNB %d] mbsfn_SubframeConfigList.list.count = %ld\n", Mod_id, eNB_rrc_inst[Mod_id].sib2->mbsfn_SubframeConfigList->list.count);
265
266
267
268
269
           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)
270
271
          LOG_D (RRC, "[eNB %d] radioframe_allocation_offset  = %ld\n",
                 Mod_id,
272
273
                 eNB_rrc_inst[Mod_id].sib2->mbsfn_SubframeConfigList->list.array[i]->radioframeAllocationOffset);
	}
274
          //   SIB13
275
276
277
278
279
280
281
        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",
282
                 Mod_id,
283
                 eNB_rrc_inst[Mod_id].sib13->mbsfn_AreaInfoList_r9.list.array[i]->mcch_Config_r9.mcch_RepetitionPeriod_r9);
284
          LOG_D (RRC, "[eNB %d] MCCH Offset: %d\n", Mod_id,
285
286
287
288
                 eNB_rrc_inst[Mod_id].sib13->mbsfn_AreaInfoList_r9.list.array[i]->mcch_Config_r9.mcch_Offset_r9);
       
	}
      }
289
290
#endif

291
292
293
294
295
296
297
298
299
300
301
302
303
304
      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,
305
			  NULL,
306
307
308
309
310
311
312
                          &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
313
#ifdef Rel10
314
315
316
317
318
                          ,
                          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
319
320
#endif
#ifdef CBA
321
                          ,0,  //eNB_rrc_inst[Mod_id].num_active_cba_groups,
322
323
324
325
326
327
328
329
330
                          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 ("");
    }
331
332
333
}

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

337
  int sync_area=0;
338
  // initialize RRC_eNB_INST MCCH entry
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
  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);
359
360
361
362
363
364
      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);
365
      LOG_D (RRC, "[eNB %d] MBSFN Subframe Pattern: %02x (in hex)\n",
366
367
368
369
370
             Mod_id,
             eNB_rrc_inst[Mod_id].mcch_message->commonSF_Alloc_r9.list.
             array[0]->subframeAllocation.choice.oneFrame.buf[0]);


371
372
373
374
      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;
375
    }
376
  }
377
  //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)
378
 
379
380
381
382
383

  // ??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]);
384
  //  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]);
385
386
387
388
389
390
391
392
393
  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,
394
		      NULL,
395
396
397
                      (u8 *) NULL,
                      (u16 *) NULL,
                      NULL, NULL, NULL, (MBSFN_SubframeConfigList_t *) NULL
398
#ifdef Rel10
399
400
401
                      ,
                      0,
                      (MBSFN_AreaInfoList_r9_t *) NULL,
402
                      (PMCH_InfoList_r9_t *) & (eNB_rrc_inst[Mod_id].mcch_message->pmch_InfoList_r9)
403
#endif
404
#ifdef CBA
405
                      , 0, 0
406
#endif
407
    );
408
409

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

411
412
}

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

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

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

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

winckel's avatar
winckel committed
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
/*------------------------------------------------------------------------------*/
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]);
    }

    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
/*------------------------------------------------------------------------------*/
winckel's avatar
winckel committed
588
589
590
591
592
void rrc_eNB_generate_defaultRRCConnectionReconfiguration (u8 Mod_id, u32 frame,
                                                           u16 UE_index,
                                                           u8 * nas_pdu,
                                                           u32 nas_length,
                                                           u8 ho_state)
593
{
594

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
602


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


winckel's avatar
winckel committed
606
607
608
609
610
611
612
  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;
613

winckel's avatar
winckel committed
614
615
616
617
618
619
620
621
  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];
622

winckel's avatar
winckel committed
623
624
625
626
627
628
629
630
631
632
633
  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
634

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

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

winckel's avatar
winckel committed
644
  C_RNTI_t *cba_RNTI = NULL;
645
#ifdef CBA
winckel's avatar
winckel committed
646
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
  //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);
    }
672
673


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

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

winckel's avatar
winckel committed
685
686
687
688
689
690
691
692
  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;
693

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

winckel's avatar
winckel committed
697
  SRB2_lchan_config->present =  SRB_ToAddMod__logicalChannelConfig_PR_explicitValue;
698
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
873
  // Report Configurations for periodical, A1-A5 events
  ReportConfig_list = CALLOC (1, sizeof (*ReportConfig_list));
  memset ((void *) ReportConfig_list, 0, sizeof (*ReportConfig_list));
874

winckel's avatar
winckel committed
875
876
  ReportConfig_per = CALLOC (1, sizeof (*ReportConfig_per));
  memset ((void *) ReportConfig_per, 0, sizeof (*ReportConfig_per));
877

winckel's avatar
winckel committed
878
879
  ReportConfig_A1 = CALLOC (1, sizeof (*ReportConfig_A1));
  memset ((void *) ReportConfig_A1, 0, sizeof (*ReportConfig_A1));
880

winckel's avatar
winckel committed
881
882
  ReportConfig_A2 = CALLOC (1, sizeof (*ReportConfig_A2));
  memset ((void *) ReportConfig_A2, 0, sizeof (*ReportConfig_A2));
883

winckel's avatar
winckel committed
884
885
  ReportConfig_A3 = CALLOC (1, sizeof (*ReportConfig_A3));
  memset ((void *) ReportConfig_A3, 0, sizeof (*ReportConfig_A3));
886

winckel's avatar
winckel committed
887
888
  ReportConfig_A4 = CALLOC (1, sizeof (*ReportConfig_A4));
  memset ((void *) ReportConfig_A4, 0, sizeof (*ReportConfig_A4));
889

winckel's avatar
winckel committed
890
891
  ReportConfig_A5 = CALLOC (1, sizeof (*ReportConfig_A5));
  memset ((void *) ReportConfig_A5, 0, sizeof (*ReportConfig_A5));
892

winckel's avatar
winckel committed
893
894
895
896
897
898
899
900
901
  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;
902

winckel's avatar
winckel committed
903
904
905
906
907
908
909
910
911
  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;
912

winckel's avatar
winckel committed
913
914
915
916
917
  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;
918

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

winckel's avatar
winckel committed
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
  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);
937

winckel's avatar
winckel committed
938
939
940
941
    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;
942

winckel's avatar
winckel committed
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
981
982
983
984
985
986
987
    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;
988

winckel's avatar
winckel committed
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
1025
1026
1027
1028
1029
1030
1031
    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));
1032

winckel's avatar
winckel committed
1033
1034
1035
  }
   
  memset (buffer, 0, RRC_BUF_SIZE);
1036

winckel's avatar
winckel committed
1037
1038
1039
1040
1041
1042
1043
  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,
                                          cba_RNTI, nas_pdu, nas_length);
1044

winckel's avatar
winckel committed
1045
1046
  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);
1047

winckel's avatar
winckel committed
1048
1049
1050
1051
1052
1053
  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);
1054

winckel's avatar
winckel committed
1055
}
1056

winckel's avatar
winckel committed
1057
1058
1059
1060
/*------------------------------------------------------------------------------*/
void rrc_eNB_process_MeasurementReport (u8 Mod_id, u32 frame, u16 UE_index,
                                   MeasResults_t * measResults2)
{
1061

winckel's avatar
winckel committed
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
  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));
  }
1072
#ifdef Rel10
winckel's avatar
winckel committed
1073
1074
1075
1076
1077
1078
1079
1080
1081
  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);
1082
#endif
1083

winckel's avatar
winckel committed
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
  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
1096

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

winckel's avatar
winckel committed
1100
1101
1102
1103
1104
  //    u8 buffer[100];
  //    int size=rrc_eNB_generate_Handover_Command_TeNB(0,0,buffer);
  //
  //      send_check_message((char*)buffer,size);
  //send_handover_command();
1105

1106
1107
}

winckel's avatar
winckel committed
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
/*------------------------------------------------------------------------------*/
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
1119

winckel's avatar
winckel committed
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
  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));
1132

winckel's avatar
winckel committed
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
  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
1152
    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
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175

    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);
1176
  }
winckel's avatar
RRC:    
winckel committed
1177
  else
winckel's avatar
winckel committed
1178
    LOG_E(RRC,"\nError in obtaining Module ID of target eNB for handover \n");
1179
1180
}

winckel's avatar
winckel committed
1181
1182
/*------------------------------------------------------------------------------*/
void rrc_eNB_process_handoverPreparationInformation(u8 Mod_id,u32 frame, u16 UE_index) {
1183

winckel's avatar
winckel committed
1184
  LOG_I(RRC,"[eNB %d] Frame %d : Logical Channel UL-DCCH, processing RRCHandoverPreparationInformation, sending RRCConnectionReconfiguration to UE %d \n",Mod_id,frame,UE_index);
1185
1186


winckel's avatar
winckel committed
1187
1188
  //eNB_rrc_inst[Mod_id].Info.UE_list[UE_index]
  rrc_eNB_generate_RRCConnectionReconfiguration_handover(Mod_id,frame,UE_index,NULL,0);
1189

winckel's avatar
winckel committed
1190
}
1191

winckel's avatar
winckel committed
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
/*------------------------------------------------------------------------------*/
void check_handovers(u8 Mod_id, u32 frame) {
  u8 i;
  for (i=0;i<NUMBER_OF_UE_MAX;i++) {
    if(eNB_rrc_inst[Mod_id].handover_info[i] != NULL) {
      if(eNB_rrc_inst[Mod_id].handover_info[i]->ho_prepare == 0xFF) {
        LOG_D(RRC,"[eNB %d] Frame %d: Incoming handover detected for new UE_idx %d (source eNB %d->target eNB %d) \n",
              Mod_id, frame, i,Mod_id, eNB_rrc_inst[Mod_id].handover_info[i]->modid_t);
        // source eNB generates rrcconnectionreconfiguration to prepare the HO
        rrc_eNB_process_handoverPreparationInformation(Mod_id,frame,i);
        eNB_rrc_inst[Mod_id].handover_info[i]->ho_prepare = 0xF1;
      }
      
      if(eNB_rrc_inst[Mod_id].handover_info[i]->ho_complete == 0xF1) {
        LOG_D(RRC,"[eNB %d] Frame %d: handover Command received for new UE_idx %d current eNB %d target eNB: %d \n",
              Mod_id, frame, i,Mod_id,eNB_rrc_inst[Mod_id].handover_info[i]->modid_t);
        //rrc_eNB_process_handoverPreparationInformation(Mod_id,frame,i);
        pdcp_data_req(Mod_id,frame, 1,
                      (i* NB_RB_MAX)+DCCH,
                      rrc_eNB_mui++,0,
                      eNB_rrc_inst[Mod_id].handover_info[i]->size,
                      eNB_rrc_inst[Mod_id].handover_info[i]->buf,1);
        eNB_rrc_inst[Mod_id].handover_info[i]->ho_complete = 0xF2;
      }
    }
  }
1218
}
winckel's avatar
RRC:    
winckel committed
1219

winckel's avatar
winckel committed
1220
1221
1222
/*------------------------------------------------------------------------------*/
// 5.3.5.4 RRCConnectionReconfiguration including the mobilityControlInfo to prepare the UE handover
void rrc_eNB_generate_RRCConnectionReconfiguration_handover (u8 Mod_id, u32 frame,u16 UE_index,u8 *nas_pdu,u32 nas_length)  {
Cedric Roux's avatar