NR_IF_Module.c 11.9 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.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
 */

22
/* \file NR_IF_Module.c
23
 * \brief functions for NR UE FAPI-like interface
24
 * \author R. Knopp, K.H. HSU
25 26
 * \date 2018
 * \version 0.1
27 28
 * \company Eurecom / NTUST
 * \email: knopp@eurecom.fr, kai-hsiang.hsu@eurecom.fr
29 30 31 32 33
 * \note
 * \warning
 */

#include "NR_IF_Module.h"
34
#include "mac_proto.h"
35
#include "assertions.h"
36
#include "LAYER2/NR_MAC_UE/mac_extern.h"
37
#include "SCHED_NR_UE/fapi_nr_ue_l1.h"
38

39
#include <stdio.h>
40 41 42 43 44

#define MAX_IF_MODULES 100

static nr_ue_if_module_t *nr_ue_if_module_inst[MAX_IF_MODULES];

45
//  L2 Abstraction Layer
laurent's avatar
fixes  
laurent committed
46
int handle_bcch_bch(UE_nr_rxtx_proc_t *proc, module_id_t module_id, int cc_id, unsigned int gNB_index, uint8_t *pduP, unsigned int additional_bits, uint32_t ssb_index, uint32_t ssb_length, uint16_t cell_id){
47

laurent's avatar
fixes  
laurent committed
48 49
  return nr_ue_decode_mib( proc,
		           module_id,
50 51 52 53 54 55 56
			   cc_id,
			   gNB_index,
			   additional_bits,
			   ssb_length,  //  Lssb = 64 is not support    
			   ssb_index,
			   pduP, 
			   cell_id);
57

58
}
59

60
//  L2 Abstraction Layer
61
int handle_bcch_dlsch(module_id_t module_id, int cc_id, unsigned int gNB_index, uint32_t sibs_mask, uint8_t *pduP, uint32_t pdu_len){
62

63
  return 0;
64
}
65
//  L2 Abstraction Layer
66
int handle_dci(module_id_t module_id, int cc_id, unsigned int gNB_index, fapi_nr_dci_pdu_rel15_t *dci, uint16_t rnti, uint32_t dci_type){
67

68
  //printf("handle_dci: rnti %x,dci_type %d\n",rnti,dci_type);
69
  return nr_ue_process_dci(module_id, cc_id, gNB_index, dci, rnti, dci_type);
70

Agustin's avatar
Agustin committed
71 72 73 74
}
//  L2 Abstraction Layer
int8_t handle_dlsch (module_id_t module_id, int cc_id, uint8_t gNB_index, fapi_nr_dci_indication_t *dci_ind, uint8_t *pduP, uint32_t pdu_len){

75 76 77 78
  //    return 0;
  return nr_ue_process_dlsch( module_id,
			      cc_id,
			      gNB_index,
laurent's avatar
laurent committed
79
			      dci_ind,
80 81
			      pduP,
			      pdu_len);
Agustin's avatar
Agustin committed
82

83 84
}

85
int nr_ue_ul_indication(nr_uplink_indication_t *ul_info){
86

87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
  NR_UE_L2_STATE_t ret;
  module_id_t module_id = ul_info->module_id;
  NR_UE_MAC_INST_t *mac = get_mac_inst(module_id);

  // clean previous FAPI messages
  mac->tx_request.number_of_pdus = 0;
  mac->ul_config_request.number_pdus = 0;
  mac->dl_config_request.number_pdus = 0;
  // clean previous FAPI messages

  ret = nr_ue_scheduler(
			ul_info->module_id,
			ul_info->gNB_index,
			ul_info->cc_id,
			ul_info->frame,
			ul_info->slot,
			ul_info->ssb_index, 
			0, 0); //  TODO check tx/rx frame/slot is need for NR version

  switch(ret){
laurent's avatar
laurent committed
107
  case UE_CONNECTION_OK:
108
    break;
laurent's avatar
laurent committed
109
  case UE_CONNECTION_LOST:
110
    break;
laurent's avatar
laurent committed
111
  case UE_PHY_RESYNCH:
112
    break;
laurent's avatar
laurent committed
113
  case UE_PHY_HO_PRACH:
114 115 116 117 118 119 120 121 122
    break;
  default:
    break;
  }


  mac->if_module->scheduled_response(&mac->scheduled_response);

  return 0;
123 124
}

125
int nr_ue_dl_indication(nr_downlink_indication_t *dl_info){
126
    
127 128 129 130
  int32_t i;
  uint32_t ret_mask = 0x0;
  module_id_t module_id = dl_info->module_id;
  NR_UE_MAC_INST_t *mac = get_mac_inst(module_id);
131 132 133 134 135 136 137 138 139 140 141 142 143
  fapi_nr_dl_config_request_t *dl_config = &mac->dl_config_request;
  fapi_nr_ul_config_request_t *ul_config = &mac->ul_config_request;

  dl_config->number_pdus = 0;
  ul_config->number_pdus = 0;
  //hook up pointers
  mac->scheduled_response.dl_config = dl_config;
  mac->scheduled_response.ul_config = ul_config;
  mac->scheduled_response.tx_request = &mac->tx_request;
  mac->scheduled_response.module_id = dl_info->module_id;
  mac->scheduled_response.CC_id = dl_info->cc_id;
  mac->scheduled_response.frame = dl_info->frame;
  mac->scheduled_response.slot = dl_info->slot;
144 145

  if(dl_info->dci_ind != NULL){
146
    LOG_D(MAC,"[L2][IF MODULE][DL INDICATION][DCI_IND]\n");
147
    for(i=0; i<dl_info->dci_ind->number_of_dcis; ++i){
148
      LOG_I(MAC,">>>NR_IF_Module i=%d, dl_info->dci_ind->number_of_dcis=%d\n",i,dl_info->dci_ind->number_of_dcis);
149
      fapi_nr_dci_pdu_rel15_t *dci = &dl_info->dci_ind->dci_list[i].dci;
150

151 152 153 154 155 156 157
      ret_mask |= (handle_dci(
			      dl_info->module_id,
			      dl_info->cc_id,
			      dl_info->gNB_index,
			      dci, 
			      (dl_info->dci_ind->dci_list+i)->rnti, 
			      (dl_info->dci_ind->dci_list+i)->dci_format)) << FAPI_NR_DCI_IND;
158

159 160 161 162 163 164 165 166 167 168 169

      /*switch((dl_info->dci_ind->dci_list+i)->dci_type){
	case FAPI_NR_DCI_TYPE_0_0:
	case FAPI_NR_DCI_TYPE_0_1:
	case FAPI_NR_DCI_TYPE_1_1:
	case FAPI_NR_DCI_TYPE_2_0:
	case FAPI_NR_DCI_TYPE_2_1:
	case FAPI_NR_DCI_TYPE_2_2:
	case FAPI_NR_DCI_TYPE_2_3:
	AssertFatal(1==0, "Not yet support at this moment!\n");
	break;
170
                
171
	case FAPI_NR_DCI_TYPE_1_0:
172
                    
173
	dl_config->dl_config_list[dl_config->number_pdus].pdu_type = FAPI_NR_DL_CONFIG_TYPE_DLSCH;
174

175 176
	//  mapping into DL_CONFIG_REQ for DL-SCH
	fapi_nr_dl_config_dlsch_pdu_rel15_t *dlsch_config_pdu = &dl_config->dl_config_list[dl_config->number_pdus].dlsch_config_pdu.dlsch_config_rel15;
177
                    
178 179
	dl_config->dl_config_list[dl_config->number_pdus].dlsch_config_pdu.rnti = 0x0000;   //  TX RNTI: UE-spec
	memcpy(dlsch_config_pdu, dci, sizeof(fapi_nr_dci_pdu_rel15_t));
180

181
	dl_config->number_pdus = dl_config->number_pdus + 1;
182

183 184 185 186 187 188 189
	ret_mask |= (handle_dci(
	dl_info->module_id,
	dl_info->cc_id,
	dl_info->gNB_index,
	dci, 
	(dl_info->dci_ind->dci_list+i)->rnti, 
	(dl_info->dci_ind->dci_list+i)->dci_type)) << FAPI_NR_DCI_IND;
190 191

                    
192

193
	break;
194

195 196 197
	default:
	break;
	}*/
198

199
      //(dl_info->dci_list+i)->rnti
200 201 202 203
            
            


204
    }
205 206 207
  }

  if(dl_info->rx_ind != NULL){
208
    LOG_I(MAC,"[L2][IF MODULE][DL INDICATION][RX_IND]\n");
209 210 211
    for(i=0; i<dl_info->rx_ind->number_pdus; ++i){
      switch(dl_info->rx_ind->rx_indication_body[i].pdu_type){
      case FAPI_NR_RX_PDU_TYPE_MIB:
laurent's avatar
fixes  
laurent committed
212 213
	ret_mask |= (handle_bcch_bch( dl_info->proc,
				     dl_info->module_id, dl_info->cc_id, dl_info->gNB_index,
214 215 216 217 218 219 220 221 222 223 224 225 226 227
				     (dl_info->rx_ind->rx_indication_body+i)->mib_pdu.pdu,
				     (dl_info->rx_ind->rx_indication_body+i)->mib_pdu.additional_bits,
				     (dl_info->rx_ind->rx_indication_body+i)->mib_pdu.ssb_index,
				     (dl_info->rx_ind->rx_indication_body+i)->mib_pdu.ssb_length,
				     (dl_info->rx_ind->rx_indication_body+i)->mib_pdu.cell_id )) << FAPI_NR_RX_PDU_TYPE_MIB;
	break;
      case FAPI_NR_RX_PDU_TYPE_SIB:
	ret_mask |= (handle_bcch_dlsch(dl_info->module_id, dl_info->cc_id, dl_info->gNB_index,
				       (dl_info->rx_ind->rx_indication_body+i)->sib_pdu.sibs_mask,
				       (dl_info->rx_ind->rx_indication_body+i)->sib_pdu.pdu,
				       (dl_info->rx_ind->rx_indication_body+i)->sib_pdu.pdu_length )) << FAPI_NR_RX_PDU_TYPE_SIB;
	break;
      case FAPI_NR_RX_PDU_TYPE_DLSCH:
	//                    ret_mask |= (0) << FAPI_NR_RX_PDU_TYPE_DLSCH;
228
	ret_mask |= (handle_dlsch(dl_info->module_id, dl_info->cc_id, dl_info->gNB_index, dl_info->dci_ind,
229 230 231 232 233 234 235 236 237
				  (dl_info->rx_ind->rx_indication_body+i)->pdsch_pdu.pdu,
				  (dl_info->rx_ind->rx_indication_body+i)->pdsch_pdu.pdu_length)) << FAPI_NR_RX_PDU_TYPE_DLSCH;

	break;
      default:

	break;

      }
Agustin's avatar
Agustin committed
238
    }
239
  }
Agustin's avatar
Agustin committed
240

241 242 243
  //clean up nr_downlink_indication_t *dl_info
  dl_info->rx_ind = NULL;
  dl_info->dci_ind = NULL;
Agustin's avatar
Agustin committed
244

245 246
  AssertFatal( nr_ue_if_module_inst[module_id] != NULL, "IF module is void!\n" );
  nr_ue_if_module_inst[module_id]->scheduled_response(&mac->scheduled_response);
247

248
  return 0;
249
}
250 251 252

nr_ue_if_module_t *nr_ue_if_module_init(uint32_t module_id){

253 254 255 256 257 258 259
  if (nr_ue_if_module_inst[module_id] == NULL) {
    nr_ue_if_module_inst[module_id] = (nr_ue_if_module_t *)malloc(sizeof(nr_ue_if_module_t));
    memset((void*)nr_ue_if_module_inst[module_id],0,sizeof(nr_ue_if_module_t));

    nr_ue_if_module_inst[module_id]->cc_mask=0;
    nr_ue_if_module_inst[module_id]->current_frame = 0;
    nr_ue_if_module_inst[module_id]->current_slot = 0;
260 261
    nr_ue_if_module_inst[module_id]->phy_config_request = nr_ue_phy_config_request;
    nr_ue_if_module_inst[module_id]->scheduled_response = nr_ue_scheduled_response;
262 263 264
    nr_ue_if_module_inst[module_id]->dl_indication = nr_ue_dl_indication;
    nr_ue_if_module_inst[module_id]->ul_indication = nr_ue_ul_indication;
  }
265

266
  return nr_ue_if_module_inst[module_id];
267 268
}

269
int nr_ue_if_module_kill(uint32_t module_id) {
270

271 272 273 274
  if (nr_ue_if_module_inst[module_id] != NULL){
    free(nr_ue_if_module_inst[module_id]);
  } 
  return 0;
275
}
276 277 278 279

int nr_ue_dcireq(nr_dcireq_t *dcireq) {
  
  fapi_nr_dl_config_request_t *dl_config=&dcireq->dl_config_req;
280
  NR_UE_MAC_INST_t *UE_mac = get_mac_inst(0);
281 282 283 284
  
  //  Type0 PDCCH search space
  dl_config->number_pdus =  1;
  dl_config->dl_config_list[0].pdu_type = FAPI_NR_DL_CONFIG_TYPE_DCI;
285
  dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.rnti = 0x1234;	//	to be set
286 287
  
  uint64_t mask = 0x0;
288 289
  uint16_t num_rbs=24;
  uint16_t rb_offset=0;
290 291 292 293 294 295 296 297 298 299
  uint16_t cell_id=0;
  uint16_t num_symbols=2;
  for(int i=0; i<(num_rbs/6); ++i){   //  38.331 Each bit corresponds a group of 6 RBs
    mask = mask >> 1;
    mask = mask | 0x100000000000;
  }
  dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.frequency_domain_resource = mask;
  dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.rb_offset = rb_offset;  //  additional parameter other than coreset
  
  dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.duration = num_symbols;
300
  dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.cce_reg_mapping_type =CCE_REG_MAPPING_TYPE_NON_INTERLEAVED;
301
  dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.cce_reg_interleaved_reg_bundle_size = 0;   //  L 38.211 7.3.2.2
302
  dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.cce_reg_interleaved_interleaver_size = 0;  //  R 38.211 7.3.2.2
303 304 305 306 307 308
  dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.cce_reg_interleaved_shift_index = cell_id;
  dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.precoder_granularity = PRECODER_GRANULARITY_SAME_AS_REG_BUNDLE;
  dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.pdcch_dmrs_scrambling_id = cell_id;
  
  uint32_t number_of_search_space_per_slot=1;
  uint32_t first_symbol_index=0;
309
  uint32_t search_space_duration=0;  //  element of search space
310 311 312 313 314 315 316 317 318 319 320 321
  uint32_t coreset_duration;  //  element of coreset
  
  coreset_duration = num_symbols * number_of_search_space_per_slot;
  
  dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.number_of_candidates[0] = table_38213_10_1_1_c2[0];
  dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.number_of_candidates[1] = table_38213_10_1_1_c2[1];
  dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.number_of_candidates[2] = table_38213_10_1_1_c2[2];   //  CCE aggregation level = 4
  dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.number_of_candidates[3] = table_38213_10_1_1_c2[3];   //  CCE aggregation level = 8
  dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.number_of_candidates[4] = table_38213_10_1_1_c2[4];   //  CCE aggregation level = 16
  dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.duration = search_space_duration;
  dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.monitoring_symbols_within_slot = (0x3fff << first_symbol_index) & (0x3fff >> (14-coreset_duration-first_symbol_index)) & 0x3fff;

322
  dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.N_RB_BWP = UE_mac->initial_bwp_dl.N_RB;
323 324

  
laurent's avatar
laurent committed
325
  return 0;
326
}