rrc_eNB.c 86.1 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*******************************************************************************

  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"
#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"
#include "rlc.h"
#include "SIMULATION/ETH_TRANSPORT/extern.h"

//#ifdef Rel10
57
#include "MeasResults.h"
58
59
60
//#endif

#ifdef USER_MODE
61
62
63
64
#include "RRC/NAS/nas_config.h"
#include "RRC/NAS/rb_config.h"
#include "OCG.h"
#include "OCG_extern.h"
65
66
#endif

67
68
69
70
#if defined(ENABLE_SECURITY)
# include "UTIL/OSA/osa_defs.h"
#endif

71
#if defined(ENABLE_USE_MME)
72
#include "../../S1AP/s1ap_eNB.h"
73
74
#endif

75
76
77
78
79
80
#include "pdcp.h"

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

81
82
83
84
85
86
87
88
//#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
89
extern void *bigphys_malloc (int);
90
91
#endif

92
93
extern inline unsigned int taus (void);
void
94
init_SI (u8 Mod_id) {
95

96
97
  u8 SIwindowsize = 1;
  u16 SIperiod = 8;
98
#ifdef Rel10
99
  int i;
100
#endif
101
  /*
102
103
104
105
106
107
108
109
110
111
112
113
114
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
     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);
   */
146
147
148
149

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

150
  eNB_rrc_inst[Mod_id].SIB1 = (u8 *) malloc16 (32);
151
152

  /*
153
154
155
156
157
     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);
   */
158
159

  if (eNB_rrc_inst[Mod_id].SIB1)
160
161
162
163
164
165
166
167
168
169
170
    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 ("");
    }
171
  /*
172
173
174
175
176
     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);
   */
177
  if (eNB_rrc_inst[Mod_id].sizeof_SIB1 == 255)
178
179
180
    mac_xface->macphy_exit ("");

  eNB_rrc_inst[Mod_id].SIB23 = (u8 *) malloc16 (64);
181
  if (eNB_rrc_inst[Mod_id].SIB23)    {
182
183
184
185
186
187
188
189
190
191
192

      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
193
#ifdef Rel10
194
                                                    ,
195
196
                                                    &eNB_rrc_inst[Mod_id].sib13,
                                                    eNB_rrc_inst[Mod_id].MBMS_flag
197
#endif
198
199
200
201
202
203
204
205
206
207
208
209
210
211
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
        );
      /*
         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);
240
241
242


#ifdef Rel10
243
244
245
246
247
248
      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
249
          //   LOG_D(RRC, "[eNB %d] mbsfn_SubframeConfigList.list.count = %ld\n", Mod_id, eNB_rrc_inst[Mod_id].sib2->mbsfn_SubframeConfigList->list.count);
250
251
252
253
254
           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)
255
256
          LOG_D (RRC, "[eNB %d] radioframe_allocation_offset  = %ld\n",
                 Mod_id,
257
258
                 eNB_rrc_inst[Mod_id].sib2->mbsfn_SubframeConfigList->list.array[i]->radioframeAllocationOffset);
	}
259
          //   SIB13
260
261
262
263
264
265
266
        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",
267
                 Mod_id,
268
                 eNB_rrc_inst[Mod_id].sib13->mbsfn_AreaInfoList_r9.list.array[i]->mcch_Config_r9.mcch_RepetitionPeriod_r9);
269
          LOG_D (RRC, "[eNB %d] MCCH Offset: %d\n", Mod_id,
270
271
272
273
                 eNB_rrc_inst[Mod_id].sib13->mbsfn_AreaInfoList_r9.list.array[i]->mcch_Config_r9.mcch_Offset_r9);
       
	}
      }
274
275
#endif

276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
      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,
                          &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
297
#ifdef Rel10
298
299
300
301
302
                          ,
                          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
303
304
#endif
#ifdef CBA
305
306
307
308
309
310
311
312
313
314
                          , 0,  //eNB_rrc_inst[Mod_id].num_active_cba_groups,
                          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 ("");
    }
315
316
317
}

#ifdef Rel10
318
void
319
init_MCCH (u8 Mod_id) {
320

321
  int sync_area=0;
322
  // initialize RRC_eNB_INST MCCH entry
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
  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);
343
344
345
346
347
348
      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);
349
      LOG_D (RRC, "[eNB %d] MBSFN Subframe Pattern: %02x (in hex)\n",
350
351
352
353
354
             Mod_id,
             eNB_rrc_inst[Mod_id].mcch_message->commonSF_Alloc_r9.list.
             array[0]->subframeAllocation.choice.oneFrame.buf[0]);


355
356
357
358
      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;
359
    }
360
  }
361
  //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)
362
 
363
364
365
366
367

  // ??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]);
368
  //  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]);
369
370
371
372
373
374
375
376
377
378
379
380
  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,
                      (u8 *) NULL,
                      (u16 *) NULL,
                      NULL, NULL, NULL, (MBSFN_SubframeConfigList_t *) NULL
381
#ifdef Rel10
382
383
384
                      ,
                      0,
                      (MBSFN_AreaInfoList_r9_t *) NULL,
385
                      (PMCH_InfoList_r9_t *) & (eNB_rrc_inst[Mod_id].mcch_message->pmch_InfoList_r9)
386
#endif
387
#ifdef CBA
388
                      , 0, 0
389
#endif
390
    );
391
392

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

394
395
}

396
void
397
398
init_MBMS (u8 Mod_id, u32 frame) {
  // init the configuration for MTCH 
399

400
  if (eNB_rrc_inst[Mod_id].MBMS_flag > 0) {
401

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

405
406
      rrc_pdcp_config_asn1_req (Mod_id, frame, 1, 0, 
				NULL,      // SRB_ToAddModList
407
                                NULL,   // DRB_ToAddModList
408
409
410
411
412
                                (DRB_ToReleaseList_t *) NULL,
				0, // security mode
				NULL, // key rrc encryption
				NULL, // key rrc integrity
				NULL // key encryption
413
#ifdef Rel10
414
                                ,
415
                                &(eNB_rrc_inst[Mod_id].mcch_message->pmch_InfoList_r9)
416
#endif
417
418
419
420
421
422
423
424
425
426
427
428
			     );
    
    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();
    
  }  
  
429
430
431
432
}

#endif

433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
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
}

450
/*------------------------------------------------------------------------------*/
451
452
453
char
openair_rrc_lite_eNB_init (u8 Mod_id)
{
454
455
456
  /*-----------------------------------------------------------------------------*/

  unsigned char j;
457
458
459
  LOG_I (RRC, "[eNB %d] Init (UE State = RRC_IDLE)...\n", Mod_id);
  LOG_D (RRC, "[MSC_NEW][FRAME 00000][RRC_eNB][MOD %02d][]\n", Mod_id);
  LOG_D (RRC, "[MSC_NEW][FRAME 00000][IP][MOD %02d][]\n", Mod_id);
460

461
462
  for (j = 0; j < NUMBER_OF_UE_MAX; j++)
    eNB_rrc_inst[Mod_id].Info.Status[j] = RRC_IDLE;     //CH_READY;
463

464
465
466
467
468
469
470
  /* Init security parameters */
  for (j = 0; j < NUMBER_OF_UE_MAX; j++) {
    eNB_rrc_inst[Mod_id].ciphering_algorithm[j] = SecurityAlgorithmConfig__cipheringAlgorithm_eea2;
    eNB_rrc_inst[Mod_id].integrity_algorithm[j] = SecurityAlgorithmConfig__integrityProtAlgorithm_eia2;
    rrc_lite_eNB_init_security(Mod_id, j);
  }

471
472
#if defined(ENABLE_USE_MME)
  /* Connect eNB to MME */
473
474
475
476
477
478
479
  if (oai_emulation.info.mme_enabled > 0)
    {
      if (s1ap_eNB_init (oai_emulation.info.mme_ip_address, Mod_id) < 0)
        {
          mac_xface->macphy_exit ("");
          return -1;
        }
480
481
482
    }
#endif

483
  eNB_rrc_inst[Mod_id].Info.Nb_ue = 0;
484

485
  eNB_rrc_inst[Mod_id].Srb0.Active = 0;
486

487
488
489
490
  for (j = 0; j < (NUMBER_OF_UE_MAX + 1); j++)
    {
      eNB_rrc_inst[Mod_id].Srb2[j].Active = 0;
    }
491
492
493
494
495


  /// System Information INIT


496
  LOG_I (RRC, "Checking release \n");
497
498
#ifdef Rel10

499
  // Thishas to come from some top-level configuration
500
501
  printf ("Rel10 RRC detected, MBMS flag %d\n",
          eNB_rrc_inst[Mod_id].MBMS_flag);
502

503
504
#else
  printf ("Rel8 RRC\n");
505
#endif
506
507
#ifdef CBA
  for (j = 0; j < NUM_MAX_CBA_GROUP; j++)
508
    eNB_rrc_inst[Mod_id].cba_rnti[j] = CBA_OFFSET + j;
509

510
511
  if (eNB_rrc_inst[Mod_id].num_active_cba_groups > NUM_MAX_CBA_GROUP)
    eNB_rrc_inst[Mod_id].num_active_cba_groups = NUM_MAX_CBA_GROUP;
512
513
514
515
516
517
518

  LOG_D (RRC,
         "[eNB %d] Initialization of 4 cba_RNTI values (%x %x %x %x) num active groups %d\n",
         Mod_id, eNB_rrc_inst[Mod_id].cba_rnti[0],
         eNB_rrc_inst[Mod_id].cba_rnti[1], eNB_rrc_inst[Mod_id].cba_rnti[2],
         eNB_rrc_inst[Mod_id].cba_rnti[3],
         eNB_rrc_inst[Mod_id].num_active_cba_groups);
519
520
#endif

521
  init_SI (Mod_id);
522
523

#ifdef Rel10
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
  switch (eNB_rrc_inst[Mod_id].MBMS_flag) {
  case 1:
  case 2:
  case 3:
    LOG_I(RRC,"[eNB %d] Configuring 1 MBSFN sync area\n", Mod_id);
    eNB_rrc_inst[Mod_id].num_mbsfn_sync_area=1;
    break;
  case 4: 
    LOG_I(RRC,"[eNB %d] Configuring 2 MBSFN sync area\n", Mod_id);
    eNB_rrc_inst[Mod_id].num_mbsfn_sync_area=2;
    break;
  default:
    eNB_rrc_inst[Mod_id].num_mbsfn_sync_area=0;
    break;
  }
  // if we are here the eNB_rrc_inst[Mod_id].MBMS_flag > 0,
  /// MCCH INIT
  if (eNB_rrc_inst[Mod_id].MBMS_flag > 0 ) {
    init_MCCH (Mod_id);
    /// MTCH data bearer init
    init_MBMS (Mod_id, 0);
  }
  
547
#endif
548

549
550
#ifdef NO_RRM                   //init ch SRB0, SRB1 & BDTCH
  openair_rrc_on (Mod_id, 1);
551
#else
552
553
554
555
  eNB_rrc_inst[Mod_id].Last_scan_req = 0;
  send_msg (&S_rrc,
            msg_rrc_phy_synch_to_MR_ind (Mod_id,
                                         eNB_rrc_inst[Mod_id].Mac_id));
556
557
558
559
560
561
562
#endif

  return 0;

}


563
564
565
u8
get_next_UE_index (u8 Mod_id, u8 * UE_identity)
{
566

567
  u8 i, first_index = 255, reg = 0;
568

569
570
  for (i = 0; i < NUMBER_OF_UE_MAX; i++)
    {
571
572


573
574
575
576
      if ((first_index == 255)
          && (*(unsigned int *) eNB_rrc_inst[Mod_id].Info.UE_list[i] ==
              0x00000000))
        first_index = i;        // save first free position
577

578
579
      if ((eNB_rrc_inst[Mod_id].Info.UE_list[i][0] == UE_identity[0]) && (eNB_rrc_inst[Mod_id].Info.UE_list[i][1] == UE_identity[1]) && (eNB_rrc_inst[Mod_id].Info.UE_list[i][2] == UE_identity[2]) && (eNB_rrc_inst[Mod_id].Info.UE_list[i][3] == UE_identity[3]) && (eNB_rrc_inst[Mod_id].Info.UE_list[i][4] == UE_identity[4]))      // UE_identity already registered
        reg = 1;
580

581
    }
582

583
584
585
586
587
  if (reg == 0)
    {
      LOG_I (RRC, "Adding UE %d\n", first_index);
      return (first_index);
    }
588
  else
589
    return (255);
590
591
}

592
593
594
void
rrc_remove_UE (u8 Mod_id, u8 UE_id)
{
595

596
  LOG_I (RRC, "Removing UE %d\n", UE_id);
597
  eNB_rrc_inst[Mod_id].Info.Status[UE_id] = RRC_IDLE;
598
  *(unsigned int *) eNB_rrc_inst[Mod_id].Info.UE_list[UE_id] = 0x00000000;
599
600
601
602
}


/*------------------------------------------------------------------------------*/
603
604
605
606
int
rrc_eNB_decode_dcch (u8 Mod_id, u32 frame, u8 Srb_id, u8 UE_index,
                     u8 * Rx_sdu, u8 sdu_size)
{
607
608
609
610
  /*------------------------------------------------------------------------------*/

  asn_dec_rval_t dec_rval;
  //UL_DCCH_Message_t uldcchmsg;
611
612
  UL_DCCH_Message_t *ul_dcch_msg = NULL;        //&uldcchmsg;
  UE_EUTRA_Capability_t *UE_EUTRA_Capability = NULL;
613
614
615

  int i;

616
617
618
619
620
621
  if (Srb_id != 1)
    {
      LOG_E (RRC,
             "[eNB %d] Frame %d: Received message on SRB%d, should not have ...\n",
             Mod_id, frame, Srb_id);
    }
622
623
624

  //memset(ul_dcch_msg,0,sizeof(UL_DCCH_Message_t));

625
626
627
628
629
630
631
632
633
634
635
636
637
638
  LOG_D (RRC, "[eNB %d] Frame %d: Decoding UL-DCCH Message\n", Mod_id, frame);
  dec_rval = uper_decode (NULL,
                          &asn_DEF_UL_DCCH_Message,
                          (void **) &ul_dcch_msg, Rx_sdu, sdu_size, 0, 0);
  for (i = 0; i < sdu_size; i++)
    LOG_T (RRC, "%x.", Rx_sdu[i]);
  LOG_T (RRC, "\n");

  if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0))
    {
      LOG_E (RRC, "[UE %d] Frame %d : Failed to decode UL-DCCH (%d bytes)\n",
             Mod_id, frame, dec_rval.consumed);
      return -1;
    }
639

640
641
642
643
644
645
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
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
  if (ul_dcch_msg->message.present == UL_DCCH_MessageType_PR_c1)
    {

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

        case UL_DCCH_MessageType__c1_PR_NOTHING:        /* No components present */
          break;
        case UL_DCCH_MessageType__c1_PR_csfbParametersRequestCDMA2000:
          break;
        case UL_DCCH_MessageType__c1_PR_measurementReport:
          LOG_D (RRC,
                 "[MSC_MSG][FRAME %05d][RLC][MOD %02d][RB %02d][--- RLC_DATA_IND "
                 "%d bytes (measurementReport) --->][RRC_eNB][MOD %02d][]\n",
                 frame, Mod_id, DCCH, sdu_size, Mod_id);
          rrc_eNB_process_MeasurementReport (Mod_id, UE_index,
                                             &ul_dcch_msg->message.choice.c1.
                                             choice.measurementReport.
                                             criticalExtensions.choice.c1.
                                             choice.measurementReport_r8.
                                             measResults);
          break;
        case UL_DCCH_MessageType__c1_PR_rrcConnectionReconfigurationComplete:
          LOG_D (RRC,
                 "[MSC_MSG][FRAME %05d][RLC][MOD %02d][RB %02d][--- RLC_DATA_IND %d bytes "
                 "(RRCConnectionReconfigurationComplete) --->][RRC_eNB][MOD %02d][]\n",
                 frame, Mod_id, DCCH, sdu_size, Mod_id);
          if (ul_dcch_msg->message.choice.c1.choice.
              rrcConnectionReconfigurationComplete.criticalExtensions.
              present ==
              RRCConnectionReconfigurationComplete__criticalExtensions_PR_rrcConnectionReconfigurationComplete_r8)
            {
              rrc_eNB_process_RRCConnectionReconfigurationComplete (Mod_id,
                                                                    frame,
                                                                    UE_index,
                                                                    &ul_dcch_msg->
                                                                    message.
                                                                    choice.c1.
                                                                    choice.
                                                                    rrcConnectionReconfigurationComplete.
                                                                    criticalExtensions.
                                                                    choice.
                                                                    rrcConnectionReconfigurationComplete_r8);
              eNB_rrc_inst[Mod_id].Info.Status[UE_index] = RRC_RECONFIGURED;
              LOG_I (RRC, "[eNB %d] UE %d State = RRC_RECONFIGURED \n",
                     Mod_id, UE_index);
            }
          break;
        case UL_DCCH_MessageType__c1_PR_rrcConnectionReestablishmentComplete:
          LOG_D (RRC,
                 "[MSC_MSG][FRAME %05d][RLC][MOD %02d][RB %02d][--- RLC_DATA_IND %d bytes "
                 "(rrcConnectionReestablishmentComplete) --->][RRC_eNB][MOD %02d][]\n",
                 frame, Mod_id, DCCH, sdu_size, Mod_id);
          break;
        case UL_DCCH_MessageType__c1_PR_rrcConnectionSetupComplete:
          LOG_D (RRC,
                 "[MSC_MSG][FRAME %05d][RLC][MOD %02d][RB %02d][--- RLC_DATA_IND %d bytes "
                 "(RRCConnectionSetupComplete) --->][RRC_eNB][MOD %02d][]\n",
                 frame, Mod_id, DCCH, sdu_size, Mod_id);

          if (ul_dcch_msg->message.choice.c1.choice.
              rrcConnectionSetupComplete.criticalExtensions.present ==
              RRCConnectionSetupComplete__criticalExtensions_PR_c1)
            {
              if (ul_dcch_msg->message.choice.c1.choice.
                  rrcConnectionSetupComplete.criticalExtensions.choice.c1.
                  present ==
                  RRCConnectionSetupComplete__criticalExtensions__c1_PR_rrcConnectionSetupComplete_r8)
                {
                  rrc_eNB_process_RRCConnectionSetupComplete (Mod_id, frame,
                                                              UE_index,
                                                              &ul_dcch_msg->
                                                              message.choice.
                                                              c1.choice.
                                                              rrcConnectionSetupComplete.
                                                              criticalExtensions.
                                                              choice.c1.
                                                              choice.
                                                              rrcConnectionSetupComplete_r8);
                  eNB_rrc_inst[Mod_id].Info.Status[UE_index] = RRC_CONNECTED;
                  LOG_I (RRC, "[eNB %d] UE %d State = RRC_CONNECTED \n",
                         Mod_id, UE_index);
                  LOG_D (RRC,
                         "[MSC_NBOX][FRAME %05d][RRC_eNB][MOD %02d][][Rx RRCConnectionSetupComplete\n"
                         "Now CONNECTED with UE %d][RRC_eNB][MOD %02d][]\n",
                         frame, Mod_id, UE_index, Mod_id);
                }
            }
          break;
        case UL_DCCH_MessageType__c1_PR_securityModeComplete:
          LOG_I (RRC,
                 "[eNB %d] Frame %d received securityModeComplete on UL-DCCH %d from UE %d\n",
                 Mod_id, frame, DCCH, UE_index);
          LOG_D (RRC,
                 "[MSC_MSG][FRAME %05d][RLC][MOD %02d][RB %02d][--- RLC_DATA_IND %d bytes "
                 "(securityModeComplete) --->][RRC_eNB][MOD %02d][]\n", frame,
                 Mod_id, DCCH, sdu_size, Mod_id);
737
#ifdef XER_PRINT
738
          xer_fprint (stdout, &asn_DEF_UL_DCCH_Message, (void *) ul_dcch_msg);
739
#endif
740
741
742
743
744
745
746
747
748
749
          // confirm with PDCP about the security mode for DCCH
          //rrc_pdcp_config_req (Mod_id, frame, 1,ACTION_SET_SECURITY_MODE, (UE_index * NB_RB_MAX) + DCCH, 0x77);
          // continue the procedure
          rrc_eNB_generate_UECapabilityEnquiry (Mod_id, frame, UE_index);
          break;
        case UL_DCCH_MessageType__c1_PR_securityModeFailure:
          LOG_D (RRC,
                 "[MSC_MSG][FRAME %05d][RLC][MOD %02d][RB %02d][--- RLC_DATA_IND %d bytes "
                 "(securityModeFailure) --->][RRC_eNB][MOD %02d][]\n", frame,
                 Mod_id, DCCH, sdu_size, Mod_id);
750
#ifdef XER_PRINT
751
          xer_fprint (stdout, &asn_DEF_UL_DCCH_Message, (void *) ul_dcch_msg);
752
#endif
753
754
755
756
757
758
759
760
761
762
763
764
765
          // cancel the security mode in PDCP

          // followup with the remaining procedure
          rrc_eNB_generate_UECapabilityEnquiry (Mod_id, frame, UE_index);
          break;
        case UL_DCCH_MessageType__c1_PR_ueCapabilityInformation:
          LOG_I (RRC,
                 "[eNB %d] Frame %d received ueCapabilityInformation on UL-DCCH %d from UE %d\n",
                 Mod_id, frame, DCCH, UE_index);
          LOG_D (RRC,
                 "[MSC_MSG][FRAME %05d][RLC][MOD %02d][RB %02d][--- RLC_DATA_IND %d bytes "
                 "(UECapabilityInformation) --->][RRC_eNB][MOD %02d][]\n",
                 frame, Mod_id, DCCH, sdu_size, Mod_id);
766
#ifdef XER_PRINT
767
          xer_fprint (stdout, &asn_DEF_UL_DCCH_Message, (void *) ul_dcch_msg);
768
#endif
769
770
771
772
773
774
775
776
777
778
779
780
781
782
          dec_rval = uper_decode (NULL,
                                  &asn_DEF_UE_EUTRA_Capability,
                                  (void **) &UE_EUTRA_Capability,
                                  ul_dcch_msg->message.choice.c1.choice.
                                  ueCapabilityInformation.criticalExtensions.
                                  choice.c1.choice.ueCapabilityInformation_r8.
                                  ue_CapabilityRAT_ContainerList.list.
                                  array[0]->ueCapabilityRAT_Container.buf,
                                  ul_dcch_msg->message.choice.c1.choice.
                                  ueCapabilityInformation.criticalExtensions.
                                  choice.c1.choice.ueCapabilityInformation_r8.
                                  ue_CapabilityRAT_ContainerList.list.
                                  array[0]->ueCapabilityRAT_Container.size, 0,
                                  0);
783
#ifdef XER_PRINT
784
785
          xer_fprint (stdout, &asn_DEF_UE_EUTRA_Capability,
                      (void *) UE_EUTRA_Capability);
786
#endif
787
788
789
790
791
792
793
          rrc_eNB_generate_defaultRRCConnectionReconfiguration (Mod_id, frame,
                                                                UE_index,
                                                                NULL, 0);
          break;
        case UL_DCCH_MessageType__c1_PR_ulHandoverPreparationTransfer:
          break;
        case UL_DCCH_MessageType__c1_PR_ulInformationTransfer:
794
#if defined(ENABLE_USE_MME)
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
          {
            if (oai_emulation.info.mme_enabled == 1)
              {
                ULInformationTransfer_t *ulInformationTransfer;
                ulInformationTransfer =
                  &ul_dcch_msg->message.choice.c1.choice.
                  ulInformationTransfer;

                if (ulInformationTransfer->criticalExtensions.present ==
                    ULInformationTransfer__criticalExtensions_PR_c1)
                  {
                    if (ulInformationTransfer->criticalExtensions.choice.c1.
                        present ==
                        ULInformationTransfer__criticalExtensions__c1_PR_ulInformationTransfer_r8)
                      {

                        ULInformationTransfer_r8_IEs_t
                          *ulInformationTransferR8;
                        ulInformationTransferR8 =
                          &ulInformationTransfer->criticalExtensions.choice.
                          c1.choice.ulInformationTransfer_r8;
                        if (ulInformationTransferR8->dedicatedInfoType.
                            present ==
                            ULInformationTransfer_r8_IEs__dedicatedInfoType_PR_dedicatedInfoNAS)
                          s1ap_eNB_new_data_request (Mod_id, UE_index,
                                                     ulInformationTransferR8->
                                                     dedicatedInfoType.choice.
                                                     dedicatedInfoNAS.buf,
                                                     ulInformationTransferR8->
                                                     dedicatedInfoType.choice.
                                                     dedicatedInfoNAS.size);
                      }
                  }
              }
          }
830
#endif
831
832
833
          break;
        case UL_DCCH_MessageType__c1_PR_counterCheckResponse:
          break;
834
#ifdef Rel10
835
836
837
838
839
840
841
842
843
844
        case UL_DCCH_MessageType__c1_PR_ueInformationResponse_r9:
          break;
        case UL_DCCH_MessageType__c1_PR_proximityIndication_r9:
          break;
        case UL_DCCH_MessageType__c1_PR_rnReconfigurationComplete_r10:
          break;
        case UL_DCCH_MessageType__c1_PR_mbmsCountingResponse_r10:
          break;
        case UL_DCCH_MessageType__c1_PR_interFreqRSTDMeasurementIndication_r10:
          break;
845
#endif
846
847
848
849
850
851
852
853
854
        default:
          LOG_E (RRC, "[UE %d] Frame %d : Unknown message\n", Mod_id, frame);
          return -1;
        }
      return 0;
    }
  else
    {
      LOG_E (RRC, "[UE %d] Frame %d : Unknown error\n", Mod_id, frame);
855
856
857
858
859
860
861
      return -1;
    }

}


/*------------------------------------------------------------------------------*/
862
863
864
int
rrc_eNB_decode_ccch (u8 Mod_id, u32 frame, SRB_INFO * Srb_info)
{
865
866
  /*------------------------------------------------------------------------------*/

867
  u16 Idx, UE_index;
868
869
870

  asn_dec_rval_t dec_rval;
  //UL_CCCH_Message_t ulccchmsg;
871
  UL_CCCH_Message_t *ul_ccch_msg = NULL;        //&ulccchmsg;
872
  RRCConnectionRequest_r8_IEs_t *rrcConnectionRequest;
873
  int i, rval;
874
875
876
877


  //memset(ul_ccch_msg,0,sizeof(UL_CCCH_Message_t));

878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
  LOG_T (RRC, "[eNB %d] Frame %d: Decoding UL CCCH %x.%x.%x.%x.%x.%x (%p)\n",
         Mod_id, frame, ((uint8_t *) Srb_info->Rx_buffer.Payload)[0],
         ((uint8_t *) Srb_info->Rx_buffer.Payload)[1],
         ((uint8_t *) Srb_info->Rx_buffer.Payload)[2],
         ((uint8_t *) Srb_info->Rx_buffer.Payload)[3],
         ((uint8_t *) Srb_info->Rx_buffer.Payload)[4],
         ((uint8_t *) Srb_info->Rx_buffer.Payload)[5],
         (uint8_t *) Srb_info->Rx_buffer.Payload);
  dec_rval =
    uper_decode (NULL, &asn_DEF_UL_CCCH_Message, (void **) &ul_ccch_msg,
                 (uint8_t *) Srb_info->Rx_buffer.Payload, 100, 0, 0);
  for (i = 0; i < 8; i++)
    LOG_T (RRC, "%x.", ((u8 *) & ul_ccch_msg)[i]);
  if (dec_rval.consumed == 0)
    {
      LOG_E (RRC, "[eNB %d] FATAL Error in receiving CCCH\n", Mod_id);
      return -1;                //mac_xface->macphy_exit(""); //exit(-1);
    }
  if (ul_ccch_msg->message.present == UL_CCCH_MessageType_PR_c1)
    {

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

        case UL_CCCH_MessageType__c1_PR_NOTHING:
          LOG_I (RRC,
                 "[eNB %d] Frame %d : Received PR_NOTHING on UL-CCCH-Message\n",
                 Mod_id, frame);
          break;

        case UL_CCCH_MessageType__c1_PR_rrcConnectionReestablishmentRequest:
          LOG_D (RRC,
                 "[MSC_MSG][FRAME %05d][MAC_eNB][MOD %02d][][--- MAC_DATA_IND (rrcConnectionReestablishmentRequest on SRB0) -->][RRC_eNB][MOD %02d][]\n",
                 frame, Mod_id, Mod_id);
          LOG_I (RRC,
                 "[eNB %d] Frame %d : RRCConnectionReestablishmentRequest not supported yet\n",
                 Mod_id, frame);
          break;

        case UL_CCCH_MessageType__c1_PR_rrcConnectionRequest:
          LOG_D (RRC,
                 "[MSC_MSG][FRAME %05d][MAC_eNB][MOD %02d][][--- MAC_DATA_IND  (rrcConnectionRequest on SRB0) -->][RRC_eNB][MOD %02d][]\n",
                 frame, Mod_id, Mod_id);

          rrcConnectionRequest =
            &ul_ccch_msg->message.choice.c1.choice.rrcConnectionRequest.
            criticalExtensions.choice.rrcConnectionRequest_r8;
          UE_index =
            get_next_UE_index (Mod_id,
                               (u8 *) rrcConnectionRequest->ue_Identity.
                               choice.randomValue.buf);

          if (UE_index != 255)
            {

              //      memcpy(&Rrc_xface->UE_id[Mod_id][UE_index],(u8 *)rrcConnectionRequest->ue_Identity.choice.randomValue.buf,5);
              memcpy (&eNB_rrc_inst[Mod_id].Info.UE_list[UE_index],
                      (u8 *) rrcConnectionRequest->ue_Identity.choice.
                      randomValue.buf, 5);

              LOG_I (RRC,
                     "[eNB %d] Frame %d : Accept new connection from UE %d (%x%x%x%x%x)\n",
                     Mod_id, frame, UE_index,
                     eNB_rrc_inst[Mod_id].Info.UE_list[UE_index][0],
                     eNB_rrc_inst[Mod_id].Info.UE_list[UE_index][1],
                     eNB_rrc_inst[Mod_id].Info.UE_list[UE_index][2],
                     eNB_rrc_inst[Mod_id].Info.UE_list[UE_index][3],
                     eNB_rrc_inst[Mod_id].Info.UE_list[UE_index][4]);

              //CONFIG SRB2  (DCCHs, ONE per User)  //meas && lchan Cfg
              //eNB_rrc_inst[Mod_id].Info.Dtch_bd_config[UE_index].Status=NEED_RADIO_CONFIG;
              //eNB_rrc_inst[Mod_id].Info.Dtch_bd_config[UE_index].Next_eNBeck_frame=Rrc_xface->Frame_index+1;
              eNB_rrc_inst[Mod_id].Info.Nb_ue++;
951
952

#ifndef NO_RRM
953
              send_msg (&S_rrc, msg_rrc_MR_attach_ind (Mod_id, Mac_id));
954
955
956
#else


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
988
989
990
991
              Idx = (UE_index * NB_RB_MAX) + DCCH;
              // SRB1
              eNB_rrc_inst[Mod_id].Srb1[UE_index].Active = 1;
              eNB_rrc_inst[Mod_id].Srb1[UE_index].Srb_info.Srb_id = Idx;
              memcpy (&eNB_rrc_inst[Mod_id].Srb1[UE_index].Srb_info.
                      Lchan_desc[0], &DCCH_LCHAN_DESC, LCHAN_DESC_SIZE);
              memcpy (&eNB_rrc_inst[Mod_id].Srb1[UE_index].Srb_info.
                      Lchan_desc[1], &DCCH_LCHAN_DESC, LCHAN_DESC_SIZE);

              // SRB2
              eNB_rrc_inst[Mod_id].Srb2[UE_index].Active = 1;
              eNB_rrc_inst[Mod_id].Srb2[UE_index].Srb_info.Srb_id = Idx;
              memcpy (&eNB_rrc_inst[Mod_id].Srb2[UE_index].Srb_info.
                      Lchan_desc[0], &DCCH_LCHAN_DESC, LCHAN_DESC_SIZE);
              memcpy (&eNB_rrc_inst[Mod_id].Srb2[UE_index].Srb_info.
                      Lchan_desc[1], &DCCH_LCHAN_DESC, LCHAN_DESC_SIZE);

              rrc_eNB_generate_RRCConnectionSetup (Mod_id, frame, UE_index);
              //LOG_D(RRC, "[MSC_NBOX][FRAME %05d][RRC_eNB][MOD %02d][][Tx RRCConnectionSetup][RRC_eNB][MOD %02d][]\n",
              //      frame, Mod_id, Mod_id);

              //LOG_D(RRC,"[eNB %d] RLC AM allocation index@0 is %d\n",Mod_id,rlc[Mod_id].m_rlc_am_array[0].allocation);
              //LOG_D(RRC,"[eNB %d] RLC AM allocation index@1 is %d\n",Mod_id,rlc[Mod_id].m_rlc_am_array[1].allocation);
              LOG_I (RRC,
                     "[eNB %d] CALLING RLC CONFIG SRB1 (rbid %d) for UE %d\n",
                     Mod_id, Idx, UE_index);

              //      rrc_pdcp_config_req (Mod_id, frame, 1, ACTION_ADD, idx, UNDEF_SECURITY_MODE);

              //      rrc_rlc_config_req(Mod_id,frame,1,ACTION_ADD,Idx,SIGNALLING_RADIO_BEARER,Rlc_info_am_config);

              rrc_pdcp_config_asn1_req (Mod_id, frame, 1, UE_index,
                                        eNB_rrc_inst[Mod_id].
                                        SRB_configList[UE_index],
                                        (DRB_ToAddModList_t *) NULL,
992
993
994
995
996
                                        (DRB_ToReleaseList_t *) NULL,
                                        0xff,
                                        NULL,
                                        NULL,
                                        NULL
997
#ifdef Rel10
998
                                        , (PMCH_InfoList_r9_t *) NULL
999
#endif
1000
1001
1002
1003
1004
1005
1006
                );

              rrc_rlc_config_asn1_req (Mod_id, frame, 1, UE_index,
                                       eNB_rrc_inst[Mod_id].
                                       SRB_configList[UE_index],
                                       (DRB_ToAddModList_t *) NULL,
                                       (DRB_ToReleaseList_t *) NULL
1007
#ifdef Rel10
1008
                                       , (MBMS_SessionInfoList_r9_t *) NULL
1009
#endif
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
                );
              //LOG_D(RRC,"[eNB %d] RLC AM allocation index@0 is %d\n",Mod_id,rlc[Mod_id].m_rlc_am_array[0].allocation);
              //LOG_D(RRC,"[eNB %d] RLC AM allocation index@1 is %d\n",Mod_id,rlc[Mod_id].m_rlc_am_array[1].allocation);

              /*

                 LOG_D(RRC,"[eNB %d] CALLING RLC CONFIG SRB2 (rbid %d) for UE %d\n",
                 Mod_id,Idx+1,UE_index);
                 Mac_rlc_xface->rrc_rlc_config_req(Mod_id,ACTION_ADD,Idx+1,SIGNALLING_RADIO_BEARER,Rlc_info_am_config);
                 LOG_D(RRC,"[eNB %d] RLC AM allocation index@0 is %d\n",Mod_id,rlc[Mod_id].m_rlc_am_array[0].allocation);
                 LOG_D(RRC,"[eNB %d] RLC AM allocation index@1 is %d\n",rlc[Mod_id].m_rlc_am_array[1].allocation);
               */
1022
#endif //NO_RRM
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
            }
          else
            {
              LOG_E (RRC, "can't add UE, max user count reached!\n");
            }
          break;

        default:
          LOG_E (RRC, "[eNB %d] Frame %d : Unknown message\n", Mod_id, frame);
          rval = -1;
        }
      rval = 0;
    }
  else
    {
      LOG_E (RRC, "[eNB %d] Frame %d : Unknown error \n", Mod_id, frame);
1039
1040
1041
1042
1043
1044
1045
      rval = -1;
    }
  return rval;
}



1046
1047
1048
1049
1050
1051
1052
void
rrc_eNB_process_RRCConnectionSetupComplete (u8 Mod_id,
                                            u32 frame,
                                            u8 UE_index,
                                            RRCConnectionSetupComplete_r8_IEs_t
                                            * rrcConnectionSetupComplete)
{
1053

1054
1055
1056
  LOG_I (RRC, "[eNB %d][RAPROC] Frame %d : Logical Channel UL-DCCH, "
         "processing RRCConnectionSetupComplete from UE %d\n",
         Mod_id, frame, UE_index);
1057
1058
1059
1060

  // Forward message to S1AP layer
#if defined(ENABLE_USE_MME)
  if (oai_emulation.info.mme_enabled == 1)
1061
1062
1063
1064
1065
    s1ap_eNB_new_data_request (Mod_id, UE_index,
                               rrcConnectionSetupComplete->dedicatedInfoNAS.
                               buf,
                               rrcConnectionSetupComplete->dedicatedInfoNAS.
                               size);
1066
1067
1068
  else
#endif

1069
    rrc_eNB_generate_SecurityModeCommand (Mod_id, frame, UE_index);
1070
1071
1072
  //rrc_eNB_generate_UECapabilityEnquiry(Mod_id,frame,UE_index);
}

1073
mui_t rrc_eNB_mui = 0;
1074

1075
1076
1077
void
rrc_eNB_generate_SecurityModeCommand (u8 Mod_id, u32 frame, u16 UE_index)
{
1078
1079
1080
1081

  uint8_t buffer[100];
  uint8_t size;

1082
1083
1084
  size = do_SecurityModeCommand (Mod_id, buffer, UE_index, 0,
                                 eNB_rrc_inst[Mod_id].ciphering_algorithm[UE_index],
                                 eNB_rrc_inst[Mod_id].integrity_algorithm[UE_index]);
1085

1086
1087
1088
  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);
1089
1090


1091
1092
1093
1094
  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);
1095
  //rrc_rlc_data_req(Mod_id,frame, 1,(UE_index*NB_RB_MAX)+DCCH,rrc_eNB_mui++,0,size,(char*)buffer);
1096
1097
  pdcp_rrc_data_req (Mod_id, frame, 1, (UE_index * NB_RB_MAX) + DCCH,
                     rrc_eNB_mui++, 0, size, buffer, 1);
1098
1099
1100
1101

}


1102
1103
1104
void
rrc_eNB_generate_UECapabilityEnquiry (u8 Mod_id, u32 frame, u16 UE_index)
{
1105
1106
1107
1108

  uint8_t buffer[100];
  uint8_t size;

1109
  size = do_UECapabilityEnquiry (Mod_id, buffer, UE_index, 0);
1110

1111
1112
1113
  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);
1114
1115


1116
1117
1118
1119
  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);
1120
  //rrc_rlc_data_req(Mod_id,frame, 1,(UE_index*NB_RB_MAX)+DCCH,rrc_eNB_mui++,0,size,(char*)buffer);
1121
1122
  pdcp_rrc_data_req (Mod_id, frame, 1, (UE_index * NB_RB_MAX) + DCCH,
                     rrc_eNB_mui++, 0, size, buffer, 1);
1123
1124
1125

}

1126
1127
1128
1129
1130
1131
void
rrc_eNB_generate_defaultRRCConnectionReconfiguration (u8 Mod_id, u32 frame,
                                                      u16 UE_index,
                                                      u8 * nas_pdu,
                                                      u32 nas_length)
{
1132
1133
1134
1135
1136
1137
1138
1139
1140


  u8 buffer[100];
  u8 size;
  int i;

  // configure SRB1/SRB2, PhysicalConfigDedicated, MAC_MainConfig for UE
  eNB_RRC_INST *rrc_inst = &eNB_rrc_inst[Mod_id];

1141
1142
1143

  struct PhysicalConfigDedicated **physicalConfigDedicated =
    &rrc_inst->physicalConfigDedicated[UE_index];
1144
1145
1146
1147
1148


  struct SRB_ToAddMod *SRB2_config;
  struct SRB_ToAddMod__rlc_Config *SRB2_rlc_config;
  struct SRB_ToAddMod__logicalChannelConfig *SRB2_lchan_config;
1149
1150
1151
  struct LogicalChannelConfig__ul_SpecificParameters
    *SRB2_ul_SpecificParameters;
  SRB_ToAddModList_t *SRB_configList = rrc_inst->SRB_configList[UE_index];
1152
1153
1154
1155
1156
1157
1158
  SRB_ToAddModList_t *SRB_configList2;

  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;
1159
1160
  struct LogicalChannelConfig__ul_SpecificParameters
    *DRB_ul_SpecificParameters;
1161
1162
1163
1164
1165
1166
  DRB_ToAddModList_t **DRB_configList = &rrc_inst->DRB_configList[UE_index];

  MAC_MainConfig_t *mac_MainConfig;
  MeasObjectToAddModList_t *MeasObj_list;
  MeasObjectToAddMod_t *MeasObj;
  ReportConfigToAddModList_t *ReportConfig_list;
1167
1168
  ReportConfigToAddMod_t *ReportConfig_per, *ReportConfig_A1,
    *ReportConfig_A2, *ReportConfig_A3, *ReportConfig_A4, *ReportConfig_A5;
1169
  MeasIdToAddModList_t *MeasId_list;
1170
  MeasIdToAddMod_t *MeasId0, *MeasId1, *MeasId2, *MeasId3, *MeasId4, *MeasId5;
1171
#if Rel10
1172
  long *sr_ProhibitTimer_r9;
1173
1174
#endif

1175
  long *logicalchannelgroup, *logicalchannelgroup_drb;
1176
1177
  long *maxHARQ_Tx, *periodicBSR_Timer;

1178
1179
  // RSRP_Range_t *rsrp;
  // struct MeasConfig__speedStatePars *Sparams;
1180
1181
  CellsToAddMod_t *CellToAdd;
  CellsToAddModList_t *CellsToAddModList;
1182
1183

  C_RNTI_t *cba_RNTI = NULL;
1184
1185
1186
#ifdef CBA
  //struct PUSCH_CBAConfigDedicated_vlola  *pusch_CBAConfigDedicated_vlola;
  uint8_t *cba_RNTI_buf;
1187
1188
  cba_RNTI = CALLOC (1, sizeof (C_RNTI_t));
  cba_RNTI_buf = CALLOC (1, 2 * sizeof (uint8_t));
1189
1190
  cba_RNTI->buf = cba_RNTI_buf;
  cba_RNTI->size = 2;
1191
  cba_RNTI->bits_unused = 0;
1192
  // associate UEs to the CBa groups as a function of their UE id
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
  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);
    }


#endif
1214
1215
1216
1217
1218

  //
  // Configure SRB2

  /// SRB2
1219
1220
1221
1222
  SRB2_config = CALLOC (1, sizeof (*SRB2_config));
  SRB_configList2 = CALLOC (1, sizeof (*SRB_configList2));
  memset (SRB_configList2, 0, sizeof (*SRB_configList2));

1223
  SRB2_config->srb_Identity = 2;
1224
1225
  SRB2_rlc_config = CALLOC (1, sizeof (*SRB2_rlc_config));
  SRB2_config->rlc_Config = SRB2_rlc_config;
1226
1227

  SRB2_rlc_config->present = SRB_ToAddMod__rlc_Config_PR_explicitValue;
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
  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;

  SRB2_lchan_config = CALLOC (1, sizeof (*SRB2_lchan_config));
  SRB2_config->logicalChannelConfig = SRB2_lchan_config;

  SRB2_lchan_config->present =
    SRB_ToAddMod__logicalChannelConfig_PR_explicitValue;


  SRB2_ul_SpecificParameters =
    CALLOC (1, sizeof (*SRB2_ul_SpecificParameters));

  SRB2_ul_SpecificParameters->priority = 1;
  SRB2_ul_SpecificParameters->prioritisedBitRate =
    LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
  SRB2_ul_SpecificParameters->bucketSizeDuration =
    LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
1257
1258

  // LCG for CCCH and DCCH is 0 as defined in 36331
1259
1260
  logicalchannelgroup = CALLOC (1, sizeof (long));
  *logicalchannelgroup = 0;
1261
1262
1263

  SRB2_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup;

1264
1265
1266
1267
  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);
1268
1269
1270

  // Configure DRB

1271
  *DRB_configList = CALLOC (1, sizeof (*DRB_configList));
1272
1273

  /// DRB
1274
  DRB_config = CALLOC (1, sizeof (*DRB_config));
1275
1276
1277

  //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
1278
1279
  DRB_config->drb_Identity = (DRB_Identity_t) 1;        // (UE_index+1); //allowed values 1..32
  DRB_config->logicalChannelIdentity = CALLOC (1, sizeof (long));
1280
  *(DRB_config->logicalChannelIdentity) = (long) 3;
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
  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;

  DRB_pdcp_config = CALLOC (1, sizeof (*DRB_pdcp_config));
  DRB_config->pdcp_Config = DRB_pdcp_config;
  DRB_pdcp_config->discardTimer = NULL;
1294
  DRB_pdcp_config->rlc_AM = NULL;
1295
1296
  PDCP_rlc_UM = CALLOC (1, sizeof (*PDCP_rlc_UM));
  DRB_pdcp_config->rlc_UM = PDCP_rlc_UM;
1297
  PDCP_rlc_UM->pdcp_SN_Size = PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits;
1298
1299
  DRB_pdcp_config->headerCompression.present =
    PDCP_Config__headerCompression_PR_notUsed;
1300

1301
1302
1303
  DRB_lchan_config = CALLOC (1, sizeof (*DRB_lchan_config));
  DRB_config->logicalChannelConfig = DRB_lchan_config;
  DRB_ul_SpecificParameters = CALLOC (1, sizeof (*DRB_ul_SpecificParameters));
1304
1305
1306
  DRB_lchan_config->ul_SpecificParameters = DRB_ul_SpecificParameters;


1307
1308
1309
1310
1311
1312
  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;

1313
  // LCG for DTCH can take the value from 1 to 3 as defined in 36331: normally controlled by upper layers (like RRM)
1314
1315
  logicalchannelgroup_drb = CALLOC (1, sizeof (long));
  *logicalchannelgroup_drb = 1;
1316
1317
1318
  DRB_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup_drb;


1319
  ASN_SEQUENCE_ADD (&(*DRB_configList)->list, DRB_config);
1320

1321
  mac_MainConfig = CALLOC (1, sizeof (*mac_MainConfig));
1322
1323
  eNB_rrc_inst[Mod_id].mac_MainConfig[UE_index] = mac_MainConfig;

1324
1325
  mac_MainConfig->ul_SCH_Config =
    CALLOC (1, sizeof (*mac_MainConfig->ul_SCH_Config));
1326

1327
1328
  maxHARQ_Tx = CALLOC (1, sizeof (long));
  *maxHARQ_Tx = MAC_MainConfig__ul_SCH_Config__maxHARQ_Tx_n5;
1329
1330
  mac_MainConfig->ul_SCH_Config->maxHARQ_Tx = maxHARQ_Tx;

1331
  periodicBSR_Timer = CALLOC (1, sizeof (long));
1332
  *periodicBSR_Timer = MAC_MainConfig__ul_SCH_Config__periodicBSR_Timer_sf64;
1333
  mac_MainConfig->ul_SCH_Config->periodicBSR_Timer = periodicBSR_Timer;
1334

1335
1336
  mac_MainConfig->ul_SCH_Config->retxBSR_Timer =
    MAC_MainConfig__ul_SCH_Config__retxBSR_Timer_sf320;
1337

1338
  mac_MainConfig->ul_SCH_Config->ttiBundling = 0;       // FALSE
1339
1340
1341

  mac_MainConfig->drx_Config = NULL;

1342
1343
  mac_MainConfig->phr_Config =
    CALLOC (1, sizeof (*mac_MainConfig->phr_Config));
1344
1345

  mac_MainConfig->phr_Config->present = MAC_MainConfig__phr_Config_PR_setup;
1346
  mac_MainConfig->phr_Config->choice.setup.periodicPHR_Timer = MAC_MainConfig__phr_Config__setup__periodicPHR_Timer_sf20;       // sf20 = 20 subframes
1347

1348
  mac_MainConfig->phr_Config->choice.setup.prohibitPHR_Timer = MAC_MainConfig__phr_Config__setup__prohibitPHR_Timer_sf20;       // sf20 = 20 subframes
1349

1350
  mac_MainConfig->phr_Config->choice.setup.dl_PathlossChange = MAC_MainConfig__phr_Config__setup__dl_PathlossChange_dB1;        // Value dB1 =1 dB, dB3 = 3 dB
1351
1352

#ifdef Rel10
1353
1354
1355
  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;
1356
1357
1358
1359
1360
  //sps_RA_ConfigList_rlola = NULL;
#endif


  // Measurement ID list
1361
1362
  MeasId_list = CALLOC (1, sizeof (*MeasId_list));
  memset ((void *) MeasId_list, 0, sizeof (*MeasId_list));
1363

1364
  MeasId0 = CALLOC (1, sizeof (*MeasId0));
1365
1366
1367
  MeasId0->measId = 1;
  MeasId0->measObjectId = 1;
  MeasId0->reportConfigId = 1;
1368
  ASN_SEQUENCE_ADD (&MeasId_list->list, MeasId0);
1369

1370
  MeasId1 = CALLOC (1, sizeof (*MeasId1));
1371
1372
1373
  MeasId1->measId = 2;
  MeasId1->measObjectId = 1;
  MeasId1->reportConfigId = 2;
1374
  ASN_SEQUENCE_ADD (&MeasId_list->list, MeasId1);
1375

1376
  MeasId2 = CALLOC (1, sizeof (*MeasId2));
1377
1378
1379
  MeasId2->measId = 3;
  MeasId2->measObjectId = 1;
  MeasId2->reportConfigId = 3;
1380
  ASN_SEQUENCE_ADD (&MeasId_list->list, MeasId2);
1381

1382
  MeasId3 = CALLOC (1, sizeof (*MeasId3));
1383
1384
1385
  MeasId3->measId = 4;
  MeasId3->measObjectId = 1;
  MeasId3->reportConfigId = 4;
1386
  ASN_SEQUENCE_ADD (&MeasId_list->list, MeasId3);
1387

1388
  MeasId4 = CALLOC (1, sizeof (*MeasId4));
1389
1390
1391
  MeasId4->measId = 5;
  MeasId4->measObjectId = 1;
  MeasId4->reportConfigId = 5;
1392
  ASN_SEQUENCE_ADD (&MeasId_list->list, MeasId4);
1393

1394
  MeasId5 = CALLOC (1, sizeof (*MeasId5));
1395
1396
1397
  MeasId5->measId = 6;
  MeasId5->measObjectId = 1;
  MeasId5->reportConfigId = 6;
1398
  ASN_SEQUENCE_ADD (&MeasId_list->list, MeasId5);
1399
1400
1401
1402

  //  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->measIdToAddModList = MeasId_list;

  // Add one EUTRA Measurement Object
1403
1404
  MeasObj_list = CALLOC (1, sizeof (*MeasObj_list));
  memset ((void *) MeasObj_list, 0, sizeof (*MeasObj_list));
1405
1406
1407

  // Configure MeasObject

1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
  MeasObj = CALLOC (1, sizeof (*MeasObj));
  memset ((void *) MeasObj, 0, sizeof (*MeasObj));

  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;
1422
  MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.bits_unused = 6;
1423
  MeasObj->measObject.choice.measObjectEUTRA.offsetFreq = NULL; // Default is 15 or 0dB
1424

1425
1426
  MeasObj->measObject.choice.measObjectEUTRA.cellsToAddModList =
    (CellsToAddModList_t *) CALLOC (1, sizeof (*CellsToAddModList));