rrc_eNB.c 172 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 33
 * \author Navid Nikaein and  Raymond Knopp 
 * \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 62 63
#include "rlc.h"
#include "SIMULATION/ETH_TRANSPORT/extern.h"

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

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

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

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

87 88 89
#include "pdcp.h"

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

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

97 98 99
//#define XER_PRINT

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

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

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

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

winckel's avatar
winckel committed
118
/*------------------------------------------------------------------------------*/
Lionel Gauthier's avatar
 
Lionel Gauthier committed
119 120
static void init_SI(
    module_id_t enb_mod_idP
winckel's avatar
winckel committed
121
#if defined(ENABLE_ITTI)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
122 123
    ,
    RrcConfigurationReq * configuration
winckel's avatar
winckel committed
124
#endif
Lionel Gauthier's avatar
 
Lionel Gauthier committed
125 126 127
    ) {
    uint8_t                             SIwindowsize = 1;
    uint16_t                            SIperiod = 8;
128
#ifdef Rel10
Lionel Gauthier's avatar
 
Lionel Gauthier committed
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
    int                                 i;
#endif
    /*
       uint32_t mib=0;
       int i;
       int N_RB_DL,phich_resource;

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

       for (i=0;i<1024;i+=4)
       do_MIB(enb_mod_idP, mac_xface->lte_frame_parms,i,&mib);

       N_RB_DL=6;
       while (N_RB_DL != 0) {
       phich_resource = 1;
       while (phich_resource != 0) {
       for (i=0;i<2;i++) {
       mac_xface->lte_frame_parms->N_RB_DL = N_RB_DL;
       mac_xface->lte_frame_parms->phich_config_common.phich_duration=i;
       mac_xface->lte_frame_parms->phich_config_common.phich_resource = phich_resource;
       do_MIB(enb_mod_idP, mac_xface->lte_frame_parms,0,&mib);
       }
       if (phich_resource == 1)
       phich_resource = 3;
       else if (phich_resource == 3)
       phich_resource = 6;
       else if (phich_resource == 6)
       phich_resource = 12;
       else if (phich_resource == 12)
       phich_resource = 0;
       }
       if (N_RB_DL == 6)
       N_RB_DL = 15;
       else if (N_RB_DL == 15)
       N_RB_DL = 25;
       else if (N_RB_DL == 25)
       N_RB_DL = 50;
       else if (N_RB_DL == 50)
       N_RB_DL = 75;
       else if (N_RB_DL == 75)
       N_RB_DL = 100;
       else if (N_RB_DL == 100)
       N_RB_DL = 0;
       }
       exit(-1);
     */

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

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

    /*
       printf ("before SIB1 init : Nid_cell %d\n", mac_xface->lte_frame_parms->Nid_cell);
       printf ("before SIB1 init : frame_type %d,tdd_config %d\n",
       mac_xface->lte_frame_parms->frame_type,
       mac_xface->lte_frame_parms->tdd_config);
     */

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

    eNB_rrc_inst[enb_mod_idP].SIB23 = (uint8_t *) malloc16(64);
    if (eNB_rrc_inst[enb_mod_idP].SIB23) {
        eNB_rrc_inst[enb_mod_idP].sizeof_SIB23 = do_SIB23(enb_mod_idP,
                                                     mac_xface->lte_frame_parms,
                                                     eNB_rrc_inst[enb_mod_idP].SIB23,
                                                     &eNB_rrc_inst[enb_mod_idP].systemInformation,
                                                     &eNB_rrc_inst[enb_mod_idP].sib2, &eNB_rrc_inst[enb_mod_idP].sib3
216
#ifdef Rel10
Lionel Gauthier's avatar
 
Lionel Gauthier committed
217
                                                     , &eNB_rrc_inst[enb_mod_idP].sib13, eNB_rrc_inst[enb_mod_idP].MBMS_flag
218 219
#endif
#if defined(ENABLE_ITTI)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
                                                     , configuration
#endif
            );
        /*
           eNB_rrc_inst[enb_mod_idP].sizeof_SIB23 = do_SIB2_AT4(enb_mod_idP,
           eNB_rrc_inst[enb_mod_idP].SIB23,
           &eNB_rrc_inst[enb_mod_idP].systemInformation,
           &eNB_rrc_inst[enb_mod_idP].sib2,
           #if defined(ENABLE_ITTI)
           , configuration
           #endif
           );
         */
        if (eNB_rrc_inst[enb_mod_idP].sizeof_SIB23 == 255)
            mac_xface->macphy_exit("[RRC][init_SI] FATAL, eNB_rrc_inst[enb_mod_idP].sizeof_SIB23 == 255");

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

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

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

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

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

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

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

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

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

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

    // ??Configure MCCH logical channel
    // call mac_config_req with appropriate structure from ASN.1 description

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

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

409 410
}

winckel's avatar
winckel committed
411
/*------------------------------------------------------------------------------*/
Lionel Gauthier's avatar
 
Lionel Gauthier committed
412 413 414
static void init_MBMS(
    module_id_t enb_mod_idP,
    frame_t frameP) {
415
    // init the configuration for MTCH
Lionel Gauthier's avatar
 
Lionel Gauthier committed
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433

    if (eNB_rrc_inst[enb_mod_idP].MBMS_flag > 0) {

        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

        rrc_pdcp_config_asn1_req(enb_mod_idP, 0, frameP, 1, NULL,    // SRB_ToAddModList
                                 NULL,  // DRB_ToAddModList
                                 (DRB_ToReleaseList_t *) NULL, 0,   // security mode
                                 NULL,  // key rrc encryption
                                 NULL,  // key rrc integrity
                                 NULL   // key encryption
#   ifdef Rel10
                                 , &(eNB_rrc_inst[enb_mod_idP].mcch_message->pmch_InfoList_r9)
#   endif
            );

        rrc_rlc_config_asn1_req(enb_mod_idP, 0, frameP, ENB_FLAG_YES, NULL, // SRB_ToAddModList
434
                                NULL,   // DRB_ToAddModList
Lionel Gauthier's avatar
 
Lionel Gauthier committed
435 436 437 438 439
                                NULL,   // DRB_ToReleaseList
                                &(eNB_rrc_inst[enb_mod_idP].mcch_message->pmch_InfoList_r9));

        //rrc_mac_config_req();
    }
440 441 442
}
#endif

winckel's avatar
winckel committed
443
/*------------------------------------------------------------------------------*/
Lionel Gauthier's avatar
 
Lionel Gauthier committed
444 445 446
static void rrc_lite_eNB_init_security(
    module_id_t enb_mod_idP,
    module_id_t ue_mod_idP) {
winckel's avatar
winckel committed
447
#if defined(ENABLE_SECURITY)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
448 449
    char                                ascii_buffer[65];
    uint8_t                             i;
winckel's avatar
winckel committed
450

Lionel Gauthier's avatar
 
Lionel Gauthier committed
451
    memset(eNB_rrc_inst[enb_mod_idP].kenb[ue_mod_idP], ue_mod_idP, 32);
winckel's avatar
winckel committed
452 453

    for (i = 0; i < 32; i++) {
Lionel Gauthier's avatar
 
Lionel Gauthier committed
454
        sprintf(&ascii_buffer[2 * i], "%02X", eNB_rrc_inst[enb_mod_idP].kenb[ue_mod_idP][i]);
winckel's avatar
winckel committed
455
    }
456
    ascii_buffer[2 * i] = '\0';
winckel's avatar
winckel committed
457

Lionel Gauthier's avatar
 
Lionel Gauthier committed
458
    LOG_T(RRC, "[OSA][eNB %d][UE %d] kenb    = %s\n", enb_mod_idP, ue_mod_idP, ascii_buffer);
winckel's avatar
winckel committed
459 460 461
#endif
}

462
/*------------------------------------------------------------------------------*/
Lionel Gauthier's avatar
 
Lionel Gauthier committed
463 464 465
uint8_t rrc_eNB_get_next_transaction_identifier(
    module_id_t enb_mod_idP) {
    static uint8_t                      rrc_transaction_identifier[NUMBER_OF_eNB_MAX];
winckel's avatar
RRC:  
winckel committed
466

Lionel Gauthier's avatar
 
Lionel Gauthier committed
467
    rrc_transaction_identifier[enb_mod_idP] = (rrc_transaction_identifier[enb_mod_idP] + 1) % RRC_TRANSACTION_IDENTIFIER_NUMBER;
winckel's avatar
RRC:  
winckel committed
468

Lionel Gauthier's avatar
 
Lionel Gauthier committed
469
    return rrc_transaction_identifier[enb_mod_idP];
winckel's avatar
RRC:  
winckel committed
470 471
}

472 473
/*------------------------------------------------------------------------------*/
/* Functions to handle UE index in eNB UE list */
winckel's avatar
winckel committed
474

475 476 477 478 479 480 481 482 483 484 485 486

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) {
hrizi's avatar
 
hrizi committed
487 488 489
	// UE_identity already registered
	reg = TRUE;
	break;
490 491 492 493 494 495 496 497 498
      }
    }
    
    if (reg == FALSE) {
      return (UE_MODULE_INVALID);
    } else
      return (i);
}

Lionel Gauthier's avatar
 
Lionel Gauthier committed
499 500 501
static module_id_t rrc_eNB_get_next_free_UE_index(
    module_id_t enb_mod_idP,
    uint64_t UE_identity) {
502

Lionel Gauthier's avatar
 
Lionel Gauthier committed
503 504
    boolean_t      reg = FALSE;
    module_id_t    i, first_index = UE_MODULE_INVALID;
505

506 507 508
    LOG_D(RRC,"ENB_ID= %d \n",enb_mod_idP);
    LOG_D(RRC,"N_ID= %d \n",NB_eNB_INST);

Lionel Gauthier's avatar
 
Lionel Gauthier committed
509 510 511 512
    AssertFatal(enb_mod_idP < NB_eNB_INST, "eNB index invalid (%d/%d)!", enb_mod_idP, NB_eNB_INST);

    for (i = 0; i < NUMBER_OF_UE_MAX; i++) {
        if ((first_index == UE_MODULE_INVALID) && (eNB_rrc_inst[enb_mod_idP].Info.UE_list[i] == 0)) {
hrizi's avatar
 
hrizi committed
513
	  first_index = i;    // save first free position
Lionel Gauthier's avatar
 
Lionel Gauthier committed
514
        }
515

Lionel Gauthier's avatar
 
Lionel Gauthier committed
516 517
        if (eNB_rrc_inst[enb_mod_idP].Info.UE_list[i] == UE_identity) {
            // UE_identity already registered
hrizi's avatar
 
hrizi committed
518
	  reg = TRUE;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
519
        }
520 521
    }

Lionel Gauthier's avatar
 
Lionel Gauthier committed
522
    if (reg == 0) {
523 524 525 526
      LOG_I(RRC, "[eNB %d] Adding UE %d with identity " PRIu64 "\n", enb_mod_idP, first_index, UE_identity);
      return (first_index);
    } else
      return (UE_MODULE_INVALID);
527 528
}

Lionel Gauthier's avatar
 
Lionel Gauthier committed
529 530 531 532 533 534 535
void rrc_eNB_free_UE_index(
    module_id_t enb_mod_idP,
    module_id_t ue_mod_idP) {
    AssertFatal(enb_mod_idP < NB_eNB_INST, "eNB inst invalid (%d/%d) for UE %d!", enb_mod_idP, NB_eNB_INST, ue_mod_idP);
    AssertFatal(ue_mod_idP < NUMBER_OF_UE_MAX, "UE inst invalid (%d/%d) for eNB %d!", ue_mod_idP, NUMBER_OF_UE_MAX,
                enb_mod_idP);

536
    LOG_W(RRC, "[eNB %d] Removing UE %d rv 0x%" PRIx64 "\n", enb_mod_idP, ue_mod_idP,
Lionel Gauthier's avatar
 
Lionel Gauthier committed
537 538 539
          eNB_rrc_inst[enb_mod_idP].Info.UE_list[ue_mod_idP]);
    eNB_rrc_inst[enb_mod_idP].Info.UE[ue_mod_idP].Status = RRC_IDLE;
    eNB_rrc_inst[enb_mod_idP].Info.UE_list[ue_mod_idP] = 0;
540
    free(eNB_rrc_inst[enb_mod_idP].SRB_configList[ue_mod_idP]);
541 542
}

winckel's avatar
winckel committed
543
/*------------------------------------------------------------------------------*/
Lionel Gauthier's avatar
 
Lionel Gauthier committed
544 545 546 547 548 549 550 551
void rrc_eNB_process_RRCConnectionSetupComplete(
    module_id_t enb_mod_idP,
    frame_t     frameP,
    module_id_t ue_mod_idP,
    RRCConnectionSetupComplete_r8_IEs_t * rrcConnectionSetupComplete) {
    LOG_I(RRC,
          "[eNB %d][RAPROC] Frame %d : Logical Channel UL-DCCH, " "processing RRCConnectionSetupComplete from UE %d\n",
          enb_mod_idP, frameP, ue_mod_idP);
winckel's avatar
winckel committed
552 553

#if defined(ENABLE_USE_MME)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
554 555 556 557
    if (EPC_MODE_ENABLED == 1) {
        // Forward message to S1AP layer
        rrc_eNB_send_S1AP_NAS_FIRST_REQ(enb_mod_idP, ue_mod_idP, rrcConnectionSetupComplete);
    } else
winckel's avatar
winckel committed
558
#endif
Lionel Gauthier's avatar
 
Lionel Gauthier committed
559 560 561 562 563
    {
        // RRC loop back (no S1AP), send SecurityModeCommand to UE
        rrc_eNB_generate_SecurityModeCommand(enb_mod_idP, frameP, ue_mod_idP);
        // rrc_eNB_generate_UECapabilityEnquiry(enb_mod_idP,frameP,ue_mod_idP);
    }
winckel's avatar
winckel committed
564 565
}

566
/*------------------------------------------------------------------------------*/
Lionel Gauthier's avatar
 
Lionel Gauthier committed
567 568 569 570 571 572 573 574
void rrc_eNB_generate_SecurityModeCommand(
    module_id_t enb_mod_idP,
    frame_t     frameP,
    module_id_t ue_mod_idP) {
    uint8_t                             buffer[100];
    uint8_t                             size;

    size = do_SecurityModeCommand(enb_mod_idP, buffer, ue_mod_idP, rrc_eNB_get_next_transaction_identifier(enb_mod_idP),
hrizi's avatar
 
hrizi committed
575
				  eNB_rrc_inst[enb_mod_idP].ciphering_algorithm[ue_mod_idP],
Lionel Gauthier's avatar
 
Lionel Gauthier committed
576 577
                                  eNB_rrc_inst[enb_mod_idP].integrity_algorithm[ue_mod_idP]);

578
#ifdef RRC_MSG_PRINT
579 580
    uint16_t i=0;
    LOG_F(RRC,"[MSG] RRC Security Mode Command\n");
581 582 583 584 585
    for (i = 0; i < size; i++)
      LOG_F(RRC,"%02x ", ((uint8_t*)buffer)[i]);
    LOG_F(RRC,"\n");
#endif

Lionel Gauthier's avatar
 
Lionel Gauthier committed
586 587 588 589 590 591 592 593 594
    LOG_I(RRC,
          "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate SecurityModeCommand (bytes %d, UE id %d)\n",
          enb_mod_idP, frameP, size, ue_mod_idP);

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

}

598
/*------------------------------------------------------------------------------*/
Lionel Gauthier's avatar
 
Lionel Gauthier committed
599 600 601 602
void rrc_eNB_generate_UECapabilityEnquiry(
    module_id_t enb_mod_idP,
    frame_t     frameP,
    module_id_t ue_mod_idP) {
603

Lionel Gauthier's avatar
 
Lionel Gauthier committed
604 605
    uint8_t                             buffer[100];
    uint8_t                             size;
606

Lionel Gauthier's avatar
 
Lionel Gauthier committed
607
    size = do_UECapabilityEnquiry(enb_mod_idP, buffer, ue_mod_idP, rrc_eNB_get_next_transaction_identifier(enb_mod_idP));
winckel's avatar
winckel committed
608

Lionel Gauthier's avatar
 
Lionel Gauthier committed
609 610 611
    LOG_I(RRC,
          "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate UECapabilityEnquiry (bytes %d, UE id %d)\n",
          enb_mod_idP, frameP, size, ue_mod_idP);
winckel's avatar
winckel committed
612

Lionel Gauthier's avatar
 
Lionel Gauthier committed
613 614 615 616 617
    LOG_D(RRC,
          "[FRAME %05d][RRC_eNB][MOD %02d][][--- PDCP_DATA_REQ/%d Bytes (UECapabilityEnquiry to UE %d MUI %d) --->][PDCP][MOD %02d][RB %02d]\n",
          frameP, enb_mod_idP, size, ue_mod_idP, rrc_eNB_mui, enb_mod_idP, DCCH);
    //rrc_rlc_data_req(enb_mod_idP,frameP, 1,(ue_mod_idP*NB_RB_MAX)+DCCH,rrc_eNB_mui++,0,size,(char*)buffer);
    pdcp_rrc_data_req(enb_mod_idP, ue_mod_idP, frameP, 1, DCCH, rrc_eNB_mui++, 0, size, buffer, 1);
618 619 620

}

Raymond Knopp's avatar
 
Raymond Knopp committed
621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642
void rrc_eNB_generate_RRCConnectionRelease(module_id_t enb_mod_idP,
					   frame_t frameP,
					   ue_id_t ue_idP) {

    uint8_t                             buffer[RRC_BUF_SIZE];
    uint16_t                            size;

    memset(buffer, 0, RRC_BUF_SIZE);

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

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

    LOG_D(RRC,
          "[FRAME %05d][RRC_eNB][MOD %u/%u][][--- PDCP_DATA_REQ/%d Bytes (rrcConnectionRelease to UE %d MUI %d) --->][PDCP][MOD %u/%u][RB %u]\n",
          frameP, enb_mod_idP, ue_idP, size, ue_idP, rrc_eNB_mui, enb_mod_idP, ue_idP, DCCH);
    //rrc_rlc_data_req(enb_mod_idP,frameP, 1,(ue_idP*NB_RB_MAX)+DCCH,rrc_eNB_mui++,0,size,(char*)buffer);
    pdcp_rrc_data_req(enb_mod_idP, ue_idP, frameP, 1, DCCH, rrc_eNB_mui++, 0, size, buffer, 1);
}
						  
643
/*------------------------------------------------------------------------------*/
Lionel Gauthier's avatar
 
Lionel Gauthier committed
644
static void rrc_eNB_generate_defaultRRCConnectionReconfiguration(
Raymond Knopp's avatar
 
Raymond Knopp committed
645 646 647 648
								 module_id_t enb_mod_idP,
								 frame_t     frameP,
								 module_id_t ue_mod_idP,
								 uint8_t ho_state) {
649
#if defined(ENABLE_ITTI)
Raymond Knopp's avatar
 
Raymond Knopp committed
650
  eNB_RRC_UE_INFO                    *UE_info = &eNB_rrc_inst[enb_mod_idP].Info.UE[ue_mod_idP];
Lionel Gauthier's avatar
 
Lionel Gauthier committed
651 652 653 654 655 656 657 658 659 660
#endif
    uint8_t                             buffer[RRC_BUF_SIZE];
    uint16_t                            size;
    int                                 i;

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

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

661 662 663
    struct SRB_ToAddMod                *SRB2_config                      = NULL;
    struct SRB_ToAddMod__rlc_Config    *SRB2_rlc_config                  = NULL;
    struct SRB_ToAddMod__logicalChannelConfig *SRB2_lchan_config         = NULL;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
664
    struct LogicalChannelConfig__ul_SpecificParameters
665
                                       *SRB2_ul_SpecificParameters       = NULL;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
666
    SRB_ToAddModList_t                 *SRB_configList = rrc_inst->SRB_configList[ue_mod_idP];
667 668 669 670 671 672 673 674
    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;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
675
    struct LogicalChannelConfig__ul_SpecificParameters
676
                                       *DRB_ul_SpecificParameters        = NULL;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
677 678
    DRB_ToAddModList_t                **DRB_configList = &rrc_inst->DRB_configList[ue_mod_idP];

679 680 681 682
    MAC_MainConfig_t                   *mac_MainConfig                   = NULL;
    MeasObjectToAddModList_t           *MeasObj_list                     = NULL;
    MeasObjectToAddMod_t               *MeasObj                          = NULL;
    ReportConfigToAddModList_t         *ReportConfig_list                = NULL;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
683 684
    ReportConfigToAddMod_t             *ReportConfig_per, *ReportConfig_A1,
        *ReportConfig_A2, *ReportConfig_A3, *ReportConfig_A4, *ReportConfig_A5;
685
    MeasIdToAddModList_t               *MeasId_list                      = NULL;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
686
    MeasIdToAddMod_t                   *MeasId0, *MeasId1, *MeasId2, *MeasId3, *MeasId4, *MeasId5;
winckel's avatar
winckel committed
687
#if Rel10
688
    long                               *sr_ProhibitTimer_r9              = NULL;
689 690
//     uint8_t sCellIndexToAdd = rrc_find_free_SCell_index(enb_mod_idP, ue_mod_idP, 1);
    uint8_t                            sCellIndexToAdd = 0;
winckel's avatar
winckel committed
691
#endif
692

Lionel Gauthier's avatar
 
Lionel Gauthier committed
693 694
    long                               *logicalchannelgroup, *logicalchannelgroup_drb;
    long                               *maxHARQ_Tx, *periodicBSR_Timer;
695

696 697 698 699 700
    RSRP_Range_t                       *rsrp                             = NULL;
    struct MeasConfig__speedStatePars  *Sparams                          = NULL;
    QuantityConfig_t                   *quantityConfig                   = NULL;
    CellsToAddMod_t                    *CellToAdd                        = NULL;
    CellsToAddModList_t                *CellsToAddModList                = NULL;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
701
    struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList = NULL;
702
    DedicatedInfoNAS_t                 *dedicatedInfoNas                 = NULL;
703

704
    C_RNTI_t                           *cba_RNTI                         = NULL;
705
#ifdef CBA
Lionel Gauthier's avatar
 
Lionel Gauthier committed
706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725
    //struct PUSCH_CBAConfigDedicated_vlola  *pusch_CBAConfigDedicated_vlola;
    uint8_t                            *cba_RNTI_buf;
    cba_RNTI = CALLOC(1, sizeof(C_RNTI_t));
    cba_RNTI_buf = CALLOC(1, 2 * sizeof(uint8_t));
    cba_RNTI->buf = cba_RNTI_buf;
    cba_RNTI->size = 2;
    cba_RNTI->bits_unused = 0;
    // associate UEs to the CBa groups as a function of their UE id
    if (rrc_inst->num_active_cba_groups) {
        cba_RNTI->buf[0] = rrc_inst->cba_rnti[ue_mod_idP % rrc_inst->num_active_cba_groups] & 0xff;
        cba_RNTI->buf[1] = 0xff;
        LOG_D(RRC,
              "[eNB %d] Frame %d: cba_RNTI = %x in group %d is attribued to UE %d\n",
              enb_mod_idP, frameP,
              rrc_inst->cba_rnti[ue_mod_idP % rrc_inst->num_active_cba_groups],
              ue_mod_idP % rrc_inst->num_active_cba_groups, ue_mod_idP);
    } else {
        cba_RNTI->buf[0] = 0x0;
        cba_RNTI->buf[1] = 0x0;
        LOG_D(RRC, "[eNB %d] Frame %d: no cba_RNTI is configured for UE %d\n", enb_mod_idP, frameP, ue_mod_idP);
winckel's avatar
winckel committed
726
    }
727

728
#endif
Lionel Gauthier's avatar
 
Lionel Gauthier committed
729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776
    // Configure SRB2
    /// SRB2
    SRB2_config = CALLOC(1, sizeof(*SRB2_config));
    SRB_configList2 = CALLOC(1, sizeof(*SRB_configList2));
    memset(SRB_configList2, 0, sizeof(*SRB_configList2));

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

    SRB2_rlc_config->present = SRB_ToAddMod__rlc_Config_PR_explicitValue;
    SRB2_rlc_config->choice.explicitValue.present = RLC_Config_PR_am;
    SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.t_PollRetransmit = T_PollRetransmit_ms15;
    SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollPDU = PollPDU_p8;
    SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollByte = PollByte_kB1000;
    SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.maxRetxThreshold = UL_AM_RLC__maxRetxThreshold_t32;
    SRB2_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_Reordering = T_Reordering_ms50;
    SRB2_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_StatusProhibit = T_StatusProhibit_ms10;

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

    SRB2_lchan_config->present = SRB_ToAddMod__logicalChannelConfig_PR_explicitValue;

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

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

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

    SRB2_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup;

    SRB2_lchan_config->choice.explicitValue.ul_SpecificParameters = SRB2_ul_SpecificParameters;
    ASN_SEQUENCE_ADD(&SRB_configList->list, SRB2_config);
    ASN_SEQUENCE_ADD(&SRB_configList2->list, SRB2_config);

    // Configure DRB
    *DRB_configList = CALLOC(1, sizeof(*DRB_configList));
    /// DRB
    DRB_config = CALLOC(1, sizeof(*DRB_config));

    DRB_config->eps_BearerIdentity = CALLOC(1, sizeof(long));
777
    *(DRB_config->eps_BearerIdentity) = 5L; // LW set to first value, allowed value 5..15, value : x+4
Lionel Gauthier's avatar
 
Lionel Gauthier committed
778 779 780
    // 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
781
    DRB_config->drb_Identity = (DRB_Identity_t) 1;  // (ue_mod_idP+1); //allowed values 1..32, value: x
Lionel Gauthier's avatar
 
Lionel Gauthier committed
782
    DRB_config->logicalChannelIdentity = CALLOC(1, sizeof(long));
783
    *(DRB_config->logicalChannelIdentity) = (long)3; // value : x+2
Lionel Gauthier's avatar
 
Lionel Gauthier committed
784 785
    DRB_rlc_config = CALLOC(1, sizeof(*DRB_rlc_config));
    DRB_config->rlc_Config = DRB_rlc_config;
winckel's avatar
winckel committed
786

787
#ifdef RRC_RLC_AM // EXMIMO_IOT
Lionel Gauthier's avatar
 
Lionel Gauthier committed
788 789 790 791 792 793 794
    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;
795
#else
Lionel Gauthier's avatar
 
Lionel Gauthier committed
796 797 798 799
    DRB_rlc_config->present = RLC_Config_PR_um_Bi_Directional;
    DRB_rlc_config->choice.um_Bi_Directional.ul_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
    DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
    DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering = T_Reordering_ms5;
800
#endif
801

Lionel Gauthier's avatar
 
Lionel Gauthier committed
802 803 804 805 806 807
    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;
808

809
#ifdef RRC_RLC_AM // EXMIMO_IOT
Lionel Gauthier's avatar
 
Lionel Gauthier committed
810 811 812
    PDCP_rlc_AM = CALLOC(1, sizeof(*PDCP_rlc_AM));
    DRB_pdcp_config->rlc_AM = PDCP_rlc_AM;
    PDCP_rlc_AM->statusReportRequired = FALSE;
813
#else
Lionel Gauthier's avatar
 
Lionel Gauthier committed
814 815 816
    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;
817
#endif
Lionel Gauthier's avatar
 
Lionel Gauthier committed
818
    DRB_pdcp_config->headerCompression.present = PDCP_Config__headerCompression_PR_notUsed;
819

Lionel Gauthier's avatar
 
Lionel Gauthier committed
820 821 822 823
    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;
824

Lionel Gauthier's avatar
 
Lionel Gauthier committed
825 826 827 828 829
    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;
830

Lionel Gauthier's avatar
 
Lionel Gauthier committed
831 832 833 834
    // 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
835

Lionel Gauthier's avatar
 
Lionel Gauthier committed
836
    ASN_SEQUENCE_ADD(&(*DRB_configList)->list, DRB_config);
winckel's avatar
RRC:  
winckel committed
837

Lionel Gauthier's avatar
 
Lionel Gauthier committed
838 839
    mac_MainConfig = CALLOC(1, sizeof(*mac_MainConfig));
    eNB_rrc_inst[enb_mod_idP].mac_MainConfig[ue_mod_idP] = mac_MainConfig;
winckel's avatar
RRC:  
winckel committed
840

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

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

852 853
    mac_MainConfig->timeAlignmentTimerDedicated = TimeAlignmentTimer_infinity;

Lionel Gauthier's avatar
 
Lionel Gauthier committed
854
    mac_MainConfig->drx_Config = NULL;
winckel's avatar
winckel committed
855

Lionel Gauthier's avatar
 
Lionel Gauthier committed
856
    mac_MainConfig->phr_Config = CALLOC(1, sizeof(*mac_MainConfig->phr_Config));
winckel's avatar
RRC:  
winckel committed
857

Lionel Gauthier's avatar
 
Lionel Gauthier committed
858 859
    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
860

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

Lionel Gauthier's avatar
 
Lionel Gauthier committed
863
    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
864

winckel's avatar
winckel committed
865
#ifdef Rel10
Lionel Gauthier's avatar
 
Lionel Gauthier committed
866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924
    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;
925 926
    MeasObj->measObject.choice.measObjectEUTRA.carrierFreq = 3350; //band 7, 2.68GHz 
    //MeasObj->measObject.choice.measObjectEUTRA.carrierFreq = 36090; //band 33, 1.909GHz
Lionel Gauthier's avatar
 
Lionel Gauthier committed
927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948
    MeasObj->measObject.choice.measObjectEUTRA.allowedMeasBandwidth = AllowedMeasBandwidth_mbw25;
    MeasObj->measObject.choice.measObjectEUTRA.presenceAntennaPort1 = 1;
    MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.buf = CALLOC(1, sizeof(uint8_t));
    MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.buf[0] = 0;
    MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.size = 1;
    MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.bits_unused = 6;
    MeasObj->measObject.choice.measObjectEUTRA.offsetFreq = NULL;   // Default is 15 or 0dB

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

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

    // Add adjacent cell lists (6 per eNB)
    for (i = 0; i < 6; i++) {
        CellToAdd = (CellsToAddMod_t *) CALLOC(1, sizeof(*CellToAdd));
        CellToAdd->cellIndex = i + 1;
        CellToAdd->physCellId = get_adjacent_cell_id(enb_mod_idP, i);
        CellToAdd->cellIndividualOffset = Q_OffsetRange_dB0;

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

Lionel Gauthier's avatar
 
Lionel Gauthier committed
950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137
    ASN_SEQUENCE_ADD(&MeasObj_list->list, MeasObj);
    //  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->measObjectToAddModList = MeasObj_list;

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

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

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

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

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

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

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

    ReportConfig_per->reportConfigId = 1;
    ReportConfig_per->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
    ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerType.present =
        ReportConfigEUTRA__triggerType_PR_periodical;
    ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerType.choice.periodical.purpose =
        ReportConfigEUTRA__triggerType__periodical__purpose_reportStrongestCells;
    ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerQuantity = ReportConfigEUTRA__triggerQuantity_rsrp;
    ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
    ReportConfig_per->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
    ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportInterval = ReportInterval_ms120;
    ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;

    ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_per);

    ReportConfig_A1->reportConfigId = 2;
    ReportConfig_A1->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
    ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.present =
        ReportConfigEUTRA__triggerType_PR_event;
    ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
        ReportConfigEUTRA__triggerType__event__eventId_PR_eventA1;
    ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA1.
        a1_Threshold.present = ThresholdEUTRA_PR_threshold_RSRP;
    ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA1.
        a1_Threshold.choice.threshold_RSRP = 10;

    ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerQuantity = ReportConfigEUTRA__triggerQuantity_rsrp;
    ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
    ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
    ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportInterval = ReportInterval_ms120;
    ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;

    ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A1);

    if (ho_state == 1 /*HO_MEASURMENT */ ) {
        LOG_I(RRC, "[eNB %d] frame %d: requesting A2, A3, A4, A5, and A6 event reporting\n", enb_mod_idP, frameP);
        ReportConfig_A2->reportConfigId = 3;
        ReportConfig_A2->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
        ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.present =
            ReportConfigEUTRA__triggerType_PR_event;
        ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
            ReportConfigEUTRA__triggerType__event__eventId_PR_eventA2;
        ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
            eventA2.a2_Threshold.present = ThresholdEUTRA_PR_threshold_RSRP;
        ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
            eventA2.a2_Threshold.choice.threshold_RSRP = 10;

        ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerQuantity =
            ReportConfigEUTRA__triggerQuantity_rsrp;
        ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
        ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
        ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportInterval = ReportInterval_ms120;
        ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;

        ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A2);

        ReportConfig_A3->reportConfigId = 4;
        ReportConfig_A3->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
        ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.present =
            ReportConfigEUTRA__triggerType_PR_event;
        ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
            ReportConfigEUTRA__triggerType__event__eventId_PR_eventA3;

        ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA3.a3_Offset = 1;   //10;
        ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
            eventA3.reportOnLeave = 1;

        ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerQuantity =
            ReportConfigEUTRA__triggerQuantity_rsrp;
        ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
        ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
        ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportInterval = ReportInterval_ms120;
        ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;

        ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.hysteresis = 0.5;
        ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.timeToTrigger =
            TimeToTrigger_ms40;
        ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A3);

        ReportConfig_A4->reportConfigId = 5;
        ReportConfig_A4->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
        ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.present =
            ReportConfigEUTRA__triggerType_PR_event;
        ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
            ReportConfigEUTRA__triggerType__event__eventId_PR_eventA4;
        ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
            eventA4.a4_Threshold.present = ThresholdEUTRA_PR_threshold_RSRP;
        ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
            eventA4.a4_Threshold.choice.threshold_RSRP = 10;

        ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerQuantity =
            ReportConfigEUTRA__triggerQuantity_rsrp;
        ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
        ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
        ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportInterval = ReportInterval_ms120;
        ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;

        ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A4);

        ReportConfig_A5->reportConfigId = 6;
        ReportConfig_A5->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
        ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.present =
            ReportConfigEUTRA__triggerType_PR_event;
        ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
            ReportConfigEUTRA__triggerType__event__eventId_PR_eventA5;
        ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
            eventA5.a5_Threshold1.present = ThresholdEUTRA_PR_threshold_RSRP;
        ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
            eventA5.a5_Threshold2.present = ThresholdEUTRA_PR_threshold_RSRP;
        ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
            eventA5.a5_Threshold1.choice.threshold_RSRP = 10;
        ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
            eventA5.a5_Threshold2.choice.threshold_RSRP = 10;

        ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerQuantity =
            ReportConfigEUTRA__triggerQuantity_rsrp;
        ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportQuantity = ReportConfigEUTRA__reportQuantity_both;
        ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2;
        ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportInterval = ReportInterval_ms120;
        ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportAmount = ReportConfigEUTRA__reportAmount_infinity;

        ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A5);
        //  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->reportConfigToAddModList = ReportConfig_list;

        rsrp = CALLOC(1, sizeof(RSRP_Range_t));
        *rsrp = 20;

        Sparams = CALLOC(1, sizeof(*Sparams));
        Sparams->present = MeasConfig__speedStatePars_PR_setup;
        Sparams->choice.setup.timeToTrigger_SF.sf_High = SpeedStateScaleFactors__sf_Medium_oDot75;
        Sparams->choice.setup.timeToTrigger_SF.sf_Medium = SpeedStateScaleFactors__sf_High_oDot5;
        Sparams->choice.setup.mobilityStateParameters.n_CellChangeHigh = 10;
        Sparams->choice.setup.mobilityStateParameters.n_CellChangeMedium = 5;
        Sparams->choice.setup.mobilityStateParameters.t_Evaluation = MobilityStateParameters__t_Evaluation_s60;
        Sparams->choice.setup.mobilityStateParameters.t_HystNormal = MobilityStateParameters__t_HystNormal_s120;

        quantityConfig = CALLOC(1, sizeof(*quantityConfig));
        memset((void *)quantityConfig, 0, sizeof(*quantityConfig));
        quantityConfig->quantityConfigEUTRA = CALLOC(1, sizeof(struct QuantityConfigEUTRA));
        memset((void *)quantityConfig->quantityConfigEUTRA, 0, sizeof(*quantityConfig->quantityConfigEUTRA));
        quantityConfig->quantityConfigCDMA2000 = NULL;
        quantityConfig->quantityConfigGERAN = NULL;
        quantityConfig->quantityConfigUTRA = NULL;
        quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP =
            CALLOC(1, sizeof(*(quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP)));
        quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ =
            CALLOC(1, sizeof(*(quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ)));
        *quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP = FilterCoefficient_fc4;
        *quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ = FilterCoefficient_fc4;

        LOG_I(RRC,
              "[eNB %d] Frame %d: potential handover preparation: store the information in an intermediate structure in case of failure\n",
              enb_mod_idP, frameP);
        // store the information in an intermediate structure for Hanodver management
        //rrc_inst->handover_info.as_config.sourceRadioResourceConfig.srb_ToAddModList = CALLOC(1,sizeof());
        rrc_inst->handover_info[ue_mod_idP] = CALLOC(1, sizeof(*(rrc_inst->handover_info[ue_mod_idP])));
        //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.srb_ToAddModList,(void *)SRB_list,sizeof(SRB_ToAddModList_t));
        rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.srb_ToAddModList = SRB_configList2;
        //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.drb_ToAddModList,(void *)DRB_list,sizeof(DRB_ToAddModList_t));
        rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.drb_ToAddModList = *DRB_configList;
        rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.drb_ToReleaseList = NULL;
        rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.mac_MainConfig =
            CALLOC(1, sizeof(*rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.mac_MainConfig));
        memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.mac_MainConfig,
               (void *)mac_MainConfig, sizeof(MAC_MainConfig_t));
        rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.physicalConfigDedicated =
            CALLOC(1, sizeof(PhysicalConfigDedicated_t));
        memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.physicalConfigDedicated,
               (void *)rrc_inst->physicalConfigDedicated[ue_mod_idP], sizeof(PhysicalConfigDedicated_t));
        rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.sps_Config = NULL;
        //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.sps_Config,(void *)rrc_inst->sps_Config[ue_mod_idP],sizeof(SPS_Config_t));
1138

Lionel Gauthier's avatar
 
Lionel Gauthier committed
1139
    }
1140
#if defined(ENABLE_ITTI)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1141 1142 1143 1144 1145 1146
    /* Initialize NAS list */
    dedicatedInfoNASList = CALLOC(1, sizeof(struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList));
    /* Add all NAS PDUs to the list */
    for (i = 0; i < UE_info->nb_of_e_rabs; i++) {
        if (UE_info->e_rab[i].param.nas_pdu.buffer != NULL) {
            dedicatedInfoNas = CALLOC(1, sizeof(DedicatedInfoNAS_t));
hrizi's avatar
 
hrizi committed
1147
	    memset(dedicatedInfoNas, 0, sizeof(OCTET_STRING_t));
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1148 1149 1150 1151
            OCTET_STRING_fromBuf(dedicatedInfoNas, (char *)UE_info->e_rab[i].param.nas_pdu.buffer,
                                 UE_info->e_rab[i].param.nas_pdu.length);
            ASN_SEQUENCE_ADD(&dedicatedInfoNASList->list, dedicatedInfoNas);
        }
1152

Lionel Gauthier's avatar
 
Lionel Gauthier committed
1153 1154 1155 1156 1157 1158
        /* TODO parameters yet to process ... */
        {
            UE_info->e_rab[i].param.qos;
            UE_info->e_rab[i].param.sgw_addr;
            UE_info->e_rab[i].param.gtp_teid;
        }
1159

Lionel Gauthier's avatar
 
Lionel Gauthier committed
1160 1161 1162 1163 1164 1165 1166
        /* TODO should test if e RAB are Ok before! */
        eNB_rrc_inst[enb_mod_idP].Info.UE[ue_mod_idP].e_rab[i].status = E_RAB_STATUS_DONE;
    }
    /* If list is empty free the list and reset the address */
    if (dedicatedInfoNASList->list.count == 0) {
        free(dedicatedInfoNASList);
        dedicatedInfoNASList = NULL;
1167
    }
1168 1169
#endif

Lionel Gauthier's avatar
 
Lionel Gauthier committed
1170
    memset(buffer, 0, RRC_BUF_SIZE);
1171

1172 1173 1174 1175 1176
    size = do_RRCConnectionReconfiguration(enb_mod_idP, buffer, ue_mod_idP, 
					   rrc_eNB_get_next_transaction_identifier(enb_mod_idP),   //Transaction_id,
					   NULL, /// NN: do not reconfig srb1: SRB_configList2,
					   *DRB_configList, NULL,  // DRB2_list,
					   NULL,    // *sps_Config,
1177
#ifdef EXMIMO_IOT
1178
					   NULL, NULL, NULL, NULL,NULL,
1179
#else
1180
					   physicalConfigDedicated[ue_mod_idP], MeasObj_list, ReportConfig_list, quantityConfig, MeasId_list,
1181
#endif
1182 1183 1184 1185 1186
					   mac_MainConfig, NULL, NULL, Sparams, rsrp, cba_RNTI, dedicatedInfoNASList
#ifdef Rel10
					   , NULL //SCellToAddMod_r10_t  
#endif
					   );
1187

1188
#ifdef RRC_MSG_PRINT
1189
    LOG_F(RRC,"[MSG] RRC Connection Reconfiguration\n");
1190
  for (i = 0; i < size; i++)
1191
      LOG_F(RRC,"%02x ", ((uint8_t*)buffer)[i]);
1192 1193 1194 1195
  LOG_F(RRC,"\n");
  ////////////////////////////////////////
#endif

1196
#if defined(ENABLE_ITTI)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1197 1198 1199 1200 1201 1202 1203
    /* Free all NAS PDUs */
    for (i = 0; i < UE_info->nb_of_e_rabs; i++) {
        if (UE_info->e_rab[i].param.nas_pdu.buffer != NULL) {
            /* Free the NAS PDU buffer and invalidate it */
            free(UE_info->e_rab[i].param.nas_pdu.buffer);
            UE_info->e_rab[i].param.nas_pdu.buffer = NULL;
        }
1204
    }
1205
#endif
1206

Lionel Gauthier's avatar
 
Lionel Gauthier committed
1207 1208 1209
    LOG_I(RRC,
          "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate RRCConnectionReconfiguration (bytes %d, UE id %d)\n",
          enb_mod_idP, frameP, size, ue_mod_idP);
1210

Lionel Gauthier's avatar
 
Lionel Gauthier committed
1211 1212 1213 1214 1215
    LOG_D(RRC,
          "[FRAME %05d][RRC_eNB][MOD %u/%u][][--- PDCP_DATA_REQ/%d Bytes (rrcConnectionReconfiguration to UE %d MUI %d) --->][PDCP][MOD %u/%u][RB %u]\n",
          frameP, enb_mod_idP, ue_mod_idP, size, ue_mod_idP, rrc_eNB_mui, enb_mod_idP, ue_mod_idP, DCCH);
    //rrc_rlc_data_req(enb_mod_idP,frameP, 1,(ue_mod_idP*NB_RB_MAX)+DCCH,rrc_eNB_mui++,0,size,(char*)buffer);
    pdcp_rrc_data_req(enb_mod_idP, ue_mod_idP, frameP, 1, DCCH, rrc_eNB_mui++, 0, size, buffer, 1);
winckel's avatar
winckel committed
1216
}
1217

1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228


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

  uint8_t size;
  uint8_t buffer[100];
  
#ifdef Rel10
  uint8_t sCellIndexToAdd = 0; //one SCell so far
//   uint8_t sCellIndexToAdd;
//   sCellIndexToAdd = rrc_find_free_SCell_index(enb_mod_idP, ue_mod_idP, 1);
1229 1230 1231
//  if (eNB_rrc_inst[enb_mod_idP].sCell_config[ue_mod_idP][sCellIndexToAdd] ) {
  if (eNB_rrc_inst[enb_mod_idP].sCell_config != NULL) {
    eNB_rrc_inst[enb_mod_idP].sCell_config[ue_mod_idP][sCellIndexToAdd].cellIdentification_r10->dl_CarrierFreq_r10 = dl_CarrierFreq_r10;
1232 1233 1234 1235 1236 1237 1238 1239 1240
  }
  else {
    LOG_E(RRC,"Scell not configured!\n");
    return(-1);
  }  
#endif
  size = do_RRCConnectionReconfiguration(enb_mod_idP,
                                         buffer,
                                         ue_mod_idP,
1241
                                         rrc_eNB_get_next_transaction_identifier(enb_mod_idP),//Transaction_id,
1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256
                                         (SRB_ToAddModList_t*)NULL,
                                         (DRB_ToAddModList_t*)NULL,
                                         (DRB_ToReleaseList_t*)NULL,
                                         (struct SPS_Config*)NULL,
                                         (struct PhysicalConfigDedicated*)NULL,
                                         (MeasObjectToAddModList_t*)NULL,
                                         (ReportConfigToAddModList_t*)NULL,
                                         (QuantityConfig_t*)NULL, 
                                         (MeasIdToAddModList_t*)NULL,
                                         (MAC_MainConfig_t*)NULL,
                                         (MeasGapConfig_t*)NULL,
                                         (MobilityControlInfo_t*)NULL,
                                         (struct MeasConfig__speedStatePars*)NULL,
                                         (RSRP_Range_t*)NULL,
                                         (C_RNTI_t*)NULL,
1257 1258 1259 1260 1261 1262
                                         (struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList*)NULL

#ifdef Rel10
					 , eNB_rrc_inst[enb_mod_idP].sCell_config
#endif
					 ); 
1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276

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

  LOG_D(RRC, "[MSC_MSG][FRAME %05d][RRC_eNB][MOD %02d][][--- PDCP_DATA_REQ/%d Bytes (rrcConnectionReconfiguration to UE %d MUI %d) --->][PDCP][MOD %02d][RB %02d]\n",
        frame, enb_mod_idP, size, ue_mod_idP, rrc_eNB_mui, enb_mod_idP, /*(ue_mod_idP*MAX_NUM_RB)+*/DCCH);
  //rrc_rlc_data_req(Mod_id,frame, 1,(UE_index*MAX_NUM_RB)+DCCH,rrc_eNB_mui++,0,size,(char*)buffer);
//   pdcp_data_req(enb_mod_idP, ue_mod_idP, frame, 1, /*(UE_index * MAX_NUM_RB) + */DCCH, rrc_eNB_mui++, 0, size, (char*)buffer, 1);
    pdcp_rrc_data_req(enb_mod_idP, ue_mod_idP, frame, 1, DCCH, rrc_eNB_mui++, 0, size, buffer, 1);

  return(0);
}


winckel's avatar
winckel committed
1277
/*------------------------------------------------------------------------------*/
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295
void rrc_eNB_process_MeasurementReport(
    module_id_t enb_mod_idP,
    frame_t frameP,
    module_id_t ue_mod_idP,
    MeasResults_t * measResults2) {

    LOG_I(RRC, "[eNB %d] Frame %d: Process Measurement Report From UE %d (Measurement Id %d)\n",
          enb_mod_idP, frameP, ue_mod_idP, (int)measResults2->measId);
    if (measResults2->measResultNeighCells->choice.measResultListEUTRA.list.count > 0) {
        LOG_I(RRC, "Physical Cell Id %d\n",
              (int)measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[0]->physCellId);
        LOG_I(RRC, "RSRP of Target %d\n",
              (int)*(measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[0]->
                     measResult.rsrpResult));
        LOG_I(RRC, "RSRQ of Target %d\n",
              (int)*(measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[0]->
                     measResult.rsrqResult));
    }
1296
#ifdef Rel10
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1297 1298
    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
1299
#else
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1300 1301 1302 1303 1304
    LOG_I(RRC, "RSRP of Source %d\n", measResults2->measResultServCell.rsrpResult);
    LOG_I(RRC, "RSRQ of Source %d\n", measResults2->measResultServCell.rsrqResult);
#endif

    if (eNB_rrc_inst[enb_mod_idP].handover_info[ue_mod_idP]->ho_prepare != 0xF0) {
hrizi's avatar
 
hrizi committed
1305
    	rrc_eNB_generate_HandoverPreparationInformation(enb_mod_idP,
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317
                                                        frameP,
                                                        ue_mod_idP,
                                                        measResults2->measResultNeighCells->choice.
                                                        measResultListEUTRA.list.array[0]->physCellId);
    } else {
        LOG_D(RRC, "[eNB %d] Frame %d: Ignoring MeasReport from UE %d as Handover is in progress... \n", enb_mod_idP, frameP,
              ue_mod_idP);
    }
    //Look for IP address of the target eNB
    //Send Handover Request -> target eNB
    //Wait for Handover Acknowledgement <- target eNB
    //Send Handover Command
1318

Lionel Gauthier's avatar
 
Lionel Gauthier committed
1319 1320
    //x2delay();
    //    handover_request_x2(ue_mod_idP,enb_mod_idP,measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[0]->physCellId);
1321

Lionel Gauthier's avatar
 
Lionel Gauthier committed
1322 1323 1324 1325 1326
    //    uint8_t buffer[100];
    //    int size=rrc_eNB_generate_Handover_Command_TeNB(0,0,buffer);
    //
    //      send_check_message((char*)buffer,size);
    //send_handover_command();
1327

1328 1329
}

winckel's avatar
winckel committed
1330
/*------------------------------------------------------------------------------*/
Lionel Gauthier's avatar
 
Lionel Gauthier committed
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 1361 1362 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
void rrc_eNB_generate_HandoverPreparationInformation(
    module_id_t enb_mod_idP,
    frame_t frameP,
    module_id_t ue_mod_idP,
    PhysCellId_t targetPhyId) {
    uint8_t                             UE_id_target;
    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));
     */

    handoverInfo->as_config.antennaInfoCommon.antennaPortsCount = 0;    //Not used 0- but check value
    handoverInfo->as_config.sourceDl_CarrierFreq = 36090;   //Verify!
    memcpy((void *)&handoverInfo->as_config.sourceMasterInformationBlock,
           (void *)&eNB_rrc_inst[enb_mod_idP].mib, sizeof(MasterInformationBlock_t));
    memcpy((void *)&handoverInfo->as_config.sourceMeasConfig,
           (void *)&eNB_rrc_inst[enb_mod_idP].measConfig[ue_mod_idP], sizeof(MeasConfig_t));
    //to be configured
    memset((void *)&eNB_rrc_inst[enb_mod_idP].handover_info[ue_mod_idP]->as_config.sourceSecurityAlgorithmConfig,
           0, sizeof(SecurityAlgorithmConfig_t));

    memcpy((void *)&eNB_rrc_inst[enb_mod_idP].handover_info[ue_mod_idP]->as_config.sourceSystemInformationBlockType1,
           (void *)&eNB_rrc_inst[enb_mod_idP].SIB1, sizeof(SystemInformationBlockType1_t));
    memcpy((void *)&eNB_rrc_inst[enb_mod_idP].handover_info[ue_mod_idP]->as_config.sourceSystemInformationBlockType2,
           (void *)&eNB_rrc_inst[enb_mod_idP].SIB23, sizeof(SystemInformationBlockType2_t));

    eNB_rrc_inst[enb_mod_idP].handover_info[ue_mod_idP]->as_context.reestablishmentInfo =
        CALLOC(1, sizeof(ReestablishmentInfo_t));
    eNB_rrc_inst[enb_mod_idP].handover_info[ue_mod_idP]->as_context.reestablishmentInfo->sourcePhysCellId =
        eNB_rrc_inst[enb_mod_idP].physCellId;
    eNB_rrc_inst[enb_mod_idP].handover_info[ue_mod_idP]->as_context.reestablishmentInfo->targetCellShortMAC_I.buf = NULL;  // Check values later
    eNB_rrc_inst[enb_mod_idP].handover_info[ue_mod_idP]->as_context.reestablishmentInfo->targetCellShortMAC_I.size = 0;
    eNB_rrc_inst[enb_mod_idP].handover_info[ue_mod_idP]->as_context.reestablishmentInfo->targetCellShortMAC_I.bits_unused = 0;
    eNB_rrc_inst[enb_mod_idP].handover_info[ue_mod_idP]->as_context.reestablishmentInfo->additionalReestabInfoList = NULL;

    eNB_rrc_inst[enb_mod_idP].handover_info[ue_mod_idP]->ho_prepare = 0xFF;    //0xF0;
    eNB_rrc_inst[enb_mod_idP].handover_info[ue_mod_idP]->ho_complete = 0;

    if (mod_id_target != 0xFF) {
        //UE_id_target = rrc_find_free_ue_index(modid_target);
        UE_id_target = rrc_eNB_get_next_free_UE_index(mod_id_target, eNB_rrc_inst[enb_mod_idP].Info.UE_list[ue_mod_idP]);  //this should return a new index

        if (UE_id_target != 0xFF) {
            LOG_N(RRC,
                  "[eNB %d] Frame %d : Emulate sending HandoverPreparationInformation msg from eNB source %d to eNB target %d: source UE_id %d target UE_id %d source_modId: %d target_modId: %d\n",
                  enb_mod_idP, frameP, eNB_rrc_inst[enb_mod_idP].physCellId, targetPhyId, ue_mod_idP, UE_id_target, enb_mod_idP,
                  mod_id_target);
            eNB_rrc_inst[mod_id_target].handover_info[UE_id_target] =
                CALLOC(1, sizeof(*(eNB_rrc_inst[mod_id_target].handover_info[UE_id_target])));
            memcpy((void *)&eNB_rrc_inst[mod_id_target].handover_info[UE_id_target]->as_context,
                   (void *)&eNB_rrc_inst[enb_mod_idP].handover_info[ue_mod_idP]->as_context, sizeof(AS_Context_t));
            memcpy((void *)&eNB_rrc_inst[mod_id_target].handover_info[UE_id_target]->as_config,
                   (void *)&eNB_rrc_inst[enb_mod_idP].handover_info[ue_mod_idP]->as_config, sizeof(AS_Config_t));

            eNB_rrc_inst[mod_id_target].handover_info[UE_id_target]->ho_prepare = 0xFF;
            eNB_rrc_inst[mod_id_target].handover_info[UE_id_target]->ho_complete = 0;

            eNB_rrc_inst[enb_mod_idP].handover_info[ue_mod_idP]->modid_t = mod_id_target;
            eNB_rrc_inst[enb_mod_idP].handover_info[ue_mod_idP]->ueid_s = ue_mod_idP;
            eNB_rrc_inst[enb_mod_idP].handover_info[ue_mod_idP]->modid_s = enb_mod_idP;
            eNB_rrc_inst[mod_id_target].handover_info[UE_id_target]->modid_t = mod_id_target;
            eNB_rrc_inst[mod_id_target].handover_info[UE_id_target]->modid_s = enb_mod_idP;
            eNB_rrc_inst[mod_id_target].handover_info[UE_id_target]->ueid_t = UE_id_target;
        } else
            LOG_E(RRC, "\nError in obtaining free UE id in target eNB %l for handover \n", targetPhyId);
    } else
        LOG_E(RRC, "\nError in obtaining Module ID of target eNB for handover \n");
1402 1403
}

winckel's avatar
winckel committed
1404
/*------------------------------------------------------------------------------*/
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1405 1406 1407 1408
void rrc_eNB_process_handoverPreparationInformation(
    module_id_t enb_mod_idP,
    frame_t frameP,
    module_id_t ue_mod_idP) {
1409

Lionel Gauthier's avatar
 
Lionel Gauthier committed
1410 1411 1412
    LOG_I(RRC,
          "[eNB %d] Frame %d : Logical Channel UL-DCCH, processing RRCHandoverPreparationInformation, sending RRCConnectionReconfiguration to UE %d \n",
          enb_mod_idP, frameP, ue_mod_idP);
1413

Lionel Gauthier's avatar
 
Lionel Gauthier committed
1414 1415
    //eNB_rrc_inst[enb_mod_idP].Info.UE_list[ue_mod_idP]
    rrc_eNB_generate_RRCConnectionReconfiguration_handover(enb_mod_idP, frameP, ue_mod_idP, NULL, 0);
1416

winckel's avatar
winckel committed
1417
}
1418

winckel's avatar
winckel committed
1419
/*------------------------------------------------------------------------------*/
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441
void check_handovers(
    module_id_t enb_mod_idP,
    frame_t frameP) {
    uint8_t                             i;
    int                                 result;

    for (i = 0; i < NUMBER_OF_UE_MAX; i++) {
        if (eNB_rrc_inst[enb_mod_idP].handover_info[i] != NULL) {
            if (eNB_rrc_inst[enb_mod_idP].handover_info[i]->ho_prepare == 0xFF) {
                LOG_D(RRC,
                      "[eNB %d] Frame %d: Incoming handover detected for new UE_idx %d (source eNB %d->target eNB %d) \n",
                      enb_mod_idP, frameP, i, enb_mod_idP, eNB_rrc_inst[enb_mod_idP].handover_info[i]->modid_t);
                // source eNB generates rrcconnectionreconfiguration to prepare the HO
                rrc_eNB_process_handoverPreparationInformation(enb_mod_idP, frameP, i);
                eNB_rrc_inst[enb_mod_idP].handover_info[i]->ho_prepare = 0xF1;
            }

            if (eNB_rrc_inst[enb_mod_idP].handover_info[i]->ho_complete == 0xF1) {
                LOG_D(RRC,
                      "[eNB %d] Frame %d: handover Command received for new UE_idx %d current eNB %d target eNB: %d \n",
                      enb_mod_idP, frameP, i, enb_mod_idP, eNB_rrc_inst[enb_mod_idP].handover_info[i]->modid_t);
                //rrc_eNB_process_handoverPreparationInformation(enb_mod_idP,frameP,i);
1442
                result = pdcp_data_req(enb_mod_idP, i, frameP, ENB_FLAG_YES, SRB_FLAG_YES,
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1443
                                       DCCH,
1444
                                       rrc_eNB_mui++, FALSE,
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1445 1446 1447 1448 1449 1450
                                       eNB_rrc_inst[enb_mod_idP].handover_info[i]->size,
                                       eNB_rrc_inst[enb_mod_idP].handover_info[i]->buf, 1);
                AssertFatal(result == TRUE, "PDCP data request failed!\n");
                eNB_rrc_inst[enb_mod_idP].handover_info[i]->ho_complete = 0xF2;
            }
        }
winckel's avatar
winckel committed
1451
    }
1452
}
winckel's avatar
RRC:  
winckel committed
1453

winckel's avatar
winckel committed
1454 1455
/*------------------------------------------------------------------------------*/
// 5.3.5.4 RRCConnectionReconfiguration including the mobilityControlInfo to prepare the UE handover
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502
void rrc_eNB_generate_RRCConnectionReconfiguration_handover(
    module_id_t enb_mod_idP,
    frame_t frameP,
    module_id_t ue_mod_idP,
    uint8_t * nas_pdu,
    uint32_t  nas_length) {

    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
    eNB_RRC_INST                       *rrc_inst = &eNB_rrc_inst[enb_mod_idP];

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

    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;
    SRB_ToAddModList_t                 *SRB_configList = rrc_inst->SRB_configList[ue_mod_idP];    // not used in this context: may be removed
    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_configList = &rrc_inst->DRB_configList[ue_mod_idP];
    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 =
        get_adjacent_cell_mod_id(rrc_inst->handover_info[ue_mod_idP]->as_context.reestablishmentInfo->sourcePhysCellId);
1503
#if Rel10
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526
    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;

    LOG_D(RRC, "[eNB %d] Frame %d: handover preparation: get the newSourceUEIdentity (C-RNTI): ", enb_mod_idP, frameP);
    for (i = 0; i < 2; i++) {
        rv[i] = taus() & 0xff;
        LOG_D(RRC, " %x.", rv[i]);
winckel's avatar
winckel committed
1527
    }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570

    LOG_D(RRC, "[eNB %d] Frame %d : handover reparation: add target eNB SRB1 and PHYConfigDedicated reconfiguration\n",
          enb_mod_idP, frameP);
    // 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_ms50;
    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);

1571
    //2nd: now reconfigure phy config dedicated
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613
    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;
1614
    physicalConfigDedicated2->uplinkPowerControlDedicated->accumulationEnabled = 1; // should be TRUE in order to have 0dB power offset
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677
    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;
    physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_RNTI.buf[1] = 0x34 + ue_mod_idP;
    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;
    physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_RNTI.buf[1] = 0x34 + ue_mod_idP;
    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;
     */

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

    //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);
1678
    /*
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733
       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;
    physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_PUCCH_ResourceIndex = ue_mod_idP;

    if (mac_xface->lte_frame_parms->frame_type == 0) {  // FDD
        physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_ConfigIndex = 5 + (ue_mod_idP % 10);   // Isr = 5 (every 10 subframes, offset=2+UE_id mod3)
    } else {
        switch (mac_xface->lte_frame_parms->tdd_config) {
            case 1:
                physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_ConfigIndex = 7 + (ue_mod_idP & 1) + ((ue_mod_idP & 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..)
                break;
            case 3:
                physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_ConfigIndex = 7 + (ue_mod_idP % 3);    // Isr = 5 (every 10 subframes, offset=2 for UE0, 3 for UE1, 3 for UE2, 2 for UE3 , etc..)
                break;
            case 4:
                physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_ConfigIndex = 7 + (ue_mod_idP & 1);    // Isr = 5 (every 10 subframes, offset=2 for UE0, 3 for UE1, 3 for UE2, 2 for UE3 , etc..)
                break;
            default:
                physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_ConfigIndex = 7; // Isr = 5 (every 10 subframes, offset=2 for all UE0 etc..)
                break;
        }
    }

    //  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,
          "handover_config [FRAME %05d][RRC_eNB][MOD %02d][][--- MAC_CONFIG_REQ  (SRB1 UE %d) --->][MAC_eNB][MOD %02d][]\n",
          frameP, enb_mod_idP, ue_mod_idP, enb_mod_idP);
    rrc_mac_config_req(enb_mod_idP, ENB_FLAG_YES, ue_mod_idP, 0, (RadioResourceConfigCommonSIB_t *) NULL,
1734 1735
                       eNB_rrc_inst[enb_mod_idP].physicalConfigDedicated[ue_mod_idP], 
#ifdef Rel10
hrizi's avatar
 
hrizi committed
1736 1737 1738 1739
	(SCellToAddMod_r10_t *)NULL,
	//(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
#endif		       
		       (MeasObjectToAddMod_t **) NULL,
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1740 1741 1742 1743
                       eNB_rrc_inst[enb_mod_idP].mac_MainConfig[ue_mod_idP], 1, SRB1_logicalChannelConfig,
                       eNB_rrc_inst[enb_mod_idP].measGapConfig[ue_mod_idP], (TDD_Config_t *) NULL,
                       (MobilityControlInfo_t *) NULL, (uint8_t *) NULL, (uint16_t *) NULL, NULL, NULL, NULL,
                       (MBSFN_SubframeConfigList_t *) NULL
1744
#ifdef Rel10
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1745
                       , 0, (MBSFN_AreaInfoList_r9_t *) NULL, (PMCH_InfoList_r9_t *) NULL
1746
#endif
winckel's avatar
winckel committed
1747
#ifdef CBA
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1748 1749 1750
                       , eNB_rrc_inst[enb_mod_idP].num_active_cba_groups, eNB_rrc_inst[enb_mod_idP].cba_rnti[0]
#endif
        );
1751

Lionel Gauthier's avatar
 
Lionel Gauthier committed
1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769
    // 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_ms50;
    SRB2_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_StatusProhibit = T_StatusProhibit_ms10;
1770

Lionel Gauthier's avatar
 
Lionel Gauthier committed
1771 1772
    SRB2_lchan_config = CALLOC(1, sizeof(*SRB2_lchan_config));
    SRB2_config->logicalChannelConfig = SRB2_lchan_config;
1773

Lionel Gauthier's avatar
 
Lionel Gauthier committed
1774
    SRB2_lchan_config->present = SRB_ToAddMod__logicalChannelConfig_PR_explicitValue;
1775

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

Lionel Gauthier's avatar
 
Lionel Gauthier committed
1778 1779 1780 1781 1782
    SRB2_ul_SpecificParameters->priority = 1;
    SRB2_ul_SpecificParameters->prioritisedBitRate =
        LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
    SRB2_ul_SpecificParameters->bucketSizeDuration =
        LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
1783

Lionel Gauthier's avatar
 
Lionel Gauthier committed
1784 1785 1786
    // LCG for CCCH and DCCH is 0 as defined in 36331
    logicalchannelgroup = CALLOC(1, sizeof(long));
    *logicalchannelgroup = 0;
1787

Lionel Gauthier's avatar
 
Lionel Gauthier committed
1788 1789 1790 1791
    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);
1792

Lionel Gauthier's avatar
 
Lionel Gauthier committed
1793 1794 1795 1796
    // Configure target eNB DRB
    DRB_configList2 = CALLOC(1, sizeof(*DRB_configList2));
    /// DRB
    DRB_config = CALLOC(1, sizeof(*DRB_config));
1797

Lionel Gauthier's avatar
 
Lionel Gauthier committed
1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808
    //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_ms5;
1809

Lionel Gauthier's avatar
 
Lionel Gauthier committed
1810 1811 1812 1813 1814 1815 1816 1817
    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;
1818

Lionel Gauthier's avatar
 
Lionel Gauthier committed
1819 1820 1821 1822
    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;
1823

Lionel Gauthier's avatar
 
Lionel Gauthier committed
1824 1825 1826 1827 1828
    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;
1829

Lionel Gauthier's avatar
 
Lionel Gauthier committed
1830 1831 1832 1833
    // 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;
1834

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

Lionel Gauthier's avatar
 
Lionel Gauthier committed
1837 1838
    mac_MainConfig = CALLOC(1, sizeof(*mac_MainConfig));
    eNB_rrc_inst[enb_mod_idP].mac_MainConfig[ue_mod_idP] = mac_MainConfig;
1839

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

Lionel Gauthier's avatar
 
Lionel Gauthier committed
1842 1843 1844
    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;
1845

Lionel Gauthier's avatar
 
Lionel Gauthier committed
1846 1847 1848
    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;
1849

Lionel Gauthier's avatar
 
Lionel Gauthier committed
1850
    mac_MainConfig->ul_SCH_Config->retxBSR_Timer = MAC_MainConfig__ul_SCH_Config__retxBSR_Timer_sf320;
1851

Lionel Gauthier's avatar
 
Lionel Gauthier committed
1852 1853 1854
    mac_MainConfig->ul_SCH_Config->ttiBundling = 0; // FALSE

    mac_MainConfig->drx_Config = NULL;
1855

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

Lionel Gauthier's avatar
 
Lionel Gauthier committed
1858 1859
    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
1860

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

Lionel Gauthier's avatar
 
Lionel Gauthier committed
1863
    mac_MainConfig->phr_Config->choice.setup.dl_PathlossChange = MAC_MainConfig__phr_Config__setup__dl_PathlossChange_dB1;  // Value dB1 =1 dB, dB3 = 3 dB
1864

1865
#ifdef Rel10
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 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
    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;
        CellToAdd->physCellId = get_adjacent_cell_id(enb_mod_idP, i);
        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;
2100

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 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 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193
    /* mobilityinfo  */

    mobilityInfo = CALLOC(1, sizeof(*mobilityInfo));
    memset((void *)mobilityInfo, 0, sizeof(*mobilityInfo));
    mobilityInfo->targetPhysCellId =
        (PhysCellId_t) two_tier_hexagonal_cellIds[rrc_inst->handover_info[ue_mod_idP]->modid_t];
    LOG_D(RRC, "[eNB %d] Frame %d: handover preparation: targetPhysCellId: %d mod_id: %d ue_mod_idP: %d \n", enb_mod_idP,
          frameP, mobilityInfo->targetPhysCellId, enb_mod_idP, ue_mod_idP);

    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,
           (void *)&rrc_inst->sib2->radioResourceConfigCommon.rach_ConfigCommon, sizeof(RACH_ConfigCommon_t));
    mobilityInfo->radioResourceConfigCommon.prach_Config.prach_ConfigInfo =
        CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.prach_Config.prach_ConfigInfo));
    memcpy((void *)mobilityInfo->radioResourceConfigCommon.prach_Config.prach_ConfigInfo,
           (void *)&rrc_inst->sib2->radioResourceConfigCommon.prach_Config.prach_ConfigInfo,
           sizeof(PRACH_ConfigInfo_t));

    mobilityInfo->radioResourceConfigCommon.prach_Config.rootSequenceIndex =
        rrc_inst->sib2->radioResourceConfigCommon.prach_Config.rootSequenceIndex;
    mobilityInfo->radioResourceConfigCommon.pdsch_ConfigCommon =
        CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.pdsch_ConfigCommon));
    memcpy((void *)mobilityInfo->radioResourceConfigCommon.pdsch_ConfigCommon,
           (void *)&rrc_inst->sib2->radioResourceConfigCommon.pdsch_ConfigCommon, sizeof(PDSCH_ConfigCommon_t));
    memcpy((void *)&mobilityInfo->radioResourceConfigCommon.pusch_ConfigCommon,
           (void *)&rrc_inst->sib2->radioResourceConfigCommon.pusch_ConfigCommon, sizeof(PUSCH_ConfigCommon_t));
    mobilityInfo->radioResourceConfigCommon.phich_Config = NULL;
    mobilityInfo->radioResourceConfigCommon.pucch_ConfigCommon =
        CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.pucch_ConfigCommon));
    memcpy((void *)mobilityInfo->radioResourceConfigCommon.pucch_ConfigCommon,
           (void *)&rrc_inst->sib2->radioResourceConfigCommon.pucch_ConfigCommon, sizeof(PUCCH_ConfigCommon_t));
    mobilityInfo->radioResourceConfigCommon.soundingRS_UL_ConfigCommon =
        CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.soundingRS_UL_ConfigCommon));
    memcpy((void *)mobilityInfo->radioResourceConfigCommon.soundingRS_UL_ConfigCommon,
           (void *)&rrc_inst->sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon,
           sizeof(SoundingRS_UL_ConfigCommon_t));
    mobilityInfo->radioResourceConfigCommon.uplinkPowerControlCommon =
        CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.uplinkPowerControlCommon));
    memcpy((void *)mobilityInfo->radioResourceConfigCommon.uplinkPowerControlCommon,
           (void *)&rrc_inst->sib2->radioResourceConfigCommon.uplinkPowerControlCommon,
           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 =
        rrc_inst->sib2->radioResourceConfigCommon.ul_CyclicPrefixLength;
    //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;

    mobilityInfo->carrierBandwidth = CALLOC(1, sizeof(*mobilityInfo->carrierBandwidth));    //CALLOC(1,sizeof(struct CarrierBandwidthEUTRA));  AllowedMeasBandwidth_mbw25
    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

    memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.srb_ToAddModList,
           (void *)SRB_configList2, sizeof(SRB_ToAddModList_t));
    memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.drb_ToAddModList,
           (void *)DRB_configList2, sizeof(DRB_ToAddModList_t));
    rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.drb_ToReleaseList = NULL;
    memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.mac_MainConfig,
           (void *)mac_MainConfig, sizeof(MAC_MainConfig_t));
    memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.physicalConfigDedicated,
           (void *)rrc_inst->physicalConfigDedicated[ue_mod_idP], sizeof(PhysicalConfigDedicated_t));
    /*    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;
2194
    Idx = DCCH;
winckel's avatar
winckel committed
2195
    // SRB1
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2196 2197 2198 2199 2200
    eNB_rrc_inst[enb_mod_idP].Srb1[ue_mod_idP].Active = 1;
    eNB_rrc_inst[enb_mod_idP].Srb1[ue_mod_idP].Srb_info.Srb_id = Idx;
    memcpy(&eNB_rrc_inst[enb_mod_idP].Srb1[ue_mod_idP].Srb_info.Lchan_desc[0], &DCCH_LCHAN_DESC, LCHAN_DESC_SIZE);
    memcpy(&eNB_rrc_inst[enb_mod_idP].Srb1[ue_mod_idP].Srb_info.Lchan_desc[1], &DCCH_LCHAN_DESC, LCHAN_DESC_SIZE);

winckel's avatar
winckel committed
2201
    // SRB2
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214
    eNB_rrc_inst[enb_mod_idP].Srb2[ue_mod_idP].Active = 1;
    eNB_rrc_inst[enb_mod_idP].Srb2[ue_mod_idP].Srb_info.Srb_id = Idx;
    memcpy(&eNB_rrc_inst[enb_mod_idP].Srb2[ue_mod_idP].Srb_info.Lchan_desc[0], &DCCH_LCHAN_DESC, LCHAN_DESC_SIZE);
    memcpy(&eNB_rrc_inst[enb_mod_idP].Srb2[ue_mod_idP].Srb_info.Lchan_desc[1], &DCCH_LCHAN_DESC, LCHAN_DESC_SIZE);

    LOG_I(RRC, "[eNB %d] CALLING RLC CONFIG SRB1 (rbid %d) for UE %d\n", enb_mod_idP, Idx, ue_mod_idP);

    //      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(enb_mod_idP, ue_mod_idP, frameP, 1,
                             eNB_rrc_inst[enb_mod_idP].SRB_configList[ue_mod_idP],
                             (DRB_ToAddModList_t *) NULL, (DRB_ToReleaseList_t *) NULL, 0xff, NULL, NULL, NULL
winckel's avatar
winckel committed
2215 2216 2217
#ifdef Rel10
                             , (PMCH_InfoList_r9_t *) NULL
#endif
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2218 2219 2220 2221 2222 2223 2224 2225 2226 2227
        );

    rrc_rlc_config_asn1_req(enb_mod_idP, ue_mod_idP, frameP, 1,
                            eNB_rrc_inst[enb_mod_idP].SRB_configList[ue_mod_idP],
                            (DRB_ToAddModList_t *) NULL, (DRB_ToReleaseList_t *) NULL
#ifdef Rel10
                            , (PMCH_InfoList_r9_t *) NULL
#endif
        );

2228 2229 2230
    /* Initialize NAS list */
    dedicatedInfoNASList = NULL;

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2231 2232 2233
    //  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->reportConfigToAddModList = ReportConfig_list;
    memset(buffer, 0, RRC_BUF_SIZE);

hrizi's avatar
 
hrizi committed
2234 2235
    size = do_RRCConnectionReconfiguration(enb_mod_idP, buffer, ue_mod_idP, rrc_eNB_get_next_transaction_identifier(enb_mod_idP),   //Transaction_id,
                                           SRB_configList2, DRB_configList2, NULL,  // DRB2_list,
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2236
                                           NULL,    //*sps_Config,
hrizi's avatar
 
hrizi committed
2237 2238
                                           physicalConfigDedicated[ue_mod_idP], MeasObj_list, ReportConfig_list, NULL,    //quantityConfig,
                                           MeasId_list, mac_MainConfig, NULL, mobilityInfo, Sparams,
2239 2240 2241 2242 2243
                                           NULL, NULL, dedicatedInfoNASList
#ifdef Rel10
					   , NULL   // SCellToAddMod_r10_t  
#endif
					   );
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270

    LOG_I(RRC,
          "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate RRCConnectionReconfiguration for handover (bytes %d, UE id %d)\n",
          enb_mod_idP, frameP, size, ue_mod_idP);
    // to be updated if needed
    /*if (eNB_rrc_inst[enb_mod_idP].SRB1_config[ue_mod_idP]->logicalChannelConfig) {
       if (eNB_rrc_inst[enb_mod_idP].SRB1_config[ue_mod_idP]->logicalChannelConfig->present == SRB_ToAddMod__logicalChannelConfig_PR_explicitValue) {
       SRB1_logicalChannelConfig = &eNB_rrc_inst[enb_mod_idP].SRB1_config[ue_mod_idP]->logicalChannelConfig->choice.explicitValue;
       }
       else {
       SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
       }
       }
       else {
       SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
       }
     */

    LOG_D(RRC,
          "[FRAME %05d][RRC_eNB][MOD %02d][][--- PDCP_DATA_REQ/%d Bytes (rrcConnectionReconfiguration_handover to UE %d MUI %d) --->][PDCP][MOD %02d][RB %02d]\n",
          frameP, enb_mod_idP, size, ue_mod_idP, rrc_eNB_mui, enb_mod_idP, DCCH);

    //rrc_rlc_data_req(enb_mod_idP,frameP, 1,(ue_mod_idP*NB_RB_MAX)+DCCH,rrc_eNB_mui++,0,size,(char*)buffer);
    //pdcp_data_req (enb_mod_idP, frameP, 1, (ue_mod_idP * NB_RB_MAX) + DCCH,rrc_eNB_mui++, 0, size, (char *) buffer, 1);
    rrc_mac_config_req(enb_mod_idP, ENB_FLAG_YES, ue_mod_idP, 0,
                       (RadioResourceConfigCommonSIB_t *) NULL,
                       eNB_rrc_inst[enb_mod_idP].physicalConfigDedicated[ue_mod_idP],
2271
#ifdef Rel10
hrizi's avatar
 
hrizi committed
2272 2273
	(SCellToAddMod_r10_t *)NULL,
	//(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
2274
#endif
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2275 2276 2277 2278 2279 2280 2281 2282
                       (MeasObjectToAddMod_t **) NULL,
                       eNB_rrc_inst[enb_mod_idP].mac_MainConfig[ue_mod_idP],
                       1,
                       SRB1_logicalChannelConfig,
                       eNB_rrc_inst[enb_mod_idP].measGapConfig[ue_mod_idP],
                       (TDD_Config_t *) NULL,
                       (MobilityControlInfo_t *) mobilityInfo,
                       (uint8_t *) NULL, (uint16_t *) NULL, NULL, NULL, NULL, (MBSFN_SubframeConfigList_t *) NULL
2283
#ifdef Rel10
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2284
                       , 0, (MBSFN_AreaInfoList_r9_t *) NULL, (PMCH_InfoList_r9_t *) NULL
2285 2286
#endif
#ifdef CBA
2287
                       , 0, 0
2288
#endif
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2289
        );
2290

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310
    /*
       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;
     */

    if (sourceModId != 0xFF) {
        memcpy(eNB_rrc_inst[sourceModId].handover_info[eNB_rrc_inst[enb_mod_idP].handover_info[ue_mod_idP]->ueid_s]->buf,
               (void *)buffer, size);
        eNB_rrc_inst[sourceModId].handover_info[eNB_rrc_inst[enb_mod_idP].handover_info[ue_mod_idP]->ueid_s]->size = size;
        eNB_rrc_inst[sourceModId].handover_info[eNB_rrc_inst[enb_mod_idP].handover_info[ue_mod_idP]->ueid_s]->ho_complete =
            0xF1;
        //eNB_rrc_inst[enb_mod_idP].handover_info[ue_mod_idP]->ho_complete = 0xFF;
        LOG_D(RRC, "[eNB %d] Frame %d: setting handover complete to 0xF1 for (%d,%d) and to 0xFF for (%d,%d)\n",
              enb_mod_idP, frameP, sourceModId, eNB_rrc_inst[enb_mod_idP].handover_info[ue_mod_idP]->ueid_s, enb_mod_idP, ue_mod_idP);
    } else
        LOG_W(RRC,
              "[eNB %d] Frame %d: rrc_eNB_generate_RRCConnectionReconfiguration_handover: Could not find source eNB mod_id.\n",
              enb_mod_idP, frameP);
2311

winckel's avatar
winckel committed
2312
}
2313

winckel's avatar
winckel committed
2314
/*
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2315
  void ue_rrc_process_rrcConnectionReconfiguration(uint8_t enb_mod_idP,frame_t frameP,
winckel's avatar
winckel committed
2316
  RRCConnectionReconfiguration_t *rrcConnectionReconfiguration,
2317
  uint8_t CH_index) {
2318

winckel's avatar
winckel committed
2319 2320
  if (rrcConnectionReconfiguration->criticalExtensions.present == RRCConnectionReconfiguration__criticalExtensions_PR_c1)
  if (rrcConnectionReconfiguration->criticalExtensions.choice.c1.present == RRCConnectionReconfiguration__criticalExtensions__c1_PR_rrcConnectionReconfiguration_r8) {
2321

winckel's avatar
winckel committed
2322
  if (rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated) {
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2323
  rrc_ue_process_radioResourceConfigDedicated(enb_mod_idP,frameP,CH_index,
winckel's avatar
winckel committed
2324
  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated);
2325

winckel's avatar
winckel committed
2326 2327 2328 2329 2330 2331 2332 2333
  }

  // check other fields for
  }
  }
*/

/*------------------------------------------------------------------------------*/
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2334 2335 2336 2337 2338 2339
void rrc_eNB_process_RRCConnectionReconfigurationComplete(
    module_id_t enb_mod_idP,
    frame_t     frameP,
    module_id_t ue_mod_idP,
    RRCConnectionReconfigurationComplete_r8_IEs_t * rrcConnectionReconfigurationComplete) {
    int                                 i;
winckel's avatar
winckel committed
2340
#ifdef NAS_NETLINK
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2341 2342
    int                                 oip_ifup = 0;
    int                                 dest_ip_offset = 0;
winckel's avatar
winckel committed
2343 2344
#endif

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2345 2346 2347
    uint8_t                            *kRRCenc = NULL;
    uint8_t                            *kRRCint = NULL;
    uint8_t                            *kUPenc = NULL;
winckel's avatar
winckel committed
2348

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2349 2350
    DRB_ToAddModList_t                 *DRB_configList = eNB_rrc_inst[enb_mod_idP].DRB_configList[ue_mod_idP];
    SRB_ToAddModList_t                 *SRB_configList = eNB_rrc_inst[enb_mod_idP].SRB_configList[ue_mod_idP];
winckel's avatar
winckel committed
2351 2352

#if defined(ENABLE_SECURITY)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2353 2354 2355 2356 2357
    /* Derive the keys from kenb */
    if (DRB_configList != NULL) {
        derive_key_up_enc(eNB_rrc_inst[enb_mod_idP].ciphering_algorithm[ue_mod_idP],
                          eNB_rrc_inst[enb_mod_idP].kenb[ue_mod_idP], &kUPenc);
    }
winckel's avatar
winckel committed
2358

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2359 2360 2361 2362
    derive_key_rrc_enc(eNB_rrc_inst[enb_mod_idP].ciphering_algorithm[ue_mod_idP],
                       eNB_rrc_inst[enb_mod_idP].kenb[ue_mod_idP], &kRRCenc);
    derive_key_rrc_int(eNB_rrc_inst[enb_mod_idP].integrity_algorithm[ue_mod_idP],
                       eNB_rrc_inst[enb_mod_idP].kenb[ue_mod_idP], &kRRCint);
2363

winckel's avatar
winckel committed
2364
#endif
Lionel Gauthier's avatar
Lionel Gauthier committed
2365
#ifdef ENABLE_RAL
Lionel Gauthier's avatar
 
Lionel Gauthier committed
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
    {
        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));
        connection_reconfiguration_ind.ue_id = ue_mod_idP;
        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;
        }
        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");
        itti_send_msg_to_task(TASK_RAL_ENB, enb_mod_idP, message_ral_p);
    }
#endif
    // Refresh SRBs/DRBs
2395
    rrc_pdcp_config_asn1_req(enb_mod_idP, ue_mod_idP, frameP, ENB_FLAG_YES,
hrizi's avatar
 
hrizi committed
2396
			     NULL,  //LG-RK 14/05/2014 SRB_configList,
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2397
                             DRB_configList, (DRB_ToReleaseList_t *) NULL,
2398 2399
                             /*eNB_rrc_inst[enb_mod_idP].ciphering_algorithm[ue_mod_idP] |
                             (eNB_rrc_inst[enb_mod_idP].integrity_algorithm[ue_mod_idP] << 4), 
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2400 2401 2402 2403 2404
                              */
                             0xff, // already configured during the securitymodecommand
                             kRRCenc,
                             kRRCint,
                             kUPenc
winckel's avatar
winckel committed
2405
#ifdef Rel10
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2406
                             , (PMCH_InfoList_r9_t *) NULL
winckel's avatar
winckel committed
2407
#endif
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2408 2409
        );
    // Refresh SRBs/DRBs
2410 2411 2412 2413 2414 2415 2416
    rrc_rlc_config_asn1_req(enb_mod_idP,
        ue_mod_idP,
        frameP,
        1,
        NULL,  //LG-RK 14/05/2014 SRB_configList,
        DRB_configList,
        (DRB_ToReleaseList_t *) NULL
winckel's avatar
winckel committed
2417
#ifdef Rel10
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2418
                            , (PMCH_InfoList_r9_t *) NULL
winckel's avatar
winckel committed
2419
#endif
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2420
        );
winckel's avatar
winckel committed
2421

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444
    // Loop through DRBs and establish if necessary

    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,
                      "[eNB %d] Frame  %d : Logical Channel UL-DCCH, Received RRCConnectionReconfigurationComplete from UE %d, reconfiguring DRB %d/LCID %d\n",
                      enb_mod_idP, frameP, ue_mod_idP,
                      (int)DRB_configList->list.array[i]->drb_Identity,
                      (ue_mod_idP * NB_RB_MAX) + (int)*DRB_configList->list.array[i]->logicalChannelIdentity);
                if (eNB_rrc_inst[enb_mod_idP].DRB_active[ue_mod_idP][i] == 0) {
                    /*
                       rrc_pdcp_config_req (enb_mod_idP, frameP, 1, CONFIG_ACTION_ADD,
                       (ue_mod_idP * NB_RB_MAX) + *DRB_configList->list.array[i]->logicalChannelIdentity,UNDEF_SECURITY_MODE);
                       rrc_rlc_config_req(enb_mod_idP,frameP,1,CONFIG_ACTION_ADD,
                       (ue_mod_idP * NB_RB_MAX) + (int)*eNB_rrc_inst[enb_mod_idP].DRB_config[ue_mod_idP][i]->logicalChannelIdentity,
                       RADIO_ACCESS_BEARER,Rlc_info_um);
                     */
                    eNB_rrc_inst[enb_mod_idP].DRB_active[ue_mod_idP][i] = 1;

                    LOG_D(RRC,
                          "[eNB %d] Frame %d: Establish RLC UM Bidirectional, DRB %d Active\n",
                          enb_mod_idP, frameP, (int)DRB_configList->list.array[i]->drb_Identity);
winckel's avatar
winckel committed
2445 2446

#ifdef NAS_NETLINK
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2447 2448 2449
                    // can mean also IPV6 since ether -> ipv6 autoconf
#   if !defined(OAI_NW_DRIVER_TYPE_ETHERNET) && !defined(EXMIMO)
                    LOG_I(OIP, "[eNB %d] trying to bring up the OAI interface oai%d\n", enb_mod_idP, enb_mod_idP);
2450 2451 2452 2453
                    oip_ifup = nas_config(
                        enb_mod_idP,   // interface index
                        enb_mod_idP + 1,   // thrid octet
                        enb_mod_idP + 1);  // fourth octet
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2454 2455 2456 2457 2458 2459 2460 2461 2462

                    if (oip_ifup == 0) {    // interface is up --> send a config the DRB
#      ifdef OAI_EMU
                        oai_emulation.info.oai_ifup[enb_mod_idP] = 1;
                        dest_ip_offset = NB_eNB_INST;
#      else
                        dest_ip_offset = 8;
#      endif
                        LOG_I(OIP,
2463 2464 2465
                            "[eNB %d] Config the oai%d to send/receive pkt on DRB %d to/from the protocol stack\n",
                            enb_mod_idP, enb_mod_idP,
                            (ue_mod_idP * maxDRB) + DRB_configList->list.array[i]->drb_Identity);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2466
                        rb_conf_ipv4(0, //add
2467 2468
                            ue_mod_idP,  //cx
                            enb_mod_idP,    //inst
2469
                            (ue_mod_idP * maxDRB) + DRB_configList->list.array[i]->drb_Identity, // RB
2470 2471 2472
                            0,    //dscp
                            ipv4_address(enb_mod_idP + 1, enb_mod_idP + 1),  //saddr
                            ipv4_address(enb_mod_idP + 1, dest_ip_offset + ue_mod_idP + 1));  //daddr
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2473 2474

                        LOG_D(RRC, "[eNB %d] State = Attached (UE %d)\n", enb_mod_idP, ue_mod_idP);
winckel's avatar
winckel committed
2475
                    }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487
#   else
#      ifdef OAI_EMU
                    oai_emulation.info.oai_ifup[enb_mod_idP] = 1;
#      endif
#   endif
#endif

                    LOG_D(RRC,
                          "[FRAME %05d][RRC_eNB][MOD %02d][][--- MAC_CONFIG_REQ  (DRB UE %d) --->][MAC_eNB][MOD %02d][]\n",
                          frameP, enb_mod_idP, ue_mod_idP, enb_mod_idP);
                    if (DRB_configList->list.array[i]->logicalChannelIdentity)
                        DRB2LCHAN[i] = (uint8_t) * DRB_configList->list.array[i]->logicalChannelIdentity;
2488 2489 2490 2491 2492 2493 2494
                    rrc_mac_config_req(
                        enb_mod_idP,
                        ENB_FLAG_YES,
                        ue_mod_idP,
                        0,
                        (RadioResourceConfigCommonSIB_t *) NULL,
                        eNB_rrc_inst[enb_mod_idP].physicalConfigDedicated[ue_mod_idP],
2495
#ifdef Rel10
hrizi's avatar
 
hrizi committed
2496 2497
	(SCellToAddMod_r10_t *)NULL,
	//(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
2498
#endif
2499 2500 2501 2502 2503 2504 2505 2506 2507
                        (MeasObjectToAddMod_t **) NULL,
                        eNB_rrc_inst[enb_mod_idP].mac_MainConfig[ue_mod_idP],
                        DRB2LCHAN[i],
                        DRB_configList->list.array[i]->logicalChannelConfig,
                        eNB_rrc_inst[enb_mod_idP].measGapConfig[ue_mod_idP],
                        (TDD_Config_t *) NULL,
                        NULL,
                        (uint8_t *) NULL,
                        (uint16_t *) NULL, NULL, NULL, NULL, (MBSFN_SubframeConfigList_t *) NULL
winckel's avatar
winckel committed
2508
#ifdef Rel10
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2509
                                       , 0, (MBSFN_AreaInfoList_r9_t *) NULL, (PMCH_InfoList_r9_t *) NULL
winckel's avatar
winckel committed
2510 2511
#endif
#ifdef CBA
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2512
                                       , eNB_rrc_inst[enb_mod_idP].num_active_cba_groups, eNB_rrc_inst[enb_mod_idP].cba_rnti[0]
winckel's avatar
winckel committed
2513
#endif
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2514
                        );
winckel's avatar
winckel committed
2515

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2516 2517 2518 2519 2520 2521 2522
                } else {        // remove LCHAN from MAC/PHY

                    if (eNB_rrc_inst[enb_mod_idP].DRB_active[ue_mod_idP][i] == 1) {
                        // DRB has just been removed so remove RLC + PDCP for DRB
                        /*      rrc_pdcp_config_req (enb_mod_idP, frameP, 1, CONFIG_ACTION_REMOVE,
                           (ue_mod_idP * NB_RB_MAX) + DRB2LCHAN[i],UNDEF_SECURITY_MODE);
                         */
2523 2524
                        rrc_rlc_config_req(enb_mod_idP, ue_mod_idP, frameP, ENB_FLAG_YES, SRB_FLAG_NO, MBMS_FLAG_NO, CONFIG_ACTION_REMOVE,
                                           DRB2LCHAN[i], Rlc_info_um);
winckel's avatar
winckel committed
2525
                    }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536
                    eNB_rrc_inst[enb_mod_idP].DRB_active[ue_mod_idP][i] = 0;
                    LOG_D(RRC,
                          "[FRAME %05d][RRC_eNB][MOD %02d][][--- MAC_CONFIG_REQ  (DRB UE %d) --->][MAC_eNB][MOD %02d][]\n",
                          frameP, enb_mod_idP, ue_mod_idP, enb_mod_idP);

                    rrc_mac_config_req(enb_mod_idP,
                                       ENB_FLAG_YES,
                                       ue_mod_idP,
                                       0,
                                       (RadioResourceConfigCommonSIB_t *) NULL,
                                       eNB_rrc_inst[enb_mod_idP].physicalConfigDedicated[ue_mod_idP],
2537
#ifdef Rel10
hrizi's avatar
 
hrizi committed
2538 2539
	(SCellToAddMod_r10_t *)NULL,
	//(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
2540
#endif
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2541 2542 2543 2544 2545 2546 2547
                                       (MeasObjectToAddMod_t **) NULL,
                                       eNB_rrc_inst[enb_mod_idP].mac_MainConfig[ue_mod_idP],
                                       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
2548
#ifdef Rel10
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2549
                                       , 0, (MBSFN_AreaInfoList_r9_t *) NULL, (PMCH_InfoList_r9_t *) NULL
winckel's avatar
winckel committed
2550 2551
#endif
#ifdef CBA
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2552
                                       , 0, 0
winckel's avatar
winckel committed
2553
#endif
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2554
                        );
winckel's avatar
winckel committed
2555 2556 2557 2558 2559
                }
            }
        }
    }
}
2560

winckel's avatar
winckel committed
2561
/*------------------------------------------------------------------------------*/
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579
void rrc_eNB_generate_RRCConnectionSetup(
    module_id_t  enb_mod_idP,
    frame_t      frameP,
    module_id_t  ue_mod_idP) {

    LogicalChannelConfig_t             *SRB1_logicalChannelConfig;  //,*SRB2_logicalChannelConfig;
    SRB_ToAddModList_t                **SRB_configList;
    SRB_ToAddMod_t                     *SRB1_config;
    int                                 cnt;

    AssertFatal(ue_mod_idP < NUMBER_OF_UE_MAX, "UE index invalid (%d/%d) for eNB %d!", ue_mod_idP, NUMBER_OF_UE_MAX,
                enb_mod_idP);

    SRB_configList = &eNB_rrc_inst[enb_mod_idP].SRB_configList[ue_mod_idP];

    eNB_rrc_inst[enb_mod_idP].Srb0.Tx_buffer.payload_size =
        do_RRCConnectionSetup(enb_mod_idP,
                              (uint8_t *) eNB_rrc_inst[enb_mod_idP].Srb0.Tx_buffer.Payload,
2580 2581
			      (mac_xface->lte_frame_parms->nb_antennas_tx==2)?2:1,
			      ue_mod_idP,
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2582 2583 2584 2585
                              rrc_eNB_get_next_transaction_identifier(enb_mod_idP),
                              mac_xface->lte_frame_parms,
                              SRB_configList, &eNB_rrc_inst[enb_mod_idP].physicalConfigDedicated[ue_mod_idP]);

2586
#ifdef RRC_MSG_PRINT
2587 2588 2589
    LOG_F(RRC,"[MSG] RRC Connection Setup\n");
    for (cnt = 0; cnt < eNB_rrc_inst[enb_mod_idP].Srb0.Tx_buffer.payload_size; cnt++)
      LOG_F(RRC,"%02x ", ((uint8_t*)eNB_rrc_inst[enb_mod_idP].Srb0.Tx_buffer.Payload)[cnt]);
2590 2591 2592 2593
    LOG_F(RRC,"\n");
  //////////////////////////////////
#endif

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605
    // 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;
winckel's avatar
winckel committed
2606
                    }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2607 2608
                } else {
                    SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
winckel's avatar
winckel committed
2609
                }
2610

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2611 2612 2613 2614 2615 2616
                LOG_D(RRC,
                      "[FRAME %05d][RRC_eNB][MOD %02d][][--- MAC_CONFIG_REQ  (SRB1 UE %d) --->][MAC_eNB][MOD %02d][]\n",
                      frameP, enb_mod_idP, ue_mod_idP, enb_mod_idP);
                rrc_mac_config_req(enb_mod_idP, ENB_FLAG_YES, ue_mod_idP, 0,
                                   (RadioResourceConfigCommonSIB_t *) NULL,
                                   eNB_rrc_inst[enb_mod_idP].physicalConfigDedicated[ue_mod_idP],
2617
#ifdef Rel10
hrizi's avatar
 
hrizi committed
2618 2619
	(SCellToAddMod_r10_t *)NULL,
	//(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
2620
#endif
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2621 2622 2623 2624 2625 2626 2627 2628 2629
                                   (MeasObjectToAddMod_t **) NULL,
                                   eNB_rrc_inst[enb_mod_idP].mac_MainConfig[ue_mod_idP],
                                   1,
                                   SRB1_logicalChannelConfig,
                                   eNB_rrc_inst[enb_mod_idP].measGapConfig[ue_mod_idP],
                                   (TDD_Config_t *) NULL,
                                   NULL,
                                   (uint8_t *) NULL,
                                   (uint16_t *) NULL, NULL, NULL, NULL, (MBSFN_SubframeConfigList_t *) NULL
winckel's avatar
winckel committed
2630
#ifdef Rel10
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2631
                                   , 0, (MBSFN_AreaInfoList_r9_t *) NULL, (PMCH_InfoList_r9_t *) NULL
winckel's avatar
winckel committed
2632 2633
#endif
#ifdef CBA
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2634
                                   , 0, 0
winckel's avatar
winckel committed
2635
#endif
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2636 2637
                    );
                break;
winckel's avatar
winckel committed
2638 2639 2640
            }
        }
    }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2641 2642 2643
    LOG_I(RRC,
          "[eNB %d][RAPROC] Frame %d : Logical Channel DL-CCCH, Generating RRCConnectionSetup (bytes %d, UE %d)\n",
          enb_mod_idP, frameP, eNB_rrc_inst[enb_mod_idP].Srb0.Tx_buffer.payload_size, ue_mod_idP);
2644

winckel's avatar
winckel committed
2645
}
2646

winckel's avatar
winckel committed
2647
/*------------------------------------------------------------------------------*/
winckel's avatar
winckel committed
2648
#if defined(ENABLE_ITTI)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2649 2650
char openair_rrc_lite_eNB_init(
    module_id_t enb_mod_idP) {
winckel's avatar
winckel committed
2651 2652 2653
    /* Dummy function, initialization will be done through ITTI messaging */
    return 0;
}
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2654 2655 2656
#endif

#if defined(ENABLE_ITTI)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2657 2658 2659
char openair_rrc_lite_eNB_configuration(
    uint8_t enb_mod_idP,
    RrcConfigurationReq * configuration)
winckel's avatar
winckel committed
2660
#else
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2661 2662
char openair_rrc_lite_eNB_init(
    module_id_t enb_mod_idP)
winckel's avatar
winckel committed
2663
#endif
winckel's avatar
winckel committed
2664 2665
{
  /*-----------------------------------------------------------------------------*/
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2666 2667
    module_id_t                       j;
    LOG_I(RRC, "[eNB %d] Init (UE State = RRC_IDLE)...\n", enb_mod_idP);
2668

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2669 2670
    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
2671

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2672 2673
    for (j = 0; j < NUMBER_OF_UE_MAX; j++)
        eNB_rrc_inst[enb_mod_idP].Info.UE[j].Status = RRC_IDLE;  //CH_READY;
2674

winckel's avatar
winckel committed
2675
#if defined(ENABLE_USE_MME)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2676 2677
    /* Connect eNB to MME */
    if (EPC_MODE_ENABLED <= 0)
winckel's avatar
winckel committed
2678
#endif
winckel's avatar
winckel committed
2679
    {
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2680 2681
        /* Init security parameters */
        for (j = 0; j < NUMBER_OF_UE_MAX; j++) {
2682 2683 2684
            eNB_rrc_inst[enb_mod_idP].ciphering_algorithm[j] = SecurityAlgorithmConfig__cipheringAlgorithm_eea0;
            eNB_rrc_inst[enb_mod_idP].integrity_algorithm[j] = SecurityAlgorithmConfig__integrityProtAlgorithm_eia2;
            rrc_lite_eNB_init_security(enb_mod_idP, j);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2685
        }
2686
    }
2687

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2688
    eNB_rrc_inst[enb_mod_idP].Info.Nb_ue = 0;
2689

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2690
    eNB_rrc_inst[enb_mod_idP].Srb0.Active = 0;
2691

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2692 2693
    for (j = 0; j < (NUMBER_OF_UE_MAX + 1); j++) {
        eNB_rrc_inst[enb_mod_idP].Srb2[j].Active = 0;
winckel's avatar
winckel committed
2694
    }
2695

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2696
    /// System Information INIT
2697

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2698
    LOG_I(RRC, "[eNB %d] Checking release \n", enb_mod_idP);
2699 2700
#ifdef Rel10

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2701 2702
    // This has to come from some top-level configuration
    LOG_I(RRC, "[eNB %d] Rel10 RRC detected, MBMS flag %d\n", enb_mod_idP, eNB_rrc_inst[enb_mod_idP].MBMS_flag);
2703

winckel's avatar
winckel committed
2704
#else
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2705
    LOG_I(RRC, "[eNB %d] Rel8 RRC\n", enb_mod_idP);
winckel's avatar
winckel committed
2706 2707
#endif
#ifdef CBA
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2708 2709
    for (j = 0; j < NUM_MAX_CBA_GROUP; j++)
        eNB_rrc_inst[enb_mod_idP].cba_rnti[j] = CBA_OFFSET + j;
2710

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2711 2712
    if (eNB_rrc_inst[enb_mod_idP].num_active_cba_groups > NUM_MAX_CBA_GROUP)
        eNB_rrc_inst[enb_mod_idP].num_active_cba_groups = NUM_MAX_CBA_GROUP;
2713

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2714 2715 2716 2717
    LOG_D(RRC, "[eNB %d] Initialization of 4 cba_RNTI values (%x %x %x %x) num active groups %d\n",
          enb_mod_idP, eNB_rrc_inst[enb_mod_idP].cba_rnti[0],
          eNB_rrc_inst[enb_mod_idP].cba_rnti[1], eNB_rrc_inst[enb_mod_idP].cba_rnti[2],
          eNB_rrc_inst[enb_mod_idP].cba_rnti[3], eNB_rrc_inst[enb_mod_idP].num_active_cba_groups);
winckel's avatar
winckel committed
2718
#endif
2719

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2720
    init_SI(enb_mod_idP
winckel's avatar
winckel committed
2721
#if defined(ENABLE_ITTI)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2722
            , configuration
winckel's avatar
winckel committed
2723
#endif
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2724
        );
2725

winckel's avatar
winckel committed
2726
#ifdef Rel10
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748
    switch (eNB_rrc_inst[enb_mod_idP].MBMS_flag) {
        case 1:
        case 2:
        case 3:
            LOG_I(RRC, "[eNB %d] Configuring 1 MBSFN sync area\n", enb_mod_idP);
            eNB_rrc_inst[enb_mod_idP].num_mbsfn_sync_area = 1;
            break;
        case 4:
            LOG_I(RRC, "[eNB %d] Configuring 2 MBSFN sync area\n", enb_mod_idP);
            eNB_rrc_inst[enb_mod_idP].num_mbsfn_sync_area = 2;
            break;
        default:
            eNB_rrc_inst[enb_mod_idP].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[enb_mod_idP].MBMS_flag > 0) {
        init_MCCH(enb_mod_idP);
        /// MTCH data bearer init
        init_MBMS(enb_mod_idP, 0);
    }
winckel's avatar
winckel committed
2749
#endif
2750

winckel's avatar
winckel committed
2751
#ifdef NO_RRM                   //init ch SRB0, SRB1 & BDTCH
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2752
    openair_rrc_on(enb_mod_idP, 1);
winckel's avatar
winckel committed
2753
#else
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2754 2755
    eNB_rrc_inst[enb_mod_idP].Last_scan_req = 0;
    send_msg(&S_rrc, msg_rrc_phy_synch_to_MR_ind(enb_mod_idP, eNB_rrc_inst[enb_mod_idP].Mac_id));
winckel's avatar
winckel committed
2756
#endif
2757

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2758
    return 0;
2759

winckel's avatar
winckel committed
2760
}
2761
 
winckel's avatar
winckel committed
2762
/*------------------------------------------------------------------------------*/
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2763 2764 2765 2766
int rrc_eNB_decode_ccch(
    module_id_t enb_mod_idP,
    frame_t frameP,
    SRB_INFO * Srb_info) {
winckel's avatar
winckel committed
2767
  /*------------------------------------------------------------------------------*/
2768

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2769 2770 2771 2772
    module_id_t                         Idx, ue_mod_id;
    asn_dec_rval_t                      dec_rval;
    UL_CCCH_Message_t                  *ul_ccch_msg = NULL;
    RRCConnectionRequest_r8_IEs_t      *rrcConnectionRequest;
2773
    RRCConnectionReestablishmentRequest_r8_IEs_t *rrcConnectionReestablishmentRequest;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2774 2775 2776 2777
    int                                 i, rval;

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

2778
    LOG_D(RRC, "[eNB %d] Frame %d: Decoding UL CCCH %x.%x.%x.%x.%x.%x (%p)\n",
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2779 2780 2781 2782 2783 2784 2785 2786 2787
          enb_mod_idP, frameP, ((uint8_t *) Srb_info->Rx_buffer.Payload)[0],
          ((uint8_t *) Srb_info->Rx_buffer.Payload)[1],
          ((uint8_t *) Srb_info->Rx_buffer.Payload)[2],
          ((uint8_t *) Srb_info->Rx_buffer.Payload)[3],
          ((uint8_t *) Srb_info->Rx_buffer.Payload)[4],
          ((uint8_t *) Srb_info->Rx_buffer.Payload)[5], (uint8_t *) Srb_info->Rx_buffer.Payload);
    dec_rval =
        uper_decode(NULL, &asn_DEF_UL_CCCH_Message, (void **)&ul_ccch_msg,
                    (uint8_t *) Srb_info->Rx_buffer.Payload, 100, 0, 0);
2788

winckel's avatar
winckel committed
2789
#if defined(ENABLE_ITTI)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2790
#   if defined(DISABLE_ITTI_XER_PRINT)
2791
    {
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2792
        MessageDef                         *message_p;
2793

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2794 2795
        message_p = itti_alloc_new_message(TASK_RRC_ENB, RRC_UL_CCCH_MESSAGE);
        memcpy(&message_p->ittiMsg, (void *)ul_ccch_msg, sizeof(RrcUlCcchMessage));
2796

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2797
        itti_send_msg_to_task(TASK_UNKNOWN, enb_mod_idP, message_p);
winckel's avatar
winckel committed
2798
    }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2799
#   else
winckel's avatar
winckel committed
2800
    {
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2801 2802
        char                                message_string[10000];
        size_t                              message_string_size;
2803

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2804 2805 2806
        if ((message_string_size =
             xer_sprint(message_string, sizeof(message_string), &asn_DEF_UL_CCCH_Message, (void *)ul_ccch_msg)) > 0) {
            MessageDef                         *msg_p;
2807

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2808 2809 2810
            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);
2811

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2812 2813 2814 2815 2816
            itti_send_msg_to_task(TASK_UNKNOWN, enb_mod_idP, msg_p);
        }
    }
#   endif
#endif
2817

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832
    for (i = 0; i < 8; i++)
        LOG_T(RRC, "%x.", ((uint8_t *) & ul_ccch_msg)[i]);
    if (dec_rval.consumed == 0) {
        LOG_E(RRC, "[eNB %d] FATAL Error in receiving CCCH\n", enb_mod_idP);
        return -1;
    }
    if (ul_ccch_msg->message.present == UL_CCCH_MessageType_PR_c1) {

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

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

            case UL_CCCH_MessageType__c1_PR_rrcConnectionReestablishmentRequest:
2833
#ifdef RRC_MSG_PRINT
hrizi's avatar
 
hrizi committed
2834 2835 2836 2837
	      LOG_F(RRC,"[MSG] RRC Connection Reestablishement Request\n");
	      for (i = 0; i < Srb_info->Rx_buffer.payload_size; i++)
		LOG_F(RRC,"%02x ", ((uint8_t*)Srb_info->Rx_buffer.Payload)[i]);
	      LOG_F(RRC,"\n");
2838
#endif
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2839 2840 2841 2842
                LOG_D(RRC,
                      "[FRAME %05d][MAC_eNB][MOD %02d][][--- MAC_DATA_IND (rrcConnectionReestablishmentRequest on SRB0) -->][RRC_eNB][MOD %02d][]\n",
                      frameP, enb_mod_idP, enb_mod_idP);

hrizi's avatar
 
hrizi committed
2843
		rrcConnectionReestablishmentRequest = &ul_ccch_msg->message.choice.c1.choice.rrcConnectionReestablishmentRequest.criticalExtensions.choice.rrcConnectionReestablishmentRequest_r8;
2844 2845 2846

                LOG_I(RRC, "[eNB %d] Frame %d UE %d: RRCConnectionReestablishmentRequest cause %s\n", enb_mod_idP,
                      frameP, 
hrizi's avatar
 
hrizi committed
2847 2848 2849 2850 2851 2852 2853 2854 2855 2856
		      ((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);
2857
                }
hrizi's avatar
 
hrizi committed
2858 2859 2860 2861 2862 2863 2864
		
		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);
		}
2865
                break;
hrizi's avatar
 
hrizi committed
2866
		*/
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2867
            case UL_CCCH_MessageType__c1_PR_rrcConnectionRequest:
2868
#ifdef RRC_MSG_PRINT
hrizi's avatar
 
hrizi committed
2869 2870 2871 2872
	      LOG_F(RRC,"[MSG] RRC Connection Request\n");
	      for (i = 0; i < Srb_info->Rx_buffer.payload_size; i++)
		LOG_F(RRC,"%02x ", ((uint8_t*)Srb_info->Rx_buffer.Payload)[i]);
	      LOG_F(RRC,"\n");
2873
#endif
2874
                LOG_D(RRC,
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2875 2876 2877
                      "[FRAME %05d][MAC_eNB][MOD %02d][][--- MAC_DATA_IND  (rrcConnectionRequest on SRB0) -->][RRC_eNB][MOD %02d][]\n",
                      frameP, enb_mod_idP, enb_mod_idP);

hrizi's avatar
 
hrizi committed
2878
	      rrcConnectionRequest = &ul_ccch_msg->message.choice.c1.choice.rrcConnectionRequest.criticalExtensions.choice.rrcConnectionRequest_r8;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2879 2880
                {
                    uint64_t                            random_value = 0;
2881

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2882 2883 2884 2885
                    memcpy(((uint8_t *) & random_value) + 3, rrcConnectionRequest->ue_Identity.choice.randomValue.buf,
                           rrcConnectionRequest->ue_Identity.choice.randomValue.size);
                    ue_mod_id = rrc_eNB_get_next_free_UE_index(enb_mod_idP, random_value);
                }
2886

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2887
                if (ue_mod_id != UE_MODULE_INVALID) {
winckel's avatar
winckel committed
2888
#if defined(ENABLE_ITTI)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902
                    /* Check s-TMSI presence in message */
                    eNB_rrc_inst[enb_mod_idP].Info.UE[ue_mod_id].Initialue_identity_s_TMSI.presence =
                        (rrcConnectionRequest->ue_Identity.present == InitialUE_Identity_PR_s_TMSI);
                    if (eNB_rrc_inst[enb_mod_idP].Info.UE[ue_mod_id].Initialue_identity_s_TMSI.presence) {
                        /* Save s-TMSI */
                        S_TMSI_t                            s_TMSI = rrcConnectionRequest->ue_Identity.choice.s_TMSI;

                        eNB_rrc_inst[enb_mod_idP].Info.UE[ue_mod_id].Initialue_identity_s_TMSI.mme_code =
                            BIT_STRING_to_uint8(&s_TMSI.mmec);
                        eNB_rrc_inst[enb_mod_idP].Info.UE[ue_mod_id].Initialue_identity_s_TMSI.m_tmsi =
                            BIT_STRING_to_uint32(&s_TMSI.m_TMSI);
                    }
                    eNB_rrc_inst[enb_mod_idP].Info.UE[ue_mod_id].establishment_cause =
                        rrcConnectionRequest->establishmentCause;
winckel's avatar
winckel committed
2903
#endif
2904

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2905 2906 2907
                    //      memcpy(&Rrc_xface->UE_id[enb_mod_idP][ue_mod_idP],(uint8_t *)rrcConnectionRequest->ue_Identity.choice.randomValue.buf,5);
                    memcpy(&eNB_rrc_inst[enb_mod_idP].Info.UE_list[ue_mod_id],
                           (uint8_t *) rrcConnectionRequest->ue_Identity.choice.randomValue.buf, 5);
2908

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2909 2910
                    LOG_I(RRC, "[eNB %d] Frame %d : Accept new connection from UE %d (0x%" PRIx64 ")\n",
                          enb_mod_idP, frameP, ue_mod_id, eNB_rrc_inst[enb_mod_idP].Info.UE_list[ue_mod_id]);
2911

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2912 2913 2914 2915
                    //CONFIG SRB2  (DCCHs, ONE per User)  //meas && lchan Cfg
                    //eNB_rrc_inst[enb_mod_idP].Info.Dtch_bd_config[ue_mod_idP].Status=NEED_RADIO_CONFIG;
                    //eNB_rrc_inst[enb_mod_idP].Info.Dtch_bd_config[ue_mod_idP].Next_eNBeck_frame=Rrc_xface->Frame_index+1;
                    eNB_rrc_inst[ue_mod_id].Info.Nb_ue++;
2916

winckel's avatar
winckel committed
2917
#ifndef NO_RRM
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2918
                    send_msg(&S_rrc, msg_rrc_MR_attach_ind(enb_mod_idP, Mac_id));
winckel's avatar
winckel committed
2919
#else
2920

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977
                    //LG COMMENT Idx = (ue_mod_idP * NB_RB_MAX) + DCCH;
                    Idx = DCCH;
                    // SRB1
                    eNB_rrc_inst[enb_mod_idP].Srb1[ue_mod_id].Active = 1;
                    eNB_rrc_inst[enb_mod_idP].Srb1[ue_mod_id].Srb_info.Srb_id = Idx;
                    memcpy(&eNB_rrc_inst[enb_mod_idP].Srb1[ue_mod_id].Srb_info.Lchan_desc[0], &DCCH_LCHAN_DESC,
                           LCHAN_DESC_SIZE);
                    memcpy(&eNB_rrc_inst[enb_mod_idP].Srb1[ue_mod_id].Srb_info.Lchan_desc[1], &DCCH_LCHAN_DESC,
                           LCHAN_DESC_SIZE);

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

                    rrc_eNB_generate_RRCConnectionSetup(enb_mod_idP, frameP, ue_mod_id);
                    //LOG_D(RRC, "[MSC_NBOX][FRAME %05d][RRC_eNB][MOD %02d][][Tx RRCConnectionSetup][RRC_eNB][MOD %02d][]\n",
                    //      frameP, enb_mod_idP, enb_mod_idP);

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

                    //      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(enb_mod_idP, ue_mod_id, frameP, 1,
                                             eNB_rrc_inst[enb_mod_idP].SRB_configList[ue_mod_id],
                                             (DRB_ToAddModList_t *) NULL,
                                             (DRB_ToReleaseList_t *) NULL, 0xff, NULL, NULL, NULL
#   ifdef Rel10
                                             , (PMCH_InfoList_r9_t *) NULL
#   endif
                        );

                    rrc_rlc_config_asn1_req(enb_mod_idP, ue_mod_id, frameP, 1,
                                            eNB_rrc_inst[enb_mod_idP].SRB_configList[ue_mod_id],
                                            (DRB_ToAddModList_t *) NULL, (DRB_ToReleaseList_t *) NULL
#   ifdef Rel10
                                            , (PMCH_InfoList_r9_t *) NULL
#   endif
                        );
                    //LOG_D(RRC,"[eNB %d] RLC AM allocation index@0 is %d\n",enb_mod_idP,rlc[enb_mod_idP].m_rlc_am_array[0].allocation);
                    //LOG_D(RRC,"[eNB %d] RLC AM allocation index@1 is %d\n",enb_mod_idP,rlc[enb_mod_idP].m_rlc_am_array[1].allocation);

                    /*

                       LOG_D(RRC,"[eNB %d] CALLING RLC CONFIG SRB2 (rbid %d) for UE %d\n",
                       enb_mod_idP,Idx+1,ue_mod_idP);
                       Mac_rlc_xface->rrc_rlc_config_req(enb_mod_idP,CONFIG_ACTION_ADD,Idx+1,SIGNALLING_RADIO_BEARER,Rlc_info_am_config);
                       LOG_D(RRC,"[eNB %d] RLC AM allocation index@0 is %d\n",enb_mod_idP,rlc[enb_mod_idP].m_rlc_am_array[0].allocation);
                       LOG_D(RRC,"[eNB %d] RLC AM allocation index@1 is %d\n",rlc[enb_mod_idP].m_rlc_am_array[1].allocation);
                     */
winckel's avatar
winckel committed
2978
#endif //NO_RRM
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2979 2980 2981 2982
                } else {
                    LOG_E(RRC, "can't add UE, max user count reached!\n");
                }
                break;
2983

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2984 2985 2986 2987
            default:
                LOG_E(RRC, "[eNB %d] Frame %d : Unknown message\n", enb_mod_idP, frameP);
                rval = -1;
                break;
winckel's avatar
winckel committed
2988
        }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2989 2990 2991 2992
        rval = 0;
    } else {
        LOG_E(RRC, "[eNB %d] Frame %d : Unknown error \n", enb_mod_idP, frameP);
        rval = -1;
winckel's avatar
winckel committed
2993
    }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2994
    return rval;
2995 2996
}

winckel's avatar
winckel committed
2997
/*------------------------------------------------------------------------------*/
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2998 2999 3000 3001 3002 3003 3004
int rrc_eNB_decode_dcch(
    module_id_t enb_mod_idP,
    frame_t     frameP,
    uint8_t     Srb_id,
    module_id_t ue_mod_idP,
    uint8_t    *Rx_sdu,
    sdu_size_t  sdu_sizeP) {
winckel's avatar
winckel committed
3005 3006
  /*------------------------------------------------------------------------------*/

Lionel Gauthier's avatar
 
Lionel Gauthier committed
3007 3008 3009 3010
    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;
3011 3012
    int i;
    
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3013 3014
    if ((Srb_id != 1) && (Srb_id != 2)) {
        LOG_E(RRC, "[eNB %d] Frame %d: Received message on SRB%d, should not have ...\n", enb_mod_idP, frameP, Srb_id);
winckel's avatar
winckel committed
3015
    }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3016
    //memset(ul_dcch_msg,0,sizeof(UL_DCCH_Message_t));
3017

Lionel Gauthier's avatar
 
Lionel Gauthier committed
3018 3019
    LOG_D(RRC, "[eNB %d] Frame %d: Decoding UL-DCCH Message\n", enb_mod_idP, frameP);
    dec_rval = uper_decode(NULL, &asn_DEF_UL_DCCH_Message, (void **)&ul_dcch_msg, Rx_sdu, sdu_sizeP, 0, 0);
3020

winckel's avatar
winckel committed
3021
#if defined(ENABLE_ITTI)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3022
#   if defined(DISABLE_ITTI_XER_PRINT)
3023
    {
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3024
        MessageDef                         *message_p;
3025

Lionel Gauthier's avatar
 
Lionel Gauthier committed
3026 3027
        message_p = itti_alloc_new_message(TASK_RRC_ENB, RRC_UL_DCCH_MESSAGE);
        memcpy(&message_p->ittiMsg, (void *)ul_dcch_msg, sizeof(RrcUlDcchMessage));
3028

Lionel Gauthier's avatar
 
Lionel Gauthier committed
3029
        itti_send_msg_to_task(TASK_UNKNOWN, enb_mod_idP, message_p);
3030
    }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3031 3032 3033 3034
#   else
    {
        char                                message_string[10000];
        size_t                              message_string_size;
3035

Lionel Gauthier's avatar
 
Lionel Gauthier committed
3036 3037 3038
        if ((message_string_size =
             xer_sprint(message_string, sizeof(message_string), &asn_DEF_UL_DCCH_Message, (void *)ul_dcch_msg)) >= 0) {
            MessageDef                         *msg_p;
3039

Lionel Gauthier's avatar
 
Lionel Gauthier committed
3040 3041 3042
            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);
3043

Lionel Gauthier's avatar
 
Lionel Gauthier committed
3044 3045
            itti_send_msg_to_task(TASK_UNKNOWN, enb_mod_idP, msg_p);
        }
winckel's avatar
winckel committed
3046
    }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3047 3048
#   endif
#endif
3049

3050
    {  
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3051 3052 3053 3054
        for (i = 0; i < sdu_sizeP; i++)
            LOG_T(RRC, "%x.", Rx_sdu[i]);
        LOG_T(RRC, "\n");
    }
winckel's avatar
winckel committed
3055

Lionel Gauthier's avatar
 
Lionel Gauthier committed
3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080
    if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0)) {
        LOG_E(RRC, "[UE %d] Frame %d : Failed to decode UL-DCCH (%d bytes)\n", enb_mod_idP, frameP, dec_rval.consumed);
        return -1;
    }

    if (ul_dcch_msg->message.present == UL_DCCH_MessageType_PR_c1) {

        switch (ul_dcch_msg->message.choice.c1.present) {
            case UL_DCCH_MessageType__c1_PR_NOTHING:   /* No components present */
                break;

            case UL_DCCH_MessageType__c1_PR_csfbParametersRequestCDMA2000:
                break;

            case UL_DCCH_MessageType__c1_PR_measurementReport:
                LOG_D(RRC,
                      "[FRAME %05d][RLC][MOD %02d][RB %02d][--- RLC_DATA_IND "
                      "%d bytes (measurementReport) --->][RRC_eNB][MOD %02d][]\n",
                      frameP, enb_mod_idP, DCCH, sdu_sizeP, enb_mod_idP);
                rrc_eNB_process_MeasurementReport(enb_mod_idP, frameP, ue_mod_idP,
                                                  &ul_dcch_msg->message.choice.c1.choice.measurementReport.
                                                  criticalExtensions.choice.c1.choice.measurementReport_r8.measResults);
                break;

            case UL_DCCH_MessageType__c1_PR_rrcConnectionReconfigurationComplete:
3081
#ifdef RRC_MSG_PRINT
hrizi's avatar
 
hrizi committed
3082 3083 3084 3085
	      LOG_F(RRC,"[MSG] RRC Connection Reconfiguration Complete\n");
	      for (i = 0; i < sdu_sizeP; i++)
		LOG_F(RRC,"%02x ", ((uint8_t*)Rx_sdu)[i]);
	      LOG_F(RRC,"\n");
3086
#endif
hrizi's avatar
 
hrizi committed
3087 3088 3089 3090
	      LOG_D(RRC,
		    "[FRAME %05d][RLC][MOD %02d][RB %02d][--- RLC_DATA_IND %d bytes "
		    "(RRCConnectionReconfigurationComplete) --->][RRC_eNB][MOD %02d][]\n",
		    frameP, enb_mod_idP, DCCH, sdu_sizeP, enb_mod_idP);
3091 3092

               if (ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.criticalExtensions.
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3093 3094
                    present ==
                    RRCConnectionReconfigurationComplete__criticalExtensions_PR_rrcConnectionReconfigurationComplete_r8)
winckel's avatar
winckel committed
3095
                {
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3096 3097 3098 3099 3100 3101 3102
                    rrc_eNB_process_RRCConnectionReconfigurationComplete(enb_mod_idP, frameP, ue_mod_idP,
                                                                         &ul_dcch_msg->message.choice.c1.choice.
                                                                         rrcConnectionReconfigurationComplete.
                                                                         criticalExtensions.choice.
                                                                         rrcConnectionReconfigurationComplete_r8);
                    eNB_rrc_inst[enb_mod_idP].Info.UE[ue_mod_idP].Status = RRC_RECONFIGURED;
                    LOG_I(RRC, "[eNB %d] UE %d State = RRC_RECONFIGURED \n", enb_mod_idP, ue_mod_idP);
3103
                }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3104 3105 3106 3107 3108 3109 3110 3111 3112 3113
#if defined(ENABLE_USE_MME)
#   if defined(ENABLE_ITTI)
                if (EPC_MODE_ENABLED == 1) {
                    rrc_eNB_send_S1AP_INITIAL_CONTEXT_SETUP_RESP(enb_mod_idP, ue_mod_idP);
                }
#   endif
#endif
                break;

            case UL_DCCH_MessageType__c1_PR_rrcConnectionReestablishmentComplete:
3114
#ifdef RRC_MSG_PRINT
hrizi's avatar
 
hrizi committed
3115 3116 3117 3118
	      LOG_F(RRC,"[MSG] RRC Connection Reestablishment Complete\n");
	      for (i = 0; i < sdu_sizeP; i++)
		LOG_F(RRC,"%02x ", ((uint8_t*)Rx_sdu)[i]);
	      LOG_F(RRC,"\n");
3119
#endif
hrizi's avatar
 
hrizi committed
3120
	      LOG_I(RRC,
3121 3122 3123 3124
                      "[FRAME %05d][RLC][MOD %02d][RB %02d][--- RLC_DATA_IND %d bytes "
                      "(rrcConnectionReestablishmentComplete) --->][RRC_eNB][MOD %02d][]\n",
                      frameP, enb_mod_idP, DCCH, sdu_sizeP, enb_mod_idP);
                break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3125 3126

            case UL_DCCH_MessageType__c1_PR_rrcConnectionSetupComplete:
3127
#ifdef RRC_MSG_PRINT
hrizi's avatar
 
hrizi committed
3128 3129 3130 3131
	      LOG_F(RRC,"[MSG] RRC Connection SetupComplete\n");
	      for (i = 0; i < sdu_sizeP; i++)
		LOG_F(RRC,"%02x ", ((uint8_t*)Rx_sdu)[i]);
	      LOG_F(RRC,"\n");
3132
#endif
3133
                LOG_D(RRC,
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156
                      "[FRAME %05d][RLC][MOD %02d][RB %02d][--- RLC_DATA_IND %d bytes "
                      "(RRCConnectionSetupComplete) --->][RRC_eNB][MOD %02d][]\n",
                      frameP, enb_mod_idP, DCCH, sdu_sizeP, enb_mod_idP);

                if (ul_dcch_msg->message.choice.c1.choice.rrcConnectionSetupComplete.criticalExtensions.present ==
                    RRCConnectionSetupComplete__criticalExtensions_PR_c1) {
                    if (ul_dcch_msg->message.choice.c1.choice.rrcConnectionSetupComplete.criticalExtensions.choice.c1.
                        present ==
                        RRCConnectionSetupComplete__criticalExtensions__c1_PR_rrcConnectionSetupComplete_r8) {
                        rrc_eNB_process_RRCConnectionSetupComplete(enb_mod_idP, frameP, ue_mod_idP,
                                                                   &ul_dcch_msg->message.choice.c1.choice.
                                                                   rrcConnectionSetupComplete.criticalExtensions.choice.
                                                                   c1.choice.rrcConnectionSetupComplete_r8);
                        eNB_rrc_inst[enb_mod_idP].Info.UE[ue_mod_idP].Status = RRC_CONNECTED;
                        LOG_I(RRC, "[eNB %d] UE %d State = RRC_CONNECTED \n", enb_mod_idP, ue_mod_idP);
                        LOG_D(RRC,
                              "[MSC_NBOX][FRAME %05d][RRC_eNB][MOD %02d][][Rx RRCConnectionSetupComplete\n"
                              "Now CONNECTED with UE %d][RRC_eNB][MOD %02d][]\n", frameP, enb_mod_idP, ue_mod_idP, enb_mod_idP);
                    }
                }
                break;

            case UL_DCCH_MessageType__c1_PR_securityModeComplete:
3157
#ifdef RRC_MSG_PRINT
hrizi's avatar
 
hrizi committed
3158 3159 3160 3161
	      LOG_F(RRC,"[MSG] RRC Security Mode Complete\n");
	      for (i = 0; i < sdu_sizeP; i++)
		LOG_F(RRC,"%02x ", ((uint8_t*)Rx_sdu)[i]);
	      LOG_F(RRC,"\n");
3162
#endif
3163
                LOG_I(RRC,
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3164 3165 3166 3167 3168
                      "[eNB %d] Frame %d received securityModeComplete on UL-DCCH %d from UE %d\n",
                      enb_mod_idP, frameP, DCCH, ue_mod_idP);
                LOG_D(RRC,
                      "[FRAME %05d][RLC][MOD %02d][RB %02d][--- RLC_DATA_IND %d bytes "
                      "(securityModeComplete) --->][RRC_eNB][MOD %02d][]\n", frameP, enb_mod_idP, DCCH, sdu_sizeP, enb_mod_idP);
winckel's avatar
winckel committed
3169
#ifdef XER_PRINT
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3170 3171 3172 3173 3174 3175 3176 3177 3178
                xer_fprint(stdout, &asn_DEF_UL_DCCH_Message, (void *)ul_dcch_msg);
#endif
                // 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
                rrc_eNB_generate_UECapabilityEnquiry(enb_mod_idP, frameP, ue_mod_idP);
                break;

            case UL_DCCH_MessageType__c1_PR_securityModeFailure:
3179
#ifdef RRC_MSG_PRINT
hrizi's avatar
 
hrizi committed
3180 3181 3182 3183
	      LOG_F(RRC,"[MSG] RRC Security Mode Failure\n");
	      for (i = 0; i < sdu_sizeP; i++)
		LOG_F(RRC,"%02x ", ((uint8_t*)Rx_sdu)[i]);
	      LOG_F(RRC,"\n");
3184
#endif
3185
                LOG_D(RRC,
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3186 3187
                      "[FRAME %05d][RLC][MOD %02d][RB %02d][--- RLC_DATA_IND %d bytes "
                      "(securityModeFailure) --->][RRC_eNB][MOD %02d][]\n", frameP, enb_mod_idP, DCCH, sdu_sizeP, enb_mod_idP);
winckel's avatar
winckel committed
3188
#ifdef XER_PRINT
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3189 3190 3191 3192 3193 3194 3195 3196 3197
                xer_fprint(stdout, &asn_DEF_UL_DCCH_Message, (void *)ul_dcch_msg);
#endif
                // cancel the security mode in PDCP

                // followup with the remaining procedure
                rrc_eNB_generate_UECapabilityEnquiry(enb_mod_idP, frameP, ue_mod_idP);
                break;

            case UL_DCCH_MessageType__c1_PR_ueCapabilityInformation:
3198
#ifdef RRC_MSG_PRINT
hrizi's avatar
 
hrizi committed
3199 3200 3201 3202
	      LOG_F(RRC,"[MSG] RRC UECapablility Information \n");
	      for (i = 0; i < sdu_sizeP; i++)
		LOG_F(RRC,"%02x ", ((uint8_t*)Rx_sdu)[i]);
	      LOG_F(RRC,"\n");
3203
#endif
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3204 3205 3206 3207 3208 3209
                LOG_I(RRC,
                      "[eNB %d] Frame %d received ueCapabilityInformation on UL-DCCH %d from UE %d\n",
                      enb_mod_idP, frameP, DCCH, ue_mod_idP);
                LOG_D(RRC,
                      "[FRAME %05d][RLC][MOD %02d][RB %02d][--- RLC_DATA_IND %d bytes "
                      "(UECapabilityInformation) --->][RRC_eNB][MOD %02d][]\n", frameP, enb_mod_idP, DCCH, sdu_sizeP, enb_mod_idP);
winckel's avatar
winckel committed
3210
#ifdef XER_PRINT
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221
                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);
3222
		//#ifdef XER_PRINT
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3223
                xer_fprint(stdout, &asn_DEF_UE_EUTRA_Capability, (void *)UE_EUTRA_Capability);
3224
		//#endif
3225

3226
#if defined(ENABLE_USE_MME)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3227 3228 3229
                if (EPC_MODE_ENABLED == 1) {
                    rrc_eNB_send_S1AP_UE_CAPABILITIES_IND(enb_mod_idP, ue_mod_idP, ul_dcch_msg);
                }
3230 3231
#endif

Lionel Gauthier's avatar
 
Lionel Gauthier committed
3232 3233 3234
                rrc_eNB_generate_defaultRRCConnectionReconfiguration(enb_mod_idP, frameP,
                                                                     ue_mod_idP, eNB_rrc_inst[enb_mod_idP].HO_flag);
                break;
3235

Lionel Gauthier's avatar
 
Lionel Gauthier committed
3236 3237
            case UL_DCCH_MessageType__c1_PR_ulHandoverPreparationTransfer:
                break;
3238

Lionel Gauthier's avatar
 
Lionel Gauthier committed
3239
            case UL_DCCH_MessageType__c1_PR_ulInformationTransfer:
3240
#ifdef RRC_MSG_PRINT
hrizi's avatar
 
hrizi committed
3241 3242 3243 3244
	      LOG_F(RRC,"[MSG] RRC UL Information Transfer \n");
	      for (i = 0; i < sdu_sizeP; i++)
		LOG_F(RRC,"%02x ", ((uint8_t*)Rx_sdu)[i]);
	      LOG_F(RRC,"\n");
3245 3246
#endif

winckel's avatar
winckel committed
3247
#if defined(ENABLE_USE_MME)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3248 3249 3250
                if (EPC_MODE_ENABLED == 1) {
                    rrc_eNB_send_S1AP_UPLINK_NAS(enb_mod_idP, ue_mod_idP, ul_dcch_msg);
                }
winckel's avatar
winckel committed
3251
#endif
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3252
                break;
3253

Lionel Gauthier's avatar
 
Lionel Gauthier committed
3254 3255
            case UL_DCCH_MessageType__c1_PR_counterCheckResponse:
                break;
3256

winckel's avatar
winckel committed
3257
#ifdef Rel10
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3258 3259
            case UL_DCCH_MessageType__c1_PR_ueInformationResponse_r9:
                break;
3260

Lionel Gauthier's avatar
 
Lionel Gauthier committed
3261 3262
            case UL_DCCH_MessageType__c1_PR_proximityIndication_r9:
                break;
3263

Lionel Gauthier's avatar
 
Lionel Gauthier committed
3264 3265
            case UL_DCCH_MessageType__c1_PR_rnReconfigurationComplete_r10:
                break;
3266

Lionel Gauthier's avatar
 
Lionel Gauthier committed
3267 3268
            case UL_DCCH_MessageType__c1_PR_mbmsCountingResponse_r10:
                break;
winckel's avatar
winckel committed
3269

Lionel Gauthier's avatar
 
Lionel Gauthier committed
3270 3271
            case UL_DCCH_MessageType__c1_PR_interFreqRSTDMeasurementIndication_r10:
                break;
3272
#endif
3273

Lionel Gauthier's avatar
 
Lionel Gauthier committed
3274 3275 3276
            default:
                LOG_E(RRC, "[UE %d] Frame %d : Unknown message\n", enb_mod_idP, frameP);
                return -1;
winckel's avatar
winckel committed
3277
        }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3278 3279 3280 3281
        return 0;
    } else {
        LOG_E(RRC, "[UE %d] Frame %d : Unknown error\n", enb_mod_idP, frameP);
        return -1;
winckel's avatar
winckel committed
3282 3283 3284 3285
    }

}

3286
#if defined(ENABLE_ITTI)
winckel's avatar
winckel committed
3287
/*------------------------------------------------------------------------------*/
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3288 3289 3290 3291 3292
void                               *rrc_enb_task(
    void *args_p) {
    MessageDef                         *msg_p;
    const char                         *msg_name_p;
    instance_t                          instance;
3293
    unsigned int  ue_mod_id;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363
    int                                 result;
    SRB_INFO                           *srb_info_p;

    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:
                LOG_I(RRC, "[eNB %d] Received %s: frameP %d,\n", instance, msg_name_p,
                      RRC_MAC_CCCH_DATA_IND(msg_p).frame);

                srb_info_p = &eNB_rrc_inst[instance].Srb0;

                memcpy(srb_info_p->Rx_buffer.Payload, RRC_MAC_CCCH_DATA_IND(msg_p).sdu,
                       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;
                rrc_eNB_decode_ccch(instance, RRC_MAC_CCCH_DATA_IND(msg_p).frame, srb_info_p);
                break;

                /* Messages from PDCP */
            case RRC_DCCH_DATA_IND:
                LOG_I(RRC, "[eNB %d][UE %d] Received %s: frameP %d, DCCH %d\n", instance,
                      RRC_DCCH_DATA_IND(msg_p).ue_index, msg_name_p, RRC_DCCH_DATA_IND(msg_p).frame,
                      RRC_DCCH_DATA_IND(msg_p).dcch_index);

                rrc_eNB_decode_dcch(instance, RRC_DCCH_DATA_IND(msg_p).frame, RRC_DCCH_DATA_IND(msg_p).dcch_index,
                                    RRC_DCCH_DATA_IND(msg_p).ue_index, RRC_DCCH_DATA_IND(msg_p).sdu_p,
                                    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;

#   if defined(ENABLE_USE_MME)
                /* Messages from S1AP */
            case S1AP_DOWNLINK_NAS:
                rrc_eNB_process_S1AP_DOWNLINK_NAS(msg_p, msg_name_p, instance, &rrc_eNB_mui);
                break;

            case S1AP_INITIAL_CONTEXT_SETUP_REQ:
                rrc_eNB_process_S1AP_INITIAL_CONTEXT_SETUP_REQ(msg_p, msg_name_p, instance);
                break;

            case S1AP_UE_CTXT_MODIFICATION_REQ:
                rrc_eNB_process_S1AP_UE_CTXT_MODIFICATION_REQ(msg_p, msg_name_p, instance);
                break;

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

            case S1AP_UE_CONTEXT_RELEASE_REQ:
                rrc_eNB_process_S1AP_UE_CONTEXT_RELEASE_REQ(msg_p, msg_name_p, instance);
                break;
3364

3365 3366 3367 3368
            case S1AP_UE_CONTEXT_RELEASE_COMMAND:
                rrc_eNB_process_S1AP_UE_CONTEXT_RELEASE_COMMAND(msg_p, msg_name_p, instance);
                break;

3369 3370 3371 3372
            case GTPV1U_ENB_CREATE_TUNNEL_RESP:
              rrc_eNB_process_GTPV1U_CREATE_TUNNEL_RESP(msg_p, msg_name_p, instance);
              break;

Lionel Gauthier's avatar
 
Lionel Gauthier committed
3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386
#   endif

                /* Messages from eNB app */
            case RRC_CONFIGURATION_REQ:
                LOG_I(RRC, "[eNB %d] Received %s\n", instance, msg_name_p);
                openair_rrc_lite_eNB_configuration(instance, &RRC_CONFIGURATION_REQ(msg_p));
                break;

#   ifdef ENABLE_RAL
            case RRC_RAL_CONFIGURE_THRESHOLD_REQ:
                rrc_enb_ral_handle_configure_threshold_request(instance, msg_p);
                break;
#   endif

3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398
                //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 */
                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
#   ifdef ENABLE_RAL
                rrc_eNB_generate_RRCConnectionReconfiguration_SCell(instance, 0/* TODO put frameP number ! */, /*ue_mod_id force ue_mod_id to first UE*/0, 36126);
#   else
                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);
#   endif
                break;

Lionel Gauthier's avatar
 
Lionel Gauthier committed
3399 3400 3401 3402
            default:
                LOG_E(RRC, "[eNB %d] Received unexpected message %s\n", instance, msg_name_p);
                break;
        }
Lionel Gauthier's avatar
Lionel Gauthier committed
3403

Lionel Gauthier's avatar
 
Lionel Gauthier committed
3404 3405 3406
        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;
3407 3408 3409
    }
}
#endif
winckel's avatar
winckel committed
3410 3411

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