rrc_eNB.c 455 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
#include "common/utils/LOG/vcd_signal_dumper.h"
66

67
68
#include "T.h"

69
70
//#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
#include "LTE_MeasResults.h"
71
72
//#endif

Mongazon's avatar
Mongazon committed
73
74
75
76
#include "RRC/NAS/nas_config.h"
#include "RRC/NAS/rb_config.h"
#include "OCG.h"
#include "OCG_extern.h"
77

78
#if defined(ENABLE_SECURITY)
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
79
  #include "UTIL/OSA/osa_defs.h"
80
81
#endif

82
83
#include "rrc_eNB_S1AP.h"
#include "rrc_eNB_GTPV1U.h"
84

85
#include "pdcp.h"
86
#include "gtpv1u_eNB_task.h"
87

88
#include "intertask_interface.h"
89

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

94
#include "SIMULATION/TOOLS/sim.h" // for taus
95

96

97
98
extern RAN_CONTEXT_t RC;

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

gauthier's avatar
   
gauthier committed
105
extern uint16_t                     two_tier_hexagonal_cellIds[7];
winckel's avatar
RRC:    
winckel committed
106

gauthier's avatar
   
gauthier committed
107
mui_t                               rrc_eNB_mui = 0;
winckel's avatar
RRC:    
winckel committed
108

109
110
extern uint32_t to_earfcn_DL(int eutra_bandP, uint32_t dl_CarrierFreq, uint32_t bw);

111
112
void
openair_rrc_on(
Cedric Roux's avatar
Cedric Roux committed
113
  const protocol_ctxt_t *const ctxt_pP
114
115
116
117
)
//-----------------------------------------------------------------------------
{
  int            CC_id;
Cedric Roux's avatar
Cedric Roux committed
118
119
  LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" ENB:OPENAIR RRC IN....\n",
        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
120

Cedric Roux's avatar
Cedric Roux committed
121
122
123
124
125
126
  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;
    rrc_config_buffer (&RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0, CCCH, 1);
    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Active = 1;
  }
127
128
}

129
130
131
//-----------------------------------------------------------------------------
static void
init_SI(
132
  const protocol_ctxt_t *const ctxt_pP,
133
  const int              CC_id,
134
  RrcConfigurationReq *configuration
135
)
136
//-----------------------------------------------------------------------------
137
{
138
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
139
140
  int                                 i;
#endif
141
142
#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 1, 0))
  LTE_SystemInformationBlockType1_v1310_IEs_t *sib1_v13ext=(LTE_SystemInformationBlockType1_v1310_IEs_t *)NULL;
143
#endif
Cedric Roux's avatar
Cedric Roux committed
144
  LOG_D(RRC,"%s()\n\n\n\n",__FUNCTION__);
Cedric Roux's avatar
Cedric Roux committed
145
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].MIB = (uint8_t *) malloc16(4);
146
147
148
149
150
151
  // copy basic parameters
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].physCellId      = configuration->Nid_cell[CC_id];
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].p_eNB           = configuration->nb_antenna_ports[CC_id];
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Ncp             = configuration->prefix_type[CC_id];
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].dl_CarrierFreq  = configuration->downlink_frequency[CC_id];
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].ul_CarrierFreq  = configuration->downlink_frequency[CC_id]+ configuration->uplink_frequency_offset[CC_id];
152
153
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].eutra_band      = configuration->eutra_band[CC_id];
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].N_RB_DL         = configuration->N_RB_DL[CC_id];
154
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
155
156
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].pbch_repetition = configuration->pbch_repetition[CC_id];
#endif
157
158
159
160
  LOG_I(RRC, "Configuring MIB (N_RB_DL %d,phich_Resource %d,phich_Duration %d)\n",
        configuration->N_RB_DL[CC_id],
        (int)configuration->radioresourceconfig[CC_id].phich_resource,
        (int)configuration->radioresourceconfig[CC_id].phich_duration);
161
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
162
163
  LOG_I(RRC, "configuration->schedulingInfoSIB1_BR_r13[CC_id] %d\n",(int)configuration->schedulingInfoSIB1_BR_r13[CC_id]);
#endif
164
  do_MIB(&RC.rrc[ctxt_pP->module_id]->carrier[CC_id],
165
166
167
168
         configuration->N_RB_DL[CC_id],
         (int)configuration->radioresourceconfig[CC_id].phich_resource,
         (int)configuration->radioresourceconfig[CC_id].phich_duration,
         0
169
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
170
         ,configuration->schedulingInfoSIB1_BR_r13[CC_id]
171
#endif
172
        );
173
174
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB1 = 0;
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB23 = 0;
Cedric Roux's avatar
Cedric Roux committed
175
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SIB1 = (uint8_t *) malloc16(32);
176
  AssertFatal(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SIB1!=NULL,PROTOCOL_RRC_CTXT_FMT" init_SI: FATAL, no memory for SIB1 allocated\n",
177
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
178
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB1 = do_SIB1(&RC.rrc[ctxt_pP->module_id]->carrier[CC_id],ctxt_pP->module_id,CC_id
179
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
180
      ,FALSE
winckel's avatar
winckel committed
181
#endif
182
183
      , configuration
                                                                  );
184
  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");
185
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
186
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB1_BR = 0;
187

188
  if (configuration->schedulingInfoSIB1_BR_r13[CC_id]>0) {
189
    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SIB1_BR = (uint8_t *) malloc16(32);
190
    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB1_BR = do_SIB1(&RC.rrc[ctxt_pP->module_id]->carrier[CC_id],ctxt_pP->module_id,CC_id
191
192
193
        ,TRUE
        , configuration
                                                                       );
194
  }
195

196
#endif
197
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SIB23 = (uint8_t *) malloc16(64);
198
199
  AssertFatal(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SIB23!=NULL,"cannot allocate memory for SIB");
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB23 = do_SIB23(
200
201
        ctxt_pP->module_id,
        CC_id
202
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
203
        ,FALSE
gauthier's avatar
   
gauthier committed
204
#endif
205
206
        , configuration
      );
207
  AssertFatal(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB23 != 255,"FATAL, RC.rrc[mod].carrier[CC_id].sizeof_SIB23 == 255");
208
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
209
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB23_BR = 0;
210

211
  if (configuration->schedulingInfoSIB1_BR_r13[CC_id]>0) {
212
    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SIB23_BR = (uint8_t *) malloc16(64);
213
214
    AssertFatal(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SIB23_BR!=NULL,"cannot allocate memory for SIB");
    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB23_BR = do_SIB23(
215
216
217
218
219
          ctxt_pP->module_id,
          CC_id,
          TRUE,
          configuration
        );
220
  }
221

222
#endif
223
  LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" SIB2/3 Contents (partial)\n",
Cedric Roux's avatar
Cedric Roux committed
224
        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
225
  LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.n_SB = %ld\n",
Cedric Roux's avatar
Cedric Roux committed
226
227
228
        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
        RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
        pusch_ConfigBasic.n_SB);
229
  LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.hoppingMode = %ld\n",
Cedric Roux's avatar
Cedric Roux committed
230
231
232
        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
        RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
        pusch_ConfigBasic.hoppingMode);
233
  LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.pusch_HoppingOffset = %ld\n",
Cedric Roux's avatar
Cedric Roux committed
234
235
236
        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
        RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
        pusch_ConfigBasic.pusch_HoppingOffset);
237
  LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.enable64QAM = %d\n",
Cedric Roux's avatar
Cedric Roux committed
238
239
240
        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
        (int)RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
        pusch_ConfigBasic.enable64QAM);
241
  LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.groupHoppingEnabled = %d\n",
Cedric Roux's avatar
Cedric Roux committed
242
243
244
        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
        (int)RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
        ul_ReferenceSignalsPUSCH.groupHoppingEnabled);
245
  LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.groupAssignmentPUSCH = %ld\n",
Cedric Roux's avatar
Cedric Roux committed
246
247
248
        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
        RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
        ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH);
249
  LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.sequenceHoppingEnabled = %d\n",
Cedric Roux's avatar
Cedric Roux committed
250
251
252
        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
        (int)RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
        ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled);
253
  LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.cyclicShift  = %ld\n",
254
255
256
        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
        RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
        ul_ReferenceSignalsPUSCH.cyclicShift);
257
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
258

259
260
261
262
263
  if (RC.rrc[ctxt_pP->module_id]->carrier[CC_id].MBMS_flag > 0) {
    for (i = 0; i < RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->mbsfn_SubframeConfigList->list.count; i++) {
      // 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);
      LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" SIB13 contents for MBSFN subframe allocation %d/%d(partial)\n",
Cedric Roux's avatar
Cedric Roux committed
264
265
266
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            i,
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->mbsfn_SubframeConfigList->list.count);
267
      LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" mbsfn_Subframe_pattern is  = %x\n",
Cedric Roux's avatar
Cedric Roux committed
268
269
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->mbsfn_SubframeConfigList->list.array[i]->subframeAllocation.choice.oneFrame.buf[0] >> 0);
270
      LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" radioframe_allocation_period  = %ld (just index number, not the real value)\n",
Cedric Roux's avatar
Cedric Roux committed
271
272
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->mbsfn_SubframeConfigList->list.array[i]->radioframeAllocationPeriod);   // need to display the real value, using array of char (like in dumping SIB2)
273
      LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" radioframe_allocation_offset  = %ld\n",
Cedric Roux's avatar
Cedric Roux committed
274
275
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->mbsfn_SubframeConfigList->list.array[i]->radioframeAllocationOffset);
276
    }
277

278
279
280
    //   SIB13
    for (i = 0; i < RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib13->mbsfn_AreaInfoList_r9.list.count; i++) {
      LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" SIB13 contents for MBSFN sync area %d/%d (partial)\n",
Cedric Roux's avatar
Cedric Roux committed
281
282
283
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            i,
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib13->mbsfn_AreaInfoList_r9.list.count);
284
      LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" MCCH Repetition Period: %ld (just index number, not real value)\n",
Cedric Roux's avatar
Cedric Roux committed
285
286
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib13->mbsfn_AreaInfoList_r9.list.array[i]->mcch_Config_r9.mcch_RepetitionPeriod_r9);
287
      LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" MCCH Offset: %ld\n",
Cedric Roux's avatar
Cedric Roux committed
288
289
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib13->mbsfn_AreaInfoList_r9.list.array[i]->mcch_Config_r9.mcch_Offset_r9);
290
    }
291
  } 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));
292
293

  //TTN - SIB 18
294
295
296
  if (configuration->SL_configured>0) {
    for (int j = 0; j < RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib18->commConfig_r12->commRxPool_r12.list.count; j++) {
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Contents of SIB18 %d/%d \n",
297
298
299
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            j+1,
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib18->commConfig_r12->commRxPool_r12.list.count);
300
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 rxPool_sc_CP_Len: %ld \n",
301
302
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_CP_Len_r12);
303
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 sc_Period_r12: %ld \n",
304
305
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_Period_r12);
306
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 data_CP_Len_r12: %ld \n",
307
308
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib18->commConfig_r12->commRxPool_r12.list.array[j]->data_CP_Len_r12);
309
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 prb_Num_r12: %ld \n",
310
311
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_TF_ResourceConfig_r12.prb_Num_r12);
312
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 prb_Start_r12: %ld \n",
313
314
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_TF_ResourceConfig_r12.prb_Start_r12);
315
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 prb_End_r12: %ld \n",
316
317
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_TF_ResourceConfig_r12.prb_End_r12);
318
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 offsetIndicator: %ld \n",
319
320
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_TF_ResourceConfig_r12.offsetIndicator_r12.choice.small_r12);
321
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 subframeBitmap_choice_bs_buf: %s \n",
322
323
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_TF_ResourceConfig_r12.subframeBitmap_r12.choice.bs16_r12.buf);
324
325
326
327
    }

    for (int j = 0; j < RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib19->discConfig_r12->discRxPool_r12.list.count; j++) {
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Contents of SIB19 %d/%d \n",
328
329
330
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            j+1,
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib19->discConfig_r12->discRxPool_r12.list.count);
331
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 cp_Len_r12: %ld \n",
332
333
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib19->discConfig_r12->discRxPool_r12.list.array[j]->cp_Len_r12);
334
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 discPeriod_r12: %ld \n",
335
336
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib19->discConfig_r12->discRxPool_r12.list.array[j]->discPeriod_r12);
337
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 numRetx_r12: %ld \n",
338
339
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib19->discConfig_r12->discRxPool_r12.list.array[j]->numRetx_r12);
340
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 numRepetition_r12: %ld \n",
341
342
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib19->discConfig_r12->discRxPool_r12.list.array[j]->numRepetition_r12);
343
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 tf_ResourceConfig_r12 prb_Num_r12: %ld \n",
344
345
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib19->discConfig_r12->discRxPool_r12.list.array[j]->tf_ResourceConfig_r12.prb_Num_r12);
346
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 tf_ResourceConfig_r12 prb_Start_r12: %ld \n",
347
348
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib19->discConfig_r12->discRxPool_r12.list.array[j]->tf_ResourceConfig_r12.prb_Start_r12);
349
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 tf_ResourceConfig_r12 prb_End_r12: %ld \n",
350
351
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib19->discConfig_r12->discRxPool_r12.list.array[j]->tf_ResourceConfig_r12.prb_End_r12);
352
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 tf_ResourceConfig_r12 offsetIndicator: %ld \n",
353
354
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib19->discConfig_r12->discRxPool_r12.list.array[j]->tf_ResourceConfig_r12.offsetIndicator_r12.choice.small_r12);
355
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 tf_ResourceConfig_r12 subframeBitmap_choice_bs_buf: %s \n",
356
357
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib19->discConfig_r12->discRxPool_r12.list.array[j]->tf_ResourceConfig_r12.subframeBitmap_r12.choice.bs16_r12.buf);
358
    }
359
360
  }

361
#endif // (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))    
362
  LOG_D(RRC,
Cedric Roux's avatar
Cedric Roux committed
363
364
        PROTOCOL_RRC_CTXT_FMT" RRC_UE --- MAC_CONFIG_REQ (SIB1.tdd & SIB2 params) ---> MAC_UE\n",
        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
365
#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
Cedric Roux's avatar
Cedric Roux committed
366
367

  if ((RC.rrc[ctxt_pP->module_id]->carrier[CC_id].mib.message.schedulingInfoSIB1_BR_r13>0) &&
368
      (RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1_BR!=NULL)) {
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
    AssertFatal(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1_BR->nonCriticalExtension!=NULL,
                "sib2_br->nonCriticalExtension is null (v8.9)\n");
    AssertFatal(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1_BR->nonCriticalExtension->nonCriticalExtension!=NULL,
                "sib2_br->nonCriticalExtension is null (v9.2)\n");
    AssertFatal(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1_BR->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension!=NULL,
                "sib2_br->nonCriticalExtension is null (v11.3)\n");
    AssertFatal(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1_BR->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension!=NULL,
                "sib2_br->nonCriticalExtension is null (v12.5)\n");
    AssertFatal(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1_BR->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension!=NULL,
                "sib2_br->nonCriticalExtension is null (v13.10)\n");
    sib1_v13ext = RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1_BR->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension->nonCriticalExtension;
    // Basic Asserts for CE_level0 PRACH configuration
    LTE_RadioResourceConfigCommonSIB_t *radioResourceConfigCommon_BR = &RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2_BR->radioResourceConfigCommon;
    struct LTE_PRACH_ConfigSIB_v1310 *ext4_prach=radioResourceConfigCommon_BR->ext4->prach_ConfigCommon_v1310;
    LTE_PRACH_ParametersListCE_r13_t   *prach_ParametersListCE_r13 = &ext4_prach->prach_ParametersListCE_r13;
    AssertFatal(prach_ParametersListCE_r13->list.count>0,"prach_ParametersListCE_r13 is empty\n");
    LTE_PRACH_ParametersCE_r13_t *p = prach_ParametersListCE_r13->list.array[0];
    AssertFatal(p->prach_StartingSubframe_r13 != NULL, "prach_StartingSubframe_r13 celevel0 is null\n");
    AssertFatal((1<<p->numRepetitionPerPreambleAttempt_r13)<=(2<<*p->prach_StartingSubframe_r13),
                "prachce0->numReptitionPerPreambleAttempt_r13 %d > prach_StartingSubframe_r13 %d\n",
                1<<p->numRepetitionPerPreambleAttempt_r13,
                2<<*p->prach_StartingSubframe_r13);
391
392
  }

Cedric Roux's avatar
Cedric Roux committed
393
#endif
Cedric Roux's avatar
Cedric Roux committed
394
  LOG_D(RRC, "About to call rrc_mac_config_req_eNB\n");
395
  rrc_mac_config_req_eNB(ctxt_pP->module_id, CC_id,
Cedric Roux's avatar
Cedric Roux committed
396
397
398
399
400
                         RC.rrc[ctxt_pP->module_id]->carrier[CC_id].physCellId,
                         RC.rrc[ctxt_pP->module_id]->carrier[CC_id].p_eNB,
                         RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Ncp,
                         RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1->freqBandIndicator,
                         RC.rrc[ctxt_pP->module_id]->carrier[CC_id].dl_CarrierFreq,
401
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
Cedric Roux's avatar
Cedric Roux committed
402
                         RC.rrc[ctxt_pP->module_id]->carrier[CC_id].pbch_repetition,
403
#endif
Cedric Roux's avatar
Cedric Roux committed
404
                         0, // rnti
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
405
                         (LTE_BCCH_BCH_Message_t *)
Cedric Roux's avatar
Cedric Roux committed
406
                         &RC.rrc[ctxt_pP->module_id]->carrier[CC_id].mib,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
407
                         (LTE_RadioResourceConfigCommonSIB_t *) &
Cedric Roux's avatar
Cedric Roux committed
408
                         RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon,
409
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
410
                         (LTE_RadioResourceConfigCommonSIB_t *) &
Cedric Roux's avatar
Cedric Roux committed
411
                         RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2_BR->radioResourceConfigCommon,
412
#endif
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
413
                         (struct LTE_PhysicalConfigDedicated *)NULL,
414
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
415
416
                         (LTE_SCellToAddMod_r10_t *)NULL,
                         //(struct LTE_PhysicalConfigDedicatedSCell_r10 *)NULL,
Cedric Roux's avatar
Cedric Roux committed
417
#endif
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
418
419
420
421
                         (LTE_MeasObjectToAddMod_t **) NULL,
                         (LTE_MAC_MainConfig_t *) NULL, 0,
                         (struct LTE_LogicalChannelConfig *)NULL,
                         (LTE_MeasGapConfig_t *) NULL,
Cedric Roux's avatar
Cedric Roux committed
422
423
424
425
426
427
                         RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1->tdd_Config,
                         NULL,
                         &RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1->schedulingInfoList,
                         RC.rrc[ctxt_pP->module_id]->carrier[CC_id].ul_CarrierFreq,
                         RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->freqInfo.ul_Bandwidth,
                         &RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->freqInfo.additionalSpectrumEmission,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
428
                         (LTE_MBSFN_SubframeConfigList_t *) RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->mbsfn_SubframeConfigList
429
#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
Cedric Roux's avatar
Cedric Roux committed
430
431
                         ,
                         RC.rrc[ctxt_pP->module_id]->carrier[CC_id].MBMS_flag,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
432
433
                         (LTE_MBSFN_AreaInfoList_r9_t *) & RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib13->mbsfn_AreaInfoList_r9,
                         (LTE_PMCH_InfoList_r9_t *) NULL
434
#endif
435
#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
Cedric Roux's avatar
Cedric Roux committed
436
437
                         ,
                         sib1_v13ext
438
#endif
Cedric Roux's avatar
Cedric Roux committed
439
                        );
440
441
}

442
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
winckel's avatar
winckel committed
443
/*------------------------------------------------------------------------------*/
444
445
static void
init_MCCH(
446
447
  module_id_t enb_mod_idP,
  int CC_id
448
449
)
//-----------------------------------------------------------------------------
450
451
452
{
  int                                 sync_area = 0;
  // initialize RRC_eNB_INST MCCH entry
453
  RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESSAGE =
Cedric Roux's avatar
Cedric Roux committed
454
    malloc(RC.rrc[enb_mod_idP]->carrier[CC_id].num_mbsfn_sync_area * sizeof(uint8_t *));
gauthier's avatar
   
gauthier committed
455

456
457
458
  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);
459
    AssertFatal(RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESSAGE[sync_area] != NULL,
Cedric Roux's avatar
Cedric Roux committed
460
                "[eNB %d]init_MCCH: FATAL, no memory for MCCH MESSAGE allocated \n", enb_mod_idP);
461
    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
462
463
464
465
        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);
466
    LOG_I(RRC, "mcch message pointer %p for sync area %d \n",
Cedric Roux's avatar
Cedric Roux committed
467
468
          RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESSAGE[sync_area],
          sync_area);
469
470
    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
471
          RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->commonSF_AllocPeriod_r9);
472
    LOG_D(RRC,
Cedric Roux's avatar
Cedric Roux committed
473
474
          "[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);
475
    LOG_D(RRC, "[eNB %d] MBSFN Subframe Pattern: %02x (in hex)\n",
Cedric Roux's avatar
Cedric Roux committed
476
477
478
          enb_mod_idP,
          RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->commonSF_Alloc_r9.list.array[0]->subframeAllocation.
          choice.oneFrame.buf[0]);
479
    AssertFatal(RC.rrc[enb_mod_idP]->carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] != 255,
Cedric Roux's avatar
Cedric Roux committed
480
                "RC.rrc[enb_mod_idP]->carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] == 255");
481
    RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESS[sync_area].Active = 1;
482
  }
gauthier's avatar
   
gauthier committed
483

484
  //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)
485
486
  // ??Configure MCCH logical channel
  // call mac_config_req with appropriate structure from ASN.1 description
487
488
489
  //  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]);
  rrc_mac_config_req_eNB(enb_mod_idP, CC_id,
Cedric Roux's avatar
Cedric Roux committed
490
                         0,0,0,0,0,
491
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
Cedric Roux's avatar
Cedric Roux committed
492
                         0,
493
#endif
Cedric Roux's avatar
Cedric Roux committed
494
                         0,//rnti
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
495
496
                         (LTE_BCCH_BCH_Message_t *)NULL,
                         (LTE_RadioResourceConfigCommonSIB_t *) NULL,
497
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
498
                         (LTE_RadioResourceConfigCommonSIB_t *) NULL,
499
#endif
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
500
501
502
503
504
                         (struct LTE_PhysicalConfigDedicated *)NULL,
                         (LTE_SCellToAddMod_r10_t *)NULL,
                         //(struct LTE_PhysicalConfigDedicatedSCell_r10 *)NULL,
                         (LTE_MeasObjectToAddMod_t **) NULL,
                         (LTE_MAC_MainConfig_t *) NULL,
Cedric Roux's avatar
Cedric Roux committed
505
                         0,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
506
507
508
509
510
511
                         (struct LTE_LogicalChannelConfig *)NULL,
                         (LTE_MeasGapConfig_t *) NULL,
                         (LTE_TDD_Config_t *) NULL,
                         (LTE_MobilityControlInfo_t *)NULL,
                         (LTE_SchedulingInfoList_t *) NULL,
                         0, NULL, NULL, (LTE_MBSFN_SubframeConfigList_t *) NULL
Cedric Roux's avatar
Cedric Roux committed
512
513
                         ,
                         0,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
514
515
                         (LTE_MBSFN_AreaInfoList_r9_t *) NULL,
                         (LTE_PMCH_InfoList_r9_t *) & (RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->pmch_InfoList_r9)
516
#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
Cedric Roux's avatar
Cedric Roux committed
517
                         ,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
518
                         (LTE_SystemInformationBlockType1_v1310_IEs_t *)NULL
519
#endif
Cedric Roux's avatar
Cedric Roux committed
520
                        );
521
  //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);
522
523
}

524
//-----------------------------------------------------------------------------
gauthier's avatar
   
gauthier committed
525
static void init_MBMS(
526
  module_id_t enb_mod_idP,
527
  int         CC_id,
528
529
530
  frame_t frameP
)
//-----------------------------------------------------------------------------
531
532
533
{
  // init the configuration for MTCH
  protocol_ctxt_t               ctxt;
gauthier's avatar
   
gauthier committed
534

535
  if (RC.rrc[enb_mod_idP]->carrier[CC_id].MBMS_flag > 0) {
536
    PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, enb_mod_idP, ENB_FLAG_YES, NOT_A_RNTI, frameP, 0,enb_mod_idP);
537
538
539
    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
540
541
                             (LTE_SRB_ToAddModList_t *)NULL,   // LTE_SRB_ToAddModList
                             (LTE_DRB_ToAddModList_t *)NULL,   // LTE_DRB_ToAddModList
542
                             (LTE_DRB_ToReleaseList_t *)NULL,
543
544
545
546
                             0,     // security mode
                             NULL,  // key rrc encryption
                             NULL,  // key rrc integrity
                             NULL   // key encryption
547
                             , &(RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->pmch_InfoList_r9)
548
                             ,NULL);
549
    rrc_rlc_config_asn1_req(&ctxt,
550
551
                            NULL, // LTE_SRB_ToAddModList
                            NULL,   // LTE_DRB_ToAddModList
552
                            NULL,   // DRB_ToReleaseList
553
                            &(RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->pmch_InfoList_r9)
554
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
555
556
                            ,0, 0
#endif
Cedric Roux's avatar
Cedric Roux committed
557
                           );
558
559
    //rrc_mac_config_req();
  }
560
}
561
#endif
562

563
564
565
566
567
568
//-----------------------------------------------------------------------------
uint8_t
rrc_eNB_get_next_transaction_identifier(
  module_id_t enb_mod_idP
)
//-----------------------------------------------------------------------------
569
{
570
571
  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;
572
  LOG_T(RRC,"generated xid is %d\n",rrc_transaction_identifier[enb_mod_idP]);
573
574
575
576
577
  return rrc_transaction_identifier[enb_mod_idP];
}
/*------------------------------------------------------------------------------*/
/* Functions to handle UE index in eNB UE list */

winckel's avatar
winckel committed
578

579
580
581
582
583
584
585
586
587
588
589
590
591
592
////-----------------------------------------------------------------------------
//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
593
//    for (i = 0; i < MAX_MOBILES_PER_ENB; i++) {
594
//        if (RC.rrc[enb_mod_idP]->Info.UE_list[i] == UE_identity) {
595
596
597
598
599
600
601
602
603
604
605
606
607
//            // UE_identity already registered
//            reg = TRUE;
//            break;
//        }
//    }
//
//    if (reg == FALSE) {
//        return (UE_MODULE_INVALID);
//    } else
//        return (i);
//}


608
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
609
// return the ue context if there is already an UE with ue_identityP, NULL otherwise
Cedric Roux's avatar
Cedric Roux committed
610
static struct rrc_eNB_ue_context_s *
611
rrc_eNB_ue_context_random_exist(
Cedric Roux's avatar
Cedric Roux committed
612
  const protocol_ctxt_t *const ctxt_pP,
613
614
615
616
  const uint64_t               ue_identityP
)
//-----------------------------------------------------------------------------
{
Cedric Roux's avatar
Cedric Roux committed
617
  struct rrc_eNB_ue_context_s        *ue_context_p = NULL;
618
  RB_FOREACH(ue_context_p, rrc_ue_tree_s, &(RC.rrc[ctxt_pP->module_id]->rrc_ue_head)) {
619
    if (ue_context_p->ue_context.random_ue_identity == ue_identityP)
gauthier's avatar
gauthier committed
620
      return ue_context_p;
621
  }
gauthier's avatar
gauthier committed
622
623
624
625
  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
626
static struct rrc_eNB_ue_context_s *
gauthier's avatar
gauthier committed
627
rrc_eNB_ue_context_stmsi_exist(
Cedric Roux's avatar
Cedric Roux committed
628
  const protocol_ctxt_t *const ctxt_pP,
gauthier's avatar
gauthier committed
629
630
631
632
633
  const mme_code_t             mme_codeP,
  const m_tmsi_t               m_tmsiP
)
//-----------------------------------------------------------------------------
{
Cedric Roux's avatar
Cedric Roux committed
634
  struct rrc_eNB_ue_context_s        *ue_context_p = NULL;
635
  RB_FOREACH(ue_context_p, rrc_ue_tree_s, &(RC.rrc[ctxt_pP->module_id]->rrc_ue_head)) {
Florian Kaltenberger's avatar
Florian Kaltenberger committed
636
    LOG_I(RRC,"checking for UE S-TMSI %x, mme %x (%p): rnti %x",
Cedric Roux's avatar
Cedric Roux committed
637
638
639
          m_tmsiP, mme_codeP, ue_context_p,
          ue_context_p->ue_context.rnti);

Florian Kaltenberger's avatar
Florian Kaltenberger committed
640
    if (ue_context_p->ue_context.Initialue_identity_s_TMSI.presence == TRUE) {
641
      printf("=> S-TMSI %x, MME %x\n",
Cedric Roux's avatar
Cedric Roux committed
642
643
644
             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
645
646
647
      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
648
    } else
Florian Kaltenberger's avatar
Florian Kaltenberger committed
649
      printf("\n");
gauthier's avatar
gauthier committed
650
651
  }
  return NULL;
652
653
}

654
655
//-----------------------------------------------------------------------------
// return a new ue context structure if ue_identityP, ctxt_pP->rnti not found in collection
Cedric Roux's avatar
Cedric Roux committed
656
static struct rrc_eNB_ue_context_s *
657
rrc_eNB_get_next_free_ue_context(
Cedric Roux's avatar
Cedric Roux committed
658
  const protocol_ctxt_t *const ctxt_pP,
659
660
661
662
  const uint64_t               ue_identityP
)
//-----------------------------------------------------------------------------
{
Cedric Roux's avatar
Cedric Roux committed
663
  struct rrc_eNB_ue_context_s        *ue_context_p = NULL;
664
  ue_context_p = rrc_eNB_get_ue_context(
Cedric Roux's avatar
Cedric Roux committed
665
666
                   RC.rrc[ctxt_pP->module_id],
                   ctxt_pP->rnti);
667
668

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

671
672
673
674
675
    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;
676
    }
677

678
679
680
    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;
681
    RB_INSERT(rrc_ue_tree_s, &RC.rrc[ctxt_pP->module_id]->rrc_ue_head, ue_context_p);
682
683
684
685
686
687
688
689
690
691
692
    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;
  }
winckel's avatar
winckel committed
693
694
}

695
696
697
//-----------------------------------------------------------------------------
void
rrc_eNB_free_mem_UE_context(
Cedric Roux's avatar
Cedric Roux committed
698
699
  const protocol_ctxt_t               *const ctxt_pP,
  struct rrc_eNB_ue_context_s         *const ue_context_pP
700
)
701
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
702
{
703
704
  int i;
  LOG_T(RRC,
Cedric Roux's avatar
Cedric Roux committed
705
        PROTOCOL_RRC_CTXT_UE_FMT" Clearing UE context 0x%p (free internal structs)\n",
706
707
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
        ue_context_pP);
708
709
710
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
  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]);
711
712
713
#endif

  if (ue_context_pP->ue_context.SRB_configList) {
714
    ASN_STRUCT_FREE(asn_DEF_LTE_SRB_ToAddModList, ue_context_pP->ue_context.SRB_configList);
715
716
    ue_context_pP->ue_context.SRB_configList = NULL;
  }
717

Cedric Roux's avatar
Cedric Roux committed
718
719
720
721
722
  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;
    }
723
724
  }

725
  if (ue_context_pP->ue_context.DRB_configList) {
726
    ASN_STRUCT_FREE(asn_DEF_LTE_DRB_ToAddModList, ue_context_pP->ue_context.DRB_configList);
727
728
    ue_context_pP->ue_context.DRB_configList = NULL;
  }
729

Cedric Roux's avatar
Cedric Roux committed
730
731
732
733
734
735
736
737
738
739
  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;
    }
740
741
  }

742
  memset(ue_context_pP->ue_context.DRB_active, 0, sizeof(ue_context_pP->ue_context.DRB_active));
743

744
  if (ue_context_pP->ue_context.physicalConfigDedicated) {
745
    ASN_STRUCT_FREE(asn_DEF_LTE_PhysicalConfigDedicated, ue_context_pP->ue_context.physicalConfigDedicated);
746
    ue_context_pP->ue_context.physicalConfigDedicated = NULL;
747
748
  }

749
  if (ue_context_pP->ue_context.sps_Config) {
750
    ASN_STRUCT_FREE(asn_DEF_LTE_SPS_Config, ue_context_pP->ue_context.sps_Config);
751
    ue_context_pP->ue_context.sps_Config = NULL;
752
753
  }

754
755
  for (i=0; i < MAX_MEAS_OBJ; i++) {
    if (ue_context_pP->ue_context.MeasObj[i] != NULL) {
756
      ASN_STRUCT_FREE(asn_DEF_LTE_MeasObjectToAddMod, ue_context_pP->ue_context.MeasObj[i]);
757
758
      ue_context_pP->ue_context.MeasObj[i] = NULL;
    }
759
  }
760

761
762
  for (i=0; i < MAX_MEAS_CONFIG; i++) {
    if (ue_context_pP->ue_context.ReportConfig[i] != NULL) {
763
      ASN_STRUCT_FREE(asn_DEF_LTE_ReportConfigToAddMod, ue_context_pP->ue_context.ReportConfig[i]);
764
765
766
      ue_context_pP->ue_context.ReportConfig[i] = NULL;
    }
  }
767

768
  if (ue_context_pP->ue_context.QuantityConfig) {
769
    ASN_STRUCT_FREE(asn_DEF_LTE_QuantityConfig, ue_context_pP->ue_context.QuantityConfig);
770
771
    ue_context_pP->ue_context.QuantityConfig = NULL;
  }
772

773
  if (ue_context_pP->ue_context.mac_MainConfig) {
774
    ASN_STRUCT_FREE(asn_DEF_LTE_MAC_MainConfig, ue_context_pP->ue_context.mac_MainConfig);
775
776
    ue_context_pP->ue_context.mac_MainConfig = NULL;
  }
777

Cedric Roux's avatar
Cedric Roux committed
778
  /*  if (ue_context_pP->ue_context.measGapConfig) {