rrc_eNB.c 468 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
Cedric Roux's avatar
Cedric Roux committed
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 23

/*! \file rrc_eNB.c
 * \brief rrc procedures for eNB
24
 * \author Navid Nikaein and  Raymond Knopp
nikaeinn's avatar
nikaeinn committed
25
 * \date 2011 - 2014
26 27
 * \version 1.0
 * \company Eurecom
nikaeinn's avatar
nikaeinn committed
28
 * \email: navid.nikaein@eurecom.fr and raymond.knopp@eurecom.fr
29
 */
gauthier's avatar
gauthier committed
30 31
#define RRC_ENB
#define RRC_ENB_C
32 33 34
#include <asn_application.h>
#include <asn_internal.h> /* for _ASN_DEFAULT_STACK_MAX */
#include <per_encoder.h>
35 36
#include "rrc_defs.h"
#include "rrc_extern.h"
37
#include "assertions.h"
38
#include "common/ran_context.h"
39
#include "asn1_conversions.h"
knopp's avatar
knopp committed
40
#include "asn_internal.h"
41 42
#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"
#include "LAYER2/RLC/rlc.h"
43
#include "LAYER2/MAC/mac_proto.h"
44
#include "common/utils/LOG/log.h"
45
#include "COMMON/mac_rrc_primitives.h"
46
#include "RRC/LTE/MESSAGES/asn1_msg.h"
47 48
#include "LTE_RRCConnectionRequest.h"
#include "LTE_RRCConnectionReestablishmentRequest.h"
49
//#include "ReestablishmentCause.h"
50 51 52 53 54 55
#include "LTE_BCCH-BCH-Message.h"
#include "LTE_UL-CCCH-Message.h"
#include "LTE_DL-CCCH-Message.h"
#include "LTE_UL-DCCH-Message.h"
#include "LTE_DL-DCCH-Message.h"
#include "LTE_TDD-Config.h"
56
#include "LTE_HandoverPreparationInformation.h"
57
#include "LTE_HandoverCommand.h"
58
#include "rlc.h"
59 60 61
#include "rrc_eNB_UE_context.h"
#include "platform_types.h"
#include "msc.h"
62 63 64
#include "LTE_SL-CommConfig-r12.h"
#include "LTE_PeriodicBSR-Timer-r12.h"
#include "LTE_RetxBSR-Timer-r12.h"
65 66 67 68 69 70

#include "LTE_BCCH-BCH-Message-MBMS.h"
#include "LTE_BCCH-DL-SCH-Message-MBMS.h"
#include "LTE_SystemInformationBlockType1-MBMS-r14.h"
#include "LTE_NonMBSFN-SubframeConfig-r14.h"

71
#include "common/utils/LOG/vcd_signal_dumper.h"
Cedric Roux's avatar
Cedric Roux committed
72
#include "x2ap_eNB.h"
73

74
#include "T.h"
75
#include "LTE_MeasResults.h"
76

Mongazon's avatar
Mongazon committed
77 78 79 80
#include "RRC/NAS/nas_config.h"
#include "RRC/NAS/rb_config.h"
#include "OCG.h"
#include "OCG_extern.h"
81

82
#include "UTIL/OSA/osa_defs.h"
83

84 85
#include "rrc_eNB_S1AP.h"
#include "rrc_eNB_GTPV1U.h"
86

87
#include "pdcp.h"
88
#include "gtpv1u_eNB_task.h"
89

90
#include "intertask_interface.h"
91

92
#if ENABLE_RAL
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
93
  #include "rrc_eNB_ral.h"
gauthier's avatar
gauthier committed
94 95
#endif

96
#include "SIMULATION/TOOLS/sim.h" // for taus
97

98

99 100
extern RAN_CONTEXT_t RC;

101
#ifdef PHY_EMUL
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
102
  extern EMULATION_VARS              *Emul_vars;
103
#endif
104 105
extern eNB_MAC_INST                *eNB_mac_inst;
extern UE_MAC_INST                 *UE_mac_inst;
106

107
extern uint16_t                     two_tier_hexagonal_cellIds[7];
winckel's avatar
RRC:  
winckel committed
108

109
mui_t                               rrc_eNB_mui = 0;
winckel's avatar
RRC:  
winckel committed
110

111
extern uint32_t to_earfcn_DL(int eutra_bandP, uint32_t dl_CarrierFreq, uint32_t bw);
112 113
extern int rrc_eNB_process_security(const protocol_ctxt_t *const ctxt_pP, rrc_eNB_ue_context_t *const ue_context_pP, security_capabilities_t *security_capabilities_pP);
extern void process_eNB_security_key (const protocol_ctxt_t *const ctxt_pP, rrc_eNB_ue_context_t *const ue_context_pP, uint8_t *security_key_pP);
114
extern int derive_keNB_star(const uint8_t *kenb_32, const uint16_t pci, const uint32_t earfcn_dl, const bool is_rel8_only, uint8_t *kenb_star);
115

116 117 118 119
pthread_mutex_t      rrc_release_freelist;
RRC_release_list_t   rrc_release_info;
pthread_mutex_t      lock_ue_freelist;

120 121
void
openair_rrc_on(
Cedric Roux's avatar
Cedric Roux committed
122
  const protocol_ctxt_t *const ctxt_pP
123 124 125 126
)
//-----------------------------------------------------------------------------
{
  int            CC_id;
Cedric Roux's avatar
Cedric Roux committed
127 128
  LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" ENB:OPENAIR RRC IN....\n",
        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
129

Cedric Roux's avatar
Cedric Roux committed
130 131 132 133
  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
    rrc_config_buffer (&RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SI, BCCH, 1);
    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SI.Active = 1;
  }
134 135
}

136 137 138
//-----------------------------------------------------------------------------
static void
init_SI(
139
  const protocol_ctxt_t *const ctxt_pP,
140
  const int              CC_id,
141
  RrcConfigurationReq *configuration
142
)
143
//-----------------------------------------------------------------------------
144 145
{
  int                                 i;
146
  LTE_SystemInformationBlockType1_v1310_IEs_t *sib1_v13ext=(LTE_SystemInformationBlockType1_v1310_IEs_t *)NULL;
Cedric Roux's avatar
Cedric Roux committed
147
  LOG_D(RRC,"%s()\n\n\n\n",__FUNCTION__);
148

149 150 151 152 153
  if(configuration->radioresourceconfig[CC_id].mbms_dedicated_serving_cell == TRUE) {
    LOG_I(RRC, "Configuring MIB FeMBMS (N_RB_DL %d)\n",
          (int)configuration->N_RB_DL[CC_id]);
    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].MIB_FeMBMS = (uint8_t *) malloc16(4);
    do_MIB_FeMBMS(&RC.rrc[ctxt_pP->module_id]->carrier[CC_id],
154
#ifdef ENABLE_ITTI
155 156
                  configuration->N_RB_DL[CC_id],
                  0 //additionalNonMBSFN
157
#else
158 159 160 161 162 163 164 165
                  50,0
#endif
                  ,0);
    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB1_MBMS = 0;
    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SIB1_MBMS = (uint8_t *) malloc16(32);
    AssertFatal(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SIB1_MBMS!=NULL,PROTOCOL_RRC_CTXT_FMT" init_SI: FATAL, no memory for SIB1_MBMS allocated\n",
                PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB1_MBMS = do_SIB1_MBMS(&RC.rrc[ctxt_pP->module_id]->carrier[CC_id],ctxt_pP->module_id,CC_id
166
#if defined(ENABLE_ITTI)
167
        , configuration
168
#endif
169 170
                                                                              );
    LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Contents of SIB1-MBMS\n",
171
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP)
172 173
         );
    LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB1-MBMS freqBandIndicator_r14 %ld\n",
174
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
175 176
          RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1_MBMS->freqBandIndicator_r14
         );
177

178 179
    for (i = 0; i < RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1_MBMS->schedulingInfoList_MBMS_r14.list.count; i++) {
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB1-MBMS contents for Scheduling Info List %d/%d(partial)\n",
180 181 182
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            i,
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1_MBMS->schedulingInfoList_MBMS_r14.list.count);
183 184 185
    }

    LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB1-MBMS SIB13-r14 contents for MBSFN subframe allocation (partial)\n",
186
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP)
187
         );
188 189

    for (i = 0; i < RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1_MBMS->systemInformationBlockType13_r14->mbsfn_AreaInfoList_r9.list.count; i++) {
190
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB1-MBMS SIB13-r14 contents for MBSFN sync area %d/%d (partial)\n",
191 192 193
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            i,
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1_MBMS->systemInformationBlockType13_r14->mbsfn_AreaInfoList_r9.list.count);
194
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB1-MBMS MCCH Repetition Period: %ld (just index number, not real value)\n",
195 196
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1_MBMS->systemInformationBlockType13_r14->mbsfn_AreaInfoList_r9.list.array[i]->mcch_Config_r9.mcch_RepetitionPeriod_r9);
197
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB1-MBMS MCCH Offset: %ld\n",
198 199
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1_MBMS->systemInformationBlockType13_r14->mbsfn_AreaInfoList_r9.list.array[i]->mcch_Config_r9.mcch_Offset_r9);
200
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB1-MBMS MCCH Modification Period: %ld\n",
201 202
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1_MBMS->systemInformationBlockType13_r14->mbsfn_AreaInfoList_r9.list.array[i]->mcch_Config_r9.mcch_ModificationPeriod_r9);
203
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB1-MBMS MCCH Signalling MCS: %ld\n",
204 205
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1_MBMS->systemInformationBlockType13_r14->mbsfn_AreaInfoList_r9.list.array[i]->mcch_Config_r9.signallingMCS_r9);
206 207 208
      //LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB1-MBMS SIB13 sf_AllocInfo is = %x\n",
      //    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
      //    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1_MBMS->systemInformationBlockType13_r14->mbsfn_AreaInfoList_r9.list.array[i]->mcch_Config_r9.sf_AllocInfo_r9.buf);
209

210 211 212 213 214 215
      if(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1_MBMS->systemInformationBlockType13_r14->mbsfn_AreaInfoList_r9.list.array[i]->ext1) {
        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB1-MBMS Subcarrier Spacing MBMS: %s\n",
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
              (*RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1_MBMS->systemInformationBlockType13_r14->mbsfn_AreaInfoList_r9.list.array[i]->ext1->subcarrierSpacingMBMS_r14 ==
               LTE_MBSFN_AreaInfo_r9__ext1__subcarrierSpacingMBMS_r14_khz_1dot25 ? "khz_1dot25": "khz_7dot5"));
      }
216 217 218
    }

    if(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1_MBMS->nonMBSFN_SubframeConfig_r14) {
219 220 221 222 223 224 225 226 227
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB1-MBMS non MBSFN Subframe Config radioFrameAllocationPeriod-r14 %ld\n",
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1_MBMS->nonMBSFN_SubframeConfig_r14->radioFrameAllocationPeriod_r14
           );
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB1-MBMS non MBSFN Subframe Config radioFrameAllocationOffset-r14 %ld\n",
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1_MBMS->nonMBSFN_SubframeConfig_r14->radioFrameAllocationOffset_r14
           );
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB1-MBMS non MBSFN Subframe Config subframeAllocation-r14 is = %s\n",
228 229 230 231
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1_MBMS->nonMBSFN_SubframeConfig_r14->subframeAllocation_r14.buf);
    }

232 233
    //AssertFatal(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB1 != 255,"FATAL, RC.rrc[enb_mod_idP].carrier[CC_id].sizeof_SIB1 == 255");
  }
234

235 236
  eNB_RRC_INST *rrc = RC.rrc[ctxt_pP->module_id];
  rrc_eNB_carrier_data_t *carrier=&rrc->carrier[CC_id];
237
  carrier->MIB = (uint8_t *) malloc16(4);
238 239
  carrier->sizeof_SIB1 = 0;
  carrier->sizeof_SIB23 = 0;
240
  carrier->SIB1 = (uint8_t *) malloc16(32);
241
  AssertFatal(carrier->SIB1!=NULL,PROTOCOL_RRC_CTXT_FMT" init_SI: FATAL, no memory for SIB1 allocated\n",
242
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
243
  LOG_I(RRC,"[eNB %d] Node type %d \n ", ctxt_pP->module_id, rrc->node_type);
244

245
  if (NODE_IS_DU(rrc->node_type) || NODE_IS_MONOLITHIC(rrc->node_type)) {
246 247 248 249 250 251
    // copy basic Cell parameters
    carrier->physCellId      = configuration->Nid_cell[CC_id];
    carrier->p_eNB           = configuration->nb_antenna_ports[CC_id];
    carrier->Ncp             = configuration->prefix_type[CC_id];
    carrier->dl_CarrierFreq  = configuration->downlink_frequency[CC_id];
    carrier->ul_CarrierFreq  = configuration->downlink_frequency[CC_id]+ configuration->uplink_frequency_offset[CC_id];
252 253
    carrier->eutra_band      = configuration->eutra_band[CC_id];
    carrier->N_RB_DL         = configuration->N_RB_DL[CC_id];
254
    carrier->pbch_repetition = configuration->pbch_repetition[CC_id];
255
    LOG_I(RRC, "configuration->schedulingInfoSIB1_BR_r13[CC_id] %d\n",(int)configuration->schedulingInfoSIB1_BR_r13[CC_id]);
256 257 258 259
    LOG_I(RRC, "Configuring MIB (N_RB_DL %d,phich_Resource %d,phich_Duration %d)\n",
          (int)configuration->N_RB_DL[CC_id],
          (int)configuration->radioresourceconfig[CC_id].phich_resource,
          (int)configuration->radioresourceconfig[CC_id].phich_duration);
260 261 262 263
    carrier->sizeof_MIB = do_MIB(&rrc->carrier[CC_id],
                                 configuration->N_RB_DL[CC_id],
                                 configuration->radioresourceconfig[CC_id].phich_resource,
                                 configuration->radioresourceconfig[CC_id].phich_duration,
264 265 266
                                 0,
                                 configuration->schedulingInfoSIB1_BR_r13[CC_id]
                                );
267 268
    carrier->sizeof_SIB1 = do_SIB1(&rrc->carrier[CC_id],
                                   ctxt_pP->module_id,
269 270 271 272
                                   CC_id,
                                   FALSE,
                                   configuration
                                  );
273
    AssertFatal(carrier->sizeof_SIB1 != 255,"FATAL, RC.rrc[enb_mod_idP].carrier[CC_id].sizeof_SIB1 == 255");
274
    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB1_BR = 0;
275

276 277 278
    if (configuration->schedulingInfoSIB1_BR_r13[CC_id] > 0) {
      RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SIB1_BR = (uint8_t *) malloc16(32);
      RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB1_BR = do_SIB1(&RC.rrc[ctxt_pP->module_id]->carrier[CC_id],
279 280
          ctxt_pP->module_id,
          CC_id, TRUE, configuration);
281
    }
282
  }
283

284
  if (!NODE_IS_DU(rrc->node_type)) {
285
    carrier->SIB23 = (uint8_t *) malloc16(64);
286
    AssertFatal(carrier->SIB23!=NULL,"cannot allocate memory for SIB");
287
    carrier->sizeof_SIB23 = do_SIB23(ctxt_pP->module_id,
288 289 290 291
                                     CC_id,
                                     FALSE,
                                     configuration
                                    );
292
    LOG_I(RRC,"do_SIB23, size %d \n ", carrier->sizeof_SIB23);
293
    AssertFatal(carrier->sizeof_SIB23 != 255,"FATAL, RC.rrc[mod].carrier[CC_id].sizeof_SIB23 == 255");
294 295 296 297 298 299 300 301
    carrier->sizeof_SIB23_BR = 0;

    if (configuration->schedulingInfoSIB1_BR_r13[CC_id]>0) {
      carrier->SIB23_BR = (uint8_t *) malloc16(64);
      AssertFatal(carrier->SIB23_BR!=NULL,"cannot allocate memory for SIB");
      carrier->sizeof_SIB23_BR = do_SIB23(ctxt_pP->module_id, CC_id, TRUE, configuration);
    }

302
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" SIB2/3 Contents (partial)\n",
303
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
304
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.n_SB = %ld\n",
305 306
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
          carrier->sib2->radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.n_SB);
307
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.hoppingMode = %ld\n",
308 309
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
          carrier->sib2->radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.hoppingMode);
310
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.pusch_HoppingOffset = %ld\n",
311 312
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
          carrier->sib2->radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.pusch_HoppingOffset);
313
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.enable64QAM = %d\n",
314 315
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
          (int)carrier->sib2->radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.enable64QAM);
316
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.groupHoppingEnabled = %d\n",
317 318
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
          (int)carrier->sib2->radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.groupHoppingEnabled);
319
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.groupAssignmentPUSCH = %ld\n",
320 321
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
          carrier->sib2->radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH);
322
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.sequenceHoppingEnabled = %d\n",
323 324
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
          (int)carrier->sib2->radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled);
325
    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.cyclicShift  = %ld\n",
326 327
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
          carrier->sib2->radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.cyclicShift);
328

329 330
    if (carrier->MBMS_flag > 0) {
      for (i = 0; i < carrier->sib2->mbsfn_SubframeConfigList->list.count; i++) {
331 332
        // SIB 2
        //   LOG_D(RRC, "[eNB %d] mbsfn_SubframeConfigList.list.count = %ld\n", enb_mod_idP, RC.rrc[enb_mod_idP].sib2->mbsfn_SubframeConfigList->list.count);
333 334 335 336 337 338 339 340 341 342 343 344 345
        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" SIB13 contents for MBSFN subframe allocation %d/%d(partial)\n",
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
              i,
              carrier->sib2->mbsfn_SubframeConfigList->list.count);
        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" mbsfn_Subframe_pattern is  = %x\n",
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
              carrier->sib2->mbsfn_SubframeConfigList->list.array[i]->subframeAllocation.choice.oneFrame.buf[0] >> 0);
        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" radioframe_allocation_period  = %ld (just index number, not the real value)\n",
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
              carrier->sib2->mbsfn_SubframeConfigList->list.array[i]->radioframeAllocationPeriod);   // need to display the real value, using array of char (like in dumping SIB2)
        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" radioframe_allocation_offset  = %ld\n",
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
              carrier->sib2->mbsfn_SubframeConfigList->list.array[i]->radioframeAllocationOffset);
346
      }
347

348 349
      //   SIB13
      for (i = 0; i < carrier->sib13->mbsfn_AreaInfoList_r9.list.count; i++) {
350 351 352 353 354 355 356 357 358 359
        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" SIB13 contents for MBSFN sync area %d/%d (partial)\n",
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
              i,
              carrier->sib13->mbsfn_AreaInfoList_r9.list.count);
        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" MCCH Repetition Period: %ld (just index number, not real value)\n",
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
              carrier->sib13->mbsfn_AreaInfoList_r9.list.array[i]->mcch_Config_r9.mcch_RepetitionPeriod_r9);
        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" MCCH Offset: %ld\n",
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
              carrier->sib13->mbsfn_AreaInfoList_r9.list.array[i]->mcch_Config_r9.mcch_Offset_r9);
360
      }
361
    } else memset((void *)&RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib13,0,sizeof(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib13));
362

363
    //TTN - SIB 18
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
    if (configuration->SL_configured > 0) {
      for (int j = 0; j < carrier->sib18->commConfig_r12->commRxPool_r12.list.count; j++) {
        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Contents of SIB18 %d/%d \n",
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
              j+1,
              carrier->sib18->commConfig_r12->commRxPool_r12.list.count);
        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 rxPool_sc_CP_Len: %ld \n",
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
              carrier->sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_CP_Len_r12);
        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 sc_Period_r12: %ld \n",
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
              carrier->sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_Period_r12);
        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 data_CP_Len_r12: %ld \n",
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
              carrier->sib18->commConfig_r12->commRxPool_r12.list.array[j]->data_CP_Len_r12);
        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 prb_Num_r12: %ld \n",
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
              carrier->sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_TF_ResourceConfig_r12.prb_Num_r12);
        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 prb_Start_r12: %ld \n",
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
              carrier->sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_TF_ResourceConfig_r12.prb_Start_r12);
        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 prb_End_r12: %ld \n",
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
              carrier->sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_TF_ResourceConfig_r12.prb_End_r12);
        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 offsetIndicator: %ld \n",
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
              carrier->sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_TF_ResourceConfig_r12.offsetIndicator_r12.choice.small_r12);
        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 subframeBitmap_choice_bs_buf: %s \n",
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
              carrier->sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs16_r12.buf);
      }
395

396 397 398 399 400
      //TTN - SIB 19
      for (int j = 0; j < carrier->sib19->discConfig_r12->discRxPool_r12.list.count; j++) {
        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Contents of SIB19 %d/%d \n",
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
              j+1,
401
              carrier->sib19->discConfig_r12->discRxPool_r12.list.count);
402
        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 cp_Len_r12: %ld \n",
403 404
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
              carrier->sib19->discConfig_r12->discRxPool_r12.list.array[j]->cp_Len_r12);
405
        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 discPeriod_r12: %ld \n",
406 407
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
              carrier->sib19->discConfig_r12->discRxPool_r12.list.array[j]->discPeriod_r12);
408
        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 numRetx_r12: %ld \n",
409 410
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
              carrier->sib19->discConfig_r12->discRxPool_r12.list.array[j]->numRetx_r12);
411
        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 numRepetition_r12: %ld \n",
412 413
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
              carrier->sib19->discConfig_r12->discRxPool_r12.list.array[j]->numRepetition_r12);
414
        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 tf_ResourceConfig_r12 prb_Num_r12: %ld \n",
415 416
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
              carrier->sib19->discConfig_r12->discRxPool_r12.list.array[j]->tf_ResourceConfig_r12.prb_Num_r12);
417
        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 tf_ResourceConfig_r12 prb_Start_r12: %ld \n",
418 419
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
              carrier->sib19->discConfig_r12->discRxPool_r12.list.array[j]->tf_ResourceConfig_r12.prb_Start_r12);
420
        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 tf_ResourceConfig_r12 prb_End_r12: %ld \n",
421 422
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
              carrier->sib19->discConfig_r12->discRxPool_r12.list.array[j]->tf_ResourceConfig_r12.prb_End_r12);
423
        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 tf_ResourceConfig_r12 offsetIndicator: %ld \n",
424 425
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
              carrier->sib19->discConfig_r12->discRxPool_r12.list.array[j]->tf_ResourceConfig_r12.offsetIndicator_r12.choice.small_r12);
426
        LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 tf_ResourceConfig_r12 subframeBitmap_choice_bs_buf: %s \n",
427 428
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
              carrier->sib19->discConfig_r12->discRxPool_r12.list.array[j]->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs16_r12.buf);
429
      }
430
    }
431
  }
432

433
  LOG_D(RRC,
Cedric Roux's avatar
Cedric Roux committed
434 435 436
        PROTOCOL_RRC_CTXT_FMT" RRC_UE --- MAC_CONFIG_REQ (SIB1.tdd & SIB2 params) ---> MAC_UE\n",
        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));

437
  // LTE-M stuff here (take out CU-DU for now)
438
  if (NODE_IS_MONOLITHIC(rrc->node_type)) {
439
    if ((carrier->mib.message.schedulingInfoSIB1_BR_r13>0) &&
440
        (carrier->sib1_BR!=NULL)) {
441
      AssertFatal(carrier->sib1_BR->nonCriticalExtension!=NULL,
442
                  "sib2_br->nonCriticalExtension is null (v8.9)\n");
443
      AssertFatal(carrier->sib1_BR->nonCriticalExtension->nonCriticalExtension!=NULL,
444
                  "sib2_br->nonCriticalExtension is null (v9.2)\n");
445
      AssertFatal(carrier->sib1_BR->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension!=NULL,
446
                  "sib2_br->nonCriticalExtension is null (v11.3)\n");
447
      AssertFatal(carrier->sib1_BR->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension!=NULL,
448
                  "sib2_br->nonCriticalExtension is null (v12.5)\n");
449
      AssertFatal(carrier->sib1_BR->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension!=NULL,
450
                  "sib2_br->nonCriticalExtension is null (v13.10)\n");
451
      sib1_v13ext = carrier->sib1_BR->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension;
islam.galal's avatar
islam.galal committed
452
      // Basic Asserts for CE_level0 PRACH configuration
453 454
      LTE_RadioResourceConfigCommonSIB_t *radioResourceConfigCommon_BR = &carrier[CC_id].sib2_BR->radioResourceConfigCommon;
      struct LTE_PRACH_ConfigSIB_v1310 *ext4_prach=radioResourceConfigCommon_BR->ext4->prach_ConfigCommon_v1310;
455
      LTE_PRACH_ParametersListCE_r13_t   *prach_ParametersListCE_r13 = &ext4_prach->prach_ParametersListCE_r13;
islam.galal's avatar
islam.galal committed
456
      AssertFatal(prach_ParametersListCE_r13->list.count>0,"prach_ParametersListCE_r13 is empty\n");
457
      LTE_PRACH_ParametersCE_r13_t *p = prach_ParametersListCE_r13->list.array[0];
islam.galal's avatar
islam.galal committed
458 459
      AssertFatal(p->prach_StartingSubframe_r13 != NULL, "prach_StartingSubframe_r13 celevel0 is null\n");
      AssertFatal((1<<p->numRepetitionPerPreambleAttempt_r13)<=(2<<*p->prach_StartingSubframe_r13),
460 461 462
                  "prachce0->numReptitionPerPreambleAttempt_r13 %d > prach_StartingSubframe_r13 %d\n",
                  1<<p->numRepetitionPerPreambleAttempt_r13,
                  2<<*p->prach_StartingSubframe_r13);
463 464
    }
  }
465

466
  if (NODE_IS_MONOLITHIC(rrc->node_type)) {
467 468
    LOG_D(RRC, "About to call rrc_mac_config_req_eNB for ngran_eNB\n");
    rrc_mac_config_req_eNB(ctxt_pP->module_id, CC_id,
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490
                           carrier->physCellId,
                           carrier->p_eNB,
                           carrier->Ncp,
                           carrier->sib1->freqBandIndicator,
                           carrier->dl_CarrierFreq,
                           carrier->pbch_repetition,
                           0, // rnti
                           (LTE_BCCH_BCH_Message_t *) &carrier->mib,
                           (LTE_RadioResourceConfigCommonSIB_t *) &carrier->sib2->radioResourceConfigCommon,
                           (LTE_RadioResourceConfigCommonSIB_t *) &carrier->sib2_BR->radioResourceConfigCommon,
                           (struct LTE_PhysicalConfigDedicated *)NULL,
                           (LTE_SCellToAddMod_r10_t *)NULL,
                           (LTE_MeasObjectToAddMod_t **) NULL,
                           (LTE_MAC_MainConfig_t *) NULL, 0,
                           (struct LTE_LogicalChannelConfig *)NULL,
                           (LTE_MeasGapConfig_t *) NULL,
                           carrier->sib1->tdd_Config,
                           NULL,
                           &carrier->sib1->schedulingInfoList,
                           carrier->ul_CarrierFreq,
                           carrier->sib2->freqInfo.ul_Bandwidth,
                           &carrier->sib2->freqInfo.additionalSpectrumEmission,
491
                           (LTE_MBSFN_SubframeConfigList_t *) carrier->sib2->mbsfn_SubframeConfigList,
492
                           carrier->MBMS_flag,
493 494 495 496 497 498 499 500 501 502
                           (LTE_MBSFN_AreaInfoList_r9_t *) & carrier->sib13->mbsfn_AreaInfoList_r9,
                           (LTE_PMCH_InfoList_r9_t *) NULL,
                           sib1_v13ext,
                           RC.rrc[ctxt_pP->module_id]->carrier[CC_id].FeMBMS_flag,
                           (LTE_BCCH_DL_SCH_Message_MBMS_t *) NULL,
                           (LTE_SchedulingInfo_MBMS_r14_t *) NULL,
                           (struct LTE_NonMBSFN_SubframeConfig_r14 *) NULL,
                           (LTE_SystemInformationBlockType1_MBMS_r14_t *) NULL,
                           (LTE_MBSFN_AreaInfoList_r9_t *) NULL
                          );
503
  }
504 505 506

  /* set flag to indicate that cell information is configured. This is required
   * in DU to trigger F1AP_SETUP procedure */
507 508 509
  pthread_mutex_lock(&rrc->cell_info_mutex);
  rrc->cell_info_configured=1;
  pthread_mutex_unlock(&rrc->cell_info_mutex);
510 511
}

winckel's avatar
winckel committed
512
/*------------------------------------------------------------------------------*/
513 514
static void
init_MCCH(
515 516
  module_id_t enb_mod_idP,
  int CC_id
517 518
)
//-----------------------------------------------------------------------------
519 520 521
{
  int                                 sync_area = 0;
  // initialize RRC_eNB_INST MCCH entry
522
  eNB_RRC_INST *rrc = RC.rrc[enb_mod_idP];
523
  RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESSAGE =
Cedric Roux's avatar
Cedric Roux committed
524
    malloc(RC.rrc[enb_mod_idP]->carrier[CC_id].num_mbsfn_sync_area * sizeof(uint8_t *));
525

526 527 528
  for (sync_area = 0; sync_area < RC.rrc[enb_mod_idP]->carrier[CC_id].num_mbsfn_sync_area; sync_area++) {
    RC.rrc[enb_mod_idP]->carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] = 0;
    RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESSAGE[sync_area] = (uint8_t *) malloc16(32);
529
    AssertFatal(RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESSAGE[sync_area] != NULL,
Cedric Roux's avatar
Cedric Roux committed
530
                "[eNB %d]init_MCCH: FATAL, no memory for MCCH MESSAGE allocated \n", enb_mod_idP);
531
    RC.rrc[enb_mod_idP]->carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] = do_MBSFNAreaConfig(enb_mod_idP,
Cedric Roux's avatar
Cedric Roux committed
532 533 534 535
        sync_area,
        (uint8_t *)RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESSAGE[sync_area],
        &RC.rrc[enb_mod_idP]->carrier[CC_id].mcch,
        &RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message);
536
    LOG_I(RRC, "mcch message pointer %p for sync area %d \n",
Cedric Roux's avatar
Cedric Roux committed
537 538
          RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESSAGE[sync_area],
          sync_area);
539 540
    LOG_D(RRC, "[eNB %d] MCCH_MESSAGE  contents for Sync Area %d (partial)\n", enb_mod_idP, sync_area);
    LOG_D(RRC, "[eNB %d] CommonSF_AllocPeriod_r9 %ld\n", enb_mod_idP,
Cedric Roux's avatar
Cedric Roux committed
541
          RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->commonSF_AllocPeriod_r9);
542
    LOG_D(RRC,
Cedric Roux's avatar
Cedric Roux committed
543 544
          "[eNB %d] CommonSF_Alloc_r9.list.count (number of MBSFN Subframe Pattern) %d\n",
          enb_mod_idP, RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->commonSF_Alloc_r9.list.count);
545
    LOG_D(RRC, "[eNB %d] MBSFN Subframe Pattern: %02x (in hex)\n",
Cedric Roux's avatar
Cedric Roux committed
546 547 548
          enb_mod_idP,
          RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->commonSF_Alloc_r9.list.array[0]->subframeAllocation.
          choice.oneFrame.buf[0]);
549
    AssertFatal(RC.rrc[enb_mod_idP]->carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] != 255,
Cedric Roux's avatar
Cedric Roux committed
550
                "RC.rrc[enb_mod_idP]->carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] == 255");
551
    RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESS[sync_area].Active = 1;
552
  }
553

554
  //Set the RC.rrc[enb_mod_idP]->MCCH_MESS.Active to 1 (allow to  transfer MCCH message RRC->MAC in function mac_rrc_data_req)
555 556
  // ??Configure MCCH logical channel
  // call mac_config_req with appropriate structure from ASN.1 description
557 558
  //  LOG_I(RRC, "DUY: serviceID is %d\n",RC.rrc[enb_mod_idP]->mcch_message->pmch_InfoList_r9.list.array[0]->mbms_SessionInfoList_r9.list.array[0]->tmgi_r9.serviceId_r9.buf[2]);
  //  LOG_I(RRC, "DUY: session ID is %d\n",RC.rrc[enb_mod_idP]->mcch_message->pmch_InfoList_r9.list.array[0]->mbms_SessionInfoList_r9.list.array[0]->sessionId_r9->buf[0]);
559
  if (NODE_IS_MONOLITHIC(rrc->node_type)) {
560
    rrc_mac_config_req_eNB(enb_mod_idP, CC_id,
561
                           0,0,0,0,0, 0, 0,//rnti
562 563 564 565 566
                           (LTE_BCCH_BCH_Message_t *)NULL,
                           (LTE_RadioResourceConfigCommonSIB_t *) NULL,
                           (LTE_RadioResourceConfigCommonSIB_t *) NULL,
                           (struct LTE_PhysicalConfigDedicated *)NULL,
                           (LTE_SCellToAddMod_r10_t *)NULL,
567
                           //(struct LTE_PhysicalConfigDedicatedSCell_r10 *)NULL,
568 569 570 571 572 573 574 575
                           (LTE_MeasObjectToAddMod_t **) NULL,
                           (LTE_MAC_MainConfig_t *) NULL,
                           0,
                           (struct LTE_LogicalChannelConfig *)NULL,
                           (LTE_MeasGapConfig_t *) NULL,
                           (LTE_TDD_Config_t *) NULL,
                           (LTE_MobilityControlInfo_t *)NULL,
                           (LTE_SchedulingInfoList_t *) NULL,
576
                           0, NULL, NULL, (LTE_MBSFN_SubframeConfigList_t *) NULL, 0,
577
                           (LTE_MBSFN_AreaInfoList_r9_t *) NULL,
578 579 580 581 582 583 584 585 586
                           (LTE_PMCH_InfoList_r9_t *) & (RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->pmch_InfoList_r9),
                           (LTE_SystemInformationBlockType1_v1310_IEs_t *)NULL,
                           0,
                           (LTE_BCCH_DL_SCH_Message_MBMS_t *) NULL,
                           (LTE_SchedulingInfo_MBMS_r14_t *) NULL,
                           (struct LTE_NonMBSFN_SubframeConfig_r14 *) NULL,
                           (LTE_SystemInformationBlockType1_MBMS_r14_t *) NULL,
                           (LTE_MBSFN_AreaInfoList_r9_t *) NULL
                          );
587
  }
588

589
  //LOG_I(RRC,"DUY: lcid after rrc_mac_config_req is %02d\n",RC.rrc[enb_mod_idP]->mcch_message->pmch_InfoList_r9.list.array[0]->mbms_SessionInfoList_r9.list.array[0]->logicalChannelIdentity_r9);
590 591
}

592
//-----------------------------------------------------------------------------
593
static void init_MBMS(
594
  module_id_t enb_mod_idP,
595
  int         CC_id,
596 597 598
  frame_t frameP
)
//-----------------------------------------------------------------------------
599 600 601
{
  // init the configuration for MTCH
  protocol_ctxt_t               ctxt;
602

603
  if (RC.rrc[enb_mod_idP]->carrier[CC_id].MBMS_flag > 0) {
604
    PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, enb_mod_idP, ENB_FLAG_YES, NOT_A_RNTI, frameP, 0,enb_mod_idP);
605 606 607
    LOG_D(RRC, "[eNB %d] Frame %d : Radio Bearer config request for MBMS\n", enb_mod_idP, frameP);   //check the lcid
    // Configuring PDCP and RLC for MBMS Radio Bearer
    rrc_pdcp_config_asn1_req(&ctxt,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
608 609
                             (LTE_SRB_ToAddModList_t *)NULL,   // LTE_SRB_ToAddModList
                             (LTE_DRB_ToAddModList_t *)NULL,   // LTE_DRB_ToAddModList
610
                             (LTE_DRB_ToReleaseList_t *)NULL,
611 612 613 614
                             0,     // security mode
                             NULL,  // key rrc encryption
                             NULL,  // key rrc integrity
                             NULL   // key encryption
615
                             , &(RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->pmch_InfoList_r9)
616
                             ,NULL);
617

618
    if (!NODE_IS_CU(RC.rrc[enb_mod_idP]->node_type)) {
619
      rrc_rlc_config_asn1_req(&ctxt,
620 621 622
                              NULL, // LTE_SRB_ToAddModList
                              NULL,   // LTE_DRB_ToAddModList
                              NULL,   // DRB_ToReleaseList
623 624
                              &(RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->pmch_InfoList_r9),0, 0
                             );
625
    }
626 627

    //rrc_mac_config_req();
628
  }
629 630
}

631 632 633 634 635 636
//-----------------------------------------------------------------------------
uint8_t
rrc_eNB_get_next_transaction_identifier(
  module_id_t enb_mod_idP
)
//-----------------------------------------------------------------------------
637
{
638 639
  static uint8_t                      rrc_transaction_identifier[NUMBER_OF_eNB_MAX];
  rrc_transaction_identifier[enb_mod_idP] = (rrc_transaction_identifier[enb_mod_idP] + 1) % RRC_TRANSACTION_IDENTIFIER_NUMBER;
640
  LOG_T(RRC,"generated xid is %d\n",rrc_transaction_identifier[enb_mod_idP]);
641 642 643 644 645
  return rrc_transaction_identifier[enb_mod_idP];
}
/*------------------------------------------------------------------------------*/
/* Functions to handle UE index in eNB UE list */

winckel's avatar
winckel committed
646

647 648 649 650 651 652 653 654 655 656 657 658 659 660
////-----------------------------------------------------------------------------
//static module_id_t
//rrc_eNB_get_UE_index(
//                module_id_t enb_mod_idP,
//                uint64_t    UE_identity
//)
////-----------------------------------------------------------------------------
//{
//
//    boolean_t      reg = FALSE;
//    module_id_t    i;
//
//    AssertFatal(enb_mod_idP < NB_eNB_INST, "eNB index invalid (%d/%d)!", enb_mod_idP, NB_eNB_INST);
//
knopp's avatar
knopp committed
661
//    for (i = 0; i < MAX_MOBILES_PER_ENB; i++) {
662
//        if (RC.rrc[enb_mod_idP]->Info.UE_list[i] == UE_identity) {
663 664 665 666 667 668 669 670 671 672 673 674 675
//            // UE_identity already registered
//            reg = TRUE;
//            break;
//        }
//    }
//
//    if (reg == FALSE) {
//        return (UE_MODULE_INVALID);
//    } else
//        return (i);
//}


676
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
677
// return the ue context if there is already an UE with ue_identityP, NULL otherwise
Cedric Roux's avatar
Cedric Roux committed
678
static struct rrc_eNB_ue_context_s *
679
rrc_eNB_ue_context_random_exist(
Cedric Roux's avatar
Cedric Roux committed
680
  const protocol_ctxt_t *const ctxt_pP,
681 682 683 684
  const uint64_t               ue_identityP
)
//-----------------------------------------------------------------------------
{
Cedric Roux's avatar
Cedric Roux committed
685
  struct rrc_eNB_ue_context_s        *ue_context_p = NULL;
686
  RB_FOREACH(ue_context_p, rrc_ue_tree_s, &(RC.rrc[ctxt_pP->module_id]->rrc_ue_head)) {
687
    if (ue_context_p->ue_context.random_ue_identity == ue_identityP)
gauthier's avatar
gauthier committed
688
      return ue_context_p;
689
  }
gauthier's avatar
gauthier committed
690 691 692 693
  return NULL;
}
//-----------------------------------------------------------------------------
// return the ue context if there is already an UE with the same S-TMSI(MMEC+M-TMSI), NULL otherwise
Cedric Roux's avatar
Cedric Roux committed
694
static struct rrc_eNB_ue_context_s *
gauthier's avatar
gauthier committed
695
rrc_eNB_ue_context_stmsi_exist(
Cedric Roux's avatar
Cedric Roux committed
696
  const protocol_ctxt_t *const ctxt_pP,
gauthier's avatar
gauthier committed
697 698 699 700 701
  const mme_code_t             mme_codeP,
  const m_tmsi_t               m_tmsiP
)
//-----------------------------------------------------------------------------
{
Cedric Roux's avatar
Cedric Roux committed
702
  struct rrc_eNB_ue_context_s        *ue_context_p = NULL;
703
  RB_FOREACH(ue_context_p, rrc_ue_tree_s, &(RC.rrc[ctxt_pP->module_id]->rrc_ue_head)) {
704
    LOG_I(RRC,"checking for UE S-TMSI %x, mme %x (%p): rnti %x",
Cedric Roux's avatar
Cedric Roux committed
705 706 707
          m_tmsiP, mme_codeP, ue_context_p,
          ue_context_p->ue_context.rnti);

708
    if (ue_context_p->ue_context.Initialue_identity_s_TMSI.presence == TRUE) {
709
      printf("=> S-TMSI %x, MME %x\n",
Cedric Roux's avatar
Cedric Roux committed
710 711 712
             ue_context_p->ue_context.Initialue_identity_s_TMSI.m_tmsi,
             ue_context_p->ue_context.Initialue_identity_s_TMSI.mme_code);

gauthier's avatar
gauthier committed
713 714 715
      if (ue_context_p->ue_context.Initialue_identity_s_TMSI.m_tmsi == m_tmsiP)
        if (ue_context_p->ue_context.Initialue_identity_s_TMSI.mme_code == mme_codeP)
          return ue_context_p;
Cedric Roux's avatar
Cedric Roux committed
716
    } else
717
      printf("\n");
gauthier's avatar
gauthier committed
718 719
  }
  return NULL;
720 721
}

722 723
//-----------------------------------------------------------------------------
// return a new ue context structure if ue_identityP, ctxt_pP->rnti not found in collection
Cedric Roux's avatar
Cedric Roux committed
724
static struct rrc_eNB_ue_context_s *
725
rrc_eNB_get_next_free_ue_context(
Cedric Roux's avatar
Cedric Roux committed
726
  const protocol_ctxt_t *const ctxt_pP,
727 728 729 730
  const uint64_t               ue_identityP
)
//-----------------------------------------------------------------------------
{
Cedric Roux's avatar
Cedric Roux committed
731
  struct rrc_eNB_ue_context_s        *ue_context_p = NULL;
732
  ue_context_p = rrc_eNB_get_ue_context(
Cedric Roux's avatar
Cedric Roux committed
733 734
                   RC.rrc[ctxt_pP->module_id],
                   ctxt_pP->rnti);
735 736

  if (ue_context_p == NULL) {
737
    ue_context_p = rrc_eNB_allocate_new_UE_context(RC.rrc[ctxt_pP->module_id]);
winckel's avatar
winckel committed
738

739 740 741 742 743
    if (ue_context_p == NULL) {
      LOG_E(RRC,
            PROTOCOL_RRC_CTXT_UE_FMT" Cannot create new UE context, no memory\n",
            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
      return NULL;
744
    }
745

746 747 748
    ue_context_p->ue_id_rnti                    = ctxt_pP->rnti; // here ue_id_rnti is just a key, may be something else
    ue_context_p->ue_context.rnti               = ctxt_pP->rnti; // yes duplicate, 1 may be removed
    ue_context_p->ue_context.random_ue_identity = ue_identityP;
749
    RB_INSERT(rrc_ue_tree_s, &RC.rrc[ctxt_pP->module_id]->rrc_ue_head, ue_context_p);
750 751 752 753 754 755 756 757 758 759 760
    LOG_D(RRC,
          PROTOCOL_RRC_CTXT_UE_FMT" Created new UE context uid %u\n",
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
          ue_context_p->local_uid);
    return ue_context_p;
  } else {
    LOG_E(RRC,
          PROTOCOL_RRC_CTXT_UE_FMT" Cannot create new UE context, already exist\n",
          PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
    return NULL;
  }
761

762
  return(ue_context_p);
winckel's avatar
winckel committed
763 764
}

765 766 767
//-----------------------------------------------------------------------------
void
rrc_eNB_free_mem_UE_context(
Cedric Roux's avatar
Cedric Roux committed
768 769
  const protocol_ctxt_t               *const ctxt_pP,
  struct rrc_eNB_ue_context_s         *const ue_context_pP
770
)
771
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
772
{
773 774
  int i;
  LOG_T(RRC,
Cedric Roux's avatar
Cedric Roux committed
775
        PROTOCOL_RRC_CTXT_UE_FMT" Clearing UE context 0x%p (free internal structs)\n",
776 777
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
        ue_context_pP);
778 779
  ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_LTE_SCellToAddMod_r10, &ue_context_pP->ue_context.sCell_config[0]);
  ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_LTE_SCellToAddMod_r10, &ue_context_pP->ue_context.sCell_config[1]);
780 781

  if (ue_context_pP->ue_context.SRB_configList) {
782
    ASN_STRUCT_FREE(asn_DEF_LTE_SRB_ToAddModList, ue_context_pP->ue_context.SRB_configList);
783 784
    ue_context_pP->ue_context.SRB_configList = NULL;
  }
785

Cedric Roux's avatar
Cedric Roux committed
786 787 788 789 790
  for(i = 0; i < RRC_TRANSACTION_IDENTIFIER_NUMBER; i++) {
    if (ue_context_pP->ue_context.SRB_configList2[i]) {
      free(ue_context_pP->ue_context.SRB_configList2[i]);
      ue_context_pP->ue_context.SRB_configList2[i] = NULL;
    }
791 792
  }

793
  if (ue_context_pP->ue_context.DRB_configList) {
794
    ASN_STRUCT_FREE(asn_DEF_LTE_DRB_ToAddModList, ue_context_pP->ue_context.DRB_configList);
795 796
    ue_context_pP->ue_context.DRB_configList = NULL;
  }
797

Cedric Roux's avatar
Cedric Roux committed
798 799 800 801 802 803 804 805 806 807
  for(i = 0; i < RRC_TRANSACTION_IDENTIFIER_NUMBER; i++) {
    if (ue_context_pP->ue_context.DRB_configList2[i]) {
      free(ue_context_pP->ue_context.DRB_configList2[i]);
      ue_context_pP->ue_context.DRB_configList2[i] = NULL;
    }

    if (ue_context_pP->ue_context.DRB_Release_configList2[i]) {
      free(ue_context_pP->ue_context.DRB_Release_configList2[i]);
      ue_context_pP->ue_context.DRB_Release_configList2[i] = NULL;
    }
808 809
  }

810
  memset(ue_context_pP->ue_context.DRB_active, 0, sizeof(ue_context_pP->ue_context.DRB_active));
811

812
  if (ue_context_pP->ue_context.physicalConfigDedicated) {
813
    ASN_STRUCT_FREE(asn_DEF_LTE_PhysicalConfigDedicated, ue_context_pP->ue_context.physicalConfigDedicated);
814
    ue_context_pP->ue_context.physicalConfigDedicated = NULL;
815 816
  }

817
  if (ue_context_pP->ue_context.sps_Config) {
818
    ASN_STRUCT_FREE(asn_DEF_LTE_SPS_Config, ue_context_pP->ue_context.sps_Config);
819
    ue_context_pP->ue_context.sps_Config = NULL;
820 821
  }

822 823
  for (i=0; i < MAX_MEAS_OBJ; i++) {
    if (ue_context_pP->ue_context.MeasObj[i] != NULL) {
824
      ASN_STRUCT_FREE(asn_DEF_LTE_MeasObjectToAddMod, ue_context_pP->ue_context.MeasObj[i]);
825 826
      ue_context_pP->ue_context.MeasObj[i] = NULL;
    }
827
  }
828

829 830
  for (i=0; i < MAX_MEAS_CONFIG; i++) {
    if (ue_context_pP->ue_context.ReportConfig[i] != NULL) {
831
      ASN_STRUCT_FREE(asn_DEF_LTE_ReportConfigToAddMod, ue_context_pP->ue_context.ReportConfig[i]);
832 833 834
      ue_context_pP->ue_context.ReportConfig[i] = NULL;
    }
  }
835

836
  if (ue_context_pP->ue_context.QuantityConfig) {
837
    ASN_STRUCT_FREE(asn_DEF_LTE_QuantityConfig, ue_context_pP->ue_context.QuantityConfig);
838 839
    ue_context_pP->ue_context.QuantityConfig = NULL;
  }
840

841
  if (ue_context_pP->ue_context.mac_MainConfig) {
842
    ASN_STRUCT_FREE(asn_DEF_LTE_MAC_MainConfig, ue_context_pP->ue_context.mac_MainConfig);
843 844
    ue_context_pP->ue_context.mac_MainConfig = NULL;
  }
845

Cedric Roux's avatar
Cedric Roux committed
846
  /*  if (ue_context_pP->ue_context.measGapConfig) {
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
847
      ASN_STRUCT_FREE(asn_DEF_LTE_MeasGapConfig, ue_context_pP->ue_context.measGapConfig);
Cedric Roux's avatar
Cedric Roux committed
848 849 850
      ue_context_pP->ue_context.measGapConfig = NULL;
    }*/
  if (ue_context_pP->ue_context.handover_info) {
Konstantinos Alexandris's avatar
Konstantinos Alexandris committed
851 852
    /* TODO: be sure free is enough here (check memory leaks) */
    free(ue_context_pP->ue_context.handover_info);
Cedric Roux's avatar
Cedric Roux committed
853 854
    ue_context_pP->ue_context.handover_info = NULL;
  }
855

856 857
  if (ue_context_pP->ue_context.measurement_info) {
    /* TODO: be sure free is enough here (check memory leaks) */
858 859 860 861 862
    if (ue_context_pP->ue_context.measurement_info->events) {
      if (ue_context_pP->ue_context.measurement_info->events->a3_event) {
        free(ue_context_pP->ue_context.measurement_info->events->a3_event);
        ue_context_pP->ue_context.measurement_info->events->a3_event = NULL;
      }
863

864 865 866
      free(ue_context_pP->ue_context.measurement_info->events);
      ue_context_pP->ue_context.measurement_info->events = NULL;
    }
867

868 869 870 871
    free(ue_context_pP->ue_context.measurement_info);
    ue_context_pP->ue_context.measurement_info = NULL;
  }

872 873 874 875 876
  //SRB_INFO                           SI;
  //SRB_INFO                           Srb0;
  //SRB_INFO_TABLE_ENTRY               Srb1;
  //SRB_INFO_TABLE_ENTRY               Srb2;
  if (ue_context_pP->ue_context.measConfig) {
877
    ASN_STRUCT_FREE(asn_DEF_LTE_MeasConfig, ue_context_pP->ue_context.measConfig);
878
    ue_context_pP->ue_context.measConfig = NULL;
879
  }
880

881
  if (ue_context_pP->ue_context.measConfig) {
882
    ASN_STRUCT_FREE(asn_DEF_LTE_MeasConfig, ue_context_pP->ue_context.measConfig);
883
    ue_context_pP->ue_context.measConfig = NULL;
884
  }
885

886
#if 0
887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906
  //HANDOVER_INFO                     *handover_info;
  //uint8_t kenb[32];
  //e_SecurityAlgorithmConfig__cipheringAlgorithm     ciphering_algorithm;
  //e_SecurityAlgorithmConfig__integrityProtAlgorithm integrity_algorithm;
  //uint8_t                            Status;
  //rnti_t                             rnti;
  //uint64_t                           random_ue_identity;
#if defined(ENABLE_ITTI)
  //UE_S_TMSI                          Initialue_identity_s_TMSI;
  //EstablishmentCause_t               establishment_cause;
  //ReestablishmentCause_t             reestablishment_cause;
  //uint16_t                           ue_initial_id;
  //uint32_t                           eNB_ue_s1ap_id :24;
  //security_capabilities_t            security_capabilities;
  //uint8_t                            nb_of_e_rabs;
  //e_rab_param_t                      e_rab[S1AP_MAX_E_RAB];
  //uint32_t                           enb_gtp_teid[S1AP_MAX_E_RAB];
  //transport_layer_addr_t             enb_gtp_addrs[S1AP_MAX_E_RAB];
  //rb_id_t                            enb_gtp_ebi[S1AP_MAX_E_RAB];
#endif
907
#endif
908 909
}

910
//-----------------------------------------------------------------------------
911
/*
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
912
* Should be called when UE context in eNB should be released
913
* or when S1 command UE_CONTEXT_RELEASE_REQ should be sent
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
914
*/