rrc_eNB.c 187 KB
Newer Older
1
/*******************************************************************************
2 3
    OpenAirInterface
    Copyright(c) 1999 - 2014 Eurecom
4

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


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

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
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
32
 * \author Navid Nikaein and  Raymond Knopp
33
 * \date 2011 - 2014
34 35
 * \version 1.0
 * \company Eurecom
36
 * \email: navid.nikaein@eurecom.fr and raymond.knopp@eurecom.fr
37
 */
Lionel Gauthier's avatar
Lionel 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
#include "rlc.h"
#include "SIMULATION/ETH_TRANSPORT/extern.h"
62 63 64
#include "rrc_eNB_UE_context.h"
#include "platform_types.h"
#include "msc.h"
65 66

//#ifdef Rel10
67
#include "MeasResults.h"
68 69 70
//#endif

#ifdef USER_MODE
Lionel Gauthier's avatar
 
Lionel Gauthier committed
71 72 73 74
#   include "RRC/NAS/nas_config.h"
#   include "RRC/NAS/rb_config.h"
#   include "OCG.h"
#   include "OCG_extern.h"
75 76
#endif

77
#if defined(ENABLE_SECURITY)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
78
#   include "UTIL/OSA/osa_defs.h"
79 80
#endif

81
#if defined(ENABLE_USE_MME)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
82
#   include "rrc_eNB_S1AP.h"
83
#   include "rrc_eNB_GTPV1U.h"
Lionel Gauthier's avatar
 
Lionel Gauthier committed
84 85 86 87
#   if defined(ENABLE_ITTI)
#   else
#      include "../../S1AP/s1ap_eNB.h"
#   endif
88 89
#endif

90 91 92
#include "pdcp.h"

#if defined(ENABLE_ITTI)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
93
#   include "intertask_interface.h"
94 95
#endif

Lionel Gauthier's avatar
Lionel Gauthier committed
96
#ifdef ENABLE_RAL
Lionel Gauthier's avatar
 
Lionel Gauthier committed
97
#   include "rrc_eNB_ral.h"
Lionel Gauthier's avatar
Lionel Gauthier committed
98 99
#endif

100 101
#include "SIMULATION/TOOLS/defs.h" // for taus

102 103 104
//#define XER_PRINT

#ifdef PHY_EMUL
Lionel Gauthier's avatar
 
Lionel Gauthier committed
105
extern EMULATION_VARS              *Emul_vars;
106
#endif
Lionel Gauthier's avatar
 
Lionel Gauthier committed
107 108
extern eNB_MAC_INST                *eNB_mac_inst;
extern UE_MAC_INST                 *UE_mac_inst;
109
#ifdef BIGPHYSAREA
110
extern void*                        bigphys_malloc(int);
111 112
#endif

Lionel Gauthier's avatar
 
Lionel Gauthier committed
113
extern uint16_t                     two_tier_hexagonal_cellIds[7];
winckel's avatar
RRC:  
winckel committed
114

115
/* TS 36.331: RRC-TransactionIdentifier ::= INTEGER (0..3) */
Lionel Gauthier's avatar
 
Lionel Gauthier committed
116
static const uint8_t                RRC_TRANSACTION_IDENTIFIER_NUMBER = 4;
117

Lionel Gauthier's avatar
 
Lionel Gauthier committed
118
mui_t                               rrc_eNB_mui = 0;
winckel's avatar
RRC:  
winckel committed
119

120 121 122
//-----------------------------------------------------------------------------
static void
init_SI(
123 124
  const protocol_ctxt_t* const ctxt_pP,
  const int              CC_id
winckel's avatar
winckel committed
125
#if defined(ENABLE_ITTI)
126 127
  ,
  RrcConfigurationReq * configuration
winckel's avatar
winckel committed
128
#endif
129
)
130
//-----------------------------------------------------------------------------
131 132 133
{
  uint8_t                             SIwindowsize = 1;
  uint16_t                            SIperiod = 8;
134
#ifdef Rel10
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
  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);
   */
Lionel Gauthier's avatar
 
Lionel Gauthier committed
181

182 183 184
  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);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
185

186 187 188 189 190 191
  /*
     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);
   */
Lionel Gauthier's avatar
 
Lionel Gauthier committed
192

193 194
  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(
195
          ctxt_pP->module_id,
196
          CC_id,
197
          mac_xface->lte_frame_parms,
198 199 200
          (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
201
#if defined(ENABLE_ITTI)
202
          , configuration
winckel's avatar
winckel committed
203
#endif
204
        );
205
  else {
206 207
    LOG_E(RRC, PROTOCOL_RRC_CTXT_FMT" init_SI: FATAL, no memory for SIB1 allocated\n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
208 209 210 211 212 213 214 215 216
    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);
   */
217 218
  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");
219
  }
220

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

223 224
  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(
225
          ctxt_pP->module_id,
226
          CC_id,
227
          mac_xface->lte_frame_parms,
228 229 230 231
          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
232
#ifdef Rel10
233 234
          , &eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib13,
          eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].MBMS_flag
235 236
#endif
#if defined(ENABLE_ITTI)
237
          , configuration
Lionel Gauthier's avatar
 
Lionel Gauthier committed
238
#endif
239
        );
240 241

    /*
242 243 244 245
       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,
246 247 248 249 250
       #if defined(ENABLE_ITTI)
       , configuration
       #endif
       );
     */
251 252
    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");
253 254 255 256 257 258
    }

    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),
259 260
          eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
          pusch_ConfigBasic.n_SB);
261 262
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.hoppingMode = %ld\n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
263 264
          eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
          pusch_ConfigBasic.hoppingMode);
265 266
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.pusch_HoppingOffset = %ld\n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
267
          eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
268
          pusch_ConfigBasic.pusch_HoppingOffset);
269 270
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.enable64QAM = %d\n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
271
          (int)eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
272
          pusch_ConfigBasic.enable64QAM);
273 274
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.groupHoppingEnabled = %d\n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
275
          (int)eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
276
          ul_ReferenceSignalsPUSCH.groupHoppingEnabled);
277 278
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.groupAssignmentPUSCH = %ld\n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
279 280
          eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
          ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH);
281 282
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.sequenceHoppingEnabled = %d\n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
283 284
          (int)eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
          ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled);
285 286
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.cyclicShift  = %ld\n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
287 288
          eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
          ul_ReferenceSignalsPUSCH.cyclicShift);
289 290

#ifdef Rel10
291

292 293
    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++) {
294 295
        // 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);
296 297 298
        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" SIB13 contents for MBSFN subframe allocation %d/%d(partial)\n",
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
              i,
299
              eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->mbsfn_SubframeConfigList->list.count);
300 301
        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" mbsfn_Subframe_pattern is  = %x\n",
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
302
              eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->mbsfn_SubframeConfigList->list.array[i]->subframeAllocation.choice.oneFrame.buf[0] >> 0);
303 304
        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),
305
              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)
306 307
        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" radioframe_allocation_offset  = %ld\n",
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
308
              eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->mbsfn_SubframeConfigList->list.array[i]->radioframeAllocationOffset);
309 310 311
      }

      //   SIB13
312
      for (i = 0; i < eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib13->mbsfn_AreaInfoList_r9.list.count; i++) {
313 314 315
        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" SIB13 contents for MBSFN sync area %d/2 (partial)\n",
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
              i,
316
              eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib13->mbsfn_AreaInfoList_r9.list.count);
317 318
        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" MCCH Repetition Period: %d (just index number, not real value)\n",
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
319
              eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib13->mbsfn_AreaInfoList_r9.list.array[i]->mcch_Config_r9.mcch_RepetitionPeriod_r9);
320 321
        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" MCCH Offset: %d\n",
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
322
              eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib13->mbsfn_AreaInfoList_r9.list.array[i]->mcch_Config_r9.mcch_Offset_r9);
323 324 325
      }
    }

326 327
#endif

328
    LOG_D(RRC,
329 330
          PROTOCOL_RRC_CTXT_FMT" RRC_UE --- MAC_CONFIG_REQ (SIB1.tdd & SIB2 params) ---> MAC_UE\n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
331
    rrc_mac_config_req(ctxt_pP->module_id, CC_id, ENB_FLAG_YES, 0, 0,
332
                       (RadioResourceConfigCommonSIB_t *) &
333
                       eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->radioResourceConfigCommon,
334
                       (struct PhysicalConfigDedicated *)NULL,
335
#ifdef Rel10
336 337
                       (SCellToAddMod_r10_t *)NULL,
                       //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
338
#endif
339 340 341 342
                       (MeasObjectToAddMod_t **) NULL,
                       (MAC_MainConfig_t *) NULL, 0,
                       (struct LogicalChannelConfig *)NULL,
                       (MeasGapConfig_t *) NULL,
343
                       eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib1->tdd_Config,
344 345
                       NULL,
                       &SIwindowsize, &SIperiod,
346 347 348 349
                       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
350
#ifdef Rel10
351
                       ,
352 353
                       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,
354
                       (PMCH_InfoList_r9_t *) NULL
355 356
#endif
#ifdef CBA
357 358
                       , 0, //eNB_rrc_inst[ctxt_pP->module_id].num_active_cba_groups,
                       0    //eNB_rrc_inst[ctxt_pP->module_id].cba_rnti[0]
359
#endif
360 361
                      );
  } else {
362 363
    LOG_E(RRC, PROTOCOL_RRC_CTXT_FMT" init_SI: FATAL, no memory for SIB2/3 allocated\n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
364 365
    mac_xface->macphy_exit("[RRC][init_SI] FATAL, no memory for SIB2/3 allocated");
  }
366 367 368
}

#ifdef Rel10
winckel's avatar
winckel committed
369
/*------------------------------------------------------------------------------*/
370 371
static void
init_MCCH(
372 373
  module_id_t enb_mod_idP,
  int CC_id
374 375
)
//-----------------------------------------------------------------------------
376
{
Lionel Gauthier's avatar
 
Lionel Gauthier committed
377

378 379
  int                                 sync_area = 0;
  // initialize RRC_eNB_INST MCCH entry
380
  eNB_rrc_inst[enb_mod_idP].carrier[CC_id].MCCH_MESSAGE =
381
    malloc(eNB_rrc_inst[enb_mod_idP].carrier[CC_id].num_mbsfn_sync_area * sizeof(uint8_t*));
Lionel Gauthier's avatar
 
Lionel Gauthier committed
382

383
  for (sync_area = 0; sync_area < eNB_rrc_inst[enb_mod_idP].carrier[CC_id].num_mbsfn_sync_area; sync_area++) {
Lionel Gauthier's avatar
 
Lionel Gauthier committed
384

385 386
    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);
387

388
    if (eNB_rrc_inst[enb_mod_idP].carrier[CC_id].MCCH_MESSAGE[sync_area] == NULL) {
389 390 391
      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 {
392
      eNB_rrc_inst[enb_mod_idP].carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] = do_MBSFNAreaConfig(enb_mod_idP,
393
          mac_xface->lte_frame_parms,
394 395 396 397 398 399 400
          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],
401 402 403
            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,
404
            eNB_rrc_inst[enb_mod_idP].carrier[CC_id].mcch_message->commonSF_AllocPeriod_r9);
405 406
      LOG_D(RRC,
            "[eNB %d] CommonSF_Alloc_r9.list.count (number of MBSFN Subframe Pattern) %d\n",
407
            enb_mod_idP, eNB_rrc_inst[enb_mod_idP].carrier[CC_id].mcch_message->commonSF_Alloc_r9.list.count);
408 409
      LOG_D(RRC, "[eNB %d] MBSFN Subframe Pattern: %02x (in hex)\n",
            enb_mod_idP,
410
            eNB_rrc_inst[enb_mod_idP].carrier[CC_id].mcch_message->commonSF_Alloc_r9.list.array[0]->subframeAllocation.
411 412
            choice.oneFrame.buf[0]);

413 414
      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");
415
      } else {
416
        eNB_rrc_inst[enb_mod_idP].carrier[CC_id].MCCH_MESS[sync_area].Active = 1;
417
      }
418
    }
419
  }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
420

421
  //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)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
422

423 424 425 426 427
  // ??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]);
428
  rrc_mac_config_req(enb_mod_idP, CC_id, ENB_FLAG_YES, 0, 0,
429 430
                     (RadioResourceConfigCommonSIB_t *) NULL,
                     (struct PhysicalConfigDedicated *)NULL,
431
#ifdef Rel10
432 433 434 435 436 437 438 439 440 441
                     (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
Lionel Gauthier's avatar
 
Lionel Gauthier committed
442
#   ifdef Rel10
443 444 445
                     ,
                     0,
                     (MBSFN_AreaInfoList_r9_t *) NULL,
446
                     (PMCH_InfoList_r9_t *) & (eNB_rrc_inst[enb_mod_idP].carrier[CC_id].mcch_message->pmch_InfoList_r9)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
447 448
#   endif
#   ifdef CBA
449
                     , 0, 0
Lionel Gauthier's avatar
 
Lionel Gauthier committed
450
#   endif
451
                    );
452

453
  //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);
454

455 456
}

457
//-----------------------------------------------------------------------------
Lionel Gauthier's avatar
 
Lionel Gauthier committed
458
static void init_MBMS(
459
  module_id_t enb_mod_idP,
460
  int         CC_id,
461 462 463
  frame_t frameP
)
//-----------------------------------------------------------------------------
464 465 466
{
  // init the configuration for MTCH
  protocol_ctxt_t               ctxt;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
467

468
  if (eNB_rrc_inst[enb_mod_idP].carrier[CC_id].MBMS_flag > 0) {
469
    PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, enb_mod_idP, ENB_FLAG_YES, NOT_A_RNTI, frameP, 0,enb_mod_idP);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
470

471 472
    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
Lionel Gauthier's avatar
 
Lionel Gauthier committed
473

474 475 476 477 478 479 480 481
    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
Lionel Gauthier's avatar
 
Lionel Gauthier committed
482
#   ifdef Rel10
483
                             , &(eNB_rrc_inst[enb_mod_idP].carrier[CC_id].mcch_message->pmch_InfoList_r9)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
484
#   endif
485
                            );
Lionel Gauthier's avatar
 
Lionel Gauthier committed
486

487 488 489 490
    rrc_rlc_config_asn1_req(&ctxt,
                            NULL, // SRB_ToAddModList
                            NULL,   // DRB_ToAddModList
                            NULL,   // DRB_ToReleaseList
491
                            &(eNB_rrc_inst[enb_mod_idP].carrier[CC_id].mcch_message->pmch_InfoList_r9));
Lionel Gauthier's avatar
 
Lionel Gauthier committed
492

493 494
    //rrc_mac_config_req();
  }
495 496 497
}
#endif

498 499 500 501 502 503
//-----------------------------------------------------------------------------
uint8_t
rrc_eNB_get_next_transaction_identifier(
  module_id_t enb_mod_idP
)
//-----------------------------------------------------------------------------
504
{
505 506 507 508 509 510 511
  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;
  return rrc_transaction_identifier[enb_mod_idP];
}
/*------------------------------------------------------------------------------*/
/* Functions to handle UE index in eNB UE list */

winckel's avatar
winckel committed
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 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567
////-----------------------------------------------------------------------------
//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);
//}


//-----------------------------------------------------------------------------
// 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,
              PROTOCOL_RRC_CTXT_UE_FMT" Cannot create new UE context, already exist rand UE id 0x%x, uid %u\n",
              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
568

569 570 571 572 573
    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;
574
    }
575

576 577 578 579 580 581 582 583 584
    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
585

586 587 588 589 590 591
  } 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
592 593
}

594 595 596 597 598 599 600 601
#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)
602
{
603 604
  module_id_t                         enb_module_id;
  struct rrc_eNB_ue_context_s*        ue_context_p = NULL;
605
  int                                 CC_id;
606 607 608

  // find enb_module_id
  for (enb_module_id = 0; enb_module_id < NUMBER_OF_eNB_MAX; enb_module_id++) {
609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625
    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)
        ) {
          oai_emulation.info.eNB_ue_module_id_to_rnti[enb_module_id][ue_module_idP] = rntiP;
          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
626

627 628
          return;
        }
629 630 631
      }
    }
  }
winckel's avatar
winckel committed
632

633 634 635 636 637
  AssertFatal(enb_module_id == NUMBER_OF_eNB_MAX,
              "Cell identity not found for ue module id %u rnti %x",
              ue_module_idP, rntiP);
}
#endif
638

639 640 641 642 643
//-----------------------------------------------------------------------------
void
rrc_eNB_free_mem_UE_context(
  const protocol_ctxt_t*               const ctxt_pP,
  struct rrc_eNB_ue_context_s*         const ue_context_pP
644
)
645
//-----------------------------------------------------------------------------
Lionel Gauthier's avatar
Lionel Gauthier committed
646
{
647 648 649 650 651 652 653 654 655 656 657 658 659 660
  int i;
  LOG_T(RRC,
        PROTOCOL_RRC_CTXT_UE_FMT" Clearing UE context 0x%x (free internal structs)\n",
        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;
  }
661

662 663 664 665
  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;
  }
666

667
  memset(ue_context_pP->ue_context.DRB_active, 0, sizeof(ue_context_pP->ue_context.DRB_active));
668

669 670 671
  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;
672 673
  }

674 675 676
  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;
677 678
  }

679 680 681 682 683
  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;
    }
684
  }
685

686 687 688 689 690 691
  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;
    }
  }
692

693 694 695 696
  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;
  }
697

698 699 700 701
  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;
  }
702

703 704 705 706
  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;
  }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
707

708 709 710 711 712 713 714
  //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;
715
  }
716

717 718 719
  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;
720
  }
721

722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743
  //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
744 745
}

746 747
//-----------------------------------------------------------------------------
// called by MAC layer only
748
void
749 750 751 752 753
rrc_eNB_free_UE(
  const module_id_t enb_mod_idP,
  const rnti_t      rntiP,
  const frame_t     frameP,
  const sub_frame_t subframeP
754
)
755
//-----------------------------------------------------------------------------
Lionel Gauthier's avatar
Lionel Gauthier committed
756
{
Raymond Knopp's avatar
 
Raymond Knopp committed
757

758
  struct rrc_eNB_ue_context_s*        ue_context_p = NULL;
759
  protocol_ctxt_t                     ctxt;
760 761 762 763 764 765 766 767
#if !defined(ENABLE_USE_MME)
  module_id_t                         ue_module_id;
#endif
  AssertFatal(enb_mod_idP < NB_eNB_INST, "eNB inst invalid (%d/%d) for UE %x!", enb_mod_idP, NB_eNB_INST, rntiP);
  ue_context_p = rrc_eNB_get_ue_context(
                   &eNB_rrc_inst[enb_mod_idP],
                   rntiP
                 );
768

769
  if (NULL != ue_context_p) {
770
    PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, enb_mod_idP, ENB_FLAG_YES, rntiP, frameP, subframeP,enb_mod_idP);
771
    LOG_W(RRC, "[eNB %d] Removing UE RNTI %x\n", enb_mod_idP, rntiP);
Lionel Gauthier's avatar
Lionel Gauthier committed
772 773

#if defined(ENABLE_USE_MME)
774
    rrc_eNB_send_S1AP_UE_CONTEXT_RELEASE_REQ(enb_mod_idP, ue_context_p, S1AP_CAUSE_RADIO_NETWORK, 21); // send cause 21: connection with ue lost
775 776 777 778 779 780
    /* 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].
     */
781
#else
782
#if defined(OAI_EMU)
783 784 785 786 787
    AssertFatal(ue_context_p->local_uid < NUMBER_OF_UE_MAX, "local_uid invalid (%d<%d) for UE %x!", ue_context_p->local_uid, NUMBER_OF_UE_MAX, rntiP);
    ue_module_id = oai_emulation.info.eNB_ue_local_uid_to_ue_module_id[enb_mod_idP][ue_context_p->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, rntiP);
    oai_emulation.info.eNB_ue_local_uid_to_ue_module_id[enb_mod_idP][ue_context_p->local_uid] = -1;
    oai_emulation.info.eNB_ue_module_id_to_rnti[enb_mod_idP][ue_module_id] = NOT_A_RNTI;
788
#endif
Lionel Gauthier's avatar
Lionel Gauthier committed
789
#endif
790
    ue_context_p->ue_context.Status = RRC_IDLE;
791

792 793
    rrc_rlc_remove_ue(&ctxt);
    pdcp_remove_UE(&ctxt);
Raymond Knopp's avatar
 
Raymond Knopp committed
794

795 796 797 798 799
    rrc_eNB_remove_ue_context(
      &ctxt,
      &eNB_rrc_inst[enb_mod_idP],
      ue_context_p);
  }
800 801
}

802 803 804 805 806
//-----------------------------------------------------------------------------
void
rrc_eNB_process_RRCConnectionSetupComplete(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t*          const ue_context_pP,
807 808
  RRCConnectionSetupComplete_r8_IEs_t * rrcConnectionSetupComplete
)
809
//-----------------------------------------------------------------------------
Lionel Gauthier's avatar
Lionel Gauthier committed
810
{
811
  LOG_I(RRC,
812 813
        PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel UL-DCCH, " "processing RRCConnectionSetupComplete from UE\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
winckel's avatar
winckel committed
814 815

#if defined(ENABLE_USE_MME)
816 817 818

  if (EPC_MODE_ENABLED == 1) {
    // Forward message to S1AP layer
819 820 821 822
    rrc_eNB_send_S1AP_NAS_FIRST_REQ(
      ctxt_pP,
      ue_context_pP,
      rrcConnectionSetupComplete);
823
  } else
winckel's avatar
winckel committed
824
#endif
825 826
  {
    // RRC loop back (no S1AP), send SecurityModeCommand to UE
827 828 829
    rrc_eNB_generate_SecurityModeCommand(
      ctxt_pP,
      ue_context_pP);
830 831
    // rrc_eNB_generate_UECapabilityEnquiry(enb_mod_idP,frameP,ue_mod_idP);
  }
winckel's avatar
winckel committed
832 833
}

834 835 836 837 838
//-----------------------------------------------------------------------------
void
rrc_eNB_generate_SecurityModeCommand(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t*          const ue_context_pP
839
)
840
//-----------------------------------------------------------------------------
Lionel Gauthier's avatar
Lionel Gauthier committed
841
{
842 843
  uint8_t                             buffer[100];
  uint8_t                             size;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
844

845 846 847 848 849 850
  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);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
851

852
#ifdef RRC_MSG_PRINT
853 854 855
  uint16_t i=0;
  LOG_F(RRC,"[MSG] RRC Security Mode Command\n");

856
  for (i = 0; i < size; i++) {
857
    LOG_F(RRC,"%02x ", ((uint8_t*)buffer)[i]);
858
  }
859 860

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

863
  LOG_I(RRC,
864 865 866
        PROTOCOL_RRC_CTXT_UE_FMT" Logical Channel DL-DCCH, Generate SecurityModeCommand (bytes %d)\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
        size);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
867

868
  LOG_D(RRC,
869 870 871 872 873
        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);
874 875

  MSC_LOG_TX_MESSAGE(
876 877 878 879 880 881 882 883 884
    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);
885

886 887 888 889 890 891 892 893
  pdcp_rrc_data_req(
    ctxt_pP,
    DCCH,
    rrc_eNB_mui++,
    SDU_CONFIRM_NO,
    size,
    buffer,
    PDCP_TRANSMISSION_MODE_CONTROL);
894 895 896

}

897 898 899 900 901 902 903
//-----------------------------------------------------------------------------
void
rrc_eNB_generate_UECapabilityEnquiry(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t*          const ue_context_pP
)
//-----------------------------------------------------------------------------
904
{
905

906 907
  uint8_t                             buffer[100];
  uint8_t                             size;
908

909 910 911 912
  size = do_UECapabilityEnquiry(
           ctxt_pP,
           buffer,
           rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id));
winckel's avatar
winckel committed
913

914
  LOG_I(RRC,
915 916 917
        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
918

919
  LOG_D(RRC,
920 921 922 923 924
        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);
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" rrcUECapabilityEnquiry UE %x MUI %d size %u",
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP->ue_context.rnti,
    rrc_eNB_mui,
    size);
936

937 938 939 940 941 942 943 944
  pdcp_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_RRCConnectionRelease(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t*          const ue_context_pP
)
//-----------------------------------------------------------------------------
955
{
Raymond Knopp's avatar
 
Raymond Knopp committed
956

957 958
  uint8_t                             buffer[RRC_BUF_SIZE];
  uint16_t                            size;
Raymond Knopp's avatar
 
Raymond Knopp committed
959

960
  memset(buffer, 0, RRC_BUF_SIZE);
Raymond Knopp's avatar
 
Raymond Knopp committed
961

962
  size = do_RRCConnectionRelease(ctxt_pP->module_id, buffer,rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id));
Raymond Knopp's avatar
 
Raymond Knopp committed
963

964
  LOG_I(RRC,
965 966 967
        PROTOCOL_RRC_CTXT_UE_FMT" Logical Channel DL-DCCH, Generate RRCConnectionRelease (bytes %d)\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
        size);
Raymond Knopp's avatar
 
Raymond Knopp committed
968

969
  LOG_D(RRC,
970 971 972 973 974
        PROTOCOL_RRC_CTXT_UE_FMT" --- PDCP_DATA_REQ/%d Bytes (rrcConnectionRelease MUI %d) --->[PDCP][RB %u]\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
        size,
        rrc_eNB_mui,
        DCCH);
975 976

  MSC_LOG_TX_MESSAGE(
977 978 979 980 981 982 983 984 985
    MSC_RRC_ENB,
    MSC_RRC_UE,
    buffer,
    size,
    MSC_AS_TIME_FMT" rrcConnectionRelease UE %x MUI %d size %u",
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP->ue_context.rnti,
    rrc_eNB_mui,
    size);
986

987 988 989 990 991 992 993 994
  pdcp_rrc_data_req(
    ctxt_pP,
    DCCH,
    rrc_eNB_mui++,
    SDU_CONFIRM_NO,
    size,
    buffer,
    PDCP_TRANSMISSION_MODE_CONTROL);
Raymond Knopp's avatar
 
Raymond Knopp committed
995
}
996

997 998 999 1000 1001 1002 1003 1004
//-----------------------------------------------------------------------------
void
rrc_eNB_generate_defaultRRCConnectionReconfiguration(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t*          const ue_context_pP,
  const uint8_t                ho_state
)
//-----------------------------------------------------------------------------
1005 1006 1007 1008 1009 1010
{
  uint8_t                             buffer[RRC_BUF_SIZE];
  uint16_t                            size;
  int                                 i;

  // configure SRB1/SRB2, PhysicalConfigDedicated, MAC_MainConfig for UE
1011 1012
  eNB_RRC_INST*                       rrc_inst = &eNB_rrc_inst[ctxt_pP->module_id];
  struct PhysicalConfigDedicated**    physicalConfigDedicated = &ue_context_pP->ue_context.physicalConfigDedicated;
1013 1014 1015 1016 1017 1018

  struct SRB_ToAddMod                *SRB2_config                      = NULL;
  struct SRB_ToAddMod__rlc_Config    *SRB2_rlc_config                  = NULL;
  struct SRB_ToAddMod__logicalChannelConfig *SRB2_lchan_config         = NULL;
  struct LogicalChannelConfig__ul_SpecificParameters
      *SRB2_ul_SpecificParameters       = NULL;
1019
  SRB_ToAddModList_t*                 SRB_configList = ue_context_pP->ue_context.SRB_configList;
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029
  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;
  struct LogicalChannelConfig__ul_SpecificParameters
      *DRB_ul_SpecificParameters        = NULL;
1030
  DRB_ToAddModList_t**                DRB_configList = &ue_context_pP->ue_context.DRB_configList;
1031 1032 1033 1034 1035 1036 1037 1038 1039

  MAC_MainConfig_t                   *mac_MainConfig                   = NULL;
  MeasObjectToAddModList_t           *MeasObj_list                     = NULL;
  MeasObjectToAddMod_t               *MeasObj                          = NULL;
  ReportConfigToAddModList_t         *ReportConfig_list                = NULL;
  ReportConfigToAddMod_t             *ReportConfig_per, *ReportConfig_A1,
                                     *ReportConfig_A2, *ReportConfig_A3, *ReportConfig_A4, *ReportConfig_A5;
  MeasIdToAddModList_t               *MeasId_list                      = NULL;
  MeasIdToAddMod_t                   *MeasId0, *MeasId1, *MeasId2, *MeasId3, *MeasId4, *MeasId5;
winckel's avatar
winckel committed
1040
#if Rel10
1041 1042 1043
  long                               *sr_ProhibitTimer_r9              = NULL;
  //     uint8_t sCellIndexToAdd = rrc_find_free_SCell_index(enb_mod_idP, ue_mod_idP, 1);
  uint8_t                            sCellIndexToAdd = 0;
winckel's avatar
winckel committed
1044
#endif
1045

1046 1047
  long                               *logicalchannelgroup, *logicalchannelgroup_drb;
  long                               *maxHARQ_Tx, *periodicBSR_Timer;
1048

1049 1050 1051 1052 1053 1054 1055
  RSRP_Range_t                       *rsrp                             = NULL;
  struct MeasConfig__speedStatePars  *Sparams                          = NULL;
  QuantityConfig_t                   *quantityConfig                   = NULL;
  CellsToAddMod_t                    *CellToAdd                        = NULL;
  CellsToAddModList_t                *CellsToAddModList                = NULL;
  struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList = NULL;
  DedicatedInfoNAS_t                 *dedicatedInfoNas                 = NULL;
1056

1057
  C_RNTI_t                           *cba_RNTI                         = NULL;
1058
#ifdef CBA
1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080
  //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);
  }
1081

1082
#endif
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
  // 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_ms35;
  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
  //*DRB_configList = CALLOC(1, sizeof(*DRB_configList));
  *DRB_configList = CALLOC(1, sizeof(**DRB_configList));
  /// DRB
  DRB_config = CALLOC(1, sizeof(*DRB_config));

  DRB_config->eps_BearerIdentity = CALLOC(1, sizeof(long));
  *(DRB_config->eps_BearerIdentity) = 5L; // LW set to first value, allowed value 5..15, value : x+4
  // 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
  DRB_config->drb_Identity = (DRB_Identity_t) 1;  // (ue_mod_idP+1); //allowed values 1..32, value: x
  DRB_config->logicalChannelIdentity = CALLOC(1, sizeof(long));
  *(DRB_config->logicalChannelIdentity) = (long)3; // value : x+2
  DRB_rlc_config = CALLOC(1, sizeof(*DRB_rlc_config));
  DRB_config->rlc_Config = DRB_rlc_config;
winckel's avatar
winckel committed
1141

1142
#ifdef RRC_DEFAULT_RAB_IS_AM
1143 1144 1145 1146 1147 1148 1149
  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;
1150
#else
1151 1152 1153
  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;
1154
#ifdef CBA
1155
  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering   = T_Reordering_ms5;//T_Reordering_ms25;
1156 1157 1158
#else
  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering = T_Reordering_ms35;
#endif
1159
#endif
1160

1161 1162 1163 1164 1165 1166
  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;
1167

1168
#ifdef RRC_DEFAULT_RAB_IS_AM // EXMIMO_IOT
1169 1170 1171
  PDCP_rlc_AM = CALLOC(1, sizeof(*PDCP_rlc_AM));
  DRB_pdcp_config->rlc_AM = PDCP_rlc_AM;
  PDCP_rlc_AM->statusReportRequired = FALSE;
1172
#else
1173 1174 1175
  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;
1176
#endif
1177
  DRB_pdcp_config->headerCompression.present = PDCP_Config__headerCompression_PR_notUsed;
1178

1179 1180 1181 1182
  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;
1183

1184 1185 1186 1187 1188
  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;
1189

1190 1191 1192 1193
  // 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
1194

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

1197
  mac_MainConfig = CALLOC(1, sizeof(*mac_MainConfig));
1198
  ue_context_pP->ue_context.mac_MainConfig = mac_MainConfig;
winckel's avatar
RRC:  
winckel committed
1199

1200
  mac_MainConfig->ul_SCH_Config = CALLOC(1, sizeof(*mac_MainConfig->ul_SCH_Config));
1201

1202 1203 1204 1205 1206 1207 1208 1209
  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
1210

1211
  mac_MainConfig->timeAlignmentTimerDedicated = TimeAlignmentTimer_infinity;
1212

1213
  mac_MainConfig->drx_Config = NULL;
winckel's avatar
winckel committed
1214

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

1217 1218
  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
1219

1220
  mac_MainConfig->phr_Config->choice.setup.prohibitPHR_Timer = MAC_MainConfig__phr_Config__setup__prohibitPHR_Timer_sf20; // sf20 = 20 subframes
1221

1222
  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
1223

winckel's avatar
winckel committed
1224
#ifdef Rel10
1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302
  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;
  MeasObj->measObject.choice.measObjectEUTRA.carrierFreq = 3350; //band 7, 2.68GHz
  //MeasObj->measObject.choice.measObjectEUTRA.carrierFreq = 36090; //band 33, 1.909GHz
  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;
1303
    CellToAdd->physCellId = get_adjacent_cell_id(ctxt_pP->module_id, i);
1304 1305 1306 1307
    CellToAdd->cellIndividualOffset = Q_OffsetRange_dB0;

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

1309 1310
  ASN_SEQUENCE_ADD(&MeasObj_list->list, MeasObj);
  //  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->measObjectToAddModList = MeasObj_list;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1311

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

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

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

1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360
  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 */ ) {
1361 1362
    LOG_I(RRC, "[eNB %d] frame %d: requesting A2, A3, A4, A5, and A6 event reporting\n",
          ctxt_pP->module_id, ctxt_pP->frame);
1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478
    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; // FIXME ...hysteresis is of type long!
    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",
1479
          ctxt_pP->module_id, ctxt_pP->frame);
1480 1481
    // store the information in an intermediate structure for Hanodver management
    //rrc_inst->handover_info.as_config.sourceRadioResourceConfig.srb_ToAddModList = CALLOC(1,sizeof());
1482
    ue_context_pP->ue_context.handover_info = CALLOC(1, sizeof(*(ue_context_pP->ue_context.handover_info)));
1483
    //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.srb_ToAddModList,(void *)SRB_list,sizeof(SRB_ToAddModList_t));
1484
    ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.srb_ToAddModList = SRB_configList2;
1485
    //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.drb_ToAddModList,(void *)DRB_list,sizeof(DRB_ToAddModList_t));
1486 1487 1488 1489 1490
    ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.drb_ToAddModList = *DRB_configList;
    ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.drb_ToReleaseList = NULL;
    ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig =
      CALLOC(1, sizeof(*ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig));
    memcpy((void*)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig,
1491
           (void *)mac_MainConfig, sizeof(MAC_MainConfig_t));
1492
    ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.physicalConfigDedicated =
1493
      CALLOC(1, sizeof(PhysicalConfigDedicated_t));
1494 1495 1496
    memcpy((void*)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.physicalConfigDedicated,
           (void*)ue_context_pP->ue_context.physicalConfigDedicated, sizeof(PhysicalConfigDedicated_t));
    ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.sps_Config = NULL;
1497 1498 1499 1500 1501 1502 1503 1504 1505
    //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));

  }

#if defined(ENABLE_ITTI)
  /* Initialize NAS list */
  dedicatedInfoNASList = CALLOC(1, sizeof(struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList));

  /* Add all NAS PDUs to the list */
1506 1507
  for (i = 0; i < ue_context_pP->ue_context.nb_of_e_rabs; i++) {
    if (ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer != NULL) {
1508 1509
      dedicatedInfoNas = CALLOC(1, sizeof(DedicatedInfoNAS_t));
      memset(dedicatedInfoNas, 0, sizeof(OCTET_STRING_t));
1510 1511
      OCTET_STRING_fromBuf(dedicatedInfoNas, (char*)ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer,
                           ue_context_pP->ue_context.e_rab[i].param.nas_pdu.length);
1512
      ASN_SEQUENCE_ADD(&dedicatedInfoNASList->list, dedicatedInfoNas);
1513
    }
1514

1515 1516
    /* TODO parameters yet to process ... */
    {
1517 1518 1519
      //      ue_context_pP->ue_context.e_rab[i].param.qos;
      //      ue_context_pP->ue_context.e_rab[i].param.sgw_addr;
      //      ue_context_pP->ue_context.e_rab[i].param.gtp_teid;
1520
    }
1521 1522

    /* TODO should test if e RAB are Ok before! */
1523
    ue_context_pP->ue_context.e_rab[i].status = E_RAB_STATUS_DONE;
1524 1525 1526 1527 1528 1529 1530 1531
  }

  /* If list is empty free the list and reset the address */
  if (dedicatedInfoNASList->list.count == 0) {
    free(dedicatedInfoNASList);
    dedicatedInfoNASList = NULL;
  }

1532 1533
#endif

1534
  memset(buffer, 0, RRC_BUF_SIZE);
1535

1536 1537 1538 1539 1540 1541 1542
  size = do_RRCConnectionReconfiguration(ctxt_pP,
                                         buffer,
                                         rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),   //Transaction_id,
                                         (SRB_ToAddModList_t*)NULL, /// NN: do not reconfig srb1: SRB_configList2,
                                         (DRB_ToAddModList_t*)*DRB_configList,
                                         (DRB_ToReleaseList_t*)NULL,  // DRB2_list,
                                         (struct SPS_Config*)NULL,    // *sps_Config,
1543
#ifdef EXMIMO_IOT
1544
                                         NULL, NULL, NULL, NULL,NULL,
1545
#else
1546 1547 1548 1549 1550
                                         (struct PhysicalConfigDedicated*)*physicalConfigDedicated,
                                         (MeasObjectToAddModList_t*)MeasObj_list,
                                         (ReportConfigToAddModList_t*)ReportConfig_list,
                                         (QuantityConfig_t*)quantityConfig,
                                         (MeasIdToAddModList_t*)MeasId_list,
1551
#endif
1552 1553 1554 1555 1556 1557 1558
                                         (MAC_MainConfig_t*)mac_MainConfig,
                                         (MeasGapConfig_t*)NULL,
                                         (MobilityControlInfo_t*)NULL,
                                         (struct MeasConfig__speedStatePars*)Sparams,
                                         (RSRP_Range_t*)rsrp,
                                         (C_RNTI_t*)cba_RNTI,
                                         (struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList*)dedicatedInfoNASList
1559
#ifdef Rel10
1560
                                         , (SCellToAddMod_r10_t*)NULL
1561
#endif
1562
                                        );
1563

1564
#ifdef RRC_MSG_PRINT
1565 1566
  LOG_F(RRC,"[MSG] RRC Connection Reconfiguration\n");

1567
  for (i = 0; i < size; i++) {
1568
    LOG_F(RRC,"%02x ", ((uint8_t*)buffer)[i]);
1569
  }
1570

1571 1572 1573 1574
  LOG_F(RRC,"\n");
  ////////////////////////////////////////
#endif

1575
#if defined(ENABLE_ITTI)
1576 1577

  /* Free all NAS PDUs */
1578 1579
  for (i = 0; i < ue_context_pP->ue_context.nb_of_e_rabs; i++) {
    if (ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer != NULL) {
1580
      /* Free the NAS PDU buffer and invalidate it */
1581 1582
      free(ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer);
      ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer = NULL;
1583
    }
1584 1585
  }

1586
#endif
1587

1588
  LOG_I(RRC,
1589 1590
        "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate RRCConnectionReconfiguration (bytes %d, UE id %x)\n",
        ctxt_pP->module_id, ctxt_pP->frame, size, ue_context_pP->ue_context.rnti);
1591

1592
  LOG_D(RRC,
1593 1594
        "[FRAME %05d][RRC_eNB][MOD %u][][--- PDCP_DATA_REQ/%d Bytes (rrcConnectionReconfiguration to UE %x MUI %d) --->][PDCP][MOD %u][RB %u]\n",
        ctxt_pP->frame, ctxt_pP->module_id, size, ue_context_pP->ue_context.rnti, rrc_eNB_mui, ctxt_pP->module_id, DCCH);
1595 1596

  MSC_LOG_TX_MESSAGE(
1597 1598 1599 1600 1601 1602 1603 1604 1605
    MSC_RRC_ENB,
    MSC_RRC_UE,
    buffer,
    size,
    MSC_AS_TIME_FMT" rrcConnectionReconfiguration UE %x MUI %d size %u",
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP->ue_context.rnti,
    rrc_eNB_mui,
    size);
1606

1607 1608 1609 1610 1611 1612 1613 1614
  pdcp_rrc_data_req(
    ctxt_pP,
    DCCH,
    rrc_eNB_mui++,
    SDU_CONFIRM_NO,
    size,
    buffer,
    PDCP_TRANSMISSION_MODE_CONTROL);
winckel's avatar
winckel committed
1615
}
1616

1617 1618


1619 1620 1621 1622 1623 1624 1625 1626
//-----------------------------------------------------------------------------
int
rrc_eNB_generate_RRCConnectionReconfiguration_SCell(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t* const ue_context_pP,
  uint32_t dl_CarrierFreq_r10
)
//-----------------------------------------------------------------------------
1627
{
1628 1629 1630

  uint8_t size;
  uint8_t buffer[100];
1631

1632 1633
#ifdef Rel10
  uint8_t sCellIndexToAdd = 0; //one SCell so far
1634 1635 1636 1637

  //   uint8_t sCellIndexToAdd;
  //   sCellIndexToAdd = rrc_find_free_SCell_index(enb_mod_idP, ue_mod_idP, 1);
  //  if (eNB_rrc_inst[enb_mod_idP].sCell_config[ue_mod_idP][sCellIndexToAdd] ) {
1638 1639
  if (ue_context_pP->ue_context.sCell_config != NULL) {
    ue_context_pP->ue_context.sCell_config[sCellIndexToAdd].cellIdentification_r10->dl_CarrierFreq_r10 = dl_CarrierFreq_r10;
1640
  } else {
1641 1642
    LOG_E(RRC,"Scell not configured!\n");
    return(-1);
1643 1644
  }

1645
#endif
1646
  size = do_RRCConnectionReconfiguration(ctxt_pP,
1647
                                         buffer,
1648
                                         rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),//Transaction_id,
1649 1650 1651 1652 1653 1654 1655
                                         (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,
1656
                                         (QuantityConfig_t*)NULL,
1657 1658 1659 1660 1661 1662 1663
                                         (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,
1664 1665 1666
                                         (struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList*)NULL

#ifdef Rel10
1667
                                         , ue_context_pP->ue_context.sCell_config
1668
#endif
1669
                                        );
1670 1671 1672
  LOG_I(RRC,"[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate RRCConnectionReconfiguration (bytes %d, UE id %x)\n",
        ctxt_pP->module_id,ctxt_pP->frame, size, ue_context_pP->ue_context.rnti);

1673
  MSC_LOG_TX_MESSAGE(
1674 1675 1676 1677 1678 1679 1680 1681 1682
    MSC_RRC_ENB,
    MSC_RRC_UE,
    buffer,
    size,
    MSC_AS_TIME_FMT" rrcConnectionReconfiguration UE %x MUI %d size %u",
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP->ue_context.rnti,
    rrc_eNB_mui,
    size);
1683

1684 1685 1686 1687 1688 1689 1690 1691
  pdcp_rrc_data_req(
    ctxt_pP,
    DCCH,
    rrc_eNB_mui++,
    SDU_CONFIRM_NO,
    size,
    buffer,
    PDCP_TRANSMISSION_MODE_CONTROL);
1692 1693 1694 1695
  return(0);
}


1696 1697 1698 1699 1700 1701 1702 1703
//-----------------------------------------------------------------------------
void
rrc_eNB_process_MeasurementReport(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t*          const ue_context_pP,
  const MeasResults_t*   const measResults2
)
//-----------------------------------------------------------------------------
1704 1705
{

1706 1707
  LOG_I(RRC, "[eNB %d] Frame %d: Process Measurement Report From UE %x (Measurement Id %d)\n",
        ctxt_pP->module_id, ctxt_pP->frame, ctxt_pP->rnti, (int)measResults2->measId);
1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719

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

1720
#ifdef Rel10
1721 1722
  LOG_I(RRC, "RSRP of Source %d\n", measResults2->measResultPCell.rsrpResult);
  LOG_I(RRC, "RSRQ of Source %d\n", measResults2->measResultPCell.rsrqResult);
winckel's avatar
winckel committed
1723
#else
1724 1725 1726 1727
  LOG_I(RRC, "RSRP of Source %d\n", measResults2->measResultServCell.rsrpResult);
  LOG_I(RRC, "RSRQ of Source %d\n", measResults2->measResultServCell.rsrqResult);
#endif

1728 1729 1730
  if (ue_context_pP->ue_context.handover_info->ho_prepare != 0xF0) {
    rrc_eNB_generate_HandoverPreparationInformation(ctxt_pP,
        ue_context_pP,
1731 1732 1733
        measResults2->measResultNeighCells->choice.
        measResultListEUTRA.list.array[0]->physCellId);
  } else {
1734 1735
    LOG_D(RRC, "[eNB %d] Frame %d: Ignoring MeasReport from UE %x as Handover is in progress... \n", ctxt_pP->module_id, ctxt_pP->frame,
          ctxt_pP->rnti);
1736
  }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1737

1738 1739 1740 1741
  //Look for IP address of the target eNB
  //Send Handover Request -> target eNB
  //Wait for Handover Acknowledgement <- target eNB
  //Send Handover Command
1742

1743 1744
  //x2delay();
  //    handover_request_x2(ue_mod_idP,enb_mod_idP,measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[0]->physCellId);
1745

1746 1747 1748 1749 1750
  //    uint8_t buffer[100];
  //    int size=rrc_eNB_generate_Handover_Command_TeNB(0,0,buffer);
  //
  //      send_check_message((char*)buffer,size);
  //send_handover_command();
1751

1752 1753
}

1754 1755 1756 1757 1758 1759 1760 1761
//-----------------------------------------------------------------------------
void
rrc_eNB_generate_HandoverPreparationInformation(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t* const ue_context_pP,
  PhysCellId_t                 targetPhyId
)
//-----------------------------------------------------------------------------
1762
{
1763 1764
  struct rrc_eNB_ue_context_s*        ue_context_target_p = NULL;
  //uint8_t                             UE_id_target        = -1;
1765 1766 1767 1768 1769 1770 1771 1772
  uint8_t                             mod_id_target = get_adjacent_cell_mod_id(targetPhyId);
  HANDOVER_INFO                      *handoverInfo = CALLOC(1, sizeof(*handoverInfo));
  /*
     uint8_t buffer[100];
     uint8_t size;
     struct PhysicalConfigDedicated  **physicalConfigDedicated = &eNB_rrc_inst[enb_mod_idP].physicalConfigDedicated[ue_mod_idP];
     RadioResourceConfigDedicated_t *radioResourceConfigDedicated = CALLOC(1,sizeof(RadioResourceConfigDedicated_t));
   */
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1773

1774 1775 1776 1777
  handoverInfo->as_config.antennaInfoCommon.antennaPortsCount = 0;    //Not used 0- but check value
  handoverInfo->as_config.sourceDl_CarrierFreq = 36090;   //Verify!

  memcpy((void *)&handoverInfo->as_config.sourceMasterInformationBlock,
1778
         (void*)&eNB_rrc_inst[ctxt_pP->module_id].carrier[0] /* CROUX TBC */.mib, sizeof(MasterInformationBlock_t));
1779
  memcpy((void *)&handoverInfo->as_config.sourceMeasConfig,
1780
         (void*)ue_context_pP->ue_context.measConfig, sizeof(MeasConfig_t));
1781 1782 1783 1784 1785 1786

  // FIXME handoverInfo not used...
  free( handoverInfo );
  handoverInfo = 0;

  //to be configured
1787
  memset((void*)&ue_context_pP->ue_context.handover_info->as_config.sourceSecurityAlgorithmConfig,
1788 1789
         0, sizeof(SecurityAlgorithmConfig_t));

1790
  memcpy((void*)&ue_context_pP->ue_context.handover_info->as_config.sourceSystemInformationBlockType1,
1791
         (void*)&eNB_rrc_inst[ctxt_pP->module_id].carrier[0] /* CROUX TBC */.SIB1, sizeof(SystemInformationBlockType1_t));
1792
  memcpy((void*)&ue_context_pP->ue_context.handover_info->as_config.sourceSystemInformationBlockType2,
1793
         (void*)&eNB_rrc_inst[ctxt_pP->module_id].carrier[0] /* CROUX TBC */.SIB23, sizeof(SystemInformationBlockType2_t));
1794
  ue_context_pP->ue_context.handover_info->as_context.reestablishmentInfo =
1795
    CALLOC(1, sizeof(ReestablishmentInfo_t));
1796
  ue_context_pP->ue_context.handover_info->as_context.reestablishmentInfo->sourcePhysCellId =
1797
    eNB_rrc_inst[ctxt_pP->module_id].carrier[0] /* CROUX TBC */.physCellId;
1798 1799 1800 1801 1802 1803
  ue_context_pP->ue_context.handover_info->as_context.reestablishmentInfo->targetCellShortMAC_I.buf = NULL;  // Check values later
  ue_context_pP->ue_context.handover_info->as_context.reestablishmentInfo->targetCellShortMAC_I.size = 0;
  ue_context_pP->ue_context.handover_info->as_context.reestablishmentInfo->targetCellShortMAC_I.bits_unused = 0;
  ue_context_pP->ue_context.handover_info->as_context.reestablishmentInfo->additionalReestabInfoList = NULL;
  ue_context_pP->ue_context.handover_info->ho_prepare = 0xFF;    //0xF0;
  ue_context_pP->ue_context.handover_info->ho_complete = 0;
1804 1805 1806

  if (mod_id_target != 0xFF) {
    //UE_id_target = rrc_find_free_ue_index(modid_target);
1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819
    ue_context_target_p =
      rrc_eNB_get_ue_context(
        &eNB_rrc_inst[mod_id_target],
        ue_context_pP->ue_context.rnti);

    /*UE_id_target = rrc_eNB_get_next_free_UE_index(
                    mod_id_target,
                    eNB_rrc_inst[ctxt_pP->module_id].Info.UE_list[ue_mod_idP]);  //this should return a new index*/

    if (ue_context_target_p == NULL) { // if not already in target cell
      ue_context_target_p = rrc_eNB_allocate_new_UE_context(&eNB_rrc_inst[ctxt_pP->module_id]);
      ue_context_target_p->ue_id_rnti      = ue_context_pP->ue_context.rnti;             // LG: should not be the same
      ue_context_target_p->ue_context.rnti = ue_context_target_p->ue_id_rnti; // idem
1820
      LOG_N(RRC,
1821 1822 1823
            "[eNB %d] Frame %d : Emulate sending HandoverPreparationInformation msg from eNB source %d to eNB target %d: source UE_id %x target UE_id %x source_modId: %d target_modId: %d\n",
            ctxt_pP->module_id,
            ctxt_pP->frame,
1824
            eNB_rrc_inst[ctxt_pP->module_id].carrier[0] /* CROUX TBC */.physCellId,
1825 1826 1827 1828
            targetPhyId,
            ue_context_pP->ue_context.rnti,
            ue_context_target_p->ue_id_rnti,
            ctxt_pP->module_id,
1829
            mod_id_target);
1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847
      ue_context_target_p->ue_context.handover_info =
        CALLOC(1, sizeof(*(ue_context_target_p->ue_context.handover_info)));
      memcpy((void*)&ue_context_target_p->ue_context.handover_info->as_context,
             (void*)&ue_context_pP->ue_context.handover_info->as_context,
             sizeof(AS_Context_t));
      memcpy((void*)&ue_context_target_p->ue_context.handover_info->as_config,
             (void*)&ue_context_pP->ue_context.handover_info->as_config,
             sizeof(AS_Config_t));
      ue_context_target_p->ue_context.handover_info->ho_prepare = 0x00;// 0xFF;
      ue_context_target_p->ue_context.handover_info->ho_complete = 0;
      ue_context_pP->ue_context.handover_info->modid_t = mod_id_target;
      ue_context_pP->ue_context.handover_info->ueid_s  = ue_context_pP->ue_context.rnti;
      ue_context_pP->ue_context.handover_info->modid_s = ctxt_pP->module_id;
      ue_context_target_p->ue_context.handover_info->modid_t = mod_id_target;
      ue_context_target_p->ue_context.handover_info->modid_s = ctxt_pP->module_id;
      ue_context_target_p->ue_context.handover_info->ueid_t  = ue_context_target_p->ue_context.rnti;

    } else {
1848
      LOG_E(RRC, "\nError in obtaining free UE id in target eNB %l for handover \n", targetPhyId);
1849 1850 1851
    }

  } else {
1852
    LOG_E(RRC, "\nError in obtaining Module ID of target eNB for handover \n");
1853
  }
1854 1855
}

1856 1857 1858 1859 1860 1861 1862
//-----------------------------------------------------------------------------
void
rrc_eNB_process_handoverPreparationInformation(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t*           const ue_context_pP
)
//-----------------------------------------------------------------------------
1863
{
1864

1865 1866
  LOG_I(RRC,
        "[eNB %d] Frame %d : Logical Channel UL-DCCH, processing RRCHandoverPreparationInformation, sending RRCConnectionReconfiguration to UE %d \n",
1867 1868 1869 1870 1871 1872
        ctxt_pP->module_id, ctxt_pP->frame, ue_context_pP->ue_context.rnti);
  rrc_eNB_generate_RRCConnectionReconfiguration_handover(
    ctxt_pP,
    ue_context_pP,
    NULL,
    0);
winckel's avatar
winckel committed
1873
}
1874

1875 1876 1877 1878 1879

//-----------------------------------------------------------------------------
void
check_handovers(
  protocol_ctxt_t* const ctxt_pP
1880
)
1881
//-----------------------------------------------------------------------------
1882
{
1883
  int                                 result;
1884 1885 1886
  struct rrc_eNB_ue_context_s*        ue_context_p;
  RB_FOREACH(ue_context_p, rrc_ue_tree_s, &eNB_rrc_inst[ctxt_pP->module_id].rrc_ue_head) {
    ctxt_pP->rnti  = ue_context_p->ue_id_rnti;
1887

1888 1889
    if (ue_context_p->ue_context.handover_info != NULL) {
      if (ue_context_p->ue_context.handover_info->ho_prepare == 0xFF) {
1890 1891
        LOG_D(RRC,
              "[eNB %d] Frame %d: Incoming handover detected for new UE_idx %d (source eNB %d->target eNB %d) \n",
1892 1893 1894 1895 1896
              ctxt_pP->module_id,
              ctxt_pP->frame,
              ctxt_pP->rnti,
              ctxt_pP->module_id,
              ue_context_p->ue_context.handover_info->modid_t);
1897
        // source eNB generates rrcconnectionreconfiguration to prepare the HO
1898 1899 1900 1901
        rrc_eNB_process_handoverPreparationInformation(
          ctxt_pP,
          ue_context_p);
        ue_context_p->ue_context.handover_info->ho_prepare = 0xF1;
1902 1903
      }

1904
      if (ue_context_p->ue_context.handover_info->ho_complete == 0xF1) {
1905
        LOG_D(RRC,
1906 1907 1908 1909 1910 1911
              "[eNB %d] Frame %d: handover Command received for new UE_id  %x current eNB %d target eNB: %d \n",
              ctxt_pP->module_id,
              ctxt_pP->frame,
              ctxt_pP->rnti,
              ctxt_pP->module_id,
              ue_context_p->ue_context.handover_info->modid_t);
1912
        //rrc_eNB_process_handoverPreparationInformation(enb_mod_idP,frameP,i);
1913
        result = pdcp_data_req(ctxt_pP,
1914 1915 1916
                               SRB_FLAG_YES,
                               DCCH,
                               rrc_eNB_mui++,
1917 1918 1919 1920
                               SDU_CONFIRM_NO,
                               ue_context_p->ue_context.handover_info->size,
                               ue_context_p->ue_context.handover_info->buf,
                               PDCP_TRANSMISSION_MODE_CONTROL);
1921
        AssertFatal(result == TRUE, "PDCP data request failed!\n");
1922
        ue_context_p->ue_context.handover_info->ho_complete = 0xF2;
1923
      }
winckel's avatar
winckel committed
1924
    }
1925
  }
1926
}
winckel's avatar
RRC:  
winckel committed
1927

winckel's avatar
winckel committed
1928
// 5.3.5.4 RRCConnectionReconfiguration including the mobilityControlInfo to prepare the UE handover
1929 1930 1931 1932 1933 1934 1935 1936 1937
//-----------------------------------------------------------------------------
void
rrc_eNB_generate_RRCConnectionReconfiguration_handover(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t*           const ue_context_pP,
  uint8_t*                const nas_pdu,
  const uint32_t                nas_length
)
//-----------------------------------------------------------------------------
1938
{
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1939

1940 1941 1942 1943 1944 1945
  uint8_t                             buffer[RRC_BUF_SIZE];
  uint16_t                            size;
  int                                 i;
  uint8_t                             rv[2];
  uint16_t                            Idx;
  // configure SRB1/SRB2, PhysicalConfigDedicated, MAC_MainConfig for UE
1946 1947
  eNB_RRC_INST*                       rrc_inst = &eNB_rrc_inst[ctxt_pP->module_id];
  struct PhysicalConfigDedicated**    physicalConfigDedicated = &ue_context_pP->ue_context.physicalConfigDedicated;
1948 1949 1950 1951 1952 1953

  struct SRB_ToAddMod                *SRB2_config;
  struct SRB_ToAddMod__rlc_Config    *SRB2_rlc_config;
  struct SRB_ToAddMod__logicalChannelConfig *SRB2_lchan_config;
  struct LogicalChannelConfig__ul_SpecificParameters *SRB2_ul_SpecificParameters;
  LogicalChannelConfig_t             *SRB1_logicalChannelConfig = NULL;
1954
  SRB_ToAddModList_t*                 SRB_configList = ue_context_pP->ue_context.SRB_configList;    // not used in this context: may be removed
1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976
  SRB_ToAddModList_t                 *SRB_configList2;

  struct DRB_ToAddMod                *DRB_config;
  struct RLC_Config                  *DRB_rlc_config;
  struct PDCP_Config                 *DRB_pdcp_config;
  struct PDCP_Config__rlc_UM         *PDCP_rlc_UM;
  struct LogicalChannelConfig        *DRB_lchan_config;
  struct LogicalChannelConfig__ul_SpecificParameters *DRB_ul_SpecificParameters;
  DRB_ToAddModList_t                 *DRB_configList2;

  MAC_MainConfig_t                   *mac_MainConfig;
  MeasObjectToAddModList_t           *MeasObj_list;
  MeasObjectToAddMod_t               *MeasObj;
  ReportConfigToAddModList_t         *ReportConfig_list;
  ReportConfigToAddMod_t             *ReportConfig_per, *ReportConfig_A1,
                                     *ReportConfig_A2, *ReportConfig_A3, *ReportConfig_A4, *ReportConfig_A5;
  MeasIdToAddModList_t               *MeasId_list;
  MeasIdToAddMod_t                   *MeasId0, *MeasId1, *MeasId2, *MeasId3, *MeasId4, *MeasId5;
  QuantityConfig_t                   *quantityConfig;
  MobilityControlInfo_t              *mobilityInfo;
  // HandoverCommand_t handoverCommand;
  uint8_t                             sourceModId =
1977
    get_adjacent_cell_mod_id(ue_context_pP->ue_context.handover_info->as_context.reestablishmentInfo->sourcePhysCellId);
1978
#if Rel10
1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997
  long                               *sr_ProhibitTimer_r9;
#endif

  long                               *logicalchannelgroup, *logicalchannelgroup_drb;
  long                               *maxHARQ_Tx, *periodicBSR_Timer;

  // RSRP_Range_t *rsrp;
  struct MeasConfig__speedStatePars  *Sparams;
  CellsToAddMod_t                    *CellToAdd;
  CellsToAddModList_t                *CellsToAddModList;
  // srb 1: for HO
  struct SRB_ToAddMod                *SRB1_config;
  struct SRB_ToAddMod__rlc_Config    *SRB1_rlc_config;
  struct SRB_ToAddMod__logicalChannelConfig *SRB1_lchan_config;
  struct LogicalChannelConfig__ul_SpecificParameters *SRB1_ul_SpecificParameters;
  // phy config dedicated
  PhysicalConfigDedicated_t          *physicalConfigDedicated2;
  struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList;
  protocol_ctxt_t                     ctxt;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1998

1999 2000
  LOG_D(RRC, "[eNB %d] Frame %d: handover preparation: get the newSourceUEIdentity (C-RNTI): ",
        ctxt_pP->module_id, ctxt_pP->frame);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2001

2002 2003 2004 2005
  for (i = 0; i < 2; i++) {
    rv[i] = taus() & 0xff;
    LOG_D(RRC, " %x.", rv[i]);
  }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2006

2007
  LOG_D(RRC, "[eNB %d] Frame %d : handover reparation: add target eNB SRB1 and PHYConfigDedicated reconfiguration\n",
2008
        ctxt_pP->module_id, ctxt_pP->frame);
2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106
  // 1st: reconfigure SRB
  SRB_configList2 = CALLOC(1, sizeof(*SRB_configList));
  SRB1_config = CALLOC(1, sizeof(*SRB1_config));
  SRB1_config->srb_Identity = 1;
  SRB1_rlc_config = CALLOC(1, sizeof(*SRB1_rlc_config));
  SRB1_config->rlc_Config = SRB1_rlc_config;

  SRB1_rlc_config->present = SRB_ToAddMod__rlc_Config_PR_explicitValue;
  SRB1_rlc_config->choice.explicitValue.present = RLC_Config_PR_am;
  SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.t_PollRetransmit = T_PollRetransmit_ms15;
  SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollPDU = PollPDU_p8;
  SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollByte = PollByte_kB1000;
  SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.maxRetxThreshold = UL_AM_RLC__maxRetxThreshold_t16;
  SRB1_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_Reordering = T_Reordering_ms35;
  SRB1_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_StatusProhibit = T_StatusProhibit_ms10;

  SRB1_lchan_config = CALLOC(1, sizeof(*SRB1_lchan_config));
  SRB1_config->logicalChannelConfig = SRB1_lchan_config;

  SRB1_lchan_config->present = SRB_ToAddMod__logicalChannelConfig_PR_explicitValue;
  SRB1_ul_SpecificParameters = CALLOC(1, sizeof(*SRB1_ul_SpecificParameters));

  SRB1_lchan_config->choice.explicitValue.ul_SpecificParameters = SRB1_ul_SpecificParameters;

  SRB1_ul_SpecificParameters->priority = 1;

  //assign_enum(&SRB1_ul_SpecificParameters->prioritisedBitRate,LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity);
  SRB1_ul_SpecificParameters->prioritisedBitRate =
    LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;

  //assign_enum(&SRB1_ul_SpecificParameters->bucketSizeDuration,LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50);
  SRB1_ul_SpecificParameters->bucketSizeDuration =
    LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;

  logicalchannelgroup = CALLOC(1, sizeof(long));
  *logicalchannelgroup = 0;
  SRB1_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup;

  ASN_SEQUENCE_ADD(&SRB_configList2->list, SRB1_config);

  //2nd: now reconfigure phy config dedicated
  physicalConfigDedicated2 = CALLOC(1, sizeof(*physicalConfigDedicated2));
  *physicalConfigDedicated = physicalConfigDedicated2;

  physicalConfigDedicated2->pdsch_ConfigDedicated =
    CALLOC(1, sizeof(*physicalConfigDedicated2->pdsch_ConfigDedicated));
  physicalConfigDedicated2->pucch_ConfigDedicated =
    CALLOC(1, sizeof(*physicalConfigDedicated2->pucch_ConfigDedicated));
  physicalConfigDedicated2->pusch_ConfigDedicated =
    CALLOC(1, sizeof(*physicalConfigDedicated2->pusch_ConfigDedicated));
  physicalConfigDedicated2->uplinkPowerControlDedicated =
    CALLOC(1, sizeof(*physicalConfigDedicated2->uplinkPowerControlDedicated));
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH =
    CALLOC(1, sizeof(*physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH));
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH =
    CALLOC(1, sizeof(*physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH));
  physicalConfigDedicated2->cqi_ReportConfig = NULL;  //CALLOC(1,sizeof(*physicalConfigDedicated2->cqi_ReportConfig));
  physicalConfigDedicated2->soundingRS_UL_ConfigDedicated = NULL; //CALLOC(1,sizeof(*physicalConfigDedicated2->soundingRS_UL_ConfigDedicated));
  physicalConfigDedicated2->antennaInfo = CALLOC(1, sizeof(*physicalConfigDedicated2->antennaInfo));
  physicalConfigDedicated2->schedulingRequestConfig =
    CALLOC(1, sizeof(*physicalConfigDedicated2->schedulingRequestConfig));
  // PDSCH
  //assign_enum(&physicalConfigDedicated2->pdsch_ConfigDedicated->p_a,
  //          PDSCH_ConfigDedicated__p_a_dB0);
  physicalConfigDedicated2->pdsch_ConfigDedicated->p_a = PDSCH_ConfigDedicated__p_a_dB0;

  // PUCCH
  physicalConfigDedicated2->pucch_ConfigDedicated->ackNackRepetition.present =
    PUCCH_ConfigDedicated__ackNackRepetition_PR_release;
  physicalConfigDedicated2->pucch_ConfigDedicated->ackNackRepetition.choice.release = 0;
  physicalConfigDedicated2->pucch_ConfigDedicated->tdd_AckNackFeedbackMode = NULL;    //PUCCH_ConfigDedicated__tdd_AckNackFeedbackMode_multiplexing;

  // Pusch_config_dedicated
  physicalConfigDedicated2->pusch_ConfigDedicated->betaOffset_ACK_Index = 0;  // 2.00
  physicalConfigDedicated2->pusch_ConfigDedicated->betaOffset_RI_Index = 0;   // 1.25
  physicalConfigDedicated2->pusch_ConfigDedicated->betaOffset_CQI_Index = 8;  // 2.25

  // UplinkPowerControlDedicated
  physicalConfigDedicated2->uplinkPowerControlDedicated->p0_UE_PUSCH = 0; // 0 dB
  //assign_enum(&physicalConfigDedicated2->uplinkPowerControlDedicated->deltaMCS_Enabled,
  // UplinkPowerControlDedicated__deltaMCS_Enabled_en1);
  physicalConfigDedicated2->uplinkPowerControlDedicated->deltaMCS_Enabled =
    UplinkPowerControlDedicated__deltaMCS_Enabled_en1;
  physicalConfigDedicated2->uplinkPowerControlDedicated->accumulationEnabled = 1; // should be TRUE in order to have 0dB power offset
  physicalConfigDedicated2->uplinkPowerControlDedicated->p0_UE_PUCCH = 0; // 0 dB
  physicalConfigDedicated2->uplinkPowerControlDedicated->pSRS_Offset = 0; // 0 dB
  physicalConfigDedicated2->uplinkPowerControlDedicated->filterCoefficient =
    CALLOC(1, sizeof(*physicalConfigDedicated2->uplinkPowerControlDedicated->filterCoefficient));
  //  assign_enum(physicalConfigDedicated2->uplinkPowerControlDedicated->filterCoefficient,FilterCoefficient_fc4); // fc4 dB
  *physicalConfigDedicated2->uplinkPowerControlDedicated->filterCoefficient = FilterCoefficient_fc4;  // fc4 dB

  // TPC-PDCCH-Config
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->present = TPC_PDCCH_Config_PR_setup;
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_Index.present = TPC_Index_PR_indexOfFormat3;
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_Index.choice.indexOfFormat3 = 1;
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_RNTI.buf = CALLOC(1, 2);
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_RNTI.size = 2;
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_RNTI.buf[0] = 0x12;
2107
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_RNTI.buf[1] = 0x34 + ue_context_pP->local_uid;
2108 2109 2110 2111 2112 2113 2114 2115
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_RNTI.bits_unused = 0;

  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->present = TPC_PDCCH_Config_PR_setup;
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_Index.present = TPC_Index_PR_indexOfFormat3;
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_Index.choice.indexOfFormat3 = 1;
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_RNTI.buf = CALLOC(1, 2);
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_RNTI.size = 2;
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_RNTI.buf[0] = 0x22;
2116
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_RNTI.buf[1] = 0x34 + ue_context_pP->local_uid;
2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_RNTI.bits_unused = 0;

  // CQI ReportConfig
  /*
     physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportModeAperiodic=CALLOC(1,sizeof(*physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportModeAperiodic));
     assign_enum(physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportModeAperiodic,
     CQI_ReportConfig__cqi_ReportModeAperiodic_rm30); // HLC CQI, no PMI
     physicalConfigDedicated2->cqi_ReportConfig->nomPDSCH_RS_EPRE_Offset = 0; // 0 dB
     physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic=CALLOC(1,sizeof(*physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic));
     physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->present =  CQI_ReportPeriodic_PR_setup;
     physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->choice.setup.cqi_PUCCH_ResourceIndex = 0;  // n2_pucch
     physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->choice.setup.cqi_pmi_ConfigIndex = 0;  // Icqi/pmi
     physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present = CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_subbandCQI;  // subband CQI
     physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.choice.subbandCQI.k=4;

     physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->choice.setup.ri_ConfigIndex=NULL;
     physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->choice.setup.simultaneousAckNackAndCQI=0;
   */
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2135

2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149
  //soundingRS-UL-ConfigDedicated
  /*
     physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->present = SoundingRS_UL_ConfigDedicated_PR_setup;
     assign_enum(&physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.srs_Bandwidth,
     SoundingRS_UL_ConfigDedicated__setup__srs_Bandwidth_bw0);
     assign_enum(&physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.srs_HoppingBandwidth,
     SoundingRS_UL_ConfigDedicated__setup__srs_HoppingBandwidth_hbw0);
     physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.freqDomainPosition=0;
     physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.duration=1;
     physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.srs_ConfigIndex=1;
     physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.transmissionComb=0;
     assign_enum(&physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.cyclicShift,
     SoundingRS_UL_ConfigDedicated__setup__cyclicShift_cs0);
   */
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2150

2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180
  //AntennaInfoDedicated
  physicalConfigDedicated2->antennaInfo = CALLOC(1, sizeof(*physicalConfigDedicated2->antennaInfo));
  physicalConfigDedicated2->antennaInfo->present = PhysicalConfigDedicated__antennaInfo_PR_explicitValue;
  //assign_enum(&physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode,
  //     AntennaInfoDedicated__transmissionMode_tm2);
  /*
     switch (transmission_mode){
     case 1:
     physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm1;
     break;
     case 2:
     physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm2;
     break;
     case 4:
     physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm4;
     break;
     case 5:
     physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm5;
     break;
     case 6:
     physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm6;
     break;
     }
   */
  physicalConfigDedicated2->antennaInfo->choice.explicitValue.ue_TransmitAntennaSelection.present =
    AntennaInfoDedicated__ue_TransmitAntennaSelection_PR_release;
  physicalConfigDedicated2->antennaInfo->choice.explicitValue.ue_TransmitAntennaSelection.choice.release = 0;

  // SchedulingRequestConfig
  physicalConfigDedicated2->schedulingRequestConfig->present = SchedulingRequestConfig_PR_setup;
2181
  physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_PUCCH_ResourceIndex = ue_context_pP->local_uid;
2182 2183

  if (mac_xface->lte_frame_parms->frame_type == 0) {  // FDD
2184 2185
    physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_ConfigIndex = 5 + (ue_context_pP->local_uid %
        10);   // Isr = 5 (every 10 subframes, offset=2+UE_id mod3)
2186 2187 2188
  } else {
    switch (mac_xface->lte_frame_parms->tdd_config) {
    case 1:
2189 2190
      physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_ConfigIndex = 7 + (ue_context_pP->local_uid & 1) + ((
            ue_context_pP->local_uid & 3) >> 1) * 5;    // Isr = 5 (every 10 subframes, offset=2 for UE0, 3 for UE1, 7 for UE2, 8 for UE3 , 2 for UE4 etc..)
2191 2192 2193
      break;

    case 3:
2194 2195
      physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_ConfigIndex = 7 + (ue_context_pP->local_uid %
          3);    // Isr = 5 (every 10 subframes, offset=2 for UE0, 3 for UE1, 3 for UE2, 2 for UE3 , etc..)
2196 2197 2198
      break;

    case 4:
2199 2200
      physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_ConfigIndex = 7 + (ue_context_pP->local_uid &
          1);    // Isr = 5 (every 10 subframes, offset=2 for UE0, 3 for UE1, 3 for UE2, 2 for UE3 , etc..)
2201 2202 2203 2204 2205
      break;

    default:
      physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_ConfigIndex = 7; // Isr = 5 (every 10 subframes, offset=2 for all UE0 etc..)
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2206
    }
2207
  }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2208

2209 2210 2211 2212 2213 2214 2215
  //  assign_enum(&physicalConfigDedicated2->schedulingRequestConfig->choice.setup.dsr_TransMax,
  //SchedulingRequestConfig__setup__dsr_TransMax_n4);
  //  assign_enum(&physicalConfigDedicated2->schedulingRequestConfig->choice.setup.dsr_TransMax = SchedulingRequestConfig__setup__dsr_TransMax_n4;
  physicalConfigDedicated2->schedulingRequestConfig->choice.setup.dsr_TransMax =
    SchedulingRequestConfig__setup__dsr_TransMax_n4;

  LOG_D(RRC,
2216 2217 2218 2219
        "handover_config [FRAME %05d][RRC_eNB][MOD %02d][][--- MAC_CONFIG_REQ  (SRB1 UE %x) --->][MAC_eNB][MOD %02d][]\n",
        ctxt_pP->frame, ctxt_pP->module_id, ue_context_pP->ue_context.rnti, ctxt_pP->module_id);
  rrc_mac_config_req(
    ctxt_pP->module_id,
2220
    ue_context_pP->ue_context.primaryCC_id,
2221 2222 2223 2224 2225
    ENB_FLAG_YES,
    ue_context_pP->ue_context.rnti,
    0,
    (RadioResourceConfigCommonSIB_t*) NULL,
    ue_context_pP->ue_context.physicalConfigDedicated,
2226
#ifdef Rel10
2227 2228
    (SCellToAddMod_r10_t *)NULL,
    //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
2229
#endif
2230
    (MeasObjectToAddMod_t **) NULL,
2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241
    ue_context_pP->ue_context.mac_MainConfig,
    1,
    SRB1_logicalChannelConfig,
    ue_context_pP->ue_context.measGapConfig,
    (TDD_Config_t*) NULL,
    (MobilityControlInfo_t*) NULL,
    (uint8_t*) NULL,
    (uint16_t*) NULL,
    NULL,
    NULL,
    NULL,
2242
    (MBSFN_SubframeConfigList_t *) NULL
2243
#ifdef Rel10
2244
    , 0, (MBSFN_AreaInfoList_r9_t *) NULL, (PMCH_InfoList_r9_t *) NULL
2245
#endif
winckel's avatar
winckel committed
2246
#ifdef CBA
2247
    , eNB_rrc_inst[ctxt_pP->module_id].num_active_cba_groups, eNB_rrc_inst[ctxt_pP->module_id].cba_rnti[0]
2248
#endif
2249
  );
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2250

2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268
  // Configure target eNB 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_ms35;
  SRB2_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_StatusProhibit = T_StatusProhibit_ms10;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2269

2270 2271
  SRB2_lchan_config = CALLOC(1, sizeof(*SRB2_lchan_config));
  SRB2_config->logicalChannelConfig = SRB2_lchan_config;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2272

2273
  SRB2_lchan_config->present = SRB_ToAddMod__logicalChannelConfig_PR_explicitValue;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2274

2275
  SRB2_ul_SpecificParameters = CALLOC(1, sizeof(*SRB2_ul_SpecificParameters));
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2276

2277 2278 2279 2280 2281
  SRB2_ul_SpecificParameters->priority = 1;
  SRB2_ul_SpecificParameters->prioritisedBitRate =
    LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
  SRB2_ul_SpecificParameters->bucketSizeDuration =
    LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2282

2283 2284 2285
  // LCG for CCCH and DCCH is 0 as defined in 36331
  logicalchannelgroup = CALLOC(1, sizeof(long));
  *logicalchannelgroup = 0;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2286

2287 2288 2289 2290
  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);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2291

2292 2293 2294 2295
  // Configure target eNB DRB
  DRB_configList2 = CALLOC(1, sizeof(*DRB_configList2));
  /// DRB
  DRB_config = CALLOC(1, sizeof(*DRB_config));
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2296

2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307
  //DRB_config->drb_Identity = (DRB_Identity_t) 1; //allowed values 1..32
  // NN: this is the 1st DRB for this ue, so set it to 1
  DRB_config->drb_Identity = (DRB_Identity_t) 1;  // (ue_mod_idP+1); //allowed values 1..32
  DRB_config->logicalChannelIdentity = CALLOC(1, sizeof(long));
  *(DRB_config->logicalChannelIdentity) = (long)3;
  DRB_rlc_config = CALLOC(1, sizeof(*DRB_rlc_config));
  DRB_config->rlc_Config = DRB_rlc_config;
  DRB_rlc_config->present = RLC_Config_PR_um_Bi_Directional;
  DRB_rlc_config->choice.um_Bi_Directional.ul_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering = T_Reordering_ms35;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2308

2309 2310 2311 2312 2313 2314 2315 2316
  DRB_pdcp_config = CALLOC(1, sizeof(*DRB_pdcp_config));
  DRB_config->pdcp_Config = DRB_pdcp_config;
  DRB_pdcp_config->discardTimer = NULL;
  DRB_pdcp_config->rlc_AM = NULL;
  PDCP_rlc_UM = CALLOC(1, sizeof(*PDCP_rlc_UM));
  DRB_pdcp_config->rlc_UM = PDCP_rlc_UM;
  PDCP_rlc_UM->pdcp_SN_Size = PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits;
  DRB_pdcp_config->headerCompression.present = PDCP_Config__headerCompression_PR_notUsed;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2317

2318 2319 2320 2321
  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;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2322

2323 2324 2325 2326 2327
  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;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2328

2329 2330 2331 2332
  // 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;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2333

2334
  ASN_SEQUENCE_ADD(&DRB_configList2->list, DRB_config);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2335

2336
  mac_MainConfig = CALLOC(1, sizeof(*mac_MainConfig));
2337
  ue_context_pP->ue_context.mac_MainConfig = mac_MainConfig;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2338

2339
  mac_MainConfig->ul_SCH_Config = CALLOC(1, sizeof(*mac_MainConfig->ul_SCH_Config));
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2340

2341 2342 2343
  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;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2344

2345 2346 2347
  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;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2348

2349
  mac_MainConfig->ul_SCH_Config->retxBSR_Timer = MAC_MainConfig__ul_SCH_Config__retxBSR_Timer_sf320;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2350

2351 2352 2353
  mac_MainConfig->ul_SCH_Config->ttiBundling = 0; // FALSE

  mac_MainConfig->drx_Config = NULL;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2354

2355
  mac_MainConfig->phr_Config = CALLOC(1, sizeof(*mac_MainConfig->phr_Config));
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2356

2357 2358
  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
2359

2360
  mac_MainConfig->phr_Config->choice.setup.prohibitPHR_Timer = MAC_MainConfig__phr_Config__setup__prohibitPHR_Timer_sf20; // sf20 = 20 subframes
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2361

2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439
  mac_MainConfig->phr_Config->choice.setup.dl_PathlossChange = MAC_MainConfig__phr_Config__setup__dl_PathlossChange_dB1;  // Value dB1 =1 dB, dB3 = 3 dB

#ifdef Rel10
  sr_ProhibitTimer_r9 = CALLOC(1, sizeof(long));
  *sr_ProhibitTimer_r9 = 0;   // SR tx on PUCCH, Value in number of SR period(s). Value 0 = no timer for SR, Value 2= 2*SR
  mac_MainConfig->sr_ProhibitTimer_r9 = sr_ProhibitTimer_r9;
  //sps_RA_ConfigList_rlola = NULL;
#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;
  MeasObj->measObject.choice.measObjectEUTRA.carrierFreq = 36090;
  MeasObj->measObject.choice.measObjectEUTRA.allowedMeasBandwidth = AllowedMeasBandwidth_mbw25;
  MeasObj->measObject.choice.measObjectEUTRA.presenceAntennaPort1 = 1;
  MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.buf = CALLOC(1, sizeof(uint8_t));
  MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.buf[0] = 0;
  MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.size = 1;
  MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.bits_unused = 6;
  MeasObj->measObject.choice.measObjectEUTRA.offsetFreq = NULL;   // Default is 15 or 0dB

  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;
2440
    CellToAdd->physCellId = get_adjacent_cell_id(ctxt_pP->module_id, i);
2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604
    CellToAdd->cellIndividualOffset = Q_OffsetRange_dB0;

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

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

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

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

  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(*quantityConfig->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;

  /* mobilityinfo  */

  mobilityInfo = CALLOC(1, sizeof(*mobilityInfo));
  memset((void *)mobilityInfo, 0, sizeof(*mobilityInfo));
  mobilityInfo->targetPhysCellId =
2605 2606 2607 2608 2609 2610 2611
    (PhysCellId_t) two_tier_hexagonal_cellIds[ue_context_pP->ue_context.handover_info->modid_t];
  LOG_D(RRC, "[eNB %d] Frame %d: handover preparation: targetPhysCellId: %d mod_id: %d ue: %x \n",
        ctxt_pP->module_id,
        ctxt_pP->frame,
        mobilityInfo->targetPhysCellId,
        ctxt_pP->module_id,
        ue_context_pP->ue_context.rnti);
2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631

  mobilityInfo->additionalSpectrumEmission = CALLOC(1, sizeof(*mobilityInfo->additionalSpectrumEmission));
  *mobilityInfo->additionalSpectrumEmission = 1;  //Check this value!

  mobilityInfo->t304 = MobilityControlInfo__t304_ms50;    // need to configure an appropriate value here

  // New UE Identity (C-RNTI) to identify an UE uniquely in a cell
  mobilityInfo->newUE_Identity.size = 2;
  mobilityInfo->newUE_Identity.bits_unused = 0;
  mobilityInfo->newUE_Identity.buf = rv;
  mobilityInfo->newUE_Identity.buf[0] = rv[0];
  mobilityInfo->newUE_Identity.buf[1] = rv[1];

  //memset((void *)&mobilityInfo->radioResourceConfigCommon,(void *)&rrc_inst->sib2->radioResourceConfigCommon,sizeof(RadioResourceConfigCommon_t));
  //memset((void *)&mobilityInfo->radioResourceConfigCommon,0,sizeof(RadioResourceConfigCommon_t));

  // Configuring radioResourceConfigCommon
  mobilityInfo->radioResourceConfigCommon.rach_ConfigCommon =
    CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.rach_ConfigCommon));
  memcpy((void *)mobilityInfo->radioResourceConfigCommon.rach_ConfigCommon,
2632
         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.rach_ConfigCommon, sizeof(RACH_ConfigCommon_t));
2633 2634 2635
  mobilityInfo->radioResourceConfigCommon.prach_Config.prach_ConfigInfo =
    CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.prach_Config.prach_ConfigInfo));
  memcpy((void *)mobilityInfo->radioResourceConfigCommon.prach_Config.prach_ConfigInfo,
2636
         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.prach_Config.prach_ConfigInfo,
2637 2638 2639
         sizeof(PRACH_ConfigInfo_t));

  mobilityInfo->radioResourceConfigCommon.prach_Config.rootSequenceIndex =
2640
    rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.prach_Config.rootSequenceIndex;
2641 2642 2643
  mobilityInfo->radioResourceConfigCommon.pdsch_ConfigCommon =
    CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.pdsch_ConfigCommon));
  memcpy((void *)mobilityInfo->radioResourceConfigCommon.pdsch_ConfigCommon,
2644
         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.pdsch_ConfigCommon, sizeof(PDSCH_ConfigCommon_t));
2645
  memcpy((void *)&mobilityInfo->radioResourceConfigCommon.pusch_ConfigCommon,
2646
         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.pusch_ConfigCommon, sizeof(PUSCH_ConfigCommon_t));
2647 2648 2649 2650
  mobilityInfo->radioResourceConfigCommon.phich_Config = NULL;
  mobilityInfo->radioResourceConfigCommon.pucch_ConfigCommon =
    CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.pucch_ConfigCommon));
  memcpy((void *)mobilityInfo->radioResourceConfigCommon.pucch_ConfigCommon,
2651
         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.pucch_ConfigCommon, sizeof(PUCCH_ConfigCommon_t));
2652 2653 2654
  mobilityInfo->radioResourceConfigCommon.soundingRS_UL_ConfigCommon =
    CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.soundingRS_UL_ConfigCommon));
  memcpy((void *)mobilityInfo->radioResourceConfigCommon.soundingRS_UL_ConfigCommon,
2655
         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon,
2656 2657 2658 2659
         sizeof(SoundingRS_UL_ConfigCommon_t));
  mobilityInfo->radioResourceConfigCommon.uplinkPowerControlCommon =
    CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.uplinkPowerControlCommon));
  memcpy((void *)mobilityInfo->radioResourceConfigCommon.uplinkPowerControlCommon,
2660
         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.uplinkPowerControlCommon,
2661 2662 2663 2664 2665 2666 2667
         sizeof(UplinkPowerControlCommon_t));
  mobilityInfo->radioResourceConfigCommon.antennaInfoCommon = NULL;
  mobilityInfo->radioResourceConfigCommon.p_Max = NULL;   // CALLOC(1,sizeof(*mobilityInfo->radioResourceConfigCommon.p_Max));
  //memcpy((void *)mobilityInfo->radioResourceConfigCommon.p_Max,(void *)rrc_inst->sib1->p_Max,sizeof(P_Max_t));
  mobilityInfo->radioResourceConfigCommon.tdd_Config = NULL;  //CALLOC(1,sizeof(TDD_Config_t));
  //memcpy((void *)mobilityInfo->radioResourceConfigCommon.tdd_Config,(void *)rrc_inst->sib1->tdd_Config,sizeof(TDD_Config_t));
  mobilityInfo->radioResourceConfigCommon.ul_CyclicPrefixLength =
2668
    rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.ul_CyclicPrefixLength;
2669 2670 2671 2672 2673 2674
  //End of configuration of radioResourceConfigCommon

  mobilityInfo->carrierFreq = CALLOC(1, sizeof(*mobilityInfo->carrierFreq));  //CALLOC(1,sizeof(CarrierFreqEUTRA_t)); 36090
  mobilityInfo->carrierFreq->dl_CarrierFreq = 36090;
  mobilityInfo->carrierFreq->ul_CarrierFreq = NULL;

2675 2676
  mobilityInfo->carrierBandwidth = CALLOC(1, sizeof(
      *mobilityInfo->carrierBandwidth));    //CALLOC(1,sizeof(struct CarrierBandwidthEUTRA));  AllowedMeasBandwidth_mbw25
2677 2678 2679 2680 2681 2682
  mobilityInfo->carrierBandwidth->dl_Bandwidth = CarrierBandwidthEUTRA__dl_Bandwidth_n25;
  mobilityInfo->carrierBandwidth->ul_Bandwidth = NULL;
  mobilityInfo->rach_ConfigDedicated = NULL;

  // store the srb and drb list for ho management, mainly in case of failure

2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695
  memcpy(ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.srb_ToAddModList,
         (void*)SRB_configList2,
         sizeof(SRB_ToAddModList_t));
  memcpy((void*)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.drb_ToAddModList,
         (void*)DRB_configList2,
         sizeof(DRB_ToAddModList_t));
  ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.drb_ToReleaseList = NULL;
  memcpy((void*)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig,
         (void*)mac_MainConfig,
         sizeof(MAC_MainConfig_t));
  memcpy((void*)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.physicalConfigDedicated,
         (void*)ue_context_pP->ue_context.physicalConfigDedicated,
         sizeof(PhysicalConfigDedicated_t));
2696 2697 2698 2699 2700 2701 2702 2703
  /*    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));
   */
  LOG_I(RRC, "[eNB %d] Frame %d: adding new UE\n");
  //Idx = (ue_mod_idP * NB_RB_MAX) + DCCH;
  Idx = DCCH;
  // SRB1
2704 2705 2706 2707
  ue_context_pP->ue_context.Srb1.Active = 1;
  ue_context_pP->ue_context.Srb1.Srb_info.Srb_id = Idx;
  memcpy(&ue_context_pP->ue_context.Srb1.Srb_info.Lchan_desc[0], &DCCH_LCHAN_DESC, LCHAN_DESC_SIZE);
  memcpy(&ue_context_pP->ue_context.Srb1.Srb_info.Lchan_desc[1], &DCCH_LCHAN_DESC, LCHAN_DESC_SIZE);
2708 2709

  // SRB2
2710 2711 2712 2713 2714 2715
  ue_context_pP->ue_context.Srb2.Active = 1;
  ue_context_pP->ue_context.Srb2.Srb_info.Srb_id = Idx;
  memcpy(&ue_context_pP->ue_context.Srb2.Srb_info.Lchan_desc[0], &DCCH_LCHAN_DESC, LCHAN_DESC_SIZE);
  memcpy(&ue_context_pP->ue_context.Srb2.Srb_info.Lchan_desc[1], &DCCH_LCHAN_DESC, LCHAN_DESC_SIZE);
  LOG_I(RRC, "[eNB %d] CALLING RLC CONFIG SRB1 (rbid %d) for UE %x\n",
        ctxt_pP->module_id, Idx, ue_context_pP->ue_context.rnti);
2716 2717 2718 2719 2720

  //      rrc_pdcp_config_req (enb_mod_idP, frameP, 1, CONFIG_ACTION_ADD, idx, UNDEF_SECURITY_MODE);
  //      rrc_rlc_config_req(enb_mod_idP,frameP,1,CONFIG_ACTION_ADD,Idx,SIGNALLING_RADIO_BEARER,Rlc_info_am_config);

  rrc_pdcp_config_asn1_req(&ctxt,
2721
                           ue_context_pP->ue_context.SRB_configList,
2722
                           (DRB_ToAddModList_t *) NULL, (DRB_ToReleaseList_t *) NULL, 0xff, NULL, NULL, NULL
winckel's avatar
winckel committed
2723
#ifdef Rel10
2724
                           , (PMCH_InfoList_r9_t *) NULL
winckel's avatar
winckel committed
2725
#endif
2726
                          );
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2727

2728
  rrc_rlc_config_asn1_req(&ctxt,
2729
                          ue_context_pP->ue_context.SRB_configList,
2730
                          (DRB_ToAddModList_t *) NULL, (DRB_ToReleaseList_t *) NULL
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2731
#ifdef Rel10
2732
                          , (PMCH_InfoList_r9_t *) NULL
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2733
#endif
2734
                         );
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2735

2736 2737
  /* Initialize NAS list */
  dedicatedInfoNASList = NULL;
2738

2739 2740 2741
  //  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->reportConfigToAddModList = ReportConfig_list;
  memset(buffer, 0, RRC_BUF_SIZE);

2742 2743 2744 2745 2746 2747 2748
  size = do_RRCConnectionReconfiguration(
           ctxt_pP,
           buffer,
           rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),   //Transaction_id,
           SRB_configList2,
           DRB_configList2,
           NULL,  // DRB2_list,
2749
           NULL,    //*sps_Config,
2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761
           ue_context_pP->ue_context.physicalConfigDedicated,
           MeasObj_list,
           ReportConfig_list,
           NULL,    //quantityConfig,
           MeasId_list,
           mac_MainConfig,
           NULL,
           mobilityInfo,
           Sparams,
           NULL,
           NULL,
           dedicatedInfoNASList
2762
#ifdef Rel10
2763
           , NULL   // SCellToAddMod_r10_t
2764
#endif
2765
         );
2766 2767

  LOG_I(RRC,
2768 2769
        "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate RRCConnectionReconfiguration for handover (bytes %d, UE rnti %x)\n",
        ctxt_pP->module_id, ctxt_pP->frame, size, ue_context_pP->ue_context.rnti);
2770
  // to be updated if needed
2771 2772 2773
  /*if (eNB_rrc_inst[ctxt_pP->module_id].SRB1_config[ue_mod_idP]->logicalChannelConfig) {
     if (eNB_rrc_inst[ctxt_pP->module_id].SRB1_config[ue_mod_idP]->logicalChannelConfig->present == SRB_ToAddMod__logicalChannelConfig_PR_explicitValue) {
     SRB1_logicalChannelConfig = &eNB_rrc_inst[ctxt_pP->module_id].SRB1_config[ue_mod_idP]->logicalChannelConfig->choice.explicitValue;
2774 2775 2776 2777 2778 2779 2780 2781 2782
     }
     else {
     SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
     }
     }
     else {
     SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
     }
   */
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2783

2784
  LOG_D(RRC,
2785 2786 2787 2788 2789 2790
        "[FRAME %05d][RRC_eNB][MOD %02d][][--- PDCP_DATA_REQ/%d Bytes (rrcConnectionReconfiguration_handover to UE %x MUI %d) --->][PDCP][MOD %02d][RB %02d]\n",
        ctxt_pP->frame, ctxt_pP->module_id, size, ue_context_pP->ue_context.rnti, rrc_eNB_mui, ctxt_pP->module_id, DCCH);
  //rrc_rlc_data_req(ctxt_pP->module_id,frameP, 1,(ue_mod_idP*NB_RB_MAX)+DCCH,rrc_eNB_mui++,0,size,(char*)buffer);
  //pdcp_data_req (ctxt_pP->module_id, frameP, 1, (ue_mod_idP * NB_RB_MAX) + DCCH,rrc_eNB_mui++, 0, size, (char *) buffer, 1);
  rrc_mac_config_req(
    ctxt_pP->module_id,
2791
    ue_context_pP->ue_context.primaryCC_id,
2792 2793 2794
    ENB_FLAG_YES,
    ue_context_pP->ue_context.rnti,
    0,
2795
    (RadioResourceConfigCommonSIB_t *) NULL,
2796
    ue_context_pP->ue_context.physicalConfigDedicated,
2797
#ifdef Rel10
2798 2799
    (SCellToAddMod_r10_t *)NULL,
    //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
2800
#endif
2801
    (MeasObjectToAddMod_t **) NULL,
2802
    ue_context_pP->ue_context.mac_MainConfig,
2803 2804
    1,
    SRB1_logicalChannelConfig,
2805
    ue_context_pP->ue_context.measGapConfig,
2806 2807 2808
    (TDD_Config_t *) NULL,
    (MobilityControlInfo_t *) mobilityInfo,
    (uint8_t *) NULL, (uint16_t *) NULL, NULL, NULL, NULL, (MBSFN_SubframeConfigList_t *) NULL
2809
#ifdef Rel10
2810
    , 0, (MBSFN_AreaInfoList_r9_t *) NULL, (PMCH_InfoList_r9_t *) NULL
2811 2812
#endif
#ifdef CBA
2813
    , 0, 0
2814
#endif
2815
  );
2816

2817 2818 2819 2820 2821 2822
  /*
     handoverCommand.criticalExtensions.present = HandoverCommand__criticalExtensions_PR_c1;
     handoverCommand.criticalExtensions.choice.c1.present = HandoverCommand__criticalExtensions__c1_PR_handoverCommand_r8;
     handoverCommand.criticalExtensions.choice.c1.choice.handoverCommand_r8.handoverCommandMessage.buf = buffer;
     handoverCommand.criticalExtensions.choice.c1.choice.handoverCommand_r8.handoverCommandMessage.size = size;
   */
2823 2824
#warning "COMPILATION PROBLEM"
#ifdef PROBLEM_COMPILATION_RESOLVED
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2825

2826
  if (sourceModId != 0xFF) {
2827
    memcpy(eNB_rrc_inst[sourceModId].handover_info[eNB_rrc_inst[ctxt_pP->module_id].handover_info[ue_mod_idP]->ueid_s]->buf,
2828
           (void *)buffer, size);
2829 2830
    eNB_rrc_inst[sourceModId].handover_info[eNB_rrc_inst[ctxt_pP->module_id].handover_info[ue_mod_idP]->ueid_s]->size = size;
    eNB_rrc_inst[sourceModId].handover_info[eNB_rrc_inst[ctxt_pP->module_id].handover_info[ue_mod_idP]->ueid_s]->ho_complete =
2831
      0xF1;
2832
    //eNB_rrc_inst[ctxt_pP->module_id].handover_info[ue_mod_idP]->ho_complete = 0xFF;
2833
    LOG_D(RRC, "[eNB %d] Frame %d: setting handover complete to 0xF1 for (%d,%d) and to 0xFF for (%d,%d)\n",
2834 2835 2836 2837 2838 2839
          ctxt_pP->module_id,
          ctxt_pP->frame,
          sourceModId,
          eNB_rrc_inst[ctxt_pP->module_id].handover_info[ue_mod_idP]->ueid_s,
          ctxt_pP->module_id,
          ue_mod_idP);
2840 2841 2842
  } else
    LOG_W(RRC,
          "[eNB %d] Frame %d: rrc_eNB_generate_RRCConnectionReconfiguration_handover: Could not find source eNB mod_id.\n",
2843
          ctxt_pP->module_id, ctxt_pP->frame);
2844

2845
#endif
winckel's avatar
winckel committed
2846
}
2847

winckel's avatar
winckel committed
2848
/*
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2849
  void ue_rrc_process_rrcConnectionReconfiguration(uint8_t enb_mod_idP,frame_t frameP,
winckel's avatar
winckel committed
2850
  RRCConnectionReconfiguration_t *rrcConnectionReconfiguration,
2851
  uint8_t CH_index) {
2852

winckel's avatar
winckel committed
2853 2854
  if (rrcConnectionReconfiguration->criticalExtensions.present == RRCConnectionReconfiguration__criticalExtensions_PR_c1)
  if (rrcConnectionReconfiguration->criticalExtensions.choice.c1.present == RRCConnectionReconfiguration__criticalExtensions__c1_PR_rrcConnectionReconfiguration_r8) {
2855

winckel's avatar
winckel committed
2856
  if (rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated) {
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2857
  rrc_ue_process_radioResourceConfigDedicated(enb_mod_idP,frameP,CH_index,
winckel's avatar
winckel committed
2858
  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated);
2859

winckel's avatar
winckel committed
2860 2861 2862 2863 2864 2865 2866
  }

  // check other fields for
  }
  }
*/

2867 2868 2869 2870 2871 2872 2873 2874
//-----------------------------------------------------------------------------
void
rrc_eNB_process_RRCConnectionReconfigurationComplete(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t*          const ue_context_pP,
  RRCConnectionReconfigurationComplete_r8_IEs_t* rrcConnectionReconfigurationComplete
)
//-----------------------------------------------------------------------------
2875 2876
{
  int                                 i;
2877
#ifdef PDCP_USE_NETLINK
2878 2879
  int                                 oip_ifup = 0;
  int                                 dest_ip_offset = 0;
2880
  module_id_t                         ue_module_id   = -1;
winckel's avatar
winckel committed
2881 2882
#endif

2883 2884 2885
  uint8_t                            *kRRCenc = NULL;
  uint8_t                            *kRRCint = NULL;
  uint8_t                            *kUPenc = NULL;
winckel's avatar
winckel committed
2886

2887 2888
  DRB_ToAddModList_t*                 DRB_configList = ue_context_pP->ue_context.DRB_configList;
  SRB_ToAddModList_t*                 SRB_configList = ue_context_pP->ue_context.SRB_configList;
winckel's avatar
winckel committed
2889 2890 2891

#if defined(ENABLE_SECURITY)

2892 2893
  /* Derive the keys from kenb */
  if (DRB_configList != NULL) {
2894 2895
    derive_key_up_enc(ue_context_pP->ue_context.ciphering_algorithm,
                      ue_context_pP->ue_context.kenb, &kUPenc);
2896 2897
  }

2898 2899 2900 2901
  derive_key_rrc_enc(ue_context_pP->ue_context.ciphering_algorithm,
                     ue_context_pP->ue_context.kenb, &kRRCenc);
  derive_key_rrc_int(ue_context_pP->ue_context.integrity_algorithm,
                     ue_context_pP->ue_context.kenb, &kRRCint);
2902

winckel's avatar
winckel committed
2903
#endif
Lionel Gauthier's avatar
Lionel Gauthier committed
2904
#ifdef ENABLE_RAL
2905 2906 2907 2908 2909 2910 2911
  {
    MessageDef                         *message_ral_p = NULL;
    rrc_ral_connection_reconfiguration_ind_t connection_reconfiguration_ind;
    int                                 i;

    message_ral_p = itti_alloc_new_message(TASK_RRC_ENB, RRC_RAL_CONNECTION_RECONFIGURATION_IND);
    memset(&connection_reconfiguration_ind, 0, sizeof(rrc_ral_connection_reconfiguration_ind_t));
2912
    connection_reconfiguration_ind.ue_id = ctxt_pP->rnti;
2913 2914 2915 2916 2917 2918 2919 2920 2921

    if (DRB_configList != NULL) {
      connection_reconfiguration_ind.num_drb = DRB_configList->list.count;

      for (i = 0; (i < DRB_configList->list.count) && (i < maxDRB); i++) {
        connection_reconfiguration_ind.drb_id[i] = DRB_configList->list.array[i]->drb_Identity;
      }
    } else {
      connection_reconfiguration_ind.num_drb = 0;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2922
    }
2923 2924 2925 2926 2927 2928 2929 2930 2931 2932

    if (SRB_configList != NULL) {
      connection_reconfiguration_ind.num_srb = SRB_configList->list.count;
    } else {
      connection_reconfiguration_ind.num_srb = 0;
    }

    memcpy(&message_ral_p->ittiMsg, (void *)&connection_reconfiguration_ind,
           sizeof(rrc_ral_connection_reconfiguration_ind_t));
    LOG_I(RRC, "Sending RRC_RAL_CONNECTION_RECONFIGURATION_IND to RAL\n");
2933
    itti_send_msg_to_task(TASK_RAL_ENB, ctxt_pP->instance, message_ral_p);
2934
  }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2935
#endif
2936
  // Refresh SRBs/DRBs
Lionel Gauthier's avatar
Lionel Gauthier committed
2937 2938 2939 2940 2941 2942 2943 2944 2945
  MSC_LOG_TX_MESSAGE(
    MSC_RRC_ENB,
    MSC_PDCP_ENB,
    NULL,
    0,
    MSC_AS_TIME_FMT" CONFIG_REQ UE %x DRB (security unchanged)",
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP->ue_context.rnti);

2946
  rrc_pdcp_config_asn1_req(
2947
    ctxt_pP,
2948 2949
    NULL,  //LG-RK 14/05/2014 SRB_configList,
    DRB_configList, (DRB_ToReleaseList_t *) NULL,
2950 2951
    /*eNB_rrc_inst[ctxt_pP->module_id].ciphering_algorithm[ue_mod_idP] |
             (eNB_rrc_inst[ctxt_pP->module_id].integrity_algorithm[ue_mod_idP] << 4),
2952 2953 2954 2955 2956
     */
    0xff, // already configured during the securitymodecommand
    kRRCenc,
    kRRCint,
    kUPenc
winckel's avatar
winckel committed
2957
#ifdef Rel10
2958 2959 2960 2961 2962
    , (PMCH_InfoList_r9_t *) NULL
#endif
  );
  // Refresh SRBs/DRBs
  rrc_rlc_config_asn1_req(
2963
    ctxt_pP,
2964 2965 2966
    NULL,  //LG-RK 14/05/2014 SRB_configList,
    DRB_configList,
    (DRB_ToReleaseList_t *) NULL
winckel's avatar
winckel committed
2967
#ifdef Rel10
2968
    , (PMCH_InfoList_r9_t *) NULL
winckel's avatar
winckel committed
2969
#endif
2970
  );
winckel's avatar
winckel committed
2971

2972
  // Loop through DRBs and establish if necessary
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2973

2974 2975 2976 2977
  if (DRB_configList != NULL) {
    for (i = 0; i < DRB_configList->list.count; i++) {  // num max DRB (11-3-8)
      if (DRB_configList->list.array[i]) {
        LOG_I(RRC,
2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989
              "[eNB %d] Frame  %d : Logical Channel UL-DCCH, Received RRCConnectionReconfigurationComplete from UE rnti %x, reconfiguring DRB %d/LCID %d\n",
              ctxt_pP->module_id,
              ctxt_pP->frame,
              ctxt_pP->rnti,
              (int)DRB_configList->list.array[i]->drb_Identity,
              (int)*DRB_configList->list.array[i]->logicalChannelIdentity);
        // for pre-ci tests
        LOG_I(RRC,
              "[eNB %d] Frame  %d : Logical Channel UL-DCCH, Received RRCConnectionReconfigurationComplete from UE %u, reconfiguring DRB %d/LCID %d\n",
              ctxt_pP->module_id,
              ctxt_pP->frame,
              oai_emulation.info.eNB_ue_local_uid_to_ue_module_id[ctxt_pP->module_id][ue_context_pP->local_uid],
2990
              (int)DRB_configList->list.array[i]->drb_Identity,
2991
              (int)*DRB_configList->list.array[i]->logicalChannelIdentity);
2992

2993
        if (ue_context_pP->ue_context.DRB_active[i] == 0) {
2994
          /*
2995
             rrc_pdcp_config_req (ctxt_pP->module_id, frameP, 1, CONFIG_ACTION_ADD,
2996
             (ue_mod_idP * NB_RB_MAX) + *DRB_configList->list.array[i]->logicalChannelIdentity,UNDEF_SECURITY_MODE);
2997 2998
             rrc_rlc_config_req(ctxt_pP->module_id,frameP,1,CONFIG_ACTION_ADD,
             (ue_mod_idP * NB_RB_MAX) + (int)*eNB_rrc_inst[ctxt_pP->module_id].DRB_config[ue_mod_idP][i]->logicalChannelIdentity,
2999 3000
             RADIO_ACCESS_BEARER,Rlc_info_um);
           */
3001
          ue_context_pP->ue_context.DRB_active[i] = 1;
3002 3003 3004

          LOG_D(RRC,
                "[eNB %d] Frame %d: Establish RLC UM Bidirectional, DRB %d Active\n",
3005 3006
                ctxt_pP->module_id, ctxt_pP->frame, (int)DRB_configList->list.array[i]->drb_Identity);
#if  defined(PDCP_USE_NETLINK) && !defined(LINK_ENB_PDCP_TO_GTPV1U)
3007
          // can mean also IPV6 since ether -> ipv6 autoconf
Raymond Knopp's avatar
 
Raymond Knopp committed
3008
#   if !defined(OAI_NW_DRIVER_TYPE_ETHERNET) && !defined(EXMIMO) && !defined(OAI_USRP)
3009 3010 3011
          LOG_I(OIP, "[eNB %d] trying to bring up the OAI interface oai%d\n",
                ctxt_pP->module_id,
                ctxt_pP->module_id);
3012
          oip_ifup = nas_config(
3013 3014 3015
                       ctxt_pP->module_id,   // interface index
                       ctxt_pP->module_id + 1,   // thrid octet
                       ctxt_pP->module_id + 1);  // fourth octet
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3016

3017
          if (oip_ifup == 0) {    // interface is up --> send a config the DRB
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3018
#      ifdef OAI_EMU
3019
            oai_emulation.info.oai_ifup[ctxt_pP->module_id] = 1;
3020
            dest_ip_offset = NB_eNB_INST;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3021
#      else
3022
            dest_ip_offset = 8;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3023
#      endif
3024 3025
            LOG_I(OIP,
                  "[eNB %d] Config the oai%d to send/receive pkt on DRB %d to/from the protocol stack\n",
3026 3027 3028
                  ctxt_pP->module_id, ctxt_pP->module_id,
                  (ue_context_pP->local_uid * maxDRB) + DRB_configList->list.array[i]->drb_Identity);
            ue_module_id = oai_emulation.info.eNB_ue_local_uid_to_ue_module_id[ctxt_pP->module_id][ue_context_pP->local_uid];
3029
            rb_conf_ipv4(0, //add
3030 3031 3032
                         ue_module_id,  //cx
                         ctxt_pP->module_id,    //inst
                         (ue_module_id * maxDRB) + DRB_configList->list.array[i]->drb_Identity, // RB
3033
                         0,    //dscp
3034 3035 3036 3037
                         ipv4_address(ctxt_pP->module_id + 1, ctxt_pP->module_id + 1),  //saddr
                         ipv4_address(ctxt_pP->module_id + 1, dest_ip_offset + ue_module_id + 1));  //daddr
            LOG_D(RRC, "[eNB %d] State = Attached (UE rnti %x module id %u)\n",
                  ctxt_pP->module_id, ue_context_pP->ue_context.rnti, ue_module_id);
3038 3039
          }

Lionel Gauthier's avatar
 
Lionel Gauthier committed
3040 3041
#   else
#      ifdef OAI_EMU
3042
          oai_emulation.info.oai_ifup[ctxt_pP->module_id] = 1;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3043 3044 3045 3046
#      endif
#   endif
#endif

3047
          LOG_D(RRC,
3048 3049
                PROTOCOL_RRC_CTXT_UE_FMT" RRC_eNB --- MAC_CONFIG_REQ  (DRB) ---> MAC_eNB\n",
                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
3050

3051
          if (DRB_configList->list.array[i]->logicalChannelIdentity) {
3052
            DRB2LCHAN[i] = (uint8_t) * DRB_configList->list.array[i]->logicalChannelIdentity;
3053
          }
3054 3055

          rrc_mac_config_req(
3056
            ctxt_pP->module_id,
3057
            ue_context_pP->ue_context.primaryCC_id,
3058
            ENB_FLAG_YES,
3059
            ue_context_pP->ue_context.rnti,
3060 3061
            0,
            (RadioResourceConfigCommonSIB_t *) NULL,
3062
            ue_context_pP->ue_context.physicalConfigDedicated,
3063
#ifdef Rel10
3064 3065 3066 3067
            (SCellToAddMod_r10_t *)NULL,
            //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
#endif
            (MeasObjectToAddMod_t **) NULL,
3068
            ue_context_pP->ue_context.mac_MainConfig,
3069 3070
            DRB2LCHAN[i],
            DRB_configList->list.array[i]->logicalChannelConfig,
3071
            ue_context_pP->ue_context.measGapConfig,
3072 3073 3074 3075
            (TDD_Config_t *) NULL,
            NULL,
            (uint8_t *) NULL,
            (uint16_t *) NULL, NULL, NULL, NULL, (MBSFN_SubframeConfigList_t *) NULL
winckel's avatar
winckel committed
3076
#ifdef Rel10
3077
            , 0, (MBSFN_AreaInfoList_r9_t *) NULL, (PMCH_InfoList_r9_t *) NULL
winckel's avatar
winckel committed
3078 3079
#endif
#ifdef CBA
3080
            , eNB_rrc_inst[ctxt_pP->module_id].num_active_cba_groups, eNB_rrc_inst[ctxt_pP->module_id].cba_rnti[0]
3081 3082 3083 3084 3085
#endif
          );

        } else {        // remove LCHAN from MAC/PHY

3086
          if (ue_context_pP->ue_context.DRB_active[i] == 1) {
3087
            // DRB has just been removed so remove RLC + PDCP for DRB
3088
            /*      rrc_pdcp_config_req (ctxt_pP->module_id, frameP, 1, CONFIG_ACTION_REMOVE,
3089 3090 3091
               (ue_mod_idP * NB_RB_MAX) + DRB2LCHAN[i],UNDEF_SECURITY_MODE);
             */
            rrc_rlc_config_req(
3092
              ctxt_pP,
3093 3094 3095 3096 3097 3098 3099
              SRB_FLAG_NO,
              MBMS_FLAG_NO,
              CONFIG_ACTION_REMOVE,
              DRB2LCHAN[i],
              Rlc_info_um);
          }

3100
          ue_context_pP->ue_context.DRB_active[i] = 0;
3101
          LOG_D(RRC,
3102 3103 3104
                PROTOCOL_RRC_CTXT_UE_FMT" RRC_eNB --- MAC_CONFIG_REQ  (DRB) ---> MAC_eNB\n",
                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
          rrc_mac_config_req(ctxt_pP->module_id,
3105
                             ue_context_pP->ue_context.primaryCC_id,
3106
                             ENB_FLAG_YES,
3107
                             ue_context_pP->ue_context.rnti,
3108 3109
                             0,
                             (RadioResourceConfigCommonSIB_t *) NULL,
3110
                             ue_context_pP->ue_context.physicalConfigDedicated,
3111
#ifdef Rel10
3112 3113 3114 3115
                             (SCellToAddMod_r10_t *)NULL,
                             //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
#endif
                             (MeasObjectToAddMod_t **) NULL,
3116
                             ue_context_pP->ue_context.mac_MainConfig,
3117 3118 3119 3120 3121
                             DRB2LCHAN[i],
                             (LogicalChannelConfig_t *) NULL,
                             (MeasGapConfig_t *) NULL,
                             (TDD_Config_t *) NULL,
                             NULL, (uint8_t *) NULL, (uint16_t *) NULL, NULL, NULL, NULL, NULL
winckel's avatar
winckel committed
3122
#ifdef Rel10
3123
                             , 0, (MBSFN_AreaInfoList_r9_t *) NULL, (PMCH_InfoList_r9_t *) NULL
winckel's avatar
winckel committed
3124 3125
#endif
#ifdef CBA
3126
                             , 0, 0
winckel's avatar
winckel committed
3127
#endif
3128
                            );
winckel's avatar
winckel committed
3129
        }
3130
      }
winckel's avatar
winckel committed
3131
    }
3132
  }
winckel's avatar
winckel committed
3133
}
3134

3135 3136 3137 3138
//-----------------------------------------------------------------------------
void
rrc_eNB_generate_RRCConnectionSetup(
  const protocol_ctxt_t* const ctxt_pP,
3139 3140
  rrc_eNB_ue_context_t*          const ue_context_pP,
  const int                    CC_id
3141 3142
)
//-----------------------------------------------------------------------------
3143
{
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3144

3145 3146 3147 3148
  LogicalChannelConfig_t             *SRB1_logicalChannelConfig;  //,*SRB2_logicalChannelConfig;
  SRB_ToAddModList_t                **SRB_configList;
  SRB_ToAddMod_t                     *SRB1_config;
  int                                 cnt;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3149

3150
  SRB_configList = &ue_context_pP->ue_context.SRB_configList;
3151
  eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].Srb0.Tx_buffer.payload_size =
3152 3153
    do_RRCConnectionSetup(ctxt_pP,
                          ue_context_pP,
3154
                          (uint8_t*) eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].Srb0.Tx_buffer.Payload,
3155
                          (mac_xface->lte_frame_parms->nb_antennas_tx==2)?2:1,
3156
                          rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),
3157
                          mac_xface->lte_frame_parms,
3158 3159
                          SRB_configList,
                          &ue_context_pP->ue_context.physicalConfigDedicated);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3160

3161
#ifdef RRC_MSG_PRINT
3162 3163
  LOG_F(RRC,"[MSG] RRC Connection Setup\n");

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

  LOG_F(RRC,"\n");
3169 3170 3171
  //////////////////////////////////
#endif

3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190
  // configure SRB1/SRB2, PhysicalConfigDedicated, MAC_MainConfig for UE

  if (*SRB_configList != NULL) {
    for (cnt = 0; cnt < (*SRB_configList)->list.count; cnt++) {
      if ((*SRB_configList)->list.array[cnt]->srb_Identity == 1) {
        SRB1_config = (*SRB_configList)->list.array[cnt];

        if (SRB1_config->logicalChannelConfig) {
          if (SRB1_config->logicalChannelConfig->present ==
              SRB_ToAddMod__logicalChannelConfig_PR_explicitValue) {
            SRB1_logicalChannelConfig = &SRB1_config->logicalChannelConfig->choice.explicitValue;
          } else {
            SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
          }
        } else {
          SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
        }

        LOG_D(RRC,
3191 3192 3193 3194
              PROTOCOL_RRC_CTXT_UE_FMT" RRC_eNB --- MAC_CONFIG_REQ  (SRB1) ---> MAC_eNB\n",
              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
        rrc_mac_config_req(
          ctxt_pP->module_id,
3195
          ue_context_pP->ue_context.primaryCC_id,
3196 3197 3198
          ENB_FLAG_YES,
          ue_context_pP->ue_context.rnti,
          0,
3199
          (RadioResourceConfigCommonSIB_t *) NULL,
3200
          ue_context_pP->ue_context.physicalConfigDedicated,
3201
#ifdef Rel10
3202 3203
          (SCellToAddMod_r10_t *)NULL,
          //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
3204
#endif
3205
          (MeasObjectToAddMod_t **) NULL,
3206
          ue_context_pP->ue_context.mac_MainConfig,
3207 3208
          1,
          SRB1_logicalChannelConfig,
3209
          ue_context_pP->ue_context.measGapConfig,
3210 3211 3212 3213
          (TDD_Config_t *) NULL,
          NULL,
          (uint8_t *) NULL,
          (uint16_t *) NULL, NULL, NULL, NULL, (MBSFN_SubframeConfigList_t *) NULL
winckel's avatar
winckel committed
3214
#ifdef Rel10
3215
          , 0, (MBSFN_AreaInfoList_r9_t *) NULL, (PMCH_InfoList_r9_t *) NULL
winckel's avatar
winckel committed
3216 3217
#endif
#ifdef CBA
3218
          , 0, 0
winckel's avatar
winckel committed
3219
#endif
3220
        );
3221 3222
        break;
      }
winckel's avatar
winckel committed
3223
    }
3224
  }
3225 3226

  MSC_LOG_TX_MESSAGE(
3227 3228
    MSC_RRC_ENB,
    MSC_RRC_UE,
3229 3230
    eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].Srb0.Tx_buffer.Header, // LG WARNING
    eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].Srb0.Tx_buffer.payload_size,
3231 3232 3233
    MSC_AS_TIME_FMT" RRCConnectionSetup UE %x size %u",
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP->ue_context.rnti,
3234
    eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].Srb0.Tx_buffer.payload_size);
3235

3236 3237

  LOG_I(RRC,
3238 3239
        PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel DL-CCCH, Generating RRCConnectionSetup (bytes %d)\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
3240
        eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].Srb0.Tx_buffer.payload_size);
3241

winckel's avatar
winckel committed
3242
}
3243

winckel's avatar
winckel committed
3244
#if defined(ENABLE_ITTI)
3245 3246 3247 3248 3249 3250
char
//-----------------------------------------------------------------------------
openair_rrc_lite_eNB_init(
  const module_id_t enb_mod_idP
)
//-----------------------------------------------------------------------------
3251 3252 3253
{
  /* Dummy function, initialization will be done through ITTI messaging */
  return 0;
winckel's avatar
winckel committed
3254
}
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3255 3256 3257
#endif

#if defined(ENABLE_ITTI)
3258 3259 3260 3261 3262 3263
//-----------------------------------------------------------------------------
char
openair_rrc_lite_eNB_configuration(
  const module_id_t enb_mod_idP,
  RrcConfigurationReq* configuration
)
winckel's avatar
winckel committed
3264
#else
3265 3266 3267 3268
char
openair_rrc_lite_eNB_init(
  const module_id_t enb_mod_idP
)
winckel's avatar
winckel committed
3269
#endif
3270
//-----------------------------------------------------------------------------
winckel's avatar
winckel committed
3271
{
3272
  protocol_ctxt_t ctxt;
3273 3274
  int             CC_id;

3275
  PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, enb_mod_idP, ENB_FLAG_YES, NOT_A_RNTI, 0, 0,enb_mod_idP);
3276 3277 3278
  LOG_I(RRC,
        PROTOCOL_RRC_CTXT_FMT" Init...\n",
        PROTOCOL_RRC_CTXT_ARGS(&ctxt));
3279

3280 3281
  AssertFatal(eNB_rrc_inst != NULL, "eNB_rrc_inst not initialized!");
  AssertFatal(NUMBER_OF_UE_MAX < (module_id_t)0xFFFFFFFFFFFFFFFF, " variable overflow");
winckel's avatar
winckel committed
3282

3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298
  //    for (j = 0; j < NUMBER_OF_UE_MAX; j++)
  //        eNB_rrc_inst[ctxt.module_id].Info.UE[j].Status = RRC_IDLE;  //CH_READY;
  //
  //#if defined(ENABLE_USE_MME)
  //    // Connect eNB to MME
  //    if (EPC_MODE_ENABLED <= 0)
  //#endif
  //    {
  //        /* Init security parameters */
  //        for (j = 0; j < NUMBER_OF_UE_MAX; j++) {
  //            eNB_rrc_inst[ctxt.module_id].ciphering_algorithm[j] = SecurityAlgorithmConfig__cipheringAlgorithm_eea0;
  //            eNB_rrc_inst[ctxt.module_id].integrity_algorithm[j] = SecurityAlgorithmConfig__integrityProtAlgorithm_eia2;
  //            rrc_lite_eNB_init_security(enb_mod_idP, j);
  //        }
  //    }
  eNB_rrc_inst[ctxt.module_id].Nb_ue = 0;
3299

3300 3301 3302
  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
    eNB_rrc_inst[ctxt.module_id].carrier[CC_id].Srb0.Active = 0;
  }
3303

3304 3305 3306 3307 3308 3309
  uid_linear_allocator_init(&eNB_rrc_inst[ctxt.module_id].uid_allocator);
  RB_INIT(&eNB_rrc_inst[ctxt.module_id].rrc_ue_head);
  RB_INIT(&eNB_rrc_inst[ctxt.module_id].rrc_rnti_head);
  //    for (j = 0; j < (NUMBER_OF_UE_MAX + 1); j++) {
  //        eNB_rrc_inst[enb_mod_idP].Srb2[j].Active = 0;
  //    }
3310

3311
  /// System Information INIT
3312

3313 3314
  LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Checking release \n",
        PROTOCOL_RRC_CTXT_ARGS(&ctxt));
3315 3316
#ifdef Rel10

3317
  // This has to come from some top-level configuration
3318
  // only CC_id 0 is logged
3319 3320
  LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Rel10 RRC detected, MBMS flag %d\n",
        PROTOCOL_RRC_CTXT_ARGS(&ctxt),
3321
        eNB_rrc_inst[ctxt.module_id].carrier[0].MBMS_flag);
3322

winckel's avatar
winckel committed
3323
#else
3324
  LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Rel8 RRC\n", PROTOCOL_RRC_CTXT_ARGS(&ctxt));
winckel's avatar
winckel committed
3325 3326
#endif
#ifdef CBA
3327

3328 3329 3330 3331
  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
    for (j = 0; j < NUM_MAX_CBA_GROUP; j++) {
      eNB_rrc_inst[ctxt.module_id].carrier[CC_id].cba_rnti[j] = CBA_OFFSET + j;
    }
3332

3333 3334 3335
    if (eNB_rrc_inst[ctxt.module_id].carrier[CC_id].num_active_cba_groups > NUM_MAX_CBA_GROUP) {
      eNB_rrc_inst[ctxt.module_id].carrier[CC_id].num_active_cba_groups = NUM_MAX_CBA_GROUP;
    }
3336

3337 3338 3339 3340 3341 3342 3343 3344 3345
    LOG_D(RRC,
          PROTOCOL_RRC_CTXT_FMT" Initialization of 4 cba_RNTI values (%x %x %x %x) num active groups %d\n",
          PROTOCOL_RRC_CTXT_ARGS(&ctxt),
          enb_mod_idP, eNB_rrc_inst[ctxt.module_id].carrier[CC_id].cba_rnti[0],
          eNB_rrc_inst[ctxt.module_id].carrier[CC_id].cba_rnti[1],
          eNB_rrc_inst[ctxt.module_id].carrier[CC_id].cba_rnti[2],
          eNB_rrc_inst[ctxt.module_id].carrier[CC_id].cba_rnti[3],
          eNB_rrc_inst[ctxt.module_id].carrier[CC_id].num_active_cba_groups);
  }
3346

winckel's avatar
winckel committed
3347
#endif
3348

3349 3350 3351
  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
    init_SI(&ctxt,
            CC_id
winckel's avatar
winckel committed
3352
#if defined(ENABLE_ITTI)
3353
            , configuration
winckel's avatar
winckel committed
3354
#endif
3355 3356
           );
  }
3357

winckel's avatar
winckel committed
3358
#ifdef Rel10
3359

3360 3361 3362 3363 3364 3365 3366 3367
  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
    switch (eNB_rrc_inst[ctxt.module_id].carrier[CC_id].MBMS_flag) {
    case 1:
    case 2:
    case 3:
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Configuring 1 MBSFN sync area\n", PROTOCOL_RRC_CTXT_ARGS(&ctxt));
      eNB_rrc_inst[ctxt.module_id].carrier[CC_id].num_mbsfn_sync_area = 1;
      break;
3368

3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385
    case 4:
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Configuring 2 MBSFN sync area\n", PROTOCOL_RRC_CTXT_ARGS(&ctxt));
      eNB_rrc_inst[ctxt.module_id].carrier[CC_id].num_mbsfn_sync_area = 2;
      break;

    default:
      eNB_rrc_inst[ctxt.module_id].carrier[CC_id].num_mbsfn_sync_area = 0;
      break;
    }

    // if we are here the eNB_rrc_inst[enb_mod_idP].MBMS_flag > 0,
    /// MCCH INIT
    if (eNB_rrc_inst[ctxt.module_id].carrier[CC_id].MBMS_flag > 0) {
      init_MCCH(ctxt.module_id, CC_id);
      /// MTCH data bearer init
      init_MBMS(ctxt.module_id, CC_id, 0);
    }
3386 3387
  }

winckel's avatar
winckel committed
3388
#endif
3389

winckel's avatar
winckel committed
3390
#ifdef NO_RRM                   //init ch SRB0, SRB1 & BDTCH
3391
  openair_rrc_on(&ctxt);
winckel's avatar
winckel committed
3392
#else
3393 3394
  eNB_rrc_inst[ctxt.module_id].Last_scan_req = 0;
  send_msg(&S_rrc, msg_rrc_phy_synch_to_MR_ind(ctxt.module_id, eNB_rrc_inst[ctxt.module_id].Mac_id));
winckel's avatar
winckel committed
3395
#endif
3396

3397
  return 0;
3398

winckel's avatar
winckel committed
3399
}
3400

winckel's avatar
winckel committed
3401
/*------------------------------------------------------------------------------*/
3402 3403 3404
int
rrc_eNB_decode_ccch(
  protocol_ctxt_t* const ctxt_pP,
3405 3406
  const SRB_INFO*        const Srb_info,
  const int              CC_id
3407 3408
)
//-----------------------------------------------------------------------------
3409
{
3410
  module_id_t                                   Idx;
3411 3412
  asn_dec_rval_t                      dec_rval;
  UL_CCCH_Message_t                  *ul_ccch_msg = NULL;
3413 3414
  RRCConnectionRequest_r8_IEs_t*                rrcConnectionRequest = NULL;
  RRCConnectionReestablishmentRequest_r8_IEs_t* rrcConnectionReestablishmentRequest = NULL;
3415
  int                                 i, rval;
3416 3417
  struct rrc_eNB_ue_context_s*                  ue_context_p = NULL;
  uint64_t                                      random_value = 0;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3418

3419
  //memset(ul_ccch_msg,0,sizeof(UL_CCCH_Message_t));
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3420

3421 3422 3423
  LOG_D(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Decoding UL CCCH %x.%x.%x.%x.%x.%x (%p)\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
        ((uint8_t*) Srb_info->Rx_buffer.Payload)[0],
3424 3425 3426 3427 3428
        ((uint8_t *) Srb_info->Rx_buffer.Payload)[1],
        ((uint8_t *) Srb_info->Rx_buffer.Payload)[2],
        ((uint8_t *) Srb_info->Rx_buffer.Payload)[3],
        ((uint8_t *) Srb_info->Rx_buffer.Payload)[4],
        ((uint8_t *) Srb_info->Rx_buffer.Payload)[5], (uint8_t *) Srb_info->Rx_buffer.Payload);
3429 3430 3431 3432 3433 3434 3435 3436
  dec_rval = uper_decode(
               NULL,
               &asn_DEF_UL_CCCH_Message,
               (void**)&ul_ccch_msg,
               (uint8_t*) Srb_info->Rx_buffer.Payload,
               100,
               0,
               0);
3437

winckel's avatar
winckel committed
3438
#if defined(ENABLE_ITTI)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3439
#   if defined(DISABLE_ITTI_XER_PRINT)
3440 3441
  {
    MessageDef                         *message_p;
3442

3443 3444
    message_p = itti_alloc_new_message(TASK_RRC_ENB, RRC_UL_CCCH_MESSAGE);
    memcpy(&message_p->ittiMsg, (void *)ul_ccch_msg, sizeof(RrcUlCcchMessage));
3445

3446
    itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, message_p);
3447
  }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3448
#   else
3449 3450 3451
  {
    char                                message_string[10000];
    size_t                              message_string_size;
3452

3453 3454 3455
    if ((message_string_size =
           xer_sprint(message_string, sizeof(message_string), &asn_DEF_UL_CCCH_Message, (void *)ul_ccch_msg)) > 0) {
      MessageDef                         *msg_p;
3456

3457 3458 3459
      msg_p = itti_alloc_new_message_sized(TASK_RRC_ENB, RRC_UL_CCCH, message_string_size + sizeof(IttiMsgText));
      msg_p->ittiMsg.rrc_ul_ccch.size = message_string_size;
      memcpy(&msg_p->ittiMsg.rrc_ul_ccch.text, message_string, message_string_size);
3460

3461
      itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3462
    }
3463
  }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3464 3465
#   endif
#endif
3466

3467
  for (i = 0; i < 8; i++) {
3468
    LOG_T(RRC, "%x.", ((uint8_t *) & ul_ccch_msg)[i]);
3469
  }
3470 3471

  if (dec_rval.consumed == 0) {
3472 3473 3474
    LOG_E(RRC,
          PROTOCOL_RRC_CTXT_UE_FMT" FATAL Error in receiving CCCH\n",
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
3475 3476 3477 3478
    return -1;
  }

  if (ul_ccch_msg->message.present == UL_CCCH_MessageType_PR_c1) {
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3479

3480
    switch (ul_ccch_msg->message.choice.c1.present) {
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3481

3482
    case UL_CCCH_MessageType__c1_PR_NOTHING:
3483 3484 3485
      LOG_I(RRC,
            PROTOCOL_RRC_CTXT_FMT" Received PR_NOTHING on UL-CCCH-Message\n",
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
3486
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3487

3488
    case UL_CCCH_MessageType__c1_PR_rrcConnectionReestablishmentRequest:
3489
#ifdef RRC_MSG_PRINT
3490 3491
      LOG_F(RRC,"[MSG] RRC Connection Reestablishement Request\n");

3492
      for (i = 0; i < Srb_info->Rx_buffer.payload_size; i++) {
3493
        LOG_F(RRC,"%02x ", ((uint8_t*)Srb_info->Rx_buffer.Payload)[i]);
3494
      }
3495 3496 3497 3498

      LOG_F(RRC,"\n");
#endif
      LOG_D(RRC,
3499 3500 3501 3502 3503 3504 3505
            PROTOCOL_RRC_CTXT_UE_FMT"MAC_eNB--- MAC_DATA_IND (rrcConnectionReestablishmentRequest on SRB0) --> RRC_eNB\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
      rrcConnectionReestablishmentRequest =
        &ul_ccch_msg->message.choice.c1.choice.rrcConnectionReestablishmentRequest.criticalExtensions.choice.rrcConnectionReestablishmentRequest_r8;
      LOG_I(RRC,
            PROTOCOL_RRC_CTXT_UE_FMT" RRCConnectionReestablishmentRequest cause %s\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526
            ((rrcConnectionReestablishmentRequest->reestablishmentCause == ReestablishmentCause_otherFailure) ?    "Other Failure" :
             (rrcConnectionReestablishmentRequest->reestablishmentCause == ReestablishmentCause_handoverFailure) ? "Handover Failure" :
             "reconfigurationFailure"));
      /*{
      uint64_t                            c_rnti = 0;

      memcpy(((uint8_t *) & c_rnti) + 3, rrcConnectionReestablishmentRequest.UE_identity.c_RNTI.buf,
      rrcConnectionReestablishmentRequest.UE_identity.c_RNTI.size);
      ue_mod_id = rrc_eNB_get_UE_index(enb_mod_idP, c_rnti);
      }

      if ((eNB_rrc_inst[enb_mod_idP].phyCellId == rrcConnectionReestablishmentRequest.UE_identity.physCellId) &&
      (ue_mod_id != UE_INDEX_INVALID)){
      rrc_eNB_generate_RRCConnectionReestablishement(enb_mod_idP, frameP, ue_mod_id);
      }else {
      rrc_eNB_generate_RRCConnectionReestablishementReject(enb_mod_idP, frameP, ue_mod_id);
      }
      */
      break;

    case UL_CCCH_MessageType__c1_PR_rrcConnectionRequest:
3527
#ifdef RRC_MSG_PRINT
3528 3529
      LOG_F(RRC,"[MSG] RRC Connection Request\n");

3530
      for (i = 0; i < Srb_info->Rx_buffer.payload_size; i++) {
3531
        LOG_F(RRC,"%02x ", ((uint8_t*)Srb_info->Rx_buffer.Payload)[i]);
3532
      }
3533 3534

      LOG_F(RRC,"\n");
3535
#endif
3536
      LOG_D(RRC,
3537 3538 3539 3540 3541 3542 3543 3544 3545
            PROTOCOL_RRC_CTXT_UE_FMT"MAC_eNB --- MAC_DATA_IND  (rrcConnectionRequest on SRB0) --> RRC_eNB\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
      ue_context_p = rrc_eNB_get_ue_context(
                       &eNB_rrc_inst[ctxt_pP->module_id],
                       ctxt_pP->rnti);

      if (ue_context_p != NULL) {
        // erase content
        rrc_eNB_free_mem_UE_context(ctxt_pP, ue_context_p);
3546 3547

        MSC_LOG_RX_DISCARDED_MESSAGE(
3548 3549 3550 3551 3552 3553 3554 3555 3556
          MSC_RRC_ENB,
          MSC_RRC_UE,
          Srb_info->Rx_buffer.Payload,
          dec_rval.consumed,
          MSC_AS_TIME_FMT" RRCConnectionRequest UE %x size %u (UE already in context)",
          MSC_AS_TIME_ARGS(ctxt_pP),
          ue_context_p->ue_context.rnti,
          dec_rval.consumed);
      } else {
3557 3558
        rrcConnectionRequest = &ul_ccch_msg->message.choice.c1.choice.rrcConnectionRequest.criticalExtensions.choice.rrcConnectionRequest_r8;
        {
3559 3560
          memcpy(((uint8_t*) & random_value) + 3,
                 rrcConnectionRequest->ue_Identity.choice.randomValue.buf,
3561
                 rrcConnectionRequest->ue_Identity.choice.randomValue.size);
3562
          ue_context_p = rrc_eNB_get_next_free_ue_context(ctxt_pP, random_value);
3563
        }
3564 3565 3566 3567
        LOG_D(RRC,
              PROTOCOL_RRC_CTXT_UE_FMT" UE context: %X\n",
              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
              ue_context_p);
3568

3569
        if (ue_context_p != NULL) {
3570 3571


winckel's avatar
winckel committed
3572
#if defined(ENABLE_ITTI)
3573
          /* Check s-TMSI presence in message */
3574
          ue_context_p->ue_context.Initialue_identity_s_TMSI.presence =
3575
            (rrcConnectionRequest->ue_Identity.present == InitialUE_Identity_PR_s_TMSI);
3576

3577
          if (ue_context_p->ue_context.Initialue_identity_s_TMSI.presence) {
3578 3579
            /* Save s-TMSI */
            S_TMSI_t                            s_TMSI = rrcConnectionRequest->ue_Identity.choice.s_TMSI;
3580

3581
            ue_context_p->ue_context.Initialue_identity_s_TMSI.mme_code =
3582
              BIT_STRING_to_uint8(&s_TMSI.mmec);
3583
            ue_context_p->ue_context.Initialue_identity_s_TMSI.m_tmsi =
3584
              BIT_STRING_to_uint32(&s_TMSI.m_TMSI);
3585 3586

            MSC_LOG_RX_DISCARDED_MESSAGE(
3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597
              MSC_RRC_ENB,
              MSC_RRC_UE,
              Srb_info->Rx_buffer.Payload,
              dec_rval.consumed,
              MSC_AS_TIME_FMT" RRCConnectionRequest UE %x size %u (s-TMSI mmec %u m_TMSI %u random UE id (0x%" PRIx64 ")",
              MSC_AS_TIME_ARGS(ctxt_pP),
              ue_context_p->ue_context.rnti,
              dec_rval.consumed,
              s_TMSI.mmec,
              s_TMSI.m_TMSI,
              ue_context_p->ue_context.random_ue_identity);
3598

3599
          } else {
3600
            MSC_LOG_RX_DISCARDED_MESSAGE(
3601 3602 3603 3604 3605 3606 3607 3608 3609
              MSC_RRC_ENB,
              MSC_RRC_UE,
              Srb_info->Rx_buffer.Payload,
              dec_rval.consumed,
              MSC_AS_TIME_FMT" RRCConnectionRequest UE %x size %u random UE id (0x%" PRIx64 ")",
              MSC_AS_TIME_ARGS(ctxt_pP),
              ue_context_p->ue_context.rnti,
              dec_rval.consumed,
              ue_context_p->ue_context.random_ue_identity);
3610
          }
3611

3612
          ue_context_p->ue_context.establishment_cause =
3613
            rrcConnectionRequest->establishmentCause;
3614 3615 3616 3617 3618 3619 3620 3621 3622 3623
          LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Accept new connection from UE random UE identity (0x%" PRIx64 ") MME code %u TMSI %u cause %u\n",
                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
                ue_context_p->ue_context.random_ue_identity,
                ue_context_p->ue_context.Initialue_identity_s_TMSI.mme_code,
                ue_context_p->ue_context.Initialue_identity_s_TMSI.m_tmsi,
                ue_context_p->ue_context.establishment_cause);
#else
          LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Accept new connection for UE random UE identity (0x%" PRIx64 ")\n",
                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
                ue_context_p->ue_context.random_ue_identity);
3624
#endif
3625
          eNB_rrc_inst[ctxt_pP->module_id].Nb_ue++;
3626

3627 3628 3629 3630
        } else {
          // no context available
          LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Can't create new context for UE random UE identity (0x%" PRIx64 ")\n",
                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
3631
                random_value);
3632 3633 3634
          return -1;
        }
      }
3635

winckel's avatar
winckel committed
3636
#ifndef NO_RRM
3637
      send_msg(&S_rrc, msg_rrc_MR_attach_ind(ctxt_pP->module_id, Mac_id));
winckel's avatar
winckel committed
3638
#else
3639

3640 3641
      ue_context_p->ue_context.primaryCC_id = CC_id;

3642 3643 3644
      //LG COMMENT Idx = (ue_mod_idP * NB_RB_MAX) + DCCH;
      Idx = DCCH;
      // SRB1
3645 3646 3647 3648
      ue_context_p->ue_context.Srb1.Active = 1;
      ue_context_p->ue_context.Srb1.Srb_info.Srb_id = Idx;
      memcpy(&ue_context_p->ue_context.Srb1.Srb_info.Lchan_desc[0],
             &DCCH_LCHAN_DESC,
3649
             LCHAN_DESC_SIZE);
3650 3651
      memcpy(&ue_context_p->ue_context.Srb1.Srb_info.Lchan_desc[1],
             &DCCH_LCHAN_DESC,
3652
             LCHAN_DESC_SIZE);
3653

3654
      // SRB2
3655 3656 3657 3658
      ue_context_p->ue_context.Srb2.Active = 1;
      ue_context_p->ue_context.Srb2.Srb_info.Srb_id = Idx;
      memcpy(&ue_context_p->ue_context.Srb2.Srb_info.Lchan_desc[0],
             &DCCH_LCHAN_DESC,
3659
             LCHAN_DESC_SIZE);
3660 3661
      memcpy(&ue_context_p->ue_context.Srb2.Srb_info.Lchan_desc[1],
             &DCCH_LCHAN_DESC,
3662
             LCHAN_DESC_SIZE);
3663

3664
      rrc_eNB_generate_RRCConnectionSetup(ctxt_pP, ue_context_p, CC_id);
3665 3666 3667
      LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT"CALLING RLC CONFIG SRB1 (rbid %d)\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            Idx);
Lionel Gauthier's avatar
Lionel Gauthier committed
3668 3669 3670 3671 3672 3673 3674 3675 3676 3677

      MSC_LOG_TX_MESSAGE(
        MSC_RRC_ENB,
        MSC_PDCP_ENB,
        NULL,
        0,
        MSC_AS_TIME_FMT" CONFIG_REQ UE %x SRB",
        MSC_AS_TIME_ARGS(ctxt_pP),
        ue_context_p->ue_context.rnti);

3678 3679
      rrc_pdcp_config_asn1_req(ctxt_pP,
                               ue_context_p->ue_context.SRB_configList,
3680
                               (DRB_ToAddModList_t *) NULL,
3681 3682 3683 3684 3685
                               (DRB_ToReleaseList_t*) NULL,
                               0xff,
                               NULL,
                               NULL,
                               NULL
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3686
#   ifdef Rel10
3687
                               , (PMCH_InfoList_r9_t *) NULL
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3688
#   endif
3689
                              );
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3690

3691 3692 3693 3694
      rrc_rlc_config_asn1_req(ctxt_pP,
                              ue_context_p->ue_context.SRB_configList,
                              (DRB_ToAddModList_t*) NULL,
                              (DRB_ToReleaseList_t*) NULL
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3695
#   ifdef Rel10
3696
                              , (PMCH_InfoList_r9_t *) NULL
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3697
#   endif
3698
                             );
winckel's avatar
winckel committed
3699
#endif //NO_RRM
3700 3701 3702 3703

      break;

    default:
3704 3705
      LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Unknown message\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
3706 3707
      rval = -1;
      break;
winckel's avatar
winckel committed
3708
    }
3709 3710 3711

    rval = 0;
  } else {
3712 3713
    LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT"  Unknown error \n",
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
3714 3715 3716 3717
    rval = -1;
  }

  return rval;
3718 3719
}

3720 3721 3722 3723 3724 3725 3726 3727 3728
//-----------------------------------------------------------------------------
int
rrc_eNB_decode_dcch(
  const protocol_ctxt_t* const ctxt_pP,
  const rb_id_t                Srb_id,
  const uint8_t*    const      Rx_sdu,
  const sdu_size_t             sdu_sizeP
)
//-----------------------------------------------------------------------------
3729
{
winckel's avatar
winckel committed
3730

3731 3732 3733 3734 3735
  asn_dec_rval_t                      dec_rval;
  //UL_DCCH_Message_t uldcchmsg;
  UL_DCCH_Message_t                  *ul_dcch_msg = NULL; //&uldcchmsg;
  UE_EUTRA_Capability_t              *UE_EUTRA_Capability = NULL;
  int i;
3736
  struct rrc_eNB_ue_context_s*        ue_context_p = NULL;
3737 3738

  if ((Srb_id != 1) && (Srb_id != 2)) {
3739 3740 3741
    LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Received message on SRB%d, should not have ...\n",
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
          Srb_id);
3742 3743 3744
  }

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

3746 3747 3748 3749 3750 3751 3752 3753 3754 3755
  LOG_D(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Decoding UL-DCCH Message\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
  dec_rval = uper_decode(
               NULL,
               &asn_DEF_UL_DCCH_Message,
               (void**)&ul_dcch_msg,
               Rx_sdu,
               sdu_sizeP,
               0,
               0);
3756

winckel's avatar
winckel committed
3757
#if defined(ENABLE_ITTI)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3758
#   if defined(DISABLE_ITTI_XER_PRINT)
3759 3760
  {
    MessageDef                         *message_p;
3761

3762 3763
    message_p = itti_alloc_new_message(TASK_RRC_ENB, RRC_UL_DCCH_MESSAGE);
    memcpy(&message_p->ittiMsg, (void *)ul_dcch_msg, sizeof(RrcUlDcchMessage));
3764

3765
    itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, message_p);
3766
  }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3767
#   else
3768 3769 3770
  {
    char                                message_string[10000];
    size_t                              message_string_size;
3771

3772 3773 3774
    if ((message_string_size =
           xer_sprint(message_string, sizeof(message_string), &asn_DEF_UL_DCCH_Message, (void *)ul_dcch_msg)) >= 0) {
      MessageDef                         *msg_p;
3775

3776 3777 3778
      msg_p = itti_alloc_new_message_sized(TASK_RRC_ENB, RRC_UL_DCCH, message_string_size + sizeof(IttiMsgText));
      msg_p->ittiMsg.rrc_ul_dcch.size = message_string_size;
      memcpy(&msg_p->ittiMsg.rrc_ul_dcch.text, message_string, message_string_size);
3779

3780
      itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
winckel's avatar
winckel committed
3781
    }
3782
  }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3783 3784
#   endif
#endif
3785

3786
  {
3787
    for (i = 0; i < sdu_sizeP; i++) {
3788
      LOG_T(RRC, "%x.", Rx_sdu[i]);
3789
    }
winckel's avatar
winckel committed
3790

3791 3792 3793 3794
    LOG_T(RRC, "\n");
  }

  if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0)) {
3795 3796 3797
    LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Failed to decode UL-DCCH (%d bytes)\n",
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
          dec_rval.consumed);
3798 3799
    return -1;
  }
3800

3801 3802 3803
  ue_context_p = rrc_eNB_get_ue_context(
                   &eNB_rrc_inst[ctxt_pP->module_id],
                   ctxt_pP->rnti);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3804

3805
  if (ul_dcch_msg->message.present == UL_DCCH_MessageType_PR_c1) {
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3806

3807 3808 3809
    switch (ul_dcch_msg->message.choice.c1.present) {
    case UL_DCCH_MessageType__c1_PR_NOTHING:   /* No components present */
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3810

3811 3812
    case UL_DCCH_MessageType__c1_PR_csfbParametersRequestCDMA2000:
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3813

3814 3815
    case UL_DCCH_MessageType__c1_PR_measurementReport:
      LOG_D(RRC,
3816 3817 3818 3819 3820 3821 3822 3823
            PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND "
            "%d bytes (measurementReport) ---> RRC_eNB\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            DCCH,
            sdu_sizeP);
      rrc_eNB_process_MeasurementReport(
        ctxt_pP,
        ue_context_p,
3824 3825
        &ul_dcch_msg->message.choice.c1.choice.measurementReport.
        criticalExtensions.choice.c1.choice.measurementReport_r8.measResults);
3826
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3827

3828
    case UL_DCCH_MessageType__c1_PR_rrcConnectionReconfigurationComplete:
3829
#ifdef RRC_MSG_PRINT
3830 3831
      LOG_F(RRC,"[MSG] RRC Connection Reconfiguration Complete\n");

3832
      for (i = 0; i < sdu_sizeP; i++) {
3833
        LOG_F(RRC,"%02x ", ((uint8_t*)Rx_sdu)[i]);
3834
      }
3835 3836

      LOG_F(RRC,"\n");
3837
#endif
3838
      MSC_LOG_RX_MESSAGE(
3839 3840 3841 3842 3843 3844 3845 3846
        MSC_RRC_ENB,
        MSC_RRC_UE,
        Rx_sdu,
        sdu_sizeP,
        MSC_AS_TIME_FMT" RRCConnectionReconfigurationComplete UE %x size %u",
        MSC_AS_TIME_ARGS(ctxt_pP),
        ue_context_p->ue_context.rnti,
        sdu_sizeP);
3847

3848
      LOG_D(RRC,
3849 3850 3851 3852 3853
            PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
            "(RRCConnectionReconfigurationComplete) ---> RRC_eNB]\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            DCCH,
            sdu_sizeP);
3854 3855 3856 3857

      if (ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.criticalExtensions.
          present ==
          RRCConnectionReconfigurationComplete__criticalExtensions_PR_rrcConnectionReconfigurationComplete_r8) {
3858 3859 3860
        rrc_eNB_process_RRCConnectionReconfigurationComplete(
          ctxt_pP,
          ue_context_p,
3861 3862 3863 3864
          &ul_dcch_msg->message.choice.c1.choice.
          rrcConnectionReconfigurationComplete.
          criticalExtensions.choice.
          rrcConnectionReconfigurationComplete_r8);
3865 3866 3867 3868
        ue_context_p->ue_context.Status = RRC_RECONFIGURED;
        LOG_I(RRC,
              PROTOCOL_RRC_CTXT_UE_FMT" UE State = RRC_RECONFIGURED \n",
              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
3869 3870
      }

Lionel Gauthier's avatar
 
Lionel Gauthier committed
3871 3872
#if defined(ENABLE_USE_MME)
#   if defined(ENABLE_ITTI)
3873 3874

      if (EPC_MODE_ENABLED == 1) {
3875 3876 3877
        rrc_eNB_send_S1AP_INITIAL_CONTEXT_SETUP_RESP(
          ctxt_pP,
          ue_context_p);
3878 3879
      }

Lionel Gauthier's avatar
 
Lionel Gauthier committed
3880 3881
#   endif
#endif
3882
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3883

3884
    case UL_DCCH_MessageType__c1_PR_rrcConnectionReestablishmentComplete:
3885
#ifdef RRC_MSG_PRINT
3886 3887
      LOG_F(RRC,"[MSG] RRC Connection Reestablishment Complete\n");

3888
      for (i = 0; i < sdu_sizeP; i++) {
3889
        LOG_F(RRC,"%02x ", ((uint8_t*)Rx_sdu)[i]);
3890
      }
3891 3892

      LOG_F(RRC,"\n");
3893
#endif
3894 3895

      MSC_LOG_RX_MESSAGE(
3896 3897 3898 3899 3900 3901 3902 3903
        MSC_RRC_ENB,
        MSC_RRC_UE,
        Rx_sdu,
        sdu_sizeP,
        MSC_AS_TIME_FMT" rrcConnectionReestablishmentComplete UE %x size %u",
        MSC_AS_TIME_ARGS(ctxt_pP),
        ue_context_p->ue_context.rnti,
        sdu_sizeP);
3904

3905
      LOG_I(RRC,
3906 3907 3908 3909 3910
            PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
            "(rrcConnectionReestablishmentComplete) ---> RRC_eNB\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            DCCH,
            sdu_sizeP);
3911 3912 3913
      break;

    case UL_DCCH_MessageType__c1_PR_rrcConnectionSetupComplete:
3914
#ifdef RRC_MSG_PRINT
3915 3916
      LOG_F(RRC,"[MSG] RRC Connection SetupComplete\n");

3917
      for (i = 0; i < sdu_sizeP; i++) {
3918
        LOG_F(RRC,"%02x ", ((uint8_t*)Rx_sdu)[i]);
3919
      }
3920 3921

      LOG_F(RRC,"\n");
3922
#endif
3923 3924

      MSC_LOG_RX_MESSAGE(
3925 3926 3927 3928 3929 3930 3931 3932
        MSC_RRC_ENB,
        MSC_RRC_UE,
        Rx_sdu,
        sdu_sizeP,
        MSC_AS_TIME_FMT" RRCConnectionSetupComplete UE %x size %u",
        MSC_AS_TIME_ARGS(ctxt_pP),
        ue_context_p->ue_context.rnti,
        sdu_sizeP);
3933

3934
      LOG_D(RRC,
3935 3936 3937 3938 3939
            PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
            "(RRCConnectionSetupComplete) ---> RRC_eNB\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            DCCH,
            sdu_sizeP);
3940 3941 3942 3943 3944 3945

      if (ul_dcch_msg->message.choice.c1.choice.rrcConnectionSetupComplete.criticalExtensions.present ==
          RRCConnectionSetupComplete__criticalExtensions_PR_c1) {
        if (ul_dcch_msg->message.choice.c1.choice.rrcConnectionSetupComplete.criticalExtensions.choice.c1.
            present ==
            RRCConnectionSetupComplete__criticalExtensions__c1_PR_rrcConnectionSetupComplete_r8) {
3946 3947 3948 3949 3950 3951 3952
          rrc_eNB_process_RRCConnectionSetupComplete(
            ctxt_pP,
            ue_context_p,
            &ul_dcch_msg->message.choice.c1.choice.rrcConnectionSetupComplete.criticalExtensions.choice.c1.choice.rrcConnectionSetupComplete_r8);
          ue_context_p->ue_context.Status = RRC_CONNECTED;
          LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" UE State = RRC_CONNECTED \n",
                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
3953 3954 3955 3956 3957 3958
        }
      }

      break;

    case UL_DCCH_MessageType__c1_PR_securityModeComplete:
3959
#ifdef RRC_MSG_PRINT
3960 3961
      LOG_F(RRC,"[MSG] RRC Security Mode Complete\n");

3962
      for (i = 0; i < sdu_sizeP; i++) {
3963
        LOG_F(RRC,"%02x ", ((uint8_t*)Rx_sdu)[i]);
3964
      }
3965 3966

      LOG_F(RRC,"\n");
3967
#endif
3968 3969

      MSC_LOG_RX_MESSAGE(
3970 3971 3972 3973 3974 3975 3976 3977
        MSC_RRC_ENB,
        MSC_RRC_UE,
        Rx_sdu,
        sdu_sizeP,
        MSC_AS_TIME_FMT" securityModeComplete UE %x size %u",
        MSC_AS_TIME_ARGS(ctxt_pP),
        ue_context_p->ue_context.rnti,
        sdu_sizeP);
3978

3979
      LOG_I(RRC,
3980 3981 3982
            PROTOCOL_RRC_CTXT_UE_FMT" received securityModeComplete on UL-DCCH %d from UE\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            DCCH);
3983
      LOG_D(RRC,
3984 3985 3986 3987 3988
            PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
            "(securityModeComplete) ---> RRC_eNB\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            DCCH,
            sdu_sizeP);
winckel's avatar
winckel committed
3989
#ifdef XER_PRINT
3990
      xer_fprint(stdout, &asn_DEF_UL_DCCH_Message, (void *)ul_dcch_msg);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3991
#endif
3992 3993 3994
      // confirm with PDCP about the security mode for DCCH
      //rrc_pdcp_config_req (enb_mod_idP, frameP, 1,CONFIG_ACTION_SET_SECURITY_MODE, (ue_mod_idP * NB_RB_MAX) + DCCH, 0x77);
      // continue the procedure
3995 3996 3997
      rrc_eNB_generate_UECapabilityEnquiry(
        ctxt_pP,
        ue_context_p);
3998
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3999

4000
    case UL_DCCH_MessageType__c1_PR_securityModeFailure:
4001
#ifdef RRC_MSG_PRINT
4002 4003
      LOG_F(RRC,"[MSG] RRC Security Mode Failure\n");

4004
      for (i = 0; i < sdu_sizeP; i++) {
4005
        LOG_F(RRC,"%02x ", ((uint8_t*)Rx_sdu)[i]);
4006
      }
4007 4008 4009

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

      MSC_LOG_RX_MESSAGE(
4012 4013 4014 4015 4016 4017 4018 4019
        MSC_RRC_ENB,
        MSC_RRC_UE,
        Rx_sdu,
        sdu_sizeP,
        MSC_AS_TIME_FMT" securityModeFailure UE %x size %u",
        MSC_AS_TIME_ARGS(ctxt_pP),
        ue_context_p->ue_context.rnti,
        sdu_sizeP);
4020

4021 4022 4023 4024 4025 4026
      LOG_W(RRC,
            PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
            "(securityModeFailure) ---> RRC_eNB\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            DCCH,
            sdu_sizeP);
winckel's avatar
winckel committed
4027
#ifdef XER_PRINT
4028
      xer_fprint(stdout, &asn_DEF_UL_DCCH_Message, (void *)ul_dcch_msg);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4029
#endif
4030
      // cancel the security mode in PDCP
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4031

4032
      // followup with the remaining procedure
4033
#warning "LG Removed rrc_eNB_generate_UECapabilityEnquiry after receiving securityModeFailure"
Raymond Knopp's avatar
Raymond Knopp committed
4034
      rrc_eNB_generate_UECapabilityEnquiry(ctxt_pP, ue_context_p);
4035
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4036

4037
    case UL_DCCH_MessageType__c1_PR_ueCapabilityInformation:
4038
#ifdef RRC_MSG_PRINT
4039 4040
      LOG_F(RRC,"[MSG] RRC UECapablility Information \n");

4041
      for (i = 0; i < sdu_sizeP; i++) {
4042
        LOG_F(RRC,"%02x ", ((uint8_t*)Rx_sdu)[i]);
4043
      }
4044 4045

      LOG_F(RRC,"\n");
4046
#endif
4047 4048

      MSC_LOG_RX_MESSAGE(
4049 4050 4051 4052 4053 4054 4055 4056
        MSC_RRC_ENB,
        MSC_RRC_UE,
        Rx_sdu,
        sdu_sizeP,
        MSC_AS_TIME_FMT" ueCapabilityInformation UE %x size %u",
        MSC_AS_TIME_ARGS(ctxt_pP),
        ue_context_p->ue_context.rnti,
        sdu_sizeP);
4057

4058
      LOG_I(RRC,
4059 4060 4061
            PROTOCOL_RRC_CTXT_UE_FMT" received ueCapabilityInformation on UL-DCCH %d from UE\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            DCCH);
4062
      LOG_D(RRC,
4063 4064 4065 4066 4067
            PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
            "(UECapabilityInformation) ---> RRC_eNB\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            DCCH,
            sdu_sizeP);
winckel's avatar
winckel committed
4068
#ifdef XER_PRINT
4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082
      xer_fprint(stdout, &asn_DEF_UL_DCCH_Message, (void *)ul_dcch_msg);
#endif
      dec_rval = uper_decode(NULL,
                             &asn_DEF_UE_EUTRA_Capability,
                             (void **)&UE_EUTRA_Capability,
                             ul_dcch_msg->message.choice.c1.choice.ueCapabilityInformation.criticalExtensions.
                             choice.c1.choice.ueCapabilityInformation_r8.ue_CapabilityRAT_ContainerList.list.
                             array[0]->ueCapabilityRAT_Container.buf,
                             ul_dcch_msg->message.choice.c1.choice.ueCapabilityInformation.criticalExtensions.
                             choice.c1.choice.ueCapabilityInformation_r8.ue_CapabilityRAT_ContainerList.list.
                             array[0]->ueCapabilityRAT_Container.size, 0, 0);
      //#ifdef XER_PRINT
      xer_fprint(stdout, &asn_DEF_UE_EUTRA_Capability, (void *)UE_EUTRA_Capability);
      //#endif
4083

4084
#if defined(ENABLE_USE_MME)
4085 4086

      if (EPC_MODE_ENABLED == 1) {
4087 4088 4089
        rrc_eNB_send_S1AP_UE_CAPABILITIES_IND(ctxt_pP,
                                              ue_context_p,
                                              ul_dcch_msg);
4090 4091
      }

4092 4093
#endif

4094 4095 4096
      rrc_eNB_generate_defaultRRCConnectionReconfiguration(ctxt_pP,
          ue_context_p,
          eNB_rrc_inst[ctxt_pP->module_id].HO_flag);
4097
      break;
4098

4099 4100
    case UL_DCCH_MessageType__c1_PR_ulHandoverPreparationTransfer:
      break;
4101

4102
    case UL_DCCH_MessageType__c1_PR_ulInformationTransfer:
4103
#ifdef RRC_MSG_PRINT
4104 4105
      LOG_F(RRC,"[MSG] RRC UL Information Transfer \n");

4106
      for (i = 0; i < sdu_sizeP; i++) {
4107
        LOG_F(RRC,"%02x ", ((uint8_t*)Rx_sdu)[i]);
4108
      }
4109 4110

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

4113 4114

      MSC_LOG_RX_MESSAGE(
4115 4116 4117 4118 4119 4120 4121 4122
        MSC_RRC_ENB,
        MSC_RRC_UE,
        Rx_sdu,
        sdu_sizeP,
        MSC_AS_TIME_FMT" ulInformationTransfer UE %x size %u",
        MSC_AS_TIME_ARGS(ctxt_pP),
        ue_context_p->ue_context.rnti,
        sdu_sizeP);
4123

winckel's avatar
winckel committed
4124
#if defined(ENABLE_USE_MME)
4125 4126

      if (EPC_MODE_ENABLED == 1) {
4127 4128 4129
        rrc_eNB_send_S1AP_UPLINK_NAS(ctxt_pP,
                                     ue_context_p,
                                     ul_dcch_msg);
4130 4131
      }

winckel's avatar
winckel committed
4132
#endif
4133
      break;
4134

4135 4136
    case UL_DCCH_MessageType__c1_PR_counterCheckResponse:
      break;
4137

winckel's avatar
winckel committed
4138
#ifdef Rel10
4139

4140 4141 4142 4143 4144
    case UL_DCCH_MessageType__c1_PR_ueInformationResponse_r9:
      break;

    case UL_DCCH_MessageType__c1_PR_proximityIndication_r9:
      break;
4145

4146 4147
    case UL_DCCH_MessageType__c1_PR_rnReconfigurationComplete_r10:
      break;
4148

4149 4150
    case UL_DCCH_MessageType__c1_PR_mbmsCountingResponse_r10:
      break;
winckel's avatar
winckel committed
4151

4152 4153
    case UL_DCCH_MessageType__c1_PR_interFreqRSTDMeasurementIndication_r10:
      break;
4154
#endif
4155

4156
    default:
4157 4158 4159
      LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Unknown message %s:%u\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            __FILE__, __LINE__);
4160
      return -1;
winckel's avatar
winckel committed
4161 4162
    }

4163 4164
    return 0;
  } else {
4165 4166 4167
    LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Unknown error %s:%u\n",
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
          __FILE__, __LINE__);
4168 4169 4170
    return -1;
  }

winckel's avatar
winckel committed
4171 4172
}

4173
#if defined(ENABLE_ITTI)
4174 4175 4176 4177 4178 4179
//-----------------------------------------------------------------------------
void*
rrc_enb_task(
  void* args_p
)
//-----------------------------------------------------------------------------
4180 4181 4182 4183 4184 4185
{
  MessageDef                         *msg_p;
  const char                         *msg_name_p;
  instance_t                          instance;
  int                                 result;
  SRB_INFO                           *srb_info_p;
4186
  int                                 CC_id;
4187

4188
  protocol_ctxt_t                     ctxt;
4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208
  itti_mark_task_ready(TASK_RRC_ENB);

  while (1) {
    // Wait for a message
    itti_receive_msg(TASK_RRC_ENB, &msg_p);

    msg_name_p = ITTI_MSG_NAME(msg_p);
    instance = ITTI_MSG_INSTANCE(msg_p);

    switch (ITTI_MSG_ID(msg_p)) {
    case TERMINATE_MESSAGE:
      itti_exit_task();
      break;

    case MESSAGE_TEST:
      LOG_I(RRC, "[eNB %d] Received %s\n", instance, msg_name_p);
      break;

      /* Messages from MAC */
    case RRC_MAC_CCCH_DATA_IND:
4209 4210 4211 4212 4213 4214 4215 4216 4217
      PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt,
                                    instance,
                                    ENB_FLAG_YES,
                                    RRC_MAC_CCCH_DATA_IND(msg_p).rnti,
                                    msg_p->ittiMsgHeader.lte_time.frame,
                                    msg_p->ittiMsgHeader.lte_time.slot);
      LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Received %s\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(&ctxt),
            msg_name_p);
4218

4219 4220
      CC_id = RRC_MAC_CCCH_DATA_IND(msg_p).CC_id;
      srb_info_p = &eNB_rrc_inst[instance].carrier[CC_id].Srb0;
4221

4222 4223
      memcpy(srb_info_p->Rx_buffer.Payload,
             RRC_MAC_CCCH_DATA_IND(msg_p).sdu,
4224 4225
             RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size);
      srb_info_p->Rx_buffer.payload_size = RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size;
4226
      rrc_eNB_decode_ccch(&ctxt, srb_info_p, CC_id);
4227 4228 4229 4230
      break;

      /* Messages from PDCP */
    case RRC_DCCH_DATA_IND:
4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243
      PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt,
                                    instance,
                                    ENB_FLAG_YES,
                                    RRC_DCCH_DATA_IND(msg_p).rnti,
                                    msg_p->ittiMsgHeader.lte_time.frame,
                                    msg_p->ittiMsgHeader.lte_time.slot);
      LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Received on DCCH %d %s\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(&ctxt),
            RRC_DCCH_DATA_IND(msg_p).dcch_index,
            msg_name_p);
      rrc_eNB_decode_dcch(&ctxt,
                          RRC_DCCH_DATA_IND(msg_p).dcch_index,
                          RRC_DCCH_DATA_IND(msg_p).sdu_p,
4244 4245 4246 4247 4248 4249
                          RRC_DCCH_DATA_IND(msg_p).sdu_size);

      // Message buffer has been processed, free it now.
      result = itti_free(ITTI_MSG_ORIGIN_ID(msg_p), RRC_DCCH_DATA_IND(msg_p).sdu_p);
      AssertFatal(result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4250 4251 4252

#   if defined(ENABLE_USE_MME)

4253 4254 4255 4256
      /* Messages from S1AP */
    case S1AP_DOWNLINK_NAS:
      rrc_eNB_process_S1AP_DOWNLINK_NAS(msg_p, msg_name_p, instance, &rrc_eNB_mui);
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4257

4258 4259 4260
    case S1AP_INITIAL_CONTEXT_SETUP_REQ:
      rrc_eNB_process_S1AP_INITIAL_CONTEXT_SETUP_REQ(msg_p, msg_name_p, instance);
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4261

4262 4263 4264
    case S1AP_UE_CTXT_MODIFICATION_REQ:
      rrc_eNB_process_S1AP_UE_CTXT_MODIFICATION_REQ(msg_p, msg_name_p, instance);
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4265

4266 4267 4268
    case S1AP_PAGING_IND:
      LOG_E(RRC, "[eNB %d] Received not yet implemented message %s\n", instance, msg_name_p);
      break;
4269

4270 4271 4272
    case S1AP_UE_CONTEXT_RELEASE_REQ:
      rrc_eNB_process_S1AP_UE_CONTEXT_RELEASE_REQ(msg_p, msg_name_p, instance);
      break;
4273

4274 4275 4276
    case S1AP_UE_CONTEXT_RELEASE_COMMAND:
      rrc_eNB_process_S1AP_UE_CONTEXT_RELEASE_COMMAND(msg_p, msg_name_p, instance);
      break;
4277

4278
    case GTPV1U_ENB_CREATE_TUNNEL_RESP:
4279 4280 4281 4282 4283 4284 4285
      PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt,
                                    instance,
                                    ENB_FLAG_YES,
                                    GTPV1U_ENB_CREATE_TUNNEL_RESP(msg_p).rnti,
                                    msg_p->ittiMsgHeader.lte_time.frame,
                                    msg_p->ittiMsgHeader.lte_time.slot);
      rrc_eNB_process_GTPV1U_CREATE_TUNNEL_RESP(&ctxt, msg_p, msg_name_p);
4286 4287 4288 4289 4290 4291 4292
      break;

    case GTPV1U_ENB_DELETE_TUNNEL_RESP:
      /* Nothing to do. Apparently everything is done in S1AP processing */
      //LOG_I(RRC, "[eNB %d] Received message %s, not processed because procedure not synched\n",
      //instance, msg_name_p);
      break;
Lionel Gauthier's avatar
Lionel Gauthier committed
4293

Lionel Gauthier's avatar
 
Lionel Gauthier committed
4294 4295
#   endif

4296 4297 4298
      /* Messages from eNB app */
    case RRC_CONFIGURATION_REQ:
      LOG_I(RRC, "[eNB %d] Received %s\n", instance, msg_name_p);
4299
      openair_rrc_lite_eNB_configuration(ENB_INSTANCE_TO_MODULE_ID(instance), &RRC_CONFIGURATION_REQ(msg_p));
4300
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4301 4302

#   ifdef ENABLE_RAL
4303 4304 4305 4306

    case RRC_RAL_CONFIGURE_THRESHOLD_REQ:
      rrc_enb_ral_handle_configure_threshold_request(instance, msg_p);
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4307 4308
#   endif

4309 4310 4311
      //SPECTRA: Add the RRC connection reconfiguration with Second cell configuration
    case RRC_RAL_CONNECTION_RECONFIGURATION_REQ:
      //                 ue_mod_id = 0; /* TODO force ue_mod_id to first UE, NAS UE not virtualized yet */
4312 4313 4314 4315 4316 4317 4318
#warning "TODO GET RIGHT RNTI"
      PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt,
                                    instance,
                                    ENB_FLAG_YES,
                                    NOT_A_RNTI, // TO DO GET RIGHT RNTI
                                    msg_p->ittiMsgHeader.lte_time.frame,
                                    msg_p->ittiMsgHeader.lte_time.slot);
4319 4320
      LOG_I(RRC, "[eNB %d] Send RRC_RAL_CONNECTION_RECONFIGURATION_REQ to UE %s\n", instance, msg_name_p);
      //Method RRC connection reconfiguration command with Second cell configuration
4321
#   ifdef ENABLE_RAL
4322
      //rrc_eNB_generate_RRCConnectionReconfiguration_SCell(instance, 0/* TODO put frameP number ! */, /*ue_mod_id force ue_mod_id to first UE*/0, 36126);
4323
#   else
4324 4325
      //rrc_eNB_generate_defaultRRCConnectionReconfiguration(instance, 0/* TODO put frameP number ! */, /*ue_mod_id force ue_mod_id to first UE*/0,
      //                                                     eNB_rrc_inst[instance].HO_flag);
4326
#   endif
4327
      break;
4328

4329 4330 4331
    default:
      LOG_E(RRC, "[eNB %d] Received unexpected message %s\n", instance, msg_name_p);
      break;
4332
    }
4333 4334 4335 4336 4337

    result = itti_free(ITTI_MSG_ORIGIN_ID(msg_p), msg_p);
    AssertFatal(result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
    msg_p = NULL;
  }
4338 4339
}
#endif
winckel's avatar
winckel committed
4340 4341

#ifndef USER_MODE
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4342
EXPORT_SYMBOL(Rlc_info_am_config);
winckel's avatar
winckel committed
4343
#endif