rrc_eNB.c 451 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
#include "UTIL/OSA/osa_defs.h"
79

80
81
#include "rrc_eNB_S1AP.h"
#include "rrc_eNB_GTPV1U.h"
82

83
#include "pdcp.h"
84
#include "gtpv1u_eNB_task.h"
85

86
#include "intertask_interface.h"
87

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

92
#include "SIMULATION/TOOLS/sim.h" // for taus
93

94

95
96
extern RAN_CONTEXT_t RC;

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

gauthier's avatar
   
gauthier committed
103
extern uint16_t                     two_tier_hexagonal_cellIds[7];
winckel's avatar
RRC:    
winckel committed
104

gauthier's avatar
   
gauthier committed
105
mui_t                               rrc_eNB_mui = 0;
winckel's avatar
RRC:    
winckel committed
106

107
extern uint32_t to_earfcn_DL(int eutra_bandP, uint32_t dl_CarrierFreq, uint32_t bw);
108
109
110
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);
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);
111

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

Cedric Roux's avatar
Cedric Roux committed
122
123
124
125
126
127
  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;
  }
128
129
}

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

189
  if (configuration->schedulingInfoSIB1_BR_r13[CC_id]>0) {
190
    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SIB1_BR = (uint8_t *) malloc16(32);
191
    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
192
193
194
        ,TRUE
        , configuration
                                                                       );
195
  }
196

197
#endif
198
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SIB23 = (uint8_t *) malloc16(64);
199
200
  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(
201
202
        ctxt_pP->module_id,
        CC_id
203
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
204
        ,FALSE
gauthier's avatar
   
gauthier committed
205
#endif
206
207
        , configuration
      );
208
  AssertFatal(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB23 != 255,"FATAL, RC.rrc[mod].carrier[CC_id].sizeof_SIB23 == 255");
209
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
210
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB23_BR = 0;
211

212
  if (configuration->schedulingInfoSIB1_BR_r13[CC_id]>0) {
213
    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SIB23_BR = (uint8_t *) malloc16(64);
214
215
    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(
216
217
218
219
220
          ctxt_pP->module_id,
          CC_id,
          TRUE,
          configuration
        );
221
  }
222

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

260
261
262
263
264
  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
265
266
267
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            i,
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->mbsfn_SubframeConfigList->list.count);
268
      LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" mbsfn_Subframe_pattern is  = %x\n",
Cedric Roux's avatar
Cedric Roux committed
269
270
            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);
271
      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
272
273
            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)
274
      LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" radioframe_allocation_offset  = %ld\n",
Cedric Roux's avatar
Cedric Roux committed
275
276
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->mbsfn_SubframeConfigList->list.array[i]->radioframeAllocationOffset);
277
    }
278

279
280
281
    //   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
282
283
284
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            i,
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib13->mbsfn_AreaInfoList_r9.list.count);
285
      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
286
287
            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);
288
      LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" MCCH Offset: %ld\n",
Cedric Roux's avatar
Cedric Roux committed
289
290
            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);
291
    }
292
  } 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));
293
294

  //TTN - SIB 18
295
296
297
  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",
298
299
300
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            j+1,
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib18->commConfig_r12->commRxPool_r12.list.count);
301
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 rxPool_sc_CP_Len: %ld \n",
302
303
            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);
304
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 sc_Period_r12: %ld \n",
305
306
            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);
307
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 data_CP_Len_r12: %ld \n",
308
309
            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);
310
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 prb_Num_r12: %ld \n",
311
312
            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);
313
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 prb_Start_r12: %ld \n",
314
315
            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);
316
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 prb_End_r12: %ld \n",
317
318
            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);
319
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 offsetIndicator: %ld \n",
320
321
            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);
322
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 subframeBitmap_choice_bs_buf: %s \n",
323
324
            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);
325
326
327
328
    }

    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",
329
330
331
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            j+1,
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib19->discConfig_r12->discRxPool_r12.list.count);
332
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 cp_Len_r12: %ld \n",
333
334
            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);
335
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 discPeriod_r12: %ld \n",
336
337
            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);
338
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 numRetx_r12: %ld \n",
339
340
            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);
341
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 numRepetition_r12: %ld \n",
342
343
            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);
344
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 tf_ResourceConfig_r12 prb_Num_r12: %ld \n",
345
346
            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);
347
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 tf_ResourceConfig_r12 prb_Start_r12: %ld \n",
348
349
            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);
350
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 tf_ResourceConfig_r12 prb_End_r12: %ld \n",
351
352
            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);
353
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 tf_ResourceConfig_r12 offsetIndicator: %ld \n",
354
355
            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);
356
      LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 tf_ResourceConfig_r12 subframeBitmap_choice_bs_buf: %s \n",
357
358
            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);
359
    }
360
361
  }

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

  if ((RC.rrc[ctxt_pP->module_id]->carrier[CC_id].mib.message.schedulingInfoSIB1_BR_r13>0) &&
369
      (RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1_BR!=NULL)) {
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
    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);
392
393
  }

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

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

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

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

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

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

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

winckel's avatar
winckel committed
579

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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