main.c 3.86 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 37 38
#include "assertions.h"

#include "LAYER2/PDCP_v10.1.0/pdcp.h"
#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/nr-softmodem.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_list_t    *UE_list;
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 85

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

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

88 89
    // These should be out of here later
    pdcp_layer_init();
90

91 92
    if(IS_SOFTMODEM_NOS1)
      nr_ip_over_LTE_DRB_preconfiguration();
93

94
    rrc_init_nr_global_param();
95 96 97 98 99 100 101

  }else {
    RC.nrmac = NULL;
  }

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

103 104
    nrmac = RC.nrmac[i];
    nrmac->if_inst = NR_IF_Module_init(i);
105
    
106 107 108 109 110 111
    UE_list = &nrmac->UE_list;
    UE_list->num_UEs = 0;
    UE_list->head = -1;
    UE_list->head_ul = -1;
    UE_list->avail = 0;

112 113
    for (list_el = 0; list_el < MAX_MOBILES_PER_GNB - 1; list_el++) {
       UE_list->next[list_el] = list_el + 1;
114
      UE_list->next_ul[list_el] = list_el + 1;
Raymond Knopp's avatar
Raymond Knopp committed
115
      UE_list->active[list_el] = FALSE;
116 117 118 119
    }

    UE_list->next[list_el] = -1;
    UE_list->next_ul[list_el] = -1;
Raymond Knopp's avatar
Raymond Knopp committed
120
    UE_list->active[list_el] = FALSE;
121 122
  }

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