rrc_eNB.c 223 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
 * the OAI Public License, Version 1.0  (the "License"); you may not use this file
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */
21
22
23

/*! \file rrc_eNB.c
 * \brief rrc procedures for eNB
24
 * \author Navid Nikaein and  Raymond Knopp
nikaeinn's avatar
nikaeinn committed
25
 * \date 2011 - 2014
26
27
 * \version 1.0
 * \company Eurecom
nikaeinn's avatar
nikaeinn committed
28
 * \email: navid.nikaein@eurecom.fr and raymond.knopp@eurecom.fr
29
 */
gauthier's avatar
gauthier committed
30
31
#define RRC_ENB
#define RRC_ENB_C
32
33
34

#include "defs.h"
#include "extern.h"
35
#include "assertions.h"
36
#include "asn1_conversions.h"
37
38
#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"
#include "LAYER2/RLC/rlc.h"
39
#include "LAYER2/MAC/proto.h"
40
41
42
43
#include "UTIL/LOG/log.h"
#include "COMMON/mac_rrc_primitives.h"
#include "RRC/LITE/MESSAGES/asn1_msg.h"
#include "RRCConnectionRequest.h"
44
45
#include "RRCConnectionReestablishmentRequest.h"
//#include "ReestablishmentCause.h"
46
47
48
49
50
#include "UL-CCCH-Message.h"
#include "DL-CCCH-Message.h"
#include "UL-DCCH-Message.h"
#include "DL-DCCH-Message.h"
#include "TDD-Config.h"
51
#include "HandoverCommand.h"
52
53
#include "rlc.h"
#include "SIMULATION/ETH_TRANSPORT/extern.h"
54
55
56
#include "rrc_eNB_UE_context.h"
#include "platform_types.h"
#include "msc.h"
57

58
59
#include "T.h"

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

#ifdef USER_MODE
gauthier's avatar
   
gauthier committed
65
66
67
68
#   include "RRC/NAS/nas_config.h"
#   include "RRC/NAS/rb_config.h"
#   include "OCG.h"
#   include "OCG_extern.h"
69
70
#endif

71
#if defined(ENABLE_SECURITY)
gauthier's avatar
   
gauthier committed
72
#   include "UTIL/OSA/osa_defs.h"
73
74
#endif

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

84
85
86
#include "pdcp.h"

#if defined(ENABLE_ITTI)
gauthier's avatar
   
gauthier committed
87
#   include "intertask_interface.h"
88
89
#endif

90
#if ENABLE_RAL
gauthier's avatar
   
gauthier committed
91
#   include "rrc_eNB_ral.h"
gauthier's avatar
gauthier committed
92
93
#endif

94
95
#include "SIMULATION/TOOLS/defs.h" // for taus

96
#if defined(FLEXRAN_AGENT_SB_IF)
97
#include "flexran_agent_extern.h"
98
#endif
99
//#define XER_PRINT
100
101

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

gauthier's avatar
   
gauthier committed
110
extern uint16_t                     two_tier_hexagonal_cellIds[7];
winckel's avatar
RRC:    
winckel committed
111

gauthier's avatar
   
gauthier committed
112
mui_t                               rrc_eNB_mui = 0;
winckel's avatar
RRC:    
winckel committed
113

114
115
116
//-----------------------------------------------------------------------------
static void
init_SI(
117
118
  const protocol_ctxt_t* const ctxt_pP,
  const int              CC_id
winckel's avatar
winckel committed
119
#if defined(ENABLE_ITTI)
120
121
  ,
  RrcConfigurationReq * configuration
winckel's avatar
winckel committed
122
#endif
123
)
124
//-----------------------------------------------------------------------------
125
126
127
{
  uint8_t                             SIwindowsize = 1;
  uint16_t                            SIperiod = 8;
128
#ifdef Rel10
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
  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);
   */
gauthier's avatar
   
gauthier committed
175

176
177
178
  eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sizeof_SIB1 = 0;
  eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sizeof_SIB23 = 0;
  eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].SIB1 = (uint8_t*) malloc16(32);
gauthier's avatar
   
gauthier committed
179

180
181
182
183
184
185
  /*
     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);
   */
gauthier's avatar
   
gauthier committed
186

187
188
  if (eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].SIB1)
    eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sizeof_SIB1 = do_SIB1(
189
          ctxt_pP->module_id,
190
          CC_id,
191
          mac_xface->frame_parms,
192
193
194
          (uint8_t*)eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].SIB1,
          &eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].siblock1,
          &eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib1
winckel's avatar
winckel committed
195
#if defined(ENABLE_ITTI)
196
          , configuration
winckel's avatar
winckel committed
197
#endif
198
        );
199
  else {
200
201
    LOG_E(RRC, PROTOCOL_RRC_CTXT_FMT" init_SI: FATAL, no memory for SIB1 allocated\n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
202
203
204
205
206
207
208
209
210
    mac_xface->macphy_exit("[RRC][init_SI] FATAL, no memory for SIB1 allocated");
  }

  /*
     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);
   */
211
212
  if (eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sizeof_SIB1 == 255) {
    mac_xface->macphy_exit("[RRC][init_SI] FATAL, eNB_rrc_inst[enb_mod_idP].carrier[CC_id].sizeof_SIB1 == 255");
213
  }
214

215
  eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].SIB23 = (uint8_t*) malloc16(64);
216

217
218
  if (eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].SIB23) {
    eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sizeof_SIB23 = do_SIB23(
219
          ctxt_pP->module_id,
220
          CC_id,
221
          mac_xface->frame_parms,
222
223
224
225
          eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].SIB23,
          &eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].systemInformation,
          &eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2,
          &eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib3
226
#ifdef Rel10
227
228
          , &eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib13,
          eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].MBMS_flag
229
230
#endif
#if defined(ENABLE_ITTI)
231
          , configuration
gauthier's avatar
   
gauthier committed
232
#endif
233
        );
234
235

    /*
236
237
238
239
       eNB_rrc_inst[ctxt_pP->module_id].sizeof_SIB23 = do_SIB2_AT4(ctxt_pP->module_id,
       eNB_rrc_inst[ctxt_pP->module_id].SIB23,
       &eNB_rrc_inst[ctxt_pP->module_id].systemInformation,
       &eNB_rrc_inst[ctxt_pP->module_id].sib2,
240
241
242
243
244
       #if defined(ENABLE_ITTI)
       , configuration
       #endif
       );
     */
245
246
    if (eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sizeof_SIB23 == 255) {
      mac_xface->macphy_exit("[RRC][init_SI] FATAL, eNB_rrc_inst[mod].carrier[CC_id].sizeof_SIB23 == 255");
247
248
249
250
251
252
    }

    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" SIB2/3 Contents (partial)\n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.n_SB = %ld\n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
253
254
          eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
          pusch_ConfigBasic.n_SB);
255
256
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.hoppingMode = %ld\n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
257
258
          eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
          pusch_ConfigBasic.hoppingMode);
259
260
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.pusch_HoppingOffset = %ld\n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
261
          eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
262
          pusch_ConfigBasic.pusch_HoppingOffset);
263
264
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.enable64QAM = %d\n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
265
          (int)eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
266
          pusch_ConfigBasic.enable64QAM);
267
268
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.groupHoppingEnabled = %d\n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
269
          (int)eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
270
          ul_ReferenceSignalsPUSCH.groupHoppingEnabled);
271
272
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.groupAssignmentPUSCH = %ld\n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
273
274
          eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
          ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH);
275
276
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.sequenceHoppingEnabled = %d\n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
277
278
          (int)eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
          ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled);
279
280
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.cyclicShift  = %ld\n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
281
282
          eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
          ul_ReferenceSignalsPUSCH.cyclicShift);
283
284

#ifdef Rel10
285

286
287
    if (eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].MBMS_flag > 0) {
      for (i = 0; i < eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->mbsfn_SubframeConfigList->list.count; i++) {
288
289
        // 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);
290
291
292
        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" SIB13 contents for MBSFN subframe allocation %d/%d(partial)\n",
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
              i,
293
              eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->mbsfn_SubframeConfigList->list.count);
294
295
        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" mbsfn_Subframe_pattern is  = %x\n",
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
296
              eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->mbsfn_SubframeConfigList->list.array[i]->subframeAllocation.choice.oneFrame.buf[0] >> 0);
297
298
        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" radioframe_allocation_period  = %ld (just index number, not the real value)\n",
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
299
              eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->mbsfn_SubframeConfigList->list.array[i]->radioframeAllocationPeriod);   // need to display the real value, using array of char (like in dumping SIB2)
300
301
        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" radioframe_allocation_offset  = %ld\n",
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
302
              eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->mbsfn_SubframeConfigList->list.array[i]->radioframeAllocationOffset);
303
304
305
      }

      //   SIB13
306
      for (i = 0; i < eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib13->mbsfn_AreaInfoList_r9.list.count; i++) {
Cedric Roux's avatar
Cedric Roux committed
307
        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" SIB13 contents for MBSFN sync area %d/%d (partial)\n",
308
309
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
              i,
310
              eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib13->mbsfn_AreaInfoList_r9.list.count);
Cedric Roux's avatar
Cedric Roux committed
311
        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" MCCH Repetition Period: %ld (just index number, not real value)\n",
312
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
313
              eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib13->mbsfn_AreaInfoList_r9.list.array[i]->mcch_Config_r9.mcch_RepetitionPeriod_r9);
Cedric Roux's avatar
Cedric Roux committed
314
        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" MCCH Offset: %ld\n",
315
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
316
              eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib13->mbsfn_AreaInfoList_r9.list.array[i]->mcch_Config_r9.mcch_Offset_r9);
317
318
319
      }
    }

320
321
#endif

322
    LOG_D(RRC,
323
324
          PROTOCOL_RRC_CTXT_FMT" RRC_UE --- MAC_CONFIG_REQ (SIB1.tdd & SIB2 params) ---> MAC_UE\n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
325
    rrc_mac_config_req(ctxt_pP->module_id, CC_id, ENB_FLAG_YES, 0, 0,
326
                       (RadioResourceConfigCommonSIB_t *) &
327
                       eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->radioResourceConfigCommon,
328
                       (struct PhysicalConfigDedicated *)NULL,
329
#ifdef Rel10
330
331
                       (SCellToAddMod_r10_t *)NULL,
                       //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
332
#endif
333
334
335
336
                       (MeasObjectToAddMod_t **) NULL,
                       (MAC_MainConfig_t *) NULL, 0,
                       (struct LogicalChannelConfig *)NULL,
                       (MeasGapConfig_t *) NULL,
337
                       eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib1->tdd_Config,
338
339
                       NULL,
                       &SIwindowsize, &SIperiod,
340
341
342
343
                       eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->freqInfo.ul_CarrierFreq,
                       eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->freqInfo.ul_Bandwidth,
                       &eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->freqInfo.additionalSpectrumEmission,
                       (MBSFN_SubframeConfigList_t*) eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->mbsfn_SubframeConfigList
344
#ifdef Rel10
345
                       ,
346
347
                       eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].MBMS_flag,
                       (MBSFN_AreaInfoList_r9_t*) & eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib13->mbsfn_AreaInfoList_r9,
348
                       (PMCH_InfoList_r9_t *) NULL
349
350
#endif
#ifdef CBA
351
352
                       , 0, //eNB_rrc_inst[ctxt_pP->module_id].num_active_cba_groups,
                       0    //eNB_rrc_inst[ctxt_pP->module_id].cba_rnti[0]
353
#endif
354
355
                      );
  } else {
356
357
    LOG_E(RRC, PROTOCOL_RRC_CTXT_FMT" init_SI: FATAL, no memory for SIB2/3 allocated\n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
358
359
    mac_xface->macphy_exit("[RRC][init_SI] FATAL, no memory for SIB2/3 allocated");
  }
360
361
362
}

#ifdef Rel10
winckel's avatar
winckel committed
363
/*------------------------------------------------------------------------------*/
364
365
static void
init_MCCH(
366
367
  module_id_t enb_mod_idP,
  int CC_id
368
369
)
//-----------------------------------------------------------------------------
370
{
gauthier's avatar
   
gauthier committed
371

372
373
  int                                 sync_area = 0;
  // initialize RRC_eNB_INST MCCH entry
374
  eNB_rrc_inst[enb_mod_idP].carrier[CC_id].MCCH_MESSAGE =
375
    malloc(eNB_rrc_inst[enb_mod_idP].carrier[CC_id].num_mbsfn_sync_area * sizeof(uint8_t*));
gauthier's avatar
   
gauthier committed
376

377
  for (sync_area = 0; sync_area < eNB_rrc_inst[enb_mod_idP].carrier[CC_id].num_mbsfn_sync_area; sync_area++) {
gauthier's avatar
   
gauthier committed
378

379
380
    eNB_rrc_inst[enb_mod_idP].carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] = 0;
    eNB_rrc_inst[enb_mod_idP].carrier[CC_id].MCCH_MESSAGE[sync_area] = (uint8_t *) malloc16(32);
381

382
    if (eNB_rrc_inst[enb_mod_idP].carrier[CC_id].MCCH_MESSAGE[sync_area] == NULL) {
383
384
385
      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 {
386
      eNB_rrc_inst[enb_mod_idP].carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] = do_MBSFNAreaConfig(enb_mod_idP,
387
          mac_xface->frame_parms,
388
389
390
391
392
393
394
          sync_area,
          (uint8_t *)eNB_rrc_inst[enb_mod_idP].carrier[CC_id].MCCH_MESSAGE[sync_area],
          &eNB_rrc_inst[enb_mod_idP].carrier[CC_id].mcch,
          &eNB_rrc_inst[enb_mod_idP].carrier[CC_id].mcch_message);

      LOG_I(RRC, "mcch message pointer %p for sync area %d \n",
            eNB_rrc_inst[enb_mod_idP].carrier[CC_id].MCCH_MESSAGE[sync_area],
395
396
            sync_area);
      LOG_D(RRC, "[eNB %d] MCCH_MESSAGE  contents for Sync Area %d (partial)\n", enb_mod_idP, sync_area);
Cedric Roux's avatar
Cedric Roux committed
397
      LOG_D(RRC, "[eNB %d] CommonSF_AllocPeriod_r9 %ld\n", enb_mod_idP,
398
            eNB_rrc_inst[enb_mod_idP].carrier[CC_id].mcch_message->commonSF_AllocPeriod_r9);
399
400
      LOG_D(RRC,
            "[eNB %d] CommonSF_Alloc_r9.list.count (number of MBSFN Subframe Pattern) %d\n",
401
            enb_mod_idP, eNB_rrc_inst[enb_mod_idP].carrier[CC_id].mcch_message->commonSF_Alloc_r9.list.count);
402
403
      LOG_D(RRC, "[eNB %d] MBSFN Subframe Pattern: %02x (in hex)\n",
            enb_mod_idP,
404
            eNB_rrc_inst[enb_mod_idP].carrier[CC_id].mcch_message->commonSF_Alloc_r9.list.array[0]->subframeAllocation.
405
406
            choice.oneFrame.buf[0]);

407
408
      if (eNB_rrc_inst[enb_mod_idP].carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] == 255) {
        mac_xface->macphy_exit("[RRC][init_MCCH] eNB_rrc_inst[enb_mod_idP].carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] == 255");
409
      } else {
410
        eNB_rrc_inst[enb_mod_idP].carrier[CC_id].MCCH_MESS[sync_area].Active = 1;
411
      }
412
    }
413
  }
gauthier's avatar
   
gauthier committed
414

415
  //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)
gauthier's avatar
   
gauthier committed
416

417
418
419
420
421
  // ??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]);
422
  rrc_mac_config_req(enb_mod_idP, CC_id, ENB_FLAG_YES, 0, 0,
423
424
                     (RadioResourceConfigCommonSIB_t *) NULL,
                     (struct PhysicalConfigDedicated *)NULL,
425
#ifdef Rel10
426
427
428
429
430
431
432
433
434
435
                     (SCellToAddMod_r10_t *)NULL,
                     //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
#endif
                     (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
gauthier's avatar
   
gauthier committed
436
#   ifdef Rel10
437
438
439
                     ,
                     0,
                     (MBSFN_AreaInfoList_r9_t *) NULL,
440
                     (PMCH_InfoList_r9_t *) & (eNB_rrc_inst[enb_mod_idP].carrier[CC_id].mcch_message->pmch_InfoList_r9)
gauthier's avatar
   
gauthier committed
441
442
#   endif
#   ifdef CBA
443
                     , 0, 0
gauthier's avatar
   
gauthier committed
444
#   endif
445
                    );
446

447
  //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);
448

449
450
}

451
//-----------------------------------------------------------------------------
gauthier's avatar
   
gauthier committed
452
static void init_MBMS(
453
  module_id_t enb_mod_idP,
454
  int         CC_id,
455
456
457
  frame_t frameP
)
//-----------------------------------------------------------------------------
458
459
460
{
  // init the configuration for MTCH
  protocol_ctxt_t               ctxt;
gauthier's avatar
   
gauthier committed
461

462
  if (eNB_rrc_inst[enb_mod_idP].carrier[CC_id].MBMS_flag > 0) {
463
    PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, enb_mod_idP, ENB_FLAG_YES, NOT_A_RNTI, frameP, 0,enb_mod_idP);
gauthier's avatar
   
gauthier committed
464

465
466
    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
467

468
469
470
471
472
473
474
475
    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
                             NULL,  // key rrc encryption
                             NULL,  // key rrc integrity
                             NULL   // key encryption
gauthier's avatar
   
gauthier committed
476
#   ifdef Rel10
477
                             , &(eNB_rrc_inst[enb_mod_idP].carrier[CC_id].mcch_message->pmch_InfoList_r9)
gauthier's avatar
   
gauthier committed
478
#   endif
479
                             ,NULL);
gauthier's avatar
   
gauthier committed
480

481
482
483
484
    rrc_rlc_config_asn1_req(&ctxt,
                            NULL, // SRB_ToAddModList
                            NULL,   // DRB_ToAddModList
                            NULL,   // DRB_ToReleaseList
485
                            &(eNB_rrc_inst[enb_mod_idP].carrier[CC_id].mcch_message->pmch_InfoList_r9));
gauthier's avatar
   
gauthier committed
486

487
488
    //rrc_mac_config_req();
  }
489
490
491
}
#endif

492
493
494
495
496
497
//-----------------------------------------------------------------------------
uint8_t
rrc_eNB_get_next_transaction_identifier(
  module_id_t enb_mod_idP
)
//-----------------------------------------------------------------------------
498
{
499
500
  static uint8_t                      rrc_transaction_identifier[NUMBER_OF_eNB_MAX];
  rrc_transaction_identifier[enb_mod_idP] = (rrc_transaction_identifier[enb_mod_idP] + 1) % RRC_TRANSACTION_IDENTIFIER_NUMBER;
501
  LOG_T(RRC,"generated xid is %d\n",rrc_transaction_identifier[enb_mod_idP]);
502
503
504
505
506
  return rrc_transaction_identifier[enb_mod_idP];
}
/*------------------------------------------------------------------------------*/
/* Functions to handle UE index in eNB UE list */

winckel's avatar
winckel committed
507

508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
////-----------------------------------------------------------------------------
//static module_id_t
//rrc_eNB_get_UE_index(
//                module_id_t enb_mod_idP,
//                uint64_t    UE_identity
//)
////-----------------------------------------------------------------------------
//{
//
//    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) {
//            // UE_identity already registered
//            reg = TRUE;
//            break;
//        }
//    }
//
//    if (reg == FALSE) {
//        return (UE_MODULE_INVALID);
//    } else
//        return (i);
//}


537
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
538
539
// return the ue context if there is already an UE with ue_identityP, NULL otherwise
static struct rrc_eNB_ue_context_s*
540
541
542
543
544
545
546
547
548
rrc_eNB_ue_context_random_exist(
  const protocol_ctxt_t* const ctxt_pP,
  const uint64_t               ue_identityP
)
//-----------------------------------------------------------------------------
{
  struct rrc_eNB_ue_context_s*        ue_context_p = NULL;
  RB_FOREACH(ue_context_p, rrc_ue_tree_s, &(eNB_rrc_inst[ctxt_pP->module_id].rrc_ue_head)) {
    if (ue_context_p->ue_context.random_ue_identity == ue_identityP)
gauthier's avatar
gauthier committed
549
      return ue_context_p;
550
  }
gauthier's avatar
gauthier committed
551
552
553
554
555
556
557
558
559
560
561
562
563
564
  return NULL;
}
//-----------------------------------------------------------------------------
// return the ue context if there is already an UE with the same S-TMSI(MMEC+M-TMSI), NULL otherwise
static struct rrc_eNB_ue_context_s*
rrc_eNB_ue_context_stmsi_exist(
  const protocol_ctxt_t* const ctxt_pP,
  const mme_code_t             mme_codeP,
  const m_tmsi_t               m_tmsiP
)
//-----------------------------------------------------------------------------
{
  struct rrc_eNB_ue_context_s*        ue_context_p = NULL;
  RB_FOREACH(ue_context_p, rrc_ue_tree_s, &(eNB_rrc_inst[ctxt_pP->module_id].rrc_ue_head)) {
Florian Kaltenberger's avatar
Florian Kaltenberger committed
565
566
567
568
    LOG_I(RRC,"checking for UE S-TMSI %x, mme %x (%p): rnti %x",
	  m_tmsiP, mme_codeP, ue_context_p, 
	  ue_context_p->ue_context.rnti);
    if (ue_context_p->ue_context.Initialue_identity_s_TMSI.presence == TRUE) {
569
      printf("=> S-TMSI %x, MME %x\n",
Florian Kaltenberger's avatar
Florian Kaltenberger committed
570
571
	    ue_context_p->ue_context.Initialue_identity_s_TMSI.m_tmsi,
	    ue_context_p->ue_context.Initialue_identity_s_TMSI.mme_code);
gauthier's avatar
gauthier committed
572
573
574
      if (ue_context_p->ue_context.Initialue_identity_s_TMSI.m_tmsi == m_tmsiP)
        if (ue_context_p->ue_context.Initialue_identity_s_TMSI.mme_code == mme_codeP)
          return ue_context_p;
Florian Kaltenberger's avatar
Florian Kaltenberger committed
575
576
577
578
    }
    else
      printf("\n");

gauthier's avatar
gauthier committed
579
580
  }
  return NULL;
581
582
}

583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
//-----------------------------------------------------------------------------
// return a new ue context structure if ue_identityP, ctxt_pP->rnti not found in collection
static struct rrc_eNB_ue_context_s*
rrc_eNB_get_next_free_ue_context(
  const protocol_ctxt_t* const ctxt_pP,
  const uint64_t               ue_identityP
)
//-----------------------------------------------------------------------------
{
  struct rrc_eNB_ue_context_s*        ue_context_p = NULL;
  ue_context_p = rrc_eNB_get_ue_context(
                   &eNB_rrc_inst[ctxt_pP->module_id],
                   ctxt_pP->rnti);

  if (ue_context_p == NULL) {
    RB_FOREACH(ue_context_p, rrc_ue_tree_s, &(eNB_rrc_inst[ctxt_pP->module_id].rrc_ue_head)) {
      if (ue_context_p->ue_context.random_ue_identity == ue_identityP) {
        LOG_D(RRC,
Cedric Roux's avatar
Cedric Roux committed
601
              PROTOCOL_RRC_CTXT_UE_FMT" Cannot create new UE context, already exist rand UE id 0x%"PRIx64", uid %u\n",
602
603
604
605
606
607
608
              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
              ue_identityP,
              ue_context_p->local_uid);
        return NULL;
      }
    }
    ue_context_p = rrc_eNB_allocate_new_UE_context(&eNB_rrc_inst[ctxt_pP->module_id]);
winckel's avatar
winckel committed
609

610
611
612
613
614
    if (ue_context_p == NULL) {
      LOG_E(RRC,
            PROTOCOL_RRC_CTXT_UE_FMT" Cannot create new UE context, no memory\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
      return NULL;
615
    }
616

617
618
619
620
621
622
623
624
625
    ue_context_p->ue_id_rnti                    = ctxt_pP->rnti; // here ue_id_rnti is just a key, may be something else
    ue_context_p->ue_context.rnti               = ctxt_pP->rnti; // yes duplicate, 1 may be removed
    ue_context_p->ue_context.random_ue_identity = ue_identityP;
    RB_INSERT(rrc_ue_tree_s, &eNB_rrc_inst[ctxt_pP->module_id].rrc_ue_head, ue_context_p);
    LOG_D(RRC,
          PROTOCOL_RRC_CTXT_UE_FMT" Created new UE context uid %u\n",
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
          ue_context_p->local_uid);
    return ue_context_p;
winckel's avatar
winckel committed
626

627
628
629
630
631
632
  } else {
    LOG_E(RRC,
          PROTOCOL_RRC_CTXT_UE_FMT" Cannot create new UE context, already exist\n",
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
    return NULL;
  }
winckel's avatar
winckel committed
633
634
}

635
636
637
638
639
640
641
642
#if !defined(ENABLE_USE_MME)
void rrc_eNB_emulation_notify_ue_module_id(
  const module_id_t ue_module_idP,
  const rnti_t      rntiP,
  const uint8_t     cell_identity_byte0P,
  const uint8_t     cell_identity_byte1P,
  const uint8_t     cell_identity_byte2P,
  const uint8_t     cell_identity_byte3P)
643
{
644
645
  module_id_t                         enb_module_id;
  struct rrc_eNB_ue_context_s*        ue_context_p = NULL;
646
  int                                 CC_id;
647
648
649

  // find enb_module_id
  for (enb_module_id = 0; enb_module_id < NUMBER_OF_eNB_MAX; enb_module_id++) {
650
651
652
    if(enb_module_id>0){ /*FIX LATER*/
      return;
    }
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
    for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
      if (eNB_rrc_inst[enb_module_id].carrier[CC_id].sib1 != NULL) {
        if (
          (eNB_rrc_inst[enb_module_id].carrier[CC_id].sib1->cellAccessRelatedInfo.cellIdentity.buf[0] == cell_identity_byte0P) &&
          (eNB_rrc_inst[enb_module_id].carrier[CC_id].sib1->cellAccessRelatedInfo.cellIdentity.buf[1] == cell_identity_byte1P) &&
          (eNB_rrc_inst[enb_module_id].carrier[CC_id].sib1->cellAccessRelatedInfo.cellIdentity.buf[2] == cell_identity_byte2P) &&
          (eNB_rrc_inst[enb_module_id].carrier[CC_id].sib1->cellAccessRelatedInfo.cellIdentity.buf[3] == cell_identity_byte3P)
        ) {
          ue_context_p = rrc_eNB_get_ue_context(
                           &eNB_rrc_inst[enb_module_id],
                           rntiP
                         );

          if (NULL != ue_context_p) {
            oai_emulation.info.eNB_ue_local_uid_to_ue_module_id[enb_module_id][ue_context_p->local_uid] = ue_module_idP;
          }
winckel's avatar
RRC:    
winckel committed
669

670
          //return;
671
        }
672
673
      }
    }
674
    oai_emulation.info.eNB_ue_module_id_to_rnti[enb_module_id][ue_module_idP] = rntiP;
675
  }
winckel's avatar
winckel committed
676

677
678
679
680
681
  AssertFatal(enb_module_id == NUMBER_OF_eNB_MAX,
              "Cell identity not found for ue module id %u rnti %x",
              ue_module_idP, rntiP);
}
#endif
682

683
684
685
686
687
//-----------------------------------------------------------------------------
void
rrc_eNB_free_mem_UE_context(
  const protocol_ctxt_t*               const ctxt_pP,
  struct rrc_eNB_ue_context_s*         const ue_context_pP
688
)
689
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
690
{
691
692
  int i;
  LOG_T(RRC,
Cedric Roux's avatar
Cedric Roux committed
693
        PROTOCOL_RRC_CTXT_UE_FMT" Clearing UE context 0x%p (free internal structs)\n",
694
695
696
697
698
699
700
701
702
703
704
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
        ue_context_pP);
#ifdef Rel10
  ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_SCellToAddMod_r10, &ue_context_pP->ue_context.sCell_config[0]);
  ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_SCellToAddMod_r10, &ue_context_pP->ue_context.sCell_config[1]);
#endif

  if (ue_context_pP->ue_context.SRB_configList) {
    ASN_STRUCT_FREE(asn_DEF_SRB_ToAddModList, ue_context_pP->ue_context.SRB_configList);
    ue_context_pP->ue_context.SRB_configList = NULL;
  }
705

706
707
708
709
  if (ue_context_pP->ue_context.DRB_configList) {
    ASN_STRUCT_FREE(asn_DEF_DRB_ToAddModList, ue_context_pP->ue_context.DRB_configList);
    ue_context_pP->ue_context.DRB_configList = NULL;
  }
710

711
  memset(ue_context_pP->ue_context.DRB_active, 0, sizeof(ue_context_pP->ue_context.DRB_active));
712

713
714
715
  if (ue_context_pP->ue_context.physicalConfigDedicated) {
    ASN_STRUCT_FREE(asn_DEF_PhysicalConfigDedicated, ue_context_pP->ue_context.physicalConfigDedicated);
    ue_context_pP->ue_context.physicalConfigDedicated = NULL;
716
717
  }

718
719
720
  if (ue_context_pP->ue_context.sps_Config) {
    ASN_STRUCT_FREE(asn_DEF_SPS_Config, ue_context_pP->ue_context.sps_Config);
    ue_context_pP->ue_context.sps_Config = NULL;
721
722
  }

723
724
725
726
727
  for (i=0; i < MAX_MEAS_OBJ; i++) {
    if (ue_context_pP->ue_context.MeasObj[i] != NULL) {
      ASN_STRUCT_FREE(asn_DEF_MeasObjectToAddMod, ue_context_pP->ue_context.MeasObj[i]);
      ue_context_pP->ue_context.MeasObj[i] = NULL;
    }
728
  }
729

730
731
732
733
734
735
  for (i=0; i < MAX_MEAS_CONFIG; i++) {
    if (ue_context_pP->ue_context.ReportConfig[i] != NULL) {
      ASN_STRUCT_FREE(asn_DEF_ReportConfigToAddMod, ue_context_pP->ue_context.ReportConfig[i]);
      ue_context_pP->ue_context.ReportConfig[i] = NULL;
    }
  }
736

737
738
739
740
  if (ue_context_pP->ue_context.QuantityConfig) {
    ASN_STRUCT_FREE(asn_DEF_QuantityConfig, ue_context_pP->ue_context.QuantityConfig);
    ue_context_pP->ue_context.QuantityConfig = NULL;
  }
741

742
743
744
745
  if (ue_context_pP->ue_context.mac_MainConfig) {
    ASN_STRUCT_FREE(asn_DEF_MAC_MainConfig, ue_context_pP->ue_context.mac_MainConfig);
    ue_context_pP->ue_context.mac_MainConfig = NULL;
  }
746

747
748
749
750
  if (ue_context_pP->ue_context.measGapConfig) {
    ASN_STRUCT_FREE(asn_DEF_MeasGapConfig, ue_context_pP->ue_context.measGapConfig);
    ue_context_pP->ue_context.measGapConfig = NULL;
  }
gauthier's avatar
   
gauthier committed
751

752
753
754
755
756
757
758
  //SRB_INFO                           SI;
  //SRB_INFO                           Srb0;
  //SRB_INFO_TABLE_ENTRY               Srb1;
  //SRB_INFO_TABLE_ENTRY               Srb2;
  if (ue_context_pP->ue_context.measConfig) {
    ASN_STRUCT_FREE(asn_DEF_MeasConfig, ue_context_pP->ue_context.measConfig);
    ue_context_pP->ue_context.measConfig = NULL;
759
  }
760

761
762
763
  if (ue_context_pP->ue_context.measConfig) {
    ASN_STRUCT_FREE(asn_DEF_MeasConfig, ue_context_pP->ue_context.measConfig);
    ue_context_pP->ue_context.measConfig = NULL;
764
  }
765

766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
  //HANDOVER_INFO                     *handover_info;
#if defined(ENABLE_SECURITY)
  //uint8_t kenb[32];
#endif
  //e_SecurityAlgorithmConfig__cipheringAlgorithm     ciphering_algorithm;
  //e_SecurityAlgorithmConfig__integrityProtAlgorithm integrity_algorithm;
  //uint8_t                            Status;
  //rnti_t                             rnti;
  //uint64_t                           random_ue_identity;
#if defined(ENABLE_ITTI)
  //UE_S_TMSI                          Initialue_identity_s_TMSI;
  //EstablishmentCause_t               establishment_cause;
  //ReestablishmentCause_t             reestablishment_cause;
  //uint16_t                           ue_initial_id;
  //uint32_t                           eNB_ue_s1ap_id :24;
  //security_capabilities_t            security_capabilities;
  //uint8_t                            nb_of_e_rabs;
  //e_rab_param_t                      e_rab[S1AP_MAX_E_RAB];
  //uint32_t                           enb_gtp_teid[S1AP_MAX_E_RAB];
  //transport_layer_addr_t             enb_gtp_addrs[S1AP_MAX_E_RAB];
  //rb_id_t                            enb_gtp_ebi[S1AP_MAX_E_RAB];
#endif
788
789
}

790
//-----------------------------------------------------------------------------
791
// should be called when UE is lost by eNB
792
void
793
rrc_eNB_free_UE(const module_id_t enb_mod_idP,const struct rrc_eNB_ue_context_s*        const ue_context_pP)
794
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
795
{
knopp's avatar
   
knopp committed
796

797

798
  protocol_ctxt_t                     ctxt;
799
800
#if !defined(ENABLE_USE_MME)
  module_id_t                         ue_module_id;
Cedric Roux's avatar
Cedric Roux committed
801
802
  /* avoid gcc warnings */
  (void)ue_module_id;
803
#endif
804
805
806
807
808
  rnti_t rnti = ue_context_pP->ue_context.rnti;


  AssertFatal(enb_mod_idP < NB_eNB_INST, "eNB inst invalid (%d/%d) for UE %x!", enb_mod_idP, NB_eNB_INST, rnti);
  /*  ue_context_p = rrc_eNB_get_ue_context(
809
810
811
                   &eNB_rrc_inst[enb_mod_idP],
                   rntiP
                 );
812
813
814
815
  */
  if (NULL != ue_context_pP) {
    PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, enb_mod_idP, ENB_FLAG_YES, rnti, 0, 0,enb_mod_idP);
    LOG_W(RRC, "[eNB %d] Removing UE RNTI %x\n", enb_mod_idP, rnti);
gauthier's avatar
gauthier committed
816
817

#if defined(ENABLE_USE_MME)
818
    rrc_eNB_send_S1AP_UE_CONTEXT_RELEASE_REQ(enb_mod_idP, ue_context_pP, S1AP_CAUSE_RADIO_NETWORK, 21); // send cause 21: connection with ue lost
819
820
821
822
823
824
    /* 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].
     */
825
#else
Florian Kaltenberger's avatar
Florian Kaltenberger committed
826
#if defined(OAI_EMU)
827
828
829
830
    AssertFatal(ue_context_pP->local_uid < NUMBER_OF_UE_MAX, "local_uid invalid (%d<%d) for UE %x!", ue_context_pP->local_uid, NUMBER_OF_UE_MAX, rnti);
    ue_module_id = oai_emulation.info.eNB_ue_local_uid_to_ue_module_id[enb_mod_idP][ue_context_pP->local_uid];
    AssertFatal(ue_module_id < NUMBER_OF_UE_MAX, "ue_module_id invalid (%d<%d) for UE %x!", ue_module_id, NUMBER_OF_UE_MAX, rnti);
    oai_emulation.info.eNB_ue_local_uid_to_ue_module_id[enb_mod_idP][ue_context_pP->local_uid] = -1;
831
    oai_emulation.info.eNB_ue_module_id_to_rnti[enb_mod_idP][ue_module_id] = NOT_A_RNTI;
Florian Kaltenberger's avatar
Florian Kaltenberger committed
832
#endif
gauthier's avatar
gauthier committed
833
#endif
834

835
    rrc_mac_remove_ue(enb_mod_idP,rnti);
836
837
    rrc_rlc_remove_ue(&ctxt);
    pdcp_remove_UE(&ctxt);
knopp's avatar
   
knopp committed
838

839
840
841
    rrc_eNB_remove_ue_context(
      &ctxt,
      &eNB_rrc_inst[enb_mod_idP],
842
      (struct rrc_eNB_ue_context_s*) ue_context_pP);
843
  }
844
845
}

846
847
848
849
//-----------------------------------------------------------------------------
void
rrc_eNB_process_RRCConnectionSetupComplete(
  const protocol_ctxt_t* const ctxt_pP,
850
  rrc_eNB_ue_context_t*         ue_context_pP,
851
852
  RRCConnectionSetupComplete_r8_IEs_t * rrcConnectionSetupComplete
)
853
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
854
{
855
  LOG_I(RRC,
856
        PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel UL-DCCH, " "processing RRCConnectionSetupComplete from UE (SRB1 Active)\n",
857
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
winckel's avatar
winckel committed
858

nikaeinn's avatar
nikaeinn committed
859
  ue_context_pP->ue_context.Srb1.Active=1;  
Cedric Roux's avatar
Cedric Roux committed
860
861
862
  T(T_ENB_RRC_CONNECTION_SETUP_COMPLETE, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

winckel's avatar
winckel committed
863
#if defined(ENABLE_USE_MME)
864
865
866

  if (EPC_MODE_ENABLED == 1) {
    // Forward message to S1AP layer
867
868
869
870
    rrc_eNB_send_S1AP_NAS_FIRST_REQ(
      ctxt_pP,
      ue_context_pP,
      rrcConnectionSetupComplete);
871
  } else
winckel's avatar
winckel committed
872
#endif
873
874
  {
    // RRC loop back (no S1AP), send SecurityModeCommand to UE
875
876
877
    rrc_eNB_generate_SecurityModeCommand(
      ctxt_pP,
      ue_context_pP);
878
879
    // rrc_eNB_generate_UECapabilityEnquiry(enb_mod_idP,frameP,ue_mod_idP);
  }
winckel's avatar
winckel committed
880
881
}

882
883
884
885
886
//-----------------------------------------------------------------------------
void
rrc_eNB_generate_SecurityModeCommand(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t*          const ue_context_pP
887
)
888
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
889
{
890
891
  uint8_t                             buffer[100];
  uint8_t                             size;
gauthier's avatar
   
gauthier committed
892

Cedric Roux's avatar
Cedric Roux committed
893
894
895
  T(T_ENB_RRC_SECURITY_MODE_COMMAND, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

896
897
898
899
900
901
  size = do_SecurityModeCommand(
           ctxt_pP,
           buffer,
           rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),
           ue_context_pP->ue_context.ciphering_algorithm,
           ue_context_pP->ue_context.integrity_algorithm);
gauthier's avatar
   
gauthier committed
902

903
#ifdef RRC_MSG_PRINT
904
905
906
  uint16_t i=0;
  LOG_F(RRC,"[MSG] RRC Security Mode Command\n");

907
  for (i = 0; i < size; i++) {
908
    LOG_F(RRC,"%02x ", ((uint8_t*)buffer)[i]);
909
  }
910
911

  LOG_F(RRC,"\n");
912
913
#endif

914
  LOG_I(RRC,
915
916
917
        PROTOCOL_RRC_CTXT_UE_FMT" Logical Channel DL-DCCH, Generate SecurityModeCommand (bytes %d)\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
        size);
gauthier's avatar
   
gauthier committed
918

919
  LOG_D(RRC,
920
921
922
923
924
        PROTOCOL_RRC_CTXT_UE_FMT" --- PDCP_DATA_REQ/%d Bytes (securityModeCommand to UE MUI %d) --->[PDCP][RB %02d]\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
        size,
        rrc_eNB_mui,
        DCCH);
gauthier's avatar
gauthier committed
925
926

  MSC_LOG_TX_MESSAGE(
927
928
929
930
931
932
933
934
935
    MSC_RRC_ENB,
    MSC_RRC_UE,
    buffer,
    size,
    MSC_AS_TIME_FMT" securityModeCommand UE %x MUI %d size %u",
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP->ue_context.rnti,
    rrc_eNB_mui,
    size);
gauthier's avatar
gauthier committed
936

937
938
939
940
941
942
943
944
  rrc_data_req(
	       ctxt_pP,
	       DCCH,
	       rrc_eNB_mui++,
	       SDU_CONFIRM_NO,
	       size,
	       buffer,
	       PDCP_TRANSMISSION_MODE_CONTROL);
945
946
947

}

948
949
950
951
952
953
954
//-----------------------------------------------------------------------------
void
rrc_eNB_generate_UECapabilityEnquiry(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t*          const ue_context_pP
)
//-----------------------------------------------------------------------------
955
{
956

957
958
  uint8_t                             buffer[100];
  uint8_t                             size;
959

Cedric Roux's avatar
Cedric Roux committed
960
961
962
  T(T_ENB_RRC_UE_CAPABILITY_ENQUIRY, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

963
964
965
966
  size = do_UECapabilityEnquiry(
           ctxt_pP,
           buffer,
           rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id));
winckel's avatar
winckel committed
967

968
  LOG_I(RRC,
969
970
971
        PROTOCOL_RRC_CTXT_UE_FMT" Logical Channel DL-DCCH, Generate UECapabilityEnquiry (bytes %d)\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
        size);
winckel's avatar
winckel committed
972

973
  LOG_D(RRC,
974
975
976
977
978
        PROTOCOL_RRC_CTXT_UE_FMT" --- PDCP_DATA_REQ/%d Bytes (UECapabilityEnquiry MUI %d) --->[PDCP][RB %02d]\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
        size,
        rrc_eNB_mui,
        DCCH);
gauthier's avatar
gauthier committed
979
980

  MSC_LOG_TX_MESSAGE(
981
982
983
984
985
986
987
988
989
    MSC_RRC_ENB,
    MSC_RRC_UE,
    buffer,
    size,
    MSC_AS_TIME_FMT" rrcUECapabilityEnquiry UE %x MUI %d size %u",
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP->ue_context.rnti,
    rrc_eNB_mui,
    size);
gauthier's avatar
gauthier committed
990

991
992
993
994
995
996
997
998
  rrc_data_req(
	       ctxt_pP,
	       DCCH,
	       rrc_eNB_mui++,
	       SDU_CONFIRM_NO,
	       size,
	       buffer,
	       PDCP_TRANSMISSION_MODE_CONTROL);
999
1000
1001

}

1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
//-----------------------------------------------------------------------------
void
rrc_eNB_generate_RRCConnectionReject(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t*          const ue_context_pP,
  const int                    CC_id
)
//-----------------------------------------------------------------------------
{
#ifdef RRC_MSG_PRINT
  int                                 cnt;
#endif

Cedric Roux's avatar
Cedric Roux committed
1015
1016
1017
  T(T_ENB_RRC_CONNECTION_REJECT, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

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
  eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].Srb0.Tx_buffer.payload_size =
    do_RRCConnectionReject(ctxt_pP->module_id,
                          (uint8_t*) eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].Srb0.Tx_buffer.Payload);

#ifdef RRC_MSG_PRINT
  LOG_F(RRC,"[MSG] RRCConnectionReject\n");

  for (cnt = 0; cnt < eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].Srb0.Tx_buffer.payload_size; cnt++) {
    LOG_F(RRC,"%02x ", ((uint8_t*)eNB_rrc_inst[ctxt_pP->module_id].Srb0.Tx_buffer.Payload)[cnt]);
  }

  LOG_F(RRC,"\n");
#endif

  MSC_LOG_TX_MESSAGE(
    MSC_RRC_ENB,
    MSC_RRC_UE,
    eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].Srb0.Tx_buffer.Header,
    eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].Srb0.Tx_buffer.payload_size,
    MSC_AS_TIME_FMT" RRCConnectionReject UE %x size %u",
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP == NULL ? -1 : ue_context_pP->ue_context.rnti,
    eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].Srb0.Tx_buffer.payload_size);

  LOG_I(RRC,
        PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel DL-CCCH, Generating RRCConnectionReject (bytes %d)\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
        eNB_rrc_inst[ctxt_pP