IF_Module_L1_primitives_NB_IoT.c 20.3 KB
Newer Older
Matthieu Kanj's avatar
Matthieu Kanj committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/*
 * 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
 */

/*! \file IF_Module_L1_primitives_NB_IoT.c
 * \brief handling nfapi 
 * \author  NTUST BMW Lab./
 * \date 2017
 * \email: 
 * \version 1.0
 *
 */
30 31


32 33
//#include "PHY/LTE_TRANSPORT/dlsch_tbs_full_NB_IoT.h"

34
#include "openair2/PHY_INTERFACE/IF_Module_NB_IoT.h"
35
#include "../SCHED/IF_Module_L1_primitives_NB_IoT.h"
36
//#include "../SCHED/defs.h"
37
#include "../SCHED/defs_NB_IoT.h"
38
#include "assertions.h"
39
//#include "PHY/defs.h"
40
#include "PHY/defs_NB_IoT.h"
41 42
//#include "PHY/extern.h"
#include "PHY/extern_NB_IoT.h"
AlanLi's avatar
AlanLi committed
43
#include "PHY/extern.h"
44

45
//#include "PHY/vars.h"
46

47
#include "PHY/INIT/defs_NB_IoT.h"
48

49 50
int Irep_to_Nrep_x[16] = {1,2,4,8,16,32,64,128,192,256,384,512,768,1024,1536,2048};

51

AlanLi's avatar
AlanLi committed
52 53
void handle_nfapi_dlsch_pdu_NB_IoT(PHY_VARS_eNB *eNB,
						  		   eNB_rxtx_proc_t *proc,
54 55
		       	   	   	           nfapi_dl_config_request_pdu_t *dl_config_pdu,
						   		   uint8_t *sdu)
56
{
57 58

	NB_IoT_eNB_NDLSCH_t *ndlsch;
Matthieu Kanj's avatar
Matthieu Kanj committed
59 60
	NB_IoT_eNB_NDLSCH_t *ndlsch23;

61
	NB_IoT_DL_eNB_HARQ_t *ndlsch_harq;
Matthieu Kanj's avatar
Matthieu Kanj committed
62
	NB_IoT_DL_eNB_HARQ_t *ndlsch_harq23;
63
	nfapi_dl_config_ndlsch_pdu_rel13_t *rel13 = &dl_config_pdu->ndlsch_pdu.ndlsch_pdu_rel13;
64
	int UE_id= -1;
AlanLi's avatar
AlanLi committed
65
	int flag_malloc = 0;
Matthieu Kanj's avatar
Matthieu Kanj committed
66
	ndlsch= eNB->ndlsch_SIB1;
Matthieu Kanj's avatar
Matthieu Kanj committed
67
	ndlsch23= eNB->ndlsch_SIB23;
AlanLi's avatar
AlanLi committed
68
	
Matthieu Kanj's avatar
Matthieu Kanj committed
69
//	if(flag_malloc) free (ndlsch->harq_process);
70

Matthieu Kanj's avatar
Matthieu Kanj committed
71
//	ndlsch->harq_process = (NB_IoT_DL_eNB_HARQ_t*) malloc (sizeof(NB_IoT_DL_eNB_HARQ_t));
AlanLi's avatar
AlanLi committed
72
	flag_malloc = 1 ;
73
  //Check for SI PDU since in NB-IoT there is no DCI for that
74 75
  //SIB1 (type 0), other DLSCH data (type 1) (include the SI messages) based on our ASSUMPTIONs

76
	//is SIB1-NB
77
  if(rel13->rnti_type == 0 && rel13->rnti == 65535)
78
  {
79
  		
80 81
	  /*
	   * the configuration of the NDLSCH PDU for the SIB1-NB shoudl be the following:
82 83 84 85 86 87
	   * -RNTI type = 0; (BCCH)
	   * -RNTI = OxFFFF (65535)
	   * -Repetition number = 0-15 and should be mapped to 4,8,16 as reported in Table 16.4.1.3-3 TS 36.213 (is the schedulingInoSIB1 of the MIB)
	   * -Number of subframe for resource assignment = may is not neded to know since the scheduling is fixed
	   *  (Spec TS 36.331 "SIB1-NB transmission occur in subframe #4 of every other frame in 16 continuous frame"
	   *  meaning that from the starting point we should transmit the SIB1-NB in 8 subframes  among the 16 available (every other))
88
	   *
89
	   * From spec. TS 36.321 v14.2.o pag 31 --> there is an HARQ process for all the broadcast (so we consider it also for SIB1-NB)
90 91
	   *
	   */
AlanLi's avatar
AlanLi committed
92
  		//LOG_I(PHY,"B NB-handle_nfapi_dlsch_pdu_NB_IoT SIB1\n");
Matthieu Kanj's avatar
Matthieu Kanj committed
93 94 95 96
  		ndlsch->active = 1;

  		ndlsch->rnti = 65535;

97 98
  		ndlsch_harq = ndlsch->harq_process;

99
	  	ndlsch->ndlsch_type = SIB1;
AlanLi's avatar
AlanLi committed
100
	  	
101
		ndlsch->npdsch_start_symbol = rel13->start_symbol; //start symbol for the ndlsch transmission
102
		
AlanLi's avatar
AlanLi committed
103 104 105
		
		//ndlsch_harq->pdu = sdu;
		//LOG_I(PHY,"B content_sib1:%d\n",sdu);
Matthieu Kanj's avatar
Matthieu Kanj committed
106 107
		/////ndlsch->content_sib1.pdu = sdu;
		ndlsch_harq->pdu = sdu;
AlanLi's avatar
AlanLi committed
108 109
		//LOG_I(PHY,"A content_sib1:%d\n",ndlsch->content_sib1.pdu);
		
110
		//should be from 1 to 8
AlanLi's avatar
AlanLi committed
111
		
112 113 114 115 116 117
		ndlsch->resource_assignment_SIB1 = rel13->number_of_subframes_for_resource_assignment;//maybe we don't care about it since a fixed schedule
		ndlsch->repetition_number_SIB1 = rel13->repetition_number; //is the schedulingInfoSIB1 (value 1-15) of MIB that is mapped into value 4-8-16 (see NDLSCH fapi specs Table 4-47)
		ndlsch->modulation = rel13->modulation;
		ndlsch->status = ACTIVE_NB_IoT;

		//ndlsch->
AlanLi's avatar
AlanLi committed
118
		
119
		//SI information in reality have no feedback (so there is no retransmission from the HARQ view point since no ack and nack)
120 121
//        ndlsch_harq->frame = frame;
//        ndlsch_harq->subframe = subframe;
AlanLi's avatar
AlanLi committed
122
		
123 124
        ndlsch->nrs_antenna_ports = rel13->nrs_antenna_ports_assumed_by_the_ue;
        ndlsch->scrambling_sequence_intialization = rel13->scrambling_sequence_initialization_cinit;
AlanLi's avatar
AlanLi committed
125 126
		
        //LOG_I(PHY,"A NB-handle_nfapi_dlsch_pdu_NB_IoT SIB1\n");
127
        ndlsch_harq->TBS = TBStable_NB_IoT_SIB1[rel13->repetition_number];
128

129 130


131
  }
132
  //is SI message (this is an NDLSCH that will be transmitted very frequently)
133 134 135 136 137 138 139 140
  else if(rel13->rnti_type == 1 && rel13->rnti == 65535)
  {
	  /*
	   *
	   * the configuration of the NDLSCH PDU for the SIB1-NB should be the following:
	   * RNTI type = 1;
	   * RNTI = OxFFFF (65535)
	   * Repetition number = 0 and should be mapped to 1 through Table 16.4.1.3-2 TS 36.213
141
	   * Number of subframe for resource assignment = will be evaluated by the MAC based on the value of the "si-TB" field inside the SIB1-NB (value 2 or 8)
142 143 144
	   *
	   * From spec. TS 36.321 v14.2.o pag 31 --> there is an HARQ process for all the broadcast
	   *
145 146 147
	   * XXX for the moment we are not able to prevent the problem of Error: first transmission but sdu = NULL.
	   * anyway, the PHY layer if have finished the transmission it will not transmit anything and will generate the error
	   *
148
	   */
AlanLi's avatar
AlanLi committed
149
  		//LOG_I(PHY,"B NB-handle_nfapi_dlsch_pdu_NB_IoT SIB23\n");
Matthieu Kanj's avatar
Matthieu Kanj committed
150
	  	ndlsch_harq23 = ndlsch23->harq_process;
151

152
		//new SI starting transmission (should enter here only the first time for a new transmission)
153
		if(sdu != NULL)
154
		{
Matthieu Kanj's avatar
Matthieu Kanj committed
155 156 157

			ndlsch23->active = 1;
		  	ndlsch23->ndlsch_type = SI_Message;
Matthieu Kanj's avatar
Matthieu Kanj committed
158
		  	ndlsch23->rnti = 65535;
Matthieu Kanj's avatar
Matthieu Kanj committed
159
			ndlsch23->npdsch_start_symbol = rel13->start_symbol; //start OFDM symbol for the ndlsch transmission
AlanLi's avatar
AlanLi committed
160 161
			//ndlsch_harq->pdu = sdu;
			//LOG_I(PHY,"B content_sib23:%d\n",sdu);
Matthieu Kanj's avatar
Matthieu Kanj committed
162
			ndlsch_harq23->pdu = sdu;
Matthieu Kanj's avatar
Matthieu Kanj committed
163
			
Matthieu Kanj's avatar
Matthieu Kanj committed
164 165
			ndlsch_harq23->repetition_number = rel13->repetition_number;//should be always fix to 0 to be mapped in 1
			ndlsch_harq23->modulation = rel13->modulation;
Matthieu Kanj's avatar
Matthieu Kanj committed
166
			ndlsch_harq23->TBS = rel13->length;
AlanLi's avatar
AlanLi committed
167
			//LOG_I(PHY,"A content_sib23:%d\n",sdu);
Matthieu Kanj's avatar
Matthieu Kanj committed
168
			ndlsch23->resource_assignment = rel13->number_of_subframes_for_resource_assignment;//value 2 or 8
Matthieu Kanj's avatar
Matthieu Kanj committed
169 170 171
			ndlsch23->counter_repetition_number = rel13->number_of_subframes_for_resource_assignment;
            ndlsch23->counter_current_sf_repetition   = 0;
		    ndlsch23->pointer_to_subframe             = 0;
172
			//SI information in reality have no feedback (so there is no retransmission from the HARQ view point since no sck and nack)
Matthieu Kanj's avatar
Matthieu Kanj committed
173 174
	        //  ndlsch_harq->frame = frame;
	        //  ndlsch_harq->subframe = subframe;
175

Matthieu Kanj's avatar
Matthieu Kanj committed
176 177
			ndlsch23->nrs_antenna_ports = rel13->nrs_antenna_ports_assumed_by_the_ue;
			ndlsch23->scrambling_sequence_intialization = rel13->scrambling_sequence_initialization_cinit;
178
		}
179 180
		else
		{
181
			//continue the remaining transmission of the previous SI at PHY if any (otherwise nothing)
182
			//there is no need of repeating the configuration on the ndlsch
AlanLi's avatar
AlanLi committed
183 184
			//ndlsch_harq->pdu = NULL;
			//LOG_I(PHY,"sib23=NULL\n");
Matthieu Kanj's avatar
Matthieu Kanj committed
185
			ndlsch_harq23->pdu = NULL;
AlanLi's avatar
AlanLi committed
186 187
			

188
		}
189

190
		//Independently if we have the PDU or not (first transmission or repetition) the process is activated for triggering the ndlsch_procedure
AlanLi's avatar
AlanLi committed
191
	  	//LOG_I(PHY,"ACTIVE_NB_IoT\n");
Matthieu Kanj's avatar
Matthieu Kanj committed
192
	  	ndlsch_harq23->status = ACTIVE_NB_IoT;
193
	  	//LOG_D(PHY,"A NB-handle_nfapi_dlsch_pdu_NB_IoT SIB23\n");
194

195
  }
196
  //ue specific data or RAR (we already have received the DCI for this)
197 198
  else if(rel13->rnti != 65535 && rel13->rnti_type == 1)
  {
199
  	  //printf("rel13->rnti: %d, eNB->ndlsch_RAR->rnti: %d\n",rel13->rnti,eNB->ndlsch_RAR->rnti);
Nick Ho's avatar
Nick Ho committed
200
  	  //eNB->ndlsch_RAR->rnti = rel13->rnti;
201
	  //check if the PDU is for RAR
202 203
 	  if(eNB->ndlsch_RAR != NULL && eNB->ndlsch_RAR->ndlsch_type == RAR) //rnti for the RAR should have been set priviously by the DCI
	  //if(eNB->ndlsch_RAR != NULL && rel13->rnti == eNB->ndlsch_RAR->rnti) //rnti for the RAR should have been set priviously by the DCI
204
	  {
205 206 207 208
		  
	  	  eNB->ndlsch_RAR->active = 1;
	  	  eNB->ndlsch_RAR->harq_process->TBS = rel13->length;

209 210 211 212
		  eNB->ndlsch_RAR->harq_process->pdu 		= sdu;
		  eNB->ndlsch_RAR->npdsch_start_symbol 		= rel13->start_symbol;
		  eNB->ndlsch_RAR->active 					= 1;

Matthieu Kanj's avatar
Matthieu Kanj committed
213
		  eNB->ndlsch_RAR->rnti 					= rel13->rnti;  
214

Matthieu Kanj's avatar
Matthieu Kanj committed
215 216
		  eNB->ndlsch_RAR->rnti_type 				= rel13->rnti_type;
  		  eNB->ndlsch_RAR->resource_assignment 		= rel13->resource_assignment;    // for NDLSCH // this value point to -->  number of subframes needed
217
          eNB->ndlsch_RAR->repetition_number 		= Irep_to_Nrep_x[rel13->repetition_number];
218 219 220 221
  		  eNB->ndlsch_RAR->modulation 				= rel13->modulation;

  		  eNB->ndlsch_RAR->number_of_subframes_for_resource_assignment   = rel13->number_of_subframes_for_resource_assignment; // for NDLSCH //table 16.4.1.3-1 // TS 36.213

222
		  eNB->ndlsch_RAR->counter_repetition_number       = Irep_to_Nrep_x[rel13->repetition_number];
223 224
		  eNB->ndlsch_RAR->counter_current_sf_repetition   = 0;
		  eNB->ndlsch_RAR->pointer_to_subframe             = 0;
Nick Ho's avatar
Nick Ho committed
225
		  printf("number of subframe : %d, Rep of subframe : %d\n",eNB->ndlsch_RAR->number_of_subframes_for_resource_assignment,eNB->ndlsch_RAR->counter_repetition_number);
226

227 228 229 230 231 232 233
	  }
	  else
	  { //this for ue data
		  //TODO
		  //program addition DLSCH parameters not from DCI (for the moment we only pass the pdu)
		  //int UE_id = find_dlsch(rel13->rnti,eNB,SEARCH_EXIST);

234

235
		  UE_id =  find_ue_NB_IoT(rel13->rnti,eNB);
236
	  	  AssertFatal(UE_id==-1,"no existing ue specific dlsch_context\n");
237

238
	  	  ndlsch = eNB->ndlsch[(uint8_t)UE_id];
239 240
	  	  ndlsch_harq     = eNB->ndlsch[(uint8_t)UE_id]->harq_process;
	  	  AssertFatal(ndlsch_harq!=NULL,"dlsch_harq for ue specific is null\n");
241

242 243
	  	  ndlsch->npdsch_start_symbol = rel13->start_symbol;
	  	  ndlsch_harq->pdu  = sdu;
244 245
	  	  ndlsch->active = 1;

246 247 248 249
	  	  eNB->ndlsch_RAR->rnti 					= rel13->rnti;  // how this value is tested in line 177 ???? i am missing something ????

		  eNB->ndlsch_RAR->rnti_type 				= rel13->rnti_type;   
  		  eNB->ndlsch_RAR->resource_assignment 		= rel13->resource_assignment ;    // for NDLSCH // this value point to -->  number of subframes needed
250
          eNB->ndlsch_RAR->repetition_number 		= Irep_to_Nrep_x[rel13->repetition_number];
251 252 253 254
  		  eNB->ndlsch_RAR->modulation 				= rel13->modulation;

  		  eNB->ndlsch_RAR->number_of_subframes_for_resource_assignment   = rel13->number_of_subframes_for_resource_assignment; // for NDLSCH //table 16.4.1.3-1 // TS 36.213

255
		  eNB->ndlsch_RAR->counter_repetition_number       = Irep_to_Nrep_x[rel13->repetition_number];
256 257
		  eNB->ndlsch_RAR->counter_current_sf_repetition   = 0;
		  eNB->ndlsch_RAR->pointer_to_subframe             = 0;
258
	  }
259 260

  }
261 262 263
  //I don't know which kind of data is
  else
  {
264
	  LOG_E(PHY, "handle_nfapi_dlsch_pdu_NB_IoT: Unknown type of data (rnti type %d, rnti %d)\n", rel13->rnti_type, rel13->rnti);
265
  }
266

AlanLi's avatar
AlanLi committed
267

268 269 270 271
}



272 273
/////////////////////////////////////////////////////////////////////////////////////////////////
//Memo for initialization TODO: target/SIMU/USER/init_lte.c/init_lte_eNB --> new_eNB_dlsch(..) //
274
//this is where the allocation of PHy_vars_eNB_NB_IoT and all the ndlsch structures happen            //
275 276
/////////////////////////////////////////////////////////////////////////////////////////////////

277

278
// do the schedule response and trigger the TX
279
void schedule_response_NB_IoT(Sched_Rsp_NB_IoT_t *Sched_INFO)
280
{
AlanLi's avatar
AlanLi committed
281
  //LOG_I(PHY,"schedule_response_NB_IoT\n");
282
  //XXX check if correct to take eNB like this
AlanLi's avatar
AlanLi committed
283 284
  PHY_VARS_eNB 		*eNB     = PHY_vars_eNB_g[0][Sched_INFO->CC_id];
  eNB_rxtx_proc_t 	*proc 	 = &eNB->proc.proc_rxtx[0];
285 286 287
  NB_IoT_eNB_NPBCH_t 		*npbch;
  ///
  int 						i;
288 289
  //module_id_t                     Mod_id    = Sched_INFO->module_id;
  //uint8_t                         CC_id     = Sched_INFO->CC_id;
290 291 292 293
  nfapi_dl_config_request_t 	*DL_req    		= Sched_INFO->DL_req;
  nfapi_ul_config_request_t 	*UL_req    		= Sched_INFO->UL_req;
  nfapi_hi_dci0_request_t 		*HI_DCI0_req 	= Sched_INFO->HI_DCI0_req;
  nfapi_tx_request_t        	*TX_req    		= Sched_INFO->TX_req; 
294

295 296 297
  //uint32_t                     hypersfn  		= Sched_INFO->hypersfn;
  //frame_t                      frame     		= Sched_INFO->frame;       // unused for instance
  sub_frame_t                    subframe  		= Sched_INFO->subframe;	 
298

AlanLi's avatar
AlanLi committed
299

300
  // implicite declaration of AssertFatal
301 302
  //AsserFatal(proc->subframe_tx != subframe, "Current subframe %d != NFAPI subframe %d\n",proc->subframe_tx,subframe);
  //AsserFatal(proc->frame_tx != frame, "Current sframe %d != NFAPI frame %d\n", proc->frame_tx,frame );
AlanLi's avatar
AlanLi committed
303
  
304

305
  uint8_t number_dl_pdu             = DL_req->dl_config_request_body.number_pdu;
306
  uint8_t number_ul_pdu				= UL_req->ul_config_request_body.number_of_pdus;
307
  uint8_t number_ul_dci             = HI_DCI0_req->hi_dci0_request_body.number_of_dci;
AlanLi's avatar
AlanLi committed
308 309 310 311 312
  
  /*
  if(number_dl_pdu>=5) number_dl_pdu=0;
  if(number_ul_dci>=5) number_ul_dci=0;
  */
313
  //uint8_t number_pdsch_rnti         = DL_req->number_pdsch_rnti; // for the moment not used
314
  // at most 2 pdus (DCI) in the case of NPDCCH
315 316 317
  nfapi_dl_config_request_pdu_t 	*dl_config_pdu;
  nfapi_ul_config_request_pdu_t 	*ul_config_pdu;
  nfapi_hi_dci0_request_pdu_t 		*hi_dci0_pdu;
318

Matthieu Kanj's avatar
Matthieu Kanj committed
319
  //clear previous possible allocation (maybe something else should be added)
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
  for(int i = 0; i < NUMBER_OF_UE_MAX_NB_IoT; i++)
  {
	  if(eNB->ndlsch[i])
	  {
		  eNB->ndlsch[i]->harq_process->round=0; // may not needed
		  /*clear previous allocation information for all UEs*/
		  eNB->ndlsch[i]->subframe_tx[subframe] = 0;
	  }

	  /*clear the DCI allocation maps for new subframe*/
	  if(eNB->nulsch[i])
	  {
		  eNB->nulsch[i]->harq_process->dci_alloc = 0; //flag for indicating that a DCI has been allocated for UL
		  eNB->nulsch[i]->harq_process->rar_alloc = 0; //Flag indicating that this ULSCH has been allocated by a RAR (for Msg3)
		  //no phich for NB-IoT so no DMRS should be utilized
	  }

  }


340
  for (i=0;i<number_dl_pdu;i++) //in principle this should be at most 2 (in case of DCI)
341
  {
342
    dl_config_pdu = &DL_req->dl_config_request_body.dl_config_pdu_list[i];
AlanLi's avatar
AlanLi committed
343
    //LOG_I(PHY, "number_dl_pdu: %d ,dl_config_pdu type: %d\n",number_dl_pdu,dl_config_pdu->pdu_type);
344 345 346
    switch (dl_config_pdu->pdu_type) 
    {
    	case NFAPI_DL_CONFIG_NPDCCH_PDU_TYPE:
347
    		//Remember: there is no DCI for SI information
348
    		//LOG_D(PHY,"Generate DL DCI PDU information from scheduler\n");
349
    		//TODO: separate the ndlsch structure configuration from the DCI (here we will encode only the DCI)
350
      		generate_eNB_dlsch_params_NB_IoT(eNB,proc,dl_config_pdu);
351 352
      		break;
    	case NFAPI_DL_CONFIG_NBCH_PDU_TYPE:
353

354
    		// for the moment we don't care about the n-bch pdu content since we need only the sdu if tx.request
AlanLi's avatar
AlanLi committed
355
    		npbch = &eNB->npbch; //in the main of the lte-softmodem they should allocate this memory of PHY_vars
356
    		npbch->h_sfn_lsb = dl_config_pdu->nbch_pdu.nbch_pdu_rel13.hyper_sfn_2_lsbs;
AlanLi's avatar
AlanLi committed
357 358 359 360
    		//LOG_I(PHY,"npbch->pdu\n");
    		dl_config_pdu->nbch_pdu.nbch_pdu_rel13.pdu_index = 1;
			
			
361 362
    		if(TX_req->tx_request_body.tx_pdu_list[dl_config_pdu->nbch_pdu.nbch_pdu_rel13.pdu_index].segments[0].segment_data != NULL)
    			npbch->pdu = TX_req->tx_request_body.tx_pdu_list[dl_config_pdu->nbch_pdu.nbch_pdu_rel13.pdu_index].segments[0].segment_data;
363
    		else
364
    			LOG_E(PHY, "Received a schedule_response with N-BCH but no SDU!!\n");
365

366
      		break;
367
    	case NFAPI_DL_CONFIG_NDLSCH_PDU_TYPE:
368
    		//we can have three types of NDLSCH based on our assumptions: SIB1, SI, Data, RAR
369 370 371 372 373 374 375 376 377 378
    		//remember that SI messages have no DCI in NB-IoT therefore this is the only way to configure the ndlsch_SI/ndlsch_SIB1 structures ndlsch->active = 1;

    		/*
    		 * OBSERVATION:
    		 * Although 2 DCI may be received over a schedule_response the transmission of the NDLSCH data foresees only 1 NDLSCH PDU at time.
    		 * Therefore is the MAC scheduler that knowing the different timing delay will send the corresponding schedule_response containing the NDLSCH PDU and the MAC PDU
    		 * at the proper DL subframe
    		 * -for this reason the activation of the ndslch structure is done only when we receive the NDLSCH pdu (here) such the in the TX procedure only 1 ue-specific pdu
    		 * 	result active from the loop before calling the ndlsch_procedure
    		 */
AlanLi's avatar
AlanLi committed
379
    		dl_config_pdu->ndlsch_pdu.ndlsch_pdu_rel13.pdu_index = 1;
380
    		handle_nfapi_dlsch_pdu_NB_IoT(eNB, proc,dl_config_pdu,TX_req->tx_request_body.tx_pdu_list[dl_config_pdu->ndlsch_pdu.ndlsch_pdu_rel13.pdu_index].segments[0].segment_data);
AlanLi's avatar
AlanLi committed
381
    		
382 383
    		break;
    	default:
AlanLi's avatar
AlanLi committed
384
    		LOG_D(PHY, "dl_config_pdu type not for NB_IoT\n");
385
    		break;
386 387 388
   }
  }
  
AlanLi's avatar
AlanLi committed
389
  
390 391
  for (i=0;i<number_ul_dci;i++) 
  {
392
    hi_dci0_pdu = &HI_DCI0_req->hi_dci0_request_body.hi_dci0_pdu_list[i];
AlanLi's avatar
AlanLi committed
393
    LOG_D(PHY, "number_ul_dci:%d ,hi_dci0_pdu->pdu_type: %d\n",number_ul_dci,hi_dci0_pdu->pdu_type);
394 395 396
    switch (hi_dci0_pdu->pdu_type) 
    {
    	case NFAPI_HI_DCI0_NPDCCH_DCI_PDU_TYPE:
397

AlanLi's avatar
AlanLi committed
398
      		//generate_eNB_ulsch_params_NB_IoT(eNB,proc,hi_dci0_pdu);
399 400 401

      		break;
    	default:
AlanLi's avatar
AlanLi committed
402
    		LOG_E(PHY, "hi_dci0_pdu type not for NB_IoT\n");
403
    		break;
404 405 406

  	}
  }
407 408


409
  for(i = 0; i< number_ul_pdu; i++)
410 411 412 413 414
  {
	  ul_config_pdu = &UL_req->ul_config_request_body.ul_config_pdu_list[i];
	  switch(ul_config_pdu->pdu_type)
	  {
	  case NFAPI_UL_CONFIG_NULSCH_PDU_TYPE:
415 416 417 418 419 420 421 422 423
		  //TODO should distinguish between data and between data (npusch format)
		  /*NB: for reception of Msg3 generally not exist a DCI (because scheduling information are implicitly given by the RAR)
		   * but in case of FAPI specs we should receive an UL_config (containing the NULSCH pdu) for configuring the PHY for Msg3 reception from the MAC
		   * (this UL_config most probably will be created by the MAC when fill the RAR)
		   * (most probably we don't have the DL_config (for the RAR transmission) and the UL_CONFIG (for the Msg3 reception) at the same time (same subrame)
		   * since we are working in HD-FDD mode so for sure the UE will transmit the Msg3 in another subframe so make sense to have a UL_CONFIG in subframe
		   * diferent from the DL_CONFIG one)
		   *
		   */
424 425
		  break;
	  case NFAPI_UL_CONFIG_NRACH_PDU_TYPE:
426
		  //TODO just for update the nprach  configuration (given at the beginning through phy_config_sib2)
427 428 429 430 431
		  break;
	  }
  }


432 433
  //XXX problem: although we may have nothing to transmit this function should be always triggered in order to allow the PHY layer to complete the repetitions
  //of previous Transport Blocks
434
  //phy_procedures_eNB_TX_NB_IoT(eNB,proc,NULL);
AlanLi's avatar
AlanLi committed
435 436 437
  
  //phy_procedures_eNB_TX_NB_IoT(eNB,proc,0); // check if 0 or NULL ?!
  LOG_D(PHY,"Schedule response has been done\n");
438 439
}

440
void PHY_config_req_NB_IoT(PHY_Config_NB_IoT_t* config_INFO){
AlanLi's avatar
AlanLi committed
441
	LOG_D(PHY,"[NB-IoT] PHY CONFIG REQ NB-IoT In\n");
442 443 444


	if(config_INFO->get_MIB != 0){
445

446
		//MIB-NB configuration
447
		phy_config_mib_eNB_NB_IoT(config_INFO->mod_id,
448
								  config_INFO->CC_id,
449 450 451 452 453 454
							  	  config_INFO->cfg->nfapi_config.rf_bands.rf_band[0],//eutraband
							  	  config_INFO->cfg->sch_config.physical_cell_id.value,
							      config_INFO->cfg->subframe_config.dl_cyclic_prefix_type.value,
							  	  config_INFO->cfg->subframe_config.ul_cyclic_prefix_type.value,
							  	  config_INFO->cfg->rf_config.tx_antenna_ports.value,
							  	  config_INFO->cfg->nfapi_config.earfcn.value,
455 456 457 458
							  	  config_INFO->cfg->nb_iot_config.prb_index.value,
							  	  config_INFO->cfg->nb_iot_config.operating_mode.value,
							  	  config_INFO->cfg->nb_iot_config.control_region_size.value,
							  	  config_INFO->cfg->nb_iot_config.assumed_crs_aps.value); //defined only in in-band different PCI
459

460 461 462 463 464
	}

	if(config_INFO->get_COMMON != 0)
	{
		//Common Configuration included in SIB2-NB
465
		phy_config_sib2_eNB_NB_IoT(config_INFO->mod_id,
466 467
								   config_INFO->CC_id,
						       	   &config_INFO->cfg->nb_iot_config, // FIXME to be evaluated is should be passed a pointer
468 469 470
						       	   &config_INFO->cfg->rf_config,
							   	   &config_INFO->cfg->uplink_reference_signal_config,
							   	   &config_INFO->extra_phy_parms);
471 472
	}

473
	///FOR FAPI is not specified
474 475 476 477
	if(config_INFO->get_DEDICATED!= 0)
	{
	//Dedicated Configuration

478
			/*phy_config_dedicated_eNB_NB_IoT(config_INFO->mod_id,
479 480
											config_INFO->CC_id,
											config_INFO->rnti,
481
											&config_INFO->extra_phy_parms);*/
482 483

	}
484

AlanLi's avatar
AlanLi committed
485
	LOG_D(PHY,"IF Module for PHY Configuration has been done\n");
486 487
}