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

22
/*! \file l2_interface.c
gauthier's avatar
   
gauthier committed
23
24
25
26
27
28
29
 * \brief layer 2 interface, used to support different RRC sublayer
 * \author Raymond Knopp and Navid Nikaein
 * \date 2010-2014
 * \version 1.0
 * \company Eurecom
 * \email: raymond.knopp@eurecom.fr
 */
nikaeinn's avatar
nikaeinn committed
30

gauthier's avatar
gauthier committed
31
#include "platform_types.h"
32
33
34
35
36
37
38
39
//#include "openair_defs.h"
//#include "openair_proto.h"
#include "defs.h"
#include "extern.h"
//#include "mac_lchan_interface.h"
//#include "openair_rrc_utils.h"
//#include "openair_rrc_main.h"
#include "UTIL/LOG/log.h"
40
#include "rrc_eNB_UE_context.h"
41
#include "pdcp.h"
42
#include "msc.h"
43
44
45
46
47
48
49
50

#ifdef PHY_EMUL
#include "SIMULATION/simulation_defs.h"
extern EMULATION_VARS *Emul_vars;
extern eNB_MAC_INST *eNB_mac_inst;
extern UE_MAC_INST *UE_mac_inst;
#endif

51
52
53
54
#if defined(ENABLE_ITTI)
# include "intertask_interface.h"
#endif

55
//#define RRC_DATA_REQ_DEBUG
gauthier's avatar
define    
gauthier committed
56
#define DEBUG_RRC 1
57

gauthier's avatar
gauthier committed
58
mui_t mui=0;
59

60
61
//------------------------------------------------------------------------------
int8_t
62
mac_rrc_data_req(
63
  const module_id_t Mod_idP,
64
  const int         CC_id,
65
66
67
68
69
70
71
72
73
  const frame_t     frameP,
  const rb_id_t     Srb_id,
  const uint8_t     Nb_tb,
  uint8_t*    const buffer_pP,
  const eNB_flag_t  enb_flagP,
  const uint8_t     eNB_index,
  const uint8_t     mbsfn_sync_area
)
//--------------------------------------------------------------------------
74
75
76
{
  SRB_INFO *Srb_info;
  uint8_t Sdu_size=0;
77
78

#ifdef DEBUG_RRC
79
  int i;
80
  LOG_T(RRC,"[eNB %d] mac_rrc_data_req to SRB ID=%d\n",Mod_idP,Srb_id);
81
82
#endif

83
  if( enb_flagP == ENB_FLAG_YES) {
84

85
    if((Srb_id & RAB_OFFSET) == BCCH) {
86
      if(eNB_rrc_inst[Mod_idP].carrier[CC_id].SI.Active==0) {
87
88
        return 0;
      }
89

90
      // All even frames transmit SIB in SF 5
91
      if (eNB_rrc_inst[Mod_idP].carrier[CC_id].sizeof_SIB1 == 255) {
92
        LOG_E(RRC,"[eNB %d] MAC Request for SIB1 and SIB1 not initialized\n",Mod_idP);
93
        mac_xface->macphy_exit("mac_rrc_data_req:  MAC Request for SIB1 and SIB1 not initialized");
94
95
96
      }

      if ((frameP%2) == 0) {
97
98
99
        memcpy(&buffer_pP[0],
               eNB_rrc_inst[Mod_idP].carrier[CC_id].SIB1,
               eNB_rrc_inst[Mod_idP].carrier[CC_id].sizeof_SIB1);
100
101

#if defined(ENABLE_ITTI)
102
103
        {
          MessageDef *message_p;
104
          int sib1_size = eNB_rrc_inst[Mod_idP].carrier[CC_id].sizeof_SIB1;
105
106
107
108
109
110
111
112
113
114
          int sdu_size = sizeof(RRC_MAC_BCCH_DATA_REQ (message_p).sdu);

          if (sib1_size > sdu_size) {
            LOG_E(RRC, "SIB1 SDU larger than BCCH SDU buffer size (%d, %d)", sib1_size, sdu_size);
            sib1_size = sdu_size;
          }

          message_p = itti_alloc_new_message (TASK_RRC_ENB, RRC_MAC_BCCH_DATA_REQ);
          RRC_MAC_BCCH_DATA_REQ (message_p).frame    = frameP;
          RRC_MAC_BCCH_DATA_REQ (message_p).sdu_size = sib1_size;
Cedric Roux's avatar
Cedric Roux committed
115
          memset (RRC_MAC_BCCH_DATA_REQ (message_p).sdu, 0, BCCH_SDU_SIZE);
116
117
118
          memcpy (RRC_MAC_BCCH_DATA_REQ (message_p).sdu,
                  eNB_rrc_inst[Mod_idP].carrier[CC_id].SIB1,
                  sib1_size);
119
120
          RRC_MAC_BCCH_DATA_REQ (message_p).enb_index = eNB_index;

121
          itti_send_msg_to_task (TASK_MAC_ENB, ENB_MODULE_ID_TO_INSTANCE(Mod_idP), message_p);
122
        }
123
124
#endif

125
#ifdef DEBUG_RRC
126
        LOG_T(RRC,"[eNB %d] Frame %d : BCCH request => SIB 1\n",Mod_idP,frameP);
127

128
        for (i=0; i<eNB_rrc_inst[Mod_idP].carrier[CC_id].sizeof_SIB1; i++) {
129
          LOG_T(RRC,"%x.",buffer_pP[i]);
130
        }
131
132

        LOG_T(RRC,"\n");
133
134
#endif

135
        return (eNB_rrc_inst[Mod_idP].carrier[CC_id].sizeof_SIB1);
136
137
      } // All RFN mod 8 transmit SIB2-3 in SF 5
      else if ((frameP%8) == 1) {
138
139
140
        memcpy(&buffer_pP[0],
               eNB_rrc_inst[Mod_idP].carrier[CC_id].SIB23,
               eNB_rrc_inst[Mod_idP].carrier[CC_id].sizeof_SIB23);
141
142

#if defined(ENABLE_ITTI)
143
144
        {
          MessageDef *message_p;
145
          int sib23_size = eNB_rrc_inst[Mod_idP].carrier[CC_id].sizeof_SIB23;
146
147
148
149
150
151
152
153
154
155
          int sdu_size = sizeof(RRC_MAC_BCCH_DATA_REQ (message_p).sdu);

          if (sib23_size > sdu_size) {
            LOG_E(RRC, "SIB23 SDU larger than BCCH SDU buffer size (%d, %d)", sib23_size, sdu_size);
            sib23_size = sdu_size;
          }

          message_p = itti_alloc_new_message (TASK_RRC_ENB, RRC_MAC_BCCH_DATA_REQ);
          RRC_MAC_BCCH_DATA_REQ (message_p).frame = frameP;
          RRC_MAC_BCCH_DATA_REQ (message_p).sdu_size = sib23_size;
Cedric Roux's avatar
Cedric Roux committed
156
          memset (RRC_MAC_BCCH_DATA_REQ (message_p).sdu, 0, BCCH_SDU_SIZE);
157
158
159
          memcpy (RRC_MAC_BCCH_DATA_REQ (message_p).sdu,
                  eNB_rrc_inst[Mod_idP].carrier[CC_id].SIB23,
                  sib23_size);
160
161
          RRC_MAC_BCCH_DATA_REQ (message_p).enb_index = eNB_index;

162
          itti_send_msg_to_task (TASK_MAC_ENB, ENB_MODULE_ID_TO_INSTANCE(Mod_idP), message_p);
163
        }
164
165
#endif

166
#ifdef DEBUG_RRC
167
        LOG_T(RRC,"[eNB %d] Frame %d BCCH request => SIB 2-3\n",Mod_idP,frameP);
168

169
        for (i=0; i<eNB_rrc_inst[Mod_idP].carrier[CC_id].sizeof_SIB23; i++) {
170
          LOG_T(RRC,"%x.",buffer_pP[i]);
171
        }
172
173

        LOG_T(RRC,"\n");
174
#endif
175
        return(eNB_rrc_inst[Mod_idP].carrier[CC_id].sizeof_SIB23);
176
      } else {
177
        return(0);
178
      }
179
    }
180

181
    if( (Srb_id & RAB_OFFSET ) == CCCH) {
182
      LOG_T(RRC,"[eNB %d] Frame %d CCCH request (Srb_id %d)\n",Mod_idP,frameP, Srb_id);
183

184
      if(eNB_rrc_inst[Mod_idP].carrier[CC_id].Srb0.Active==0) {
185
186
187
188
        LOG_E(RRC,"[eNB %d] CCCH Not active\n",Mod_idP);
        return -1;
      }

189
      Srb_info=&eNB_rrc_inst[Mod_idP].carrier[CC_id].Srb0;
190

191
192
193
      // check if data is there for MAC
      if(Srb_info->Tx_buffer.payload_size>0) { //Fill buffer
        LOG_D(RRC,"[eNB %d] CCCH (%p) has %d bytes (dest: %p, src %p)\n",Mod_idP,Srb_info,Srb_info->Tx_buffer.payload_size,buffer_pP,Srb_info->Tx_buffer.Payload);
194
195

#if defined(ENABLE_ITTI)
196
197
198
199
200
201
        {
          MessageDef *message_p;
          int ccch_size = Srb_info->Tx_buffer.payload_size;
          int sdu_size = sizeof(RRC_MAC_CCCH_DATA_REQ (message_p).sdu);

          if (ccch_size > sdu_size) {
Bilel's avatar
Bilel committed
202
            LOG_E(RRC, "SDU larger than CCCH SDU buffer size (%d, %d)", ccch_size, sdu_size);
203
204
205
206
207
208
            ccch_size = sdu_size;
          }

          message_p = itti_alloc_new_message (TASK_RRC_ENB, RRC_MAC_CCCH_DATA_REQ);
          RRC_MAC_CCCH_DATA_REQ (message_p).frame = frameP;
          RRC_MAC_CCCH_DATA_REQ (message_p).sdu_size = ccch_size;
Cedric Roux's avatar
Cedric Roux committed
209
          memset (RRC_MAC_CCCH_DATA_REQ (message_p).sdu, 0, CCCH_SDU_SIZE);
210
211
212
          memcpy (RRC_MAC_CCCH_DATA_REQ (message_p).sdu, Srb_info->Tx_buffer.Payload, ccch_size);
          RRC_MAC_CCCH_DATA_REQ (message_p).enb_index = eNB_index;

213
          itti_send_msg_to_task (TASK_MAC_ENB, ENB_MODULE_ID_TO_INSTANCE(Mod_idP), message_p);
214
        }
215
216
#endif

217
218
219
220
        memcpy(buffer_pP,Srb_info->Tx_buffer.Payload,Srb_info->Tx_buffer.payload_size);
        Sdu_size = Srb_info->Tx_buffer.payload_size;
        Srb_info->Tx_buffer.payload_size=0;
      }
221

222
223
      return (Sdu_size);
    }
224
225

#ifdef Rel10
226
227

    if((Srb_id & RAB_OFFSET) == MCCH) {
228
      if(eNB_rrc_inst[Mod_idP].carrier[CC_id].MCCH_MESS[mbsfn_sync_area].Active==0) {
229
230
        return 0;  // this parameter is set in function init_mcch in rrc_eNB.c
      }
231
232
233
234
235
236

      // this part not needed as it is done in init_mcch
      /*     if (eNB_rrc_inst[Mod_id].sizeof_MCCH_MESSAGE[mbsfn_sync_area] == 255) {
      LOG_E(RRC,"[eNB %d] MAC Request for MCCH MESSAGE and MCCH MESSAGE is not initialized\n",Mod_id);
      mac_xface->macphy_exit("");
      }*/
237
238
239


#if defined(ENABLE_ITTI)
240
241
      {
        MessageDef *message_p;
242
        int mcch_size = eNB_rrc_inst[Mod_idP].carrier[CC_id].sizeof_MCCH_MESSAGE[mbsfn_sync_area];
243
244
245
246
247
248
249
250
251
252
        int sdu_size = sizeof(RRC_MAC_MCCH_DATA_REQ (message_p).sdu);

        if (mcch_size > sdu_size) {
          LOG_E(RRC, "SDU larger than MCCH SDU buffer size (%d, %d)", mcch_size, sdu_size);
          mcch_size = sdu_size;
        }

        message_p = itti_alloc_new_message (TASK_RRC_ENB, RRC_MAC_MCCH_DATA_REQ);
        RRC_MAC_MCCH_DATA_REQ (message_p).frame = frameP;
        RRC_MAC_MCCH_DATA_REQ (message_p).sdu_size = mcch_size;
Cedric Roux's avatar
Cedric Roux committed
253
        memset (RRC_MAC_MCCH_DATA_REQ (message_p).sdu, 0, MCCH_SDU_SIZE);
254
255
256
        memcpy (RRC_MAC_MCCH_DATA_REQ (message_p).sdu,
                eNB_rrc_inst[Mod_idP].carrier[CC_id].MCCH_MESSAGE[mbsfn_sync_area],
                mcch_size);
257
258
259
        RRC_MAC_MCCH_DATA_REQ (message_p).enb_index = eNB_index;
        RRC_MAC_MCCH_DATA_REQ (message_p).mbsfn_sync_area = mbsfn_sync_area;

260
        itti_send_msg_to_task (TASK_MAC_ENB, ENB_MODULE_ID_TO_INSTANCE(Mod_idP), message_p);
261
      }
262
263
#endif

264
      memcpy(&buffer_pP[0],
265
266
             eNB_rrc_inst[Mod_idP].carrier[CC_id].MCCH_MESSAGE[mbsfn_sync_area],
             eNB_rrc_inst[Mod_idP].carrier[CC_id].sizeof_MCCH_MESSAGE[mbsfn_sync_area]);
gauthier's avatar
   
gauthier committed
267

268
#ifdef DEBUG_RRC
269
270
      LOG_D(RRC,"[eNB %d] Frame %d : MCCH request => MCCH_MESSAGE \n",Mod_idP,frameP);

271
      for (i=0; i<eNB_rrc_inst[Mod_idP].carrier[CC_id].sizeof_MCCH_MESSAGE[mbsfn_sync_area]; i++) {
272
        LOG_T(RRC,"%x.",buffer_pP[i]);
273
      }
274
275

      LOG_T(RRC,"\n");
276
#endif
gauthier's avatar
   
gauthier committed
277

278
      return (eNB_rrc_inst[Mod_idP].carrier[CC_id].sizeof_MCCH_MESSAGE[mbsfn_sync_area]);
279
280
281
      //      }
      //else
      //return(0);
282
283
    }

284
#endif //Rel10
285
  } else {  //This is an UE
286

287
288
    LOG_D(RRC,"[UE %d] Frame %d Filling CCCH SRB_ID %d\n",Mod_idP,frameP,Srb_id);
    LOG_D(RRC,"[UE %d] Frame %d buffer_pP status %d,\n",Mod_idP,frameP, UE_rrc_inst[Mod_idP].Srb0[eNB_index].Tx_buffer.payload_size);
289

290
291

    if( (UE_rrc_inst[Mod_idP].Srb0[eNB_index].Tx_buffer.payload_size > 0) ) {
292
293

#if defined(ENABLE_ITTI)
294
295
296
297
      {
        MessageDef *message_p;
        int ccch_size = UE_rrc_inst[Mod_idP].Srb0[eNB_index].Tx_buffer.payload_size;
        int sdu_size = sizeof(RRC_MAC_CCCH_DATA_REQ (message_p).sdu);
298

299
        if (ccch_size > sdu_size) {
Bilel's avatar
Bilel committed
300
          LOG_E(RRC, "SDU larger than CCCH SDU buffer size (%d, %d)", ccch_size, sdu_size);
301
          ccch_size = sdu_size;
gauthier's avatar
   
gauthier committed
302
        }
303
304
305
306

        message_p = itti_alloc_new_message (TASK_RRC_UE, RRC_MAC_CCCH_DATA_REQ);
        RRC_MAC_CCCH_DATA_REQ (message_p).frame = frameP;
        RRC_MAC_CCCH_DATA_REQ (message_p).sdu_size = ccch_size;
Cedric Roux's avatar
Cedric Roux committed
307
        memset (RRC_MAC_CCCH_DATA_REQ (message_p).sdu, 0, CCCH_SDU_SIZE);
308
309
310
        memcpy (RRC_MAC_CCCH_DATA_REQ (message_p).sdu, UE_rrc_inst[Mod_idP].Srb0[eNB_index].Tx_buffer.Payload, ccch_size);
        RRC_MAC_CCCH_DATA_REQ (message_p).enb_index = eNB_index;

311
        itti_send_msg_to_task (TASK_MAC_UE, UE_MODULE_ID_TO_INSTANCE(Mod_idP), message_p);
312
313
314
315
316
317
318
319
320
321
322
323
      }
#endif

      memcpy(&buffer_pP[0],&UE_rrc_inst[Mod_idP].Srb0[eNB_index].Tx_buffer.Payload[0],UE_rrc_inst[Mod_idP].Srb0[eNB_index].Tx_buffer.payload_size);
      uint8_t Ret_size=UE_rrc_inst[Mod_idP].Srb0[eNB_index].Tx_buffer.payload_size;
      //   UE_rrc_inst[Mod_id].Srb0[eNB_index].Tx_buffer.payload_size=0;
      UE_rrc_inst[Mod_idP].Info[eNB_index].T300_active = 1;
      UE_rrc_inst[Mod_idP].Info[eNB_index].T300_cnt = 0;
      //      msg("[RRC][UE %d] Sending rach\n",Mod_id);
      return(Ret_size);
    } else {
      return 0;
324
    }
325
326
327
  }

  return(0);
328
329
}

330
331
//------------------------------------------------------------------------------
int8_t
332
mac_rrc_data_ind(
333
  const module_id_t     module_idP,
334
  const int             CC_id,
335
  const frame_t         frameP,
gauthier's avatar
gauthier committed
336
  const sub_frame_t     sub_frameP,
337
338
339
340
341
342
343
344
345
  const rnti_t          rntiP,
  const rb_id_t         srb_idP,
  const uint8_t*        sduP,
  const sdu_size_t      sdu_lenP,
  const eNB_flag_t      eNB_flagP,
  const mac_enb_index_t eNB_indexP,
  const uint8_t         mbsfn_sync_areaP
)
//--------------------------------------------------------------------------
346
347
{
  SRB_INFO *Srb_info;
348
  protocol_ctxt_t ctxt;
349
  sdu_size_t      sdu_size = 0;
Cedric Roux's avatar
Cedric Roux committed
350
351
352
353

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

354
  /*
355
  int si_window;
356
   */
gauthier's avatar
gauthier committed
357
  PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, module_idP, eNB_flagP, rntiP, frameP, sub_frameP,eNB_indexP);
358

359
360
  if(eNB_flagP == ENB_FLAG_NO) {
    if(srb_idP == BCCH) {
361
      LOG_D(RRC,"[UE %d] Received SDU for BCCH on SRB %d from eNB %d\n",module_idP,srb_idP,eNB_indexP);
362

gauthier's avatar
   
gauthier committed
363
#if defined(ENABLE_ITTI)
364
365
366
367
      {
        MessageDef *message_p;
        int msg_sdu_size = sizeof(RRC_MAC_BCCH_DATA_IND (message_p).sdu);

368
369
        if (sdu_lenP > msg_sdu_size) {
          LOG_E(RRC, "SDU larger than BCCH SDU buffer size (%d, %d)", sdu_lenP, msg_sdu_size);
370
          sdu_size = msg_sdu_size;
371
372
        } else {
          sdu_size = sdu_lenP;
373
374
375
        }

        message_p = itti_alloc_new_message (TASK_MAC_UE, RRC_MAC_BCCH_DATA_IND);
Cedric Roux's avatar
Cedric Roux committed
376
        memset (RRC_MAC_BCCH_DATA_IND (message_p).sdu, 0, BCCH_SDU_SIZE);
gauthier's avatar
gauthier committed
377
378
379
        RRC_MAC_BCCH_DATA_IND (message_p).frame     = frameP;
        RRC_MAC_BCCH_DATA_IND (message_p).sub_frame = sub_frameP;
        RRC_MAC_BCCH_DATA_IND (message_p).sdu_size  = sdu_size;
380
381
        memcpy (RRC_MAC_BCCH_DATA_IND (message_p).sdu, sduP, sdu_size);
        RRC_MAC_BCCH_DATA_IND (message_p).enb_index = eNB_indexP;
gauthier's avatar
gauthier committed
382
383
        RRC_MAC_BCCH_DATA_IND (message_p).rsrq      = 30 /* TODO change phy to report rspq */;
        RRC_MAC_BCCH_DATA_IND (message_p).rsrp      = 45 /* TODO change phy to report rspp */;
384

385
        itti_send_msg_to_task (TASK_RRC_UE, ctxt.instance, message_p);
386
      }
387
#else
Cedric Roux's avatar
Cedric Roux committed
388
      decode_BCCH_DLSCH_Message(&ctxt,eNB_indexP,(uint8_t*)sduP,sdu_lenP, 0, 0);
389
#endif
390
    }
391

392
393
394
395
    if(srb_idP == PCCH) {
      LOG_D(RRC,"[UE %d] Received SDU for PCCH on SRB %d from eNB %d\n",module_idP,srb_idP,eNB_indexP);
      decode_PCCH_DLSCH_Message(&ctxt,eNB_indexP,(uint8_t*)sduP,sdu_lenP);
    }
396
397
398
    if((srb_idP & RAB_OFFSET) == CCCH) {
      if (sdu_lenP>0) {
        LOG_T(RRC,"[UE %d] Received SDU for CCCH on SRB %d from eNB %d\n",module_idP,srb_idP & RAB_OFFSET,eNB_indexP);
399
400

#if defined(ENABLE_ITTI)
401
402
        {
          MessageDef *message_p;
403
          int msg_sdu_size = CCCH_SDU_SIZE;
404

405
          if (sdu_lenP > msg_sdu_size) {
Bilel's avatar
Bilel committed
406
            LOG_E(RRC, "SDU larger than CCCH SDU buffer size (%d, %d)", sdu_size, msg_sdu_size);
407
            sdu_size = msg_sdu_size;
408
409
          } else {
            sdu_size =  sdu_lenP;
410
411
412
          }

          message_p = itti_alloc_new_message (TASK_MAC_UE, RRC_MAC_CCCH_DATA_IND);
413
414
          memset (RRC_MAC_CCCH_DATA_IND (message_p).sdu, 0, CCCH_SDU_SIZE);
          memcpy (RRC_MAC_CCCH_DATA_IND (message_p).sdu, sduP, sdu_size);
gauthier's avatar
gauthier committed
415
416
417
          RRC_MAC_CCCH_DATA_IND (message_p).frame     = frameP;
          RRC_MAC_CCCH_DATA_IND (message_p).sub_frame = sub_frameP;
          RRC_MAC_CCCH_DATA_IND (message_p).sdu_size  = sdu_size;
418
419
420
          RRC_MAC_CCCH_DATA_IND (message_p).enb_index = eNB_indexP;
          RRC_MAC_CCCH_DATA_IND (message_p).rnti      = rntiP;
          itti_send_msg_to_task (TASK_RRC_UE, ctxt.instance, message_p);
421
        }
422
#else
423
424
425
426
        Srb_info = &UE_rrc_inst[module_idP].Srb0[eNB_indexP];
        memcpy(Srb_info->Rx_buffer.Payload,sduP,sdu_lenP);
        Srb_info->Rx_buffer.payload_size = sdu_lenP;
        rrc_ue_decode_ccch(&ctxt, Srb_info, eNB_indexP);
427
#endif
428
429
      }
    }
430

gauthier's avatar
   
gauthier committed
431
#ifdef Rel10
432

433
    if ((srb_idP & RAB_OFFSET) == MCCH) {
434
      LOG_T(RRC,"[UE %d] Frame %d: Received SDU on MBSFN sync area %d for MCCH on SRB %d from eNB %d\n",
435
            module_idP,frameP, mbsfn_sync_areaP, srb_idP & RAB_OFFSET,eNB_indexP);
436

gauthier's avatar
   
gauthier committed
437
#if defined(ENABLE_ITTI)
438
439
440
441
442
443
444
445
446
447
448
      {
        MessageDef *message_p;
        int msg_sdu_size = sizeof(RRC_MAC_MCCH_DATA_IND (message_p).sdu);

        if (sdu_size > msg_sdu_size) {
          LOG_E(RRC, "SDU larger than MCCH SDU buffer size (%d, %d)", sdu_size, msg_sdu_size);
          sdu_size = msg_sdu_size;
        }

        message_p = itti_alloc_new_message (TASK_MAC_UE, RRC_MAC_MCCH_DATA_IND);
        RRC_MAC_MCCH_DATA_IND (message_p).frame           = frameP;
gauthier's avatar
gauthier committed
449
        RRC_MAC_MCCH_DATA_IND (message_p).sub_frame       = sub_frameP;
450
        RRC_MAC_MCCH_DATA_IND (message_p).sdu_size        = sdu_lenP;
Cedric Roux's avatar
Cedric Roux committed
451
        memset (RRC_MAC_MCCH_DATA_IND (message_p).sdu, 0, MCCH_SDU_SIZE);
452
453
454
455
        memcpy (RRC_MAC_MCCH_DATA_IND (message_p).sdu, sduP, sdu_lenP);
        RRC_MAC_MCCH_DATA_IND (message_p).enb_index       = eNB_indexP;
        RRC_MAC_MCCH_DATA_IND (message_p).mbsfn_sync_area = mbsfn_sync_areaP;
        itti_send_msg_to_task (TASK_RRC_UE, ctxt.instance, message_p);
456
      }
457
#else
458
      decode_MCCH_Message(&ctxt, eNB_indexP, sduP, sdu_lenP, mbsfn_sync_areaP);
459
#endif
460
461
    }

462
463
#endif // Rel10

464
  } else { // This is an eNB
465
    Srb_info = &eNB_rrc_inst[module_idP].carrier[CC_id].Srb0;
466
    LOG_T(RRC,"[eNB %d] Received SDU for CCCH on SRB %d\n",module_idP,Srb_info->Srb_id);
467

468
#if defined(ENABLE_ITTI)
469
470
471
472
    {
      MessageDef *message_p;
      int msg_sdu_size = sizeof(RRC_MAC_CCCH_DATA_IND (message_p).sdu);

473
      if (sdu_lenP > msg_sdu_size) {
Bilel's avatar
Bilel committed
474
        LOG_E(RRC, "SDU larger than CCCH SDU buffer size (%d, %d)", sdu_lenP, msg_sdu_size);
475
        sdu_size = msg_sdu_size;
476
477
      } else {
        sdu_size = sdu_lenP;
478
479
480
      }

      message_p = itti_alloc_new_message (TASK_MAC_ENB, RRC_MAC_CCCH_DATA_IND);
gauthier's avatar
gauthier committed
481
482
483
484
      RRC_MAC_CCCH_DATA_IND (message_p).frame     = frameP;
      RRC_MAC_CCCH_DATA_IND (message_p).sub_frame = sub_frameP;
      RRC_MAC_CCCH_DATA_IND (message_p).rnti      = rntiP;
      RRC_MAC_CCCH_DATA_IND (message_p).sdu_size  = sdu_size;
485
      RRC_MAC_CCCH_DATA_IND (message_p).CC_id = CC_id;
Cedric Roux's avatar
Cedric Roux committed
486
      memset (RRC_MAC_CCCH_DATA_IND (message_p).sdu, 0, CCCH_SDU_SIZE);
487
      memcpy (RRC_MAC_CCCH_DATA_IND (message_p).sdu, sduP, sdu_size);
488
      itti_send_msg_to_task (TASK_RRC_ENB, ctxt.instance, message_p);
489
    }
490
#else
491
492

    //    msg("\n******INST %d Srb_info %p, Srb_id=%d****\n\n",Mod_id,Srb_info,Srb_info->Srb_id);
493
494
495
    if (sdu_lenP > 0) {
      memcpy(Srb_info->Rx_buffer.Payload,sduP,sdu_lenP);
      Srb_info->Rx_buffer.payload_size = sdu_lenP;
496
      rrc_eNB_decode_ccch(&ctxt, Srb_info, CC_id);
gauthier's avatar
   
gauthier committed
497
    }
498

499
500
501
502
#endif
  }

  return(0);
503
504
505
506

}

//-------------------------------------------------------------------------------------------//
507
// this function is Not USED anymore
508
void mac_sync_ind(module_id_t Mod_idP,uint8_t Status)
509
510
{
  //-------------------------------------------------------------------------------------------//
511
512
}

513
514
//------------------------------------------------------------------------------
uint8_t
515
rrc_data_req(
516
517
518
519
520
521
522
523
524
  const protocol_ctxt_t*   const ctxt_pP,
  const rb_id_t                  rb_idP,
  const mui_t                    muiP,
  const confirm_t                confirmP,
  const sdu_size_t               sdu_sizeP,
  uint8_t*                 const buffer_pP,
  const pdcp_transmission_mode_t modeP
)
//------------------------------------------------------------------------------
525
{
gauthier's avatar
gauthier committed
526
  MSC_LOG_TX_MESSAGE(
527
528
529
530
531
532
533
534
535
    ctxt_pP->enb_flag ? MSC_RRC_ENB : MSC_RRC_UE,
    ctxt_pP->enb_flag ? MSC_PDCP_ENB : MSC_PDCP_UE,
    buffer_pP,
    sdu_sizeP,
    MSC_AS_TIME_FMT"RRC_DCCH_DATA_REQ UE %x MUI %d size %u",
    MSC_AS_TIME_ARGS(ctxt_pP),
    ctxt_pP->rnti,
    muiP,
    sdu_sizeP);
gauthier's avatar
gauthier committed
536

537
#if defined(ENABLE_ITTI)
538
539
540
541
542
  {
    MessageDef *message_p;
    // Uses a new buffer to avoid issue with PDCP buffer content that could be changed by PDCP (asynchronous message handling).
    uint8_t *message_buffer;

543
544
545
546
547
548
    message_buffer = itti_malloc (
                       ctxt_pP->enb_flag ? TASK_RRC_ENB : TASK_RRC_UE,
                       ctxt_pP->enb_flag ? TASK_PDCP_ENB : TASK_PDCP_UE,
                       sdu_sizeP);

    memcpy (message_buffer, buffer_pP, sdu_sizeP);
549

550
551
552
    message_p = itti_alloc_new_message (ctxt_pP->enb_flag ? TASK_RRC_ENB : TASK_RRC_UE, RRC_DCCH_DATA_REQ);
    RRC_DCCH_DATA_REQ (message_p).frame     = ctxt_pP->frame;
    RRC_DCCH_DATA_REQ (message_p).enb_flag  = ctxt_pP->enb_flag;
553
554
555
    RRC_DCCH_DATA_REQ (message_p).rb_id     = rb_idP;
    RRC_DCCH_DATA_REQ (message_p).muip      = muiP;
    RRC_DCCH_DATA_REQ (message_p).confirmp  = confirmP;
556
    RRC_DCCH_DATA_REQ (message_p).sdu_size  = sdu_sizeP;
557
    RRC_DCCH_DATA_REQ (message_p).sdu_p     = message_buffer;
558
559
560
    RRC_DCCH_DATA_REQ (message_p).mode      = modeP;
    RRC_DCCH_DATA_REQ (message_p).module_id = ctxt_pP->module_id;
    RRC_DCCH_DATA_REQ (message_p).rnti      = ctxt_pP->rnti;
561
    RRC_DCCH_DATA_REQ (message_p).eNB_index = ctxt_pP->eNB_index;
562
563
564
565
566

    itti_send_msg_to_task (
      ctxt_pP->enb_flag ? TASK_PDCP_ENB : TASK_PDCP_UE,
      ctxt_pP->instance,
      message_p);
567
568
569
    return TRUE; // TODO should be changed to a CNF message later, currently RRC lite does not used the returned value anyway.

  }
570
#else
571
572
573
574
575
576
577
578
579
  return pdcp_data_req (
           ctxt_pP,
           SRB_FLAG_YES,
           rb_idP,
           muiP,
           confirmP,
           sdu_sizeP,
           buffer_pP,
           modeP);
580
#endif
581
582
}

583
584
//------------------------------------------------------------------------------
void
585
rrc_data_ind(
586
587
588
589
590
591
  const protocol_ctxt_t* const ctxt_pP,
  const rb_id_t                Srb_id,
  const sdu_size_t             sdu_sizeP,
  const uint8_t*   const       buffer_pP
)
//------------------------------------------------------------------------------
592
593
{
  rb_id_t    DCCH_index = Srb_id;
594

595
  if (ctxt_pP->enb_flag == ENB_FLAG_NO) {
596
    LOG_N(RRC, "[UE %x] Frame %d: received a DCCH %d message on SRB %d with Size %d from eNB %d\n",
597
          ctxt_pP->module_id, ctxt_pP->frame, DCCH_index,Srb_id,sdu_sizeP,  ctxt_pP->eNB_index);
598
  } else {
Cedric Roux's avatar
fix log    
Cedric Roux committed
599
    LOG_N(RRC, "[eNB %d] Frame %d: received a DCCH %d message on SRB %d with Size %d from UE %x\n",
600
601
602
          ctxt_pP->module_id,
          ctxt_pP->frame,
          DCCH_index,
603
          Srb_id,
604
605
          sdu_sizeP,
          ctxt_pP->rnti);
606
  }
607
608

#if defined(ENABLE_ITTI)
609
610
611
612
613
  {
    MessageDef *message_p;
    // Uses a new buffer to avoid issue with PDCP buffer content that could be changed by PDCP (asynchronous message handling).
    uint8_t *message_buffer;

614
    message_buffer = itti_malloc (ctxt_pP->enb_flag ? TASK_PDCP_ENB : TASK_PDCP_UE, ctxt_pP->enb_flag ? TASK_RRC_ENB : TASK_RRC_UE, sdu_sizeP);
615
616
    memcpy (message_buffer, buffer_pP, sdu_sizeP);

617
618
    message_p = itti_alloc_new_message (ctxt_pP->enb_flag ? TASK_PDCP_ENB : TASK_PDCP_UE, RRC_DCCH_DATA_IND);
    RRC_DCCH_DATA_IND (message_p).frame      = ctxt_pP->frame;
619
620
621
    RRC_DCCH_DATA_IND (message_p).dcch_index = DCCH_index;
    RRC_DCCH_DATA_IND (message_p).sdu_size   = sdu_sizeP;
    RRC_DCCH_DATA_IND (message_p).sdu_p      = message_buffer;
622
623
    RRC_DCCH_DATA_IND (message_p).rnti       = ctxt_pP->rnti;
    RRC_DCCH_DATA_IND (message_p).module_id  = ctxt_pP->module_id;
624
625
    RRC_DCCH_DATA_IND (message_p).eNB_index  = ctxt_pP->eNB_index;

626
    itti_send_msg_to_task (ctxt_pP->enb_flag ? TASK_RRC_ENB : TASK_RRC_UE, ctxt_pP->instance, message_p);
627
628
  }
#else
gauthier's avatar
   
gauthier committed
629

630
631
632
633
634
635
  if (ctxt_pP->enb_flag == ENB_FLAG_YES) {
    rrc_eNB_decode_dcch(
      ctxt_pP,
      DCCH_index,
      buffer_pP,
      sdu_sizeP);
636
  } else {
Cedric Roux's avatar
Cedric Roux committed
637
//#warning "LG put 0 to arg4 that is eNB index"
638
639
640
641
642
    rrc_ue_decode_dcch(
      ctxt_pP,
      DCCH_index,
      buffer_pP,
      0);
643
  }
gauthier's avatar
   
gauthier committed
644

645
#endif
646
647
}

648
//-------------------------------------------------------------------------------------------//
649
void rrc_in_sync_ind(module_id_t Mod_idP, frame_t frameP, uint16_t eNB_index)
650
651
{
  //-------------------------------------------------------------------------------------------//
652
#if defined(ENABLE_ITTI)
653
654
  {
    MessageDef *message_p;
655
    //LOG_I(RRC,"sending a message to task_mac_ue\n");
656
657
658
    message_p = itti_alloc_new_message (TASK_MAC_UE, RRC_MAC_IN_SYNC_IND);
    RRC_MAC_IN_SYNC_IND (message_p).frame = frameP;
    RRC_MAC_IN_SYNC_IND (message_p).enb_index = eNB_index;
659

660
    itti_send_msg_to_task (TASK_RRC_UE, UE_MODULE_ID_TO_INSTANCE(Mod_idP), message_p);
661
  }
662
#else
663
664
  UE_rrc_inst[Mod_idP].Info[eNB_index].N310_cnt=0;

665
  if (UE_rrc_inst[Mod_idP].Info[eNB_index].T310_active==1) {
666
    UE_rrc_inst[Mod_idP].Info[eNB_index].N311_cnt++;
667
  }
668

669
#endif
670
671
}

672
//-------------------------------------------------------------------------------------------//
673
void rrc_out_of_sync_ind(module_id_t Mod_idP, frame_t frameP, uint16_t eNB_index)
674
675
{
  //-------------------------------------------------------------------------------------------//
676
677
678
679
680
681
682
683
  if (UE_rrc_inst[Mod_idP].Info[eNB_index].N310_cnt>10)
    LOG_I(RRC,"[UE %d] Frame %d: OUT OF SYNC FROM eNB %d (T310 active %d : T310 %d, N310 %d, N311 %d)\n ",
	  Mod_idP,frameP,eNB_index,
	  UE_rrc_inst[Mod_idP].Info[eNB_index].T300_active,
	  UE_rrc_inst[Mod_idP].Info[eNB_index].T310_cnt,
	  UE_rrc_inst[Mod_idP].Info[eNB_index].N310_cnt,
	  UE_rrc_inst[Mod_idP].Info[eNB_index].N311_cnt);
  
684
#if defined(ENABLE_ITTI)
685
686
  {
    MessageDef *message_p;
687

688
689
690
    message_p = itti_alloc_new_message (TASK_MAC_UE, RRC_MAC_OUT_OF_SYNC_IND);
    RRC_MAC_OUT_OF_SYNC_IND (message_p).frame = frameP;
    RRC_MAC_OUT_OF_SYNC_IND (message_p).enb_index = eNB_index;
691

692
    itti_send_msg_to_task (TASK_RRC_UE, UE_MODULE_ID_TO_INSTANCE(Mod_idP), message_p);
693
  }
694
#else
695
  UE_rrc_inst[Mod_idP].Info[eNB_index].N310_cnt++;
696
#endif
697
698
}

699
700
//------------------------------------------------------------------------------
int
701
mac_eNB_get_rrc_status(
702
703
704
705
  const module_id_t Mod_idP,
  const rnti_t      rntiP
)
//------------------------------------------------------------------------------
706
{
707
708
709
710
711
712
713
  struct rrc_eNB_ue_context_s* ue_context_p = NULL;
  ue_context_p = rrc_eNB_get_ue_context(
                   &eNB_rrc_inst[Mod_idP],
                   rntiP);

  if (ue_context_p != NULL) {
    return(ue_context_p->ue_context.Status);
714
  } else {
715
    return RRC_INACTIVE;
716
  }
717
718
}

719
720
void mac_eNB_rrc_ul_failure(const module_id_t Mod_instP,
			    const int CC_idP,
721
722
			    const frame_t frameP,
			    const sub_frame_t subframeP,
723
724
			    const rnti_t rntiP)
{
725
726
727
728
729
730
  struct rrc_eNB_ue_context_s* ue_context_p = NULL;
  ue_context_p = rrc_eNB_get_ue_context(
                   &eNB_rrc_inst[Mod_instP],
                   rntiP);

  if (ue_context_p != NULL) {
Florian Kaltenberger's avatar
Florian Kaltenberger committed
731
    LOG_I(RRC,"Frame %d, Subframe %d: UE %x UL failure, activating timer\n",frameP,subframeP,rntiP);
732
733
734
    ue_context_p->ue_context.ul_failure_timer=1;
  }
  else {
735
    LOG_W(RRC,"Frame %d, Subframe %d: UL failure: UE %x unknown \n",frameP,subframeP,rntiP);
736
  }
737
  rrc_mac_remove_ue(Mod_instP,rntiP);
738
}
Florian Kaltenberger's avatar
Florian Kaltenberger committed
739
740

void mac_eNB_rrc_ul_in_sync(const module_id_t Mod_instP, 
741
			    const int CC_idP, 
Florian Kaltenberger's avatar
Florian Kaltenberger committed
742
743
			    const frame_t frameP,
			    const sub_frame_t subframeP,
744
745
			    const rnti_t rntiP)
{
746
747
748
749
750
751
  struct rrc_eNB_ue_context_s* ue_context_p = NULL;
  ue_context_p = rrc_eNB_get_ue_context(
                   &eNB_rrc_inst[Mod_instP],
                   rntiP);

  if (ue_context_p != NULL) {
752
753
754
755
756
757
    LOG_I(RRC,"Frame %d, Subframe %d: UE %x to UL in synch\n",
          frameP, subframeP, rntiP);
    ue_context_p->ue_context.ul_failure_timer = 0;
  } else {
    LOG_E(RRC,"Frame %d, Subframe %d: UE %x unknown \n",
          frameP, subframeP, rntiP);
758
  }
Florian Kaltenberger's avatar
Florian Kaltenberger committed
759
}
760
761
//------------------------------------------------------------------------------
int
762
mac_UE_get_rrc_status(
763
764
765
766
767
768
769
770
  const module_id_t Mod_idP,
  const uint8_t     indexP
)
//------------------------------------------------------------------------------
{
  return(UE_rrc_inst[Mod_idP].Info[indexP].State);
}

771
//-------------------------------------------------------------------------------------------//
772
773
774
int mac_ue_ccch_success_ind(module_id_t Mod_idP, uint8_t eNB_index)
{
  //-------------------------------------------------------------------------------------------//
775
#if defined(ENABLE_ITTI)
776
777
  {
    MessageDef *message_p;
778

779
780
    message_p = itti_alloc_new_message (TASK_MAC_UE, RRC_MAC_CCCH_DATA_CNF);
    RRC_MAC_CCCH_DATA_CNF (message_p).enb_index = eNB_index;
781

782
    itti_send_msg_to_task (TASK_RRC_UE, UE_MODULE_ID_TO_INSTANCE(Mod_idP), message_p);
783
  }
784
#else
785
786
  // reset the tx buffer to indicate RRC that ccch was successfully transmitted (for example if contention resolution succeeds)
  UE_rrc_inst[Mod_idP].Srb0[eNB_index].Tx_buffer.payload_size=0;
787
#endif
788
  return 0;
789
}