main.c 6.45 KB
Newer Older
1 2 3 4 5
/*
 * 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
6
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 * 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
 */

22
/*! \file main.c
23
 * \brief top init of Layer 2
24
 * \author  Navid Nikaein and Raymond Knopp
25
 * \date 2010 - 2014
26
 * \version 1.0
27 28
 * \email: navid.nikaein@eurecom.fr
 * @ingroup _mac
29

30
 */
31

32
#include <dlfcn.h>
33 34 35
#include "mac.h"
#include "mac_proto.h"
#include "mac_extern.h"
Lionel Gauthier's avatar
Lionel Gauthier committed
36
#include "assertions.h"
37 38 39
//#include "PHY_INTERFACE/phy_extern.h"
//#include "PHY/defs_eNB.h"
//#include "SCHED/sched_eNB.h"
Lionel Gauthier's avatar
Lionel Gauthier committed
40
#include "LAYER2/PDCP_v10.1.0/pdcp.h"
41
#include "RRC/LTE/rrc_defs.h"
42
#include "common/utils/LOG/log.h"
43 44
#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"

45 46 47 48
#include "common/ran_context.h"

extern RAN_CONTEXT_t RC;

49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
void init_UE_list(UE_list_t *UE_list)
{
  int list_el;
  UE_list->num_UEs = 0;
  UE_list->head = -1;
  UE_list->head_ul = -1;
  UE_list->avail = 0;
  for (list_el = 0; list_el < MAX_MOBILES_PER_ENB - 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;
  memset(UE_list->DLSCH_pdu, 0, sizeof(UE_list->DLSCH_pdu));
  memset(UE_list->UE_template, 0, sizeof(UE_list->UE_template));
  memset(UE_list->eNB_UE_stats, 0, sizeof(UE_list->eNB_UE_stats));
  memset(UE_list->UE_sched_ctrl, 0, sizeof(UE_list->UE_sched_ctrl));
  memset(UE_list->active, 0, sizeof(UE_list->active));
  memset(UE_list->assoc_dl_slice_idx, 0, sizeof(UE_list->assoc_dl_slice_idx));
  memset(UE_list->assoc_ul_slice_idx, 0, sizeof(UE_list->assoc_ul_slice_idx));
}

void init_slice_info(slice_info_t *sli)
{
  sli->intraslice_share_active = 1;
  sli->interslice_share_active = 1;

  sli->n_dl = 1;
  memset(sli->dl, 0, sizeof(slice_sched_conf_dl_t) * MAX_NUM_SLICES);
  sli->dl[0].pct = 1.0;
  sli->dl[0].prio = 10;
  sli->dl[0].pos_high = N_RBG_MAX;
  sli->dl[0].maxmcs = 28;
  sli->dl[0].sorting = 0x012345;
  sli->dl[0].sched_name = "schedule_ue_spec";
  sli->dl[0].sched_cb = dlsym(NULL, sli->dl[0].sched_name);
  AssertFatal(sli->dl[0].sched_cb, "DLSCH scheduler callback is NULL\n");

  sli->n_ul = 1;
  memset(sli->ul, 0, sizeof(slice_sched_conf_ul_t) * MAX_NUM_SLICES);
  sli->ul[0].pct = 1.0;
  sli->ul[0].maxmcs = 20;
  sli->ul[0].sorting = 0x0123;
  sli->ul[0].sched_name = "schedule_ulsch_rnti";
  sli->ul[0].sched_cb = dlsym(NULL, sli->ul[0].sched_name);
  AssertFatal(sli->ul[0].sched_cb, "ULSCH scheduler callback is NULL\n");
}

97
void mac_top_init_eNB(void)
98
{
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
  module_id_t i, j;
  eNB_MAC_INST **mac;

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

  if (RC.nb_macrlc_inst <= 0) {
    RC.mac = NULL;
    return;
  }

  mac = malloc16(RC.nb_macrlc_inst * sizeof(eNB_MAC_INST *));
  AssertFatal(mac != NULL,
              "can't ALLOCATE %zu Bytes for %d eNB_MAC_INST with size %zu \n",
              RC.nb_macrlc_inst * sizeof(eNB_MAC_INST *),
              RC.nb_macrlc_inst, sizeof(eNB_MAC_INST));
  for (i = 0; i < RC.nb_macrlc_inst; i++) {
    mac[i] = malloc16(sizeof(eNB_MAC_INST));
    AssertFatal(mac[i] != NULL,
                "can't ALLOCATE %zu Bytes for %d eNB_MAC_INST with size %zu \n",
                RC.nb_macrlc_inst * sizeof(eNB_MAC_INST *),
                RC.nb_macrlc_inst, sizeof(eNB_MAC_INST));
    LOG_D(MAC,
          "[MAIN] ALLOCATE %zu Bytes for %d eNB_MAC_INST @ %p\n",
          sizeof(eNB_MAC_INST), RC.nb_macrlc_inst, mac);
    bzero(mac[i], sizeof(eNB_MAC_INST));
    mac[i]->Mod_id = i;
    for (j = 0; j < MAX_NUM_CCs; j++) {
      mac[i]->DL_req[j].dl_config_request_body.dl_config_pdu_list =
          mac[i]->dl_config_pdu_list[j];
      mac[i]->UL_req[j].ul_config_request_body.ul_config_pdu_list =
          mac[i]->ul_config_pdu_list[j];
      for (int k = 0; k < 10; k++)
        mac[i]->UL_req_tmp[j][k].ul_config_request_body.ul_config_pdu_list =
            mac[i]->ul_config_pdu_list_tmp[j][k];
      for(int sf=0;sf<10;sf++)
        mac[i]->HI_DCI0_req[j][sf].hi_dci0_request_body.hi_dci0_pdu_list =
            mac[i]->hi_dci0_pdu_list[j][sf];
      mac[i]->TX_req[j].tx_request_body.tx_pdu_list = mac[i]->tx_request_pdu[j];
      mac[i]->ul_handle = 0;
139
    }
140

141
    mac[i]->if_inst = IF_Module_init(i);
142

143 144
    init_UE_list(&mac[i]->UE_list);
    init_slice_info(&mac[i]->slice_info);
145 146 147 148 149 150 151 152 153 154 155
  }

  RC.mac = mac;

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

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

  rrc_init_global_param();
156
}
157

158 159
void mac_init_cell_params(int Mod_idP, int CC_idP)
{
160

161 162
    int j;
    UE_TEMPLATE *UE_template;
163

164
    LOG_D(MAC, "[MSC_NEW][FRAME 00000][MAC_eNB][MOD %02d][]\n", Mod_idP);
165
    //COMMON_channels_t *cc = &RC.mac[Mod_idP]->common_channels[CC_idP];
166

167 168 169 170
    memset(&RC.mac[Mod_idP]->eNB_stats, 0, sizeof(eNB_STATS));
    UE_template =
	(UE_TEMPLATE *) & RC.mac[Mod_idP]->UE_list.UE_template[CC_idP][0];

171
    for (j = 0; j < MAX_MOBILES_PER_ENB; j++) {
172 173 174 175
	UE_template[j].rnti = 0;
	// initiallize the eNB to UE statistics
	memset(&RC.mac[Mod_idP]->UE_list.eNB_UE_stats[CC_idP][j], 0,
	       sizeof(eNB_UE_STATS));
176 177 178 179 180 181
    }

}


int rlcmac_init_global_param(void)
182
{
183

184

185
    LOG_I(MAC, "[MAIN] CALLING RLC_MODULE_INIT...\n");
186

187 188 189
    if (rlc_module_init() != 0) {
	return (-1);
    }
190

191
    pdcp_layer_init();
192

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

195
    return 0;
196 197 198
}


199 200
void mac_top_cleanup(void)
{
201

202 203 204
    if (NB_UE_INST > 0) {
	free(UE_mac_inst);
    }
205

206 207 208
    if (RC.nb_macrlc_inst > 0) {
	free(RC.mac);
    }
209

210 211
}

212
int l2_init_eNB(void)
213
{
214 215 216



217
    LOG_I(MAC, "[MAIN] MAC_INIT_GLOBAL_PARAM IN...\n");
218

219
    rlcmac_init_global_param();
220

221
    LOG_D(MAC, "[MAIN] ALL INIT OK\n");
222 223


224
    return (1);
225
}