rrc_UE.c 287 KB
Newer Older
1 2 3 4 5
/*
 * 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
6
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
7 8 9 10 11 12 13 14 15 16 17 18 19 20
 * 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

/*! \file rrc_UE.c
23
 * \brief rrc procedures for UE
24 25
 * \author Navid Nikaein and Raymond Knopp
 * \date 2011 - 2014
26 27
 * \version 1.0
 * \company Eurecom
28
 * \email: navid.nikaein@eurecom.fr and raymond.knopp@eurecom.fr
29
 */
30

Lionel Gauthier's avatar
Lionel Gauthier committed
31 32
#define RRC_UE
#define RRC_UE_C
33
#define _GNU_SOURCE
34

35
#include "assertions.h"
36
#include "hashtable.h"
37
#include "asn1_conversions.h"
38
#include "defs.h"
39
#include "PHY/TOOLS/dB_routines.h"
40 41 42 43 44 45
#include "extern.h"
#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"
#include "LAYER2/RLC/rlc.h"
#include "COMMON/mac_rrc_primitives.h"
#include "UTIL/LOG/log.h"
#include "UTIL/LOG/vcd_signal_dumper.h"
46 47 48
#ifndef CELLULAR
#include "RRC/LITE/MESSAGES/asn1_msg.h"
#endif
49 50 51 52 53 54 55
#include "RRCConnectionRequest.h"
#include "RRCConnectionReconfiguration.h"
#include "UL-CCCH-Message.h"
#include "DL-CCCH-Message.h"
#include "UL-DCCH-Message.h"
#include "DL-DCCH-Message.h"
#include "BCCH-DL-SCH-Message.h"
56
#include "PCCH-Message.h"
Cedric Roux's avatar
Cedric Roux committed
57
#if defined(Rel10) || defined(Rel14)
58 59 60 61 62 63 64 65 66 67
#include "MCCH-Message.h"
#endif
#include "MeasConfig.h"
#include "MeasGapConfig.h"
#include "MeasObjectEUTRA.h"
#include "TDD-Config.h"
#include "UECapabilityEnquiry.h"
#include "UE-CapabilityRequest.h"
#include "RRC/NAS/nas_config.h"
#include "RRC/NAS/rb_config.h"
68
#if ENABLE_RAL
Lionel Gauthier's avatar
Lionel Gauthier committed
69 70
#include "rrc_UE_ral.h"
#endif
71 72 73 74 75

#if defined(ENABLE_SECURITY)
# include "UTIL/OSA/osa_defs.h"
#endif

76
#include "pdcp.h"
77
#include "plmn_data.h"
Lionel Gauthier's avatar
Lionel Gauthier committed
78
#include "msc.h"
79

80 81 82 83
#if defined(ENABLE_ITTI)
# include "intertask_interface.h"
#endif

84 85
#include "SIMULATION/TOOLS/defs.h" // for taus

86 87 88
#ifdef Rel14
#include "SL-Preconfiguration-r12.h"

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
89
//for D2D
90 91 92 93
int ctrl_sock_fd;
#define BUFSIZE 1024
struct sockaddr_in prose_app_addr;
int slrb_id;
94
int send_ue_information = 0;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
95
#endif
96

97 98 99 100 101 102 103 104 105
#ifdef PHY_EMUL
extern EMULATION_VARS *Emul_vars;
#endif
extern eNB_MAC_INST *eNB_mac_inst;
extern UE_MAC_INST *UE_mac_inst;
#ifdef BIGPHYSAREA
extern void *bigphys_malloc(int);
#endif

matzakos's avatar
matzakos committed
106 107
extern uint8_t  nfapi_mode;

108
//#define XER_PRINT
109

110
//extern int8_t dB_fixed2(uint32_t x,uint32_t y);
111

112 113 114 115 116 117 118 119 120
extern void pdcp_config_set_security(
  const protocol_ctxt_t* const  ctxt_pP,
  pdcp_t         * const pdcp_pP,
  const rb_id_t         rb_idP,
  const uint16_t        lc_idP,
  const uint8_t         security_modeP,
  uint8_t        * const kRRCenc,
  uint8_t        * const kRRCint,
  uint8_t        * const  kUPenc);
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143

// internal prototypes

void rrc_ue_process_securityModeCommand( const protocol_ctxt_t* const ctxt_pP, SecurityModeCommand_t* const securityModeCommand, const uint8_t eNB_index );

static int decode_SI( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index );

static int decode_SIB1( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index, const uint8_t rsrq, const uint8_t rsrp );

/** \brief Generates/Encodes RRCConnnectionSetupComplete message at UE
 *  \param ctxt_pP Running context
 *  \param eNB_index Index of corresponding eNB/CH
 *  \param Transaction_id Transaction identifier
 */
static void rrc_ue_generate_RRCConnectionSetupComplete( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index, const uint8_t Transaction_id );

/** \brief Generates/Encodes RRCConnectionReconfigurationComplete message at UE
 *  \param ctxt_pP Running context
 *  \param eNB_index Index of corresponding eNB/CH
 *  \param Transaction_id RRC transaction identifier
 */
static void rrc_ue_generate_RRCConnectionReconfigurationComplete( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index, const uint8_t Transaction_id );

144
static void rrc_ue_generate_MeasurementReport(protocol_ctxt_t* const ctxt_pP, uint8_t eNB_index );
145 146 147 148 149 150 151 152 153 154

static uint8_t check_trigger_meas_event(
  uint8_t module_idP,
  frame_t frameP,
  uint8_t eNB_index,
  uint8_t ue_cnx_index,
  uint8_t meas_index,
  Q_OffsetRange_t ofn, Q_OffsetRange_t ocn, Hysteresis_t hys,
  Q_OffsetRange_t ofs, Q_OffsetRange_t ocs, long a3_offset, TimeToTrigger_t ttt);

Cedric Roux's avatar
Cedric Roux committed
155
#if defined(Rel10) || defined(Rel14)
156
static void decode_MBSFNAreaConfiguration(module_id_t module_idP, uint8_t eNB_index, frame_t frameP,uint8_t mbsfn_sync_area);
157
uint8_t rrc_ue_generate_SidelinkUEInformation( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index,SL_DestinationInfoList_r12_t  *destinationInfoList, long *discTxResourceReq, SL_TRIGGER_t mode);
Cedric Roux's avatar
Cedric Roux committed
158
#endif
159 160 161 162 163 164 165 166








winckel's avatar
winckel committed
167
/*------------------------------------------------------------------------------*/
Cedric Roux's avatar
Cedric Roux committed
168 169
/* to avoid gcc warnings when compiling with certain options */
#if defined(ENABLE_USE_MME) || ENABLE_RAL
170 171
static Rrc_State_t rrc_get_state (module_id_t ue_mod_idP)
{
Lionel Gauthier's avatar
 
Lionel Gauthier committed
172
  return UE_rrc_inst[ue_mod_idP].RrcState;
winckel's avatar
winckel committed
173
}
Cedric Roux's avatar
Cedric Roux committed
174
#endif
winckel's avatar
winckel committed
175

176 177
static Rrc_Sub_State_t rrc_get_sub_state (module_id_t ue_mod_idP)
{
Lionel Gauthier's avatar
 
Lionel Gauthier committed
178
  return UE_rrc_inst[ue_mod_idP].RrcSubState;
winckel's avatar
winckel committed
179 180
}

181 182
static int rrc_set_state (module_id_t ue_mod_idP, Rrc_State_t state)
{
winckel's avatar
winckel committed
183
  AssertFatal ((RRC_STATE_FIRST <= state) && (state <= RRC_STATE_LAST),
184
               "Invalid state %d!\n", state);
winckel's avatar
winckel committed
185

Lionel Gauthier's avatar
 
Lionel Gauthier committed
186
  if (UE_rrc_inst[ue_mod_idP].RrcState != state) {
187
    UE_rrc_inst[ue_mod_idP].RrcState = state;
winckel's avatar
winckel committed
188

189
#if defined(ENABLE_ITTI)
190 191
    {
      MessageDef *msg_p;
192

193 194 195
      msg_p = itti_alloc_new_message(TASK_RRC_UE, RRC_STATE_IND);
      RRC_STATE_IND(msg_p).state = UE_rrc_inst[ue_mod_idP].RrcState;
      RRC_STATE_IND(msg_p).sub_state = UE_rrc_inst[ue_mod_idP].RrcSubState;
winckel's avatar
winckel committed
196

197
      itti_send_msg_to_task(TASK_UNKNOWN, UE_MODULE_ID_TO_INSTANCE(ue_mod_idP), msg_p);
198
    }
199
#endif
200
    return (1);
winckel's avatar
winckel committed
201 202 203 204 205
  }

  return (0);
}

206
//-----------------------------------------------------------------------------
207
static int rrc_set_sub_state( module_id_t ue_mod_idP, Rrc_Sub_State_t subState )
208
{
209
#if (defined(ENABLE_ITTI) && (defined(ENABLE_USE_MME) || ENABLE_RAL))
210

Lionel Gauthier's avatar
 
Lionel Gauthier committed
211
  switch (UE_rrc_inst[ue_mod_idP].RrcState) {
212 213
  case RRC_STATE_INACTIVE:
    AssertFatal ((RRC_SUB_STATE_INACTIVE_FIRST <= subState) && (subState <= RRC_SUB_STATE_INACTIVE_LAST),
214
                 "Invalid sub state %d for state %d!\n", subState, UE_rrc_inst[ue_mod_idP].RrcState);
215 216 217 218
    break;

  case RRC_STATE_IDLE:
    AssertFatal ((RRC_SUB_STATE_IDLE_FIRST <= subState) && (subState <= RRC_SUB_STATE_IDLE_LAST),
219
                 "Invalid sub state %d for state %d!\n", subState, UE_rrc_inst[ue_mod_idP].RrcState);
220 221 222 223
    break;

  case RRC_STATE_CONNECTED:
    AssertFatal ((RRC_SUB_STATE_CONNECTED_FIRST <= subState) && (subState <= RRC_SUB_STATE_CONNECTED_LAST),
224
                 "Invalid sub state %d for state %d!\n", subState, UE_rrc_inst[ue_mod_idP].RrcState);
225
    break;
winckel's avatar
winckel committed
226
  }
227

228
#endif
winckel's avatar
winckel committed
229

Lionel Gauthier's avatar
 
Lionel Gauthier committed
230
  if (UE_rrc_inst[ue_mod_idP].RrcSubState != subState) {
231
    UE_rrc_inst[ue_mod_idP].RrcSubState = subState;
winckel's avatar
winckel committed
232

233
#if defined(ENABLE_ITTI)
234 235
    {
      MessageDef *msg_p;
winckel's avatar
winckel committed
236

237 238 239
      msg_p = itti_alloc_new_message(TASK_RRC_UE, RRC_STATE_IND);
      RRC_STATE_IND(msg_p).state = UE_rrc_inst[ue_mod_idP].RrcState;
      RRC_STATE_IND(msg_p).sub_state = UE_rrc_inst[ue_mod_idP].RrcSubState;
240

241
      itti_send_msg_to_task(TASK_UNKNOWN, UE_MODULE_ID_TO_INSTANCE(ue_mod_idP), msg_p);
242
    }
243
#endif
244
    return (1);
winckel's avatar
winckel committed
245 246 247 248 249
  }

  return (0);
}

250
//-----------------------------------------------------------------------------
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
void
openair_rrc_on_ue(
  const protocol_ctxt_t* const ctxt_pP
)
//-----------------------------------------------------------------------------
{
  unsigned short i;


    LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" UE?:OPENAIR RRC IN....\n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));

    for (i = 0; i < NB_eNB_INST; i++) {
      LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" Activating CCCH (eNB %d)\n",
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP), i);
      UE_rrc_inst[ctxt_pP->module_id].Srb0[i].Srb_id = CCCH;
      memcpy (&UE_rrc_inst[ctxt_pP->module_id].Srb0[i].Lchan_desc[0], &CCCH_LCHAN_DESC, LCHAN_DESC_SIZE);
      memcpy (&UE_rrc_inst[ctxt_pP->module_id].Srb0[i].Lchan_desc[1], &CCCH_LCHAN_DESC, LCHAN_DESC_SIZE);
      rrc_config_buffer (&UE_rrc_inst[ctxt_pP->module_id].Srb0[i], CCCH, 1);
      UE_rrc_inst[ctxt_pP->module_id].Srb0[i].Active = 1;
    }
}

274
//-----------------------------------------------------------------------------
275
static void init_SI_UE( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index )
276
{
277 278
  UE_rrc_inst[ctxt_pP->module_id].sizeof_SIB1[eNB_index] = 0;
  UE_rrc_inst[ctxt_pP->module_id].sizeof_SI[eNB_index] = 0;
279 280 281 282 283 284 285 286 287 288 289 290
  UE_rrc_inst[ctxt_pP->module_id].SIB1[eNB_index] = (uint8_t*)malloc16_clear( 32 );
  UE_rrc_inst[ctxt_pP->module_id].sib1[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType1_t) );
  UE_rrc_inst[ctxt_pP->module_id].sib2[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType2_t) );
  UE_rrc_inst[ctxt_pP->module_id].sib3[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType3_t) );
  UE_rrc_inst[ctxt_pP->module_id].sib4[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType4_t) );
  UE_rrc_inst[ctxt_pP->module_id].sib5[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType5_t) );
  UE_rrc_inst[ctxt_pP->module_id].sib6[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType6_t) );
  UE_rrc_inst[ctxt_pP->module_id].sib7[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType7_t) );
  UE_rrc_inst[ctxt_pP->module_id].sib8[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType8_t) );
  UE_rrc_inst[ctxt_pP->module_id].sib9[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType9_t) );
  UE_rrc_inst[ctxt_pP->module_id].sib10[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType10_t) );
  UE_rrc_inst[ctxt_pP->module_id].sib11[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType11_t) );
Cedric Roux's avatar
Cedric Roux committed
291
#if defined(Rel10) || defined(Rel14)
292 293
  UE_rrc_inst[ctxt_pP->module_id].sib12[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType12_r9_t) );
  UE_rrc_inst[ctxt_pP->module_id].sib13[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType13_r9_t) );
294 295
  UE_rrc_inst[ctxt_pP->module_id].sib18[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType18_r12_t) );
  UE_rrc_inst[ctxt_pP->module_id].sib19[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType19_r12_t) );
296
  UE_rrc_inst[ctxt_pP->module_id].sib21[eNB_index] = malloc16_clear( sizeof(SystemInformationBlockType21_r14_t) );
297

298 299
#endif
  UE_rrc_inst[ctxt_pP->module_id].SI[eNB_index] = (uint8_t*)malloc16_clear( 64 );
300

301
  UE_rrc_inst[ctxt_pP->module_id].si[eNB_index] = (SystemInformation_t*)malloc16_clear( sizeof(SystemInformation_t) );
302

303
  UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus = 0;
304
  UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIcnt    = 0;
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
#ifdef Rel14
void init_SL_preconfig(UE_RRC_INST *UE, const uint8_t eNB_index )
{
  LOG_I(RRC,"Initializing Sidelink Pre-configuration for UE\n");

  UE->SL_Preconfiguration[eNB_index] = malloc16_clear( sizeof(struct SL_Preconfiguration_r12) );
  UE->SL_Preconfiguration[eNB_index]->preconfigGeneral_r12.rohc_Profiles_r12.profile0x0001_r12       = true;
  UE->SL_Preconfiguration[eNB_index]->preconfigGeneral_r12.carrierFreq_r12                           = 3350;
  UE->SL_Preconfiguration[eNB_index]->preconfigGeneral_r12.maxTxPower_r12                            = 0;
  UE->SL_Preconfiguration[eNB_index]->preconfigGeneral_r12.additionalSpectrumEmission_r12            = 0;
  UE->SL_Preconfiguration[eNB_index]->preconfigGeneral_r12.sl_bandwidth_r12                          = SL_PreconfigGeneral_r12__sl_bandwidth_r12_n50;
  UE->SL_Preconfiguration[eNB_index]->preconfigGeneral_r12.tdd_ConfigSL_r12.subframeAssignmentSL_r12 = TDD_ConfigSL_r12__subframeAssignmentSL_r12_none;

  UE->SL_Preconfiguration[eNB_index]->preconfigSync_r12.syncCP_Len_r12            = SL_CP_Len_r12_normal;
  UE->SL_Preconfiguration[eNB_index]->preconfigSync_r12.syncOffsetIndicator1_r12  = 0;
  UE->SL_Preconfiguration[eNB_index]->preconfigSync_r12.syncOffsetIndicator2_r12  = 0;
  UE->SL_Preconfiguration[eNB_index]->preconfigSync_r12.syncTxParameters_r12      = 0;
  UE->SL_Preconfiguration[eNB_index]->preconfigSync_r12.syncTxThreshOoC_r12       = 0;
  UE->SL_Preconfiguration[eNB_index]->preconfigSync_r12.filterCoefficient_r12     = FilterCoefficient_fc0;
  UE->SL_Preconfiguration[eNB_index]->preconfigSync_r12.syncRefMinHyst_r12        = SL_PreconfigSync_r12__syncRefMinHyst_r12_dB0;
  UE->SL_Preconfiguration[eNB_index]->preconfigSync_r12.syncRefDiffHyst_r12       = SL_PreconfigSync_r12__syncRefDiffHyst_r12_dB0;
  UE->SL_Preconfiguration[eNB_index]->preconfigSync_r12.ext1                      = malloc16_clear(sizeof(struct SL_PreconfigSync_r12__ext1));
  UE->SL_Preconfiguration[eNB_index]->preconfigSync_r12.ext1->syncTxPeriodic_r13  = NULL;

  struct SL_PreconfigCommPool_r12 *preconfigpool = malloc16_clear(sizeof(struct SL_PreconfigCommPool_r12));
  preconfigpool->sc_CP_Len_r12                                                    = SL_CP_Len_r12_normal;
  preconfigpool->sc_Period_r12                                                    = SL_PeriodComm_r12_sf40;
  // 20 PRBs for SL communications
335 336
  preconfigpool->sc_TF_ResourceConfig_r12.prb_Num_r12                             = 20;
  preconfigpool->sc_TF_ResourceConfig_r12.prb_Start_r12                           = 5;
337 338 339
  preconfigpool->sc_TF_ResourceConfig_r12.prb_End_r12                             = 44;
  // Offset set to 0 subframes
  preconfigpool->sc_TF_ResourceConfig_r12.offsetIndicator_r12.present             = SL_OffsetIndicator_r12_PR_small_r12;
340
  preconfigpool->sc_TF_ResourceConfig_r12.offsetIndicator_r12.choice.small_r12    = 0;
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
  // 40 ms SL Period
  preconfigpool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.present              = SubframeBitmapSL_r12_PR_bs40_r12;
  preconfigpool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.buf         = CALLOC(1,5);
  preconfigpool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.size        = 5;
  preconfigpool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.bits_unused = 0;
  // 1st 4 subframes for PSCCH
  preconfigpool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.buf[0]      = 0xF;
  preconfigpool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.buf[1]      = 0;
  preconfigpool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.buf[2]      = 0;
  preconfigpool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.buf[3]      = 0;
  preconfigpool->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.buf[4]      = 0;
  preconfigpool->sc_TxParameters_r12                                              = 0;

  preconfigpool->data_CP_Len_r12                                                  = SL_CP_Len_r12_normal;
  // 20 PRBs for SL communications
356 357
  preconfigpool->data_TF_ResourceConfig_r12.prb_Num_r12                             = 20;
  preconfigpool->data_TF_ResourceConfig_r12.prb_Start_r12                           = 5;
358 359 360
  preconfigpool->data_TF_ResourceConfig_r12.prb_End_r12                             = 44;
  // Offset set to 0 subframes
  preconfigpool->data_TF_ResourceConfig_r12.offsetIndicator_r12.present             = SL_OffsetIndicator_r12_PR_small_r12;
361
  preconfigpool->data_TF_ResourceConfig_r12.offsetIndicator_r12.choice.small_r12    = 0;
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
  // 40 ms SL Period
  preconfigpool->data_TF_ResourceConfig_r12.subframeBitmap_r12.present              = SubframeBitmapSL_r12_PR_bs40_r12;
  preconfigpool->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.buf         = CALLOC(1,5);
  preconfigpool->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.size        = 5;
  preconfigpool->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.bits_unused = 0;
  // last 36 subframes for PSCCH
  preconfigpool->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.buf[0]      = 0xF0;
  preconfigpool->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.buf[1]      = 0xFF;
  preconfigpool->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.buf[2]      = 0xFF;
  preconfigpool->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.buf[3]      = 0xFF;
  preconfigpool->data_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs40_r12.buf[5]      = 0xFF;

  preconfigpool->dataHoppingConfig_r12.hoppingParameter_r12                         = 0;
  preconfigpool->dataHoppingConfig_r12.numSubbands_r12                              = SL_HoppingConfigComm_r12__numSubbands_r12_ns1;
  preconfigpool->dataHoppingConfig_r12.rb_Offset_r12                                = 0;

  preconfigpool->dataTxParameters_r12                                               = 0;

  ASN_SEQUENCE_ADD(&UE->SL_Preconfiguration[eNB_index]->preconfigComm_r12.list,preconfigpool);

  // Rel13 extensions
  UE->SL_Preconfiguration[eNB_index]->ext1 = NULL;
384
/*
385
  // Establish a SLRB (using DRB 3 for now)
386 387 388
  protocol_ctxt_t ctxt;
  PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, 0, ENB_FLAG_NO, 0x1234, 0, 0,0);

389 390 391 392 393 394 395 396
  UE->DRB_config[0][0] = CALLOC(1,sizeof(struct DRB_ToAddMod));
  UE->DRB_config[0][0]->eps_BearerIdentity = CALLOC(1, sizeof(long));
  UE->DRB_config[0][0]->drb_Identity =  3;
  UE->DRB_config[0][0]->eps_BearerIdentity = CALLOC(1, sizeof(long));
  // allowed value 5..15, value : x+4
  *(UE->DRB_config[0][0]->eps_BearerIdentity) = 3;
  UE->DRB_config[0][0]->logicalChannelIdentity = CALLOC(1, sizeof(long));
  *(UE->DRB_config[0][0]->logicalChannelIdentity) = UE->DRB_config[0][0]->drb_Identity; //(long) (ue_context_pP->ue_context.e_rab[i].param.e_rab_id + 2); // value : x+2
397

398 399 400 401 402 403 404 405 406
  // TTN - Establish a new SLRB for PC5-S (using DRB 10 for now)
  UE->DRB_config[0][1] = CALLOC(1,sizeof(struct DRB_ToAddMod));
  UE->DRB_config[0][1]->eps_BearerIdentity = CALLOC(1, sizeof(long));
  UE->DRB_config[0][1]->drb_Identity =  10;
  UE->DRB_config[0][1]->eps_BearerIdentity = CALLOC(1, sizeof(long));
  // allowed value 5..15, value : x+4
  *(UE->DRB_config[0][1]->eps_BearerIdentity) = 10;
  UE->DRB_config[0][1]->logicalChannelIdentity = CALLOC(1, sizeof(long));
  *(UE->DRB_config[0][1]->logicalChannelIdentity) = UE->DRB_config[0][1]->drb_Identity; //(long) (ue_context_pP->ue_context.e_rab[i].param.e_rab_id + 2); // value : x+2
407 408 409 410 411 412 413 414 415 416 417 418 419 420

  struct RLC_Config                  *DRB_rlc_config                   = CALLOC(1,sizeof(struct RLC_Config));
  struct PDCP_Config                 *DRB_pdcp_config                  = CALLOC(1,sizeof(struct PDCP_Config));
  struct PDCP_Config__rlc_UM         *PDCP_rlc_UM                      = CALLOC(1,sizeof(struct PDCP_Config__rlc_UM));
  struct LogicalChannelConfig        *DRB_lchan_config                 = CALLOC(1,sizeof(struct LogicalChannelConfig));
  struct LogicalChannelConfig__ul_SpecificParameters
    *DRB_ul_SpecificParameters                                         = CALLOC(1, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
  long                               *logicalchannelgroup_drb          = CALLOC(1, sizeof(long));

  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;
  UE->DRB_config[0][0]->rlc_Config = DRB_rlc_config;
421
  UE->DRB_config[0][1]->rlc_Config = DRB_rlc_config;
422 423 424

  DRB_pdcp_config = CALLOC(1, sizeof(*DRB_pdcp_config));
  UE->DRB_config[0][0]->pdcp_Config = DRB_pdcp_config;
425
  UE->DRB_config[0][1]->pdcp_Config = DRB_pdcp_config;
426 427 428 429 430
  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;

431
  // avoid gcc warnings
432 433 434 435 436 437 438
  (void)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;

  UE->DRB_config[0][0]->logicalChannelConfig = DRB_lchan_config;
439
  UE->DRB_config[0][1]->logicalChannelConfig = DRB_lchan_config;
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455
  DRB_ul_SpecificParameters = CALLOC(1, sizeof(*DRB_ul_SpecificParameters));
  DRB_lchan_config->ul_SpecificParameters = DRB_ul_SpecificParameters;

  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;
  DRB_ul_SpecificParameters->bucketSizeDuration =
    LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;

  // LCG for DTCH can take the value from 1 to 3 as defined in 36331: normally controlled by upper layers (like RRM)

  *logicalchannelgroup_drb = 1;
  DRB_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup_drb;

  UE->DRB_configList = CALLOC(1,sizeof(DRB_ToAddModList_t));
  ASN_SEQUENCE_ADD(&UE->DRB_configList->list,UE->DRB_config[0][0]);
456
  ASN_SEQUENCE_ADD(&UE->DRB_configList->list,UE->DRB_config[0][1]);
457 458 459 460 461 462 463 464 465

  rrc_pdcp_config_asn1_req(&ctxt,
			   (SRB_ToAddModList_t *) NULL,
			   UE->DRB_configList,
			   (DRB_ToReleaseList_t*) NULL,
			   0xff, NULL, NULL, NULL
#if defined(Rel10) || defined(Rel14)
                           , (PMCH_InfoList_r9_t *) NULL
#endif
466 467
                           ,NULL);

468 469 470 471 472 473 474 475
  rrc_rlc_config_asn1_req(&ctxt,
			  (SRB_ToAddModList_t*)NULL,
			  UE->DRB_configList,
			  (DRB_ToReleaseList_t*)NULL
#if defined(Rel10) || defined(Rel14)
			  ,(PMCH_InfoList_r9_t *)NULL
#endif
			  );
476
*/
477 478 479 480
}

#endif

Cedric Roux's avatar
Cedric Roux committed
481
#if defined(Rel10) || defined(Rel14)
482
//-----------------------------------------------------------------------------
483
#if 0
484
void init_MCCH_UE(module_id_t ue_mod_idP, uint8_t eNB_index)
485
{
486
  int i;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
487 488 489
  UE_rrc_inst[ue_mod_idP].sizeof_MCCH_MESSAGE[eNB_index] = 0;
  UE_rrc_inst[ue_mod_idP].MCCH_MESSAGE[eNB_index] = (uint8_t *)malloc16(32);
  UE_rrc_inst[ue_mod_idP].mcch_message[eNB_index] = (MBSFNAreaConfiguration_r9_t *)malloc16(sizeof(MBSFNAreaConfiguration_r9_t));
490

491
  for (i=0; i<8; i++) { // MAX MBSFN Area
Lionel Gauthier's avatar
 
Lionel Gauthier committed
492
    UE_rrc_inst[ue_mod_idP].Info[eNB_index].MCCHStatus[i] = 0;
493

494
  }
495 496
}
#endif
497
#endif
498

499
//-----------------------------------------------------------------------------
500
void openair_rrc_ue_init_security( const protocol_ctxt_t* const ctxt_pP )
501 502
{
#if defined(ENABLE_SECURITY)
503 504 505 506
  //    uint8_t *kRRCenc;
  //    uint8_t *kRRCint;
  char ascii_buffer[65];
  uint8_t i;
507

508
  memset(UE_rrc_inst[ctxt_pP->module_id].kenb, ctxt_pP->module_id, 32);
509

510
  for (i = 0; i < 32; i++) {
511
    sprintf(&ascii_buffer[2 * i], "%02X", UE_rrc_inst[ctxt_pP->module_id].kenb[i]);
512
  }
513

514 515 516
  LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT"[OSA] kenb    = %s\n",
        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
        ascii_buffer);
517
#endif
518
}
519

520
//-----------------------------------------------------------------------------
521
char openair_rrc_ue_init( const module_id_t ue_mod_idP, const unsigned char eNB_index )
522
{
523
  protocol_ctxt_t ctxt;
524
  PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_idP, ENB_FLAG_NO, NOT_A_RNTI, 0, 0,eNB_index);
525 526 527
  LOG_I(RRC,
        PROTOCOL_RRC_CTXT_FMT" Init...\n",
        PROTOCOL_RRC_CTXT_ARGS(&ctxt));
Lionel Gauthier's avatar
 
Lionel Gauthier committed
528 529 530
  rrc_set_state (ue_mod_idP, RRC_STATE_INACTIVE);
  rrc_set_sub_state (ue_mod_idP, RRC_SUB_STATE_INACTIVE);

531 532 533 534 535 536 537 538 539 540
  LOG_D(RRC,"[UE %d] INIT State = RRC_IDLE (eNB %d)\n",ctxt.module_id,eNB_index);
  UE_rrc_inst[ctxt.module_id].Info[eNB_index].State=RRC_IDLE;
  UE_rrc_inst[ctxt.module_id].Info[eNB_index].T300_active = 0;
  UE_rrc_inst[ctxt.module_id].Info[eNB_index].T304_active = 0;
  UE_rrc_inst[ctxt.module_id].Info[eNB_index].T310_active = 0;
  UE_rrc_inst[ctxt.module_id].Info[eNB_index].UE_index=0xffff;
  UE_rrc_inst[ctxt.module_id].Srb0[eNB_index].Active=0;
  UE_rrc_inst[ctxt.module_id].Srb1[eNB_index].Active=0;
  UE_rrc_inst[ctxt.module_id].Srb2[eNB_index].Active=0;
  UE_rrc_inst[ctxt.module_id].HandoverInfoUe.measFlag=1;
Cedric Roux's avatar
Cedric Roux committed
541 542
  UE_rrc_inst[ctxt.module_id].ciphering_algorithm = CipheringAlgorithm_r12_eea0;
#if defined(Rel10) || defined(Rel14)
543
  UE_rrc_inst[ctxt.module_id].integrity_algorithm = SecurityAlgorithmConfig__integrityProtAlgorithm_eia0_v920;
544
#else
545
  UE_rrc_inst[ctxt.module_id].integrity_algorithm = SecurityAlgorithmConfig__integrityProtAlgorithm_reserved;
546 547
#endif

548
  openair_rrc_ue_init_security(&ctxt);
549 550 551
  init_SI_UE(&ctxt,eNB_index);
  LOG_D(RRC,PROTOCOL_RRC_CTXT_FMT"  INIT: phy_sync_2_ch_ind\n",
        PROTOCOL_RRC_CTXT_ARGS(&ctxt));
552

553 554 555 556 557 558


#ifndef NO_RRM
  send_msg(&S_rrc,msg_rrc_phy_synch_to_CH_ind(ctxt.module_id,eNB_index,UE_rrc_inst[ctxt.module_id].Mac_id));
#endif

559
#ifndef NO_RRM
560
  send_msg(&S_rrc,msg_rrc_phy_synch_to_CH_ind(ctxt.module_id,eNB_index,UE_rrc_inst[ctxt.module_id].Mac_id));
561 562 563
#endif

#ifdef NO_RRM //init ch SRB0, SRB1 & BDTCH
564
  openair_rrc_on_ue(&ctxt);
565
#endif
566
#ifdef CBA
567
  int j;
568

569
  for(j=0; j<NUM_MAX_CBA_GROUP; j++) {
Lionel Gauthier's avatar
 
Lionel Gauthier committed
570
    UE_rrc_inst[ue_mod_idP].cba_rnti[j] = 0x0000;
571
  }
572

Lionel Gauthier's avatar
 
Lionel Gauthier committed
573
  UE_rrc_inst[ue_mod_idP].num_active_cba_groups = 0;
574 575 576 577 578
#endif

  return 0;
}

579
//-----------------------------------------------------------------------------
580
void rrc_ue_generate_RRCConnectionRequest( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index )
581
{
582
  uint8_t i=0,rv[6];
583

584
  if(UE_rrc_inst[ctxt_pP->module_id].Srb0[eNB_index].Tx_buffer.payload_size ==0) {
585

586 587 588 589 590 591
    // Get RRCConnectionRequest, fill random for now
    // Generate random byte stream for contention resolution
    for (i=0; i<6; i++) {
#ifdef SMBV
      // if SMBV is configured the contention resolution needs to be fix for the connection procedure to succeed
      rv[i]=i;
592
#else
593
      rv[i]=taus()&0xff;
594
#endif
595 596
      LOG_T(RRC,"%x.",rv[i]);
    }
597

598
    LOG_T(RRC,"\n");
599 600 601 602 603
    UE_rrc_inst[ctxt_pP->module_id].Srb0[eNB_index].Tx_buffer.payload_size =
      do_RRCConnectionRequest(
        ctxt_pP->module_id,
        (uint8_t*)UE_rrc_inst[ctxt_pP->module_id].Srb0[eNB_index].Tx_buffer.Payload,
        rv);
604 605

    LOG_I(RRC,"[UE %d] : Frame %d, Logical Channel UL-CCCH (SRB0), Generating RRCConnectionRequest (bytes %d, eNB %d)\n",
606
          ctxt_pP->module_id, ctxt_pP->frame, UE_rrc_inst[ctxt_pP->module_id].Srb0[eNB_index].Tx_buffer.payload_size, eNB_index);
607

608 609
    for (i=0; i<UE_rrc_inst[ctxt_pP->module_id].Srb0[eNB_index].Tx_buffer.payload_size; i++) {
      LOG_T(RRC,"%x.",UE_rrc_inst[ctxt_pP->module_id].Srb0[eNB_index].Tx_buffer.Payload[i]);
610 611 612
    }

    LOG_T(RRC,"\n");
613 614
    /*UE_rrc_inst[ue_mod_idP].Srb0[Idx].Tx_buffer.Payload[i] = taus()&0xff;
    UE_rrc_inst[ue_mod_idP].Srb0[Idx].Tx_buffer.payload_size =i; */
615 616 617 618 619 620 621

  }
}


mui_t rrc_mui=0;

622
#if !(defined(ENABLE_ITTI) && defined(ENABLE_USE_MME))
623
/* NAS Attach request with IMSI */
624
static const char const nas_attach_req_imsi[] = {
625 626 627 628 629 630 631 632 633 634 635
  0x07, 0x41,
  /* EPS Mobile identity = IMSI */
  0x71, 0x08, 0x29, 0x80, 0x43, 0x21, 0x43, 0x65, 0x87,
  0xF9,
  /* End of EPS Mobile Identity */
  0x02, 0xE0, 0xE0, 0x00, 0x20, 0x02, 0x03,
  0xD0, 0x11, 0x27, 0x1A, 0x80, 0x80, 0x21, 0x10, 0x01, 0x00, 0x00,
  0x10, 0x81, 0x06, 0x00, 0x00, 0x00, 0x00, 0x83, 0x06, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x0A, 0x00, 0x52, 0x12, 0xF2,
  0x01, 0x27, 0x11,
};
636
#endif /* !(defined(ENABLE_ITTI) && defined(ENABLE_USE_MME)) */
637

638
#if 0
639
/* NAS Attach request with GUTI */
640
static const char const nas_attach_req_guti[] = {
641 642 643 644 645 646 647 648 649 650 651
  0x07, 0x41,
  /* EPS Mobile identity = GUTI */
  0x71, 0x0B, 0xF6, 0x12, 0xF2, 0x01, 0x80, 0x00, 0x01, 0xE0, 0x00,
  0xDA, 0x1F,
  /* End of EPS Mobile Identity */
  0x02, 0xE0, 0xE0, 0x00, 0x20, 0x02, 0x03,
  0xD0, 0x11, 0x27, 0x1A, 0x80, 0x80, 0x21, 0x10, 0x01, 0x00, 0x00,
  0x10, 0x81, 0x06, 0x00, 0x00, 0x00, 0x00, 0x83, 0x06, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x0A, 0x00, 0x52, 0x12, 0xF2,
  0x01, 0x27, 0x11,
};
652
#endif
653

654
//-----------------------------------------------------------------------------
655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694
void
rrc_t310_expiration(
  const protocol_ctxt_t* const ctxt_pP,
  const uint8_t                 eNB_index
)
//-----------------------------------------------------------------------------
{

  if (UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].State != RRC_CONNECTED) {
    LOG_D(RRC, "Timer 310 expired, going to RRC_IDLE\n");
    UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].State = RRC_IDLE;
    UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].UE_index = 0xffff;
    UE_rrc_inst[ctxt_pP->module_id].Srb0[eNB_index].Rx_buffer.payload_size = 0;
    UE_rrc_inst[ctxt_pP->module_id].Srb0[eNB_index].Tx_buffer.payload_size = 0;
    UE_rrc_inst[ctxt_pP->module_id].Srb1[eNB_index].Srb_info.Rx_buffer.payload_size = 0;
    UE_rrc_inst[ctxt_pP->module_id].Srb1[eNB_index].Srb_info.Tx_buffer.payload_size = 0;

    if (UE_rrc_inst[ctxt_pP->module_id].Srb2[eNB_index].Active == 1) {
      LOG_D (RRC,"[Inst %d] eNB_index %d, Remove RB %d\n ", ctxt_pP->module_id, eNB_index,
           UE_rrc_inst[ctxt_pP->module_id].Srb2[eNB_index].Srb_info.Srb_id);
      rrc_pdcp_config_req (ctxt_pP,
                           SRB_FLAG_YES,
                           CONFIG_ACTION_REMOVE,
                           UE_rrc_inst[ctxt_pP->module_id].Srb2[eNB_index].Srb_info.Srb_id,
                           0);
      rrc_rlc_config_req (ctxt_pP,
                          SRB_FLAG_YES,
                          MBMS_FLAG_NO,
                          CONFIG_ACTION_REMOVE,
                          UE_rrc_inst[ctxt_pP->module_id].Srb2[eNB_index].Srb_info.Srb_id,
                          Rlc_info_um);
      UE_rrc_inst[ctxt_pP->module_id].Srb2[eNB_index].Active = 0;
      UE_rrc_inst[ctxt_pP->module_id].Srb2[eNB_index].Status = IDLE;
      UE_rrc_inst[ctxt_pP->module_id].Srb2[eNB_index].Next_check_frame = 0;
    }
  } else { // Restablishment procedure
    LOG_D(RRC, "Timer 310 expired, trying RRCRestablishment ...\n");
  }
}

695
//-----------------------------------------------------------------------------
696
static void rrc_ue_generate_RRCConnectionSetupComplete( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index, const uint8_t Transaction_id )
697
{
698

699 700
  uint8_t    buffer[100];
  uint8_t    size;
701
  const char * nas_msg;
winckel's avatar
winckel committed
702
  int   nas_msg_length;
703

winckel's avatar
winckel committed
704
#if defined(ENABLE_ITTI) && defined(ENABLE_USE_MME)
705 706
  nas_msg         = (char*) UE_rrc_inst[ctxt_pP->module_id].initialNasMsg.data;
  nas_msg_length  = UE_rrc_inst[ctxt_pP->module_id].initialNasMsg.length;
winckel's avatar
winckel committed
707 708 709 710 711
#else
  nas_msg         = nas_attach_req_imsi;
  nas_msg_length  = sizeof(nas_attach_req_imsi);
#endif

712
  size = do_RRCConnectionSetupComplete(ctxt_pP->module_id, buffer, Transaction_id, nas_msg_length, nas_msg);
713 714

  LOG_I(RRC,"[UE %d][RAPROC] Frame %d : Logical Channel UL-DCCH (SRB1), Generating RRCConnectionSetupComplete (bytes%d, eNB %d)\n",
715 716
        ctxt_pP->module_id,ctxt_pP->frame, size, eNB_index);
  LOG_D(RLC,
Lionel Gauthier's avatar
Lionel Gauthier committed
717
        "[FRAME %05d][RRC_UE][MOD %02d][][--- PDCP_DATA_REQ/%d Bytes (RRCConnectionSetupComplete to eNB %d MUI %d) --->][PDCP][MOD %02d][RB %02d]\n",
718
        ctxt_pP->frame, ctxt_pP->module_id+NB_eNB_INST, size, eNB_index, rrc_mui, ctxt_pP->module_id+NB_eNB_INST, DCCH);
719
  rrc_data_req_ue (
720 721 722 723 724 725 726
		ctxt_pP,
		DCCH,
		rrc_mui++,
		SDU_CONFIRM_NO,
		size,
		buffer,
		PDCP_TRANSMISSION_MODE_CONTROL);
727 728
}

729
//-----------------------------------------------------------------------------
730
void rrc_ue_generate_RRCConnectionReconfigurationComplete( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index, const uint8_t Transaction_id )
731
{
732

733
  uint8_t buffer[32], size;
734 735 736 737
  size = do_RRCConnectionReconfigurationComplete(ctxt_pP, buffer, Transaction_id);
  LOG_I(RRC,PROTOCOL_RRC_CTXT_UE_FMT" Logical Channel UL-DCCH (SRB1), Generating RRCConnectionReconfigurationComplete (bytes %d, eNB_index %d)\n",
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP), size, eNB_index);
  LOG_D(RLC,
Lionel Gauthier's avatar
Lionel Gauthier committed
738
        "[FRAME %05d][RRC_UE][INST %02d][][--- PDCP_DATA_REQ/%d Bytes (RRCConnectionReconfigurationComplete to eNB %d MUI %d) --->][PDCP][INST %02d][RB %02d]\n",
739 740 741 742 743 744 745
        ctxt_pP->frame,
        UE_MODULE_ID_TO_INSTANCE(ctxt_pP->module_id),
        size,
        eNB_index,
        rrc_mui,
        UE_MODULE_ID_TO_INSTANCE(ctxt_pP->module_id),
        DCCH);
746
  rrc_data_req_ue (
747 748 749 750 751 752 753
		ctxt_pP,
		DCCH,
		rrc_mui++,
		SDU_CONFIRM_NO,
		size,
		buffer,
		PDCP_TRANSMISSION_MODE_CONTROL);
754 755 756
}


757 758
//-----------------------------------------------------------------------------
// Called by L2 interface (MAC)
759
int rrc_ue_decode_ccch( const protocol_ctxt_t* const ctxt_pP, const SRB_INFO* const Srb_info, const uint8_t eNB_index )
760 761
{
  DL_CCCH_Message_t* dl_ccch_msg=NULL;
762
  asn_dec_rval_t dec_rval;
763
  int rval=0;
764

765
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_CCCH, VCD_FUNCTION_IN);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
766 767
  //  LOG_D(RRC,"[UE %d] Decoding DL-CCCH message (%d bytes), State %d\n",ue_mod_idP,Srb_info->Rx_buffer.payload_size,
  //  UE_rrc_inst[ue_mod_idP].Info[eNB_index].State);
768 769

  dec_rval = uper_decode(NULL,
770 771 772 773
                         &asn_DEF_DL_CCCH_Message,
                         (void**)&dl_ccch_msg,
                         (uint8_t*)Srb_info->Rx_buffer.Payload,
                         100,0,0);
774 775 776 777 778

#ifdef XER_PRINT
  xer_fprint(stdout,&asn_DEF_DL_CCCH_Message,(void*)dl_ccch_msg);
#endif

779
#if defined(ENABLE_ITTI)
780
# if defined(DISABLE_ITTI_XER_PRINT)
781
  {
winckel's avatar
winckel committed
782
    MessageDef *msg_p;
783

winckel's avatar
winckel committed
784 785
    msg_p = itti_alloc_new_message (TASK_RRC_UE, RRC_DL_CCCH_MESSAGE);
    memcpy (&msg_p->ittiMsg, (void *) dl_ccch_msg, sizeof(RrcDlCcchMessage));
786

787
    itti_send_msg_to_task (TASK_UNKNOWN, ctxt_pP->instance, msg_p);
788
  }
789 790
# else
  {
791 792
    char        message_string[10000];
    size_t      message_string_size;
793

794
    //LOG_I(RRC, "Panos-D: rrc_ue_decode_ccch, Before xer_sprint() \n");
795 796
    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_DL_CCCH_Message, (void *)dl_ccch_msg)) > 0) {
      MessageDef *msg_p;
797

798 799 800
      msg_p = itti_alloc_new_message_sized (TASK_RRC_UE, RRC_DL_CCCH, message_string_size + sizeof (IttiMsgText));
      msg_p->ittiMsg.rrc_dl_ccch.size = message_string_size;
      memcpy(&msg_p->ittiMsg.rrc_dl_ccch.text, message_string, message_string_size);
801

802
      itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
803
    }
804 805
  }
# endif
806 807
#endif

808
  if ((dec_rval.code != RC_OK) && (dec_rval.consumed==0)) {
Cedric Roux's avatar
Cedric Roux committed
809
    LOG_E(RRC,"[UE %d] Frame %d : Failed to decode DL-CCCH-Message (%zu bytes)\n",ctxt_pP->module_id,ctxt_pP->frame,dec_rval.consumed);
810
    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_CCCH, VCD_FUNCTION_OUT);
811
    return -1;
812 813 814 815
  }

  if (dl_ccch_msg->message.present == DL_CCCH_MessageType_PR_c1) {

816
    if (UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].State == RRC_SI_RECEIVED) {
817

818
      switch (dl_ccch_msg->message.choice.c1.present) {
819

820
      case DL_CCCH_MessageType__c1_PR_NOTHING:
821 822 823
        LOG_I(RRC, "[UE%d] Frame %d : Received PR_NOTHING on DL-CCCH-Message\n",
              ctxt_pP->module_id,
              ctxt_pP->frame);
824 825
        rval = 0;
        break;
826

827 828
      case DL_CCCH_MessageType__c1_PR_rrcConnectionReestablishment:
        LOG_I(RRC,
829 830 831
              "[UE%d] Frame %d : Logical Channel DL-CCCH (SRB0), Received RRCConnectionReestablishment\n",
              ctxt_pP->module_id,
              ctxt_pP->frame);
832 833
        rval = 0;
        break;
834

835 836
      case DL_CCCH_MessageType__c1_PR_rrcConnectionReestablishmentReject:
        LOG_I(RRC,
837 838 839
              "[UE%d] Frame %d : Logical Channel DL-CCCH (SRB0), Received RRCConnectionReestablishmentReject\n",
              ctxt_pP->module_id,
              ctxt_pP->frame);
840 841
        rval = 0;
        break;
842

843 844
      case DL_CCCH_MessageType__c1_PR_rrcConnectionReject:
        LOG_I(RRC,
845 846 847
              "[UE%d] Frame %d : Logical Channel DL-CCCH (SRB0), Received RRCConnectionReject \n",
              ctxt_pP->module_id,
              ctxt_pP->frame);
848 849
        rval = 0;
        break;
850

851 852
      case DL_CCCH_MessageType__c1_PR_rrcConnectionSetup:
        LOG_I(RRC,
853 854 855 856
              "[UE%d][RAPROC] Frame %d : Logical Channel DL-CCCH (SRB0), Received RRCConnectionSetup RNTI %x\n",
              ctxt_pP->module_id,
              ctxt_pP->frame,
              ctxt_pP->rnti);
857
        // Get configuration
858

859
        // Release T300 timer
860 861 862 863
        UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].T300_active = 0;
        rrc_ue_process_radioResourceConfigDedicated(
          ctxt_pP,
          eNB_index,
864
          &dl_ccch_msg->message.choice.c1.choice.rrcConnectionSetup.criticalExtensions.choice.c1.choice.rrcConnectionSetup_r8.radioResourceConfigDedicated);
865

866 867 868 869 870 871 872
        rrc_set_state (ctxt_pP->module_id, RRC_STATE_CONNECTED);
        rrc_set_sub_state (ctxt_pP->module_id, RRC_SUB_STATE_CONNECTED);
        UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].rnti = ctxt_pP->rnti;
        rrc_ue_generate_RRCConnectionSetupComplete(
          ctxt_pP,
          eNB_index,
          dl_ccch_msg->message.choice.c1.choice.rrcConnectionSetup.rrc_TransactionIdentifier);
873

874 875
        rval = 0;
        break;
876

877
      default:
878 879 880
        LOG_E(RRC, "[UE%d] Frame %d : Unknown message\n",
              ctxt_pP->module_id,
              ctxt_pP->frame);
881 882
        rval = -1;
        break;
883
      }
884
    }
885 886
  }

887
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_CCCH, VCD_FUNCTION_OUT);
888 889 890
  return rval;
}

891 892 893 894 895 896 897 898 899
//-----------------------------------------------------------------------------
int32_t
rrc_ue_establish_srb1(
  module_id_t ue_mod_idP,
  frame_t frameP,
  uint8_t eNB_index,
  struct SRB_ToAddMod* SRB_config
)
//-----------------------------------------------------------------------------
900
{
901
  // add descriptor from RRC PDU
902

903
  uint8_t lchan_id = DCCH;
904

Lionel Gauthier's avatar
 
Lionel Gauthier committed
905 906 907
  UE_rrc_inst[ue_mod_idP].Srb1[eNB_index].Active = 1;
  UE_rrc_inst[ue_mod_idP].Srb1[eNB_index].Status = RADIO_CONFIG_OK;//RADIO CFG
  UE_rrc_inst[ue_mod_idP].Srb1[eNB_index].Srb_info.Srb_id = 1;
908

909
  // copy default configuration for now
Lionel Gauthier's avatar
 
Lionel Gauthier committed
910 911
  //  memcpy(&UE_rrc_inst[ue_mod_idP].Srb1[eNB_index].Srb_info.Lchan_desc[0],&DCCH_LCHAN_DESC,LCHAN_DESC_SIZE);
  //  memcpy(&UE_rrc_inst[ue_mod_idP].Srb1[eNB_index].Srb_info.Lchan_desc[1],&DCCH_LCHAN_DESC,LCHAN_DESC_SIZE);
912 913


Lionel Gauthier's avatar
 
Lionel Gauthier committed
914
  LOG_I(RRC,"[UE %d], CONFIG_SRB1 %d corresponding to eNB_index %d\n", ue_mod_idP,lchan_id,eNB_index);
915

Lionel Gauthier's avatar
 
Lionel Gauthier committed
916 917
  //rrc_pdcp_config_req (ue_mod_idP+NB_eNB_INST, frameP, 0, CONFIG_ACTION_ADD, lchan_id,UNDEF_SECURITY_MODE);
  //  rrc_rlc_config_req(ue_mod_idP+NB_eNB_INST,frameP,0,CONFIG_ACTION_ADD,lchan_id,SIGNALLING_RADIO_BEARER,Rlc_info_am_config);
918

Lionel Gauthier's avatar
 
Lionel Gauthier committed
919
  //  UE_rrc_inst[ue_mod_idP].Srb1[eNB_index].Srb_info.Tx_buffer.payload_size=DEFAULT_MEAS_IND_SIZE+1;
920 921 922 923 924


  return(0);
}

925 926 927 928 929 930 931 932 933
//-----------------------------------------------------------------------------
int32_t
rrc_ue_establish_srb2(
  module_id_t ue_mod_idP,
  frame_t frameP,
  uint8_t eNB_index,
  struct SRB_ToAddMod* SRB_config
)
//-----------------------------------------------------------------------------
934
{
935
  // add descriptor from RRC PDU
936

937
  uint8_t lchan_id = DCCH1;
938

Lionel Gauthier's avatar
 
Lionel Gauthier committed
939 940 941
  UE_rrc_inst[ue_mod_idP].Srb2[eNB_index].Active = 1;
  UE_rrc_inst[ue_mod_idP].Srb2[eNB_index].Status = RADIO_CONFIG_OK;//RADIO CFG
  UE_rrc_inst[ue_mod_idP].Srb2[eNB_index].Srb_info.Srb_id = 2;
942

943
  // copy default configuration for now
Lionel Gauthier's avatar
 
Lionel Gauthier committed
944 945
  //  memcpy(&UE_rrc_inst[ue_mod_idP].Srb2[eNB_index].Srb_info.Lchan_desc[0],&DCCH_LCHAN_DESC,LCHAN_DESC_SIZE);
  //  memcpy(&UE_rrc_inst[ue_mod_idP].Srb2[eNB_index].Srb_info.Lchan_desc[1],&DCCH_LCHAN_DESC,LCHAN_DESC_SIZE);
946 947


Lionel Gauthier's avatar
 
Lionel Gauthier committed
948
  LOG_I(RRC,"[UE %d], CONFIG_SRB2 %d corresponding to eNB_index %d\n",ue_mod_idP,lchan_id,eNB_index);
949

Lionel Gauthier's avatar
 
Lionel Gauthier committed
950 951
  //rrc_pdcp_config_req (ue_mod_idP+NB_eNB_INST, frameP, 0, CONFIG_ACTION_ADD, lchan_id, UNDEF_SECURITY_MODE);
  //  rrc_rlc_config_req(ue_mod_idP+NB_eNB_INST,frameP,0,CONFIG_ACTION_ADD,lchan_id,SIGNALLING_RADIO_BEARER,Rlc_info_am_config);
952

Lionel Gauthier's avatar
 
Lionel Gauthier committed
953
  //  UE_rrc_inst[ue_mod_idP].Srb1[eNB_index].Srb_info.Tx_buffer.payload_size=DEFAULT_MEAS_IND_SIZE+1;
954 955 956 957 958


  return(0);
}

959 960 961 962 963 964 965 966 967
//-----------------------------------------------------------------------------
int32_t
rrc_ue_establish_drb(
  module_id_t ue_mod_idP,
  frame_t frameP,
  uint8_t eNB_index,
  struct DRB_ToAddMod* DRB_config
)
//-----------------------------------------------------------------------------
968
{
969 970
  // add descriptor from RRC PDU
#ifdef PDCP_USE_NETLINK
971
  int oip_ifup=0,ip_addr_offset3=0,ip_addr_offset4=0;
Cedric Roux's avatar
Cedric Roux committed
972 973 974 975
  /* avoid gcc warnings */
  (void)oip_ifup;
  (void)ip_addr_offset3;
  (void)ip_addr_offset4;
976
#endif
977

978
  LOG_I(RRC,"[UE %d] Frame %d: processing RRCConnectionReconfiguration: reconfiguring DRB %ld/LCID %d\n",
979
        ue_mod_idP, frameP, DRB_config->drb_Identity, (int)*DRB_config->logicalChannelIdentity);
980
  /*
Lionel Gauthier's avatar
 
Lionel Gauthier committed
981
  rrc_pdcp_config_req (ue_mod_idP+NB_eNB_INST, frameP, 0, CONFIG_ACTION_ADD,
982
                             (eNB_index * NB_RB_MAX) + *DRB_config->logicalChannelIdentity, UNDEF_SECURITY_MODE);
983

984
  rrc_rlc_config_req(ue_mod_idP+NB_eNB_INST,frameP,0,CONFIG_ACTION_ADD,
985 986
                    (eNB_index * NB_RB_MAX) + *DRB_config->logicalChannelIdentity,
                    RADIO_ACCESS_BEARER,Rlc_info_um);
987
   */
988
#ifdef PDCP_USE_NETLINK
989
#   if !defined(OAI_NW_DRIVER_TYPE_ETHERNET) && !defined(EXMIMO) && !defined(OAI_USRP) && !defined(OAI_BLADERF) && !defined(ETHERNET) && !defined(LINK_ENB_PDCP_TO_GTPV1U)
990
  ip_addr_offset3 = 0;
991
  ip_addr_offset4 = 1;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
992
  LOG_I(OIP,"[UE %d] trying to bring up the OAI interface oai%d, IP 10.0.%d.%d\n", ue_mod_idP, ip_addr_offset3+ue_mod_idP,
993
        ip_addr_offset3+ue_mod_idP+1,ip_addr_offset4+ue_mod_idP+1);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
994
  oip_ifup=nas_config(ip_addr_offset3+ue_mod_idP,   // interface_id
995 996 997 998
                      ip_addr_offset3+ue_mod_idP+1, // third_octet
                      ip_addr_offset4+ue_mod_idP+1); // fourth_octet

  if (oip_ifup == 0 ) { // interface is up --> send a config the DRB
999
    LOG_I(OIP,"[UE %d] Config the oai%d to send/receive pkt on DRB %ld to/from the protocol stack\n",
Lionel Gauthier's avatar
 
Lionel Gauthier committed
1000 1001
          ue_mod_idP,
          ip_addr_offset3+ue_mod_idP,
1002
          (long int)((eNB_index * maxDRB) + DRB_config->drb_Identity));
1003

1004 1005 1006 1007 1008 1009 1010 1011
    rb_conf_ipv4(0,//add
                 ue_mod_idP,//cx align with the UE index
                 ip_addr_offset3+ue_mod_idP,//inst num_enb+ue_index
                 (eNB_index * maxDRB) + DRB_config->drb_Identity,//rb
                 0,//dscp
                 ipv4_address(ip_addr_offset3+ue_mod_idP+1,ip_addr_offset4+ue_mod_idP+1),//saddr
                 ipv4_address(ip_addr_offset3+ue_mod_idP+1,eNB_index+1));//daddr
    LOG_D(RRC,"[UE %d] State = Attached (eNB %d)\n",ue_mod_idP,eNB_index);
1012
  }
1013

1014 1015 1016 1017 1018 1019 1020
#    endif
#endif

  return(0);
}


1021 1022 1023 1024 1025 1026 1027 1028
//-----------------------------------------------------------------------------
void
rrc_ue_process_measConfig(
  const protocol_ctxt_t* const       ctxt_pP,
  const uint8_t                      eNB_index,
  MeasConfig_t* const               measConfig
)
//-----------------------------------------------------------------------------
1029
{
1030 1031 1032 1033 1034 1035 1036

  // This is the procedure described in 36.331 Section 5.5.2.1
  int i;
  long ind;
  MeasObjectToAddMod_t *measObj;

  if (measConfig->measObjectToRemoveList != NULL) {
1037 1038
    for (i=0; i<measConfig->measObjectToRemoveList->list.count; i++) {
      ind   = *measConfig->measObjectToRemoveList->list.array[i];
1039
      free(UE_rrc_inst[ctxt_pP->module_id].MeasObj[eNB_index][ind-1]);
1040
    }
1041
  }
1042

1043
  if (measConfig->measObjectToAddModList != NULL) {
1044 1045 1046 1047 1048 1049
    LOG_D(RRC,"Measurement Object List is present\n");

    for (i=0; i<measConfig->measObjectToAddModList->list.count; i++) {
      measObj = measConfig->measObjectToAddModList->list.array[i];
      ind   = measConfig->measObjectToAddModList->list.array[i]->measObjectId;

1050
      if (UE_rrc_inst[ctxt_pP->module_id].MeasObj[eNB_index][ind-1]) {
Cedric Roux's avatar
Cedric Roux committed
1051
        LOG_D(RRC,"Modifying measurement object %ld\n",ind);
1052
        memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].MeasObj[eNB_index][ind-1],
1053 1054 1055
               (char*)measObj,
               sizeof(MeasObjectToAddMod_t));
      } else {
Cedric Roux's avatar
Cedric Roux committed
1056
        LOG_I(RRC,"Adding measurement object %ld\n",ind);
1057 1058

        if (measObj->measObject.present == MeasObjectToAddMod__measObject_PR_measObjectEUTRA) {
Cedric Roux's avatar
Cedric Roux committed
1059
          LOG_I(RRC,"EUTRA Measurement : carrierFreq %ld, allowedMeasBandwidth %ld,presenceAntennaPort1 %d, neighCellConfig %d\n",
1060 1061 1062 1063
                measObj->measObject.choice.measObjectEUTRA.carrierFreq,
                measObj->measObject.choice.measObjectEUTRA.allowedMeasBandwidth,
                measObj->measObject.choice.measObjectEUTRA.presenceAntennaPort1,
                measObj->measObject.choice.measObjectEUTRA.neighCellConfig.buf[0]);
1064
          UE_rrc_inst[ctxt_pP->module_id].MeasObj[eNB_index][ind-1]=measObj;
1065
        }
1066
      }
1067 1068
    }

1069
    LOG_I(RRC,"call rrc_mac_config_req \n");
1070

1071 1072 1073
    rrc_mac_config_req_ue(ctxt_pP->module_id,0,eNB_index,
			  (RadioResourceConfigCommonSIB_t *)NULL,
			  (struct PhysicalConfigDedicated *)NULL,
Cedric Roux's avatar
Cedric Roux committed
1074
#if defined(Rel10) || defined(Rel14)
1075 1076
			  (SCellToAddMod_r10_t *)NULL,
			  //struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
1077
#endif
1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090
			  UE_rrc_inst[ctxt_pP->module_id].MeasObj[eNB_index],
			  (MAC_MainConfig_t *)NULL,
			  0,
			  (struct LogicalChannelConfig *)NULL,
			  (MeasGapConfig_t *)NULL,
			  (TDD_Config_t *)NULL,
			  (MobilityControlInfo_t *)NULL,
			  NULL,
			  NULL,
			  NULL,
			  NULL,
			  NULL,
			  NULL
Cedric Roux's avatar
Cedric Roux committed
1091
#if defined(Rel10) || defined(Rel14)
1092
			  ,0,
1093 1094
			  (MBSFN_AreaInfoList_r9_t *)NULL,
			  (PMCH_InfoList_r9_t *)NULL
1095

1096 1097
#endif
#ifdef CBA
1098 1099 1100
			  ,
			  0,
			  0
1101 1102 1103
#endif
#if defined(Rel14)
           ,
1104
           0,
1105
           NULL,
1106
           NULL,
1107
           NULL
1108
#endif
1109
			  );
1110
  }
1111

1112
  if (measConfig->reportConfigToRemoveList != NULL) {
1113 1114
    for (i=0; i<measConfig->reportConfigToRemoveList->list.count; i++) {
      ind   = *measConfig->reportConfigToRemoveList->list.array[i];
1115
      free(UE_rrc_inst[ctxt_pP->module_id].ReportConfig[eNB_index][ind-1]);
1116
    }
1117
  }
1118

1119
  if (measConfig->reportConfigToAddModList != NULL) {
1120 1121 1122 1123 1124
    LOG_I(RRC,"Report Configuration List is present\n");

    for (i=0; i<measConfig->reportConfigToAddModList->list.count; i++) {
      ind   = measConfig->reportConfigToAddModList->list.array[i]->reportConfigId;

1125
      if (UE_rrc_inst[ctxt_pP->module_id].ReportConfig[eNB_index][ind-1]) {
Cedric Roux's avatar
Cedric Roux committed
1126
        LOG_I(RRC,"Modifying Report Configuration %ld\n",ind-1);
1127
        memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].ReportConfig[eNB_index][ind-1],
1128 1129 1130
               (char*)measConfig->reportConfigToAddModList->list.array[i],
               sizeof(ReportConfigToAddMod_t));
      } else {
Cedric Roux's avatar
Cedric Roux committed
1131
        LOG_D(RRC,"Adding Report Configuration %ld %p \n",ind-1,measConfig->reportConfigToAddModList->list.array[i]);
1132
        UE_rrc_inst[ctxt_pP->module_id].ReportConfig[eNB_index][ind-1] = measConfig->reportConfigToAddModList->list.array[i];
1133
      }
1134
    }
1135 1136 1137
  }

  if (measConfig->quantityConfig != NULL) {
1138
    if (UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index]) {
1139
      LOG_D(RRC,"Modifying Quantity Configuration \n");
1140
      memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index],
1141 1142 1143 1144
             (char*)measConfig->quantityConfig,
             sizeof(QuantityConfig_t));
    } else {
      LOG_D(RRC,"Adding Quantity configuration\n");
1145
      UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index] = measConfig->quantityConfig;
1146
    }
1147 1148 1149
  }

  if (measConfig->measIdToRemoveList != NULL) {
1150 1151
    for (i=0; i<measConfig->measIdToRemoveList->list.count; i++) {
      ind   = *measConfig->measIdToRemoveList->list.array[i];
1152
      free(UE_rrc_inst[ctxt_pP->module_id].MeasId[eNB_index][ind-1]);
1153
    }
1154 1155 1156
  }

  if (measConfig->measIdToAddModList != NULL) {
1157 1158 1159
    for (i=0; i<measConfig->measIdToAddModList->list.count; i++) {
      ind   = measConfig->measIdToAddModList->list.array[i]->measId;

1160
      if (UE_rrc_inst[ctxt_pP->module_id].MeasId[eNB_index][ind-1]) {
Cedric Roux's avatar
Cedric Roux committed
1161
        LOG_D(RRC,"Modifying Measurement ID %ld\n",ind-1);
1162
        memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].MeasId[eNB_index][ind-1],
1163 1164 1165
               (char*)measConfig->measIdToAddModList->list.array[i],
               sizeof(MeasIdToAddMod_t));
      } else {
Cedric Roux's avatar
Cedric Roux committed
1166
        LOG_D(RRC,"Adding Measurement ID %ld %p\n",ind-1,measConfig->measIdToAddModList->list.array[i]);
1167
        UE_rrc_inst[ctxt_pP->module_id].MeasId[eNB_index][ind-1] = measConfig->measIdToAddModList->list.array[i];
1168
      }
1169
    }
1170 1171 1172
  }

  if (measConfig->measGapConfig !=NULL) {
1173 1174
    if (UE_rrc_inst[ctxt_pP->module_id].measGapConfig[eNB_index]) {
      memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].measGapConfig[eNB_index],
1175 1176 1177
             (char*)measConfig->measGapConfig,
             sizeof(MeasGapConfig_t));
    } else {
1178
      UE_rrc_inst[ctxt_pP->module_id].measGapConfig[eNB_index] = measConfig->measGapConfig;
1179
    }
1180 1181
  }

1182
  if (measConfig->quantityConfig != NULL) {
1183
    if (UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index]) {
1184
      LOG_I(RRC,"Modifying Quantity Configuration \n");
1185
      memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index],
1186 1187 1188 1189
             (char*)measConfig->quantityConfig,
             sizeof(QuantityConfig_t));
    } else {
      LOG_I(RRC,"Adding Quantity configuration\n");
1190
      UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index] = measConfig->quantityConfig;
1191
    }
1192

1193 1194 1195 1196
    UE_rrc_inst[ctxt_pP->module_id].filter_coeff_rsrp = 1./pow(2,
        (*UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index]->quantityConfigEUTRA->filterCoefficientRSRP)/4);
    UE_rrc_inst[ctxt_pP->module_id].filter_coeff_rsrq = 1./pow(2,
        (*UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index]->quantityConfigEUTRA->filterCoefficientRSRQ)/4);
1197

Cedric Roux's avatar
Cedric Roux committed
1198
    LOG_I(RRC,"[UE %d] set rsrp-coeff for eNB %d: %ld rsrq-coeff: %ld rsrp_factor: %f rsrq_factor: %f \n",
1199 1200 1201 1202 1203
          ctxt_pP->module_id, eNB_index, // UE_rrc_inst[ue_mod_idP].Info[eNB_index].UE_index,
          *UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index]->quantityConfigEUTRA->filterCoefficientRSRP,
          *UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[eNB_index]->quantityConfigEUTRA->filterCoefficientRSRQ,
          UE_rrc_inst[ctxt_pP->module_id].filter_coeff_rsrp,
          UE_rrc_inst[ctxt_pP->module_id].filter_coeff_rsrq);
1204 1205
  }

1206
  if (measConfig->s_Measure != NULL) {
1207
    UE_rrc_inst[ctxt_pP->module_id].s_measure = *measConfig->s_Measure;
1208
  }
1209

1210
  if (measConfig->speedStatePars != NULL) {
1211 1212 1213 1214 1215
    if (UE_rrc_inst[ctxt_pP->module_id].speedStatePars) {
      memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].speedStatePars,(char*)measConfig->speedStatePars,sizeof(struct MeasConfig__speedStatePars));
    } else {
      UE_rrc_inst[ctxt_pP->module_id].speedStatePars = measConfig->speedStatePars;
    }
1216 1217

    LOG_I(RRC,"[UE %d] Configuring mobility optimization params for UE %d \n",
1218
          ctxt_pP->module_id,UE_rrc_inst[ctxt_pP->module_id].Info[0].UE_index);
1219
  }
1220 1221
}

1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234

void
rrc_ue_update_radioResourceConfigDedicated(RadioResourceConfigDedicated_t* radioResourceConfigDedicated,
        const protocol_ctxt_t* const ctxt_pP,
        uint8_t eNB_index)
{
    PhysicalConfigDedicated_t* physicalConfigDedicated2 = NULL;

    physicalConfigDedicated2 = CALLOC(1,sizeof(*physicalConfigDedicated2));
    physicalConfigDedicated2->pdsch_ConfigDedicated         = CALLOC(1,sizeof(*physicalConfigDedicated2->pdsch_ConfigDedicated));
    physicalConfigDedicated2->pusch_ConfigDedicated         = CALLOC(1,sizeof(*physicalConfigDedicated2->pusch_ConfigDedicated));
    physicalConfigDedicated2->pucch_ConfigDedicated         = CALLOC(1,sizeof(*physicalConfigDedicated2->pucch_ConfigDedicated));
    physicalConfigDedicated2->cqi_ReportConfig              = CALLOC(1,sizeof(*physicalConfigDedicated2->cqi_ReportConfig));
1235 1236
    physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic
                                                            = CALLOC(1,sizeof(*physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic));
1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297
    physicalConfigDedicated2->soundingRS_UL_ConfigDedicated = CALLOC(1,sizeof(*physicalConfigDedicated2->soundingRS_UL_ConfigDedicated));
    physicalConfigDedicated2->schedulingRequestConfig       = CALLOC(1,sizeof(*physicalConfigDedicated2->schedulingRequestConfig));
    physicalConfigDedicated2->antennaInfo                   = CALLOC(1,sizeof(*physicalConfigDedicated2->antennaInfo));

    physicalConfigDedicated2->uplinkPowerControlDedicated   = CALLOC(1,sizeof(*physicalConfigDedicated2->uplinkPowerControlDedicated));
    physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH         = CALLOC(1,sizeof(*physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH));
    physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH         = CALLOC(1,sizeof(*physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH));

    // Update pdsch_ConfigDedicated
    if(radioResourceConfigDedicated->physicalConfigDedicated->pdsch_ConfigDedicated != NULL)
    {
        LOG_I(RRC,"Update pdsch_ConfigDedicated config \n");

        if(UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->pdsch_ConfigDedicated == NULL)
            UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->pdsch_ConfigDedicated = CALLOC(1,sizeof(PDSCH_ConfigDedicated_t));

        memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->pdsch_ConfigDedicated,
                (char*)radioResourceConfigDedicated->physicalConfigDedicated->pdsch_ConfigDedicated,
                sizeof(physicalConfigDedicated2->pdsch_ConfigDedicated));
    }
    else
    {
        LOG_I(RRC,"Keep old config for pdsch_ConfigDedicated\n");
    }

    // Update pusch_ConfigDedicated
    if(radioResourceConfigDedicated->physicalConfigDedicated->pusch_ConfigDedicated != NULL)
    {
        LOG_I(RRC,"Update pusch_ConfigDedicated config \n");

        if(UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->pusch_ConfigDedicated == NULL)
            UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->pusch_ConfigDedicated = CALLOC(1,sizeof(PUSCH_ConfigDedicated_t));

        memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->pusch_ConfigDedicated,
                (char*)radioResourceConfigDedicated->physicalConfigDedicated->pusch_ConfigDedicated,
                sizeof(physicalConfigDedicated2->pusch_ConfigDedicated));
    }
    else
    {
        LOG_I(RRC,"Keep old config for pusch_ConfigDedicated\n");
    }

    // Update pucch_ConfigDedicated
    if(radioResourceConfigDedicated->physicalConfigDedicated->pucch_ConfigDedicated != NULL)
    {
        LOG_I(RRC,"Update pucch_ConfigDedicated config \n");
        if(UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->pucch_ConfigDedicated == NULL)
            UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->pucch_ConfigDedicated = CALLOC(1,sizeof(PUCCH_ConfigDedicated_t));

        memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->pucch_ConfigDedicated,
                (char*)radioResourceConfigDedicated->physicalConfigDedicated->pucch_ConfigDedicated,
                sizeof(physicalConfigDedicated2->pucch_ConfigDedicated));
    }
    else
    {
        LOG_I(RRC,"Keep old config for pucch_ConfigDedicated\n");
    }

    // Update cqi_ReportConfig
    if(radioResourceConfigDedicated->physicalConfigDedicated->cqi_ReportConfig != NULL)
    {
Cedric Roux's avatar
Cedric Roux committed
1298
        LOG_I(RRC,"Update cqi_ReportConfig config (size=%zu,%zu)\n", sizeof(*physicalConfigDedicated2->cqi_ReportConfig), sizeof(CQI_ReportConfig_t));
1299 1300 1301 1302 1303 1304

        if(UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->cqi_ReportConfig == NULL)
            UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->cqi_ReportConfig = CALLOC(1,sizeof(CQI_ReportConfig_t));

        memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->cqi_ReportConfig,
                (char*)radioResourceConfigDedicated->physicalConfigDedicated->cqi_ReportConfig,
1305 1306 1307
                sizeof(*physicalConfigDedicated2->cqi_ReportConfig));

        if (radioResourceConfigDedicated->physicalConfigDedicated->cqi_ReportConfig->cqi_ReportPeriodic != NULL) {
Cedric Roux's avatar
Cedric Roux committed
1308
          LOG_I(RRC,"Update cqi_ReportPeriodic config (size=%zu,%zu)\n", sizeof(*physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic), sizeof(CQI_ReportPeriodic_t));
1309 1310 1311 1312 1313 1314 1315 1316

          if(UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->cqi_ReportConfig->cqi_ReportPeriodic == NULL)
            UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->cqi_ReportConfig->cqi_ReportPeriodic = CALLOC(1,sizeof(CQI_ReportPeriodic_t));

          memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->cqi_ReportConfig->cqi_ReportPeriodic,
                  (char*)radioResourceConfigDedicated->physicalConfigDedicated->cqi_ReportConfig->cqi_ReportPeriodic,
                  sizeof(*physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic));
        }
1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367
    }
    else
    {
        LOG_I(RRC,"Keep old config for cqi_ReportConfig\n");
    }

    // Update schedulingRequestConfig
    if(radioResourceConfigDedicated->physicalConfigDedicated->schedulingRequestConfig != NULL)
    {
        LOG_I(RRC,"Update schedulingRequestConfig config \n");

        if(UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->schedulingRequestConfig == NULL)
            UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->schedulingRequestConfig = CALLOC(1,sizeof(SchedulingRequestConfig_t));

        memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->schedulingRequestConfig,
                (char*)radioResourceConfigDedicated->physicalConfigDedicated->schedulingRequestConfig,
                sizeof(physicalConfigDedicated2->schedulingRequestConfig));
    }
    else
    {
        LOG_I(RRC,"Keep old config for schedulingRequestConfig\n");
    }

    // Update soundingRS_UL_ConfigDedicated
    if(radioResourceConfigDedicated->physicalConfigDedicated->soundingRS_UL_ConfigDedicated != NULL)
    {
        LOG_I(RRC,"Update soundingRS_UL_ConfigDedicated config \n");

        if(UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->soundingRS_UL_ConfigDedicated == NULL)
            UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->soundingRS_UL_ConfigDedicated = CALLOC(1,sizeof(SoundingRS_UL_ConfigDedicated_t));

        memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->soundingRS_UL_ConfigDedicated,
                (char*)radioResourceConfigDedicated->physicalConfigDedicated->soundingRS_UL_ConfigDedicated,
                sizeof(physicalConfigDedicated2->soundingRS_UL_ConfigDedicated));
    }
    else
    {
        LOG_I(RRC,"Keep old config for soundingRS_UL_ConfigDedicated\n");
    }

    // Update antennaInfo
    if(radioResourceConfigDedicated->physicalConfigDedicated->antennaInfo != NULL)
    {
        LOG_I(RRC,"Update antennaInfo config \n");

        if(UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->antennaInfo == NULL)
            UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->antennaInfo = CALLOC(1,sizeof(struct PhysicalConfigDedicated__antennaInfo));

        memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->antennaInfo,
                (char*)radioResourceConfigDedicated->physicalConfigDedicated->antennaInfo,
                sizeof(physicalConfigDedicated2->antennaInfo));
1368 1369 1370 1371 1372 1373 1374 1375

        UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->antennaInfo->choice.explicitValue.transmissionMode =
        		radioResourceConfigDedicated->physicalConfigDedicated->antennaInfo->choice.explicitValue.transmissionMode;
        UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->antennaInfo->choice.explicitValue.codebookSubsetRestriction =
        		radioResourceConfigDedicated->physicalConfigDedicated->antennaInfo->choice.explicitValue.codebookSubsetRestriction;
        UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->antennaInfo->choice.explicitValue.ue_TransmitAntennaSelection =
        		radioResourceConfigDedicated->physicalConfigDedicated->antennaInfo->choice.explicitValue.ue_TransmitAntennaSelection;

1376 1377
        LOG_I(PHY,"New Transmission Mode %ld \n",radioResourceConfigDedicated->physicalConfigDedicated->antennaInfo->choice.explicitValue.transmissionMode);
        LOG_I(PHY,"Configured Transmission Mode %ld \n",UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->antennaInfo->choice.explicitValue.transmissionMode);
1378

1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438
    }
    else
    {
        LOG_I(RRC,"Keep old config for antennaInfo\n");
    }


    // Update uplinkPowerControlDedicated
    if(radioResourceConfigDedicated->physicalConfigDedicated->uplinkPowerControlDedicated != NULL)
    {
        LOG_I(RRC,"Update uplinkPowerControlDedicated config \n");

        if(UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->uplinkPowerControlDedicated == NULL)
            UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->uplinkPowerControlDedicated = CALLOC(1,sizeof(UplinkPowerControlDedicated_t));

        memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->uplinkPowerControlDedicated,
                (char*)radioResourceConfigDedicated->physicalConfigDedicated->uplinkPowerControlDedicated,
                sizeof(physicalConfigDedicated2->uplinkPowerControlDedicated));
    }
    else
    {
        LOG_I(RRC,"Keep old config for uplinkPowerControlDedicated\n");
    }

    // Update tpc_PDCCH_ConfigPUCCH
    if(radioResourceConfigDedicated->physicalConfigDedicated->tpc_PDCCH_ConfigPUCCH != NULL)
    {
        LOG_I(RRC,"Update tpc_PDCCH_ConfigPUCCH config \n");

        if(UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->tpc_PDCCH_ConfigPUCCH == NULL)
            UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->tpc_PDCCH_ConfigPUCCH = CALLOC(1,sizeof(TPC_PDCCH_Config_t));

        memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->tpc_PDCCH_ConfigPUCCH,
                (char*)radioResourceConfigDedicated->physicalConfigDedicated->tpc_PDCCH_ConfigPUCCH,
                sizeof(physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH));
    }
    else
    {
        LOG_I(RRC,"Keep old config for tpc_PDCCH_ConfigPUCCH\n");
    }

    // Update tpc_PDCCH_ConfigPUSCH
    if(radioResourceConfigDedicated->physicalConfigDedicated->tpc_PDCCH_ConfigPUSCH != NULL)
    {
        LOG_I(RRC,"Update tpc_PDCCH_ConfigPUSCH config \n");

        if(UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->tpc_PDCCH_ConfigPUSCH == NULL)
            UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->tpc_PDCCH_ConfigPUSCH = CALLOC(1,sizeof(TPC_PDCCH_Config_t));

        memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]->tpc_PDCCH_ConfigPUSCH,
                (char*)radioResourceConfigDedicated->physicalConfigDedicated->tpc_PDCCH_ConfigPUSCH,
                sizeof(physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH));

    }
    else
    {
        LOG_I(RRC,"Keep old config for tpc_PDCCH_ConfigPUSCH\n");
    }

}
1439
//-----------------------------------------------------------------------------
1440
void
1441 1442 1443 1444 1445 1446
rrc_ue_process_radioResourceConfigDedicated(
  const protocol_ctxt_t* const ctxt_pP,
  uint8_t eNB_index,
  RadioResourceConfigDedicated_t* radioResourceConfigDedicated
)
//-----------------------------------------------------------------------------
1447
{
1448 1449 1450 1451

  long SRB_id,DRB_id;
  int i,cnt;
  LogicalChannelConfig_t *SRB1_logicalChannelConfig,*SRB2_logicalChannelConfig;
1452
#ifdef CBA
1453 1454
  uint8_t cba_found = 0;
  uint16_t cba_RNTI;
1455
#endif
1456 1457 1458

  // Save physicalConfigDedicated if present
  if (radioResourceConfigDedicated->physicalConfigDedicated) {
1459 1460
    LOG_I(RRC,"Save physicalConfigDedicated if present \n");

1461
    if (UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index]) {
1462 1463 1464
#if 1
        rrc_ue_update_radioResourceConfigDedicated(radioResourceConfigDedicated, ctxt_pP, eNB_index);
#else
1465
      memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index],(char*)radioResourceConfigDedicated->physicalConfigDedicated,
1466
             sizeof(struct PhysicalConfigDedicated));
1467
#endif
1468
    } else {
1469
      LOG_I(RRC,"Init physicalConfigDedicated UE_rrc_inst to radioResourceConfigDedicated->physicalConfigDedicated\n");
1470
      UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index] = radioResourceConfigDedicated->physicalConfigDedicated;
1471
    }
1472
  }
1473

1474 1475
  // Apply macMainConfig if present
  if (radioResourceConfigDedicated->mac_MainConfig) {
1476
    if (radioResourceConfigDedicated->mac_MainConfig->present == RadioResourceConfigDedicated__mac_MainConfig_PR_explicitValue) {
1477 1478
      if (UE_rrc_inst[ctxt_pP->module_id].mac_MainConfig[eNB_index]) {
        memcpy((char*)UE_rrc_inst[ctxt_pP->module_id].mac_MainConfig[eNB_index],(char*)&radioResourceConfigDedicated->mac_MainConfig->choice.explicitValue,
1479
               sizeof(MAC_MainConfig_t));
1480 1481 1482
      } else {
        UE_rrc_inst[ctxt_pP->module_id].mac_MainConfig[eNB_index] = &radioResourceConfigDedicated->mac_MainConfig->choice.explicitValue;
      }
1483
    }
1484 1485 1486 1487
  }

  // Apply spsConfig if present
  if (radioResourceConfigDedicated->sps_Config) {
1488 1489
    if (UE_rrc_inst[ctxt_pP->module_id].sps_Config[eNB_index]) {
      memcpy(UE_rrc_inst[ctxt_pP->module_id].sps_Config[eNB_index],radioResourceConfigDedicated->sps_Config,
1490 1491
             sizeof(struct SPS_Config));
    } else {
1492
      UE_rrc_inst[ctxt_pP->module_id].sps_Config[eNB_index] = radioResourceConfigDedicated->sps_Config;
1493
    }
1494
  }
1495

1496
#ifdef CBA
1497

1498
  if (radioResourceConfigDedicated->cba_RNTI_vlola) {
1499 1500 1501 1502
    cba_RNTI = (uint16_t) (((radioResourceConfigDedicated->cba_RNTI_vlola->buf[1]&0xff) << 8) |
                           (radioResourceConfigDedicated->cba_RNTI_vlola->buf[0]&0xff));

    for (i=0 ; i< NUM_MAX_CBA_GROUP; i++) {
1503
      if (UE_rrc_inst[ctxt_pP->module_id].cba_rnti[i] == cba_RNTI ) {
1504 1505
        cba_found=1;
        break;
1506
      } else if (UE_rrc_inst[ctxt_pP->module_id].cba_rnti[i] == 0 ) {
1507
        break;
1508
      }
1509 1510 1511
    }

    if (cba_found==0) {
1512 1513
      UE_rrc_inst[ctxt_pP->module_id].num_active_cba_groups++;
      UE_rrc_inst[ctxt_pP->module_id].cba_rnti[i]=cba_RNTI;
1514
      LOG_D(RRC, "[UE %d] Frame %d: radioResourceConfigDedicated reveived CBA_RNTI = %x for group %d from eNB %d \n",
1515
            ctxt_pP->module_id,frameP, UE_rrc_inst[ctxt_pP->module_id].cba_rnti[i], i, eNB_index);
1516
    }
1517
  }
1518 1519 1520

#endif

1521 1522 1523
  // Establish SRBs if present
  // loop through SRBToAddModList
  if (radioResourceConfigDedicated->srb_ToAddModList) {
1524 1525
    uint8_t *kRRCenc = NULL;
    uint8_t *kRRCint = NULL;
1526 1527

#if defined(ENABLE_SECURITY)
1528 1529 1530 1531
    derive_key_rrc_enc(UE_rrc_inst[ctxt_pP->module_id].ciphering_algorithm,
                       UE_rrc_inst[ctxt_pP->module_id].kenb, &kRRCenc);
    derive_key_rrc_int(UE_rrc_inst[ctxt_pP->module_id].integrity_algorithm,
                       UE_rrc_inst[ctxt_pP->module_id].kenb, &kRRCint);
1532 1533
#endif
    // Refresh SRBs
1534
    rrc_pdcp_config_asn1_req(ctxt_pP,
1535 1536 1537
                             radioResourceConfigDedicated->srb_ToAddModList,
                             (DRB_ToAddModList_t*)NULL,
                             (DRB_ToReleaseList_t*)NULL,
1538 1539
                             UE_rrc_inst[ctxt_pP->module_id].ciphering_algorithm |
                             (UE_rrc_inst[ctxt_pP->module_id].integrity_algorithm << 4),
1540 1541 1542
                             kRRCenc,
                             kRRCint,
                             NULL
Cedric Roux's avatar
Cedric Roux committed
1543
#if defined(Rel10) || defined(Rel14)
1544
                             ,(PMCH_InfoList_r9_t *)NULL
1545
#endif
1546
                             ,NULL);
1547

1548
    // Refresh SRBs
1549
    rrc_rlc_config_asn1_req(ctxt_pP,
1550 1551 1552
                            radioResourceConfigDedicated->srb_ToAddModList,
                            (DRB_ToAddModList_t*)NULL,
                            (DRB_ToReleaseList_t*)NULL
Cedric Roux's avatar
Cedric Roux committed
1553
#if defined(Rel10) || defined(Rel14)
1554
                            ,(PMCH_InfoList_r9_t *)NULL
1555
                            , 0, 0
1556
#endif
1557
                           );
1558

1559
#if ENABLE_RAL
1560
    // first msg that includes srb config
1561
    UE_rrc_inst[ctxt_pP->module_id].num_srb=radioResourceConfigDedicated->srb_ToAddModList->list.count;
1562
#endif
1563

1564 1565 1566
    for (cnt=0; cnt<radioResourceConfigDedicated->srb_ToAddModList->list.count; cnt++) {
      //  connection_reestablishment_ind.num_srb+=1;
      SRB_id = radioResourceConfigDedicated->srb_ToAddModList->list.array[cnt]->srb_Identity;
1567
      LOG_D(RRC,"[UE %d]: Frame %d SRB config cnt %d (SRB%ld)\n",ctxt_pP->module_id,ctxt_pP->frame,cnt,SRB_id);
1568 1569

      if (SRB_id == 1) {
1570 1571
        if (UE_rrc_inst[ctxt_pP->module_id].SRB1_config[eNB_index]) {
          memcpy(UE_rrc_inst[ctxt_pP->module_id].SRB1_config[eNB_index],radioResourceConfigDedicated->srb_ToAddModList->list.array[cnt],
1572 1573
                 sizeof(struct SRB_ToAddMod));
        } else {
1574 1575
          UE_rrc_inst[ctxt_pP->module_id].SRB1_config[eNB_index] = radioResourceConfigDedicated->srb_ToAddModList->list.array[cnt];
          rrc_ue_establish_srb1(ctxt_pP->module_id,ctxt_pP->frame,eNB_index,radioResourceConfigDedicated->srb_ToAddModList->list.array[cnt]);
1576

1577 1578 1579
          if (UE_rrc_inst[ctxt_pP->module_id].SRB1_config[eNB_index]->logicalChannelConfig) {
            if (UE_rrc_inst[ctxt_pP->module_id].SRB1_config[eNB_index]->logicalChannelConfig->present == SRB_ToAddMod__logicalChannelConfig_PR_explicitValue) {
              SRB1_logicalChannelConfig = &UE_rrc_inst[ctxt_pP->module_id].SRB1_config[eNB_index]->logicalChannelConfig->choice.explicitValue;
1580 1581 1582 1583 1584 1585 1586 1587

            } else {
              SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
            }
          } else {
            SRB1_logicalChannelConfig = &SRB1_logicalChannelConfig_defaultValue;
          }

1588
          LOG_I(RRC, "[FRAME %05d][RRC_UE][MOD %02d][][--- MAC_CONFIG_REQ  (SRB1 eNB %d) --->][MAC_UE][MOD %02d][]\n",
1589
                ctxt_pP->frame, ctxt_pP->module_id, eNB_index, ctxt_pP->module_id);
1590

1591 1592 1593
          rrc_mac_config_req_ue(ctxt_pP->module_id,0,eNB_index,
				(RadioResourceConfigCommonSIB_t *)NULL,
				UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index],
Cedric Roux's avatar
Cedric Roux committed
1594
#if defined(Rel10) || defined(Rel14)
1595 1596
				(SCellToAddMod_r10_t *)NULL,
				//struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
1597
#endif
1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610
				(MeasObjectToAddMod_t **)NULL,
				UE_rrc_inst[ctxt_pP->module_id].mac_MainConfig[eNB_index],
				1,
				SRB1_logicalChannelConfig,
				(MeasGapConfig_t *)NULL,
				NULL,
				NULL,
				NULL,
				NULL,
				NULL,
				NULL,
				NULL,
				NULL
Cedric Roux's avatar
Cedric Roux committed
1611
#if defined(Rel10) || defined(Rel14)
1612 1613 1614 1615
				,
				0,
				(MBSFN_AreaInfoList_r9_t *)NULL,
				(PMCH_InfoList_r9_t *)NULL
1616 1617
#endif
#ifdef CBA
1618 1619 1620
				,
				0,
				0
1621 1622 1623
#endif
#if defined(Rel14)
           ,
1624
           0,
1625
           NULL,
1626
           NULL,
1627
           NULL
1628
#endif
1629
				);
1630 1631
        }
      } else {
1632 1633
        if (UE_rrc_inst[ctxt_pP->module_id].SRB2_config[eNB_index]) {
          memcpy(UE_rrc_inst[ctxt_pP->module_id].SRB2_config[eNB_index],radioResourceConfigDedicated->srb_ToAddModList->list.array[cnt],
1634 1635
                 sizeof(struct SRB_ToAddMod));
        } else {
1636 1637
          UE_rrc_inst[ctxt_pP->module_id].SRB2_config[eNB_index] = radioResourceConfigDedicated->srb_ToAddModList->list.array[cnt];
          rrc_ue_establish_srb2(ctxt_pP->module_id,ctxt_pP->frame,eNB_index,radioResourceConfigDedicated->srb_ToAddModList->list.array[cnt]);
1638

1639 1640
          if (UE_rrc_inst[ctxt_pP->module_id].SRB2_config[eNB_index]->logicalChannelConfig) {
            if (UE_rrc_inst[ctxt_pP->module_id].SRB2_config[eNB_index]->logicalChannelConfig->present == SRB_ToAddMod__logicalChannelConfig_PR_explicitValue) {
1641
              LOG_I(RRC,"Applying Explicit SRB2 logicalChannelConfig\n");
1642
              SRB2_logicalChannelConfig = &UE_rrc_inst[ctxt_pP->module_id].SRB2_config[eNB_index]->logicalChannelConfig->choice.explicitValue;
1643 1644 1645 1646 1647 1648
            } else {
              LOG_I(RRC,"Applying default SRB2 logicalChannelConfig\n");
              SRB2_logicalChannelConfig = &SRB2_logicalChannelConfig_defaultValue;
            }
          } else {
            SRB2_logicalChannelConfig = &SRB2_logicalChannelConfig_defaultValue;
1649
          }
1650

1651
          LOG_I(RRC, "[FRAME %05d][RRC_UE][MOD %02d][][--- MAC_CONFIG_REQ  (SRB2 eNB %d) --->][MAC_UE][MOD %02d][]\n",
1652 1653 1654 1655
                ctxt_pP->frame,
                ctxt_pP->module_id,
                eNB_index,
                ctxt_pP->module_id);
1656 1657 1658
          rrc_mac_config_req_ue(ctxt_pP->module_id,0,eNB_index,
				(RadioResourceConfigCommonSIB_t *)NULL,
				UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index],
Cedric Roux's avatar
Cedric Roux committed
1659
#if defined(Rel10) || defined(Rel14)
1660 1661
				(SCellToAddMod_r10_t *)NULL,
				//struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
1662
#endif
1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675
				(MeasObjectToAddMod_t **)NULL,
				UE_rrc_inst[ctxt_pP->module_id].mac_MainConfig[eNB_index],
				2,
				SRB2_logicalChannelConfig,
				UE_rrc_inst[ctxt_pP->module_id].measGapConfig[eNB_index],
				(TDD_Config_t *)NULL,
				(MobilityControlInfo_t *)NULL,
				NULL,
				NULL,
				NULL,
				NULL,
				NULL,
				NULL
Cedric Roux's avatar
Cedric Roux committed
1676
#if defined(Rel10) || defined(Rel14)
1677 1678 1679 1680
				,
				0,
				(MBSFN_AreaInfoList_r9_t *)NULL,
				(PMCH_InfoList_r9_t *)NULL
1681

1682 1683
#endif
#ifdef CBA
1684 1685 1686
				,
				0,
				0
1687 1688 1689
#endif
#if defined(Rel14)
           ,
1690
           0,
1691
           NULL,
1692
           NULL,
1693
           NULL
1694
#endif
1695
				);
1696
        }
1697
      }
1698
    }
1699 1700 1701 1702
  }

  // Establish DRBs if present
  if (radioResourceConfigDedicated->drb_ToAddModList) {
1703 1704 1705 1706 1707 1708 1709 1710 1711

    if ( (UE_rrc_inst[ctxt_pP->module_id].defaultDRB == NULL) &&
         (radioResourceConfigDedicated->drb_ToAddModList->list.count >= 1) ) {
        // configure the first DRB ID as the default DRB ID
        UE_rrc_inst[ctxt_pP->module_id].defaultDRB = malloc(sizeof(rb_id_t));
        *UE_rrc_inst[ctxt_pP->module_id].defaultDRB = radioResourceConfigDedicated->drb_ToAddModList->list.array[0]->drb_Identity;
        LOG_I(RRC,"[UE %d] default DRB = %d\n",ctxt_pP->module_id, *UE_rrc_inst[ctxt_pP->module_id].defaultDRB);
      }

1712
    uint8_t *kUPenc = NULL;
1713 1714

#if defined(ENABLE_SECURITY)
1715 1716
    derive_key_up_enc(UE_rrc_inst[ctxt_pP->module_id].integrity_algorithm,
                      UE_rrc_inst[ctxt_pP->module_id].kenb, &kUPenc);
1717 1718
#endif

Lionel Gauthier's avatar
Lionel Gauthier committed
1719 1720 1721 1722 1723 1724 1725 1726 1727
    MSC_LOG_TX_MESSAGE(
      MSC_RRC_UE,
      MSC_PDCP_UE,
      NULL,
      0,
      MSC_AS_TIME_FMT" CONFIG_REQ UE %x DRB (security %X)",
      MSC_AS_TIME_ARGS(ctxt_pP),
      ctxt_pP->rnti,
      UE_rrc_inst[ctxt_pP->module_id].ciphering_algorithm |
1728
      (UE_rrc_inst[ctxt_pP->module_id].integrity_algorithm << 4));
Lionel Gauthier's avatar
Lionel Gauthier committed
1729

1730
    // Refresh DRBs
1731
    rrc_pdcp_config_asn1_req(ctxt_pP,
1732 1733 1734
                             (SRB_ToAddModList_t*)NULL,
                             radioResourceConfigDedicated->drb_ToAddModList,
                             (DRB_ToReleaseList_t*)NULL,
1735 1736
                             UE_rrc_inst[ctxt_pP->module_id].ciphering_algorithm |
                             (UE_rrc_inst[ctxt_pP->module_id].integrity_algorithm << 4),
1737 1738 1739
                             NULL,
                             NULL,
                             kUPenc
Cedric Roux's avatar
Cedric Roux committed
1740
#if defined(Rel10) || defined(Rel14)
1741
                             ,(PMCH_InfoList_r9_t *)NULL
1742
#endif
1743
                             , UE_rrc_inst[ctxt_pP->module_id].defaultDRB);
1744

1745
    // Refresh DRBs
1746
    rrc_rlc_config_asn1_req(ctxt_pP,
1747 1748 1749
                            (SRB_ToAddModList_t*)NULL,
                            radioResourceConfigDedicated->drb_ToAddModList,
                            (DRB_ToReleaseList_t*)NULL
Cedric Roux's avatar
Cedric Roux committed
1750
#if defined(Rel10) || defined(Rel14)
1751
                            ,(PMCH_InfoList_r9_t *)NULL
1752
                            , 0, 0
1753 1754 1755 1756 1757 1758
#endif
                           );

    for (i=0; i<radioResourceConfigDedicated->drb_ToAddModList->list.count; i++) {
      DRB_id   = radioResourceConfigDedicated->drb_ToAddModList->list.array[i]->drb_Identity-1;

1759 1760 1761
      if (UE_rrc_inst[ctxt_pP->module_id].DRB_config[eNB_index][DRB_id]) {
        memcpy(UE_rrc_inst[ctxt_pP->module_id].DRB_config[eNB_index][DRB_id],
               radioResourceConfigDedicated->drb_ToAddModList->list.array[i],
1762 1763
               sizeof(struct DRB_ToAddMod));
      } else {
1764 1765
        UE_rrc_inst[ctxt_pP->module_id].DRB_config[eNB_index][DRB_id] = radioResourceConfigDedicated->drb_ToAddModList->list.array[i];
        rrc_ue_establish_drb(ctxt_pP->module_id,ctxt_pP->frame,eNB_index,radioResourceConfigDedicated->drb_ToAddModList->list.array[i]);
1766
        // MAC/PHY Configuration
Cedric Roux's avatar
Cedric Roux committed
1767
        LOG_I(RRC, "[FRAME %05d][RRC_UE][MOD %02d][][--- MAC_CONFIG_REQ (DRB %ld eNB %d) --->][MAC_UE][MOD %02d][]\n",
1768 1769 1770 1771
              ctxt_pP->frame, ctxt_pP->module_id,
              radioResourceConfigDedicated->drb_ToAddModList->list.array[i]->drb_Identity,
              eNB_index,
              ctxt_pP->module_id);
1772 1773 1774
        rrc_mac_config_req_ue(ctxt_pP->module_id,0,eNB_index,
			      (RadioResourceConfigCommonSIB_t *)NULL,
			      UE_rrc_inst[ctxt_pP->module_id].physicalConfigDedicated[eNB_index],
Cedric Roux's avatar
Cedric Roux committed
1775
#if defined(Rel10) || defined(Rel14)
1776 1777
			      (SCellToAddMod_r10_t *)NULL,
			      //struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
1778
#endif
1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791
			      (MeasObjectToAddMod_t **)NULL,
			      UE_rrc_inst[ctxt_pP->module_id].mac_MainConfig[eNB_index],
			      *UE_rrc_inst[ctxt_pP->module_id].DRB_config[eNB_index][DRB_id]->logicalChannelIdentity,
			      UE_rrc_inst[ctxt_pP->module_id].DRB_config[eNB_index][DRB_id]->logicalChannelConfig,
			      UE_rrc_inst[ctxt_pP->module_id].measGapConfig[eNB_index],
			      (TDD_Config_t*)NULL,
			      (MobilityControlInfo_t *)NULL,
			      NULL,
			      NULL,
			      NULL,
			      NULL,
			      NULL,
			      NULL
Cedric Roux's avatar
Cedric Roux committed
1792
#if defined(Rel10) || defined(Rel14)
1793 1794 1795 1796
			      ,
			      0,
			      (MBSFN_AreaInfoList_r9_t *)NULL,
			      (PMCH_InfoList_r9_t *)NULL
1797 1798
#endif
#ifdef CBA
1799 1800 1801
			      ,
			      UE_rrc_inst[ue_mod_idP].num_active_cba_groups, //
			      UE_rrc_inst[ue_mod_idP].cba_rnti[0]
1802 1803 1804
#endif
#if defined(Rel14)
           ,
1805
           0,
1806
           NULL,
1807
           NULL,
1808
           NULL
1809
#endif
1810
			      );
1811

1812
      }
1813
    }
1814
  }
1815

1816 1817
  UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].State = RRC_CONNECTED;
  LOG_I(RRC,"[UE %d] State = RRC_CONNECTED (eNB %d)\n",ctxt_pP->module_id,eNB_index);
1818 1819
}

1820 1821 1822 1823 1824 1825 1826 1827 1828

//-----------------------------------------------------------------------------
void
rrc_ue_process_securityModeCommand(
  const protocol_ctxt_t* const ctxt_pP,
  SecurityModeCommand_t* const securityModeCommand,
  const uint8_t                eNB_index
)
//-----------------------------------------------------------------------------
1829
{
1830 1831 1832 1833 1834 1835 1836

  asn_enc_rval_t enc_rval;

  UL_DCCH_Message_t ul_dcch_msg;
  // SecurityModeCommand_t SecurityModeCommand;
  uint8_t buffer[200];
  int i, securityMode;
1837

1838 1839
  LOG_I(RRC,"[UE %d] SFN/SF %d/%d: Receiving from SRB1 (DL-DCCH), Processing securityModeCommand (eNB %d)\n",
        ctxt_pP->module_id,ctxt_pP->frame, ctxt_pP->subframe, eNB_index);
1840

1841
  switch (securityModeCommand->criticalExtensions.choice.c1.choice.securityModeCommand_r8.securityConfigSMC.securityAlgorithmConfig.cipheringAlgorithm) {
Cedric Roux's avatar
Cedric Roux committed
1842
  case CipheringAlgorithm_r12_eea0:
1843 1844
    LOG_I(RRC,"[UE %d] Security algorithm is set to eea0\n",
          ctxt_pP->module_id);
Cedric Roux's avatar
Cedric Roux committed
1845
    securityMode= CipheringAlgorithm_r12_eea0;
1846
    break;
1847

Cedric Roux's avatar
Cedric Roux committed
1848
  case CipheringAlgorithm_r12_eea1:
1849
    LOG_I(RRC,"[UE %d] Security algorithm is set to eea1\n",ctxt_pP->module_id);
Cedric Roux's avatar
Cedric Roux committed
1850
    securityMode= CipheringAlgorithm_r12_eea1;
1851
    break;
1852

Cedric Roux's avatar
Cedric Roux committed
1853
  case CipheringAlgorithm_r12_eea2:
1854 1855
    LOG_I(RRC,"[UE %d] Security algorithm is set to eea2\n",
          ctxt_pP->module_id);
Cedric Roux's avatar
Cedric Roux committed
1856
    securityMode = CipheringAlgorithm_r12_eea2;
1857
    break;
1858

1859
  default:
1860
    LOG_I(RRC,"[UE %d] Security algorithm is set to none\n",ctxt_pP->module_id);
Cedric Roux's avatar
Cedric Roux committed
1861
    securityMode = CipheringAlgorithm_r12_spare1;
1862 1863
    break;
  }
1864 1865

  switch (securityModeCommand->criticalExtensions.choice.c1.choice.securityModeCommand_r8.securityConfigSMC.securityAlgorithmConfig.integrityProtAlgorithm) {
1866
  case SecurityAlgorithmConfig__integrityProtAlgorithm_eia1:
1867
    LOG_I(RRC,"[UE %d] Integrity protection algorithm is set to eia1\n",ctxt_pP->module_id);
1868 1869
    securityMode |= 1 << 5;
    break;
1870

1871
  case SecurityAlgorithmConfig__integrityProtAlgorithm_eia2:
1872
    LOG_I(RRC,"[UE %d] Integrity protection algorithm is set to eia2\n",ctxt_pP->module_id);
1873 1874
    securityMode |= 1 << 6;
    break;
1875

1876
  default:
1877
    LOG_I(RRC,"[UE %d] Integrity protection algorithm is set to none\n",ctxt_pP->module_id);
1878 1879 1880
    securityMode |= 0x70 ;
    break;
  }
1881

1882
  LOG_D(RRC,"[UE %d] security mode is %x \n",ctxt_pP->module_id, securityMode);
1883 1884

  /* Store the parameters received */
1885 1886 1887 1888
  UE_rrc_inst[ctxt_pP->module_id].ciphering_algorithm =
    securityModeCommand->criticalExtensions.choice.c1.choice.securityModeCommand_r8.securityConfigSMC.securityAlgorithmConfig.cipheringAlgorithm;
  UE_rrc_inst[ctxt_pP->module_id].integrity_algorithm =
    securityModeCommand->criticalExtensions.choice.c1.choice.securityModeCommand_r8.securityConfigSMC.securityAlgorithmConfig.integrityProtAlgorithm;
1889

1890 1891 1892 1893
  memset((void *)&ul_dcch_msg,0,sizeof(UL_DCCH_Message_t));
  //memset((void *)&SecurityModeCommand,0,sizeof(SecurityModeCommand_t));

  ul_dcch_msg.message.present           = UL_DCCH_MessageType_PR_c1;
1894

1895
  if (securityMode >= NO_SECURITY_MODE) {
1896
	  LOG_I(RRC, "rrc_ue_process_securityModeCommand, security mode complete case \n");
1897
    ul_dcch_msg.message.choice.c1.present = UL_DCCH_MessageType__c1_PR_securityModeComplete;
1898
  } else {
1899
	  LOG_I(RRC, "rrc_ue_process_securityModeCommand, security mode failure case \n");
1900
    ul_dcch_msg.message.choice.c1.present = UL_DCCH_MessageType__c1_PR_securityModeFailure;
1901
  }
1902

1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916

#if defined(ENABLE_SECURITY)
  uint8_t *kRRCenc = NULL;
  uint8_t *kUPenc = NULL;
  uint8_t *kRRCint = NULL;
  pdcp_t *pdcp_p = NULL;
  hash_key_t key = HASHTABLE_NOT_A_KEY_VALUE;
  hashtable_rc_t h_rc;

  key = PDCP_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti,
      ctxt_pP->enb_flag, DCCH, SRB_FLAG_YES);
  h_rc = hashtable_get(pdcp_coll_p, key, (void**) &pdcp_p);

  if (h_rc == HASH_TABLE_OK) {
Cedric Roux's avatar
Cedric Roux committed
1917
    LOG_D(RRC, "PDCP_COLL_KEY_VALUE() returns valid key = %ld\n", key);
1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949

    LOG_D(RRC, "driving kRRCenc, kRRCint and kUPenc from KeNB="
        "%02x%02x%02x%02x"
        "%02x%02x%02x%02x"
        "%02x%02x%02x%02x"
        "%02x%02x%02x%02x"
        "%02x%02x%02x%02x"
        "%02x%02x%02x%02x"
        "%02x%02x%02x%02x"
        "%02x%02x%02x%02x\n",
        UE_rrc_inst[ctxt_pP->module_id].kenb[0],  UE_rrc_inst[ctxt_pP->module_id].kenb[1],  UE_rrc_inst[ctxt_pP->module_id].kenb[2],  UE_rrc_inst[ctxt_pP->module_id].kenb[3],
        UE_rrc_inst[ctxt_pP->module_id].kenb[4],  UE_rrc_inst[ctxt_pP->module_id].kenb[5],  UE_rrc_inst[ctxt_pP->module_id].kenb[6],  UE_rrc_inst[ctxt_pP->module_id].kenb[7],
        UE_rrc_inst[ctxt_pP->module_id].kenb[8],  UE_rrc_inst[ctxt_pP->module_id].kenb[9],  UE_rrc_inst[ctxt_pP->module_id].kenb[10], UE_rrc_inst[ctxt_pP->module_id].kenb[11],
        UE_rrc_inst[ctxt_pP->module_id].kenb[12], UE_rrc_inst[ctxt_pP->module_id].kenb[13], UE_rrc_inst[ctxt_pP->module_id].kenb[14], UE_rrc_inst[ctxt_pP->module_id].kenb[15],
        UE_rrc_inst[ctxt_pP->module_id].kenb[16], UE_rrc_inst[ctxt_pP->module_id].kenb[17], UE_rrc_inst[ctxt_pP->module_id].kenb[18], UE_rrc_inst[ctxt_pP->module_id].kenb[19],
        UE_rrc_inst[ctxt_pP->module_id].kenb[20], UE_rrc_inst[ctxt_pP->module_id].kenb[21], UE_rrc_inst[ctxt_pP->module_id].kenb[22], UE_rrc_inst[ctxt_pP->module_id].kenb[23],
        UE_rrc_inst[ctxt_pP->module_id].kenb[24], UE_rrc_inst[ctxt_pP->module_id].kenb[25], UE_rrc_inst[ctxt_pP->module_id].kenb[26], UE_rrc_inst[ctxt_pP->module_id].kenb[27],
        UE_rrc_inst[ctxt_pP->module_id].kenb[28], UE_rrc_inst[ctxt_pP->module_id].kenb[29], UE_rrc_inst[ctxt_pP->module_id].kenb[30], UE_rrc_inst[ctxt_pP->module_id].kenb[31]);

    derive_key_rrc_enc(UE_rrc_inst[ctxt_pP->module_id].ciphering_algorithm,
        UE_rrc_inst[ctxt_pP->module_id].kenb, &kRRCenc);
    derive_key_rrc_int(UE_rrc_inst[ctxt_pP->module_id].integrity_algorithm,
        UE_rrc_inst[ctxt_pP->module_id].kenb, &kRRCint);
    derive_key_up_enc(UE_rrc_inst[ctxt_pP->module_id].ciphering_algorithm,
        UE_rrc_inst[ctxt_pP->module_id].kenb, &kUPenc);

    if (securityMode != 0xff) {
      pdcp_config_set_security(ctxt_pP, pdcp_p, 0, 0,
          UE_rrc_inst[ctxt_pP->module_id].ciphering_algorithm
              | (UE_rrc_inst[ctxt_pP->module_id].integrity_algorithm << 4),
          kRRCenc, kRRCint, kUPenc);
    } else {
1950
      LOG_I(RRC, "skipped pdcp_config_set_security() as securityMode == 0x%02x",
1951 1952 1953
          securityMode);
    }
  } else {
1954
    LOG_I(RRC, "Could not get PDCP instance where key=0x%ld\n", key);
1955 1956 1957 1958
  }

#endif //#if defined(ENABLE_SECURITY)

1959
  if (securityModeCommand->criticalExtensions.present == SecurityModeCommand__criticalExtensions_PR_c1) {
1960 1961 1962 1963 1964 1965 1966 1967 1968
    if (securityModeCommand->criticalExtensions.choice.c1.present != SecurityModeCommand__criticalExtensions__c1_PR_securityModeCommand_r8)
      LOG_W(RRC,"securityModeCommand->criticalExtensions.choice.c1.present (%d) != SecurityModeCommand__criticalExtensions__c1_PR_securityModeCommand_r8\n",
	    securityModeCommand->criticalExtensions.choice.c1.present);
    
    
    ul_dcch_msg.message.choice.c1.choice.securityModeComplete.rrc_TransactionIdentifier = securityModeCommand->rrc_TransactionIdentifier;
    ul_dcch_msg.message.choice.c1.choice.securityModeComplete.criticalExtensions.present = SecurityModeCommand__criticalExtensions_PR_c1;
    ul_dcch_msg.message.choice.c1.choice.securityModeComplete.criticalExtensions.choice.securityModeComplete_r8.nonCriticalExtension =NULL;
    
1969 1970
    LOG_I(RRC,"[UE %d] SFN/SF %d/%d: Receiving from SRB1 (DL-DCCH), encoding securityModeComplete (eNB %d), rrc_TransactionIdentifier: %ld\n",
	  ctxt_pP->module_id,ctxt_pP->frame, ctxt_pP->subframe, eNB_index, securityModeCommand->rrc_TransactionIdentifier);
1971 1972 1973 1974 1975 1976 1977 1978
    
    enc_rval = uper_encode_to_buffer(&asn_DEF_UL_DCCH_Message,
				     (void*)&ul_dcch_msg,
				     buffer,
				     100);
    AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %jd)!\n",
		 enc_rval.failed_type->name, enc_rval.encoded);
    
1979
#ifdef XER_PRINT
1980
    xer_fprint(stdout, &asn_DEF_UL_DCCH_Message, (void*)&ul_dcch_msg);
1981
#endif
1982
    
1983 1984
#if defined(ENABLE_ITTI)
# if !defined(DISABLE_XER_SPRINT)
1985 1986 1987 1988
    {
      char        message_string[20000];
      size_t      message_string_size;
      
1989
      //LOG_I(RRC, "Panos-D: rrc_ue_process_securityModeCommand, Before xer_sprint() \n");
1990 1991 1992 1993 1994 1995 1996 1997
      if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_UL_DCCH_Message, (void *) &ul_dcch_msg)) > 0) {
	MessageDef *msg_p;
	
	msg_p = itti_alloc_new_message_sized (TASK_RRC_UE, 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);
	
	itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
1998
      }
1999
    }
2000 2001 2002
# endif
#endif

Cedric Roux's avatar
Cedric Roux committed
2003
      LOG_D(RRC, "securityModeComplete Encoded %zd bits (%zd bytes)\n", enc_rval.encoded, (enc_rval.encoded+7)/8);
2004

2005
      for (i = 0; i < (enc_rval.encoded + 7) / 8; i++) {
2006
        LOG_T(RRC, "%02x.", buffer[i]);
2007
      }
2008 2009

      LOG_T(RRC, "\n");
2010 2011 2012 2013 2014 2015 2016 2017
      rrc_data_req (
		    ctxt_pP,
		    DCCH,
		    rrc_mui++,
		    SDU_CONFIRM_NO,
		    (enc_rval.encoded + 7) / 8,
		    buffer,
		    PDCP_TRANSMISSION_MODE_CONTROL);
2018
    }
2019 2020 2021
    
  else LOG_W(RRC,"securityModeCommand->criticalExtensions.present (%d) != SecurityModeCommand__criticalExtensions_PR_c1\n",
	     securityModeCommand->criticalExtensions.present);
2022
}
2023

2024 2025 2026 2027 2028 2029 2030 2031
//-----------------------------------------------------------------------------
void
rrc_ue_process_ueCapabilityEnquiry(
  const protocol_ctxt_t* const ctxt_pP,
  UECapabilityEnquiry_t* UECapabilityEnquiry,
  uint8_t eNB_index
)
//-----------------------------------------------------------------------------
2032
{
2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044

  asn_enc_rval_t enc_rval;

  UL_DCCH_Message_t ul_dcch_msg;


  UE_CapabilityRAT_Container_t ue_CapabilityRAT_Container;

  uint8_t buffer[200];
  int i;

  LOG_I(RRC,"[UE %d] Frame %d: Receiving from SRB1 (DL-DCCH), Processing UECapabilityEnquiry (eNB %d)\n",
2045 2046 2047
        ctxt_pP->module_id,
        ctxt_pP->frame,
        eNB_index);
2048 2049 2050 2051 2052 2053 2054


  memset((void *)&ul_dcch_msg,0,sizeof(UL_DCCH_Message_t));
  memset((void *)&ue_CapabilityRAT_Container,0,sizeof(UE_CapabilityRAT_Container_t));

  ul_dcch_msg.message.present           = UL_DCCH_MessageType_PR_c1;
  ul_dcch_msg.message.choice.c1.present = UL_DCCH_MessageType__c1_PR_ueCapabilityInformation;
2055
  ul_dcch_msg.message.choice.c1.choice.ueCapabilityInformation.rrc_TransactionIdentifier = UECapabilityEnquiry->rrc_TransactionIdentifier;
2056 2057 2058

  ue_CapabilityRAT_Container.rat_Type = RAT_Type_eutra;
  OCTET_STRING_fromBuf(&ue_CapabilityRAT_Container.ueCapabilityRAT_Container,
2059 2060
                       (const char*)UE_rrc_inst[ctxt_pP->module_id].UECapability,
                       UE_rrc_inst[ctxt_pP->module_id].UECapability_size);
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2061 2062
  //  ue_CapabilityRAT_Container.ueCapabilityRAT_Container.buf  = UE_rrc_inst[ue_mod_idP].UECapability;
  // ue_CapabilityRAT_Container.ueCapabilityRAT_Container.size = UE_rrc_inst[ue_mod_idP].UECapability_size;
2063

2064

2065 2066 2067
  AssertFatal(UECapabilityEnquiry->criticalExtensions.present == UECapabilityEnquiry__criticalExtensions_PR_c1,
	      "UECapabilityEnquiry->criticalExtensions.present (%d) != UECapabilityEnquiry__criticalExtensions_PR_c1 (%d)\n",
	      UECapabilityEnquiry->criticalExtensions.present,UECapabilityEnquiry__criticalExtensions_PR_c1);
2068

2069
  if (UECapabilityEnquiry->criticalExtensions.choice.c1.present != UECapabilityEnquiry__criticalExtensions__c1_PR_ueCapabilityEnquiry_r8)
matzakos's avatar
matzakos committed
2070
    LOG_I(RRC,"UECapabilityEnquiry->criticalExtensions.choice.c1.present (%d) != UECapabilityEnquiry__criticalExtensions__c1_PR_ueCapabilityEnquiry_r8)\n",
2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090
	  UECapabilityEnquiry->criticalExtensions.choice.c1.present);
  
  ul_dcch_msg.message.choice.c1.choice.ueCapabilityInformation.criticalExtensions.present           = UECapabilityInformation__criticalExtensions_PR_c1;
  ul_dcch_msg.message.choice.c1.choice.ueCapabilityInformation.criticalExtensions.choice.c1.present =
    UECapabilityInformation__criticalExtensions__c1_PR_ueCapabilityInformation_r8;
  ul_dcch_msg.message.choice.c1.choice.ueCapabilityInformation.criticalExtensions.choice.c1.choice.ueCapabilityInformation_r8.ue_CapabilityRAT_ContainerList.list.count
    =0;
  
  for (i=0; i<UECapabilityEnquiry->criticalExtensions.choice.c1.choice.ueCapabilityEnquiry_r8.ue_CapabilityRequest.list.count; i++) {
    
    if (*UECapabilityEnquiry->criticalExtensions.choice.c1.choice.ueCapabilityEnquiry_r8.ue_CapabilityRequest.list.array[i]
	== RAT_Type_eutra) {
      ASN_SEQUENCE_ADD(
		       &ul_dcch_msg.message.choice.c1.choice.ueCapabilityInformation.criticalExtensions.choice.c1.choice.ueCapabilityInformation_r8.ue_CapabilityRAT_ContainerList.list,
		       &ue_CapabilityRAT_Container);
      
      enc_rval = uper_encode_to_buffer(&asn_DEF_UL_DCCH_Message, (void*) &ul_dcch_msg, buffer, 100);
      AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %jd)!\n",
		   enc_rval.failed_type->name, enc_rval.encoded);
      
2091
#ifdef XER_PRINT
2092
      xer_fprint(stdout, &asn_DEF_UL_DCCH_Message, (void*)&ul_dcch_msg);
2093
#endif
2094
      
2095 2096
#if defined(ENABLE_ITTI)
# if !defined(DISABLE_XER_SPRINT)
2097 2098 2099 2100
      {
	char        message_string[20000];
	size_t      message_string_size;
	
2101
	//LOG_I(RRC, "Panos-D: rrc_ue_process_ueCapabilityEnquiry, Before xer_sprint() \n");
2102 2103 2104 2105 2106 2107 2108 2109 2110 2111
	if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_UL_DCCH_Message, (void *) &ul_dcch_msg)) > 0) {
	  MessageDef *msg_p;
	  
	  msg_p = itti_alloc_new_message_sized (TASK_RRC_UE, 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);
	  
	  itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
	}
      }
2112 2113
# endif
#endif
2114
	
2115

matzakos's avatar
matzakos committed
2116
          LOG_I(RRC,"UECapabilityInformation Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8);
2117

2118
          for (i = 0; i < (enc_rval.encoded + 7) / 8; i++) {
2119
            LOG_T(RRC, "%02x.", buffer[i]);
2120
          }
2121 2122
      
      LOG_T(RRC, "\n");
2123
      rrc_data_req_ue (
2124 2125 2126 2127 2128 2129 2130
		    ctxt_pP,
		    DCCH,
		    rrc_mui++,
		    SDU_CONFIRM_NO,
		    (enc_rval.encoded + 7) / 8,
		    buffer,
		    PDCP_TRANSMISSION_MODE_CONTROL);
2131
    }
2132 2133 2134
  }
}

2135

2136 2137 2138 2139
//-----------------------------------------------------------------------------
void
rrc_ue_process_rrcConnectionReconfiguration(
  const protocol_ctxt_t* const       ctxt_pP,
2140
  RRCConnectionReconfiguration_t *rrcConnectionReconfiguration,
2141 2142 2143
  uint8_t eNB_index
)
//-----------------------------------------------------------------------------
2144
{
2145

2146
  LOG_I(RRC,"[UE %d] Frame %d: Receiving from SRB1 (DL-DCCH), Processing RRCConnectionReconfiguration (eNB %d)\n",
2147
        ctxt_pP->module_id,ctxt_pP->frame,eNB_index);
2148

2149
  if (rrcConnectionReconfiguration->criticalExtensions.present == RRCConnectionReconfiguration__criticalExtensions_PR_c1) {
2150 2151
    if (rrcConnectionReconfiguration->criticalExtensions.choice.c1.present ==
        RRCConnectionReconfiguration__criticalExtensions__c1_PR_rrcConnectionReconfiguration_r8) {
2152 2153
      RRCConnectionReconfiguration_r8_IEs_t* rrcConnectionReconfiguration_r8 =
        &rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8;
Lionel Gauthier's avatar
Lionel Gauthier committed
2154

2155 2156
      if (rrcConnectionReconfiguration_r8->mobilityControlInfo) {
        LOG_I(RRC,"Mobility Control Information is present\n");
2157 2158 2159 2160
        rrc_ue_process_mobilityControlInfo(
          ctxt_pP,
          eNB_index,
          rrcConnectionReconfiguration_r8->mobilityControlInfo);
2161 2162 2163 2164
      }

      if (rrcConnectionReconfiguration_r8->measConfig != NULL) {
        LOG_I(RRC,"Measurement Configuration is present\n");
2165 2166
        rrc_ue_process_measConfig(ctxt_pP,
                                  eNB_index,
2167 2168 2169 2170 2171
                                  rrcConnectionReconfiguration_r8->measConfig);
      }

      if (rrcConnectionReconfiguration_r8->radioResourceConfigDedicated) {
        LOG_I(RRC,"Radio Resource Configuration is present\n");
2172
        rrc_ue_process_radioResourceConfigDedicated(ctxt_pP,eNB_index, rrcConnectionReconfiguration_r8->radioResourceConfigDedicated);
2173
      }
2174

2175 2176
      //TTN for D2D
      //if RRCConnectionReconfiguration message includes the sl-CommConfig
2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197
      if ((rrcConnectionReconfiguration_r8->nonCriticalExtension != NULL)
            && (rrcConnectionReconfiguration_r8->nonCriticalExtension->nonCriticalExtension
                  != NULL)
                  && (rrcConnectionReconfiguration_r8->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension
                        != NULL)
                        && (rrcConnectionReconfiguration_r8->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension
                              != NULL)
                              && (rrcConnectionReconfiguration_r8->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension
                                    != NULL)
                                    && (rrcConnectionReconfiguration_r8->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->sl_CommConfig_r12
                                          != NULL)) {
         if (rrcConnectionReconfiguration_r8->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->sl_CommConfig_r12->commTxResources_r12->present != SL_CommConfig_r12__commTxResources_r12_PR_NOTHING){
            LOG_I(RRC,"sl-CommConfig is present\n");
            //process sl-CommConfig
            rrc_ue_process_sidelink_radioResourceConfig(ctxt_pP->module_id,eNB_index,
                  (SystemInformationBlockType18_r12_t *)NULL,
                  (SystemInformationBlockType19_r12_t *)NULL,
                  rrcConnectionReconfiguration_r8->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->sl_CommConfig_r12,
                  (SL_DiscConfig_r12_t *)NULL
            );
         }
2198
      }
2199 2200

/*
2201 2202
      //if RRCConnectionReconfiguration message includes the sl-DiscConfig
      if (rrcConnectionReconfiguration_r8->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->sl_DiscConfig_r12->discTxResources_r12->present != SL_DiscConfig_r12__discTxResources_r12_PR_NOTHING ){
2203 2204
         LOG_I(RRC,"sl-DiscConfig is present\n");
         //process sl-DiscConfig
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
2205
         rrc_ue_process_sidelink_radioResourceConfig(ctxt_pP->module_id,eNB_index,
2206 2207 2208 2209 2210
               (SystemInformationBlockType18_r12_t *)NULL,
               (SystemInformationBlockType19_r12_t *)NULL,
               (SL_CommConfig_r12_t* )NULL,
               rrcConnectionReconfiguration_r8->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->sl_DiscConfig_r12
               );
2211 2212
      }
*/
2213

2214 2215
#if defined(ENABLE_ITTI)

2216 2217 2218 2219 2220 2221
      /* Check if there is dedicated NAS information to forward to NAS */
      if (rrcConnectionReconfiguration_r8->dedicatedInfoNASList != NULL) {
        int list_count;
        uint32_t pdu_length;
        uint8_t *pdu_buffer;
        MessageDef *msg_p;
2222

2223 2224 2225
        for (list_count = 0; list_count < rrcConnectionReconfiguration_r8->dedicatedInfoNASList->list.count; list_count++) {
          pdu_length = rrcConnectionReconfiguration_r8->dedicatedInfoNASList->list.array[list_count]->size;
          pdu_buffer = rrcConnectionReconfiguration_r8->dedicatedInfoNASList->list.array[list_count]->buf;
2226

2227 2228 2229 2230
          msg_p = itti_alloc_new_message(TASK_RRC_UE, NAS_CONN_ESTABLI_CNF);
          NAS_CONN_ESTABLI_CNF(msg_p).errCode = AS_SUCCESS;
          NAS_CONN_ESTABLI_CNF(msg_p).nasMsg.length = pdu_length;
          NAS_CONN_ESTABLI_CNF(msg_p).nasMsg.data = pdu_buffer;
2231

2232
          itti_send_msg_to_task(TASK_NAS_UE, ctxt_pP->instance, msg_p);
2233
        }
2234

2235 2236
        free (rrcConnectionReconfiguration_r8->dedicatedInfoNASList);
      }
2237

2238
#if ENABLE_RAL
2239 2240 2241 2242 2243 2244 2245 2246
      {
        MessageDef                                 *message_ral_p = NULL;
        rrc_ral_connection_reestablishment_ind_t    connection_reestablishment_ind;
        int                                         i;

        message_ral_p = itti_alloc_new_message (TASK_RRC_UE, RRC_RAL_CONNECTION_REESTABLISHMENT_IND);
        memset(&connection_reestablishment_ind, 0, sizeof(rrc_ral_connection_reestablishment_ind_t));
        // TO DO ral_si_ind.plmn_id        = 0;
2247
        connection_reestablishment_ind.ue_id            = ctxt_pP->rnti;
2248 2249 2250 2251 2252

        if (rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList != NULL) {
          connection_reestablishment_ind.num_drb      =
            rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList->list.count;

2253 2254 2255
          for (i=0; (
                 i<rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList->list.count)
               && (i < maxDRB); i++) {
2256 2257 2258
            // why minus 1 in RRC code for drb_identity ?
            connection_reestablishment_ind.drb_id[i]   =
              rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList->list.array[i]->drb_Identity;
2259
          }
2260 2261 2262 2263 2264 2265
        } else {
          connection_reestablishment_ind.num_drb      = 0;
        }

        if (rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->srb_ToAddModList != NULL) {
          connection_reestablishment_ind.num_srb      =
2266 2267
            rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->srb_ToAddModList->list.count +
            UE_rrc_inst[ctxt_pP->module_id].num_srb;
2268 2269

        } else {
2270
          connection_reestablishment_ind.num_srb      += UE_rrc_inst[ctxt_pP->module_id].num_srb;
2271 2272
        }

2273
        if (connection_reestablishment_ind.num_srb > 2) { // fixme: only 2 srbs can exist, adjust the value
2274
          connection_reestablishment_ind.num_srb =2;
2275
        }
2276 2277 2278 2279

        memcpy (&message_ral_p->ittiMsg, (void *) &connection_reestablishment_ind, sizeof(rrc_ral_connection_reestablishment_ind_t));
        //#warning "ue_mod_idP ? for instance ? => YES"
        LOG_I(RRC, "Sending RRC_RAL_CONNECTION_REESTABLISHMENT_IND to mRAL\n");
2280
        itti_send_msg_to_task (TASK_RAL_UE, ctxt_pP->instance, message_ral_p);
2281
      }
Lionel Gauthier's avatar
Lionel Gauthier committed
2282
#endif
2283
#endif
2284
    } // c1 present
2285
  } // critical extensions present
2286 2287
}

2288
/* 36.331, 5.3.5.4      Reception of an RRCConnectionReconfiguration including the mobilityControlInfo by the UE (handover) */
2289 2290 2291 2292 2293 2294 2295 2296
//-----------------------------------------------------------------------------
void
rrc_ue_process_mobilityControlInfo(
  const protocol_ctxt_t* const       ctxt_pP,
  const uint8_t                      eNB_index,
  struct MobilityControlInfo* const mobilityControlInfo
)
//-----------------------------------------------------------------------------
2297
{
2298
  /*
2299 2300
  DRB_ToReleaseList_t*  drb2release_list;
  DRB_Identity_t *lcid;
2301
   */
2302
  LOG_N(RRC,"Note: This function needs some updates\n");
2303

2304 2305 2306
  if(UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].T310_active == 1) {
    UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].T310_active = 0;
  }
2307

2308 2309
  UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].T304_active = 1;
  UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].T304_cnt = T304[mobilityControlInfo->t304];
2310

2311
  /*
2312 2313 2314
  drb2release_list = CALLOC (1, sizeof (*drb2release_list));
  lcid= CALLOC (1, sizeof (DRB_Identity_t)); // long
  for (*lcid=0;*lcid<NB_RB_MAX;*lcid++)
2315
  {
2316
    ASN_SEQUENCE_ADD (&(drb2release_list)->list,lcid);
2317
  }
2318
   */
2319
  //Removing SRB1 and SRB2 and DRB0
2320 2321 2322 2323 2324 2325 2326
  LOG_N(RRC,"[UE %d] : Update needed for rrc_pdcp_config_req (deprecated) and rrc_rlc_config_req commands(deprecated)\n", ctxt_pP->module_id);
  rrc_pdcp_config_req (ctxt_pP, SRB_FLAG_YES, CONFIG_ACTION_REMOVE, DCCH,UNDEF_SECURITY_MODE);
  rrc_rlc_config_req(ctxt_pP, SRB_FLAG_YES, MBMS_FLAG_NO, CONFIG_ACTION_REMOVE,ctxt_pP->module_id+DCCH,Rlc_info_am_config);
  rrc_pdcp_config_req (ctxt_pP, SRB_FLAG_YES, CONFIG_ACTION_REMOVE, DCCH1,UNDEF_SECURITY_MODE);
  rrc_rlc_config_req(ctxt_pP, SRB_FLAG_YES,CONFIG_ACTION_REMOVE, MBMS_FLAG_NO,ctxt_pP->module_id+DCCH1,Rlc_info_am_config);
  rrc_pdcp_config_req (ctxt_pP, SRB_FLAG_NO, CONFIG_ACTION_REMOVE, DTCH,UNDEF_SECURITY_MODE);
  rrc_rlc_config_req(ctxt_pP, SRB_FLAG_NO,CONFIG_ACTION_REMOVE, MBMS_FLAG_NO,ctxt_pP->module_id+DTCH,Rlc_info_um);
2327
  /*
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2328
  rrc_pdcp_config_asn1_req(NB_eNB_INST+ue_mod_idP,frameP, 0,eNB_index,
2329 2330 2331 2332 2333 2334 2335
         NULL, // SRB_ToAddModList
         NULL, // DRB_ToAddModList
         drb2release_list,
         0, // security mode
         NULL, // key rrc encryption
         NULL, // key rrc integrity
         NULL // key encryption
Cedric Roux's avatar
Cedric Roux committed
2336
#if defined(Rel10) || defined(Rel14)
2337
         ,NULL
Cedric Roux's avatar
Cedric Roux committed
2338
#endif
2339
         ,NULL);
2340

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2341
  rrc_rlc_config_asn1_req(NB_eNB_INST+ue_mod_idP, frameP,0,eNB_index,
2342 2343 2344
        NULL,// SRB_ToAddModList
        NULL,// DRB_ToAddModList
        drb2release_list // DRB_ToReleaseList
Cedric Roux's avatar
Cedric Roux committed
2345
#if defined(Rel10) || defined(Rel14)
2346
        ,NULL
Cedric Roux's avatar
Cedric Roux committed
2347
#endif
2348
        ,NULL);
2349
   */
2350

2351 2352 2353 2354

  //A little cleanup at RRC...
  //Copying current queue config to free RRC index
  /*
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2355 2356 2357
    memcpy((void *)UE_rrc_inst[ue_mod_idP].SRB1_config[~(7<<eNB_index)],(void *)UE_rrc_inst[ue_mod_idP].SRB1_config[7<<eNB_index],sizeof(SRB_ToAddMod_t));
    memcpy((void *)UE_rrc_inst[ue_mod_idP].SRB2_config[~(7<<eNB_index)],(void *)UE_rrc_inst[ue_mod_idP].SRB2_config[7<<eNB_index],sizeof(SRB_ToAddMod_t));
    memcpy((void *)UE_rrc_inst[ue_mod_idP].DRB_config[~(7<<eNB_index)][0],(void *)UE_rrc_inst[ue_mod_idP].DRB_config[7<<eNB_index][0],sizeof(DRB_ToAddMod_t));
2358
   */
2359 2360
  /*
  LOG_N(RRC,"Not sure if Freeing the current queue config works properly: Fix me\n");
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2361 2362 2363
  free((void *)&UE_rrc_inst[ue_mod_idP].SRB1_config[eNB_index]);
  free((void *)&UE_rrc_inst[ue_mod_idP].SRB2_config[eNB_index]);
  free((void *)&UE_rrc_inst[ue_mod_idP].DRB_config[eNB_index][0]);
2364

Lionel Gauthier's avatar
 
Lionel Gauthier committed
2365 2366 2367
  UE_rrc_inst[ue_mod_idP].SRB1_config[eNB_index] = NULL;
  UE_rrc_inst[ue_mod_idP].SRB2_config[eNB_index] = NULL;
  UE_rrc_inst[ue_mod_idP].DRB_config[eNB_index][0] = NULL;
2368
   */
2369
  //Synchronisation to DL of target cell
2370
  LOG_I(RRC,
Lionel Gauthier's avatar
Lionel Gauthier committed
2371
        "HO: Reset PDCP and RLC for configured RBs.. \n[FRAME %05d][RRC_UE][MOD %02d][][--- MAC_CONFIG_REQ  (SRB2 eNB %d) --->][MAC_UE][MOD %02d][]\n",
2372
        ctxt_pP->frame, ctxt_pP->module_id, eNB_index, ctxt_pP->module_id);
2373 2374

  // Reset MAC and configure PHY
2375 2376 2377 2378 2379
  rrc_mac_config_req_ue(ctxt_pP->module_id,
			0,
			eNB_index,
			(RadioResourceConfigCommonSIB_t *)NULL,
			(struct PhysicalConfigDedicated *)NULL,
Cedric Roux's avatar
Cedric Roux committed
2380
#if defined(Rel10) || defined(Rel14)
2381 2382
			(SCellToAddMod_r10_t *)NULL,
			//(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
2383
#endif
2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396
			(MeasObjectToAddMod_t **)NULL,
			(MAC_MainConfig_t *)NULL,
			0,
			(struct LogicalChannelConfig *)NULL,
			(MeasGapConfig_t *)NULL,
			(TDD_Config_t *)NULL,
			mobilityControlInfo,
			(uint8_t *)NULL,
			(uint16_t *)NULL,
			NULL,
			NULL,
			NULL,
			NULL
Cedric Roux's avatar
Cedric Roux committed
2397
#if defined(Rel10) || defined(Rel14)
2398 2399 2400
			,0,
			(MBSFN_AreaInfoList_r9_t *)NULL,
			(PMCH_InfoList_r9_t *)NULL
2401 2402
#endif
#ifdef CBA
2403 2404
			,0,
			0
2405 2406 2407
#endif
#if defined(Rel14)
           ,
2408
           0,
2409
           NULL,
2410
           NULL,
2411
           NULL
2412
#endif
2413
			);
2414

2415
  // Re-establish PDCP for all RBs that are established
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2416 2417 2418
  // rrc_pdcp_config_req (ue_mod_idP+NB_eNB_INST, frameP, 0, CONFIG_ACTION_ADD, ue_mod_idP+DCCH);
  // rrc_pdcp_config_req (ue_mod_idP+NB_eNB_INST, frameP, 0, CONFIG_ACTION_ADD, ue_mod_idP+DCCH1);
  // rrc_pdcp_config_req (ue_mod_idP+NB_eNB_INST, frameP, 0, CONFIG_ACTION_ADD, ue_mod_idP+DTCH);
2419 2420


2421
  // Re-establish RLC for all RBs that are established
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2422 2423 2424
  // rrc_rlc_config_req(ue_mod_idP+NB_eNB_INST,frameP,0,CONFIG_ACTION_ADD,ue_mod_idP+DCCH,SIGNALLING_RADIO_BEARER,Rlc_info_am_config);
  // rrc_rlc_config_req(ue_mod_idP+NB_eNB_INST,frameP,0,CONFIG_ACTION_ADD,ue_mod_idP+DCCH1,SIGNALLING_RADIO_BEARER,Rlc_info_am_config);
  // rrc_rlc_config_req(ue_mod_idP+NB_eNB_INST,frameP,0,CONFIG_ACTION_ADD,ue_mod_idP+DTCH,RADIO_ACCESS_BEARER,Rlc_info_um);
2425
  UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].State = RRC_SI_RECEIVED;
2426
}
2427 2428 2429 2430 2431 2432 2433 2434

//-----------------------------------------------------------------------------
void
rrc_detach_from_eNB(
  module_id_t ue_mod_idP,
  uint8_t eNB_index
)
//-----------------------------------------------------------------------------
2435
{
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2436
  //UE_rrc_inst[ue_mod_idP].DRB_config[eNB_index]
2437 2438
}

2439 2440 2441 2442 2443 2444 2445 2446 2447
//-----------------------------------------------------------------------------
void
rrc_ue_decode_dcch(
  const protocol_ctxt_t* const ctxt_pP,
  const rb_id_t                Srb_id,
  const uint8_t*         const Buffer,
  const uint8_t                eNB_indexP
)
//-----------------------------------------------------------------------------
2448
{
2449 2450 2451 2452

  //DL_DCCH_Message_t dldcchmsg;
  DL_DCCH_Message_t *dl_dcch_msg=NULL;//&dldcchmsg;
  //  asn_dec_rval_t dec_rval;
2453
  // int i;
2454
  uint8_t target_eNB_index=0xFF;
winckel's avatar
winckel committed
2455 2456 2457 2458
#if defined(ENABLE_ITTI)
  MessageDef *msg_p;
#endif

2459
  if (Srb_id != 1) {
2460
    LOG_E(RRC,"[UE %d] Frame %d: Received message on DL-DCCH (SRB%d), should not have ...\n",
2461
          ctxt_pP->module_id, ctxt_pP->frame, Srb_id);
2462
    return;
2463 2464 2465 2466 2467
  }

  //memset(dl_dcch_msg,0,sizeof(DL_DCCH_Message_t));

  // decode messages
Lionel Gauthier's avatar
 
Lionel Gauthier committed
2468
  //  LOG_D(RRC,"[UE %d] Decoding DL-DCCH message\n",ue_mod_idP);
2469 2470 2471 2472
  /*
  for (i=0;i<30;i++)
    LOG_T(RRC,"%x.",Buffer[i]);
  LOG_T(RRC, "\n");
2473
   */
2474
  uper_decode(NULL,
2475 2476 2477 2478
              &asn_DEF_DL_DCCH_Message,
              (void**)&dl_dcch_msg,
              (uint8_t*)Buffer,
              RRC_BUF_SIZE,0,0);
2479 2480 2481 2482 2483

#ifdef XER_PRINT
  xer_fprint(stdout,&asn_DEF_DL_DCCH_Message,(void*)dl_dcch_msg);
#endif

2484
#if defined(ENABLE_ITTI)
2485
# if defined(DISABLE_ITTI_XER_PRINT)
2486
  {
winckel's avatar
winckel committed
2487 2488
    msg_p = itti_alloc_new_message (TASK_RRC_UE, RRC_DL_DCCH_MESSAGE);
    memcpy (&msg_p->ittiMsg, (void *) dl_dcch_msg, sizeof(RrcDlDcchMessage));
2489

2490
    itti_send_msg_to_task (TASK_UNKNOWN, ctxt_pP->instance, msg_p);
2491
  }
2492 2493
# else
  {
2494
    char        message_string[30000];
2495
    size_t      message_string_size;
2496

2497
    //LOG_I(RRC, "Panos-D: rrc_ue_decode_dcch, Before xer_sprint() \n");
2498 2499 2500 2501
    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_DL_DCCH_Message, (void *)dl_dcch_msg)) > 0) {
      msg_p = itti_alloc_new_message_sized (TASK_RRC_UE, RRC_DL_DCCH, message_string_size + sizeof (IttiMsgText));
      msg_p->ittiMsg.rrc_dl_dcch.size = message_string_size;
      memcpy(&msg_p->ittiMsg.rrc_dl_dcch.text, message_string, message_string_size);
2502

2503
      itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
2504
    }
2505 2506
  }
# endif
2507 2508
#endif

2509 2510
  if (dl_dcch_msg->message.present == DL_DCCH_MessageType_PR_c1) {

2511
    if (UE_rrc_inst[ctxt_pP->module_id].Info[eNB_indexP].State >= RRC_CONNECTED) {
2512

2513
      switch (dl_dcch_msg->message.choice.c1.present) {
2514

2515
      case DL_DCCH_MessageType__c1_PR_NOTHING:
2516 2517
        LOG_I(RRC, "[UE %d] Frame %d : Received PR_NOTHING on DL-DCCH-Message\n",
              ctxt_pP->module_id, ctxt_pP->frame);
2518
        return;
winckel's avatar
RRC:  
winckel committed
2519

2520 2521
      case DL_DCCH_MessageType__c1_PR_csfbParametersResponseCDMA2000:
        break;
2522

2523
      case DL_DCCH_MessageType__c1_PR_dlInformationTransfer: {
winckel's avatar
RRC:  
winckel committed
2524
#if defined(ENABLE_ITTI)
2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542
        DLInformationTransfer_t *dlInformationTransfer = &dl_dcch_msg->message.choice.c1.choice.dlInformationTransfer;

        if ((dlInformationTransfer->criticalExtensions.present == DLInformationTransfer__criticalExtensions_PR_c1)
            && (dlInformationTransfer->criticalExtensions.choice.c1.present
                == DLInformationTransfer__criticalExtensions__c1_PR_dlInformationTransfer_r8)
            && (dlInformationTransfer->criticalExtensions.choice.c1.choice.dlInformationTransfer_r8.dedicatedInfoType.present
                == DLInformationTransfer_r8_IEs__dedicatedInfoType_PR_dedicatedInfoNAS)) {
          /* This message hold a dedicated info NAS payload, forward it to NAS */
          struct DLInformationTransfer_r8_IEs__dedicatedInfoType *dedicatedInfoType =
                &dlInformationTransfer->criticalExtensions.choice.c1.choice.dlInformationTransfer_r8.dedicatedInfoType;
          uint32_t pdu_length;
          uint8_t *pdu_buffer;
          MessageDef *msg_p;

          pdu_length = dedicatedInfoType->choice.dedicatedInfoNAS.size;
          pdu_buffer = dedicatedInfoType->choice.dedicatedInfoNAS.buf;

          msg_p = itti_alloc_new_message(TASK_RRC_UE, NAS_DOWNLINK_DATA_IND);
2543
          NAS_DOWNLINK_DATA_IND(msg_p).UEid = ctxt_pP->module_id; // TODO set the UEid to something else ?
2544 2545 2546
          NAS_DOWNLINK_DATA_IND(msg_p).nasMsg.length = pdu_length;
          NAS_DOWNLINK_DATA_IND(msg_p).nasMsg.data = pdu_buffer;

2547
          itti_send_msg_to_task(TASK_NAS_UE, ctxt_pP->instance, msg_p);
2548 2549
        }

winckel's avatar
RRC:  
winckel committed
2550
#endif
2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565
        break;
      }

      case DL_DCCH_MessageType__c1_PR_handoverFromEUTRAPreparationRequest:
        break;

      case DL_DCCH_MessageType__c1_PR_mobilityFromEUTRACommand:
        break;

      case DL_DCCH_MessageType__c1_PR_rrcConnectionReconfiguration:

        // first check if mobilityControlInfo  is present
        if (dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.mobilityControlInfo
            != NULL) {
          /* 36.331, 5.3.5.4 Reception of an RRCConnectionReconfiguration including the mobilityControlInfo by the UE (handover)*/
2566
          if (UE_rrc_inst[ctxt_pP->module_id].HandoverInfoUe.targetCellId
2567 2568
              != dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.mobilityControlInfo->targetPhysCellId) {
            LOG_W(RRC,
Cedric Roux's avatar
Cedric Roux committed
2569
                  "[UE %d] Frame %d: Handover target (%ld) is different from RSRP measured target (%ld)..\n",
2570 2571
                  ctxt_pP->module_id,
                  ctxt_pP->frame,
2572
                  dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.mobilityControlInfo->targetPhysCellId,
2573
                  UE_rrc_inst[ctxt_pP->module_id].HandoverInfoUe.targetCellId);
2574
            return;
2575
          } else if ((target_eNB_index = get_adjacent_cell_mod_id(UE_rrc_inst[ctxt_pP->module_id].HandoverInfoUe.targetCellId))
2576 2577
                     == 0xFF) {
            LOG_W(RRC,
2578 2579 2580
                  "[UE %d] Frame %d: ue_mod_idP of the target eNB not found, check the network topology\n",
                  ctxt_pP->module_id,
                  ctxt_pP->frame);
2581 2582 2583
            return;
          } else {
            LOG_I(RRC,
2584 2585 2586 2587
                  "[UE% d] Frame %d: Received rrcConnectionReconfiguration with mobilityControlInfo \n",
                  ctxt_pP->module_id,
                  ctxt_pP->frame);
            UE_rrc_inst[ctxt_pP->module_id].HandoverInfoUe.measFlag = 1; // Ready to send more MeasReports if required
2588
          }
2589
        }
2590

2591 2592 2593 2594
        rrc_ue_process_rrcConnectionReconfiguration(
          ctxt_pP,
          &dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration,
          eNB_indexP);
2595 2596

        if (target_eNB_index != 0xFF) {
2597 2598 2599
          rrc_ue_generate_RRCConnectionReconfigurationComplete(
            ctxt_pP,
            target_eNB_index,
2600
            dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.rrc_TransactionIdentifier);
2601 2602 2603 2604
          UE_rrc_inst[ctxt_pP->module_id].Info[eNB_indexP].State = RRC_HO_EXECUTION;
          UE_rrc_inst[ctxt_pP->module_id].Info[target_eNB_index].State = RRC_RECONFIGURED;
          LOG_I(RRC, "[UE %d] State = RRC_RECONFIGURED during HO (eNB %d)\n",
                ctxt_pP->module_id, target_eNB_index);
Lionel Gauthier's avatar
Lionel Gauthier committed
2605
#if defined(ENABLE_ITTI)
2606
#if ENABLE_RAL
2607 2608 2609 2610 2611 2612 2613
          {
            MessageDef                                 *message_ral_p = NULL;
            rrc_ral_connection_reconfiguration_ho_ind_t connection_reconfiguration_ho_ind;
            int                                         i;

            message_ral_p = itti_alloc_new_message (TASK_RRC_UE, RRC_RAL_CONNECTION_RECONFIGURATION_HO_IND);
            memset(&connection_reconfiguration_ho_ind, 0, sizeof(rrc_ral_connection_reconfiguration_ho_ind_t));
2614
            connection_reconfiguration_ho_ind.ue_id = ctxt_pP->module_id;
2615

2616 2617
            if (dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList
                != NULL) {
2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631
              connection_reconfiguration_ho_ind.num_drb      =
                dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList->list.count;

              for (i=0; (
                     i<dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList->list.count)
                   && (i < maxDRB); i++) {
                // why minus 1 in RRC code for drb_identity ?
                connection_reconfiguration_ho_ind.drb_id[i]   =
                  dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList->list.array[i]->drb_Identity;
              }
            } else {
              connection_reconfiguration_ho_ind.num_drb      = 0;
            }

2632 2633
            if (dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->srb_ToAddModList
                != NULL) {
2634
              connection_reconfiguration_ho_ind.num_srb      =
2635 2636 2637
                dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->srb_ToAddModList->list.count
                +
                UE_rrc_inst[ctxt_pP->module_id].num_srb;
2638
            } else {
2639
              connection_reconfiguration_ho_ind.num_srb      += UE_rrc_inst[ctxt_pP->module_id].num_srb;
2640 2641
            }

2642
            if (connection_reconfiguration_ho_ind.num_srb > 2 ) {
2643
              connection_reconfiguration_ho_ind.num_srb =2;
2644
            }
2645 2646 2647 2648

            memcpy (&message_ral_p->ittiMsg, (void *) &connection_reconfiguration_ho_ind, sizeof(rrc_ral_connection_reconfiguration_ho_ind_t));
            //#warning "ue_mod_idP ? for instance ? => YES"
            LOG_I(RRC, "Sending RRC_RAL_CONNECTION_RECONFIGURATION_HO_IND to mRAL\n");
2649
            itti_send_msg_to_task (TASK_RAL_UE, ctxt_pP->instance, message_ral_p);
2650
          }
Lionel Gauthier's avatar
Lionel Gauthier committed
2651 2652
#endif
#endif
2653
        } else {
2654 2655 2656
          rrc_ue_generate_RRCConnectionReconfigurationComplete(
            ctxt_pP,
            eNB_indexP,
2657
            dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.rrc_TransactionIdentifier);
2658 2659 2660 2661
          UE_rrc_inst[ctxt_pP->module_id].Info[eNB_indexP].State = RRC_RECONFIGURED;
          LOG_I(RRC, "[UE %d] State = RRC_RECONFIGURED (eNB %d)\n",
                ctxt_pP->module_id,
                eNB_indexP);
Lionel Gauthier's avatar
Lionel Gauthier committed
2662
#if defined(ENABLE_ITTI)
2663
#if ENABLE_RAL
2664 2665 2666 2667 2668 2669 2670
          {
            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_UE, RRC_RAL_CONNECTION_RECONFIGURATION_IND);
            memset(&connection_reconfiguration_ind, 0, sizeof(rrc_ral_connection_reconfiguration_ind_t));
2671
            connection_reconfiguration_ind.ue_id = ctxt_pP->module_id;
2672

2673 2674
            if (dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList
                != NULL) {
2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688
              connection_reconfiguration_ind.num_drb      =
                dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList->list.count;

              for (i=0; (
                     i<dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList->list.count)
                   && (i < maxDRB); i++) {
                // why minus 1 in RRC code for drb_identity ?
                connection_reconfiguration_ind.drb_id[i]   =
                  dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->drb_ToAddModList->list.array[i]->drb_Identity;
              }
            } else {
              connection_reconfiguration_ind.num_drb      = 0;
            }

2689 2690
            if (dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->srb_ToAddModList
                != NULL) {
2691
              connection_reconfiguration_ind.num_srb      =
2692 2693 2694
                dl_dcch_msg->message.choice.c1.choice.rrcConnectionReconfiguration.criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.radioResourceConfigDedicated->srb_ToAddModList->list.count
                +
                UE_rrc_inst[ctxt_pP->module_id].num_srb;
2695
            } else {
2696
              connection_reconfiguration_ind.num_srb      +=UE_rrc_inst[ctxt_pP->module_id].num_srb;
2697 2698
            }

2699
            if (connection_reconfiguration_ind.num_srb > 2 ) {
2700
              connection_reconfiguration_ind.num_srb =2;
2701
            }
2702 2703 2704 2705

            memcpy (&message_ral_p->ittiMsg, (void *) &connection_reconfiguration_ind, sizeof(rrc_ral_connection_reconfiguration_ind_t));
            //#warning "ue_mod_idP ? for instance ? => YES"
            LOG_I(RRC, "Sending RRC_RAL_CONNECTION_RECONFIGURATION_IND to mRAL\n");
2706
            itti_send_msg_to_task (TASK_RAL_UE, ctxt_pP->instance, message_ral_p);
2707
          }
Lionel Gauthier's avatar
Lionel Gauthier committed
2708 2709 2710
#endif
#endif

2711 2712
        }

2713
        //TTN test D2D (should not be here - in reality, this message will be triggered from ProSeApp)
2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728
        if (send_ue_information == 0) {
           LOG_I(RRC, "TEST SidelinkUEInformation [UE %d] Received  (eNB %d)\n",
                 ctxt_pP->module_id, eNB_indexP);
           SL_DestinationInfoList_r12_t *destinationInfoList = CALLOC(1, sizeof(SL_DestinationInfoList_r12_t));
           SL_DestinationIdentity_r12_t *sl_destination_identity = CALLOC(1, sizeof(SL_DestinationIdentity_r12_t));
           sl_destination_identity->size = 3;
           sl_destination_identity->buf = CALLOC(1,3);
           sl_destination_identity->buf[0] = 0x00;
           sl_destination_identity->buf[1] = 0x00;
           sl_destination_identity->buf[2] = 0x01;
           sl_destination_identity->bits_unused = 0;
           ASN_SEQUENCE_ADD(&destinationInfoList->list,sl_destination_identity);
           rrc_ue_generate_SidelinkUEInformation(ctxt_pP, eNB_indexP, destinationInfoList, NULL, SL_TRANSMIT_NON_RELAY_ONE_TO_ONE);
           send_ue_information ++;
        }
2729
        break;
2730

2731
      case DL_DCCH_MessageType__c1_PR_rrcConnectionRelease:
2732
#if defined(ENABLE_ITTI)
2733 2734 2735 2736 2737 2738 2739 2740 2741
        msg_p = itti_alloc_new_message(TASK_RRC_UE, NAS_CONN_RELEASE_IND);

        if ((dl_dcch_msg->message.choice.c1.choice.rrcConnectionRelease.criticalExtensions.present
             == RRCConnectionRelease__criticalExtensions_PR_c1)
            && (dl_dcch_msg->message.choice.c1.choice.rrcConnectionRelease.criticalExtensions.choice.c1.present
                == RRCConnectionRelease__criticalExtensions__c1_PR_rrcConnectionRelease_r8)) {
          NAS_CONN_RELEASE_IND(msg_p).cause =
            dl_dcch_msg->message.choice.c1.choice.rrcConnectionRelease.criticalExtensions.choice.c1.choice.rrcConnectionRelease_r8.releaseCause;
        }
winckel's avatar
winckel committed
2742

2743
        itti_send_msg_to_task(TASK_NAS_UE, ctxt_pP->instance, msg_p);
2744
#if ENABLE_RAL
2745
        msg_p = itti_alloc_new_message(TASK_RRC_UE, RRC_RAL_CONNECTION_RELEASE_IND);
2746 2747
        RRC_RAL_CONNECTION_RELEASE_IND(msg_p).ue_id = ctxt_pP->module_id;
        itti_send_msg_to_task(TASK_RAL_UE, ctxt_pP->instance, msg_p);
Lionel Gauthier's avatar
Lionel Gauthier committed
2748
#endif
2749
#endif
2750
        break;
2751

2752
      case DL_DCCH_MessageType__c1_PR_securityModeCommand:
2753 2754 2755 2756 2757 2758
        LOG_I(RRC, "[UE %d] Received securityModeCommand (eNB %d)\n",
              ctxt_pP->module_id, eNB_indexP);
        rrc_ue_process_securityModeCommand(
          ctxt_pP,
          &dl_dcch_msg->message.choice.c1.choice.securityModeCommand,
          eNB_indexP);
2759
        break;
2760

2761
      case DL_DCCH_MessageType__c1_PR_ueCapabilityEnquiry:
2762 2763 2764 2765 2766 2767 2768
        LOG_I(RRC, "[UE %d] Received Capability Enquiry (eNB %d)\n",
              ctxt_pP->module_id,
              eNB_indexP);
        rrc_ue_process_ueCapabilityEnquiry(
          ctxt_pP,
          &dl_dcch_msg->message.choice.c1.choice.ueCapabilityEnquiry,
          eNB_indexP);
2769
        break;
2770

2771 2772
      case DL_DCCH_MessageType__c1_PR_counterCheck:
        break;
winckel's avatar
RRC:  
winckel committed
2773

Cedric Roux's avatar
Cedric Roux committed
2774
#if defined(Rel10) || defined(Rel14)
2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788

      case DL_DCCH_MessageType__c1_PR_ueInformationRequest_r9:
        break;

      case DL_DCCH_MessageType__c1_PR_loggedMeasurementConfiguration_r10:
        break;

      case DL_DCCH_MessageType__c1_PR_rnReconfiguration_r10:
        break;
#endif

      case DL_DCCH_MessageType__c1_PR_spare1:
      case DL_DCCH_MessageType__c1_PR_spare2:
      case DL_DCCH_MessageType__c1_PR_spare3:
Cedric Roux's avatar
Cedric Roux committed
2789
#if !defined(Rel14)
2790
      case DL_DCCH_MessageType__c1_PR_spare4:
Cedric Roux's avatar
Cedric Roux committed
2791
#endif
2792 2793 2794 2795
        break;

      default:
        break;
2796
      }
2797
    }
2798
  }
2799

2800
#ifndef NO_RRM
2801
  send_msg(&S_rrc,msg_rrc_end_scan_req(ctxt_pP->module_id,eNB_indexP));
2802 2803 2804
#endif
}

2805
const char siWindowLength[8][5] = {"1ms","2ms","5ms","10ms","15ms","20ms","40ms","ERR"};
2806 2807
const char siWindowLength_int[7] = {1,2,5,10,15,20,40};

2808 2809
const char SIBType[12][6] = {"SIB3","SIB4","SIB5","SIB6","SIB7","SIB8","SIB9","SIB10","SIB11","SIB12","SIB13","Spare"};
const char SIBPeriod[8][6]= {"rf8","rf16","rf32","rf64","rf128","rf256","rf512","ERR"};
2810 2811
int siPeriod_int[7] = {80,160,320,640,1280,2560,5120};

2812
const char* SIBreserved( long value )
2813 2814 2815 2816 2817 2818 2819 2820 2821
{
  if (value < 0 || value > 1)
    return "ERR";

  if (value)
    return "notReserved";

  return "reserved";
}
2822
const char* SIBbarred( long value )
2823 2824 2825 2826 2827 2828 2829 2830 2831
{
  if (value < 0 || value > 1)
    return "ERR";

  if (value)
    return "notBarred";

  return "barred";
}
2832
const char* SIBallowed( long value )
2833 2834 2835 2836 2837 2838 2839 2840 2841
{
  if (value < 0 || value > 1)
    return "ERR";

  if (value)
    return "notAllowed";

  return "allowed";
}
2842
const char* SIB2SoundingPresent( int value )
2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856
{
  switch (value) {
  case SoundingRS_UL_ConfigCommon_PR_NOTHING:
    return "NOTHING";

  case SoundingRS_UL_ConfigCommon_PR_release:
    return "release";

  case SoundingRS_UL_ConfigCommon_PR_setup:
    return "setup";
  }

  return "ERR";
}
2857
const char* SIB2numberOfRA_Preambles( long value )
2858 2859 2860 2861 2862 2863
{
  static char temp[4] = {0};

  if (value < 0 || value > 15)
    return "ERR";

2864
  snprintf( temp, sizeof(temp), "n%ld", value*4 + 4 );
2865 2866 2867
  temp[3] = 0; // terminate string
  return temp;
}
2868
const char* SIB2powerRampingStep( long value )
2869 2870 2871 2872 2873 2874 2875
{
  if (value < 0 || value > 3)
    return "ERR";

  static const char str[4][4] = {"dB0","dB2","dB4","dB6"};
  return str[value];
}
2876
const char* SIB2preambleInitialReceivedTargetPower( long value )
2877 2878 2879 2880 2881 2882
{
  static char temp[8] = {0};

  if (value < 0 || value > 15)
    return "ERR";

2883
  snprintf( temp, sizeof(temp), "dBm-%ld", 120 - value*2 );
2884 2885 2886
  temp[7] = 0; // terminate string
  return temp;
}
2887
const char* SIB2preambleTransMax( long value )
2888 2889 2890 2891 2892 2893 2894
{
  static char temp[5] = {0};

  if (value < 0 || value > 10)
    return "ERR";

  if (value <= 5) {
2895
    snprintf( temp, sizeof(temp), "n%ld", value+3 );
2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914
    return temp;
  }

  switch (value) {
  case 6:
    return "n10";

  case 7:
    return "n20";

  case 8:
    return "n50";

  case 9:
    return "n100";

  case 10:
    return "n200";
  }
Cedric Roux's avatar
Cedric Roux committed
2915 2916 2917

  /* unreachable but gcc warns... */
  return "ERR";
2918
}
2919
const char* SIB2ra_ResponseWindowSize( long value )
2920 2921 2922 2923 2924 2925 2926 2927 2928
{
  static char temp[4] = {0};

  if (value < 0 || value > 7)
    return "ERR";

  if (value == 7)
    return "sf10";

2929
  snprintf( temp, sizeof(temp), "sf%ld", value+2 );
2930 2931
  return temp;
}
2932
const char* SIB2mac_ContentionResolutionTimer( long value )
2933 2934 2935 2936 2937 2938
{
  static char temp[5] = {0};

  if (value < 0 || value > 7)
    return "ERR";

2939
  snprintf( temp, sizeof(temp), "sf%ld", 8 + value*8 );
2940 2941
  return temp;
}
2942
const char* SIB2modificationPeriodCoeff( long value )
2943
{
Cedric Roux's avatar
Cedric Roux committed
2944
  static char temp[32] = {0};
2945 2946 2947 2948 2949 2950 2951

  if (value < 0 || value > 3)
    return "ERR";

  snprintf( temp, sizeof(temp), "n%d", (int)pow(2,value+1) );
  return temp;
}
2952
const char* SIB2defaultPagingCycle( long value )
2953
{
Cedric Roux's avatar
Cedric Roux committed
2954
  static char temp[32] = {0};
2955 2956 2957 2958 2959 2960 2961

  if (value < 0 || value > 3)
    return "ERR";

  snprintf( temp, sizeof(temp), "rf%d", (int)pow(2,value+4) );
  return temp;
}
2962
const char* SIB2nB( long value )
2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973
{
  if (value < 0 || value > 7)
    return "ERR";

  static const char str[8][17] = {"fourT","twoT","oneT","halfT","quarterT","oneEigthT","oneSixteenthT","oneThirtySecondT"};
  return str[value];
}




2974
//-----------------------------------------------------------------------------
2975
int decode_BCCH_DLSCH_Message(
2976 2977 2978 2979 2980
  const protocol_ctxt_t* const ctxt_pP,
  const uint8_t                eNB_index,
  uint8_t*               const Sdu,
  const uint8_t                Sdu_len,
  const uint8_t                rsrq,
2981
  const uint8_t                rsrp )
Lionel Gauthier's avatar
Lionel Gauthier committed
2982
{
2983
  BCCH_DL_SCH_Message_t *bcch_message = NULL;
2984 2985
  SystemInformationBlockType1_t* sib1 = UE_rrc_inst[ctxt_pP->module_id].sib1[eNB_index];
  int i;
2986

2987
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_BCCH, VCD_FUNCTION_IN );
2988

2989 2990 2991 2992
  if (((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&1) == 1) &&  // SIB1 received
      (UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIcnt == sib1->schedulingInfoList.list.count)) {
    // Avoid decoding  SystemInformationBlockType1_t* sib1 = UE_rrc_inst[ctxt_pP->module_id].sib1[eNB_index];
    // to prevent memory bloating
2993
    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_BCCH, VCD_FUNCTION_OUT );
2994
    return 0;
2995
  }
2996

matzakos's avatar
matzakos committed
2997
  // Temporary better solution should be found for nfapi_mode=3
2998 2999
  /*if(UE_rrc_inst[ctxt_pP->module_id].RrcState == RRC_STATE_INACTIVE && nfapi_mode==3)
	  UE_rrc_inst[ctxt_pP->module_id].RrcState = RRC_STATE_IDLE;*/
matzakos's avatar
matzakos committed
3000 3001

  //LOG_I(RRC, "decode_BCCH_DLSCH_Message before calling rrc_set_sub_state() \n");
3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013
  rrc_set_sub_state( ctxt_pP->module_id, RRC_SUB_STATE_IDLE_RECEIVING_SIB );

  asn_dec_rval_t dec_rval = uper_decode_complete( NULL,
                            &asn_DEF_BCCH_DL_SCH_Message,
                            (void **)&bcch_message,
                            (const void *)Sdu,
                            Sdu_len );

  if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0)) {
    LOG_E( RRC, "[UE %"PRIu8"] Failed to decode BCCH_DLSCH_MESSAGE (%zu bits)\n",
           ctxt_pP->module_id,
           dec_rval.consumed );
3014 3015 3016
    for (i=0;i<Sdu_len;i++)
      printf("%02x ",Sdu[i]);
    printf("\n");
3017 3018 3019 3020 3021
    // free the memory
    SEQUENCE_free( &asn_DEF_BCCH_DL_SCH_Message, (void*)bcch_message, 1 );
    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_BCCH, VCD_FUNCTION_OUT );
    return -1;
  }
3022 3023

#if defined(ENABLE_ITTI)
3024
# if defined(DISABLE_ITTI_XER_PRINT)
3025 3026
  {
    MessageDef *msg_p;
3027

3028 3029
    msg_p = itti_alloc_new_message (TASK_RRC_UE, RRC_DL_BCCH_MESSAGE);
    memcpy (&msg_p->ittiMsg, (void *) bcch_message, sizeof(RrcDlBcchMessage));
3030

3031 3032
    itti_send_msg_to_task (TASK_UNKNOWN, ctxt_pP->instance, msg_p);
  }
3033
# else
3034 3035 3036
  {
    char        message_string[15000];
    size_t      message_string_size;
3037

3038
    //LOG_I(RRC, "Panos-D: decode_BCCH_DLSCH_Message, Before xer_sprint() \n");
3039 3040
    if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_BCCH_DL_SCH_Message, (void *)bcch_message)) > 0) {
      MessageDef *msg_p;
3041

3042 3043 3044
      msg_p = itti_alloc_new_message_sized (TASK_RRC_UE, RRC_DL_BCCH, message_string_size + sizeof (IttiMsgText));
      msg_p->ittiMsg.rrc_dl_bcch.size = message_string_size;
      memcpy(&msg_p->ittiMsg.rrc_dl_bcch.text, message_string, message_string_size);
winckel's avatar
winckel committed
3045

3046
      itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p);
3047
    }
3048
  }
3049
# endif
3050 3051
#endif

3052 3053 3054 3055 3056
  if (bcch_message->message.present == BCCH_DL_SCH_MessageType_PR_c1) {
    switch (bcch_message->message.choice.c1.present) {
    case BCCH_DL_SCH_MessageType__c1_PR_systemInformationBlockType1:
      if ((ctxt_pP->frame % 2) == 0) {
        // even frame
3057
        if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&1) == 0) {
3058 3059 3060 3061 3062
          SystemInformationBlockType1_t* sib1 = UE_rrc_inst[ctxt_pP->module_id].sib1[eNB_index];
          memcpy( (void*)sib1,
                  (void*)&bcch_message->message.choice.c1.choice.systemInformationBlockType1,
                  sizeof(SystemInformationBlockType1_t) );
          LOG_D( RRC, "[UE %"PRIu8"] Decoding First SIB1\n", ctxt_pP->module_id );
3063

3064
          //LOG_I( RRC, "Panos-D: decode_BCCH_DLSCH_Message1 BEFORE decode_SIB1");
3065
          //printf("Panos-D: decode_BCCH_DLSCH_Message1 BEFORE decode_SIB1");
3066
          decode_SIB1( ctxt_pP, eNB_index, rsrq, rsrp );
3067
        }
3068
      }
3069

3070
      break;
3071

3072
    case BCCH_DL_SCH_MessageType__c1_PR_systemInformation:
3073
      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&1) == 1) {
3074
        // SIB1 with schedulingInfoList is available
3075

3076 3077 3078 3079
        SystemInformation_t* si = UE_rrc_inst[ctxt_pP->module_id].si[eNB_index];
        memcpy( si,
                &bcch_message->message.choice.c1.choice.systemInformation,
                sizeof(SystemInformation_t) );
3080

3081 3082 3083
        LOG_D( RRC, "[UE %"PRIu8"] Decoding SI for frameP %"PRIu32"\n",
               ctxt_pP->module_id,
               ctxt_pP->frame );
3084
        //LOG_I( RRC, "Panos-D: decode_BCCH_DLSCH_Message1 BEFORE OTHER decode_SI");
3085
        //printf("Panos-D: decode_BCCH_DLSCH_Message1 BEFORE OTHER decode_SI");
3086
        decode_SI( ctxt_pP, eNB_index );
3087 3088
        //if (nfapi_mode == 3)
        	UE_mac_inst[ctxt_pP->module_id].SI_Decoded = 1;
3089
      }
3090 3091 3092 3093 3094 3095

      break;

    case BCCH_DL_SCH_MessageType__c1_PR_NOTHING:
    default:
      break;
3096
    }
3097
  }
winckel's avatar
winckel committed
3098

3099

3100
  if ((rrc_get_sub_state(ctxt_pP->module_id) == RRC_SUB_STATE_IDLE_SIB_COMPLETE)
3101
#if defined(ENABLE_USE_MME)
3102
      && (UE_rrc_inst[ctxt_pP->module_id].initialNasMsg.data != NULL)
3103
#endif
3104
     ) {
3105
	//printf("Panos-D: decode_BCCH_DLSCH_Message() BEFORE calling rrc_ue_generate_RRCConnectionRequest \n \n");
3106
    rrc_ue_generate_RRCConnectionRequest(ctxt_pP, 0);
3107
    rrc_set_sub_state( ctxt_pP->module_id, RRC_SUB_STATE_IDLE_CONNECTING );
winckel's avatar
winckel committed
3108 3109
  }

3110
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_BCCH, VCD_FUNCTION_OUT );
3111 3112

  return 0;
3113 3114
}

3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147
//-----------------------------------------------------------------------------
int decode_PCCH_DLSCH_Message(
  const protocol_ctxt_t* const ctxt_pP,
  const uint8_t                eNB_index,
  uint8_t*               const Sdu,
  const uint8_t                Sdu_len)
{
  PCCH_Message_t *pcch_message = NULL;
  int i;

  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_PCCH, VCD_FUNCTION_IN );

  asn_dec_rval_t dec_rval = uper_decode_complete( NULL,
                            &asn_DEF_PCCH_Message,
                            (void **)&pcch_message,
                            (const void *)Sdu,
                            Sdu_len );

  if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0)) {
    LOG_E( RRC, "[UE %"PRIu8"] Failed to decode PCCH_MESSAGE (%zu bits)\n",
           ctxt_pP->module_id,
           dec_rval.consumed );
    for (i=0;i<Sdu_len;i++)
      printf("%02x ",Sdu[i]);
    printf("\n");
    // free the memory
    SEQUENCE_free( &asn_DEF_PCCH_Message, (void*)pcch_message, 1 );
    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_UE_DECODE_PCCH, VCD_FUNCTION_OUT );
    return -1;
  }

  return(0);
}
3148

3149
//-----------------------------------------------------------------------------
3150
int decode_SIB1( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index, const uint8_t rsrq, const uint8_t rsrp )
Lionel Gauthier's avatar
Lionel Gauthier committed
3151
{
3152
  SystemInformationBlockType1_t* sib1 = UE_rrc_inst[ctxt_pP->module_id].sib1[eNB_index];
3153

3154
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_UE_DECODE_SIB1, VCD_FUNCTION_IN );
3155

3156
  LOG_I( RRC, "[UE %d] : Dumping SIB 1\n", ctxt_pP->module_id );
3157

3158
  PLMN_Identity_t *PLMN_identity = &sib1->cellAccessRelatedInfo.plmn_IdentityList.list.array[0]->plmn_Identity;
3159

3160 3161 3162 3163
  int mccdigits = PLMN_identity->mcc->list.count;
  int mncdigits = PLMN_identity->mnc.list.count;

  int mcc;
3164

3165
  if (mccdigits == 2) {
3166 3167
    mcc = *PLMN_identity->mcc->list.array[0]*10 + *PLMN_identity->mcc->list.array[1];
  } else {
3168 3169
    mcc = *PLMN_identity->mcc->list.array[0]*100 + *PLMN_identity->mcc->list.array[1]*10 + *PLMN_identity->mcc->list.array[2];
  }
3170

3171 3172
  int mnc;

3173
  if (mncdigits == 2) {
3174
    mnc = *PLMN_identity->mnc.list.array[0]*10 + *PLMN_identity->mnc.list.array[1];
3175
  } else {
3176 3177
    mnc = *PLMN_identity->mnc.list.array[0]*100 + *PLMN_identity->mnc.list.array[1]*10 + *PLMN_identity->mnc.list.array[2];
  }
3178

3179 3180 3181 3182
  int tac = 0;

  if (sib1->cellAccessRelatedInfo.trackingAreaCode.size == 2) {
    tac = (sib1->cellAccessRelatedInfo.trackingAreaCode.buf[0]<<8) + sib1->cellAccessRelatedInfo.trackingAreaCode.buf[1];
3183
  }
3184

3185 3186 3187 3188 3189 3190
  LOG_I( RRC, "PLMN MCC %0*d, MNC %0*d, TAC 0x%04x\n", mccdigits, mcc, mncdigits, mnc, tac );
  long cellReservedForOperatorUse = sib1->cellAccessRelatedInfo.plmn_IdentityList.list.array[0]->cellReservedForOperatorUse;
  LOG_I( RRC, "cellReservedForOperatorUse                 : raw:%ld decoded:%s\n", cellReservedForOperatorUse, SIBreserved(cellReservedForOperatorUse) );

  // search internal table for provider name
  int plmn_ind = 0;
3191

3192 3193 3194
  while (plmn_data[plmn_ind].mcc > 0) {
    if ((plmn_data[plmn_ind].mcc == mcc) && (plmn_data[plmn_ind].mnc == mnc)) {
      LOG_I( RRC, "Found %s (name from internal table)\n", plmn_data[plmn_ind].oper_short );
3195 3196
      break;
    }
3197

3198 3199
    plmn_ind++;
  }
3200

3201 3202
  if (plmn_data[plmn_ind].mcc < 0) {
    LOG_I( RRC, "Found Unknown operator (no entry in internal table)\n" );
3203
  }
3204

3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223
  LOG_I( RRC, "cellAccessRelatedInfo.cellIdentity         : raw:%"PRIu32" decoded:%02x.%02x.%02x.%02x\n",
         BIT_STRING_to_uint32( &sib1->cellAccessRelatedInfo.cellIdentity ),
         sib1->cellAccessRelatedInfo.cellIdentity.buf[0],
         sib1->cellAccessRelatedInfo.cellIdentity.buf[1],
         sib1->cellAccessRelatedInfo.cellIdentity.buf[2],
         sib1->cellAccessRelatedInfo.cellIdentity.buf[3] >> sib1->cellAccessRelatedInfo.cellIdentity.bits_unused);

  long cellBarred = sib1->cellAccessRelatedInfo.cellBarred;
  LOG_I( RRC, "cellAccessRelatedInfo.cellBarred           : raw:%ld decoded:%s\n", cellBarred, SIBbarred(cellBarred) );
  long intraFreqReselection = sib1->cellAccessRelatedInfo.intraFreqReselection;
  LOG_I( RRC, "cellAccessRelatedInfo.intraFreqReselection : raw:%ld decoded:%s\n", intraFreqReselection, SIBallowed(intraFreqReselection) );
  LOG_I( RRC, "cellAccessRelatedInfo.csg_Indication       : %d\n", sib1->cellAccessRelatedInfo.csg_Indication );

  if (sib1->cellAccessRelatedInfo.csg_Identity)
    LOG_I( RRC, "cellAccessRelatedInfo.csg_Identity         : %"PRIu32"\n", BIT_STRING_to_uint32(sib1->cellAccessRelatedInfo.csg_Identity) );
  else
    LOG_I( RRC, "cellAccessRelatedInfo.csg_Identity         : not defined\n" );

  LOG_I( RRC, "cellSelectionInfo.q_RxLevMin               : %ld\n", sib1->cellSelectionInfo.q_RxLevMin );
3224

3225 3226 3227 3228
  if (sib1->cellSelectionInfo.q_RxLevMinOffset)
    LOG_I( RRC, "cellSelectionInfo.q_RxLevMinOffset         : %ld\n", *sib1->cellSelectionInfo.q_RxLevMinOffset );
  else
    LOG_I( RRC, "cellSelectionInfo.q_RxLevMinOffset         : not defined\n" );
3229

3230 3231 3232 3233
  if (sib1->p_Max)
    LOG_I( RRC, "p_Max                                      : %ld\n", *sib1->p_Max );
  else
    LOG_I( RRC, "p_Max                                      : not defined\n" );
3234

3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248
  LOG_I( RRC, "freqBandIndicator                          : %ld\n", sib1->freqBandIndicator );

  if (sib1->schedulingInfoList.list.count > 0) {
    for (int i=0; i<sib1->schedulingInfoList.list.count; i++) {
      LOG_I( RRC, "si_Periodicity[%d]                          : %s\n", i, SIBPeriod[min(sib1->schedulingInfoList.list.array[i]->si_Periodicity,7)]);

      if (sib1->schedulingInfoList.list.array[i]->sib_MappingInfo.list.count > 0) {
        char temp[32 * sizeof(SIBType[0])] = {0}; // maxSIB==32

        for (int j=0; j<sib1->schedulingInfoList.list.array[i]->sib_MappingInfo.list.count; j++) {
          sprintf( temp + j*sizeof(SIBType[0]), "%*s ", (int)sizeof(SIBType[0])-1, SIBType[min(*sib1->schedulingInfoList.list.array[i]->sib_MappingInfo.list.array[0],11)] );
        }

        LOG_I( RRC, "siSchedulingInfoSIBType[%d]                 : %s\n", i, temp );
3249
      } else {
3250
        LOG_I( RRC, "mapping list %d is null\n", i );
3251
      }
3252 3253
    }
  } else {
3254
    LOG_E( RRC, "siSchedulingInfoPeriod[0]                  : PROBLEM!!!\n" );
3255
    return -1;
3256 3257
  }

3258 3259 3260
  if (sib1->tdd_Config) {
    LOG_I( RRC, "TDD subframeAssignment                     : %ld\n", sib1->tdd_Config->subframeAssignment );
    LOG_I( RRC, "TDD specialSubframePatterns                : %ld\n", sib1->tdd_Config->specialSubframePatterns );
3261 3262
  }

3263 3264 3265 3266 3267
  LOG_I( RRC, "siWindowLength                             : %s\n", siWindowLength[min(sib1->si_WindowLength,7)] );
  LOG_I( RRC, "systemInfoValueTag                         : %ld\n", sib1->systemInfoValueTag );

  UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIperiod     = siPeriod_int[sib1->schedulingInfoList.list.array[0]->si_Periodicity];
  UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIwindowsize = siWindowLength_int[sib1->si_WindowLength];
3268
  LOG_I( RRC, "[FRAME unknown][RRC_UE][MOD %02"PRIu8"][][--- MAC_CONFIG_REQ (SIB1 params eNB %"PRIu8") --->][MAC_UE][MOD %02"PRIu8"][]\n",
3269 3270
         ctxt_pP->module_id, eNB_index, ctxt_pP->module_id );

3271 3272 3273
  rrc_mac_config_req_ue(ctxt_pP->module_id, 0, eNB_index,
			(RadioResourceConfigCommonSIB_t *)NULL,
			(struct PhysicalConfigDedicated *)NULL,
Cedric Roux's avatar
Cedric Roux committed
3274
#if defined(Rel10) || defined(Rel14)
3275 3276
			(SCellToAddMod_r10_t *)NULL,
			//(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
3277
#endif
3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290
			(MeasObjectToAddMod_t **)NULL,
			(MAC_MainConfig_t *)NULL,
			0,
			(struct LogicalChannelConfig *)NULL,
			(MeasGapConfig_t *)NULL,
			UE_rrc_inst[ctxt_pP->module_id].sib1[eNB_index]->tdd_Config,
			(MobilityControlInfo_t *) NULL,
			&UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIwindowsize,
			&UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIperiod,
			NULL,
			NULL,
			NULL,
			(MBSFN_SubframeConfigList_t *)NULL
Cedric Roux's avatar
Cedric Roux committed
3291
#if defined(Rel10) || defined(Rel14)
3292 3293 3294
			,0,
			(MBSFN_AreaInfoList_r9_t *)NULL,
			(PMCH_InfoList_r9_t *)NULL
3295

3296 3297
#endif
#ifdef CBA
3298 3299 3300
			,
			0,
			0
3301 3302 3303
#endif
#if defined(Rel14)
           ,
3304
           0,
3305
           NULL,
3306
           NULL,
3307
           NULL
3308
#endif
3309
			);
3310

3311
  UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus = 1;
3312
  UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIB1systemInfoValueTag = sib1->systemInfoValueTag;
3313 3314 3315 3316 3317

#if defined(ENABLE_ITTI) && defined(ENABLE_USE_MME)
  {
    int cell_valid = 0;

3318
    if (sib1->cellAccessRelatedInfo.cellBarred == SystemInformationBlockType1__cellAccessRelatedInfo__cellBarred_notBarred) {
3319 3320 3321 3322
      /* Cell is not barred */
      int plmn;
      int plmn_number;

3323
      plmn_number = sib1->cellAccessRelatedInfo.plmn_IdentityList.list.count;
3324 3325 3326 3327 3328

      /* Compare requested PLMN and PLMNs from SIB1*/
      for (plmn = 0; plmn < plmn_number; plmn++) {
        PLMN_Identity_t *plmn_Identity;

3329
        plmn_Identity = &sib1->cellAccessRelatedInfo.plmn_IdentityList.list.array[plmn]->plmn_Identity;
3330

3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351
        if (
          (
            (plmn_Identity->mcc == NULL)
            ||
            (
              (UE_rrc_inst[ctxt_pP->module_id].plmnID.MCCdigit1 == *(plmn_Identity->mcc->list.array[0])) &&
              (UE_rrc_inst[ctxt_pP->module_id].plmnID.MCCdigit2 == *(plmn_Identity->mcc->list.array[1])) &&
              (UE_rrc_inst[ctxt_pP->module_id].plmnID.MCCdigit3 == *(plmn_Identity->mcc->list.array[2]))
            )
          )
          &&
          (UE_rrc_inst[ctxt_pP->module_id].plmnID.MNCdigit1 == *(plmn_Identity->mnc.list.array[0]))
          &&
          (UE_rrc_inst[ctxt_pP->module_id].plmnID.MNCdigit2 == *(plmn_Identity->mnc.list.array[1]))
          &&
          (
            ((UE_rrc_inst[ctxt_pP->module_id].plmnID.MNCdigit3 == 0xf) && (plmn_Identity->mnc.list.count == 2))
            ||
            (UE_rrc_inst[ctxt_pP->module_id].plmnID.MNCdigit3 == *(plmn_Identity->mnc.list.array[2]))
          )
        ) {
3352 3353 3354 3355 3356
          /* PLMN match, send a confirmation to NAS */
          MessageDef  *msg_p;

          msg_p = itti_alloc_new_message(TASK_RRC_UE, NAS_CELL_SELECTION_CNF);
          NAS_CELL_SELECTION_CNF (msg_p).errCode = AS_SUCCESS;
3357 3358
          NAS_CELL_SELECTION_CNF (msg_p).cellID = BIT_STRING_to_uint32(&sib1->cellAccessRelatedInfo.cellIdentity);
          NAS_CELL_SELECTION_CNF (msg_p).tac = BIT_STRING_to_uint16(&sib1->cellAccessRelatedInfo.trackingAreaCode);
3359 3360 3361 3362
          NAS_CELL_SELECTION_CNF (msg_p).rat = 0xFF;
          NAS_CELL_SELECTION_CNF (msg_p).rsrq = rsrq;
          NAS_CELL_SELECTION_CNF (msg_p).rsrp = rsrp;

3363
          itti_send_msg_to_task(TASK_NAS_UE, ctxt_pP->instance, msg_p);
3364 3365
          cell_valid = 1;
          break;
3366
        }
3367
      }
3368 3369
    }

3370 3371 3372
    if (cell_valid == 0) {
      /* Cell can not be used, ask PHY to try the next one */
      MessageDef  *msg_p;
3373

3374
      msg_p = itti_alloc_new_message(TASK_RRC_UE, PHY_FIND_NEXT_CELL_REQ);
3375

3376
      itti_send_msg_to_task(TASK_PHY_UE, ctxt_pP->instance, msg_p);
3377
    }
3378 3379 3380
  }
#endif

3381
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_UE_DECODE_SIB1, VCD_FUNCTION_OUT );
3382

3383
  return 0;
3384 3385 3386
}


3387
//-----------------------------------------------------------------------------
3388
 void dump_sib2( SystemInformationBlockType2_t *sib2 )
Lionel Gauthier's avatar
Lionel Gauthier committed
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 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431
  // ac_BarringInfo
  if (sib2->ac_BarringInfo) {
    LOG_I( RRC, "ac_BarringInfo->ac_BarringForEmergency : %d\n",
           sib2->ac_BarringInfo->ac_BarringForEmergency );

    if (sib2->ac_BarringInfo->ac_BarringForMO_Signalling) {
      LOG_I( RRC, "ac_BarringInfo->ac_BarringForMO_Signalling->ac_BarringFactor       : %ld\n",
             sib2->ac_BarringInfo->ac_BarringForMO_Signalling->ac_BarringFactor );
      LOG_I( RRC, "ac_BarringInfo->ac_BarringForMO_Signalling->ac_BarringTime         : %ld\n",
             sib2->ac_BarringInfo->ac_BarringForMO_Signalling->ac_BarringTime );
      LOG_I( RRC, "ac_BarringInfo->ac_BarringForMO_Signalling->ac_BarringForSpecialAC : %"PRIu32"\n",
             BIT_STRING_to_uint32(&sib2->ac_BarringInfo->ac_BarringForMO_Signalling->ac_BarringForSpecialAC) );
    } else
      LOG_I( RRC, "ac_BarringInfo->ac_BarringForMO_Signalling : not defined\n" );

    if (sib2->ac_BarringInfo->ac_BarringForMO_Data) {
      LOG_I( RRC, "ac_BarringInfo->ac_BarringForMO_Data->ac_BarringFactor       : %ld\n",
             sib2->ac_BarringInfo->ac_BarringForMO_Data->ac_BarringFactor );
      LOG_I( RRC, "ac_BarringInfo->ac_BarringForMO_Data->ac_BarringTime         : %ld\n",
             sib2->ac_BarringInfo->ac_BarringForMO_Data->ac_BarringTime );
      LOG_I( RRC, "ac_BarringInfo->ac_BarringForMO_Data->ac_BarringForSpecialAC : %"PRIu32"\n",
             BIT_STRING_to_uint32(&sib2->ac_BarringInfo->ac_BarringForMO_Data->ac_BarringForSpecialAC) );
    } else
      LOG_I( RRC, "ac_BarringInfo->ac_BarringForMO_Data : not defined\n" );
  } else
    LOG_I( RRC, "ac_BarringInfo : not defined\n" );

  // RACH
  LOG_I( RRC, "radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.numberOfRA_Preambles  : raw:%ld decoded:%s\n",
         sib2->radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.numberOfRA_Preambles,
         SIB2numberOfRA_Preambles(sib2->radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.numberOfRA_Preambles) );

  if (sib2->radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.preamblesGroupAConfig) {
    LOG_I( RRC, "radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.preamblesGroupAConfig->sizeOfRA_PreamblesGroupA : %ld\n",
           sib2->radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.preamblesGroupAConfig->sizeOfRA_PreamblesGroupA );
    LOG_I( RRC, "radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.preamblesGroupAConfig->messageSizeGroupA        : %ld\n",
           sib2->radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.preamblesGroupAConfig->messageSizeGroupA );
    LOG_I( RRC, "radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.preamblesGroupAConfig->messagePowerOffsetGroupB : %ld\n",
           sib2->radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.preamblesGroupAConfig->messagePowerOffsetGroupB );
  } else {
    LOG_I( RRC, "radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.preamblesGroupAConfig : not defined\n" );
  }
3432

3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476
  LOG_I( RRC, "radioResourceConfigCommon.rach_ConfigCommon.powerRampingParameters.powerRampingStep                   : raw:%ld decoded:%s\n",
         sib2->radioResourceConfigCommon.rach_ConfigCommon.powerRampingParameters.powerRampingStep,
         SIB2powerRampingStep(sib2->radioResourceConfigCommon.rach_ConfigCommon.powerRampingParameters.powerRampingStep) );
  LOG_I( RRC, "radioResourceConfigCommon.rach_ConfigCommon.powerRampingParameters.preambleInitialReceivedTargetPower : raw:%ld decoded:%s\n",
         sib2->radioResourceConfigCommon.rach_ConfigCommon.powerRampingParameters.preambleInitialReceivedTargetPower,
         SIB2preambleInitialReceivedTargetPower(sib2->radioResourceConfigCommon.rach_ConfigCommon.powerRampingParameters.preambleInitialReceivedTargetPower) );

  LOG_I( RRC, "radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.preambleTransMax              : raw:%ld decoded:%s\n",
         sib2->radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.preambleTransMax,
         SIB2preambleTransMax(sib2->radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.preambleTransMax) );
  LOG_I( RRC, "radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.ra_ResponseWindowSize         : raw:%ld decoded:%s\n",
         sib2->radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.ra_ResponseWindowSize,
         SIB2ra_ResponseWindowSize(sib2->radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.ra_ResponseWindowSize) );
  LOG_I( RRC, "radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.mac_ContentionResolutionTimer : raw:%ld decoded:%s\n",
         sib2->radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.mac_ContentionResolutionTimer,
         SIB2mac_ContentionResolutionTimer(sib2->radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.mac_ContentionResolutionTimer) );

  LOG_I( RRC, "radioResourceConfigCommon.rach_ConfigCommon.maxHARQ_Msg3Tx : %ld\n",
         sib2->radioResourceConfigCommon.rach_ConfigCommon.maxHARQ_Msg3Tx );

  // BCCH
  LOG_I( RRC, "radioResourceConfigCommon.bcch_Config.modificationPeriodCoeff : raw:%ld decoded:%s\n",
         sib2->radioResourceConfigCommon.bcch_Config.modificationPeriodCoeff,
         SIB2modificationPeriodCoeff(sib2->radioResourceConfigCommon.bcch_Config.modificationPeriodCoeff) );

  // PCCH
  LOG_I( RRC, "radioResourceConfigCommon.pcch_Config.defaultPagingCycle : raw:%ld decoded:%s\n",
         sib2->radioResourceConfigCommon.pcch_Config.defaultPagingCycle,
         SIB2defaultPagingCycle(sib2->radioResourceConfigCommon.pcch_Config.defaultPagingCycle) );
  LOG_I( RRC, "radioResourceConfigCommon.pcch_Config.nB                 : raw:%ld decoded:%s\n",
         sib2->radioResourceConfigCommon.pcch_Config.nB,
         SIB2nB(sib2->radioResourceConfigCommon.pcch_Config.nB) );

  // PRACH
  LOG_I( RRC, "radioResourceConfigCommon.prach_Config.rootSequenceIndex                          : %ld\n",
         sib2->radioResourceConfigCommon.prach_Config.rootSequenceIndex );
  LOG_I( RRC, "radioResourceConfigCommon.prach_Config.prach_ConfigInfo.prach_ConfigIndex         : %ld\n",
         sib2->radioResourceConfigCommon.prach_Config.prach_ConfigInfo.prach_ConfigIndex );
  LOG_I( RRC, "radioResourceConfigCommon.prach_Config.prach_ConfigInfo.highSpeedFlag             : %d\n",
         sib2->radioResourceConfigCommon.prach_Config.prach_ConfigInfo.highSpeedFlag );
  LOG_I( RRC, "radioResourceConfigCommon.prach_Config.prach_ConfigInfo.zeroCorrelationZoneConfig : %ld\n",
         sib2->radioResourceConfigCommon.prach_Config.prach_ConfigInfo.zeroCorrelationZoneConfig );
  LOG_I( RRC, "radioResourceConfigCommon.prach_Config.prach_ConfigInfo.prach_FreqOffset          : %ld\n",
         sib2->radioResourceConfigCommon.prach_Config.prach_ConfigInfo.prach_FreqOffset );
3477

3478 3479 3480 3481 3482
  // PDSCH-Config
  LOG_I( RRC, "radioResourceConfigCommon.pdsch_ConfigCommon.referenceSignalPower : %ld\n",
         sib2->radioResourceConfigCommon.pdsch_ConfigCommon.referenceSignalPower );
  LOG_I( RRC, "radioResourceConfigCommon.pdsch_ConfigCommon.p_b                  : %ld\n",
         sib2->radioResourceConfigCommon.pdsch_ConfigCommon.p_b );
3483

3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500
  // PUSCH-Config
  LOG_I( RRC, "radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.n_SB                : %ld\n",
         sib2->radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.n_SB );
  LOG_I( RRC, "radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.hoppingMode         : %ld\n",
         sib2->radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.hoppingMode );
  LOG_I( RRC, "radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.pusch_HoppingOffset : %ld\n",
         sib2->radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.pusch_HoppingOffset );
  LOG_I( RRC, "radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.enable64QAM         : %d\n",
         sib2->radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.enable64QAM );
  LOG_I( RRC, "radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.groupHoppingEnabled    : %d\n",
         sib2->radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.groupHoppingEnabled );
  LOG_I( RRC, "radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH   : %ld\n",
         sib2->radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH );
  LOG_I( RRC, "radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled : %d\n",
         sib2->radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled );
  LOG_I( RRC, "radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.cyclicShift            : %ld\n",
         sib2->radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.cyclicShift );
3501

3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523
  // PUCCH-Config
  LOG_I( RRC, "radioResourceConfigCommon.pucch_ConfigCommon.deltaPUCCH_Shift : %ld\n",
         sib2->radioResourceConfigCommon.pucch_ConfigCommon.deltaPUCCH_Shift );
  LOG_I( RRC, "radioResourceConfigCommon.pucch_ConfigCommon.nRB_CQI          : %ld\n",
         sib2->radioResourceConfigCommon.pucch_ConfigCommon.nRB_CQI );
  LOG_I( RRC, "radioResourceConfigCommon.pucch_ConfigCommon.nCS_AN           : %ld\n",
         sib2->radioResourceConfigCommon.pucch_ConfigCommon.nCS_AN );
  LOG_I( RRC, "radioResourceConfigCommon.pucch_ConfigCommon.n1PUCCH_AN       : %ld\n",
         sib2->radioResourceConfigCommon.pucch_ConfigCommon.n1PUCCH_AN );

  // SoundingRS_UL_Config
  LOG_I( RRC, "radioResourceConfigCommon.soundingRS_UL_ConfigCommon.present : raw:%d decoded:%s\n",
         sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.present,
         SIB2SoundingPresent(sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.present) );

  if (sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.present == SoundingRS_UL_ConfigCommon_PR_setup) {
    LOG_I( RRC, "radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_BandwidthConfig                 : %ld\n",
           sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_BandwidthConfig );
    LOG_I( RRC, "radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_SubframeConfig                  : %ld\n",
           sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_SubframeConfig );
    LOG_I( RRC, "radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.ackNackSRS_SimultaneousTransmission : %d\n",
           sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.ackNackSRS_SimultaneousTransmission );
3524 3525 3526 3527 3528 3529 3530

    if(sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_MaxUpPts)
    {
    LOG_I( RRC, "radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_MaxUpPts                        : %ld\n",
           /* TODO: check that it's okay to access [0] */
           sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.setup.srs_MaxUpPts[0] );
    }
3531
  }
3532

3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554
  // uplinkPowerControlCommon
  LOG_I( RRC, "radioResourceConfigCommon.uplinkPowerControlCommon.p0_NominalPUSCH   : %ld\n",
         sib2->radioResourceConfigCommon.uplinkPowerControlCommon.p0_NominalPUSCH );
  LOG_I( RRC, "radioResourceConfigCommon.uplinkPowerControlCommon.alpha             : %ld\n",
         sib2->radioResourceConfigCommon.uplinkPowerControlCommon.alpha );
  LOG_I( RRC, "radioResourceConfigCommon.uplinkPowerControlCommon.p0_NominalPUCCH   : %ld\n",
         sib2->radioResourceConfigCommon.uplinkPowerControlCommon.p0_NominalPUCCH );
  LOG_I( RRC, "radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format1  : %ld\n",
         sib2->radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format1 );
  LOG_I( RRC, "radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format1b : %ld\n",
         sib2->radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format1b );
  LOG_I( RRC, "radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format2  : %ld\n",
         sib2->radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format2 );
  LOG_I( RRC, "radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format2a : %ld\n",
         sib2->radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format2a );
  LOG_I( RRC, "radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format2b : %ld\n",
         sib2->radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format2b );
  LOG_I( RRC, "radioResourceConfigCommon.uplinkPowerControlCommon.deltaPreambleMsg3 : %ld\n",
         sib2->radioResourceConfigCommon.uplinkPowerControlCommon.deltaPreambleMsg3 );

  LOG_I( RRC, "radioResourceConfigCommon.ul_CyclicPrefixLength : %ld\n",
         sib2->radioResourceConfigCommon.ul_CyclicPrefixLength );
3555

Cedric Roux's avatar
Cedric Roux committed
3556
#if defined(Rel10) || defined(Rel14)
3557 3558 3559
  // UplinkPowerControlCommon_v1020
  // ...
#endif
3560

3561 3562 3563 3564 3565 3566
  LOG_I( RRC, "ue_TimersAndConstants.t300 : %ld\n", sib2->ue_TimersAndConstants.t300 );
  LOG_I( RRC, "ue_TimersAndConstants.t301 : %ld\n", sib2->ue_TimersAndConstants.t301 );
  LOG_I( RRC, "ue_TimersAndConstants.t310 : %ld\n", sib2->ue_TimersAndConstants.t310 );
  LOG_I( RRC, "ue_TimersAndConstants.n310 : %ld\n", sib2->ue_TimersAndConstants.n310 );
  LOG_I( RRC, "ue_TimersAndConstants.t311 : %ld\n", sib2->ue_TimersAndConstants.t311 );
  LOG_I( RRC, "ue_TimersAndConstants.n311 : %ld\n", sib2->ue_TimersAndConstants.n311 );
3567

3568 3569 3570 3571
  if (sib2->freqInfo.ul_CarrierFreq)
    LOG_I( RRC, "freqInfo.ul_CarrierFreq             : %ld\n", *sib2->freqInfo.ul_CarrierFreq );
  else
    LOG_I( RRC, "freqInfo.ul_CarrierFreq             : not defined\n" );
3572

3573 3574 3575 3576
  if (sib2->freqInfo.ul_Bandwidth)
    LOG_I( RRC, "freqInfo.ul_Bandwidth               : %ld\n", *sib2->freqInfo.ul_Bandwidth );
  else
    LOG_I( RRC, "freqInfo.ul_Bandwidth               : not defined\n" );
3577

3578
  LOG_I( RRC, "freqInfo.additionalSpectrumEmission : %ld\n", sib2->freqInfo.additionalSpectrumEmission );
3579

3580 3581 3582 3583 3584
  if (sib2->mbsfn_SubframeConfigList) {
    LOG_I( RRC, "mbsfn_SubframeConfigList : %p\n", sib2->mbsfn_SubframeConfigList );
    // FIXME
  } else
    LOG_I( RRC, "mbsfn_SubframeConfigList : not defined\n" );
3585

3586
  LOG_I( RRC, "timeAlignmentTimerCommon : %ld\n", sib2->timeAlignmentTimerCommon );
3587

Cedric Roux's avatar
Cedric Roux committed
3588
#if defined(Rel10) || defined(Rel14)
3589

3590 3591 3592 3593 3594
  if (sib2->lateNonCriticalExtension) {
    LOG_I( RRC, "lateNonCriticalExtension : %p\n", sib2->lateNonCriticalExtension );
  } else
    LOG_I( RRC, "lateNonCriticalExtension : not defined\n" );

3595
  if (sib2->ext1 && sib2->ext1->ssac_BarringForMMTEL_Voice_r9) {
3596
    LOG_I( RRC, "ssac_BarringForMMTEL_Voice_r9->ac_BarringFactor       : %ld\n",
3597
           sib2->ext1->ssac_BarringForMMTEL_Voice_r9->ac_BarringFactor );
3598
    LOG_I( RRC, "ssac_BarringForMMTEL_Voice_r9->ac_BarringTime         : %ld\n",
3599
           sib2->ext1->ssac_BarringForMMTEL_Voice_r9->ac_BarringTime );
3600
    LOG_I( RRC, "ssac_BarringForMMTEL_Voice_r9->ac_BarringForSpecialAC : %"PRIu32"\n",
3601
           BIT_STRING_to_uint32(&sib2->ext1->ssac_BarringForMMTEL_Voice_r9->ac_BarringForSpecialAC) );
3602 3603 3604
  } else
    LOG_I( RRC, "ssac_BarringForMMTEL_Voice_r9 : not defined\n" );

3605
  if (sib2->ext1 && sib2->ext1->ssac_BarringForMMTEL_Video_r9) {
3606
    LOG_I( RRC, "ssac_BarringForMMTEL_Video_r9->ac_BarringFactor       : %ld\n",
3607
           sib2->ext1->ssac_BarringForMMTEL_Video_r9->ac_BarringFactor );
3608
    LOG_I( RRC, "ssac_BarringForMMTEL_Video_r9->ac_BarringTime         : %ld\n",
3609
           sib2->ext1->ssac_BarringForMMTEL_Video_r9->ac_BarringTime );
3610
    LOG_I( RRC, "ssac_BarringForMMTEL_Video_r9->ac_BarringForSpecialAC : %"PRIu32"\n",
3611
           BIT_STRING_to_uint32(&sib2->ext1->ssac_BarringForMMTEL_Video_r9->ac_BarringForSpecialAC) );
3612 3613 3614
  } else
    LOG_I( RRC, "ssac_BarringForMMTEL_Video_r9 : not defined\n" );

3615
  if (sib2->ext2 && sib2->ext2->ac_BarringForCSFB_r10) {
3616
    LOG_I( RRC, "ac_BarringForCSFB_r10->ac_BarringFactor       : %ld\n",
3617
           sib2->ext2->ac_BarringForCSFB_r10->ac_BarringFactor );
3618
    LOG_I( RRC, "ac_BarringForCSFB_r10->ac_BarringTime         : %ld\n",
3619
           sib2->ext2->ac_BarringForCSFB_r10->ac_BarringTime );
3620
    LOG_I( RRC, "ac_BarringForCSFB_r10->ac_BarringForSpecialAC : %"PRIu32"\n",
3621
           BIT_STRING_to_uint32(&sib2->ext2->ac_BarringForCSFB_r10->ac_BarringForSpecialAC) );
3622 3623
  } else
    LOG_I( RRC, "ac_BarringForCSFB_r10 : not defined\n" );
3624

3625
#endif
3626 3627
}

3628
//-----------------------------------------------------------------------------
3629
 void dump_sib3( SystemInformationBlockType3_t *sib3 )
3630
{
3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674
  LOG_I( RRC, "Dumping SIB3 (see TS36.331 V8.21.0)\n" );

  int q_Hyst_dB = sib3->cellReselectionInfoCommon.q_Hyst; // sib3->cellReselectionInfoCommon.q_Hyst is a enumerated value

  if (q_Hyst_dB > 6)
    q_Hyst_dB = (q_Hyst_dB-6) * 2 + 6;

  LOG_I( RRC, "cellReselectionInfoCommon.q_Hyst : raw:%ld  decoded:%d dB\n", sib3->cellReselectionInfoCommon.q_Hyst, q_Hyst_dB );

  if (sib3->cellReselectionInfoCommon.speedStateReselectionPars) {
    LOG_I( RRC, "cellReselectionInfoCommon.speedStateReselectionPars->mobilityStateParameters.t_Evaluation : %ld\n",
           sib3->cellReselectionInfoCommon.speedStateReselectionPars->mobilityStateParameters.t_Evaluation );
    LOG_I( RRC, "cellReselectionInfoCommon.speedStateReselectionPars->mobilityStateParameters.t_HystNormal : %ld\n",
           sib3->cellReselectionInfoCommon.speedStateReselectionPars->mobilityStateParameters.t_HystNormal );
    LOG_I( RRC, "cellReselectionInfoCommon.speedStateReselectionPars->mobilityStateParameters.n_CellChangeMedium : %ld\n",
           sib3->cellReselectionInfoCommon.speedStateReselectionPars->mobilityStateParameters.n_CellChangeMedium );
    LOG_I( RRC, "cellReselectionInfoCommon.speedStateReselectionPars->mobilityStateParameters.n_CellChangeHigh : %ld\n",
           sib3->cellReselectionInfoCommon.speedStateReselectionPars->mobilityStateParameters.n_CellChangeHigh );
    int q_HystSF_Medium = 6 - 2 * sib3->cellReselectionInfoCommon.speedStateReselectionPars->q_HystSF.sf_Medium;
    int q_HystSF_High = 6 - 2 * sib3->cellReselectionInfoCommon.speedStateReselectionPars->q_HystSF.sf_High;
    LOG_I( RRC, "cellReselectionInfoCommon.speedStateReselectionPars->q_HystSF.sf_Medium : raw:%ld decoded:%d dB\n", sib3->cellReselectionInfoCommon.speedStateReselectionPars->q_HystSF.sf_Medium,
           q_HystSF_Medium );
    LOG_I( RRC, "cellReselectionInfoCommon.speedStateReselectionPars->q_HystSF.sf_High : raw:%ld decoded:%d dB\n", sib3->cellReselectionInfoCommon.speedStateReselectionPars->q_HystSF.sf_High,
           q_HystSF_High );
  } else {
    LOG_I( RRC, "cellReselectionInfoCommon.speedStateReselectionPars : not defined\n" );
  }

  if (sib3->cellReselectionServingFreqInfo.s_NonIntraSearch) {
    LOG_I( RRC, "cellReselectionServingFreqInfo.s_NonIntraSearch : %ld\n", *(sib3->cellReselectionServingFreqInfo.s_NonIntraSearch) );
  } else {
    LOG_I( RRC, "cellReselectionServingFreqInfo.s_NonIntraSearch : not defined\n" );
  }

  LOG_I( RRC, "cellReselectionServingFreqInfo.threshServingLow : %ld\n", sib3->cellReselectionServingFreqInfo.threshServingLow );
  LOG_I( RRC, "cellReselectionServingFreqInfo.cellReselectionPriority : %ld\n", sib3->cellReselectionServingFreqInfo.cellReselectionPriority );

  LOG_I( RRC, "intraFreqCellReselectionInfo.q_RxLevMin : %ld\n", sib3->intraFreqCellReselectionInfo.q_RxLevMin );

  if (sib3->intraFreqCellReselectionInfo.p_Max) {
    LOG_I( RRC, "intraFreqCellReselectionInfo.p_Max : %ld\n", *(sib3->intraFreqCellReselectionInfo.p_Max) );
  } else {
    LOG_I( RRC, "intraFreqCellReselectionInfo.p_Max : not defined\n" );
  }
3675

3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697
  if (sib3->intraFreqCellReselectionInfo.s_IntraSearch) {
    LOG_I( RRC, "intraFreqCellReselectionInfo.s_IntraSearch : %ld\n", *(sib3->intraFreqCellReselectionInfo.s_IntraSearch) );
  } else {
    LOG_I( RRC, "intraFreqCellReselectionInfo.s_IntraSearch : not defined\n" );
  }

  if (sib3->intraFreqCellReselectionInfo.allowedMeasBandwidth) {
    LOG_I( RRC, "intraFreqCellReselectionInfo.allowedMeasBandwidth : %ld\n", *(sib3->intraFreqCellReselectionInfo.allowedMeasBandwidth) );
  } else {
    LOG_I( RRC, "intraFreqCellReselectionInfo.allowedMeasBandwidth : not defined\n" );
  }

  LOG_I( RRC, "intraFreqCellReselectionInfo.presenceAntennaPort1 : %d\n", sib3->intraFreqCellReselectionInfo.presenceAntennaPort1 );
  LOG_I( RRC, "intraFreqCellReselectionInfo.neighCellConfig : %"PRIu8"\n", BIT_STRING_to_uint8( &(sib3->intraFreqCellReselectionInfo.neighCellConfig) ) );
  LOG_I( RRC, "intraFreqCellReselectionInfo.t_ReselectionEUTRA : %ld\n", sib3->intraFreqCellReselectionInfo.t_ReselectionEUTRA );

  if (sib3->intraFreqCellReselectionInfo.t_ReselectionEUTRA_SF) {
    LOG_I( RRC, "intraFreqCellReselectionInfo.t_ReselectionEUTRA_SF->sf_Medium : %ld\n", sib3->intraFreqCellReselectionInfo.t_ReselectionEUTRA_SF->sf_Medium );
    LOG_I( RRC, "intraFreqCellReselectionInfo.t_ReselectionEUTRA_SF->sf_High : %ld\n", sib3->intraFreqCellReselectionInfo.t_ReselectionEUTRA_SF->sf_High );
  } else {
    LOG_I( RRC, "intraFreqCellReselectionInfo.t_ReselectionEUTRA_SF : not defined\n" );
  }
3698 3699
}

3700 3701 3702 3703
int Qoffsettab[31] = {-24,-22,-20,-18,-16,-14,-12,-10,-8,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,8,10,12,14,16,18,20,22,24};
int PhysCellIdRange[16] = {4,8,12,16,24,32,48,64,84,96,128,168,252,504,0,0};

uint64_t arfcn_to_freq(long arfcn) {
3704

3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737
  if (arfcn < 600)  // Band 1
    return((uint64_t)2110000000 + (arfcn*100000));
  else if (arfcn <1200) // Band 2
    return((uint64_t)1930000000 + ((arfcn-600)*100000));
  else if (arfcn <1950) // Band 3
    return((uint64_t)1805000000 + ((arfcn-1200)*100000));
  else if (arfcn <2400) // Band 4
    return((uint64_t)2110000000 + ((arfcn-1950)*100000));
  else if (arfcn <2650) // Band 5
    return((uint64_t)869000000 + ((arfcn-2400)*100000));
  else if (arfcn <2750) // Band 6
    return((uint64_t)875000000 + ((arfcn-2650)*100000));
  else if (arfcn <3450) // Band 7
    return((uint64_t)2620000000 + ((arfcn-2750)*100000));
  else if (arfcn <3800) // Band 8
    return((uint64_t)925000000 + ((arfcn-3450)*100000));
  else if (arfcn <4150) // Band 9
    return((uint64_t)1844900000 + ((arfcn-3800)*100000));
  else if (arfcn <4650) // Band 10
    return((uint64_t)2110000000 + ((arfcn-4150)*100000));
  else if (arfcn <5010) // Band 11
    return((uint64_t)1475900000 + ((arfcn-4750)*100000));
  else if (arfcn <5180) // Band 12
    return((uint64_t)729000000 + ((arfcn-5010)*100000));
  else if (arfcn <5280) // Band 13
    return((uint64_t)746000000 + ((arfcn-5180)*100000));
  else if (arfcn <5730) // Band 14
    return((uint64_t)758000000 + ((arfcn-5280)*100000));
  else if (arfcn <5850) // Band 17
    return((uint64_t)734000000 + ((arfcn-5730)*100000));
  else if (arfcn <6000) // Band 18
    return((uint64_t)860000000 + ((arfcn-5850)*100000));
  else if (arfcn <6150) // Band 19
3738
    return((uint64_t)875000000 + ((arfcn-6000)*100000));
3739
  else if (arfcn <6450) // Band 20
3740
    return((uint64_t)791000000 + ((arfcn-6150)*100000));
3741
  else if (arfcn <6600) // Band 21
3742
    return((uint64_t)1495900000 + ((arfcn-6450)*100000));
3743
  else if (arfcn <7500) // Band 22
3744
    return((uint64_t)351000000 + ((arfcn-6600)*100000));
3745
  else if (arfcn <7700) // Band 23
3746
    return((uint64_t)2180000000 + ((arfcn-7500)*100000));
3747
  else if (arfcn <8040) // Band 24
3748
    return((uint64_t)1525000000 + ((arfcn-7700)*100000));
3749
  else if (arfcn <8690) // Band 25
3750
    return((uint64_t)1930000000 + ((arfcn-8040)*100000));
3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772
  else if (arfcn <36200) // Band 33
    return((uint64_t)1900000000 + ((arfcn-36000)*100000));
  else if (arfcn <36350) // Band 34
    return((uint64_t)2010000000 + ((arfcn-36200)*100000));
  else if (arfcn <36950) // Band 35
    return((uint64_t)1850000000 + ((arfcn-36350)*100000));
  else if (arfcn <37550) // Band 36
    return((uint64_t)1930000000 + ((arfcn-36950)*100000));
  else if (arfcn <37750) // Band 37
    return((uint64_t)1910000000 + ((arfcn-37550)*100000));
  else if (arfcn <38250) // Band 38
    return((uint64_t)2570000000 + ((arfcn-37750)*100000));
  else if (arfcn <38650) // Band 39
    return((uint64_t)1880000000 + ((arfcn-38250)*100000));
  else if (arfcn <39650) // Band 40
    return((uint64_t)2300000000 + ((arfcn-38650)*100000));
  else if (arfcn <41590) // Band 41
    return((uint64_t)2496000000 + ((arfcn-39650)*100000));
  else if (arfcn <43590) // Band 42
    return((uint64_t)3400000000 + ((arfcn-41590)*100000));
  else if (arfcn <45590) // Band 43
    return((uint64_t)3600000000 + ((arfcn-43950)*100000));
Cedric Roux's avatar
Cedric Roux committed
3773
  else {
Cedric Roux's avatar
Cedric Roux committed
3774
    LOG_E(RRC,"Unknown EARFCN %ld\n",arfcn);
Cedric Roux's avatar
Cedric Roux committed
3775 3776
    exit(1);
  }
3777
}
3778
 void dump_sib5( SystemInformationBlockType5_t *sib5 )
3779 3780
{
  InterFreqCarrierFreqList_t interFreqCarrierFreqList = sib5->interFreqCarrierFreqList;
3781
  int i,j;
3782 3783 3784
  InterFreqCarrierFreqInfo_t *ifcfInfo;

  LOG_I( RRC, "Dumping SIB5 (see TS36.331 V8.21.0)\n" );
3785

3786 3787 3788
  for (i=0;i<interFreqCarrierFreqList.list.count;i++) {
    LOG_I(RRC, "SIB5 InterFreqCarrierFreq element %d/%d\n",i,interFreqCarrierFreqList.list.count);
    ifcfInfo = interFreqCarrierFreqList.list.array[i];
Cedric Roux's avatar
Cedric Roux committed
3789
    LOG_I(RRC, "   DL Carrier Frequency/ARFCN : %ld/%ld\n",
3790 3791
	  arfcn_to_freq(ifcfInfo->dl_CarrierFreq),
	  ifcfInfo->dl_CarrierFreq);
Cedric Roux's avatar
Cedric Roux committed
3792 3793 3794 3795
    LOG_I(RRC,"   Q_RXLevMin : %ld\n", ifcfInfo->q_RxLevMin);
    if (ifcfInfo->p_Max != NULL)
      LOG_I(RRC,"   P_max : %ld\n", *ifcfInfo->p_Max);
    LOG_I(RRC,"   T_ReselectionEUTRA : %ld\n",ifcfInfo->t_ReselectionEUTRA);
3796
    if (ifcfInfo->t_ReselectionEUTRA_SF) {
Cedric Roux's avatar
Cedric Roux committed
3797
      LOG_I(RRC,"   t_ReselectionEUTRA_SF.sf_Medium %ld, t_ReselectionEUTRA_SF.sf_High %ld",
3798 3799 3800
	    ifcfInfo->t_ReselectionEUTRA_SF->sf_Medium,
	    ifcfInfo->t_ReselectionEUTRA_SF->sf_High);
    }
Cedric Roux's avatar
Cedric Roux committed
3801 3802
    LOG_I(RRC,"   threshX_High : %ld\n",ifcfInfo->threshX_High);
    LOG_I(RRC,"   threshX_Low : %ld\n",ifcfInfo->threshX_Low);
3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827
    switch(ifcfInfo->allowedMeasBandwidth) {
    case AllowedMeasBandwidth_mbw6:
      LOG_I(RRC,"   AllowedMeasBandwidth : 6\n");
      break;
    case AllowedMeasBandwidth_mbw15:
      LOG_I(RRC,"   AllowedMeasBandwidth : 15\n");
      break;
    case AllowedMeasBandwidth_mbw25:
      LOG_I(RRC,"   AllowedMeasBandwidth : 25\n");
      break;
    case AllowedMeasBandwidth_mbw50:
      LOG_I(RRC,"   AllowedMeasBandwidth : 50\n");
      break;
    case AllowedMeasBandwidth_mbw75:
      LOG_I(RRC,"   AllowedMeasBandwidth : 75\n");
      break;
    case AllowedMeasBandwidth_mbw100:
      LOG_I(RRC,"   AllowedMeasBandwidth : 100\n");
      break;
    }
    if (ifcfInfo->presenceAntennaPort1)
      LOG_I(RRC,"   PresenceAntennaPort1 : True\n");
    else
      LOG_I(RRC,"   PresenceAntennaPort1 : False\n");
    if (ifcfInfo->cellReselectionPriority) {
Cedric Roux's avatar
Cedric Roux committed
3828
      LOG_I(RRC,"   CellReselectionPriority : %ld\n",
3829 3830 3831
	    *ifcfInfo->cellReselectionPriority);
    }
    LOG_I(RRC,"   NeighCellConfig  : ");
3832 3833
    for (j=0;j<ifcfInfo->neighCellConfig.size;j++) {
      printf("%2x ",ifcfInfo->neighCellConfig.buf[j]);
3834
    }
3835
    printf("\n");
3836
    if (ifcfInfo->q_OffsetFreq)
3837
      LOG_I(RRC,"   Q_OffsetFreq : %d\n",Qoffsettab[*ifcfInfo->q_OffsetFreq]);
3838
    if (ifcfInfo->interFreqNeighCellList) {
3839

3840
      for (j=0;j<ifcfInfo->interFreqNeighCellList->list.count;j++) {
Cedric Roux's avatar
Cedric Roux committed
3841 3842 3843
	LOG_I(RRC,"   Cell %d\n", j);
	LOG_I(RRC,"      PhysCellId : %ld\n",ifcfInfo->interFreqNeighCellList->list.array[j]->physCellId);
	LOG_I(RRC,"      Q_OffsetRange : %ld\n",ifcfInfo->interFreqNeighCellList->list.array[j]->q_OffsetCell);
3844

3845 3846 3847
      }
    }
    if (ifcfInfo->interFreqBlackCellList) {
3848

3849
      for (j=0;j<ifcfInfo->interFreqBlackCellList->list.count;j++) {
Cedric Roux's avatar
Cedric Roux committed
3850 3851
	LOG_I(RRC,"   Cell %d\n", j);
	LOG_I(RRC,"      PhysCellId start: %ld\n",ifcfInfo->interFreqBlackCellList->list.array[j]->start);
3852
	if (ifcfInfo->interFreqBlackCellList->list.array[i]->range) {
Cedric Roux's avatar
Cedric Roux committed
3853
	  LOG_I(RRC,"      PhysCellId Range : %ld\n",*ifcfInfo->interFreqBlackCellList->list.array[j]->range);
3854 3855 3856
	}
      }
    }
Cedric Roux's avatar
Cedric Roux committed
3857
#if defined(Rel10) || defined(Rel14)
3858
    if (ifcfInfo->ext1 && ifcfInfo->ext1->q_QualMin_r9)
Cedric Roux's avatar
Cedric Roux committed
3859
      LOG_I(RRC,"   Q_QualMin_r9 : %ld\n",*ifcfInfo->ext1->q_QualMin_r9);
3860

3861
    if (ifcfInfo->ext1 && ifcfInfo->ext1->threshX_Q_r9) {
Cedric Roux's avatar
Cedric Roux committed
3862 3863
      LOG_I(RRC,"   threshX_HighQ_r9 : %ld\n",ifcfInfo->ext1->threshX_Q_r9->threshX_HighQ_r9);
      LOG_I(RRC,"   threshX_LowQ_r9: %ld\n",ifcfInfo->ext1->threshX_Q_r9->threshX_LowQ_r9);
3864
    }
roux's avatar
roux committed
3865
#endif
3866
  }
3867

3868
}
3869

Cedric Roux's avatar
Cedric Roux committed
3870
#if defined(Rel10) || defined(Rel14)
3871
 void dump_sib13( SystemInformationBlockType13_r9_t *sib13 )
3872
{
3873 3874 3875 3876 3877
  LOG_I( RRC, "[UE] Dumping SIB13\n" );
  LOG_I( RRC, "[UE] dumping sib13 second time\n" );
  LOG_I( RRC, "[UE] NotificationRepetitionCoeff-r9 : %ld\n", sib13->notificationConfig_r9.notificationRepetitionCoeff_r9 );
  LOG_I( RRC, "[UE] NotificationOffset-r9 : %d\n", (int)sib13->notificationConfig_r9.notificationOffset_r9 );
  LOG_I( RRC, "[UE] NotificationSF-Index-r9 : %d\n", (int)sib13->notificationConfig_r9.notificationSF_Index_r9 );
3878
}
3879

winckel's avatar
winckel committed
3880

3881
//TTN - SIB18
3882
//-----------------------------------------------------------------------------
3883
 void dump_sib18(SystemInformationBlockType18_r12_t *sib18){
3884 3885 3886
   LOG_I( RRC, "[UE] Dumping SIB18\n" );
   for (int i = 0; i < sib18->commConfig_r12->commRxPool_r12.list.count; i++) {
       LOG_I(RRC, " Contents of SIB18 %d/%d \n", i+1, sib18->commConfig_r12->commRxPool_r12.list.count);
3887 3888 3889 3890 3891 3892
       LOG_I(RRC, " SIB18 rxPool_sc_CP_Len: %ld \n", sib18->commConfig_r12->commRxPool_r12.list.array[i]->sc_CP_Len_r12);
       LOG_I(RRC, " SIB18 sc_Period_r12: %ld \n", sib18->commConfig_r12->commRxPool_r12.list.array[i]->sc_Period_r12);
       LOG_I(RRC, " SIB18 data_CP_Len_r12: %ld \n", sib18->commConfig_r12->commRxPool_r12.list.array[i]->data_CP_Len_r12);
       LOG_I(RRC, " SIB18 prb_Num_r12: %ld \n", sib18->commConfig_r12->commRxPool_r12.list.array[i]->sc_TF_ResourceConfig_r12.prb_Num_r12);
       LOG_I(RRC, " SIB18 prb_Start_r12: %ld \n", sib18->commConfig_r12->commRxPool_r12.list.array[i]->sc_TF_ResourceConfig_r12.prb_Start_r12);
       LOG_I(RRC, " SIB18 prb_End_r12: %ld \n", sib18->commConfig_r12->commRxPool_r12.list.array[i]->sc_TF_ResourceConfig_r12.prb_End_r12);
3893 3894
       //to add more log
     }
3895
}
3896

3897 3898
//TTN -  SIB19
//-----------------------------------------------------------------------------
3899
 void dump_sib19(SystemInformationBlockType19_r12_t *sib19){
3900 3901
   LOG_I( RRC, "[UE] Dumping SIB19\n" );
   for (int i = 0; i < sib19->discConfig_r12->discRxPool_r12.list.count; i++) {
3902
       LOG_I(RRC, " Contents of SIB19 %d/%d \n", i+1, sib19->discConfig_r12->discRxPool_r12.list.count);
3903 3904 3905 3906 3907 3908 3909
       LOG_I(RRC, " SIB19 cp_Len_r12: %ld \n", sib19->discConfig_r12->discRxPool_r12.list.array[i]->cp_Len_r12);
       LOG_I(RRC, " SIB19 discPeriod_r12: %ld \n", sib19->discConfig_r12->discRxPool_r12.list.array[i]->discPeriod_r12);
       LOG_I(RRC, " SIB19 numRetx_r12: %ld \n", sib19->discConfig_r12->discRxPool_r12.list.array[i]->numRetx_r12);
       LOG_I(RRC, " SIB19 numRepetition_r12: %ld \n", sib19->discConfig_r12->discRxPool_r12.list.array[i]->numRepetition_r12);
       LOG_I(RRC, " SIB19 prb_Num_r12: %ld \n", sib19->discConfig_r12->discRxPool_r12.list.array[i]->tf_ResourceConfig_r12.prb_Num_r12);
       LOG_I(RRC, " SIB19 prb_Start_r12: %ld \n", sib19->discConfig_r12->discRxPool_r12.list.array[i]->tf_ResourceConfig_r12.prb_Start_r12);
       LOG_I(RRC, " SIB19 prb_End_r12: %ld \n", sib19->discConfig_r12->discRxPool_r12.list.array[i]->tf_ResourceConfig_r12.prb_End_r12);
3910 3911
       //to add more log
     }
3912
}
3913

3914 3915 3916 3917 3918 3919
 void dump_sib21(SystemInformationBlockType21_r14_t *sib21){
    if ((sib21->sl_V2X_ConfigCommon_r14 != NULL) && (sib21->sl_V2X_ConfigCommon_r14->v2x_CommRxPool_r14 !=NULL) ){
       for (int i = 0; i < sib21->sl_V2X_ConfigCommon_r14->v2x_CommRxPool_r14->list.count; i++) {
          LOG_I(RRC, " Contents of SIB21 %d/%d \n", i+1, sib21->sl_V2X_ConfigCommon_r14->v2x_CommRxPool_r14->list.count);
          LOG_I(RRC, " SIB21 sl_Subframe_r14: %d \n", sib21->sl_V2X_ConfigCommon_r14->v2x_CommRxPool_r14->list.array[i]->sl_Subframe_r14.present);
          LOG_I(RRC, " SIB21 adjacencyPSCCH_PSSCH_r14: %d \n", sib21->sl_V2X_ConfigCommon_r14->v2x_CommRxPool_r14->list.array[i]->adjacencyPSCCH_PSSCH_r14);
3920 3921 3922
          LOG_I(RRC, " SIB21 sizeSubchannel_r14: %ld \n", sib21->sl_V2X_ConfigCommon_r14->v2x_CommRxPool_r14->list.array[i]->sizeSubchannel_r14);
          LOG_I(RRC, " SIB21 numSubchannel_r14: %ld \n", sib21->sl_V2X_ConfigCommon_r14->v2x_CommRxPool_r14->list.array[i]->numSubchannel_r14);
          LOG_I(RRC, " SIB21 startRB_Subchannel_r14: %ld \n", sib21->sl_V2X_ConfigCommon_r14->v2x_CommRxPool_r14->list.array[i]->startRB_Subchannel_r14);
3923 3924 3925 3926 3927 3928 3929
          //to add more log
       }
    }
 }


#endif
3930
//-----------------------------------------------------------------------------
3931
 int decode_SI( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index )
3932
{
3933
  //LOG_D( RRC, "Panos-D: decode_SI 1 \n");
3934
  SystemInformation_t** si = &UE_rrc_inst[ctxt_pP->module_id].si[eNB_index];
3935 3936
  int new_sib = 0;
  SystemInformationBlockType1_t* sib1 = UE_rrc_inst[ctxt_pP->module_id].sib1[eNB_index];
3937

3938
  //LOG_D( RRC, "Panos-D: decode_SI 2 \n");
3939
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_UE_DECODE_SI, VCD_FUNCTION_IN );
3940 3941

  // Dump contents
3942 3943
  if ((*si)->criticalExtensions.present == SystemInformation__criticalExtensions_PR_systemInformation_r8 ||
		  (*si)->criticalExtensions.present == SystemInformation__criticalExtensions_PR_criticalExtensionsFuture) {
3944
    LOG_D( RRC, "[UE] (*si)->criticalExtensions.choice.systemInformation_r8.sib_TypeAndInfo.list.count %d\n",
3945
           (*si)->criticalExtensions.choice.systemInformation_r8.sib_TypeAndInfo.list.count );
3946
  } else {
3947
	  //LOG_D( RRC, "Panos-D: decode_SI 2.3 \n");
3948
    LOG_D( RRC, "[UE] Unknown criticalExtension version (not Rel8)\n" );
3949
    return -1;
3950 3951
  }

3952
  LOG_D( RRC, "Panos-D: decode_SI 3 \n");
3953
  for (int i=0; i<(*si)->criticalExtensions.choice.systemInformation_r8.sib_TypeAndInfo.list.count; i++) {
3954
    //LOG_I( RRC, "Panos-D: SI count %d\n", i );
3955 3956
    struct SystemInformation_r8_IEs__sib_TypeAndInfo__Member *typeandinfo;
    typeandinfo = (*si)->criticalExtensions.choice.systemInformation_r8.sib_TypeAndInfo.list.array[i];
3957

3958 3959
    switch(typeandinfo->present) {
    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib2:
3960
    	//LOG_D( RRC, "Panos-D: decode_SI 4 \n");
3961 3962 3963 3964 3965 3966 3967 3968
      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&2) == 0) {
	UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=2;
	new_sib=1;
	memcpy( UE_rrc_inst[ctxt_pP->module_id].sib2[eNB_index], &typeandinfo->choice.sib2, sizeof(SystemInformationBlockType2_t) );
	LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB2 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
	dump_sib2( UE_rrc_inst[ctxt_pP->module_id].sib2[eNB_index] );
	LOG_I( RRC, "[FRAME %05"PRIu32"][RRC_UE][MOD %02"PRIu8"][][--- MAC_CONFIG_REQ (SIB2 params  eNB %"PRIu8") --->][MAC_UE][MOD %02"PRIu8"][]\n",
	       ctxt_pP->frame, ctxt_pP->module_id, eNB_index, ctxt_pP->module_id );
3969

3970 3971 3972
	rrc_mac_config_req_ue(ctxt_pP->module_id, 0, eNB_index,
			      &UE_rrc_inst[ctxt_pP->module_id].sib2[eNB_index]->radioResourceConfigCommon,
			      (struct PhysicalConfigDedicated *)NULL,
Cedric Roux's avatar
Cedric Roux committed
3973
#if defined(Rel10) || defined(Rel14)
3974
			      (SCellToAddMod_r10_t *)NULL,
3975
#endif
3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988
			      (MeasObjectToAddMod_t **)NULL,
			      (MAC_MainConfig_t *)NULL,
			      0,
			      (struct LogicalChannelConfig *)NULL,
			      (MeasGapConfig_t *)NULL,
			      (TDD_Config_t *)NULL,
			      (MobilityControlInfo_t *)NULL,
			      NULL,
			      NULL,
			      UE_rrc_inst[ctxt_pP->module_id].sib2[eNB_index]->freqInfo.ul_CarrierFreq,
			      UE_rrc_inst[ctxt_pP->module_id].sib2[eNB_index]->freqInfo.ul_Bandwidth,
			      &UE_rrc_inst[ctxt_pP->module_id].sib2[eNB_index]->freqInfo.additionalSpectrumEmission,
			      UE_rrc_inst[ctxt_pP->module_id].sib2[eNB_index]->mbsfn_SubframeConfigList
Cedric Roux's avatar
Cedric Roux committed
3989
#if defined(Rel10) || defined(Rel14)
3990 3991 3992
			      ,0,
			      (MBSFN_AreaInfoList_r9_t *)NULL,
			      (PMCH_InfoList_r9_t *)NULL
3993

3994 3995
#endif
#ifdef CBA
3996 3997
			      ,0,
			      0
3998 3999 4000
#endif
#if defined(Rel14)
           ,
4001
           0,
4002
           NULL,
4003
           NULL,
4004
           NULL
4005
#endif
4006
			      );
4007
	// After SI is received, prepare RRCConnectionRequest
Cedric Roux's avatar
Cedric Roux committed
4008
#if defined(Rel10) || defined(Rel14)
4009

4010
	if (UE_rrc_inst[ctxt_pP->module_id].MBMS_flag < 3) // see -Q option
4011
#endif
winckel's avatar
winckel committed
4012
#if !(defined(ENABLE_ITTI) && defined(ENABLE_USE_MME))
4013
	  rrc_ue_generate_RRCConnectionRequest( ctxt_pP, eNB_index );
4014

winckel's avatar
winckel committed
4015
#endif
4016

4017 4018 4019
	if (UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].State == RRC_IDLE) {
	  LOG_I( RRC, "[UE %d] Received SIB1/SIB2/SIB3 Switching to RRC_SI_RECEIVED\n", ctxt_pP->module_id );
	  UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].State = RRC_SI_RECEIVED;
4020
#if ENABLE_RAL
4021 4022 4023
	  {
	    MessageDef                            *message_ral_p = NULL;
	    rrc_ral_system_information_ind_t       ral_si_ind;
4024

4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041
	    message_ral_p = itti_alloc_new_message (TASK_RRC_UE, RRC_RAL_SYSTEM_INFORMATION_IND);
	    memset(&ral_si_ind, 0, sizeof(rrc_ral_system_information_ind_t));
	    ral_si_ind.plmn_id.MCCdigit2 = '0';
	    ral_si_ind.plmn_id.MCCdigit1 = '2';
	    ral_si_ind.plmn_id.MNCdigit3 = '0';
	    ral_si_ind.plmn_id.MCCdigit3 = '8';
	    ral_si_ind.plmn_id.MNCdigit2 = '9';
	    ral_si_ind.plmn_id.MNCdigit1 = '9';
	    ral_si_ind.cell_id        = 1;
	    ral_si_ind.dbm            = 0;
	    //ral_si_ind.dbm            = fifo_dump_emos_UE.PHY_measurements->rx_rssi_dBm[eNB_index];
	    // TO DO
	    ral_si_ind.sinr           = 0;
	    //ral_si_ind.sinr           = fifo_dump_emos_UE.PHY_measurements->subband_cqi_dB[eNB_index][phy_vars_ue->lte_frame_parms.nb_antennas_rx][0];
	    // TO DO
	    ral_si_ind.link_data_rate = 0;
	    memcpy (&message_ral_p->ittiMsg, (void *) &ral_si_ind, sizeof(rrc_ral_system_information_ind_t));
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4042
#warning "ue_mod_idP ? for instance ?"
4043 4044
	    itti_send_msg_to_task (TASK_RAL_UE, UE_MODULE_ID_TO_INSTANCE(ctxt_pP->module_id), message_ral_p);
	  }
4045
#endif
4046
	}
4047
      }
4048
      break; // case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib2
4049 4050

    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib3:
4051
    	//LOG_D( RRC, "Panos-D: decode_SI 5 \n");
4052 4053 4054 4055 4056 4057 4058 4059
      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&4) == 0) {
	UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=4;
	new_sib=1;
	memcpy( UE_rrc_inst[ctxt_pP->module_id].sib3[eNB_index], &typeandinfo->choice.sib3, sizeof(SystemInformationBlockType3_t) );
	LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB3 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
	dump_sib3( UE_rrc_inst[ctxt_pP->module_id].sib3[eNB_index] );

      }
4060 4061 4062
      break;

    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib4:
4063 4064 4065 4066 4067 4068 4069
      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&8) == 0) {
	UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=8;
	new_sib=1;
	memcpy( UE_rrc_inst[ctxt_pP->module_id].sib4[eNB_index], &typeandinfo->choice.sib4, sizeof(SystemInformationBlockType4_t) );
	LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB4 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
      }

4070 4071 4072
      break;

    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib5:
4073 4074 4075
      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&16) == 0) {
	UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=16;
	new_sib=1;
4076

4077 4078
	memcpy( UE_rrc_inst[ctxt_pP->module_id].sib5[eNB_index], &typeandinfo->choice.sib5, sizeof(SystemInformationBlockType5_t) );
	LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB5 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
4079
	dump_sib5(UE_rrc_inst[ctxt_pP->module_id].sib5[eNB_index]);
4080
      }
4081 4082 4083
      break;

    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib6:
4084 4085 4086
      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&32) == 0) {
	UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=32;
	new_sib=1;
4087

4088 4089 4090
	memcpy( UE_rrc_inst[ctxt_pP->module_id].sib6[eNB_index], &typeandinfo->choice.sib6, sizeof(SystemInformationBlockType6_t) );
	LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB6 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
      }
4091 4092 4093
      break;

    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib7:
4094 4095 4096 4097 4098 4099
      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&64) == 0) {
	UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=64;
	new_sib=1;
	memcpy( UE_rrc_inst[ctxt_pP->module_id].sib7[eNB_index], &typeandinfo->choice.sib7, sizeof(SystemInformationBlockType7_t) );
	LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB7 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
      }
4100 4101 4102
      break;

    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib8:
4103 4104 4105 4106 4107 4108
      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&128) == 0) {
	UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=128;
	new_sib=1;
	memcpy( UE_rrc_inst[ctxt_pP->module_id].sib8[eNB_index], &typeandinfo->choice.sib8, sizeof(SystemInformationBlockType8_t) );
	LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB8 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
      }
4109 4110 4111
      break;

    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib9:
4112 4113 4114
      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&256) == 0) {
	UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=256;
	new_sib=1;
4115

4116 4117 4118
	memcpy( UE_rrc_inst[ctxt_pP->module_id].sib9[eNB_index], &typeandinfo->choice.sib9, sizeof(SystemInformationBlockType9_t) );
	LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB9 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
      }
4119 4120 4121
      break;

    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib10:
4122 4123 4124 4125 4126 4127
      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&512) == 0) {
	UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=512;
	new_sib=1;
	memcpy( UE_rrc_inst[ctxt_pP->module_id].sib10[eNB_index], &typeandinfo->choice.sib10, sizeof(SystemInformationBlockType10_t) );
	LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB10 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
      }
4128 4129 4130
      break;

    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib11:
4131 4132 4133 4134 4135 4136 4137
      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&1024) == 0) {
	UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=1024;
	new_sib=1;

	memcpy( UE_rrc_inst[ctxt_pP->module_id].sib11[eNB_index], &typeandinfo->choice.sib11, sizeof(SystemInformationBlockType11_t) );
	LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB11 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
      }
4138
      break;
4139

Cedric Roux's avatar
Cedric Roux committed
4140
#if defined(Rel10) || defined(Rel14)
4141 4142

    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib12_v920:
4143 4144 4145 4146 4147 4148
      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&2048) == 0) {
	UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=2048;
	new_sib=1;
	memcpy( UE_rrc_inst[ctxt_pP->module_id].sib12[eNB_index], &typeandinfo->choice.sib12_v920, sizeof(SystemInformationBlockType12_r9_t) );
	LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB12 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
      }
4149
      break;
4150

4151
    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib13_v920:
4152 4153 4154
      if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&4096) == 0) {
	UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=4096;
	new_sib=1;
4155

4156 4157 4158 4159
	memcpy( UE_rrc_inst[ctxt_pP->module_id].sib13[eNB_index], &typeandinfo->choice.sib13_v920, sizeof(SystemInformationBlockType13_r9_t) );
	LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB13 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
	dump_sib13( UE_rrc_inst[ctxt_pP->module_id].sib13[eNB_index] );
	// adding here function to store necessary parameters for using in decode_MCCH_Message + maybe transfer to PHY layer
4160
	LOG_I( RRC, "[FRAME %05"PRIu32"][RRC_UE][MOD %02"PRIu8"][][--- MAC_CONFIG_REQ (SIB13 params eNB %"PRIu8") --->][MAC_UE][MOD %02"PRIu8"][]\n",
4161
	       ctxt_pP->frame, ctxt_pP->module_id, eNB_index, ctxt_pP->module_id);
4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181
	rrc_mac_config_req_ue(ctxt_pP->module_id,0,eNB_index,
			      (RadioResourceConfigCommonSIB_t *)NULL,
			      (struct PhysicalConfigDedicated *)NULL,
			      (SCellToAddMod_r10_t *)NULL,
			      (MeasObjectToAddMod_t **)NULL,
			      (MAC_MainConfig_t *)NULL,
			      0,
			      (struct LogicalChannelConfig *)NULL,
			      (MeasGapConfig_t *)NULL,
			      (TDD_Config_t *)NULL,
			      (MobilityControlInfo_t *)NULL,
			      NULL,
			      NULL,
			      NULL,
			      NULL,
			      NULL,
			      (MBSFN_SubframeConfigList_t *)NULL,
			      0,
			      &UE_rrc_inst[ctxt_pP->module_id].sib13[eNB_index]->mbsfn_AreaInfoList_r9,
			      (PMCH_InfoList_r9_t *)NULL
4182
#ifdef CBA
4183 4184
			      ,0,
			      0
4185 4186 4187
#endif
#if defined(Rel14)
           ,
4188
           0,
4189
           NULL,
4190
           NULL,
4191
           NULL
4192
#endif
4193
			      );
4194 4195
	break;
      }
4196
#endif
4197 4198 4199

#if defined(Rel10) || defined(Rel14)
      //SIB18
4200 4201 4202 4203 4204 4205 4206 4207 4208 4209
    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib18_v1250:
       if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&8192) == 0) {
          UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=8192;
          new_sib=1;

          memcpy( UE_rrc_inst[ctxt_pP->module_id].sib18[eNB_index], &typeandinfo->choice.sib18_v1250, sizeof(SystemInformationBlockType18_r12_t) );
          LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB18 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
          dump_sib18( UE_rrc_inst[ctxt_pP->module_id].sib18[eNB_index] );
          // adding here function to store necessary parameters to transfer to PHY layer
          LOG_I( RRC, "[FRAME %05"PRIu32"][RRC_UE][MOD %02"PRIu8"][][--- MAC_CONFIG_REQ (SIB18 params eNB %"PRIu8") --->][MAC_UE][MOD %02"PRIu8"][]\n",
4210
                ctxt_pP->frame, ctxt_pP->module_id, eNB_index, ctxt_pP->module_id);
4211 4212

          //process SIB18 to transfer SL-related parameters to PHY
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
4213
          rrc_ue_process_sidelink_radioResourceConfig(ctxt_pP->module_id,eNB_index,
4214 4215 4216 4217
                UE_rrc_inst[ctxt_pP->module_id].sib18[eNB_index],
                (SystemInformationBlockType19_r12_t *)NULL,
                (SL_CommConfig_r12_t *)NULL,
                (SL_DiscConfig_r12_t *)NULL
4218
          );
4219 4220 4221 4222

       }
       break;

4223 4224 4225 4226 4227
       //SIB19
    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib19_v1250:
       if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&16384) == 0) {
          UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=16384;
          new_sib=1;
4228

4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241
          memcpy( UE_rrc_inst[ctxt_pP->module_id].sib19[eNB_index], &typeandinfo->choice.sib19_v1250, sizeof(SystemInformationBlockType19_r12_t) );
          LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB19 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
          dump_sib19( UE_rrc_inst[ctxt_pP->module_id].sib19[eNB_index] );
          // adding here function to store necessary parameters to transfer to PHY layer
          LOG_I( RRC, "[FRAME %05"PRIu32"][RRC_UE][MOD %02"PRIu8"][][--- MAC_CONFIG_REQ (SIB19 params eNB %"PRIu8") --->][MAC_UE][MOD %02"PRIu8"][]\n",
                ctxt_pP->frame, ctxt_pP->module_id, eNB_index, ctxt_pP->module_id);
          //process SIB19 to transfer SL-related parameters to PHY
          rrc_ue_process_sidelink_radioResourceConfig(ctxt_pP->module_id,eNB_index,
                (SystemInformationBlockType18_r12_t *)NULL,
                UE_rrc_inst[ctxt_pP->module_id].sib19[eNB_index],
                (SL_CommConfig_r12_t *)NULL,
                (SL_DiscConfig_r12_t *)NULL
          );
4242

4243 4244
       }
       break;
4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263

       //SIB21
    case SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib21_v1430:
       if ((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&32768) == 0) {
          UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus|=32768;
          new_sib=1;

          memcpy( UE_rrc_inst[ctxt_pP->module_id].sib21[eNB_index], &typeandinfo->choice.sib21_v1430, sizeof(SystemInformationBlockType21_r14_t) );
          LOG_I( RRC, "[UE %"PRIu8"] Frame %"PRIu32" Found SIB21 from eNB %"PRIu8"\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index );
          dump_sib21( UE_rrc_inst[ctxt_pP->module_id].sib21[eNB_index] );
          // adding here function to store necessary parameters to transfer to PHY layer
          LOG_I( RRC, "[FRAME %05"PRIu32"][RRC_UE][MOD %02"PRIu8"][][--- MAC_CONFIG_REQ (SIB21 params eNB %"PRIu8") --->][MAC_UE][MOD %02"PRIu8"][]\n",
                ctxt_pP->frame, ctxt_pP->module_id, eNB_index, ctxt_pP->module_id);
          //process SIB21
          //TODO
       }
       break;


4264
#endif
4265 4266 4267
    default:
      break;
    }
4268 4269

  }
4270 4271 4272 4273 4274 4275
  if (new_sib == 1) {
    UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIcnt++;

    if (UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIcnt == sib1->schedulingInfoList.list.count)
      rrc_set_sub_state( ctxt_pP->module_id, RRC_SUB_STATE_IDLE_SIB_COMPLETE );

4276
    LOG_I(RRC,"SIStatus %x, SIcnt %d/%d\n",
4277 4278 4279 4280
	  UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus,
	  UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIcnt,
	  sib1->schedulingInfoList.list.count);
  }
4281

4282
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_UE_DECODE_SI  , VCD_FUNCTION_OUT);
4283 4284 4285
  return 0;
}

4286
// layer 3 filtering of RSRP (EUTRA) measurements: 36.331, Sec. 5.5.3.2
4287
//-----------------------------------------------------------------------------
4288
void ue_meas_filtering( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index )
4289
{
4290 4291
  float a  = UE_rrc_inst[ctxt_pP->module_id].filter_coeff_rsrp; // 'a' in 36.331 Sec. 5.5.3.2
  float a1 = UE_rrc_inst[ctxt_pP->module_id].filter_coeff_rsrq;
4292
  //float rsrp_db, rsrq_db;
4293
  uint8_t    eNB_offset;
4294

4295 4296 4297
  if(UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[0] != NULL) { // Only consider 1 serving cell (index: 0)
    if (UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[0]->quantityConfigEUTRA != NULL) {
      if(UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[0]->quantityConfigEUTRA->filterCoefficientRSRP != NULL) {
4298 4299 4300 4301 4302 4303 4304
        for (eNB_offset = 0; eNB_offset<1+get_n_adj_cells(ctxt_pP->module_id,0); eNB_offset++) {
          UE_rrc_inst[ctxt_pP->module_id].rsrp_db[eNB_offset] = get_RSRP(ctxt_pP->module_id,0,eNB_offset);
	  /*
	  (dB_fixed_times10(get_RSRP(ctxt_pP->module_id,0,eNB_offset))/10.0) -
	  get_rx_total_gain_dB(ctxt_pP->module_id,0) -
	  get_bw_gain_dB(ctxt_pP->module_id);
	  */
4305 4306 4307
          UE_rrc_inst[ctxt_pP->module_id].rsrp_db_filtered[eNB_offset] =
            (1.0-a)*UE_rrc_inst[ctxt_pP->module_id].rsrp_db_filtered[eNB_offset] +
            a*UE_rrc_inst[ctxt_pP->module_id].rsrp_db[eNB_offset];
4308

4309 4310 4311
          LOG_D(RRC,"RSRP_dBm: %3.2f \n",get_RSRP(ctxt_pP->module_id,0,eNB_offset));;
	  /*          LOG_D(RRC,"gain_loss_dB: %d \n",get_rx_total_gain_dB(ctxt_pP->module_id,0));
		      LOG_D(RRC,"gain_fixed_dB: %d \n",dB_fixed(frame_parms->N_RB_DL*12));*/
4312
          LOG_D(PHY,"[UE %d] Frame %d, RRC Measurements => rssi %3.1f dBm (digital: %3.1f dB)\n",
4313 4314
                ctxt_pP->module_id,
                ctxt_pP->frame,
4315 4316
                10*log10(get_RSSI(ctxt_pP->module_id,0))-get_rx_total_gain_dB(ctxt_pP->module_id,0),
                10*log10(get_RSSI(ctxt_pP->module_id,0)));
Cedric Roux's avatar
Cedric Roux committed
4317
          LOG_D(RRC,"[UE %d] Frame %d: Meas RSRP: eNB_offset: %d rsrp_coef: %3.1f filter_coef: %ld before L3 filtering: rsrp: %3.1f after L3 filtering: rsrp: %3.1f \n ",
4318 4319
                ctxt_pP->module_id,
                ctxt_pP->frame, eNB_offset,a,
4320
                *UE_rrc_inst->QuantityConfig[0]->quantityConfigEUTRA->filterCoefficientRSRP,
4321 4322
                UE_rrc_inst[ctxt_pP->module_id].rsrp_db[eNB_offset],
                UE_rrc_inst[ctxt_pP->module_id].rsrp_db_filtered[eNB_offset]);
4323
        }
4324
      }
4325
    } else {
4326 4327
      for (eNB_offset = 0; eNB_offset<1+get_n_adj_cells(ctxt_pP->module_id,0); eNB_offset++) {
        UE_rrc_inst[ctxt_pP->module_id].rsrp_db_filtered[eNB_offset]= get_RSRP(ctxt_pP->module_id,0,eNB_offset);
4328
      }
4329 4330
    }

4331 4332
    if (UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[0]->quantityConfigEUTRA != NULL) {
      if(UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[0]->quantityConfigEUTRA->filterCoefficientRSRQ != NULL) {
4333 4334
        for (eNB_offset = 0; eNB_offset<1+get_n_adj_cells(ctxt_pP->module_id,0); eNB_offset++) {
          UE_rrc_inst[ctxt_pP->module_id].rsrq_db[eNB_offset] = (10*log10(get_RSRQ(ctxt_pP->module_id,0,eNB_offset)))-20;
4335 4336
          UE_rrc_inst[ctxt_pP->module_id].rsrq_db_filtered[eNB_offset]=(1-a1)*UE_rrc_inst[ctxt_pP->module_id].rsrq_db_filtered[eNB_offset] +
              a1 *UE_rrc_inst[ctxt_pP->module_id].rsrq_db[eNB_offset];
4337
        }
4338
      }
4339
    } else {
4340 4341
      for (eNB_offset = 0; eNB_offset<1+get_n_adj_cells(ctxt_pP->module_id,0); eNB_offset++) {
        UE_rrc_inst[ctxt_pP->module_id].rsrq_db_filtered[eNB_offset]= get_RSRQ(ctxt_pP->module_id,0,eNB_offset);
4342
      }
4343
    }
4344 4345 4346
  }
}

4347
//Below routine implements Measurement Reporting procedure from 36.331 Section 5.5.5
4348
//-----------------------------------------------------------------------------
4349
 void rrc_ue_generate_MeasurementReport(protocol_ctxt_t* const ctxt_pP, uint8_t eNB_index )
4350
{
4351 4352 4353 4354 4355 4356

  uint8_t             buffer[32], size;
  uint8_t             i;
  uint8_t             target_eNB_offset;
  MeasId_t         measId;
  PhysCellId_t     cellId, targetCellId;
4357 4358 4359
  long             rsrp_t,rsrq_t;
  long             rsrp_s,rsrq_s;
  long             nElem, nElem1;
4360 4361 4362
  float            rsrp_filtered, rsrq_filtered;
  static frame_t   pframe=0;
  int              result;
4363 4364 4365

  nElem = 98;
  nElem1 = 35;
4366
  target_eNB_offset = UE_rrc_inst[ctxt_pP->module_id].Info[0].handoverTarget; // eNB_offset of target eNB: used to obtain the mod_id of target eNB
4367

4368
  for (i=0; i<MAX_MEAS_ID; i++) {
4369 4370
    if (UE_rrc_inst[ctxt_pP->module_id].measReportList[0][i] != NULL) {
      measId = UE_rrc_inst[ctxt_pP->module_id].measReportList[0][i]->measId;
4371 4372

      // Note: Values in the meas report have to be the mapped values...to implement binary search for LUT
4373
      rsrp_filtered = UE_rrc_inst[ctxt_pP->module_id].rsrp_db_filtered[eNB_index];//nid_cell];
4374 4375
      rsrp_s = binary_search_float(RSRP_meas_mapping,nElem, rsrp_filtered);

4376
      rsrq_filtered = UE_rrc_inst[ctxt_pP->module_id].rsrq_db_filtered[eNB_index];//nid_cell]; //RSRQ of serving cell
4377 4378 4379
      rsrq_s = binary_search_float(RSRQ_meas_mapping,nElem1,rsrq_filtered);//mapped RSRQ of serving cell

      LOG_D(RRC,"[UE %d] Frame %d: source eNB %d :rsrp_s: %ld rsrq_s: %ld rsrp_filtered: %f rsrq_filtered: %f \n",
4380 4381 4382 4383 4384 4385 4386 4387 4388
            ctxt_pP->module_id,
            ctxt_pP->frame,
            eNB_index,
            rsrp_s,
            rsrq_s,
            rsrp_filtered,
            rsrq_filtered);
      rsrp_t = binary_search_float(RSRP_meas_mapping,nElem,UE_rrc_inst[ctxt_pP->module_id].rsrp_db_filtered[target_eNB_offset]); //RSRP of target cell
      rsrq_t = binary_search_float(RSRQ_meas_mapping,nElem1,UE_rrc_inst[ctxt_pP->module_id].rsrq_db_filtered[target_eNB_offset]); //RSRQ of target cell
4389 4390

      LOG_D(RRC,"[UE %d] Frame %d: target eNB %d :rsrp_t: %ld rsrq_t: %ld rsrp_filtered: %f rsrq_filtered: %f \n",
4391 4392 4393 4394 4395 4396 4397
            ctxt_pP->module_id,
            ctxt_pP->frame,
            target_eNB_offset,
            rsrp_t,
            rsrq_t,
            UE_rrc_inst[ctxt_pP->module_id].rsrp_db_filtered[target_eNB_offset],
            UE_rrc_inst[ctxt_pP->module_id].rsrq_db_filtered[target_eNB_offset]);
4398 4399

      //  if (measFlag == 1) {
4400 4401
      cellId = get_adjacent_cell_id(ctxt_pP->module_id, eNB_index); //PhycellId of serving cell
      targetCellId = UE_rrc_inst[ctxt_pP->module_id].HandoverInfoUe.targetCellId ;//get_adjacent_cell_id(ue_mod_idP,target_eNB_offset); //PhycellId of target cell
4402

4403 4404
      if (pframe!=ctxt_pP->frame) {
        pframe=ctxt_pP->frame;
Cedric Roux's avatar
Cedric Roux committed
4405
        LOG_D(RRC, "[UE %d] Frame %d: doing MeasReport: servingCell(%ld) targetCell(%ld) rsrp_s(%ld) rsrq_s(%ld) rsrp_t(%ld) rsrq_t(%ld) \n",
4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416
              ctxt_pP->module_id,
              ctxt_pP->frame,
              cellId,
              targetCellId,
              rsrp_s,
              rsrq_s,
              rsrp_t,
              rsrq_t);
        size = do_MeasurementReport(ctxt_pP->module_id, buffer,measId,targetCellId,rsrp_s,rsrq_s,rsrp_t,rsrq_t);
        LOG_I(RRC, "[UE %d] Frame %d : Generating Measurement Report for eNB %d\n",
              ctxt_pP->module_id, ctxt_pP->frame, eNB_index);
4417 4418 4419 4420 4421
        result = pdcp_data_req(ctxt_pP,  SRB_FLAG_YES, DCCH, rrc_mui++, 0, size, buffer, PDCP_TRANSMISSION_MODE_DATA
#ifdef Rel14
                               ,NULL, NULL
#endif
                               );
4422 4423
        AssertFatal (result == TRUE, "PDCP data request failed!\n");
        //LOG_D(RRC, "[UE %d] Frame %d Sending MeasReport (%d bytes) through DCCH%d to PDCP \n",ue_mod_idP,frameP, size, DCCH);
4424
      }
4425 4426 4427 4428

      //          measFlag = 0; //re-setting measFlag so that no more MeasReports are sent in this frameP
      //          }
    }
4429 4430 4431
  }
}

4432
// Measurement report triggering, described in 36.331 Section 5.5.4.1: called periodically
4433
//-----------------------------------------------------------------------------
4434
void ue_measurement_report_triggering(protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index )
4435
{
4436
  uint8_t               i,j;
4437 4438 4439 4440 4441 4442 4443 4444
  Hysteresis_t     hys;
  TimeToTrigger_t  ttt_ms;
  Q_OffsetRange_t  ofn;
  Q_OffsetRange_t  ocn;
  Q_OffsetRange_t  ofs = 0;
  Q_OffsetRange_t  ocs = 0;
  long             a3_offset;
  MeasObjectId_t   measObjId;
4445
  ReportConfigId_t reportConfigId;
4446

4447
  for(i=0 ; i<NB_CNX_UE ; i++) {
4448
    for(j=0 ; j<MAX_MEAS_ID ; j++) {
4449 4450 4451
      if(UE_rrc_inst[ctxt_pP->module_id].MeasId[i][j] != NULL) {
        measObjId = UE_rrc_inst[ctxt_pP->module_id].MeasId[i][j]->measObjectId;
        reportConfigId = UE_rrc_inst[ctxt_pP->module_id].MeasId[i][j]->reportConfigId;
4452

4453 4454
        if( /*UE_rrc_inst[ctxt_pP->module_id].MeasId[i][j] != NULL && */ UE_rrc_inst[ctxt_pP->module_id].MeasObj[i][measObjId-1] != NULL) {
          if(UE_rrc_inst[ctxt_pP->module_id].MeasObj[i][measObjId-1]->measObject.present == MeasObjectToAddMod__measObject_PR_measObjectEUTRA) {
4455 4456 4457
            /* consider any neighboring cell detected on the associated frequency to be
             * applicable when the concerned cell is not included in the blackCellsToAddModList
             * defined within the VarMeasConfig for this measId */
4458 4459 4460 4461 4462 4463 4464 4465 4466
            //    LOG_I(RRC,"event %d %d %p \n", measObjId,reportConfigId, UE_rrc_inst[ctxt_pP->module_id].ReportConfig[i][reportConfigId-1]);
            if((UE_rrc_inst[ctxt_pP->module_id].ReportConfig[i][reportConfigId-1] != NULL) &&
                (UE_rrc_inst[ctxt_pP->module_id].ReportConfig[i][reportConfigId-1]->reportConfig.present==ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA) &&
                (UE_rrc_inst[ctxt_pP->module_id].ReportConfig[i][reportConfigId-1]->reportConfig.choice.reportConfigEUTRA.triggerType.present ==
                 ReportConfigEUTRA__triggerType_PR_event)) {
              hys = UE_rrc_inst[ctxt_pP->module_id].ReportConfig[i][reportConfigId-1]->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.hysteresis;
              //LOG_N(RRC,"[UE%d] Frame %d Check below lines for segfault :), Fix me \n",ctxt_pP->module_id, frameP);
              ttt_ms = timeToTrigger_ms[UE_rrc_inst[ctxt_pP->module_id].ReportConfig[i][reportConfigId
                                        -1]->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.timeToTrigger];
4467
              // Freq specific offset of neighbor cell freq
4468 4469
              ofn = 5;//((UE_rrc_inst[ctxt_pP->module_id].MeasObj[i][measObjId-1]->measObject.choice.measObjectEUTRA.offsetFreq != NULL) ?
              // *UE_rrc_inst[ctxt_pP->module_id].MeasObj[i][measObjId-1]->measObject.choice.measObjectEUTRA.offsetFreq : 15); //  /* 15 is the Default */
4470 4471
              // cellIndividualOffset of neighbor cell - not defined yet
              ocn = 0;
4472 4473
              a3_offset = UE_rrc_inst[ctxt_pP->module_id].ReportConfig[i][reportConfigId
                          -1]->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA3.a3_Offset;
4474

4475
              switch (UE_rrc_inst[ctxt_pP->module_id].ReportConfig[i][reportConfigId-1]->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present) {
4476
              case ReportConfigEUTRA__triggerType__event__eventId_PR_eventA1:
4477 4478
                LOG_D(RRC,"[UE %d] Frame %d : A1 event: check if serving becomes better than threshold\n",
                      ctxt_pP->module_id, ctxt_pP->frame);
4479 4480 4481
                break;

              case ReportConfigEUTRA__triggerType__event__eventId_PR_eventA2:
4482 4483
                LOG_D(RRC,"[UE %d] Frame %d : A2 event, check if serving becomes worse than a threshold\n",
                      ctxt_pP->module_id, ctxt_pP->frame);
4484 4485 4486
                break;

              case ReportConfigEUTRA__triggerType__event__eventId_PR_eventA3:
4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497
                LOG_D(RRC,"[UE %d] Frame %d : A3 event: check if a neighboring cell becomes offset better than serving to trigger a measurement event \n",
                      ctxt_pP->module_id, ctxt_pP->frame);

                if ((check_trigger_meas_event(
                       ctxt_pP->module_id,
                       ctxt_pP->frame,
                       eNB_index,
                       i,j,ofn,ocn,hys,ofs,ocs,a3_offset,ttt_ms)) &&
                    (UE_rrc_inst[ctxt_pP->module_id].Info[0].State >= RRC_CONNECTED) &&
                    (UE_rrc_inst[ctxt_pP->module_id].Info[0].T304_active == 0 )      &&
                    (UE_rrc_inst[ctxt_pP->module_id].HandoverInfoUe.measFlag == 1)) {
4498
                  //trigger measurement reporting procedure (36.331, section 5.5.5)
4499 4500
                  if (UE_rrc_inst[ctxt_pP->module_id].measReportList[i][j] == NULL) {
                    UE_rrc_inst[ctxt_pP->module_id].measReportList[i][j] = malloc(sizeof(MEAS_REPORT_LIST));
4501 4502
                  }

4503 4504 4505 4506 4507 4508 4509 4510
                  UE_rrc_inst[ctxt_pP->module_id].measReportList[i][j]->measId = UE_rrc_inst[ctxt_pP->module_id].MeasId[i][j]->measId;
                  UE_rrc_inst[ctxt_pP->module_id].measReportList[i][j]->numberOfReportsSent = 0;
                  rrc_ue_generate_MeasurementReport(
                    ctxt_pP,
                    eNB_index);
                  UE_rrc_inst[ctxt_pP->module_id].HandoverInfoUe.measFlag = 1;
                  LOG_I(RRC,"[UE %d] Frame %d: A3 event detected, state: %d \n",
                        ctxt_pP->module_id, ctxt_pP->frame, UE_rrc_inst[ctxt_pP->module_id].Info[0].State);
4511
                } else {
4512 4513
                  if(UE_rrc_inst[ctxt_pP->module_id].measReportList[i][j] != NULL) {
                    free(UE_rrc_inst[ctxt_pP->module_id].measReportList[i][j]);
4514
                  }
4515

4516
                  UE_rrc_inst[ctxt_pP->module_id].measReportList[i][j] = NULL;
4517 4518 4519 4520 4521
                }

                break;

              case ReportConfigEUTRA__triggerType__event__eventId_PR_eventA4:
4522 4523
                LOG_D(RRC,"[UE %d] Frame %d : received an A4 event, neighbor becomes offset better than a threshold\n",
                      ctxt_pP->module_id, ctxt_pP->frame);
4524 4525 4526
                break;

              case ReportConfigEUTRA__triggerType__event__eventId_PR_eventA5:
4527 4528
                LOG_D(RRC,"[UE %d] Frame %d: received an A5 event, serving becomes worse than threshold 1 and neighbor becomes better than threshold 2\n",
                      ctxt_pP->module_id, ctxt_pP->frame);
4529 4530 4531 4532
                break;

              default:
                LOG_D(RRC,"Invalid ReportConfigEUTRA__triggerType__event__eventId: %d",
4533
                      UE_rrc_inst[ctxt_pP->module_id].ReportConfig[i][j]->reportConfig.choice.reportConfigEUTRA.triggerType.present);
4534
                break;
winckel's avatar
winckel committed
4535
              }
4536
            }
winckel's avatar
winckel committed
4537
          }
4538
        }
4539
      }
4540
    }
4541 4542 4543
  }
}

Lionel Gauthier's avatar
 
Lionel Gauthier committed
4544
//check_trigger_meas_event(ue_mod_idP, frameP, eNB_index, i,j,ofn,ocn,hys,ofs,ocs,a3_offset,ttt_ms)
4545
//-----------------------------------------------------------------------------
4546

4547
 uint8_t check_trigger_meas_event(
4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558
  module_id_t     ue_mod_idP,
  frame_t         frameP,
  uint8_t         eNB_index,
  uint8_t         ue_cnx_index,
  uint8_t         meas_index,
  Q_OffsetRange_t ofn,
  Q_OffsetRange_t ocn,
  Hysteresis_t    hys,
  Q_OffsetRange_t ofs,
  Q_OffsetRange_t ocs,
  long            a3_offset,
4559
  TimeToTrigger_t ttt )
Lionel Gauthier's avatar
Lionel Gauthier committed
4560
{
4561
  uint8_t eNB_offset;
4562
  //  uint8_t currentCellIndex = frame_parms->Nid_cell;
4563
  uint8_t tmp_offset;
Lionel Gauthier's avatar
Lionel Gauthier committed
4564

Cedric Roux's avatar
Cedric Roux committed
4565
  LOG_I(RRC,"[UE %d] ofn(%ld) ocn(%ld) hys(%ld) ofs(%ld) ocs(%ld) a3_offset(%ld) ttt(%ld) rssi %3.1f\n",
4566 4567
        ue_mod_idP,
        ofn,ocn,hys,ofs,ocs,a3_offset,ttt,
4568
        10*log10(get_RSSI(ue_mod_idP,0))-get_rx_total_gain_dB(ue_mod_idP,0));
4569

4570
  for (eNB_offset = 0; eNB_offset<1+get_n_adj_cells(ue_mod_idP,0); eNB_offset++) {
4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581
    /* RHS: Verify that idx 0 corresponds to currentCellIndex in rsrp array */
    if((eNB_offset!=eNB_index)&&(eNB_offset<NB_eNB_INST)) {
      if(eNB_offset<eNB_index) {
        tmp_offset = eNB_offset;
      } else {
        tmp_offset = eNB_offset-1;
      }

      if(UE_rrc_inst[ue_mod_idP].rsrp_db_filtered[eNB_offset]+ofn+ocn-hys > UE_rrc_inst[ue_mod_idP].rsrp_db_filtered[eNB_index]+ofs+ocs-1/*+a3_offset*/) {
        UE_rrc_inst->measTimer[ue_cnx_index][meas_index][tmp_offset] += 2; //Called every subframe = 2ms
        LOG_D(RRC,"[UE %d] Frame %d: Entry measTimer[%d][%d][%d]: %d currentCell: %d betterCell: %d \n",
4582
              ue_mod_idP, frameP, ue_cnx_index,meas_index,tmp_offset,UE_rrc_inst->measTimer[ue_cnx_index][meas_index][tmp_offset],0,eNB_offset);
4583 4584 4585
      } else {
        UE_rrc_inst->measTimer[ue_cnx_index][meas_index][tmp_offset] = 0; //Exit condition: Resetting the measurement timer
        LOG_D(RRC,"[UE %d] Frame %d: Exit measTimer[%d][%d][%d]: %d currentCell: %d betterCell: %d \n",
4586
              ue_mod_idP, frameP, ue_cnx_index,meas_index,tmp_offset,UE_rrc_inst->measTimer[ue_cnx_index][meas_index][tmp_offset],0,eNB_offset);
4587 4588 4589 4590
      }

      if (UE_rrc_inst->measTimer[ue_cnx_index][meas_index][tmp_offset] >= ttt) {
        UE_rrc_inst->HandoverInfoUe.targetCellId = get_adjacent_cell_id(ue_mod_idP,tmp_offset); //WARNING!!!...check this!
4591
        LOG_D(RRC,"[UE %d] Frame %d eNB %d: Handover triggered: targetCellId: %ld currentCellId: %d eNB_offset: %d rsrp source: %3.1f rsrp target: %3.1f\n",
4592 4593
              ue_mod_idP, frameP, eNB_index,
              UE_rrc_inst->HandoverInfoUe.targetCellId,ue_cnx_index,eNB_offset,
4594 4595
	      get_RSRP(ue_mod_idP,0,0),
	      get_RSRP(ue_mod_idP,0,1));
4596 4597 4598 4599 4600 4601 4602 4603 4604
        UE_rrc_inst->Info[0].handoverTarget = eNB_offset;
        //LOG_D(RRC,"PHY_ID: %d \n",UE_rrc_inst->HandoverInfoUe.targetCellId);
        return 1;
      }

      // else{
      //  LOG_D(RRC,"Condition does not hold\n");
      // }
    }
4605
  }
4606

4607 4608 4609
  return 0;
}

Cedric Roux's avatar
Cedric Roux committed
4610
#if defined(Rel10) || defined(Rel14)
4611
//-----------------------------------------------------------------------------
4612
int decode_MCCH_Message( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index, const uint8_t* const Sdu, const uint8_t Sdu_len, const uint8_t mbsfn_sync_area )
Lionel Gauthier's avatar
Lionel Gauthier committed
4613
{
4614

Lionel Gauthier's avatar
Lionel Gauthier committed
4615
  MCCH_Message_t               *mcch=NULL;
4616
  MBSFNAreaConfiguration_r9_t** mcch_message=&UE_rrc_inst[ctxt_pP->module_id].mcch_message[eNB_index];
4617

Lionel Gauthier's avatar
Lionel Gauthier committed
4618
  asn_dec_rval_t                dec_rval;
4619

4620
  if (UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].MCCHStatus[mbsfn_sync_area] == 1) {
4621
    LOG_D(RRC,"[UE %d] Frame %d: MCCH MESSAGE for MBSFN sync area %d has been already received!\n",
4622 4623 4624
          ctxt_pP->module_id,
          ctxt_pP->frame,
          mbsfn_sync_area);
4625 4626 4627 4628 4629 4630 4631 4632 4633
    return 0; // avoid decoding to prevent memory bloating
  } else {
    dec_rval = uper_decode_complete(NULL,
                                    &asn_DEF_MCCH_Message,
                                    (void **)&mcch,
                                    (const void *)Sdu,
                                    Sdu_len);

    if ((dec_rval.code != RC_OK) && (dec_rval.consumed==0)) {
Cedric Roux's avatar
Cedric Roux committed
4634
      LOG_E(RRC,"[UE %d] Failed to decode MCCH__MESSAGE (%lu bits)\n",
4635 4636
            ctxt_pP->module_id,
            dec_rval.consumed);
4637 4638 4639 4640 4641
      //free the memory
      SEQUENCE_free(&asn_DEF_MCCH_Message, (void*)mcch, 1);
      return -1;
    }

4642
#ifdef XER_PRINT
4643
    xer_fprint(stdout, &asn_DEF_MCCH_Message, (void*)mcch);
4644 4645
#endif

4646
    if (mcch->message.present == MCCH_MessageType_PR_c1) {
4647 4648
      LOG_D(RRC,"[UE %d] Found mcch message \n",
            ctxt_pP->module_id);
4649 4650 4651

      if(mcch->message.choice.c1.present == MCCH_MessageType__c1_PR_mbsfnAreaConfiguration_r9) {
        /*
winckel's avatar
winckel committed
4652
        memcpy((void*)*mcch_message,
4653 4654 4655
         (void*)&mcch->message.choice.c1.choice.mbsfnAreaConfiguration_r9,
         sizeof(MBSFNAreaConfiguration_r9_t)); */
        *mcch_message = &mcch->message.choice.c1.choice.mbsfnAreaConfiguration_r9;
4656 4657 4658 4659 4660 4661 4662 4663 4664
        LOG_I(RRC,"[UE %d] Frame %d : Found MBSFNAreaConfiguration from eNB %d \n",
              ctxt_pP->module_id,
              ctxt_pP->frame,
              eNB_index);
        decode_MBSFNAreaConfiguration(
          ctxt_pP->module_id,
          eNB_index,
          ctxt_pP->frame,
          mbsfn_sync_area);
4665 4666

      }
4667
    }
4668
  }
4669

4670 4671 4672
  return 0;
}

4673
//-----------------------------------------------------------------------------
4674
 void decode_MBSFNAreaConfiguration( module_id_t ue_mod_idP, uint8_t eNB_index, frame_t frameP, uint8_t mbsfn_sync_area )
Lionel Gauthier's avatar
Lionel Gauthier committed
4675
{
4676
  protocol_ctxt_t               ctxt;
Lionel Gauthier's avatar
Lionel Gauthier committed
4677

4678
  LOG_I(RRC,"[UE %d] Frame %d : Number of MCH(s) in the MBSFN Sync Area %d  is %d\n",
4679
        ue_mod_idP, frameP, mbsfn_sync_area, UE_rrc_inst[ue_mod_idP].mcch_message[eNB_index]->pmch_InfoList_r9.list.count);
4680
  //  store to MAC/PHY necessary parameters for receiving MTCHs
4681

4682 4683 4684
  rrc_mac_config_req_ue(ue_mod_idP,0,eNB_index,
			(RadioResourceConfigCommonSIB_t *)NULL,
			(struct PhysicalConfigDedicated *)NULL,
Cedric Roux's avatar
Cedric Roux committed
4685
#if defined(Rel10) || defined(Rel14)
4686 4687
			(SCellToAddMod_r10_t *)NULL,
			//(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
4688
#endif
4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701
			(MeasObjectToAddMod_t **)NULL,
			(MAC_MainConfig_t *)NULL,
			0,
			(struct LogicalChannelConfig *)NULL,
			(MeasGapConfig_t *)NULL,
			(TDD_Config_t *)NULL,
			(MobilityControlInfo_t *)NULL,
			NULL,
			NULL,
			NULL,
			NULL,
			NULL,
			(MBSFN_SubframeConfigList_t *)NULL
Cedric Roux's avatar
Cedric Roux committed
4702
#if defined(Rel10) || defined(Rel14)
4703 4704 4705 4706
			,
			0,
			(MBSFN_AreaInfoList_r9_t *)NULL,
			&UE_rrc_inst[ue_mod_idP].mcch_message[eNB_index]->pmch_InfoList_r9
4707

4708 4709
#endif
#ifdef CBA
4710 4711 4712
			,
			0,
			0
4713 4714 4715
#endif
#if defined(Rel14)
           ,
4716
           0,
4717
           NULL,
4718
           NULL,
4719
           NULL
4720
#endif
4721
			);
4722

Lionel Gauthier's avatar
 
Lionel Gauthier committed
4723
  UE_rrc_inst[ue_mod_idP].Info[eNB_index].MCCHStatus[mbsfn_sync_area] = 1;
4724

4725
  PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_idP, ENB_FLAG_NO, UE_rrc_inst[ue_mod_idP].Info[eNB_index].rnti, frameP, 0,eNB_index);
Lionel Gauthier's avatar
Lionel Gauthier committed
4726

4727
  // Config Radio Bearer for MBMS user data (similar way to configure for eNB side in init_MBMS function)
Lionel Gauthier's avatar
Lionel Gauthier committed
4728
  rrc_pdcp_config_asn1_req(&ctxt,
4729 4730 4731 4732 4733 4734 4735
                           NULL, // SRB_ToAddModList
                           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
4736
#if defined(Rel10) || defined(Rel14)
4737
                           ,&(UE_rrc_inst[ue_mod_idP].mcch_message[eNB_index]->pmch_InfoList_r9)
4738
#endif
4739
                           ,NULL);
winckel's avatar
winckel committed
4740

Lionel Gauthier's avatar
Lionel Gauthier committed
4741
  rrc_rlc_config_asn1_req(&ctxt,
4742 4743 4744
                          NULL,// SRB_ToAddModList
                          NULL,// DRB_ToAddModList
                          NULL,// DRB_ToReleaseList
Cedric Roux's avatar
Cedric Roux committed
4745
#if defined(Rel10) || defined(Rel14)
4746
                          &(UE_rrc_inst[ue_mod_idP].mcch_message[eNB_index]->pmch_InfoList_r9)
4747
                          , 0, 0
4748 4749
#endif
                         );
4750
  // */
4751

4752 4753 4754 4755
}

#endif // rel10

4756
#if defined(ENABLE_ITTI)
4757
//-----------------------------------------------------------------------------
4758
void *rrc_ue_task( void *args_p )
Lionel Gauthier's avatar
Lionel Gauthier committed
4759
{
4760 4761 4762
  MessageDef   *msg_p;
  const char   *msg_name;
  instance_t    instance;
Lionel Gauthier's avatar
 
Lionel Gauthier committed
4763
  unsigned int  ue_mod_id;
4764 4765
  int           result;
  SRB_INFO     *srb_info_p;
4766

4767
  protocol_ctxt_t  ctxt;
4768 4769 4770
  itti_mark_task_ready (TASK_RRC_UE);

  while(1) {
4771 4772
    // Wait for a message
    itti_receive_msg (TASK_RRC_UE, &msg_p);
4773

4774 4775
    msg_name = ITTI_MSG_NAME (msg_p);
    instance = ITTI_MSG_INSTANCE (msg_p);
4776
    ue_mod_id = UE_INSTANCE_TO_MODULE_ID(instance);
4777

4778 4779
    switch (ITTI_MSG_ID(msg_p)) {
    case TERMINATE_MESSAGE:
4780
      LOG_W(RRC, " *** Exiting RRC thread\n");
4781 4782
      itti_exit_task ();
      break;
4783

4784
    case MESSAGE_TEST:
4785
      LOG_D(RRC, "[UE %d] Received %s\n", ue_mod_id, msg_name);
4786
      break;
4787

4788 4789 4790
      /* MAC messages */
    case RRC_MAC_IN_SYNC_IND:
      LOG_D(RRC, "[UE %d] Received %s: frameP %d, eNB %d\n", ue_mod_id, msg_name,
4791
            RRC_MAC_IN_SYNC_IND (msg_p).frame, RRC_MAC_IN_SYNC_IND (msg_p).enb_index);
4792

4793
      UE_rrc_inst[ue_mod_id].Info[RRC_MAC_IN_SYNC_IND (msg_p).enb_index].N310_cnt = 0;
4794

4795
      if (UE_rrc_inst[ue_mod_id].Info[RRC_MAC_IN_SYNC_IND (msg_p).enb_index].T310_active == 1) {
4796
        UE_rrc_inst[ue_mod_id].Info[RRC_MAC_IN_SYNC_IND (msg_p).enb_index].N311_cnt++;
4797
      }
matzakos's avatar
matzakos committed
4798
      //LOG_I(RRC, "In rrc_ue_task() received RRC_MAC_IN_SYNC_IND message through ITTI, UE RRC state: %d \n", rrc_get_state(ue_mod_id));
4799 4800 4801 4802

      break;

    case RRC_MAC_OUT_OF_SYNC_IND:
matzakos's avatar
matzakos committed
4803
    	//LOG_I(RRC, "In rrc_ue_task() received RRC_MAC_OUT_OF_SYNC_IND message through ITTI, UE RRC state: %d \n", rrc_get_state(ue_mod_id));
4804
      LOG_D(RRC, "[UE %d] Received %s: frameP %d, eNB %d\n", ue_mod_id, msg_name,
4805
            RRC_MAC_OUT_OF_SYNC_IND (msg_p).frame, RRC_MAC_OUT_OF_SYNC_IND (msg_p).enb_index);
4806

4807 4808
      UE_rrc_inst[ue_mod_id].Info[RRC_MAC_OUT_OF_SYNC_IND (msg_p).enb_index].N310_cnt ++;
      break;
4809

4810
    case RRC_MAC_BCCH_DATA_IND:
matzakos's avatar
matzakos committed
4811
    	//LOG_I(RRC, "In rrc_ue_task() received RRC_MAC_BCCH_DATA_IND message through ITTI, UE RRC state: %d \n", rrc_get_state(ue_mod_id));
4812
      LOG_D(RRC, "[UE %d] Received %s: frameP %d, eNB %d\n", ue_mod_id, msg_name,
4813
            RRC_MAC_BCCH_DATA_IND (msg_p).frame, RRC_MAC_BCCH_DATA_IND (msg_p).enb_index);
4814

4815 4816
      //      PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, ENB_FLAG_NO, NOT_A_RNTI, RRC_MAC_BCCH_DATA_IND (msg_p).frame, 0);
      PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_id, ENB_FLAG_NO, NOT_A_RNTI, RRC_MAC_BCCH_DATA_IND (msg_p).frame, 0,RRC_MAC_BCCH_DATA_IND (msg_p).enb_index);
4817 4818 4819
      decode_BCCH_DLSCH_Message (&ctxt,
                                 RRC_MAC_BCCH_DATA_IND (msg_p).enb_index,
                                 RRC_MAC_BCCH_DATA_IND (msg_p).sdu,
4820
                                 RRC_MAC_BCCH_DATA_IND (msg_p).sdu_size,
4821 4822
                                 RRC_MAC_BCCH_DATA_IND (msg_p).rsrq,
                                 RRC_MAC_BCCH_DATA_IND (msg_p).rsrp);
4823
      break;
4824

4825
    case RRC_MAC_CCCH_DATA_CNF:
4826
      LOG_D(RRC, "[UE %d] Received %s: eNB %d\n", ue_mod_id, msg_name,
4827
            RRC_MAC_CCCH_DATA_CNF (msg_p).enb_index);
4828

4829 4830 4831
      // reset the tx buffer to indicate RRC that ccch was successfully transmitted (for example if contention resolution succeeds)
      UE_rrc_inst[ue_mod_id].Srb0[RRC_MAC_CCCH_DATA_CNF (msg_p).enb_index].Tx_buffer.payload_size = 0;
      break;
4832

4833
    case RRC_MAC_CCCH_DATA_IND:
4834
      LOG_D(RRC, "[UE %d] RNTI %x Received %s: frameP %d, eNB %d\n",
4835 4836 4837 4838 4839
            ue_mod_id,
            RRC_MAC_CCCH_DATA_IND (msg_p).rnti,
            msg_name,
            RRC_MAC_CCCH_DATA_IND (msg_p).frame,
            RRC_MAC_CCCH_DATA_IND (msg_p).enb_index);
4840

4841
      srb_info_p = &UE_rrc_inst[ue_mod_id].Srb0[RRC_MAC_CCCH_DATA_IND (msg_p).enb_index];
4842

4843 4844 4845
      memcpy (srb_info_p->Rx_buffer.Payload, RRC_MAC_CCCH_DATA_IND (msg_p).sdu,
              RRC_MAC_CCCH_DATA_IND (msg_p).sdu_size);
      srb_info_p->Rx_buffer.payload_size = RRC_MAC_CCCH_DATA_IND (msg_p).sdu_size;
4846 4847
      //      PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, ENB_FLAG_NO, RRC_MAC_CCCH_DATA_IND (msg_p).rnti, RRC_MAC_CCCH_DATA_IND (msg_p).frame, 0);
      PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_id, ENB_FLAG_NO, RRC_MAC_CCCH_DATA_IND (msg_p).rnti, RRC_MAC_CCCH_DATA_IND (msg_p).frame, 0, RRC_MAC_CCCH_DATA_IND (msg_p).enb_index);
4848 4849
      rrc_ue_decode_ccch (&ctxt,
                          srb_info_p,
4850 4851
                          RRC_MAC_CCCH_DATA_IND (msg_p).enb_index);
      break;
4852

Cedric Roux's avatar
Cedric Roux committed
4853
# if defined(Rel10) || defined(Rel14)
4854 4855

    case RRC_MAC_MCCH_DATA_IND:
4856
      LOG_D(RRC, "[UE %d] Received %s: frameP %d, eNB %d, mbsfn SA %d\n", ue_mod_id, msg_name,
4857
            RRC_MAC_MCCH_DATA_IND (msg_p).frame, RRC_MAC_MCCH_DATA_IND (msg_p).enb_index, RRC_MAC_MCCH_DATA_IND (msg_p).mbsfn_sync_area);
4858

4859 4860
      //PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, ENB_FLAG_NO, M_RNTI, RRC_MAC_MCCH_DATA_IND (msg_p).frame, 0);
      PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_id, ENB_FLAG_NO, M_RNTI, RRC_MAC_MCCH_DATA_IND (msg_p).frame, 0,RRC_MAC_MCCH_DATA_IND (msg_p).enb_index);
4861 4862 4863 4864 4865
      decode_MCCH_Message (
        &ctxt,
        RRC_MAC_MCCH_DATA_IND (msg_p).enb_index,
        RRC_MAC_MCCH_DATA_IND (msg_p).sdu,
        RRC_MAC_MCCH_DATA_IND (msg_p).sdu_size,
4866
        RRC_MAC_MCCH_DATA_IND (msg_p).mbsfn_sync_area);
4867
      break;
4868 4869 4870 4871 4872 4873 4874 4875 4876

  /*  //TTN (for D2D)
    case RRC_MAC_SL_DISCOVERY_DATA_IND:
       LOG_D(RRC, "[UE %d] Received %s: frameP %d, eNB %d\n", ue_mod_id, msg_name,
             RRC_MAC_SL_DISCOVERY_DATA_IND (msg_p).frame, RRC_MAC_SL_DISCOVERY_DATA_IND (msg_p).enb_index);
       PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_id, ENB_FLAG_NO, M_RNTI, RRC_MAC_SL_DISCOVERY_DATA_IND (msg_p).frame, 0,RRC_MAC_SL_DISCOVERY_DATA_IND (msg_p).enb_index);
       //send to ProSeApp
       break;
*/
4877
# endif
4878

4879 4880
      /* PDCP messages */
    case RRC_DCCH_DATA_IND:
4881
      PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, RRC_DCCH_DATA_IND (msg_p).module_id, ENB_FLAG_NO, RRC_DCCH_DATA_IND (msg_p).rnti, RRC_DCCH_DATA_IND (msg_p).frame, 0,RRC_DCCH_DATA_IND (msg_p).eNB_index);
4882
      LOG_D(RRC, "[UE %d] Received %s: frameP %d, DCCH %d, eNB %d\n",
4883 4884 4885 4886
            RRC_DCCH_DATA_IND (msg_p).module_id,
            msg_name,
            RRC_DCCH_DATA_IND (msg_p).frame,
            RRC_DCCH_DATA_IND (msg_p).dcch_index,
4887
            RRC_DCCH_DATA_IND (msg_p).eNB_index);
4888

4889
      LOG_D(RRC, PROTOCOL_RRC_CTXT_UE_FMT"Received %s DCCH %d, eNB %d\n",
4890 4891 4892 4893 4894 4895 4896 4897 4898
            PROTOCOL_RRC_CTXT_UE_ARGS(&ctxt),
            msg_name,
            RRC_DCCH_DATA_IND (msg_p).dcch_index,
            RRC_DCCH_DATA_IND (msg_p).eNB_index);
      rrc_ue_decode_dcch (
        &ctxt,
        RRC_DCCH_DATA_IND (msg_p).dcch_index,
        RRC_DCCH_DATA_IND (msg_p).sdu_p,
        RRC_DCCH_DATA_IND (msg_p).eNB_index);
4899 4900 4901 4902
      // 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;
4903

4904 4905
# if defined(ENABLE_USE_MME)

4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929
    case NAS_KENB_REFRESH_REQ:
        memcpy((void*)UE_rrc_inst[ue_mod_id].kenb, (void*)NAS_KENB_REFRESH_REQ(msg_p).kenb, sizeof(UE_rrc_inst[ue_mod_id].kenb));

        LOG_D(RRC, "[UE %d] Received %s: refreshed RRC::KeNB = "
            "%02x%02x%02x%02x"
            "%02x%02x%02x%02x"
            "%02x%02x%02x%02x"
            "%02x%02x%02x%02x"
            "%02x%02x%02x%02x"
            "%02x%02x%02x%02x"
            "%02x%02x%02x%02x"
            "%02x%02x%02x%02x\n",
            ue_mod_id, msg_name,
            UE_rrc_inst[ue_mod_id].kenb[0],  UE_rrc_inst[ue_mod_id].kenb[1],  UE_rrc_inst[ue_mod_id].kenb[2],  UE_rrc_inst[ue_mod_id].kenb[3],
            UE_rrc_inst[ue_mod_id].kenb[4],  UE_rrc_inst[ue_mod_id].kenb[5],  UE_rrc_inst[ue_mod_id].kenb[6],  UE_rrc_inst[ue_mod_id].kenb[7],
            UE_rrc_inst[ue_mod_id].kenb[8],  UE_rrc_inst[ue_mod_id].kenb[9],  UE_rrc_inst[ue_mod_id].kenb[10], UE_rrc_inst[ue_mod_id].kenb[11],
            UE_rrc_inst[ue_mod_id].kenb[12], UE_rrc_inst[ue_mod_id].kenb[13], UE_rrc_inst[ue_mod_id].kenb[14], UE_rrc_inst[ue_mod_id].kenb[15],
            UE_rrc_inst[ue_mod_id].kenb[16], UE_rrc_inst[ue_mod_id].kenb[17], UE_rrc_inst[ue_mod_id].kenb[18], UE_rrc_inst[ue_mod_id].kenb[19],
            UE_rrc_inst[ue_mod_id].kenb[20], UE_rrc_inst[ue_mod_id].kenb[21], UE_rrc_inst[ue_mod_id].kenb[22], UE_rrc_inst[ue_mod_id].kenb[23],
            UE_rrc_inst[ue_mod_id].kenb[24], UE_rrc_inst[ue_mod_id].kenb[25], UE_rrc_inst[ue_mod_id].kenb[26], UE_rrc_inst[ue_mod_id].kenb[27],
            UE_rrc_inst[ue_mod_id].kenb[28], UE_rrc_inst[ue_mod_id].kenb[29], UE_rrc_inst[ue_mod_id].kenb[30], UE_rrc_inst[ue_mod_id].kenb[31]);

      break;

4930 4931 4932
      /* NAS messages */
    case NAS_CELL_SELECTION_REQ:

matzakos's avatar
matzakos committed
4933
      LOG_I(RRC, "[UE %d] Received %s: state %d, plmnID (%d%d%d.%d%d%d), rat %x\n", ue_mod_id, msg_name, rrc_get_state(ue_mod_id),
Cedric Roux's avatar
Cedric Roux committed
4934 4935 4936 4937 4938 4939 4940
            NAS_CELL_SELECTION_REQ (msg_p).plmnID.MCCdigit1,
            NAS_CELL_SELECTION_REQ (msg_p).plmnID.MCCdigit2,
            NAS_CELL_SELECTION_REQ (msg_p).plmnID.MCCdigit3,
            NAS_CELL_SELECTION_REQ (msg_p).plmnID.MNCdigit1,
            NAS_CELL_SELECTION_REQ (msg_p).plmnID.MNCdigit2,
            NAS_CELL_SELECTION_REQ (msg_p).plmnID.MNCdigit3,
            NAS_CELL_SELECTION_REQ (msg_p).rat);
4941

4942 4943
      if (rrc_get_state(ue_mod_id) == RRC_STATE_INACTIVE) {
        // have a look at MAC/main.c void dl_phy_sync_success(...)
matzakos's avatar
matzakos committed
4944
    	  LOG_I(RRC, "rrc_ue_task() in RRC_STATE_INACTIVE before openair_rrc_ue_init() \n");
4945 4946
        openair_rrc_ue_init(ue_mod_id,0);
      }
4947

4948 4949 4950 4951
      /* Save cell selection criterion */
      {
        UE_rrc_inst[ue_mod_id].plmnID = NAS_CELL_SELECTION_REQ (msg_p).plmnID;
        UE_rrc_inst[ue_mod_id].rat = NAS_CELL_SELECTION_REQ (msg_p).rat;
4952
        LOG_D(RRC, "[UE %d] Save cell selection criterion MCC %X%X%X MNC %X%X%X\n",
4953 4954 4955 4956 4957 4958 4959
              ue_mod_id,
              UE_rrc_inst[ue_mod_id].plmnID.MCCdigit1,
              UE_rrc_inst[ue_mod_id].plmnID.MCCdigit2,
              UE_rrc_inst[ue_mod_id].plmnID.MCCdigit3,
              UE_rrc_inst[ue_mod_id].plmnID.MNCdigit1,
              UE_rrc_inst[ue_mod_id].plmnID.MNCdigit2,
              UE_rrc_inst[ue_mod_id].plmnID.MNCdigit3);
Lionel Gauthier's avatar
Lionel Gauthier committed
4960

4961
      }
4962

4963 4964
      switch (rrc_get_state(ue_mod_id)) {
      case RRC_STATE_INACTIVE: {
4965
    	  //LOG_I(RRC, "Panos-D: rrc_ue_task() RRC state: RRC_STATE_INACTIVE \n");
4966 4967
        /* Need to first activate lower layers */
        MessageDef *message_p;
4968

4969
        message_p = itti_alloc_new_message(TASK_RRC_UE, ACTIVATE_MESSAGE);
4970

4971
        itti_send_msg_to_task(TASK_L2L1, UE_MODULE_ID_TO_INSTANCE(ue_mod_id), message_p);
4972

4973 4974 4975
        rrc_set_state (ue_mod_id, RRC_STATE_IDLE);
        /* Fall through to next case */
      }
winckel's avatar
winckel committed
4976

4977
      case RRC_STATE_IDLE: {
4978
    	  //LOG_I(RRC, "Panos-D: rrc_ue_task() RRC state: RRC_STATE_IDLE \n");
4979 4980
        /* Ask to layer 1 to find a cell matching the criterion */
        MessageDef *message_p;
winckel's avatar
winckel committed
4981

4982
        message_p = itti_alloc_new_message(TASK_RRC_UE, PHY_FIND_CELL_REQ);
winckel's avatar
winckel committed
4983

4984 4985
        PHY_FIND_CELL_REQ (message_p).earfcn_start = 1;
        PHY_FIND_CELL_REQ (message_p).earfcn_end = 1;
winckel's avatar
winckel committed
4986

4987
        itti_send_msg_to_task(TASK_PHY_UE, UE_MODULE_ID_TO_INSTANCE(ue_mod_id), message_p);
4988
        rrc_set_sub_state (ue_mod_id, RRC_SUB_STATE_IDLE_SEARCHING);
winckel's avatar
winckel committed
4989

4990 4991
        break;
      }
4992

4993 4994 4995 4996
      case RRC_STATE_CONNECTED:
        /* should not happen */
        LOG_E(RRC, "[UE %d] request %s in RRC state %d\n", ue_mod_id, msg_name, rrc_get_state(ue_mod_id));
        break;
4997

4998 4999
      default:
        LOG_C(RRC, "[UE %d] Invalid RRC state %d\n", ue_mod_id, rrc_get_state(ue_mod_id));
5000
        break;
5001
      }
winckel's avatar
winckel committed
5002

5003
      break;
winckel's avatar
winckel committed
5004

5005
    case NAS_CONN_ESTABLI_REQ:
Cedric Roux's avatar
Cedric Roux committed
5006 5007 5008 5009 5010 5011 5012 5013 5014 5015
      LOG_D(RRC, "[UE %d] Received %s: cause %d, type %d, s_tmsi (mme code %"PRIu8", m-tmsi %"PRIu32"), plmnID (%d%d%d.%d%d%d)\n", ue_mod_id, msg_name, NAS_CONN_ESTABLI_REQ (msg_p).cause,
            NAS_CONN_ESTABLI_REQ (msg_p).type,
            NAS_CONN_ESTABLI_REQ (msg_p).s_tmsi.MMEcode,
            NAS_CONN_ESTABLI_REQ (msg_p).s_tmsi.m_tmsi,
            NAS_CONN_ESTABLI_REQ (msg_p).plmnID.MCCdigit1,
            NAS_CONN_ESTABLI_REQ (msg_p).plmnID.MCCdigit2,
            NAS_CONN_ESTABLI_REQ (msg_p).plmnID.MCCdigit3,
            NAS_CONN_ESTABLI_REQ (msg_p).plmnID.MNCdigit1,
            NAS_CONN_ESTABLI_REQ (msg_p).plmnID.MNCdigit2,
            NAS_CONN_ESTABLI_REQ (msg_p).plmnID.MNCdigit3);
winckel's avatar
winckel committed
5016

5017 5018 5019
      //PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, ENB_FLAG_NO, NOT_A_RNTI, 0, 0);
      PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_id, ENB_FLAG_NO, NOT_A_RNTI, 0, 0, 0);

5020
      UE_rrc_inst[ue_mod_id].initialNasMsg = NAS_CONN_ESTABLI_REQ (msg_p).initialNasMsg;
winckel's avatar
winckel committed
5021

5022 5023 5024
      switch (rrc_get_state(ue_mod_id)) {
      case RRC_STATE_IDLE: {
        if (rrc_get_sub_state(ue_mod_id) == RRC_SUB_STATE_IDLE_SIB_COMPLETE) {
5025
          rrc_ue_generate_RRCConnectionRequest(&ctxt, 0);
5026
          LOG_D(RRC, "not sending connection request\n");
winckel's avatar
winckel committed
5027

5028 5029
          rrc_set_sub_state (ue_mod_id, RRC_SUB_STATE_IDLE_CONNECTING);
        }
winckel's avatar
winckel committed
5030

5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043
        break;
      }

      case RRC_STATE_INACTIVE:
      case RRC_STATE_CONNECTED:
        /* should not happen */
        LOG_E(RRC, "[UE %d] request %s in RRC state %d\n", ue_mod_id, msg_name, rrc_get_state(ue_mod_id));
        break;

      default:
        LOG_C(RRC, "[UE %d] Invalid RRC state %d\n", ue_mod_id, rrc_get_state(ue_mod_id));
        break;
      }
winckel's avatar
winckel committed
5044

5045
      break;
winckel's avatar
RRC:  
winckel committed
5046

5047 5048 5049
    case NAS_UPLINK_DATA_REQ: {
      uint32_t length;
      uint8_t *buffer;
winckel's avatar
RRC:  
winckel committed
5050

5051
      LOG_D(RRC, "[UE %d] Received %s: UEid %d\n", ue_mod_id, msg_name, NAS_UPLINK_DATA_REQ (msg_p).UEid);
5052 5053 5054 5055 5056

      /* Create message for PDCP (ULInformationTransfer_t) */
      length = do_ULInformationTransfer(&buffer, NAS_UPLINK_DATA_REQ (msg_p).nasMsg.length, NAS_UPLINK_DATA_REQ (msg_p).nasMsg.data);

      /* Transfer data to PDCP */
5057
      PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_id, ENB_FLAG_NO, UE_rrc_inst[ue_mod_id].Info[0].rnti, 0, 0,0);
5058

5059
      // check if SRB2 is created, if yes request data_req on DCCH1 (SRB2)
5060 5061
      if(UE_rrc_inst[ue_mod_id].SRB2_config[0] == NULL)
      {
5062
          rrc_data_req_ue (&ctxt,
5063 5064 5065 5066 5067 5068 5069 5070
                  DCCH,
                  rrc_mui++,
                  SDU_CONFIRM_NO,
                  length, buffer,
                  PDCP_TRANSMISSION_MODE_CONTROL);
      }
      else
      {
5071
          rrc_data_req_ue (&ctxt,
5072 5073 5074 5075 5076 5077
                  DCCH1,
                  rrc_mui++,
                  SDU_CONFIRM_NO,
                  length, buffer,
                  PDCP_TRANSMISSION_MODE_CONTROL);
      }
5078 5079
      break;
    }
5080

5081
# endif
winckel's avatar
RRC:  
winckel committed
5082

5083
# if ENABLE_RAL
5084

5085
    case RRC_RAL_SCAN_REQ:
5086
      LOG_D(RRC, "[UE %d] Received %s: state %d\n", ue_mod_id, msg_name);
5087

5088 5089 5090 5091
      switch (rrc_get_state(ue_mod_id)) {
      case RRC_STATE_INACTIVE: {
        /* Need to first activate lower layers */
        MessageDef *message_p;
5092

5093
        message_p = itti_alloc_new_message(TASK_RRC_UE, ACTIVATE_MESSAGE);
5094

5095
        itti_send_msg_to_task(TASK_L2L1, instance, message_p);
5096

5097 5098 5099
        rrc_set_state (ue_mod_id, RRC_STATE_IDLE);
        /* Fall through to next case */
      }
5100

5101 5102 5103 5104
      case RRC_STATE_IDLE: {
        if (rrc_get_sub_state(ue_mod_id) != RRC_SUB_STATE_IDLE_SEARCHING) {
          /* Ask to layer 1 to find a cell matching the criterion */
          MessageDef *message_p;
5105

5106
          message_p = itti_alloc_new_message(TASK_RRC_UE, PHY_FIND_CELL_REQ);
5107

5108
          rrc_set_sub_state (ue_mod_id, RRC_SUB_STATE_IDLE_SEARCHING);
5109

5110 5111 5112
          PHY_FIND_CELL_REQ (message_p).transaction_id = RRC_RAL_SCAN_REQ (msg_p).transaction_id;
          PHY_FIND_CELL_REQ (message_p).earfcn_start   = 1;
          PHY_FIND_CELL_REQ (message_p).earfcn_end     = 1; //44
5113

5114 5115
          itti_send_msg_to_task(TASK_PHY_UE, instance, message_p);
        }
5116

5117 5118
        break;
      }
5119

5120 5121 5122 5123
      case RRC_STATE_CONNECTED:
        /* should not happen */
        LOG_E(RRC, "[UE %d] request %s in RRC state %d\n", ue_mod_id, msg_name, rrc_get_state(ue_mod_id));
        break;
5124

5125 5126 5127 5128
      default:
        LOG_C(RRC, "[UE %d] Invalid RRC state %d\n", ue_mod_id, rrc_get_state(ue_mod_id));
        break;
      }
5129

5130
      break;
5131

5132
    case PHY_FIND_CELL_IND:
5133
      LOG_D(RRC, "[UE %d] Received %s: state %d\n", ue_mod_id, msg_name, rrc_get_state(ue_mod_id));
5134

5135 5136 5137 5138 5139 5140
      switch (rrc_get_state(ue_mod_id)) {
      case RRC_STATE_IDLE:
        switch (rrc_get_sub_state(ue_mod_id)) {
        case RRC_SUB_STATE_IDLE_SEARCHING: {
          MessageDef *message_p;
          int         i;
5141

5142
          message_p = itti_alloc_new_message(TASK_RRC_UE, RRC_RAL_SCAN_CONF);
5143

5144 5145
          RRC_RAL_SCAN_CONF (message_p).transaction_id = PHY_FIND_CELL_IND(msg_p).transaction_id;
          RRC_RAL_SCAN_CONF (message_p).num_scan_resp  = PHY_FIND_CELL_IND(msg_p).cell_nb;
5146

5147 5148 5149 5150 5151
          for (i = 0 ; i < PHY_FIND_CELL_IND(msg_p).cell_nb; i++) {
            // TO DO
            memset(&RRC_RAL_SCAN_CONF (message_p).link_scan_resp[i].link_addr,  0, sizeof(ral_link_addr_t));
            // TO DO
            memset(&RRC_RAL_SCAN_CONF (message_p).link_scan_resp[i].network_id, 0, sizeof(ral_network_id_t));
5152

5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180
            RRC_RAL_SCAN_CONF (message_p).link_scan_resp[i].sig_strength.choice     = RAL_SIG_STRENGTH_CHOICE_DBM;
            RRC_RAL_SCAN_CONF (message_p).link_scan_resp[i].sig_strength._union.dbm = PHY_FIND_CELL_IND(msg_p).cells[i].rsrp;
          }

          rrc_set_sub_state (ue_mod_id, RRC_SUB_STATE_IDLE);

          itti_send_msg_to_task(TASK_RAL_UE, instance, message_p);
          break;
        }

        default:
          LOG_C(RRC, "[UE %d] Invalid RRC state %d substate %d\n",
                ue_mod_id,
                rrc_get_state(ue_mod_id),
                rrc_get_sub_state(ue_mod_id));
        }

        break;

      case RRC_STATE_INACTIVE:
      case RRC_STATE_CONNECTED:
        /* should not happen */
        LOG_E(RRC, "[UE %d] indication %s in RRC state %d\n", ue_mod_id, msg_name, rrc_get_state(ue_mod_id));
        break;

      default:
        LOG_C(RRC, "[UE %d] Invalid RRC state %d\n", ue_mod_id, rrc_get_state(ue_mod_id));
        break;
5181
      }
5182

5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196
      break; // PHY_FIND_CELL_IND

    case PHY_MEAS_REPORT_IND: {
      MessageDef *message_p;
      message_p = itti_alloc_new_message(TASK_RRC_UE, RRC_RAL_MEASUREMENT_REPORT_IND);

      memcpy(&RRC_RAL_MEASUREMENT_REPORT_IND (message_p).threshold,
             &PHY_MEAS_REPORT_IND(msg_p).threshold,
             sizeof(RRC_RAL_MEASUREMENT_REPORT_IND (message_p).threshold));

      memcpy(&RRC_RAL_MEASUREMENT_REPORT_IND (message_p).link_param,
             &PHY_MEAS_REPORT_IND(msg_p).link_param,
             sizeof(RRC_RAL_MEASUREMENT_REPORT_IND (message_p).link_param));

5197
      LOG_D(RRC, "[UE %d] PHY_MEAS_REPORT_IN: sending msg %s to %s \n", ue_mod_id, "RRC_RAL_MEASUREMENT_REPORT_IND", "TASK_RAL_UE");
5198 5199 5200 5201 5202 5203 5204 5205 5206
      itti_send_msg_to_task(TASK_RAL_UE, instance, message_p);
      break;
    }

    case RRC_RAL_CONFIGURE_THRESHOLD_REQ:
      rrc_ue_ral_handle_configure_threshold_request(ue_mod_id, msg_p);
      break;

    case RRC_RAL_CONNECTION_ESTABLISHMENT_REQ:
5207
      LOG_D(RRC, "[UE %d] Received %s\n", ue_mod_id, msg_name);
5208 5209 5210 5211

      switch (rrc_get_state(ue_mod_id)) {
      case RRC_STATE_IDLE: {
        if (rrc_get_sub_state(ue_mod_id) == RRC_SUB_STATE_IDLE_SIB_COMPLETE) {
5212
          PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_id, ENB_FLAG_NO, UE_rrc_inst[ue_mod_id].Info[0].rnti, 0, 0, 0);
5213
          rrc_ue_generate_RRCConnectionRequest(&ctxt, 0);
5214
          LOG_D(RRC, "not sending connection request\n");
5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234
          rrc_set_sub_state (ue_mod_id, RRC_SUB_STATE_IDLE_CONNECTING);
        }

        break;
      }

      case RRC_STATE_INACTIVE:
      case RRC_STATE_CONNECTED:
        /* should not happen */
        LOG_E(RRC, "[UE %d] request %s in RRC state %d\n", ue_mod_id, msg_name, rrc_get_state(ue_mod_id));
        break;

      default:
        LOG_C(RRC, "[UE %d] Invalid RRC state %d\n", ue_mod_id, rrc_get_state(ue_mod_id));
        break;
      }

      break;

    case RRC_RAL_CONNECTION_RELEASE_REQ:
5235
      LOG_D(RRC, "[UE %d] Received %s\n", ue_mod_id, msg_name);
5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247
      break;
#endif

    default:
      LOG_E(RRC, "[UE %d] Received unexpected message %s\n", ue_mod_id, msg_name);
      break;
    }

    result = itti_free (ITTI_MSG_ORIGIN_ID(msg_p), msg_p);
    AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
    AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
    msg_p = NULL;
5248 5249 5250
  }
}
#endif
5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287



/*------------------------------------------------------------------------------*/
void
openair_rrc_top_init_ue(
			int eMBMS_active,
			char* uecap_xer,
			uint8_t cba_group_active,
			uint8_t HO_active
)
//-----------------------------------------------------------------------------
{

  module_id_t         module_id;
  OAI_UECapability_t *UECap     = NULL;
  int                 CC_id;

  /* for no gcc warnings */
  (void)CC_id;

  LOG_D(RRC, "[OPENAIR][INIT] Init function start: NB_UE_INST=%d, NB_eNB_INST=%d\n", NB_UE_INST, NB_eNB_INST);

  if (NB_UE_INST > 0) {
    UE_rrc_inst = (UE_RRC_INST*) malloc16(NB_UE_INST*sizeof(UE_RRC_INST));
    memset (UE_rrc_inst, 0, NB_UE_INST * sizeof(UE_RRC_INST));
    LOG_D(RRC, "ALLOCATE %d Bytes for UE_RRC_INST @ %p\n", (unsigned int)(NB_UE_INST*sizeof(UE_RRC_INST)), UE_rrc_inst);

    // fill UE capability
    UECap = fill_ue_capability (uecap_xer);

    for (module_id = 0; module_id < NB_UE_INST; module_id++) {
      UE_rrc_inst[module_id].UECap = UECap;
      UE_rrc_inst[module_id].UECapability = UECap->sdu;
      UE_rrc_inst[module_id].UECapability_size = UECap->sdu_size;
    }

5288
#if defined(Rel10) || defined(Rel14)
5289 5290 5291 5292 5293 5294 5295
    LOG_I(RRC,"[UE] eMBMS active state is %d \n", eMBMS_active);

    for (module_id=0; module_id<NB_UE_INST; module_id++) {
      UE_rrc_inst[module_id].MBMS_flag = (uint8_t)eMBMS_active;
    }

#endif
5296 5297 5298 5299 5300

#ifdef Rel14
  init_SL_preconfig(&UE_rrc_inst[module_id],0);
#endif

5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315
  } else {
    UE_rrc_inst = NULL;
  }

}

//-----------------------------------------------------------------------------
void
rrc_top_cleanup_ue(
  void
)
//-----------------------------------------------------------------------------
{

  if (NB_UE_INST > 0) free (UE_rrc_inst);
5316

5317 5318

}
5319 5320 5321


//-----------------------------------------------------------------------------
5322
uint8_t rrc_ue_generate_SidelinkUEInformation( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index,SL_DestinationInfoList_r12_t  *destinationInfoList, long *discTxResourceReq, SL_TRIGGER_t mode)
5323
{
5324
   uint8_t    size=0;
5325 5326 5327
   uint8_t buffer[100];

   //Generate SidelinkUEInformation
5328
   if (((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&8192) > 0) && (destinationInfoList != NULL)) {//if SIB18 is available
5329 5330 5331
      size = do_SidelinkUEInformation(ctxt_pP->module_id, buffer, destinationInfoList, NULL, mode);
      LOG_I(RRC,"[UE %d][RRC_UE] Frame %d : Logical Channel UL-DCCH, Generating SidelinkUEInformation (bytes%d, eNB %d)\n",
            ctxt_pP->module_id,ctxt_pP->frame, size, eNB_index);
5332
      //return size;
5333
   }
5334
   if (((UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus&16384) > 0) && (discTxResourceReq != NULL)) {//if SIB19 is available
5335 5336 5337
      size = do_SidelinkUEInformation(ctxt_pP->module_id, buffer, NULL, discTxResourceReq, mode);
      LOG_I(RRC,"[UE %d][RRC_UE] Frame %d : Logical Channel UL-DCCH, Generating SidelinkUEInformation (bytes%d, eNB %d)\n",
            ctxt_pP->module_id,ctxt_pP->frame, size, eNB_index);
5338
     //return size;
5339
   }
5340 5341 5342 5343 5344 5345 5346 5347 5348 5349

   rrc_data_req_ue (
       ctxt_pP,
       DCCH,
       rrc_mui++,
       SDU_CONFIRM_NO,
       size,
       buffer,
       PDCP_TRANSMISSION_MODE_CONTROL);
   return size;
5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369
}


// 3GPP 36.331 (Section 5.10.7.3)
uint8_t fill_SLSS(const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_index, SLSSID_r12_t *slss_id, uint8_t *subframe, uint8_t mode)
{
   long syncOffsetIndicator = 0;
   switch(mode) {
   case 1: //if triggered by SL discovery announcement and in-coverage
      //discSyncConfig_r12 contains only one element
      *slss_id = UE_rrc_inst[ctxt_pP->module_id].sib19[eNB_index]->discConfig_r12->discSyncConfig_r12->list.array[0]->slssid_r12;
      syncOffsetIndicator = UE_rrc_inst[ctxt_pP->module_id].sib19[eNB_index]->discConfig_r12->discSyncConfig_r12->list.array[0]->syncOffsetIndicator_r12;
      //select subframe for SLSS
      break;
   case 2: //if triggered by SL communication and in-coverage

      if (UE_rrc_inst[ctxt_pP->module_id].sib18[eNB_index]->commConfig_r12->commSyncConfig_r12->list.array[0]->txParameters_r12) {
         *slss_id = UE_rrc_inst[ctxt_pP->module_id].sib18[eNB_index]->commConfig_r12->commSyncConfig_r12->list.array[0]->slssid_r12;
         syncOffsetIndicator = UE_rrc_inst[ctxt_pP->module_id].sib18[eNB_index]->commConfig_r12->commSyncConfig_r12->list.array[0]->syncOffsetIndicator_r12;

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
5370
         //if RRC_CONNECTED (Todo: and if networkControlledSyncTx (RRCConnectionReconfiguration) is configured and set to On)
5371 5372
         if (UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].State == RRC_CONNECTED){
            //select subframe(s) indicated by syncOffsetIndicator
5373
            *subframe = syncOffsetIndicator;
5374 5375 5376 5377 5378
         } else {
            //select subframe(s) indicated by syncOffsetIndicator within SC period
         }
         break;
   case 3: //if triggered by V2X communication and in coverage
5379

5380 5381
      break;
   case 4: //if triggered by V2X communication and out-of-coverage
5382

5383 5384 5385 5386 5387 5388 5389
      break;
   case 5: //if triggered by V2X communication and UE has GNSS as the synchronization reference

   default:
      //if UE has a selected SyncRefUE
      //TODO
      //else (no SyncRefUE Selected)
5390 5391 5392 5393
      //Todo  if trigger by V2X
      //else randomly select an SLSSID from the set defined for out-of-coverage
      *slss_id = 170;//hardcoded
      //select the subframe according to syncOffsetIndicator1/2 from the preconfigured parameters
5394 5395 5396
      break;
      }
   }
5397 5398 5399 5400 5401 5402
   return 0;
}


//-----------------------------------------------------------------------------
void
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
5403
rrc_ue_process_sidelink_radioResourceConfig(
5404 5405 5406 5407 5408 5409 5410 5411 5412
      module_id_t                      Mod_idP,
      uint8_t                          eNB_index,
      SystemInformationBlockType18_r12_t     *sib18,
      SystemInformationBlockType19_r12_t     *sib19,
      SL_CommConfig_r12_t* sl_CommConfig,
      SL_DiscConfig_r12_t* sl_DiscConfig
)
//-----------------------------------------------------------------------------
{
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
5413
   //process SIB18, configure MAC/PHY for receiving SL communication (RRC_IDLE and RRC_CONNECTED), for transmitting SL communication (RRC_IDLE)
5414
   if (sib18 != NULL) {
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
5415 5416 5417 5418
      if (sib18->commConfig_r12 != NULL) {
         //do not consider commTXPoolExceptional for the moment
         //configure PHY/MAC to receive SL communication by using the RPs indicated by commRxPool
         //sib18->commConfig_r12->commRxPool_r12
5419
         //TODO
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
5420 5421 5422 5423 5424 5425 5426

         if (sib18->commConfig_r12->commTxPoolNormalCommon_r12 !=NULL) { //commTxPoolNormalCommon - to transmit SL communication in RRC_IDLE
            //maybe we don't consider this case for the moment since UE will immediately establish a RRC connection after receiving SIB messages
            //configure PHY/MAC to transmit SL communication using the RPs indicated by the first entry in commTxPoolNormalCommon
            //SL_CommResourcePool_r12_t sl_CommResourcePool = sib18->commConfig_r12->commTxPoolNormalCommon_r12->list.array[0];
         }
      }
5427 5428
   }

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
5429
   //process SIB19, configure MAC/PHY for receiving SL discovery (RRC_IDLE and RRC_CONNECTED), for transmitting SL discovery (RRC_IDLE)
5430
   if (sib19 != NULL) {
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
5431 5432 5433 5434 5435
      //to receive non-PS related discovery announcements (discRxPool)
      //sib19->discConfig_r12->discRxPool_r12;

      //to receive PS related discovery announcements (discRxPoolPS)
      //sib19->ext1->discConfigPS_13->discRxPoolPS_r13;
5436

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
5437 5438 5439 5440 5441
      //to transmit non-PS related discovery in RRC_IDLE
      //sib19->discConfig_r12->discTxPoolCommon_r12;

      //to transmit PS related discovery in RRC_IDLE
      //sib19->ext1->discConfigPS_13->discTxPoolPS_Common_r13;
5442
   }
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
5443 5444

   //process sl_CommConfig, configure MAC/PHY for transmitting SL communication (RRC_CONNECTED)
5445 5446 5447 5448 5449 5450
   if (sl_CommConfig != NULL) {

      if (sl_CommConfig->commTxResources_r12 != NULL) {
         switch (sl_CommConfig->commTxResources_r12->present){
         case SL_CommConfig_r12__commTxResources_r12_PR_setup:
            if (sl_CommConfig->commTxResources_r12->choice.setup.present == SL_CommConfig_r12__commTxResources_r12__setup_PR_scheduled_r12 ){
5451 5452 5453 5454 5455

               LOG_I(RRC,"[UE %d][RRC_UE] scheduled resource for SL, sl_RNTI size %d  \n",
                     Mod_idP, sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.sl_RNTI_r12.size );
               LOG_I(RRC,"[UE %d][RRC_UE] scheduled resource for SL, sl_RNTI buf 0x%08x \n",
                     Mod_idP, sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.sl_RNTI_r12.buf );
5456
               LOG_I(RRC,"[UE %d][RRC_UE] scheduled resource for SL, Mac_MainConfig_r12.retx_BSR_TimerSL %ld \n",
5457
                     Mod_idP, sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.mac_MainConfig_r12.retx_BSR_TimerSL );
5458
               LOG_I(RRC,"[UE %d][RRC_UE] scheduled resource for SL, sc_CommTxConfig %ld \n",
5459
                     Mod_idP, sl_CommConfig->commTxResources_r12->choice.setup.choice.scheduled_r12.mac_MainConfig_r12.retx_BSR_TimerSL );
5460
               //configure scheduled resource for SL
5461
               //TODO
5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473
            } else if (sl_CommConfig->commTxResources_r12->choice.setup.present == SL_CommConfig_r12__commTxResources_r12__setup_PR_ue_Selected_r12){
               //configure dedicated resources (commTxPoolNormalDedicated) for SL from which UE can autonomously select
               //sl_CommConfig->commTxResources_r12->choice.setup.choice.ue_Selected_r12.commTxPoolNormalDedicated_r12;

               //for the moment, only pass the first entry (e.g., do not consider priorityList in commTxPoolNormalDedicated (3GPP 36.331 Section 5.10.4 1>2>3>4))
               //sl_CommConfig->commTxResources_r12->choice.setup.choice.ue_Selected_r12.commTxPoolNormalDedicated_r12.poolToAddModList_r12->list.array[0];
            } else {
               //SL_CommConfig_r12__commTxResources_r12__setup_PR_NOTHING /* No components present */
            }
            break;

         case SL_CommConfig_r12__commTxResources_r12_PR_release:
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
5474
            //release dedicated resources for SL communication
5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486
            break;

         case SL_CommConfig_r12__commTxResources_r12_PR_NOTHING: /* No components present */
            break;

         default:
            break;
         }
      }

   }

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
5487
   //process sl_DiscConfig, configure MAC/PHY for transmitting SL discovery announcements (RRC_CONNECTED)
5488
   if (sl_DiscConfig != NULL) {
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
5489
      //dedicated resources for transmitting non-PS related discovery
5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504
      if (sl_DiscConfig->discTxResources_r12 != NULL) {

         switch (sl_DiscConfig->discTxResources_r12->present) {
         case SL_DiscConfig_r12__discTxResources_r12_PR_setup:
            if (sl_DiscConfig->discTxResources_r12->choice.setup.present == SL_DiscConfig_r12__discTxResources_r12__setup_PR_scheduled_r12) {
               //sl_DiscConfig->discTxResources_r12->choice.setup.choice.scheduled_r12.discHoppingConfig_r12;
               //sl_DiscConfig->discTxResources_r12->choice.setup.choice.scheduled_r12.discTF_IndexList_r12;
               //sl_DiscConfig->discTxResources_r12->choice.setup.choice.scheduled_r12.discTxConfig_r12;
            } else if (sl_DiscConfig->discTxResources_r12->choice.setup.present == SL_DiscConfig_r12__discTxResources_r12__setup_PR_ue_Selected_r12) {
               //sl_DiscConfig->discTxResources_r12->choice.setup.choice.ue_Selected_r12.discTxPoolDedicated_r12;
            } else {
               //SL_DiscConfig_r12__discTxResources_r12__setup_PR_NOTHING,   /* No components present */
            }
            break;
         case SL_DiscConfig_r12__discTxResources_r12_PR_release:
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
5505
            //release dedicated resources for SL discovery
5506 5507 5508 5509 5510 5511 5512 5513
            break;
         case SL_DiscConfig_r12__discTxResources_r12_PR_NOTHING: /* No components present */
            break;
         default:
            break;
         }

      }
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536
      //dedicated resources for transmitting PS related discovery
      if (sl_DiscConfig->ext2->discTxResourcesPS_r13 != NULL){
         switch (sl_DiscConfig->ext2->discTxResourcesPS_r13->present) {
         case SL_DiscConfig_r12__ext2__discTxResourcesPS_r13_PR_setup:
            if (sl_DiscConfig->ext2->discTxResourcesPS_r13->choice.setup.present == SL_DiscConfig_r12__ext2__discTxResourcesPS_r13__setup_PR_scheduled_r13) {
               //sl_DiscConfig->ext2->discTxResourcesPS_r13->choice.setup.choice.scheduled_r13.discHoppingConfig_r13;
               //sl_DiscConfig->ext2->discTxResourcesPS_r13->choice.setup.choice.scheduled_r13.discTxConfig_r13
            } else if (sl_DiscConfig->ext2->discTxResourcesPS_r13->choice.setup.present == SL_DiscConfig_r12__ext2__discTxResourcesPS_r13__setup_PR_ue_Selected_r13) {
               //sl_DiscConfig->ext2->discTxResourcesPS_r13->choice.setup.choice.ue_Selected_r13.discTxPoolPS_Dedicated_r13;
            } else {
               //SL_DiscConfig_r12__ext2__discTxResourcesPS_r13__setup_PR_NOTHING, /* No components present */
            }

            break;
         case SL_DiscConfig_r12__ext2__discTxResourcesPS_r13_PR_release:
            break;
         case SL_DiscConfig_r12__ext2__discTxResourcesPS_r13_PR_NOTHING:
            /* No components present */
            break;
         default:
            break;
         }
      }
5537
   }
5538
}
5539

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
5540
#ifdef Rel14
5541 5542 5543 5544 5545 5546 5547 5548
//-----------------------------------------------------------
void
rrc_control_socket_init(){

   struct sockaddr_in rrc_ctrl_socket_addr;
   pthread_attr_t     attr;
   struct sched_param sched_param;
   int optval; // flag value for setsockopt
5549
   //int n; // message byte size
5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599


   // create the control socket
   ctrl_sock_fd = socket(AF_INET, SOCK_DGRAM, 0);
   if (ctrl_sock_fd == -1) {
      LOG_E(RRC,"[rrc_control_socket_init] :Error opening socket %d (%d:%s)\n",ctrl_sock_fd,errno, strerror(errno));
      exit(EXIT_FAILURE);
   }
   //   if (ctrl_sock_fd < 0)
   //      error("ERROR: Failed on opening socket");
   optval = 1;
   setsockopt(ctrl_sock_fd, SOL_SOCKET, SO_REUSEADDR,
         (const void *)&optval , sizeof(int));

   //build the server's  address
   bzero((char *) &rrc_ctrl_socket_addr, sizeof(rrc_ctrl_socket_addr));
   rrc_ctrl_socket_addr.sin_family = AF_INET;
   rrc_ctrl_socket_addr.sin_addr.s_addr = htonl(INADDR_ANY);
   rrc_ctrl_socket_addr.sin_port = htons(CONTROL_SOCKET_PORT_NO);
   // associate the parent socket with a port
   if (bind(ctrl_sock_fd, (struct sockaddr *) &rrc_ctrl_socket_addr,
         sizeof(rrc_ctrl_socket_addr)) < 0) {
      LOG_E(RRC,"[rrc_control_socket_init] ERROR: Failed on binding the socket\n");
      exit(1);
   }
   //create thread to listen to incoming packets
   if (pthread_attr_init(&attr) != 0) {
      LOG_E(RRC, "[rrc_control_socket_init]Failed to initialize pthread attribute for ProSe -> RRC communication (%d:%s)\n",
            errno, strerror(errno));
      exit(EXIT_FAILURE);
   }

   sched_param.sched_priority = 10;

   pthread_attr_setschedpolicy(&attr, SCHED_RR);
   pthread_attr_setschedparam(&attr, &sched_param);

   pthread_t rrc_control_socket_thread;

   if (pthread_create(&rrc_control_socket_thread, &attr, rrc_control_socket_thread_fct, NULL) != 0) {
      LOG_E(RRC, "[rrc_control_socket_init]Failed to create new thread for RRC/ProSeApp communication (%d:%s)\n",
            errno, strerror(errno));
      exit(EXIT_FAILURE);
   }

   pthread_setname_np( rrc_control_socket_thread, "RRC Control Socket" );

}

//--------------------------------------------------------
5600
void *rrc_control_socket_thread_fct(void *arg)
5601 5602 5603 5604 5605
{

   int prose_addr_len;
   char send_buf[BUFSIZE];
   char receive_buf[BUFSIZE];
5606
   //int optval;
5607
   int n;
5608 5609
   struct sidelink_ctrl_element *sl_ctrl_msg_recv = NULL;
   struct sidelink_ctrl_element *sl_ctrl_msg_send = NULL;
5610 5611
   uint32_t sourceL2Id, groupL2Id, destinationL2Id;
   module_id_t         module_id = 0; //hardcoded for testing only
5612
   uint8_t type;
5613 5614 5615 5616 5617 5618 5619 5620
   UE_RRC_INST *UE  = NULL;
   protocol_ctxt_t ctxt;
   struct RLC_Config                  *DRB_rlc_config                   = NULL;
   struct PDCP_Config                 *DRB_pdcp_config                  = NULL;
   struct PDCP_Config__rlc_UM         *PDCP_rlc_UM                      = NULL;
   struct LogicalChannelConfig        *DRB_lchan_config                 = NULL;
   struct LogicalChannelConfig__ul_SpecificParameters  *DRB_ul_SpecificParameters = NULL;
   long                               *logicalchannelgroup_drb          = NULL;
5621 5622
   int j = 0;
   int i = 0;
5623 5624 5625

   //from the main program, listen for the incoming messages from control socket (ProSe App)
   prose_addr_len = sizeof(prose_app_addr);
5626
   //int enable_notification = 1;
5627
   while (1) {
5628
      LOG_I(RRC,"Listening to incoming connection from ProSe App \n");
5629 5630 5631
      // receive a message from ProSe App
      memset(receive_buf, 0, BUFSIZE);
      n = recvfrom(ctrl_sock_fd, receive_buf, BUFSIZE, 0,
5632
            (struct sockaddr *) &prose_app_addr, (socklen_t *)&prose_addr_len);
5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646
      if (n < 0){
         LOG_E(RRC, "ERROR: Failed to receive from ProSe App\n");
         exit(EXIT_FAILURE);
      }
      //TODO: should store the address of ProSeApp [UE_rrc_inst] to be able to send UE state notification to the App

      //sl_ctrl_msg_recv = (struct sidelink_ctrl_element *) receive_buf;
      sl_ctrl_msg_recv = calloc(1, sizeof(struct sidelink_ctrl_element));
      memcpy((void *)sl_ctrl_msg_recv, (void *)receive_buf, sizeof(struct sidelink_ctrl_element));

      //process the message
      switch (sl_ctrl_msg_recv->type) {
      case SESSION_INIT_REQ:
#ifdef DEBUG_CTRL_SOCKET
5647
         LOG_I(RRC,"Received SessionInitializationRequest on socket from ProSe App (msg type: %d)\n", sl_ctrl_msg_recv->type);
5648 5649 5650
#endif
         //TODO: get SL_UE_STATE from lower layer

5651
         LOG_I(RRC,"Send UEStateInformation to ProSe App \n");
5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670
         memset(send_buf, 0, BUFSIZE);

         sl_ctrl_msg_send = calloc(1, sizeof(struct sidelink_ctrl_element));
         sl_ctrl_msg_send->type = UE_STATUS_INFO;
         sl_ctrl_msg_send->sidelinkPrimitive.ue_state = UE_STATE_OFF_NETWORK; //off-network
         memcpy((void *)send_buf, (void *)sl_ctrl_msg_send, sizeof(struct sidelink_ctrl_element));
         free(sl_ctrl_msg_send);

         prose_addr_len = sizeof(prose_app_addr);
         n = sendto(ctrl_sock_fd, (char *)send_buf, sizeof(struct sidelink_ctrl_element), 0, (struct sockaddr *)&prose_app_addr, prose_addr_len);
         if (n < 0) {
            LOG_E(RRC, "ERROR: Failed to send to ProSe App\n");
            exit(EXIT_FAILURE);
         }


#ifdef DEBUG_CTRL_SOCKET
         struct sidelink_ctrl_element *ptr_ctrl_msg = NULL;
         ptr_ctrl_msg = (struct sidelink_ctrl_element *) send_buf;
5671 5672
         LOG_I(RRC,"[UEStateInformation] msg type: %d\n",ptr_ctrl_msg->type);
         LOG_I(RRC,"[UEStateInformation] UE state: %d\n",ptr_ctrl_msg->sidelinkPrimitive.ue_state);
5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685
#endif

         /*  if (enable_notification > 0) {
              //create thread to send status notification (for testing purpose, status notification will be sent e.g., every 20 seconds)
              pthread_t notification_thread;
              if( pthread_create( &notification_thread , NULL ,  send_UE_status_notification , (void*) &sockfd) < 0)
                 error("ERROR: could not create thread");
           }
           enable_notification = 0;
          */
         break;

      case GROUP_COMMUNICATION_ESTABLISH_REQ:
5686 5687
         sourceL2Id = sl_ctrl_msg_recv->sidelinkPrimitive.group_comm_establish_req.sourceL2Id;
         groupL2Id = sl_ctrl_msg_recv->sidelinkPrimitive.group_comm_establish_req.groupL2Id;
5688
         int group_comm_rbid = 4;
5689

5690
#ifdef DEBUG_CTRL_SOCKET
5691
         LOG_I(RRC,"[GroupCommunicationEstablishReq] Received on socket from ProSe App (msg type: %d)\n",sl_ctrl_msg_recv->type);
5692 5693
         LOG_I(RRC,"[GroupCommunicationEstablishReq] source Id: 0x%08x\n",sl_ctrl_msg_recv->sidelinkPrimitive.group_comm_establish_req.sourceL2Id);
         LOG_I(RRC,"[GroupCommunicationEstablishReq] group Id: 0x%08x\n",sl_ctrl_msg_recv->sidelinkPrimitive.group_comm_establish_req.groupL2Id);
5694
         LOG_I(RRC,"[GroupCommunicationEstablishReq] group IP Address: " IPV4_ADDR "\n",IPV4_ADDR_FORMAT(sl_ctrl_msg_recv->sidelinkPrimitive.group_comm_establish_req.groupIpAddress));
5695
#endif
5696

5697
         //store sourceL2Id/groupL2Id
5698 5699
         UE_rrc_inst[module_id].sourceL2Id = sourceL2Id;
         UE_rrc_inst[module_id].groupL2Id = groupL2Id;
5700 5701
         j = 0;
         i = 0;
5702
         for (i=0; i< MAX_NUM_DEST; i++) {
5703 5704
            if ((UE_rrc_inst[module_id].groupList[i] == 0) && (j == 0)) j = i+1;
            if (UE_rrc_inst[module_id].groupList[i] == groupL2Id) break; //group already exists!
5705
         }
5706
         if ((i == MAX_NUM_DEST) && (j > 0))  UE_rrc_inst[module_id].groupList[j-1] = groupL2Id;
5707

5708
         // configure lower layers PDCP/MAC/PHY for this communication
5709
         //Establish a new RBID/LCID for this communication
5710
         // Establish a SLRB (using DRB 4 for now)
5711
         UE  = &UE_rrc_inst[module_id];
5712 5713 5714 5715
         PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, 0, ENB_FLAG_NO, 0x1234, 0, 0,0);

         UE->DRB_config[0][0] = CALLOC(1,sizeof(struct DRB_ToAddMod));
         UE->DRB_config[0][0]->eps_BearerIdentity = CALLOC(1, sizeof(long));
5716
         UE->DRB_config[0][0]->drb_Identity =  group_comm_rbid;
5717 5718
         UE->DRB_config[0][0]->eps_BearerIdentity = CALLOC(1, sizeof(long));
         // allowed value 5..15, value : x+4
5719
         *(UE->DRB_config[0][0]->eps_BearerIdentity) = group_comm_rbid;
5720 5721 5722
         UE->DRB_config[0][0]->logicalChannelIdentity = CALLOC(1, sizeof(long));
         *(UE->DRB_config[0][0]->logicalChannelIdentity) = UE->DRB_config[0][0]->drb_Identity; //(long) (ue_context_pP->ue_context.e_rab[i].param.e_rab_id + 2); // value : x+2

5723 5724 5725 5726 5727 5728
         DRB_rlc_config                   = CALLOC(1,sizeof(struct RLC_Config));
         DRB_pdcp_config                  = CALLOC(1,sizeof(struct PDCP_Config));
         PDCP_rlc_UM                      = CALLOC(1,sizeof(struct PDCP_Config__rlc_UM));
         DRB_lchan_config                 = CALLOC(1,sizeof(struct LogicalChannelConfig));
         DRB_ul_SpecificParameters                                         = CALLOC(1, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
         logicalchannelgroup_drb          = CALLOC(1, sizeof(long));
5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777

         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;
         UE->DRB_config[0][0]->rlc_Config = DRB_rlc_config;

         DRB_pdcp_config = CALLOC(1, sizeof(*DRB_pdcp_config));
         UE->DRB_config[0][0]->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;

         /* avoid gcc warnings */
         (void)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;

         UE->DRB_config[0][0]->logicalChannelConfig = DRB_lchan_config;
         DRB_ul_SpecificParameters = CALLOC(1, sizeof(*DRB_ul_SpecificParameters));
         DRB_lchan_config->ul_SpecificParameters = DRB_ul_SpecificParameters;

         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;
         DRB_ul_SpecificParameters->bucketSizeDuration =
               LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;

         // LCG for DTCH can take the value from 1 to 3 as defined in 36331: normally controlled by upper layers (like RRM)

         *logicalchannelgroup_drb = 1;
         DRB_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup_drb;

         UE->DRB_configList = CALLOC(1,sizeof(DRB_ToAddModList_t));
         ASN_SEQUENCE_ADD(&UE->DRB_configList->list,UE->DRB_config[0][0]);

         rrc_pdcp_config_asn1_req(&ctxt,
               (SRB_ToAddModList_t *) NULL,
               UE->DRB_configList,
               (DRB_ToReleaseList_t*) NULL,
               0xff, NULL, NULL, NULL
#if defined(Rel10) || defined(Rel14)
               , (PMCH_InfoList_r9_t *) NULL
#endif
               ,NULL);

5778

5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800
         rrc_rlc_config_asn1_req(&ctxt,
               (SRB_ToAddModList_t*)NULL,
               UE->DRB_configList,
               (DRB_ToReleaseList_t*)NULL
#if defined(Rel10) || defined(Rel14)
               ,(PMCH_InfoList_r9_t *)NULL
               , 0, 0
#endif
         );

         rrc_rlc_config_asn1_req(&ctxt,
               (SRB_ToAddModList_t*)NULL,
               UE->DRB_configList,
               (DRB_ToReleaseList_t*)NULL
#ifdef Rel14
               ,(PMCH_InfoList_r9_t *)NULL
               , sourceL2Id, groupL2Id
#endif
         );


         //configure MAC with sourceL2Id/groupL2ID
5801
         rrc_mac_config_req_ue(module_id,0,0, //eNB_index =0
5802 5803 5804 5805 5806 5807 5808 5809
               (RadioResourceConfigCommonSIB_t *)NULL,
               (struct PhysicalConfigDedicated *)NULL,
#if defined(Rel10) || defined(Rel14)
               (SCellToAddMod_r10_t *)NULL,
               //struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
#endif
               (MeasObjectToAddMod_t **)NULL,
               (MAC_MainConfig_t *)NULL,
5810
               group_comm_rbid, //LCID
5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834
               (struct LogicalChannelConfig *)NULL,
               (MeasGapConfig_t *)NULL,
               (TDD_Config_t *)NULL,
               (MobilityControlInfo_t *)NULL,
               NULL,
               NULL,
               NULL,
               NULL,
               NULL,
               NULL
#if defined(Rel10) || defined(Rel14)
               ,0,
               (MBSFN_AreaInfoList_r9_t *)NULL,
               (PMCH_InfoList_r9_t *)NULL

#endif
#ifdef CBA
               ,
               0,
               0
#endif
#if defined(Rel10) || defined(Rel14)
               ,CONFIG_ACTION_ADD,
               &sourceL2Id,
5835
               NULL,
5836 5837 5838
               &groupL2Id
#endif
         );
5839

5840
         LOG_I(RRC,"Send GroupCommunicationEstablishResp to ProSe App\n");
5841 5842 5843
         memset(send_buf, 0, BUFSIZE);
         sl_ctrl_msg_send = calloc(1, sizeof(struct sidelink_ctrl_element));
         sl_ctrl_msg_send->type = GROUP_COMMUNICATION_ESTABLISH_RSP;
5844
         sl_ctrl_msg_send->sidelinkPrimitive.slrb_id = group_comm_rbid; //slrb_id
5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858

         memcpy((void *)send_buf, (void *)sl_ctrl_msg_send, sizeof(struct sidelink_ctrl_element));
         free(sl_ctrl_msg_send);

         prose_addr_len = sizeof(prose_app_addr);
         n = sendto(ctrl_sock_fd, (char *)send_buf, sizeof(struct sidelink_ctrl_element), 0, (struct sockaddr *)&prose_app_addr, prose_addr_len);
         if (n < 0){
            LOG_E(RRC, "ERROR: Failed to send to ProSe App\n");
            exit(EXIT_FAILURE);
         }


#ifdef DEBUG_CTRL_SOCKET
         ptr_ctrl_msg = (struct sidelink_ctrl_element *) send_buf;
5859 5860
         LOG_I(RRC,"[GroupCommunicationEstablishResponse]  msg type: %d\n",ptr_ctrl_msg->type);
         LOG_I(RRC,"[GroupCommunicationEstablishResponse]  slrb_id: %d\n",ptr_ctrl_msg->sidelinkPrimitive.slrb_id);
5861 5862
#endif
         break;
5863

5864 5865 5866
      case GROUP_COMMUNICATION_RELEASE_REQ:
         printf("-----------------------------------\n");
#ifdef DEBUG_CTRL_SOCKET
5867 5868
         LOG_I(RRC,"[GroupCommunicationReleaseRequest] Received on socket from ProSe App (msg type: %d)\n",sl_ctrl_msg_recv->type);
         LOG_I(RRC,"[GroupCommunicationReleaseRequest] Slrb Id: %i\n",sl_ctrl_msg_recv->sidelinkPrimitive.slrb_id);
5869
#endif
5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905
         //reset groupL2ID from MAC LAYER
         UE_rrc_inst[module_id].groupL2Id = 0x00000000;
         sourceL2Id = UE_rrc_inst[module_id].sourceL2Id;

         rrc_mac_config_req_ue(module_id,0,0, //eNB_index =0
                    (RadioResourceConfigCommonSIB_t *)NULL,
                    (struct PhysicalConfigDedicated *)NULL,
         #if defined(Rel10) || defined(Rel14)
                    (SCellToAddMod_r10_t *)NULL,
                    //struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
         #endif
                    (MeasObjectToAddMod_t **)NULL,
                    (MAC_MainConfig_t *)NULL,
                    0,
                    (struct LogicalChannelConfig *)NULL,
                    (MeasGapConfig_t *)NULL,
                    (TDD_Config_t *)NULL,
                    (MobilityControlInfo_t *)NULL,
                    NULL,
                    NULL,
                    NULL,
                    NULL,
                    NULL,
                    NULL
         #if defined(Rel10) || defined(Rel14)
                    ,0,
                    (MBSFN_AreaInfoList_r9_t *)NULL,
                    (PMCH_InfoList_r9_t *)NULL

         #endif
         #ifdef CBA
                    ,
                    0,
                    0
         #endif
         #if defined(Rel10) || defined(Rel14)
5906
                    ,CONFIG_ACTION_REMOVE,
5907
                    &sourceL2Id,
5908 5909
                    &destinationL2Id,
                    NULL
5910 5911 5912 5913
         #endif
                    );


5914
         LOG_I(RRC,"Send GroupCommunicationReleaseResponse to ProSe App \n");
5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936
         memset(send_buf, 0, BUFSIZE);

         sl_ctrl_msg_send = calloc(1, sizeof(struct sidelink_ctrl_element));
         sl_ctrl_msg_send->type = GROUP_COMMUNICATION_RELEASE_RSP;
         //if the requested id exists -> release this ID
         if (sl_ctrl_msg_recv->sidelinkPrimitive.slrb_id == slrb_id) {
            sl_ctrl_msg_send->sidelinkPrimitive.group_comm_release_rsp = GROUP_COMMUNICATION_RELEASE_OK;
            slrb_id = 0; //Reset slrb_id
         } else {
            sl_ctrl_msg_send->sidelinkPrimitive.group_comm_release_rsp = GROUP_COMMUNICATION_RELEASE_FAILURE;
         }
         memcpy((void *)send_buf, (void *)sl_ctrl_msg_send, sizeof(struct sidelink_ctrl_element));
         free(sl_ctrl_msg_send);

         prose_addr_len = sizeof(prose_app_addr);
         n = sendto(ctrl_sock_fd, (char *)send_buf, sizeof(struct sidelink_ctrl_element), 0, (struct sockaddr *)&prose_app_addr, prose_addr_len);
         if (n < 0){
            LOG_E(RRC, "ERROR: Failed to send to ProSe App\n");
            exit(EXIT_FAILURE);
         }
         break;

5937

5938 5939 5940
      case DIRECT_COMMUNICATION_ESTABLISH_REQ:
         sourceL2Id = sl_ctrl_msg_recv->sidelinkPrimitive.direct_comm_establish_req.sourceL2Id;
         destinationL2Id = sl_ctrl_msg_recv->sidelinkPrimitive.direct_comm_establish_req.destinationL2Id;
5941
         int direct_comm_rbid = 3;
5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956

#ifdef DEBUG_CTRL_SOCKET
         LOG_I(RRC,"[DirectCommunicationEstablishReq] Received on socket from ProSe App (msg type: %d)\n",sl_ctrl_msg_recv->type);
         LOG_I(RRC,"[DirectCommunicationEstablishReq] source Id: 0x%08x\n",sl_ctrl_msg_recv->sidelinkPrimitive.group_comm_establish_req.sourceL2Id);
         LOG_I(RRC,"[DirectCommunicationEstablishReq] destination Id: 0x%08x\n",sl_ctrl_msg_recv->sidelinkPrimitive.group_comm_establish_req.groupL2Id);
#endif

         //store sourceL2Id/destinationL2Id
         UE_rrc_inst[module_id].sourceL2Id = sourceL2Id;
         i = 0;
         j = 0;
         for (i=0; i< MAX_NUM_DEST; i++) {
            if ((UE_rrc_inst[module_id].destinationList[i] == 0) && (j == 0)) j = i+1;
            if (UE_rrc_inst[module_id].destinationList[i] == destinationL2Id) break; //destination already exists!
         }
5957
         if ((i == MAX_NUM_DEST) && (j > 0))  UE_rrc_inst[module_id].destinationList[j-1] = destinationL2Id;
5958 5959 5960 5961 5962 5963 5964 5965 5966

         // configure lower layers PDCP/MAC/PHY for this communication
         //Establish a new RBID/LCID for this communication
         // Establish a SLRB (using DRB 3 for now)
         UE  = &UE_rrc_inst[module_id];
         PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, 0, ENB_FLAG_NO, 0x1234, 0, 0,0);

         UE->DRB_config[0][0] = CALLOC(1,sizeof(struct DRB_ToAddMod));
         UE->DRB_config[0][0]->eps_BearerIdentity = CALLOC(1, sizeof(long));
5967
         UE->DRB_config[0][0]->drb_Identity =  direct_comm_rbid;
5968 5969
         UE->DRB_config[0][0]->eps_BearerIdentity = CALLOC(1, sizeof(long));
         // allowed value 5..15, value : x+4
5970
         *(UE->DRB_config[0][0]->eps_BearerIdentity) = direct_comm_rbid;
5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060
         UE->DRB_config[0][0]->logicalChannelIdentity = CALLOC(1, sizeof(long));
         *(UE->DRB_config[0][0]->logicalChannelIdentity) = UE->DRB_config[0][0]->drb_Identity; //(long) (ue_context_pP->ue_context.e_rab[i].param.e_rab_id + 2); // value : x+2

         DRB_rlc_config                   = CALLOC(1,sizeof(struct RLC_Config));
         DRB_pdcp_config                  = CALLOC(1,sizeof(struct PDCP_Config));
         PDCP_rlc_UM                      = CALLOC(1,sizeof(struct PDCP_Config__rlc_UM));
         DRB_lchan_config                 = CALLOC(1,sizeof(struct LogicalChannelConfig));
         DRB_ul_SpecificParameters                                         = CALLOC(1, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
         logicalchannelgroup_drb          = CALLOC(1, sizeof(long));

         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;
         UE->DRB_config[0][0]->rlc_Config = DRB_rlc_config;

         DRB_pdcp_config = CALLOC(1, sizeof(*DRB_pdcp_config));
         UE->DRB_config[0][0]->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;

         /* avoid gcc warnings */
         (void)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;

         UE->DRB_config[0][0]->logicalChannelConfig = DRB_lchan_config;
         DRB_ul_SpecificParameters = CALLOC(1, sizeof(*DRB_ul_SpecificParameters));
         DRB_lchan_config->ul_SpecificParameters = DRB_ul_SpecificParameters;

         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;
         DRB_ul_SpecificParameters->bucketSizeDuration =
               LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;

         // LCG for DTCH can take the value from 1 to 3 as defined in 36331: normally controlled by upper layers (like RRM)

         *logicalchannelgroup_drb = 1;
         DRB_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup_drb;

         UE->DRB_configList = CALLOC(1,sizeof(DRB_ToAddModList_t));
         ASN_SEQUENCE_ADD(&UE->DRB_configList->list,UE->DRB_config[0][0]);

         rrc_pdcp_config_asn1_req(&ctxt,
               (SRB_ToAddModList_t *) NULL,
               UE->DRB_configList,
               (DRB_ToReleaseList_t*) NULL,
               0xff, NULL, NULL, NULL
#if defined(Rel10) || defined(Rel14)
               , (PMCH_InfoList_r9_t *) NULL
#endif
               ,NULL);


         rrc_rlc_config_asn1_req(&ctxt,
               (SRB_ToAddModList_t*)NULL,
               UE->DRB_configList,
               (DRB_ToReleaseList_t*)NULL
#if defined(Rel10) || defined(Rel14)
               ,(PMCH_InfoList_r9_t *)NULL
               , 0, 0
#endif
         );

         rrc_rlc_config_asn1_req(&ctxt,
               (SRB_ToAddModList_t*)NULL,
               UE->DRB_configList,
               (DRB_ToReleaseList_t*)NULL
#ifdef Rel14
               ,(PMCH_InfoList_r9_t *)NULL
               , sourceL2Id, destinationL2Id
#endif
         );


         //configure MAC with sourceL2Id/destinationL2Id
         rrc_mac_config_req_ue(module_id,0,0, //eNB_index =0
               (RadioResourceConfigCommonSIB_t *)NULL,
               (struct PhysicalConfigDedicated *)NULL,
#if defined(Rel10) || defined(Rel14)
               (SCellToAddMod_r10_t *)NULL,
               //struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
#endif
               (MeasObjectToAddMod_t **)NULL,
               (MAC_MainConfig_t *)NULL,
6061
               direct_comm_rbid, //LCID
6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085
               (struct LogicalChannelConfig *)NULL,
               (MeasGapConfig_t *)NULL,
               (TDD_Config_t *)NULL,
               (MobilityControlInfo_t *)NULL,
               NULL,
               NULL,
               NULL,
               NULL,
               NULL,
               NULL
#if defined(Rel10) || defined(Rel14)
               ,0,
               (MBSFN_AreaInfoList_r9_t *)NULL,
               (PMCH_InfoList_r9_t *)NULL

#endif
#ifdef CBA
               ,
               0,
               0
#endif
#if defined(Rel10) || defined(Rel14)
               ,CONFIG_ACTION_ADD,
               &sourceL2Id,
6086 6087
               &destinationL2Id,
               NULL
6088 6089 6090 6091 6092 6093 6094
#endif
         );

         LOG_I(RRC,"Send DirectCommunicationEstablishResp to ProSe App\n");
         memset(send_buf, 0, BUFSIZE);
         sl_ctrl_msg_send = calloc(1, sizeof(struct sidelink_ctrl_element));
         sl_ctrl_msg_send->type = DIRECT_COMMUNICATION_ESTABLISH_RSP;
6095
         sl_ctrl_msg_send->sidelinkPrimitive.slrb_id = direct_comm_rbid; //slrb_id
6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114

         memcpy((void *)send_buf, (void *)sl_ctrl_msg_send, sizeof(struct sidelink_ctrl_element));
         free(sl_ctrl_msg_send);

         prose_addr_len = sizeof(prose_app_addr);
         n = sendto(ctrl_sock_fd, (char *)send_buf, sizeof(struct sidelink_ctrl_element), 0, (struct sockaddr *)&prose_app_addr, prose_addr_len);
         if (n < 0){
            LOG_E(RRC, "ERROR: Failed to send to ProSe App\n");
            exit(EXIT_FAILURE);
         }


#ifdef DEBUG_CTRL_SOCKET
         ptr_ctrl_msg = (struct sidelink_ctrl_element *) send_buf;
         LOG_I(RRC,"[DirectCommunicationEstablishResponse]  msg type: %d\n",ptr_ctrl_msg->type);
         LOG_I(RRC,"[DirectCommunicationEstablishResponse]  slrb_id: %d\n",ptr_ctrl_msg->sidelinkPrimitive.slrb_id);
#endif
         break;

6115
      case PC5S_ESTABLISH_REQ:
6116
         type =  sl_ctrl_msg_recv->sidelinkPrimitive.pc5s_establish_req.type;
6117
         sourceL2Id = sl_ctrl_msg_recv->sidelinkPrimitive.pc5s_establish_req.sourceL2Id;
6118
         int pc5s_rbid = 10;
6119 6120 6121 6122
#ifdef DEBUG_CTRL_SOCKET
         LOG_I(RRC,"[PC5EstablishReq] Received on socket from ProSe App (msg type: %d)\n",sl_ctrl_msg_recv->type);
         LOG_I(RRC,"[PC5EstablishReq] type: %d\n",sl_ctrl_msg_recv->sidelinkPrimitive.pc5s_establish_req.type); //RX/TX
         LOG_I(RRC,"[PC5EstablishReq] source Id: 0x%08x \n",sl_ctrl_msg_recv->sidelinkPrimitive.pc5s_establish_req.sourceL2Id);
6123 6124 6125
#endif
         if (type > 0) {
            destinationL2Id = sl_ctrl_msg_recv->sidelinkPrimitive.pc5s_establish_req.destinationL2Id;
6126
#ifdef DEBUG_CTRL_SOCKET
6127
            LOG_I(RRC,"[PC5EstablishReq] destination Id: 0x%08x \n",sl_ctrl_msg_recv->sidelinkPrimitive.pc5s_establish_req.destinationL2Id);
6128
#endif
6129 6130
         }

6131
         //store sourceL2Id/destinationL2Id
6132 6133
         if (type > 0) { //TX
            UE_rrc_inst[module_id].sourceL2Id = sourceL2Id;
6134 6135
            j = 0;
            i = 0;
6136 6137
            for (i=0; i< MAX_NUM_DEST; i++) {
               if ((UE_rrc_inst[module_id].destinationList[i] == 0) && (j == 0)) j = i+1;
6138
               if (UE_rrc_inst[module_id].destinationList[i] == destinationL2Id) break; //destination already exists!
6139
            }
6140
            if ((i == MAX_NUM_DEST) && (j > 0))  UE_rrc_inst[module_id].destinationList[j-1] = destinationL2Id;
6141 6142 6143 6144 6145 6146 6147
         } else {//RX
            UE_rrc_inst[module_id].sourceL2Id = sourceL2Id;
         }

         // configure lower layers PDCP/MAC/PHY for this communication
         //Establish a new RBID/LCID for this communication
         // Establish a SLRB (using DRB 10 for now)
6148
         UE  = &UE_rrc_inst[module_id];
6149 6150 6151 6152
         PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, 0, ENB_FLAG_NO, 0x1234, 0, 0,0);

         UE->DRB_config[0][0] = CALLOC(1,sizeof(struct DRB_ToAddMod));
         UE->DRB_config[0][0]->eps_BearerIdentity = CALLOC(1, sizeof(long));
6153
         UE->DRB_config[0][0]->drb_Identity =  pc5s_rbid;
6154 6155
         UE->DRB_config[0][0]->eps_BearerIdentity = CALLOC(1, sizeof(long));
         // allowed value 5..15, value : x+4
6156
         *(UE->DRB_config[0][0]->eps_BearerIdentity) = pc5s_rbid;
6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185
         UE->DRB_config[0][0]->logicalChannelIdentity = CALLOC(1, sizeof(long));
         *(UE->DRB_config[0][0]->logicalChannelIdentity) = UE->DRB_config[0][0]->drb_Identity; //(long) (ue_context_pP->ue_context.e_rab[i].param.e_rab_id + 2); // value : x+2

         DRB_rlc_config                   = CALLOC(1,sizeof(struct RLC_Config));
         DRB_pdcp_config                  = CALLOC(1,sizeof(struct PDCP_Config));
         PDCP_rlc_UM                      = CALLOC(1,sizeof(struct PDCP_Config__rlc_UM));
         DRB_lchan_config                 = CALLOC(1,sizeof(struct LogicalChannelConfig));
         DRB_ul_SpecificParameters                                         = CALLOC(1, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
         logicalchannelgroup_drb          = CALLOC(1, sizeof(long));

         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;
         UE->DRB_config[0][0]->rlc_Config = DRB_rlc_config;

         DRB_pdcp_config = CALLOC(1, sizeof(*DRB_pdcp_config));
         UE->DRB_config[0][0]->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;

         /* avoid gcc warnings */
         (void)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;
6186

6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233
         UE->DRB_config[0][0]->logicalChannelConfig = DRB_lchan_config;
         DRB_ul_SpecificParameters = CALLOC(1, sizeof(*DRB_ul_SpecificParameters));
         DRB_lchan_config->ul_SpecificParameters = DRB_ul_SpecificParameters;

         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;
         DRB_ul_SpecificParameters->bucketSizeDuration =
               LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50;

         // LCG for DTCH can take the value from 1 to 3 as defined in 36331: normally controlled by upper layers (like RRM)

         *logicalchannelgroup_drb = 1;
         DRB_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup_drb;

         UE->DRB_configList = CALLOC(1,sizeof(DRB_ToAddModList_t));
         ASN_SEQUENCE_ADD(&UE->DRB_configList->list,UE->DRB_config[0][0]);

         rrc_pdcp_config_asn1_req(&ctxt,
               (SRB_ToAddModList_t *) NULL,
               UE->DRB_configList,
               (DRB_ToReleaseList_t*) NULL,
               0xff, NULL, NULL, NULL
#if defined(Rel10) || defined(Rel14)
               , (PMCH_InfoList_r9_t *) NULL
#endif
               ,NULL);


         rrc_rlc_config_asn1_req(&ctxt,
               (SRB_ToAddModList_t*)NULL,
               UE->DRB_configList,
               (DRB_ToReleaseList_t*)NULL
#if defined(Rel10) || defined(Rel14)
               ,(PMCH_InfoList_r9_t *)NULL
               , 0, 0
#endif
         );

         //TX
         if (type > 0) {
            rrc_rlc_config_asn1_req(&ctxt,
                  (SRB_ToAddModList_t*)NULL,
                  UE->DRB_configList,
                  (DRB_ToReleaseList_t*)NULL
#ifdef Rel14
                  ,(PMCH_InfoList_r9_t *)NULL
6234
                  , sourceL2Id, destinationL2Id
6235 6236 6237 6238
#endif
            );

            //configure MAC with sourceL2Id/groupL2ID
6239
            rrc_mac_config_req_ue(module_id,0,0, //eNB_index =0
6240 6241 6242 6243 6244 6245 6246 6247
                  (RadioResourceConfigCommonSIB_t *)NULL,
                  (struct PhysicalConfigDedicated *)NULL,
#if defined(Rel10) || defined(Rel14)
                  (SCellToAddMod_r10_t *)NULL,
                  //struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
#endif
                  (MeasObjectToAddMod_t **)NULL,
                  (MAC_MainConfig_t *)NULL,
6248
                  pc5s_rbid, //LCID
6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262
                  (struct LogicalChannelConfig *)NULL,
                  (MeasGapConfig_t *)NULL,
                  (TDD_Config_t *)NULL,
                  (MobilityControlInfo_t *)NULL,
                  NULL,
                  NULL,
                  NULL,
                  NULL,
                  NULL,
                  NULL
#if defined(Rel10) || defined(Rel14)
                  ,0,
                  (MBSFN_AreaInfoList_r9_t *)NULL,
                  (PMCH_InfoList_r9_t *)NULL
6263

6264 6265 6266 6267 6268 6269 6270 6271 6272
#endif
#ifdef CBA
                  ,
                  0,
                  0
#endif
#if defined(Rel10) || defined(Rel14)
                  ,CONFIG_ACTION_ADD,
                  &sourceL2Id,
6273 6274
                  &destinationL2Id,
                  NULL
6275 6276
#endif
            );
6277
         } else {//RX
6278 6279 6280 6281 6282 6283 6284 6285 6286 6287
            //configure MAC with sourceL2Id/groupL2ID
            rrc_mac_config_req_ue(module_id,0,0, //eNB_index =0
                  (RadioResourceConfigCommonSIB_t *)NULL,
                  (struct PhysicalConfigDedicated *)NULL,
#if defined(Rel10) || defined(Rel14)
                  (SCellToAddMod_r10_t *)NULL,
                  //struct PhysicalConfigDedicatedSCell_r10 *physicalConfigDedicatedSCell_r10,
#endif
                  (MeasObjectToAddMod_t **)NULL,
                  (MAC_MainConfig_t *)NULL,
6288
                  pc5s_rbid, //LCID
6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302
                  (struct LogicalChannelConfig *)NULL,
                  (MeasGapConfig_t *)NULL,
                  (TDD_Config_t *)NULL,
                  (MobilityControlInfo_t *)NULL,
                  NULL,
                  NULL,
                  NULL,
                  NULL,
                  NULL,
                  NULL
#if defined(Rel10) || defined(Rel14)
                  ,0,
                  (MBSFN_AreaInfoList_r9_t *)NULL,
                  (PMCH_InfoList_r9_t *)NULL
6303

6304 6305 6306 6307 6308 6309 6310 6311 6312
#endif
#ifdef CBA
                  ,
                  0,
                  0
#endif
#if defined(Rel10) || defined(Rel14)
                  ,CONFIG_ACTION_ADD,
                  &sourceL2Id,
6313
                  NULL,
6314 6315 6316 6317 6318
                  NULL
#endif
            );

         }
6319 6320 6321 6322 6323

         LOG_I(RRC,"Send PC5EstablishRsp to ProSe App\n");
         memset(send_buf, 0, BUFSIZE);
         sl_ctrl_msg_send = calloc(1, sizeof(struct sidelink_ctrl_element));
         sl_ctrl_msg_send->type = PC5S_ESTABLISH_RSP;
6324 6325 6326
         sl_ctrl_msg_send->sidelinkPrimitive.pc5s_establish_rsp.slrbid_lcid28 = pc5s_rbid;
         sl_ctrl_msg_send->sidelinkPrimitive.pc5s_establish_rsp.slrbid_lcid29 = pc5s_rbid;
         sl_ctrl_msg_send->sidelinkPrimitive.pc5s_establish_rsp.slrbid_lcid30 = pc5s_rbid;
6327 6328 6329 6330
         memcpy((void *)send_buf, (void *)sl_ctrl_msg_send, sizeof(struct sidelink_ctrl_element));

         prose_addr_len = sizeof(prose_app_addr);
         n = sendto(ctrl_sock_fd, (char *)send_buf, sizeof(struct sidelink_ctrl_element), 0, (struct sockaddr *)&prose_app_addr, prose_addr_len);
6331
//         free(sl_ctrl_msg_send);
6332 6333 6334 6335 6336 6337
         if (n < 0){
            LOG_E(RRC, "ERROR: Failed to send to ProSe App\n");
            exit(EXIT_FAILURE);
         }
         break;

6338

6339
      case PC5_DISCOVERY_MESSAGE:
6340 6341

 #ifdef DEBUG_CTRL_SOCKET
6342
           LOG_I(RRC,"[PC5DiscoveryMessage] Received on socket from ProSe App (msg type: %d)\n",sl_ctrl_msg_recv->type);
6343 6344
 #endif
        //prepare SL_Discovery buffer
6345
         if (UE_rrc_inst) {
6346 6347 6348
           memcpy((void*)&UE_rrc_inst[module_id].SL_Discovery[0].Tx_buffer.Payload[0], (void*)&sl_ctrl_msg_recv->sidelinkPrimitive.pc5_discovery_message.payload[0], PC5_DISCOVERY_PAYLOAD_SIZE);
           UE_rrc_inst[module_id].SL_Discovery[0].Tx_buffer.payload_size = PC5_DISCOVERY_PAYLOAD_SIZE;
           LOG_I(RRC,"[PC5DiscoveryMessage] Copied %d bytes\n",PC5_DISCOVERY_PAYLOAD_SIZE);
6349
         }
6350
         break;
6351 6352 6353 6354 6355 6356 6357 6358 6359
      default:
         break;
      }
   }
   free (sl_ctrl_msg_recv);
   return 0;
}


6360
//-----------------------------------------------------------------------------
6361
int decode_SL_Discovery_Message(
6362 6363 6364 6365 6366 6367 6368 6369 6370
  const protocol_ctxt_t* const ctxt_pP,
  const uint8_t                eNB_index,
  uint8_t*               const Sdu,
  const uint8_t                Sdu_len)
{

   int prose_addr_len;
   char send_buf[BUFSIZE];
   int n;
6371
   struct sidelink_ctrl_element *sl_ctrl_msg_send = NULL;
6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383

   //from the main program, listen for the incoming messages from control socket (ProSe App)
   prose_addr_len = sizeof(prose_app_addr);

   //Store in Rx_buffer
   memcpy((void*)&UE_rrc_inst[ctxt_pP->module_id].SL_Discovery[0].Rx_buffer.Payload[0], (void*)Sdu, Sdu_len);
   UE_rrc_inst[ctxt_pP->module_id].SL_Discovery[0].Rx_buffer.payload_size = Sdu_len;

   memset(send_buf, 0, BUFSIZE);
   //send to ProSeApp
   memcpy((void *)send_buf, (void*)Sdu, Sdu_len);
   prose_addr_len = sizeof(prose_app_addr);
6384

6385 6386 6387
   sl_ctrl_msg_send = calloc(1, sizeof(struct sidelink_ctrl_element));
   sl_ctrl_msg_send->type = PC5_DISCOVERY_MESSAGE;
   // TODO:  Add a check for the SDU size.
William Johnson's avatar
William Johnson committed
6388
   memcpy((void*)&sl_ctrl_msg_send->sidelinkPrimitive.pc5_discovery_message.payload[0], (void*) Sdu,  PC5_DISCOVERY_PAYLOAD_SIZE);
6389 6390 6391 6392 6393 6394 6395

   memcpy((void *)send_buf, (void *)sl_ctrl_msg_send, sizeof(struct sidelink_ctrl_element));
   free(sl_ctrl_msg_send);

   prose_addr_len = sizeof(prose_app_addr);

   n = sendto(ctrl_sock_fd, (char *)send_buf, sizeof(struct sidelink_ctrl_element), 0, (struct sockaddr *)&prose_app_addr, prose_addr_len);
6396
   if (n < 0){
6397 6398
      // TODO:  We should not just exit if the Prose App has not yet attached.  It creates a race condition.
      LOG_I(RRC, "ERROR: Failed to send to ProSe App\n");
6399
      //exit(EXIT_FAILURE);
6400
   }
6401 6402


6403 6404 6405 6406

  return(0);
}

6407
#endif
6408

6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520
//-----------------------------------------------------------------------------
RRC_status_t
rrc_rx_tx_ue(
  protocol_ctxt_t* const ctxt_pP,
  const uint8_t      enb_indexP,
  const int          CC_id
)
//-----------------------------------------------------------------------------
{

#ifdef LOCALIZATION
  double                         estimated_distance;
  protocol_ctxt_t                ctxt;
#endif
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_RX_TX,VCD_FUNCTION_IN);

    // check timers

    if (UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T300_active == 1) {
      if ((UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T300_cnt % 10) == 0)
        LOG_D(RRC,
              "[UE %d][RAPROC] Frame %d T300 Count %d ms\n", ctxt_pP->module_id, ctxt_pP->frame, UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T300_cnt);

      if (UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T300_cnt
          == T300[UE_rrc_inst[ctxt_pP->module_id].sib2[enb_indexP]->ue_TimersAndConstants.t300]) {
        UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T300_active = 0;
        // ALLOW CCCH to be used
        UE_rrc_inst[ctxt_pP->module_id].Srb0[enb_indexP].Tx_buffer.payload_size = 0;
        rrc_ue_generate_RRCConnectionRequest (ctxt_pP, enb_indexP);
        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_RX_TX,VCD_FUNCTION_OUT);
        return (RRC_ConnSetup_failed);
      }

      UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T300_cnt++;
    }

    if ((UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].SIStatus&2)>0) {
      if (UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].N310_cnt
          == N310[UE_rrc_inst[ctxt_pP->module_id].sib2[enb_indexP]->ue_TimersAndConstants.n310]) {
	LOG_I(RRC,"Activating T310\n");
        UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T310_active = 1;
      }
    } else { // in case we have not received SIB2 yet
      /*      if (UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].N310_cnt == 100) {
        UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].N310_cnt = 0;

	}*/
      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_RX_TX,VCD_FUNCTION_OUT);
      return RRC_OK;
    }

    if (UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T310_active == 1) {
      if (UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].N311_cnt
          == N311[UE_rrc_inst[ctxt_pP->module_id].sib2[enb_indexP]->ue_TimersAndConstants.n311]) {
        UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T310_active = 0;
        UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].N311_cnt = 0;
      }

      if ((UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T310_cnt % 10) == 0) {
        LOG_D(RRC, "[UE %d] Frame %d T310 Count %d ms\n", ctxt_pP->module_id, ctxt_pP->frame, UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T310_cnt);
      }

      if (UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T310_cnt    == T310[UE_rrc_inst[ctxt_pP->module_id].sib2[enb_indexP]->ue_TimersAndConstants.t310]) {
        UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T310_active = 0;
        rrc_t310_expiration (ctxt_pP, enb_indexP);
        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_RX_TX,VCD_FUNCTION_OUT);
	LOG_I(RRC,"Returning RRC_PHY_RESYNCH: T310 expired\n"); 
        return RRC_PHY_RESYNCH;
      }

      UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T310_cnt++;
    }

    if (UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T304_active==1) {
      if ((UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T304_cnt % 10) == 0)
        LOG_D(RRC,"[UE %d][RAPROC] Frame %d T304 Count %d ms\n",ctxt_pP->module_id,ctxt_pP->frame,
              UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T304_cnt);

      if (UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T304_cnt == 0) {
        UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T304_active = 0;
        UE_rrc_inst[ctxt_pP->module_id].HandoverInfoUe.measFlag = 1;
        LOG_E(RRC,"[UE %d] Handover failure..initiating connection re-establishment procedure... \n",
              ctxt_pP->module_id);
        //Implement 36.331, section 5.3.5.6 here
        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_RX_TX,VCD_FUNCTION_OUT);
        return(RRC_Handover_failed);
      }

      UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].T304_cnt--;
    }

    // Layer 3 filtering of RRC measurements
    if (UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[0] != NULL) {
      ue_meas_filtering(ctxt_pP,enb_indexP);
    }

    ue_measurement_report_triggering(ctxt_pP,enb_indexP);

    if (UE_rrc_inst[ctxt_pP->module_id].Info[0].handoverTarget > 0) {
      LOG_I(RRC,"[UE %d] Frame %d : RRC handover initiated\n", ctxt_pP->module_id, ctxt_pP->frame);
    }

    if((UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].State == RRC_HO_EXECUTION)   &&
        (UE_rrc_inst[ctxt_pP->module_id].HandoverInfoUe.targetCellId != 0xFF)) {
      UE_rrc_inst[ctxt_pP->module_id].Info[enb_indexP].State= RRC_IDLE;
      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_RX_TX,VCD_FUNCTION_OUT);
      return(RRC_HO_STARTED);
    }

  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_RX_TX,VCD_FUNCTION_OUT);
  return (RRC_OK);
}
6521