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

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

#include "defs.h"
34 35 36 37

// NB-IoT Section
#include "defs_NB_IoT.h"
#include "vars_NB_IoT.h"
38
#include "extern.h"
39 40 41
#include "extern_NB_IoT.h"
#include "LAYER2/MAC/proto_NB_IoT.h"
#include "RRC/LITE/MESSAGES/asn1_msg_NB_IoT.h"
42 43
#include "RRCConnectionRequest-NB.h"
#include "UL-CCCH-Message-NB.h"
44
// NB-IoT end
45
#include "assertions.h"
46
#include "asn1_conversions.h"
47 48
#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"
#include "LAYER2/RLC/rlc.h"
49
#include "LAYER2/MAC/proto.h"
50 51 52 53
#include "UTIL/LOG/log.h"
#include "COMMON/mac_rrc_primitives.h"
#include "RRC/LITE/MESSAGES/asn1_msg.h"
#include "RRCConnectionRequest.h"
54 55
#include "RRCConnectionReestablishmentRequest.h"
//#include "ReestablishmentCause.h"
56 57 58 59 60
#include "UL-CCCH-Message.h"
#include "DL-CCCH-Message.h"
#include "UL-DCCH-Message.h"
#include "DL-DCCH-Message.h"
#include "TDD-Config.h"
61
#include "HandoverCommand.h"
62 63
#include "rlc.h"
#include "SIMULATION/ETH_TRANSPORT/extern.h"
64 65 66
#include "rrc_eNB_UE_context.h"
#include "platform_types.h"
#include "msc.h"
67

68 69
#include "T.h"

Cedric Roux's avatar
Cedric Roux committed
70
//#if defined(Rel10) || defined(Rel14)
71
#include "MeasResults.h"
72 73 74
//#endif

#ifdef USER_MODE
Lionel Gauthier's avatar
 
Lionel Gauthier committed
75 76 77 78
#   include "RRC/NAS/nas_config.h"
#   include "RRC/NAS/rb_config.h"
#   include "OCG.h"
#   include "OCG_extern.h"
79 80
#endif

81
#if defined(ENABLE_SECURITY)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
82
#   include "UTIL/OSA/osa_defs.h"
83 84
#endif

85
#if defined(ENABLE_USE_MME)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
86
#   include "rrc_eNB_S1AP.h"
87
#   include "rrc_eNB_GTPV1U.h"
Lionel Gauthier's avatar
 
Lionel Gauthier committed
88 89 90 91
#   if defined(ENABLE_ITTI)
#   else
#      include "../../S1AP/s1ap_eNB.h"
#   endif
92 93
#endif

94 95 96
#include "pdcp.h"

#if defined(ENABLE_ITTI)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
97
#   include "intertask_interface.h"
98 99
#endif

100
#if ENABLE_RAL
Lionel Gauthier's avatar
 
Lionel Gauthier committed
101
#   include "rrc_eNB_ral.h"
Lionel Gauthier's avatar
Lionel Gauthier committed
102 103
#endif

104 105
#include "SIMULATION/TOOLS/defs.h" // for taus

106
#if defined(FLEXRAN_AGENT_SB_IF)
107
#include "flexran_agent_extern.h"
108
#endif
109
//#define XER_PRINT
110 111

#ifdef PHY_EMUL
Lionel Gauthier's avatar
 
Lionel Gauthier committed
112
extern EMULATION_VARS              *Emul_vars;
113
#endif
Lionel Gauthier's avatar
 
Lionel Gauthier committed
114 115
extern eNB_MAC_INST                *eNB_mac_inst;
extern UE_MAC_INST                 *UE_mac_inst;
116
#ifdef BIGPHYSAREA
117
extern void*                        bigphys_malloc(int);
118 119
#endif

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

Lionel Gauthier's avatar
 
Lionel Gauthier committed
122
mui_t                               rrc_eNB_mui = 0;
winckel's avatar
RRC:  
winckel committed
123

124
uint8_t* generate_msg4_NB_IoT(rrc_eNB_carrier_data_NB_IoT_t *carrier)
Nick Ho's avatar
Nick Ho committed
125
{
126
  LOG_D(RRC,"start the RRC connection setup PDU\n");
Nick Ho's avatar
Nick Ho committed
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142

  rrc_eNB_ue_context_NB_IoT_t* ue_context_pP_NB_IoT;
      
  ue_context_pP_NB_IoT = (rrc_eNB_ue_context_NB_IoT_t*)malloc(sizeof(rrc_eNB_ue_context_NB_IoT_t));

  SRB_ToAddModList_NB_r13_t  **SRB_configList_NB_IoT;

  SRB_configList_NB_IoT = &ue_context_pP_NB_IoT->ue_context.SRB_configList;

  carrier[0].Srb0.Tx_buffer.payload_size = do_RRCConnectionSetup_NB_IoT(ue_context_pP_NB_IoT,
                                                                                0,
                                                                                carrier[0].Srb0.Tx_buffer.Payload,
                                                                                0,
                                                                                SRB_configList_NB_IoT,
                                                                                &ue_context_pP_NB_IoT->ue_context.physicalConfigDedicated_NB_IoT);

143
  LOG_I(RRC,"[MSG] RRC Connection Setup NB-IoT: ");
Nick Ho's avatar
Nick Ho committed
144 145 146 147 148 149 150 151

  int                                 cnt;

  for (cnt = 0; cnt < carrier[0].Srb0.Tx_buffer.payload_size; cnt++) 
  {
    printf("%02x ", carrier[0].Srb0.Tx_buffer.Payload[cnt]);
  }
  printf("\n");
152 153

  return carrier[0].Srb0.Tx_buffer.Payload;
Nick Ho's avatar
Nick Ho committed
154 155
}

156
uint8_t* mac_rrc_msg3_ind_NB_IoT(uint8_t *payload_ptr, uint16_t rnti, uint32_t length)
157
{
158
  LOG_D(RRC,"recieve MSG3 CCCH SDU from MAC\n");
Nick Ho's avatar
Nick Ho committed
159 160
  asn_dec_rval_t                      dec_rval;
  struct rrc_eNB_ue_context_NB_IoT_s  *ue_context_p = NULL;
161
  uint8_t* msg4_rrc_sdu = NULL;
Nick Ho's avatar
Nick Ho committed
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
  SRB_INFO_NB_IoT *srb_info = NULL;
  srb_info = &eNB_rrc_inst_NB_IoT->carrier[0].Srb0;
  memcpy(srb_info->Rx_buffer.Payload,payload_ptr,length);
  srb_info->Rx_buffer.payload_size = length;
  LOG_D(RRC,"Decoding UL CCCH %x.%x.%x.%x.%x.%x.%x.%x.%x (%p)\n",
        ((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)[6], 
        ((uint8_t *) srb_info->Rx_buffer.Payload)[7], 
        ((uint8_t *) srb_info->Rx_buffer.Payload)[8],  
        (uint8_t *) srb_info->Rx_buffer.Payload);

178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
  RRCConnectionRequest_NB_r13_IEs_t* rrcConnectionRequest_NB = NULL;
  UL_CCCH_Message_NB_t* ul_ccch_msg_NB = NULL;
  dec_rval = uper_decode(
               NULL,
               &asn_DEF_UL_CCCH_Message_NB,
               (void**)&ul_ccch_msg_NB,
               payload_ptr,
               100,
               0,
               0);
  if (ul_ccch_msg_NB->message.choice.c1.present==UL_CCCH_MessageType_NB__c1_PR_rrcConnectionRequest_r13)
  {
    LOG_I(RRC,"The decode CCH MSG is RRC connection Request NB\n");
    rrcConnectionRequest_NB = &ul_ccch_msg_NB->message.choice.c1.choice.rrcConnectionRequest_r13.criticalExtensions.choice.rrcConnectionRequest_r13;
    if (rrcConnectionRequest_NB->ue_Identity_r13.present == InitialUE_Identity_PR_randomValue)
    {
      uint8_t *da = rrcConnectionRequest_NB->ue_Identity_r13.choice.randomValue.buf;   /* BIT STRING body */
      int length = rrcConnectionRequest_NB->ue_Identity_r13.choice.randomValue.size;       /* Size of the above buffer */
      printf("Random Value: ");
      for(int a = 0; a<length;a++)
        printf("%02x ",da[a]);
      printf("\n");
    }else if (rrcConnectionRequest_NB->ue_Identity_r13.present == InitialUE_Identity_PR_s_TMSI)
    {
      uint8_t *da = rrcConnectionRequest_NB->ue_Identity_r13.choice.s_TMSI.m_TMSI.buf;   /* BIT STRING body */
      int length = rrcConnectionRequest_NB->ue_Identity_r13.choice.s_TMSI.m_TMSI.size;       /* Size of the above buffer */
      
      printf("TMSI: ");
      for(int a = 0; a<length;a++)
        printf("%02x ",da[a]);
      printf("\n");
Nick Ho's avatar
Nick Ho committed
209 210 211 212 213
    }
    else
    {
	     LOG_E(RRC,"unknown TMSI or Random Value format in RRC connection request NB\n");
    }
214
    msg4_rrc_sdu = generate_msg4_NB_IoT(&eNB_rrc_inst_NB_IoT->carrier[0]);
Nick Ho's avatar
Nick Ho committed
215 216
  }
  else
217 218
	 LOG_E(RRC,"unknown MSG3 format for NB-IoT for current test\n");
  return msg4_rrc_sdu;
219 220
}

AlanLi's avatar
AlanLi committed
221 222 223 224 225 226
uint8_t *get_NB_IoT_MIB(
    rrc_eNB_carrier_data_NB_IoT_t *carrier,
    uint16_t N_RB_DL,//may not needed--> for NB_IoT only 1 PRB is used
    uint32_t subframe,
    uint32_t frame,
    uint32_t hyper_frame)
227
{
AlanLi's avatar
AlanLi committed
228 229 230 231 232 233 234 235 236 237

   if(frame%64==0 && subframe ==0)
      {//printf("dooooo MIB");

     
       do_MIB_NB_IoT(carrier,N_RB_DL,frame,hyper_frame);
       /* for(int i = 0; i<5;i++)
         printf("%02X ",eNB_rrc_inst_NB_IoT->carrier[0].MIB_NB_IoT[i]);
        printf("\n");*/
      }
238 239 240 241
  // CC_ID=0
  return eNB_rrc_inst_NB_IoT->carrier[0].MIB_NB_IoT;
}

AlanLi's avatar
AlanLi committed
242

Matthieu Kanj's avatar
Matthieu Kanj committed
243
uint8_t get_NB_IoT_MIB_size(void)
AlanLi's avatar
AlanLi committed
244 245 246 247 248
{
  // CC_ID=0
  return eNB_rrc_inst_NB_IoT->carrier[0].sizeof_MIB_NB_IoT;
}

AlanLi's avatar
AlanLi committed
249 250 251 252 253 254 255 256 257 258 259
uint8_t *get_NB_IoT_SIB1(uint8_t Mod_id, int CC_id,
        rrc_eNB_carrier_data_NB_IoT_t *carrier,
        uint16_t mcc, //208
        uint16_t mnc, //92
        uint16_t tac, //1
        uint32_t cell_identity, //3584
        uint16_t band,  // 7
        uint16_t mnc_digit_length,
        uint32_t subframe,
        uint32_t frame,
        uint32_t hyper_frame)
260
{
AlanLi's avatar
AlanLi committed
261 262

  
Nick Ho's avatar
Nick Ho committed
263 264
  //if(frame%64==1 && subframe ==0)
      //{     
AlanLi's avatar
AlanLi committed
265
       do_SIB1_NB_IoT_x(Mod_id,CC_id,carrier,mcc,mnc,tac,cell_identity,band,mnc_digit_length,hyper_frame);
Nick Ho's avatar
Nick Ho committed
266
      //}
AlanLi's avatar
AlanLi committed
267 268 269

      

270 271 272
  return eNB_rrc_inst_NB_IoT->carrier[0].SIB1_NB_IoT;
}

Matthieu Kanj's avatar
Matthieu Kanj committed
273
uint8_t get_NB_IoT_SIB1_size(void)
AlanLi's avatar
AlanLi committed
274 275 276 277
{
  return eNB_rrc_inst_NB_IoT->carrier[0].sizeof_SIB1_NB_IoT;
}

Matthieu Kanj's avatar
SIB23  
Matthieu Kanj committed
278 279 280 281 282
uint8_t *get_NB_IoT_SIB23(void)
{
  return eNB_rrc_inst_NB_IoT->carrier[0].SIB23_NB_IoT;
}

Matthieu Kanj's avatar
Matthieu Kanj committed
283
uint8_t get_NB_IoT_SIB23_size(void)
AlanLi's avatar
AlanLi committed
284 285 286 287 288
{
  return eNB_rrc_inst_NB_IoT->carrier[0].sizeof_SIB23_NB_IoT;
}


289 290 291 292 293
long *get_NB_IoT_SIB1_eutracontrolregionsize(void)
{
  return eNB_rrc_inst_NB_IoT->carrier[0].sib1_NB_IoT->eutraControlRegionSize_r13;
}

294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
void init_testing_NB_IoT(uint8_t Mod_id, int CC_id, rrc_eNB_carrier_data_NB_IoT_t *carrier, RrcConfigurationReq *configuration, uint32_t frame, uint32_t hyper_frame)
{

 //copy basic parameters
  carrier[CC_id].physCellId      = configuration->Nid_cell[CC_id];
  carrier[CC_id].p_rx_eNB   = 1;
  carrier[CC_id].Ncp             = configuration->prefix_type[CC_id]; //DL Cyclic prefix
  carrier[CC_id].Ncp_UL           = configuration->prefix_type_UL[CC_id];//UL cyclic prefix
  carrier[CC_id].dl_CarrierFreq  = configuration->downlink_frequency[CC_id];
  carrier[CC_id].ul_CarrierFreq  = configuration->downlink_frequency[CC_id]+ configuration->uplink_frequency_offset[CC_id];


  //TODO: verify who allocate memory for sib1_NB_IoT, sib2_NB_IoT, sib3_NB and mib_nb in the carrier before being passed as parameter

  carrier[CC_id].sizeof_SIB1_NB_IoT  = 0;
  carrier[CC_id].sizeof_SIB23_NB_IoT = 0;
  carrier[CC_id].sizeof_MIB_NB_IoT   = 0;

  //MIB
  carrier[CC_id].MIB_NB_IoT = (uint8_t*) malloc16(32); //MIB is 34 bits=5bytes needed


  if (carrier[CC_id].MIB_NB_IoT)
  {
    carrier[CC_id].sizeof_MIB_NB_IoT =
            do_MIB_NB_IoT(carrier,
                  configuration->N_RB_DL[CC_id],
                  0, //frame
                  0// hyper sfn
                  );
  }
  else {
      LOG_E(RRC, " init_SI: FATAL, no memory for MIB_NB_IoT allocated\n");
      //exit here
    }


  if (carrier[CC_id].sizeof_MIB_NB_IoT == 255) {
     // exit here
    }

 //SIB1_NB_IoT
  carrier[CC_id].SIB1_NB_IoT = (uint8_t*) malloc16(32);//allocation of buffer memory for SIB1_NB_IOT

  if (carrier[CC_id].SIB1_NB_IoT)
    carrier[CC_id].sizeof_SIB1_NB_IoT = do_SIB1_NB_IoT( //follow the new implementation
            Mod_id,
          CC_id,
          carrier,
          configuration,
          0 //FIXME is correct to pass frame = 0??
            );

  else {
      LOG_E(RRC, " init_SI: FATAL, no memory for SIB1_NB_IoT allocated\n");
    //exit here
  }

  if (carrier[CC_id].sizeof_SIB1_NB_IoT == 255) {
    //exit here
  }

356 357 358 359 360 361 362 363
  //dump SIB1_NB_IoT
  
  LOG_I(RRC,"Dump SIB1 NB-IoT content\n");
  
  for(int i = 0; i<32;i++)
	printf("%02X ",carrier[CC_id].SIB1_NB_IoT[i]);
  printf("\n");

364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395
  //SIB23_NB_IoT
  carrier[CC_id].SIB23_NB_IoT = (uint8_t*) malloc16(64);

  if (carrier[CC_id].SIB23_NB_IoT) {
    carrier[CC_id].sizeof_SIB23_NB_IoT = do_SIB23_NB_IoT(
          Mod_id,
          CC_id,
          carrier,
          configuration
        );

    if (carrier[CC_id].sizeof_SIB23_NB_IoT == 255) {
      //exit here
    }


    //Configure MAC




         rrc_mac_config_req_NB_IoT(Mod_id,
                                  CC_id,
                                  0,
                                  carrier,
                                  (SystemInformationBlockType1_NB_t*) carrier[CC_id].sib1_NB_IoT,
                                  (RadioResourceConfigCommonSIB_NB_r13_t *) &carrier[CC_id].sib2_NB_IoT->radioResourceConfigCommon_r13,
                                  (struct PhysicalConfigDedicated_NB_r13 *)NULL,
                                  (struct LogicalChannelConfig_NB_r13 *)NULL,
                                  0,
                                  0
                                  );
Nick Ho's avatar
Nick Ho committed
396 397

      LOG_I(MAC,"testing_NB_IoT config done\n");
398 399 400 401 402 403
  } else {
      LOG_E(RRC, " init_SI: FATAL, no memory for SIB23_NB_IoT allocated\n");
    //exit here
  }
}

404 405 406
//-----------------------------------------------------------------------------
static void
init_SI(
407 408
  const protocol_ctxt_t* const ctxt_pP,
  const int              CC_id
winckel's avatar
winckel committed
409
#if defined(ENABLE_ITTI)
410 411
  ,
  RrcConfigurationReq * configuration
winckel's avatar
winckel committed
412
#endif
413
)
414
//-----------------------------------------------------------------------------
415 416 417
{
  uint8_t                             SIwindowsize = 1;
  uint16_t                            SIperiod = 8;
Cedric Roux's avatar
Cedric Roux committed
418
#if defined(Rel10) || defined(Rel14)
419 420
  int                                 i;
#endif
Nick Ho's avatar
Nick Ho committed
421
  /*Nick Start*/
422

Matthieu Kanj's avatar
Matthieu Kanj committed
423
  /////////////////// for NB-IoT Initialization configuration testing  //////////////////////////////////////////////
424 425 426 427 428 429

  if(eNB_rrc_inst_NB_IoT==NULL)
    eNB_rrc_inst_NB_IoT = (eNB_RRC_INST_NB_IoT*) malloc (sizeof(eNB_RRC_INST_NB_IoT));

  init_testing_NB_IoT(ctxt_pP->module_id,CC_id,&eNB_rrc_inst_NB_IoT[ctxt_pP->module_id].carrier[CC_id],configuration,0,0);

Matthieu Kanj's avatar
Matthieu Kanj committed
430
//////////////////////////////////////// END //////////////////////////////////////////////////////////////////////////////////
Nick Ho's avatar
Nick Ho committed
431
  /*Here will copy basic parameters and implement do_MIB, rrc_eNB_carrier_data_t will add some parameters in MIB*/
Lionel Gauthier's avatar
 
Lionel Gauthier committed
432

433 434
  eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sizeof_SIB1 = 0;
  eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sizeof_SIB23 = 0;
435
  eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].SIB1 = (uint8_t*) malloc16(32);//allocation of buffer memory
Lionel Gauthier's avatar
 
Lionel Gauthier committed
436

437 438 439 440 441 442
  /*
     printf ("before SIB1 init : Nid_cell %d\n", mac_xface->lte_frame_parms->Nid_cell);
     printf ("before SIB1 init : frame_type %d,tdd_config %d\n",
     mac_xface->lte_frame_parms->frame_type,
     mac_xface->lte_frame_parms->tdd_config);
   */
Lionel Gauthier's avatar
 
Lionel Gauthier committed
443

444
  if (eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].SIB1)
Nick Ho's avatar
Nick Ho committed
445
  	/*the I/O of do_SIB1 will modify, the parameters like SIB1 siblock1 sib1 will assign in the carrier structure */
446
    eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sizeof_SIB1 = do_SIB1(
447
          ctxt_pP->module_id,
448
          CC_id,
449
          mac_xface->frame_parms,
450 451 452
          (uint8_t*)eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].SIB1, //buffer
          &eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].siblock1, //BCCH_DL_SCH message (parametro in un array)
          &eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib1 //SystemInformationBlockType1 (puntatore dentro un array)
winckel's avatar
winckel committed
453
#if defined(ENABLE_ITTI)
454
          , configuration
winckel's avatar
winckel committed
455
#endif
456
        );
457
  else {
458 459
    LOG_E(RRC, PROTOCOL_RRC_CTXT_FMT" init_SI: FATAL, no memory for SIB1 allocated\n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
460 461 462 463 464 465 466 467 468
    mac_xface->macphy_exit("[RRC][init_SI] FATAL, no memory for SIB1 allocated");
  }

  /*
     printf ("after SIB1 init : Nid_cell %d\n", mac_xface->lte_frame_parms->Nid_cell);
     printf ("after SIB1 init : frame_type %d,tdd_config %d\n",
     mac_xface->lte_frame_parms->frame_type,
     mac_xface->lte_frame_parms->tdd_config);
   */
469 470
  if (eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sizeof_SIB1 == 255) {
    mac_xface->macphy_exit("[RRC][init_SI] FATAL, eNB_rrc_inst[enb_mod_idP].carrier[CC_id].sizeof_SIB1 == 255");
471
  }
472

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

475
  if (eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].SIB23) {
Nick Ho's avatar
Nick Ho committed
476
  	/*Modify as do_sib1*/
477
    eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sizeof_SIB23 = do_SIB23(
478
          ctxt_pP->module_id,
479
          CC_id,
480
          mac_xface->frame_parms,
481 482 483 484
          eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].SIB23,
          &eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].systemInformation,
          &eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2,
          &eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib3
Cedric Roux's avatar
Cedric Roux committed
485
#if defined(Rel10) || defined(Rel14)
486 487
          , &eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib13,
          eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].MBMS_flag
488 489
#endif
#if defined(ENABLE_ITTI)
490
          , configuration
Lionel Gauthier's avatar
 
Lionel Gauthier committed
491
#endif
492
        );
493

Nick Ho's avatar
Nick Ho committed
494

495 496
    if (eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sizeof_SIB23 == 255) {
      mac_xface->macphy_exit("[RRC][init_SI] FATAL, eNB_rrc_inst[mod].carrier[CC_id].sizeof_SIB23 == 255");
497 498 499 500 501 502
    }

    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" SIB2/3 Contents (partial)\n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.n_SB = %ld\n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
503 504
          eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
          pusch_ConfigBasic.n_SB);
505 506
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.hoppingMode = %ld\n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
507 508
          eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
          pusch_ConfigBasic.hoppingMode);
509 510
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.pusch_HoppingOffset = %ld\n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
511
          eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
512
          pusch_ConfigBasic.pusch_HoppingOffset);
513 514
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.enable64QAM = %d\n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
515
          (int)eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
516
          pusch_ConfigBasic.enable64QAM);
517 518
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.groupHoppingEnabled = %d\n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
519
          (int)eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
520
          ul_ReferenceSignalsPUSCH.groupHoppingEnabled);
521 522
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.groupAssignmentPUSCH = %ld\n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
523 524
          eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
          ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH);
525 526
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.sequenceHoppingEnabled = %d\n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
527 528
          (int)eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
          ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled);
529 530
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.cyclicShift  = %ld\n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
531 532
          eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
          ul_ReferenceSignalsPUSCH.cyclicShift);
533

Cedric Roux's avatar
Cedric Roux committed
534
#if defined(Rel10) || defined(Rel14)
535

536 537
    if (eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].MBMS_flag > 0) {
      for (i = 0; i < eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->mbsfn_SubframeConfigList->list.count; i++) {
538 539
        // 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);
540 541 542
        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" SIB13 contents for MBSFN subframe allocation %d/%d(partial)\n",
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
              i,
543
              eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->mbsfn_SubframeConfigList->list.count);
544 545
        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" mbsfn_Subframe_pattern is  = %x\n",
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
546
              eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->mbsfn_SubframeConfigList->list.array[i]->subframeAllocation.choice.oneFrame.buf[0] >> 0);
547 548
        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" radioframe_allocation_period  = %ld (just index number, not the real value)\n",
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
549
              eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->mbsfn_SubframeConfigList->list.array[i]->radioframeAllocationPeriod);   // need to display the real value, using array of char (like in dumping SIB2)
550 551
        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" radioframe_allocation_offset  = %ld\n",
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
552
              eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->mbsfn_SubframeConfigList->list.array[i]->radioframeAllocationOffset);
553 554 555
      }

      //   SIB13
556
      for (i = 0; i < eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib13->mbsfn_AreaInfoList_r9.list.count; i++) {
Cedric Roux's avatar
Cedric Roux committed
557
        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" SIB13 contents for MBSFN sync area %d/%d (partial)\n",
558 559
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
              i,
560
              eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib13->mbsfn_AreaInfoList_r9.list.count);
Cedric Roux's avatar
Cedric Roux committed
561
        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" MCCH Repetition Period: %ld (just index number, not real value)\n",
562
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
563
              eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib13->mbsfn_AreaInfoList_r9.list.array[i]->mcch_Config_r9.mcch_RepetitionPeriod_r9);
Cedric Roux's avatar
Cedric Roux committed
564
        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" MCCH Offset: %ld\n",
565
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
566
              eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib13->mbsfn_AreaInfoList_r9.list.array[i]->mcch_Config_r9.mcch_Offset_r9);
567 568 569
      }
    }

570 571
#endif

572
    LOG_D(RRC,
573 574
          PROTOCOL_RRC_CTXT_FMT" RRC_UE --- MAC_CONFIG_REQ (SIB1.tdd & SIB2 params) ---> MAC_UE\n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
Nick Ho's avatar
Nick Ho committed
575
    /*modify to rrc_mac_config_req_eNB*/
576
    rrc_mac_config_req(ctxt_pP->module_id, CC_id, ENB_FLAG_YES, 0, 0,
577
                       (RadioResourceConfigCommonSIB_t *) &
578
                       eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->radioResourceConfigCommon,
579
                       (struct PhysicalConfigDedicated *)NULL,
Cedric Roux's avatar
Cedric Roux committed
580
#if defined(Rel10) || defined(Rel14)
581 582
                       (SCellToAddMod_r10_t *)NULL,
                       //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
583
#endif
584 585 586 587
                       (MeasObjectToAddMod_t **) NULL,
                       (MAC_MainConfig_t *) NULL, 0,
                       (struct LogicalChannelConfig *)NULL,
                       (MeasGapConfig_t *) NULL,
588
                       eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib1->tdd_Config,
589 590
                       NULL,
                       &SIwindowsize, &SIperiod,
591 592 593 594
                       eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->freqInfo.ul_CarrierFreq,
                       eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->freqInfo.ul_Bandwidth,
                       &eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->freqInfo.additionalSpectrumEmission,
                       (MBSFN_SubframeConfigList_t*) eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib2->mbsfn_SubframeConfigList
Cedric Roux's avatar
Cedric Roux committed
595
#if defined(Rel10) || defined(Rel14)
596
                       ,
597 598
                       eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].MBMS_flag,
                       (MBSFN_AreaInfoList_r9_t*) & eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].sib13->mbsfn_AreaInfoList_r9,
599
                       (PMCH_InfoList_r9_t *) NULL
600 601
#endif
#ifdef CBA
602 603
                       , 0, //eNB_rrc_inst[ctxt_pP->module_id].num_active_cba_groups,
                       0    //eNB_rrc_inst[ctxt_pP->module_id].cba_rnti[0]
604
#endif
605 606
                      );
  } else {
607 608
    LOG_E(RRC, PROTOCOL_RRC_CTXT_FMT" init_SI: FATAL, no memory for SIB2/3 allocated\n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
609 610
    mac_xface->macphy_exit("[RRC][init_SI] FATAL, no memory for SIB2/3 allocated");
  }
611 612
}

Cedric Roux's avatar
Cedric Roux committed
613
#if defined(Rel10) || defined(Rel14)
winckel's avatar
winckel committed
614
/*------------------------------------------------------------------------------*/
615 616
static void
init_MCCH(
617 618
  module_id_t enb_mod_idP,
  int CC_id
619 620
)
//-----------------------------------------------------------------------------
621
{
Lionel Gauthier's avatar
 
Lionel Gauthier committed
622

623 624
  int                                 sync_area = 0;
  // initialize RRC_eNB_INST MCCH entry
625
  eNB_rrc_inst[enb_mod_idP].carrier[CC_id].MCCH_MESSAGE =
626
    malloc(eNB_rrc_inst[enb_mod_idP].carrier[CC_id].num_mbsfn_sync_area * sizeof(uint8_t*));
Lionel Gauthier's avatar
 
Lionel Gauthier committed
627

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

630 631
    eNB_rrc_inst[enb_mod_idP].carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] = 0;
    eNB_rrc_inst[enb_mod_idP].carrier[CC_id].MCCH_MESSAGE[sync_area] = (uint8_t *) malloc16(32);
632

633
    if (eNB_rrc_inst[enb_mod_idP].carrier[CC_id].MCCH_MESSAGE[sync_area] == NULL) {
634 635 636
      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 {
637
      eNB_rrc_inst[enb_mod_idP].carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] = do_MBSFNAreaConfig(enb_mod_idP,
638
          mac_xface->frame_parms,
639 640 641 642 643 644 645
          sync_area,
          (uint8_t *)eNB_rrc_inst[enb_mod_idP].carrier[CC_id].MCCH_MESSAGE[sync_area],
          &eNB_rrc_inst[enb_mod_idP].carrier[CC_id].mcch,
          &eNB_rrc_inst[enb_mod_idP].carrier[CC_id].mcch_message);

      LOG_I(RRC, "mcch message pointer %p for sync area %d \n",
            eNB_rrc_inst[enb_mod_idP].carrier[CC_id].MCCH_MESSAGE[sync_area],
646 647
            sync_area);
      LOG_D(RRC, "[eNB %d] MCCH_MESSAGE  contents for Sync Area %d (partial)\n", enb_mod_idP, sync_area);
Cedric Roux's avatar
Cedric Roux committed
648
      LOG_D(RRC, "[eNB %d] CommonSF_AllocPeriod_r9 %ld\n", enb_mod_idP,
649
            eNB_rrc_inst[enb_mod_idP].carrier[CC_id].mcch_message->commonSF_AllocPeriod_r9);
650 651
      LOG_D(RRC,
            "[eNB %d] CommonSF_Alloc_r9.list.count (number of MBSFN Subframe Pattern) %d\n",
652
            enb_mod_idP, eNB_rrc_inst[enb_mod_idP].carrier[CC_id].mcch_message->commonSF_Alloc_r9.list.count);
653 654
      LOG_D(RRC, "[eNB %d] MBSFN Subframe Pattern: %02x (in hex)\n",
            enb_mod_idP,
655
            eNB_rrc_inst[enb_mod_idP].carrier[CC_id].mcch_message->commonSF_Alloc_r9.list.array[0]->subframeAllocation.
656 657
            choice.oneFrame.buf[0]);

658 659
      if (eNB_rrc_inst[enb_mod_idP].carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] == 255) {
        mac_xface->macphy_exit("[RRC][init_MCCH] eNB_rrc_inst[enb_mod_idP].carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] == 255");
660
      } else {
661
        eNB_rrc_inst[enb_mod_idP].carrier[CC_id].MCCH_MESS[sync_area].Active = 1;
662
      }
663
    }
664
  }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
665

666
  //Set the eNB_rrc_inst[enb_mod_idP].MCCH_MESS.Active to 1 (allow to  transfer MCCH message RRC->MAC in function mac_rrc_data_req)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
667

668 669 670 671 672
  // ??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]);
673
  rrc_mac_config_req(enb_mod_idP, CC_id, ENB_FLAG_YES, 0, 0,
674 675
                     (RadioResourceConfigCommonSIB_t *) NULL,
                     (struct PhysicalConfigDedicated *)NULL,
Cedric Roux's avatar
Cedric Roux committed
676
#if defined(Rel10) || defined(Rel14)
677 678 679 680 681 682 683 684 685 686
                     (SCellToAddMod_r10_t *)NULL,
                     //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
#endif
                     (MeasObjectToAddMod_t **) NULL,
                     (MAC_MainConfig_t *) NULL,
                     0,
                     (struct LogicalChannelConfig *)NULL,
                     (MeasGapConfig_t *) NULL,
                     (TDD_Config_t *) NULL,
                     NULL, (uint8_t *) NULL, (uint16_t *) NULL, NULL, NULL, NULL, (MBSFN_SubframeConfigList_t *) NULL
Cedric Roux's avatar
Cedric Roux committed
687
#   if defined(Rel10) || defined(Rel14)
688 689 690
                     ,
                     0,
                     (MBSFN_AreaInfoList_r9_t *) NULL,
691
                     (PMCH_InfoList_r9_t *) & (eNB_rrc_inst[enb_mod_idP].carrier[CC_id].mcch_message->pmch_InfoList_r9)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
692 693
#   endif
#   ifdef CBA
694
                     , 0, 0
Lionel Gauthier's avatar
 
Lionel Gauthier committed
695
#   endif
696
                    );
697

698
  //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);
699

700 701
}

702
//-----------------------------------------------------------------------------
Lionel Gauthier's avatar
 
Lionel Gauthier committed
703
static void init_MBMS(
704
  module_id_t enb_mod_idP,
705
  int         CC_id,
706 707 708
  frame_t frameP
)
//-----------------------------------------------------------------------------
709 710 711
{
  // init the configuration for MTCH
  protocol_ctxt_t               ctxt;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
712

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

716 717
    LOG_D(RRC, "[eNB %d] Frame %d : Radio Bearer config request for MBMS\n", enb_mod_idP, frameP);   //check the lcid
    // Configuring PDCP and RLC for MBMS Radio Bearer
Lionel Gauthier's avatar
 
Lionel Gauthier committed
718

719 720 721 722 723 724 725 726
    rrc_pdcp_config_asn1_req(&ctxt,
                             (SRB_ToAddModList_t  *)NULL,  // SRB_ToAddModList
                             (DRB_ToAddModList_t  *)NULL,  // DRB_ToAddModList
                             (DRB_ToReleaseList_t *)NULL,
                             0,     // security mode
                             NULL,  // key rrc encryption
                             NULL,  // key rrc integrity
                             NULL   // key encryption
Cedric Roux's avatar
Cedric Roux committed
727
#   if defined(Rel10) || defined(Rel14)
728
                             , &(eNB_rrc_inst[enb_mod_idP].carrier[CC_id].mcch_message->pmch_InfoList_r9)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
729
#   endif
730
                             ,NULL);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
731

732 733 734 735
    rrc_rlc_config_asn1_req(&ctxt,
                            NULL, // SRB_ToAddModList
                            NULL,   // DRB_ToAddModList
                            NULL,   // DRB_ToReleaseList
736
                            &(eNB_rrc_inst[enb_mod_idP].carrier[CC_id].mcch_message->pmch_InfoList_r9));
Lionel Gauthier's avatar
 
Lionel Gauthier committed
737

738 739
    //rrc_mac_config_req();
  }
740 741 742
}
#endif

743 744 745 746 747 748
//-----------------------------------------------------------------------------
uint8_t
rrc_eNB_get_next_transaction_identifier(
  module_id_t enb_mod_idP
)
//-----------------------------------------------------------------------------
749
{
750 751
  static uint8_t                      rrc_transaction_identifier[NUMBER_OF_eNB_MAX];
  rrc_transaction_identifier[enb_mod_idP] = (rrc_transaction_identifier[enb_mod_idP] + 1) % RRC_TRANSACTION_IDENTIFIER_NUMBER;
752
  LOG_T(RRC,"generated xid is %d\n",rrc_transaction_identifier[enb_mod_idP]);
753 754 755 756 757
  return rrc_transaction_identifier[enb_mod_idP];
}
/*------------------------------------------------------------------------------*/
/* Functions to handle UE index in eNB UE list */

winckel's avatar
winckel committed
758

759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787
////-----------------------------------------------------------------------------
//static module_id_t
//rrc_eNB_get_UE_index(
//                module_id_t enb_mod_idP,
//                uint64_t    UE_identity
//)
////-----------------------------------------------------------------------------
//{
//
//    boolean_t      reg = FALSE;
//    module_id_t    i;
//
//    AssertFatal(enb_mod_idP < NB_eNB_INST, "eNB index invalid (%d/%d)!", enb_mod_idP, NB_eNB_INST);
//
//    for (i = 0; i < NUMBER_OF_UE_MAX; i++) {
//        if (eNB_rrc_inst[enb_mod_idP].Info.UE_list[i] == UE_identity) {
//            // UE_identity already registered
//            reg = TRUE;
//            break;
//        }
//    }
//
//    if (reg == FALSE) {
//        return (UE_MODULE_INVALID);
//    } else
//        return (i);
//}


788
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
789 790
// return the ue context if there is already an UE with ue_identityP, NULL otherwise
static struct rrc_eNB_ue_context_s*
791 792 793 794 795 796 797 798 799
rrc_eNB_ue_context_random_exist(
  const protocol_ctxt_t* const ctxt_pP,
  const uint64_t               ue_identityP
)
//-----------------------------------------------------------------------------
{
  struct rrc_eNB_ue_context_s*        ue_context_p = NULL;
  RB_FOREACH(ue_context_p, rrc_ue_tree_s, &(eNB_rrc_inst[ctxt_pP->module_id].rrc_ue_head)) {
    if (ue_context_p->ue_context.random_ue_identity == ue_identityP)
gauthier's avatar
gauthier committed
800
      return ue_context_p;
801
  }
gauthier's avatar
gauthier committed
802 803 804 805 806 807 808 809 810 811 812 813 814 815
  return NULL;
}
//-----------------------------------------------------------------------------
// return the ue context if there is already an UE with the same S-TMSI(MMEC+M-TMSI), NULL otherwise
static struct rrc_eNB_ue_context_s*
rrc_eNB_ue_context_stmsi_exist(
  const protocol_ctxt_t* const ctxt_pP,
  const mme_code_t             mme_codeP,
  const m_tmsi_t               m_tmsiP
)
//-----------------------------------------------------------------------------
{
  struct rrc_eNB_ue_context_s*        ue_context_p = NULL;
  RB_FOREACH(ue_context_p, rrc_ue_tree_s, &(eNB_rrc_inst[ctxt_pP->module_id].rrc_ue_head)) {
kaltenbe's avatar
kaltenbe committed
816 817 818 819
    LOG_I(RRC,"checking for UE S-TMSI %x, mme %x (%p): rnti %x",
	  m_tmsiP, mme_codeP, ue_context_p, 
	  ue_context_p->ue_context.rnti);
    if (ue_context_p->ue_context.Initialue_identity_s_TMSI.presence == TRUE) {
820
      printf("=> S-TMSI %x, MME %x\n",
kaltenbe's avatar
kaltenbe committed
821 822
	    ue_context_p->ue_context.Initialue_identity_s_TMSI.m_tmsi,
	    ue_context_p->ue_context.Initialue_identity_s_TMSI.mme_code);
gauthier's avatar
gauthier committed
823 824 825
      if (ue_context_p->ue_context.Initialue_identity_s_TMSI.m_tmsi == m_tmsiP)
        if (ue_context_p->ue_context.Initialue_identity_s_TMSI.mme_code == mme_codeP)
          return ue_context_p;
kaltenbe's avatar
kaltenbe committed
826 827 828 829
    }
    else
      printf("\n");

gauthier's avatar
gauthier committed
830 831
  }
  return NULL;
832 833
}

834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851
//-----------------------------------------------------------------------------
// return a new ue context structure if ue_identityP, ctxt_pP->rnti not found in collection
static struct rrc_eNB_ue_context_s*
rrc_eNB_get_next_free_ue_context(
  const protocol_ctxt_t* const ctxt_pP,
  const uint64_t               ue_identityP
)
//-----------------------------------------------------------------------------
{
  struct rrc_eNB_ue_context_s*        ue_context_p = NULL;
  ue_context_p = rrc_eNB_get_ue_context(
                   &eNB_rrc_inst[ctxt_pP->module_id],
                   ctxt_pP->rnti);

  if (ue_context_p == NULL) {
    RB_FOREACH(ue_context_p, rrc_ue_tree_s, &(eNB_rrc_inst[ctxt_pP->module_id].rrc_ue_head)) {
      if (ue_context_p->ue_context.random_ue_identity == ue_identityP) {
        LOG_D(RRC,
Cedric Roux's avatar
Cedric Roux committed
852
              PROTOCOL_RRC_CTXT_UE_FMT" Cannot create new UE context, already exist rand UE id 0x%"PRIx64", uid %u\n",
853 854 855 856 857 858 859
              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
              ue_identityP,
              ue_context_p->local_uid);
        return NULL;
      }
    }
    ue_context_p = rrc_eNB_allocate_new_UE_context(&eNB_rrc_inst[ctxt_pP->module_id]);
winckel's avatar
winckel committed
860

861 862 863 864 865
    if (ue_context_p == NULL) {
      LOG_E(RRC,
            PROTOCOL_RRC_CTXT_UE_FMT" Cannot create new UE context, no memory\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
      return NULL;
866
    }
867

868 869 870 871 872 873 874 875 876
    ue_context_p->ue_id_rnti                    = ctxt_pP->rnti; // here ue_id_rnti is just a key, may be something else
    ue_context_p->ue_context.rnti               = ctxt_pP->rnti; // yes duplicate, 1 may be removed
    ue_context_p->ue_context.random_ue_identity = ue_identityP;
    RB_INSERT(rrc_ue_tree_s, &eNB_rrc_inst[ctxt_pP->module_id].rrc_ue_head, ue_context_p);
    LOG_D(RRC,
          PROTOCOL_RRC_CTXT_UE_FMT" Created new UE context uid %u\n",
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
          ue_context_p->local_uid);
    return ue_context_p;
winckel's avatar
winckel committed
877

878 879 880 881 882 883
  } else {
    LOG_E(RRC,
          PROTOCOL_RRC_CTXT_UE_FMT" Cannot create new UE context, already exist\n",
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
    return NULL;
  }
winckel's avatar
winckel committed
884 885
}

886 887 888 889 890 891 892 893
#if !defined(ENABLE_USE_MME)
void rrc_eNB_emulation_notify_ue_module_id(
  const module_id_t ue_module_idP,
  const rnti_t      rntiP,
  const uint8_t     cell_identity_byte0P,
  const uint8_t     cell_identity_byte1P,
  const uint8_t     cell_identity_byte2P,
  const uint8_t     cell_identity_byte3P)
894
{
895 896
  module_id_t                         enb_module_id;
  struct rrc_eNB_ue_context_s*        ue_context_p = NULL;
897
  int                                 CC_id;
898 899 900

  // find enb_module_id
  for (enb_module_id = 0; enb_module_id < NUMBER_OF_eNB_MAX; enb_module_id++) {
901 902 903
    if(enb_module_id>0){ /*FIX LATER*/
      return;
    }
904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919
    for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
      if (eNB_rrc_inst[enb_module_id].carrier[CC_id].sib1 != NULL) {
        if (
          (eNB_rrc_inst[enb_module_id].carrier[CC_id].sib1->cellAccessRelatedInfo.cellIdentity.buf[0] == cell_identity_byte0P) &&
          (eNB_rrc_inst[enb_module_id].carrier[CC_id].sib1->cellAccessRelatedInfo.cellIdentity.buf[1] == cell_identity_byte1P) &&
          (eNB_rrc_inst[enb_module_id].carrier[CC_id].sib1->cellAccessRelatedInfo.cellIdentity.buf[2] == cell_identity_byte2P) &&
          (eNB_rrc_inst[enb_module_id].carrier[CC_id].sib1->cellAccessRelatedInfo.cellIdentity.buf[3] == cell_identity_byte3P)
        ) {
          ue_context_p = rrc_eNB_get_ue_context(
                           &eNB_rrc_inst[enb_module_id],
                           rntiP
                         );

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

921
          //return;
922
        }
923 924
      }
    }
925
    oai_emulation.info.eNB_ue_module_id_to_rnti[enb_module_id][ue_module_idP] = rntiP;
926
  }
winckel's avatar
winckel committed
927

928 929 930 931 932
  AssertFatal(enb_module_id == NUMBER_OF_eNB_MAX,
              "Cell identity not found for ue module id %u rnti %x",
              ue_module_idP, rntiP);
}
#endif
933

934 935 936 937 938
//-----------------------------------------------------------------------------
void
rrc_eNB_free_mem_UE_context(
  const protocol_ctxt_t*               const ctxt_pP,
  struct rrc_eNB_ue_context_s*         const ue_context_pP
939
)
940
//-----------------------------------------------------------------------------
Lionel Gauthier's avatar
Lionel Gauthier committed
941
{
942 943
  int i;
  LOG_T(RRC,
Cedric Roux's avatar
Cedric Roux committed
944
        PROTOCOL_RRC_CTXT_UE_FMT" Clearing UE context 0x%p (free internal structs)\n",
945 946
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
        ue_context_pP);
Cedric Roux's avatar
Cedric Roux committed
947
#if defined(Rel10) || defined(Rel14)
948 949 950 951 952 953 954 955
  ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_SCellToAddMod_r10, &ue_context_pP->ue_context.sCell_config[0]);
  ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_SCellToAddMod_r10, &ue_context_pP->ue_context.sCell_config[1]);
#endif

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

957 958 959 960
  if (ue_context_pP->ue_context.DRB_configList) {
    ASN_STRUCT_FREE(asn_DEF_DRB_ToAddModList, ue_context_pP->ue_context.DRB_configList);
    ue_context_pP->ue_context.DRB_configList = NULL;
  }
961

962
  memset(ue_context_pP->ue_context.DRB_active, 0, sizeof(ue_context_pP->ue_context.DRB_active));
963

964 965 966
  if (ue_context_pP->ue_context.physicalConfigDedicated) {
    ASN_STRUCT_FREE(asn_DEF_PhysicalConfigDedicated, ue_context_pP->ue_context.physicalConfigDedicated);
    ue_context_pP->ue_context.physicalConfigDedicated = NULL;
967 968
  }

969 970 971
  if (ue_context_pP->ue_context.sps_Config) {
    ASN_STRUCT_FREE(asn_DEF_SPS_Config, ue_context_pP->ue_context.sps_Config);
    ue_context_pP->ue_context.sps_Config = NULL;
972 973
  }

974 975 976 977 978
  for (i=0; i < MAX_MEAS_OBJ; i++) {
    if (ue_context_pP->ue_context.MeasObj[i] != NULL) {
      ASN_STRUCT_FREE(asn_DEF_MeasObjectToAddMod, ue_context_pP->ue_context.MeasObj[i]);
      ue_context_pP->ue_context.MeasObj[i] = NULL;
    }
979
  }
980

981 982 983 984 985 986
  for (i=0; i < MAX_MEAS_CONFIG; i++) {
    if (ue_context_pP->ue_context.ReportConfig[i] != NULL) {
      ASN_STRUCT_FREE(asn_DEF_ReportConfigToAddMod, ue_context_pP->ue_context.ReportConfig[i]);
      ue_context_pP->ue_context.ReportConfig[i] = NULL;
    }
  }
987

988 989 990 991
  if (ue_context_pP->ue_context.QuantityConfig) {
    ASN_STRUCT_FREE(asn_DEF_QuantityConfig, ue_context_pP->ue_context.QuantityConfig);
    ue_context_pP->ue_context.QuantityConfig = NULL;
  }
992

993 994 995 996
  if (ue_context_pP->ue_context.mac_MainConfig) {
    ASN_STRUCT_FREE(asn_DEF_MAC_MainConfig, ue_context_pP->ue_context.mac_MainConfig);
    ue_context_pP->ue_context.mac_MainConfig = NULL;
  }
997

998 999 1000 1001
  if (ue_context_pP->ue_context.measGapConfig) {
    ASN_STRUCT_FREE(asn_DEF_MeasGapConfig, ue_context_pP->ue_context.measGapConfig);
    ue_context_pP->ue_context.measGapConfig = NULL;
  }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1002

1003 1004 1005 1006 1007 1008 1009
  //SRB_INFO                           SI;
  //SRB_INFO                           Srb0;
  //SRB_INFO_TABLE_ENTRY               Srb1;
  //SRB_INFO_TABLE_ENTRY               Srb2;
  if (ue_context_pP->ue_context.measConfig) {
    ASN_STRUCT_FREE(asn_DEF_MeasConfig, ue_context_pP->ue_context.measConfig);
    ue_context_pP->ue_context.measConfig = NULL;
1010
  }
1011

1012 1013 1014
  if (ue_context_pP->ue_context.measConfig) {
    ASN_STRUCT_FREE(asn_DEF_MeasConfig, ue_context_pP->ue_context.measConfig);
    ue_context_pP->ue_context.measConfig = NULL;
1015
  }
1016

1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038
  //HANDOVER_INFO                     *handover_info;
#if defined(ENABLE_SECURITY)
  //uint8_t kenb[32];
#endif
  //e_SecurityAlgorithmConfig__cipheringAlgorithm     ciphering_algorithm;
  //e_SecurityAlgorithmConfig__integrityProtAlgorithm integrity_algorithm;
  //uint8_t                            Status;
  //rnti_t                             rnti;
  //uint64_t                           random_ue_identity;
#if defined(ENABLE_ITTI)
  //UE_S_TMSI                          Initialue_identity_s_TMSI;
  //EstablishmentCause_t               establishment_cause;
  //ReestablishmentCause_t             reestablishment_cause;
  //uint16_t                           ue_initial_id;
  //uint32_t                           eNB_ue_s1ap_id :24;
  //security_capabilities_t            security_capabilities;
  //uint8_t                            nb_of_e_rabs;
  //e_rab_param_t                      e_rab[S1AP_MAX_E_RAB];
  //uint32_t                           enb_gtp_teid[S1AP_MAX_E_RAB];
  //transport_layer_addr_t             enb_gtp_addrs[S1AP_MAX_E_RAB];
  //rb_id_t                            enb_gtp_ebi[S1AP_MAX_E_RAB];
#endif
1039 1040
}

1041
//-----------------------------------------------------------------------------
1042
// should be called when UE is lost by eNB
1043
void
1044
rrc_eNB_free_UE(const module_id_t enb_mod_idP,const struct rrc_eNB_ue_context_s*        const ue_context_pP)
1045
//-----------------------------------------------------------------------------
Lionel Gauthier's avatar
Lionel Gauthier committed
1046
{
Raymond Knopp's avatar
 
Raymond Knopp committed
1047

1048

1049
  protocol_ctxt_t                     ctxt;
1050 1051
#if !defined(ENABLE_USE_MME)
  module_id_t                         ue_module_id;
Cedric Roux's avatar
Cedric Roux committed
1052 1053
  /* avoid gcc warnings */
  (void)ue_module_id;
1054
#endif
1055 1056 1057 1058 1059
  rnti_t rnti = ue_context_pP->ue_context.rnti;


  AssertFatal(enb_mod_idP < NB_eNB_INST, "eNB inst invalid (%d/%d) for UE %x!", enb_mod_idP, NB_eNB_INST, rnti);
  /*  ue_context_p = rrc_eNB_get_ue_context(
1060 1061 1062
                   &eNB_rrc_inst[enb_mod_idP],
                   rntiP
                 );
1063 1064 1065 1066
  */
  if (NULL != ue_context_pP) {
    PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, enb_mod_idP, ENB_FLAG_YES, rnti, 0, 0,enb_mod_idP);
    LOG_W(RRC, "[eNB %d] Removing UE RNTI %x\n", enb_mod_idP, rnti);
Lionel Gauthier's avatar
Lionel Gauthier committed
1067 1068

#if defined(ENABLE_USE_MME)
1069
    rrc_eNB_send_S1AP_UE_CONTEXT_RELEASE_REQ(enb_mod_idP, ue_context_pP, S1AP_CAUSE_RADIO_NETWORK, 21); // send cause 21: connection with ue lost
1070 1071 1072 1073 1074 1075
    /* From 3GPP 36300v10 p129 : 19.2.2.2.2 S1 UE Context Release Request (eNB triggered)
     * If the E-UTRAN internal reason is a radio link failure detected in the eNB, the eNB shall wait a sufficient time before
     *  triggering the S1 UE Context Release Request procedure
     *  in order to allow the UE to perform the NAS recovery
     *  procedure, see TS 23.401 [17].
     */
1076
#else
1077
#if defined(OAI_EMU)
1078 1079 1080 1081
    AssertFatal(ue_context_pP->local_uid < NUMBER_OF_UE_MAX, "local_uid invalid (%d<%d) for UE %x!", ue_context_pP->local_uid, NUMBER_OF_UE_MAX, rnti);
    ue_module_id = oai_emulation.info.eNB_ue_local_uid_to_ue_module_id[enb_mod_idP][ue_context_pP->local_uid];
    AssertFatal(ue_module_id < NUMBER_OF_UE_MAX, "ue_module_id invalid (%d<%d) for UE %x!", ue_module_id, NUMBER_OF_UE_MAX, rnti);
    oai_emulation.info.eNB_ue_local_uid_to_ue_module_id[enb_mod_idP][ue_context_pP->local_uid] = -1;
1082
    oai_emulation.info.eNB_ue_module_id_to_rnti[enb_mod_idP][ue_module_id] = NOT_A_RNTI;
1083
#endif
Lionel Gauthier's avatar
Lionel Gauthier committed
1084
#endif
1085

1086
    rrc_mac_remove_ue(enb_mod_idP,rnti);
1087 1088
    rrc_rlc_remove_ue(&ctxt);
    pdcp_remove_UE(&ctxt);
Raymond Knopp's avatar
 
Raymond Knopp committed
1089

1090 1091 1092
    rrc_eNB_remove_ue_context(
      &ctxt,
      &eNB_rrc_inst[enb_mod_idP],
1093
      (struct rrc_eNB_ue_context_s*) ue_context_pP);
1094
  }
1095 1096
}

1097 1098 1099 1100
//-----------------------------------------------------------------------------
void
rrc_eNB_process_RRCConnectionSetupComplete(
  const protocol_ctxt_t* const ctxt_pP,
1101
  rrc_eNB_ue_context_t*         ue_context_pP,
1102 1103
  RRCConnectionSetupComplete_r8_IEs_t * rrcConnectionSetupComplete
)
1104
//-----------------------------------------------------------------------------
Lionel Gauthier's avatar
Lionel Gauthier committed
1105
{
1106
  LOG_I(RRC,
1107
        PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel UL-DCCH, " "processing RRCConnectionSetupComplete from UE (SRB1 Active)\n",
1108
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
winckel's avatar
winckel committed
1109

1110
  ue_context_pP->ue_context.Srb1.Active=1;  //attivo SRB1
Cedric Roux's avatar
Cedric Roux committed
1111 1112 1113
  T(T_ENB_RRC_CONNECTION_SETUP_COMPLETE, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

winckel's avatar
winckel committed
1114
#if defined(ENABLE_USE_MME)
1115 1116 1117

  if (EPC_MODE_ENABLED == 1) {
    // Forward message to S1AP layer
1118 1119 1120 1121
    rrc_eNB_send_S1AP_NAS_FIRST_REQ(
      ctxt_pP,
      ue_context_pP,
      rrcConnectionSetupComplete);
1122
  } else
winckel's avatar
winckel committed
1123
#endif
1124 1125
  {
    // RRC loop back (no S1AP), send SecurityModeCommand to UE
1126 1127 1128
    rrc_eNB_generate_SecurityModeCommand(
      ctxt_pP,
      ue_context_pP);
1129 1130
    // rrc_eNB_generate_UECapabilityEnquiry(enb_mod_idP,frameP,ue_mod_idP);
  }
winckel's avatar
winckel committed
1131 1132
}

1133 1134 1135 1136 1137
//-----------------------------------------------------------------------------
void
rrc_eNB_generate_SecurityModeCommand(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t*          const ue_context_pP
1138
)
1139
//-----------------------------------------------------------------------------
Lionel Gauthier's avatar
Lionel Gauthier committed
1140
{
1141 1142
  uint8_t                             buffer[100];
  uint8_t                             size;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1143

Cedric Roux's avatar
Cedric Roux committed
1144 1145 1146
  T(T_ENB_RRC_SECURITY_MODE_COMMAND, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

1147 1148 1149 1150 1151 1152
  size = do_SecurityModeCommand(
           ctxt_pP,
           buffer,
           rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),
           ue_context_pP->ue_context.ciphering_algorithm,
           ue_context_pP->ue_context.integrity_algorithm);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1153

1154
#ifdef RRC_MSG_PRINT
1155 1156 1157
  uint16_t i=0;
  LOG_F(RRC,"[MSG] RRC Security Mode Command\n");

1158
  for (i = 0; i < size; i++) {
1159
    LOG_F(RRC,"%02x ", ((uint8_t*)buffer)[i]);
1160
  }
1161 1162

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

1165
  LOG_I(RRC,
1166 1167 1168
        PROTOCOL_RRC_CTXT_UE_FMT" Logical Channel DL-DCCH, Generate SecurityModeCommand (bytes %d)\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
        size);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1169

1170
  LOG_D(RRC,
1171 1172 1173 1174 1175
        PROTOCOL_RRC_CTXT_UE_FMT" --- PDCP_DATA_REQ/%d Bytes (securityModeCommand to UE MUI %d) --->[PDCP][RB %02d]\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
        size,
        rrc_eNB_mui,
        DCCH);
1176 1177

  MSC_LOG_TX_MESSAGE(
1178 1179 1180 1181 1182 1183 1184 1185 1186
    MSC_RRC_ENB,
    MSC_RRC_UE,
    buffer,
    size,
    MSC_AS_TIME_FMT" securityModeCommand UE %x MUI %d size %u",
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP->ue_context.rnti,
    rrc_eNB_mui,
    size);
1187

1188 1189 1190 1191 1192 1193 1194 1195
  rrc_data_req(
	       ctxt_pP,
	       DCCH,
	       rrc_eNB_mui++,
	       SDU_CONFIRM_NO,
	       size,
	       buffer,
	       PDCP_TRANSMISSION_MODE_CONTROL);
1196 1197 1198

}

1199 1200 1201 1202 1203 1204 1205
//-----------------------------------------------------------------------------
void
rrc_eNB_generate_UECapabilityEnquiry(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t*          const ue_context_pP
)
//-----------------------------------------------------------------------------
1206
{
1207

1208 1209
  uint8_t                             buffer[100];
  uint8_t                             size;
1210

Cedric Roux's avatar
Cedric Roux committed
1211 1212 1213
  T(T_ENB_RRC_UE_CAPABILITY_ENQUIRY, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

1214 1215 1216 1217
  size = do_UECapabilityEnquiry(
           ctxt_pP,
           buffer,
           rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id));
winckel's avatar
winckel committed
1218

1219
  LOG_I(RRC,
1220 1221 1222
        PROTOCOL_RRC_CTXT_UE_FMT" Logical Channel DL-DCCH, Generate UECapabilityEnquiry (bytes %d)\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
        size);
winckel's avatar
winckel committed
1223

1224
  LOG_D(RRC,
1225 1226 1227 1228 1229
        PROTOCOL_RRC_CTXT_UE_FMT" --- PDCP_DATA_REQ/%d Bytes (UECapabilityEnquiry MUI %d) --->[PDCP][RB %02d]\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
        size,
        rrc_eNB_mui,
        DCCH);
1230 1231

  MSC_LOG_TX_MESSAGE(
1232 1233 1234 1235 1236 1237 1238 1239 1240
    MSC_RRC_ENB,
    MSC_RRC_UE,
    buffer,
    size,
    MSC_AS_TIME_FMT" rrcUECapabilityEnquiry UE %x MUI %d size %u",
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP->ue_context.rnti,
    rrc_eNB_mui,
    size);
1241

1242 1243 1244 1245 1246 1247 1248 1249
  rrc_data_req(
	       ctxt_pP,
	       DCCH,
	       rrc_eNB_mui++,
	       SDU_CONFIRM_NO,
	       size,
	       buffer,
	       PDCP_TRANSMISSION_MODE_CONTROL);
1250 1251 1252

}

1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265
//-----------------------------------------------------------------------------
void
rrc_eNB_generate_RRCConnectionReject(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t*          const ue_context_pP,
  const int                    CC_id
)
//-----------------------------------------------------------------------------
{
#ifdef RRC_MSG_PRINT
  int                                 cnt;
#endif

Cedric Roux's avatar
Cedric Roux committed
1266 1267 1268
  T(T_ENB_RRC_CONNECTION_REJECT, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298
  eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].Srb0.Tx_buffer.payload_size =
    do_RRCConnectionReject(ctxt_pP->module_id,
                          (uint8_t*) eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].Srb0.Tx_buffer.Payload);

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

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

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

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

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

1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311
//-----------------------------------------------------------------------------
void
rrc_eNB_generate_RRCConnectionReestablishmentReject(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t*          const ue_context_pP,
  const int                    CC_id
)
//-----------------------------------------------------------------------------
{
#ifdef RRC_MSG_PRINT
  int                                 cnt;
#endif

Cedric Roux's avatar
Cedric Roux committed
1312 1313 1314
  T(T_ENB_RRC_CONNECTION_REESTABLISHMENT_REJECT, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335
  eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].Srb0.Tx_buffer.payload_size =
    do_RRCConnectionReestablishmentReject(ctxt_pP->module_id,
                          (uint8_t*) eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].Srb0.Tx_buffer.Payload);

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

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

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

  MSC_LOG_TX_MESSAGE(
    MSC_RRC_ENB,
    MSC_RRC_UE,
    eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].Srb0.Tx_buffer.Header,
    eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].Srb0.Tx_buffer.payload_size,
    MSC_AS_TIME_FMT" RRCConnectionReestablishmentReject UE %x size %u",
    MSC_AS_TIME_ARGS(ctxt_pP),
navid's avatar
navid committed
1336
    ue_context_pP == NULL ? -1 : ue_context_pP->ue_context.rnti,
1337 1338 1339 1340 1341 1342 1343 1344
    eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].Srb0.Tx_buffer.payload_size);

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

1345 1346 1347 1348 1349 1350 1351
//-----------------------------------------------------------------------------
void
rrc_eNB_generate_RRCConnectionRelease(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t*          const ue_context_pP
)
//-----------------------------------------------------------------------------
1352
{
Raymond Knopp's avatar
 
Raymond Knopp committed
1353

1354 1355
  uint8_t                             buffer[RRC_BUF_SIZE];
  uint16_t                            size;
Raymond Knopp's avatar
 
Raymond Knopp committed
1356

Cedric Roux's avatar
Cedric Roux committed
1357 1358 1359
  T(T_ENB_RRC_CONNECTION_RELEASE, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

1360
  memset(buffer, 0, RRC_BUF_SIZE);
Raymond Knopp's avatar
 
Raymond Knopp committed
1361

1362
  size = do_RRCConnectionRelease(ctxt_pP->module_id, buffer,rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id));
1363 1364
  // set release timer
  ue_context_pP->ue_context.ue_release_timer=1;
1365 1366
  // remove UE after 10 frames after RRCConnectionRelease is triggered
  ue_context_pP->ue_context.ue_release_timer_thres=100;
1367
  LOG_I(RRC,
1368 1369 1370
        PROTOCOL_RRC_CTXT_UE_FMT" Logical Channel DL-DCCH, Generate RRCConnectionRelease (bytes %d)\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
        size);
Raymond Knopp's avatar
 
Raymond Knopp committed
1371

1372
  LOG_D(RRC,
1373 1374 1375 1376 1377
        PROTOCOL_RRC_CTXT_UE_FMT" --- PDCP_DATA_REQ/%d Bytes (rrcConnectionRelease MUI %d) --->[PDCP][RB %u]\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
        size,
        rrc_eNB_mui,
        DCCH);
1378 1379

  MSC_LOG_TX_MESSAGE(
1380 1381 1382 1383 1384 1385 1386 1387 1388
    MSC_RRC_ENB,
    MSC_RRC_UE,
    buffer,
    size,
    MSC_AS_TIME_FMT" rrcConnectionRelease UE %x MUI %d size %u",
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP->ue_context.rnti,
    rrc_eNB_mui,
    size);
1389

1390 1391 1392 1393 1394 1395 1396 1397
  rrc_data_req(
	       ctxt_pP,
	       DCCH,
	       rrc_eNB_mui++,
	       SDU_CONFIRM_NO,
	       size,
	       buffer,
	       PDCP_TRANSMISSION_MODE_CONTROL);
Raymond Knopp's avatar
 
Raymond Knopp committed
1398
}
1399

1400 1401
uint8_t qci_to_priority[9]={2,4,3,5,1,6,7,8,9};

1402 1403
// TBD: this directive can be remived if we create a similar e_rab_param_t structure in RRC context
#if defined(ENABLE_ITTI) 
1404 1405
//-----------------------------------------------------------------------------
void
1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423
rrc_eNB_generate_dedicatedRRCConnectionReconfiguration(const protocol_ctxt_t* const ctxt_pP,
						     rrc_eNB_ue_context_t*          const ue_context_pP,
						     const uint8_t                ho_state
						     )
//-----------------------------------------------------------------------------
{
  
  uint8_t                             buffer[RRC_BUF_SIZE];
  uint16_t                            size;
  int i;
  
  struct DRB_ToAddMod                *DRB_config                       = NULL;
  struct RLC_Config                  *DRB_rlc_config                   = NULL;
  struct PDCP_Config                 *DRB_pdcp_config                  = NULL;
  struct PDCP_Config__rlc_AM         *PDCP_rlc_AM                      = NULL;
  struct PDCP_Config__rlc_UM         *PDCP_rlc_UM                      = NULL;
  struct LogicalChannelConfig        *DRB_lchan_config                 = NULL;
  struct LogicalChannelConfig__ul_SpecificParameters
1424
    *DRB_ul_SpecificParameters        = NULL;
1425 1426
  //  DRB_ToAddModList_t**                DRB_configList=&ue_context_pP->ue_context.DRB_configList; 
  DRB_ToAddModList_t*                DRB_configList=ue_context_pP->ue_context.DRB_configList; 
1427
  DRB_ToAddModList_t**                DRB_configList2=NULL;
1428 1429 1430 1431
  //DRB_ToAddModList_t**                RRC_DRB_configList=&ue_context_pP->ue_context.DRB_configList;

  struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList = NULL;
  DedicatedInfoNAS_t                 *dedicatedInfoNas                 = NULL;
1432 1433
  /* for no gcc warnings */
  (void)dedicatedInfoNas;
1434

1435 1436
  long  *logicalchannelgroup_drb;
  int drb_identity_index=0;
1437 1438

  uint8_t xid = rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id);   //Transaction_id,
1439 1440 1441 1442
  DRB_configList2=&ue_context_pP->ue_context.DRB_configList2[xid];
  if (*DRB_configList2) {
    free(*DRB_configList2);
  }
1443
  //*DRB_configList = CALLOC(1, sizeof(*DRB_configList));
1444 1445
  *DRB_configList2 = CALLOC(1, sizeof(**DRB_configList2)); 
  /* Initialize NAS list */
1446
  dedicatedInfoNASList = CALLOC(1, sizeof(struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList));
Navid Nikaein's avatar
Navid Nikaein committed
1447 1448

  int e_rab_done=0;
1449 1450
  
  for ( i = 0  ;
1451
	i < ue_context_pP->ue_context.setup_e_rabs ;
1452
	i++){
1453
    
1454
    // bypass the new and already configured erabs
1455
    if (ue_context_pP->ue_context.e_rab[i].status >= E_RAB_STATUS_DONE) {
1456
      drb_identity_index++;
1457 1458
      continue;
    }
1459
        
1460 1461 1462
    DRB_config = CALLOC(1, sizeof(*DRB_config));

    DRB_config->eps_BearerIdentity = CALLOC(1, sizeof(long));
Navid Nikaein's avatar
Navid Nikaein committed
1463
    // allowed value 5..15, value : x+4
1464
    *(DRB_config->eps_BearerIdentity) = ue_context_pP->ue_context.e_rab[i].param.e_rab_id;//+ 4; // especial case generation  
1465

Navid Nikaein's avatar
Navid Nikaein committed
1466
    DRB_config->drb_Identity =  1 + drb_identity_index + e_rab_done;// + i ;// (DRB_Identity_t) ue_context_pP->ue_context.e_rab[i].param.e_rab_id;
1467 1468 1469
    // 1 + drb_identiy_index;  

    DRB_config->logicalChannelIdentity = CALLOC(1, sizeof(long));
1470
    *(DRB_config->logicalChannelIdentity) = DRB_config->drb_Identity + 2; //(long) (ue_context_pP->ue_context.e_rab[i].param.e_rab_id + 2); // value : x+2
1471
    
1472 1473 1474 1475 1476 1477 1478 1479 1480 1481
    DRB_rlc_config = CALLOC(1, sizeof(*DRB_rlc_config));
    DRB_config->rlc_Config = DRB_rlc_config;

    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;

1482

1483
    switch (ue_context_pP->ue_context.e_rab[i].param.qos.qci){
1484 1485 1486 1487 1488 1489 1490
      /*
       * type: realtime data with medium packer error rate
       * action: swtich to RLC UM
       */
    case 1: // 100ms, 10^-2, p2, GBR
    case 2: // 150ms, 10^-3, p4, GBR
    case 3: // 50ms, 10^-3, p3, GBR
1491
    case 4:  // 300ms, 10^-6, p5 
1492
    case 7: // 100ms, 10^-3, p7, GBR
1493
    case 9: // 300ms, 10^-6, p9
1494 1495
    case 65: // 75ms, 10^-2, p0.7, mission critical voice, GBR
    case 66: // 100ms, 10^-2, p2, non-mission critical  voice , GBR
1496 1497 1498 1499
      // RLC 
      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;
1500
      DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering = T_Reordering_ms35;
1501 1502 1503 1504 1505
      // PDCP
      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;
      break;
1506 1507 1508 1509 1510 1511 1512 1513 1514 1515
      
      /*
       * type: non-realtime data with low packer error rate
       * action: swtich to RLC AM
       */
    case 5:  // 100ms, 10^-6, p1 , IMS signaling 
    case 6:  // 300ms, 10^-6, p6 
    case 8: // 300ms, 10^-6, p8 
    case 69: // 60ms, 10^-6, p0.5, mission critical delay sensitive data, Lowest Priority 
    case 70: // 200ms, 10^-6, p5.5, mision critical data 
1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529
      // RLC
       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;

       // PDCP
       PDCP_rlc_AM = CALLOC(1, sizeof(*PDCP_rlc_AM));
       DRB_pdcp_config->rlc_AM = PDCP_rlc_AM;
       PDCP_rlc_AM->statusReportRequired = FALSE;
       
1530 1531 1532 1533 1534 1535
       break;
    default :
      LOG_E(RRC,"not supported qci %d\n", ue_context_pP->ue_context.e_rab[i].param.qos.qci);
      ue_context_pP->ue_context.e_rab[i].status = E_RAB_STATUS_FAILED; 
      ue_context_pP->ue_context.e_rab[i].xid = xid;
      continue;
1536 1537 1538 1539 1540 1541 1542 1543 1544
    }

    DRB_pdcp_config->headerCompression.present = PDCP_Config__headerCompression_PR_notUsed;
    
    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;

1545
    if (ue_context_pP->ue_context.e_rab[i].param.qos.qci < 9 )
1546 1547 1548 1549 1550 1551 1552
      DRB_ul_SpecificParameters->priority = qci_to_priority[ue_context_pP->ue_context.e_rab[i].param.qos.qci-1] + 3; 
    // ue_context_pP->ue_context.e_rab[i].param.qos.allocation_retention_priority.priority_level;
    else 
      DRB_ul_SpecificParameters->priority= 4;

    DRB_ul_SpecificParameters->prioritisedBitRate = LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_kBps8;
      //LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
1553 1554 1555 1556
    DRB_ul_SpecificParameters->bucketSizeDuration =
      LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
    
    logicalchannelgroup_drb = CALLOC(1, sizeof(long));
1557
    *logicalchannelgroup_drb = 1;//(i+1) % 3;
1558
    DRB_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup_drb;
1559

1560
    ASN_SEQUENCE_ADD(&DRB_configList->list, DRB_config);
1561
    ASN_SEQUENCE_ADD(&(*DRB_configList2)->list, DRB_config);
1562 1563
    //ue_context_pP->ue_context.DRB_configList2[drb_identity_index] = &(*DRB_configList);
    
Cedric Roux's avatar
Cedric Roux committed
1564
    LOG_I(RRC,"EPS ID %ld, DRB ID %ld (index %d), QCI %d, priority %ld, LCID %ld LCGID %ld \n",
1565 1566 1567 1568 1569
	  *DRB_config->eps_BearerIdentity,
	  DRB_config->drb_Identity, i,
	  ue_context_pP->ue_context.e_rab[i].param.qos.qci,
	  DRB_ul_SpecificParameters->priority,
	  *(DRB_config->logicalChannelIdentity),
1570
	  *DRB_ul_SpecificParameters->logicalChannelGroup	  
1571
	  );
1572

1573 1574 1575 1576
    e_rab_done++;
    ue_context_pP->ue_context.e_rab[i].status = E_RAB_STATUS_DONE; 
    ue_context_pP->ue_context.e_rab[i].xid = xid;
    
1577 1578 1579 1580 1581 1582 1583 1584
    {
      if (ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer != NULL) {
	dedicatedInfoNas = CALLOC(1, sizeof(DedicatedInfoNAS_t));
	memset(dedicatedInfoNas, 0, sizeof(OCTET_STRING_t));
	OCTET_STRING_fromBuf(dedicatedInfoNas, 
			     (char*)ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer,
			     ue_context_pP->ue_context.e_rab[i].param.nas_pdu.length);
	ASN_SEQUENCE_ADD(&dedicatedInfoNASList->list, dedicatedInfoNas);
1585
	LOG_I(RRC,"add NAS info with size %d (rab id %d)\n",ue_context_pP->ue_context.e_rab[i].param.nas_pdu.length, i);
1586
      } 
1587 1588 1589
      else {
	LOG_W(RRC,"Not received activate dedicated EPS bearer context request\n");
      }
1590 1591 1592 1593 1594 1595
      /* TODO parameters yet to process ... */
      {
	//      ue_context_pP->ue_context.e_rab[i].param.qos;
	//      ue_context_pP->ue_context.e_rab[i].param.sgw_addr;
	//      ue_context_pP->ue_context.e_rab[i].param.gtp_teid;
      }
1596 1597 1598
    }
    
  }
1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610

  /* If list is empty free the list and reset the address */
  if (dedicatedInfoNASList != NULL) {
    if (dedicatedInfoNASList->list.count == 0) {
      free(dedicatedInfoNASList);
      dedicatedInfoNASList = NULL;
      LOG_W(RRC,"dedlicated NAS list is empty, free the list and reset the address\n");
    }				
  } else {
    LOG_W(RRC,"dedlicated NAS list is empty\n");
  }

1611 1612 1613 1614
  memset(buffer, 0, RRC_BUF_SIZE);

   size = do_RRCConnectionReconfiguration(ctxt_pP,
					  buffer,
1615
					  xid,
1616
					  (SRB_ToAddModList_t*)NULL, 
1617
					  (DRB_ToAddModList_t*)*DRB_configList2,
1618 1619 1620 1621 1622
					  (DRB_ToReleaseList_t*)NULL,  // DRB2_list,
                                         (struct SPS_Config*)NULL,    // *sps_Config,
					  NULL, NULL, NULL, NULL,NULL,
					  NULL, NULL,  NULL, NULL, NULL, NULL, 
					  (struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList*)dedicatedInfoNASList
Cedric Roux's avatar
Cedric Roux committed
1623
#if defined(Rel10) || defined(Rel14)
1624 1625 1626
                                         , (SCellToAddMod_r10_t*)NULL
#endif
                                        );
1627
 
1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650

#ifdef RRC_MSG_PRINT
  LOG_F(RRC,"[MSG] RRC Connection Reconfiguration\n");
  for (i = 0; i < size; i++) {
    LOG_F(RRC,"%02x ", ((uint8_t*)buffer)[i]);
  }
  LOG_F(RRC,"\n");
  ////////////////////////////////////////
#endif

#if defined(ENABLE_ITTI)

  /* Free all NAS PDUs */
  for (i = 0; i < ue_context_pP->ue_context.nb_of_e_rabs; i++) {
    if (ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer != NULL) {
      /* Free the NAS PDU buffer and invalidate it */
      free(ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer);
      ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer = NULL;
    }
  }
#endif

 LOG_I(RRC,
1651
        "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate RRCConnectionReconfiguration (bytes %d, UE RNTI %x)\n",
1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668
        ctxt_pP->module_id, ctxt_pP->frame, size, ue_context_pP->ue_context.rnti);

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

  MSC_LOG_TX_MESSAGE(
    MSC_RRC_ENB,
    MSC_RRC_UE,
    buffer,
    size,
    MSC_AS_TIME_FMT" dedicated rrcConnectionReconfiguration UE %x MUI %d size %u",
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP->ue_context.rnti,
    rrc_eNB_mui,
    size);

1669
  rrc_data_req(
1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686
    ctxt_pP,
    DCCH,
    rrc_eNB_mui++,
    SDU_CONFIRM_NO,
    size,
    buffer,
    PDCP_TRANSMISSION_MODE_CONTROL);


}
#endif 
//-----------------------------------------------------------------------------
void
rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt_t* const ctxt_pP,
						     rrc_eNB_ue_context_t*          const ue_context_pP,
						     const uint8_t                ho_state
						     )
1687
//-----------------------------------------------------------------------------
1688 1689 1690 1691 1692 1693
{
  uint8_t                             buffer[RRC_BUF_SIZE];
  uint16_t                            size;
  int                                 i;

  // configure SRB1/SRB2, PhysicalConfigDedicated, MAC_MainConfig for UE
1694 1695
  eNB_RRC_INST*                       rrc_inst = &eNB_rrc_inst[ctxt_pP->module_id];
  struct PhysicalConfigDedicated**    physicalConfigDedicated = &ue_context_pP->ue_context.physicalConfigDedicated;
1696 1697 1698 1699

  struct SRB_ToAddMod                *SRB2_config                      = NULL;
  struct SRB_ToAddMod__rlc_Config    *SRB2_rlc_config                  = NULL;
  struct SRB_ToAddMod__logicalChannelConfig *SRB2_lchan_config         = NULL;
1700
  struct LogicalChannelConfig__ul_SpecificParameters   *SRB2_ul_SpecificParameters       = NULL;
1701
  SRB_ToAddModList_t*                 SRB_configList = ue_context_pP->ue_context.SRB_configList;
1702
  SRB_ToAddModList_t                 **SRB_configList2                  = NULL;
1703 1704 1705 1706 1707 1708 1709 1710 1711

  struct DRB_ToAddMod                *DRB_config                       = NULL;
  struct RLC_Config                  *DRB_rlc_config                   = NULL;
  struct PDCP_Config                 *DRB_pdcp_config                  = NULL;
  struct PDCP_Config__rlc_AM         *PDCP_rlc_AM                      = NULL;
  struct PDCP_Config__rlc_UM         *PDCP_rlc_UM                      = NULL;
  struct LogicalChannelConfig        *DRB_lchan_config                 = NULL;
  struct LogicalChannelConfig__ul_SpecificParameters
      *DRB_ul_SpecificParameters        = NULL;
1712
  DRB_ToAddModList_t**                DRB_configList = &ue_context_pP->ue_context.DRB_configList;
1713 1714
  DRB_ToAddModList_t**                DRB_configList2 = NULL;
   MAC_MainConfig_t                   *mac_MainConfig                   = NULL;
1715 1716 1717 1718 1719 1720 1721
  MeasObjectToAddModList_t           *MeasObj_list                     = NULL;
  MeasObjectToAddMod_t               *MeasObj                          = NULL;
  ReportConfigToAddModList_t         *ReportConfig_list                = NULL;
  ReportConfigToAddMod_t             *ReportConfig_per, *ReportConfig_A1,
                                     *ReportConfig_A2, *ReportConfig_A3, *ReportConfig_A4, *ReportConfig_A5;
  MeasIdToAddModList_t               *MeasId_list                      = NULL;
  MeasIdToAddMod_t                   *MeasId0, *MeasId1, *MeasId2, *MeasId3, *MeasId4, *MeasId5;
Cedric Roux's avatar
Cedric Roux committed
1722
#if defined(Rel10) || defined(Rel14)
1723 1724
  long                               *sr_ProhibitTimer_r9              = NULL;
  //     uint8_t sCellIndexToAdd = rrc_find_free_SCell_index(enb_mod_idP, ue_mod_idP, 1);
1725
  //uint8_t                            sCellIndexToAdd = 0;
winckel's avatar
winckel committed
1726
#endif
1727

1728 1729
  long                               *logicalchannelgroup, *logicalchannelgroup_drb;
  long                               *maxHARQ_Tx, *periodicBSR_Timer;
1730

1731 1732 1733 1734 1735 1736 1737
  RSRP_Range_t                       *rsrp                             = NULL;
  struct MeasConfig__speedStatePars  *Sparams                          = NULL;
  QuantityConfig_t                   *quantityConfig                   = NULL;
  CellsToAddMod_t                    *CellToAdd                        = NULL;
  CellsToAddModList_t                *CellsToAddModList                = NULL;
  struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList = NULL;
  DedicatedInfoNAS_t                 *dedicatedInfoNas                 = NULL;
Cedric Roux's avatar
Cedric Roux committed
1738 1739
  /* for no gcc warnings */
  (void)dedicatedInfoNas;
1740

1741
  C_RNTI_t                           *cba_RNTI                         = NULL;
1742 1743 1744

  uint8_t xid = rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id);   //Transaction_id,

1745
#ifdef CBA
1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767
  //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);
  }
1768

1769
#endif
1770 1771 1772 1773

  T(T_ENB_RRC_CONNECTION_RECONFIGURATION, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

1774 1775
  // Configure SRB2
  /// SRB2
1776
  SRB_configList2=&ue_context_pP->ue_context.SRB_configList2[xid]; //why no asterix?
1777 1778 1779 1780 1781
  if (*SRB_configList2) {
    free(*SRB_configList2);
  }
  *SRB_configList2 = CALLOC(1, sizeof(**SRB_configList2));
  memset(*SRB_configList2, 0, sizeof(**SRB_configList2));
1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803
  SRB2_config = CALLOC(1, sizeof(*SRB2_config));

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

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

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

  SRB2_lchan_config->present = SRB_ToAddMod__logicalChannelConfig_PR_explicitValue;

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

1804
  SRB2_ul_SpecificParameters->priority = 3; // let some priority for SRB1 and dedicated DRBs
1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816
  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;
Navid Nikaein's avatar
Navid Nikaein committed
1817
  // this list has the configuration for SRB1 and SRB2
1818
  ASN_SEQUENCE_ADD(&SRB_configList->list, SRB2_config);
Navid Nikaein's avatar
Navid Nikaein committed
1819
  // this list has only the configuration for SRB2
1820
  ASN_SEQUENCE_ADD(&(*SRB_configList2)->list, SRB2_config);
1821 1822 1823

  // Configure DRB
  //*DRB_configList = CALLOC(1, sizeof(*DRB_configList));
1824
  // list for all the configured DRB
1825 1826 1827
  if (*DRB_configList) {
    free(*DRB_configList);
  }
1828
  //DRB_ConfigList era gi� stato linkato a ue_context al momento della dichiarazione
1829
  *DRB_configList = CALLOC(1, sizeof(**DRB_configList));
1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840
  memset(*DRB_configList, 0, sizeof(**DRB_configList));

  // list for the configured DRB for a this xid
  DRB_configList2=&ue_context_pP->ue_context.DRB_configList2[xid];
  if (*DRB_configList2) {
    free(*DRB_configList2);
  }
  *DRB_configList2 = CALLOC(1, sizeof(**DRB_configList2));
  memset(*DRB_configList2, 0, sizeof(**DRB_configList2));


1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852
  /// DRB
  DRB_config = CALLOC(1, sizeof(*DRB_config));

  DRB_config->eps_BearerIdentity = CALLOC(1, sizeof(long));
  *(DRB_config->eps_BearerIdentity) = 5L; // LW set to first value, allowed value 5..15, value : x+4
  // DRB_config->drb_Identity = (DRB_Identity_t) 1; //allowed values 1..32
  // NN: this is the 1st DRB for this ue, so set it to 1
  DRB_config->drb_Identity = (DRB_Identity_t) 1;  // (ue_mod_idP+1); //allowed values 1..32, value: x
  DRB_config->logicalChannelIdentity = CALLOC(1, sizeof(long));
  *(DRB_config->logicalChannelIdentity) = (long)3; // value : x+2
  DRB_rlc_config = CALLOC(1, sizeof(*DRB_rlc_config));
  DRB_config->rlc_Config = DRB_rlc_config;
winckel's avatar
winckel committed
1853

1854
#ifdef RRC_DEFAULT_RAB_IS_AM
1855 1856 1857 1858 1859 1860 1861
  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;
1862
#else
1863 1864 1865
  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;
1866
#ifdef CBA
1867
  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering   = T_Reordering_ms5;//T_Reordering_ms25;
1868 1869 1870
#else
  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering = T_Reordering_ms35;
#endif
1871
#endif
1872

1873 1874 1875 1876 1877 1878
  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;
1879

Cedric Roux's avatar
Cedric Roux committed
1880 1881
  /* avoid gcc warnings */
  (void)PDCP_rlc_AM;
Cedric Roux's avatar
Cedric Roux committed
1882
  (void)PDCP_rlc_UM;
Cedric Roux's avatar
Cedric Roux committed
1883

1884
#ifdef RRC_DEFAULT_RAB_IS_AM // EXMIMO_IOT
1885 1886 1887
  PDCP_rlc_AM = CALLOC(1, sizeof(*PDCP_rlc_AM));
  DRB_pdcp_config->rlc_AM = PDCP_rlc_AM;
  PDCP_rlc_AM->statusReportRequired = FALSE;
1888
#else
1889 1890 1891
  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;
1892
#endif
1893
  DRB_pdcp_config->headerCompression.present = PDCP_Config__headerCompression_PR_notUsed;
1894

1895 1896 1897 1898
  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;
1899

1900 1901 1902
  DRB_ul_SpecificParameters->priority = 12;    // lower priority than srb1, srb2 and other dedicated bearer
  DRB_ul_SpecificParameters->prioritisedBitRate =LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_kBps8 ;
    //LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
1903 1904
  DRB_ul_SpecificParameters->bucketSizeDuration =
    LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
1905

1906 1907 1908 1909
  // 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
1910

1911
  ASN_SEQUENCE_ADD(&(*DRB_configList)->list, DRB_config);
1912 1913
  ASN_SEQUENCE_ADD(&(*DRB_configList2)->list, DRB_config);

1914
  //ue_context_pP->ue_context.DRB_configList2[0] = &(*DRB_configList);
winckel's avatar
RRC:  
winckel committed
1915

1916
  mac_MainConfig = CALLOC(1, sizeof(*mac_MainConfig));
1917
  ue_context_pP->ue_context.mac_MainConfig = mac_MainConfig;
winckel's avatar
RRC:  
winckel committed
1918

1919
  mac_MainConfig->ul_SCH_Config = CALLOC(1, sizeof(*mac_MainConfig->ul_SCH_Config));
1920

1921 1922 1923 1924
  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));
Cedric Roux's avatar
Cedric Roux committed
1925
  *periodicBSR_Timer = PeriodicBSR_Timer_r12_sf64;
1926
  mac_MainConfig->ul_SCH_Config->periodicBSR_Timer = periodicBSR_Timer;
Cedric Roux's avatar
Cedric Roux committed
1927
  mac_MainConfig->ul_SCH_Config->retxBSR_Timer = RetxBSR_Timer_r12_sf320;
1928
  mac_MainConfig->ul_SCH_Config->ttiBundling = 0; // FALSE
1929

1930
  mac_MainConfig->timeAlignmentTimerDedicated = TimeAlignmentTimer_infinity;
1931

1932
  mac_MainConfig->drx_Config = NULL;
winckel's avatar
winckel committed
1933

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

1936 1937
  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
1938

1939
  mac_MainConfig->phr_Config->choice.setup.prohibitPHR_Timer = MAC_MainConfig__phr_Config__setup__prohibitPHR_Timer_sf20; // sf20 = 20 subframes
1940

1941
  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
1942

Cedric Roux's avatar
Cedric Roux committed
1943
#if defined(Rel10) || defined(Rel14)
1944 1945
  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
1946 1947
  mac_MainConfig->ext1 = CALLOC(1, sizeof(struct MAC_MainConfig__ext1));
  mac_MainConfig->ext1->sr_ProhibitTimer_r9 = sr_ProhibitTimer_r9;
1948 1949 1950
  //sps_RA_ConfigList_rlola = NULL;
#endif

1951
  //change the transmission mode for the primary component carrier
1952
  //TODO: add codebook subset restriction here
1953
  //TODO: change TM for secondary CC in SCelltoaddmodlist
1954
  if (*physicalConfigDedicated) {
1955
    if ((*physicalConfigDedicated)->antennaInfo) {
1956
      (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.transmissionMode = rrc_inst->configuration.ue_TransmissionMode[0];
Cedric Roux's avatar
Cedric Roux committed
1957
      LOG_D(RRC,"Setting transmission mode to %ld+1\n",rrc_inst->configuration.ue_TransmissionMode[0]);
1958
      if (rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm3) {
1959 1960 1961 1962 1963 1964 1965 1966 1967
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=     
	  CALLOC(1,sizeof(AntennaInfoDedicated__codebookSubsetRestriction_PR));
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
	  AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm3;
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.buf= MALLOC(1);
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.buf[0] = 0xc0;
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.size=1;
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.bits_unused=6;
      }
1968
      else if (rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm4) {
1969 1970 1971 1972 1973 1974 1975 1976
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=     
	  CALLOC(1,sizeof(AntennaInfoDedicated__codebookSubsetRestriction_PR));
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
	  AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm4;
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm4.buf= MALLOC(1);
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm4.buf[0] = 0xfc;
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm4.size=1;
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm4.bits_unused=2;
1977

1978
      }
1979
      else if (rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm5) {
1980 1981 1982 1983 1984 1985 1986 1987 1988
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=     
	  CALLOC(1,sizeof(AntennaInfoDedicated__codebookSubsetRestriction_PR));
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
	  AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm5;
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm5.buf= MALLOC(1);
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm5.buf[0] = 0xf0;
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm5.size=1;
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm5.bits_unused=4;
      }
1989
      else if (rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm6) {
1990 1991 1992 1993 1994 1995 1996 1997 1998
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction=     
	  CALLOC(1,sizeof(AntennaInfoDedicated__codebookSubsetRestriction_PR));
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present =
	  AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm6;
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm6.buf= MALLOC(1);
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm6.buf[0] = 0xf0;
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm6.size=1;
	(*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm6.bits_unused=4;
      }
1999
    }
2000 2001 2002 2003 2004 2005 2006 2007 2008 2009
    else {
      LOG_E(RRC,"antenna_info not present in physical_config_dedicated. Not reconfiguring!\n");
    }
    if ((*physicalConfigDedicated)->cqi_ReportConfig) {
      if ((rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm4) ||
	  (rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm5) ||
	  (rrc_inst->configuration.ue_TransmissionMode[0]==AntennaInfoDedicated__transmissionMode_tm6)) {
	//feedback mode needs to be set as well
	//TODO: I think this is taken into account in the PHY automatically based on the transmission mode variable
	printf("setting cqi reporting mode to rm31\n");
Cedric Roux's avatar
Cedric Roux committed
2010
#if defined(Rel10) || defined(Rel14)
2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023
	*((*physicalConfigDedicated)->cqi_ReportConfig->cqi_ReportModeAperiodic)=CQI_ReportModeAperiodic_rm31;
#else
	*((*physicalConfigDedicated)->cqi_ReportConfig->cqi_ReportModeAperiodic)=CQI_ReportConfig__cqi_ReportModeAperiodic_rm31; // HLC CQI, no PMI
#endif
      }
    }
    else {
      LOG_E(RRC,"cqi_ReportConfig not present in physical_config_dedicated. Not reconfiguring!\n");
    }
  }
  else {
    LOG_E(RRC,"physical_config_dedicated not present in RRCConnectionReconfiguration. Not reconfiguring!\n");
  }
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
  // Measurement ID list
  MeasId_list = CALLOC(1, sizeof(*MeasId_list));
  memset((void *)MeasId_list, 0, sizeof(*MeasId_list));

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

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

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

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

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

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

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

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

  // Configure MeasObject

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

  MeasObj->measObjectId = 1;
  MeasObj->measObject.present = MeasObjectToAddMod__measObject_PR_measObjectEUTRA;
  MeasObj->measObject.choice.measObjectEUTRA.carrierFreq = 3350; //band 7, 2.68GHz
  //MeasObj->measObject.choice.measObjectEUTRA.carrierFreq = 36090; //band 33, 1.909GHz
  MeasObj->measObject.choice.measObjectEUTRA.allowedMeasBandwidth = AllowedMeasBandwidth_mbw25;
  MeasObj->measObject.choice.measObjectEUTRA.presenceAntennaPort1 = 1;
  MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.buf = CALLOC(1, sizeof(uint8_t));
  MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.buf[0] = 0;
  MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.size = 1;
  MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.bits_unused = 6;
  MeasObj->measObject.choice.measObjectEUTRA.offsetFreq = NULL;   // Default is 15 or 0dB

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

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

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

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

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

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

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

2111
  ReportConfig_A1 = CALLOC(1, sizeof(*ReportConfig_A1));
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
  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 */ ) {
2155 2156
    LOG_I(RRC, "[eNB %d] frame %d: requesting A2, A3, A4, A5, and A6 event reporting\n",
          ctxt_pP->module_id, ctxt_pP->frame);
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 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 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 2271 2272
    ReportConfig_A2->reportConfigId = 3;
    ReportConfig_A2->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.present =
      ReportConfigEUTRA__triggerType_PR_event;
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
      ReportConfigEUTRA__triggerType__event__eventId_PR_eventA2;
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
    eventA2.a2_Threshold.present = ThresholdEUTRA_PR_threshold_RSRP;
    ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
    eventA2.a2_Threshold.choice.threshold_RSRP = 10;

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

    ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A2);

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

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

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

    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.hysteresis = 0.5; // FIXME ...hysteresis is of type long!
    ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.timeToTrigger =
      TimeToTrigger_ms40;
    ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A3);

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

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

    ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A4);

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

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

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

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

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

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

    LOG_I(RRC,
          "[eNB %d] Frame %d: potential handover preparation: store the information in an intermediate structure in case of failure\n",
2273
          ctxt_pP->module_id, ctxt_pP->frame);
2274 2275
    // store the information in an intermediate structure for Hanodver management
    //rrc_inst->handover_info.as_config.sourceRadioResourceConfig.srb_ToAddModList = CALLOC(1,sizeof());
2276
    ue_context_pP->ue_context.handover_info = CALLOC(1, sizeof(*(ue_context_pP->ue_context.handover_info)));
2277
    //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.srb_ToAddModList,(void *)SRB_list,sizeof(SRB_ToAddModList_t));
2278
    ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.srb_ToAddModList = *SRB_configList2;
2279
    //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.drb_ToAddModList,(void *)DRB_list,sizeof(DRB_ToAddModList_t));
2280 2281 2282 2283 2284
    ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.drb_ToAddModList = *DRB_configList;
    ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.drb_ToReleaseList = NULL;
    ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig =
      CALLOC(1, sizeof(*ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig));
    memcpy((void*)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig,
2285
           (void *)mac_MainConfig, sizeof(MAC_MainConfig_t));
2286
    ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.physicalConfigDedicated =
2287
      CALLOC(1, sizeof(PhysicalConfigDedicated_t));
2288 2289 2290
    memcpy((void*)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.physicalConfigDedicated,
           (void*)ue_context_pP->ue_context.physicalConfigDedicated, sizeof(PhysicalConfigDedicated_t));
    ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.sps_Config = NULL;
2291 2292 2293 2294 2295 2296 2297 2298 2299
    //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.sps_Config,(void *)rrc_inst->sps_Config[ue_mod_idP],sizeof(SPS_Config_t));

  }

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

  /* Add all NAS PDUs to the list */
2300 2301
  for (i = 0; i < ue_context_pP->ue_context.nb_of_e_rabs; i++) {
    if (ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer != NULL) {
2302 2303
      dedicatedInfoNas = CALLOC(1, sizeof(DedicatedInfoNAS_t));
      memset(dedicatedInfoNas, 0, sizeof(OCTET_STRING_t));
2304 2305
      OCTET_STRING_fromBuf(dedicatedInfoNas, 
			   (char*)ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer,
2306
                           ue_context_pP->ue_context.e_rab[i].param.nas_pdu.length);
2307
      ASN_SEQUENCE_ADD(&dedicatedInfoNASList->list, dedicatedInfoNas);
2308
    }
2309

2310 2311
    /* TODO parameters yet to process ... */
    {
2312 2313 2314
      //      ue_context_pP->ue_context.e_rab[i].param.qos;
      //      ue_context_pP->ue_context.e_rab[i].param.sgw_addr;
      //      ue_context_pP->ue_context.e_rab[i].param.gtp_teid;
2315
    }
2316 2317

    /* TODO should test if e RAB are Ok before! */
2318
    ue_context_pP->ue_context.e_rab[i].status = E_RAB_STATUS_DONE;
2319 2320
    LOG_D(RRC, "setting the status for the default DRB (index %d) to (%d,%s)\n", 
	  i, ue_context_pP->ue_context.e_rab[i].status, "E_RAB_STATUS_DONE");
2321 2322 2323 2324 2325 2326 2327 2328
  }

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

2329 2330
#endif

2331
  memset(buffer, 0, RRC_BUF_SIZE);
2332

2333 2334
  size = do_RRCConnectionReconfiguration(ctxt_pP,
                                         buffer,
2335
                                         xid,   //Transaction_id,
2336
                                         (SRB_ToAddModList_t*)*SRB_configList2,
2337 2338 2339
                                         (DRB_ToAddModList_t*)*DRB_configList,
                                         (DRB_ToReleaseList_t*)NULL,  // DRB2_list,
                                         (struct SPS_Config*)NULL,    // *sps_Config,
2340
                                         (struct PhysicalConfigDedicated*)*physicalConfigDedicated,
2341
#ifdef EXMIMO_IOT
2342
                                         NULL, NULL, NULL,NULL,
2343
#else
2344 2345 2346 2347
                                         (MeasObjectToAddModList_t*)MeasObj_list,
                                         (ReportConfigToAddModList_t*)ReportConfig_list,
                                         (QuantityConfig_t*)quantityConfig,
                                         (MeasIdToAddModList_t*)MeasId_list,
2348
#endif
2349 2350 2351 2352 2353 2354 2355
                                         (MAC_MainConfig_t*)mac_MainConfig,
                                         (MeasGapConfig_t*)NULL,
                                         (MobilityControlInfo_t*)NULL,
                                         (struct MeasConfig__speedStatePars*)Sparams,
                                         (RSRP_Range_t*)rsrp,
                                         (C_RNTI_t*)cba_RNTI,
                                         (struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList*)dedicatedInfoNASList
Cedric Roux's avatar
Cedric Roux committed
2356
#if defined(Rel10) || defined(Rel14)
2357
                                         , (SCellToAddMod_r10_t*)NULL
2358
#endif
2359
                                        );
2360

2361
#ifdef RRC_MSG_PRINT
2362
  LOG_F(RRC,"[MSG] RRC Connection Reconfiguration\n");
2363
  for (i = 0; i < size; i++) {
2364
    LOG_F(RRC,"%02x ", ((uint8_t*)buffer)[i]);
2365
  }
2366 2367 2368 2369
  LOG_F(RRC,"\n");
  ////////////////////////////////////////
#endif

2370
#if defined(ENABLE_ITTI)
2371 2372

  /* Free all NAS PDUs */
2373 2374
  for (i = 0; i < ue_context_pP->ue_context.nb_of_e_rabs; i++) {
    if (ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer != NULL) {
2375
      /* Free the NAS PDU buffer and invalidate it */
2376 2377
      free(ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer);
      ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer = NULL;
2378
    }
2379 2380
  }

2381
#endif
2382

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

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

  MSC_LOG_TX_MESSAGE(
2392 2393 2394 2395 2396 2397 2398 2399 2400
    MSC_RRC_ENB,
    MSC_RRC_UE,
    buffer,
    size,
    MSC_AS_TIME_FMT" rrcConnectionReconfiguration UE %x MUI %d size %u",
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP->ue_context.rnti,
    rrc_eNB_mui,
    size);
2401

2402 2403 2404 2405 2406 2407 2408 2409
  rrc_data_req(
	       ctxt_pP,
	       DCCH,
	       rrc_eNB_mui++,
	       SDU_CONFIRM_NO,
	       size,
	       buffer,
	       PDCP_TRANSMISSION_MODE_CONTROL);
winckel's avatar
winckel committed
2410
}
2411

2412 2413


2414 2415 2416 2417 2418 2419 2420 2421
//-----------------------------------------------------------------------------
int
rrc_eNB_generate_RRCConnectionReconfiguration_SCell(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t* const ue_context_pP,
  uint32_t dl_CarrierFreq_r10
)
//-----------------------------------------------------------------------------
2422
{
2423 2424 2425

  uint8_t size;
  uint8_t buffer[100];
2426

Cedric Roux's avatar
Cedric Roux committed
2427
#if defined(Rel10) || defined(Rel14)
2428
  uint8_t sCellIndexToAdd = 0; //one SCell so far
2429 2430 2431 2432

  //   uint8_t sCellIndexToAdd;
  //   sCellIndexToAdd = rrc_find_free_SCell_index(enb_mod_idP, ue_mod_idP, 1);
  //  if (eNB_rrc_inst[enb_mod_idP].sCell_config[ue_mod_idP][sCellIndexToAdd] ) {
2433 2434
  if (ue_context_pP->ue_context.sCell_config != NULL) {
    ue_context_pP->ue_context.sCell_config[sCellIndexToAdd].cellIdentification_r10->dl_CarrierFreq_r10 = dl_CarrierFreq_r10;
2435
  } else {
2436 2437
    LOG_E(RRC,"Scell not configured!\n");
    return(-1);
2438 2439
  }

2440
#endif
2441
  size = do_RRCConnectionReconfiguration(ctxt_pP,
2442
                                         buffer,
2443
                                         rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),//Transaction_id,
2444 2445 2446 2447 2448 2449 2450
                                         (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,
2451
                                         (QuantityConfig_t*)NULL,
2452 2453 2454 2455 2456 2457 2458
                                         (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,
2459 2460
                                         (struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList*)NULL

Cedric Roux's avatar
Cedric Roux committed
2461
#if defined(Rel10) || defined(Rel14)
2462
                                         , ue_context_pP->ue_context.sCell_config
2463
#endif
2464
                                        );
2465 2466 2467
  LOG_I(RRC,"[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate RRCConnectionReconfiguration (bytes %d, UE id %x)\n",
        ctxt_pP->module_id,ctxt_pP->frame, size, ue_context_pP->ue_context.rnti);

2468
  MSC_LOG_TX_MESSAGE(
2469 2470 2471 2472 2473 2474 2475 2476 2477
    MSC_RRC_ENB,
    MSC_RRC_UE,
    buffer,
    size,
    MSC_AS_TIME_FMT" rrcConnectionReconfiguration UE %x MUI %d size %u",
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP->ue_context.rnti,
    rrc_eNB_mui,
    size);
2478

2479 2480 2481 2482 2483 2484 2485 2486
  rrc_data_req(
	       ctxt_pP,
	       DCCH,
	       rrc_eNB_mui++,
	       SDU_CONFIRM_NO,
	       size,
	       buffer,
	       PDCP_TRANSMISSION_MODE_CONTROL);
2487 2488 2489 2490
  return(0);
}


2491 2492 2493 2494 2495 2496 2497 2498
//-----------------------------------------------------------------------------
void
rrc_eNB_process_MeasurementReport(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t*          const ue_context_pP,
  const MeasResults_t*   const measResults2
)
//-----------------------------------------------------------------------------
2499
{
Cedric Roux's avatar
Cedric Roux committed
2500 2501 2502
  T(T_ENB_RRC_MEASUREMENT_REPORT, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

2503

2504 2505
  LOG_I(RRC, "[eNB %d] Frame %d: Process Measurement Report From UE %x (Measurement Id %d)\n",
        ctxt_pP->module_id, ctxt_pP->frame, ctxt_pP->rnti, (int)measResults2->measId);
2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517

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

Cedric Roux's avatar
Cedric Roux committed
2518
#if defined(Rel10) || defined(Rel14)
Cedric Roux's avatar
Cedric Roux committed
2519 2520
  LOG_I(RRC, "RSRP of Source %ld\n", measResults2->measResultPCell.rsrpResult);
  LOG_I(RRC, "RSRQ of Source %ld\n", measResults2->measResultPCell.rsrqResult);
winckel's avatar
winckel committed
2521
#else
2522 2523
  LOG_I(RRC, "RSRP of Source %ld\n", measResults2->measResultServCell.rsrpResult);
  LOG_I(RRC, "RSRQ of Source %ld\n", measResults2->measResultServCell.rsrqResult);
2524 2525
#endif

2526 2527 2528
  if (ue_context_pP->ue_context.handover_info->ho_prepare != 0xF0) {
    rrc_eNB_generate_HandoverPreparationInformation(ctxt_pP,
        ue_context_pP,
2529 2530 2531
        measResults2->measResultNeighCells->choice.
        measResultListEUTRA.list.array[0]->physCellId);
  } else {
2532 2533
    LOG_D(RRC, "[eNB %d] Frame %d: Ignoring MeasReport from UE %x as Handover is in progress... \n", ctxt_pP->module_id, ctxt_pP->frame,
          ctxt_pP->rnti);
2534
  }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2535

2536 2537 2538 2539
  //Look for IP address of the target eNB
  //Send Handover Request -> target eNB
  //Wait for Handover Acknowledgement <- target eNB
  //Send Handover Command
2540

2541 2542
  //x2delay();
  //    handover_request_x2(ue_mod_idP,enb_mod_idP,measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[0]->physCellId);
2543

2544 2545 2546 2547 2548
  //    uint8_t buffer[100];
  //    int size=rrc_eNB_generate_Handover_Command_TeNB(0,0,buffer);
  //
  //      send_check_message((char*)buffer,size);
  //send_handover_command();
2549

2550 2551
}

2552 2553 2554 2555 2556 2557 2558 2559
//-----------------------------------------------------------------------------
void
rrc_eNB_generate_HandoverPreparationInformation(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t* const ue_context_pP,
  PhysCellId_t                 targetPhyId
)
//-----------------------------------------------------------------------------
2560
{
2561 2562
  struct rrc_eNB_ue_context_s*        ue_context_target_p = NULL;
  //uint8_t                             UE_id_target        = -1;
2563 2564 2565 2566 2567 2568 2569 2570
  uint8_t                             mod_id_target = get_adjacent_cell_mod_id(targetPhyId);
  HANDOVER_INFO                      *handoverInfo = CALLOC(1, sizeof(*handoverInfo));
  /*
     uint8_t buffer[100];
     uint8_t size;
     struct PhysicalConfigDedicated  **physicalConfigDedicated = &eNB_rrc_inst[enb_mod_idP].physicalConfigDedicated[ue_mod_idP];
     RadioResourceConfigDedicated_t *radioResourceConfigDedicated = CALLOC(1,sizeof(RadioResourceConfigDedicated_t));
   */
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2571

Cedric Roux's avatar
Cedric Roux committed
2572 2573 2574
  T(T_ENB_RRC_HANDOVER_PREPARATION_INFORMATION, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

2575 2576 2577 2578
  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,
2579
         (void*)&eNB_rrc_inst[ctxt_pP->module_id].carrier[0] /* CROUX TBC */.mib, sizeof(MasterInformationBlock_t));
2580
  memcpy((void *)&handoverInfo->as_config.sourceMeasConfig,
2581
         (void*)ue_context_pP->ue_context.measConfig, sizeof(MeasConfig_t));
2582 2583 2584 2585 2586 2587

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

  //to be configured
2588
  memset((void*)&ue_context_pP->ue_context.handover_info->as_config.sourceSecurityAlgorithmConfig,
2589 2590
         0, sizeof(SecurityAlgorithmConfig_t));

2591
  memcpy((void*)&ue_context_pP->ue_context.handover_info->as_config.sourceSystemInformationBlockType1,
2592
         (void*)&eNB_rrc_inst[ctxt_pP->module_id].carrier[0] /* CROUX TBC */.SIB1, sizeof(SystemInformationBlockType1_t));
2593
  memcpy((void*)&ue_context_pP->ue_context.handover_info->as_config.sourceSystemInformationBlockType2,
2594
         (void*)&eNB_rrc_inst[ctxt_pP->module_id].carrier[0] /* CROUX TBC */.SIB23, sizeof(SystemInformationBlockType2_t));
2595
  ue_context_pP->ue_context.handover_info->as_context.reestablishmentInfo =
2596
    CALLOC(1, sizeof(ReestablishmentInfo_t));
2597
  ue_context_pP->ue_context.handover_info->as_context.reestablishmentInfo->sourcePhysCellId =
2598
    eNB_rrc_inst[ctxt_pP->module_id].carrier[0] /* CROUX TBC */.physCellId;
2599 2600 2601 2602 2603 2604
  ue_context_pP->ue_context.handover_info->as_context.reestablishmentInfo->targetCellShortMAC_I.buf = NULL;  // Check values later
  ue_context_pP->ue_context.handover_info->as_context.reestablishmentInfo->targetCellShortMAC_I.size = 0;
  ue_context_pP->ue_context.handover_info->as_context.reestablishmentInfo->targetCellShortMAC_I.bits_unused = 0;
  ue_context_pP->ue_context.handover_info->as_context.reestablishmentInfo->additionalReestabInfoList = NULL;
  ue_context_pP->ue_context.handover_info->ho_prepare = 0xFF;    //0xF0;
  ue_context_pP->ue_context.handover_info->ho_complete = 0;
2605 2606 2607

  if (mod_id_target != 0xFF) {
    //UE_id_target = rrc_find_free_ue_index(modid_target);
2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620
    ue_context_target_p =
      rrc_eNB_get_ue_context(
        &eNB_rrc_inst[mod_id_target],
        ue_context_pP->ue_context.rnti);

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

    if (ue_context_target_p == NULL) { // if not already in target cell
      ue_context_target_p = rrc_eNB_allocate_new_UE_context(&eNB_rrc_inst[ctxt_pP->module_id]);
      ue_context_target_p->ue_id_rnti      = ue_context_pP->ue_context.rnti;             // LG: should not be the same
      ue_context_target_p->ue_context.rnti = ue_context_target_p->ue_id_rnti; // idem
2621
      LOG_N(RRC,
Cedric Roux's avatar
Cedric Roux committed
2622
            "[eNB %d] Frame %d : Emulate sending HandoverPreparationInformation msg from eNB source %d to eNB target %ld: source UE_id %x target UE_id %x source_modId: %d target_modId: %d\n",
2623 2624
            ctxt_pP->module_id,
            ctxt_pP->frame,
2625
            eNB_rrc_inst[ctxt_pP->module_id].carrier[0] /* CROUX TBC */.physCellId,
2626 2627 2628 2629
            targetPhyId,
            ue_context_pP->ue_context.rnti,
            ue_context_target_p->ue_id_rnti,
            ctxt_pP->module_id,
2630
            mod_id_target);
2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648
      ue_context_target_p->ue_context.handover_info =
        CALLOC(1, sizeof(*(ue_context_target_p->ue_context.handover_info)));
      memcpy((void*)&ue_context_target_p->ue_context.handover_info->as_context,
             (void*)&ue_context_pP->ue_context.handover_info->as_context,
             sizeof(AS_Context_t));
      memcpy((void*)&ue_context_target_p->ue_context.handover_info->as_config,
             (void*)&ue_context_pP->ue_context.handover_info->as_config,
             sizeof(AS_Config_t));
      ue_context_target_p->ue_context.handover_info->ho_prepare = 0x00;// 0xFF;
      ue_context_target_p->ue_context.handover_info->ho_complete = 0;
      ue_context_pP->ue_context.handover_info->modid_t = mod_id_target;
      ue_context_pP->ue_context.handover_info->ueid_s  = ue_context_pP->ue_context.rnti;
      ue_context_pP->ue_context.handover_info->modid_s = ctxt_pP->module_id;
      ue_context_target_p->ue_context.handover_info->modid_t = mod_id_target;
      ue_context_target_p->ue_context.handover_info->modid_s = ctxt_pP->module_id;
      ue_context_target_p->ue_context.handover_info->ueid_t  = ue_context_target_p->ue_context.rnti;

    } else {
Cedric Roux's avatar
Cedric Roux committed
2649
      LOG_E(RRC, "\nError in obtaining free UE id in target eNB %ld for handover \n", targetPhyId);
2650 2651 2652
    }

  } else {
2653
    LOG_E(RRC, "\nError in obtaining Module ID of target eNB for handover \n");
2654
  }
2655 2656
}

2657 2658 2659 2660 2661 2662 2663
//-----------------------------------------------------------------------------
void
rrc_eNB_process_handoverPreparationInformation(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t*           const ue_context_pP
)
//-----------------------------------------------------------------------------
2664
{
Cedric Roux's avatar
Cedric Roux committed
2665 2666 2667
  T(T_ENB_RRC_HANDOVER_PREPARATION_INFORMATION, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

2668

2669 2670
  LOG_I(RRC,
        "[eNB %d] Frame %d : Logical Channel UL-DCCH, processing RRCHandoverPreparationInformation, sending RRCConnectionReconfiguration to UE %d \n",
2671 2672 2673 2674 2675 2676
        ctxt_pP->module_id, ctxt_pP->frame, ue_context_pP->ue_context.rnti);
  rrc_eNB_generate_RRCConnectionReconfiguration_handover(
    ctxt_pP,
    ue_context_pP,
    NULL,
    0);
winckel's avatar
winckel committed
2677
}
2678

2679 2680 2681 2682 2683

//-----------------------------------------------------------------------------
void
check_handovers(
  protocol_ctxt_t* const ctxt_pP
2684
)
2685
//-----------------------------------------------------------------------------
2686
{
2687
  int                                 result;
2688 2689 2690
  struct rrc_eNB_ue_context_s*        ue_context_p;
  RB_FOREACH(ue_context_p, rrc_ue_tree_s, &eNB_rrc_inst[ctxt_pP->module_id].rrc_ue_head) {
    ctxt_pP->rnti  = ue_context_p->ue_id_rnti;
2691

2692 2693
    if (ue_context_p->ue_context.handover_info != NULL) {
      if (ue_context_p->ue_context.handover_info->ho_prepare == 0xFF) {
2694 2695
        LOG_D(RRC,
              "[eNB %d] Frame %d: Incoming handover detected for new UE_idx %d (source eNB %d->target eNB %d) \n",
2696 2697 2698 2699 2700
              ctxt_pP->module_id,
              ctxt_pP->frame,
              ctxt_pP->rnti,
              ctxt_pP->module_id,
              ue_context_p->ue_context.handover_info->modid_t);
2701
        // source eNB generates rrcconnectionreconfiguration to prepare the HO
2702 2703 2704 2705
        rrc_eNB_process_handoverPreparationInformation(
          ctxt_pP,
          ue_context_p);
        ue_context_p->ue_context.handover_info->ho_prepare = 0xF1;
2706 2707
      }

2708
      if (ue_context_p->ue_context.handover_info->ho_complete == 0xF1) {
2709
        LOG_D(RRC,
2710 2711 2712 2713 2714 2715
              "[eNB %d] Frame %d: handover Command received for new UE_id  %x current eNB %d target eNB: %d \n",
              ctxt_pP->module_id,
              ctxt_pP->frame,
              ctxt_pP->rnti,
              ctxt_pP->module_id,
              ue_context_p->ue_context.handover_info->modid_t);
2716
        //rrc_eNB_process_handoverPreparationInformation(enb_mod_idP,frameP,i);
2717
        result = pdcp_data_req(ctxt_pP,
2718 2719 2720
                               SRB_FLAG_YES,
                               DCCH,
                               rrc_eNB_mui++,
2721 2722 2723 2724
                               SDU_CONFIRM_NO,
                               ue_context_p->ue_context.handover_info->size,
                               ue_context_p->ue_context.handover_info->buf,
                               PDCP_TRANSMISSION_MODE_CONTROL);
2725
        AssertFatal(result == TRUE, "PDCP data request failed!\n");
2726
        ue_context_p->ue_context.handover_info->ho_complete = 0xF2;
2727
      }
winckel's avatar
winckel committed
2728
    }
2729
  }
2730
}
winckel's avatar
RRC:  
winckel committed
2731

winckel's avatar
winckel committed
2732
// 5.3.5.4 RRCConnectionReconfiguration including the mobilityControlInfo to prepare the UE handover
2733 2734 2735 2736 2737 2738 2739 2740 2741
//-----------------------------------------------------------------------------
void
rrc_eNB_generate_RRCConnectionReconfiguration_handover(
  const protocol_ctxt_t* const ctxt_pP,
  rrc_eNB_ue_context_t*           const ue_context_pP,
  uint8_t*                const nas_pdu,
  const uint32_t                nas_length
)
//-----------------------------------------------------------------------------
2742
{
Cedric Roux's avatar
Cedric Roux committed
2743 2744 2745
  T(T_ENB_RRC_CONNECTION_RECONFIGURATION, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2746

2747 2748 2749 2750 2751 2752
  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
2753 2754
  eNB_RRC_INST*                       rrc_inst = &eNB_rrc_inst[ctxt_pP->module_id];
  struct PhysicalConfigDedicated**    physicalConfigDedicated = &ue_context_pP->ue_context.physicalConfigDedicated;
2755 2756 2757 2758 2759 2760

  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;
2761
  SRB_ToAddModList_t*                 SRB_configList = ue_context_pP->ue_context.SRB_configList;    // not used in this context: may be removed
2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782
  SRB_ToAddModList_t                 *SRB_configList2;

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

  MAC_MainConfig_t                   *mac_MainConfig;
  MeasObjectToAddModList_t           *MeasObj_list;
  MeasObjectToAddMod_t               *MeasObj;
  ReportConfigToAddModList_t         *ReportConfig_list;
  ReportConfigToAddMod_t             *ReportConfig_per, *ReportConfig_A1,
                                     *ReportConfig_A2, *ReportConfig_A3, *ReportConfig_A4, *ReportConfig_A5;
  MeasIdToAddModList_t               *MeasId_list;
  MeasIdToAddMod_t                   *MeasId0, *MeasId1, *MeasId2, *MeasId3, *MeasId4, *MeasId5;
  QuantityConfig_t                   *quantityConfig;
  MobilityControlInfo_t              *mobilityInfo;
  // HandoverCommand_t handoverCommand;
2783 2784
  //uint8_t                             sourceModId =
  //  get_adjacent_cell_mod_id(ue_context_pP->ue_context.handover_info->as_context.reestablishmentInfo->sourcePhysCellId);
Cedric Roux's avatar
Cedric Roux committed
2785
#if defined(Rel10) || defined(Rel14)
2786 2787 2788 2789 2790 2791 2792 2793 2794 2795
  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;
2796

2797 2798 2799 2800 2801 2802 2803 2804 2805
  // srb 1: for HO
  struct SRB_ToAddMod                *SRB1_config;
  struct SRB_ToAddMod__rlc_Config    *SRB1_rlc_config;
  struct SRB_ToAddMod__logicalChannelConfig *SRB1_lchan_config;
  struct LogicalChannelConfig__ul_SpecificParameters *SRB1_ul_SpecificParameters;
  // phy config dedicated
  PhysicalConfigDedicated_t          *physicalConfigDedicated2;
  struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList;
  protocol_ctxt_t                     ctxt;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2806

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

2810 2811 2812 2813
  for (i = 0; i < 2; i++) {
    rv[i] = taus() & 0xff;
    LOG_D(RRC, " %x.", rv[i]);
  }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2814

2815
  LOG_D(RRC, "[eNB %d] Frame %d : handover reparation: add target eNB SRB1 and PHYConfigDedicated reconfiguration\n",
2816
        ctxt_pP->module_id, ctxt_pP->frame);
2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873
  // 1st: reconfigure SRB
  SRB_configList2 = CALLOC(1, sizeof(*SRB_configList));
  SRB1_config = CALLOC(1, sizeof(*SRB1_config));
  SRB1_config->srb_Identity = 1;
  SRB1_rlc_config = CALLOC(1, sizeof(*SRB1_rlc_config));
  SRB1_config->rlc_Config = SRB1_rlc_config;

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

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

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

  SRB1_lchan_config->choice.explicitValue.ul_SpecificParameters = SRB1_ul_SpecificParameters;

  SRB1_ul_SpecificParameters->priority = 1;

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

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

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

  ASN_SEQUENCE_ADD(&SRB_configList2->list, SRB1_config);

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

  physicalConfigDedicated2->pdsch_ConfigDedicated =
    CALLOC(1, sizeof(*physicalConfigDedicated2->pdsch_ConfigDedicated));
  physicalConfigDedicated2->pucch_ConfigDedicated =
    CALLOC(1, sizeof(*physicalConfigDedicated2->pucch_ConfigDedicated));
  physicalConfigDedicated2->pusch_ConfigDedicated =
    CALLOC(1, sizeof(*physicalConfigDedicated2->pusch_ConfigDedicated));
  physicalConfigDedicated2->uplinkPowerControlDedicated =
    CALLOC(1, sizeof(*physicalConfigDedicated2->uplinkPowerControlDedicated));
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH =
    CALLOC(1, sizeof(*physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH));
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH =
    CALLOC(1, sizeof(*physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH));
  physicalConfigDedicated2->cqi_ReportConfig = NULL;  //CALLOC(1,sizeof(*physicalConfigDedicated2->cqi_ReportConfig));
hbilel's avatar
hbilel committed
2874
  physicalConfigDedicated2->soundingRS_UL_ConfigDedicated = CALLOC(1,sizeof(*physicalConfigDedicated2->soundingRS_UL_ConfigDedicated));
2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914
  physicalConfigDedicated2->antennaInfo = CALLOC(1, sizeof(*physicalConfigDedicated2->antennaInfo));
  physicalConfigDedicated2->schedulingRequestConfig =
    CALLOC(1, sizeof(*physicalConfigDedicated2->schedulingRequestConfig));
  // PDSCH
  //assign_enum(&physicalConfigDedicated2->pdsch_ConfigDedicated->p_a,
  //          PDSCH_ConfigDedicated__p_a_dB0);
  physicalConfigDedicated2->pdsch_ConfigDedicated->p_a = PDSCH_ConfigDedicated__p_a_dB0;

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

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

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

  // TPC-PDCCH-Config
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->present = TPC_PDCCH_Config_PR_setup;
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_Index.present = TPC_Index_PR_indexOfFormat3;
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_Index.choice.indexOfFormat3 = 1;
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_RNTI.buf = CALLOC(1, 2);
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_RNTI.size = 2;
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_RNTI.buf[0] = 0x12;
2915
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_RNTI.buf[1] = 0x34 + ue_context_pP->local_uid;
2916 2917 2918 2919 2920 2921 2922 2923
  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;
2924
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_RNTI.buf[1] = 0x34 + ue_context_pP->local_uid;
2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942
  physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_RNTI.bits_unused = 0;

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

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

2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957
  //soundingRS-UL-ConfigDedicated
  /*
     physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->present = SoundingRS_UL_ConfigDedicated_PR_setup;
     assign_enum(&physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.srs_Bandwidth,
     SoundingRS_UL_ConfigDedicated__setup__srs_Bandwidth_bw0);
     assign_enum(&physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.srs_HoppingBandwidth,
     SoundingRS_UL_ConfigDedicated__setup__srs_HoppingBandwidth_hbw0);
     physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.freqDomainPosition=0;
     physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.duration=1;
     physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.srs_ConfigIndex=1;
     physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.transmissionComb=0;
     assign_enum(&physicalConfigDedicated2->soundingRS_UL_ConfigDedicated->choice.setup.cyclicShift,
     SoundingRS_UL_ConfigDedicated__setup__cyclicShift_cs0);
   */
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2958

2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988
  //AntennaInfoDedicated
  physicalConfigDedicated2->antennaInfo = CALLOC(1, sizeof(*physicalConfigDedicated2->antennaInfo));
  physicalConfigDedicated2->antennaInfo->present = PhysicalConfigDedicated__antennaInfo_PR_explicitValue;
  //assign_enum(&physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode,
  //     AntennaInfoDedicated__transmissionMode_tm2);
  /*
     switch (transmission_mode){
     case 1:
     physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm1;
     break;
     case 2:
     physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm2;
     break;
     case 4:
     physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm4;
     break;
     case 5:
     physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm5;
     break;
     case 6:
     physicalConfigDedicated2->antennaInfo->choice.explicitValue.transmissionMode=     AntennaInfoDedicated__transmissionMode_tm6;
     break;
     }
   */
  physicalConfigDedicated2->antennaInfo->choice.explicitValue.ue_TransmitAntennaSelection.present =
    AntennaInfoDedicated__ue_TransmitAntennaSelection_PR_release;
  physicalConfigDedicated2->antennaInfo->choice.explicitValue.ue_TransmitAntennaSelection.choice.release = 0;

  // SchedulingRequestConfig
  physicalConfigDedicated2->schedulingRequestConfig->present = SchedulingRequestConfig_PR_setup;
2989
  physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_PUCCH_ResourceIndex = ue_context_pP->local_uid;
2990

2991
  if (mac_xface->frame_parms->frame_type == 0) {  // FDD
2992 2993
    physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_ConfigIndex = 5 + (ue_context_pP->local_uid %
        10);   // Isr = 5 (every 10 subframes, offset=2+UE_id mod3)
2994
  } else {
2995
    switch (mac_xface->frame_parms->tdd_config) {
2996
    case 1:
2997 2998
      physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_ConfigIndex = 7 + (ue_context_pP->local_uid & 1) + ((
            ue_context_pP->local_uid & 3) >> 1) * 5;    // Isr = 5 (every 10 subframes, offset=2 for UE0, 3 for UE1, 7 for UE2, 8 for UE3 , 2 for UE4 etc..)
2999 3000 3001
      break;

    case 3:
3002 3003
      physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_ConfigIndex = 7 + (ue_context_pP->local_uid %
          3);    // Isr = 5 (every 10 subframes, offset=2 for UE0, 3 for UE1, 3 for UE2, 2 for UE3 , etc..)
3004 3005 3006
      break;

    case 4:
3007 3008
      physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_ConfigIndex = 7 + (ue_context_pP->local_uid &
          1);    // Isr = 5 (every 10 subframes, offset=2 for UE0, 3 for UE1, 3 for UE2, 2 for UE3 , etc..)
3009 3010 3011 3012 3013
      break;

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

3017 3018 3019 3020 3021 3022 3023
  //  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,
3024 3025 3026 3027
        "handover_config [FRAME %05d][RRC_eNB][MOD %02d][][--- MAC_CONFIG_REQ  (SRB1 UE %x) --->][MAC_eNB][MOD %02d][]\n",
        ctxt_pP->frame, ctxt_pP->module_id, ue_context_pP->ue_context.rnti, ctxt_pP->module_id);
  rrc_mac_config_req(
    ctxt_pP->module_id,
3028
    ue_context_pP->ue_context.primaryCC_id,
3029 3030 3031 3032 3033
    ENB_FLAG_YES,
    ue_context_pP->ue_context.rnti,
    0,
    (RadioResourceConfigCommonSIB_t*) NULL,
    ue_context_pP->ue_context.physicalConfigDedicated,
Cedric Roux's avatar
Cedric Roux committed
3034
#if defined(Rel10) || defined(Rel14)
3035 3036
    (SCellToAddMod_r10_t *)NULL,
    //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
3037
#endif
3038
    (MeasObjectToAddMod_t **) NULL,
3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049
    ue_context_pP->ue_context.mac_MainConfig,
    1,
    SRB1_logicalChannelConfig,
    ue_context_pP->ue_context.measGapConfig,
    (TDD_Config_t*) NULL,
    (MobilityControlInfo_t*) NULL,
    (uint8_t*) NULL,
    (uint16_t*) NULL,
    NULL,
    NULL,
    NULL,
3050
    (MBSFN_SubframeConfigList_t *) NULL
Cedric Roux's avatar
Cedric Roux committed
3051
#if defined(Rel10) || defined(Rel14)
3052
    , 0, (MBSFN_AreaInfoList_r9_t *) NULL, (PMCH_InfoList_r9_t *) NULL
3053
#endif
winckel's avatar
winckel committed
3054
#ifdef CBA
3055
    , eNB_rrc_inst[ctxt_pP->module_id].num_active_cba_groups, eNB_rrc_inst[ctxt_pP->module_id].cba_rnti[0]
3056
#endif
3057
  );
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3058

3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076
  // Configure target eNB SRB2
  /// SRB2
  SRB2_config = CALLOC(1, sizeof(*SRB2_config));
  SRB_configList2 = CALLOC(1, sizeof(*SRB_configList2));
  memset(SRB_configList2, 0, sizeof(*SRB_configList2));

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

  SRB2_rlc_config->present = SRB_ToAddMod__rlc_Config_PR_explicitValue;
  SRB2_rlc_config->choice.explicitValue.present = RLC_Config_PR_am;
  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.t_PollRetransmit = T_PollRetransmit_ms15;
  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollPDU = PollPDU_p8;
  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollByte = PollByte_kB1000;
  SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.maxRetxThreshold = UL_AM_RLC__maxRetxThreshold_t32;
  SRB2_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_Reordering = T_Reordering_ms35;
  SRB2_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_StatusProhibit = T_StatusProhibit_ms10;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3077

3078 3079
  SRB2_lchan_config = CALLOC(1, sizeof(*SRB2_lchan_config));
  SRB2_config->logicalChannelConfig = SRB2_lchan_config;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3080

3081
  SRB2_lchan_config->present = SRB_ToAddMod__logicalChannelConfig_PR_explicitValue;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3082

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

3085 3086 3087 3088 3089
  SRB2_ul_SpecificParameters->priority = 1;
  SRB2_ul_SpecificParameters->prioritisedBitRate =
    LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
  SRB2_ul_SpecificParameters->bucketSizeDuration =
    LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3090

3091 3092 3093
  // LCG for CCCH and DCCH is 0 as defined in 36331
  logicalchannelgroup = CALLOC(1, sizeof(long));
  *logicalchannelgroup = 0;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3094

3095 3096 3097 3098
  SRB2_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup;
  SRB2_lchan_config->choice.explicitValue.ul_SpecificParameters = SRB2_ul_SpecificParameters;
  ASN_SEQUENCE_ADD(&SRB_configList->list, SRB2_config);
  ASN_SEQUENCE_ADD(&SRB_configList2->list, SRB2_config);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3099

3100 3101 3102 3103
  // Configure target eNB DRB
  DRB_configList2 = CALLOC(1, sizeof(*DRB_configList2));
  /// DRB
  DRB_config = CALLOC(1, sizeof(*DRB_config));
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3104

3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115
  //DRB_config->drb_Identity = (DRB_Identity_t) 1; //allowed values 1..32
  // NN: this is the 1st DRB for this ue, so set it to 1
  DRB_config->drb_Identity = (DRB_Identity_t) 1;  // (ue_mod_idP+1); //allowed values 1..32
  DRB_config->logicalChannelIdentity = CALLOC(1, sizeof(long));
  *(DRB_config->logicalChannelIdentity) = (long)3;
  DRB_rlc_config = CALLOC(1, sizeof(*DRB_rlc_config));
  DRB_config->rlc_Config = DRB_rlc_config;
  DRB_rlc_config->present = RLC_Config_PR_um_Bi_Directional;
  DRB_rlc_config->choice.um_Bi_Directional.ul_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.sn_FieldLength = SN_FieldLength_size10;
  DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering = T_Reordering_ms35;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3116

3117 3118 3119 3120 3121 3122 3123 3124
  DRB_pdcp_config = CALLOC(1, sizeof(*DRB_pdcp_config));
  DRB_config->pdcp_Config = DRB_pdcp_config;
  DRB_pdcp_config->discardTimer = NULL;
  DRB_pdcp_config->rlc_AM = NULL;
  PDCP_rlc_UM = CALLOC(1, sizeof(*PDCP_rlc_UM));
  DRB_pdcp_config->rlc_UM = PDCP_rlc_UM;
  PDCP_rlc_UM->pdcp_SN_Size = PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits;
  DRB_pdcp_config->headerCompression.present = PDCP_Config__headerCompression_PR_notUsed;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3125

3126 3127 3128 3129
  DRB_lchan_config = CALLOC(1, sizeof(*DRB_lchan_config));
  DRB_config->logicalChannelConfig = DRB_lchan_config;
  DRB_ul_SpecificParameters = CALLOC(1, sizeof(*DRB_ul_SpecificParameters));
  DRB_lchan_config->ul_SpecificParameters = DRB_ul_SpecificParameters;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3130

3131 3132 3133 3134 3135
  DRB_ul_SpecificParameters->priority = 2;    // lower priority than srb1, srb2
  DRB_ul_SpecificParameters->prioritisedBitRate =
    LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity;
  DRB_ul_SpecificParameters->bucketSizeDuration =
    LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3136

3137 3138 3139 3140
  // LCG for DTCH can take the value from 1 to 3 as defined in 36331: normally controlled by upper layers (like RRM)
  logicalchannelgroup_drb = CALLOC(1, sizeof(long));
  *logicalchannelgroup_drb = 1;
  DRB_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup_drb;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3141

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

3144
  mac_MainConfig = CALLOC(1, sizeof(*mac_MainConfig));
3145
  ue_context_pP->ue_context.mac_MainConfig = mac_MainConfig;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3146

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

3149 3150 3151
  maxHARQ_Tx = CALLOC(1, sizeof(long));
  *maxHARQ_Tx = MAC_MainConfig__ul_SCH_Config__maxHARQ_Tx_n5;
  mac_MainConfig->ul_SCH_Config->maxHARQ_Tx = maxHARQ_Tx;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3152

3153
  periodicBSR_Timer = CALLOC(1, sizeof(long));
Cedric Roux's avatar
Cedric Roux committed
3154
  *periodicBSR_Timer = PeriodicBSR_Timer_r12_sf64;
3155
  mac_MainConfig->ul_SCH_Config->periodicBSR_Timer = periodicBSR_Timer;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3156

Cedric Roux's avatar
Cedric Roux committed
3157
  mac_MainConfig->ul_SCH_Config->retxBSR_Timer = RetxBSR_Timer_r12_sf320;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3158

3159 3160 3161
  mac_MainConfig->ul_SCH_Config->ttiBundling = 0; // FALSE

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

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

3165 3166
  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
3167

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

3170 3171
  mac_MainConfig->phr_Config->choice.setup.dl_PathlossChange = MAC_MainConfig__phr_Config__setup__dl_PathlossChange_dB1;  // Value dB1 =1 dB, dB3 = 3 dB

Cedric Roux's avatar
Cedric Roux committed
3172
#if defined(Rel10) || defined(Rel14)
3173 3174
  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
3175 3176
  mac_MainConfig->ext1 = CALLOC(1, sizeof(struct MAC_MainConfig__ext1));
  mac_MainConfig->ext1->sr_ProhibitTimer_r9 = sr_ProhibitTimer_r9;
3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248
  //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;
3249
    CellToAdd->physCellId = get_adjacent_cell_id(ctxt_pP->module_id, i);
3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 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 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413
    CellToAdd->cellIndividualOffset = Q_OffsetRange_dB0;

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

  ASN_SEQUENCE_ADD(&MeasObj_list->list, MeasObj);
  //  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->measObjectToAddModList = MeasObj_list;

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

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

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

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

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

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

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

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

  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_per);

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

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

  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A1);

  ReportConfig_A2->reportConfigId = 3;
  ReportConfig_A2->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.present =
    ReportConfigEUTRA__triggerType_PR_event;
  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
    ReportConfigEUTRA__triggerType__event__eventId_PR_eventA2;
  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA2.
  a2_Threshold.present = ThresholdEUTRA_PR_threshold_RSRP;
  ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA2.
  a2_Threshold.choice.threshold_RSRP = 10;

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

  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A2);

  ReportConfig_A3->reportConfigId = 4;
  ReportConfig_A3->reportConfig.present = ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA;
  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.present =
    ReportConfigEUTRA__triggerType_PR_event;
  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present =
    ReportConfigEUTRA__triggerType__event__eventId_PR_eventA3;
  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA3.a3_Offset =
    10;
  ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.
  eventA3.reportOnLeave = 1;

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

  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A3);

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

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

  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A4);

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

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

  ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A5);

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

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

  /* mobilityinfo  */

  mobilityInfo = CALLOC(1, sizeof(*mobilityInfo));
  memset((void *)mobilityInfo, 0, sizeof(*mobilityInfo));
  mobilityInfo->targetPhysCellId =
3414
    (PhysCellId_t) two_tier_hexagonal_cellIds[ue_context_pP->ue_context.handover_info->modid_t];
Cedric Roux's avatar
Cedric Roux committed
3415
  LOG_D(RRC, "[eNB %d] Frame %d: handover preparation: targetPhysCellId: %ld mod_id: %d ue: %x \n",
3416 3417 3418 3419 3420
        ctxt_pP->module_id,
        ctxt_pP->frame,
        mobilityInfo->targetPhysCellId,
        ctxt_pP->module_id,
        ue_context_pP->ue_context.rnti);
3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440

  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,
3441
         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.rach_ConfigCommon, sizeof(RACH_ConfigCommon_t));
3442 3443 3444
  mobilityInfo->radioResourceConfigCommon.prach_Config.prach_ConfigInfo =
    CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.prach_Config.prach_ConfigInfo));
  memcpy((void *)mobilityInfo->radioResourceConfigCommon.prach_Config.prach_ConfigInfo,
3445
         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.prach_Config.prach_ConfigInfo,
3446 3447 3448
         sizeof(PRACH_ConfigInfo_t));

  mobilityInfo->radioResourceConfigCommon.prach_Config.rootSequenceIndex =
3449
    rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.prach_Config.rootSequenceIndex;
3450 3451 3452
  mobilityInfo->radioResourceConfigCommon.pdsch_ConfigCommon =
    CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.pdsch_ConfigCommon));
  memcpy((void *)mobilityInfo->radioResourceConfigCommon.pdsch_ConfigCommon,
3453
         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.pdsch_ConfigCommon, sizeof(PDSCH_ConfigCommon_t));
3454
  memcpy((void *)&mobilityInfo->radioResourceConfigCommon.pusch_ConfigCommon,
3455
         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.pusch_ConfigCommon, sizeof(PUSCH_ConfigCommon_t));
3456 3457 3458 3459
  mobilityInfo->radioResourceConfigCommon.phich_Config = NULL;
  mobilityInfo->radioResourceConfigCommon.pucch_ConfigCommon =
    CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.pucch_ConfigCommon));
  memcpy((void *)mobilityInfo->radioResourceConfigCommon.pucch_ConfigCommon,
3460
         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.pucch_ConfigCommon, sizeof(PUCCH_ConfigCommon_t));
3461 3462 3463
  mobilityInfo->radioResourceConfigCommon.soundingRS_UL_ConfigCommon =
    CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.soundingRS_UL_ConfigCommon));
  memcpy((void *)mobilityInfo->radioResourceConfigCommon.soundingRS_UL_ConfigCommon,
3464
         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon,
3465 3466 3467 3468
         sizeof(SoundingRS_UL_ConfigCommon_t));
  mobilityInfo->radioResourceConfigCommon.uplinkPowerControlCommon =
    CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.uplinkPowerControlCommon));
  memcpy((void *)mobilityInfo->radioResourceConfigCommon.uplinkPowerControlCommon,
3469
         (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.uplinkPowerControlCommon,
3470 3471 3472 3473 3474 3475 3476
         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 =
3477
    rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.ul_CyclicPrefixLength;
3478 3479 3480 3481 3482 3483
  //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;

3484 3485
  mobilityInfo->carrierBandwidth = CALLOC(1, sizeof(
      *mobilityInfo->carrierBandwidth));    //CALLOC(1,sizeof(struct CarrierBandwidthEUTRA));  AllowedMeasBandwidth_mbw25
3486 3487 3488 3489 3490 3491
  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

3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504
  memcpy(ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.srb_ToAddModList,
         (void*)SRB_configList2,
         sizeof(SRB_ToAddModList_t));
  memcpy((void*)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.drb_ToAddModList,
         (void*)DRB_configList2,
         sizeof(DRB_ToAddModList_t));
  ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.drb_ToReleaseList = NULL;
  memcpy((void*)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig,
         (void*)mac_MainConfig,
         sizeof(MAC_MainConfig_t));
  memcpy((void*)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.physicalConfigDedicated,
         (void*)ue_context_pP->ue_context.physicalConfigDedicated,
         sizeof(PhysicalConfigDedicated_t));
3505 3506 3507 3508
  /*    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));
   */
Cedric Roux's avatar
Cedric Roux committed
3509 3510
  LOG_I(RRC, "[eNB %d] Frame %d: adding new UE\n",
        ctxt_pP->module_id, ctxt_pP->frame);
3511 3512 3513
  //Idx = (ue_mod_idP * NB_RB_MAX) + DCCH;
  Idx = DCCH;
  // SRB1
3514 3515 3516 3517
  ue_context_pP->ue_context.Srb1.Active = 1;
  ue_context_pP->ue_context.Srb1.Srb_info.Srb_id = Idx;
  memcpy(&ue_context_pP->ue_context.Srb1.Srb_info.Lchan_desc[0], &DCCH_LCHAN_DESC, LCHAN_DESC_SIZE);
  memcpy(&ue_context_pP->ue_context.Srb1.Srb_info.Lchan_desc[1], &DCCH_LCHAN_DESC, LCHAN_DESC_SIZE);
3518

3519
  // SRB2 
3520 3521 3522 3523
  ue_context_pP->ue_context.Srb2.Active = 1;
  ue_context_pP->ue_context.Srb2.Srb_info.Srb_id = Idx;
  memcpy(&ue_context_pP->ue_context.Srb2.Srb_info.Lchan_desc[0], &DCCH_LCHAN_DESC, LCHAN_DESC_SIZE);
  memcpy(&ue_context_pP->ue_context.Srb2.Srb_info.Lchan_desc[1], &DCCH_LCHAN_DESC, LCHAN_DESC_SIZE);
3524

3525 3526
  LOG_I(RRC, "[eNB %d] CALLING RLC CONFIG SRB1 (rbid %d) for UE %x\n",
        ctxt_pP->module_id, Idx, ue_context_pP->ue_context.rnti);
3527 3528 3529 3530 3531

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

  rrc_pdcp_config_asn1_req(&ctxt,
3532
                           ue_context_pP->ue_context.SRB_configList,
3533
                           (DRB_ToAddModList_t *) NULL, (DRB_ToReleaseList_t *) NULL, 0xff, NULL, NULL, NULL
Cedric Roux's avatar
Cedric Roux committed
3534
#if defined(Rel10) || defined(Rel14)
3535
                           , (PMCH_InfoList_r9_t *) NULL
winckel's avatar
winckel committed
3536
#endif
3537
                           ,NULL);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3538

3539
  rrc_rlc_config_asn1_req(&ctxt,
3540
                          ue_context_pP->ue_context.SRB_configList,
3541
                          (DRB_ToAddModList_t *) NULL, (DRB_ToReleaseList_t *) NULL
Cedric Roux's avatar
Cedric Roux committed
3542
#if defined(Rel10) || defined(Rel14)
3543
                          , (PMCH_InfoList_r9_t *) NULL
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3544
#endif
3545
                         );
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3546

3547 3548
  /* Initialize NAS list */
  dedicatedInfoNASList = NULL;
3549

3550 3551 3552
  //  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->reportConfigToAddModList = ReportConfig_list;
  memset(buffer, 0, RRC_BUF_SIZE);

3553 3554 3555 3556 3557 3558 3559
  size = do_RRCConnectionReconfiguration(
           ctxt_pP,
           buffer,
           rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),   //Transaction_id,
           SRB_configList2,
           DRB_configList2,
           NULL,  // DRB2_list,
3560
           NULL,    //*sps_Config,
3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572
           ue_context_pP->ue_context.physicalConfigDedicated,
           MeasObj_list,
           ReportConfig_list,
           NULL,    //quantityConfig,
           MeasId_list,
           mac_MainConfig,
           NULL,
           mobilityInfo,
           Sparams,
           NULL,
           NULL,
           dedicatedInfoNASList
Cedric Roux's avatar
Cedric Roux committed
3573
#if defined(Rel10) || defined(Rel14)
3574
           , NULL   // SCellToAddMod_r10_t
3575
#endif
3576
         );
3577 3578

  LOG_I(RRC,
3579 3580
        "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate RRCConnectionReconfiguration for handover (bytes %d, UE rnti %x)\n",
        ctxt_pP->module_id, ctxt_pP->frame, size, ue_context_pP->ue_context.rnti);
3581
  // to be updated if needed
3582 3583 3584
  /*if (eNB_rrc_inst[ctxt_pP->module_id].SRB1_config[ue_mod_idP]->logicalChannelConfig) {
     if (eNB_rrc_inst[ctxt_pP->module_id].SRB1_config[ue_mod_idP]->logicalChannelConfig->present == SRB_ToAddMod__logicalChannelConfig_PR_explicitValue) {
     SRB1_logicalChannelConfig = &eNB_rrc_inst[ctxt_pP->module_id].SRB1_config[ue_mod_idP]->logicalChannelConfig->choice.explicitValue;
3585 3586 3587 3588 3589 3590 3591 3592 3593
     }
     else {
     SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
     }
     }
     else {
     SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
     }
   */
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3594

3595
  LOG_D(RRC,
3596 3597 3598 3599 3600 3601
        "[FRAME %05d][RRC_eNB][MOD %02d][][--- PDCP_DATA_REQ/%d Bytes (rrcConnectionReconfiguration_handover to UE %x MUI %d) --->][PDCP][MOD %02d][RB %02d]\n",
        ctxt_pP->frame, ctxt_pP->module_id, size, ue_context_pP->ue_context.rnti, rrc_eNB_mui, ctxt_pP->module_id, DCCH);
  //rrc_rlc_data_req(ctxt_pP->module_id,frameP, 1,(ue_mod_idP*NB_RB_MAX)+DCCH,rrc_eNB_mui++,0,size,(char*)buffer);
  //pdcp_data_req (ctxt_pP->module_id, frameP, 1, (ue_mod_idP * NB_RB_MAX) + DCCH,rrc_eNB_mui++, 0, size, (char *) buffer, 1);
  rrc_mac_config_req(
    ctxt_pP->module_id,
3602
    ue_context_pP->ue_context.primaryCC_id,
3603 3604 3605
    ENB_FLAG_YES,
    ue_context_pP->ue_context.rnti,
    0,
3606
    (RadioResourceConfigCommonSIB_t *) NULL,
3607
    ue_context_pP->ue_context.physicalConfigDedicated,
Cedric Roux's avatar
Cedric Roux committed
3608
#if defined(Rel10) || defined(Rel14)
3609 3610
    (SCellToAddMod_r10_t *)NULL,
    //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
3611
#endif
3612
    (MeasObjectToAddMod_t **) NULL,
3613
    ue_context_pP->ue_context.mac_MainConfig,
3614 3615
    1,
    SRB1_logicalChannelConfig,
3616
    ue_context_pP->ue_context.measGapConfig,
3617 3618 3619
    (TDD_Config_t *) NULL,
    (MobilityControlInfo_t *) mobilityInfo,
    (uint8_t *) NULL, (uint16_t *) NULL, NULL, NULL, NULL, (MBSFN_SubframeConfigList_t *) NULL
Cedric Roux's avatar
Cedric Roux committed
3620
#if defined(Rel10) || defined(Rel14)
3621
    , 0, (MBSFN_AreaInfoList_r9_t *) NULL, (PMCH_InfoList_r9_t *) NULL
3622 3623
#endif
#ifdef CBA
3624
    , 0, 0
3625
#endif
3626
  );
3627

3628 3629 3630 3631 3632 3633
  /*
     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;
   */
3634
//#warning "COMPILATION PROBLEM"
3635
#ifdef PROBLEM_COMPILATION_RESOLVED
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3636

3637
  if (sourceModId != 0xFF) {
3638
    memcpy(eNB_rrc_inst[sourceModId].handover_info[eNB_rrc_inst[ctxt_pP->module_id].handover_info[ue_mod_idP]->ueid_s]->buf,
3639
           (void *)buffer, size);
3640 3641
    eNB_rrc_inst[sourceModId].handover_info[eNB_rrc_inst[ctxt_pP->module_id].handover_info[ue_mod_idP]->ueid_s]->size = size;
    eNB_rrc_inst[sourceModId].handover_info[eNB_rrc_inst[ctxt_pP->module_id].handover_info[ue_mod_idP]->ueid_s]->ho_complete =
3642
      0xF1;
3643
    //eNB_rrc_inst[ctxt_pP->module_id].handover_info[ue_mod_idP]->ho_complete = 0xFF;
3644
    LOG_D(RRC, "[eNB %d] Frame %d: setting handover complete to 0xF1 for (%d,%d) and to 0xFF for (%d,%d)\n",
3645 3646 3647 3648 3649 3650
          ctxt_pP->module_id,
          ctxt_pP->frame,
          sourceModId,
          eNB_rrc_inst[ctxt_pP->module_id].handover_info[ue_mod_idP]->ueid_s,
          ctxt_pP->module_id,
          ue_mod_idP);
3651 3652 3653
  } else
    LOG_W(RRC,
          "[eNB %d] Frame %d: rrc_eNB_generate_RRCConnectionReconfiguration_handover: Could not find source eNB mod_id.\n",
3654
          ctxt_pP->module_id, ctxt_pP->frame);
3655

3656
#endif
winckel's avatar
winckel committed
3657
}
3658

winckel's avatar
winckel committed
3659
/*
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3660
  void ue_rrc_process_rrcConnectionReconfiguration(uint8_t enb_mod_idP,frame_t frameP,
winckel's avatar
winckel committed
3661
  RRCConnectionReconfiguration_t *rrcConnectionReconfiguration,
3662
  uint8_t CH_index) {
3663

winckel's avatar
winckel committed
3664 3665
  if (rrcConnectionReconfiguration->criticalExtensions.present == RRCConnectionReconfiguration__criticalExtensions_PR_c1)
  if (rrcConnectionReconfiguration->criticalExtensions.choice.c1.present == RRCConnectionReconfiguration__criticalExtensions__c1_PR_rrcConnectionReconfiguration_r8) {
3666

winckel's avatar
winckel committed
3667
  if (rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated) {
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3668
  rrc_ue_process_radioResourceConfigDedicated(enb_mod_idP,frameP,CH_index,
winckel's avatar
winckel committed
3669
  rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated);
3670

winckel's avatar
winckel committed
3671 3672 3673 3674 3675 3676 3677
  }

  // check other fields for
  }
  }
*/

3678 3679 3680 3681
//-----------------------------------------------------------------------------
void
rrc_eNB_process_RRCConnectionReconfigurationComplete(
  const protocol_ctxt_t* const ctxt_pP,
3682 3683
  rrc_eNB_ue_context_t*        ue_context_pP,
  const uint8_t xid
3684 3685
)
//-----------------------------------------------------------------------------
3686
{
3687
  int                                 i, drb_id;
3688
#ifdef PDCP_USE_NETLINK
3689 3690
  int                                 oip_ifup = 0;
  int                                 dest_ip_offset = 0;
3691
  module_id_t                         ue_module_id   = -1;
Cedric Roux's avatar
Cedric Roux committed
3692 3693 3694 3695
  /* avoid gcc warnings */
  (void)oip_ifup;
  (void)dest_ip_offset;
  (void)ue_module_id;
winckel's avatar
winckel committed
3696 3697
#endif

3698 3699 3700
  uint8_t                            *kRRCenc = NULL;
  uint8_t                            *kRRCint = NULL;
  uint8_t                            *kUPenc = NULL;
winckel's avatar
winckel committed
3701

3702

3703 3704
  DRB_ToAddModList_t*                 DRB_configList = ue_context_pP->ue_context.DRB_configList2[xid];
  SRB_ToAddModList_t*                 SRB_configList = ue_context_pP->ue_context.SRB_configList2[xid];
winckel's avatar
winckel committed
3705

Cedric Roux's avatar
Cedric Roux committed
3706 3707 3708
  T(T_ENB_RRC_CONNECTION_RECONFIGURATION_COMPLETE, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

winckel's avatar
winckel committed
3709 3710
#if defined(ENABLE_SECURITY)

3711 3712
  /* Derive the keys from kenb */
  if (DRB_configList != NULL) {
3713 3714
    derive_key_up_enc(ue_context_pP->ue_context.ciphering_algorithm,
                      ue_context_pP->ue_context.kenb, &kUPenc);
3715 3716
  }

3717 3718 3719 3720
  derive_key_rrc_enc(ue_context_pP->ue_context.ciphering_algorithm,
                     ue_context_pP->ue_context.kenb, &kRRCenc);
  derive_key_rrc_int(ue_context_pP->ue_context.integrity_algorithm,
                     ue_context_pP->ue_context.kenb, &kRRCint);
3721

winckel's avatar
winckel committed
3722
#endif
3723
#if ENABLE_RAL
3724 3725 3726 3727 3728 3729 3730
  {
    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));
3731
    connection_reconfiguration_ind.ue_id = ctxt_pP->rnti;
3732 3733 3734 3735 3736 3737 3738 3739 3740

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

      for (i = 0; (i < DRB_configList->list.count) && (i < maxDRB); i++) {
        connection_reconfiguration_ind.drb_id[i] = DRB_configList->list.array[i]->drb_Identity;
      }
    } else {
      connection_reconfiguration_ind.num_drb = 0;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3741
    }
3742 3743 3744 3745 3746 3747 3748 3749 3750 3751

    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");
3752
    itti_send_msg_to_task(TASK_RAL_ENB, ctxt_pP->instance, message_ral_p);
3753
  }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3754
#endif
3755
  // Refresh SRBs/DRBs
Lionel Gauthier's avatar
Lionel Gauthier committed
3756 3757 3758 3759 3760 3761 3762 3763 3764
  MSC_LOG_TX_MESSAGE(
    MSC_RRC_ENB,
    MSC_PDCP_ENB,
    NULL,
    0,
    MSC_AS_TIME_FMT" CONFIG_REQ UE %x DRB (security unchanged)",
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP->ue_context.rnti);

3765
  rrc_pdcp_config_asn1_req(
3766
    ctxt_pP,
Navid Nikaein's avatar
Navid Nikaein committed
3767
    SRB_configList, //NULL,  //LG-RK 14/05/2014 SRB_configList,
3768 3769
    DRB_configList, 
    (DRB_ToReleaseList_t *) NULL,
3770 3771
    /*eNB_rrc_inst[ctxt_pP->module_id].ciphering_algorithm[ue_mod_idP] |
             (eNB_rrc_inst[ctxt_pP->module_id].integrity_algorithm[ue_mod_idP] << 4),
3772 3773 3774 3775 3776
     */
    0xff, // already configured during the securitymodecommand
    kRRCenc,
    kRRCint,
    kUPenc
Cedric Roux's avatar
Cedric Roux committed
3777
#if defined(Rel10) || defined(Rel14)
3778 3779
    , (PMCH_InfoList_r9_t *) NULL
#endif
3780
    ,NULL);
3781 3782
  // Refresh SRBs/DRBs
  rrc_rlc_config_asn1_req(
3783
    ctxt_pP,
Navid Nikaein's avatar
Navid Nikaein committed
3784
    SRB_configList, // NULL,  //LG-RK 14/05/2014 SRB_configList,
3785 3786
    DRB_configList,
    (DRB_ToReleaseList_t *) NULL
Cedric Roux's avatar
Cedric Roux committed
3787
#if defined(Rel10) || defined(Rel14)
3788
    , (PMCH_InfoList_r9_t *) NULL
winckel's avatar
winckel committed
3789
#endif
3790
  );
3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805
  
  // set the SRB active in Ue context
  if (SRB_configList != NULL) {
    for (i = 0; (i < SRB_configList->list.count) && (i < 3); i++) {
      if (SRB_configList->list.array[i]->srb_Identity == 1 ){
	ue_context_pP->ue_context.Srb1.Active=1;
      }
      else if (SRB_configList->list.array[i]->srb_Identity == 2 )  {
	  ue_context_pP->ue_context.Srb2.Active=1;
	  ue_context_pP->ue_context.Srb2.Srb_info.Srb_id=2;
	     LOG_I(RRC,"[eNB %d] Frame  %d CC %d : SRB2 is now active\n",
		ctxt_pP->module_id,
		ctxt_pP->frame,
		ue_context_pP->ue_context.primaryCC_id);
      } else {
Cedric Roux's avatar
Cedric Roux committed
3806
	LOG_W(RRC,"[eNB %d] Frame  %d CC %d : invalide SRB identity %ld\n",
3807 3808
	      ctxt_pP->module_id,
	      ctxt_pP->frame,
Cedric Roux's avatar
Cedric Roux committed
3809
              ue_context_pP->ue_context.primaryCC_id,
3810 3811 3812 3813 3814
	      SRB_configList->list.array[i]->srb_Identity);
      }
    }
  }
  
3815
  // Loop through DRBs and establish if necessary
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3816

3817
  if (DRB_configList != NULL) {
3818
    for (i = 0; i < DRB_configList->list.count; i++) {  // num max DRB (11-3-8) (for NB_IoT is 2 DRB)
3819
      if (DRB_configList->list.array[i]) {
3820
	drb_id = (int)DRB_configList->list.array[i]->drb_Identity;
3821
        LOG_I(RRC,
3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833
              "[eNB %d] Frame  %d : Logical Channel UL-DCCH, Received RRCConnectionReconfigurationComplete from UE rnti %x, reconfiguring DRB %d/LCID %d\n",
              ctxt_pP->module_id,
              ctxt_pP->frame,
              ctxt_pP->rnti,
              (int)DRB_configList->list.array[i]->drb_Identity,
              (int)*DRB_configList->list.array[i]->logicalChannelIdentity);
        // for pre-ci tests
        LOG_I(RRC,
              "[eNB %d] Frame  %d : Logical Channel UL-DCCH, Received RRCConnectionReconfigurationComplete from UE %u, reconfiguring DRB %d/LCID %d\n",
              ctxt_pP->module_id,
              ctxt_pP->frame,
              oai_emulation.info.eNB_ue_local_uid_to_ue_module_id[ctxt_pP->module_id][ue_context_pP->local_uid],
3834
              (int)DRB_configList->list.array[i]->drb_Identity,
3835
              (int)*DRB_configList->list.array[i]->logicalChannelIdentity);
3836

3837
        if (ue_context_pP->ue_context.DRB_active[drb_id] == 0) {
3838
          /*
3839
             rrc_pdcp_config_req (ctxt_pP->module_id, frameP, 1, CONFIG_ACTION_ADD,
3840
             (ue_mod_idP * NB_RB_MAX) + *DRB_configList->list.array[i]->logicalChannelIdentity,UNDEF_SECURITY_MODE);
3841 3842
             rrc_rlc_config_req(ctxt_pP->module_id,frameP,1,CONFIG_ACTION_ADD,
             (ue_mod_idP * NB_RB_MAX) + (int)*eNB_rrc_inst[ctxt_pP->module_id].DRB_config[ue_mod_idP][i]->logicalChannelIdentity,
3843 3844
             RADIO_ACCESS_BEARER,Rlc_info_um);
           */
3845
          ue_context_pP->ue_context.DRB_active[drb_id] = 1;
3846 3847 3848

          LOG_D(RRC,
                "[eNB %d] Frame %d: Establish RLC UM Bidirectional, DRB %d Active\n",
3849 3850
                ctxt_pP->module_id, ctxt_pP->frame, (int)DRB_configList->list.array[i]->drb_Identity);
#if  defined(PDCP_USE_NETLINK) && !defined(LINK_ENB_PDCP_TO_GTPV1U)
3851
          // can mean also IPV6 since ether -> ipv6 autoconf
3852
#   if !defined(OAI_NW_DRIVER_TYPE_ETHERNET) && !defined(EXMIMO) && !defined(OAI_USRP) && !defined(OAI_BLADERF) && !defined(ETHERNET)
3853 3854 3855
          LOG_I(OIP, "[eNB %d] trying to bring up the OAI interface oai%d\n",
                ctxt_pP->module_id,
                ctxt_pP->module_id);
3856
          oip_ifup = nas_config(
3857 3858 3859
                       ctxt_pP->module_id,   // interface index
                       ctxt_pP->module_id + 1,   // thrid octet
                       ctxt_pP->module_id + 1);  // fourth octet
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3860

3861
          if (oip_ifup == 0) {    // interface is up --> send a config the DRB
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3862
#      ifdef OAI_EMU
3863
            oai_emulation.info.oai_ifup[ctxt_pP->module_id] = 1;
3864
            dest_ip_offset = NB_eNB_INST;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3865
#      else
3866
            dest_ip_offset = 8;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3867
#      endif
3868
            LOG_I(OIP,
3869
                  "[eNB %d] Config the oai%d to send/receive pkt on DRB %ld to/from the protocol stack\n",
3870
                  ctxt_pP->module_id, ctxt_pP->module_id,
3871
                  (long int)((ue_context_pP->local_uid * maxDRB) + DRB_configList->list.array[i]->drb_Identity));
3872
            ue_module_id = oai_emulation.info.eNB_ue_local_uid_to_ue_module_id[ctxt_pP->module_id][ue_context_pP->local_uid];
3873
            rb_conf_ipv4(0, //add
3874 3875 3876
                         ue_module_id,  //cx
                         ctxt_pP->module_id,    //inst
                         (ue_module_id * maxDRB) + DRB_configList->list.array[i]->drb_Identity, // RB
3877
                         0,    //dscp
3878 3879 3880 3881
                         ipv4_address(ctxt_pP->module_id + 1, ctxt_pP->module_id + 1),  //saddr
                         ipv4_address(ctxt_pP->module_id + 1, dest_ip_offset + ue_module_id + 1));  //daddr
            LOG_D(RRC, "[eNB %d] State = Attached (UE rnti %x module id %u)\n",
                  ctxt_pP->module_id, ue_context_pP->ue_context.rnti, ue_module_id);
3882 3883
          }

Lionel Gauthier's avatar
 
Lionel Gauthier committed
3884 3885
#   else
#      ifdef OAI_EMU
3886
          oai_emulation.info.oai_ifup[ctxt_pP->module_id] = 1;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3887 3888 3889 3890
#      endif
#   endif
#endif

3891
          LOG_D(RRC,
3892 3893
                PROTOCOL_RRC_CTXT_UE_FMT" RRC_eNB --- MAC_CONFIG_REQ  (DRB) ---> MAC_eNB\n",
                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
3894

3895
          if (DRB_configList->list.array[i]->logicalChannelIdentity) {
3896
            DRB2LCHAN[i] = (uint8_t) * DRB_configList->list.array[i]->logicalChannelIdentity;
3897
          }
3898 3899

          rrc_mac_config_req(
3900
            ctxt_pP->module_id,
3901
            ue_context_pP->ue_context.primaryCC_id,
3902
            ENB_FLAG_YES,
3903
            ue_context_pP->ue_context.rnti,
3904 3905
            0,
            (RadioResourceConfigCommonSIB_t *) NULL,
3906
            ue_context_pP->ue_context.physicalConfigDedicated,
Cedric Roux's avatar
Cedric Roux committed
3907
#if defined(Rel10) || defined(Rel14)
3908 3909 3910 3911
            (SCellToAddMod_r10_t *)NULL,
            //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
#endif
            (MeasObjectToAddMod_t **) NULL,
3912
            ue_context_pP->ue_context.mac_MainConfig,
3913 3914
            DRB2LCHAN[i],
            DRB_configList->list.array[i]->logicalChannelConfig,
3915
            ue_context_pP->ue_context.measGapConfig,
3916 3917 3918 3919
            (TDD_Config_t *) NULL,
            NULL,
            (uint8_t *) NULL,
            (uint16_t *) NULL, NULL, NULL, NULL, (MBSFN_SubframeConfigList_t *) NULL
Cedric Roux's avatar
Cedric Roux committed
3920
#if defined(Rel10) || defined(Rel14)
3921
            , 0, (MBSFN_AreaInfoList_r9_t *) NULL, (PMCH_InfoList_r9_t *) NULL
winckel's avatar
winckel committed
3922 3923
#endif
#ifdef CBA
3924
            , eNB_rrc_inst[ctxt_pP->module_id].num_active_cba_groups, eNB_rrc_inst[ctxt_pP->module_id].cba_rnti[0]
3925 3926 3927 3928 3929
#endif
          );

        } else {        // remove LCHAN from MAC/PHY

3930
          if (ue_context_pP->ue_context.DRB_active[drb_id] == 1) {
3931
            // DRB has just been removed so remove RLC + PDCP for DRB
3932
            /*      rrc_pdcp_config_req (ctxt_pP->module_id, frameP, 1, CONFIG_ACTION_REMOVE,
3933 3934 3935
               (ue_mod_idP * NB_RB_MAX) + DRB2LCHAN[i],UNDEF_SECURITY_MODE);
             */
            rrc_rlc_config_req(
3936
              ctxt_pP,
3937 3938 3939 3940 3941 3942 3943
              SRB_FLAG_NO,
              MBMS_FLAG_NO,
              CONFIG_ACTION_REMOVE,
              DRB2LCHAN[i],
              Rlc_info_um);
          }

3944
          ue_context_pP->ue_context.DRB_active[drb_id] = 0;
3945
          LOG_D(RRC,
3946 3947 3948
                PROTOCOL_RRC_CTXT_UE_FMT" RRC_eNB --- MAC_CONFIG_REQ  (DRB) ---> MAC_eNB\n",
                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
          rrc_mac_config_req(ctxt_pP->module_id,
3949
                             ue_context_pP->ue_context.primaryCC_id,
3950
                             ENB_FLAG_YES,
3951
                             ue_context_pP->ue_context.rnti,
3952 3953
                             0,
                             (RadioResourceConfigCommonSIB_t *) NULL,
3954
                             ue_context_pP->ue_context.physicalConfigDedicated,
Cedric Roux's avatar
Cedric Roux committed
3955
#if defined(Rel10) || defined(Rel14)
3956 3957 3958 3959
                             (SCellToAddMod_r10_t *)NULL,
                             //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
#endif
                             (MeasObjectToAddMod_t **) NULL,
3960
                             ue_context_pP->ue_context.mac_MainConfig,
3961 3962 3963 3964 3965
                             DRB2LCHAN[i],
                             (LogicalChannelConfig_t *) NULL,
                             (MeasGapConfig_t *) NULL,
                             (TDD_Config_t *) NULL,
                             NULL, (uint8_t *) NULL, (uint16_t *) NULL, NULL, NULL, NULL, NULL
Cedric Roux's avatar
Cedric Roux committed
3966
#if defined(Rel10) || defined(Rel14)
3967
                             , 0, (MBSFN_AreaInfoList_r9_t *) NULL, (PMCH_InfoList_r9_t *) NULL
winckel's avatar
winckel committed
3968 3969
#endif
#ifdef CBA
3970
                             , 0, 0
winckel's avatar
winckel committed
3971
#endif
3972
                            );
winckel's avatar
winckel committed
3973
        }
3974
      }
winckel's avatar
winckel committed
3975
    }
3976
  }
winckel's avatar
winckel committed
3977
}
3978

3979 3980 3981 3982
//-----------------------------------------------------------------------------
void
rrc_eNB_generate_RRCConnectionSetup(
  const protocol_ctxt_t* const ctxt_pP,
3983 3984
  rrc_eNB_ue_context_t*          const ue_context_pP,
  const int                    CC_id
3985 3986
)
//-----------------------------------------------------------------------------
3987
{
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3988

3989 3990 3991 3992
  LogicalChannelConfig_t             *SRB1_logicalChannelConfig;  //,*SRB2_logicalChannelConfig;
  SRB_ToAddModList_t                **SRB_configList;
  SRB_ToAddMod_t                     *SRB1_config;
  int                                 cnt;
3993
  LTE_DL_FRAME_PARMS *fp = mac_xface->get_lte_frame_parms(ctxt_pP->module_id,CC_id);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
3994

Cedric Roux's avatar
Cedric Roux committed
3995 3996 3997
  T(T_ENB_RRC_CONNECTION_SETUP, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

3998
  SRB_configList = &ue_context_pP->ue_context.SRB_configList;
3999
  eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].Srb0.Tx_buffer.payload_size =
4000 4001
    do_RRCConnectionSetup(ctxt_pP,
                          ue_context_pP,
4002
                          CC_id,
4003
                          (uint8_t*) eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].Srb0.Tx_buffer.Payload,
4004
			  (fp->nb_antenna_ports_eNB==2)?2:1, //at this point we do not have the UE capability information, so it can only be TM1 or TM2
4005
                          rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),
4006
                          fp,
4007
                          SRB_configList, //qui le mando come argomento puntatore di puntatore cos� vengono configurate
4008
                          &ue_context_pP->ue_context.physicalConfigDedicated);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4009

4010
#ifdef RRC_MSG_PRINT
4011 4012
  LOG_F(RRC,"[MSG] RRC Connection Setup\n");

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

  LOG_F(RRC,"\n");
4018 4019 4020
  //////////////////////////////////
#endif

4021 4022 4023 4024
  // configure SRB1/SRB2, PhysicalConfigDedicated, MAC_MainConfig for UE

  if (*SRB_configList != NULL) {
    for (cnt = 0; cnt < (*SRB_configList)->list.count; cnt++) {
4025
    	//sta lavorando solo con SRB1--> perch� RRCConnectionSetup setta solo SRB1 (per NB_IoT??)
4026 4027 4028 4029 4030 4031 4032 4033
      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;
          }
4034 4035 4036
          else {
            SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
          	  }
4037 4038 4039 4040 4041
        } else {
          SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
        }

        LOG_D(RRC,
4042 4043 4044 4045
              PROTOCOL_RRC_CTXT_UE_FMT" RRC_eNB --- MAC_CONFIG_REQ  (SRB1) ---> MAC_eNB\n",
              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
        rrc_mac_config_req(
          ctxt_pP->module_id,
4046
          ue_context_pP->ue_context.primaryCC_id,
4047 4048 4049
          ENB_FLAG_YES,
          ue_context_pP->ue_context.rnti,
          0,
4050
          (RadioResourceConfigCommonSIB_t *) NULL,
4051
          ue_context_pP->ue_context.physicalConfigDedicated,
Cedric Roux's avatar
Cedric Roux committed
4052
#if defined(Rel10) || defined(Rel14)
4053 4054
          (SCellToAddMod_r10_t *)NULL,
          //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
4055
#endif
4056
          (MeasObjectToAddMod_t **) NULL,
4057
          ue_context_pP->ue_context.mac_MainConfig,
4058 4059
          1,
          SRB1_logicalChannelConfig,
4060
          ue_context_pP->ue_context.measGapConfig,
4061 4062 4063 4064
          (TDD_Config_t *) NULL,
          NULL,
          (uint8_t *) NULL,
          (uint16_t *) NULL, NULL, NULL, NULL, (MBSFN_SubframeConfigList_t *) NULL
Cedric Roux's avatar
Cedric Roux committed
4065
#if defined(Rel10) || defined(Rel14)
4066
          , 0, (MBSFN_AreaInfoList_r9_t *) NULL, (PMCH_InfoList_r9_t *) NULL
winckel's avatar
winckel committed
4067 4068
#endif
#ifdef CBA
4069
          , 0, 0
winckel's avatar
winckel committed
4070
#endif
4071
        );
4072 4073
        break;
      }
winckel's avatar
winckel committed
4074
    }
4075
  }
4076 4077

  MSC_LOG_TX_MESSAGE(
4078 4079
    MSC_RRC_ENB,
    MSC_RRC_UE,
4080 4081
    eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].Srb0.Tx_buffer.Header, // LG WARNING
    eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].Srb0.Tx_buffer.payload_size,
4082 4083 4084
    MSC_AS_TIME_FMT" RRCConnectionSetup UE %x size %u",
    MSC_AS_TIME_ARGS(ctxt_pP),
    ue_context_pP->ue_context.rnti,
4085
    eNB_rrc_inst[ctxt_pP->module_id].carrier[CC_id].Srb0.Tx_buffer.payload_size);
4086

4087 4088

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

4093 4094 4095 4096
  // activate release timer, if RRCSetupComplete not received after 10 frames, remove UE
  ue_context_pP->ue_context.ue_release_timer=1;
  // remove UE after 10 frames after RRCConnectionRelease is triggered
  ue_context_pP->ue_context.ue_release_timer_thres=100;
winckel's avatar
winckel committed
4097
}
4098

winckel's avatar
winckel committed
4099
#if defined(ENABLE_ITTI)
4100 4101
char
//-----------------------------------------------------------------------------
4102
openair_rrc_eNB_init(
4103 4104 4105
  const module_id_t enb_mod_idP
)
//-----------------------------------------------------------------------------
4106 4107 4108
{
  /* Dummy function, initialization will be done through ITTI messaging */
  return 0;
winckel's avatar
winckel committed
4109
}
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4110 4111 4112
#endif

#if defined(ENABLE_ITTI)
4113 4114
//-----------------------------------------------------------------------------
char
4115
openair_rrc_eNB_configuration(
4116 4117 4118
  const module_id_t enb_mod_idP,
  RrcConfigurationReq* configuration
)
winckel's avatar
winckel committed
4119
#else
4120
char
4121
openair_rrc_eNB_init(
4122 4123
  const module_id_t enb_mod_idP
)
winckel's avatar
winckel committed
4124
#endif
4125
//-----------------------------------------------------------------------------
winckel's avatar
winckel committed
4126
{
4127
  protocol_ctxt_t ctxt;
4128 4129
  int             CC_id;

4130
  PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, enb_mod_idP, ENB_FLAG_YES, NOT_A_RNTI, 0, 0,enb_mod_idP);
4131 4132 4133
  LOG_I(RRC,
        PROTOCOL_RRC_CTXT_FMT" Init...\n",
        PROTOCOL_RRC_CTXT_ARGS(&ctxt));
4134

laurent's avatar
laurent committed
4135 4136 4137 4138 4139 4140
#if OCP_FRAMEWORK
while ( eNB_rrc_inst == NULL ) {
  LOG_E(RRC, "eNB_rrc_inst not yet initialized, waiting 1 second\n");
  sleep(1);
}
#endif 
4141 4142
  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
4143

4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155
  //    for (j = 0; j < NUMBER_OF_UE_MAX; j++)
  //        eNB_rrc_inst[ctxt.module_id].Info.UE[j].Status = RRC_IDLE;  //CH_READY;
  //
  //#if defined(ENABLE_USE_MME)
  //    // Connect eNB to MME
  //    if (EPC_MODE_ENABLED <= 0)
  //#endif
  //    {
  //        /* Init security parameters */
  //        for (j = 0; j < NUMBER_OF_UE_MAX; j++) {
  //            eNB_rrc_inst[ctxt.module_id].ciphering_algorithm[j] = SecurityAlgorithmConfig__cipheringAlgorithm_eea0;
  //            eNB_rrc_inst[ctxt.module_id].integrity_algorithm[j] = SecurityAlgorithmConfig__integrityProtAlgorithm_eia2;
4156
  //            rrc_eNB_init_security(enb_mod_idP, j);
4157 4158 4159
  //        }
  //    }
  eNB_rrc_inst[ctxt.module_id].Nb_ue = 0;
4160

4161 4162 4163
  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
    eNB_rrc_inst[ctxt.module_id].carrier[CC_id].Srb0.Active = 0;
  }
4164

4165 4166 4167 4168 4169
  uid_linear_allocator_init(&eNB_rrc_inst[ctxt.module_id].uid_allocator);
  RB_INIT(&eNB_rrc_inst[ctxt.module_id].rrc_ue_head);
  //    for (j = 0; j < (NUMBER_OF_UE_MAX + 1); j++) {
  //        eNB_rrc_inst[enb_mod_idP].Srb2[j].Active = 0;
  //    }
4170

4171 4172 4173 4174

  eNB_rrc_inst[ctxt.module_id].initial_id2_s1ap_ids = hashtable_create (NUMBER_OF_UE_MAX * 2, NULL, NULL);
  eNB_rrc_inst[ctxt.module_id].s1ap_id2_s1ap_ids    = hashtable_create (NUMBER_OF_UE_MAX * 2, NULL, NULL);

4175
  memcpy(&eNB_rrc_inst[ctxt.module_id].configuration,configuration,sizeof(RrcConfigurationReq));
4176

4177
  /// System Information INIT
4178

4179 4180
  LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Checking release \n",
        PROTOCOL_RRC_CTXT_ARGS(&ctxt));
Cedric Roux's avatar
Cedric Roux committed
4181
#if defined(Rel10) || defined(Rel14)
4182

4183
  // This has to come from some top-level configuration
4184
  // only CC_id 0 is logged
Cedric Roux's avatar
Cedric Roux committed
4185
#if defined(Rel10)
4186
  LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Rel10 RRC detected, MBMS flag %d\n",
Cedric Roux's avatar
Cedric Roux committed
4187 4188 4189
#else
  LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Rel14 RRC detected, MBMS flag %d\n",
#endif
4190
        PROTOCOL_RRC_CTXT_ARGS(&ctxt),
4191
        eNB_rrc_inst[ctxt.module_id].carrier[0].MBMS_flag);
4192

winckel's avatar
winckel committed
4193
#else
4194
  LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Rel8 RRC\n", PROTOCOL_RRC_CTXT_ARGS(&ctxt));
winckel's avatar
winckel committed
4195 4196
#endif
#ifdef CBA
4197

4198 4199 4200 4201
  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
    for (j = 0; j < NUM_MAX_CBA_GROUP; j++) {
      eNB_rrc_inst[ctxt.module_id].carrier[CC_id].cba_rnti[j] = CBA_OFFSET + j;
    }
4202

4203 4204 4205
    if (eNB_rrc_inst[ctxt.module_id].carrier[CC_id].num_active_cba_groups > NUM_MAX_CBA_GROUP) {
      eNB_rrc_inst[ctxt.module_id].carrier[CC_id].num_active_cba_groups = NUM_MAX_CBA_GROUP;
    }
4206

4207 4208 4209 4210 4211 4212 4213 4214 4215
    LOG_D(RRC,
          PROTOCOL_RRC_CTXT_FMT" Initialization of 4 cba_RNTI values (%x %x %x %x) num active groups %d\n",
          PROTOCOL_RRC_CTXT_ARGS(&ctxt),
          enb_mod_idP, eNB_rrc_inst[ctxt.module_id].carrier[CC_id].cba_rnti[0],
          eNB_rrc_inst[ctxt.module_id].carrier[CC_id].cba_rnti[1],
          eNB_rrc_inst[ctxt.module_id].carrier[CC_id].cba_rnti[2],
          eNB_rrc_inst[ctxt.module_id].carrier[CC_id].cba_rnti[3],
          eNB_rrc_inst[ctxt.module_id].carrier[CC_id].num_active_cba_groups);
  }
4216

winckel's avatar
winckel committed
4217
#endif
4218

4219 4220 4221
  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
    init_SI(&ctxt,
            CC_id
winckel's avatar
winckel committed
4222
#if defined(ENABLE_ITTI)
4223
            , configuration
winckel's avatar
winckel committed
4224
#endif
4225 4226
           );
  }
4227

Cedric Roux's avatar
Cedric Roux committed
4228
#if defined(Rel10) || defined(Rel14)
4229

4230 4231 4232 4233 4234 4235 4236 4237
  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
    switch (eNB_rrc_inst[ctxt.module_id].carrier[CC_id].MBMS_flag) {
    case 1:
    case 2:
    case 3:
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Configuring 1 MBSFN sync area\n", PROTOCOL_RRC_CTXT_ARGS(&ctxt));
      eNB_rrc_inst[ctxt.module_id].carrier[CC_id].num_mbsfn_sync_area = 1;
      break;
4238

4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255
    case 4:
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Configuring 2 MBSFN sync area\n", PROTOCOL_RRC_CTXT_ARGS(&ctxt));
      eNB_rrc_inst[ctxt.module_id].carrier[CC_id].num_mbsfn_sync_area = 2;
      break;

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

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

winckel's avatar
winckel committed
4258
#endif
4259

winckel's avatar
winckel committed
4260
#ifdef NO_RRM                   //init ch SRB0, SRB1 & BDTCH
4261
  openair_rrc_on(&ctxt);
winckel's avatar
winckel committed
4262
#else
4263 4264
  eNB_rrc_inst[ctxt.module_id].Last_scan_req = 0;
  send_msg(&S_rrc, msg_rrc_phy_synch_to_MR_ind(ctxt.module_id, eNB_rrc_inst[ctxt.module_id].Mac_id));
winckel's avatar
winckel committed
4265
#endif
4266

4267
  return 0;
4268

winckel's avatar
winckel committed
4269
}
4270

winckel's avatar
winckel committed
4271
/*------------------------------------------------------------------------------*/
4272 4273 4274
int
rrc_eNB_decode_ccch(
  protocol_ctxt_t* const ctxt_pP,
4275 4276
  const SRB_INFO*        const Srb_info,
  const int              CC_id
4277 4278
)
//-----------------------------------------------------------------------------
4279
{
4280
  module_id_t                                   Idx;
4281 4282
  asn_dec_rval_t                      dec_rval;
  UL_CCCH_Message_t                  *ul_ccch_msg = NULL;
4283 4284
  RRCConnectionRequest_r8_IEs_t*                rrcConnectionRequest = NULL;
  RRCConnectionReestablishmentRequest_r8_IEs_t* rrcConnectionReestablishmentRequest = NULL;
4285
  int                                 i, rval;
4286 4287
  struct rrc_eNB_ue_context_s*                  ue_context_p = NULL;
  uint64_t                                      random_value = 0;
4288
  int                                           stmsi_received = 0;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4289

Cedric Roux's avatar
Cedric Roux committed
4290 4291 4292
  T(T_ENB_RRC_UL_CCCH_DATA_IN, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

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

4295 4296 4297
  LOG_D(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Decoding UL CCCH %x.%x.%x.%x.%x.%x (%p)\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
        ((uint8_t*) Srb_info->Rx_buffer.Payload)[0],
4298 4299 4300 4301 4302
        ((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);
4303 4304 4305 4306 4307 4308 4309 4310
  dec_rval = uper_decode(
               NULL,
               &asn_DEF_UL_CCCH_Message,
               (void**)&ul_ccch_msg,
               (uint8_t*) Srb_info->Rx_buffer.Payload,
               100,
               0,
               0);
4311

winckel's avatar
winckel committed
4312
#if defined(ENABLE_ITTI)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4313
#   if defined(DISABLE_ITTI_XER_PRINT)
4314 4315
  {
    MessageDef                         *message_p;
4316

4317 4318
    message_p = itti_alloc_new_message(TASK_RRC_ENB, RRC_UL_CCCH_MESSAGE);
    memcpy(&message_p->ittiMsg, (void *)ul_ccch_msg, sizeof(RrcUlCcchMessage));
4319

4320
    itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, message_p);
4321
  }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4322
#   else
4323 4324 4325
  {
    char                                message_string[10000];
    size_t                              message_string_size;
4326

4327 4328 4329
    if ((message_string_size =
           xer_sprint(message_string, sizeof(message_string), &asn_DEF_UL_CCCH_Message, (void *)ul_ccch_msg)) > 0) {
      MessageDef                         *msg_p;
4330

4331 4332 4333
      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);
4334

4335
      itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4336
    }
4337
  }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4338 4339
#   endif
#endif
4340

4341
  for (i = 0; i < 8; i++) {
4342
    LOG_T(RRC, "%x.", ((uint8_t *) & ul_ccch_msg)[i]);
4343
  }
4344 4345

  if (dec_rval.consumed == 0) {
4346 4347 4348
    LOG_E(RRC,
          PROTOCOL_RRC_CTXT_UE_FMT" FATAL Error in receiving CCCH\n",
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
4349 4350 4351 4352
    return -1;
  }

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

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

4356
    case UL_CCCH_MessageType__c1_PR_NOTHING:
4357 4358 4359
      LOG_I(RRC,
            PROTOCOL_RRC_CTXT_FMT" Received PR_NOTHING on UL-CCCH-Message\n",
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
4360
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4361

4362
    case UL_CCCH_MessageType__c1_PR_rrcConnectionReestablishmentRequest:
Cedric Roux's avatar
Cedric Roux committed
4363 4364 4365
      T(T_ENB_RRC_CONNECTION_REESTABLISHMENT_REQUEST, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

4366
#ifdef RRC_MSG_PRINT
4367 4368
      LOG_F(RRC,"[MSG] RRC Connection Reestablishement Request\n");

4369
      for (i = 0; i < Srb_info->Rx_buffer.payload_size; i++) {
4370
        LOG_F(RRC,"%02x ", ((uint8_t*)Srb_info->Rx_buffer.Payload)[i]);
4371
      }
4372 4373 4374 4375

      LOG_F(RRC,"\n");
#endif
      LOG_D(RRC,
4376 4377 4378 4379 4380 4381 4382
            PROTOCOL_RRC_CTXT_UE_FMT"MAC_eNB--- MAC_DATA_IND (rrcConnectionReestablishmentRequest on SRB0) --> RRC_eNB\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
      rrcConnectionReestablishmentRequest =
        &ul_ccch_msg->message.choice.c1.choice.rrcConnectionReestablishmentRequest.criticalExtensions.choice.rrcConnectionReestablishmentRequest_r8;
      LOG_I(RRC,
            PROTOCOL_RRC_CTXT_UE_FMT" RRCConnectionReestablishmentRequest cause %s\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
4383 4384 4385
            ((rrcConnectionReestablishmentRequest->reestablishmentCause == ReestablishmentCause_otherFailure) ?    "Other Failure" :
             (rrcConnectionReestablishmentRequest->reestablishmentCause == ReestablishmentCause_handoverFailure) ? "Handover Failure" :
             "reconfigurationFailure"));
4386 4387


4388
      //qui in realt� andr� gestita diversamente senza reject sempre
4389

4390 4391 4392 4393 4394 4395 4396 4397 4398 4399
      /*{
      uint64_t                            c_rnti = 0;

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

      if ((eNB_rrc_inst[enb_mod_idP].phyCellId == rrcConnectionReestablishmentRequest.UE_identity.physCellId) &&
      (ue_mod_id != UE_INDEX_INVALID)){
4400
      rrc_eNB_generate_RRCConnectionReestablishment(enb_mod_idP, frameP, ue_mod_id);
4401
      }else {
4402
      rrc_eNB_generate_RRCConnectionReestablishmentReject(enb_mod_idP, frameP, ue_mod_id);
4403 4404
      }
      */
4405 4406 4407 4408
      /* reject all reestablishment attempts for the moment */
      rrc_eNB_generate_RRCConnectionReestablishmentReject(ctxt_pP,
                       rrc_eNB_get_ue_context(&eNB_rrc_inst[ctxt_pP->module_id], ctxt_pP->rnti),
                       CC_id);
4409

4410 4411 4412
      break;

    case UL_CCCH_MessageType__c1_PR_rrcConnectionRequest:
Cedric Roux's avatar
Cedric Roux committed
4413 4414 4415
      T(T_ENB_RRC_CONNECTION_REQUEST, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

4416
#ifdef RRC_MSG_PRINT
4417 4418
      LOG_F(RRC,"[MSG] RRC Connection Request\n");

4419
      for (i = 0; i < Srb_info->Rx_buffer.payload_size; i++) {
4420
        LOG_F(RRC,"%02x ", ((uint8_t*)Srb_info->Rx_buffer.Payload)[i]);
4421
      }
4422 4423

      LOG_F(RRC,"\n");
4424
#endif
4425
      LOG_D(RRC,
4426 4427 4428 4429 4430 4431 4432 4433 4434
            PROTOCOL_RRC_CTXT_UE_FMT"MAC_eNB --- MAC_DATA_IND  (rrcConnectionRequest on SRB0) --> RRC_eNB\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
      ue_context_p = rrc_eNB_get_ue_context(
                       &eNB_rrc_inst[ctxt_pP->module_id],
                       ctxt_pP->rnti);

      if (ue_context_p != NULL) {
        // erase content
        rrc_eNB_free_mem_UE_context(ctxt_pP, ue_context_p);
4435 4436

        MSC_LOG_RX_DISCARDED_MESSAGE(
4437 4438 4439 4440 4441 4442 4443 4444 4445
          MSC_RRC_ENB,
          MSC_RRC_UE,
          Srb_info->Rx_buffer.Payload,
          dec_rval.consumed,
          MSC_AS_TIME_FMT" RRCConnectionRequest UE %x size %u (UE already in context)",
          MSC_AS_TIME_ARGS(ctxt_pP),
          ue_context_p->ue_context.rnti,
          dec_rval.consumed);
      } else {
4446 4447
        rrcConnectionRequest = &ul_ccch_msg->message.choice.c1.choice.rrcConnectionRequest.criticalExtensions.choice.rrcConnectionRequest_r8;
        {
gauthier's avatar
gauthier committed
4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458
          if (InitialUE_Identity_PR_randomValue == rrcConnectionRequest->ue_Identity.present) {
            AssertFatal(rrcConnectionRequest->ue_Identity.choice.randomValue.size == 5,
                        "wrong InitialUE-Identity randomValue size, expected 5, provided %d",
                        rrcConnectionRequest->ue_Identity.choice.randomValue.size);
            memcpy(((uint8_t*) & random_value) + 3,
                   rrcConnectionRequest->ue_Identity.choice.randomValue.buf,
                   rrcConnectionRequest->ue_Identity.choice.randomValue.size);
            /* if there is already a registered UE (with another RNTI) with this random_value,
             * the current one must be removed from MAC/PHY (zombie UE)
             */
            if ((ue_context_p = rrc_eNB_ue_context_random_exist(ctxt_pP, random_value))) {
Cedric Roux's avatar
Cedric Roux committed
4459 4460 4461
              LOG_W(RRC, "new UE rnti %x (coming with random value) is already there as UE %x, removing %x from MAC/PHY\n",
                    ctxt_pP->rnti, ue_context_p->ue_context.rnti, ctxt_pP->rnti);
	      rrc_mac_remove_ue(ctxt_pP->module_id, ctxt_pP->rnti);
gauthier's avatar
gauthier committed
4462
              ue_context_p = NULL;
Cedric Roux's avatar
Cedric Roux committed
4463
              return 0;
gauthier's avatar
gauthier committed
4464 4465 4466 4467 4468 4469 4470 4471 4472 4473
            } else {
              ue_context_p = rrc_eNB_get_next_free_ue_context(ctxt_pP, random_value);
            }
          } else if (InitialUE_Identity_PR_s_TMSI == rrcConnectionRequest->ue_Identity.present) {
            /* Save s-TMSI */
            S_TMSI_t   s_TMSI = rrcConnectionRequest->ue_Identity.choice.s_TMSI;
            mme_code_t mme_code = BIT_STRING_to_uint8(&s_TMSI.mmec);
            m_tmsi_t   m_tmsi   = BIT_STRING_to_uint32(&s_TMSI.m_TMSI);
            random_value = (((uint64_t)mme_code) << 32) | m_tmsi;
            if ((ue_context_p = rrc_eNB_ue_context_stmsi_exist(ctxt_pP, mme_code, m_tmsi))) {
4474
	      LOG_I(RRC," S-TMSI exists, ue_context_p %p, old rnti %x => %x\n",ue_context_p,ue_context_p->ue_context.rnti,ctxt_pP->rnti);
Cedric Roux's avatar
Cedric Roux committed
4475
	      rrc_mac_remove_ue(ctxt_pP->module_id, ue_context_p->ue_context.rnti);
4476
	      stmsi_received=1;
4477 4478 4479 4480 4481
              /* replace rnti in the context */
              /* for that, remove the context from the RB tree */
              RB_REMOVE(rrc_ue_tree_s, &eNB_rrc_inst[ctxt_pP->module_id].rrc_ue_head, ue_context_p);
              /* and insert again, after changing rnti everywhere it has to be changed */
              ue_context_p->ue_id_rnti = ctxt_pP->rnti;
Raymond Knopp's avatar
Raymond Knopp committed
4482
	      ue_context_p->ue_context.rnti = ctxt_pP->rnti;
4483 4484 4485 4486
              RB_INSERT(rrc_ue_tree_s, &eNB_rrc_inst[ctxt_pP->module_id].rrc_ue_head, ue_context_p);
              /* reset timers */
              ue_context_p->ue_context.ul_failure_timer = 0;
              ue_context_p->ue_context.ue_release_timer = 0;
gauthier's avatar
gauthier committed
4487
            } else {
Cedric Roux's avatar
Cedric Roux committed
4488
	      LOG_I(RRC," S-TMSI doesn't exist, setting Initialue_identity_s_TMSI.m_tmsi to %p => %x\n",ue_context_p,m_tmsi);
gauthier's avatar
gauthier committed
4489
              ue_context_p = rrc_eNB_get_next_free_ue_context(ctxt_pP, NOT_A_RANDOM_UE_IDENTITY);
4490 4491 4492 4493 4494 4495 4496
              if (ue_context_p == NULL)
                LOG_E(RRC, "%s:%d:%s: rrc_eNB_get_next_free_ue_context returned NULL\n", __FILE__, __LINE__, __FUNCTION__);
              if (ue_context_p != NULL) {
	        ue_context_p->ue_context.Initialue_identity_s_TMSI.presence = TRUE;
	        ue_context_p->ue_context.Initialue_identity_s_TMSI.mme_code = mme_code;
	        ue_context_p->ue_context.Initialue_identity_s_TMSI.m_tmsi = m_tmsi;
              } else {
Cedric Roux's avatar
Cedric Roux committed
4497 4498
                /* TODO: do we have to break here? */
                //break;
4499
              }
gauthier's avatar
gauthier committed
4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514
            }

            MSC_LOG_RX_MESSAGE(
              MSC_RRC_ENB,
              MSC_RRC_UE,
              Srb_info->Rx_buffer.Payload,
              dec_rval.consumed,
              MSC_AS_TIME_FMT" RRCConnectionRequest UE %x size %u (s-TMSI mmec %u m_TMSI %u random UE id (0x%" PRIx64 ")",
              MSC_AS_TIME_ARGS(ctxt_pP),
              ue_context_p->ue_context.rnti,
              dec_rval.consumed,
              ue_context_p->ue_context.Initialue_identity_s_TMSI.mme_code,
              ue_context_p->ue_context.Initialue_identity_s_TMSI.m_tmsi,
              ue_context_p->ue_context.random_ue_identity);
          } else {
4515
            LOG_E(RRC,
gauthier's avatar
gauthier committed
4516
                  PROTOCOL_RRC_CTXT_UE_FMT" RRCConnectionRequest without random UE identity or S-TMSI not supported, let's reject the UE\n",
4517 4518 4519 4520 4521 4522
                  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
            rrc_eNB_generate_RRCConnectionReject(ctxt_pP,
                             rrc_eNB_get_ue_context(&eNB_rrc_inst[ctxt_pP->module_id], ctxt_pP->rnti),
                             CC_id);
            break;
          }
gauthier's avatar
gauthier committed
4523

4524
        }
4525
        LOG_D(RRC,
Cedric Roux's avatar
Cedric Roux committed
4526
              PROTOCOL_RRC_CTXT_UE_FMT" UE context: %p\n",
4527 4528
              PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
              ue_context_p);
4529

4530
        if (ue_context_p != NULL) {
4531 4532


winckel's avatar
winckel committed
4533
#if defined(ENABLE_ITTI)
gauthier's avatar
gauthier committed
4534
          ue_context_p->ue_context.establishment_cause = rrcConnectionRequest->establishmentCause;
Raymond Knopp's avatar
Raymond Knopp committed
4535
	  if (stmsi_received==0)
Cedric Roux's avatar
Cedric Roux committed
4536
	    LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Accept new connection from UE random UE identity (0x%" PRIx64 ") MME code %u TMSI %u cause %ld\n",
Raymond Knopp's avatar
Raymond Knopp committed
4537 4538 4539 4540 4541 4542
		  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
		  ue_context_p->ue_context.random_ue_identity,
		  ue_context_p->ue_context.Initialue_identity_s_TMSI.mme_code,
		  ue_context_p->ue_context.Initialue_identity_s_TMSI.m_tmsi,
		  ue_context_p->ue_context.establishment_cause);
	  else
Cedric Roux's avatar
Cedric Roux committed
4543
	    LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Accept new connection from UE  MME code %u TMSI %u cause %ld\n",
Raymond Knopp's avatar
Raymond Knopp committed
4544 4545 4546 4547
		  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
		  ue_context_p->ue_context.Initialue_identity_s_TMSI.mme_code,
		  ue_context_p->ue_context.Initialue_identity_s_TMSI.m_tmsi,
		  ue_context_p->ue_context.establishment_cause);
4548 4549 4550 4551
#else
          LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Accept new connection for UE random UE identity (0x%" PRIx64 ")\n",
                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
                ue_context_p->ue_context.random_ue_identity);
4552
#endif
4553 4554
          if (stmsi_received == 0)
	    eNB_rrc_inst[ctxt_pP->module_id].Nb_ue++;
4555

4556 4557 4558 4559
        } else {
          // no context available
          LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Can't create new context for UE random UE identity (0x%" PRIx64 ")\n",
                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
4560
                random_value);
4561
	  rrc_mac_remove_ue(ctxt_pP->module_id,ctxt_pP->rnti);
4562 4563 4564
          return -1;
        }
      }
4565

winckel's avatar
winckel committed
4566
#ifndef NO_RRM
4567
      send_msg(&S_rrc, msg_rrc_MR_attach_ind(ctxt_pP->module_id, Mac_id));
winckel's avatar
winckel committed
4568
#else
4569

4570 4571
      ue_context_p->ue_context.primaryCC_id = CC_id;

4572 4573 4574
      //LG COMMENT Idx = (ue_mod_idP * NB_RB_MAX) + DCCH;
      Idx = DCCH;
      // SRB1
4575
      ue_context_p->ue_context.Srb1.Active = 1;
4576
      ue_context_p->ue_context.Srb1.Srb_info.Srb_id = Idx; //module_id
4577 4578
      memcpy(&ue_context_p->ue_context.Srb1.Srb_info.Lchan_desc[0],
             &DCCH_LCHAN_DESC,
4579
             LCHAN_DESC_SIZE);
4580 4581
      memcpy(&ue_context_p->ue_context.Srb1.Srb_info.Lchan_desc[1],
             &DCCH_LCHAN_DESC,
4582
             LCHAN_DESC_SIZE);
4583

4584
      // SRB2: set  it to go through SRB1 with id 1 (DCCH) ????
4585 4586 4587 4588
      ue_context_p->ue_context.Srb2.Active = 1;
      ue_context_p->ue_context.Srb2.Srb_info.Srb_id = Idx;
      memcpy(&ue_context_p->ue_context.Srb2.Srb_info.Lchan_desc[0],
             &DCCH_LCHAN_DESC,
4589
             LCHAN_DESC_SIZE);
4590 4591
      memcpy(&ue_context_p->ue_context.Srb2.Srb_info.Lchan_desc[1],
             &DCCH_LCHAN_DESC,
4592
             LCHAN_DESC_SIZE);
4593
      
4594
      rrc_eNB_generate_RRCConnectionSetup(ctxt_pP, ue_context_p, CC_id);
4595 4596 4597
      LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT"CALLING RLC CONFIG SRB1 (rbid %d)\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            Idx);
Lionel Gauthier's avatar
Lionel Gauthier committed
4598 4599 4600 4601 4602 4603 4604 4605 4606 4607

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

4608 4609
      rrc_pdcp_config_asn1_req(ctxt_pP,
                               ue_context_p->ue_context.SRB_configList,
4610
                               (DRB_ToAddModList_t *) NULL,
4611 4612 4613 4614 4615
                               (DRB_ToReleaseList_t*) NULL,
                               0xff,
                               NULL,
                               NULL,
                               NULL
Cedric Roux's avatar
Cedric Roux committed
4616
#   if defined(Rel10) || defined(Rel14)
4617
                               , (PMCH_InfoList_r9_t *) NULL
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4618
#   endif
4619
                               ,NULL);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4620

4621 4622 4623 4624
      rrc_rlc_config_asn1_req(ctxt_pP,
                              ue_context_p->ue_context.SRB_configList,
                              (DRB_ToAddModList_t*) NULL,
                              (DRB_ToReleaseList_t*) NULL
Cedric Roux's avatar
Cedric Roux committed
4625
#   if defined(Rel10) || defined(Rel14)
4626
                              , (PMCH_InfoList_r9_t *) NULL
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4627
#   endif
4628
                             );
winckel's avatar
winckel committed
4629
#endif //NO_RRM
4630 4631 4632 4633

      break;

    default:
4634 4635
      LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Unknown message\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
4636 4637
      rval = -1;
      break;
winckel's avatar
winckel committed
4638
    }
4639 4640 4641

    rval = 0;
  } else {
4642 4643
    LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT"  Unknown error \n",
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
4644 4645 4646 4647
    rval = -1;
  }

  return rval;
4648 4649
}

4650 4651 4652 4653 4654 4655 4656 4657 4658
//-----------------------------------------------------------------------------
int
rrc_eNB_decode_dcch(
  const protocol_ctxt_t* const ctxt_pP,
  const rb_id_t                Srb_id,
  const uint8_t*    const      Rx_sdu,
  const sdu_size_t             sdu_sizeP
)
//-----------------------------------------------------------------------------
4659
{
winckel's avatar
winckel committed
4660

4661 4662 4663 4664 4665
  asn_dec_rval_t                      dec_rval;
  //UL_DCCH_Message_t uldcchmsg;
  UL_DCCH_Message_t                  *ul_dcch_msg = NULL; //&uldcchmsg;
  UE_EUTRA_Capability_t              *UE_EUTRA_Capability = NULL;
  int i;
4666
  struct rrc_eNB_ue_context_s*        ue_context_p = NULL;
4667

4668
  int dedicated_DRB=0; 
nikaeinn's avatar
nikaeinn committed
4669

Cedric Roux's avatar
Cedric Roux committed
4670 4671 4672
  T(T_ENB_RRC_UL_DCCH_DATA_IN, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
    T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

4673
  if ((Srb_id != 1) && (Srb_id != 2)) {
4674 4675 4676
    LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Received message on SRB%d, should not have ...\n",
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
          Srb_id);
4677 4678 4679 4680
  } else {
    LOG_D(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Received message on SRB%d\n",
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
          Srb_id);
4681 4682
  }
  //memset(ul_dcch_msg,0,sizeof(UL_DCCH_Message_t));
4683

4684 4685 4686 4687 4688 4689 4690 4691 4692 4693
  LOG_D(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Decoding UL-DCCH Message\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
  dec_rval = uper_decode(
               NULL,
               &asn_DEF_UL_DCCH_Message,
               (void**)&ul_dcch_msg,
               Rx_sdu,
               sdu_sizeP,
               0,
               0);
4694

winckel's avatar
winckel committed
4695
#if defined(ENABLE_ITTI)
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4696
#   if defined(DISABLE_ITTI_XER_PRINT)
4697 4698
  {
    MessageDef                         *message_p;
4699

4700 4701
    message_p = itti_alloc_new_message(TASK_RRC_ENB, RRC_UL_DCCH_MESSAGE);
    memcpy(&message_p->ittiMsg, (void *)ul_dcch_msg, sizeof(RrcUlDcchMessage));
4702

4703
    itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, message_p);
4704
  }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4705
#   else
4706 4707 4708
  {
    char                                message_string[10000];
    size_t                              message_string_size;
4709

4710 4711 4712
    if ((message_string_size =
           xer_sprint(message_string, sizeof(message_string), &asn_DEF_UL_DCCH_Message, (void *)ul_dcch_msg)) >= 0) {
      MessageDef                         *msg_p;
4713

4714 4715 4716
      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);
4717

4718
      itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
winckel's avatar
winckel committed
4719
    }
4720
  }
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4721 4722
#   endif
#endif
4723

4724
  {
4725
    for (i = 0; i < sdu_sizeP; i++) {
4726
      LOG_T(RRC, "%x.", Rx_sdu[i]);
4727
    }
winckel's avatar
winckel committed
4728

4729 4730 4731 4732
    LOG_T(RRC, "\n");
  }

  if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0)) {
Cedric Roux's avatar
Cedric Roux committed
4733
    LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Failed to decode UL-DCCH (%zu bytes)\n",
4734 4735
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
          dec_rval.consumed);
4736 4737
    return -1;
  }
4738

4739 4740 4741
  ue_context_p = rrc_eNB_get_ue_context(
                   &eNB_rrc_inst[ctxt_pP->module_id],
                   ctxt_pP->rnti);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4742

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

4745 4746 4747
    switch (ul_dcch_msg->message.choice.c1.present) {
    case UL_DCCH_MessageType__c1_PR_NOTHING:   /* No components present */
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4748

4749 4750
    case UL_DCCH_MessageType__c1_PR_csfbParametersRequestCDMA2000:
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4751

4752 4753
    case UL_DCCH_MessageType__c1_PR_measurementReport:
      LOG_D(RRC,
4754 4755 4756 4757 4758 4759 4760 4761
            PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND "
            "%d bytes (measurementReport) ---> RRC_eNB\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            DCCH,
            sdu_sizeP);
      rrc_eNB_process_MeasurementReport(
        ctxt_pP,
        ue_context_p,
4762 4763
        &ul_dcch_msg->message.choice.c1.choice.measurementReport.
        criticalExtensions.choice.c1.choice.measurementReport_r8.measResults);
4764
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4765

4766
    case UL_DCCH_MessageType__c1_PR_rrcConnectionReconfigurationComplete:
4767
#ifdef RRC_MSG_PRINT
4768 4769
      LOG_F(RRC,"[MSG] RRC Connection Reconfiguration Complete\n");

4770
      for (i = 0; i < sdu_sizeP; i++) {
4771
        LOG_F(RRC,"%02x ", ((uint8_t*)Rx_sdu)[i]);
4772
      }
4773 4774

      LOG_F(RRC,"\n");
4775
#endif
4776
      MSC_LOG_RX_MESSAGE(
4777 4778 4779 4780 4781 4782 4783 4784
        MSC_RRC_ENB,
        MSC_RRC_UE,
        Rx_sdu,
        sdu_sizeP,
        MSC_AS_TIME_FMT" RRCConnectionReconfigurationComplete UE %x size %u",
        MSC_AS_TIME_ARGS(ctxt_pP),
        ue_context_p->ue_context.rnti,
        sdu_sizeP);
4785

4786
      LOG_D(RRC,
4787 4788 4789 4790 4791
            PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
            "(RRCConnectionReconfigurationComplete) ---> RRC_eNB]\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            DCCH,
            sdu_sizeP);
4792 4793 4794 4795

      if (ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.criticalExtensions.
          present ==
          RRCConnectionReconfigurationComplete__criticalExtensions_PR_rrcConnectionReconfigurationComplete_r8) {
4796
	/*NN: revise the condition */
4797 4798 4799
        if (ue_context_p->ue_context.Status == RRC_RECONFIGURED){
	  dedicated_DRB = 1;
	  LOG_I(RRC,
Cedric Roux's avatar
Cedric Roux committed
4800
		PROTOCOL_RRC_CTXT_UE_FMT" UE State = RRC_RECONFIGURED (dedicated DRB, xid %ld)\n",
4801
		PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);
4802
	}else {
4803
	  dedicated_DRB = 0;
4804 4805
	  ue_context_p->ue_context.Status = RRC_RECONFIGURED;
	  LOG_I(RRC,
Cedric Roux's avatar
Cedric Roux committed
4806
		PROTOCOL_RRC_CTXT_UE_FMT" UE State = RRC_RECONFIGURED (default DRB, xid %ld)\n",
4807
		PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);
4808
	}
4809
	rrc_eNB_process_RRCConnectionReconfigurationComplete(
4810 4811
          ctxt_pP,
          ue_context_p,
4812 4813
	  ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);

4814
#if defined(FLEXRAN_AGENT_SB_IF)
4815 4816
	//WARNING:Inform the controller about the UE activation. Should be moved to RRC agent in the future
	if (mac_agent_registered[ctxt_pP->module_id]) {
4817
	  agent_mac_xface[ctxt_pP->eNB_index]->flexran_agent_notify_ue_state_change(ctxt_pP->module_id,
4818
										ue_context_p->ue_id_rnti,
4819
										PROTOCOL__FLEX_UE_STATE_CHANGE_TYPE__FLUESC_UPDATED);
4820
	}
4821
#endif
4822
      }
4823 4824
#if defined(ENABLE_ITTI)
#   if defined(ENABLE_USE_MME)
4825
      if (EPC_MODE_ENABLED == 1) {
4826 4827
	if (dedicated_DRB == 1){
	  rrc_eNB_send_S1AP_E_RAB_SETUP_RESP(ctxt_pP,
4828 4829
					     ue_context_p,
					     ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);
4830 4831 4832 4833 4834 4835 4836
	}else {
	  rrc_eNB_send_S1AP_INITIAL_CONTEXT_SETUP_RESP(ctxt_pP,
						       ue_context_p);
	}
      }    
#else  // establish a dedicated bearer 
      if (dedicated_DRB == 0 ) {
4837
	//	ue_context_p->ue_context.e_rab[0].status = E_RAB_STATUS_ESTABLISHED;
4838
	rrc_eNB_reconfigure_DRBs(ctxt_pP,ue_context_p);
4839
      }
4840
      
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4841
#endif
4842
#endif 
4843
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4844

4845
    case UL_DCCH_MessageType__c1_PR_rrcConnectionReestablishmentComplete:
Cedric Roux's avatar
Cedric Roux committed
4846 4847 4848
      T(T_ENB_RRC_CONNECTION_REESTABLISHMENT_COMPLETE, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

4849
#ifdef RRC_MSG_PRINT
4850 4851
      LOG_F(RRC,"[MSG] RRC Connection Reestablishment Complete\n");

4852
      for (i = 0; i < sdu_sizeP; i++) {
4853
        LOG_F(RRC,"%02x ", ((uint8_t*)Rx_sdu)[i]);
4854
      }
4855 4856

      LOG_F(RRC,"\n");
4857
#endif
4858 4859

      MSC_LOG_RX_MESSAGE(
4860 4861 4862 4863 4864 4865 4866 4867
        MSC_RRC_ENB,
        MSC_RRC_UE,
        Rx_sdu,
        sdu_sizeP,
        MSC_AS_TIME_FMT" rrcConnectionReestablishmentComplete UE %x size %u",
        MSC_AS_TIME_ARGS(ctxt_pP),
        ue_context_p->ue_context.rnti,
        sdu_sizeP);
4868

4869
      LOG_I(RRC,
4870 4871 4872 4873 4874
            PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
            "(rrcConnectionReestablishmentComplete) ---> RRC_eNB\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            DCCH,
            sdu_sizeP);
4875 4876 4877
      break;

    case UL_DCCH_MessageType__c1_PR_rrcConnectionSetupComplete:
4878
#ifdef RRC_MSG_PRINT
4879 4880
      LOG_F(RRC,"[MSG] RRC Connection SetupComplete\n");

4881
      for (i = 0; i < sdu_sizeP; i++) {
4882
        LOG_F(RRC,"%02x ", ((uint8_t*)Rx_sdu)[i]);
4883
      }
4884 4885

      LOG_F(RRC,"\n");
4886
#endif
4887 4888

      MSC_LOG_RX_MESSAGE(
4889 4890 4891 4892 4893 4894 4895 4896
        MSC_RRC_ENB,
        MSC_RRC_UE,
        Rx_sdu,
        sdu_sizeP,
        MSC_AS_TIME_FMT" RRCConnectionSetupComplete UE %x size %u",
        MSC_AS_TIME_ARGS(ctxt_pP),
        ue_context_p->ue_context.rnti,
        sdu_sizeP);
4897

4898
      LOG_D(RRC,
4899 4900 4901 4902 4903
            PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
            "(RRCConnectionSetupComplete) ---> RRC_eNB\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            DCCH,
            sdu_sizeP);
4904 4905 4906 4907 4908 4909

      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) {
4910 4911 4912 4913 4914 4915 4916
          rrc_eNB_process_RRCConnectionSetupComplete(
            ctxt_pP,
            ue_context_p,
            &ul_dcch_msg->message.choice.c1.choice.rrcConnectionSetupComplete.criticalExtensions.choice.c1.choice.rrcConnectionSetupComplete_r8);
          ue_context_p->ue_context.Status = RRC_CONNECTED;
          LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" UE State = RRC_CONNECTED \n",
                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
4917 4918
	  
#if defined(FLEXRAN_AGENT_SB_IF)
4919 4920
	  //WARNING:Inform the controller about the UE activation. Should be moved to RRC agent in the future
	  if (mac_agent_registered[ctxt_pP->module_id]) {
4921
	    agent_mac_xface[ctxt_pP->eNB_index]->flexran_agent_notify_ue_state_change(ctxt_pP->module_id,
4922
										  ue_context_p->ue_id_rnti,
4923
										  PROTOCOL__FLEX_UE_STATE_CHANGE_TYPE__FLUESC_ACTIVATED);
4924
	  }
4925
#endif
4926 4927 4928
        }
      }

4929
      ue_context_p->ue_context.ue_release_timer=0;
4930 4931 4932
      break;

    case UL_DCCH_MessageType__c1_PR_securityModeComplete:
Cedric Roux's avatar
Cedric Roux committed
4933 4934 4935
      T(T_ENB_RRC_SECURITY_MODE_COMPLETE, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

4936
#ifdef RRC_MSG_PRINT
4937 4938
      LOG_F(RRC,"[MSG] RRC Security Mode Complete\n");

4939
      for (i = 0; i < sdu_sizeP; i++) eNB->pusch_vars[UE_id]{
4940
        LOG_F(RRC,"%02x ", ((uint8_t*)Rx_sdu)[i]);
4941
      }
4942 4943

      LOG_F(RRC,"\n");
4944
#endif
4945 4946

      MSC_LOG_RX_MESSAGE(
4947 4948 4949 4950 4951 4952 4953 4954
        MSC_RRC_ENB,
        MSC_RRC_UE,
        Rx_sdu,
        sdu_sizeP,
        MSC_AS_TIME_FMT" securityModeComplete UE %x size %u",
        MSC_AS_TIME_ARGS(ctxt_pP),
        ue_context_p->ue_context.rnti,
        sdu_sizeP);
4955

4956
      LOG_I(RRC,
4957 4958 4959
            PROTOCOL_RRC_CTXT_UE_FMT" received securityModeComplete on UL-DCCH %d from UE\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            DCCH);
4960
      LOG_D(RRC,
4961 4962 4963 4964 4965
            PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
            "(securityModeComplete) ---> RRC_eNB\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            DCCH,
            sdu_sizeP);
winckel's avatar
winckel committed
4966
#ifdef XER_PRINT
4967
      xer_fprint(stdout, &asn_DEF_UL_DCCH_Message, (void *)ul_dcch_msg);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4968
#endif
4969 4970 4971
      // 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
4972 4973 4974
      rrc_eNB_generate_UECapabilityEnquiry(
        ctxt_pP,
        ue_context_p);
4975
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4976

4977
    case UL_DCCH_MessageType__c1_PR_securityModeFailure:
Cedric Roux's avatar
Cedric Roux committed
4978 4979 4980
      T(T_ENB_RRC_SECURITY_MODE_FAILURE, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

4981
#ifdef RRC_MSG_PRINT
4982 4983
      LOG_F(RRC,"[MSG] RRC Security Mode Failure\n");

4984
      for (i = 0; i < sdu_sizeP; i++) {
4985
        LOG_F(RRC,"%02x ", ((uint8_t*)Rx_sdu)[i]);
4986
      }
4987 4988 4989

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

      MSC_LOG_RX_MESSAGE(
4992 4993 4994 4995 4996 4997 4998 4999
        MSC_RRC_ENB,
        MSC_RRC_UE,
        Rx_sdu,
        sdu_sizeP,
        MSC_AS_TIME_FMT" securityModeFailure UE %x size %u",
        MSC_AS_TIME_ARGS(ctxt_pP),
        ue_context_p->ue_context.rnti,
        sdu_sizeP);
5000

5001 5002 5003 5004 5005 5006
      LOG_W(RRC,
            PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
            "(securityModeFailure) ---> RRC_eNB\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            DCCH,
            sdu_sizeP);
winckel's avatar
winckel committed
5007
#ifdef XER_PRINT
5008
      xer_fprint(stdout, &asn_DEF_UL_DCCH_Message, (void *)ul_dcch_msg);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
5009
#endif
5010
      // cancel the security mode in PDCP
Lionel Gauthier's avatar
 
Lionel Gauthier committed
5011

5012
      // followup with the remaining procedure
5013
//#warning "LG Removed rrc_eNB_generate_UECapabilityEnquiry after receiving securityModeFailure"
Raymond Knopp's avatar
Raymond Knopp committed
5014
      rrc_eNB_generate_UECapabilityEnquiry(ctxt_pP, ue_context_p);
5015
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
5016

5017
    case UL_DCCH_MessageType__c1_PR_ueCapabilityInformation:
Cedric Roux's avatar
Cedric Roux committed
5018 5019 5020
      T(T_ENB_RRC_UE_CAPABILITY_INFORMATION, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

5021
#ifdef RRC_MSG_PRINT
5022 5023
      LOG_F(RRC,"[MSG] RRC UECapablility Information \n");

5024
      for (i = 0; i < sdu_sizeP; i++) {
5025
        LOG_F(RRC,"%02x ", ((uint8_t*)Rx_sdu)[i]);
5026
      }
5027 5028

      LOG_F(RRC,"\n");
5029
#endif
5030 5031

      MSC_LOG_RX_MESSAGE(
5032 5033 5034 5035 5036 5037 5038 5039
        MSC_RRC_ENB,
        MSC_RRC_UE,
        Rx_sdu,
        sdu_sizeP,
        MSC_AS_TIME_FMT" ueCapabilityInformation UE %x size %u",
        MSC_AS_TIME_ARGS(ctxt_pP),
        ue_context_p->ue_context.rnti,
        sdu_sizeP);
5040

5041
      LOG_I(RRC,
5042 5043 5044
            PROTOCOL_RRC_CTXT_UE_FMT" received ueCapabilityInformation on UL-DCCH %d from UE\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            DCCH);
5045
      LOG_D(RRC,
5046 5047 5048 5049 5050
            PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
            "(UECapabilityInformation) ---> RRC_eNB\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            DCCH,
            sdu_sizeP);
winckel's avatar
winckel committed
5051
#ifdef XER_PRINT
5052 5053
      xer_fprint(stdout, &asn_DEF_UL_DCCH_Message, (void *)ul_dcch_msg);
#endif
5054
      LOG_I(RRC, "got UE capabilities for UE %x\n", ctxt_pP->rnti);
5055 5056 5057 5058 5059 5060 5061 5062 5063 5064
      dec_rval = uper_decode(NULL,
                             &asn_DEF_UE_EUTRA_Capability,
                             (void **)&UE_EUTRA_Capability,
                             ul_dcch_msg->message.choice.c1.choice.ueCapabilityInformation.criticalExtensions.
                             choice.c1.choice.ueCapabilityInformation_r8.ue_CapabilityRAT_ContainerList.list.
                             array[0]->ueCapabilityRAT_Container.buf,
                             ul_dcch_msg->message.choice.c1.choice.ueCapabilityInformation.criticalExtensions.
                             choice.c1.choice.ueCapabilityInformation_r8.ue_CapabilityRAT_ContainerList.list.
                             array[0]->ueCapabilityRAT_Container.size, 0, 0);
      //#ifdef XER_PRINT
5065
      //xer_fprint(stdout, &asn_DEF_UE_EUTRA_Capability, (void *)UE_EUTRA_Capability);
5066
      //#endif
5067

5068
#if defined(ENABLE_USE_MME)
5069 5070

      if (EPC_MODE_ENABLED == 1) {
5071 5072 5073
        rrc_eNB_send_S1AP_UE_CAPABILITIES_IND(ctxt_pP,
                                              ue_context_p,
                                              ul_dcch_msg);
5074
      }
5075 5076 5077 5078 5079 5080 5081 5082
#else 
      ue_context_p->ue_context.nb_of_e_rabs = 1;
      for (i = 0; i < ue_context_p->ue_context.nb_of_e_rabs; i++){
	ue_context_p->ue_context.e_rab[i].status = E_RAB_STATUS_NEW;
	ue_context_p->ue_context.e_rab[i].param.e_rab_id = 1+i;
	ue_context_p->ue_context.e_rab[i].param.qos.qci=9;
      }
      ue_context_p->ue_context.setup_e_rabs =ue_context_p->ue_context.nb_of_e_rabs;
5083 5084
#endif

5085 5086 5087
      rrc_eNB_generate_defaultRRCConnectionReconfiguration(ctxt_pP,
          ue_context_p,
          eNB_rrc_inst[ctxt_pP->module_id].HO_flag);
5088
      break;
5089

5090
    case UL_DCCH_MessageType__c1_PR_ulHandoverPreparationTransfer:
Cedric Roux's avatar
Cedric Roux committed
5091 5092 5093
      T(T_ENB_RRC_UL_HANDOVER_PREPARATION_TRANSFER, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

5094
      break;
5095

5096
    case UL_DCCH_MessageType__c1_PR_ulInformationTransfer:
Cedric Roux's avatar
Cedric Roux committed
5097 5098 5099
      T(T_ENB_RRC_UL_INFORMATION_TRANSFER, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

5100
#ifdef RRC_MSG_PRINT
5101 5102
      LOG_F(RRC,"[MSG] RRC UL Information Transfer \n");

5103
      for (i = 0; i < sdu_sizeP; i++) {
5104
        LOG_F(RRC,"%02x ", ((uint8_t*)Rx_sdu)[i]);
5105
      }
5106 5107

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

5110 5111

      MSC_LOG_RX_MESSAGE(
5112 5113 5114 5115 5116 5117 5118 5119
        MSC_RRC_ENB,
        MSC_RRC_UE,
        Rx_sdu,
        sdu_sizeP,
        MSC_AS_TIME_FMT" ulInformationTransfer UE %x size %u",
        MSC_AS_TIME_ARGS(ctxt_pP),
        ue_context_p->ue_context.rnti,
        sdu_sizeP);
5120

winckel's avatar
winckel committed
5121
#if defined(ENABLE_USE_MME)
5122 5123

      if (EPC_MODE_ENABLED == 1) {
5124 5125 5126
        rrc_eNB_send_S1AP_UPLINK_NAS(ctxt_pP,
                                     ue_context_p,
                                     ul_dcch_msg);
5127 5128
      }

winckel's avatar
winckel committed
5129
#endif
5130
      break;
5131

5132
    case UL_DCCH_MessageType__c1_PR_counterCheckResponse:
Cedric Roux's avatar
Cedric Roux committed
5133 5134 5135
      T(T_ENB_RRC_COUNTER_CHECK_RESPONSE, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

5136
      break;
5137

Cedric Roux's avatar
Cedric Roux committed
5138
#if defined(Rel10) || defined(Rel14)
5139

5140
    case UL_DCCH_MessageType__c1_PR_ueInformationResponse_r9:
Cedric Roux's avatar
Cedric Roux committed
5141 5142 5143
      T(T_ENB_RRC_UE_INFORMATION_RESPONSE_R9, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

5144 5145 5146
      break;

    case UL_DCCH_MessageType__c1_PR_proximityIndication_r9:
Cedric Roux's avatar
Cedric Roux committed
5147 5148 5149
      T(T_ENB_RRC_PROXIMITY_INDICATION_R9, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

5150
      break;
5151

5152
    case UL_DCCH_MessageType__c1_PR_rnReconfigurationComplete_r10:
Cedric Roux's avatar
Cedric Roux committed
5153 5154 5155
      T(T_ENB_RRC_RECONFIGURATION_COMPLETE_R10, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

5156
      break;
5157

5158
    case UL_DCCH_MessageType__c1_PR_mbmsCountingResponse_r10:
Cedric Roux's avatar
Cedric Roux committed
5159 5160 5161
      T(T_ENB_RRC_MBMS_COUNTING_RESPONSE_R10, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

5162
      break;
winckel's avatar
winckel committed
5163

5164
    case UL_DCCH_MessageType__c1_PR_interFreqRSTDMeasurementIndication_r10:
Cedric Roux's avatar
Cedric Roux committed
5165 5166 5167
      T(T_ENB_RRC_INTER_FREQ_RSTD_MEASUREMENT_INDICATION, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

5168
      break;
5169
#endif
5170

5171
    default:
Cedric Roux's avatar
Cedric Roux committed
5172 5173 5174
      T(T_ENB_RRC_UNKNOW_MESSAGE, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
        T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));

5175 5176 5177
      LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Unknown message %s:%u\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
            __FILE__, __LINE__);
5178
      return -1;
winckel's avatar
winckel committed
5179 5180
    }

5181 5182
    return 0;
  } else {
5183 5184 5185
    LOG_E(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Unknown error %s:%u\n",
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
          __FILE__, __LINE__);
5186 5187 5188
    return -1;
  }

winckel's avatar
winckel committed
5189 5190
}

5191
#if defined(ENABLE_ITTI)
5192 5193
// This function triggers the establishemnt of dedicated bearer in the absence of EPC
// to emulate it only establish 3 bearers but it can also establish 10 dedicated bearers.
5194 5195 5196 5197
void rrc_eNB_reconfigure_DRBs (const protocol_ctxt_t* const ctxt_pP,
			       rrc_eNB_ue_context_t*  ue_context_pP){

  int i;
Navid Nikaein's avatar
Navid Nikaein committed
5198
  int e_rab_done=0;
5199
  for (i = 0; 
Navid Nikaein's avatar
Navid Nikaein committed
5200
       i < 3;//NB_RB_MAX - 3;  // S1AP_MAX_E_RAB
5201 5202
       i++) {
    
5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216
    if ( ue_context_pP->ue_context.e_rab[i].status < E_RAB_STATUS_DONE){ 
      ue_context_pP->ue_context.e_rab[i].status = E_RAB_STATUS_NEW;
      ue_context_pP->ue_context.e_rab[i].param.e_rab_id = i + 1;
      ue_context_pP->ue_context.e_rab[i].param.qos.qci = i % 9;
      ue_context_pP->ue_context.e_rab[i].param.qos.allocation_retention_priority.priority_level= i % PRIORITY_LEVEL_LOWEST;
      ue_context_pP->ue_context.e_rab[i].param.qos.allocation_retention_priority.pre_emp_capability= PRE_EMPTION_CAPABILITY_DISABLED;
      ue_context_pP->ue_context.e_rab[i].param.qos.allocation_retention_priority.pre_emp_vulnerability= PRE_EMPTION_VULNERABILITY_DISABLED;
      ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer = NULL;
      ue_context_pP->ue_context.e_rab[i].param.nas_pdu.length = 0;
      //	memset (ue_context_pP->ue_context.e_rab[i].param.sgw_addr.buffer,0,20);
      ue_context_pP->ue_context.e_rab[i].param.sgw_addr.length = 0;
      ue_context_pP->ue_context.e_rab[i].param.gtp_teid=0;
      
      ue_context_pP->ue_context.nb_of_e_rabs++;
Navid Nikaein's avatar
Navid Nikaein committed
5217
      e_rab_done++;
5218 5219 5220
      LOG_I(RRC,"setting up the dedicated DRBs %d (index %d) status %d \n", 
	    ue_context_pP->ue_context.e_rab[i].param.e_rab_id, i, ue_context_pP->ue_context.e_rab[i].status);
    }
5221
  }
Navid Nikaein's avatar
Navid Nikaein committed
5222 5223
  ue_context_pP->ue_context.setup_e_rabs+=e_rab_done;
 
5224 5225 5226 5227
  rrc_eNB_generate_dedicatedRRCConnectionReconfiguration(ctxt_pP, ue_context_pP, 0);
}


5228 5229 5230 5231 5232 5233
//-----------------------------------------------------------------------------
void*
rrc_enb_task(
  void* args_p
)
//-----------------------------------------------------------------------------
5234 5235 5236 5237 5238 5239
{
  MessageDef                         *msg_p;
  const char                         *msg_name_p;
  instance_t                          instance;
  int                                 result;
  SRB_INFO                           *srb_info_p;
5240
  int                                 CC_id;
5241

5242
  protocol_ctxt_t                     ctxt;
5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262
  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:
5263 5264 5265 5266 5267 5268 5269 5270 5271
      PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt,
                                    instance,
                                    ENB_FLAG_YES,
                                    RRC_MAC_CCCH_DATA_IND(msg_p).rnti,
                                    msg_p->ittiMsgHeader.lte_time.frame,
                                    msg_p->ittiMsgHeader.lte_time.slot);
      LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Received %s\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(&ctxt),
            msg_name_p);
5272

5273 5274
      CC_id = RRC_MAC_CCCH_DATA_IND(msg_p).CC_id;
      srb_info_p = &eNB_rrc_inst[instance].carrier[CC_id].Srb0;
5275

5276 5277
      memcpy(srb_info_p->Rx_buffer.Payload,
             RRC_MAC_CCCH_DATA_IND(msg_p).sdu,
5278 5279
             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;
5280
      rrc_eNB_decode_ccch(&ctxt, srb_info_p, CC_id);
5281 5282 5283 5284
      break;

      /* Messages from PDCP */
    case RRC_DCCH_DATA_IND:
5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297
      PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt,
                                    instance,
                                    ENB_FLAG_YES,
                                    RRC_DCCH_DATA_IND(msg_p).rnti,
                                    msg_p->ittiMsgHeader.lte_time.frame,
                                    msg_p->ittiMsgHeader.lte_time.slot);
      LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Received on DCCH %d %s\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(&ctxt),
            RRC_DCCH_DATA_IND(msg_p).dcch_index,
            msg_name_p);
      rrc_eNB_decode_dcch(&ctxt,
                          RRC_DCCH_DATA_IND(msg_p).dcch_index,
                          RRC_DCCH_DATA_IND(msg_p).sdu_p,
5298 5299 5300 5301 5302 5303
                          RRC_DCCH_DATA_IND(msg_p).sdu_size);

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

#   if defined(ENABLE_USE_MME)

5307 5308 5309 5310
      /* Messages from S1AP */
    case S1AP_DOWNLINK_NAS:
      rrc_eNB_process_S1AP_DOWNLINK_NAS(msg_p, msg_name_p, instance, &rrc_eNB_mui);
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
5311

5312 5313 5314
    case S1AP_INITIAL_CONTEXT_SETUP_REQ:
      rrc_eNB_process_S1AP_INITIAL_CONTEXT_SETUP_REQ(msg_p, msg_name_p, instance);
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
5315

5316 5317 5318
    case S1AP_UE_CTXT_MODIFICATION_REQ:
      rrc_eNB_process_S1AP_UE_CTXT_MODIFICATION_REQ(msg_p, msg_name_p, instance);
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
5319

5320 5321 5322
    case S1AP_PAGING_IND:
      LOG_E(RRC, "[eNB %d] Received not yet implemented message %s\n", instance, msg_name_p);
      break;
5323 5324 5325 5326 5327 5328
  
    case S1AP_E_RAB_SETUP_REQ: 
      rrc_eNB_process_S1AP_E_RAB_SETUP_REQ(msg_p, msg_name_p, instance);
      LOG_D(RRC, "[eNB %d] Received the message %s\n", instance, msg_name_p);
      break;
    
5329 5330 5331
    case S1AP_UE_CONTEXT_RELEASE_REQ:
      rrc_eNB_process_S1AP_UE_CONTEXT_RELEASE_REQ(msg_p, msg_name_p, instance);
      break;
5332

5333 5334 5335
    case S1AP_UE_CONTEXT_RELEASE_COMMAND:
      rrc_eNB_process_S1AP_UE_CONTEXT_RELEASE_COMMAND(msg_p, msg_name_p, instance);
      break;
5336

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

Lionel Gauthier's avatar
 
Lionel Gauthier committed
5343 5344
#   endif

5345 5346 5347
      /* Messages from eNB app */
    case RRC_CONFIGURATION_REQ:
      LOG_I(RRC, "[eNB %d] Received %s\n", instance, msg_name_p);
5348
      openair_rrc_eNB_configuration(ENB_INSTANCE_TO_MODULE_ID(instance), &RRC_CONFIGURATION_REQ(msg_p));
5349
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
5350

5351
#   if ENABLE_RAL
5352 5353 5354 5355

    case RRC_RAL_CONFIGURE_THRESHOLD_REQ:
      rrc_enb_ral_handle_configure_threshold_request(instance, msg_p);
      break;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
5356

5357 5358 5359
      //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 */
5360
//#warning "TODO GET RIGHT RNTI"
5361 5362 5363 5364 5365 5366
      PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt,
                                    instance,
                                    ENB_FLAG_YES,
                                    NOT_A_RNTI, // TO DO GET RIGHT RNTI
                                    msg_p->ittiMsgHeader.lte_time.frame,
                                    msg_p->ittiMsgHeader.lte_time.slot);
5367 5368
      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
5369 5370 5371
      //rrc_eNB_generate_RRCConnectionReconfiguration_SCell(instance, 0/* TODO put frameP number ! */, /*ue_mod_id force ue_mod_id to first UE*/0, 36126);
      //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);
5372
      break;
5373
#   endif
5374

5375 5376 5377
    default:
      LOG_E(RRC, "[eNB %d] Received unexpected message %s\n", instance, msg_name_p);
      break;
5378
    }
5379 5380 5381 5382 5383

    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;
  }
5384 5385
}
#endif
winckel's avatar
winckel committed
5386 5387

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