rrc_eNB.c 380 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
56
#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"
#include "LTE_HandoverCommand.h"
57
#include "rlc.h"
58
59
60
#include "rrc_eNB_UE_context.h"
#include "platform_types.h"
#include "msc.h"
61
62
63
#include "LTE_SL-CommConfig-r12.h"
#include "LTE_PeriodicBSR-Timer-r12.h"
#include "LTE_RetxBSR-Timer-r12.h"
64
#include "common/utils/LOG/vcd_signal_dumper.h"
65

66
67
#include "T.h"

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

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

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

81
#if defined(ENABLE_USE_MME)
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
82
83
84
85
86
87
  #include "rrc_eNB_S1AP.h"
  #include "rrc_eNB_GTPV1U.h"
  #if defined(ENABLE_ITTI)
  #else
    #include "../../S1AP/s1ap_eNB.h"
  #endif
frtabu's avatar
frtabu committed
88
#else
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
89
  #define EPC_MODE_ENABLED 0
90
91
#endif

92
#include "pdcp.h"
93
#include "gtpv1u_eNB_task.h"
94
95

#if defined(ENABLE_ITTI)
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
96
  #include "intertask_interface.h"
97
98
#endif

99
#if ENABLE_RAL
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
100
  #include "rrc_eNB_ral.h"
gauthier's avatar
gauthier committed
101
102
#endif

103
#include "SIMULATION/TOOLS/sim.h" // for taus
104

105

106
107
extern RAN_CONTEXT_t RC;

108
#ifdef PHY_EMUL
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
109
  extern EMULATION_VARS              *Emul_vars;
110
#endif
gauthier's avatar
   
gauthier committed
111
112
extern eNB_MAC_INST                *eNB_mac_inst;
extern UE_MAC_INST                 *UE_mac_inst;
113
#ifdef BIGPHYSAREA
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
114
  extern void                        *bigphys_malloc(int);
115
116
#endif

gauthier's avatar
   
gauthier committed
117
extern uint16_t                     two_tier_hexagonal_cellIds[7];
winckel's avatar
RRC:    
winckel committed
118

gauthier's avatar
   
gauthier committed
119
mui_t                               rrc_eNB_mui = 0;
winckel's avatar
RRC:    
winckel committed
120

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

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
131
132
133
134
135
136
  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;
  }
137
138
}

139
140
141
//-----------------------------------------------------------------------------
static void
init_SI(
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
142
  const protocol_ctxt_t *const ctxt_pP,
143
  const int              CC_id
winckel's avatar
winckel committed
144
#if defined(ENABLE_ITTI)
145
  ,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
146
  RrcConfigurationReq *configuration
winckel's avatar
winckel committed
147
#endif
148
)
149
//-----------------------------------------------------------------------------
150
{
151
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
152
153
  int                                 i;
#endif
154
155
#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 1, 0))
  LTE_SystemInformationBlockType1_v1310_IEs_t *sib1_v13ext=(LTE_SystemInformationBlockType1_v1310_IEs_t *)NULL;
156
#endif
Cedric Roux's avatar
Cedric Roux committed
157
  LOG_D(RRC,"%s()\n\n\n\n",__FUNCTION__);
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
158
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].MIB = (uint8_t *) malloc16(4);
159
160
161
162
163
164
  // 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];
165
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
166
167
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].pbch_repetition = configuration->pbch_repetition[CC_id];
#endif
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
168
169
170
171
  LOG_I(RRC, "Configuring MIB (N_RB_DL %d,phich_Resource %d,phich_Duration %d)\n",
        (int)configuration->N_RB_DL[CC_id],
        (int)configuration->phich_resource[CC_id],
        (int)configuration->phich_duration[CC_id]);
172
173
  do_MIB(&RC.rrc[ctxt_pP->module_id]->carrier[CC_id],
#ifdef ENABLE_ITTI
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
174
175
176
         configuration->N_RB_DL[CC_id],
         configuration->phich_resource[CC_id],
         configuration->phich_duration[CC_id]
177
#else
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
178
         50,0,0
179
#endif
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
180
         ,0);
181
182
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB1 = 0;
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB23 = 0;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
183
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SIB1 = (uint8_t *) malloc16(32);
184
  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",
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
185
              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
186
  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
winckel's avatar
winckel committed
187
#if defined(ENABLE_ITTI)
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
188
      , configuration
winckel's avatar
winckel committed
189
#endif
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
190
                                                                  );
191
  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");
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
192
  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SIB23 = (uint8_t *) malloc16(64);
193
194
  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(
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
195
196
        ctxt_pP->module_id,
        CC_id
197
#if defined(ENABLE_ITTI)
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
198
        , configuration
gauthier's avatar
   
gauthier committed
199
#endif
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
200
      );
201
202
  AssertFatal(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB23 != 255,"FATAL, RC.rrc[mod].carrier[CC_id].sizeof_SIB23 == 255");
  LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" SIB2/3 Contents (partial)\n",
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
203
        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
204
  LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.n_SB = %ld\n",
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
205
206
207
        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
        RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
        pusch_ConfigBasic.n_SB);
208
  LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.hoppingMode = %ld\n",
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
209
210
211
        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
        RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
        pusch_ConfigBasic.hoppingMode);
212
  LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.pusch_HoppingOffset = %ld\n",
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
213
214
215
        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
        RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
        pusch_ConfigBasic.pusch_HoppingOffset);
216
  LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.enable64QAM = %d\n",
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
217
218
219
        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
        (int)RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
        pusch_ConfigBasic.enable64QAM);
220
  LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.groupHoppingEnabled = %d\n",
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
221
222
223
        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
        (int)RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
        ul_ReferenceSignalsPUSCH.groupHoppingEnabled);
224
  LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.groupAssignmentPUSCH = %ld\n",
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
225
226
227
        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
        RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
        ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH);
228
  LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.sequenceHoppingEnabled = %d\n",
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
229
230
231
        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
        (int)RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
        ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled);
232
  LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.cyclicShift  = %ld\n",
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
233
234
235
        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
        RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
        ul_ReferenceSignalsPUSCH.cyclicShift);
236
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
237

238
239
240
241
242
  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",
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
243
244
245
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            i,
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->mbsfn_SubframeConfigList->list.count);
246
      LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" mbsfn_Subframe_pattern is  = %x\n",
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
247
248
            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);
249
      LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" radioframe_allocation_period  = %ld (just index number, not the real value)\n",
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
250
251
            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)
252
      LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" radioframe_allocation_offset  = %ld\n",
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
253
254
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->mbsfn_SubframeConfigList->list.array[i]->radioframeAllocationOffset);
255
    }
256

257
#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
258

259
260
261
    //   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",
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
262
263
264
            PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
            i,
            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib13->mbsfn_AreaInfoList_r9.list.count);
265
      LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" MCCH Repetition Period: %ld (just index number, not real value)\n",
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
266
267
            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);
268
      LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" MCCH Offset: %ld\n",
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
269
270
            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);
271
    }
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
272

273
#endif
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
274
  } 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));
275
276
277

  //TTN - SIB 18
  for (int j = 0; j < RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib18->commConfig_r12->commRxPool_r12.list.count; j++) {
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
    LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Contents of SIB18 %d/%d \n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
          j+1,
          RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib18->commConfig_r12->commRxPool_r12.list.count);
    LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 rxPool_sc_CP_Len: %ld \n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
          RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_CP_Len_r12);
    LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 sc_Period_r12: %ld \n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
          RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_Period_r12);
    LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 data_CP_Len_r12: %ld \n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
          RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib18->commConfig_r12->commRxPool_r12.list.array[j]->data_CP_Len_r12);
    LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 prb_Num_r12: %ld \n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
          RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_TF_ResourceConfig_r12.prb_Num_r12);
    LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 prb_Start_r12: %ld \n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
          RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_TF_ResourceConfig_r12.prb_Start_r12);
    LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 prb_End_r12: %ld \n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
          RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib18->commConfig_r12->commRxPool_r12.list.array[j]->sc_TF_ResourceConfig_r12.prb_End_r12);
    LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 offsetIndicator: %ld \n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
          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);
    LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB18 subframeBitmap_choice_bs_buf: %s \n",
          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);
306
307
308
309
  }

  //TTN - SIB 19
  for (int j = 0; j < RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib19->discConfig_r12->discRxPool_r12.list.count; j++) {
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
    LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Contents of SIB19 %d/%d \n",
          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
          j+1,
          RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib19->discConfig_r12->discRxPool_r12.list.count);
    LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 cp_Len_r12: %ld \n",
          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);
    LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 discPeriod_r12: %ld \n",
          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);
    LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 numRetx_r12: %ld \n",
          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);
    LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 numRepetition_r12: %ld \n",
          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);
    LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 tf_ResourceConfig_r12 prb_Num_r12: %ld \n",
          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);
    LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 tf_ResourceConfig_r12 prb_Start_r12: %ld \n",
          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);
    LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 tf_ResourceConfig_r12 prb_End_r12: %ld \n",
          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);
    LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 tf_ResourceConfig_r12 offsetIndicator: %ld \n",
          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);
    LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" SIB19 tf_ResourceConfig_r12 subframeBitmap_choice_bs_buf: %s \n",
          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);
341
342
  }

343
#endif
344
  LOG_D(RRC,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
345
346
        PROTOCOL_RRC_CTXT_FMT" RRC_UE --- MAC_CONFIG_REQ (SIB1.tdd & SIB2 params) ---> MAC_UE\n",
        PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
347
#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
348
349

  if ((RC.rrc[ctxt_pP->module_id]->carrier[CC_id].mib.message.schedulingInfoSIB1_BR_r13>0) &&
350
      (RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1_BR!=NULL)) {
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
351
352
353
354
355
356
357
358
359
360
361
    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;
362
363
  }

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
364
#endif
Cedric Roux's avatar
Cedric Roux committed
365
  LOG_D(RRC, "About to call rrc_mac_config_req_eNB\n");
366
  rrc_mac_config_req_eNB(ctxt_pP->module_id, CC_id,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
367
368
369
370
371
                         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,
372
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
373
                         RC.rrc[ctxt_pP->module_id]->carrier[CC_id].pbch_repetition,
374
#endif
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
375
376
377
378
379
                         0, // rnti
                         (LTE_BCCH_BCH_Message_t *)
                         &RC.rrc[ctxt_pP->module_id]->carrier[CC_id].mib,
                         (LTE_RadioResourceConfigCommonSIB_t *) &
                         RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon,
380
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
381
382
                         (LTE_RadioResourceConfigCommonSIB_t *) &
                         RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2_BR->radioResourceConfigCommon,
383
#endif
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
384
                         (struct LTE_PhysicalConfigDedicated *)NULL,
385
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
386
387
388
389
390
391
392
393
394
395
396
397
398
399
                         (LTE_SCellToAddMod_r10_t *)NULL,
                         //(struct LTE_PhysicalConfigDedicatedSCell_r10 *)NULL,
#endif
                         (LTE_MeasObjectToAddMod_t **) NULL,
                         (LTE_MAC_MainConfig_t *) NULL, 0,
                         (struct LTE_LogicalChannelConfig *)NULL,
                         (LTE_MeasGapConfig_t *) NULL,
                         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,
                         (LTE_MBSFN_SubframeConfigList_t *) RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->mbsfn_SubframeConfigList
400
#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
401
402
403
404
                         ,
                         RC.rrc[ctxt_pP->module_id]->carrier[CC_id].MBMS_flag,
                         (LTE_MBSFN_AreaInfoList_r9_t *) & RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib13->mbsfn_AreaInfoList_r9,
                         (LTE_PMCH_InfoList_r9_t *) NULL
405
#endif
406
#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
407
408
                         ,
                         sib1_v13ext
409
#endif
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
410
                        );
411
412
}

413
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
winckel's avatar
winckel committed
414
/*------------------------------------------------------------------------------*/
415
416
static void
init_MCCH(
417
418
  module_id_t enb_mod_idP,
  int CC_id
419
420
)
//-----------------------------------------------------------------------------
421
422
423
{
  int                                 sync_area = 0;
  // initialize RRC_eNB_INST MCCH entry
424
  RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESSAGE =
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
425
    malloc(RC.rrc[enb_mod_idP]->carrier[CC_id].num_mbsfn_sync_area * sizeof(uint8_t *));
gauthier's avatar
   
gauthier committed
426

427
428
429
  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);
430
    AssertFatal(RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESSAGE[sync_area] != NULL,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
431
                "[eNB %d]init_MCCH: FATAL, no memory for MCCH MESSAGE allocated \n", enb_mod_idP);
432
    RC.rrc[enb_mod_idP]->carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] = do_MBSFNAreaConfig(enb_mod_idP,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
433
434
435
436
        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);
437
    LOG_I(RRC, "mcch message pointer %p for sync area %d \n",
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
438
439
          RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESSAGE[sync_area],
          sync_area);
440
441
    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,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
442
          RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->commonSF_AllocPeriod_r9);
443
    LOG_D(RRC,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
444
445
          "[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);
446
    LOG_D(RRC, "[eNB %d] MBSFN Subframe Pattern: %02x (in hex)\n",
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
447
448
449
          enb_mod_idP,
          RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->commonSF_Alloc_r9.list.array[0]->subframeAllocation.
          choice.oneFrame.buf[0]);
450
    AssertFatal(RC.rrc[enb_mod_idP]->carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] != 255,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
451
                "RC.rrc[enb_mod_idP]->carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] == 255");
452
    RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESS[sync_area].Active = 1;
453
  }
gauthier's avatar
   
gauthier committed
454

455
  //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)
456
457
  // ??Configure MCCH logical channel
  // call mac_config_req with appropriate structure from ASN.1 description
458
459
460
  //  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,
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
461
                         0,0,0,0,0,
462
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
463
                         0,
464
#endif
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
465
466
467
                         0,//rnti
                         (LTE_BCCH_BCH_Message_t *)NULL,
                         (LTE_RadioResourceConfigCommonSIB_t *) NULL,
468
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
469
                         (LTE_RadioResourceConfigCommonSIB_t *) NULL,
470
#endif
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
471
                         (struct LTE_PhysicalConfigDedicated *)NULL,
472
#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0))
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
473
474
475
476
477
478
479
480
481
482
483
484
                         (LTE_SCellToAddMod_r10_t *)NULL,
                         //(struct LTE_PhysicalConfigDedicatedSCell_r10 *)NULL,
#endif
                         (LTE_MeasObjectToAddMod_t **) NULL,
                         (LTE_MAC_MainConfig_t *) NULL,
                         0,
                         (struct LTE_LogicalChannelConfig *)NULL,
                         (LTE_MeasGapConfig_t *) NULL,
                         (LTE_TDD_Config_t *) NULL,
                         (LTE_MobilityControlInfo_t *)NULL,
                         (LTE_SchedulingInfoList_t *) NULL,
                         0, NULL, NULL, (LTE_MBSFN_SubframeConfigList_t *) NULL
485
#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
486
487
488
489
                         ,
                         0,
                         (LTE_MBSFN_AreaInfoList_r9_t *) NULL,
                         (LTE_PMCH_InfoList_r9_t *) & (RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->pmch_InfoList_r9)
490
#endif
491
#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0))
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
492
493
                         ,
                         (LTE_SystemInformationBlockType1_v1310_IEs_t *)NULL
494
#endif
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
495
                        );
496
  //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);
497
498
}

499
//-----------------------------------------------------------------------------
gauthier's avatar
   
gauthier committed
500
static void init_MBMS(
501
  module_id_t enb_mod_idP,
502
  int         CC_id,
503
504
505
  frame_t frameP
)
//-----------------------------------------------------------------------------
506
507
508
{
  // init the configuration for MTCH
  protocol_ctxt_t               ctxt;
gauthier's avatar
   
gauthier committed
509

510
  if (RC.rrc[enb_mod_idP]->carrier[CC_id].MBMS_flag > 0) {
511
    PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, enb_mod_idP, ENB_FLAG_YES, NOT_A_RNTI, frameP, 0,enb_mod_idP);
512
513
514
    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
515
516
                             (LTE_SRB_ToAddModList_t *)NULL,   // LTE_SRB_ToAddModList
                             (LTE_DRB_ToAddModList_t *)NULL,   // LTE_DRB_ToAddModList
517
                             (LTE_DRB_ToReleaseList_t *)NULL,
518
519
520
521
                             0,     // security mode
                             NULL,  // key rrc encryption
                             NULL,  // key rrc integrity
                             NULL   // key encryption
522
#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
523
                             , &(RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->pmch_InfoList_r9)
524
#endif
525
                             ,NULL);
526
    rrc_rlc_config_asn1_req(&ctxt,
527
528
                            NULL, // LTE_SRB_ToAddModList
                            NULL,   // LTE_DRB_ToAddModList
529
                            NULL,   // DRB_ToReleaseList
530
                            &(RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->pmch_InfoList_r9)
531
#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0))
532
533
                            ,0, 0
#endif
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
534
                           );
535
536
    //rrc_mac_config_req();
  }
537
538
539
}
#endif

540
541
542
543
544
545
//-----------------------------------------------------------------------------
uint8_t
rrc_eNB_get_next_transaction_identifier(
  module_id_t enb_mod_idP
)
//-----------------------------------------------------------------------------
546
{
547
548
  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;
549
  LOG_T(RRC,"generated xid is %d\n",rrc_transaction_identifier[enb_mod_idP]);
550
551
552
553
554
  return rrc_transaction_identifier[enb_mod_idP];
}
/*------------------------------------------------------------------------------*/
/* Functions to handle UE index in eNB UE list */

winckel's avatar
winckel committed
555

556
557
558
559
560
561
562
563
564
565
566
567
568
569
////-----------------------------------------------------------------------------
//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
570
//    for (i = 0; i < MAX_MOBILES_PER_ENB; i++) {
571
//        if (RC.rrc[enb_mod_idP]->Info.UE_list[i] == UE_identity) {
572
573
574
575
576
577
578
579
580
581
582
583
584
//            // UE_identity already registered
//            reg = TRUE;
//            break;
//        }
//    }
//
//    if (reg == FALSE) {
//        return (UE_MODULE_INVALID);
//    } else
//        return (i);
//}


585
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
586
// return the ue context if there is already an UE with ue_identityP, NULL otherwise
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
587
static struct rrc_eNB_ue_context_s *
588
rrc_eNB_ue_context_random_exist(
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
589
  const protocol_ctxt_t *const ctxt_pP,
590
591
592
593
  const uint64_t               ue_identityP
)
//-----------------------------------------------------------------------------
{
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
594
  struct rrc_eNB_ue_context_s        *ue_context_p = NULL;
595
  RB_FOREACH(ue_context_p, rrc_ue_tree_s, &(RC.rrc[ctxt_pP->module_id]->rrc_ue_head)) {
596
    if (ue_context_p->ue_context.random_ue_identity == ue_identityP)
gauthier's avatar
gauthier committed
597
      return ue_context_p;
598
  }
gauthier's avatar
gauthier committed
599
600
601
602
  return NULL;
}
//-----------------------------------------------------------------------------
// return the ue context if there is already an UE with the same S-TMSI(MMEC+M-TMSI), NULL otherwise
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
603
static struct rrc_eNB_ue_context_s *
gauthier's avatar
gauthier committed
604
rrc_eNB_ue_context_stmsi_exist(
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
605
  const protocol_ctxt_t *const ctxt_pP,
gauthier's avatar
gauthier committed
606
607
608
609
610
  const mme_code_t             mme_codeP,
  const m_tmsi_t               m_tmsiP
)
//-----------------------------------------------------------------------------
{
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
611
  struct rrc_eNB_ue_context_s        *ue_context_p = NULL;
612
  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
613
    LOG_I(RRC,"checking for UE S-TMSI %x, mme %x (%p): rnti %x",
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
614
615
616
          m_tmsiP, mme_codeP, ue_context_p,
          ue_context_p->ue_context.rnti);

Florian Kaltenberger's avatar
Florian Kaltenberger committed
617
    if (ue_context_p->ue_context.Initialue_identity_s_TMSI.presence == TRUE) {
618
      printf("=> S-TMSI %x, MME %x\n",
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
619
620
621
             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
622
623
624
      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;
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
625
    } else
Florian Kaltenberger's avatar
Florian Kaltenberger committed
626
      printf("\n");
gauthier's avatar
gauthier committed
627
628
  }
  return NULL;
629
630
}

631
632
//-----------------------------------------------------------------------------
// return a new ue context structure if ue_identityP, ctxt_pP->rnti not found in collection
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
633
static struct rrc_eNB_ue_context_s *
634
rrc_eNB_get_next_free_ue_context(
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
635
  const protocol_ctxt_t *const ctxt_pP,
636
637
638
639
  const uint64_t               ue_identityP
)
//-----------------------------------------------------------------------------
{
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
640
  struct rrc_eNB_ue_context_s        *ue_context_p = NULL;
641
  ue_context_p = rrc_eNB_get_ue_context(
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
642
643
                   RC.rrc[ctxt_pP->module_id],
                   ctxt_pP->rnti);
644
645

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

648
649
650
651
652
    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;
653
    }
654

655
656
657
    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;
658
    RB_INSERT(rrc_ue_tree_s, &RC.rrc[ctxt_pP->module_id]->rrc_ue_head, ue_context_p);
659
660
661
662
663
664
665
666
667
668
669
    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
670
671
}

672
673
674
//-----------------------------------------------------------------------------
void
rrc_eNB_free_mem_UE_context(
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
675
676
  const protocol_ctxt_t               *const ctxt_pP,
  struct rrc_eNB_ue_context_s         *const ue_context_pP
677
)
678
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
679
{
680
681
  int i;
  LOG_T(RRC,
Cedric Roux's avatar
Cedric Roux committed
682
        PROTOCOL_RRC_CTXT_UE_FMT" Clearing UE context 0x%p (free internal structs)\n",
683
684
        PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
        ue_context_pP);
685
686
687
#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]);
688
689
690
#endif

  if (ue_context_pP->ue_context.SRB_configList) {
691
    ASN_STRUCT_FREE(asn_DEF_LTE_SRB_ToAddModList, ue_context_pP->ue_context.SRB_configList);
692
693
    ue_context_pP->ue_context.SRB_configList = NULL;
  }
694

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
695
696
697
698
699
  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;
    }
700
701
  }

702
  if (ue_context_pP->ue_context.DRB_configList) {
703
    ASN_STRUCT_FREE(asn_DEF_LTE_DRB_ToAddModList, ue_context_pP->ue_context.DRB_configList);
704
705
    ue_context_pP->ue_context.DRB_configList = NULL;
  }
706

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
707
708
709
710
711
712
713
714
715
716
  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;
    }
717
718
  }

719
  memset(ue_context_pP->ue_context.DRB_active, 0, sizeof(ue_context_pP->ue_context.DRB_active));
720

721
  if (ue_context_pP->ue_context.physicalConfigDedicated) {
722
    ASN_STRUCT_FREE(asn_DEF_LTE_PhysicalConfigDedicated, ue_context_pP->ue_context.physicalConfigDedicated);
723
    ue_context_pP->ue_context.physicalConfigDedicated = NULL;
724
725
  }

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

731
732
  for (i=0; i < MAX_MEAS_OBJ; i++) {
    if (ue_context_pP->ue_context.MeasObj[i] != NULL) {
733
      ASN_STRUCT_FREE(asn_DEF_LTE_MeasObjectToAddMod, ue_context_pP->ue_context.MeasObj[i]);
734
735
      ue_context_pP->ue_context.MeasObj[i] = NULL;
    }
736
  }
737

738
739
  for (i=0; i < MAX_MEAS_CONFIG; i++) {
    if (ue_context_pP->ue_context.ReportConfig[i] != NULL) {
740
      ASN_STRUCT_FREE(asn_DEF_LTE_ReportConfigToAddMod, ue_context_pP->ue_context.ReportConfig[i]);
741
742
743
      ue_context_pP->ue_context.ReportConfig[i] = NULL;
    }
  }
744

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

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

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
755
756
757
758
759
760
761
762
  /*  if (ue_context_pP->ue_context.measGapConfig) {
      ASN_STRUCT_FREE(asn_DEF_LTE_MeasGapConfig, ue_context_pP->ue_context.measGapConfig);
      ue_context_pP->ue_context.measGapConfig = NULL;
    }*/
  if (ue_context_pP->ue_context.handover_info) {
    ASN_STRUCT_FREE(asn_DEF_LTE_Handover, ue_context_pP->ue_context.handover_info);
    ue_context_pP->ue_context.handover_info = NULL;
  }
gauthier's avatar
   
gauthier committed
763

764
765
766
767
768
  //SRB_INFO                           SI;
  //SRB_INFO                           Srb0;
  //SRB_INFO_TABLE_ENTRY               Srb1;
  //SRB_INFO_TABLE_ENTRY               Srb2;
  if (ue_context_pP->ue_context.measConfig) {
769
    ASN_STRUCT_FREE(asn_DEF_LTE_MeasConfig, ue_context_pP->ue_context.measConfig);
770
    ue_context_pP->ue_context.measConfig = NULL;
771
  }
772

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

778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
  //HANDOVER_INFO                     *handover_info;
#if defined(ENABLE_SECURITY)
  //uint8_t kenb[32];
#endif
  //e_SecurityAlgorithmConfig__cipheringAlgorithm     ciphering_algorithm;
  //e_SecurityAlgorithmConfig__integrityProtAlgorithm integrity_algorithm;
  //uint8_t                            Status;
  //rnti_t                             rnti;
  //uint64_t                           random_ue_identity;
#if defined(ENABLE_ITTI)
  //UE_S_TMSI                          Initialue_identity_s_TMSI;
  //EstablishmentCause_t               establishment_cause;
  //ReestablishmentCause_t             reestablishment_cause;
  //uint16_t                           ue_initial_id;
  //uint32_t                           eNB_ue_s1ap_id :24;
  //security_capabilities_t            security_capabilities;
  //uint8_t                            nb_of_e_rabs;
  //e_rab_param_t                      e_rab[S1AP_MAX_E_RAB];
  //uint32_t                           enb_gtp_teid[S1AP_MAX_E_RAB];
  //transport_layer_addr_t             enb_gtp_addrs[S1AP_MAX_E_RAB];
  //rb_id_t                            enb_gtp_ebi[S1AP_MAX_E_RAB];
#endif
800
801
}

802
//-----------------------------------------------------------------------------
803
/*
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
804
* Should be called when UE context in eNB should be released
805
* or when S1 command UE_CONTEXT_RELEASE_REQ should be sent
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
806
*/
807
void
808
809
810
rrc_eNB_free_UE(
  const module_id_t enb_mod_idP,
  const struct rrc_eNB_ue_context_s *const ue_context_pP)
811
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
812
{
813
  rnti_t rnti = ue_context_pP->ue_context.rnti;
814

815
  if (enb_mod_idP >= NB_eNB_INST) {
816
    LOG_E(RRC, "eNB instance invalid (%d/%d) for UE %x!\n",
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
817
818
819
          enb_mod_idP,
          NB_eNB_INST,
          rnti);
820
    return;
821
  }
822

823
824
  if (EPC_MODE_ENABLED) {
    if ((ue_context_pP->ue_context.ul_failure_timer >= 20000) && (mac_eNB_get_rrc_status(enb_mod_idP, rnti) >= RRC_CONNECTED)) {
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
825
826
827
828
      LOG_I(RRC, "[eNB %d] S1AP_UE_CONTEXT_RELEASE_REQ sent for RNTI %x, cause 21, radio connection with ue lost\n",
            enb_mod_idP,
            rnti);
      rrc_eNB_send_S1AP_UE_CONTEXT_RELEASE_REQ(enb_mod_idP, ue_context_pP, S1AP_CAUSE_RADIO_NETWORK, 21);
829
830
831
832
833
834
835
836
      // send cause 21: radio connection with ue lost
      /* From 3GPP 36300v10 p129 : 19.2.2.2.2 S1 UE Context Release Request (eNB triggered)
        * If the E-UTRAN internal reason is a radio link failure detected in the eNB, the eNB shall wait a sufficient time before
        *  triggering the S1 UE Context Release Request procedure in order to allow the UE to perform the NAS recovery
        *  procedure, see TS 23.401 [17].
        */
      return;
    }
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
837

838
839
    // if((ue_context_pP->ue_context.ue_rrc_inactivity_timer >= ue_context_pP->ue_context.ue_rrc_inactivity_timer_thres) &&
    if((ue_context_pP->ue_context.ue_rrc_inactivity_timer >= RC.rrc[enb_mod_idP]->configuration.rrc_inactivity_timer_thres) &&
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
840
841
842
843
844
        (mac_eNB_get_rrc_status(enb_mod_idP, rnti) >= RRC_CONNECTED)) {
      LOG_I(RRC, "[eNB %d] S1AP_UE_CONTEXT_RELEASE_REQ sent for RNTI %x, cause 20, user inactivity\n",
            enb_mod_idP,
            rnti);
      rrc_eNB_send_S1AP_UE_CONTEXT_RELEASE_REQ(enb_mod_idP, ue_context_pP, S1AP_CAUSE_RADIO_NETWORK, 20);
845
846
      // send cause 20: user inactivity
      return;
847
    }
848
  }
849

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
850
851
852
  LOG_W(RRC, "[eNB %d] Removing UE RNTI %x\n",
        enb_mod_idP,
        rnti);
853
854
  // add UE info to freeList
  LOG_I(RRC, "Put UE %x into freeList\n",
Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
855
        rnti);
856
  put_UE_in_freelist(enb_mod_idP, rnti, 1);
857
858
}

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
859
860
861
862
863
864
865
866
void remove_UE_from_freelist(module_id_t mod_id, rnti_t rnti) {
  eNB_MAC_INST                             *eNB_MAC = RC.mac[mod_id];
  pthread_mutex_lock(&lock_ue_freelist);
  UE_free_list_t                           *free_list = &eNB_MAC->UE_free_list;
  free_list->UE_free_ctrl[free_list->head_freelist].rnti = 0;
  free_list->head_freelist = (free_list->head_freelist + 1) % (NUMBER_OF_UE_MAX+1);
  free_list->num_UEs--;
  pthread_mutex_unlock(&lock_ue_freelist);
867
868
}

Louis Adrien Dufrene's avatar
Louis Adrien Dufrene committed
869
870