main.c 7.14 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
Cedric Roux's avatar
Cedric Roux committed
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
gauthier's avatar
gauthier committed
23
 * \brief top init of Layer 2
24
 * \author  Navid Nikaein and Raymond Knopp
25
 * \date 2010 - 2014
nikaeinn's avatar
nikaeinn committed
26
 * \version 1.0
gauthier's avatar
gauthier committed
27
28
 * \email: navid.nikaein@eurecom.fr
 * @ingroup _mac
29

gauthier's avatar
gauthier committed
30
 */
31
32

#include "defs.h"
33
#include "proto.h"
34
#include "extern.h"
gauthier's avatar
gauthier committed
35
#include "assertions.h"
36
37
38
#include "PHY_INTERFACE/extern.h"
#include "PHY/defs.h"
#include "SCHED/defs.h"
gauthier's avatar
gauthier committed
39
#include "LAYER2/PDCP_v10.1.0/pdcp.h"
40
41
42
43
44
45
#include "RRC/LITE/defs.h"
#include "UTIL/LOG/log.h"
#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"

#include "SCHED/defs.h"

46

47
48
49
50
#include "common/ran_context.h"

extern RAN_CONTEXT_t RC;

51
void dl_phy_sync_success(module_id_t module_idP, frame_t frameP, unsigned char eNB_index, uint8_t first_sync)	//init as MR
52
{
53
54
    LOG_D(MAC, "[UE %d] Frame %d: PHY Sync to eNB_index %d successful \n",
	  module_idP, frameP, eNB_index);
55
#if defined(ENABLE_USE_MME)
56
    int mme_enabled = 1;
57
#else
58
    int mme_enabled = 0;
59
#endif
60

61
62
63
64
65
66
    if (first_sync == 1 && !(mme_enabled == 1)) {
	//layer2_init_UE(module_idP);
	openair_rrc_ue_init(module_idP, eNB_index);
    } else {
	rrc_in_sync_ind(module_idP, frameP, eNB_index);
    }
67
68
}

69
70
71
void
mac_UE_out_of_sync_ind(module_id_t module_idP, frame_t frameP,
		       uint16_t eNB_index)
72
{
73

74
    //  Mac_rlc_xface->mac_out_of_sync_ind(Mod_id, frameP, eNB_index);
75
76
77
}


78
79
80
int
mac_top_init_ue(int eMBMS_active, char *uecap_xer,
		uint8_t cba_group_active, uint8_t HO_active)
81
{
82

83
    int i;
knopp's avatar
knopp committed
84

85
    LOG_I(MAC, "[MAIN] Init function start:Nb_UE_INST=%d\n", NB_UE_INST);
86

87
88
89
    if (NB_UE_INST > 0) {
	UE_mac_inst =
	    (UE_MAC_INST *) malloc16(NB_UE_INST * sizeof(UE_MAC_INST));
gauthier's avatar
gauthier committed
90

91
92
93
94
	AssertFatal(UE_mac_inst != NULL,
		    "[MAIN] Can't ALLOCATE %zu Bytes for %d UE_MAC_INST with size %zu \n",
		    NB_UE_INST * sizeof(UE_MAC_INST), NB_UE_INST,
		    sizeof(UE_MAC_INST));
gauthier's avatar
gauthier committed
95

96
97
	LOG_D(MAC, "[MAIN] ALLOCATE %zu Bytes for %d UE_MAC_INST @ %p\n",
	      NB_UE_INST * sizeof(UE_MAC_INST), NB_UE_INST, UE_mac_inst);
98

99
	bzero(UE_mac_inst, NB_UE_INST * sizeof(UE_MAC_INST));
100

101
102
103
104
105
	for (i = 0; i < NB_UE_INST; i++) {
	    ue_init_mac(i);
	}
    } else {
	UE_mac_inst = NULL;
106
    }
gauthier's avatar
gauthier committed
107

108

109
110
111
    LOG_I(MAC, "[MAIN] calling RRC\n");
    openair_rrc_top_init_ue(eMBMS_active, uecap_xer, cba_group_active,
			    HO_active);
112
113


114
115
116
    LOG_I(MAC, "[MAIN][INIT] Init function finished\n");

    return (0);
117

118
119
120
}


knopp's avatar
knopp committed
121
void mac_top_init_eNB()
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
    module_id_t i, j;
    int list_el;
    UE_list_t *UE_list;
    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 =
	    (eNB_MAC_INST **) malloc16(RC.nb_macrlc_inst *
				       sizeof(eNB_MAC_INST *));
	AssertFatal(RC.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++) {
	    RC.mac[i] = (eNB_MAC_INST *) malloc16(sizeof(eNB_MAC_INST));
	    AssertFatal(RC.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));
	    LOG_D(MAC,
		  "[MAIN] ALLOCATE %zu Bytes for %d eNB_MAC_INST @ %p\n",
		  sizeof(eNB_MAC_INST), RC.nb_macrlc_inst, RC.mac);
	    bzero(RC.mac[i], sizeof(eNB_MAC_INST));
	    RC.mac[i]->Mod_id = i;
	    for (j = 0; j < MAX_NUM_CCs; j++) {
		RC.mac[i]->DL_req[j].dl_config_request_body.
		    dl_config_pdu_list = RC.mac[i]->dl_config_pdu_list[j];
		RC.mac[i]->UL_req[j].ul_config_request_body.
		    ul_config_pdu_list = RC.mac[i]->ul_config_pdu_list[j];
		for (int k = 0; k < 10; k++)
		    RC.mac[i]->UL_req_tmp[j][k].
			ul_config_request_body.ul_config_pdu_list =
			RC.mac[i]->ul_config_pdu_list_tmp[j][k];
		RC.mac[i]->HI_DCI0_req[j].
		    hi_dci0_request_body.hi_dci0_pdu_list =
		    RC.mac[i]->hi_dci0_pdu_list[j];
		RC.mac[i]->TX_req[j].tx_request_body.tx_pdu_list =
		    RC.mac[i]->tx_request_pdu[j];
		RC.mac[i]->ul_handle = 0;
	    }
	}

	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();

    } else {
	RC.mac = NULL;
179
    }
180

181
182
183
    // Initialize Linked-List for Active UEs
    for (i = 0; i < RC.nb_macrlc_inst; i++) {
	mac = RC.mac[i];
184
185


186
	mac->if_inst = IF_Module_init(i);
187

188
	UE_list = &mac->UE_list;
189

190
191
192
193
	UE_list->num_UEs = 0;
	UE_list->head = -1;
	UE_list->head_ul = -1;
	UE_list->avail = 0;
194

195
196
197
198
	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;
	}
199

200
201
202
	UE_list->next[list_el] = -1;
	UE_list->next_ul[list_el] = -1;
    }
203

204
}
205

206
207
void mac_init_cell_params(int Mod_idP, int CC_idP)
{
208

209
210
    int j;
    UE_TEMPLATE *UE_template;
211

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

215
216
217
218
219
220
221
222
223
    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];

    for (j = 0; j < NUMBER_OF_UE_MAX; j++) {
	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));
224
225
226
227
228
229
    }

}


int rlcmac_init_global_param(void)
230
{
231

232

233
    LOG_I(MAC, "[MAIN] CALLING RLC_MODULE_INIT...\n");
234

235
236
237
    if (rlc_module_init() != 0) {
	return (-1);
    }
238

239
    pdcp_layer_init();
240

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

243
    return 0;
244
245
246
}


247
248
void mac_top_cleanup(void)
{
249

250
#ifndef USER_MODE
251
    pdcp_module_cleanup();
252
#endif
253

254
255
256
    if (NB_UE_INST > 0) {
	free(UE_mac_inst);
    }
257

258
259
260
    if (RC.nb_macrlc_inst > 0) {
	free(RC.mac);
    }
261

262
263
}

264
265
266
int
l2_init_ue(int eMBMS_active, char *uecap_xer, uint8_t cba_group_active,
	   uint8_t HO_active)
267
{
268
269
270
271
272
273
274
275
    LOG_I(MAC, "[MAIN] MAC_INIT_GLOBAL_PARAM IN...\n");
    //    NB_NODE=2;
    //    NB_INST=2;

    rlcmac_init_global_param();
    LOG_I(MAC, "[MAIN] init UE MAC functions \n");
    mac_top_init_ue(eMBMS_active, uecap_xer, cba_group_active, HO_active);
    return (1);
276
277
}

278
int l2_init_eNB()
279
{
280
281
282



283
    LOG_I(MAC, "[MAIN] MAC_INIT_GLOBAL_PARAM IN...\n");
284

285
    rlcmac_init_global_param();
286

287
    LOG_D(MAC, "[MAIN] ALL INIT OK\n");
288
289


290
    return (1);
291
}