main.c 10.2 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
 * 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
 */

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;

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

63
  if (first_sync==1 && !(mme_enabled==1)) {
64
    //layer2_init_UE(module_idP);
65
66
    openair_rrc_ue_init(module_idP,eNB_index);
  } else
gauthier's avatar
gauthier committed
67
  {
68
    rrc_in_sync_ind(module_idP,frameP,eNB_index);
69
70
71
  }
}

72
73
void mac_UE_out_of_sync_ind(module_id_t module_idP, frame_t frameP, uint16_t eNB_index)
{
74

gauthier's avatar
gauthier committed
75
  //  Mac_rlc_xface->mac_out_of_sync_ind(Mod_id, frameP, eNB_index);
76
77
78
}


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

knopp's avatar
knopp committed
82
  int i;
knopp's avatar
knopp committed
83

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

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

89
90
    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
91

Cedric Roux's avatar
Cedric Roux committed
92
    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);
93
94
95

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

96
    for(i=0; i<NB_UE_INST; i++) {
97
      ue_init_mac(i);
98
99
    }
  } else {
100
    UE_mac_inst = NULL;
101
  }
gauthier's avatar
gauthier committed
102

103

104
105
  LOG_I(MAC,"[MAIN] calling RRC\n");
  openair_rrc_top_init_ue(eMBMS_active, uecap_xer, cba_group_active,HO_active);
106

107
  
108
  LOG_I(MAC,"[MAIN][INIT] Init function finished\n");
109

110
  return(0);
111

112
113
114
}


knopp's avatar
knopp committed
115
void mac_top_init_eNB()
116
117
{

knopp's avatar
knopp committed
118
  module_id_t    i,j;
119
120
121
  int list_el;
  UE_list_t *UE_list;
  eNB_MAC_INST *mac;
122

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

125
126
127
128
129
130
131
  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++) {
132
      RC.mac[i] = (eNB_MAC_INST*)malloc16(sizeof(eNB_MAC_INST));
133
134
135
136
137
      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));
knopp's avatar
knopp committed
138
      RC.mac[i]->Mod_id = i;
139
      for (j=0;j<MAX_NUM_CCs;j++) {
140
141
	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];
142
	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];
143
144
145
	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;
146
      }
147
    }
148
149
150
151
152
153
154
155

    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
  } else {
    RC.mac = NULL;
  }
159
  
160
  // Initialize Linked-List for Active UEs
knopp's avatar
knopp committed
161
162
  for(i=0; i<RC.nb_macrlc_inst; i++) {
    mac = RC.mac[i];
163

164

knopp's avatar
knopp committed
165
    mac->if_inst                = IF_Module_init(i);
166

167
    UE_list = &mac->UE_list;
168

169
170
171
172
    UE_list->num_UEs=0;
    UE_list->head=-1;
    UE_list->head_ul=-1;
    UE_list->avail=0;
173

174
175
176
177
178
179
180
181
    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;
    }

    UE_list->next[list_el]=-1;
    UE_list->next_ul[list_el]=-1;
  }
182
183
184

}

185
void mac_init_cell_params(int Mod_idP,int CC_idP) {
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
224
225
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
  int j;
  RA_TEMPLATE *RA_template;
  UE_TEMPLATE *UE_template;
  int size_bytes1,size_bytes2,size_bits1,size_bits2;

  LOG_D(MAC,"[MAIN][eNB %d] CC_id %d initializing RA_template\n",Mod_idP, CC_idP);
  LOG_D(MAC, "[MSC_NEW][FRAME 00000][MAC_eNB][MOD %02d][]\n", Mod_idP);
  COMMON_channels_t *cc = &RC.mac[Mod_idP]->common_channels[CC_idP];

  RA_template = (RA_TEMPLATE *)&cc->RA_template[0];
  
  for (j=0; j<NB_RA_PROC_MAX; j++) {
    if ( cc->tdd_Config != NULL) {
      switch (cc->mib->message.dl_Bandwidth) {
      case MasterInformationBlock__dl_Bandwidth_n6:
	size_bytes1 = sizeof(DCI1A_1_5MHz_TDD_1_6_t);
	size_bytes2 = sizeof(DCI1A_1_5MHz_TDD_1_6_t);
	size_bits1 = sizeof_DCI1A_1_5MHz_TDD_1_6_t;
	size_bits2 = sizeof_DCI1A_1_5MHz_TDD_1_6_t;
	break;
	
      case MasterInformationBlock__dl_Bandwidth_n25:
	size_bytes1 = sizeof(DCI1A_5MHz_TDD_1_6_t);
	size_bytes2 = sizeof(DCI1A_5MHz_TDD_1_6_t);
	size_bits1 = sizeof_DCI1A_5MHz_TDD_1_6_t;
	size_bits2 = sizeof_DCI1A_5MHz_TDD_1_6_t;
	break;
	
      case MasterInformationBlock__dl_Bandwidth_n50:
	size_bytes1 = sizeof(DCI1A_10MHz_TDD_1_6_t);
	size_bytes2 = sizeof(DCI1A_10MHz_TDD_1_6_t);
	size_bits1 = sizeof_DCI1A_10MHz_TDD_1_6_t;
	size_bits2 = sizeof_DCI1A_10MHz_TDD_1_6_t;
	break;
	
      case MasterInformationBlock__dl_Bandwidth_n100:
	size_bytes1 = sizeof(DCI1A_20MHz_TDD_1_6_t);
	size_bytes2 = sizeof(DCI1A_20MHz_TDD_1_6_t);
	size_bits1 = sizeof_DCI1A_20MHz_TDD_1_6_t;
	size_bits2 = sizeof_DCI1A_20MHz_TDD_1_6_t;
	break;
	
      default:
	size_bytes1 = sizeof(DCI1A_1_5MHz_TDD_1_6_t);
	size_bytes2 = sizeof(DCI1A_1_5MHz_TDD_1_6_t);
	size_bits1 = sizeof_DCI1A_1_5MHz_TDD_1_6_t;
	size_bits2 = sizeof_DCI1A_1_5MHz_TDD_1_6_t;
	break;
      }
      
    } else {
      switch (cc->mib->message.dl_Bandwidth) {
      case MasterInformationBlock__dl_Bandwidth_n6:
	size_bytes1 = sizeof(DCI1A_1_5MHz_FDD_t);
	size_bytes2 = sizeof(DCI1A_1_5MHz_FDD_t);
	size_bits1 = sizeof_DCI1A_1_5MHz_FDD_t;
	size_bits2 = sizeof_DCI1A_1_5MHz_FDD_t;
	break;
	
      case MasterInformationBlock__dl_Bandwidth_n25:
	size_bytes1 = sizeof(DCI1A_5MHz_FDD_t);
	size_bytes2 = sizeof(DCI1A_5MHz_FDD_t);
	size_bits1 = sizeof_DCI1A_5MHz_FDD_t;
	size_bits2 = sizeof_DCI1A_5MHz_FDD_t;
	break;
	
      case MasterInformationBlock__dl_Bandwidth_n50:
	size_bytes1 = sizeof(DCI1A_10MHz_FDD_t);
	size_bytes2 = sizeof(DCI1A_10MHz_FDD_t);
	size_bits1 = sizeof_DCI1A_10MHz_FDD_t;
	size_bits2 = sizeof_DCI1A_10MHz_FDD_t;
	break;
	
      case MasterInformationBlock__dl_Bandwidth_n100:
	size_bytes1 = sizeof(DCI1A_20MHz_FDD_t);
	size_bytes2 = sizeof(DCI1A_20MHz_FDD_t);
	size_bits1 = sizeof_DCI1A_20MHz_FDD_t;
	size_bits2 = sizeof_DCI1A_20MHz_FDD_t;
	break;
	
      default:
	size_bytes1 = sizeof(DCI1A_1_5MHz_FDD_t);
	size_bytes2 = sizeof(DCI1A_1_5MHz_FDD_t);
	size_bits1 = sizeof_DCI1A_1_5MHz_FDD_t;
	size_bits2 = sizeof_DCI1A_1_5MHz_FDD_t;
	break;
      }
    }
    
    memcpy((void *)&RA_template[j].RA_alloc_pdu1[0],(void *)&RA_alloc_pdu,size_bytes1);
    memcpy((void *)&RA_template[j].RA_alloc_pdu2[0],(void *)&DLSCH_alloc_pdu1A,size_bytes2);
    RA_template[j].RA_dci_size_bytes1 = size_bytes1;
    RA_template[j].RA_dci_size_bytes2 = size_bytes2;
    RA_template[j].RA_dci_size_bits1  = size_bits1;
    RA_template[j].RA_dci_size_bits2  = size_bits2;
    
    RA_template[j].RA_dci_fmt1        = format1A;
    RA_template[j].RA_dci_fmt2        = format1A;
  }
  
  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));
  }

}


int rlcmac_init_global_param(void)
300
{
301

302

303
304
  LOG_I(MAC,"[MAIN] CALLING RLC_MODULE_INIT...\n");

305
  if (rlc_module_init()!=0) {
306
    return(-1);
307
  }
308
309
310
311
312
313
314
315
316

  pdcp_layer_init ();

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

  return 0;
}


317
318
void mac_top_cleanup(void)
{
319

320
321
322
#ifndef USER_MODE
  pdcp_module_cleanup ();
#endif
323

324
  if (NB_UE_INST>0) {
325
    free (UE_mac_inst);
326
  }
327

328
  if (RC.nb_macrlc_inst>0) {
329
    free(RC.mac);
330
  }
331

332
333
334
335
336
337
338
339
340
341
}

int l2_init_ue(int eMBMS_active, char *uecap_xer,uint8_t cba_group_active, uint8_t HO_active)
{
  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");
342
  mac_top_init_ue(eMBMS_active,uecap_xer,cba_group_active,HO_active);
343
  return(1);
344
345
}

346
int l2_init_eNB()
347
{
348
349
350
351
352



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

353
  rlcmac_init_global_param();
354

355
356
357
358
359
360
  LOG_D(MAC,"[MAIN] ALL INIT OK\n");


  return(1);
}