main.c 4.06 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
/*
 * 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.1  (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
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
24 25
 * \author  Navid Nikaein and Raymond Knopp, WEI-TAI CHEN
 * \date 2010 - 2014, 2018
26
 * \version 1.0
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
27 28
 * \company Eurecom, NTUST
 * \email: navid.nikaein@eurecom.fr, kroempa@gmail.com
29 30 31 32
 * @ingroup _mac

 */

33 34
#include "NR_MAC_gNB/mac_proto.h"
#include "NR_MAC_COMMON/nr_mac_extern.h"
35 36
#include "assertions.h"

37
#include "LAYER2/nr_pdcp/nr_pdcp_entity.h"
38
#include "RRC/NR/nr_rrc_defs.h"
Raymond Knopp's avatar
Raymond Knopp committed
39
#include "common/utils/LOG/log.h"
40 41 42
//#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"

#include "common/ran_context.h"
43
#include "executables/softmodem-common.h"
44 45 46 47 48 49

extern RAN_CONTEXT_t RC;


void mac_top_init_gNB(void)
{
50
  module_id_t     i;
51
  int             list_el;
52
  NR_UE_info_t    *UE_info;
53 54 55 56 57
  gNB_MAC_INST    *nrmac;

  LOG_I(MAC, "[MAIN] Init function start:nb_nr_macrlc_inst=%d\n",RC.nb_nr_macrlc_inst);

  if (RC.nb_nr_macrlc_inst > 0) {
58

59
    RC.nrmac = (gNB_MAC_INST **) malloc16(RC.nb_nr_macrlc_inst *sizeof(gNB_MAC_INST *));
60
    
61 62 63
    AssertFatal(RC.nrmac != NULL,"can't ALLOCATE %zu Bytes for %d gNB_MAC_INST with size %zu \n",
                RC.nb_nr_macrlc_inst * sizeof(gNB_MAC_INST *),
                RC.nb_nr_macrlc_inst, sizeof(gNB_MAC_INST));
64

65
    for (i = 0; i < RC.nb_nr_macrlc_inst; i++) {
66

67 68 69
      RC.nrmac[i] = (gNB_MAC_INST *) malloc16(sizeof(gNB_MAC_INST));
      
      AssertFatal(RC.nrmac != NULL,"can't ALLOCATE %zu Bytes for %d gNB_MAC_INST with size %zu \n",
cig's avatar
cig committed
70 71
                  RC.nb_nr_macrlc_inst * sizeof(gNB_MAC_INST *),
                  RC.nb_nr_macrlc_inst, sizeof(gNB_MAC_INST));
72 73 74 75 76 77
      
      LOG_D(MAC,"[MAIN] ALLOCATE %zu Bytes for %d gNB_MAC_INST @ %p\n",sizeof(gNB_MAC_INST), RC.nb_nr_macrlc_inst, RC.mac);
      
      bzero(RC.nrmac[i], sizeof(gNB_MAC_INST));
      
      RC.nrmac[i]->Mod_id = i;
cig's avatar
cig committed
78 79 80

      RC.nrmac[i]->tag = (NR_TAG_t*)malloc(sizeof(NR_TAG_t));
      memset((void*)RC.nrmac[i]->tag,0,sizeof(NR_TAG_t));
81
        
cig's avatar
cig committed
82
      RC.nrmac[i]->ul_handle = 0;
83

84
      if (get_softmodem_params()->phy_test) {
Robert Schmidt's avatar
Robert Schmidt committed
85
        RC.nrmac[i]->pre_processor_dl = nr_preprocessor_phytest;
86 87
        RC.nrmac[i]->pre_processor_ul = nr_ul_preprocessor_phytest;
      } else {
88 89
        RC.nrmac[i]->pre_processor_dl = nr_init_fr1_dlsch_preprocessor(i, 0);
        RC.nrmac[i]->pre_processor_ul = nr_init_fr1_ulsch_preprocessor(i, 0);
90
      }
91

92 93
    }//END for (i = 0; i < RC.nb_nr_macrlc_inst; i++)

94
    AssertFatal(rlc_module_init(1) == 0,"Could not initialize RLC layer\n");
95

96 97
    // These should be out of here later
    pdcp_layer_init();
98

99
    if(IS_SOFTMODEM_NOS1 && !(get_softmodem_params()->do_ra || get_softmodem_params()->sa) )
cig's avatar
cig committed
100
      nr_DRB_preconfiguration(0x1234);
101

102
    rrc_init_nr_global_param();
103 104 105 106 107 108 109

  }else {
    RC.nrmac = NULL;
  }

  // Initialize Linked-List for Active UEs
  for (i = 0; i < RC.nb_nr_macrlc_inst; i++) {
110

111 112
    nrmac = RC.nrmac[i];
    nrmac->if_inst = NR_IF_Module_init(i);
113
    
114 115
    UE_info = &nrmac->UE_info;
    UE_info->num_UEs = 0;
116
    create_nr_list(&UE_info->list, MAX_MOBILES_PER_GNB);
Robert Schmidt's avatar
Robert Schmidt committed
117
    for (list_el = 0; list_el < MAX_MOBILES_PER_GNB; list_el++) {
118
      UE_info->active[list_el] = false;
119 120 121
    }
  }

122
  srand48(0);
Raymond Knopp's avatar
Raymond Knopp committed
123
}