main_NB_IoT.c 9.53 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * 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
 */
21
/*! \file main_NB_IoT.c
22
 * \brief top init of Layer 2
23 24 25
 * \author  NTUST BMW Lab./Nick HO, Xavier LIU, Calvin HSU
 * \date 2017 - 2018
 * \email: nick133371@gmail.com, sephiroth7277@gmail.com , kai-hsiang.hsu@eurecom.fr
26
 * \version 1.0
27
 *
28 29 30
 */


31 32 33 34
//#include "asn1_constants.h"
#include "LAYER2/MAC/defs_NB_IoT.h"
#include "LAYER2/MAC/proto_NB_IoT.h"
#include "LAYER2/MAC/extern_NB_IoT.h"
35
#include "vars_NB_IoT.h"
36
#include "RRC/LITE/proto_NB_IoT.h"
37

38 39 40
#define NUM_USS_PP 3
#define USER_NUM_USS 10

41
int mac_init_global_param_NB_IoT(void)
42
{
43 44 45 46 47 48 49
  ///// removed since already called by mac_init_global_param //////////////
  /*
   if (rlc_module_init()!=0) {
     return(-1);
   }
   */
  /////////////////////////////////////////////////////////////////////////////
50 51
 // LOG_I(MAC,"[MAIN] RRC NB-IoT initialization of global params\n");
 // rrc_init_global_param_NB_IoT();
52

53 54
 ///// removed since already called by mac_init_global_param //////////////
  /*
55
  LOG_I(MAC,"[MAIN] PDCP layer init\n");
56
  #ifdef USER_MODE
57
  pdcp_layer_init ();
58
  #else
59
  pdcp_module_init ();
60 61 62
  #endif
  */
  ////////////////////////////////////////////////////////////////////////
63 64 65
  return 0;
}

66 67

// Initial function of the intialization for NB-IoT MAC
68
void init_mac_NB_IoT(eNB_MAC_INST_NB_IoT *mac_inst)
Nick Ho's avatar
Nick Ho committed
69
{
70
  int32_t i, j, k;  
71 72

  LOG_I(MAC,"[NB-IoT] MAC start initialization\n");
73 74 75 76 77 78
  
  for(i=0;i<64;++i)
  {
    mac_inst->sib1_flag[i] = 0;
    mac_inst->sib1_count[i] = 0;
  }
Nick Ho's avatar
Nick Ho committed
79
    //rrc_mac_config_req_NB_IoT(&mac_inst->rrc_config, 1, 1, 0, 0);
80 81 82 83 84 85 86 87 88 89 90 91
  init_tool_sib1(mac_inst);

  //  output handler 
  //  RA
  mac_inst->RA_msg2_list.head = (RA_TEMPLATE_NB_IoT *)0;
  mac_inst->RA_msg3_list.head = (RA_TEMPLATE_NB_IoT *)0;
  mac_inst->RA_msg4_list.head = (RA_TEMPLATE_NB_IoT *)0;
  mac_inst->RA_msg2_list.tail = (RA_TEMPLATE_NB_IoT *)0;
  mac_inst->RA_msg3_list.tail = (RA_TEMPLATE_NB_IoT *)0;
  mac_inst->RA_msg4_list.tail = (RA_TEMPLATE_NB_IoT *)0;

  sib1_NB_IoT_sched_t *config = &mac_inst->rrc_config.sib1_NB_IoT_sched_config;
Nick Ho's avatar
Nick Ho committed
92
   
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
  // DLSF Table
  init_dlsf_info(mac_inst, &DLSF_information);

  //  init sib1 tool
  //int repetition_pattern = 1;// 1:every2frame, 2:every4frame, 3:every8frame, 4:every16frame
  for(i=0;i<8;++i){
    mac_inst->sib1_flag[(i<<1)+config->starting_rf] = 1;
  }

  for(i=0, j=0;i<64;++i){
    if(mac_inst->sib1_flag[i]==1){
      ++j;
    }
    mac_inst->sib1_count[i]=j;
  }
Nick Ho's avatar
Nick Ho committed
108
//LOG_D(MAC,"%d", mac_inst->sib1_period);
109
  for(i=0, j=0;i<640;++i){
Nick Ho's avatar
Nick Ho committed
110
    //LOG_D(MAC,"*%d", i);
111 112 113
    if(is_dlsf(mac_inst, i)){
      ++j;
    }
Nick Ho's avatar
Nick Ho committed
114
    //LOG_D(MAC,"-");
115 116 117 118 119
    if(i%10==9){
      mac_inst->dlsf_table[i/10] = j;
    }
  }

120 121
  mac_inst->rrc_config.si_window_length = ms160;
  mac_inst->rrc_config.sibs_NB_IoT_sched[0].si_periodicity = rf64;
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158

  for(i=0;i<256;++i){
    mac_inst->sibs_table[i] = -1;
  }
  for(j=0;j<6;++j){
    if(0x0 != mac_inst->rrc_config.sibs_NB_IoT_sched[j].sib_mapping_info){
      k = mac_inst->rrc_config.sibs_NB_IoT_sched[j].si_periodicity / mac_inst->rrc_config.si_window_length;
      for(i=0;i<(256/k);++i){
        mac_inst->sibs_table[(i*k)+j] = j;
      }
    }
  }

  mac_inst->schedule_subframe_DL = 0;
  mac_inst->schedule_subframe_UL = 0;

  available_resource_DL = available_resource_DL_last = (available_resource_DL_t *)0;

  //  init downlink list 0-100
  init_dl_list(mac_inst);

  for(i=0; i<MAX_NUMBER_OF_UE_MAX_NB_IoT; ++i){
    mac_inst->RA_template[i].active = 0;
    mac_inst->RA_template[i].msg3_retransmit_count = 0;
    mac_inst->RA_template[i].msg4_retransmit_count = 0;
    mac_inst->RA_template[i].ta = 0;
    mac_inst->RA_template[i].preamble_index = 0;
    mac_inst->RA_template[i].ue_rnti = 0x0;
    mac_inst->RA_template[i].ra_rnti = 0x0;
    mac_inst->RA_template[i].next = (RA_TEMPLATE_NB_IoT *)0;
    mac_inst->RA_template[i].prev = (RA_TEMPLATE_NB_IoT *)0;
    mac_inst->RA_template[i].wait_msg4_ack = 0;
    mac_inst->RA_template[i].wait_msg3_ack = 0;
  }
  //3 CE level USS list
  mac_inst->UE_list_spec = (UE_list_NB_IoT_t*)malloc(NUM_USS_PP*sizeof(UE_list_NB_IoT_t));
  //initial UE list
159
  LOG_I(MAC,"[NB-IoT] Initial UE list\n");
160 161 162 163

  mac_inst->num_uss_list = NUM_USS_PP;
  for(i=0;i<NUM_USS_PP;++i)
  {
164 165
    rrc_mac_config_req_NB_IoT(0,0,0,NULL,NULL,NULL,NULL,NULL,1,i);
    
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
    (mac_inst->UE_list_spec+i)->head = -1;
    (mac_inst->UE_list_spec+i)->tail = -1;
    (mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.R_max = mac_inst->rrc_config.npdcch_ConfigDedicated[i].R_max;
    (mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.G = mac_inst->rrc_config.npdcch_ConfigDedicated[i].G;
    (mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.a_offset = mac_inst->rrc_config.npdcch_ConfigDedicated[i].a_offset;
    //(mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.R_max = 8;
    //(mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.G = 1;
    //(mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.a_offset = 0;
    (mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.T = (mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.R_max * (mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.G;
    (mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.ss_start_uss = (mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.T * (mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.a_offset;
    for(j=0;j<MAX_NUMBER_OF_UE_MAX_NB_IoT;++j)
    {
      (mac_inst->UE_list_spec+i)->UE_template_NB_IoT[j].active=0;
      (mac_inst->UE_list_spec+i)->UE_template_NB_IoT[j].RRC_connected=0;
      (mac_inst->UE_list_spec+i)->UE_template_NB_IoT[j].direction = -1;
    }
    //SCHEDULE_LOG("[%04d][init_mac_NB_IoT] List_number %d R_max %d G %.1f a_offset %.1f T %d SS_start %d\n", mac_inst->current_subframe, i, (mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.R_max, (mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.G, (mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.a_offset, (mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.T, (mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.ss_start_uss);
183 184
    
    LOG_I(MAC,"[NB-IoT] List_number %d R_max %d G %.1f a_offset %.1f T %d SS_start %d\n", i, (mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.R_max, (mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.G, (mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.a_offset, (mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.T, (mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.ss_start_uss);
185
  }
Nick Ho's avatar
Nick Ho committed
186

187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
/*
  //Initial one UE template
  //UE_TEMPLATE_NB_IoT *UE_info=(UE_TEMPLATE_NB_IoT*)malloc(USER_NUM_USS*sizeof(UE_TEMPLATE_NB_IoT));

  mac_inst->UE_list_spec->head=0;
  mac_inst->UE_list_spec->tail=0;

  for(i=0;i<USER_NUM_USS;++i)
  {
    UE_info_setting(mac_inst->UE_list_spec->UE_template_NB_IoT+i);

    if(i==0)
    {
      (mac_inst->UE_list_spec->UE_template_NB_IoT+i)->prev=-1;
      (mac_inst->UE_list_spec->UE_template_NB_IoT+i)->next=1;
      //mac_inst->UE_list_spec->next[i]=-1;
    }
    else if(i>=USER_NUM_USS-1)
    {
      (mac_inst->UE_list_spec->UE_template_NB_IoT+i)->prev=i-1;
      (mac_inst->UE_list_spec->UE_template_NB_IoT+i)->next=-1;
    }
    else
    {
      (mac_inst->UE_list_spec->UE_template_NB_IoT+i)->prev=i-1;
      (mac_inst->UE_list_spec->UE_template_NB_IoT+i)->next=i+1;
    }
    //mac_inst->UE_list_spec->UE_template_NB_IoT[i]=UE_info[i];
    mac_inst->UE_list_spec->tail=i;
  }
*/
  //UL initial
  //Setting nprach configuration
  setting_nprach();
  //Initialize uplink resource from nprach configuration
  Initialize_Resource();
  //add_UL_Resource(mac_inst);    
224 225
  extend_available_resource_DL(mac_inst, mac_inst->current_subframe + 1 + 160);  

Nick Ho's avatar
Nick Ho committed
226 227
}

228 229 230 231 232 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
void mac_top_init_eNB_NB_IoT(void)
{
  // can be an input of this function, but now fix to 0
  module_id_t    i = 0;

  //UE_list_t *UE_list;
  //eNB_MAC_INST_NB_IoT *mac;

  int nb_inst_NB_IOT_MAC= 1;
  
  LOG_I(MAC,"[NB-IoT MAIN] Init function start:nb_nbiot_macrlc_inst=%d\n",nb_inst_NB_IOT_MAC);

  if (nb_inst_NB_IOT_MAC>0) {
    // only one inst exit in legacy OAI

      mac_inst->Mod_id = i;

            // IF Module Initialization linking
      mac_inst->if_inst_NB_IoT = IF_Module_init_NB_IoT(i);
      mac_inst->if_inst_NB_IoT->PHY_config_req = PHY_config_req_NB_IoT;
      mac_inst->if_inst_NB_IoT->schedule_response = schedule_response_NB_IoT;

      //reserve for fapi structure initializati


  } else {
    mac_inst = NULL;
  }
  
  // for NB-IoT UE list initialization will be in init_mac_NB_IoT

}
260

261
int l2_init_eNB_NB_IoT(void)
262
{
263

264 265 266

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

267 268
  mac_inst = (eNB_MAC_INST_NB_IoT *) malloc (sizeof(eNB_MAC_INST_NB_IoT));

269 270
  memset(mac_inst,0,sizeof(eNB_MAC_INST_NB_IoT));

271
  Is_rrc_registered_NB_IoT=0;
272
  mac_init_global_param_NB_IoT();
273
  Is_rrc_registered_NB_IoT=1;
274

275
  //init_mac_NB_IoT(mac_inst);
Nick Ho's avatar
Nick Ho committed
276

277 278 279
  return(1);
}