main.c 23.7 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
  OpenAirInterface Admin: openair_admin@eurecom.fr
  OpenAirInterface Tech : openair_tech@eurecom.fr
24
  OpenAirInterface Dev  : openair4g-devel@lists.eurecom.fr
25

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
/*! \file main.c
30
 * \brief top init of Layer 2
31
 * \author  Navid Nikaein and Raymond Knopp
32
 * \date 2010 - 2014
33
 * \version 1.0
34 35
 * \email: navid.nikaein@eurecom.fr
 * @ingroup _mac
36

37
 */
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55

#ifdef USER_MODE
#include "LAYER2/register.h"
#else
#ifdef KERNEL2_6
//#include <linux/config.h>
#include <linux/slab.h>
#endif

#ifdef KERNEL2_4
#include <linux/malloc.h>
#include <linux/wrapper.h>
#endif


#endif //USER_MODE

#include "defs.h"
56
#include "proto.h"
57
#include "extern.h"
Lionel Gauthier's avatar
Lionel Gauthier committed
58
#include "assertions.h"
59 60 61 62
#include "PHY_INTERFACE/extern.h"
#include "PHY_INTERFACE/defs.h"
#include "PHY/defs.h"
#include "SCHED/defs.h"
Lionel Gauthier's avatar
Lionel Gauthier committed
63
#include "LAYER2/PDCP_v10.1.0/pdcp.h"
64 65 66 67 68 69 70 71 72
#include "RRC/LITE/defs.h"
#include "UTIL/LOG/log.h"
#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"
#ifdef PHY_EMUL
#include "SIMULATION/simulation_defs.h"
#endif //PHY_EMUL

#include "SCHED/defs.h"

73
#if FAPI
74 75 76
#include "ff-mac-common.h"
#include "ff-mac-csched-sap.h"
#include "ff-mac-sched-sap.h"
77 78 79
/* for enb_config_get() and Enb_properties_array_t */
#include "enb_config.h"
#endif
80

81
void dl_phy_sync_success(module_id_t   module_idP,
82 83 84 85
                         frame_t       frameP,
                         unsigned char eNB_index,
                         uint8_t            first_sync)   //init as MR
{
86
  LOG_D(MAC,"[UE %d] Frame %d: PHY Sync to eNB_index %d successful \n", module_idP, frameP, eNB_index);
87
#if ! defined(ENABLE_USE_MME)
88

89
  if (first_sync==1) {
90 91 92
    layer2_init_UE(module_idP);
    openair_rrc_ue_init(module_idP,eNB_index);
  } else
93 94
#endif
  {
95
    mac_in_sync_ind(module_idP,frameP,eNB_index);
96
  }
97

98 99
}

100 101
void mrbch_phy_sync_failure(module_id_t module_idP, frame_t frameP, uint8_t free_eNB_index) //init as CH
{
102

103 104 105
  LOG_I(MAC,"[eNB %d] Frame %d: PHY Sync failure \n",module_idP,frameP);
  layer2_init_eNB(module_idP, free_eNB_index);
  openair_rrc_eNB_init(module_idP);
106 107
}

108 109
char layer2_init_eNB(module_id_t module_idP, unsigned char eNB_index)
{
110 111 112 113 114

  return 0;

}

115 116
char layer2_init_UE(module_id_t module_idP)
{
117

118 119 120
  return 0;
}

121 122
void mac_UE_out_of_sync_ind(module_id_t module_idP, frame_t frameP, uint16_t eNB_index)
{
123

124
  //  Mac_rlc_xface->mac_out_of_sync_ind(Mod_id, frameP, eNB_index);
125 126 127
}


128 129
int mac_top_init(int eMBMS_active, char *uecap_xer, uint8_t cba_group_active, uint8_t HO_active)
{
130

131
  module_id_t    Mod_id,i,j;
132 133
  RA_TEMPLATE *RA_template;
  UE_TEMPLATE *UE_template;
134
  int size_bytes1,size_bytes2,size_bits1,size_bits2;
Raymond Knopp's avatar
 
Raymond Knopp committed
135 136 137
  int CC_id;
  int list_el;
  UE_list_t *UE_list;
138 139

  LOG_I(MAC,"[MAIN] Init function start:Nb_UE_INST=%d\n",NB_UE_INST);
140

141
  if (NB_UE_INST>0) {
142
    UE_mac_inst = (UE_MAC_INST*)malloc16(NB_UE_INST*sizeof(UE_MAC_INST));
143

144 145 146 147
    if (UE_mac_inst == NULL) {
      LOG_C(MAC,"[MAIN] Can't ALLOCATE %d Bytes for %d UE_MAC_INST with size %d \n",NB_UE_INST*sizeof(UE_MAC_INST),NB_UE_INST,sizeof(UE_MAC_INST));
      mac_xface->macphy_exit("[MAC][MAIN] not enough memory for UEs \n");
    }
148

149 150 151 152
    LOG_D(MAC,"[MAIN] ALLOCATE %d Bytes for %d UE_MAC_INST @ %p\n",NB_UE_INST*sizeof(UE_MAC_INST),NB_UE_INST,UE_mac_inst);

    bzero(UE_mac_inst,NB_UE_INST*sizeof(UE_MAC_INST));

153
    for(i=0; i<NB_UE_INST; i++) {
154
      ue_init_mac(i);
155 156
    }
  } else {
157
    UE_mac_inst = NULL;
158
  }
159

160
  LOG_I(MAC,"[MAIN] Init function start:Nb_eNB_INST=%d\n",NB_eNB_INST);
161

162
  if (NB_eNB_INST>0) {
163 164 165 166 167 168 169 170 171
    eNB_mac_inst = (eNB_MAC_INST*)malloc16(NB_eNB_INST*sizeof(eNB_MAC_INST));

    if (eNB_mac_inst == NULL) {
      LOG_D(MAC,"[MAIN] can't ALLOCATE %d Bytes for %d eNB_MAC_INST with size %d \n",NB_eNB_INST*sizeof(eNB_MAC_INST*),NB_eNB_INST,sizeof(eNB_MAC_INST));
      mac_xface->macphy_exit("[MAC][MAIN] not enough memory for eNB \n");
    } else {
      LOG_D(MAC,"[MAIN] ALLOCATE %d Bytes for %d eNB_MAC_INST @ %p\n",sizeof(eNB_MAC_INST),NB_eNB_INST,eNB_mac_inst);
      bzero(eNB_mac_inst,NB_eNB_INST*sizeof(eNB_MAC_INST));
    }
172
  } else {
173
    eNB_mac_inst = NULL;
174
  }
175

Raymond Knopp's avatar
 
Raymond Knopp committed
176
  // Initialize Linked-List for Active UEs
177
  for(Mod_id=0; Mod_id<NB_eNB_INST; Mod_id++) {
Raymond Knopp's avatar
 
Raymond Knopp committed
178 179 180 181
    UE_list = &eNB_mac_inst[Mod_id].UE_list;

    UE_list->num_UEs=0;
    UE_list->head=-1;
182
    UE_list->head_ul=-1;
Raymond Knopp's avatar
 
Raymond Knopp committed
183
    UE_list->avail=0;
184 185

    for (list_el=0; list_el<NUMBER_OF_UE_MAX-1; list_el++) {
Raymond Knopp's avatar
 
Raymond Knopp committed
186
      UE_list->next[list_el]=list_el+1;
187
      UE_list->next_ul[list_el]=list_el+1;
Raymond Knopp's avatar
 
Raymond Knopp committed
188
    }
189

Raymond Knopp's avatar
 
Raymond Knopp committed
190
    UE_list->next[list_el]=-1;
191
    UE_list->next_ul[list_el]=-1;
192

193
#ifdef PHY_EMUL
Raymond Knopp's avatar
 
Raymond Knopp committed
194
    Mac_rlc_xface->Is_cluster_head[Mod_id]=2;//0: MR, 1: CH, 2: not CH neither MR
195
#endif
196
    /*#ifdef Rel10
197 198
    int n;
    for (n=0;n<4096;n++)
199
    eNB_mac_inst[Mod_id].MCH_pdu.payload[n] = taus();
200
    //    Mac_rlc_xface->Node_id[Mod_id]=NODE_ID[Mod_id];
201
    #endif*/
202
  }
203

204 205 206
  //  Mac_rlc_xface->frame=Mac_rlc_xface->frame;


207 208
  if (Is_rrc_registered == 1) {
    LOG_I(MAC,"[MAIN] calling RRC\n");
209
#ifndef CELLULAR //nothing to be done yet for cellular
210
    openair_rrc_top_init(eMBMS_active, uecap_xer, cba_group_active,HO_active);
211
#endif
212 213
  } else {
    LOG_I(MAC,"[MAIN] Running without an RRC\n");
214
  }
215

216 217 218
#ifndef USER_MODE
#ifndef PHY_EMUL
  LOG_I(MAC,"[MAIN] add openair2 proc\n");
219
  ////  add_openair2_stats();
220 221 222
#endif
#endif

223
  //init_transport_channels(2);
224 225 226

  // Set up DCIs for TDD 5MHz Config 1..6

227 228
  for (i=0; i<NB_eNB_INST; i++)
    for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
229
      LOG_D(MAC,"[MAIN][eNB %d] CC_id %d initializing RA_template\n",i, CC_id);
230 231
      LOG_D(MAC, "[MSC_NEW][FRAME 00000][MAC_eNB][MOD %02d][]\n", i);

Raymond Knopp's avatar
 
Raymond Knopp committed
232
      RA_template = (RA_TEMPLATE *)&eNB_mac_inst[i].common_channels[CC_id].RA_template[0];
233

234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
      for (j=0; j<NB_RA_PROC_MAX; j++) {
        if (mac_xface->lte_frame_parms->frame_type == TDD) {
          switch (mac_xface->lte_frame_parms->N_RB_DL) {
          case 6:
            size_bytes1 = sizeof(DCI1A_1_5MHz_TDD_1_6_t);
            size_bytes2 = sizeof(DCI1A_1_5MHz_TDD_1_6_t);
            size_bits1 = sizeof_DCI1A_1_5MHz_TDD_1_6_t;
            size_bits2 = sizeof_DCI1A_1_5MHz_TDD_1_6_t;
            break;

          case 25:
            size_bytes1 = sizeof(DCI1A_5MHz_TDD_1_6_t);
            size_bytes2 = sizeof(DCI1A_5MHz_TDD_1_6_t);
            size_bits1 = sizeof_DCI1A_5MHz_TDD_1_6_t;
            size_bits2 = sizeof_DCI1A_5MHz_TDD_1_6_t;
            break;

          case 50:
            size_bytes1 = sizeof(DCI1A_10MHz_TDD_1_6_t);
            size_bytes2 = sizeof(DCI1A_10MHz_TDD_1_6_t);
            size_bits1 = sizeof_DCI1A_10MHz_TDD_1_6_t;
            size_bits2 = sizeof_DCI1A_10MHz_TDD_1_6_t;
            break;

          case 100:
            size_bytes1 = sizeof(DCI1A_20MHz_TDD_1_6_t);
            size_bytes2 = sizeof(DCI1A_20MHz_TDD_1_6_t);
            size_bits1 = sizeof_DCI1A_20MHz_TDD_1_6_t;
            size_bits2 = sizeof_DCI1A_20MHz_TDD_1_6_t;
            break;

          default:
            size_bytes1 = sizeof(DCI1A_1_5MHz_TDD_1_6_t);
            size_bytes2 = sizeof(DCI1A_1_5MHz_TDD_1_6_t);
            size_bits1 = sizeof_DCI1A_1_5MHz_TDD_1_6_t;
            size_bits2 = sizeof_DCI1A_1_5MHz_TDD_1_6_t;
            break;
271
          }
272 273 274 275 276 277 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 306 307 308

        } else {
          switch (mac_xface->lte_frame_parms->N_RB_DL) {
          case 6:
            size_bytes1 = sizeof(DCI1A_1_5MHz_FDD_t);
            size_bytes2 = sizeof(DCI1A_1_5MHz_FDD_t);
            size_bits1 = sizeof_DCI1A_1_5MHz_FDD_t;
            size_bits2 = sizeof_DCI1A_1_5MHz_FDD_t;
            break;

          case 25:
            size_bytes1 = sizeof(DCI1A_5MHz_FDD_t);
            size_bytes2 = sizeof(DCI1A_5MHz_FDD_t);
            size_bits1 = sizeof_DCI1A_5MHz_FDD_t;
            size_bits2 = sizeof_DCI1A_5MHz_FDD_t;
            break;

          case 50:
            size_bytes1 = sizeof(DCI1A_10MHz_FDD_t);
            size_bytes2 = sizeof(DCI1A_10MHz_FDD_t);
            size_bits1 = sizeof_DCI1A_10MHz_FDD_t;
            size_bits2 = sizeof_DCI1A_10MHz_FDD_t;
            break;

          case 100:
            size_bytes1 = sizeof(DCI1A_20MHz_FDD_t);
            size_bytes2 = sizeof(DCI1A_20MHz_FDD_t);
            size_bits1 = sizeof_DCI1A_20MHz_FDD_t;
            size_bits2 = sizeof_DCI1A_20MHz_FDD_t;
            break;

          default:
            size_bytes1 = sizeof(DCI1A_1_5MHz_FDD_t);
            size_bytes2 = sizeof(DCI1A_1_5MHz_FDD_t);
            size_bits1 = sizeof_DCI1A_1_5MHz_FDD_t;
            size_bits2 = sizeof_DCI1A_1_5MHz_FDD_t;
            break;
309
          }
310 311 312 313 314 315 316 317 318 319 320
        }

        memcpy((void *)&RA_template[j].RA_alloc_pdu1[0],(void *)&RA_alloc_pdu,size_bytes1);
        memcpy((void *)&RA_template[j].RA_alloc_pdu2[0],(void *)&DLSCH_alloc_pdu1A,size_bytes2);
        RA_template[j].RA_dci_size_bytes1 = size_bytes1;
        RA_template[j].RA_dci_size_bytes2 = size_bytes2;
        RA_template[j].RA_dci_size_bits1  = size_bits1;
        RA_template[j].RA_dci_size_bits2  = size_bits2;

        RA_template[j].RA_dci_fmt1        = format1A;
        RA_template[j].RA_dci_fmt2        = format1A;
321
      }
322 323

      memset (&eNB_mac_inst[i].eNB_stats,0,sizeof(eNB_STATS));
Raymond Knopp's avatar
 
Raymond Knopp committed
324
      UE_template = (UE_TEMPLATE *)&eNB_mac_inst[i].UE_list.UE_template[CC_id][0];
325 326 327 328 329

      for (j=0; j<NUMBER_OF_UE_MAX; j++) {
        UE_template[j].rnti=0;
        // initiallize the eNB to UE statistics
        memset (&eNB_mac_inst[i].UE_list.eNB_UE_stats[CC_id][j],0,sizeof(eNB_UE_STATS));
330
      }
Raymond Knopp's avatar
 
Raymond Knopp committed
331
    }
332 333


334
  //ICIC init param
335
#ifdef ICIC
336
  uint8_t SB_size;
337 338 339 340
  SB_size=mac_xface->get_SB_size(mac_xface->lte_frame_parms->N_RB_DL);

  srand (time(NULL));

341 342
  for(j=0; j<NB_eNB_INST; j++)
    for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
Raymond Knopp's avatar
 
Raymond Knopp committed
343 344 345 346
      eNB_mac_inst[j][CC_id].sbmap_conf.first_subframe=0;
      eNB_mac_inst[j][CC_id].sbmap_conf.periodicity=10;
      eNB_mac_inst[j][CC_id].sbmap_conf.sb_size=SB_size;
      eNB_mac_inst[j][CC_id].sbmap_conf.nb_active_sb=1;
347

348
      for(i=0; i<NUMBER_OF_SUBBANDS; i++) {
Raymond Knopp's avatar
 
Raymond Knopp committed
349
        eNB_mac_inst[j][CC_id].sbmap_conf.sbmap[i]=1;
350
      }
351

Raymond Knopp's avatar
 
Raymond Knopp committed
352
      eNB_mac_inst[j][CC_id].sbmap_conf.sbmap[rand()%NUMBER_OF_SUBBANDS]=0;
353

354 355
    }

356
#endif
357
  //end ALU's algo
358

Cedric Roux's avatar
Cedric Roux committed
359
#if FAPI
360 361 362 363
  /* setup FAPI interface */
  /* this should be done differently/somewhere else */
  const Enb_properties_array_t *conf = enb_config_get();

364 365 366 367
  for (i=0; i<NB_eNB_INST; i++) {
    eNB_mac_inst[i].fapi = init_fapi();
    AssertFatal(eNB_mac_inst[i].fapi != NULL, "error calling init_fapi()\n");

368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
    struct CschedCellConfigReqParameters            p;
    struct CschedCellConfigCnfParameters            r;
    struct CschedCellConfigReqParametersListElement l;
    struct SiMessageListElement_s                   sib23;
#if MAX_NUM_CCs > 1
#error we do not work with FAPI with more than 1 CC yet
#endif

    p.nr_carriers = 1;
    p.ccConfigList[0] = &l;
    p.nr_vendorSpecificList = 0;

    l.puschHoppingOffset                = conf->properties[i]->pusch_hoppingOffset[0];
    l.hoppingMode                       = conf->properties[i]->pusch_hoppingMode[0];
    l.nSb                               = conf->properties[i]->pusch_n_SB[0];
    switch (conf->properties[i]->phich_resource[0]) {
    case oneSixth: l.phichResource      = PHICH_R_ONE_SIXTH; break;
    case half:     l.phichResource      = PHICH_R_HALF;      break;
    case one:      l.phichResource      = PHICH_R_ONE;       break;
    case two:      l.phichResource      = PHICH_R_TWO;       break;
    }
    switch (conf->properties[i]->phich_duration[0]) {
    case normal:   l.phichDuration      = ff_normal;   break;
    case extended: l.phichDuration      = ff_extended; break;
    }
    l.initialNrOfPdcchOfdmSymbols       = 0;        LOG_W(MAC, "set initialNrOfPdcchOfdmSymbols to its real value\n");
    l.siConfiguration.sfn               = 0;        LOG_W(MAC, "what to set for siConfiguration.sfn?\n");
    /* when mac_top_init is called, the SIBs are not generated yet, so we don't
       know their sizes. As a quick and dirty hack, let's hardcode them.
       It's "safe" though because in openair2/RRC/LITE/rrc_eNB.c we crash
       if the values are not the ones we put here */
    /* the length of sib1 is hardcoded to 15, see also openair2/RRC/LITE/rrc_eNB.c */
    l.siConfiguration.sib1Length        = 15;       LOG_W(MAC, "get the real siConfiguration.sib1Length\n");
    l.siConfiguration.siWindowLength    = 1;        LOG_W(MAC, "get the real siConfiguration.siWindowLength\n");
    l.siConfiguration.nrSI_Message_List = 1;
    l.siConfiguration.siMessageList     = &sib23;
    sib23.periodicity                   = 8;        LOG_W(MAC, "get the real sib23.periodicity\n");
    /* the length of sib2/3 is hardcoded to 30, see also openair2/RRC/LITE/rrc_eNB.c */
    sib23.length                        = 30;       LOG_W(MAC, "get the real sib23.length\n");
    l.ulBandwidth                       = conf->properties[i]->N_RB_DL[0];
    l.dlBandwidth                       = conf->properties[i]->N_RB_DL[0];
    switch (conf->properties[i]->prefix_type[0]) {
    case NORMAL:
      l.ulCyclicPrefixLength            = ff_normal;
      l.dlCyclicPrefixLength            = ff_normal;
      break;
    case EXTENDED:
      l.ulCyclicPrefixLength            = ff_extended;
      l.dlCyclicPrefixLength            = ff_extended;
      break;
    }
    l.antennaPortsCount                 = conf->properties[i]->nb_antennas_tx[0];   LOG_W(MAC, "is antennaPortsCount equal to nb_antennas_tx?\n");
    switch (conf->properties[i]->frame_type[0]) {
    case FDD:  l.duplexMode             = DFDD; break;
    case TDD:  l.duplexMode             = DTDD; break;
    }
    l.subframeAssignment                = conf->properties[i]->tdd_config[0];
    l.specialSubframePatterns           = conf->properties[i]->tdd_config_s[0];
#warning TODO: mbsfn stuff (when mbsfn_SubframeConfigPresent will be added to the structure CschedCellConfigReqParametersListElement)
    l.prachConfigurationIndex           = conf->properties[i]->prach_config_index[0];
    l.prachFreqOffset                   = conf->properties[i]->prach_freq_offset[0];
    l.raResponseWindowSize              = conf->properties[i]->rach_raResponseWindowSize[0];
    l.macContentionResolutionTimer      = conf->properties[i]->rach_macContentionResolutionTimer[0];
    l.maxHarqMsg3Tx                     = conf->properties[i]->rach_maxHARQ_Msg3Tx[0];
#warning TODO: get real n1PucchAn (fix pucch_n1_AN thing for Rel10, remove #ifndefs)
    l.n1PucchAn                         = 0; //conf->properties[i]->pucch_n1_AN[0];
    l.deltaPucchShift                   = conf->properties[i]->pucch_delta_shift[0];
    l.nrbCqi                            = conf->properties[i]->pucch_nRB_CQI[0];
    l.ncsAn                             = conf->properties[i]->pucch_nCS_AN[0];
#warning TODO: what about srs_enable of the config file (it's not in FAPI)?
    l.srsSubframeConfiguration          = conf->properties[i]->srs_SubframeConfig[0];
    l.srsSubframeOffset                 = 0;        LOG_W(MAC, "what value for srsSubframeOffset?\n");
    l.srsBandwidthConfiguration         = conf->properties[i]->srs_BandwidthConfig[0];
    switch (conf->properties[i]->srs_MaxUpPts[0]) {
    case TRUE:  l.srsMaxUpPts           = true;  break;
    case FALSE: l.srsMaxUpPts           = false; break;
    }
#warning TODO: what about srs_ackNackST of the config file (it's not in FAPI)?
    switch (conf->properties[i]->pusch_enable64QAM[0]) {
    case TRUE:  l.enable64Qam           = true;  break;
    case FALSE: l.enable64Qam           = false; break;
    }
    l.carrierIndex                      = 0;

    LOG_I(MAC, "calling CschedCellConfigReq\n");
    CschedCellConfigReq(eNB_mac_inst[i].fapi->sched, &p);
    LOG_I(MAC, "calling CschedCellConfigCnf\n");
    CschedCellConfigCnf(eNB_mac_inst[i].fapi, &r);
    if (r.result != ff_SUCCESS) { LOG_E(MAC, "CschedCellConfigCnf failed\n"); abort(); }
    LOG_I(MAC, "CschedCellConfigCnf succeeded\n");
  }
459 460 461

#endif

462
  LOG_I(MAC,"[MAIN][INIT] Init function finished\n");
463 464 465 466 467 468

  return(0);

}


469 470
int mac_init_global_param(void)
{
471

472

473 474 475
  Mac_rlc_xface = NULL;
  LOG_I(MAC,"[MAIN] CALLING RLC_MODULE_INIT...\n");

476
  if (rlc_module_init()!=0) {
477
    return(-1);
478
  }
479 480 481 482 483 484

  LOG_I(MAC,"[MAIN] RLC_MODULE_INIT OK, malloc16 for mac_rlc_xface...\n");

  Mac_rlc_xface = (MAC_RLC_XFACE*)malloc16(sizeof(MAC_RLC_XFACE));
  bzero(Mac_rlc_xface,sizeof(MAC_RLC_XFACE));

485 486 487
  if(Mac_rlc_xface == NULL) {
    LOG_E(MAC,"[MAIN] FATAL EROOR: Could not allocate memory for Mac_rlc_xface !!!\n");
    return (-1);
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518

  }

  LOG_I(MAC,"[MAIN] malloc16 OK, mac_rlc_xface @ %p\n",(void *)Mac_rlc_xface);

  //  mac_xface->macphy_data_ind=macphy_data_ind;
  mac_xface->mrbch_phy_sync_failure=mrbch_phy_sync_failure;
  mac_xface->dl_phy_sync_success=dl_phy_sync_success;
  mac_xface->out_of_sync_ind=mac_out_of_sync_ind;

  //  Mac_rlc_xface->macphy_exit=  mac_xface->macphy_exit;
  //  Mac_rlc_xface->frame = 0;
  //  Mac_rlc_xface->mac_config_req=mac_config_req;
  //  Mac_rlc_xface->mac_meas_req=mac_meas_req;
  //  Mac_rlc_xface->rrc_rlc_config_req=rrc_rlc_config_req;
  //  Mac_rlc_xface->rrc_rlc_data_req=rrc_rlc_data_req;
  //  Mac_rlc_xface->rrc_rlc_register_rrc=rrc_rlc_register_rrc;

  //  Mac_rlc_xface->rrc_mac_config_req=rrc_mac_config_req;

  //  LOG_I(MAC,"[MAIN] INIT_GLOBAL_PARAM: Mac_rlc_xface=%p,rrc_rlc_register_rrc =%p\n",Mac_rlc_xface,Mac_rlc_xface->rrc_rlc_register_rrc);

  //  Mac_rlc_xface->mac_rlc_data_req=mac_rlc_data_req;
  //  Mac_rlc_xface->mac_rlc_data_ind=mac_rlc_data_ind;
  //  Mac_rlc_xface->mac_rlc_status_ind=mac_rlc_status_ind;
  //  Mac_rlc_xface->pdcp_data_req=pdcp_data_req;
  //  Mac_rlc_xface->mrbch_phy_sync_failure=mrbch_phy_sync_failure;
  //  Mac_rlc_xface->dl_phy_sync_success=dl_phy_sync_success;

  LOG_I(MAC,"[MAIN] RLC interface setup and init\n");
  rrc_init_global_param();
519

520 521 522 523 524 525 526 527 528 529 530 531
#ifdef USER_MODE
  pdcp_layer_init ();
#else
  pdcp_module_init ();
#endif

  LOG_I(MAC,"[MAIN] Init Global Param Done\n");

  return 0;
}


532 533
void mac_top_cleanup(void)
{
534

535 536 537
#ifndef USER_MODE
  pdcp_module_cleanup ();
#endif
538

539
  if (NB_UE_INST>0) {
540
    free (UE_mac_inst);
541
  }
542

543
  if (NB_eNB_INST>0) {
544
    free(eNB_mac_inst);
545
  }
546

547 548 549
  free( Mac_rlc_xface);
}

550 551
int l2_init(LTE_DL_FRAME_PARMS *frame_parms,int eMBMS_active, char *uecap_xer,uint8_t cba_group_active, uint8_t HO_active)
{
552 553 554 555 556 557 558



  LOG_I(MAC,"[MAIN] MAC_INIT_GLOBAL_PARAM IN...\n");
  //    NB_NODE=2;
  //    NB_INST=2;

559
  Is_rrc_registered=0;
560
  mac_init_global_param();
561
  Is_rrc_registered=1;
562

Cedric Roux's avatar
Cedric Roux committed
563
  mac_xface->macphy_init = mac_top_init;
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581
#ifndef USER_MODE
  mac_xface->macphy_exit = openair_sched_exit;
#else
  mac_xface->macphy_exit=(void (*)(const char*)) exit;
#endif
  LOG_I(MAC,"[MAIN] init eNB MAC functions  \n");
  mac_xface->eNB_dlsch_ulsch_scheduler = eNB_dlsch_ulsch_scheduler;
  mac_xface->get_dci_sdu               = get_dci_sdu;
  mac_xface->fill_rar                  = fill_rar;
  mac_xface->initiate_ra_proc          = initiate_ra_proc;
  mac_xface->cancel_ra_proc            = cancel_ra_proc;
  mac_xface->SR_indication             = SR_indication;
  mac_xface->rx_sdu                    = rx_sdu;
  mac_xface->get_dlsch_sdu             = get_dlsch_sdu;
  mac_xface->get_eNB_UE_stats          = get_eNB_UE_stats;
  mac_xface->get_transmission_mode     = get_transmission_mode;
  mac_xface->get_rballoc               = get_rballoc;
  mac_xface->get_nb_rb                 = conv_nprb;
582
  mac_xface->get_prb                   = get_prb;
583
  //  mac_xface->get_SB_size               = Get_SB_size;
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609
  mac_xface->get_subframe_direction    = get_subframe_direction;
  mac_xface->Msg3_transmitted          = Msg3_tx;
  mac_xface->Msg1_transmitted          = Msg1_tx;
  mac_xface->ra_failed                 = ra_failed;
  mac_xface->ra_succeeded              = ra_succeeded;

  LOG_I(MAC,"[MAIN] init UE MAC functions \n");
  mac_xface->ue_decode_si              = ue_decode_si;
  mac_xface->ue_send_sdu               = ue_send_sdu;
#ifdef Rel10
  mac_xface->ue_send_mch_sdu           = ue_send_mch_sdu;
  mac_xface->ue_query_mch              = ue_query_mch;
#endif
  mac_xface->ue_get_SR                 = ue_get_SR;
  mac_xface->ue_get_sdu                = ue_get_sdu;
  mac_xface->ue_get_rach               = ue_get_rach;
  mac_xface->ue_process_rar            = ue_process_rar;
  mac_xface->ue_scheduler              = ue_scheduler;
  mac_xface->process_timing_advance    = process_timing_advance;


  LOG_I(MAC,"[MAIN] PHY Frame configuration \n");
  mac_xface->lte_frame_parms = frame_parms;

  mac_xface->get_ue_active_harq_pid = get_ue_active_harq_pid;
  mac_xface->get_PL                 = get_PL;
610 611 612 613 614
  mac_xface->get_RSRP               = get_RSRP;
  mac_xface->get_RSRQ               = get_RSRQ;
  mac_xface->get_RSSI               = get_RSSI;
  mac_xface->get_n_adj_cells        = get_n_adj_cells;
  mac_xface->get_rx_total_gain_dB   = get_rx_total_gain_dB;
615 616 617 618 619 620 621
  mac_xface->get_Po_NOMINAL_PUSCH   = get_Po_NOMINAL_PUSCH;
  mac_xface->get_num_prach_tdd      = get_num_prach_tdd;
  mac_xface->get_fid_prach_tdd      = get_fid_prach_tdd;
  mac_xface->get_deltaP_rampup      = get_deltaP_rampup;
  mac_xface->computeRIV             = computeRIV;
  mac_xface->get_TBS_DL             = get_TBS_DL;
  mac_xface->get_TBS_UL             = get_TBS_UL;
622
  mac_xface->get_nCCE_max           = get_nCCE_mac;
623
  mac_xface->get_nCCE_offset        = get_nCCE_offset;
624 625 626 627 628 629
  mac_xface->get_ue_mode            = get_ue_mode;
  mac_xface->phy_config_sib1_eNB    = phy_config_sib1_eNB;
  mac_xface->phy_config_sib1_ue     = phy_config_sib1_ue;

  mac_xface->phy_config_sib2_eNB        = phy_config_sib2_eNB;
  mac_xface->phy_config_sib2_ue         = phy_config_sib2_ue;
630
  mac_xface->phy_config_afterHO_ue      = phy_config_afterHO_ue;
631 632 633 634 635 636
#ifdef Rel10
  mac_xface->phy_config_sib13_eNB        = phy_config_sib13_eNB;
  mac_xface->phy_config_sib13_ue         = phy_config_sib13_ue;
#endif
#ifdef CBA
  mac_xface->phy_config_cba_rnti         = phy_config_cba_rnti ;
637
#endif
638
  mac_xface->estimate_ue_tx_power        = estimate_ue_tx_power;
639
  mac_xface->phy_config_meas_ue          = phy_config_meas_ue;
640
  mac_xface->phy_reset_ue    = phy_reset_ue;
641 642 643 644

  mac_xface->phy_config_dedicated_eNB    = phy_config_dedicated_eNB;
  mac_xface->phy_config_dedicated_ue     = phy_config_dedicated_ue;

645 646 647
  mac_xface->get_lte_frame_parms        = get_lte_frame_parms;
  mac_xface->get_mu_mimo_mode           = get_mu_mimo_mode;

648
  mac_xface->get_hundred_times_delta_TF = get_hundred_times_delta_IF_mac;
649 650 651 652 653
  mac_xface->get_target_pusch_rx_power     = get_target_pusch_rx_power;
  mac_xface->get_target_pucch_rx_power     = get_target_pucch_rx_power;

  mac_xface->get_prach_prb_offset       = get_prach_prb_offset;
  mac_xface->is_prach_subframe          = is_prach_subframe;
654

655 656
#ifdef Rel10
  mac_xface->get_mch_sdu                 = get_mch_sdu;
657 658
  mac_xface->phy_config_dedicated_scell_eNB= phy_config_dedicated_scell_eNB;
  mac_xface->phy_config_dedicated_scell_ue= phy_config_dedicated_scell_ue;
659

660 661 662 663 664
#endif

  mac_xface->get_PHR = get_PHR;
  LOG_D(MAC,"[MAIN] ALL INIT OK\n");

Raymond Knopp's avatar
 
Raymond Knopp committed
665
  mac_xface->macphy_init(eMBMS_active,uecap_xer,cba_group_active,HO_active);
666 667 668 669

  //Mac_rlc_xface->Is_cluster_head[0] = 1;
  //Mac_rlc_xface->Is_cluster_head[1] = 0;

670 671 672 673
#if FAPI
  mac_xface->fapi_ul_ack_nack = fapi_ul_ack_nack;
  mac_xface->fapi_dl_ack_nack = fapi_dl_ack_nack;
#endif
674

675 676 677
  return(1);
}