L2_interface.c 22.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
22
23
24
25
26
27
28
29
30
31
/*******************************************************************************

  Eurecom OpenAirInterface 2
  Copyright(c) 1999 - 2010 Eurecom

  This program is free software; you can redistribute it and/or modify it
  under the terms and conditions of the GNU General Public License,
  version 2, as published by the Free Software Foundation.

  This program is distributed in the hope it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  more details.

  You should have received a copy of the GNU General Public License along with
  this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.

  The full GNU General Public License is included in this distribution in
  the file called "COPYING".

  Contact Information
  Openair Admin: openair_admin@eurecom.fr
  Openair Tech : openair_tech@eurecom.fr
  Forums       : http://forums.eurecom.fsr/openairinterface
  Address      : Eurecom, 2229, route des crêtes, 06560 Valbonne Sophia Antipolis, France

*******************************************************************************/

/*! \file l2_interface.c
* \brief layer 2 interface 
32
* \author Raymond Knopp and Navid Nikaein 
33
34
35
36
37
38
39
40
41
42
43
44
45
46
* \date 2011
* \version 1.0 
* \company Eurecom
* \email: raymond.knopp@eurecom.fr 
*/ 
//#include "openair_types.h"
//#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"
47
#include "pdcp.h"
48
49
50
51
52
53
54
55

#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

56
57
58
59
#if defined(ENABLE_ITTI)
# include "intertask_interface.h"
#endif

60
//#define RRC_DATA_REQ_DEBUG
61
#define DEBUG_RRC
62
63
64

u32 mui=0;

65
//-------------------------------------------------------------------------------------------//
66
s8 mac_rrc_lite_data_req(u8 Mod_id, u32 frame, u16 Srb_id, u8 Nb_tb, u8 *Buffer, u8 eNB_flag, u8 eNB_index,
67
68
                         u8 mbsfn_sync_area) {
//-------------------------------------------------------------------------------------------//
69
70
71
72
73
  SRB_INFO *Srb_info;
  u8 Sdu_size=0;

#ifdef DEBUG_RRC
  int i;
74
  LOG_D(RRC,"[eNB %d] mac_rrc_data_req to SRB ID=%d\n",Mod_id,Srb_id);
75
76
77
78
79
80
81
82
83
84
85
86
87
#endif

  if( eNB_flag == 1){

    if((Srb_id & RAB_OFFSET) == BCCH){
      if(eNB_rrc_inst[Mod_id].SI.Active==0) return 0;

      // All even frames transmit SIB in SF 5
      if (eNB_rrc_inst[Mod_id].sizeof_SIB1 == 255) {
	LOG_E(RRC,"[eNB %d] MAC Request for SIB1 and SIB1 not initialized\n",Mod_id);
	mac_xface->macphy_exit("");
      }
      if ((frame%2) == 0) {
88
89
90
91
92
        memcpy(&Buffer[0],eNB_rrc_inst[Mod_id].SIB1,eNB_rrc_inst[Mod_id].sizeof_SIB1);

#if defined(ENABLE_ITTI)
      {
        MessageDef *message_p;
93
94
        int sib1_size = eNB_rrc_inst[Mod_id].sizeof_SIB1;
        int sdu_size = sizeof(RRC_MAC_BCCH_DATA_REQ (message_p).sdu);
95

96
97
98
99
100
        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;
        }
101
102

        message_p = itti_alloc_new_message (TASK_RRC_ENB, RRC_MAC_BCCH_DATA_REQ);
103
104
105
106
        RRC_MAC_BCCH_DATA_REQ (message_p).frame = frame;
        RRC_MAC_BCCH_DATA_REQ (message_p).sdu_size = sib1_size;
        memcpy (RRC_MAC_BCCH_DATA_REQ (message_p).sdu, eNB_rrc_inst[Mod_id].SIB1, sib1_size);
        RRC_MAC_BCCH_DATA_REQ (message_p).enb_index = eNB_index;
107
108
109
110
111

        itti_send_msg_to_task (TASK_MAC_ENB, Mod_id, message_p);
      }
#endif

112
113
114
115
116
117
118
119
120
121
122
#ifdef DEBUG_RRC
	LOG_D(RRC,"[eNB %d] Frame %d : BCCH request => SIB 1\n",Mod_id,frame);
	for (i=0;i<eNB_rrc_inst[Mod_id].sizeof_SIB1;i++)
	  LOG_T(RRC,"%x.",Buffer[i]);
	LOG_T(RRC,"\n");
#endif

	return (eNB_rrc_inst[Mod_id].sizeof_SIB1);
      } // All RFN mod 8 transmit SIB2-3 in SF 5
      else if ((frame%8) == 1){
	memcpy(&Buffer[0],eNB_rrc_inst[Mod_id].SIB23,eNB_rrc_inst[Mod_id].sizeof_SIB23);
123
124
125
126

#if defined(ENABLE_ITTI)
      {
        MessageDef *message_p;
127
128
        int sib23_size = eNB_rrc_inst[Mod_id].sizeof_SIB23;
        int sdu_size = sizeof(RRC_MAC_BCCH_DATA_REQ (message_p).sdu);
129

130
131
132
133
134
        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;
        }
135
136

        message_p = itti_alloc_new_message (TASK_RRC_ENB, RRC_MAC_BCCH_DATA_REQ);
137
138
139
140
        RRC_MAC_BCCH_DATA_REQ (message_p).frame = frame;
        RRC_MAC_BCCH_DATA_REQ (message_p).sdu_size = sib23_size;
        memcpy (RRC_MAC_BCCH_DATA_REQ (message_p).sdu, eNB_rrc_inst[Mod_id].SIB23, sib23_size);
        RRC_MAC_BCCH_DATA_REQ (message_p).enb_index = eNB_index;
141
142
143
144
145

        itti_send_msg_to_task (TASK_MAC_ENB, Mod_id, message_p);
      }
#endif

146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#ifdef DEBUG_RRC
	LOG_D(RRC,"[eNB %d] Frame %d BCCH request => SIB 2-3\n",Mod_id,frame);
	for (i=0;i<eNB_rrc_inst[Mod_id].sizeof_SIB23;i++)
	  LOG_T(RRC,"%x.",Buffer[i]);
	LOG_T(RRC,"\n");
#endif
	return(eNB_rrc_inst[Mod_id].sizeof_SIB23);
      }
      else
	return(0);
    }


    if( (Srb_id & RAB_OFFSET ) == CCCH){
      LOG_D(RRC,"[eNB %d] Frame %d CCCH request (Srb_id %d)\n",Mod_id,frame, Srb_id);

      if(eNB_rrc_inst[Mod_id].Srb0.Active==0) {
	LOG_E(RRC,"[eNB %d] CCCH Not active\n",Mod_id);
	return -1;
      }
      Srb_info=&eNB_rrc_inst[Mod_id].Srb0;

      // 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_id,Srb_info,Srb_info->Tx_buffer.payload_size,Buffer,Srb_info->Tx_buffer.Payload);
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193

#if defined(ENABLE_ITTI)
        {
          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) {
            LOG_E(RRC, "SDU larger than CCCH SDU buffer size (%d, %d)", ccch_size, sdu_size);
            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 = frame;
          RRC_MAC_CCCH_DATA_REQ (message_p).sdu_size = ccch_size;
          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;

          itti_send_msg_to_task (TASK_MAC_ENB, Mod_id, message_p);
        }
#endif

        memcpy(Buffer,Srb_info->Tx_buffer.Payload,Srb_info->Tx_buffer.payload_size);
194
195
196
197
198
199
200
201
202
	Sdu_size = Srb_info->Tx_buffer.payload_size;
	Srb_info->Tx_buffer.payload_size=0;
      }

      return (Sdu_size);
    }

#ifdef Rel10
    if((Srb_id & RAB_OFFSET) == MCCH){
203
204
205
      if(eNB_rrc_inst[Mod_id].MCCH_MESS[mbsfn_sync_area].Active==0) return 0; // this parameter is set in function init_mcch in rrc_eNB.c                                                                              
      // this part not needed as it is done in init_mcch 
      /*     if (eNB_rrc_inst[Mod_id].sizeof_MCCH_MESSAGE[mbsfn_sync_area] == 255) {
206
207
	LOG_E(RRC,"[eNB %d] MAC Request for MCCH MESSAGE and MCCH MESSAGE is not initialized\n",Mod_id);
	mac_xface->macphy_exit("");
208
	}*/
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232


#if defined(ENABLE_ITTI)
      {
        MessageDef *message_p;
        int mcch_size = eNB_rrc_inst[Mod_id].sizeof_MCCH_MESSAGE[mbsfn_sync_area];
        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 = frame;
        RRC_MAC_MCCH_DATA_REQ (message_p).sdu_size = mcch_size;
        memcpy (RRC_MAC_MCCH_DATA_REQ (message_p).sdu, eNB_rrc_inst[Mod_id].MCCH_MESSAGE[mbsfn_sync_area], mcch_size);
        RRC_MAC_MCCH_DATA_REQ (message_p).enb_index = eNB_index;
        RRC_MAC_MCCH_DATA_REQ (message_p).mbsfn_sync_area = mbsfn_sync_area;

        itti_send_msg_to_task (TASK_MAC_ENB, Mod_id, message_p);
      }
#endif

233
234
235
      memcpy(&Buffer[0],
	     eNB_rrc_inst[Mod_id].MCCH_MESSAGE[mbsfn_sync_area],
	     eNB_rrc_inst[Mod_id].sizeof_MCCH_MESSAGE[mbsfn_sync_area]);
236
237
238
      
#ifdef DEBUG_RRC
      LOG_D(RRC,"[eNB %d] Frame %d : MCCH request => MCCH_MESSAGE \n",Mod_id,frame);
239
      for (i=0;i<eNB_rrc_inst[Mod_id].sizeof_MCCH_MESSAGE[mbsfn_sync_area];i++)
240
241
242
243
	LOG_T(RRC,"%x.",Buffer[i]);
      LOG_T(RRC,"\n");
#endif
      
244
      return (eNB_rrc_inst[Mod_id].sizeof_MCCH_MESSAGE[mbsfn_sync_area]);
245
246
247
248
249
250
251
252
253
254
255
256
257
      //      }
      //else
      //return(0);
    }
#endif //Rel10    
  }

  else{   //This is an UE
#ifdef DEBUG_RRC
    LOG_D(RRC,"[UE %d] Frame %d Filling CCCH SRB_ID %d\n",Mod_id,frame,Srb_id);
    LOG_D(RRC,"[UE %d] Frame %d Buffer status %d,\n",Mod_id,frame, UE_rrc_inst[Mod_id].Srb0[eNB_index].Tx_buffer.payload_size);
#endif
    if( (UE_rrc_inst[Mod_id].Srb0[eNB_index].Tx_buffer.payload_size > 0) ) {
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279

#if defined(ENABLE_ITTI)
      {
        MessageDef *message_p;
        int ccch_size = UE_rrc_inst[Mod_id].Srb0[eNB_index].Tx_buffer.payload_size;
        int sdu_size = sizeof(RRC_MAC_CCCH_DATA_REQ (message_p).sdu);

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

        message_p = itti_alloc_new_message (TASK_RRC_UE, RRC_MAC_CCCH_DATA_REQ);
        RRC_MAC_CCCH_DATA_REQ (message_p).frame = frame;
        RRC_MAC_CCCH_DATA_REQ (message_p).sdu_size = ccch_size;
        memcpy (RRC_MAC_CCCH_DATA_REQ (message_p).sdu, UE_rrc_inst[Mod_id].Srb0[eNB_index].Tx_buffer.Payload, ccch_size);
        RRC_MAC_CCCH_DATA_REQ (message_p).enb_index = eNB_index;

        itti_send_msg_to_task (TASK_MAC_UE, Mod_id, message_p);
      }
#endif

280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
      memcpy(&Buffer[0],&UE_rrc_inst[Mod_id].Srb0[eNB_index].Tx_buffer.Payload[0],UE_rrc_inst[Mod_id].Srb0[eNB_index].Tx_buffer.payload_size);
      u8 Ret_size=UE_rrc_inst[Mod_id].Srb0[eNB_index].Tx_buffer.payload_size;
      //   UE_rrc_inst[Mod_id].Srb0[eNB_index].Tx_buffer.payload_size=0;
      UE_rrc_inst[Mod_id].Info[eNB_index].T300_active = 1;
      UE_rrc_inst[Mod_id].Info[eNB_index].T300_cnt = 0;
      //      msg("[RRC][UE %d] Sending rach\n",Mod_id);
      return(Ret_size);
    }
    else{
      return 0;
    }
  }
  return(0);
}

295
//-------------------------------------------------------------------------------------------//
296
s8 mac_rrc_lite_data_ind(u8 Mod_id, u32 frame, u16 Srb_id, u8 *Sdu, u16 sdu_size,u8 eNB_flag,u8 eNB_index,u8 mbsfn_sync_area){
297
//-------------------------------------------------------------------------------------------//
298
  SRB_INFO *Srb_info;
299
  /*
300
  int si_window;
301
  */
302
303
304
305

  if(eNB_flag == 0){

    if(Srb_id == BCCH){
306
307
      
      LOG_T(RRC,"[UE %d] Received SDU for BCCH on SRB %d from eNB %d\n",Mod_id,Srb_id,eNB_index);
308
309
310
311

#if defined(ENABLE_ITTI)
      {
        MessageDef *message_p;
312
        int msg_sdu_size = sizeof(RRC_MAC_BCCH_DATA_IND (message_p).sdu);
313

314
315
316
317
318
        if (sdu_size > msg_sdu_size)
        {
          LOG_E(RRC, "SDU larger than BCCH SDU buffer size (%d, %d)", sdu_size, msg_sdu_size);
          sdu_size = msg_sdu_size;
        }
319

320
        message_p = itti_alloc_new_message (TASK_MAC_UE, RRC_MAC_BCCH_DATA_IND);
321
322
        RRC_MAC_BCCH_DATA_IND (message_p).frame = frame;
        RRC_MAC_BCCH_DATA_IND (message_p).sdu_size = sdu_size;
323
        memcpy (RRC_MAC_BCCH_DATA_IND (message_p).sdu, Sdu, sdu_size);
324
325
326
327
328
329
        RRC_MAC_BCCH_DATA_IND (message_p).enb_index = eNB_index;

        itti_send_msg_to_task (TASK_RRC_UE, Mod_id, message_p);
      }
#else
      decode_BCCH_DLSCH_Message(Mod_id,frame,eNB_index,Sdu,sdu_size);
330
331
332
      /*
      if ((frame %2) == 0) {
	if (UE_rrc_inst[Mod_id].Info[eNB_index].SIB1Status == 0) {
333
	  LOG_D(RRC,"[UE %d] Frame %d : Received SIB1 from eNB %d (%d bytes)\n",Mod_id,frame,eNB_index,sdu_size);
334
	  if (UE_rrc_inst[Mod_id].SIB1[eNB_index])
335
	    memcpy(UE_rrc_inst[Mod_id].SIB1[eNB_index],&Sdu[0],sdu_size);
336
337
338
339
340
341
342
343
344
345
346
347
348
	  else {
	    LOG_E(RRC,"[FATAL ERROR] SIB1 buffer for eNB %d not allocated, exiting ...\n",eNB_index);
	    mac_xface->macphy_exit("");
	    return(-1);
	  }
	  UE_rrc_inst[Mod_id].Info[eNB_index].SIB1Status = 1;
	  decode_SIB1(Mod_id,eNB_index);
	}
      }
      else {
	if ((UE_rrc_inst[Mod_id].Info[eNB_index].SIB1Status == 1) &&
	    (UE_rrc_inst[Mod_id].Info[eNB_index].SIStatus == 0)) {
	  si_window = (frame%UE_rrc_inst[Mod_id].Info[eNB_index].SIperiod)/frame%UE_rrc_inst[Mod_id].Info[eNB_index].SIwindowsize;
349
350
	  LOG_D(RRC,"[UE %d] Frame %d : Received SI (%d bytes), in window %d (SIperiod %d, SIwindowsize %d)\n",Mod_id,frame,sdu_size,si_window,UE_rrc_inst[Mod_id].Info[eNB_index].SIperiod,UE_rrc_inst[Mod_id].Info[eNB_index].SIwindowsize);
	  memcpy(UE_rrc_inst[Mod_id].SI[eNB_index],&Sdu[0],sdu_size);
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
	  if (decode_SI(Mod_id,frame,eNB_index,si_window)==0) {
	    LOG_D(RRC,"[UE %d] Frame %d :Decoded SI successfully\n",Mod_id,frame);
	    UE_rrc_inst[Mod_id].Info[eNB_index].SIStatus = 1;
	  }
	  }


    
	  }


      if ((UE_rrc_inst[Mod_id].Info[eNB_index].SIB1Status == 1) &&
	  (UE_rrc_inst[Mod_id].Info[eNB_index].SIStatus == 1)) {
	if (UE_rrc_inst[Mod_id].Info[eNB_index].State == RRC_IDLE) {
	  LOG_I(RRC,"[UE %d] Received SIB1/SIB2/SIB3 Switching to RRC_SI_RECEIVED\n",Mod_id);
	  UE_rrc_inst[Mod_id].Info[eNB_index].State = RRC_SI_RECEIVED;
	}
      }
      */
370
#endif
371
372
373
    }

    if((Srb_id & RAB_OFFSET) == CCCH){
374
375
376
377
378
379
      if (sdu_size>0) {
        LOG_T(RRC,"[UE %d] Received SDU for CCCH on SRB %d from eNB %d\n",Mod_id,Srb_id & RAB_OFFSET,eNB_index);

#if defined(ENABLE_ITTI)
        {
          MessageDef *message_p;
380
          int msg_sdu_size = sizeof(RRC_MAC_CCCH_DATA_IND (message_p).sdu);
381

382
383
384
385
386
          if (sdu_size > msg_sdu_size)
          {
            LOG_E(RRC, "SDU larger than CCCH SDU buffer size (%d, %d)", sdu_size, msg_sdu_size);
            sdu_size = msg_sdu_size;
          }
387

388
          message_p = itti_alloc_new_message (TASK_MAC_UE, RRC_MAC_CCCH_DATA_IND);
389
390
          RRC_MAC_CCCH_DATA_IND (message_p).frame = frame;
          RRC_MAC_CCCH_DATA_IND (message_p).sdu_size = sdu_size;
391
          memcpy (RRC_MAC_CCCH_DATA_IND (message_p).sdu, Sdu, sdu_size);
392
393
394
395
396
397
398
399
400
401
402
          RRC_MAC_CCCH_DATA_IND (message_p).enb_index = eNB_index;

          itti_send_msg_to_task (TASK_RRC_UE, Mod_id, message_p);
      }
#else
        Srb_info = &UE_rrc_inst[Mod_id].Srb0[eNB_index];

        memcpy(Srb_info->Rx_buffer.Payload,Sdu,sdu_size);
        Srb_info->Rx_buffer.payload_size = sdu_size;
        rrc_ue_decode_ccch(Mod_id, frame, Srb_info, eNB_index);
#endif
403
404
405
406
407
      }
    }
      
#ifdef Rel10
    if ((Srb_id & RAB_OFFSET) == MCCH) {
408
409
      LOG_T(RRC,"[UE %d] Frame %d: Received SDU on MBSFN sync area %d for MCCH on SRB %d from eNB %d\n",
	    Mod_id,frame, mbsfn_sync_area, Srb_id & RAB_OFFSET,eNB_index);
410
411
412
413

#if defined(ENABLE_ITTI)
      {
        MessageDef *message_p;
414
        int msg_sdu_size = sizeof(RRC_MAC_MCCH_DATA_IND (message_p).sdu);
415

416
417
418
419
420
        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;
        }
421

422
        message_p = itti_alloc_new_message (TASK_MAC_UE, RRC_MAC_MCCH_DATA_IND);
423
424
        RRC_MAC_MCCH_DATA_IND (message_p).frame = frame;
        RRC_MAC_MCCH_DATA_IND (message_p).sdu_size = sdu_size;
425
        memcpy (RRC_MAC_MCCH_DATA_IND (message_p).sdu, Sdu, sdu_size);
426
427
428
429
430
431
432
433
        RRC_MAC_MCCH_DATA_IND (message_p).enb_index = eNB_index;
        RRC_MAC_MCCH_DATA_IND (message_p).mbsfn_sync_area = mbsfn_sync_area;

        itti_send_msg_to_task (TASK_RRC_UE, Mod_id, message_p);
      }
#else
      decode_MCCH_Message(Mod_id, frame, eNB_index, Sdu, sdu_size, mbsfn_sync_area);
#endif
434
435
436
437
438
439
    }
#endif // Rel10

  }

  else{  // This is an eNB
Florian Kaltenberger's avatar
Florian Kaltenberger committed
440
    Srb_info = &eNB_rrc_inst[Mod_id].Srb0;
441
442
    LOG_T(RRC,"[eNB %d] Received SDU for CCCH on SRB %d\n",Mod_id,Srb_info->Srb_id);
    
443
444
445
#if defined(ENABLE_ITTI)
        {
          MessageDef *message_p;
446
          int msg_sdu_size = sizeof(RRC_MAC_CCCH_DATA_IND (message_p).sdu);
447

448
449
450
451
452
          if (sdu_size > msg_sdu_size)
          {
            LOG_E(RRC, "SDU larger than CCCH SDU buffer size (%d, %d)", sdu_size, msg_sdu_size);
            sdu_size = msg_sdu_size;
          }
453

454
          message_p = itti_alloc_new_message (TASK_MAC_ENB, RRC_MAC_CCCH_DATA_IND);
455
456
          RRC_MAC_CCCH_DATA_IND (message_p).frame = frame;
          RRC_MAC_CCCH_DATA_IND (message_p).sdu_size = sdu_size;
457
          memcpy (RRC_MAC_CCCH_DATA_IND (message_p).sdu, Sdu, sdu_size);
458
459
460
461

          itti_send_msg_to_task (TASK_RRC_ENB, Mod_id, message_p);
      }
#else
462
    //    msg("\n******INST %d Srb_info %p, Srb_id=%d****\n\n",Mod_id,Srb_info,Srb_info->Srb_id);
463
464
    memcpy(Srb_info->Rx_buffer.Payload,Sdu,6);
    rrc_eNB_decode_ccch(Mod_id,frame,Srb_info);
465
466
#endif
  }
467
468
469
470
471
472

  return(0);

}

//-------------------------------------------------------------------------------------------//
473
// this function is Not USED anymore
474
475
void mac_lite_sync_ind(u8 Mod_id,u8 Status){
//-------------------------------------------------------------------------------------------//
476
477
478
479
480
481
}

//-------------------------------------------------------------------------------------------//
u8 rrc_lite_data_req(u8 Mod_id, u32 frame, u8 eNB_flag, unsigned int rb_id, u32 muiP, u32 confirmP,
                     unsigned int sdu_size, u8* Buffer, u8 mode) {
//-------------------------------------------------------------------------------------------//
482
483
484
#if defined(ENABLE_ITTI)
  {
    MessageDef *message_p;
485
486
    // Uses a new buffer to avoid issue with PDCP buffer content that could be changed by PDCP (asynchronous message handling).
    u8 *message_buffer;
487

488
489
490
    message_buffer = malloc (sdu_size);
    memcpy (message_buffer, Buffer, sdu_size);

491
    message_p = itti_alloc_new_message (eNB_flag ? TASK_RRC_ENB : TASK_RRC_UE, RRC_DCCH_DATA_REQ);
492
493
494
495
496
497
498
499
500
    RRC_DCCH_DATA_REQ (message_p).frame = frame;
    RRC_DCCH_DATA_REQ (message_p).enb_flag = eNB_flag;
    RRC_DCCH_DATA_REQ (message_p).rb_id = rb_id;
    RRC_DCCH_DATA_REQ (message_p).muip = muiP;
    RRC_DCCH_DATA_REQ (message_p).confirmp = confirmP;
    RRC_DCCH_DATA_REQ (message_p).sdu_size = sdu_size;
    RRC_DCCH_DATA_REQ (message_p).sdu_p = message_buffer;
    RRC_DCCH_DATA_REQ (message_p).mode = mode;

501
    itti_send_msg_to_task (eNB_flag ? TASK_PDCP_ENB : TASK_PDCP_UE, Mod_id, message_p);
502
    return TRUE; // TODO should be changed to a CNF message later, currently RRC lite does not used the returned value anyway.
503
504

  }
505
506
#else
  return pdcp_data_req (Mod_id, frame, eNB_flag, rb_id, muiP, confirmP, sdu_size, Buffer, mode);
507
#endif
508
509
}

510
//-------------------------------------------------------------------------------------------//
511
void rrc_lite_data_ind( u8 Mod_id, u32 frame, u8 eNB_flag,u32 Srb_id, u32 sdu_size,u8 *Buffer){
512
//-------------------------------------------------------------------------------------------//
513
514
515
  u8 UE_index=(Srb_id-1)/NB_RB_MAX;
  u8 DCCH_index = Srb_id % NB_RB_MAX;

516
  LOG_N(RRC,"[%s %d] Frame %d: received a DCCH %d message on SRB %d with Size %d\n",
517
518
519
        (eNB_flag == 1)? "eNB": "UE",
        (eNB_flag == 1)? Mod_id : UE_index,
        frame, DCCH_index,Srb_id-1,sdu_size);
520
521

#if defined(ENABLE_ITTI)
522
523
524
525
  {
    MessageDef *message_p;
    // Uses a new buffer to avoid issue with PDCP buffer content that could be changed by PDCP (asynchronous message handling).
    u8 *message_buffer;
526

527
528
    message_buffer = malloc (sdu_size);
    memcpy (message_buffer, Buffer, sdu_size);
529

530
    message_p = itti_alloc_new_message (eNB_flag ? TASK_PDCP_ENB : TASK_PDCP_UE, RRC_DCCH_DATA_IND);
531
532
533
534
535
    RRC_DCCH_DATA_IND (message_p).frame = frame;
    RRC_DCCH_DATA_IND (message_p).dcch_index = DCCH_index;
    RRC_DCCH_DATA_IND (message_p).sdu_size = sdu_size;
    RRC_DCCH_DATA_IND (message_p).sdu_p = message_buffer;
    RRC_DCCH_DATA_IND (message_p).ue_index = UE_index;
536

537
538
539
540
    if (eNB_flag == 1) {
      itti_send_msg_to_task (TASK_RRC_ENB, Mod_id, message_p);
    }
    else {
541
542
      itti_send_msg_to_task (TASK_RRC_UE, Mod_id - NB_eNB_INST, message_p);
    }
543
  }
544
#else
545
546
547
548
  if (eNB_flag ==1) {
    rrc_eNB_decode_dcch(Mod_id,frame,DCCH_index,UE_index,Buffer,sdu_size);
  }
  else {
549
    rrc_ue_decode_dcch(Mod_id-NB_eNB_INST,frame,DCCH_index,Buffer,UE_index);
550
  }
551
#endif
552
553
}

554
//-------------------------------------------------------------------------------------------//
555
void rrc_lite_in_sync_ind(u8 Mod_id, u32 frame, u16 eNB_index) {
556
//-------------------------------------------------------------------------------------------//
557
558
559
#if defined(ENABLE_ITTI)
  {
    MessageDef *message_p;
560

561
    message_p = itti_alloc_new_message (TASK_MAC_UE, RRC_MAC_IN_SYNC_IND);
562
563
564
565
566
567
    RRC_MAC_IN_SYNC_IND (message_p).frame = frame;
    RRC_MAC_IN_SYNC_IND (message_p).enb_index = eNB_index;

    itti_send_msg_to_task (TASK_RRC_UE, Mod_id, message_p);
  }
#else
568
569
570
  UE_rrc_inst[Mod_id].Info[eNB_index].N310_cnt=0;
  if (UE_rrc_inst[Mod_id].Info[eNB_index].T310_active==1)
    UE_rrc_inst[Mod_id].Info[eNB_index].N311_cnt++;
571
#endif
572
573
}

574
575
576
//-------------------------------------------------------------------------------------------//
void rrc_lite_out_of_sync_ind(u8  Mod_id, u32 frame, u16 eNB_index){
//-------------------------------------------------------------------------------------------//
577
578
579
//  rlc_info_t rlc_infoP;
//  rlc_infoP.rlc_mode=RLC_UM;

580
  LOG_I(RRC,"[UE %d] Frame %d: OUT OF SYNC FROM eNB %d (T310 %d, N310 %d, N311 %d)\n ",
581
582
583
584
        Mod_id,frame,eNB_index,
        UE_rrc_inst[Mod_id].Info[eNB_index].T310_cnt,
        UE_rrc_inst[Mod_id].Info[eNB_index].N310_cnt,
        UE_rrc_inst[Mod_id].Info[eNB_index].N311_cnt);
585

586
587
588
589
#if defined(ENABLE_ITTI)
  {
    MessageDef *message_p;

590
    message_p = itti_alloc_new_message (TASK_MAC_UE, RRC_MAC_OUT_OF_SYNC_IND);
591
592
593
594
595
596
    RRC_MAC_OUT_OF_SYNC_IND (message_p).frame = frame;
    RRC_MAC_OUT_OF_SYNC_IND (message_p).enb_index = eNB_index;

    itti_send_msg_to_task (TASK_RRC_UE, Mod_id, message_p);
  }
#else
597
  UE_rrc_inst[Mod_id].Info[eNB_index].N310_cnt++;
598
#endif
599
600
}

601
//-------------------------------------------------------------------------------------------//
602
int mac_get_rrc_lite_status(u8 Mod_id,u8 eNB_flag,u8 index){
603
//-------------------------------------------------------------------------------------------//
604
605
606
607
608
609
  if(eNB_flag == 1)
    return(eNB_rrc_inst[Mod_id].Info.Status[index]);
  else
    return(UE_rrc_inst[Mod_id].Info[index].State);
}

610
//-------------------------------------------------------------------------------------------//
611
int mac_ue_ccch_success_ind(u8 Mod_id, u8 eNB_index) {
612
613
614
615
616
//-------------------------------------------------------------------------------------------//
#if defined(ENABLE_ITTI)
  {
    MessageDef *message_p;

617
618
    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;
619
620
621
622

    itti_send_msg_to_task (TASK_RRC_UE, Mod_id - NB_eNB_INST, message_p);
  }
#else
623
624
  // reset the tx buffer to indicate RRC that ccch was successfully transmitted (for example if contention resolution succeeds)
  UE_rrc_inst[Mod_id].Srb0[eNB_index].Tx_buffer.payload_size=0;
625
#endif
Cedric Roux's avatar
Cedric Roux committed
626
  return 0;
627
}