dci_tools_NB_IoT.c 18.9 KB
Newer Older
Nick Ho's avatar
Nick Ho 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 30 31
/*
 * 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 PHY/LTE_TRANSPORT/dci_tools.c
 * \brief PHY Support routines (eNB/UE) for filling PDSCH/PUSCH/DLSCH/ULSCH data structures based on DCI PDUs generated by eNB MAC scheduler.
 * \author R. Knopp
 * \date 2011
 * \version 0.1
 * \company Eurecom
 * \email: knopp@eurecom.fr
 * \note
 * \warning
 */
32
//#include "PHY/defs.h"
33 34
#include "PHY/impl_defs_lte_NB_IoT.h"
#include "openair1/PHY/extern_NB_IoT.h"
35 36 37
//#include "PHY/LTE_TRANSPORT/extern_NB_IoT.h"
//#include "SCHED/defs_NB_IoT.h"
/*
Nick Ho's avatar
Nick Ho committed
38
#ifdef DEBUG_DCI_TOOLS
39
#include "PHY/vars_NB_IoT.h"
Nick Ho's avatar
Nick Ho committed
40
#endif
41 42
*/
//#include "assertions.h"
43
//#include "dlsch_tbs_full.h"
44
#include "PHY/LTE_TRANSPORT/dlsch_tbs_full_NB_IoT.h"
Nick Ho's avatar
Nick Ho committed
45 46 47

//#define DEBUG_HARQ

48 49
//#include "LAYER2/MAC/extern_NB_IoT.h"
//#include "LAYER2/MAC/defs_NB_IoT.h"
50
#include "PHY/defs_NB_IoT.h"
51

Nick Ho's avatar
Nick Ho committed
52 53
//#define DEBUG_DCI

54
void add_dci_NB_IoT(DCI_PDU_NB_IoT *DCI_pdu,void *pdu,rnti_t rnti,unsigned char dci_size_bytes,unsigned char aggregation,unsigned char dci_size_bits,unsigned char dci_fmt, uint8_t npdcch_start_symbol)
55
{
56
	//put the pdu
57
  memcpy(&DCI_pdu->dci_alloc[DCI_pdu->Num_dci].dci_pdu[0],pdu,dci_size_bytes);
58
  //configure the dci alloc
59 60 61 62 63
  DCI_pdu->dci_alloc[DCI_pdu->Num_dci].dci_length      = dci_size_bits;
  DCI_pdu->dci_alloc[DCI_pdu->Num_dci].L               = aggregation;
  DCI_pdu->dci_alloc[DCI_pdu->Num_dci].rnti            = rnti;
  DCI_pdu->dci_alloc[DCI_pdu->Num_dci].format          = dci_fmt;
  DCI_pdu->npdcch_start_symbol                         = npdcch_start_symbol;
Nick Ho's avatar
Nick Ho committed
64

65
  DCI_pdu->Num_dci++;
Nick Ho's avatar
Nick Ho committed
66

67 68
  LOG_D(MAC,"add ue specific dci format %d for rnti %x \n",dci_fmt,rnti);
}
Nick Ho's avatar
Nick Ho committed
69

70
//map the Isf (DCI param) to the number of subframes (Nsf)
71
int resource_to_subframe[8] = {1,2,3,4,5,6,8,10};
72

73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
int Scheddly_less_128[8] = {0,4,8,12,16,32,64,128};
int Scheddly_bigger_128[8] = {0,16,32,64,128,256,512,1024};
int Irep_to_Nrep[16] = {1,2,4,8,16,32,64,128,192,256,384,512,768,1024,1536,2048};


int Idelay_to_K0(uint8_t Sched_delay, int Rmax)
{
  int k0=0;

  if(Rmax <128)
  {
    k0 = Scheddly_less_128[Sched_delay];
  }else if(Rmax >=128)
  {
    k0 = Scheddly_bigger_128[Sched_delay];
  } 
  return k0;
}


int DCIrep_to_real_rep(uint8_t DCI_rep, int Rmax)
{
    int R=0;
    if(Rmax == 1)
    {
      if(DCI_rep == 0)
        R = 1;
    }else if (Rmax == 2)
    {
      if(DCI_rep == 0)
        R = 1;
      else if(DCI_rep == 1)
        R = 2;
    }else if (Rmax == 4)
    {
      if(DCI_rep == 0)
        R = 1;
      else if(DCI_rep == 1)
        R = 2;
        else if(DCI_rep == 2)
        R = 4;
    }else if (Rmax >= 8)
    {
      if(DCI_rep == 0)
        R = Rmax/8;
      else if(DCI_rep == 1)
        R = Rmax/4;
      else if(DCI_rep == 2)
        R = Rmax/2;
      else if(DCI_rep == 3)
        R = Rmax;
    }

    return R;
}

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 179 180 181 182 183 184 185

int generate_eNB_ulsch_params_from_dci_NB_IoT(PHY_VARS_eNB            *eNB,
                                              int                     frame,
                                              uint8_t                 subframe,
                                              DCI_CONTENT             *DCI_Content,
                                              uint16_t                rnti,
                                              NB_IoT_eNB_NPDCCH_t     *ndlcch,
                                              uint8_t                 aggregation,
                                              uint8_t                 npdcch_start_symbol,
                                              uint8_t                 ncce_index)
{

  int tmp = 0;
  int i = 0;
  uint8_t  *DCI_flip = NULL;
  ncce_index = 0;

  /// type = 0 => DCI Format N0, type = 1 => DCI Format N1, 1 bits
  uint8_t type;
  /// Subcarrier indication, 6 bits
  uint8_t scind;
  /// Resourse Assignment (RU Assignment), 3 bits
  uint8_t ResAssign;
  /// Modulation and Coding Scheme, 4 bits
  uint8_t mcs;
  /// New Data Indicator, 1 bits
  uint8_t ndi;
  /// Scheduling Delay, 2 bits
  uint8_t Scheddly;
  /// Repetition Number, 3 bits
  uint8_t RepNum;
  /// Redundancy version for HARQ (only use 0 and 2), 1 bits
  uint8_t rv;
  /// DCI subframe repetition Number, 2 bits
  uint8_t DCIRep;
  
      
  type        = DCI_Content->DCIN0.type;
  scind       = DCI_Content->DCIN0.scind;
  ResAssign   = DCI_Content->DCIN0.ResAssign;
  mcs         = DCI_Content->DCIN0.mcs;
  ndi         = DCI_Content->DCIN0.ndi;
  Scheddly    = DCI_Content->DCIN0.Scheddly;
  RepNum      = DCI_Content->DCIN0.RepNum;
  rv          = DCI_Content->DCIN0.rv;
  DCIRep      = DCI_Content->DCIN0.DCIRep;

  /*Now configure the npdcch structure*/

  // ndlcch->ncce_index          =   NCCE_index;
  // ndlcch->aggregation_level   =   aggregation;

  ndlcch->A[ncce_index]               = sizeof_DCIN0_t; // number of bits in DCI

  ndlcch->rnti[ncce_index] = rnti; //we store the RNTI (e.g. for RNTI will be used later)
  ndlcch->active[ncce_index] = 1; //will be activated by the corresponding NDSLCH pdu

186
  ndlcch->dci_repetitions[ncce_index]          = DCIrep_to_real_rep(DCIRep,16);        ////??????? should be repalce by the value in spec table 16.6-3, check also Rmax
187

188
  printf("dci_repetitions: %d, A = %d\n",ndlcch->dci_repetitions[ncce_index],ndlcch->A[ncce_index]);
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211

  DCI_flip = (uint8_t*)malloc(3*sizeof(uint8_t));

    for(i=0; i<3; ++i){
      DCI_flip[i] = 0x0;
    }

    DCI_flip[0] = (type << 7) | (scind << 1) | (ResAssign>>2);
    DCI_flip[1] =  (uint8_t)(ResAssign << 6) | (Scheddly << 4) | mcs;
    DCI_flip[2] = (rv << 7) | (RepNum << 4) | (ndi << 3) |(DCIRep <<1);
    
    ndlcch->pdu[ncce_index]    = DCI_flip;

    printf("DCI N0 content:");
    for (tmp =0;tmp<3;tmp++)
      printf("%d ",DCI_flip[tmp]);
    printf("\n");
    /*
     * TS 36.213 ch 16.4.1.5
     * ITBS is always set equivalent to IMCS for data
     * ISF = ResAssign
     */

212
    ndlcch->counter_repetition_number[ncce_index] = DCIrep_to_real_rep(DCIRep,16);          ////??????? should be repalce by the value in spec table 16.6-3, check also Rmax
213 214 215 216 217 218 219


    LOG_I(PHY,"DCI packing for N0 done \n");

}


220
int generate_eNB_dlsch_params_from_dci_NB_IoT(PHY_VARS_eNB      *eNB,
221 222 223 224 225
                                              int                      frame,
                                              uint8_t                  subframe,
                                              DCI_CONTENT              *DCI_Content,
                                              uint16_t                 rnti,
                                              DCI_format_NB_IoT_t      dci_format,
Matthieu Kanj's avatar
Matthieu Kanj committed
226
                                              NB_IoT_eNB_NPDCCH_t      *ndlcch,
227
                                              LTE_DL_FRAME_PARMS    *frame_parms,
Matthieu Kanj's avatar
Matthieu Kanj committed
228
                                              uint8_t                  aggregation,         //////????? maybe add the ncce index ??????????
229 230
									                            uint8_t                  npdcch_start_symbol,
                                              uint8_t                  ncce_index)
Nick Ho's avatar
Nick Ho committed
231 232
{

Matthieu Kanj's avatar
Matthieu Kanj committed
233
 // NB_IoT_eNB_NPDCCH_t  *ndlcch     = ;
Nick Ho's avatar
Nick Ho committed
234
  int tmp = 0;
Nick Ho's avatar
Nick Ho committed
235
  int i = 0;
Nick Ho's avatar
Nick Ho committed
236
  uint8_t  *DCI_flip = NULL;
Nick Ho's avatar
Nick Ho committed
237

238
  //N1 parameters
239
  //uint8_t ncce_index = 0;
Nick Ho's avatar
Nick Ho committed
240

241
  /// type = 0 => DCI Format N0, type = 1 => DCI Format N1, 1 bits
242
  uint8_t type = 0;
243
  //NPDCCH order indicator (set to 0),1 bits
244
  uint8_t orderIndicator = 0;
245
  // Scheduling Delay, 3 bits
246
  uint8_t Sched_delay = 0;
247
  // Resourse Assignment (RU Assignment), 3 bits
248
  uint8_t ResAssign = 0;//Isf
249
  // Modulation and Coding Scheme, 4 bits
250
  uint8_t mcs = 0;
251
  // Repetition Number, 4 bits
252
  uint8_t RepNum = 0;
253
  // DCI subframe repetition Number, 2 bits
254
  uint8_t DCIRep = 0;
255
  // New Data Indicator,1 bits
256
  uint8_t ndi = 0;
257
  // HARQ-ACK resource,4 bits
258
  uint8_t HARQackRes = 0;
Nick Ho's avatar
Nick Ho committed
259

260
  //N2 parameters
Nick Ho's avatar
Nick Ho committed
261

262
  //Direct indication information, 8 bits
263
  uint8_t directIndInf= 0;
264
  // Reserved information bits, 6 bits
265
  uint8_t resInfoBits =0;
Nick Ho's avatar
Nick Ho committed
266

267
  //   printf("Generate eNB DCI, format %d, rnti %x (pdu %p)\n",dci_format,rnti,dci_pdu);
Nick Ho's avatar
Nick Ho committed
268

269
  switch (dci_format) {
Nick Ho's avatar
Nick Ho committed
270

271
  // Impossible to have a DCI N0, we have condition before
272 273
  case DCIFormatN0:
    return(-1);
Nick Ho's avatar
Nick Ho committed
274 275
    break;

276
  case DCIFormatN1_RAR:  // This is DLSCH allocation for control traffic (no NDI and no ACK/NACK resource for RAR DCI)
Nick Ho's avatar
Nick Ho committed
277 278


279
	/*Packed DCI here-------------------------------------------*/
280 281
    type               = DCI_Content->DCIN1_RAR.type;
    orderIndicator     = DCI_Content->DCIN1_RAR.orderIndicator; 
282
    Sched_delay        = DCI_Content->DCIN1_RAR.Scheddly;
283 284 285
    ResAssign          = DCI_Content->DCIN1_RAR.ResAssign; 
    mcs                = DCI_Content->DCIN1_RAR.mcs; 
    RepNum             = DCI_Content->DCIN1_RAR.RepNum; 
286 287
    ndi                = DCI_Content->DCIN1_RAR.ndi;
    HARQackRes         = DCI_Content->DCIN1_RAR.HARQackRes; 
288
    DCIRep             = DCI_Content->DCIN1_RAR.DCIRep;
289

290
    /*Now configure the npdcch structure*/
291

Matthieu Kanj's avatar
Matthieu Kanj committed
292 293 294
   // ndlcch->ncce_index          =   NCCE_index;
   // ndlcch->aggregation_level   =   aggregation;

Nick Ho's avatar
Nick Ho committed
295
    ndlcch->A[ncce_index]               = sizeof_DCIN1_RAR_t; // number of bits in DCI
Matthieu Kanj's avatar
Matthieu Kanj committed
296 297 298

    //ndlcch->subframe_tx[subframe] = 1; // check if it's OK
    ndlcch->rnti[ncce_index] = rnti; //we store the RNTI (e.g. for RNTI will be used later)
299
    ndlcch->active[ncce_index] = 1; //will be activated by the corresponding NDSLCH pdu
Nick Ho's avatar
Nick Ho committed
300

301
    // use this value to configure PHY both harq_processes and resource mapping.
302
    ndlcch->scheduling_delay[ncce_index]         = Idelay_to_K0(Sched_delay,4);
Matthieu Kanj's avatar
Matthieu Kanj committed
303
    ndlcch->resource_assignment[ncce_index]      = resource_to_subframe[ResAssign];  //from Isf of DCI to the number of subframe
304
    ndlcch->repetition_number[ncce_index]        = Irep_to_Nrep[RepNum];                             // repetition number for NPDSCH
305
    ndlcch->dci_repetitions[ncce_index]          = DCIrep_to_real_rep(DCIRep,4);        ////??????? should be repalce by the value in spec table 16.6-3, check also Rmax
306

Nick Ho's avatar
Nick Ho committed
307
    //printf("dci_repetitions: %d, A = %d\n",ndlcch->dci_repetitions[ncce_index],ndlcch->A[ncce_index]);
308

Matthieu Kanj's avatar
Matthieu Kanj committed
309 310
    ndlcch->modulation[ncce_index]               = 2; //QPSK
    //// ////////////////////////////////////////////////if(ndlcch->round == 0) //this should be set from initialization (init-lte)
311

Matthieu Kanj's avatar
Matthieu Kanj committed
312 313
    //ndlcch->status[ncce_index] = ACTIVE_NB_IoT;
    ndlcch->mcs[ncce_index]    = mcs;
Nick Ho's avatar
Nick Ho committed
314

Nick Ho's avatar
Nick Ho committed
315 316 317

    DCI_flip = (uint8_t*)malloc(3*sizeof(uint8_t));

Nick Ho's avatar
Nick Ho committed
318 319 320 321 322 323 324
    for(i=0; i<3; ++i){
      DCI_flip[i] = 0x0;
    }

    DCI_flip[0] = (type << 7) | (orderIndicator << 6) | (Sched_delay<<2) | ResAssign ;
    DCI_flip[1] = (mcs << 4) | RepNum;
    DCI_flip[2] = (ndi << 7) | (HARQackRes << 3) | (DCIRep <<1);
Nick Ho's avatar
Nick Ho committed
325 326
    
    ndlcch->pdu[ncce_index]    = DCI_flip;
Nick Ho's avatar
Nick Ho committed
327

Nick Ho's avatar
Nick Ho committed
328
    printf("DCI N1 RAR PDU content:");
Nick Ho's avatar
Nick Ho committed
329
    for (tmp =0;tmp<3;tmp++)
Nick Ho's avatar
Nick Ho committed
330
      printf("%d ",DCI_flip[tmp]);
Nick Ho's avatar
Nick Ho committed
331
    printf("\n");
332 333 334 335 336 337
    /*
     * TS 36.213 ch 16.4.1.5
     * ITBS is always set equivalent to IMCS for data
     * ISF = ResAssign
     */

Matthieu Kanj's avatar
Matthieu Kanj committed
338 339
    ndlcch->TBS[ncce_index]      = TBStable_NB_IoT[mcs][ResAssign];
    //ndlcch->subframe[ncce_index] = subframe;
340
    ndlcch->counter_repetition_number[ncce_index] = DCIrep_to_real_rep(DCIRep,4);          ////??????? should be repalce by the value in spec table 16.6-3, check also Rmax
341 342 343 344 345 346 347
    //ndlsch_harq->B; we don-t have now my is given when we receive the dlsch data
    //ndlsch->error_treshold
    //ndlsch->G??
    //ndlsc->nsoft?? //set in new_eNB_dlsch (initialization)
    //ndlsch-> sqrt_rho_a?? set in dlsch_modulation
    //ndlsch-> sqrt_rho_b??? set in dlsch_modulation

348
    LOG_I(PHY,"DCI packing for N1RAR done \n");
349

350 351 352 353 354 355
    //set in new_eNB_dlsch (initialization)
    /*
     * Mlimit
     * nsoft
     * round
     */
Nick Ho's avatar
Nick Ho committed
356 357


358
    break;
Nick Ho's avatar
Nick Ho committed
359

360
  case DCIFormatN1: // for user data
361
    
Nick Ho's avatar
Nick Ho committed
362

363 364
    type               = DCI_Content->DCIN1.type;
    orderIndicator     = DCI_Content->DCIN1.orderIndicator; 
365
    Sched_delay        = DCI_Content->DCIN1.Scheddly;
366 367 368 369 370 371
    ResAssign          = DCI_Content->DCIN1.ResAssign; 
    mcs                = DCI_Content->DCIN1.mcs; 
    RepNum             = DCI_Content->DCIN1.RepNum; 
    ndi                = DCI_Content->DCIN1.ndi;
    HARQackRes         = DCI_Content->DCIN1.HARQackRes; 
    DCIRep             = DCI_Content->DCIN1.DCIRep;
372

373
    //add_dci_NB_IoT(eNB->DCI_pdu,DLSCH_DCI_NB_IoT,rnti,sizeof(DCIN1_t),aggregation,sizeof_DCIN1_t,DCIFormatN1,npdcch_start_symbol);
Nick Ho's avatar
Nick Ho committed
374

375
    /*Now configure the npdcch structure*/
Nick Ho's avatar
Nick Ho committed
376
    ndlcch->A[ncce_index]               = sizeof_DCIN1_t; // number of bits in DCI
377

Matthieu Kanj's avatar
Matthieu Kanj committed
378 379
    // ndlcch->ncce_index          =   NCCE_index;
    // ndlcch->aggregation_level   =   aggregation;
380

Matthieu Kanj's avatar
Matthieu Kanj committed
381 382
    //ndlcch->subframe_tx[subframe] = 1; // check if it's OK
    ndlcch->rnti[ncce_index]                  = rnti; //we store the RNTI (e.g. for RNTI will be used later)
383
    ndlcch->active[ncce_index]                = 1;//will be activated by the corresponding NDSLCH pdu
384

Matthieu Kanj's avatar
Matthieu Kanj committed
385
    // use this value to configure PHY both harq_processes and resource mapping.
Nick Ho's avatar
Nick Ho committed
386
    ndlcch->scheduling_delay[ncce_index]         = Idelay_to_K0(Sched_delay,4);
387 388
    ndlcch->resource_assignment[ncce_index]      = resource_to_subframe[ResAssign];  //from Isf of DCI to the number of subframe
    ndlcch->repetition_number[ncce_index]        = Irep_to_Nrep[RepNum];                             // repetition number for NPDSCH
Nick Ho's avatar
Nick Ho committed
389
    ndlcch->dci_repetitions[ncce_index]          = DCIrep_to_real_rep(DCIRep,4);        ////??????? should be repalce by the value in spec table 16.6-3, check also Rmax
Matthieu Kanj's avatar
Matthieu Kanj committed
390 391 392 393 394 395
    ndlcch->modulation[ncce_index]               = 2; //QPSK
    //if(ndlcch->round == 0){ //this should be set from initialization (init-lte)

  	//ndlcch->status[ncce_index]  = ACTIVE_NB_IoT;
  	ndlcch->mcs[ncce_index]     = mcs;
  	ndlcch->TBS[ncce_index]     = TBStable_NB_IoT[mcs][ResAssign]; // this table should be rewritten for nb-iot
Nick Ho's avatar
Nick Ho committed
396 397 398
    //ndlcch->pdu[ncce_index]    = DLSCH_DCI_NB_IoT;

    DCI_flip = (uint8_t*)malloc(3*sizeof(uint8_t));
Nick Ho's avatar
Nick Ho committed
399 400 401 402 403 404 405 406 407

    for(i=0; i<3; ++i){
      DCI_flip[i] = 0x0;
    }

    DCI_flip[0] = (type << 7) | (orderIndicator << 6) | (Sched_delay<<2) | ResAssign ;
    DCI_flip[1] = (mcs << 4) | RepNum;
    DCI_flip[2] = (ndi << 7) | (HARQackRes << 3) | (DCIRep <<1);
    //DCI_flip[0]        = 129;
Nick Ho's avatar
Nick Ho committed
408

409
    //DCI_flip[0]        = DCI_tmp[2]*2;
Nick Ho's avatar
Nick Ho committed
410 411
    //DCI_flip[1]        = DCI_tmp[1]*2;
    //DCI_flip[2]        = DCI_tmp[0]*2;
Nick Ho's avatar
Nick Ho committed
412
    //DCI_flip[2]        = 4;
Nick Ho's avatar
Nick Ho committed
413
    ndlcch->pdu[ncce_index]    = DCI_flip;
Matthieu Kanj's avatar
Matthieu Kanj committed
414

Nick Ho's avatar
Nick Ho committed
415 416 417 418
    printf("DCI N1 PDU content:");
    for (tmp =0;tmp<3;tmp++)
      printf("%d ",DCI_flip[tmp]);
    printf("\n");
Matthieu Kanj's avatar
Matthieu Kanj committed
419

Nick Ho's avatar
Nick Ho committed
420
    ndlcch->counter_repetition_number[ncce_index] = DCIrep_to_real_rep(DCIRep,4);          ////??????? should be repalce by the value in spec table 16.6-3, check also Rmax
Matthieu Kanj's avatar
Matthieu Kanj committed
421 422 423
    //}
    //ndlcch->frame[ncce_index]    = frame;
    //ndlcch->subframe[ncce_index] = subframe;
424 425 426 427

    break;

  case DCIFormatN2_Ind: //MP: for the moment is not implemented
Nick Ho's avatar
Nick Ho committed
428

429 430 431
    type               = DCI_Content->DCIN2_Ind.type;
    directIndInf       = DCI_Content->DCIN2_Ind.directIndInf; 
    resInfoBits        = DCI_Content->DCIN2_Ind.resInfoBits; 
Nick Ho's avatar
Nick Ho committed
432 433 434



435
    //add_dci_NB_IoT(eNB->DCI_pdu,DLSCH_DCI_NB_IoT,rnti,sizeof(DCIN2_Ind_t),aggregation,sizeof_DCIN2_Ind_t,DCIFormatN2_Ind,npdcch_start_symbol);
Nick Ho's avatar
Nick Ho committed
436

437
    // use this value to configure PHY both harq_processes and resource mapping.
438
    break;
Nick Ho's avatar
Nick Ho committed
439

440
    
441
  case DCIFormatN2_Pag:  //MP: for the moment is not implemented
Nick Ho's avatar
Nick Ho committed
442

443 444 445 446
    type               = DCI_Content->DCIN2_Pag.type;
    ResAssign          = DCI_Content->DCIN2_Pag.ResAssign; 
    mcs                = DCI_Content->DCIN2_Pag.mcs; 
    RepNum             = DCI_Content->DCIN2_Pag.RepNum; 
Nick Ho's avatar
Nick Ho committed
447
    DCIRep             = DCI_Content->DCIN2_Pag.DCIRep;
Nick Ho's avatar
Nick Ho committed
448

449
    //add_dci_NB_IoT(eNB->DCI_pdu,DLSCH_DCI_NB_IoT,rnti,sizeof(DCIN2_Pag_t),aggregation,sizeof_DCIN2_Pag_t,DCIFormatN2_Pag,npdcch_start_symbol);
Nick Ho's avatar
Nick Ho committed
450

451
    // use this value to configure PHY both harq_processes and resource mapping.
452
    break;
Nick Ho's avatar
Nick Ho committed
453 454 455 456 457 458 459 460 461 462


  default:
    LOG_E(PHY,"Unknown DCI format\n");
    return(-1);
    break;
  }

  // compute DL power control parameters

463
  //free(DLSCH_DCI_NB_IoT);
Nick Ho's avatar
Nick Ho committed
464 465

  return(0);
466
}
467 468


Matthieu Kanj's avatar
Matthieu Kanj committed
469
uint8_t subframe2harq_pid_NB_IoT(LTE_DL_FRAME_PARMS *frame_parms,uint32_t frame,uint8_t subframe)
470
{
471
  //MAC_xface_NB_IoT *mac_xface_NB_IoT; //test_xface
472 473 474 475 476 477 478 479 480 481 482
  /*
    #ifdef DEBUG_DCI
    if (frame_parms->frame_type == TDD)
    printf("dci_tools.c: subframe2_harq_pid, subframe %d for TDD configuration %d\n",subframe,frame_parms->tdd_config);
    else
    printf("dci_tools.c: subframe2_harq_pid, subframe %d for FDD \n",subframe);
    #endif
  */

  uint8_t ret = 255;

Matthieu Kanj's avatar
Matthieu Kanj committed
483
  if (frame_parms->frame_type == FDD) {
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515
    ret = (((frame<<1)+subframe)&7);
  } else {

    switch (frame_parms->tdd_config) {

    case 1:
      if ((subframe==2) ||
          (subframe==3) ||
          (subframe==7) ||
          (subframe==8))
        switch (subframe) {
        case 2:
        case 3:
          ret = (subframe-2);
          break;

        case 7:
        case 8:
          ret = (subframe-5);
          break;

        default:
          LOG_E(PHY,"subframe2_harq_pid_NB_IoT, Illegal subframe %d for TDD mode %d\n",subframe,frame_parms->tdd_config);
          ret = (255);
          break;
        }

      break;

    case 2:
      if ((subframe!=2) && (subframe!=7)) {
        LOG_E(PHY,"subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",subframe,frame_parms->tdd_config);
516
        //mac_xface_NB_IoT->macphy_exit("subframe2_harq_pid_NB_IoT, Illegal subframe");
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558
        ret = (255);
      }

      ret = (subframe/7);
      break;

    case 3:
      if ((subframe<2) || (subframe>4)) {
        LOG_E(PHY,"subframe2_harq_pid_NB_IoT, Illegal subframe %d for TDD mode %d\n",subframe,frame_parms->tdd_config);
        ret = (255);
      }

      ret = (subframe-2);
      break;

    case 4:
      if ((subframe<2) || (subframe>3)) {
        LOG_E(PHY,"subframe2_harq_pid_NB_IoT, Illegal subframe %d for TDD mode %d\n",subframe,frame_parms->tdd_config);
        ret = (255);
      }

      ret = (subframe-2);
      break;

    case 5:
      if (subframe!=2) {
        LOG_E(PHY,"subframe2_harq_pid_NB_IoT, Illegal subframe %d for TDD mode %d\n",subframe,frame_parms->tdd_config);
        ret = (255);
      }

      ret = (subframe-2);
      break;

    default:
      LOG_E(PHY,"subframe2_harq_pid_NB_IoT, Unsupported TDD mode %d\n",frame_parms->tdd_config);
      ret = (255);

    }
  }

  if (ret == 255) {
    LOG_E(PHY, "invalid harq_pid(%d) at SFN/SF = %d/%d\n", ret, frame, subframe);
559
    //mac_xface_NB_IoT->macphy_exit("invalid harq_pid");
560 561 562 563
  }
  return ret;
}