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

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


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

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

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

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

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

/*! \file rrc_eNB.c
 * \brief rrc procedures for eNB
nikaeinn's avatar
nikaeinn committed
32
33
 * \author Navid Nikaein and  Raymond Knopp 
 * \date 2011 - 2014
34
35
 * \version 1.0
 * \company Eurecom
nikaeinn's avatar
nikaeinn committed
36
 * \email: navid.nikaein@eurecom.fr and raymond.knopp@eurecom.fr
37
 */
gauthier's avatar
gauthier committed
38
39
#define RRC_ENB
#define RRC_ENB_C
40
41
42

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

//#ifdef Rel10
64
#include "MeasResults.h"
65
66
67
//#endif

#ifdef USER_MODE
gauthier's avatar
   
gauthier committed
68
69
70
71
#   include "RRC/NAS/nas_config.h"
#   include "RRC/NAS/rb_config.h"
#   include "OCG.h"
#   include "OCG_extern.h"
72
73
#endif

74
#if defined(ENABLE_SECURITY)
gauthier's avatar
   
gauthier committed
75
#   include "UTIL/OSA/osa_defs.h"
76
77
#endif

78
#if defined(ENABLE_USE_MME)
gauthier's avatar
   
gauthier committed
79
#   include "rrc_eNB_S1AP.h"
80
#   include "rrc_eNB_GTPV1U.h"
gauthier's avatar
   
gauthier committed
81
82
83
84
#   if defined(ENABLE_ITTI)
#   else
#      include "../../S1AP/s1ap_eNB.h"
#   endif
85
86
#endif

87
88
89
#include "pdcp.h"

#if defined(ENABLE_ITTI)
gauthier's avatar
   
gauthier committed
90
#   include "intertask_interface.h"
91
92
#endif

gauthier's avatar
gauthier committed
93
#ifdef ENABLE_RAL
gauthier's avatar
   
gauthier committed
94
#   include "rrc_eNB_ral.h"
gauthier's avatar
gauthier committed
95
96
#endif

97
98
99
//#define XER_PRINT

#ifdef PHY_EMUL
gauthier's avatar
   
gauthier committed
100
extern EMULATION_VARS              *Emul_vars;
101
#endif
gauthier's avatar
   
gauthier committed
102
103
extern eNB_MAC_INST                *eNB_mac_inst;
extern UE_MAC_INST                 *UE_mac_inst;
104
#ifdef BIGPHYSAREA
gauthier's avatar
   
gauthier committed
105
106
extern void                        *bigphys_malloc(
    int);
107
108
#endif

gauthier's avatar
   
gauthier committed
109
110
111
extern uint16_t                     two_tier_hexagonal_cellIds[7];
extern inline unsigned int          taus(
    void);
winckel's avatar
RRC:    
winckel committed
112

113
/* TS 36.331: RRC-TransactionIdentifier ::= INTEGER (0..3) */
gauthier's avatar
   
gauthier committed
114
static const uint8_t                RRC_TRANSACTION_IDENTIFIER_NUMBER = 4;
115

gauthier's avatar
   
gauthier committed
116
mui_t                               rrc_eNB_mui = 0;
winckel's avatar
RRC:    
winckel committed
117

winckel's avatar
winckel committed
118
/*------------------------------------------------------------------------------*/
gauthier's avatar
   
gauthier committed
119
120
static void init_SI(
    module_id_t enb_mod_idP
winckel's avatar
winckel committed
121
#if defined(ENABLE_ITTI)
gauthier's avatar
   
gauthier committed
122
123
    ,
    RrcConfigurationReq * configuration
winckel's avatar
winckel committed
124
#endif
gauthier's avatar
   
gauthier committed
125
126
127
    ) {
    uint8_t                             SIwindowsize = 1;
    uint16_t                            SIperiod = 8;
128
#ifdef Rel10
gauthier's avatar
   
gauthier committed
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
    int                                 i;
#endif
    /*
       uint32_t mib=0;
       int i;
       int N_RB_DL,phich_resource;

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

       for (i=0;i<1024;i+=4)
       do_MIB(enb_mod_idP, 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(enb_mod_idP, 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);
     */

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

    eNB_rrc_inst[enb_mod_idP].SIB1 = (uint8_t *) malloc16(32);

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

    if (eNB_rrc_inst[enb_mod_idP].SIB1)
        eNB_rrc_inst[enb_mod_idP].sizeof_SIB1 = do_SIB1(enb_mod_idP, mac_xface->lte_frame_parms, (uint8_t *)
                                                   eNB_rrc_inst[enb_mod_idP].SIB1,
                                                   &eNB_rrc_inst[enb_mod_idP].siblock1, &eNB_rrc_inst[enb_mod_idP].sib1
winckel's avatar
winckel committed
192
#if defined(ENABLE_ITTI)
gauthier's avatar
   
gauthier committed
193
                                                   , configuration
winckel's avatar
winckel committed
194
#endif
gauthier's avatar
   
gauthier committed
195
196
197
198
            );
    else {
        LOG_E(RRC, "[eNB %d] init_SI: FATAL, no memory for SIB1 allocated\n", enb_mod_idP);
        mac_xface->macphy_exit("[RRC][init_SI] FATAL, no memory for SIB1 allocated");
199
    }
gauthier's avatar
   
gauthier committed
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
    /*
       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);
     */
    if (eNB_rrc_inst[enb_mod_idP].sizeof_SIB1 == 255)
        mac_xface->macphy_exit("[RRC][init_SI] FATAL, eNB_rrc_inst[enb_mod_idP].sizeof_SIB1 == 255");

    eNB_rrc_inst[enb_mod_idP].SIB23 = (uint8_t *) malloc16(64);
    if (eNB_rrc_inst[enb_mod_idP].SIB23) {
        eNB_rrc_inst[enb_mod_idP].sizeof_SIB23 = do_SIB23(enb_mod_idP,
                                                     mac_xface->lte_frame_parms,
                                                     eNB_rrc_inst[enb_mod_idP].SIB23,
                                                     &eNB_rrc_inst[enb_mod_idP].systemInformation,
                                                     &eNB_rrc_inst[enb_mod_idP].sib2, &eNB_rrc_inst[enb_mod_idP].sib3
216
#ifdef Rel10
gauthier's avatar
   
gauthier committed
217
                                                     , &eNB_rrc_inst[enb_mod_idP].sib13, eNB_rrc_inst[enb_mod_idP].MBMS_flag
218
219
#endif
#if defined(ENABLE_ITTI)
gauthier's avatar
   
gauthier committed
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
255
256
257
258
259
                                                     , configuration
#endif
            );
        /*
           eNB_rrc_inst[enb_mod_idP].sizeof_SIB23 = do_SIB2_AT4(enb_mod_idP,
           eNB_rrc_inst[enb_mod_idP].SIB23,
           &eNB_rrc_inst[enb_mod_idP].systemInformation,
           &eNB_rrc_inst[enb_mod_idP].sib2,
           #if defined(ENABLE_ITTI)
           , configuration
           #endif
           );
         */
        if (eNB_rrc_inst[enb_mod_idP].sizeof_SIB23 == 255)
            mac_xface->macphy_exit("[RRC][init_SI] FATAL, eNB_rrc_inst[enb_mod_idP].sizeof_SIB23 == 255");

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

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

gauthier's avatar
   
gauthier committed
290
291
292
293
294
295
296
297
        LOG_D(RRC,
              "[FRAME unknown][RRC_UE][MOD %02d][][--- MAC_CONFIG_REQ (SIB1.tdd & SIB2 params) --->][MAC_UE][MOD %02d][]\n",
              enb_mod_idP, enb_mod_idP);

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

#ifdef Rel10
winckel's avatar
winckel committed
331
/*------------------------------------------------------------------------------*/
gauthier's avatar
   
gauthier committed
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
static void init_MCCH(
    module_id_t enb_mod_idP) {

    int                                 sync_area = 0;
    // initialize RRC_eNB_INST MCCH entry
    eNB_rrc_inst[enb_mod_idP].MCCH_MESSAGE = malloc(eNB_rrc_inst[enb_mod_idP].num_mbsfn_sync_area * sizeof(uint32_t *));
    for (sync_area = 0; sync_area < eNB_rrc_inst[enb_mod_idP].num_mbsfn_sync_area; sync_area++) {

        eNB_rrc_inst[enb_mod_idP].sizeof_MCCH_MESSAGE[sync_area] = 0;
        eNB_rrc_inst[enb_mod_idP].MCCH_MESSAGE[sync_area] = (uint8_t *) malloc16(32);

        if (eNB_rrc_inst[enb_mod_idP].MCCH_MESSAGE[sync_area] == NULL) {
            LOG_E(RRC, "[eNB %d][MAIN] init_MCCH: FATAL, no memory for MCCH MESSAGE allocated \n", enb_mod_idP);
            mac_xface->macphy_exit("[RRC][init_MCCH] not enough memory\n");
        } else {
            eNB_rrc_inst[enb_mod_idP].sizeof_MCCH_MESSAGE[sync_area] = do_MBSFNAreaConfig(enb_mod_idP,
                                                                                     mac_xface->lte_frame_parms,
                                                                                     sync_area, (uint8_t *)
                                                                                     eNB_rrc_inst[enb_mod_idP].MCCH_MESSAGE
                                                                                     [sync_area],
                                                                                     &eNB_rrc_inst[enb_mod_idP].mcch,
                                                                                     &eNB_rrc_inst
                                                                                     [enb_mod_idP].mcch_message);

            LOG_I(RRC, "mcch message pointer %p for sync area %d \n", eNB_rrc_inst[enb_mod_idP].MCCH_MESSAGE[sync_area],
                  sync_area);
            LOG_D(RRC, "[eNB %d] MCCH_MESSAGE  contents for Sync Area %d (partial)\n", enb_mod_idP, sync_area);
            LOG_D(RRC, "[eNB %d] CommonSF_AllocPeriod_r9 %d\n", enb_mod_idP,
                  eNB_rrc_inst[enb_mod_idP].mcch_message->commonSF_AllocPeriod_r9);
            LOG_D(RRC,
                  "[eNB %d] CommonSF_Alloc_r9.list.count (number of MBSFN Subframe Pattern) %d\n",
                  enb_mod_idP, eNB_rrc_inst[enb_mod_idP].mcch_message->commonSF_Alloc_r9.list.count);
            LOG_D(RRC, "[eNB %d] MBSFN Subframe Pattern: %02x (in hex)\n",
                  enb_mod_idP,
                  eNB_rrc_inst[enb_mod_idP].mcch_message->commonSF_Alloc_r9.list.array[0]->subframeAllocation.
                  choice.oneFrame.buf[0]);

            if (eNB_rrc_inst[enb_mod_idP].sizeof_MCCH_MESSAGE[sync_area] == 255)
                mac_xface->macphy_exit("[RRC][init_MCCH] eNB_rrc_inst[enb_mod_idP].sizeof_MCCH_MESSAGE[sync_area] == 255");
            else
                eNB_rrc_inst[enb_mod_idP].MCCH_MESS[sync_area].Active = 1;
        }
374
    }
gauthier's avatar
   
gauthier committed
375
376
377
378
379
380
381
382
383
384
    //Set the eNB_rrc_inst[enb_mod_idP].MCCH_MESS.Active to 1 (allow to  transfer MCCH message RRC->MAC in function mac_rrc_data_req)

    // ??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[enb_mod_idP].mcch_message->pmch_InfoList_r9.list.array[0]->mbms_SessionInfoList_r9.list.array[0]->tmgi_r9.serviceId_r9.buf[2]);
    //  LOG_I(RRC, "DUY: session ID is %d\n",eNB_rrc_inst[enb_mod_idP].mcch_message->pmch_InfoList_r9.list.array[0]->mbms_SessionInfoList_r9.list.array[0]->sessionId_r9->buf[0]);
    rrc_mac_config_req(enb_mod_idP, ENB_FLAG_YES, 0, 0,
                       (RadioResourceConfigCommonSIB_t *) NULL,
                       (struct PhysicalConfigDedicated *)NULL,
385
#ifdef Rel10
hrizi's avatar
   
hrizi committed
386
387
	(SCellToAddMod_r10_t *)NULL,
	//(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
388
#endif
gauthier's avatar
   
gauthier committed
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
                       (MeasObjectToAddMod_t **) NULL,
                       (MAC_MainConfig_t *) NULL,
                       0,
                       (struct LogicalChannelConfig *)NULL,
                       (MeasGapConfig_t *) NULL,
                       (TDD_Config_t *) NULL,
                       NULL, (uint8_t *) NULL, (uint16_t *) NULL, NULL, NULL, NULL, (MBSFN_SubframeConfigList_t *) NULL
#   ifdef Rel10
                       ,
                       0,
                       (MBSFN_AreaInfoList_r9_t *) NULL,
                       (PMCH_InfoList_r9_t *) & (eNB_rrc_inst[enb_mod_idP].mcch_message->pmch_InfoList_r9)
#   endif
#   ifdef CBA
                       , 0, 0
#   endif
        );
406

gauthier's avatar
   
gauthier committed
407
    //LOG_I(RRC,"DUY: lcid after rrc_mac_config_req is %02d\n",eNB_rrc_inst[enb_mod_idP].mcch_message->pmch_InfoList_r9.list.array[0]->mbms_SessionInfoList_r9.list.array[0]->logicalChannelIdentity_r9);
408

409
410
}

winckel's avatar
winckel committed
411
/*------------------------------------------------------------------------------*/
gauthier's avatar
   
gauthier committed
412
413
414
static void init_MBMS(
    module_id_t enb_mod_idP,
    frame_t frameP) {
415
    // init the configuration for MTCH
gauthier's avatar
gauthier committed
416
    protocol_ctxt_t               ctxt;
gauthier's avatar
   
gauthier committed
417
418

    if (eNB_rrc_inst[enb_mod_idP].MBMS_flag > 0) {
gauthier's avatar
gauthier committed
419
420
421
422
        ctxt.enb_module_id = enb_mod_idP;
        ctxt.ue_module_id  = 0;
        ctxt.frame         = frameP;
        ctxt.enb_flag      = ENB_FLAG_YES;
gauthier's avatar
   
gauthier committed
423
424
425
426

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

gauthier's avatar
gauthier committed
427
428
429
430
431
        rrc_pdcp_config_asn1_req(&ctxt,
                                 (SRB_ToAddModList_t  *)NULL,  // SRB_ToAddModList
                                 (DRB_ToAddModList_t  *)NULL,  // DRB_ToAddModList
                                 (DRB_ToReleaseList_t *)NULL,
                                 0,     // security mode
gauthier's avatar
   
gauthier committed
432
433
434
435
436
437
438
439
                                 NULL,  // key rrc encryption
                                 NULL,  // key rrc integrity
                                 NULL   // key encryption
#   ifdef Rel10
                                 , &(eNB_rrc_inst[enb_mod_idP].mcch_message->pmch_InfoList_r9)
#   endif
            );

gauthier's avatar
gauthier committed
440
441
        rrc_rlc_config_asn1_req(&ctxt,
                                NULL, // SRB_ToAddModList
442
                                NULL,   // DRB_ToAddModList
gauthier's avatar
   
gauthier committed
443
444
445
446
447
                                NULL,   // DRB_ToReleaseList
                                &(eNB_rrc_inst[enb_mod_idP].mcch_message->pmch_InfoList_r9));

        //rrc_mac_config_req();
    }
448
449
450
}
#endif

winckel's avatar
winckel committed
451
/*------------------------------------------------------------------------------*/
gauthier's avatar
   
gauthier committed
452
453
454
static void rrc_lite_eNB_init_security(
    module_id_t enb_mod_idP,
    module_id_t ue_mod_idP) {
winckel's avatar
winckel committed
455
#if defined(ENABLE_SECURITY)
gauthier's avatar
   
gauthier committed
456
457
    char                                ascii_buffer[65];
    uint8_t                             i;
winckel's avatar
winckel committed
458

gauthier's avatar
   
gauthier committed
459
    memset(eNB_rrc_inst[enb_mod_idP].kenb[ue_mod_idP], ue_mod_idP, 32);
winckel's avatar
winckel committed
460
461

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

gauthier's avatar
   
gauthier committed
466
    LOG_T(RRC, "[OSA][eNB %d][UE %d] kenb    = %s\n", enb_mod_idP, ue_mod_idP, ascii_buffer);
winckel's avatar
winckel committed
467
468
469
#endif
}

470
/*------------------------------------------------------------------------------*/
gauthier's avatar
   
gauthier committed
471
472
473
uint8_t rrc_eNB_get_next_transaction_identifier(
    module_id_t enb_mod_idP) {
    static uint8_t                      rrc_transaction_identifier[NUMBER_OF_eNB_MAX];
winckel's avatar
RRC:    
winckel committed
474

gauthier's avatar
   
gauthier committed
475
    rrc_transaction_identifier[enb_mod_idP] = (rrc_transaction_identifier[enb_mod_idP] + 1) % RRC_TRANSACTION_IDENTIFIER_NUMBER;
winckel's avatar
RRC:    
winckel committed
476

gauthier's avatar
   
gauthier committed
477
    return rrc_transaction_identifier[enb_mod_idP];
winckel's avatar
RRC:    
winckel committed
478
479
}

480
481
/*------------------------------------------------------------------------------*/
/* Functions to handle UE index in eNB UE list */
winckel's avatar
winckel committed
482

483

gauthier's avatar
gauthier committed
484
485
static module_id_t
rrc_eNB_get_UE_index(
486
    module_id_t enb_mod_idP,
gauthier's avatar
gauthier committed
487
488
489
    uint64_t    UE_identity
    )
{
490
491
492
493
494
495
496
497

    boolean_t      reg = FALSE;
    module_id_t    i;

    AssertFatal(enb_mod_idP < NB_eNB_INST, "eNB index invalid (%d/%d)!", enb_mod_idP, NB_eNB_INST);

    for (i = 0; i < NUMBER_OF_UE_MAX; i++) {
      if (eNB_rrc_inst[enb_mod_idP].Info.UE_list[i] == UE_identity) {
hrizi's avatar
   
hrizi committed
498
499
500
	// UE_identity already registered
	reg = TRUE;
	break;
501
502
503
504
505
506
507
508
509
      }
    }
    
    if (reg == FALSE) {
      return (UE_MODULE_INVALID);
    } else
      return (i);
}

gauthier's avatar
gauthier committed
510
511
static module_id_t
rrc_eNB_get_next_free_UE_index(
gauthier's avatar
   
gauthier committed
512
    module_id_t enb_mod_idP,
gauthier's avatar
gauthier committed
513
514
515
    uint64_t UE_identity
    )
{
516

gauthier's avatar
   
gauthier committed
517
518
    boolean_t      reg = FALSE;
    module_id_t    i, first_index = UE_MODULE_INVALID;
519

520
521
522
    LOG_D(RRC,"ENB_ID= %d \n",enb_mod_idP);
    LOG_D(RRC,"N_ID= %d \n",NB_eNB_INST);

gauthier's avatar
   
gauthier committed
523
524
525
526
    AssertFatal(enb_mod_idP < NB_eNB_INST, "eNB index invalid (%d/%d)!", enb_mod_idP, NB_eNB_INST);

    for (i = 0; i < NUMBER_OF_UE_MAX; i++) {
        if ((first_index == UE_MODULE_INVALID) && (eNB_rrc_inst[enb_mod_idP].Info.UE_list[i] == 0)) {
hrizi's avatar
   
hrizi committed
527
	  first_index = i;    // save first free position
gauthier's avatar
   
gauthier committed
528
        }
529

gauthier's avatar
   
gauthier committed
530
531
        if (eNB_rrc_inst[enb_mod_idP].Info.UE_list[i] == UE_identity) {
            // UE_identity already registered
hrizi's avatar
   
hrizi committed
532
	  reg = TRUE;
gauthier's avatar
   
gauthier committed
533
        }
534
535
    }

gauthier's avatar
   
gauthier committed
536
    if (reg == 0) {
537
538
539
540
      LOG_I(RRC, "[eNB %d] Adding UE %d with identity " PRIu64 "\n", enb_mod_idP, first_index, UE_identity);
      return (first_index);
    } else
      return (UE_MODULE_INVALID);
541
542
}

543
544
545
546
void
rrc_eNB_free_UE_index(
                module_id_t enb_mod_idP,
                module_id_t ue_mod_idP,
gauthier's avatar
gauthier committed
547
548
549
                int frameP
                )
{
knopp's avatar
   
knopp committed
550

551
  protocol_ctxt_t                     ctxt;
knopp's avatar
   
knopp committed
552
553
554
555
556
557
558
559
560
  DRB_ToAddModList_t                 *DRB_configList = eNB_rrc_inst[enb_mod_idP].DRB_configList[ue_mod_idP];
  SRB_ToAddModList_t                 *SRB_configList = eNB_rrc_inst[enb_mod_idP].SRB_configList[ue_mod_idP];

  AssertFatal(enb_mod_idP < NB_eNB_INST, "eNB inst invalid (%d/%d) for UE %d!", enb_mod_idP, NB_eNB_INST, ue_mod_idP);
  AssertFatal(ue_mod_idP < NUMBER_OF_UE_MAX, "UE inst invalid (%d/%d) for eNB %d!", ue_mod_idP, NUMBER_OF_UE_MAX,
	      enb_mod_idP);
  
  LOG_W(RRC, "[eNB %d] Removing UE %d rv 0x%" PRIx64 "\n", enb_mod_idP, ue_mod_idP,
	eNB_rrc_inst[enb_mod_idP].Info.UE_list[ue_mod_idP]);
gauthier's avatar
gauthier committed
561
562
563
564
565
566
567
568
569
570

#if defined(ENABLE_USE_MME)
  rrc_eNB_send_S1AP_UE_CONTEXT_RELEASE_REQ(enb_mod_idP, ue_mod_idP, S1AP_CAUSE_RADIO_NETWORK, 0); // ue_mod_idP ??? or ???
  /* From 3GPP 36300v10 p129 : 19.2.2.2.2 S1 UE Context Release Request (eNB triggered)
   * If the E-UTRAN internal reason is a radio link failure detected in the eNB, the eNB shall wait a sufficient time before
   *  triggering the S1 UE Context Release Request procedure
   *  in order to allow the UE to perform the NAS recovery
   *  procedure, see TS 23.401 [17].
   */
#endif
knopp's avatar
   
knopp committed
571
572
  eNB_rrc_inst[enb_mod_idP].Info.UE[ue_mod_idP].Status = RRC_IDLE;
  eNB_rrc_inst[enb_mod_idP].Info.UE_list[ue_mod_idP] = 0;
573
574
575
576
577
578
579
580

  ctxt.enb_module_id = enb_mod_idP;
  ctxt.ue_module_id  = ue_mod_idP;
  ctxt.frame         = frameP;
  ctxt.enb_flag      = ENB_FLAG_YES;

  rrc_rlc_remove_ue(&ctxt);
  pdcp_remove_UE(&ctxt);
knopp's avatar
   
knopp committed
581

knopp's avatar
   
knopp committed
582
  free(eNB_rrc_inst[enb_mod_idP].SRB_configList[ue_mod_idP]);
583
584
}

winckel's avatar
winckel committed
585
/*------------------------------------------------------------------------------*/
gauthier's avatar
   
gauthier committed
586
587
588
589
void rrc_eNB_process_RRCConnectionSetupComplete(
    module_id_t enb_mod_idP,
    frame_t     frameP,
    module_id_t ue_mod_idP,
gauthier's avatar
gauthier committed
590
591
592
    RRCConnectionSetupComplete_r8_IEs_t * rrcConnectionSetupComplete
    )
{
gauthier's avatar
   
gauthier committed
593
594
595
    LOG_I(RRC,
          "[eNB %d][RAPROC] Frame %d : Logical Channel UL-DCCH, " "processing RRCConnectionSetupComplete from UE %d\n",
          enb_mod_idP, frameP, ue_mod_idP);
winckel's avatar
winckel committed
596
597

#if defined(ENABLE_USE_MME)
gauthier's avatar
   
gauthier committed
598
599
600
601
    if (EPC_MODE_ENABLED == 1) {
        // Forward message to S1AP layer
        rrc_eNB_send_S1AP_NAS_FIRST_REQ(enb_mod_idP, ue_mod_idP, rrcConnectionSetupComplete);
    } else
winckel's avatar
winckel committed
602
#endif
gauthier's avatar
   
gauthier committed
603
604
605
606
607
    {
        // RRC loop back (no S1AP), send SecurityModeCommand to UE
        rrc_eNB_generate_SecurityModeCommand(enb_mod_idP, frameP, ue_mod_idP);
        // rrc_eNB_generate_UECapabilityEnquiry(enb_mod_idP,frameP,ue_mod_idP);
    }
winckel's avatar
winckel committed
608
609
}

610
/*------------------------------------------------------------------------------*/
gauthier's avatar
   
gauthier committed
611
612
613
void rrc_eNB_generate_SecurityModeCommand(
    module_id_t enb_mod_idP,
    frame_t     frameP,
gauthier's avatar
gauthier committed
614
615
616
    module_id_t ue_mod_idP
    )
{
gauthier's avatar
   
gauthier committed
617
618
619
620
    uint8_t                             buffer[100];
    uint8_t                             size;

    size = do_SecurityModeCommand(enb_mod_idP, buffer, ue_mod_idP, rrc_eNB_get_next_transaction_identifier(enb_mod_idP),
hrizi's avatar
   
hrizi committed
621
				  eNB_rrc_inst[enb_mod_idP].ciphering_algorithm[ue_mod_idP],
gauthier's avatar
   
gauthier committed
622
623
                                  eNB_rrc_inst[enb_mod_idP].integrity_algorithm[ue_mod_idP]);

624
#ifdef RRC_MSG_PRINT
625
626
    uint16_t i=0;
    LOG_F(RRC,"[MSG] RRC Security Mode Command\n");
627
628
629
630
631
    for (i = 0; i < size; i++)
      LOG_F(RRC,"%02x ", ((uint8_t*)buffer)[i]);
    LOG_F(RRC,"\n");
#endif

gauthier's avatar
   
gauthier committed
632
633
634
635
636
637
638
639
640
    LOG_I(RRC,
          "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate SecurityModeCommand (bytes %d, UE id %d)\n",
          enb_mod_idP, frameP, size, ue_mod_idP);

    LOG_D(RRC,
          "[FRAME %05d][RRC_eNB][MOD %02d][][--- PDCP_DATA_REQ/%d Bytes (securityModeCommand to UE %d MUI %d) --->][PDCP][MOD %02d][RB %02d]\n",
          frameP, enb_mod_idP, size, ue_mod_idP, rrc_eNB_mui, enb_mod_idP, DCCH);
    //rrc_rlc_data_req(enb_mod_idP,frameP, 1,(ue_mod_idP*NB_RB_MAX)+DCCH,rrc_eNB_mui++,0,size,(char*)buffer);
    pdcp_rrc_data_req(enb_mod_idP, ue_mod_idP, frameP, 1, DCCH, rrc_eNB_mui++, 0, size, buffer, 1);
641
642
643

}

644
/*------------------------------------------------------------------------------*/
gauthier's avatar
   
gauthier committed
645
646
647
648
void rrc_eNB_generate_UECapabilityEnquiry(
    module_id_t enb_mod_idP,
    frame_t     frameP,
    module_id_t ue_mod_idP) {
649

gauthier's avatar
   
gauthier committed
650
651
    uint8_t                             buffer[100];
    uint8_t                             size;
652

gauthier's avatar
   
gauthier committed
653
    size = do_UECapabilityEnquiry(enb_mod_idP, buffer, ue_mod_idP, rrc_eNB_get_next_transaction_identifier(enb_mod_idP));
winckel's avatar
winckel committed
654

gauthier's avatar
   
gauthier committed
655
656
657
    LOG_I(RRC,
          "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate UECapabilityEnquiry (bytes %d, UE id %d)\n",
          enb_mod_idP, frameP, size, ue_mod_idP);
winckel's avatar
winckel committed
658

gauthier's avatar
   
gauthier committed
659
660
661
662
663
    LOG_D(RRC,
          "[FRAME %05d][RRC_eNB][MOD %02d][][--- PDCP_DATA_REQ/%d Bytes (UECapabilityEnquiry to UE %d MUI %d) --->][PDCP][MOD %02d][RB %02d]\n",
          frameP, enb_mod_idP, size, ue_mod_idP, rrc_eNB_mui, enb_mod_idP, DCCH);
    //rrc_rlc_data_req(enb_mod_idP,frameP, 1,(ue_mod_idP*NB_RB_MAX)+DCCH,rrc_eNB_mui++,0,size,(char*)buffer);
    pdcp_rrc_data_req(enb_mod_idP, ue_mod_idP, frameP, 1, DCCH, rrc_eNB_mui++, 0, size, buffer, 1);
664
665
666

}

knopp's avatar
   
knopp committed
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
void rrc_eNB_generate_RRCConnectionRelease(module_id_t enb_mod_idP,
					   frame_t frameP,
					   ue_id_t ue_idP) {

    uint8_t                             buffer[RRC_BUF_SIZE];
    uint16_t                            size;

    memset(buffer, 0, RRC_BUF_SIZE);

    size = do_RRCConnectionRelease(enb_mod_idP, buffer,rrc_eNB_get_next_transaction_identifier(enb_mod_idP));

    LOG_I(RRC,
          "[eNB %d] Frame %d Logical Channel DL-DCCH, Generate RRCConnectionRelease (bytes %d, UE id %d)\n",
          enb_mod_idP, frameP, size, ue_idP);

    LOG_D(RRC,
          "[FRAME %05d][RRC_eNB][MOD %u/%u][][--- PDCP_DATA_REQ/%d Bytes (rrcConnectionRelease to UE %d MUI %d) --->][PDCP][MOD %u/%u][RB %u]\n",
          frameP, enb_mod_idP, ue_idP, size, ue_idP, rrc_eNB_mui, enb_mod_idP, ue_idP, DCCH);
    //rrc_rlc_data_req(enb_mod_idP,frameP, 1,(ue_idP*NB_RB_MAX)+DCCH,rrc_eNB_mui++,0,size,(char*)buffer);
    pdcp_rrc_data_req(enb_mod_idP, ue_idP, frameP, 1, DCCH, rrc_eNB_mui++, 0, size, buffer, 1);
}
						  
689
/*------------------------------------------------------------------------------*/
gauthier's avatar
   
gauthier committed
690
static void rrc_eNB_generate_defaultRRCConnectionReconfiguration(
knopp's avatar
   
knopp committed
691
692
693
694
								 module_id_t enb_mod_idP,
								 frame_t     frameP,
								 module_id_t ue_mod_idP,
								 uint8_t ho_state) {
winckel's avatar
winckel committed
695
#if defined(ENABLE_ITTI)
knopp's avatar
   
knopp committed
696
  eNB_RRC_UE_INFO                    *UE_info = &eNB_rrc_inst[enb_mod_idP].Info.UE[ue_mod_idP];
gauthier's avatar
   
gauthier committed
697
698
699
700
701
702
703
704
705
706
#endif
    uint8_t                             buffer[RRC_BUF_SIZE];
    uint16_t                            size;
    int                                 i;

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

    struct PhysicalConfigDedicated    **physicalConfigDedicated = &rrc_inst->physicalConfigDedicated[ue_mod_idP];

707
708
709
    struct SRB_ToAddMod                *SRB2_config                      = NULL;
    struct SRB_ToAddMod__rlc_Config    *SRB2_rlc_config                  = NULL;
    struct SRB_ToAddMod__logicalChannelConfig *SRB2_lchan_config         = NULL;
gauthier's avatar
   
gauthier committed
710
    struct LogicalChannelConfig__ul_SpecificParameters
711
                                       *SRB2_ul_SpecificParameters       = NULL;
gauthier's avatar
   
gauthier committed
712
    SRB_ToAddModList_t                 *SRB_configList = rrc_inst->SRB_configList[ue_mod_idP];
713
714
715
716
717
718
719
720
    SRB_ToAddModList_t                 *SRB_configList2                  = NULL;

    struct DRB_ToAddMod                *DRB_config                       = NULL;
    struct RLC_Config                  *DRB_rlc_config                   = NULL;
    struct PDCP_Config                 *DRB_pdcp_config                  = NULL;
    struct PDCP_Config__rlc_AM         *PDCP_rlc_AM                      = NULL;
    struct PDCP_Config__rlc_UM         *PDCP_rlc_UM                      = NULL;
    struct LogicalChannelConfig        *DRB_lchan_config                 = NULL;
gauthier's avatar
   
gauthier committed
721
    struct LogicalChannelConfig__ul_SpecificParameters
722
                                       *DRB_ul_SpecificParameters        = NULL;
gauthier's avatar
   
gauthier committed
723
724
    DRB_ToAddModList_t                **DRB_configList = &rrc_inst->DRB_configList[ue_mod_idP];

725
726
727
728
    MAC_MainConfig_t                   *mac_MainConfig                   = NULL;
    MeasObjectToAddModList_t           *MeasObj_list                     = NULL;
    MeasObjectToAddMod_t               *MeasObj                          = NULL;
    ReportConfigToAddModList_t         *ReportConfig_list                = NULL;
gauthier's avatar
   
gauthier committed
729
730
    ReportConfigToAddMod_t             *ReportConfig_per, *ReportConfig_A1,
        *ReportConfig_A2, *ReportConfig_A3, *ReportConfig_A4, *ReportConfig_A5;
731
    MeasIdToAddModList_t               *MeasId_list                      = NULL;
gauthier's avatar
   
gauthier committed
732
    MeasIdToAddMod_t                   *MeasId0, *MeasId1, *MeasId2, *MeasId3, *MeasId4, *MeasId5;
winckel's avatar
winckel committed
733
#if Rel10
734
    long                               *sr_ProhibitTimer_r9              = NULL;
735
736
//     uint8_t sCellIndexToAdd = rrc_find_free_SCell_index(enb_mod_idP, ue_mod_idP, 1);
    uint8_t                            sCellIndexToAdd = 0;
winckel's avatar
winckel committed
737
#endif
738

gauthier's avatar
   
gauthier committed
739
740
    long                               *logicalchannelgroup, *logicalchannelgroup_drb;
    long                               *maxHARQ_Tx, *periodicBSR_Timer;
741

742
743
744
745
746
    RSRP_Range_t                       *rsrp                             = NULL;
    struct MeasConfig__speedStatePars  *Sparams                          = NULL;
    QuantityConfig_t                   *quantityConfig                   = NULL;
    CellsToAddMod_t                    *CellToAdd                        = NULL;
    CellsToAddModList_t                *CellsToAddModList                = NULL;
gauthier's avatar
   
gauthier committed
747
    struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList = NULL;
748
    DedicatedInfoNAS_t                 *dedicatedInfoNas                 = NULL;
749

750
    C_RNTI_t                           *cba_RNTI                         = NULL;
751
#ifdef CBA
gauthier's avatar
   
gauthier committed
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
    //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_mod_idP % 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",
              enb_mod_idP, frameP,
              rrc_inst->cba_rnti[ue_mod_idP % rrc_inst->num_active_cba_groups],
              ue_mod_idP % rrc_inst->num_active_cba_groups, ue_mod_idP);
    } 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", enb_mod_idP, frameP, ue_mod_idP);
winckel's avatar
winckel committed
772
    }
773

774
#endif
gauthier's avatar
   
gauthier committed
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
    // Configure SRB2
    /// SRB2
    SRB2_config = CALLOC(1, sizeof(*SRB2_config));
    SRB_configList2 = CALLOC(1, sizeof(*SRB_configList2));
    memset(SRB_configList2, 0, sizeof(*SRB_configList2));

    SRB2_config->srb_Identity = 2;
    SRB2_rlc_config = CALLOC(1, sizeof(*SRB2_rlc_config));
    SRB2_config->rlc_Config = SRB2_rlc_config;

    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;

    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;

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

    SRB2_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup;

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

    // Configure DRB
nikaeinn's avatar
nikaeinn committed
818
819
    //*DRB_configList = CALLOC(1, sizeof(*DRB_configList));
    *DRB_configList = CALLOC(1, sizeof(**DRB_configList));
gauthier's avatar
   
gauthier committed
820
821
822
823
    /// DRB
    DRB_config = CALLOC(1, sizeof(*DRB_config));

    DRB_config->eps_BearerIdentity = CALLOC(1, sizeof(long));
nikaeinn's avatar
nikaeinn committed
824
    *(DRB_config->eps_BearerIdentity) = 5L; // LW set to first value, allowed value 5..15, value : x+4
gauthier's avatar
   
gauthier committed
825
826
827
    // 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
    // NN: this is the 1st DRB for this ue, so set it to 1
nikaeinn's avatar
nikaeinn committed
828
    DRB_config->drb_Identity = (DRB_Identity_t) 1;  // (ue_mod_idP+1); //allowed values 1..32, value: x
gauthier's avatar
   
gauthier committed
829
    DRB_config->logicalChannelIdentity = CALLOC(1, sizeof(long));
nikaeinn's avatar
nikaeinn committed
830
    *(DRB_config->logicalChannelIdentity) = (long)3; // value : x+2
gauthier's avatar
   
gauthier committed
831
832
    DRB_rlc_config = CALLOC(1, sizeof(*DRB_rlc_config));
    DRB_config->rlc_Config = DRB_rlc_config;
winckel's avatar
winckel committed
833

834
#ifdef RRC_RLC_AM // EXMIMO_IOT
gauthier's avatar
   
gauthier committed
835
836
837
838
839
840
841
    DRB_rlc_config->present = RLC_Config_PR_am;
    DRB_rlc_config->choice.am.ul_AM_RLC.t_PollRetransmit = T_PollRetransmit_ms50;
    DRB_rlc_config->choice.am.ul_AM_RLC.pollPDU = PollPDU_p16;
    DRB_rlc_config->choice.am.ul_AM_RLC.pollByte = PollByte_kBinfinity;
    DRB_rlc_config->choice.am.ul_AM_RLC.maxRetxThreshold = UL_AM_RLC__maxRetxThreshold_t8;
    DRB_rlc_config->choice.am.dl_AM_RLC.t_Reordering = T_Reordering_ms35;
    DRB_rlc_config->choice.am.dl_AM_RLC.t_StatusProhibit = T_StatusProhibit_ms25;
842
#else
gauthier's avatar
   
gauthier committed
843
844
845
    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;
846
847
848
#ifdef CBA
    DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering = T_Reordering_ms5;//T_Reordering_ms25;
#else 
gauthier's avatar
   
gauthier committed
849
    DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering = T_Reordering_ms25;
850
#endif 
851
#endif
852

gauthier's avatar
   
gauthier committed
853
854
855
856
857
858
    DRB_pdcp_config = CALLOC(1, sizeof(*DRB_pdcp_config));
    DRB_config->pdcp_Config = DRB_pdcp_config;
    DRB_pdcp_config->discardTimer = CALLOC(1, sizeof(long));
    *DRB_pdcp_config->discardTimer = PDCP_Config__discardTimer_infinity;
    DRB_pdcp_config->rlc_AM = NULL;
    DRB_pdcp_config->rlc_UM = NULL;
859

860
#ifdef RRC_RLC_AM // EXMIMO_IOT
gauthier's avatar
   
gauthier committed
861
862
863
    PDCP_rlc_AM = CALLOC(1, sizeof(*PDCP_rlc_AM));
    DRB_pdcp_config->rlc_AM = PDCP_rlc_AM;
    PDCP_rlc_AM->statusReportRequired = FALSE;
864
#else
gauthier's avatar
   
gauthier committed
865
866
867
    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;
868
#endif
gauthier's avatar
   
gauthier committed
869
    DRB_pdcp_config->headerCompression.present = PDCP_Config__headerCompression_PR_notUsed;
870

gauthier's avatar
   
gauthier committed
871
872
873
874
    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;
875

gauthier's avatar
   
gauthier committed
876
877
878
879
880
    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;
881

gauthier's avatar
   
gauthier committed
882
883
884
885
    // 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
886

gauthier's avatar
   
gauthier committed
887
    ASN_SEQUENCE_ADD(&(*DRB_configList)->list, DRB_config);
winckel's avatar
RRC:    
winckel committed
888

gauthier's avatar
   
gauthier committed
889
890
    mac_MainConfig = CALLOC(1, sizeof(*mac_MainConfig));
    eNB_rrc_inst[enb_mod_idP].mac_MainConfig[ue_mod_idP] = mac_MainConfig;
winckel's avatar
RRC:    
winckel committed
891

gauthier's avatar
   
gauthier committed
892
    mac_MainConfig->ul_SCH_Config = CALLOC(1, sizeof(*mac_MainConfig->ul_SCH_Config));
893

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

903
904
    mac_MainConfig->timeAlignmentTimerDedicated = TimeAlignmentTimer_infinity;

gauthier's avatar
   
gauthier committed
905
    mac_MainConfig->drx_Config = NULL;
winckel's avatar
winckel committed
906

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

gauthier's avatar
   
gauthier committed
909
910
    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
911

gauthier's avatar
   
gauthier committed
912
    mac_MainConfig->phr_Config->choice.setup.prohibitPHR_Timer = MAC_MainConfig__phr_Config__setup__prohibitPHR_Timer_sf20; // sf20 = 20 subframes
913

gauthier's avatar
   
gauthier committed
914
    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
915

winckel's avatar
winckel committed
916
#ifdef Rel10
gauthier's avatar
   
gauthier committed
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
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
    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;
#endif

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

    MeasId0 = CALLOC(1, sizeof(*MeasId0));
    MeasId0->measId = 1;
    MeasId0->measObjectId = 1;
    MeasId0->reportConfigId = 1;
    ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId0);

    MeasId1 = CALLOC(1, sizeof(*MeasId1));
    MeasId1->measId = 2;
    MeasId1->measObjectId = 1;
    MeasId1->reportConfigId = 2;
    ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId1);

    MeasId2 = CALLOC(1, sizeof(*MeasId2));
    MeasId2->measId = 3;
    MeasId2->measObjectId = 1;
    MeasId2->reportConfigId = 3;
    ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId2);

    MeasId3 = CALLOC(1, sizeof(*MeasId3));
    MeasId3->measId = 4;
    MeasId3->measObjectId = 1;
    MeasId3->reportConfigId = 4;
    ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId3);

    MeasId4 = CALLOC(1, sizeof(*MeasId4));
    MeasId4->measId = 5;
    MeasId4->measObjectId = 1;
    MeasId4->reportConfigId = 5;
    ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId4);

    MeasId5 = CALLOC(1, sizeof(*MeasId5));
    MeasId5->measId = 6;
    MeasId5->measObjectId = 1;
    MeasId5->reportConfigId = 6;
    ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId5);

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

    // Add one EUTRA Measurement Object
    MeasObj_list = CALLOC(1, sizeof(*MeasObj_list));
    memset((void *)MeasObj_list, 0, sizeof(*MeasObj_list));

    // Configure MeasObject

    MeasObj = CALLOC(1, sizeof(*MeasObj));
    memset((void *)MeasObj, 0, sizeof(*MeasObj));

    MeasObj->measObjectId = 1;
    MeasObj->measObject.present = MeasObjectToAddMod__measObject_PR_measObjectEUTRA;
976
977
    MeasObj->measObject.choice.measObjectEUTRA.carrierFreq = 3350; //band 7, 2.68GHz 
    //MeasObj->measObject.choice.measObjectEUTRA.carrierFreq = 36090; //band 33, 1.909GHz
gauthier's avatar
   
gauthier committed
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
    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

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

    CellsToAddModList = MeasObj->measObject.choice.measObjectEUTRA.cellsToAddModList;

    // 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(enb_mod_idP, i);
        CellToAdd->cellIndividualOffset = Q_OffsetRange_dB0;

        ASN_SEQUENCE_ADD(&CellsToAddModList->list, CellToAdd);
    }
1000

gauthier's avatar
   
gauthier committed
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
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
    ASN_SEQUENCE_ADD(&MeasObj_list->list, MeasObj);
    //  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->measObjectToAddModList = MeasObj_list;

    // Report Configurations for periodical, A1-A5 events
    ReportConfig_list = CALLOC(1, sizeof(*ReportConfig_list));

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

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

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

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

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

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

    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;

    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;

    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;

    ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A1);

    if (ho_state == 1 /*HO_MEASURMENT */ ) {
        LOG_I(RRC, "[eNB %d] frame %d: requesting A2, A3, A4, A5, and A6 event reporting\n", enb_mod_idP, frameP);
        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);

        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;

        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;

        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",
              enb_mod_idP, frameP);
        // 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_mod_idP] = CALLOC(1, sizeof(*(rrc_inst->handover_info[ue_mod_idP])));
        //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.srb_ToAddModList,(void *)SRB_list,sizeof(SRB_ToAddModList_t));
        rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.srb_ToAddModList = SRB_configList2;
        //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.drb_ToAddModList,(void *)DRB_list,sizeof(DRB_ToAddModList_t));
        rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.drb_ToAddModList = *DRB_configList;
        rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.drb_ToReleaseList = NULL;
        rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.mac_MainConfig =
            CALLOC(1, sizeof(*rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.mac_MainConfig));
        memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.mac_MainConfig,
               (void *)mac_MainConfig, sizeof(MAC_MainConfig_t));
        rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.physicalConfigDedicated =
            CALLOC(1, sizeof(PhysicalConfigDedicated_t));
        memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.physicalConfigDedicated,
               (void *)rrc_inst->physicalConfigDedicated[ue_mod_idP], sizeof(PhysicalConfigDedicated_t));
        rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.sps_Config = NULL;
        //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.sps_Config,(void *)rrc_inst->sps_Config[ue_mod_idP],sizeof(SPS_Config_t));
1189

gauthier's avatar
   
gauthier committed
1190
    }
winckel's avatar
winckel committed
1191
#if defined(ENABLE_ITTI)
gauthier's avatar
   
gauthier committed
1192
1193
1194
1195
1196
1197
    /* Initialize NAS list */
    dedicatedInfoNASList = CALLOC(1, sizeof(struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList));
    /* Add all NAS PDUs to the list */
    for (i = 0; i < UE_info->nb_of_e_rabs; i++) {
        if (UE_info->e_rab[i].param.nas_pdu.buffer != NULL) {
            dedicatedInfoNas = CALLOC(1, sizeof(DedicatedInfoNAS_t));
hrizi's avatar
   
hrizi committed
1198
	    memset(dedicatedInfoNas, 0, sizeof(OCTET_STRING_t));
gauthier's avatar
   
gauthier committed
1199
1200
1201
1202
            OCTET_STRING_fromBuf(dedicatedInfoNas, (char *)UE_info->e_rab[i].param.nas_pdu.buffer,
                                 UE_info->e_rab[i].param.nas_pdu.length);
            ASN_SEQUENCE_ADD(&dedicatedInfoNASList->list, dedicatedInfoNas);
        }
1203

gauthier's avatar
   
gauthier committed
1204
1205
1206
1207
1208
1209
        /* TODO parameters yet to process ... */
        {
            UE_info->e_rab[i].param.qos;
            UE_info->e_rab[i].param.sgw_addr;
            UE_info->e_rab[i].param.gtp_teid;
        }
1210

gauthier's avatar
   
gauthier committed
1211
1212
1213
1214
1215
1216
1217
        /* TODO should test if e RAB are Ok before! */
        eNB_rrc_inst[enb_mod_idP].Info.UE[ue_mod_idP].e_rab[i].status = E_RAB_STATUS_DONE;
    }
    /* If list is empty free the list and reset the address */
    if (dedicatedInfoNASList->list.count == 0) {
        free(dedicatedInfoNASList);
        dedicatedInfoNASList = NULL;
1218
    }
winckel's avatar
winckel committed
1219
1220
#endif

gauthier's avatar
   
gauthier committed
1221
    memset(buffer, 0, RRC_BUF_SIZE);
1222

1223
1224
1225
1226
1227
    size = do_RRCConnectionReconfiguration(enb_mod_idP, buffer, ue_mod_idP, 
					   rrc_eNB_get_next_transaction_identifier(enb_mod_idP),   //Transaction_id,
					   NULL, /// NN: do not reconfig srb1: SRB_configList2,
					   *DRB_configList, NULL,  // DRB2_list,
					   NULL,    // *sps_Config,
1228
#ifdef EXMIMO_IOT
1229
					   NULL, NULL, NULL, NULL,NULL,
1230
#else
1231
					   physicalConfigDedicated[ue_mod_idP], MeasObj_list, ReportConfig_list, quantityConfig, MeasId_list,
1232
#endif
1233
1234
1235
1236
1237
					   mac_MainConfig, NULL, NULL, Sparams, rsrp, cba_RNTI, dedicatedInfoNASList
#ifdef Rel10
					   , NULL //SCellToAddMod_r10_t  
#endif
					   );
1238

1239
#ifdef RRC_MSG_PRINT
1240
    LOG_F(RRC,"[MSG] RRC Connection Reconfiguration\n");
1241
  for (i = 0; i < size; i++)
1242
      LOG_F(RRC,"%02x ", ((uint8_t*)buffer)[i]);
1243
1244
1245
1246
  LOG_F(RRC,"\n");
  ////////////////////////////////////////
#endif

winckel's avatar
winckel committed
1247
#if defined(ENABLE_ITTI)
gauthier's avatar
   
gauthier committed
1248
1249
1250
1251
1252
1253
1254
    /* Free all NAS PDUs */
    for (i = 0; i < UE_info->nb_of_e_rabs; i++) {
        if (UE_info->e_rab[i].param.nas_pdu.buffer != NULL) {
            /* Free the NAS PDU buffer and invalidate it */
            free(UE_info->e_rab[i].param.nas_pdu.buffer);
            UE_info->e_rab[i].param.nas_pdu.buffer = NULL;
        }
1255
    }
winckel's avatar
winckel committed
1256
#endif
1257

gauthier's avatar
   
gauthier committed
1258
1259
1260
    LOG_I(RRC,
          "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate RRCConnectionReconfiguration (bytes %d, UE id %d)\n",
          enb_mod_idP, frameP, size, ue_mod_idP);
1261

gauthier's avatar
   
gauthier committed
1262
1263
1264
1265
1266
    LOG_D(RRC,
          "[FRAME %05d][RRC_eNB][MOD %u/%u][][--- PDCP_DATA_REQ/%d Bytes (rrcConnectionReconfiguration to UE %d MUI %d) --->][PDCP][MOD %u/%u][RB %u]\n",
          frameP, enb_mod_idP, ue_mod_idP, size, ue_mod_idP, rrc_eNB_mui, enb_mod_idP, ue_mod_idP, DCCH);
    //rrc_rlc_data_req(enb_mod_idP,frameP, 1,(ue_mod_idP*NB_RB_MAX)+DCCH,rrc_eNB_mui++,0,size,(char*)buffer);
    pdcp_rrc_data_req(enb_mod_idP, ue_mod_idP, frameP, 1, DCCH, rrc_eNB_mui++, 0, size, buffer, 1);
winckel's avatar
winckel committed
1267
}
1268

1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279


int rrc_eNB_generate_RRCConnectionReconfiguration_SCell(module_id_t enb_mod_idP, module_id_t ue_mod_idP, frame_t frame, uint32_t dl_CarrierFreq_r10) {

  uint8_t size;
  uint8_t buffer[100];
  
#ifdef Rel10
  uint8_t sCellIndexToAdd = 0; //one SCell so far
//   uint8_t sCellIndexToAdd;
//   sCellIndexToAdd = rrc_find_free_SCell_index(enb_mod_idP, ue_mod_idP, 1);
1280
1281
1282
//  if (eNB_rrc_inst[enb_mod_idP].sCell_config[ue_mod_idP][sCellIndexToAdd] ) {
  if (eNB_rrc_inst[enb_mod_idP].sCell_config != NULL) {
    eNB_rrc_inst[enb_mod_idP].sCell_config[ue_mod_idP][sCellIndexToAdd].cellIdentification_r10->dl_CarrierFreq_r10 = dl_CarrierFreq_r10;
1283
1284
1285
1286
1287
1288
1289
1290
1291
  }
  else {
    LOG_E(RRC,"Scell not configured!\n");
    return(-1);
  }  
#endif
  size = do_RRCConnectionReconfiguration(enb_mod_idP,
                                         buffer,
                                         ue_mod_idP,
1292
                                         rrc_eNB_get_next_transaction_identifier(enb_mod_idP),//Transaction_id,
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
                                         (SRB_ToAddModList_t*)NULL,
                                         (DRB_ToAddModList_t*)NULL,
                                         (DRB_ToReleaseList_t*)NULL,
                                         (struct SPS_Config*)NULL,
                                         (struct PhysicalConfigDedicated*)NULL,
                                         (MeasObjectToAddModList_t*)NULL,
                                         (ReportConfigToAddModList_t*)NULL,
                                         (QuantityConfig_t*)NULL, 
                                         (MeasIdToAddModList_t*)NULL,
                                         (MAC_MainConfig_t*)NULL,
                                         (MeasGapConfig_t*)NULL,
                                         (MobilityControlInfo_t*)NULL,
                                         (struct MeasConfig__speedStatePars*)NULL,
                                         (RSRP_Range_t*)NULL,
                                         (C_RNTI_t*)NULL,
1308
1309
1310
1311
1312
1313
                                         (struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList*)NULL

#ifdef Rel10
					 , eNB_rrc_inst[enb_mod_idP].sCell_config
#endif
					 ); 
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327

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

  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, enb_mod_idP, size, ue_mod_idP, rrc_eNB_mui, enb_mod_idP, /*(ue_mod_idP*MAX_NUM_RB)+*/DCCH);
  //rrc_rlc_data_req(Mod_id,frame, 1,(UE_index*MAX_NUM_RB)+DCCH,rrc_eNB_mui++,0,size,(char*)buffer);
//   pdcp_data_req(enb_mod_idP, ue_mod_idP, frame, 1, /*(UE_index * MAX_NUM_RB) + */DCCH, rrc_eNB_mui++, 0, size, (char*)buffer, 1);
    pdcp_rrc_data_req(enb_mod_idP, ue_mod_idP, frame, 1, DCCH, rrc_eNB_mui++, 0, size, buffer, 1);

  return(0);
}


winckel's avatar
winckel committed
1328
/*------------------------------------------------------------------------------*/
gauthier's avatar
   
gauthier committed
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
void rrc_eNB_process_MeasurementReport(
    module_id_t enb_mod_idP,
    frame_t frameP,
    module_id_t ue_mod_idP,
    MeasResults_t * measResults2) {

    LOG_I(RRC, "[eNB %d] Frame %d: Process Measurement Report From UE %d (Measurement Id %d)\n",
          enb_mod_idP, frameP, ue_mod_idP, (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));
    }
1347
#ifdef Rel10
gauthier's avatar