L2_interface.c 28.1 KB
Newer Older
1
/*******************************************************************************
2 3
    OpenAirInterface
    Copyright(c) 1999 - 2014 Eurecom
4

5 6 7 8
    OpenAirInterface is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
9 10


11 12 13 14
    OpenAirInterface is distributed in the hope that 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.
15

16 17 18 19
    You should have received a copy of the GNU General Public License
    along with OpenAirInterface.The full GNU General Public License is
    included in this distribution in the file called "COPYING". If not,
    see <http://www.gnu.org/licenses/>.
20 21

  Contact Information
22 23 24 25
  OpenAirInterface Admin: openair_admin@eurecom.fr
  OpenAirInterface Tech : openair_tech@eurecom.fr
  OpenAirInterface Dev  : openair4g-devel@eurecom.fr

ghaddab's avatar
ghaddab committed
26
  Address      : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE
27

28
 *******************************************************************************/
29 30

/*! \file l2_interface.c
31 32 33 34 35 36 37
 * \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
 */
38

gauthier's avatar
gauthier committed
39
#include "platform_types.h"
40 41 42 43 44 45 46 47
//#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"
48
#include "pdcp.h"
49 50 51 52 53 54 55 56

#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

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

61
//#define RRC_DATA_REQ_DEBUG
62
#define DEBUG_RRC
63

64
mui_t mui=0;
65

66
//-------------------------------------------------------------------------------------------//
67
int8_t mac_rrc_lite_data_req(module_id_t Mod_idP, frame_t frameP, uint16_t Srb_id, uint8_t Nb_tb, uint8_t *buffer_pP, eNB_flag_t enb_flagP, uint8_t eNB_index,
68 69 70 71
                             uint8_t mbsfn_sync_area) {
    //-------------------------------------------------------------------------------------------//
    SRB_INFO *Srb_info;
    uint8_t Sdu_size=0;
72 73

#ifdef DEBUG_RRC
74 75
    int i;
    LOG_D(RRC,"[eNB %d] mac_rrc_data_req to SRB ID=%d\n",Mod_idP,Srb_id);
76 77
#endif

78
    if( enb_flagP == ENB_FLAG_YES){
79

80 81
        if((Srb_id & RAB_OFFSET) == BCCH){
            if(eNB_rrc_inst[Mod_idP].SI.Active==0) return 0;
82

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

#if defined(ENABLE_ITTI)
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
                {
                    MessageDef *message_p;
                    int sib1_size = eNB_rrc_inst[Mod_idP].sizeof_SIB1;
                    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;
                    memset (RRC_MAC_BCCH_DATA_REQ (message_p).sdu, 0, sizeof(RRC_MAC_BCCH_DATA_REQ (message_p).sdu));
                    memcpy (RRC_MAC_BCCH_DATA_REQ (message_p).sdu, eNB_rrc_inst[Mod_idP].SIB1, sib1_size);
                    RRC_MAC_BCCH_DATA_REQ (message_p).enb_index = eNB_index;

                    itti_send_msg_to_task (TASK_MAC_ENB, Mod_idP, message_p);
                }
112 113
#endif

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

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

#if defined(ENABLE_ITTI)
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
                {
                    MessageDef *message_p;
                    int sib23_size = eNB_rrc_inst[Mod_idP].sizeof_SIB23;
                    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;
                    memset (RRC_MAC_BCCH_DATA_REQ (message_p).sdu, 0, sizeof(RRC_MAC_BCCH_DATA_REQ (message_p).sdu));
                    memcpy (RRC_MAC_BCCH_DATA_REQ (message_p).sdu, eNB_rrc_inst[Mod_idP].SIB23, sib23_size);
                    RRC_MAC_BCCH_DATA_REQ (message_p).enb_index = eNB_index;

                    itti_send_msg_to_task (TASK_MAC_ENB, Mod_idP, message_p);
                }
147 148
#endif

149
#ifdef DEBUG_RRC
150 151 152 153
                LOG_D(RRC,"[eNB %d] Frame %d BCCH request => SIB 2-3\n",Mod_idP,frameP);
                for (i=0;i<eNB_rrc_inst[Mod_idP].sizeof_SIB23;i++)
                    LOG_T(RRC,"%x.",buffer_pP[i]);
                LOG_T(RRC,"\n");
154
#endif
155 156 157 158 159
                return(eNB_rrc_inst[Mod_idP].sizeof_SIB23);
            }
            else
                return(0);
        }
160 161


162 163
        if( (Srb_id & RAB_OFFSET ) == CCCH){
            LOG_D(RRC,"[eNB %d] Frame %d CCCH request (Srb_id %d)\n",Mod_idP,frameP, Srb_id);
164

165 166 167 168 169
            if(eNB_rrc_inst[Mod_idP].Srb0.Active==0) {
                LOG_E(RRC,"[eNB %d] CCCH Not active\n",Mod_idP);
                return -1;
            }
            Srb_info=&eNB_rrc_inst[Mod_idP].Srb0;
170

171 172 173
            // 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);
174 175

#if defined(ENABLE_ITTI)
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
                {
                    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 = frameP;
                    RRC_MAC_CCCH_DATA_REQ (message_p).sdu_size = ccch_size;
                    memset (RRC_MAC_BCCH_DATA_REQ (message_p).sdu, 0, sizeof(RRC_MAC_BCCH_DATA_REQ (message_p).sdu));
                    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_idP, message_p);
                }
195 196
#endif

197 198 199 200
                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;
            }
201

202 203
            return (Sdu_size);
        }
204 205

#ifdef Rel10
206 207 208 209
        if((Srb_id & RAB_OFFSET) == MCCH){
            if(eNB_rrc_inst[Mod_idP].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) {
210 211
	LOG_E(RRC,"[eNB %d] MAC Request for MCCH MESSAGE and MCCH MESSAGE is not initialized\n",Mod_id);
	mac_xface->macphy_exit("");
212
	}*/
213 214 215


#if defined(ENABLE_ITTI)
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
            {
                MessageDef *message_p;
                int mcch_size = eNB_rrc_inst[Mod_idP].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 = frameP;
                RRC_MAC_MCCH_DATA_REQ (message_p).sdu_size = mcch_size;
                memset (RRC_MAC_BCCH_DATA_REQ (message_p).sdu, 0, sizeof(RRC_MAC_BCCH_DATA_REQ (message_p).sdu));
                memcpy (RRC_MAC_MCCH_DATA_REQ (message_p).sdu, eNB_rrc_inst[Mod_idP].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_idP, message_p);
            }
236 237
#endif

238 239 240 241
            memcpy(&buffer_pP[0],
                   eNB_rrc_inst[Mod_idP].MCCH_MESSAGE[mbsfn_sync_area],
                   eNB_rrc_inst[Mod_idP].sizeof_MCCH_MESSAGE[mbsfn_sync_area]);

242
#ifdef DEBUG_RRC
243 244 245 246
            LOG_D(RRC,"[eNB %d] Frame %d : MCCH request => MCCH_MESSAGE \n",Mod_idP,frameP);
            for (i=0;i<eNB_rrc_inst[Mod_idP].sizeof_MCCH_MESSAGE[mbsfn_sync_area];i++)
                LOG_T(RRC,"%x.",buffer_pP[i]);
            LOG_T(RRC,"\n");
247
#endif
248 249 250 251 252 253 254

            return (eNB_rrc_inst[Mod_idP].sizeof_MCCH_MESSAGE[mbsfn_sync_area]);
            //      }
            //else
            //return(0);
        }
#endif //Rel10
255 256
    }

257
    else{   //This is an UE
258
#ifdef DEBUG_RRC
259 260
        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);
261
#endif
262
        if( (UE_rrc_inst[Mod_idP].Srb0[eNB_index].Tx_buffer.payload_size > 0) ) {
263 264

#if defined(ENABLE_ITTI)
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
            {
                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);

                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 = frameP;
                RRC_MAC_CCCH_DATA_REQ (message_p).sdu_size = ccch_size;
                memset (RRC_MAC_BCCH_DATA_REQ (message_p).sdu, 0, sizeof(RRC_MAC_BCCH_DATA_REQ (message_p).sdu));
                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;

                itti_send_msg_to_task (TASK_MAC_UE, Mod_idP + NB_eNB_INST, message_p);
            }
284 285
#endif

286 287 288 289 290 291 292 293 294 295 296
            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;
        }
297
    }
298
    return(0);
299 300
}

301
//-------------------------------------------------------------------------------------------//
gauthier's avatar
gauthier committed
302
int8_t mac_rrc_lite_data_ind(module_id_t Mod_idP, frame_t frameP, rb_id_t Srb_id, uint8_t *Sdu, sdu_size_t sdu_size,eNB_flag_t enb_flagP,uint8_t eNB_index,uint8_t mbsfn_sync_area){
303 304 305
    //-------------------------------------------------------------------------------------------//
    SRB_INFO *Srb_info;
    /*
306
  int si_window;
307
     */
308

309
    if(enb_flagP == ENB_FLAG_NO){
310

311
        if(Srb_id == BCCH){
312

313
            LOG_T(RRC,"[UE %d] Received SDU for BCCH on SRB %d from eNB %d\n",Mod_idP,Srb_id,eNB_index);
314

315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
#if defined(ENABLE_ITTI)
            {
                MessageDef *message_p;
                int msg_sdu_size = sizeof(RRC_MAC_BCCH_DATA_IND (message_p).sdu);

                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;
                }

                message_p = itti_alloc_new_message (TASK_MAC_UE, RRC_MAC_BCCH_DATA_IND);
                RRC_MAC_BCCH_DATA_IND (message_p).frame = frameP;
                RRC_MAC_BCCH_DATA_IND (message_p).sdu_size = sdu_size;
                memset (RRC_MAC_CCCH_DATA_IND (message_p).sdu, 0, sizeof(RRC_MAC_CCCH_DATA_IND (message_p).sdu));
                memcpy (RRC_MAC_BCCH_DATA_IND (message_p).sdu, Sdu, sdu_size);
                RRC_MAC_BCCH_DATA_IND (message_p).enb_index = eNB_index;
                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 */;

                itti_send_msg_to_task (TASK_RRC_UE, Mod_idP + NB_eNB_INST, message_p);
            }
337
#else
338 339
            decode_BCCH_DLSCH_Message(Mod_idP,frameP,eNB_index,Sdu,sdu_size, 0, 0);
            /*
340
      if ((frameP %2) == 0) {
341
	if (UE_rrc_inst[Mod_id].Info[eNB_index].SIB1Status == 0) {
342
	  LOG_D(RRC,"[UE %d] Frame %d : Received SIB1 from eNB %d (%d bytes)\n",Mod_id,frameP,eNB_index,sdu_size);
343
	  if (UE_rrc_inst[Mod_id].SIB1[eNB_index])
344
	    memcpy(UE_rrc_inst[Mod_id].SIB1[eNB_index],&Sdu[0],sdu_size);
345 346 347 348 349 350 351 352 353 354 355 356
	  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)) {
357 358
	  si_window = (frameP%UE_rrc_inst[Mod_id].Info[eNB_index].SIperiod)/frameP%UE_rrc_inst[Mod_id].Info[eNB_index].SIwindowsize;
	  LOG_D(RRC,"[UE %d] Frame %d : Received SI (%d bytes), in window %d (SIperiod %d, SIwindowsize %d)\n",Mod_id,frameP,sdu_size,si_window,UE_rrc_inst[Mod_id].Info[eNB_index].SIperiod,UE_rrc_inst[Mod_id].Info[eNB_index].SIwindowsize);
359
	  memcpy(UE_rrc_inst[Mod_id].SI[eNB_index],&Sdu[0],sdu_size);
360 361
	  if (decode_SI(Mod_id,frameP,eNB_index,si_window)==0) {
	    LOG_D(RRC,"[UE %d] Frame %d :Decoded SI successfully\n",Mod_id,frameP);
362 363 364 365 366
	    UE_rrc_inst[Mod_id].Info[eNB_index].SIStatus = 1;
	  }
	  }


367

368 369 370 371 372 373 374 375 376 377
	  }


      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;
	}
      }
378
             */
379
#endif
380
        }
381

382 383 384
        if((Srb_id & RAB_OFFSET) == CCCH){
            if (sdu_size>0) {
                LOG_T(RRC,"[UE %d] Received SDU for CCCH on SRB %d from eNB %d\n",Mod_idP,Srb_id & RAB_OFFSET,eNB_index);
385 386

#if defined(ENABLE_ITTI)
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
                {
                    MessageDef *message_p;
                    int msg_sdu_size = sizeof(RRC_MAC_CCCH_DATA_IND (message_p).sdu);

                    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;
                    }

                    message_p = itti_alloc_new_message (TASK_MAC_UE, RRC_MAC_CCCH_DATA_IND);
                    RRC_MAC_CCCH_DATA_IND (message_p).frame = frameP;
                    RRC_MAC_CCCH_DATA_IND (message_p).sdu_size = sdu_size;
                    memset (RRC_MAC_CCCH_DATA_IND (message_p).sdu, 0, sizeof(RRC_MAC_CCCH_DATA_IND (message_p).sdu));
                    memcpy (RRC_MAC_CCCH_DATA_IND (message_p).sdu, Sdu, sdu_size);
                    RRC_MAC_CCCH_DATA_IND (message_p).enb_index = eNB_index;

                    itti_send_msg_to_task (TASK_RRC_UE, Mod_idP + NB_eNB_INST, message_p);
                }
406
#else
407
                Srb_info = &UE_rrc_inst[Mod_idP].Srb0[eNB_index];
408

409 410 411
                memcpy(Srb_info->Rx_buffer.Payload,Sdu,sdu_size);
                Srb_info->Rx_buffer.payload_size = sdu_size;
                rrc_ue_decode_ccch(Mod_idP, frameP, Srb_info, eNB_index);
412
#endif
413
            }
414
        }
415

416 417 418 419
#ifdef Rel10
        if ((Srb_id & RAB_OFFSET) == MCCH) {
            LOG_T(RRC,"[UE %d] Frame %d: Received SDU on MBSFN sync area %d for MCCH on SRB %d from eNB %d\n",
                  Mod_idP,frameP, mbsfn_sync_area, Srb_id & RAB_OFFSET,eNB_index);
420

421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441
#if defined(ENABLE_ITTI)
            {
                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;
                RRC_MAC_MCCH_DATA_IND (message_p).sdu_size        = sdu_size;
                memset (RRC_MAC_CCCH_DATA_IND (message_p).sdu, 0, sizeof(RRC_MAC_CCCH_DATA_IND (message_p).sdu));
                memcpy (RRC_MAC_MCCH_DATA_IND (message_p).sdu, Sdu, sdu_size);
                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_idP + NB_eNB_INST, message_p);
            }
442
#else
443
            decode_MCCH_Message(Mod_idP, frameP, eNB_index, Sdu, sdu_size, mbsfn_sync_area);
444
#endif
445
        }
446 447
#endif // Rel10

448 449 450 451 452
    }

    else{  // This is an eNB
        Srb_info = &eNB_rrc_inst[Mod_idP].Srb0;
        LOG_T(RRC,"[eNB %d] Received SDU for CCCH on SRB %d\n",Mod_idP,Srb_info->Srb_id);
453

454 455
#if defined(ENABLE_ITTI)
        {
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
            MessageDef *message_p;
            int msg_sdu_size = sizeof(RRC_MAC_CCCH_DATA_IND (message_p).sdu);

            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;
            }

            message_p = itti_alloc_new_message (TASK_MAC_ENB, RRC_MAC_CCCH_DATA_IND);
            RRC_MAC_CCCH_DATA_IND (message_p).frame = frameP;
            RRC_MAC_CCCH_DATA_IND (message_p).sdu_size = sdu_size;
            memset (RRC_MAC_CCCH_DATA_IND (message_p).sdu, 0, sizeof(RRC_MAC_CCCH_DATA_IND (message_p).sdu));
            memcpy (RRC_MAC_CCCH_DATA_IND (message_p).sdu, Sdu, sdu_size);

            itti_send_msg_to_task (TASK_RRC_ENB, Mod_idP, message_p);
        }
473
#else
474 475 476 477 478 479
        //    msg("\n******INST %d Srb_info %p, Srb_id=%d****\n\n",Mod_id,Srb_info,Srb_info->Srb_id);
        if (sdu_size > 0) {
            memcpy(Srb_info->Rx_buffer.Payload,Sdu,sdu_size);
            Srb_info->Rx_buffer.payload_size = sdu_size;
            rrc_eNB_decode_ccch(Mod_idP,frameP,Srb_info);
        }
480
#endif
481
    }
482

483
    return(0);
484 485 486 487

}

//-------------------------------------------------------------------------------------------//
488
// this function is Not USED anymore
489
void mac_lite_sync_ind(module_id_t Mod_idP,uint8_t Status){
490
    //-------------------------------------------------------------------------------------------//
491 492 493
}

//-------------------------------------------------------------------------------------------//
494
uint8_t rrc_lite_data_req(module_id_t enb_mod_idP, module_id_t ue_mod_idP, frame_t frameP, eNB_flag_t enb_flagP, rb_id_t rb_idP, mui_t muiP, uint32_t confirmP,
495 496
                          sdu_size_t sdu_size, uint8_t* buffer_pP, pdcp_transmission_mode_t mode) {
    //-------------------------------------------------------------------------------------------//
497
#if defined(ENABLE_ITTI)
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521
    {
        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;

        message_buffer = itti_malloc (enb_flagP ? TASK_RRC_ENB : TASK_RRC_UE, enb_flagP ? TASK_PDCP_ENB : TASK_PDCP_UE, sdu_size);
        memcpy (message_buffer, buffer_pP, sdu_size);

        message_p = itti_alloc_new_message (enb_flagP ? TASK_RRC_ENB : TASK_RRC_UE, RRC_DCCH_DATA_REQ);
        RRC_DCCH_DATA_REQ (message_p).frame     = frameP;
        RRC_DCCH_DATA_REQ (message_p).enb_flag  = enb_flagP;
        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;
        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;
        RRC_DCCH_DATA_REQ (message_p).eNB_index = enb_mod_idP;
        RRC_DCCH_DATA_REQ (message_p).ue_index  = ue_mod_idP;

        itti_send_msg_to_task (enb_flagP ? TASK_PDCP_ENB : TASK_PDCP_UE, enb_flagP ? enb_mod_idP : NB_eNB_INST + ue_mod_idP, message_p);
        return TRUE; // TODO should be changed to a CNF message later, currently RRC lite does not used the returned value anyway.

    }
522
#else
523 524 525 526 527
    protocol_ctxt_t ctxt;
    ctxt.enb_module_id = enb_mod_idP;
    ctxt.ue_module_id  = ue_mod_idP;
    ctxt.frame         = frameP;
    ctxt.enb_flag      = enb_flagP;
528

529
    return pdcp_data_req (&ctxt, SRB_FLAG_YES, rb_idP, muiP, confirmP, sdu_size, buffer_pP, mode);
530
#endif
531 532
}

533
//-------------------------------------------------------------------------------------------//
534
void rrc_lite_data_ind(module_id_t enb_mod_idP, module_id_t ue_mod_idP, frame_t frameP, eNB_flag_t enb_flagP,rb_id_t Srb_id, sdu_size_t sdu_sizeP,uint8_t *buffer_pP){
535 536
    //-------------------------------------------------------------------------------------------//
    rb_id_t    DCCH_index = Srb_id;
gauthier's avatar
gauthier committed
537
#if defined(ENABLE_ITTI)
538
    instance_t instance;
gauthier's avatar
gauthier committed
539
#endif
540

541
    if (enb_flagP == ENB_FLAG_NO) {
gauthier's avatar
gauthier committed
542
#if defined(ENABLE_ITTI)
543
        instance = ue_mod_idP + NB_eNB_INST;
gauthier's avatar
gauthier committed
544
#endif
545 546 547
        LOG_N(RRC, "[UE %d] Frame %d: received a DCCH %d message on SRB %d with Size %d from eNB %d\n",
              ue_mod_idP, frameP, DCCH_index,Srb_id-1,sdu_sizeP, enb_mod_idP);
    } else {
gauthier's avatar
gauthier committed
548
#if defined(ENABLE_ITTI)
549
        instance = enb_mod_idP;
gauthier's avatar
gauthier committed
550
#endif
551 552 553
        LOG_N(RRC, "[eNB %d] Frame %d: received a DCCH %d message on SRB %d with Size %d from UE %d\n",
              enb_mod_idP, frameP, DCCH_index,Srb_id-1,sdu_sizeP, ue_mod_idP);
    }
554 555

#if defined(ENABLE_ITTI)
556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573
    {
        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;

        message_buffer = itti_malloc (enb_flagP ? TASK_PDCP_ENB : TASK_PDCP_UE, enb_flagP ? TASK_RRC_ENB : TASK_RRC_UE, sdu_sizeP);
        memcpy (message_buffer, buffer_pP, sdu_sizeP);

        message_p = itti_alloc_new_message (enb_flagP ? TASK_PDCP_ENB : TASK_PDCP_UE, RRC_DCCH_DATA_IND);
        RRC_DCCH_DATA_IND (message_p).frame      = frameP;
        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;
        RRC_DCCH_DATA_IND (message_p).ue_index   = ue_mod_idP;
        RRC_DCCH_DATA_IND (message_p).eNB_index  = enb_mod_idP;

        itti_send_msg_to_task (enb_flagP ? TASK_RRC_ENB : TASK_RRC_UE, instance, message_p);
    }
574
#else
575 576 577 578 579 580
    if (enb_flagP == ENB_FLAG_YES) {
        rrc_eNB_decode_dcch(enb_mod_idP,frameP,DCCH_index,ue_mod_idP,buffer_pP,sdu_sizeP);
    }
    else {
        rrc_ue_decode_dcch(ue_mod_idP,frameP,DCCH_index,buffer_pP,enb_mod_idP);
    }
581
#endif
582 583
}

584
//-------------------------------------------------------------------------------------------//
585
void rrc_lite_in_sync_ind(module_id_t Mod_idP, frame_t frameP, uint16_t eNB_index) {
586
    //-------------------------------------------------------------------------------------------//
587
#if defined(ENABLE_ITTI)
588 589
    {
        MessageDef *message_p;
590

591 592 593
        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;
594

595 596
        itti_send_msg_to_task (TASK_RRC_UE, Mod_idP + NB_eNB_INST, message_p);
    }
597
#else
598 599 600
    UE_rrc_inst[Mod_idP].Info[eNB_index].N310_cnt=0;
    if (UE_rrc_inst[Mod_idP].Info[eNB_index].T310_active==1)
        UE_rrc_inst[Mod_idP].Info[eNB_index].N311_cnt++;
601
#endif
602 603
}

604
//-------------------------------------------------------------------------------------------//
605
void rrc_lite_out_of_sync_ind(module_id_t Mod_idP, frame_t frameP, uint16_t eNB_index){
606 607 608 609 610 611
    //-------------------------------------------------------------------------------------------//
    LOG_I(RRC,"[UE %d] Frame %d: OUT OF SYNC FROM eNB %d (T310 %d, N310 %d, N311 %d)\n ",
          Mod_idP,frameP,eNB_index,
          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);
612

613
#if defined(ENABLE_ITTI)
614 615
    {
        MessageDef *message_p;
616

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

621 622
        itti_send_msg_to_task (TASK_RRC_UE, Mod_idP + NB_eNB_INST, message_p);
    }
623
#else
624
    UE_rrc_inst[Mod_idP].Info[eNB_index].N310_cnt++;
625
#endif
626 627
}

628
//-------------------------------------------------------------------------------------------//
629
int mac_get_rrc_lite_status(module_id_t Mod_idP,eNB_flag_t enb_flagP,uint8_t index){
630
    //-------------------------------------------------------------------------------------------//
631 632 633
  if (enb_flagP == ENB_FLAG_YES) {
        DevAssert( Mod_idP < NB_eNB_INST );
        DevAssert( index < NUMBER_OF_UE_MAX );
634
        return(eNB_rrc_inst[Mod_idP].Info.UE[index].Status);
635 636 637
    } else {
        DevAssert( Mod_idP < NB_UE_INST );
        DevAssert( index < NB_SIG_CNX_UE );
638
        return(UE_rrc_inst[Mod_idP].Info[index].State);
639
    }
640 641
}

642
//-------------------------------------------------------------------------------------------//
643
int mac_ue_ccch_success_ind(module_id_t Mod_idP, uint8_t eNB_index) {
644
    //-------------------------------------------------------------------------------------------//
645
#if defined(ENABLE_ITTI)
646 647
    {
        MessageDef *message_p;
648

649 650
        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;
651

652 653
        itti_send_msg_to_task (TASK_RRC_UE, Mod_idP + NB_eNB_INST, message_p);
    }
654
#else
655 656
    // 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;
657
#endif
658
    return 0;
659
}