main_nb_iot.c 6.48 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 32 33
/*
 * 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
 */

/*! \file main.c
 * \brief top init of Layer 2
 * \author  Navid Nikaein and Raymond Knopp, Michele Paffetti
 * \date 2010 - 2014
 * \version 1.0
 * \email: navid.nikaein@eurecom.fr, michele.paffetti@studio.unibo.it
 * @ingroup _mac

 */


#include "asn1_constants.h"
Nick Ho's avatar
Nick Ho committed
34 35
#include "defs_nb_iot.h"
#include "proto_nb_iot.h"
36
//#include "extern.h"
37 38
#include "RRC/LITE/proto_nb_iot.h"

39 40 41 42 43 44 45 46

int mac_init_global_param_NB(void)
{

//XXX commented parts are called in the parallel path of OAI
//  Mac_rlc_xface = NULL;
//  LOG_I(MAC,"[MAIN] CALLING RLC_MODULE_INIT...\n");
//
47 48 49
  if (rlc_module_init()!=0) {
    return(-1);
 }
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
//
//  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));
//
//  if(Mac_rlc_xface == NULL) {
//    LOG_E(MAC,"[MAIN] FATAL EROOR: Could not allocate memory for Mac_rlc_xface !!!\n");
//    return (-1);
//
//  }
//
//  LOG_I(MAC,"[MAIN] malloc16 OK, mac_rlc_xface @ %p\n",(void *)Mac_rlc_xface);
//
//  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=rrc_out_of_sync_ind;
//
//  LOG_I(MAC,"[MAIN] RLC interface (mac_rlc_xface) setup and init (maybe no mre used??)\n");

  LOG_I(MAC,"[MAIN] RRC NB-IoT initialization of global params\n");
71
  rrc_init_global_param_NB_IoT();
72 73


74 75 76 77 78 79
  LOG_I(MAC,"[MAIN] PDCP layer init\n");
#ifdef USER_MODE
  pdcp_layer_init ();
#else
  pdcp_module_init ();
#endif
80 81 82 83 84 85
//
//  LOG_I(MAC,"[MAIN] Init Global Param Done\n");

  return 0;
}

86
int mac_top_init_NB()
Nick Ho's avatar
Nick Ho committed
87 88 89 90
{

  module_id_t    Mod_id,i,j;
  RA_TEMPLATE_NB *RA_template;
91
  UE_TEMPLATE_NB_IoT *UE_template;
Nick Ho's avatar
Nick Ho committed
92 93 94
  int size_bytes1,size_bytes2,size_bits1,size_bits2;
  int CC_id;
  int list_el;
95
  UE_list_NB_t *UE_list; //XXX to review if elements are correct
Nick Ho's avatar
Nick Ho committed
96 97 98

  // delete the part to init the UE_INST

99
  //XXX NB_eNB_INST is global and set in lte-softmodem = 1 always (should be modified???)
Nick Ho's avatar
Nick Ho committed
100 101 102 103 104 105 106 107 108 109
  LOG_I(MAC,"[MAIN] Init function start:Nb_eNB_INST=%d\n",NB_eNB_INST);

  if (NB_eNB_INST>0) {
    eNB_mac_inst_NB = (eNB_MAC_INST_NB*)malloc16(NB_eNB_INST*sizeof(eNB_MAC_INST_NB));

    if (eNB_mac_inst_NB == NULL) {
      LOG_D(MAC,"[MAIN] can't ALLOCATE %zu Bytes for %d eNB_MAC_INST with size %zu \n",NB_eNB_INST*sizeof(eNB_MAC_INST_NB*),NB_eNB_INST,sizeof(eNB_MAC_INST_NB));
      LOG_I(MAC,"[MAC][MAIN] not enough memory for eNB \n");
      exit(1);
    } else {
110
      LOG_D(MAC,"[MAIN] ALLOCATE %zu Bytes for %d eNB_MAC_INST @ %p\n",sizeof(eNB_MAC_INST),NB_eNB_INST,eNB_mac_inst_NB);
Nick Ho's avatar
Nick Ho committed
111 112 113
      bzero(eNB_mac_inst_NB,NB_eNB_INST*sizeof(eNB_MAC_INST_NB));
    }
  } else {
114
	LOG_I (MAC, "No instance allocated for the MAC layer (NB-IoT)\n");
Nick Ho's avatar
Nick Ho committed
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
    eNB_mac_inst_NB = NULL;
  }

  // Initialize Linked-List for Active UEs
  for(Mod_id=0; Mod_id<NB_eNB_INST; Mod_id++) {
    UE_list = &eNB_mac_inst_NB[Mod_id].UE_list;

    UE_list->num_UEs=0;
    UE_list->head=-1;
    UE_list->head_ul=-1;
    UE_list->avail=0;

    for (list_el=0; list_el<NUMBER_OF_UE_MAX-1; list_el++) {
      UE_list->next[list_el]=list_el+1;
      UE_list->next_ul[list_el]=list_el+1;
    }

    UE_list->next[list_el]=-1;
    UE_list->next_ul[list_el]=-1;

  }

  if (Is_rrc_nb_iot_registered == 1) {
138
    LOG_I(MAC,"[MAIN] calling RRC NB-IoT\n");
Nick Ho's avatar
Nick Ho committed
139
#ifndef CELLULAR //nothing to be done yet for cellular
140
    openair_rrc_top_init_eNB_NB();
Nick Ho's avatar
Nick Ho committed
141 142 143 144 145 146 147 148 149
#endif
  } else {
    LOG_I(MAC,"[MAIN] Running without an RRC\n");
  }

  // initialization for the RA template

  for (i=0; i<NB_eNB_INST; i++)
    for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
150
      LOG_D(MAC,"[MAIN][eNB %d] CC_id %d initializing RA_template (NB-IoT)\n",i, CC_id);
Nick Ho's avatar
Nick Ho committed
151 152
      LOG_D(MAC, "[MSC_NEW][FRAME 00000][MAC_eNB][MOD %02d][]\n", i);

153
      RA_template = (RA_TEMPLATE_NB *)&eNB_mac_inst_NB[i].common_channels[CC_id].RA_template[0];
Nick Ho's avatar
Nick Ho committed
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169

      for (j=0; j<NB_RA_PROC_MAX; j++) {
        size_bytes1 = sizeof(DCIN1_RAR_t);
        size_bytes2 = sizeof(DCIN1_t);
        size_bits1 = sizeof_DCIN1_RAR_t;
        size_bits2 = sizeof_DCIN1_t;

        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);//DLSCH_alloc_pdu1A global!!!!!!

        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        = DCIFormatN1_RAR;
170
        RA_template[j].RA_dci_fmt2        = DCIFormatN1; //for MSG4
Nick Ho's avatar
Nick Ho committed
171 172 173
      }

      memset (&eNB_mac_inst_NB[i].eNB_stats,0,sizeof(eNB_STATS_NB));
174
      UE_template = (UE_TEMPLATE_NB_IoT *)&eNB_mac_inst_NB[i].UE_list.UE_template[CC_id][0];
Nick Ho's avatar
Nick Ho committed
175 176 177 178 179 180 181 182 183

      for (j=0; j<NUMBER_OF_UE_MAX; j++) {
        UE_template[j].rnti=0;
        // initiallize the eNB to UE statistics
        memset (&eNB_mac_inst_NB[i].UE_list.eNB_UE_stats[CC_id][j],0,sizeof(eNB_UE_STATS_NB));
      }
    }


184
  //ICIC not used
Nick Ho's avatar
Nick Ho committed
185

186
  LOG_I(MAC,"[MAIN][INIT][NB-IoT] Init function finished\n");
Nick Ho's avatar
Nick Ho committed
187 188 189 190 191

  return(0);

}

192 193 194 195

int l2_init_eNB_NB()
{

Nick Ho's avatar
Nick Ho committed
196
  LOG_I(MAC,"[MAIN] Mapping L2 IF-Module functions\n");
197 198 199 200 201
  IF_Module_init_L2();

  LOG_I(MAC,"[MAIN] MAC_INIT_GLOBAL_PARAM NB-IoT IN...\n");

  Is_rrc_nb_iot_registered=0;
Nick Ho's avatar
Nick Ho committed
202
  mac_init_global_param_NB();
203 204
  Is_rrc_nb_iot_registered=1;

Nick Ho's avatar
Nick Ho committed
205

206
  LOG_D(MAC,"[MAIN][NB-IoT] ALL INIT OK\n");
207

208 209
//    mac_xface->macphy_init(eMBMS_active,uecap_xer,cba_group_active,HO_active); (old mac_top_init)
  mac_top_init_NB();
210 211 212 213

  return(1);
}