NR_IF_Module.c 11.7 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
 * \note
 * \warning
 */

33
#include "PHY/defs_nr_UE.h"
34
#include "NR_IF_Module.h"
35
#include "NR_MAC_UE/mac_proto.h"
36
#include "assertions.h"
37
#include "NR_MAC_UE/mac_extern.h"
38
#include "SCHED_NR_UE/fapi_nr_ue_l1.h"
39
#include "executables/softmodem-common.h"
40

41
#include <stdio.h>
42 43 44 45 46

#define MAX_IF_MODULES 100

static nr_ue_if_module_t *nr_ue_if_module_inst[MAX_IF_MODULES];

47
//  L2 Abstraction Layer
48 49 50 51 52 53 54 55 56 57
int handle_bcch_bch(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){

  return nr_ue_decode_mib(module_id,
			  cc_id,
			  gNB_index,
			  additional_bits,
			  ssb_length,  //  Lssb = 64 is not support    
			  ssb_index,
			  pduP, 
			  cell_id);
58

59
}
60

61
//  L2 Abstraction Layer
62
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){
63

64
  return 0;
65
}
66
//  L2 Abstraction Layer
67
int handle_dci(module_id_t module_id, int cc_id, unsigned int gNB_index, fapi_nr_dci_indication_pdu_t *dci){
68

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

Agustin's avatar
Agustin committed
72 73
}
//  L2 Abstraction Layer
74 75
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, frame_t frame, int slot, NR_UL_TIME_ALIGNMENT_t *ul_time_alignment){

cig's avatar
cig committed
76
  LOG_D(MAC, "handle_dlsch at MAC layer \n");
77 78
  //if (IS_SOFTMODEM_NOS1 || IS_SOFTMODEM_RFSIM)
  // sdu should be processed even when is S1 mode because data and timing advance updates are transmitted by the UE
cig's avatar
cig committed
79 80 81 82 83
  nr_ue_send_sdu(module_id, cc_id, frame, slot,
                 pduP,
                 pdu_len,
                 gNB_index,
                 ul_time_alignment);
84

85 86
  return 0;
  /*
87 88 89 90 91 92
  return nr_ue_process_dlsch(module_id,
                             cc_id,
                             gNB_index,
                             dci_ind,
                             pduP,
                             pdu_len);
93
  */
94 95
}

cig's avatar
cig committed
96
int8_t handle_rar (nr_downlink_indication_t *dl_info){
97

cig's avatar
cig committed
98 99
  LOG_D(MAC, "handling RAR at MAC layer \n");
  nr_process_rar (dl_info);
100
  return 0;
cig's avatar
cig committed
101

102 103
}

104
int nr_ue_ul_indication(nr_uplink_indication_t *ul_info){
105

106 107 108 109 110 111 112 113 114 115
  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

cig's avatar
cig committed
116
  ret = nr_ue_scheduler(NULL, ul_info);
cig's avatar
cig committed
117

cig's avatar
cig committed
118
  if (is_nr_UL_slot(mac->scc, ul_info->slot_tx) && mac->ra_state == RA_UE_IDLE && get_softmodem_params()->do_ra){
cig's avatar
cig committed
119
    nr_ue_prach_scheduler(module_id, ul_info->frame_tx, ul_info->slot_tx);
cig's avatar
cig committed
120 121 122 123 124 125 126 127
    if (mac->generate_nr_prach){
      uint16_t monitoring_slot_period, monitoring_offset;
      uint16_t rach_frame = mac->scheduled_response.ul_config->sfn;
      uint16_t rx_rach_frame = (rach_frame + 2) % MAX_FRAME_NUMBER; // compensate 2 frames offset delay at gNB side
      uint16_t rach_slot  = mac->scheduled_response.ul_config->slot;
      nr_ue_msg2_scheduler(module_id, rx_rach_frame, rach_slot, &mac->msg2_rx_frame, &mac->msg2_rx_slot);
    }
  }
128

129
  switch(ret){
laurent's avatar
laurent committed
130
  case UE_CONNECTION_OK:
131
    break;
laurent's avatar
laurent committed
132
  case UE_CONNECTION_LOST:
133
    break;
laurent's avatar
laurent committed
134
  case UE_PHY_RESYNCH:
135
    break;
laurent's avatar
laurent committed
136
  case UE_PHY_HO_PRACH:
137 138 139 140 141 142 143 144
    break;
  default:
    break;
  }

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

  return 0;
145 146
}

147
int nr_ue_dl_indication(nr_downlink_indication_t *dl_info, NR_UL_TIME_ALIGNMENT_t *ul_time_alignment){
148
    
149 150 151 152
  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);
153 154 155 156 157 158 159 160 161 162 163 164 165
  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;
166 167

  if(dl_info->dci_ind != NULL){
168
    LOG_D(MAC,"[L2][IF MODULE][DL INDICATION][DCI_IND]\n");
169
    for(i=0; i<dl_info->dci_ind->number_of_dcis; ++i){
Hongzhi Wang's avatar
Hongzhi Wang committed
170
      LOG_D(MAC,">>>NR_IF_Module i=%d, dl_info->dci_ind->number_of_dcis=%d\n",i,dl_info->dci_ind->number_of_dcis);
171
      //      fapi_nr_dci_pdu_rel15_t *dci = &dl_info->dci_ind->dci_list[i].dci;
172

Francesco Mani's avatar
Francesco Mani committed
173
      ret_mask |= (handle_dci(dl_info->module_id,
cig's avatar
cig committed
174 175 176
                              dl_info->cc_id,
                              dl_info->gNB_index,
                              dl_info->dci_ind->dci_list+i)<< FAPI_NR_DCI_IND);
177

178 179 180
      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);

181 182 183 184 185 186 187 188 189 190 191

      /*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;
192
                
193
	case FAPI_NR_DCI_TYPE_1_0:
194
                    
195
	dl_config->dl_config_list[dl_config->number_pdus].pdu_type = FAPI_NR_DL_CONFIG_TYPE_DLSCH;
196

197 198
	//  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;
199
                    
200 201
	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));
202

203
	dl_config->number_pdus = dl_config->number_pdus + 1;
204

205 206 207 208 209 210 211
	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;
212 213

                    
214

215
	break;
216

217 218 219
	default:
	break;
	}*/
220

221
      //(dl_info->dci_list+i)->rnti
222
    }
223 224 225
  }

  if(dl_info->rx_ind != NULL){
226
    LOG_D(MAC,"[L2][IF MODULE][DL INDICATION][RX_IND], Number of PDUs: %d \n", dl_info->rx_ind->number_pdus);
227 228 229
    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:
230
	ret_mask |= (handle_bcch_bch(dl_info->module_id, dl_info->cc_id, dl_info->gNB_index,
231 232 233 234 235
				     (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;
236
    	  LOG_D(MAC,"[L2][IF MODULE][DL INDICATION][RX_IND], MIB case Number of PDUs: %d \n", dl_info->rx_ind->number_pdus);
237
	/*ret_mask |= (handle_bcch_bch(      dl_info->module_id, dl_info->cc_id, dl_info->gNB_index,
238 239 240 241 242
					     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;*/
243 244
	break;
      case FAPI_NR_RX_PDU_TYPE_SIB:
245 246 247 248 249
      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;
250 251
      case FAPI_NR_RX_PDU_TYPE_DLSCH:
	//                    ret_mask |= (0) << FAPI_NR_RX_PDU_TYPE_DLSCH;
252
	ret_mask |= (handle_dlsch(dl_info->module_id, dl_info->cc_id, dl_info->gNB_index, dl_info->dci_ind,
253
				  (dl_info->rx_ind->rx_indication_body+i)->pdsch_pdu.pdu,
cig's avatar
cig committed
254
				  (dl_info->rx_ind->rx_indication_body+i)->pdsch_pdu.pdu_length, dl_info->frame, dl_info->slot, ul_time_alignment)) << FAPI_NR_RX_PDU_TYPE_DLSCH;
255

256
    	  LOG_D(MAC,"[L2][IF MODULE][DL INDICATION][RX_IND], DLSCH case Number of PDUs: %d \n", dl_info->rx_ind->number_pdus);
257

258 259 260 261 262
	  /*
	  // dl_config structure just stores what was received - not really needed
	  dl_config->dl_config_list[dl_config->number_pdus].pdu_type = FAPI_NR_DL_CONFIG_TYPE_DLSCH;
	  dl_config->number_pdus = dl_config->number_pdus + 1;
	  */
263
      break;
264

265
      case FAPI_NR_RX_PDU_TYPE_RAR:
cig's avatar
cig committed
266
        ret_mask |= (handle_rar(dl_info)) << FAPI_NR_RX_PDU_TYPE_RAR;
267
      break;
268 269

      default:
270
	    break;
271
      }
Agustin's avatar
Agustin committed
272
    }
273
  }
Agustin's avatar
Agustin committed
274

275 276 277
  //clean up nr_downlink_indication_t *dl_info
  dl_info->rx_ind = NULL;
  dl_info->dci_ind = NULL;
Agustin's avatar
Agustin committed
278

279
  return 0;
280
}
281 282 283

nr_ue_if_module_t *nr_ue_if_module_init(uint32_t module_id){

284 285 286 287 288 289 290
  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;
291 292
    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;
293 294 295
    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;
  }
296

297
  return nr_ue_if_module_inst[module_id];
298 299
}

300
int nr_ue_if_module_kill(uint32_t module_id) {
301

302 303 304 305
  if (nr_ue_if_module_inst[module_id] != NULL){
    free(nr_ue_if_module_inst[module_id]);
  } 
  return 0;
306
}
307 308 309 310

int nr_ue_dcireq(nr_dcireq_t *dcireq) {
  
  fapi_nr_dl_config_request_t *dl_config=&dcireq->dl_config_req;
311
  NR_UE_MAC_INST_t *UE_mac = get_mac_inst(0);
312

313 314
  dl_config->sfn=UE_mac->dl_config_request.sfn;
  dl_config->slot=UE_mac->dl_config_request.slot;
315
  dl_config->number_pdus=0;
cig's avatar
cig committed
316

cig's avatar
cig committed
317 318
  printf(" UE_mac->dl_config_request.slot %d VS dcireq->slot %d \n", UE_mac->dl_config_request.slot, dcireq->slot);

cig's avatar
cig committed
319
  LOG_D(PHY, "Entering UE DCI configuration frame %d slot %d \n", dcireq->frame, dcireq->slot);
cig's avatar
cig committed
320 321

  ue_dci_configuration(UE_mac, dl_config, dcireq->frame, dcireq->slot);
cig's avatar
cig committed
322

laurent's avatar
laurent committed
323
  return 0;
324
}